Skip to contentSkip to conversation

Generic PHY Framework

PATCH Superseded Kishon Vijay Abraham I 4 participants 39 messages Jun 13, 2013 – Jun 24, 2013

Subsystems (9)

v7 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v7 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.

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.

If the PHY driver has to send notification on connect/disconnect, the PHY driver should make use of the extcon framework. Using this susbsystem to use extcon framwork will have to be analysed.

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

This patch series is developed on linux mainline tree.

Changes from v6
* corrected few typos in Documentation
* Changed PHY Subsystem to *bool* in Kconfig (to avoid compilation errors when PHY Subsystem is kept as module and the dependent modules are built-in)
* Added if pm_runtime_enabled check before runtime pm calls.

Changes from v5:
* removed the new sysfs entries as it dint have any new information other than what is already there in /sys/devices/...
* removed a bunch of APIs added to get the PHY and now only phy_get and devm_phy_get are used.
* Added new APIs to register/unregister the PHY provider. This is needed for dt boot case.
* Enabled pm runtime and incorporated the comments given by Alan Stern in a different patch series by Gautam.
* Removed the *phy_bind* API. Now the phy binding information should be passed using the platform data to the controller devices.
* Fixed a few typos.

Changes from v4:
* removed of_phy_get_with_args/devm_of_phy_get_with_args. Now the *phy providers* should use their custom implementation of of_xlate or use of_phy_xlate to get *phy instance* from *phy providers*.
* Added of_phy_xlate to be used by *phy providers* if it provides only one PHY.
* changed phy_core from having subsys_initcall to module_init.
* other minor fixes.

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 (9):
drivers: phy: add generic PHY framework
usb: phy: omap-usb2: use the new generic PHY framework
usb: phy: twl4030: use the new generic PHY framework
usb: phy: twl4030: twl4030 shouldn't be subsys_initcall
ARM: OMAP: USB: Add phy binding information
ARM: dts: omap: update usb_otg_hs data
usb: musb: omap2430: use the new generic PHY framework
usb: phy: omap-usb2: remove *set_suspend* callback from omap-usb2
usb: phy: twl4030-usb: remove *set_suspend* and *phy_init* ops

 .../devicetree/bindings/phy/phy-bindings.txt       |   66 +++
 Documentation/devicetree/bindings/usb/omap-usb.txt |    5 +
 Documentation/devicetree/bindings/usb/usb-phy.txt  |    6 +
 Documentation/phy.txt                              |  124 +++++
 MAINTAINERS                                        |    7 +
 arch/arm/boot/dts/omap3-beagle-xm.dts              |    2 +
 arch/arm/boot/dts/omap3-evm.dts                    |    2 +
 arch/arm/boot/dts/omap3-overo.dtsi                 |    2 +
 arch/arm/boot/dts/omap4.dtsi                       |    3 +
 arch/arm/boot/dts/twl4030.dtsi                     |    1 +
 arch/arm/mach-omap2/usb-musb.c                     |    6 +-
 drivers/Kconfig                                    |    2 +
 drivers/Makefile                                   |    2 +
 drivers/phy/Kconfig                                |   13 +
 drivers/phy/Makefile                               |    5 +
 drivers/phy/phy-core.c                             |  543 ++++++++++++++++++++
 drivers/usb/musb/musb_core.c                       |    1 +
 drivers/usb/musb/musb_core.h                       |    3 +
 drivers/usb/musb/omap2430.c                        |   29 +-
 drivers/usb/phy/phy-omap-usb2.c                    |   54 +-
 drivers/usb/phy/phy-twl4030-usb.c                  |   73 +--
 include/linux/phy/phy.h                            |  284 ++++++++++
 include/linux/usb/musb.h                           |    3 +
 23 files changed, 1172 insertions(+), 64 deletions(-)
 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 v7 1/9 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. For dt-boot, the PHY drivers should also register *PHY provider* with the framework.

PHY drivers should create the PHY by passing id and ops like init, exit, power_on and power_off. This framework is also pm runtime enabled.

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

---
 .../devicetree/bindings/phy/phy-bindings.txt       |   66 +++
 Documentation/phy.txt                              |  124 +++++
 MAINTAINERS                                        |    7 +
 drivers/Kconfig                                    |    2 +
 drivers/Makefile                                   |    2 +
 drivers/phy/Kconfig                                |   13 +
 drivers/phy/Makefile                               |    5 +
 drivers/phy/phy-core.c                             |  543 ++++++++++++++++++++
 include/linux/phy/phy.h                            |  284 ++++++++++
 9 files changed, 1046 insertions(+)
 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/devicetree/bindings/phy/phy-bindings.txt new file +66 -0
new file mode 100644
index 0000000..8ae844f
@@ -0,0 +1,66 @@
+This document explains only the device tree data binding. For general
+information about PHY subsystem refer to Documentation/phy.txt
+
+PHY device node
+===============
+
+Required 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. The PHY
+		provider can use the values in cells to find the appropriate
+		PHY.
+
+For example:
+
+phys: phy {
+    compatible = "xxx";
+    reg = <...>;
+    .
+    .
+    #phy-cells = <1>;
+    .
+    .
+};
+
+That node describes an IP block (PHY provider) that implements 2 different PHYs.
+In order to differentiate between these 2 PHYs, an additonal specifier should be
+given while trying to get a reference to it.
+
+PHY user node
+=============
+
+Required Properties:
+phys : the phandle for the PHY device (used by the PHY subsystem)
+phy-names : the names of the PHY corresponding to the PHYs present in the
+	    *phys* phandle
+
+Example 1:
+usb1: usb_otg_ss at xxx {
+    compatible = "xxx";
+    reg = <xxx>;
+    .
+    .
+    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.
+
+Example 2:
+usb2: usb_otg_ss at xxx {
+    compatible = "xxx";
+    reg = <xxx>;
+    .
+    .
+    phys = <&phys 1>;
+    phy-names = "usbphy";
+    .
+    .
+};
+
+This node represents a controller that uses one of the PHYs of the PHY provider
+device defined previously. Note that the phy handle has an additional specifier
+"1" to differentiate between the two PHYs.
Documentation/phy.txt new file +124 -0

124 lines not on this page · raw message

MAINTAINERS +7 -0
index 0c9dc71..c234461 100644
@@ -3536,6 +3536,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 9953a42..2943fb6 100644
@@ -166,4 +166,6 @@ source "drivers/ipack/Kconfig"
 
 source "drivers/reset/Kconfig"
 
+source "drivers/phy/Kconfig"
+
 endmenu
drivers/Makefile +2 -0
index 130abc1..ce9f0d2 100644
@@ -8,6 +8,8 @@
 obj-y				+= irqchip/
 obj-y				+= bus/
 
+obj-y				+= phy/
+
 # GPIO must come after pinctrl as gpios may need to mux pins etc
 obj-y				+= pinctrl/
 obj-y				+= gpio/
drivers/phy/Kconfig new file +13 -0
new file mode 100644
index 0000000..0764a54
@@ -0,0 +1,13 @@
+#
+# PHY
+#
+
+menuconfig GENERIC_PHY
+	bool "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 +543 -0

543 lines not on this page · raw message

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

284 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH v7 1/9] drivers: phy: add generic PHY framework

Hi,

Documentation/phy.txt line 38

Quoted 3 lines · Kishon Vijay Abraham I
Documentation/phy.txt new file +3 -0
+struct phy_provider *of_phy_provider_register(struct device *dev,
+	struct module *owner, struct phy * (*of_xlate)(struct device *dev,
+	struct of_phandle_args *args))

I would rename this to __of_phy_provider_register() and in a header have:

#define of_phy_provider_register(dev, xlate)	\
	__of_phy_provider_register((dev), THIS_MODULE, (xlate))

then your users don't need to remember always passing THIS_MODULE argument.

Documentation/phy.txt line 38

Quoted 3 lines
Documentation/phy.txt new file +3 -0
+struct phy_provider *devm_of_phy_provider_register(struct device *dev,
+	struct module *owner, struct phy * (*of_xlate)(struct device *dev,
+	struct of_phandle_args *args))

likewise.

drivers/phy/phy-core.c line 515

Quoted 12 lines
drivers/phy/phy-core.c new file +12 -0
+/**
+ * phy_release() - release the phy
+ * @dev: the dev member within phy
+ *
+ * When the last reference to the device is removed, it is called
+ * from the embedded kobject as release method.
+ */
+static void phy_release(struct device *dev)
+{
+	struct phy *phy;
+
+	phy = container_of(dev, struct phy, dev);

I would have a:

#define to_phy(dev) (container_of((dev), struct phy dev))

somewhere in a header, just for the sake of brevity :-p

drivers/phy/phy-core.c line 516

Quoted 1 line
drivers/phy/phy-core.c new file +1 -0
+	dev_dbg(dev, "releasing '%s'\n", dev_name(dev));

make it dev_vdbg() instead.

Quoted 5 lines
include/linux/phy/phy.h new file +0 -0
new file mode 100644
index 0000000..df0c98a

[ ... ]

Quoted 4 lines
include/linux/phy/phy.h new file +4 -0
+static inline int phy_init(struct phy *phy)
+{
+	int ret = -ENOTSUPP;
+

include/linux/phy/phy.h line 178

Quoted 10 lines
include/linux/phy/phy.h new file +10 -0
+	if (!pm_runtime_enabled(&phy->dev))
+		goto no_pm_runtime;
+
+	ret = pm_runtime_get_sync(&phy->dev);
+	if (ret < 0) {
+		dev_err(&phy->dev, "get sync failed: %d\n", ret);
+		return ret;
+	}
+
+no_pm_runtime:

you can avoid this goto if you code as below, note that I'm also solving a possible unbalanced PM runtime call which would prevent actual *runtime* suspend of the PHY:

	ret = phy_pm_runtime_get_sync(phy);
	if (ret < 0 && ret != -ENOTSUPP)
		return ret;

	if (phy->ops->init) {
		ret = phy->ops->init(phy);
		if (ret < 0) {
			dev_err(&phy->dev, "failed to initialize --> %d\n", ret);
			goto out;
		}
	}

out:

	/*
	 * In order to avoid unbalanced PM runtime calls, let's make
	 * sure to disable what we might have enabled when entering this
	 * function.
	 */
	 phy_pm_runtime_put(phy);

	return ret;

include/linux/phy/phy.h line 195

Quoted 13 lines
include/linux/phy/phy.h new file +13 -0
+}
+
+static inline int phy_exit(struct phy *phy)
+{
+	int ret = -ENOTSUPP;
+
+	if (phy->ops->exit)
+		ret = phy->ops->exit(phy);
+
+	if (!pm_runtime_enabled(&phy->dev))
+		goto no_pm_runtime;
+
+	ret = pm_runtime_put_sync(&phy->dev);

move your pm runtime wrappers before these calls and you can use them.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130618/79f608c3/attachment.sig>
#3 lore raw

Re: [PATCH v7 1/9] drivers: phy: add generic PHY framework

In reply to Kishon Vijay Abraham I

Hi Kishon,

I've noticed there is a little inconsistency between the code and documentation.

Documentation/phy.txt line 60

Quoted 9 lines · Kishon Vijay Abraham I

+3. Creating the PHY

Documentation/phy.txt new file +8 -0
+
+The PHY driver should create the PHY in order for other peripheral controllers
+to make use of it. The PHY framework provides 2 APIs to create the PHY.
+
+struct phy *phy_create(struct device *dev, int id, const struct phy_ops *ops,
+	void *priv);
+struct phy *devm_phy_create(struct device *dev, int id,
+	const struct phy_ops *ops, void *priv);

The 'label' argument is missing in those function prototypes. It seems the labels must be unique, I guess this needs to be documented. And do we allow NULL labels ? If so, then there is probably a check for NULL label needed in phy_lookup() and if not, then phy_create() should fail when NULL label is passed ?

Quoted 54 lines
(quoted diff) +53 -0
+The PHY drivers can use one of the above 2 APIs to create the PHY by passing
+the device pointer, id, phy ops and a driver data.
+phy_ops is a set of function pointers for performing PHY operations such as
+init, exit, power_on and power_off.
 
+/**
+ * phy_create() - create a new phy
+ * @dev: device that is creating the new phy
+ * @id: id of the phy
+ * @ops: function pointers for performing phy operations
+ * @label: label given to the phy
+ * @priv: private data from phy driver
+ *
+ * Called to create a phy using phy framework.
+ */
+struct phy *phy_create(struct device *dev, u8 id, const struct phy_ops *ops,
+	const char *label, void *priv)
+{
+	int ret;
+	struct phy *phy;
+
+	if (!dev) {
+		dev_WARN(dev, "no device provided for PHY\n");
+		ret = -EINVAL;
+		goto err0;
+	}
+
+	phy = kzalloc(sizeof(*phy), GFP_KERNEL);
+	if (!phy) {
+		ret = -ENOMEM;
+		goto err0;
+	}
+
+	device_initialize(&phy->dev);
+
+	phy->dev.class = phy_class;
+	phy->dev.parent = dev;
+	phy->dev.of_node = dev->of_node;
+	phy->id = id;
+	phy->ops = ops;
+	phy->label = label;
+
+	dev_set_drvdata(&phy->dev, priv);
+
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);
+	if (ret)
+		goto err1;
+
+	ret = device_add(&phy->dev);
+	if (ret)
+		goto err1;
+
+	if (pm_runtime_enabled(dev))
+		pm_runtime_enable(&phy->dev);

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+	return phy;
+
+err1:
+	put_device(&phy->dev);
+	kfree(phy);
+
+err0:
+	return ERR_PTR(ret);
+}

Thanks,
Sylwester

#4 lore raw

Re: [PATCH v7 1/9] drivers: phy: add generic PHY framework

Quoted 5 lines · Sylwester Nawrocki

Hi Kishon,

I've noticed there is a little inconsistency between the code and documentation.

On 06/13/2013 10:43 AM, Kishon Vijay Abraham I wrote:

Quoted 15 lines

Documentation/phy.txt line 60

Quoted 9 lines

+3. Creating the PHY

Documentation/phy.txt new file +8 -0
+
+The PHY driver should create the PHY in order for other peripheral controllers
+to make use of it. The PHY framework provides 2 APIs to create the PHY.
+
+struct phy *phy_create(struct device *dev, int id, const struct phy_ops *ops,
+    void *priv);
+struct phy *devm_phy_create(struct device *dev, int id,
+    const struct phy_ops *ops, void *priv);

The 'label' argument is missing in those function prototypes. It seems the labels must be unique, I guess this needs to be documented. And do we allow NULL labels ? If so, then there is probably a check for NULL label needed in phy_lookup() and if not, then phy_create() should fail when NULL label is passed ?

Yeah. Label is used only for non-dt case so NULL should be allowed while phy_create().

Thanks
Kishon

#5 lore raw

Re: [PATCH v7 1/9] drivers: phy: add generic PHY framework

In reply to Kishon Vijay Abraham I

Hi,

Quoted 26 lines · Kishon Vijay Abraham I
drivers/phy/phy-core.c new file +26 -0
+/**
+ * phy_create() - create a new phy
+ * @dev: device that is creating the new phy
+ * @id: id of the phy
+ * @ops: function pointers for performing phy operations
+ * @label: label given to the phy
+ * @priv: private data from phy driver
+ *
+ * Called to create a phy using phy framework.
+ */
+struct phy *phy_create(struct device *dev, u8 id, const struct phy_ops *ops,
+	const char *label, void *priv)
+{
+	int ret;
+	struct phy *phy;
+
+	if (!dev) {
+		dev_WARN(dev, "no device provided for PHY\n");
+		ret = -EINVAL;
+		goto err0;
+	}
+
+	phy = kzalloc(sizeof(*phy), GFP_KERNEL);
+	if (!phy) {
+		ret = -ENOMEM;
+		goto err0;

drivers/phy/phy-core.c line 312

Quoted 10 lines
drivers/phy/phy-core.c new file +10 -0
+	}
+
+	device_initialize(&phy->dev);
+
+	phy->dev.class = phy_class;
+	phy->dev.parent = dev;
+	phy->dev.of_node = dev->of_node;
+	phy->id = id;
+	phy->ops = ops;
+	phy->label = label;

Perhaps we could make it:

	phy->label = kstrdup(label, GFP_KERNEL);

and free the label in phy_destroy() ?

That way the users would't need to keep the label around. It might be useful when PHY provider generates the labels dynamically. I guess it is OK for PHY providers to hard code the labels and having the PHY user drivers passed labels in platform data ?

Quoted 24 lines
drivers/phy/phy-core.c new file +23 -0
+	dev_set_drvdata(&phy->dev, priv);
+
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);
+	if (ret)
+		goto err1;
+
+	ret = device_add(&phy->dev);
+	if (ret)
+		goto err1;
+
+	if (pm_runtime_enabled(dev))
+		pm_runtime_enable(&phy->dev);
+
+	return phy;
+
+err1:
+	put_device(&phy->dev);
+	kfree(phy);
+
+err0:
+	return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(phy_create);
 

drivers/phy/phy-core.c line 381

Quoted 10 lines
drivers/phy/phy-core.c new file +10 -0
+/**
+ * phy_destroy() - destroy the phy
+ * @phy: the phy to be destroyed
+ *
+ * Called to destroy the phy.
+ */
+void phy_destroy(struct phy *phy)
+{
+	pm_runtime_disable(&phy->dev);
+	device_unregister(&phy->dev);

Isn't kfree(phy); missing here ?

Review

Quoted 2 lines
(quoted diff) +2 -0
+}
+EXPORT_SYMBOL_GPL(phy_destroy);

Thanks,
Sylwester

#6 lore raw

Re: [PATCH v7 1/9] drivers: phy: add generic PHY framework

Hi,

Quoted 42 lines · Sylwester Nawrocki

Hi,

Quoted 26 lines · Kishon Vijay Abraham I
drivers/phy/phy-core.c new file +26 -0
+/**
+ * phy_create() - create a new phy
+ * @dev: device that is creating the new phy
+ * @id: id of the phy
+ * @ops: function pointers for performing phy operations
+ * @label: label given to the phy
+ * @priv: private data from phy driver
+ *
+ * Called to create a phy using phy framework.
+ */
+struct phy *phy_create(struct device *dev, u8 id, const struct phy_ops *ops,
+	const char *label, void *priv)
+{
+	int ret;
+	struct phy *phy;
+
+	if (!dev) {
+		dev_WARN(dev, "no device provided for PHY\n");
+		ret = -EINVAL;
+		goto err0;
+	}
+
+	phy = kzalloc(sizeof(*phy), GFP_KERNEL);
+	if (!phy) {
+		ret = -ENOMEM;
+		goto err0;

drivers/phy/phy-core.c line 312

Quoted 10 lines
drivers/phy/phy-core.c new file +10 -0
+	}
+
+	device_initialize(&phy->dev);
+
+	phy->dev.class = phy_class;
+	phy->dev.parent = dev;
+	phy->dev.of_node = dev->of_node;
+	phy->id = id;
+	phy->ops = ops;
+	phy->label = label;

Perhaps we could make it:

Quoted 3 lines
	phy->label = kstrdup(label, GFP_KERNEL);

and free the label in phy_destroy() ?

yeah.. Fixed.

Quoted 5 lines

That way the users would't need to keep the label around. It might be useful when PHY provider generates the labels dynamically. I guess it is OK for PHY providers to hard code the labels and having the PHY user drivers passed labels in platform data ?

yeah. But the only concern here is there is no way to enforce the labels are passed in platform data. The PHY user driver can also hard code the labels while getting the reference to the PHY and we can catch such cases only by review.

Quoted 25 lines
Quoted 24 lines
drivers/phy/phy-core.c new file +23 -0
+	dev_set_drvdata(&phy->dev, priv);
+
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);
+	if (ret)
+		goto err1;
+
+	ret = device_add(&phy->dev);
+	if (ret)
+		goto err1;
+
+	if (pm_runtime_enabled(dev))
+		pm_runtime_enable(&phy->dev);
+
+	return phy;
+
+err1:
+	put_device(&phy->dev);
+	kfree(phy);
+
+err0:
+	return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(phy_create);
Quoted 12 lines

drivers/phy/phy-core.c line 381

Quoted 10 lines
drivers/phy/phy-core.c new file +10 -0
+/**
+ * phy_destroy() - destroy the phy
+ * @phy: the phy to be destroyed
+ *
+ * Called to destroy the phy.
+ */
+void phy_destroy(struct phy *phy)
+{
+	pm_runtime_disable(&phy->dev);
+	device_unregister(&phy->dev);

Isn't kfree(phy); missing here ?

Not actually. Its done in phy_release (class's dev_release method)

Thanks
Kishon

#7 lore raw

PATCH v7 2/9 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. Now the power off and power on are done in omap_usb_power_off and omap_usb_power_on respectively.

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/phy-omap-usb2.c |   40 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)
drivers/usb/phy/phy-omap-usb2.c +38 -2
index 844ab68..3c275e7 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,10 +120,36 @@ static int omap_usb2_suspend(struct usb_phy *x, int suspend)
 	return 0;
 }
 
+static int omap_usb_power_off(struct phy *x)
+{
+	struct omap_usb *phy = dev_get_drvdata(&x->dev);
+
+	omap_control_usb_phy_power(phy->control_dev, 0);
+
+	return 0;
+}
+
+static int omap_usb_power_on(struct phy *x)
+{
+	struct omap_usb *phy = dev_get_drvdata(&x->dev);
+
+	omap_control_usb_phy_power(phy->control_dev, 1);
+
+	return 0;
+}
+
+static struct phy_ops ops = {
+	.power_on	= omap_usb_power_on,
+	.power_off	= omap_usb_power_off,
+	.owner		= THIS_MODULE,
+};
+
 static int omap_usb2_probe(struct platform_device *pdev)
 {
 	struct omap_usb			*phy;
+	struct phy			*generic_phy;
 	struct usb_otg			*otg;
+	struct phy_provider		*phy_provider;
 
 	phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
 	if (!phy) {
@@ -144,6 +171,11 @@ static int omap_usb2_probe(struct platform_device *pdev)
 	phy->phy.otg		= otg;
 	phy->phy.type		= USB_PHY_TYPE_USB2;
 
+	phy_provider = devm_of_phy_provider_register(phy->dev, THIS_MODULE,
+		of_phy_simple_xlate);
+	if (IS_ERR(phy_provider))
+		return PTR_ERR(phy_provider);
+
 	phy->control_dev = omap_get_control_dev();
 	if (IS_ERR(phy->control_dev)) {
 		dev_dbg(&pdev->dev, "Failed to get control device\n");
@@ -159,6 +191,12 @@ static int omap_usb2_probe(struct platform_device *pdev)
 	otg->start_srp		= omap_usb_start_srp;
 	otg->phy		= &phy->phy;
 
+	pm_runtime_enable(phy->dev);
+
+	generic_phy = devm_phy_create(phy->dev, 0, &ops, "omap-usb2", phy);
+	if (IS_ERR(generic_phy))
+		return PTR_ERR(generic_phy);
+
 	phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k");
 	if (IS_ERR(phy->wkupclk)) {
 		dev_err(&pdev->dev, "unable to get usb_phy_cm_clk32k\n");
@@ -176,8 +214,6 @@ static int omap_usb2_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, phy);
 
-	pm_runtime_enable(phy->dev);
-
 	return 0;
 }
 
Signature · 1 line
1.7.10.4
#8 lore raw

Re: [PATCH v7 2/9] usb: phy: omap-usb2: use the new generic PHY framework

Hi,

drivers/usb/phy/phy-omap-usb2.c static int omap_usb2_probe(struct platform_device *pdev) · line 194

Quoted 5 lines · Kishon Vijay Abraham I
drivers/usb/phy/phy-omap-usb2.c +1 -0
@@ -159,6 +191,12 @@ static int omap_usb2_probe(struct platform_device *pdev)
 	otg->start_srp		= omap_usb_start_srp;
 	otg->phy		= &phy->phy;
 
+	pm_runtime_enable(phy->dev);

enabling pm_runtime here has the potential to cause a real big problem. How have you tested this patch ?

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130618/84ed60b9/attachment.sig>
#9 lore raw

Re: [PATCH v7 2/9] usb: phy: omap-usb2: use the new generic PHY framework

Hi,

Quoted 11 lines · Felipe Balbi

Hi,

drivers/usb/phy/phy-omap-usb2.c static int omap_usb2_probe(struct platform_device *pdev) · line 194

Quoted 5 lines · Kishon Vijay Abraham I
drivers/usb/phy/phy-omap-usb2.c +1 -0
@@ -159,6 +191,12 @@ static int omap_usb2_probe(struct platform_device *pdev)
  	otg->start_srp		= omap_usb_start_srp;
  	otg->phy		= &phy->phy;
 
+	pm_runtime_enable(phy->dev);

enabling pm_runtime here has the potential to cause a real big problem. How have you tested this patch ?

performed boot and enumeration testing. What issue do you expect here?

Thanks
Kishon

#10 lore raw

Re: [PATCH v7 2/9] usb: phy: omap-usb2: use the new generic PHY framework

Hi,

Quoted 10 lines · Kishon Vijay Abraham I

Hi,

Quoted 7 lines · Felipe Balbi

Hi,

Quoted 4 lines · Kishon Vijay Abraham I
drivers/usb/phy/phy-omap-usb2.c +0 -0
@@ -159,6 +191,12 @@ static int omap_usb2_probe(struct platform_device *pdev)
 	otg->start_srp		= omap_usb_start_srp;
 	otg->phy		= &phy->phy;
 
Quoted 6 lines
Quoted 4 lines

drivers/usb/phy/phy-omap-usb2.c static int omap_usb2_probe(struct platform_device *pdev) · line 194

Quoted 1 line
drivers/usb/phy/phy-omap-usb2.c +1 -0
+	pm_runtime_enable(phy->dev);

enabling pm_runtime here has the potential to cause a real big problem. How have you tested this patch ?

performed boot and enumeration testing. What issue do you expect here?

hint: look at drvdata usage around the driver. Where is it initialized ? Where is it used ?

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130618/b1c4322a/attachment.sig>
#11 lore raw

Re: [PATCH v7 2/9] usb: phy: omap-usb2: use the new generic PHY framework

Hi,

Quoted 18 lines · Felipe Balbi

Hi,

Quoted 15 lines · Kishon Vijay Abraham I

Hi,

Quoted 11 lines · Felipe Balbi

Hi,

drivers/usb/phy/phy-omap-usb2.c static int omap_usb2_probe(struct platform_device *pdev) · line 194

Quoted 5 lines · Kishon Vijay Abraham I
drivers/usb/phy/phy-omap-usb2.c +1 -0
@@ -159,6 +191,12 @@ static int omap_usb2_probe(struct platform_device *pdev)
  	otg->start_srp		= omap_usb_start_srp;
  	otg->phy		= &phy->phy;
 
+	pm_runtime_enable(phy->dev);

enabling pm_runtime here has the potential to cause a real big problem. How have you tested this patch ?

Quoted 4 lines
Quoted 1 line

performed boot and enumeration testing. What issue do you expect here?

hint: look at drvdata usage around the driver. Where is it initialized ? Where is it used ?

hmm.. since runtime_get calls weren't made very early, I think I dint see any issues. Thanks for pointing this.

Thanks
Kishon

#12 lore raw

Re: [PATCH v7 2/9] usb: phy: omap-usb2: use the new generic PHY framework

Hi,

Quoted 10 lines · Kishon Vijay Abraham I
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines · Kishon Vijay Abraham I

drivers/usb/phy/phy-omap-usb2.c static int omap_usb2_probe(struct platform_device *pdev) · line 194

Quoted 5 lines
drivers/usb/phy/phy-omap-usb2.c +1 -0
@@ -159,6 +191,12 @@ static int omap_usb2_probe(struct platform_device *pdev)
 	otg->start_srp		= omap_usb_start_srp;
 	otg->phy		= &phy->phy;
 
+	pm_runtime_enable(phy->dev);

enabling pm_runtime here has the potential to cause a real big problem. How have you tested this patch ?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

performed boot and enumeration testing. What issue do you expect here?

hint: look at drvdata usage around the driver. Where is it initialized ? Where is it used ?

hmm.. since runtime_get calls weren't made very early, I think I dint see any issues. Thanks for pointing this.

right, no problem. BTW, you don't get to_platform_device() -> platform_get_drvdata(). A simple dev_get_drvdata() is sufficient :-)

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130618/4631ffe0/attachment.sig>
#13 lore raw

PATCH v7 3/9 usb: phy: twl4030: use the new generic PHY framework

In reply to Kishon Vijay Abraham I

Used the generic PHY framework API to create the PHY. For powering on and powering off the PHY, power_on and power_off ops are used. Once the MUSB OMAP glue is adapted to the new framework, the suspend and resume ops of usb phy library will be removed.

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/phy/phy-twl4030-usb.c |   48 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)
drivers/usb/phy/phy-twl4030-usb.c +47 -1
index 8f78d2d..65a5e43 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>
@@ -431,6 +432,14 @@ static void twl4030_phy_suspend(struct twl4030_usb *twl, int controller_off)
 	dev_dbg(twl->dev, "%s\n", __func__);
 }
 
+static int twl4030_phy_power_off(struct phy *phy)
+{
+	struct twl4030_usb *twl = dev_get_drvdata(&phy->dev);
+
+	twl4030_phy_suspend(twl, 0);
+	return 0;
+}
+
 static void __twl4030_phy_resume(struct twl4030_usb *twl)
 {
 	twl4030_phy_power(twl, 1);
@@ -459,6 +468,14 @@ static void twl4030_phy_resume(struct twl4030_usb *twl)
 	}
 }
 
+static int twl4030_phy_power_on(struct phy *phy)
+{
+	struct twl4030_usb *twl = dev_get_drvdata(&phy->dev);
+
+	twl4030_phy_resume(twl);
+	return 0;
+}
+
 static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
 {
 	/* Enable writing to power configuration registers */
@@ -602,13 +619,22 @@ static int twl4030_usb_phy_init(struct usb_phy *phy)
 	status = twl4030_usb_linkstat(twl);
 	twl->linkstat = status;
 
-	if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID)
+	if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID) {
 		omap_musb_mailbox(twl->linkstat);
+		twl4030_phy_power_on(phy);
+	}
 
 	sysfs_notify(&twl->dev->kobj, NULL, "vbus");
 	return 0;
 }
 
+static int twl4030_phy_init(struct phy *phy)
+{
+	struct twl4030_usb *twl = dev_get_drvdata(&phy->dev);
+
+	return twl4030_usb_phy_init(&twl->phy);
+}
+
 static int twl4030_set_suspend(struct usb_phy *x, int suspend)
 {
 	struct twl4030_usb *twl = phy_to_twl(x);
@@ -646,13 +672,22 @@ static int twl4030_set_host(struct usb_otg *otg, struct usb_bus *host)
 	return 0;
 }
 
+static const struct phy_ops ops = {
+	.init		= twl4030_phy_init,
+	.power_on	= twl4030_phy_power_on,
+	.power_off	= twl4030_phy_power_off,
+	.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;
+	struct phy_provider	*phy_provider;
 
 	twl = devm_kzalloc(&pdev->dev, sizeof *twl, GFP_KERNEL);
 	if (!twl)
@@ -689,6 +724,17 @@ static int twl4030_usb_probe(struct platform_device *pdev)
 	otg->set_host		= twl4030_set_host;
 	otg->set_peripheral	= twl4030_set_peripheral;
 
+	phy_provider = devm_of_phy_provider_register(twl->dev, THIS_MODULE,
+		of_phy_simple_xlate);
+	if (IS_ERR(phy_provider))
+		return PTR_ERR(phy_provider);
+
+	phy = devm_phy_create(twl->dev, 0, &ops, "twl4030", 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
Reviewed-by on v7 3/9
#14 lore raw

Re: [PATCH v7 3/9] usb: phy: twl4030: use the new generic PHY framework

Quoted 11 lines · Kishon Vijay Abraham I

Used the generic PHY framework API to create the PHY. For powering on and powering off the PHY, power_on and power_off ops are used. Once the MUSB OMAP glue is adapted to the new framework, the suspend and resume ops of usb phy library will be removed.

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.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130618/d92c21b5/attachment.sig>
#15 lore raw

PATCH v7 4/9 usb: phy: twl4030: twl4030 shouldn't be subsys_initcall

In reply to Kishon Vijay Abraham I

Changed the inticall from subsys_initcall to module_init for twl4030-usb.

---
 drivers/usb/phy/phy-twl4030-usb.c |   12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/usb/phy/phy-twl4030-usb.c +1 -11
index 65a5e43..fba9697 100644
@@ -822,17 +822,7 @@ static struct platform_driver twl4030_usb_driver = {
 	},
 };
 
-static int __init twl4030_usb_init(void)
-{
-	return platform_driver_register(&twl4030_usb_driver);
-}
-subsys_initcall(twl4030_usb_init);
-
-static void __exit twl4030_usb_exit(void)
-{
-	platform_driver_unregister(&twl4030_usb_driver);
-}
-module_exit(twl4030_usb_exit);
+module_platform_driver(twl4030_usb_driver);
 
 MODULE_ALIAS("platform:twl4030_usb");
 MODULE_AUTHOR("Texas Instruments, Inc, Nokia Corporation");
Signature · 1 line
1.7.10.4
#16 lore raw

Re: [PATCH v7 4/9] usb: phy: twl4030: twl4030 shouldn't be subsys_initcall

Quoted 4 lines · Kishon Vijay Abraham I

Changed the inticall from subsys_initcall to module_init for twl4030-usb.

not part of the series, should be sent separately. I'll queue this one for v3.12 once v3.11-rc1 is tagged.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130618/2a18c565/attachment.sig>
#17 lore raw

PATCH v7 5/9 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 (phy device name) should be added in the platform data of the controller.

---
 arch/arm/mach-omap2/usb-musb.c |    6 +++++-
 include/linux/usb/musb.h       |    3 +++
 2 files changed, 8 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/usb-musb.c +5 -1
index 3242a55..284ba51 100644
@@ -85,8 +85,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;
+		musb_plat.phy_label = "omap-usb2";
+	} else if (cpu_is_omap34xx()) {
+		musb_plat.phy_label = "twl4030";
+	}
 
 	if (soc_is_am35xx()) {
 		oh_name = "am35x_otg_hs";
include/linux/usb/musb.h +3 -0
index 053c268..596f8c8 100644
@@ -104,6 +104,9 @@ struct musb_hdrc_platform_data {
 	/* for clk_get() */
 	const char	*clock;
 
+	/* phy label */
+	const char	*phy_label;
+
 	/* (HOST or OTG) switch VBUS on/off */
 	int		(*set_vbus)(struct device *dev, int is_on);
 
Signature · 1 line
1.7.10.4
#18 lore raw

Re: [PATCH v7 5/9] ARM: OMAP: USB: Add phy binding information

Quoted 5 lines · Kishon Vijay Abraham I

In order for controllers to get PHY in case of non dt boot, the phy binding information (phy device name) should be added in the platform data of the controller.

I would rather not pass strings around, any other way to handle this ? Why do you need to pass this string ?

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130618/34bb6cf0/attachment-0001.sig>
#19 lore raw

Re: [PATCH v7 5/9] ARM: OMAP: USB: Add phy binding information

Hi,

Quoted 9 lines · Felipe Balbi
Quoted 5 lines · Kishon Vijay Abraham I

In order for controllers to get PHY in case of non dt boot, the phy binding information (phy device name) should be added in the platform data of the controller.

I would rather not pass strings around, any other way to handle this ? Why do you need to pass this string ?

Our old way of binding the controller and the phy using device name started creating problems after the devices are created using PLATFORM_DEVID_AUTO. Infact non-dt boot is broken in mainline for OMAP3 platforms for which I have posted a RFC series
http://www.serverphorums.com/read.php?12,708632 which also uses strings. I'm not sure of any other way to deal with this.

Thanks
Kishon

#20 lore raw

Re: [PATCH v7 5/9] ARM: OMAP: USB: Add phy binding information

Hi,

Quoted 11 lines · Kishon Vijay Abraham I
Quoted 9 lines · Felipe Balbi
Quoted 5 lines · Kishon Vijay Abraham I

In order for controllers to get PHY in case of non dt boot, the phy binding information (phy device name) should be added in the platform data of the controller.

I would rather not pass strings around, any other way to handle this ? Why do you need to pass this string ?

Quoted 7 lines

Our old way of binding the controller and the phy using device name started creating problems after the devices are created using PLATFORM_DEVID_AUTO. Infact non-dt boot is broken in mainline for OMAP3 platforms for which I have posted a RFC series
http://www.serverphorums.com/read.php?12,708632 which also uses strings.
I'm not sure of any other way to deal with this.

have you checked how other frameworks handle it ? Regulator has some sort of binding in board-files, but I guess it passes the regulator name?

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130618/b245c2bb/attachment.sig>
#21 lore raw

Re: [PATCH v7 5/9] ARM: OMAP: USB: Add phy binding information

Hi,

Quoted 22 lines · Felipe Balbi

Hi,

Quoted 11 lines · Kishon Vijay Abraham I
Quoted 9 lines · Felipe Balbi
Quoted 5 lines · Kishon Vijay Abraham I

In order for controllers to get PHY in case of non dt boot, the phy binding information (phy device name) should be added in the platform data of the controller.

I would rather not pass strings around, any other way to handle this ? Why do you need to pass this string ?

Quoted 7 lines

Our old way of binding the controller and the phy using device name started creating problems after the devices are created using PLATFORM_DEVID_AUTO. Infact non-dt boot is broken in mainline for OMAP3 platforms for which I have posted a RFC series
http://www.serverphorums.com/read.php?12,708632 which also uses strings.
I'm not sure of any other way to deal with this.

Quoted 3 lines

have you checked how other frameworks handle it ? Regulator has some sort of binding in board-files, but I guess it passes the regulator name?

From whatever I could make of, regulator has 3 ways to get the
regulator one of which is using the binding in board-files (but it also uses device name which could create the same problem that we are facing).

1.) from dt data
2.) from _supply_ name
3.) from binding in board file

(referred regulator_dev_lookup() in regulator/core.c)

Thanks
Kishon

#22 lore raw

Re: [PATCH v7 5/9] ARM: OMAP: USB: Add phy binding information

Hi,

Quoted 29 lines · Kishon Vijay Abraham I
Quoted 20 lines · Kishon Vijay Abraham I
Quoted 11 lines · Felipe Balbi
Quoted 9 lines · Kishon Vijay Abraham I
Quoted 5 lines

In order for controllers to get PHY in case of non dt boot, the phy binding information (phy device name) should be added in the platform data of the controller.

I would rather not pass strings around, any other way to handle this ? Why do you need to pass this string ?

Quoted 7 lines

Our old way of binding the controller and the phy using device name started creating problems after the devices are created using PLATFORM_DEVID_AUTO. Infact non-dt boot is broken in mainline for OMAP3 platforms for which I have posted a RFC series
http://www.serverphorums.com/read.php?12,708632 which also uses strings.
I'm not sure of any other way to deal with this.

Quoted 3 lines

have you checked how other frameworks handle it ? Regulator has some sort of binding in board-files, but I guess it passes the regulator name?

From whatever I could make of, regulator has 3 ways to get the regulator one of which is using the binding in board-files (but it also uses device name which could create the same problem that we are facing).

Quoted 5 lines

1.) from dt data
2.) from _supply_ name
3.) from binding in board file

(referred regulator_dev_lookup() in regulator/core.c)

right, spot on. Which means we don't have a better, more elegant solution now. Let's go ahead with this.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130618/42f5d2bc/attachment.sig>
#23 lore raw

Re: [PATCH v7 5/9] ARM: OMAP: USB: Add phy binding information

Hi,

Quoted 32 lines · Felipe Balbi

Hi,

Quoted 29 lines · Kishon Vijay Abraham I
Quoted 20 lines · Kishon Vijay Abraham I
Quoted 11 lines · Felipe Balbi
Quoted 9 lines · Kishon Vijay Abraham I
Quoted 5 lines

In order for controllers to get PHY in case of non dt boot, the phy binding information (phy device name) should be added in the platform data of the controller.

I would rather not pass strings around, any other way to handle this ? Why do you need to pass this string ?

Quoted 7 lines

Our old way of binding the controller and the phy using device name started creating problems after the devices are created using PLATFORM_DEVID_AUTO. Infact non-dt boot is broken in mainline for OMAP3 platforms for which I have posted a RFC series
http://www.serverphorums.com/read.php?12,708632 which also uses strings.
I'm not sure of any other way to deal with this.

Quoted 3 lines

have you checked how other frameworks handle it ? Regulator has some sort of binding in board-files, but I guess it passes the regulator name?

From whatever I could make of, regulator has 3 ways to get the
regulator one of which is using the binding in board-files (but it also uses device name which could create the same problem that we are facing).

Quoted 8 lines
Quoted 5 lines

1.) from dt data
2.) from _supply_ name
3.) from binding in board file

(referred regulator_dev_lookup() in regulator/core.c)

right, spot on. Which means we don't have a better, more elegant solution now. Let's go ahead with this.

Ok. So I'll drop RFC and resend this patch series
http://www.serverphorums.com/read.php?12,708632

Thanks
Kishon

#24 lore raw

Re: [PATCH v7 5/9] ARM: OMAP: USB: Add phy binding information

Hi,

Quoted 39 lines · Kishon Vijay Abraham I

Hi,

Quoted 36 lines · Felipe Balbi

Hi,

Quoted 33 lines · Kishon Vijay Abraham I
Quoted 20 lines · Kishon Vijay Abraham I
Quoted 11 lines · Felipe Balbi
Quoted 9 lines · Kishon Vijay Abraham I
Quoted 5 lines

In order for controllers to get PHY in case of non dt boot, the phy binding information (phy device name) should be added in the platform data of the controller.

I would rather not pass strings around, any other way to handle this ? Why do you need to pass this string ?

Quoted 7 lines

Our old way of binding the controller and the phy using device name started creating problems after the devices are created using PLATFORM_DEVID_AUTO. Infact non-dt boot is broken in mainline for OMAP3 platforms for which I have posted a RFC series
http://www.serverphorums.com/read.php?12,708632 which also uses strings.
I'm not sure of any other way to deal with this.

Quoted 3 lines

have you checked how other frameworks handle it ? Regulator has some sort of binding in board-files, but I guess it passes the regulator name?

From whatever I could make of, regulator has 3 ways to get the regulator one of which is using the binding in board-files (but it also uses device name which could create the same problem that we are facing).

1.) from dt data
2.) from _supply_ name
3.) from binding in board file

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

(referred regulator_dev_lookup() in regulator/core.c)

right, spot on. Which means we don't have a better, more elegant solution now. Let's go ahead with this.

Ok. So I'll drop RFC and resend this patch series
http://www.serverphorums.com/read.php?12,708632

please do :-)

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130618/5566e070/attachment.sig>
#25 lore raw

PATCH v7 6/9 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 +++++
 Documentation/devicetree/bindings/usb/usb-phy.txt  |    6 ++++++
 arch/arm/boot/dts/omap3-beagle-xm.dts              |    2 ++
 arch/arm/boot/dts/omap3-evm.dts                    |    2 ++
 arch/arm/boot/dts/omap3-overo.dtsi                 |    2 ++
 arch/arm/boot/dts/omap4.dtsi                       |    3 +++
 arch/arm/boot/dts/twl4030.dtsi                     |    1 +
 7 files changed, 21 insertions(+)
Documentation/devicetree/bindings/usb/omap-usb.txt +5 -0
index d4769f3..c0871a7 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
Documentation/devicetree/bindings/usb/usb-phy.txt +6 -0
index 61496f5..c0245c8 100644
@@ -5,6 +5,8 @@ OMAP USB2 PHY
 Required properties:
  - compatible: Should be "ti,omap-usb2"
  - reg : Address and length of the register set for the device.
+ - #phy-cells: determine the number of cells that should be given in the
+   phandle while referencing this phy.
 
 Optional properties:
  - ctrl-module : phandle of the control module used by PHY driver to power on
@@ -16,6 +18,7 @@ usb2phy at 4a0ad080 {
 	compatible = "ti,omap-usb2";
 	reg = <0x4a0ad080 0x58>;
 	ctrl-module = <&omap_control_usb>;
+	#phy-cells = <0>;
 };
 
 OMAP USB3 PHY
@@ -25,6 +28,8 @@ Required properties:
  - reg : Address and length of the register set for the device.
  - reg-names: The names of the register addresses corresponding to the registers
    filled in "reg".
+ - #phy-cells: determine the number of cells that should be given in the
+   phandle while referencing this phy.
 
 Optional properties:
  - ctrl-module : phandle of the control module used by PHY driver to power on
@@ -39,4 +44,5 @@ usb3phy at 4a084400 {
 	      <0x4a084c00 0x40>;
 	reg-names = "phy_rx", "phy_tx", "pll_ctrl";
 	ctrl-module = <&omap_control_usb>;
+	#phy-cells = <0>;
 };
arch/arm/boot/dts/omap3-beagle-xm.dts +2 -0
index 3046d1f..023596e 100644
@@ -123,6 +123,8 @@
 &usb_otg_hs {
 	interface-type = <0>;
 	usb-phy = <&usb2_phy>;
+	phys = <&usb2_phy>;
+	phy-names = "usb2-phy";
 	mode = <3>;
 	power = <50>;
 };
arch/arm/boot/dts/omap3-evm.dts +2 -0
index 96d1c20..f2b8314 100644
@@ -69,6 +69,8 @@
 &usb_otg_hs {
 	interface-type = <0>;
 	usb-phy = <&usb2_phy>;
+	phys = <&usb2_phy>;
+	phy-names = "usb2-phy";
 	mode = <3>;
 	power = <50>;
 };
arch/arm/boot/dts/omap3-overo.dtsi +2 -0
index a626c50..b65916e 100644
@@ -74,6 +74,8 @@
 &usb_otg_hs {
 	interface-type = <0>;
 	usb-phy = <&usb2_phy>;
+	phys = <&usb2_phy>;
+	phy-names = "usb2-phy";
 	mode = <3>;
 	power = <50>;
 };
arch/arm/boot/dts/omap4.dtsi +3 -0
index 2a56428..dae620b 100644
@@ -517,6 +517,7 @@
 				compatible = "ti,omap-usb2";
 				reg = <0x4a0ad080 0x58>;
 				ctrl-module = <&omap_control_usb>;
+				#phy-cells = <0>;
 			};
 		};
 
@@ -655,6 +656,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/twl4030.dtsi +1 -0
index b3034da..ce4cd6f 100644
@@ -80,6 +80,7 @@
 		usb1v8-supply = <&vusb1v8>;
 		usb3v1-supply = <&vusb3v1>;
 		usb_mode = <1>;
+		#phy-cells = <0>;
 	};
 
 	twl_pwm: pwm {
Signature · 1 line
1.7.10.4
Reviewed-by on v7 6/9
#26 lore raw

Re: [PATCH v7 6/9] ARM: dts: omap: update usb_otg_hs data

Quoted 7 lines · 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

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130618/756503b6/attachment.sig>
#27 lore raw

PATCH v7 7/9 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_resume and usb_phy_set_suspend is replaced with power_on/get_sync and power_off/put_sync 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.c |    1 +
 drivers/usb/musb/musb_core.h |    3 +++
 drivers/usb/musb/omap2430.c  |   29 +++++++++++++++++++++--------
 3 files changed, 25 insertions(+), 8 deletions(-)
drivers/usb/musb/musb_core.c +1 -0
index 37a261a..f732bcc 100644
@@ -1864,6 +1864,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
 	musb->board_set_power = plat->set_power;
 	musb->min_power = plat->min_power;
 	musb->ops = plat->platform_ops;
+	musb->phy_label = plat->phy_label;
 
 	/* The musb_platform_init() call:
 	 *   - adjusts musb->mregs
drivers/usb/musb/musb_core.h +3 -0
index 7fb4819..498ae21 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;
@@ -434,6 +436,7 @@ struct musb {
 	unsigned                double_buffer_not_ok:1;
 
 	struct musb_hdrc_config	*config;
+	const char		*phy_label;
 
 #ifdef MUSB_CONFIG_PROC_FS
 	struct proc_dir_entry *proc_entry;
drivers/usb/musb/omap2430.c +21 -8
index 628b93f..c62a004 100644
@@ -348,14 +348,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_phy_get(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, musb->phy_label);
+	}
 
-	if (IS_ERR(musb->xceiv)) {
-		status = PTR_ERR(musb->xceiv);
+	if (IS_ERR(musb->xceiv) || IS_ERR(musb->phy)) {
+		status = PTR_ERR(musb->xceiv) | PTR_ERR(musb->phy);
 
 		if (status == -ENXIO)
 			return status;
@@ -397,9 +407,10 @@ static int omap2430_musb_init(struct musb *musb)
 	if (glue->status != OMAP_MUSB_UNKNOWN)
 		omap_musb_set_mailbox(glue);
 
-	usb_phy_init(musb->xceiv);
+	phy_init(musb->phy);
 
 	pm_runtime_put_noidle(musb->controller);
+	phy_pm_runtime_put(musb->phy);
 	return 0;
 
 err1:
@@ -460,6 +471,7 @@ static int omap2430_musb_exit(struct musb *musb)
 	del_timer_sync(&musb_idle_timer);
 
 	omap2430_low_level_exit(musb);
+	phy_exit(musb->phy);
 
 	return 0;
 }
@@ -619,7 +631,8 @@ static int omap2430_runtime_suspend(struct device *dev)
 				OTG_INTERFSEL);
 
 		omap2430_low_level_exit(musb);
-		usb_phy_set_suspend(musb->xceiv, 1);
+		phy_power_off(musb->phy);
+		phy_pm_runtime_put(musb->phy);
 	}
 
 	return 0;
@@ -634,8 +647,8 @@ static int omap2430_runtime_resume(struct device *dev)
 		omap2430_low_level_init(musb);
 		musb_writel(musb->mregs, OTG_INTERFSEL,
 				musb->context.otg_interfsel);
-
-		usb_phy_set_suspend(musb->xceiv, 0);
+		phy_pm_runtime_get_sync(musb->phy);
+		phy_power_on(musb->phy);
 	}
 
 	return 0;
Signature · 1 line
1.7.10.4
#28 lore raw

Re: [PATCH v7 7/9] usb: musb: omap2430: use the new generic PHY framework

Hi,

Quoted 89 lines · Kishon Vijay Abraham I

Use the generic PHY framework API to get the PHY. The usb_phy_set_resume and usb_phy_set_suspend is replaced with power_on/get_sync and power_off/put_sync 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.c |    1 +
 drivers/usb/musb/musb_core.h |    3 +++
 drivers/usb/musb/omap2430.c  |   29 +++++++++++++++++++++--------
 3 files changed, 25 insertions(+), 8 deletions(-)
drivers/usb/musb/musb_core.c +1 -0
index 37a261a..f732bcc 100644
@@ -1864,6 +1864,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
 	musb->board_set_power = plat->set_power;
 	musb->min_power = plat->min_power;
 	musb->ops = plat->platform_ops;
+	musb->phy_label = plat->phy_label;
 
 	/* The musb_platform_init() call:
 	 *   - adjusts musb->mregs
drivers/usb/musb/musb_core.h +3 -0
index 7fb4819..498ae21 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;
@@ -434,6 +436,7 @@ struct musb {
 	unsigned                double_buffer_not_ok:1;
 
 	struct musb_hdrc_config	*config;
+	const char		*phy_label;
 
 #ifdef MUSB_CONFIG_PROC_FS
 	struct proc_dir_entry *proc_entry;
drivers/usb/musb/omap2430.c +14 -4
index 628b93f..c62a004 100644
@@ -348,14 +348,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_phy_get(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, musb->phy_label);
+	}
 
-	if (IS_ERR(musb->xceiv)) {
-		status = PTR_ERR(musb->xceiv);
+	if (IS_ERR(musb->xceiv) || IS_ERR(musb->phy)) {
+		status = PTR_ERR(musb->xceiv) | PTR_ERR(musb->phy);
 
 		if (status == -ENXIO)
 			return status;

drivers/usb/musb/omap2430.c static int omap2430_musb_init(struct musb *musb) · line 413

Quoted 8 lines
drivers/usb/musb/omap2430.c +2 -1
@@ -397,9 +407,10 @@ static int omap2430_musb_init(struct musb *musb)
 	if (glue->status != OMAP_MUSB_UNKNOWN)
 		omap_musb_set_mailbox(glue);
 
-	usb_phy_init(musb->xceiv);
+	phy_init(musb->phy);
 
 	pm_runtime_put_noidle(musb->controller);
+	phy_pm_runtime_put(musb->phy);

see, weird unbalanced calls :-)

Make it all explicit:

phy_pm_runtime_get_sync(phy);
phy_init(phy);
phy_pm_runtime_put(phy);

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130618/303b3b6b/attachment.sig>
#29 lore raw

Re: [PATCH v7 7/9] usb: musb: omap2430: use the new generic PHY framework

Hi,

Quoted 103 lines · Felipe Balbi

Hi,

Quoted 89 lines · Kishon Vijay Abraham I

Use the generic PHY framework API to get the PHY. The usb_phy_set_resume and usb_phy_set_suspend is replaced with power_on/get_sync and power_off/put_sync 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.c |    1 +
  drivers/usb/musb/musb_core.h |    3 +++
  drivers/usb/musb/omap2430.c  |   29 +++++++++++++++++++++--------
  3 files changed, 25 insertions(+), 8 deletions(-)
drivers/usb/musb/musb_core.c +1 -0
index 37a261a..f732bcc 100644
@@ -1864,6 +1864,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
  	musb->board_set_power = plat->set_power;
  	musb->min_power = plat->min_power;
  	musb->ops = plat->platform_ops;
+	musb->phy_label = plat->phy_label;
 
  	/* The musb_platform_init() call:
  	 *   - adjusts musb->mregs
drivers/usb/musb/musb_core.h +3 -0
index 7fb4819..498ae21 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;
@@ -434,6 +436,7 @@ struct musb {
  	unsigned                double_buffer_not_ok:1;
 
  	struct musb_hdrc_config	*config;
+	const char		*phy_label;
 
  #ifdef MUSB_CONFIG_PROC_FS
  	struct proc_dir_entry *proc_entry;
drivers/usb/musb/omap2430.c +14 -4
index 628b93f..c62a004 100644
@@ -348,14 +348,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_phy_get(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, musb->phy_label);
+	}
 
-	if (IS_ERR(musb->xceiv)) {
-		status = PTR_ERR(musb->xceiv);
+	if (IS_ERR(musb->xceiv) || IS_ERR(musb->phy)) {
+		status = PTR_ERR(musb->xceiv) | PTR_ERR(musb->phy);
 
  		if (status == -ENXIO)
  			return status;

drivers/usb/musb/omap2430.c static int omap2430_musb_init(struct musb *musb) · line 413

Quoted 8 lines
drivers/usb/musb/omap2430.c +2 -1
@@ -397,9 +407,10 @@ static int omap2430_musb_init(struct musb *musb)
  	if (glue->status != OMAP_MUSB_UNKNOWN)
  		omap_musb_set_mailbox(glue);
 
-	usb_phy_init(musb->xceiv);
+	phy_init(musb->phy);
 
  	pm_runtime_put_noidle(musb->controller);
+	phy_pm_runtime_put(musb->phy);

see, weird unbalanced calls :-)

Quoted 5 lines

Make it all explicit:

phy_pm_runtime_get_sync(phy);
phy_init(phy);
phy_pm_runtime_put(phy);

I think then it makes sense to drop get_sync from phy_init()?

Thanks
Kishon

#30 lore raw

Re: [PATCH v7 7/9] usb: musb: omap2430: use the new generic PHY framework

Hi,

Quoted 12 lines · Kishon Vijay Abraham I
Quoted 12 lines

drivers/usb/musb/omap2430.c static int omap2430_musb_init(struct musb *musb) · line 413

Quoted 9 lines
drivers/usb/musb/omap2430.c +2 -1
@@ -397,9 +407,10 @@ static int omap2430_musb_init(struct musb *musb)
 	if (glue->status != OMAP_MUSB_UNKNOWN)
 		omap_musb_set_mailbox(glue);
 
-	usb_phy_init(musb->xceiv);
+	phy_init(musb->phy);
 
 	pm_runtime_put_noidle(musb->controller);
+	phy_pm_runtime_put(musb->phy);

see, weird unbalanced calls :-)

Quoted 7 lines
Quoted 5 lines

Make it all explicit:

phy_pm_runtime_get_sync(phy);
phy_init(phy);
phy_pm_runtime_put(phy);

I think then it makes sense to drop get_sync from phy_init()?

maybe not, you don't know if the phy has already autosuspended or not.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130624/8f85e599/attachment.sig>
#31 lore raw

PATCH v7 8/9 usb: phy: omap-usb2: remove *set_suspend* callback from omap-usb2

In reply to Kishon Vijay Abraham I

Now that omap-usb2 is adapted to the new generic PHY framework, *set_suspend* ops can be removed from omap-usb2 driver.

---
 drivers/usb/phy/phy-omap-usb2.c |   24 ------------------------
 1 file changed, 24 deletions(-)
drivers/usb/phy/phy-omap-usb2.c +0 -24
index 3c275e7..bd2e4ca 100644
@@ -97,29 +97,6 @@ static int omap_usb_set_peripheral(struct usb_otg *otg,
 	return 0;
 }
 
-static int omap_usb2_suspend(struct usb_phy *x, int suspend)
-{
-	u32 ret;
-	struct omap_usb *phy = phy_to_omapusb(x);
-
-	if (suspend && !phy->is_suspended) {
-		omap_control_usb_phy_power(phy->control_dev, 0);
-		pm_runtime_put_sync(phy->dev);
-		phy->is_suspended = 1;
-	} else if (!suspend && 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 int omap_usb_power_off(struct phy *x)
 {
 	struct omap_usb *phy = dev_get_drvdata(&x->dev);
@@ -167,7 +144,6 @@ static int omap_usb2_probe(struct platform_device *pdev)
 
 	phy->phy.dev		= phy->dev;
 	phy->phy.label		= "omap-usb2";
-	phy->phy.set_suspend	= omap_usb2_suspend;
 	phy->phy.otg		= otg;
 	phy->phy.type		= USB_PHY_TYPE_USB2;
 
Signature · 1 line
1.7.10.4
Reviewed-by on v7 8/9
#32 lore raw

Re: [PATCH v7 8/9] usb: phy: omap-usb2: remove *set_suspend* callback from omap-usb2

Quoted 4 lines · Kishon Vijay Abraham I

Now that omap-usb2 is adapted to the new generic PHY framework, *set_suspend* ops can be removed from omap-usb2 driver.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130618/80a91e77/attachment-0001.sig>
#33 lore raw

PATCH v7 9/9 usb: phy: twl4030-usb: remove *set_suspend* and *phy_init* ops

In reply to Kishon Vijay Abraham I

Now that twl4030-usb is adapted to the new generic PHY framework, *set_suspend* and *phy_init* ops can be removed from twl4030-usb driver.

---
 drivers/usb/phy/phy-twl4030-usb.c |   55 ++++++++-----------------------------
 1 file changed, 12 insertions(+), 43 deletions(-)
drivers/usb/phy/phy-twl4030-usb.c +12 -43
index fba9697..5245b86 100644
@@ -422,25 +422,20 @@ static void twl4030_phy_power(struct twl4030_usb *twl, int on)
 	}
 }
 
-static void twl4030_phy_suspend(struct twl4030_usb *twl, int controller_off)
+static int twl4030_phy_power_off(struct phy *phy)
 {
+	struct twl4030_usb *twl = dev_get_drvdata(&phy->dev);
+
 	if (twl->asleep)
-		return;
+		return 0;
 
 	twl4030_phy_power(twl, 0);
 	twl->asleep = 1;
 	dev_dbg(twl->dev, "%s\n", __func__);
-}
-
-static int twl4030_phy_power_off(struct phy *phy)
-{
-	struct twl4030_usb *twl = dev_get_drvdata(&phy->dev);
-
-	twl4030_phy_suspend(twl, 0);
 	return 0;
 }
 
-static void __twl4030_phy_resume(struct twl4030_usb *twl)
+static void __twl4030_phy_power_on(struct twl4030_usb *twl)
 {
 	twl4030_phy_power(twl, 1);
 	twl4030_i2c_access(twl, 1);
@@ -449,11 +444,13 @@ static void __twl4030_phy_resume(struct twl4030_usb *twl)
 		twl4030_i2c_access(twl, 0);
 }
 
-static void twl4030_phy_resume(struct twl4030_usb *twl)
+static int twl4030_phy_power_on(struct phy *phy)
 {
+	struct twl4030_usb *twl = dev_get_drvdata(&phy->dev);
+
 	if (!twl->asleep)
-		return;
-	__twl4030_phy_resume(twl);
+		return 0;
+	__twl4030_phy_power_on(twl);
 	twl->asleep = 0;
 	dev_dbg(twl->dev, "%s\n", __func__);
 
@@ -466,13 +463,6 @@ static void twl4030_phy_resume(struct twl4030_usb *twl)
 		cancel_delayed_work(&twl->id_workaround_work);
 		schedule_delayed_work(&twl->id_workaround_work, HZ);
 	}
-}
-
-static int twl4030_phy_power_on(struct phy *phy)
-{
-	struct twl4030_usb *twl = dev_get_drvdata(&phy->dev);
-
-	twl4030_phy_resume(twl);
 	return 0;
 }
 
@@ -604,9 +594,9 @@ static void twl4030_id_workaround_work(struct work_struct *work)
 	}
 }
 
-static int twl4030_usb_phy_init(struct usb_phy *phy)
+static int twl4030_phy_init(struct phy *phy)
 {
-	struct twl4030_usb *twl = phy_to_twl(phy);
+	struct twl4030_usb *twl = dev_get_drvdata(&phy->dev);
 	enum omap_musb_vbus_id_status status;
 
 	/*
@@ -628,25 +618,6 @@ static int twl4030_usb_phy_init(struct usb_phy *phy)
 	return 0;
 }
 
-static int twl4030_phy_init(struct phy *phy)
-{
-	struct twl4030_usb *twl = dev_get_drvdata(&phy->dev);
-
-	return twl4030_usb_phy_init(&twl->phy);
-}
-
-static int twl4030_set_suspend(struct usb_phy *x, int suspend)
-{
-	struct twl4030_usb *twl = phy_to_twl(x);
-
-	if (suspend)
-		twl4030_phy_suspend(twl, 1);
-	else
-		twl4030_phy_resume(twl);
-
-	return 0;
-}
-
 static int twl4030_set_peripheral(struct usb_otg *otg,
 					struct usb_gadget *gadget)
 {
@@ -717,8 +688,6 @@ static int twl4030_usb_probe(struct platform_device *pdev)
 	twl->phy.label		= "twl4030";
 	twl->phy.otg		= otg;
 	twl->phy.type		= USB_PHY_TYPE_USB2;
-	twl->phy.set_suspend	= twl4030_set_suspend;
-	twl->phy.init		= twl4030_usb_phy_init;
 
 	otg->phy		= &twl->phy;
 	otg->set_host		= twl4030_set_host;
Signature · 1 line
1.7.10.4
Reviewed-by on v7 9/9
#34 lore raw

Re: [PATCH v7 9/9] usb: phy: twl4030-usb: remove *set_suspend* and *phy_init* ops

Quoted 4 lines · Kishon Vijay Abraham I

Now that twl4030-usb is adapted to the new generic PHY framework, *set_suspend* and *phy_init* ops can be removed from twl4030-usb driver.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130618/8e23d22f/attachment-0001.sig>
Reviewed-by on the v7 series
#35 lore raw
In reply to Kishon Vijay Abraham I

Hi,

Quoted 21 lines · Kishon Vijay Abraham I

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.

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.

If the PHY driver has to send notification on connect/disconnect, the PHY driver should make use of the extcon framework. Using this susbsystem to use extcon framwork will have to be analysed.

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

Quoted 7 lines

This patch series is developed on linux mainline tree.

Changes from v6
* corrected few typos in Documentation
* Changed PHY Subsystem to *bool* in Kconfig (to avoid compilation errors when PHY Subsystem is kept as module and the dependent modules are built-in)
* Added if pm_runtime_enabled check before runtime pm calls.

Looks good, feel free to add:

1...3/9, 5...7/9

and Tested-by: Sylwester Nawrocki <[email protected]> for patch 1/9

Hopefully we can gather more Acks and merge it for 3.11.

I have already used this API for our MIPI CSI-2/DSIM DPHYs driver, the RFC patch series can be found at [1].

Thanks,
Sylwester

[1] http://www.spinics.net/lists/arm-kernel/msg251666.html

#36 lore raw

Hi,

Quoted 7 lines · Sylwester Nawrocki

I have already used this API for our MIPI CSI-2/DSIM DPHYs driver, the RFC patch series can be found at [1].

Thanks,
Sylwester

[1] http://www.spinics.net/lists/arm-kernel/msg251666.html

one comment to that series:

let's make the phy names standardized, how about phy-exynos-video-mipi.c or phy-mipi-csi-dsim.c ?

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130618/be6293fb/attachment.sig>
#37 lore raw

Hi,

Quoted 7 lines · Felipe Balbi
Quoted 6 lines · Sylwester Nawrocki

I have already used this API for our MIPI CSI-2/DSIM DPHYs driver, the RFC patch series can be found at [1].

Thanks,
Sylwester

Quoted 6 lines
Quoted 1 line

[1] http://www.spinics.net/lists/arm-kernel/msg251666.html

one comment to that series:

let's make the phy names standardized, how about phy-exynos-video-mipi.c or phy-mipi-csi-dsim.c ?

Yes, I have been thinking about that, wasn't sure exactly what pattern to chose. I would make it phy-exynos-mipi-video.c, phy-exynos-dsim-csis.c feels a bit odd. phy-mipi-csis-dsim.c might be to generic as MIPI CSIS stands for MIPI CSI Slave and MIPI DSIM - MIPI DSI Master. And there might be (actually are) IP blocks in an SoC that use the other MIPI Aliance standards. For the HDMI PHY I guess just phy-exynos-hdmi.c could be used.

Thanks,
Sylwester

#38 lore raw
Quoted 17 lines · Sylwester Nawrocki

Hi,

Quoted 7 lines · Felipe Balbi
Quoted 6 lines · Sylwester Nawrocki

I have already used this API for our MIPI CSI-2/DSIM DPHYs driver, the RFC patch series can be found at [1].

Thanks,
Sylwester

Quoted 6 lines
Quoted 1 line

[1] http://www.spinics.net/lists/arm-kernel/msg251666.html

one comment to that series:

let's make the phy names standardized, how about phy-exynos-video-mipi.c or phy-mipi-csi-dsim.c ?

Quoted 6 lines

Yes, I have been thinking about that, wasn't sure exactly what pattern to chose. I would make it phy-exynos-mipi-video.c, phy-exynos-dsim-csis.c feels a bit odd. phy-mipi-csis-dsim.c might be to generic as MIPI CSIS stands for MIPI CSI Slave and MIPI DSIM - MIPI DSI Master. And there might be (actually are) IP blocks in an SoC that use the other MIPI Aliance standards. For the HDMI PHY I guess just phy-exynos-hdmi.c could be used.

sounds good to me :-)

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130624/c4b283e8/attachment.sig>