Skip to contentSkip to conversation

Generic PHY Framework

PATCH Superseded Kishon Vijay Abraham I 4 participants 21 messages Mar 28, 2013 – Apr 3, 2013

Subsystems (9)

v4 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v4 cover Generic PHY Framework

Added a generic PHY framework that provides a set of APIs for the PHY drivers to create/destroy a PHY and APIs for the PHY users to obtain a reference to the PHY with or without using phandle. To obtain a reference to the PHY without using phandle, the platform specfic intialization code (say from board file) should have already called phy_bind with the binding information. The binding information consists of phy's device name, phy user device name and an index. The index is used when the same phy user binds to mulitple phys.

This framework will be of use only to devices that uses external PHY (PHY functionality is not embedded within the controller).

The intention of creating this framework is to bring the phy drivers spread all over the Linux kernel to drivers/phy to increase code re-use and to increase code maintainability.

Comments to make PHY as bus wasn't done because PHY devices can be part of other bus and making a same device attached to multiple bus leads to bad design.

Making omap-usb2 and twl4030 to use this framework is provided as a sample.

This patch series is developed on linus tree HEAD. Once the patch series gets finalised I'll resend omap-usb2 and twl4030 part based on Felipe's tree.

Changes from v3:
* Changed the return value of PHY APIs to ENOSYS
* Added APIs of_phy_get_with_args/devm_of_phy_get_with_args to support getting PHYs if the same IP implements multiple PHYs.
* modified phy_bind API so that the binding information can now be _updated_. In effect of this removed the binding information added in board files and added only in usb-musb.c. If a particular board uses a different phy binding, it can update it in board file after usb_musb_init().
* Added Documentation/devicetree/bindings/phy/phy-bindings.txt for dt binding information.

Changes from v2:
* removed phy_descriptor structure completely so changed the APIs which were taking phy_descriptor as parameters
* Added 2 more APIs *of_phy_get_byname* and *devm_of_phy_get_byname* to be used by PHY user drivers which has *phy* and *phy-names* binding in the dt data
* Fixed a few typos
* Removed phy_list and we now use class_dev_iter_init, class_dev_iter_next and class_dev_iter_exit for traversing through the phy list. (Note we still need phy_bind list and phy_bind_mutex).
* Changed the sysfs entry name from *bind* to *phy_bind*.

Changes from v1:
* Added Documentation for the PHY framework
* Added few more APIs mostly w.r.t devres
* Modified omap-usb2 and twl4030 to make use of the new framework

Did USB enumeration testing in panda and beagle.

Kishon Vijay Abraham I (6):
drivers: phy: add generic PHY framework
usb: phy: omap-usb2: use the new generic PHY framework
usb: otg: twl4030: use the new generic PHY framework
ARM: OMAP: USB: Add phy binding information
ARM: dts: omap: update usb_otg_hs data
usb: musb: omap2430: use the new generic PHY framework

 Documentation/ABI/testing/sysfs-class-phy          |   15 +
 .../devicetree/bindings/phy/phy-bindings.txt       |   76 +++
 Documentation/devicetree/bindings/usb/omap-usb.txt |    5 +
 Documentation/phy.txt                              |  119 ++++
 MAINTAINERS                                        |    7 +
 arch/arm/boot/dts/omap3.dtsi                       |    2 +
 arch/arm/boot/dts/omap4.dtsi                       |    2 +
 arch/arm/mach-omap2/usb-musb.c                     |    7 +-
 drivers/Kconfig                                    |    2 +
 drivers/Makefile                                   |    2 +
 drivers/phy/Kconfig                                |   13 +
 drivers/phy/Makefile                               |    5 +
 drivers/phy/phy-core.c                             |  689 ++++++++++++++++++++
 drivers/usb/musb/musb_core.h                       |    2 +
 drivers/usb/musb/omap2430.c                        |   22 +-
 drivers/usb/otg/twl4030-usb.c                      |   36 +
 drivers/usb/phy/omap-usb2.c                        |   47 ++
 include/linux/phy/phy.h                            |  237 +++++++
 18 files changed, 1281 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-phy
 create mode 100644 Documentation/devicetree/bindings/phy/phy-bindings.txt
 create mode 100644 Documentation/phy.txt
 create mode 100644 drivers/phy/Kconfig
 create mode 100644 drivers/phy/Makefile
 create mode 100644 drivers/phy/phy-core.c
 create mode 100644 include/linux/phy/phy.h
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v4 1/6 drivers: phy: add generic PHY framework

The PHY framework provides a set of APIs for the PHY drivers to create/destroy a PHY and APIs for the PHY users to obtain a reference to the PHY with or without using phandle. To obtain a reference to the PHY without using phandle, the platform specfic intialization code (say from board file) should have already called phy_bind with the binding information. The binding information consists of phy's device name, phy user device name and an index. The index is used when the same phy user binds to mulitple phys.

PHY drivers should create the PHY by passing phy_descriptor that has describes the PHY (label, type etc..) and ops like init, exit, suspend, resume, poweron, shutdown.

The documentation for the generic PHY framework is added in Documentation/phy.txt and the documentation for the sysfs entry is added in Documentation/ABI/testing/sysfs-class-phy and the documentation for dt binding is can be found at Documentation/devicetree/bindings/phy/phy-bindings.txt

---
 Documentation/ABI/testing/sysfs-class-phy          |   15 +
 .../devicetree/bindings/phy/phy-bindings.txt       |   76 +++
 Documentation/phy.txt                              |  119 ++++
 MAINTAINERS                                        |    7 +
 drivers/Kconfig                                    |    2 +
 drivers/Makefile                                   |    2 +
 drivers/phy/Kconfig                                |   13 +
 drivers/phy/Makefile                               |    5 +
 drivers/phy/phy-core.c                             |  689 ++++++++++++++++++++
 include/linux/phy/phy.h                            |  237 +++++++
 10 files changed, 1165 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-phy
 create mode 100644 Documentation/devicetree/bindings/phy/phy-bindings.txt
 create mode 100644 Documentation/phy.txt
 create mode 100644 drivers/phy/Kconfig
 create mode 100644 drivers/phy/Makefile
 create mode 100644 drivers/phy/phy-core.c
 create mode 100644 include/linux/phy/phy.h
Documentation/ABI/testing/sysfs-class-phy new file +15 -0
new file mode 100644
index 0000000..47f17c9
@@ -0,0 +1,15 @@
+What:		/sys/class/phy/<phy>/label
+Date:		Feb 2013
+KernelVersion:	3.10
+Contact:	Kishon Vijay Abraham I <[email protected]>
+Description:
+		This is a read-only file for getting the label of the phy.
+
+What:		/sys/class/phy/<phy>/phy_bind
+Date:		Feb 2013
+KernelVersion:	3.10
+Contact:	Kishon Vijay Abraham I <[email protected]>
+Description:
+		This is a read-only file for reading the phy binding
+		information. It contains the device name of the controller,
+		the index and the device name of the PHY in that order.
Documentation/devicetree/bindings/phy/phy-bindings.txt new file +76 -0

76 lines not on this page · raw message

Documentation/phy.txt new file +119 -0

119 lines not on this page · raw message

MAINTAINERS +7 -0
index 72b0843..f2674e7 100644
@@ -3474,6 +3474,13 @@ S:	Maintained
 F:	include/asm-generic
 F:	include/uapi/asm-generic
 
+GENERIC PHY FRAMEWORK
+M:	Kishon Vijay Abraham I <[email protected]>
+L:	linux-kernel at vger.kernel.org
+S:	Supported
+F:	drivers/phy/
+F:	include/linux/phy/
+
 GENERIC UIO DRIVER FOR PCI DEVICES
 M:	"Michael S. Tsirkin" <[email protected]>
 L:	kvm at vger.kernel.org
drivers/Kconfig +2 -0
index 202fa6d..ad2c374a 100644
@@ -162,4 +162,6 @@ source "drivers/irqchip/Kconfig"
 
 source "drivers/ipack/Kconfig"
 
+source "drivers/phy/Kconfig"
+
 endmenu
drivers/Makefile +2 -0
index dce39a9..9da8321 100644
@@ -45,6 +45,8 @@ obj-y				+= char/
 # gpu/ comes after char for AGP vs DRM startup
 obj-y				+= gpu/
 
+obj-y				+= phy/
+
 obj-$(CONFIG_CONNECTOR)		+= connector/
 
 # i810fb and intelfb depend on char/agp/
drivers/phy/Kconfig new file +13 -0
new file mode 100644
index 0000000..5f85909
@@ -0,0 +1,13 @@
+#
+# PHY
+#
+
+menuconfig GENERIC_PHY
+	tristate "PHY Subsystem"
+	help
+	  Generic PHY support.
+
+	  This framework is designed to provide a generic interface for PHY
+	  devices present in the kernel. This layer will have the generic
+	  API by which phy drivers can create PHY using the phy framework and
+	  phy users can obtain reference to the PHY.
drivers/phy/Makefile new file +5 -0
new file mode 100644
index 0000000..9e9560f
@@ -0,0 +1,5 @@
+#
+# Makefile for the phy drivers.
+#
+
+obj-$(CONFIG_GENERIC_PHY)	+= phy-core.o
drivers/phy/phy-core.c new file +689 -0

689 lines not on this page · raw message

include/linux/phy/phy.h new file +237 -0

237 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH v4 1/6] drivers: phy: add generic PHY framework

Quoted 6 lines · Kishon Vijay Abraham I

The PHY framework provides a set of APIs for the PHY drivers to create/destroy a PHY and APIs for the PHY users to obtain a reference to the

Documentation/devicetree/bindings/phy/phy-bindings.txt +1 -0
 
+This document explains only the dt data binding. For general information about

Documentation/devicetree/bindings/phy/phy-bindings.txt line 11

Quoted 10 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +10 -0
+PHY subsystem refer Documentation/phy.txt
+
+PHY device node
+===============
+
+Optional Properties:
+#phy-cells:	Number of cells in a PHY specifier;  The meaning of all those
+		cells is defined by the binding for the phy node. However
+		in-order to return the correct PHY, the PHY susbsystem
+		requires the first cell always refers to the port.

Why impose that restriction? Other DT bindings do not.

This is typically implemented by having each provider driver implement a .of_xlate() operation, which parses all of the specifier cells, and returns the ID of the object it represents. This allows bindings to use whatever arbitrary representation they want.

For the common/simple cases where #phy-cells==0, or #phy-cells==1 and directly represents the PHY ID, the PHY core can provide an implementation of that common .of_xlate() function, which PHY provider drivers can simply plug in as their .of_xlate() function.

Documentation/devicetree/bindings/phy/phy-bindings.txt line 14

Quoted 2 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +2 -0
+This property is optional because it is needed only for the case where a
+single IP implements multiple PHYs.

The property should always exist so that the DT-parsing code in the PHY core can always validate exactly how many cells are present in the PHY specifier.

Documentation/devicetree/bindings/phy/phy-bindings.txt line 22

Quoted 8 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +8 -0
+
+For example:
+
+phys: phy {
+    compatible = "xxx";
+    reg1 = <...>;
+    reg2 = <...>;
+    reg3 = <...>;

3 separate reg values should be 3 separate entries in a single reg property, not 3 separate reg properties, with non-standard names.

Documentation/devicetree/bindings/phy/phy-bindings.txt line 33

Quoted 11 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +11 -0
+    .
+    .
+    #phy-cells = <1>;
+    .
+    .
+};
+
+That node describes an IP block that implements 3 different PHYs. In order to
+differentiate between these 3 PHYs, an additonal specifier should be given
+while trying to get a reference to it. (The PHY subsystem assumes the
+specifier is port id).

A single DT node would typically represent a single HW IP block, and hence typically have a single reg property. If there are 3 separate HW IP blocks, and their register aren't interleaved, and hence can be represented by 3 separate reg values, then I'd typically expect to see 3 separate DT nodes, one for each independent register range.

The only case where I'd expect a single DT node to provide multipe PHYs, is when a single HW IP block actually implements multiple PHYs /and/ the registers for those 3 PHYs are interleaved (or share bits in the same registers) such that each PHY can't be represented by a separate non-overlapping reg property.

Documentation/devicetree/bindings/phy/phy-bindings.txt

Quoted 2 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +2 -0
+example1:
+phys: phy {

How about:

Example 1:

usb1: usb at xxx {

Documentation/devicetree/bindings/phy/phy-bindings.txt

Quoted 2 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +2 -0
+};
+This node represents a controller that uses two PHYs one for usb2 and one for

Blank line after }?

Documentation/devicetree/bindings/phy/phy-bindings.txt line 60

Quoted 4 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +4 -0
+usb3. The controller driver can get the appropriate PHY either by using
+devm_of_phy_get/of_phy_get by passing the correct index or by using
+of_phy_get_byname/devm_of_phy_get_byname by passing the names given in
+*phy-names*.

Discussions of Linux-specific driver APIs should be in the Linux API documentation, not the DT binding documentation, which is supposed to be OS-agnostic. Instead, perhaps say:

Individual bindings must specify the required set of entries the phys property. Bindings must also specify either a required order for those entries in the phys property, or specify required set of names that must be present in the phy-names property, in which case the order is arbitrary.

Documentation/devicetree/bindings/phy/phy-bindings.txt line 63

Quoted 2 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +2 -0
+example2:
+phys: phy {

How about:

Example 2:

usb2: usb at yyy {

Documentation/devicetree/bindings/phy/phy-bindings.txt line 76

Quoted 4 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +4 -0
+This node represents a controller that uses one of the PHYs which is defined
+previously. Note that the phy handle has an additional specifier "1" to
+differentiate between the three PHYs. For this case, the controller driver
+should use of_phy_get_with_args/devm_of_phy_get_with_args.

I think tha last sentence should be removed, and perhaps the previous sentence extended with:

, as required by #phy-cells = <1> in the PHY provider node.

drivers/phy/phy-core.c

Quoted 3 lines
drivers/phy/phy-core.c +1 -0
 
+subsys_initcall(phy_core_init);

Why not make that module_init(); device probe() ordering should be handled using -EPROBE_DEFER these days, so the exact initcall used doesn't really matter, and hence it'd be best to use the most common one rather than something unusual.

#3 lore raw

Re: [PATCH v4 1/6] drivers: phy: add generic PHY framework

Hi,

Quoted 20 lines · Stephen Warren
Quoted 6 lines · Kishon Vijay Abraham I

The PHY framework provides a set of APIs for the PHY drivers to create/destroy a PHY and APIs for the PHY users to obtain a reference to the

Documentation/devicetree/bindings/phy/phy-bindings.txt +1 -0
 
+This document explains only the dt data binding. For general information about

Documentation/devicetree/bindings/phy/phy-bindings.txt line 11

Quoted 10 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +10 -0
+PHY subsystem refer Documentation/phy.txt
+
+PHY device node
+===============
+
+Optional Properties:
+#phy-cells:	Number of cells in a PHY specifier;  The meaning of all those
+		cells is defined by the binding for the phy node. However
+		in-order to return the correct PHY, the PHY susbsystem
+		requires the first cell always refers to the port.

Why impose that restriction? Other DT bindings do not.

Quoted 4 lines

This is typically implemented by having each provider driver implement a .of_xlate() operation, which parses all of the specifier cells, and returns the ID of the object it represents. This allows bindings to use whatever arbitrary representation they want.

Do you mean something like this

struct phy *of_phy_get(struct device *dev, int index)

{
	struct phy *phy = NULL;
	struct phy_bind *phy_map = NULL;
	struct of_phandle_args args;
	struct device_node *node;

	if (!dev->of_node) {
		dev_dbg(dev, "device does not have a device node entry\n");
		return ERR_PTR(-EINVAL);
	}

	ret = of_parse_phandle_with_args(dev->of_node, "phys", "#phy-cells",
		index, &args);
	if (ret) {
		dev_dbg(dev, "failed to get phy in %s node\n",
			dev->of_node->full_name);
		return ERR_PTR(-ENODEV);
	}

//Here we have to get a reference to the phy in order to call of_xlate which seems a little hacky to me. I'm not sure how else can we call the provider driver :-(

	phy = of_phy_lookup(dev, node);
	if (IS_ERR(phy) || !try_module_get(phy->ops->owner)) {
		phy = ERR_PTR(-EPROBE_DEFER);
		goto err0;
	}

//here we are checking if the phy has additional specifiers and if so call of_xlate using the phy we just obtained. The provider driver should check the args and return the appropriate *phy in this case.

	if (args.args_count > 0) {
		phy = phy->of_xlate(&args);
		if (IS_ERR(phy))
			goto err0;
	}

	phy_map = phy_bind(dev_name(dev), index, dev_name(&phy->dev));
	if (!IS_ERR(phy_map)) {
		phy_map->phy = phy;
		phy_map->auto_bind = true;
	}

	get_device(&phy->dev);

err0:

	of_node_put(node);

	return phy;
}

EXPORT_SYMBOL_GPL(of_phy_get);

Quoted 96 lines

For the common/simple cases where #phy-cells==0, or #phy-cells==1 and directly represents the PHY ID, the PHY core can provide an implementation of that common .of_xlate() function, which PHY provider drivers can simply plug in as their .of_xlate() function.

Documentation/devicetree/bindings/phy/phy-bindings.txt line 14

Quoted 2 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +2 -0
+This property is optional because it is needed only for the case where a
+single IP implements multiple PHYs.

The property should always exist so that the DT-parsing code in the PHY core can always validate exactly how many cells are present in the PHY specifier.

Documentation/devicetree/bindings/phy/phy-bindings.txt line 22

Quoted 8 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +8 -0
+
+For example:
+
+phys: phy {
+    compatible = "xxx";
+    reg1 = <...>;
+    reg2 = <...>;
+    reg3 = <...>;

3 separate reg values should be 3 separate entries in a single reg property, not 3 separate reg properties, with non-standard names.

Documentation/devicetree/bindings/phy/phy-bindings.txt line 33

Quoted 11 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +11 -0
+    .
+    .
+    #phy-cells = <1>;
+    .
+    .
+};
+
+That node describes an IP block that implements 3 different PHYs. In order to
+differentiate between these 3 PHYs, an additonal specifier should be given
+while trying to get a reference to it. (The PHY subsystem assumes the
+specifier is port id).

A single DT node would typically represent a single HW IP block, and hence typically have a single reg property. If there are 3 separate HW IP blocks, and their register aren't interleaved, and hence can be represented by 3 separate reg values, then I'd typically expect to see 3 separate DT nodes, one for each independent register range.

The only case where I'd expect a single DT node to provide multipe PHYs, is when a single HW IP block actually implements multiple PHYs /and/ the registers for those 3 PHYs are interleaved (or share bits in the same registers) such that each PHY can't be represented by a separate non-overlapping reg property.

Documentation/devicetree/bindings/phy/phy-bindings.txt

Quoted 2 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +2 -0
+example1:
+phys: phy {

How about:

Example 1:

usb1: usb at xxx {

Documentation/devicetree/bindings/phy/phy-bindings.txt

Quoted 2 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +2 -0
+};
+This node represents a controller that uses two PHYs one for usb2 and one for

Blank line after }?

Documentation/devicetree/bindings/phy/phy-bindings.txt line 60

Quoted 4 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +4 -0
+usb3. The controller driver can get the appropriate PHY either by using
+devm_of_phy_get/of_phy_get by passing the correct index or by using
+of_phy_get_byname/devm_of_phy_get_byname by passing the names given in
+*phy-names*.

Discussions of Linux-specific driver APIs should be in the Linux API documentation, not the DT binding documentation, which is supposed to be OS-agnostic. Instead, perhaps say:

Individual bindings must specify the required set of entries the phys property. Bindings must also specify either a required order for those entries in the phys property, or specify required set of names that must be present in the phy-names property, in which case the order is arbitrary.

Documentation/devicetree/bindings/phy/phy-bindings.txt line 63

Quoted 2 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +2 -0
+example2:
+phys: phy {

How about:

Example 2:

usb2: usb at yyy {

Documentation/devicetree/bindings/phy/phy-bindings.txt line 76

Quoted 4 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt +4 -0
+This node represents a controller that uses one of the PHYs which is defined
+previously. Note that the phy handle has an additional specifier "1" to
+differentiate between the three PHYs. For this case, the controller driver
+should use of_phy_get_with_args/devm_of_phy_get_with_args.

I think tha last sentence should be removed, and perhaps the previous sentence extended with:

, as required by #phy-cells = <1> in the PHY provider node.

Quoted 8 lines

drivers/phy/phy-core.c

Quoted 3 lines
drivers/phy/phy-core.c +1 -0
 
+subsys_initcall(phy_core_init);

Why not make that module_init(); device probe() ordering should be handled using -EPROBE_DEFER these days, so the exact initcall used doesn't really matter, and hence it'd be best to use the most common one rather than something unusual.

hmm.. ok.

Thanks
Kishon

#4 lore raw

Re: [PATCH v4 1/6] drivers: phy: add generic PHY framework

Quoted 42 lines · Kishon Vijay Abraham I

Hi,

Quoted 20 lines · Stephen Warren
Quoted 6 lines · Kishon Vijay Abraham I

The PHY framework provides a set of APIs for the PHY drivers to create/destroy a PHY and APIs for the PHY users to obtain a reference to the

Documentation/devicetree/bindings/phy/phy-bindings.txt new file +0 -0
 

Documentation/devicetree/bindings/phy/phy-bindings.txt line 11

Quoted 10 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt new file +10 -0
+PHY subsystem refer Documentation/phy.txt
+
+PHY device node
+===============
+
+Optional Properties:
+#phy-cells:    Number of cells in a PHY specifier;  The meaning of all those
+        cells is defined by the binding for the phy node. However
+        in-order to return the correct PHY, the PHY susbsystem
+        requires the first cell always refers to the port.

Why impose that restriction? Other DT bindings do not.

Quoted 4 lines

This is typically implemented by having each provider driver implement a .of_xlate() operation, which parses all of the specifier cells, and returns the ID of the object it represents. This allows bindings to use whatever arbitrary representation they want.

Do you mean something like this

struct phy *of_phy_get(struct device *dev, int index)

{
    struct phy *phy = NULL;
    struct phy_bind *phy_map = NULL;
    struct of_phandle_args args;
    struct device_node *node;

    if (!dev->of_node) {
        dev_dbg(dev, "device does not have a device node entry\n");
        return ERR_PTR(-EINVAL);
    }
Quoted 7 lines
    ret = of_parse_phandle_with_args(dev->of_node, "phys", "#phy-cells",
        index, &args);
    if (ret) {
        dev_dbg(dev, "failed to get phy in %s node\n",
            dev->of_node->full_name);
        return ERR_PTR(-ENODEV);
    }

Looks good.

Quoted 8 lines

//Here we have to get a reference to the phy in order to call of_xlate which seems a little hacky to me. I'm not sure how else can we call the provider driver :-(

    phy = of_phy_lookup(dev, node);
    if (IS_ERR(phy) || !try_module_get(phy->ops->owner)) {
        phy = ERR_PTR(-EPROBE_DEFER);
        goto err0;
    }

I think the concept of a "PHY provider" and a "PHY instance" are different.

of_xlate should be called on a "PHY provider", and return a "PHY instance". Hence, above you want to only look up a "PHY provider", so there's no hackiness involved.

Quoted 4 lines

//here we are checking if the phy has additional specifiers and if so call of_xlate using the phy we just obtained. The provider driver should check the args and return the appropriate *phy in this case.

    if (args.args_count > 0) {

It's probably simplest to always call of_xlate; that way, you're always calling it on a "PHY provider" and getting back a "PHY instance". For providers that only provide 1 instance, the implementation should be simple:-)

Quoted 19 lines
        phy = phy->of_xlate(&args);
        if (IS_ERR(phy))
            goto err0;
    }

    phy_map = phy_bind(dev_name(dev), index, dev_name(&phy->dev));
    if (!IS_ERR(phy_map)) {
        phy_map->phy = phy;
        phy_map->auto_bind = true;
    }

    get_device(&phy->dev);

err0:

    of_node_put(node);

    return phy;
}

EXPORT_SYMBOL_GPL(of_phy_get);

#5 lore raw

Re: [PATCH v4 1/6] drivers: phy: add generic PHY framework

Quoted 62 lines · Stephen Warren
Quoted 42 lines · Kishon Vijay Abraham I

Hi,

Quoted 20 lines · Stephen Warren
Quoted 6 lines · Kishon Vijay Abraham I

The PHY framework provides a set of APIs for the PHY drivers to create/destroy a PHY and APIs for the PHY users to obtain a reference to the

Documentation/devicetree/bindings/phy/phy-bindings.txt new file +0 -0
 

Documentation/devicetree/bindings/phy/phy-bindings.txt line 11

Quoted 10 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt new file +10 -0
+PHY subsystem refer Documentation/phy.txt
+
+PHY device node
+===============
+
+Optional Properties:
+#phy-cells:    Number of cells in a PHY specifier;  The meaning of all those
+        cells is defined by the binding for the phy node. However
+        in-order to return the correct PHY, the PHY susbsystem
+        requires the first cell always refers to the port.

Why impose that restriction? Other DT bindings do not.

Quoted 4 lines

This is typically implemented by having each provider driver implement a .of_xlate() operation, which parses all of the specifier cells, and returns the ID of the object it represents. This allows bindings to use whatever arbitrary representation they want.

Do you mean something like this

struct phy *of_phy_get(struct device *dev, int index)

{
     struct phy *phy = NULL;
     struct phy_bind *phy_map = NULL;
     struct of_phandle_args args;
     struct device_node *node;

     if (!dev->of_node) {
         dev_dbg(dev, "device does not have a device node entry\n");
         return ERR_PTR(-EINVAL);
     }
Quoted 7 lines
     ret = of_parse_phandle_with_args(dev->of_node, "phys", "#phy-cells",
         index, &args);
     if (ret) {
         dev_dbg(dev, "failed to get phy in %s node\n",
             dev->of_node->full_name);
         return ERR_PTR(-ENODEV);
     }

Looks good.

Quoted 8 lines

//Here we have to get a reference to the phy in order to call of_xlate which seems a little hacky to me. I'm not sure how else can we call the provider driver :-(

     phy = of_phy_lookup(dev, node);
     if (IS_ERR(phy) || !try_module_get(phy->ops->owner)) {
         phy = ERR_PTR(-EPROBE_DEFER);
         goto err0;
     }
Quoted 5 lines

I think the concept of a "PHY provider" and a "PHY instance" are different.

of_xlate should be called on a "PHY provider", and return a "PHY instance". Hence, above you want to only look up a "PHY provider", so there's no hackiness involved.

Cool. That makes it a lot clearer.

Thanks
Kishon

#6 lore raw

Re: [PATCH v4 1/6] drivers: phy: add generic PHY framework

In reply to Kishon Vijay Abraham I

Just couple minor comments...

Quoted 20 lines · Kishon Vijay Abraham I

The PHY framework provides a set of APIs for the PHY drivers to create/destroy a PHY and APIs for the PHY users to obtain a reference to the PHY with or without using phandle. To obtain a reference to the PHY without using phandle, the platform specfic intialization code (say from board file) should have already called phy_bind with the binding information. The binding information consists of phy's device name, phy user device name and an index. The index is used when the same phy user binds to mulitple phys.

PHY drivers should create the PHY by passing phy_descriptor that has describes the PHY (label, type etc..) and ops like init, exit, suspend, resume, poweron, shutdown.

The documentation for the generic PHY framework is added in Documentation/phy.txt and the documentation for the sysfs entry is added in Documentation/ABI/testing/sysfs-class-phy and the documentation for dt binding is can be found at Documentation/devicetree/bindings/phy/phy-bindings.txt

---

[...]

Quoted 2 lines

+/**
+ * phy_put - release the PHY

nit: According to kernel-doc documentation function names should have parentheses appended to the name. So it would need to be

+ * phy_put() - release the PHY

in this case and it applies to multiple places elsewhere in this patch.

Quoted 12 lines

+ * @phy: the phy returned by phy_get()
+ *
+ * Releases a refcount the caller received from phy_get().
+ */

drivers/phy/phy-core.c new file +8 -0
+void phy_put(struct phy *phy)
+{
+	if (phy) {
+		module_put(phy->ops->owner);
+		put_device(&phy->dev);
+	}
+}
+EXPORT_SYMBOL_GPL(phy_put);

[...]

Quoted 4 lines

+/**
+ * devm_of_phy_get_byname - lookup and obtain a reference to a phy by name
+ * @dev: device that requests this phy
+ * @string - the phy name as given in the dt data

s/ -/:

Quoted 21 lines

+ *
+ * Calls devm_of_phy_get (which associates the device with the phy using devres
+ * on successful phy get) and passes on the return value of devm_of_phy_get.
+ */

drivers/phy/phy-core.c new file +17 -0
+struct phy *devm_of_phy_get_byname(struct device *dev, const char *string)
+{
+	int index;
+
+	if (!dev->of_node) {
+		dev_dbg(dev, "device does not have a device node entry\n");
+		return ERR_PTR(-EINVAL);
+	}
+
+	index = of_property_match_string(dev->of_node, "phy-names", string);
+
+	return devm_of_phy_get(dev, index);
+}
+EXPORT_SYMBOL_GPL(devm_of_phy_get_byname);
+
+/**
+ * phy_get - lookup and obtain a reference to a phy.

drivers/phy/phy-core.c line 362

Quoted 10 lines
drivers/phy/phy-core.c new file +10 -0
+ * @dev: device that requests this phy
+ * @index: the index of the phy
+ *
+ * Returns the phy driver, after getting a refcount to it; or
+ * -ENODEV if there is no such phy.  The caller is responsible for
+ * calling phy_put() to release that count.
+ */
+struct phy *phy_get(struct device *dev, int index)
+{
+	struct phy *phy = NULL;

Unneeded initialization.

drivers/phy/phy-core.c line 367

Quoted 4 lines
drivers/phy/phy-core.c new file +4 -0
+	phy = phy_lookup(dev, index);
+	if (IS_ERR(phy)) {
+		dev_err(dev, "unable to find phy\n");
+		goto err0;

Wouldn't it be better to just do:

		return phy;

drivers/phy/phy-core.c line 371

Quoted 4 lines
drivers/phy/phy-core.c new file +4 -0
+	}
+
+	if (!try_module_get(phy->ops->owner)) {
+		phy = ERR_PTR(-EPROBE_DEFER);

and

		return ERR_PTR(-EPROBE_DEFER);

Review

Quoted 1 line
(quoted diff) +1 -0
+		goto err0;

and to drop this goto and the label below ?

Quoted 17 lines
drivers/phy/phy-core.c new file +8 -0
+	}
+
+	get_device(&phy->dev);
+
+err0:
+	return phy;
+}
+EXPORT_SYMBOL_GPL(phy_get);
include/linux/phy/phy.h new file +2 -0
new file mode 100644
index 0000000..0cb2298
@@ -0,0 +1,237 @@
+/*
+ * phy.h -- generic phy header file

[...]

include/linux/phy/phy.h

Quoted 7 lines
include/linux/phy/phy.h new file +7 -0
+#ifndef __DRIVERS_PHY_H
+#define __DRIVERS_PHY_H
+
+#include<linux/err.h>
+#include<linux/of.h>
+
+struct phy

I think you also need to add either

#include <linux/device.h>

or

struct device;

struct device * is used further in this file.

Quoted 9 lines

+/**
+ * struct phy_ops - set of function pointers for performing phy operations
+ * @init: operation to be performed for initializing phy
+ * @exit: operation to be performed while exiting
+ * @suspend: suspending the phy
+ * @resume: resuming the phy

+ * @poweron: powering on the phy
+ * @shutdown: shutting down the phy

Could these be named power_on/power_off ? Looks a bit more symmetric to me that way.

include/linux/phy/phy.h line 45

Quoted 11 lines

+ * @owner: the module owner containing the ops
+ */

include/linux/phy/phy.h new file +9 -0
+struct phy_ops {
+	int	(*init)(struct phy *phy);
+	int	(*exit)(struct phy *phy);
+	int	(*suspend)(struct phy *phy);
+	int	(*resume)(struct phy *phy);
+	int	(*poweron)(struct phy *phy);
+	int	(*shutdown)(struct phy *phy);
+	struct module *owner;
+};

Thanks,
Sylwester

#7 lore raw

Re: [PATCH v4 1/6] drivers: phy: add generic PHY framework

Hi,

Quoted 33 lines · Sylwester Nawrocki

Just couple minor comments...

Quoted 26 lines · Kishon Vijay Abraham I

The PHY framework provides a set of APIs for the PHY drivers to create/destroy a PHY and APIs for the PHY users to obtain a reference to the
PHY with or without using phandle. To obtain a reference to the PHY without
using phandle, the platform specfic intialization code (say from board file)
should have already called phy_bind with the binding information. The binding
information consists of phy's device name, phy user device name and an index.
The index is used when the same phy user binds to mulitple phys.

PHY drivers should create the PHY by passing phy_descriptor that has describes the PHY (label, type etc..) and ops like init, exit, suspend, resume,
poweron, shutdown.

The documentation for the generic PHY framework is added in Documentation/phy.txt and the documentation for the sysfs entry is added in Documentation/ABI/testing/sysfs-class-phy and the documentation for dt binding is can be found at Documentation/devicetree/bindings/phy/phy-bindings.txt

---

[...]

Quoted 2 lines

+/**
+ * phy_put - release the PHY

Quoted 6 lines

nit: According to kernel-doc documentation function names should have parentheses appended to the name. So it would need to be

+ * phy_put() - release the PHY

in this case and it applies to multiple places elsewhere in this patch.

Will fix it.

Quoted 14 lines
Quoted 13 lines

+ * @phy: the phy returned by phy_get()
+ *
+ * Releases a refcount the caller received from phy_get().
+ */

drivers/phy/phy-core.c new file +8 -0
+void phy_put(struct phy *phy)
+{
+    if (phy) {
+        module_put(phy->ops->owner);
+        put_device(&phy->dev);
+    }
+}
+EXPORT_SYMBOL_GPL(phy_put);

[...]

Quoted 7 lines
Quoted 5 lines

+/**
+ * devm_of_phy_get_byname - lookup and obtain a reference to a phy by name
+ * @dev: device that requests this phy
+ * @string - the phy name as given in the dt data

s/ -/:

Ok.

Quoted 38 lines
Quoted 25 lines

+ *
+ * Calls devm_of_phy_get (which associates the device with the phy using devres
+ * on successful phy get) and passes on the return value of devm_of_phy_get.
+ */
+struct phy *devm_of_phy_get_byname(struct device *dev, const char *string)

drivers/phy/phy-core.c new file +16 -0
+{
+    int index;
+
+    if (!dev->of_node) {
+        dev_dbg(dev, "device does not have a device node entry\n");
+        return ERR_PTR(-EINVAL);
+    }
+
+    index = of_property_match_string(dev->of_node, "phy-names", string);
+
+    return devm_of_phy_get(dev, index);
+}
+EXPORT_SYMBOL_GPL(devm_of_phy_get_byname);
+
+/**
+ * phy_get - lookup and obtain a reference to a phy.

drivers/phy/phy-core.c line 362

Quoted 10 lines
drivers/phy/phy-core.c new file +10 -0
+ * @dev: device that requests this phy
+ * @index: the index of the phy
+ *
+ * Returns the phy driver, after getting a refcount to it; or
+ * -ENODEV if there is no such phy.  The caller is responsible for
+ * calling phy_put() to release that count.
+ */
+struct phy *phy_get(struct device *dev, int index)
+{
+    struct phy *phy = NULL;

Unneeded initialization.

Quoted 6 lines

drivers/phy/phy-core.c line 367

Quoted 4 lines
drivers/phy/phy-core.c new file +4 -0
+    phy = phy_lookup(dev, index);
+    if (IS_ERR(phy)) {
+        dev_err(dev, "unable to find phy\n");
+        goto err0;

Wouldn't it be better to just do:

Indeed.

Quoted 42 lines
         return phy;

drivers/phy/phy-core.c line 371

Quoted 4 lines
drivers/phy/phy-core.c new file +4 -0
+    }
+
+    if (!try_module_get(phy->ops->owner)) {
+        phy = ERR_PTR(-EPROBE_DEFER);

and

         return ERR_PTR(-EPROBE_DEFER);
Quoted 1 line

+ goto err0;

and to drop this goto and the label below ?

Quoted 17 lines
drivers/phy/phy-core.c new file +8 -0
+    }
+
+    get_device(&phy->dev);
+
+err0:
+    return phy;
+}
+EXPORT_SYMBOL_GPL(phy_get);
include/linux/phy/phy.h new file +2 -0
new file mode 100644
index 0000000..0cb2298
@@ -0,0 +1,237 @@
+/*
+ * phy.h -- generic phy header file

[...]

include/linux/phy/phy.h

Quoted 7 lines
include/linux/phy/phy.h new file +7 -0
+#ifndef __DRIVERS_PHY_H
+#define __DRIVERS_PHY_H
+
+#include<linux/err.h>
+#include<linux/of.h>
+
+struct phy

I think you also need to add either

Quoted 7 lines

#include <linux/device.h>

or

struct device;

struct device * is used further in this file.

Ok.

Quoted 9 lines
Quoted 8 lines

+/**
+ * struct phy_ops - set of function pointers for performing phy operations
+ * @init: operation to be performed for initializing phy
+ * @exit: operation to be performed while exiting
+ * @suspend: suspending the phy
+ * @resume: resuming the phy

Quoted 5 lines
Quoted 2 lines

+ * @poweron: powering on the phy
+ * @shutdown: shutting down the phy

Could these be named power_on/power_off ? Looks a bit more symmetric to me that way.

Ok. Will have it that way.

Thanks
Kishon

#8 lore raw

Re: [PATCH v4 1/6] drivers: phy: add generic PHY framework

In reply to Kishon Vijay Abraham I
Quoted 73 lines · Kishon Vijay Abraham I
Documentation/devicetree/bindings/phy/phy-bindings.txt new file +66 -0
new file mode 100644
index 0000000..35696b2
@@ -0,0 +1,76 @@
+This document explains only the dt data binding. For general information about
+PHY subsystem refer Documentation/phy.txt
+
+PHY device node
+===============
+
+Optional Properties:
+#phy-cells:	Number of cells in a PHY specifier;  The meaning of all those
+		cells is defined by the binding for the phy node. However
+		in-order to return the correct PHY, the PHY susbsystem
+		requires the first cell always refers to the port.
+
+This property is optional because it is needed only for the case where a
+single IP implements multiple PHYs.
+
+For example:
+
+phys: phy {
+    compatible = "xxx";
+    reg1 =<...>;
+    reg2 =<...>;
+    reg3 =<...>;
+    .
+    .
+    #phy-cells =<1>;
+    .
+    .
+};
+
+That node describes an IP block that implements 3 different PHYs. In order to
+differentiate between these 3 PHYs, an additonal specifier should be given
+while trying to get a reference to it. (The PHY subsystem assumes the
+specifier is port id).
+
+PHY user node
+=============
+
+Required Properties:
+phys : the phandle for the PHY device (used by the PHY subsystem)
+
+Optional properties:
+phy-names : the names of the PHY corresponding to the PHYs present in the
+	    *phys* phandle
+
+example1:
+phys: phy {
+    compatible = "xxx";
+    reg =<...>;
+    .
+    .
+    phys =<&usb2_phy>,<&usb3_phy>;
+    phy-names = "usb2phy", "usb3phy";
+    .
+    .
+};
+This node represents a controller that uses two PHYs one for usb2 and one for
+usb3. The controller driver can get the appropriate PHY either by using
+devm_of_phy_get/of_phy_get by passing the correct index or by using
+of_phy_get_byname/devm_of_phy_get_byname by passing the names given in
+*phy-names*.
+
+example2:
+phys: phy {
+    compatible = "xxx";
+    reg =<...>;
+    .

Documentation/devicetree/bindings/phy/phy-bindings.txt line 76

Quoted 10 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt new file +10 -0
+    .
+    phys =<&phys 1>;
+    .
+    .
+};
+
+This node represents a controller that uses one of the PHYs which is defined
+previously. Note that the phy handle has an additional specifier "1" to
+differentiate between the three PHYs. For this case, the controller driver
+should use of_phy_get_with_args/devm_of_phy_get_with_args.

This means a PHY user needs to know indexes at the PHY driver ?

I have been thinking of using this for an IP which has 4 video PHYs: 2 MIPI CSI-2 and 2 MIPI DSI. The IP has just 2 registers, each of which is shared between one MIPI CSI-2 DPHY and one MIPI DSI DPHY. So I thought about creating
a single device node for this IP and using 4 indexes for the PHYs, e.g. 0...3.
Then users of each PHY type would use only indexes 0..1 (to select their corresponding port).

However I fail to see how this could now be represented in the bindings.

I assume struct phy::type could be used to differentiate between CSI-2 and DSI.
And struct phy::port could be used to select specific CSI-2 or DSI channel (0, 1). Ideally the phy users should not care about index of a PHY at the PHY
device tree node. E.g. there are 2 MIPI CSI-2 receivers and each has only one PHY assigned to it. I'm just wondering how the binding should look like, so a PHY could be associated with a receiver automatically by the phy-core, e.g.

/* DPHY IP node */

video-phy {
	  reg = <0x10000000 8>;
};

/* MIPI DSI nodes */

dsi_0 {
      phys = <&video-phy 0>;
};
dsi_1 {
      phys = <&video-phy 1>;
};

/* MIPI CSI-2 nodes */

csi_0 {
      phys = <&video-phy 2>;
};
csi_1 {
      phys = <&video-phy 3>;
};

I'm not sure if it is not an overkill to use this the PHY framework with a device which has only 2 registers. Perhaps something less heavy could be designed for it. However, if the PHY framework is commonly used there should be no issue wrt enabling the whole big infrastructure for a simple device like this.

Thanks,
Sylwester

#9 lore raw

Re: [PATCH v4 1/6] drivers: phy: add generic PHY framework

Quoted 12 lines · Sylwester Nawrocki
Quoted 11 lines · Kishon Vijay Abraham I
Documentation/devicetree/bindings/phy/phy-bindings.txt new file +9 -0
 
+example2:
+phys: phy {
+    compatible = "xxx";
+    reg =<...>;
+    .
+    .
+    phys =<&phys 1>;
+    .
+    .
Quoted 8 lines

Documentation/devicetree/bindings/phy/phy-bindings.txt line 76

Quoted 6 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt new file +6 -0
+};
+
+This node represents a controller that uses one of the PHYs which is defined
+previously. Note that the phy handle has an additional specifier "1" to
+differentiate between the three PHYs. For this case, the controller driver
+should use of_phy_get_with_args/devm_of_phy_get_with_args.

This means a PHY user needs to know indexes at the PHY driver ?

The client node's DT has to specify which of the provider's PHYs it references, yes. Presumably the device driver for the client node knows absolutely nothing about this.

Quoted 4 lines

I have been thinking of using this for an IP which has 4 video PHYs: 2 MIPI CSI-2 and 2 MIPI DSI. The IP has just 2 registers, each of which is shared between one MIPI CSI-2 DPHY and one MIPI DSI DPHY. So I thought about creating a single device node for this IP and using 4 indexes for the PHYs, e.g. 0...3.

That sounds right.

Quoted 2 lines

Then users of each PHY type would use only indexes 0..1 (to select their corresponding port).

I don't follow that. If the provider exports PHYs 0..3, then the client nodes would refer to PHYS 0..3 not 0..1.

Quoted 1 line

However I fail to see how this could now be represented in the bindings.

Exactly like the example you gave below, I would expect.

Quoted 7 lines

I assume struct phy::type could be used to differentiate between CSI-2 and DSI. And struct phy::port could be used to select specific CSI-2 or DSI channel (0, 1). Ideally the phy users should not care about index of a PHY at the PHY device tree node. E.g. there are 2 MIPI CSI-2 receivers and each has only one PHY assigned to it. I'm just wondering how the binding should look like, so a PHY could be associated with a receiver automatically by the phy-core, e.g.

Details such as phy::type and phy::port sounds like internal driver implementation details which would have no effect on the bindings.

Quoted 14 lines

/* DPHY IP node */

video-phy {
      reg = <0x10000000 8>;
};

/* MIPI DSI nodes */

dsi_0 {
     phys = <&video-phy 0>;
};
dsi_1 {
     phys = <&video-phy 1>;
};
Quoted 8 lines

/* MIPI CSI-2 nodes */

csi_0 {
     phys = <&video-phy 2>;
};
csi_1 {
     phys = <&video-phy 3>;
};

That looks correct to me.

Quoted 5 lines

I'm not sure if it is not an overkill to use this the PHY framework with a device which has only 2 registers. Perhaps something less heavy could be designed for it. However, if the PHY framework is commonly used there should be no issue wrt enabling the whole big infrastructure for a simple device like this.

I don't think the number of registers should really makes any difference; the whole point of the PHY framework is to decouple to providers and consumers, so doing anything custom for special cases would completely destroy the ability of the PHY framework to do that.

#10 lore raw

Re: [PATCH v4 1/6] drivers: phy: add generic PHY framework

Quoted 22 lines · Stephen Warren
Quoted 12 lines · Sylwester Nawrocki
Quoted 11 lines · Kishon Vijay Abraham I
Documentation/devicetree/bindings/phy/phy-bindings.txt new file +9 -0
 
+example2:
+phys: phy {
+    compatible = "xxx";
+    reg =<...>;
+    .
+    .
+    phys =<&phys 1>;
+    .
+    .
Quoted 8 lines

Documentation/devicetree/bindings/phy/phy-bindings.txt line 76

Quoted 6 lines
Documentation/devicetree/bindings/phy/phy-bindings.txt new file +6 -0
+};
+
+This node represents a controller that uses one of the PHYs which is defined
+previously. Note that the phy handle has an additional specifier "1" to
+differentiate between the three PHYs. For this case, the controller driver
+should use of_phy_get_with_args/devm_of_phy_get_with_args.

This means a PHY user needs to know indexes at the PHY driver ?

Quoted 3 lines

The client node's DT has to specify which of the provider's PHYs it references, yes. Presumably the device driver for the client node knows absolutely nothing about this.

Ah, right. The device driver for the client node not necessarily need to be aware about this. I think I got misled by the 'index' argument of of_phy_get_with_args() which the PHY consumer need to supply. However it is only an index pointing to a PHY specifier in its 'phys' property, hence it would be normally 0 if the client needs only one PHY. Hopefully I got it right this time.

Quoted 5 lines
Quoted 4 lines

I have been thinking of using this for an IP which has 4 video PHYs: 2 MIPI CSI-2 and 2 MIPI DSI. The IP has just 2 registers, each of which is shared between one MIPI CSI-2 DPHY and one MIPI DSI DPHY. So I thought about creating a single device node for this IP and using 4 indexes for the PHYs, e.g. 0...3.

Quoted 7 lines

That sounds right.

Quoted 2 lines

Then users of each PHY type would use only indexes 0..1 (to select their corresponding port).

I don't follow that. If the provider exports PHYs 0..3, then the client nodes would refer to PHYS 0..3 not 0..1.

Indeed, it seems I just wanted to preserve the CSI/DSI "channel" information (0, 1), but that is not really needed anywhere.

Quoted 12 lines
Quoted 1 line

However I fail to see how this could now be represented in the bindings.

Exactly like the example you gave below, I would expect.

Quoted 7 lines

I assume struct phy::type could be used to differentiate between CSI-2 and DSI. And struct phy::port could be used to select specific CSI-2 or DSI channel (0, 1). Ideally the phy users should not care about index of a PHY at the PHY device tree node. E.g. there are 2 MIPI CSI-2 receivers and each has only one PHY assigned to it. I'm just wondering how the binding should look like, so a PHY could be associated with a receiver automatically by the phy-core, e.g.

Quoted 2 lines

Details such as phy::type and phy::port sounds like internal driver implementation details which would have no effect on the bindings.

Yes, I seem to have mixed the phy-core implementation and the bindings a bit.
My intention was to have the PHYs registered with phy::port that would reflect
data channel id, as specified in the SoC's datasheet. However I can't think of
any use of it at the moment, except for debugging purpose.

Quoted 31 lines
Quoted 14 lines

/* DPHY IP node */

video-phy {
       reg =<0x10000000 8>;
};

/* MIPI DSI nodes */

dsi_0 {
      phys =<&video-phy 0>;
};
dsi_1 {
      phys =<&video-phy 1>;
};
Quoted 8 lines

/* MIPI CSI-2 nodes */

csi_0 {
      phys =<&video-phy 2>;
};
csi_1 {
      phys =<&video-phy 3>;
};

That looks correct to me.

Quoted 5 lines

I'm not sure if it is not an overkill to use this the PHY framework with a device which has only 2 registers. Perhaps something less heavy could be designed for it. However, if the PHY framework is commonly used there should be no issue wrt enabling the whole big infrastructure for a simple device like this.

Quoted 4 lines

I don't think the number of registers should really makes any difference; the whole point of the PHY framework is to decouple to providers and consumers, so doing anything custom for special cases would completely destroy the ability of the PHY framework to do that.

Ok, that's a very good argument. Something I have not been focused on that much, given the architecture of hardware I used to work with.

I'll git it a try and I'll see if any any further questions jump out.

#11 lore raw

PATCH v4 2/6 usb: phy: omap-usb2: use the new generic PHY framework

In reply to Kishon Vijay Abraham I

Used the generic PHY framework API to create the PHY. omap_usb2_suspend is split into omap_usb_suspend and omap_usb_resume in order to align with the new framework.

However using the old USB PHY library cannot be completely removed because OTG is intertwined with PHY and moving to the new framework will break OTG. Once we have a separate OTG state machine, we can get rid of the USB PHY library.

---
 drivers/usb/phy/omap-usb2.c |   47 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
drivers/usb/phy/omap-usb2.c +47 -0
index 844ab68..819ba71 100644
@@ -28,6 +28,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/delay.h>
 #include <linux/usb/omap_control_usb.h>
+#include <linux/phy/phy.h>
 
 /**
  * omap_usb2_set_comparator - links the comparator present in the sytem with
@@ -119,9 +120,48 @@ static int omap_usb2_suspend(struct usb_phy *x, int suspend)
 	return 0;
 }
 
+static int omap_usb_suspend(struct phy *x)
+{
+	struct omap_usb *phy = dev_get_drvdata(&x->dev);
+
+	if (!phy->is_suspended) {
+		omap_control_usb_phy_power(phy->control_dev, 0);
+		pm_runtime_put_sync(phy->dev);
+		phy->is_suspended = 1;
+	}
+
+	return 0;
+}
+
+static int omap_usb_resume(struct phy *x)
+{
+	u32 ret;
+	struct omap_usb *phy = dev_get_drvdata(&x->dev);
+
+	if (phy->is_suspended) {
+		ret = pm_runtime_get_sync(phy->dev);
+		if (ret < 0) {
+			dev_err(phy->dev, "get_sync failed with err %d\n",
+									ret);
+			return ret;
+		}
+		omap_control_usb_phy_power(phy->control_dev, 1);
+		phy->is_suspended = 0;
+	}
+
+	return 0;
+}
+
+static struct phy_ops ops = {
+	.suspend	= omap_usb_suspend,
+	.resume		= omap_usb_resume,
+	.owner		= THIS_MODULE,
+};
+
 static int omap_usb2_probe(struct platform_device *pdev)
 {
 	struct omap_usb			*phy;
+	struct phy			*generic_phy;
 	struct usb_otg			*otg;
 
 	phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
@@ -144,6 +184,13 @@ static int omap_usb2_probe(struct platform_device *pdev)
 	phy->phy.otg		= otg;
 	phy->phy.type		= USB_PHY_TYPE_USB2;
 
+	generic_phy = devm_phy_create(phy->dev, "omap-usb2", pdev->dev.of_node,
+		USB_PHY_TYPE_USB2, &ops, phy);
+	if (IS_ERR(generic_phy)) {
+		dev_dbg(&pdev->dev, "Failed to create PHY\n");
+		return PTR_ERR(generic_phy);
+	}
+
 	phy->control_dev = omap_get_control_dev();
 	if (IS_ERR(phy->control_dev)) {
 		dev_dbg(&pdev->dev, "Failed to get control device\n");
Signature · 1 line
1.7.10.4
#12 lore raw

PATCH v4 3/6 usb: otg: twl4030: use the new generic PHY framework

In reply to Kishon Vijay Abraham I

Used the generic PHY framework API to create the PHY. twl4030_usb_suspend and twl4030_usb_resume is added to phy_ops in order to align with the new framework.

However using the old USB PHY library cannot be completely removed because OTG is intertwined with PHY and moving to the new framework completely will break OTG. Once we have a separate OTG state machine, we can get rid of the USB PHY library.

---
 drivers/usb/otg/twl4030-usb.c |   36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/usb/otg/twl4030-usb.c +36 -0
index a994715..aebcd6a 100644
@@ -33,6 +33,7 @@
 #include <linux/io.h>
 #include <linux/delay.h>
 #include <linux/usb/otg.h>
+#include <linux/phy/phy.h>
 #include <linux/usb/musb-omap.h>
 #include <linux/usb/ulpi.h>
 #include <linux/i2c/twl.h>
@@ -575,10 +576,38 @@ static int twl4030_set_host(struct usb_otg *otg, struct usb_bus *host)
 	return 0;
 }
 
+static int twl4030_usb_suspend(struct phy *phy)
+{
+	struct twl4030_usb *twl = dev_get_drvdata(&phy->dev);
+
+	twl4030_phy_suspend(twl, 1);
+
+	return 0;
+}
+
+static int twl4030_usb_resume(struct phy *phy)
+{
+	struct twl4030_usb *twl = dev_get_drvdata(&phy->dev);
+
+	if (!twl->asleep)
+		return -EBUSY;
+	__twl4030_phy_resume(twl);
+	twl->asleep = 0;
+
+	return 0;
+}
+
+static struct phy_ops ops = {
+	.suspend	= twl4030_usb_suspend,
+	.resume		= twl4030_usb_resume,
+	.owner		= THIS_MODULE,
+};
+
 static int twl4030_usb_probe(struct platform_device *pdev)
 {
 	struct twl4030_usb_data *pdata = pdev->dev.platform_data;
 	struct twl4030_usb	*twl;
+	struct phy		*phy;
 	int			status, err;
 	struct usb_otg		*otg;
 	struct device_node	*np = pdev->dev.of_node;
@@ -617,6 +646,13 @@ static int twl4030_usb_probe(struct platform_device *pdev)
 	otg->set_host		= twl4030_set_host;
 	otg->set_peripheral	= twl4030_set_peripheral;
 
+	phy = devm_phy_create(twl->dev, "twl4030", pdev->dev.of_node,
+		USB_PHY_TYPE_USB2, &ops, twl);
+	if (IS_ERR(phy)) {
+		dev_dbg(&pdev->dev, "Failed to create PHY\n");
+		return PTR_ERR(phy);
+	}
+
 	/* init spinlock for workqueue */
 	spin_lock_init(&twl->lock);
 
Signature · 1 line
1.7.10.4
#13 lore raw

PATCH v4 4/6 ARM: OMAP: USB: Add phy binding information

In reply to Kishon Vijay Abraham I

In order for controllers to get PHY in case of non dt boot, the phy binding information should be added in the platform specific initialization code using phy_bind.

---
 arch/arm/mach-omap2/usb-musb.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/usb-musb.c +6 -1
index 3242a55..f01bc42 100644
@@ -24,6 +24,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/io.h>
 #include <linux/usb/musb.h>
+#include <linux/phy/phy.h>
 
 #include "omap_device.h"
 #include "soc.h"
@@ -85,8 +86,12 @@ void __init usb_musb_init(struct omap_musb_board_data *musb_board_data)
 	musb_plat.mode = board_data->mode;
 	musb_plat.extvbus = board_data->extvbus;
 
-	if (cpu_is_omap44xx())
+	if (cpu_is_omap44xx()) {
 		musb_plat.has_mailbox = true;
+		phy_bind("musb-hdrc.0.auto", 0, "omap-usb2.1.auto");
+	} else if (cpu_is_omap34xx()) {
+		phy_bind("musb-hdrc.0.auto", 0, "twl4030_usb");
+	}
 
 	if (soc_is_am35xx()) {
 		oh_name = "am35x_otg_hs";
Signature · 1 line
1.7.10.4
#14 lore raw

PATCH v4 5/6 ARM: dts: omap: update usb_otg_hs data

In reply to Kishon Vijay Abraham I

Updated the usb_otg_hs dt data to include the *phy* and *phy-names* binding in order for the driver to use the new generic PHY framework. Also updated the Documentation to include the binding information. The PHY binding information can be found at Documentation/devicetree/bindings/phy/phy-bindings.txt

---
 Documentation/devicetree/bindings/usb/omap-usb.txt |    5 +++++
 arch/arm/boot/dts/omap3.dtsi                       |    2 ++
 arch/arm/boot/dts/omap4.dtsi                       |    2 ++
 3 files changed, 9 insertions(+)
Documentation/devicetree/bindings/usb/omap-usb.txt +5 -0
index abce256..9324e79 100644
@@ -19,6 +19,9 @@ OMAP MUSB GLUE
  - power : Should be "50". This signifies the controller can supply upto
    100mA when operating in host mode.
  - usb-phy : the phandle for the PHY device
+ - phys : the phandle for the PHY device (used by generic PHY framework)
+ - phy-names : the names of the PHY corresponding to the PHYs present in the
+   *phy* phandle.
 
 Optional properties:
  - ctrl-module : phandle of the control module this glue uses to write to
@@ -33,6 +36,8 @@ usb_otg_hs: usb_otg_hs at 4a0ab000 {
 	num_eps = <16>;
 	ram_bits = <12>;
 	ctrl-module = <&omap_control_usb>;
+	phys = <&usb2_phy>;
+	phy-names = "usb2-phy";
 };
 
 Board specific device node entry
arch/arm/boot/dts/omap3.dtsi +2 -0
index 1e21565..dd7d2ff 100644
@@ -405,6 +405,8 @@
 			interrupt-names = "mc", "dma";
 			ti,hwmods = "usb_otg_hs";
 			usb-phy = <&usb2_phy>;
+			phys = <&usb2_phy>;
+			phy-names = "usb2-phy";
 			multipoint = <1>;
 			num-eps = <16>;
 			ram-bits = <12>;
arch/arm/boot/dts/omap4.dtsi +2 -0
index 06d044e..b673f0f 100644
@@ -550,6 +550,8 @@
 			interrupt-names = "mc", "dma";
 			ti,hwmods = "usb_otg_hs";
 			usb-phy = <&usb2_phy>;
+			phys = <&usb2_phy>;
+			phy-names = "usb2-phy";
 			multipoint = <1>;
 			num-eps = <16>;
 			ram-bits = <12>;
Signature · 1 line
1.7.10.4
#15 lore raw

PATCH v4 6/6 usb: musb: omap2430: use the new generic PHY framework

In reply to Kishon Vijay Abraham I

Use the generic PHY framework API to get the PHY. The usb_phy_set_suspend and usb_phy_set_resume is replaced with phy_suspend and phy_resume to align with the new PHY framework.

musb->xceiv can't be removed as of now because musb core uses xceiv.state and xceiv.otg. Once there is a separate state machine to handle otg, these can be moved out of xceiv and then we can start using the generic PHY framework.

---
 drivers/usb/musb/musb_core.h |    2 ++
 drivers/usb/musb/omap2430.c  |   22 ++++++++++++++++------
 2 files changed, 18 insertions(+), 6 deletions(-)
drivers/usb/musb/musb_core.h +2 -0
index 7fb4819..78251fd 100644
@@ -46,6 +46,7 @@
 #include <linux/usb.h>
 #include <linux/usb/otg.h>
 #include <linux/usb/musb.h>
+#include <linux/phy/phy.h>
 
 struct musb;
 struct musb_hw_ep;
@@ -357,6 +358,7 @@ struct musb {
 	u16			int_tx;
 
 	struct usb_phy		*xceiv;
+	struct phy		*phy;
 
 	int nIrq;
 	unsigned		irq_wake:1;
drivers/usb/musb/omap2430.c +16 -6
index 1a42a45..55f071d 100644
@@ -349,14 +349,24 @@ static int omap2430_musb_init(struct musb *musb)
 	 * up through ULPI.  TWL4030-family PMICs include one,
 	 * which needs a driver, drivers aren't always needed.
 	 */
-	if (dev->parent->of_node)
+	if (dev->parent->of_node) {
+		musb->phy = devm_of_phy_get_byname(dev->parent, "usb2-phy");
+
+		/* We can't totally remove musb->xceiv as of now because
+		 * musb core uses xceiv.state and xceiv.otg. Once we have
+		 * a separate state machine to handle otg, these can be moved
+		 * out of xceiv and then we can start using the generic PHY
+		 * framework
+		 */
 		musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent,
 		    "usb-phy", 0);
-	else
+	} else {
 		musb->xceiv = devm_usb_get_phy_dev(dev, 0);
+		musb->phy = devm_phy_get(dev, 0);
+	}
 
-	if (IS_ERR_OR_NULL(musb->xceiv)) {
-		pr_err("HS USB OTG: no transceiver configured\n");
+	if (IS_ERR_OR_NULL(musb->xceiv) || IS_ERR_OR_NULL(musb->phy)) {
+		dev_err(dev, "no transceiver configured\n");
 		return -EPROBE_DEFER;
 	}
 
@@ -612,7 +622,7 @@ static int omap2430_runtime_suspend(struct device *dev)
 				OTG_INTERFSEL);
 
 		omap2430_low_level_exit(musb);
-		usb_phy_set_suspend(musb->xceiv, 1);
+		phy_suspend(musb->phy);
 	}
 
 	return 0;
@@ -628,7 +638,7 @@ static int omap2430_runtime_resume(struct device *dev)
 		musb_writel(musb->mregs, OTG_INTERFSEL,
 				musb->context.otg_interfsel);
 
-		usb_phy_set_suspend(musb->xceiv, 0);
+		phy_resume(musb->phy);
 	}
 
 	return 0;
Signature · 1 line
1.7.10.4
#17 lore raw

Hi,

Quoted 3 lines · David Miller

You really need to CC: netdev at vger.kernel.org rather than me explicitly on this patch set.

I was CC'ing whatever get_maintainer shows. I'll make sure to CC netdev at vger.kernel.org though there's nothing related to network in this patch series (Maybe sometime in the future it'll be used).

Thanks
Kishon

#18 lore raw

From: Kishon Vijay Abraham I <[email protected]>
Date: Wed, 3 Apr 2013 11:29:53 +0530

Quoted 11 lines

Hi,

Quoted 4 lines · David Miller

You really need to CC: netdev at vger.kernel.org rather than me explicitly
on this patch set.

I was CC'ing whatever get_maintainer shows. I'll make sure to CC netdev at vger.kernel.org though there's nothing related to network in this patch series (Maybe sometime in the future it'll be used).

What about drivers/net/phy isn't networking?

#19 lore raw

Hi,

Quoted 11 lines · David Miller

From: Kishon Vijay Abraham I <[email protected]>
Date: Wed, 3 Apr 2013 11:29:53 +0530

Quoted 8 lines

Hi,

Quoted 4 lines · David Miller

You really need to CC: netdev at vger.kernel.org rather than me explicitly
on this patch set.

Quoted 5 lines
Quoted 3 lines

I was CC'ing whatever get_maintainer shows. I'll make sure to CC netdev at vger.kernel.org though there's nothing related to network in this patch series (Maybe sometime in the future it'll be used).

What about drivers/net/phy isn't networking?

This patch series is about drivers/phy which will be used for now by usb, sata and maybe some video PHY's. Network itself has a comprehensive PHY in drivers/net/phy which we'd like to merge it with drivers/phy so that we have all the phy stuff in drivers/phy but we are not planning too far ahead here.

Thanks
Kishon

#20 lore raw

From: Kishon Vijay Abraham I <[email protected]>
Date: Wed, 3 Apr 2013 12:05:30 +0530

Quoted 5 lines

This patch series is about drivers/phy which will be used for now by usb, sata and maybe some video PHY's. Network itself has a comprehensive PHY in drivers/net/phy which we'd like to merge it with drivers/phy so that we have all the phy stuff in drivers/phy but we are not planning too far ahead here.

Ok, that makes sense, thanks.