Skip to contentSkip to conversation

PHY framework

PATCH In review Kishon Vijay Abraham I 15 participants 99 messages Jul 18, 2013 – Aug 20, 2013

Subsystems (12)
lore
Share & tools
lore
#0 lore raw

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

Exynos MIPI CSIS/DSIM PHY and Displayport PHY have started using this framework. Have included those patches also in this series.

twl4030-usb and omap-usb2 have also been adapted to this framework.

These patches are also available @
git://gitorious.org/linuxphy/linuxphy.git tags/phy-for-v3.12

Jingoo Han (3):
phy: Add driver for Exynos DP PHY
video: exynos_dp: remove non-DT support for Exynos Display Port
video: exynos_dp: Use the generic PHY driver

Kishon Vijay Abraham I (8):
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
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

Sylwester Nawrocki (4):
phy: Add driver for Exynos MIPI CSIS/DSIM DPHYs
video: exynos_mipi_dsim: Use the generic PHY driver
exynos4-is: Use the generic MIPI CSIS PHY driver
ARM: Samsung: Remove the MIPI PHY setup code

 .../devicetree/bindings/phy/phy-bindings.txt       |   66 +++
 .../devicetree/bindings/phy/samsung-phy.txt        |   22 +
 Documentation/devicetree/bindings/usb/omap-usb.txt |    5 +
 Documentation/devicetree/bindings/usb/usb-phy.txt  |    6 +
 .../devicetree/bindings/video/exynos_dp.txt        |   18 +-
 Documentation/phy.txt                              |  129 +++++
 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-exynos/include/mach/regs-pmu.h       |    5 -
 arch/arm/mach-omap2/usb-musb.c                     |    3 +
 arch/arm/mach-s5pv210/include/mach/regs-clock.h    |    4 -
 arch/arm/plat-samsung/Kconfig                      |    5 -
 arch/arm/plat-samsung/Makefile                     |    1 -
 arch/arm/plat-samsung/setup-mipiphy.c              |   60 ---
 drivers/Kconfig                                    |    2 +
 drivers/Makefile                                   |    2 +
 drivers/media/platform/exynos4-is/mipi-csis.c      |   16 +-
 drivers/phy/Kconfig                                |   28 +
 drivers/phy/Makefile                               |    7 +
 drivers/phy/phy-core.c                             |  544 ++++++++++++++++++++
 drivers/phy/phy-exynos-dp-video.c                  |  111 ++++
 drivers/phy/phy-exynos-mipi-video.c                |  169 ++++++
 drivers/usb/musb/Kconfig                           |    1 +
 drivers/usb/musb/musb_core.c                       |    1 +
 drivers/usb/musb/musb_core.h                       |    3 +
 drivers/usb/musb/omap2430.c                        |   26 +-
 drivers/usb/phy/Kconfig                            |    1 +
 drivers/usb/phy/phy-omap-usb2.c                    |   60 ++-
 drivers/usb/phy/phy-twl4030-usb.c                  |   63 ++-
 drivers/video/exynos/Kconfig                       |    2 +-
 drivers/video/exynos/exynos_dp_core.c              |  132 ++---
 drivers/video/exynos/exynos_dp_core.h              |  110 ++++
 drivers/video/exynos/exynos_dp_reg.c               |    2 -
 drivers/video/exynos/exynos_mipi_dsi.c             |   19 +-
 include/linux/phy/phy.h                            |  344 +++++++++++++
 include/linux/platform_data/mipi-csis.h            |   11 +-
 include/linux/usb/musb.h                           |    3 +
 include/video/exynos_dp.h                          |  131 -----
 include/video/exynos_mipi_dsim.h                   |    6 +-
 43 files changed, 1746 insertions(+), 389 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-bindings.txt
 create mode 100644 Documentation/devicetree/bindings/phy/samsung-phy.txt
 create mode 100644 Documentation/phy.txt
 delete mode 100644 arch/arm/plat-samsung/setup-mipiphy.c
 create mode 100644 drivers/phy/Kconfig
 create mode 100644 drivers/phy/Makefile
 create mode 100644 drivers/phy/phy-core.c
 create mode 100644 drivers/phy/phy-exynos-dp-video.c
 create mode 100644 drivers/phy/phy-exynos-mipi-video.c
 create mode 100644 include/linux/phy/phy.h
 delete mode 100644 include/video/exynos_dp.h
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/15 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                              |  129 +++++
 MAINTAINERS                                        |    7 +
 drivers/Kconfig                                    |    2 +
 drivers/Makefile                                   |    2 +
 drivers/phy/Kconfig                                |   13 +
 drivers/phy/Makefile                               |    5 +
 drivers/phy/phy-core.c                             |  544 ++++++++++++++++++++
 include/linux/phy/phy.h                            |  344 +++++++++++++
 9 files changed, 1112 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 +129 -0

129 lines not on this page · raw message

MAINTAINERS +7 -0
index bf61e04..dd03889 100644
@@ -3594,6 +3594,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 aa43b91..8f45144 100644
@@ -166,4 +166,6 @@ source "drivers/reset/Kconfig"
 
 source "drivers/fmc/Kconfig"
 
+source "drivers/phy/Kconfig"
+
 endmenu
drivers/Makefile +2 -0
index ab93de8..687da89 100644
@@ -8,6 +8,8 @@
 obj-y				+= irqchip/
 obj-y				+= bus/
 
+obj-$(CONFIG_GENERIC_PHY)	+= 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..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 +544 -0

544 lines not on this page · raw message

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

344 lines not on this page · raw message

Signature · 1 line
1.7.10.4
maintainer
#2 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Documentation/phy.txt line 43

Quoted 11 lines · Kishon Vijay Abraham I
Documentation/phy.txt new file +11 -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));
+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))
+
+__of_phy_provider_register and __devm_of_phy_provider_register can be used to
+register the phy_provider and it takes device, owner and of_xlate as
+arguments. For the dt boot case, all PHY providers should use one of the above
+2 APIs to register the PHY provider.

Why do you have __ for the prefix of a public function? Is that really the way that OF handles this type of thing?

Quoted 6 lines
drivers/phy/Kconfig new file +3 -0
@@ -0,0 +1,13 @@
+#
+# PHY
+#

drivers/phy/Kconfig line 13

Quoted 10 lines
drivers/phy/Kconfig new file +10 -0
+
+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.

Again, please reverse this. The drivers that use it should select it, not depend on it, which will then enable this option. I will never know if I need to enable it, and based on your follow-on patches, if I don't, drivers that were working just fine, now disappeared from my build, which isn't nice, and a pain to notice and fix up.

Quoted 28 lines
drivers/phy/Kconfig new file +28 -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
+ *
+ * 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)
+{
+	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);

drivers/phy/Kconfig

Quoted 10 lines
drivers/phy/Kconfig new file +10 -0
+	mutex_init(&phy->mutex);
+
+	phy->dev.class = phy_class;
+	phy->dev.parent = dev;
+	phy->dev.of_node = dev->of_node;
+	phy->id = id;
+	phy->ops = ops;
+	phy->label = kstrdup(label, GFP_KERNEL);
+
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);

Your naming is odd, no "phy" anywhere in it? You rely on the sender to never send a duplicate name.id pair? Why not create your own ids based on the number of phys in the system, like almost all other classes and subsystems do?

drivers/phy/Kconfig

Quoted 4 lines
drivers/phy/Kconfig new file +4 -0
+static inline int phy_pm_runtime_get(struct phy *phy)
+{
+	if (WARN(IS_ERR(phy), "Invalid PHY reference\n"))
+		return -EINVAL;

Why would phy ever not be valid and a error pointer? And why dump the stack if that happens, that seems really extreme.

drivers/phy/Kconfig

Quoted 6 lines
drivers/phy/Kconfig new file +6 -0
+
+	if (!pm_runtime_enabled(&phy->dev))
+		return -ENOTSUPP;
+
+	return pm_runtime_get(&phy->dev);
+}

This, and the other inline functions in this .h file seem huge, why are they inline and not in the .c file? There's no speed issues, and it should save space overall in the .c file. Please move them.

Quoted 78 lines
drivers/phy/Kconfig new file +78 -0
+static inline int phy_init(struct phy *phy)
+{
+	int ret;
+
+	ret = phy_pm_runtime_get_sync(phy);
+	if (ret < 0 && ret != -ENOTSUPP)
+		return ret;
+
+	mutex_lock(&phy->mutex);
+	if (phy->init_count++ == 0 && phy->ops->init) {
+		ret = phy->ops->init(phy);
+		if (ret < 0) {
+			dev_err(&phy->dev, "phy init failed --> %d\n", ret);
+			goto out;
+		}
+	}
+
+out:
+	mutex_unlock(&phy->mutex);
+	phy_pm_runtime_put(phy);
+	return ret;
+}
+
+static inline int phy_exit(struct phy *phy)
+{
+	int ret;
+
+	ret = phy_pm_runtime_get_sync(phy);
+	if (ret < 0 && ret != -ENOTSUPP)
+		return ret;
+
+	mutex_lock(&phy->mutex);
+	if (--phy->init_count == 0 && phy->ops->exit) {
+		ret = phy->ops->exit(phy);
+		if (ret < 0) {
+			dev_err(&phy->dev, "phy exit failed --> %d\n", ret);
+			goto out;
+		}
+	}
+
+out:
+	mutex_unlock(&phy->mutex);
+	phy_pm_runtime_put(phy);
+	return ret;
+}
+
+static inline int phy_power_on(struct phy *phy)
+{
+	int ret = -ENOTSUPP;
+
+	ret = phy_pm_runtime_get_sync(phy);
+	if (ret < 0 && ret != -ENOTSUPP)
+		return ret;
+
+	mutex_lock(&phy->mutex);
+	if (phy->power_count++ == 0 && phy->ops->power_on) {
+		ret = phy->ops->power_on(phy);
+		if (ret < 0) {
+			dev_err(&phy->dev, "phy poweron failed --> %d\n", ret);
+			goto out;
+		}
+	}
+
+out:
+	mutex_unlock(&phy->mutex);
+
+	return ret;
+}
+
+static inline int phy_power_off(struct phy *phy)
+{
+	int ret = -ENOTSUPP;
+
+	mutex_lock(&phy->mutex);
+	if (--phy->power_count == 0 && phy->ops->power_off) {
+		ret =  phy->ops->power_off(phy);
+		if (ret < 0) {
+			dev_err(&phy->dev, "phy poweroff failed --> %d\n", ret);

drivers/phy/Kconfig

Quoted 10 lines
drivers/phy/Kconfig new file +10 -0
+			goto out;
+		}
+	}
+
+out:
+	mutex_unlock(&phy->mutex);
+	phy_pm_runtime_put(phy);
+
+	return ret;
+}

Look at those 3 functions, they are all "real" and not an inline function at all, please move them.

thanks,

greg k-h

#3 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi,

Quoted 15 lines · Greg KH

Documentation/phy.txt line 43

Quoted 11 lines · Kishon Vijay Abraham I
Documentation/phy.txt new file +11 -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));
+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))
+
+__of_phy_provider_register and __devm_of_phy_provider_register can be used to
+register the phy_provider and it takes device, owner and of_xlate as
+arguments. For the dt boot case, all PHY providers should use one of the above
+2 APIs to register the PHY provider.

Why do you have __ for the prefix of a public function? Is that really the way that OF handles this type of thing?

I have a macro of_phy_provider_register/devm_of_phy_provider_register that calls these functions and should be used by the PHY drivers. Probably I should make a mention of it in the Documentation.

Quoted 15 lines
Quoted 15 lines
drivers/phy/Kconfig new file +11 -0
@@ -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
Quoted 8 lines

drivers/phy/Kconfig line 13

Quoted 2 lines
drivers/phy/Kconfig new file +2 -0
+	  API by which phy drivers can create PHY using the phy framework and
+	  phy users can obtain reference to the PHY.

Again, please reverse this. The drivers that use it should select it, not depend on it, which will then enable this option. I will never know if I need to enable it, and based on your follow-on patches, if I don't, drivers that were working just fine, now disappeared from my build, which isn't nice, and a pain to notice and fix up.

ok.

Quoted 36 lines
Quoted 36 lines
drivers/phy/Kconfig new file +35 -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
+ *
+ * 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)
+{
+	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);
+	mutex_init(&phy->mutex);
+
+	phy->dev.class = phy_class;
+	phy->dev.parent = dev;
+	phy->dev.of_node = dev->of_node;
+	phy->id = id;
+	phy->ops = ops;
Quoted 8 lines

drivers/phy/Kconfig

Quoted 3 lines
drivers/phy/Kconfig new file +3 -0
+	phy->label = kstrdup(label, GFP_KERNEL);
+
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);

Your naming is odd, no "phy" anywhere in it? You rely on the sender to never send a duplicate name.id pair? Why not create your own ids based on the number of phys in the system, like almost all other classes and subsystems do?

hmm.. some PHY drivers use the id they provide to perform some of their internal operation as in [1] (This is used only if a single PHY provider implements multiple PHYS). Probably I'll add an option like PLATFORM_DEVID_AUTO to give the PHY drivers an option to use auto id.

[1] ->
http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

Quoted 8 lines

drivers/phy/Kconfig

Quoted 5 lines
drivers/phy/Kconfig new file +4 -0
+static inline int phy_pm_runtime_get(struct phy *phy)
+{
+	if (WARN(IS_ERR(phy), "Invalid PHY reference\n"))
+		return -EINVAL;

Why would phy ever not be valid and a error pointer? And why dump the stack if that happens, that seems really extreme.

hmm.. there might be cases where the same controller in one soc needs PHY control and in some other soc does not need PHY control. In such cases, we might get error pointer here.
I'll change WARN to dev_err.

Quoted 11 lines

drivers/phy/Kconfig

Quoted 7 lines
drivers/phy/Kconfig new file +6 -0
+
+	if (!pm_runtime_enabled(&phy->dev))
+		return -ENOTSUPP;
+
+	return pm_runtime_get(&phy->dev);
+}

This, and the other inline functions in this .h file seem huge, why are they inline and not in the .c file? There's no speed issues, and it should save space overall in the .c file. Please move them.

ok

Quoted 85 lines
Quoted 85 lines
drivers/phy/Kconfig new file +83 -0
+static inline int phy_init(struct phy *phy)
+{
+	int ret;
+
+	ret = phy_pm_runtime_get_sync(phy);
+	if (ret < 0 && ret != -ENOTSUPP)
+		return ret;
+
+	mutex_lock(&phy->mutex);
+	if (phy->init_count++ == 0 && phy->ops->init) {
+		ret = phy->ops->init(phy);
+		if (ret < 0) {
+			dev_err(&phy->dev, "phy init failed --> %d\n", ret);
+			goto out;
+		}
+	}
+
+out:
+	mutex_unlock(&phy->mutex);
+	phy_pm_runtime_put(phy);
+	return ret;
+}
+
+static inline int phy_exit(struct phy *phy)
+{
+	int ret;
+
+	ret = phy_pm_runtime_get_sync(phy);
+	if (ret < 0 && ret != -ENOTSUPP)
+		return ret;
+
+	mutex_lock(&phy->mutex);
+	if (--phy->init_count == 0 && phy->ops->exit) {
+		ret = phy->ops->exit(phy);
+		if (ret < 0) {
+			dev_err(&phy->dev, "phy exit failed --> %d\n", ret);
+			goto out;
+		}
+	}
+
+out:
+	mutex_unlock(&phy->mutex);
+	phy_pm_runtime_put(phy);
+	return ret;
+}
+
+static inline int phy_power_on(struct phy *phy)
+{
+	int ret = -ENOTSUPP;
+
+	ret = phy_pm_runtime_get_sync(phy);
+	if (ret < 0 && ret != -ENOTSUPP)
+		return ret;
+
+	mutex_lock(&phy->mutex);
+	if (phy->power_count++ == 0 && phy->ops->power_on) {
+		ret = phy->ops->power_on(phy);
+		if (ret < 0) {
+			dev_err(&phy->dev, "phy poweron failed --> %d\n", ret);
+			goto out;
+		}
+	}
+
+out:
+	mutex_unlock(&phy->mutex);
+
+	return ret;
+}
+
+static inline int phy_power_off(struct phy *phy)
+{
+	int ret = -ENOTSUPP;
+
+	mutex_lock(&phy->mutex);
+	if (--phy->power_count == 0 && phy->ops->power_off) {
+		ret =  phy->ops->power_off(phy);
+		if (ret < 0) {
+			dev_err(&phy->dev, "phy poweroff failed --> %d\n", ret);
+			goto out;
+		}
+	}
+
+out:
Quoted 8 lines

drivers/phy/Kconfig

Quoted 5 lines
drivers/phy/Kconfig new file +5 -0
+	mutex_unlock(&phy->mutex);
+	phy_pm_runtime_put(phy);
+
+	return ret;
+}

Look at those 3 functions, they are all "real" and not an inline function at all, please move them.

Alright.

Thanks
Kishon

maintainer
#4 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 19 lines · Kishon Vijay Abraham I

Hi,

Quoted 15 lines · Greg KH

Documentation/phy.txt line 43

Quoted 11 lines · Kishon Vijay Abraham I
Documentation/phy.txt new file +11 -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));
+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))
+
+__of_phy_provider_register and __devm_of_phy_provider_register can be used to
+register the phy_provider and it takes device, owner and of_xlate as
+arguments. For the dt boot case, all PHY providers should use one of the above
+2 APIs to register the PHY provider.

Why do you have __ for the prefix of a public function? Is that really the way that OF handles this type of thing?

Quoted 3 lines

I have a macro of_phy_provider_register/devm_of_phy_provider_register that calls these functions and should be used by the PHY drivers. Probably I should make a mention of it in the Documentation.

Yes, mention those as you never want to be calling __* functions directly, right?

Quoted 7 lines
Quoted 6 lines

drivers/phy/phy-core.c line 314

Quoted 1 line
drivers/phy/phy-core.c new file +1 -0
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);

Your naming is odd, no "phy" anywhere in it? You rely on the sender to never send a duplicate name.id pair? Why not create your own ids based on the number of phys in the system, like almost all other classes and subsystems do?

Quoted 7 lines

hmm.. some PHY drivers use the id they provide to perform some of their internal operation as in [1] (This is used only if a single PHY provider implements multiple PHYS). Probably I'll add an option like PLATFORM_DEVID_AUTO to give the PHY drivers an option to use auto id.

[1] ->
http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

No, who cares about the id? No one outside of the phy core ever should, because you pass back the only pointer that they really do care about, if they need to do anything with the device. Use that, and then you can rip out all of the "search for a phy by a string" logic, as that's not needed either. Just stick to the pointer, it's easier, and safer that way.

Quoted 8 lines
Quoted 7 lines

include/linux/phy/phy.h line 192

Quoted 4 lines
include/linux/phy/phy.h new file +4 -0
+static inline int phy_pm_runtime_get(struct phy *phy)
+{
+	if (WARN(IS_ERR(phy), "Invalid PHY reference\n"))
+		return -EINVAL;

Why would phy ever not be valid and a error pointer? And why dump the stack if that happens, that seems really extreme.

Quoted 4 lines

hmm.. there might be cases where the same controller in one soc needs PHY control and in some other soc does not need PHY control. In such cases, we might get error pointer here.
I'll change WARN to dev_err.

I still don't understand. You have control over the code that calls these functions, just ensure that they pass in a valid pointer, it's that simple. Or am I missing something?

thanks,

greg k-h

#5 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi,

Quoted 20 lines · Greg KH
Quoted 19 lines · Kishon Vijay Abraham I

Hi,

Quoted 15 lines · Greg KH

Documentation/phy.txt line 43

Quoted 11 lines · Kishon Vijay Abraham I
Documentation/phy.txt new file +11 -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));
+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))
+
+__of_phy_provider_register and __devm_of_phy_provider_register can be used to
+register the phy_provider and it takes device, owner and of_xlate as
+arguments. For the dt boot case, all PHY providers should use one of the above
+2 APIs to register the PHY provider.

Why do you have __ for the prefix of a public function? Is that really the way that OF handles this type of thing?

Quoted 6 lines
Quoted 3 lines

I have a macro of_phy_provider_register/devm_of_phy_provider_register that calls these functions and should be used by the PHY drivers. Probably I should make a mention of it in the Documentation.

Yes, mention those as you never want to be calling __* functions directly, right?

correct.

Quoted 13 lines
Quoted 13 lines
Quoted 7 lines

drivers/phy/phy-core.c line 314

Quoted 2 lines
drivers/phy/phy-core.c new file +1 -0
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);

Your naming is odd, no "phy" anywhere in it? You rely on the sender to never send a duplicate name.id pair? Why not create your own ids based on the number of phys in the system, like almost all other classes and subsystems do?

hmm.. some PHY drivers use the id they provide to perform some of their internal operation as in [1] (This is used only if a single PHY provider implements multiple PHYS). Probably I'll add an option like PLATFORM_DEVID_AUTO to give the PHY drivers an option to use auto id.

Quoted 6 lines
Quoted 2 lines

[1] ->
http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

No, who cares about the id? No one outside of the phy core ever should, because you pass back the only pointer that they really do care about, if they need to do anything with the device. Use that, and then you can

hmm.. ok.

Quoted 1 line

rip out all of the "search for a phy by a string" logic, as that's not

Actually this is needed for non-dt boot case. In the case of dt boot, we use a phandle by which the controller can get a reference to the phy. But in the case of non-dt boot, the controller can get a reference to the phy only by label.

Quoted 11 lines

needed either. Just stick to the pointer, it's easier, and safer that way.

Quoted 8 lines
Quoted 7 lines

include/linux/phy/phy.h line 192

Quoted 4 lines
include/linux/phy/phy.h new file +4 -0
+static inline int phy_pm_runtime_get(struct phy *phy)
+{
+	if (WARN(IS_ERR(phy), "Invalid PHY reference\n"))
+		return -EINVAL;

Why would phy ever not be valid and a error pointer? And why dump the stack if that happens, that seems really extreme.

Quoted 8 lines
Quoted 4 lines

hmm.. there might be cases where the same controller in one soc needs PHY control and in some other soc does not need PHY control. In such cases, we might get error pointer here.
I'll change WARN to dev_err.

I still don't understand. You have control over the code that calls these functions, just ensure that they pass in a valid pointer, it's that simple. Or am I missing something?

You are right. Valid pointer check can be done in controller code as well.

Thanks
Kishon

maintainer
#6 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 19 lines · Kishon Vijay Abraham I
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

drivers/phy/phy-core.c line 314

Quoted 1 line
drivers/phy/phy-core.c new file +1 -0
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);

Your naming is odd, no "phy" anywhere in it? You rely on the sender to never send a duplicate name.id pair? Why not create your own ids based on the number of phys in the system, like almost all other classes and subsystems do?

hmm.. some PHY drivers use the id they provide to perform some of their internal operation as in [1] (This is used only if a single PHY provider implements multiple PHYS). Probably I'll add an option like PLATFORM_DEVID_AUTO to give the PHY drivers an option to use auto id.

Quoted 6 lines
Quoted 2 lines

[1] ->
http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

No, who cares about the id? No one outside of the phy core ever should, because you pass back the only pointer that they really do care about, if they need to do anything with the device. Use that, and then you can

Quoted 7 lines

hmm.. ok.

Quoted 1 line

rip out all of the "search for a phy by a string" logic, as that's not

Actually this is needed for non-dt boot case. In the case of dt boot, we use a phandle by which the controller can get a reference to the phy. But in the case of non-dt boot, the controller can get a reference to the phy only by label.

I don't understand. They registered the phy, and got back a pointer to it. Why can't they save it in their local structure to use it again later if needed? They should never have to "ask" for the device, as the device id might be unknown if there are multiple devices in the system.

Or am I missing something?

thanks,

greg k-h

#7 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi,

Quoted 24 lines · Greg KH
Quoted 23 lines · Kishon Vijay Abraham I
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

drivers/phy/phy-core.c line 314

Quoted 1 line
drivers/phy/phy-core.c new file +1 -0
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);

Your naming is odd, no "phy" anywhere in it? You rely on the sender to never send a duplicate name.id pair? Why not create your own ids based on the number of phys in the system, like almost all other classes and subsystems do?

hmm.. some PHY drivers use the id they provide to perform some of their internal operation as in [1] (This is used only if a single PHY provider implements multiple PHYS). Probably I'll add an option like PLATFORM_DEVID_AUTO to give the PHY drivers an option to use auto id.

Quoted 6 lines
Quoted 2 lines

[1] ->
http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

No, who cares about the id? No one outside of the phy core ever should, because you pass back the only pointer that they really do care about, if they need to do anything with the device. Use that, and then you can

hmm.. ok.

Quoted 1 line

rip out all of the "search for a phy by a string" logic, as that's not

Quoted 7 lines
Quoted 3 lines

Actually this is needed for non-dt boot case. In the case of dt boot, we use a phandle by which the controller can get a reference to the phy. But in the case of non-dt boot, the controller can get a reference to the phy only by label.

I don't understand. They registered the phy, and got back a pointer to it. Why can't they save it in their local structure to use it again later if needed? They should never have to "ask" for the device, as the

One is a *PHY provider* driver which is a driver for some PHY device. This will use phy_create to create the phy.
The other is a *PHY consumer* driver which might be any controller driver (can be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference to the phy (by *phandle* in the case of dt boot and *label* in the case of non-dt boot).

Quoted 1 line

device id might be unknown if there are multiple devices in the system.

I agree with you on the device id part. That need not be known to the PHY driver.

Thanks
Kishon

maintainer
#8 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 35 lines · Kishon Vijay Abraham I

Hi,

Quoted 24 lines · Greg KH
Quoted 23 lines · Kishon Vijay Abraham I
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);

Your naming is odd, no "phy" anywhere in it? You rely on the sender to never send a duplicate name.id pair? Why not create your own ids based on the number of phys in the system, like almost all other classes and subsystems do?

hmm.. some PHY drivers use the id they provide to perform some of their internal operation as in [1] (This is used only if a single PHY provider implements multiple PHYS). Probably I'll add an option like PLATFORM_DEVID_AUTO to give the PHY drivers an option to use auto id.

Quoted 6 lines
Quoted 2 lines

[1] ->
http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

No, who cares about the id? No one outside of the phy core ever should, because you pass back the only pointer that they really do care about, if they need to do anything with the device. Use that, and then you can

hmm.. ok.

Quoted 1 line

rip out all of the "search for a phy by a string" logic, as that's not

Quoted 7 lines
Quoted 3 lines

Actually this is needed for non-dt boot case. In the case of dt boot, we use a phandle by which the controller can get a reference to the phy. But in the case of non-dt boot, the controller can get a reference to the phy only by label.

I don't understand. They registered the phy, and got back a pointer to it. Why can't they save it in their local structure to use it again later if needed? They should never have to "ask" for the device, as the

Quoted 8 lines

One is a *PHY provider* driver which is a driver for some PHY device. This will use phy_create to create the phy.
The other is a *PHY consumer* driver which might be any controller driver (can be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference to the phy (by *phandle* in the case of dt boot and *label* in the case of non-dt boot).

Quoted 1 line

device id might be unknown if there are multiple devices in the system.

I agree with you on the device id part. That need not be known to the PHY driver.

How does a consumer know which "label" to use in a non-dt system if there are multiple PHYs in the system?

Do you have any drivers that are non-dt using this yet?

greg k-h

#9 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi,

Quoted 41 lines · Greg KH
Quoted 40 lines · Kishon Vijay Abraham I

Hi,

Quoted 24 lines · Greg KH
Quoted 23 lines · Kishon Vijay Abraham I
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);

Your naming is odd, no "phy" anywhere in it? You rely on the sender to never send a duplicate name.id pair? Why not create your own ids based on the number of phys in the system, like almost all other classes and subsystems do?

hmm.. some PHY drivers use the id they provide to perform some of their internal operation as in [1] (This is used only if a single PHY provider implements multiple PHYS). Probably I'll add an option like PLATFORM_DEVID_AUTO to give the PHY drivers an option to use auto id.

Quoted 6 lines
Quoted 2 lines

[1] ->
http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

No, who cares about the id? No one outside of the phy core ever should, because you pass back the only pointer that they really do care about, if they need to do anything with the device. Use that, and then you can

hmm.. ok.

Quoted 1 line

rip out all of the "search for a phy by a string" logic, as that's not

Quoted 7 lines
Quoted 3 lines

Actually this is needed for non-dt boot case. In the case of dt boot, we use a phandle by which the controller can get a reference to the phy. But in the case of non-dt boot, the controller can get a reference to the phy only by label.

I don't understand. They registered the phy, and got back a pointer to it. Why can't they save it in their local structure to use it again later if needed? They should never have to "ask" for the device, as the

One is a *PHY provider* driver which is a driver for some PHY device. This will use phy_create to create the phy.
The other is a *PHY consumer* driver which might be any controller driver (can be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference to the phy (by *phandle* in the case of dt boot and *label* in the case of non-dt boot).

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

device id might be unknown if there are multiple devices in the system.

I agree with you on the device id part. That need not be known to the PHY driver.

How does a consumer know which "label" to use in a non-dt system if there are multiple PHYs in the system?

That should be passed using platform data.

Quoted 2 lines

Do you have any drivers that are non-dt using this yet?

yes. tw4030 (used in OMAP3) supports non-dt.
[PATCH 04/15] ARM: OMAP: USB: Add phy binding information [PATCH 06/15] usb: musb: omap2430: use the new generic PHY framework of this patch series shows how it's used.

Thanks
Kishon

#10 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 44 lines · Kishon Vijay Abraham I

Hi,

Quoted 41 lines · Greg KH
Quoted 40 lines · Kishon Vijay Abraham I

Hi,

Quoted 24 lines · Greg KH
Quoted 23 lines · Kishon Vijay Abraham I
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);

Your naming is odd, no "phy" anywhere in it? You rely on the sender to never send a duplicate name.id pair? Why not create your own ids based on the number of phys in the system, like almost all other classes and subsystems do?

hmm.. some PHY drivers use the id they provide to perform some of their internal operation as in [1] (This is used only if a single PHY provider implements multiple PHYS). Probably I'll add an option like PLATFORM_DEVID_AUTO to give the PHY drivers an option to use auto id.

Quoted 6 lines
Quoted 2 lines

[1] ->
http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

No, who cares about the id? No one outside of the phy core ever should, because you pass back the only pointer that they really do care about, if they need to do anything with the device. Use that, and then you can

hmm.. ok.

Quoted 1 line

rip out all of the "search for a phy by a string" logic, as that's not

Quoted 7 lines
Quoted 3 lines

Actually this is needed for non-dt boot case. In the case of dt boot, we use a phandle by which the controller can get a reference to the phy. But in the case of non-dt boot, the controller can get a reference to the phy only by label.

I don't understand. They registered the phy, and got back a pointer to it. Why can't they save it in their local structure to use it again later if needed? They should never have to "ask" for the device, as the

One is a *PHY provider* driver which is a driver for some PHY device. This will use phy_create to create the phy.
The other is a *PHY consumer* driver which might be any controller driver (can be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference to the phy (by *phandle* in the case of dt boot and *label* in the case of non-dt boot).

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

device id might be unknown if there are multiple devices in the system.

I agree with you on the device id part. That need not be known to the PHY driver.

How does a consumer know which "label" to use in a non-dt system if there are multiple PHYs in the system?

That should be passed using platform data.

I don't think that's right. That's just like passing clock names in platform data, which I believe is frowned upon.

Instead, why not take the approach that e.g. regulators have taken? Each driver defines the names of the objects that it requires. There is a table (registered by a board file) that has lookup key (device name, regulator name), and the output is the regulator device (or global regulator name).

This is almost the same way that DT works, except that in DT, the table is represented as properties in the DT. The DT binding defines the names of those properties, or the strings that must be in the foo-names properties, just like a driver in non-DT Linux is going to define the names it expects to be provided with.

That way, you don't need platform data to define the names.

#11 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi,

Quoted 52 lines · Stephen Warren
Quoted 51 lines · Kishon Vijay Abraham I

Hi,

Quoted 47 lines · Greg KH
Quoted 35 lines · Kishon Vijay Abraham I

Hi,

Quoted 24 lines · Greg KH
Quoted 23 lines · Kishon Vijay Abraham I
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);

Your naming is odd, no "phy" anywhere in it? You rely on the sender to never send a duplicate name.id pair? Why not create your own ids based on the number of phys in the system, like almost all other classes and subsystems do?

hmm.. some PHY drivers use the id they provide to perform some of their internal operation as in [1] (This is used only if a single PHY provider implements multiple PHYS). Probably I'll add an option like PLATFORM_DEVID_AUTO to give the PHY drivers an option to use auto id.

Quoted 6 lines
Quoted 2 lines

[1] ->
http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

No, who cares about the id? No one outside of the phy core ever should, because you pass back the only pointer that they really do care about, if they need to do anything with the device. Use that, and then you can

hmm.. ok.

Quoted 1 line

rip out all of the "search for a phy by a string" logic, as that's not

Quoted 7 lines
Quoted 3 lines

Actually this is needed for non-dt boot case. In the case of dt boot, we use a phandle by which the controller can get a reference to the phy. But in the case of non-dt boot, the controller can get a reference to the phy only by label.

I don't understand. They registered the phy, and got back a pointer to it. Why can't they save it in their local structure to use it again later if needed? They should never have to "ask" for the device, as the

Quoted 8 lines

One is a *PHY provider* driver which is a driver for some PHY device. This will use phy_create to create the phy.
The other is a *PHY consumer* driver which might be any controller driver (can be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference to the phy (by *phandle* in the case of dt boot and *label* in the case of non-dt boot).

Quoted 1 line

device id might be unknown if there are multiple devices in the system.

I agree with you on the device id part. That need not be known to the PHY driver.

How does a consumer know which "label" to use in a non-dt system if there are multiple PHYs in the system?

Quoted 8 lines
Quoted 1 line

That should be passed using platform data.

I don't think that's right. That's just like passing clock names in platform data, which I believe is frowned upon.

Instead, why not take the approach that e.g. regulators have taken? Each driver defines the names of the objects that it requires. There is a table (registered by a board file) that has lookup key (device name,

We were using a similar approach with USB PHY layer but things started breaking after the device names are created using PLATFORM_DEVID_AUTO. Now theres no way to reliably know the device names in advance. Btw I had such device name binding in my v3 of this patch series [1] and had some discussion with Grant during that time [2].

[1] ->
http://archive.arm.linux.org.uk/lurker/message/20130320.091200.721a6fb5.hu.html
[2] -> https://lkml.org/lkml/2013/4/22/26

Thanks
Kishon

maintainer
#12 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

In reply to Kishon Vijay Abraham I
Quoted 44 lines · Kishon Vijay Abraham I

Hi,

Quoted 41 lines · Greg KH
Quoted 40 lines · Kishon Vijay Abraham I

Hi,

Quoted 24 lines · Greg KH
Quoted 23 lines · Kishon Vijay Abraham I
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);

Your naming is odd, no "phy" anywhere in it? You rely on the sender to never send a duplicate name.id pair? Why not create your own ids based on the number of phys in the system, like almost all other classes and subsystems do?

hmm.. some PHY drivers use the id they provide to perform some of their internal operation as in [1] (This is used only if a single PHY provider implements multiple PHYS). Probably I'll add an option like PLATFORM_DEVID_AUTO to give the PHY drivers an option to use auto id.

Quoted 6 lines
Quoted 2 lines

[1] ->
http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

No, who cares about the id? No one outside of the phy core ever should, because you pass back the only pointer that they really do care about, if they need to do anything with the device. Use that, and then you can

hmm.. ok.

Quoted 1 line

rip out all of the "search for a phy by a string" logic, as that's not

Quoted 7 lines
Quoted 3 lines

Actually this is needed for non-dt boot case. In the case of dt boot, we use a phandle by which the controller can get a reference to the phy. But in the case of non-dt boot, the controller can get a reference to the phy only by label.

I don't understand. They registered the phy, and got back a pointer to it. Why can't they save it in their local structure to use it again later if needed? They should never have to "ask" for the device, as the

One is a *PHY provider* driver which is a driver for some PHY device. This will use phy_create to create the phy.
The other is a *PHY consumer* driver which might be any controller driver (can be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference to the phy (by *phandle* in the case of dt boot and *label* in the case of non-dt boot).

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

device id might be unknown if there are multiple devices in the system.

I agree with you on the device id part. That need not be known to the PHY driver.

How does a consumer know which "label" to use in a non-dt system if there are multiple PHYs in the system?

That should be passed using platform data.

Ick, don't pass strings around, pass pointers. If you have platform data you can get to, then put the pointer there, don't use a "name".

thanks,

greg k-h

#13 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi,

Quoted 49 lines · Greg KH
Quoted 48 lines · Kishon Vijay Abraham I

Hi,

Quoted 45 lines · Greg KH
Quoted 43 lines · Kishon Vijay Abraham I

Hi,

Quoted 24 lines · Greg KH
Quoted 23 lines · Kishon Vijay Abraham I
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);

Your naming is odd, no "phy" anywhere in it? You rely on the sender to never send a duplicate name.id pair? Why not create your own ids based on the number of phys in the system, like almost all other classes and subsystems do?

hmm.. some PHY drivers use the id they provide to perform some of their internal operation as in [1] (This is used only if a single PHY provider implements multiple PHYS). Probably I'll add an option like PLATFORM_DEVID_AUTO to give the PHY drivers an option to use auto id.

Quoted 6 lines
Quoted 2 lines

[1] ->
http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

No, who cares about the id? No one outside of the phy core ever should, because you pass back the only pointer that they really do care about, if they need to do anything with the device. Use that, and then you can

hmm.. ok.

Quoted 1 line

rip out all of the "search for a phy by a string" logic, as that's not

Quoted 7 lines
Quoted 3 lines

Actually this is needed for non-dt boot case. In the case of dt boot, we use a phandle by which the controller can get a reference to the phy. But in the case of non-dt boot, the controller can get a reference to the phy only by label.

I don't understand. They registered the phy, and got back a pointer to it. Why can't they save it in their local structure to use it again later if needed? They should never have to "ask" for the device, as the

One is a *PHY provider* driver which is a driver for some PHY device. This will use phy_create to create the phy.
The other is a *PHY consumer* driver which might be any controller driver (can be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference to the phy (by *phandle* in the case of dt boot and *label* in the case of non-dt boot).

Quoted 1 line

device id might be unknown if there are multiple devices in the system.

I agree with you on the device id part. That need not be known to the PHY driver.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

How does a consumer know which "label" to use in a non-dt system if there are multiple PHYs in the system?

That should be passed using platform data.

Ick, don't pass strings around, pass pointers. If you have platform data you can get to, then put the pointer there, don't use a "name".

I don't think I understood you here :-s We wont have phy pointer when we create the device for the controller no?(it'll be done in board file). Probably I'm missing something.

Thanks
Kishon

maintainer
#14 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 55 lines · Kishon Vijay Abraham I

Hi,

Quoted 52 lines · Greg KH
Quoted 51 lines · Kishon Vijay Abraham I

Hi,

Quoted 47 lines · Greg KH
Quoted 35 lines · Kishon Vijay Abraham I

Hi,

Quoted 24 lines · Greg KH
Quoted 23 lines · Kishon Vijay Abraham I
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	ret = dev_set_name(&phy->dev, "%s.%d", dev_name(dev), id);

Your naming is odd, no "phy" anywhere in it? You rely on the sender to never send a duplicate name.id pair? Why not create your own ids based on the number of phys in the system, like almost all other classes and subsystems do?

hmm.. some PHY drivers use the id they provide to perform some of their internal operation as in [1] (This is used only if a single PHY provider implements multiple PHYS). Probably I'll add an option like PLATFORM_DEVID_AUTO to give the PHY drivers an option to use auto id.

Quoted 6 lines
Quoted 2 lines

[1] ->
http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

No, who cares about the id? No one outside of the phy core ever should, because you pass back the only pointer that they really do care about, if they need to do anything with the device. Use that, and then you can

hmm.. ok.

Quoted 1 line

rip out all of the "search for a phy by a string" logic, as that's not

Quoted 7 lines
Quoted 3 lines

Actually this is needed for non-dt boot case. In the case of dt boot, we use a phandle by which the controller can get a reference to the phy. But in the case of non-dt boot, the controller can get a reference to the phy only by label.

I don't understand. They registered the phy, and got back a pointer to it. Why can't they save it in their local structure to use it again later if needed? They should never have to "ask" for the device, as the

Quoted 8 lines

One is a *PHY provider* driver which is a driver for some PHY device. This will use phy_create to create the phy.
The other is a *PHY consumer* driver which might be any controller driver (can be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference to the phy (by *phandle* in the case of dt boot and *label* in the case of non-dt boot).

Quoted 1 line

device id might be unknown if there are multiple devices in the system.

I agree with you on the device id part. That need not be known to the PHY driver.

How does a consumer know which "label" to use in a non-dt system if there are multiple PHYs in the system?

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

That should be passed using platform data.

Ick, don't pass strings around, pass pointers. If you have platform data you can get to, then put the pointer there, don't use a "name".

I don't think I understood you here :-s We wont have phy pointer when we create the device for the controller no?(it'll be done in board file). Probably I'm missing something.

Why will you not have that pointer? You can't rely on the "name" as the device id will not match up, so you should be able to rely on the pointer being in the structure that the board sets up, right?

Don't use names, especially as ids can, and will, change, that is going to cause big problems. Use pointers, this is C, we are supposed to be doing that :)

thanks,

greg k-h

#15 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 9 lines · Greg KH
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

That should be passed using platform data.

Ick, don't pass strings around, pass pointers. If you have platform data you can get to, then put the pointer there, don't use a "name".

I don't think I understood you here :-s We wont have phy pointer when we create the device for the controller no?(it'll be done in board file). Probably I'm missing something.

Quoted 7 lines

Why will you not have that pointer? You can't rely on the "name" as the device id will not match up, so you should be able to rely on the pointer being in the structure that the board sets up, right?

Don't use names, especially as ids can, and will, change, that is going to cause big problems. Use pointers, this is C, we are supposed to be doing that :)

Kishon, I think what Greg means is this: The name you are using must be stored somewhere in a data structure constructed by the board file, right? Or at least, associated with some data structure somehow. Otherwise the platform code wouldn't know which PHY hardware corresponded to a particular name.

Greg's suggestion is that you store the address of that data structure in the platform data instead of storing the name string. Have the consumer pass the data structure's address when it calls phy_create, instead of passing the name. Then you don't have to worry about two PHYs accidentally ending up with the same name or any other similar problems.

Alan Stern

maintainer
#16 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 25 lines · Alan Stern
Quoted 9 lines · Greg KH
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

That should be passed using platform data.

Ick, don't pass strings around, pass pointers. If you have platform data you can get to, then put the pointer there, don't use a "name".

I don't think I understood you here :-s We wont have phy pointer when we create the device for the controller no?(it'll be done in board file). Probably I'm missing something.

Quoted 7 lines

Why will you not have that pointer? You can't rely on the "name" as the device id will not match up, so you should be able to rely on the pointer being in the structure that the board sets up, right?

Don't use names, especially as ids can, and will, change, that is going to cause big problems. Use pointers, this is C, we are supposed to be doing that :)

Kishon, I think what Greg means is this: The name you are using must be stored somewhere in a data structure constructed by the board file, right? Or at least, associated with some data structure somehow. Otherwise the platform code wouldn't know which PHY hardware corresponded to a particular name.

Quoted 6 lines

Greg's suggestion is that you store the address of that data structure in the platform data instead of storing the name string. Have the consumer pass the data structure's address when it calls phy_create, instead of passing the name. Then you don't have to worry about two PHYs accidentally ending up with the same name or any other similar problems.

Close, but the issue is that whatever returns from phy_create() should then be used, no need to call any "find" functions, as you can just use the pointer that phy_create() returns. Much like all other class api functions in the kernel work.

thanks,

greg k-h

#17 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 33 lines · Greg KH
Quoted 25 lines · Alan Stern
Quoted 9 lines · Greg KH
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

That should be passed using platform data.

Ick, don't pass strings around, pass pointers. If you have platform data you can get to, then put the pointer there, don't use a "name".

I don't think I understood you here :-s We wont have phy pointer when we create the device for the controller no?(it'll be done in board file). Probably I'm missing something.

Quoted 7 lines

Why will you not have that pointer? You can't rely on the "name" as the device id will not match up, so you should be able to rely on the pointer being in the structure that the board sets up, right?

Don't use names, especially as ids can, and will, change, that is going to cause big problems. Use pointers, this is C, we are supposed to be doing that :)

Kishon, I think what Greg means is this: The name you are using must be stored somewhere in a data structure constructed by the board file, right? Or at least, associated with some data structure somehow. Otherwise the platform code wouldn't know which PHY hardware corresponded to a particular name.

Quoted 6 lines

Greg's suggestion is that you store the address of that data structure in the platform data instead of storing the name string. Have the consumer pass the data structure's address when it calls phy_create, instead of passing the name. Then you don't have to worry about two PHYs accidentally ending up with the same name or any other similar problems.

Quoted 4 lines

Close, but the issue is that whatever returns from phy_create() should then be used, no need to call any "find" functions, as you can just use the pointer that phy_create() returns. Much like all other class api functions in the kernel work.

I think the problem here is to connect two from the bus structure completely independent devices. Several frameworks (ASoC, soc-camera) had this problem and this wasn't solved until the advent of devicetrees and their phandles.
phy_create might be called from the probe function of some i2c device (the phy device) and the resulting pointer is then needed in some other platform devices (the user of the phy) probe function.
The best solution we have right now is implemented in the clk framework which uses a string matching of the device names in clk_get() (at least in the non-dt case).

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
maintainer
#18 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 39 lines · Sascha Hauer
Quoted 33 lines · Greg KH
Quoted 25 lines · Alan Stern
Quoted 9 lines · Greg KH
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

That should be passed using platform data.

Ick, don't pass strings around, pass pointers. If you have platform data you can get to, then put the pointer there, don't use a "name".

I don't think I understood you here :-s We wont have phy pointer when we create the device for the controller no?(it'll be done in board file). Probably I'm missing something.

Quoted 7 lines

Why will you not have that pointer? You can't rely on the "name" as the device id will not match up, so you should be able to rely on the pointer being in the structure that the board sets up, right?

Don't use names, especially as ids can, and will, change, that is going to cause big problems. Use pointers, this is C, we are supposed to be doing that :)

Kishon, I think what Greg means is this: The name you are using must be stored somewhere in a data structure constructed by the board file, right? Or at least, associated with some data structure somehow. Otherwise the platform code wouldn't know which PHY hardware corresponded to a particular name.

Quoted 6 lines

Greg's suggestion is that you store the address of that data structure in the platform data instead of storing the name string. Have the consumer pass the data structure's address when it calls phy_create, instead of passing the name. Then you don't have to worry about two PHYs accidentally ending up with the same name or any other similar problems.

Quoted 4 lines

Close, but the issue is that whatever returns from phy_create() should then be used, no need to call any "find" functions, as you can just use the pointer that phy_create() returns. Much like all other class api functions in the kernel work.

Quoted 10 lines

I think the problem here is to connect two from the bus structure completely independent devices. Several frameworks (ASoC, soc-camera) had this problem and this wasn't solved until the advent of devicetrees and their phandles.
phy_create might be called from the probe function of some i2c device (the phy device) and the resulting pointer is then needed in some other platform devices (the user of the phy) probe function.
The best solution we have right now is implemented in the clk framework which uses a string matching of the device names in clk_get() (at least in the non-dt case).

I would argue that clocks are wrong here as well, as others have already pointed out.

What's wrong with the platform_data structure, why can't that be used for this?

Or, if not, we can always add pointers to the platform device structure, or even the main 'struct device' as well, that's what it is there for.

thanks,

greg k-h

#19 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 51 lines · Greg KH
Quoted 39 lines · Sascha Hauer
Quoted 33 lines · Greg KH
Quoted 25 lines · Alan Stern
Quoted 9 lines · Greg KH
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

That should be passed using platform data.

Ick, don't pass strings around, pass pointers. If you have platform data you can get to, then put the pointer there, don't use a "name".

I don't think I understood you here :-s We wont have phy pointer when we create the device for the controller no?(it'll be done in board file). Probably I'm missing something.

Quoted 7 lines

Why will you not have that pointer? You can't rely on the "name" as the device id will not match up, so you should be able to rely on the pointer being in the structure that the board sets up, right?

Don't use names, especially as ids can, and will, change, that is going to cause big problems. Use pointers, this is C, we are supposed to be doing that :)

Kishon, I think what Greg means is this: The name you are using must be stored somewhere in a data structure constructed by the board file, right? Or at least, associated with some data structure somehow. Otherwise the platform code wouldn't know which PHY hardware corresponded to a particular name.

Quoted 6 lines

Greg's suggestion is that you store the address of that data structure in the platform data instead of storing the name string. Have the consumer pass the data structure's address when it calls phy_create, instead of passing the name. Then you don't have to worry about two PHYs accidentally ending up with the same name or any other similar problems.

Quoted 4 lines

Close, but the issue is that whatever returns from phy_create() should then be used, no need to call any "find" functions, as you can just use the pointer that phy_create() returns. Much like all other class api functions in the kernel work.

Quoted 10 lines

I think the problem here is to connect two from the bus structure completely independent devices. Several frameworks (ASoC, soc-camera) had this problem and this wasn't solved until the advent of devicetrees and their phandles.
phy_create might be called from the probe function of some i2c device (the phy device) and the resulting pointer is then needed in some other platform devices (the user of the phy) probe function.
The best solution we have right now is implemented in the clk framework which uses a string matching of the device names in clk_get() (at least in the non-dt case).

Quoted 5 lines

I would argue that clocks are wrong here as well, as others have already pointed out.

What's wrong with the platform_data structure, why can't that be used for this?

At the point the platform data of some driver is initialized, e.g. in board setup code the PHY pointer is not known, since the PHY supplier driver has not initialized yet. Even though we wanted to pass pointer to a PHY through some notifier call, it would have been not clear which PHY user driver should match on such notifier. A single PHY supplier driver can create M PHY objects and this needs to be mapped to N PHY user drivers. This mapping needs to be defined somewhere by the system integrator. It works well with device tree, but except that there seems to be no other reliable infrastructure in the kernel to define links/dependencies between devices, since device identifiers are not known in advance in all cases.

What Tomasz proposed seems currently most reasonable to me for non-dt.

Quoted 2 lines

Or, if not, we can always add pointers to the platform device structure, or even the main 'struct device' as well, that's what it is there for.

Still we would need to solve a problem which platform device structure gets which PHY pointer.

--
Regards,
Sylwester

#20 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 15 lines · Sylwester Nawrocki
Quoted 2 lines

What's wrong with the platform_data structure, why can't that be used for this?

At the point the platform data of some driver is initialized, e.g. in board setup code the PHY pointer is not known, since the PHY supplier driver has not initialized yet. Even though we wanted to pass pointer to a PHY through some notifier call, it would have been not clear which PHY user driver should match on such notifier. A single PHY supplier driver can create M PHY objects and this needs to be mapped to N PHY user drivers. This mapping needs to be defined somewhere by the system integrator. It works well with device tree, but except that there seems to be no other reliable infrastructure in the kernel to define links/dependencies between devices, since device identifiers are not known in advance in all cases.

Quoted 7 lines

What Tomasz proposed seems currently most reasonable to me for non-dt.

Quoted 2 lines

Or, if not, we can always add pointers to the platform device structure, or even the main 'struct device' as well, that's what it is there for.

Still we would need to solve a problem which platform device structure gets which PHY pointer.

Can you explain the issues in more detail? I don't fully understand the situation.

Here's what I think I know:

The PHY and the controller it is attached to are both physical devices.

The connection between them is hardwired by the system manufacturer and cannot be changed by software.

PHYs are generally described by fixed system-specific board files or by Device Tree information. Are they ever discovered dynamically?

Is the same true for the controllers attached to the PHYs? If not -- if both a PHY and a controller are discovered dynamically -- how does the kernel know whether they are connected to each other?

The kernel needs to know which controller is attached to which PHY. Currently this information is represented by name or ID strings embedded in platform data.

The PHY's driver (the supplier) uses the platform data to construct a platform_device structure that represents the PHY. Until this is done, the controller's driver (the client) cannot use the PHY.

Since there is no parent-child relation between the PHY and the controller, there is no guarantee that the PHY's driver will be ready when the controller's driver wants to use it. A deferred probe may be needed.

The issue (or one of the issues) in this discussion is that Greg does not like the idea of using names or IDs to associate PHYs with controllers, because they are too prone to duplications or other errors. Pointers are more reliable.

But pointers to what? Since the only data known to be available to both the PHY driver and controller driver is the platform data, the obvious answer is a pointer to platform data (either for the PHY or for the controller, or maybe both).

Probably some of the details above are wrong; please indicate where I have gone astray. Also, I'm not clear about the role played by various APIs. For example, where does phy_create() fit into this picture?

Alan Stern

#21 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi,

Quoted 33 lines · Alan Stern
Quoted 15 lines · Sylwester Nawrocki
Quoted 2 lines

What's wrong with the platform_data structure, why can't that be used for this?

At the point the platform data of some driver is initialized, e.g. in board setup code the PHY pointer is not known, since the PHY supplier driver has not initialized yet. Even though we wanted to pass pointer to a PHY through some notifier call, it would have been not clear which PHY user driver should match on such notifier. A single PHY supplier driver can create M PHY objects and this needs to be mapped to N PHY user drivers. This mapping needs to be defined somewhere by the system integrator. It works well with device tree, but except that there seems to be no other reliable infrastructure in the kernel to define links/dependencies between devices, since device identifiers are not known in advance in all cases.

Quoted 7 lines

What Tomasz proposed seems currently most reasonable to me for non-dt.

Quoted 2 lines

Or, if not, we can always add pointers to the platform device structure, or even the main 'struct device' as well, that's what it is there for.

Still we would need to solve a problem which platform device structure gets which PHY pointer.

Can you explain the issues in more detail? I don't fully understand the situation.

Here's what I think I know:

The PHY and the controller it is attached to are both physical devices.

Quoted 6 lines

The connection between them is hardwired by the system manufacturer and cannot be changed by software.

PHYs are generally described by fixed system-specific board files or by Device Tree information. Are they ever discovered dynamically?

No. They are created just like any other platform devices are created.

Quoted 5 lines

Is the same true for the controllers attached to the PHYs? If not -- if both a PHY and a controller are discovered dynamically -- how does the kernel know whether they are connected to each other?

No differences here. Both PHY and controller will have dt information or hwmod data using which platform devices will be created.

Quoted 4 lines

The kernel needs to know which controller is attached to which PHY. Currently this information is represented by name or ID strings embedded in platform data.

right. It's embedded in the platform data of the controller.

Quoted 3 lines

The PHY's driver (the supplier) uses the platform data to construct a platform_device structure that represents the PHY.

Currently the driver assigns static labels (corresponding to the label used in the platform data of the controller).

Quoted 2 lines

Until this is done, the controller's driver (the client) cannot use the PHY.

right.

Quoted 5 lines

Since there is no parent-child relation between the PHY and the controller, there is no guarantee that the PHY's driver will be ready when the controller's driver wants to use it. A deferred probe may be needed.

right.

Quoted 10 lines

The issue (or one of the issues) in this discussion is that Greg does not like the idea of using names or IDs to associate PHYs with controllers, because they are too prone to duplications or other errors. Pointers are more reliable.

But pointers to what? Since the only data known to be available to both the PHY driver and controller driver is the platform data, the obvious answer is a pointer to platform data (either for the PHY or for the controller, or maybe both).

hmm.. it's not going to be simple though as the platform device for the PHY and controller can be created in entirely different places. e.g., in some cases the PHY device is a child of some mfd core device (the device will be created in drivers/mfd) and the controller driver (usually) is created in board file. I guess then we have to come up with something to share a pointer in two different files.

Quoted 4 lines

Probably some of the details above are wrong; please indicate where I have gone astray. Also, I'm not clear about the role played by various APIs. For example, where does phy_create() fit into this picture?

phy_create is the API by which the PHY's driver (the supplier) hook into the PHY framework. It's like the controller driver will always interact with the PHY driver through the PHY framework.

Thanks
Kishon

#22 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 11 lines · Kishon Vijay Abraham I
Quoted 9 lines

The PHY and the controller it is attached to are both physical devices.

The connection between them is hardwired by the system manufacturer and cannot be changed by software.

PHYs are generally described by fixed system-specific board files or by Device Tree information. Are they ever discovered dynamically?

No. They are created just like any other platform devices are created.

Okay. Are PHYs _always_ platform devices?

Quoted 5 lines
Quoted 4 lines

Is the same true for the controllers attached to the PHYs? If not -- if both a PHY and a controller are discovered dynamically -- how does the kernel know whether they are connected to each other?

Quoted 8 lines

No differences here. Both PHY and controller will have dt information or hwmod data using which platform devices will be created.

Quoted 4 lines

The kernel needs to know which controller is attached to which PHY. Currently this information is represented by name or ID strings embedded in platform data.

right. It's embedded in the platform data of the controller.

It must also be embedded in the PHY's platform data somehow. Otherwise, how would the kernel know which PHY to use?

Quoted 27 lines
Quoted 2 lines

The PHY's driver (the supplier) uses the platform data to construct a platform_device structure that represents the PHY.

Currently the driver assigns static labels (corresponding to the label used in the platform data of the controller).

Quoted 2 lines

Until this is done, the controller's driver (the client) cannot use the PHY.

right.

Quoted 5 lines

Since there is no parent-child relation between the PHY and the controller, there is no guarantee that the PHY's driver will be ready when the controller's driver wants to use it. A deferred probe may be needed.

right.

Quoted 10 lines

The issue (or one of the issues) in this discussion is that Greg does not like the idea of using names or IDs to associate PHYs with controllers, because they are too prone to duplications or other errors. Pointers are more reliable.

But pointers to what? Since the only data known to be available to both the PHY driver and controller driver is the platform data, the obvious answer is a pointer to platform data (either for the PHY or for the controller, or maybe both).

Quoted 6 lines

hmm.. it's not going to be simple though as the platform device for the PHY and controller can be created in entirely different places. e.g., in some cases the PHY device is a child of some mfd core device (the device will be created in drivers/mfd) and the controller driver (usually) is created in board file. I guess then we have to come up with something to share a pointer in two different files.

The ability for two different source files to share a pointer to a data item defined in a third source file has been around since long before the C language was invented. :-)

In this case, it doesn't matter where the platform_device structures are created or where the driver source code is. Let's take a simple example. Suppose the system design includes a PHY named "foo". Then the board file could contain:

struct phy_info { ... } phy_foo;
EXPORT_SYMBOL_GPL(phy_foo);

and a header file would contain:

extern struct phy_info phy_foo;

The PHY supplier could then call phy_create(&phy_foo), and the PHY client could call phy_find(&phy_foo). Or something like that; make up your own structure tags and function names.

It's still possible to have conflicts, but now two PHYs with the same name (or a misspelled name somewhere) will cause an error at link time.

Quoted 7 lines
Quoted 3 lines

Probably some of the details above are wrong; please indicate where I have gone astray. Also, I'm not clear about the role played by various APIs. For example, where does phy_create() fit into this picture?

phy_create is the API by which the PHY's driver (the supplier) hook into the PHY framework. It's like the controller driver will always interact with the PHY driver through the PHY framework.

Alan Stern

#23 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi,

Quoted 8 lines · Alan Stern
Quoted 6 lines · Kishon Vijay Abraham I
Quoted 6 lines

The PHY and the controller it is attached to are both physical devices.

The connection between them is hardwired by the system manufacturer and cannot be changed by software.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

PHYs are generally described by fixed system-specific board files or by Device Tree information. Are they ever discovered dynamically?

No. They are created just like any other platform devices are created.

Okay. Are PHYs _always_ platform devices?

Not always. It can be any other device also.

Quoted 64 lines
Quoted 6 lines
Quoted 5 lines

Is the same true for the controllers attached to the PHYs? If not -- if both a PHY and a controller are discovered dynamically -- how does the kernel know whether they are connected to each other?

Quoted 8 lines

No differences here. Both PHY and controller will have dt information or hwmod data using which platform devices will be created.

Quoted 4 lines

The kernel needs to know which controller is attached to which PHY. Currently this information is represented by name or ID strings embedded in platform data.

right. It's embedded in the platform data of the controller.

It must also be embedded in the PHY's platform data somehow. Otherwise, how would the kernel know which PHY to use?

Quoted 27 lines
Quoted 2 lines

The PHY's driver (the supplier) uses the platform data to construct a platform_device structure that represents the PHY.

Currently the driver assigns static labels (corresponding to the label used in the platform data of the controller).

Quoted 2 lines

Until this is done, the controller's driver (the client) cannot use the PHY.

right.

Quoted 5 lines

Since there is no parent-child relation between the PHY and the controller, there is no guarantee that the PHY's driver will be ready when the controller's driver wants to use it. A deferred probe may be needed.

right.

Quoted 10 lines

The issue (or one of the issues) in this discussion is that Greg does not like the idea of using names or IDs to associate PHYs with controllers, because they are too prone to duplications or other errors. Pointers are more reliable.

But pointers to what? Since the only data known to be available to both the PHY driver and controller driver is the platform data, the obvious answer is a pointer to platform data (either for the PHY or for the controller, or maybe both).

Quoted 6 lines

hmm.. it's not going to be simple though as the platform device for the PHY and controller can be created in entirely different places. e.g., in some cases the PHY device is a child of some mfd core device (the device will be created in drivers/mfd) and the controller driver (usually) is created in board file. I guess then we have to come up with something to share a pointer in two different files.

The ability for two different source files to share a pointer to a data item defined in a third source file has been around since long before the C language was invented. :-)

In this case, it doesn't matter where the platform_device structures are created or where the driver source code is. Let's take a simple example. Suppose the system design includes a PHY named "foo". Then the board file could contain:

struct phy_info { ... } phy_foo;
EXPORT_SYMBOL_GPL(phy_foo);

Quoted 7 lines

and a header file would contain:

extern struct phy_info phy_foo;

The PHY supplier could then call phy_create(&phy_foo), and the PHY client could call phy_find(&phy_foo). Or something like that; make up your own structure tags and function names.

Alright. Thanks for the hint :-)

Thanks
Kishon

#24 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

In reply to Alan Stern

Hi Alan,

Quoted 7 lines · On Monday 22 of July 2013 10:44:39 Alan Stern wrote:
Quoted 6 lines · Kishon Vijay Abraham I
Quoted 6 lines

The PHY and the controller it is attached to are both physical devices.

The connection between them is hardwired by the system manufacturer and cannot be changed by software.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

PHYs are generally described by fixed system-specific board files or by Device Tree information. Are they ever discovered dynamically?

No. They are created just like any other platform devices are created.

Okay. Are PHYs _always_ platform devices?

They can be i2c, spi or any other device types as well.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Is the same true for the controllers attached to the PHYs? If not -- if both a PHY and a controller are discovered dynamically -- how does the kernel know whether they are connected to each other?

No differences here. Both PHY and controller will have dt information or hwmod data using which platform devices will be created.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

The kernel needs to know which controller is attached to which PHY. Currently this information is represented by name or ID strings embedded in platform data.

right. It's embedded in the platform data of the controller.

It must also be embedded in the PHY's platform data somehow. Otherwise, how would the kernel know which PHY to use?

By using a PHY lookup as Stephen and I suggested in our previous replies. Without any extra data in platform data. (I have even posted a code example.)

Quoted 49 lines
Quoted 28 lines
Quoted 2 lines

The PHY's driver (the supplier) uses the platform data to construct a platform_device structure that represents the PHY.

Currently the driver assigns static labels (corresponding to the label used in the platform data of the controller).

Quoted 2 lines

Until this is done, the controller's driver (the client) cannot use the PHY.

right.

Quoted 4 lines

Since there is no parent-child relation between the PHY and the controller, there is no guarantee that the PHY's driver will be ready when the controller's driver wants to use it. A deferred probe may be needed.

right.

Quoted 9 lines

The issue (or one of the issues) in this discussion is that Greg does not like the idea of using names or IDs to associate PHYs with controllers, because they are too prone to duplications or other errors. Pointers are more reliable.

But pointers to what? Since the only data known to be available to both the PHY driver and controller driver is the platform data, the obvious answer is a pointer to platform data (either for the PHY or for the controller, or maybe both).

Quoted 6 lines

hmm.. it's not going to be simple though as the platform device for the PHY and controller can be created in entirely different places. e.g., in some cases the PHY device is a child of some mfd core device (the device will be created in drivers/mfd) and the controller driver (usually) is created in board file. I guess then we have to come up with something to share a pointer in two different files.

The ability for two different source files to share a pointer to a data item defined in a third source file has been around since long before the C language was invented. :-)

In this case, it doesn't matter where the platform_device structures are created or where the driver source code is. Let's take a simple example. Suppose the system design includes a PHY named "foo". Then the board file could contain:

struct phy_info { ... } phy_foo;
EXPORT_SYMBOL_GPL(phy_foo);

and a header file would contain:

Quoted 8 lines

extern struct phy_info phy_foo;

The PHY supplier could then call phy_create(&phy_foo), and the PHY client could call phy_find(&phy_foo). Or something like that; make up your own structure tags and function names.

It's still possible to have conflicts, but now two PHYs with the same name (or a misspelled name somewhere) will cause an error at link time.

This is incorrect, sorry. First of all it's a layering violation - you export random driver-specific symbols from one driver to another. Then imagine 4 SoCs - A, B, C, D. There are two PHY types PHY1 and PHY2 and there are two types of consumer drivers (e.g. USB host controllers). Now consider following mapping:

SoC PHY consumer
A PHY1 HOST1
B PHY1 HOST2
C PHY2 HOST1
D PHY2 HOST2

So we have to be able to use any of the PHYs with any of the host drivers. This means you would have to export symbol with the same name from both PHY drivers, which obviously would not work in this case, because having both drivers enabled (in a multiplatform aware configuration) would lead to linking conflict.

Best regards,
Tomasz

#25 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

[Fixed address of devicetree mailing list and added more people on CC.]

For reference, full thread can be found under following link:
http://thread.gmane.org/gmane.linux.ports.arm.kernel/252813

Best regards,
Tomasz

Quoted 5 lines · On Tuesday 23 of July 2013 09:29:32 Tomasz Figa wrote:

Hi Alan,

Quoted 2 lines · On Monday 22 of July 2013 10:44:39 Alan Stern wrote:
Quoted 1 line · Kishon Vijay Abraham I
Quoted 1 line

The PHY and the controller it is attached to are both

physical

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

devices.

The connection between them is hardwired by the system manufacturer and cannot be changed by software.

PHYs are generally described by fixed system-specific

board

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

files or by Device Tree information. Are they ever

discovered

Quoted 19 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

dynamically?

No. They are created just like any other platform devices are created.

Okay. Are PHYs _always_ platform devices?

They can be i2c, spi or any other device types as well.

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines

Is the same true for the controllers attached to the PHYs? If not -- if both a PHY and a controller are discovered dynamically -- how does the kernel know whether they are connected to each other?

No differences here. Both PHY and controller will have dt information
or hwmod data using which platform devices will be created.

Quoted 1 line

The kernel needs to know which controller is attached to

which

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

PHY. Currently this information is represented by name or

ID

Quoted 13 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

strings embedded in platform data.

right. It's embedded in the platform data of the controller.

It must also be embedded in the PHY's platform data somehow. Otherwise, how would the kernel know which PHY to use?

By using a PHY lookup as Stephen and I suggested in our previous replies. Without any extra data in platform data. (I have even posted a code example.)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

The PHY's driver (the supplier) uses the platform data to construct a platform_device structure that represents the

PHY.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Currently the driver assigns static labels (corresponding to the label
used in the platform data of the controller).

Quoted 1 line

Until this is done, the controller's driver (the client)

cannot

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

use the PHY.

right.

Quoted 1 line

Since there is no parent-child relation between the PHY

and the

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

controller, there is no guarantee that the PHY's driver

will be

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

ready when the controller's driver wants to use it. A

deferred

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

probe may be needed.

right.

Quoted 1 line

The issue (or one of the issues) in this discussion is

that

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Greg does not like the idea of using names or IDs to

associate

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

PHYs with controllers, because they are too prone to duplications or other errors. Pointers are more reliable.

But pointers to what? Since the only data known to be available to both the PHY driver and controller driver is

the

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

platform data, the obvious answer is a pointer to platform

data

Quoted 56 lines
Quoted 28 lines
Quoted 10 lines
Quoted 1 line

(either for the PHY or for the controller, or maybe both).

hmm.. it's not going to be simple though as the platform device for the PHY and controller can be created in entirely different places. e.g., in some cases the PHY device is a child of some mfd core device
(the device will be created in drivers/mfd) and the controller driver
(usually) is created in board file. I guess then we have to come up with something to share a pointer in two different files.

The ability for two different source files to share a pointer to a data
item defined in a third source file has been around since long before the C language was invented. :-)

In this case, it doesn't matter where the platform_device structures are created or where the driver source code is. Let's take a simple example. Suppose the system design includes a PHY named "foo". Then the board file could contain:

struct phy_info { ... } phy_foo;
EXPORT_SYMBOL_GPL(phy_foo);

and a header file would contain:

extern struct phy_info phy_foo;

Quoted 7 lines

The PHY supplier could then call phy_create(&phy_foo), and the PHY client could call phy_find(&phy_foo). Or something like that; make up your own structure tags and function names.

It's still possible to have conflicts, but now two PHYs with the same name (or a misspelled name somewhere) will cause an error at link time.

This is incorrect, sorry. First of all it's a layering violation - you export random driver-specific symbols from one driver to another. Then imagine 4 SoCs - A, B, C, D. There are two PHY types PHY1 and PHY2 and there are two types of consumer drivers (e.g. USB host controllers). Now consider following mapping:

SoC PHY consumer
A PHY1 HOST1
B PHY1 HOST2
C PHY2 HOST1
D PHY2 HOST2

So we have to be able to use any of the PHYs with any of the host drivers. This means you would have to export symbol with the same name from both PHY drivers, which obviously would not work in this case, because having both drivers enabled (in a multiplatform aware configuration) would lead to linking conflict.

Best regards,
Tomasz

#26 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 2 lines · Tomasz Figa
Quoted 1 line · On Tuesday 23 of July 2013 09:29:32 Tomasz Figa wrote:

Hi Alan,

Thanks for helping to clarify the issues here.

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

Okay. Are PHYs _always_ platform devices?

They can be i2c, spi or any other device types as well.

In those other cases, presumably there is no platform data associated with the PHY since it isn't a platform device. Then how does the kernel know which controller is attached to the PHY? Is this spelled out in platform data associated with the PHY's i2c/spi/whatever parent?

Quoted 12 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

PHY. Currently this information is represented by name or

ID

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

strings embedded in platform data.

right. It's embedded in the platform data of the controller.

It must also be embedded in the PHY's platform data somehow. Otherwise, how would the kernel know which PHY to use?

By using a PHY lookup as Stephen and I suggested in our previous replies. Without any extra data in platform data. (I have even posted a code example.)

I don't understand, because I don't know what "a PHY lookup" does.

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

In this case, it doesn't matter where the platform_device structures are created or where the driver source code is. Let's take a simple example. Suppose the system design includes a PHY named "foo". Then the board file could contain:

struct phy_info { ... } phy_foo;
EXPORT_SYMBOL_GPL(phy_foo);

and a header file would contain:

extern struct phy_info phy_foo;

The PHY supplier could then call phy_create(&phy_foo), and the PHY client could call phy_find(&phy_foo). Or something like that; make up your own structure tags and function names.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

It's still possible to have conflicts, but now two PHYs with the same name (or a misspelled name somewhere) will cause an error at link time.

This is incorrect, sorry. First of all it's a layering violation - you export random driver-specific symbols from one driver to another. Then

No, that's not what I said. Neither the PHY driver nor the controller driver exports anything to the other. Instead, both drivers use data exported by the board file.

Quoted 10 lines
Quoted 10 lines

imagine 4 SoCs - A, B, C, D. There are two PHY types PHY1 and PHY2 and there are two types of consumer drivers (e.g. USB host controllers). Now consider following mapping:

SoC PHY consumer
A PHY1 HOST1
B PHY1 HOST2
C PHY2 HOST1
D PHY2 HOST2

Quoted 5 lines
Quoted 5 lines

So we have to be able to use any of the PHYs with any of the host drivers. This means you would have to export symbol with the same name from both PHY drivers, which obviously would not work in this case, because having both drivers enabled (in a multiplatform aware configuration) would lead to linking conflict.

You're right; the scheme was too simple. Instead, the board file must export two types of data structures, one for PHYs and one for controllers. Like this:

struct phy_info {
	/* Info for the controller attached to this PHY */
	struct controller_info	*hinfo;
};
struct controller_info {
	/* Info for the PHY which this controller is attached to */
	struct phy_info		*pinfo;
};

The board file for SoC A would contain:

struct phy_info phy1 = {&host1);
EXPORT_SYMBOL(phy1);
struct controller_info host1 = {&phy1};
EXPORT_SYMBOL(host1);

The board file for SoC B would contain:

struct phy_info phy1 = {&host2);
EXPORT_SYMBOL(phy1);
struct controller_info host2 = {&phy1};
EXPORT_SYMBOL(host2);

And so on. This explicitly gives the connection between PHYs and controllers. The PHY providers would use &phy1 or &phy2, and the PHY consumers would use &host1 or &host2.

Alan Stern

#27 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 26 lines · On Tuesday 23 of July 2013 10:37:05 Alan Stern wrote:
Quoted 2 lines · Tomasz Figa
Quoted 1 line · On Tuesday 23 of July 2013 09:29:32 Tomasz Figa wrote:

Hi Alan,

Thanks for helping to clarify the issues here.

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

Okay. Are PHYs _always_ platform devices?

They can be i2c, spi or any other device types as well.

In those other cases, presumably there is no platform data associated with the PHY since it isn't a platform device. Then how does the kernel know which controller is attached to the PHY? Is this spelled out in platform data associated with the PHY's i2c/spi/whatever parent?

Quoted 11 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

PHY. Currently this information is represented by name or

ID

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

strings embedded in platform data.

right. It's embedded in the platform data of the controller.

It must also be embedded in the PHY's platform data somehow. Otherwise, how would the kernel know which PHY to use?

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

By using a PHY lookup as Stephen and I suggested in our previous replies. Without any extra data in platform data. (I have even posted a
code example.)

I don't understand, because I don't know what "a PHY lookup" does.

I have provided a code example in [1]. Feel free to ask questions about those code snippets.

[1] http://thread.gmane.org/gmane.linux.ports.arm.kernel/252813/focus=20889

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines

In this case, it doesn't matter where the platform_device structures
are created or where the driver source code is. Let's take a simple
example. Suppose the system design includes a PHY named "foo". Then
the board file could contain:

struct phy_info { ... } phy_foo;
EXPORT_SYMBOL_GPL(phy_foo);

and a header file would contain:

extern struct phy_info phy_foo;

The PHY supplier could then call phy_create(&phy_foo), and the PHY client could call phy_find(&phy_foo). Or something like that; make up
your own structure tags and function names.

It's still possible to have conflicts, but now two PHYs with the same
name (or a misspelled name somewhere) will cause an error at link time.

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

This is incorrect, sorry. First of all it's a layering violation - you
export random driver-specific symbols from one driver to another. Then

No, that's not what I said. Neither the PHY driver nor the controller driver exports anything to the other. Instead, both drivers use data exported by the board file.

It's still a random, driver-specific global symbol exported from board file to drivers.

Quoted 42 lines
Quoted 12 lines
Quoted 12 lines

imagine 4 SoCs - A, B, C, D. There are two PHY types PHY1 and PHY2 and
there are two types of consumer drivers (e.g. USB host controllers). Now
consider following mapping:

SoC PHY consumer
A PHY1 HOST1
B PHY1 HOST2
C PHY2 HOST1
D PHY2 HOST2

Quoted 6 lines
Quoted 6 lines

So we have to be able to use any of the PHYs with any of the host drivers. This means you would have to export symbol with the same name
from both PHY drivers, which obviously would not work in this case, because having both drivers enabled (in a multiplatform aware configuration) would lead to linking conflict.

You're right; the scheme was too simple. Instead, the board file must export two types of data structures, one for PHYs and one for controllers. Like this:

struct phy_info {
	/* Info for the controller attached to this PHY */
	struct controller_info	*hinfo;
};
struct controller_info {
	/* Info for the PHY which this controller is attached to */
	struct phy_info		*pinfo;
};

The board file for SoC A would contain:

struct phy_info phy1 = {&host1);
EXPORT_SYMBOL(phy1);
struct controller_info host1 = {&phy1};
EXPORT_SYMBOL(host1);

The board file for SoC B would contain:

Quoted 8 lines

struct phy_info phy1 = {&host2);
EXPORT_SYMBOL(phy1);
struct controller_info host2 = {&phy1};
EXPORT_SYMBOL(host2);

And so on. This explicitly gives the connection between PHYs and controllers. The PHY providers would use &phy1 or &phy2, and the PHY consumers would use &host1 or &host2.

This could work assuming that only one SoC and one board is supported in single kernel image. However it's not the case.

We've used to support multiple boards since a long time already and now for selected platforms we even support multiplatform, i.e. multiple SoCs in single zImage. Such solution will not work.

Best regards,
Tomasz

#28 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

In reply to Alan Stern

Hi,

Quoted 7 lines · Alan Stern
Quoted 2 lines · Tomasz Figa
Quoted 1 line · On Tuesday 23 of July 2013 09:29:32 Tomasz Figa wrote:

Hi Alan,

Thanks for helping to clarify the issues here.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

Okay. Are PHYs _always_ platform devices?

They can be i2c, spi or any other device types as well.

In those other cases, presumably there is no platform data associated with the PHY since it isn't a platform device. Then how does the kernel know which controller is attached to the PHY? Is this spelled out in platform data associated with the PHY's i2c/spi/whatever parent?

Yes. I think we could use i2c_board_info for passing platform data.

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

PHY. Currently this information is represented by name or

ID

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

strings embedded in platform data.

right. It's embedded in the platform data of the controller.

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

It must also be embedded in the PHY's platform data somehow. Otherwise, how would the kernel know which PHY to use?

By using a PHY lookup as Stephen and I suggested in our previous replies. Without any extra data in platform data. (I have even posted a code example.)

I don't understand, because I don't know what "a PHY lookup" does.

It is how the PHY framework finds a PHY, when the controller (say USB)requests a PHY from the PHY framework.

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 20 lines

In this case, it doesn't matter where the platform_device structures are created or where the driver source code is. Let's take a simple example. Suppose the system design includes a PHY named "foo". Then the board file could contain:

struct phy_info { ... } phy_foo;
EXPORT_SYMBOL_GPL(phy_foo);

and a header file would contain:

extern struct phy_info phy_foo;

The PHY supplier could then call phy_create(&phy_foo), and the PHY client could call phy_find(&phy_foo). Or something like that; make up your own structure tags and function names.

It's still possible to have conflicts, but now two PHYs with the same name (or a misspelled name somewhere) will cause an error at link time.

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

This is incorrect, sorry. First of all it's a layering violation - you export random driver-specific symbols from one driver to another. Then

No, that's not what I said. Neither the PHY driver nor the controller driver exports anything to the other. Instead, both drivers use data exported by the board file.

I think instead we can use the same data while creating the platform data of the controller and the PHY.
The PHY driver while creating the PHY (using PHY framework) will also pass the *data* it actually got from the platform data to the framework. The PHY user driver (USB), while requesting for the PHY (from the PHY framework) will pass the *data* it got from its platform data. The PHY framework can do a comparison of the *data* pointers it has and return the appropriate PHY to the controller.

Quoted 38 lines
Quoted 11 lines
Quoted 11 lines

imagine 4 SoCs - A, B, C, D. There are two PHY types PHY1 and PHY2 and there are two types of consumer drivers (e.g. USB host controllers). Now consider following mapping:

SoC PHY consumer
A PHY1 HOST1
B PHY1 HOST2
C PHY2 HOST1
D PHY2 HOST2

Quoted 5 lines
Quoted 5 lines

So we have to be able to use any of the PHYs with any of the host drivers. This means you would have to export symbol with the same name from both PHY drivers, which obviously would not work in this case, because having both drivers enabled (in a multiplatform aware configuration) would lead to linking conflict.

You're right; the scheme was too simple. Instead, the board file must export two types of data structures, one for PHYs and one for controllers. Like this:

struct phy_info {
	/* Info for the controller attached to this PHY */
	struct controller_info	*hinfo;
};
struct controller_info {
	/* Info for the PHY which this controller is attached to */
	struct phy_info		*pinfo;
};

The board file for SoC A would contain:

struct phy_info phy1 = {&host1);
EXPORT_SYMBOL(phy1);
struct controller_info host1 = {&phy1};
EXPORT_SYMBOL(host1);

Quoted 6 lines

The board file for SoC B would contain:

struct phy_info phy1 = {&host2);
EXPORT_SYMBOL(phy1);
struct controller_info host2 = {&phy1};
EXPORT_SYMBOL(host2);

I meant something like this

struct phy_info {
	const char *name;
};
struct phy_platform_data {
	.
	.
	struct phy_info *info;
};
struct usb_controller_platform_data {
	.
	.
	struct phy_info *info;
};

struct phy_info phy_info;

While creating the phy device

	struct phy_platform_data phy_data;
	phy_data.info = &info;
	platform_device_add_data(pdev, &phy_data, sizeof(*phy_data))
	platform_device_add();

While creating the controller device

	struct usb_controller_platform_data controller_data;
	controller_data.info = &info;
	platform_device_add_data(pdev, &controller_data, sizeof(*controller_data))
	platform_device_add();

Then modify PHY framework API phy create

	phy_create((struct device *dev, const struct phy_ops *ops,
        void *priv)  {//API changed to take void pointer instead of label
		. //existing implementation
		.
		phy->priv = priv;
	}

	struct phy *phy_get(struct device *dev, const char *string, void *priv) {
//API changed to take an additional pointer
		phy_lookup(priv)
	}

	static struct phy *phy_lookup(void *priv) {
		.
		.
		if (phy->priv==priv) //instead of string comparison, we'll use pointer
			return phy;
	}

PHY driver should be like

	phy_create((dev, ops, pdata->info);

The controller driver would do

	phy_get(dev, NULL, pdata->info);

Now the PHY framework will check for a match of *priv* pointer and return the PHY.

I think this should be possible?

Thanks
Kishon

maintainer
#29 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 171 lines · Kishon Vijay Abraham I

Hi,

Quoted 7 lines · Alan Stern
Quoted 2 lines · Tomasz Figa
Quoted 1 line · On Tuesday 23 of July 2013 09:29:32 Tomasz Figa wrote:

Hi Alan,

Thanks for helping to clarify the issues here.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

Okay. Are PHYs _always_ platform devices?

They can be i2c, spi or any other device types as well.

In those other cases, presumably there is no platform data associated with the PHY since it isn't a platform device. Then how does the kernel know which controller is attached to the PHY? Is this spelled out in platform data associated with the PHY's i2c/spi/whatever parent?

Yes. I think we could use i2c_board_info for passing platform data.

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

PHY. Currently this information is represented by name or

ID

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

strings embedded in platform data.

right. It's embedded in the platform data of the controller.

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

It must also be embedded in the PHY's platform data somehow. Otherwise, how would the kernel know which PHY to use?

By using a PHY lookup as Stephen and I suggested in our previous replies. Without any extra data in platform data. (I have even posted a code example.)

I don't understand, because I don't know what "a PHY lookup" does.

It is how the PHY framework finds a PHY, when the controller (say USB)requests a PHY from the PHY framework.

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 20 lines

In this case, it doesn't matter where the platform_device structures are created or where the driver source code is. Let's take a simple example. Suppose the system design includes a PHY named "foo". Then the board file could contain:

struct phy_info { ... } phy_foo;
EXPORT_SYMBOL_GPL(phy_foo);

and a header file would contain:

extern struct phy_info phy_foo;

The PHY supplier could then call phy_create(&phy_foo), and the PHY client could call phy_find(&phy_foo). Or something like that; make up your own structure tags and function names.

It's still possible to have conflicts, but now two PHYs with the same name (or a misspelled name somewhere) will cause an error at link time.

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

This is incorrect, sorry. First of all it's a layering violation - you export random driver-specific symbols from one driver to another. Then

No, that's not what I said. Neither the PHY driver nor the controller driver exports anything to the other. Instead, both drivers use data exported by the board file.

I think instead we can use the same data while creating the platform data of the controller and the PHY.
The PHY driver while creating the PHY (using PHY framework) will also pass the *data* it actually got from the platform data to the framework. The PHY user driver (USB), while requesting for the PHY (from the PHY framework) will pass the *data* it got from its platform data. The PHY framework can do a comparison of the *data* pointers it has and return the appropriate PHY to the controller.

Quoted 38 lines
Quoted 11 lines
Quoted 11 lines

imagine 4 SoCs - A, B, C, D. There are two PHY types PHY1 and PHY2 and there are two types of consumer drivers (e.g. USB host controllers). Now consider following mapping:

SoC PHY consumer
A PHY1 HOST1
B PHY1 HOST2
C PHY2 HOST1
D PHY2 HOST2

Quoted 5 lines
Quoted 5 lines

So we have to be able to use any of the PHYs with any of the host drivers. This means you would have to export symbol with the same name from both PHY drivers, which obviously would not work in this case, because having both drivers enabled (in a multiplatform aware configuration) would lead to linking conflict.

You're right; the scheme was too simple. Instead, the board file must export two types of data structures, one for PHYs and one for controllers. Like this:

struct phy_info {
	/* Info for the controller attached to this PHY */
	struct controller_info	*hinfo;
};
struct controller_info {
	/* Info for the PHY which this controller is attached to */
	struct phy_info		*pinfo;
};

The board file for SoC A would contain:

struct phy_info phy1 = {&host1);
EXPORT_SYMBOL(phy1);
struct controller_info host1 = {&phy1};
EXPORT_SYMBOL(host1);

Quoted 6 lines

The board file for SoC B would contain:

struct phy_info phy1 = {&host2);
EXPORT_SYMBOL(phy1);
struct controller_info host2 = {&phy1};
EXPORT_SYMBOL(host2);

I meant something like this

struct phy_info {
	const char *name;
};
struct phy_platform_data {
	.
	.
	struct phy_info *info;
};
struct usb_controller_platform_data {
	.
	.
	struct phy_info *info;
};

struct phy_info phy_info;

While creating the phy device

	struct phy_platform_data phy_data;
	phy_data.info = &info;
	platform_device_add_data(pdev, &phy_data, sizeof(*phy_data))
	platform_device_add();

While creating the controller device

	struct usb_controller_platform_data controller_data;
	controller_data.info = &info;
	platform_device_add_data(pdev, &controller_data, sizeof(*controller_data))
	platform_device_add();

Then modify PHY framework API phy create

	phy_create((struct device *dev, const struct phy_ops *ops,
        void *priv)  {//API changed to take void pointer instead of label
		. //existing implementation
		.
		phy->priv = priv;
	}

	struct phy *phy_get(struct device *dev, const char *string, void *priv) {
//API changed to take an additional pointer
		phy_lookup(priv)
	}

	static struct phy *phy_lookup(void *priv) {
		.
		.
		if (phy->priv==priv) //instead of string comparison, we'll use pointer
			return phy;
	}

PHY driver should be like

Quoted 8 lines
	phy_create((dev, ops, pdata->info);

The controller driver would do

	phy_get(dev, NULL, pdata->info);

Now the PHY framework will check for a match of *priv* pointer and return the PHY.

I think this should be possible?

Ick, no. Why can't you just pass the pointer to the phy itself? If you had a "priv" pointer to search from, then you could have just passed the original phy pointer in the first place, right?

The issue is that a string "name" is not going to scale at all, as it requires hard-coded information that will change over time (as the existing clock interface is already showing.)

Please just pass the real "phy" pointer around, that's what it is there for. Your "board binding" logic/code should be able to handle this, as it somehow was going to do the same thing with a "name".

thanks,

greg k-h

#30 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi Greg,

Quoted 11 lines · Greg KH
Quoted 10 lines · Kishon Vijay Abraham I

Hi,

Quoted 7 lines · Alan Stern
Quoted 2 lines · Tomasz Figa
Quoted 1 line · On Tuesday 23 of July 2013 09:29:32 Tomasz Figa wrote:

Hi Alan,

Thanks for helping to clarify the issues here.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

Okay. Are PHYs _always_ platform devices?

They can be i2c, spi or any other device types as well.

In those other cases, presumably there is no platform data associated with the PHY since it isn't a platform device. Then how does the kernel know which controller is attached to the PHY? Is this spelled out in platform data associated with the PHY's i2c/spi/whatever parent?

.
.
<snip>
.
.

Quoted 22 lines
Quoted 9 lines
	static struct phy *phy_lookup(void *priv) {
		.
		.
		if (phy->priv==priv) //instead of string comparison, we'll use pointer
			return phy;
	}

PHY driver should be like

Quoted 8 lines
	phy_create((dev, ops, pdata->info);

The controller driver would do

	phy_get(dev, NULL, pdata->info);

Now the PHY framework will check for a match of *priv* pointer and return the PHY.

I think this should be possible?

Ick, no. Why can't you just pass the pointer to the phy itself? If you had a "priv" pointer to search from, then you could have just passed the original phy pointer in the first place, right?

Quoted 7 lines

The issue is that a string "name" is not going to scale at all, as it requires hard-coded information that will change over time (as the existing clock interface is already showing.)

Please just pass the real "phy" pointer around, that's what it is there for. Your "board binding" logic/code should be able to handle this, as it somehow was going to do the same thing with a "name".

The problem is the board file won't have the *phy* pointer. *phy* pointer is created at a much later time when the phy driver is probed.

Thanks
Kishon

maintainer
#31 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 53 lines · Kishon Vijay Abraham I

Hi Greg,

Quoted 11 lines · Greg KH
Quoted 10 lines · Kishon Vijay Abraham I

Hi,

Quoted 7 lines · Alan Stern
Quoted 2 lines · Tomasz Figa
Quoted 1 line · On Tuesday 23 of July 2013 09:29:32 Tomasz Figa wrote:

Hi Alan,

Thanks for helping to clarify the issues here.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

Okay. Are PHYs _always_ platform devices?

They can be i2c, spi or any other device types as well.

In those other cases, presumably there is no platform data associated with the PHY since it isn't a platform device. Then how does the kernel know which controller is attached to the PHY? Is this spelled out in platform data associated with the PHY's i2c/spi/whatever parent?

.
.
<snip>
.
.

Quoted 26 lines
Quoted 9 lines
	static struct phy *phy_lookup(void *priv) {
		.
		.
		if (phy->priv==priv) //instead of string comparison, we'll use pointer
			return phy;
	}

PHY driver should be like

Quoted 8 lines
	phy_create((dev, ops, pdata->info);

The controller driver would do

	phy_get(dev, NULL, pdata->info);

Now the PHY framework will check for a match of *priv* pointer and return the PHY.

I think this should be possible?

Ick, no. Why can't you just pass the pointer to the phy itself? If you had a "priv" pointer to search from, then you could have just passed the original phy pointer in the first place, right?

The issue is that a string "name" is not going to scale at all, as it requires hard-coded information that will change over time (as the existing clock interface is already showing.)

Quoted 6 lines
Quoted 3 lines

Please just pass the real "phy" pointer around, that's what it is there for. Your "board binding" logic/code should be able to handle this, as it somehow was going to do the same thing with a "name".

The problem is the board file won't have the *phy* pointer. *phy* pointer is created at a much later time when the phy driver is probed.

Ok, then save it then, as no one could have used it before then, right?

All I don't want to see is any "get by name/void *" functions in the api, as that way is fragile and will break, as people have already shown.

Just pass the real pointer around. If that is somehow a problem, then something larger is a problem with how board devices are tied together :)

thanks,

greg k-h

#32 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

In reply to Greg KH
Quoted 219 lines · On Tuesday 23 of July 2013 09:18:46 Greg KH wrote:
Quoted 218 lines · Kishon Vijay Abraham I

Hi,

Quoted 8 lines · Alan Stern
Quoted 2 lines · Tomasz Figa
Quoted 1 line · On Tuesday 23 of July 2013 09:29:32 Tomasz Figa wrote:

Hi Alan,

Thanks for helping to clarify the issues here.

Quoted 2 lines
Quoted 2 lines
Quoted 1 line

Okay. Are PHYs _always_ platform devices?

Quoted 7 lines
Quoted 1 line
Quoted 1 line

They can be i2c, spi or any other device types as well.

In those other cases, presumably there is no platform data associated with the PHY since it isn't a platform device. Then how does the kernel know which controller is attached to the PHY? Is this spelled out in platform data associated with the PHY's i2c/spi/whatever parent?

Yes. I think we could use i2c_board_info for passing platform data.

Quoted 11 lines
Quoted 11 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

PHY. Currently this information is represented by name or

ID

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

strings embedded in platform data.

right. It's embedded in the platform data of the controller.

It must also be embedded in the PHY's platform data somehow. Otherwise, how would the kernel know which PHY to use?

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

By using a PHY lookup as Stephen and I suggested in our previous replies. Without any extra data in platform data. (I have even posted a
code example.)

I don't understand, because I don't know what "a PHY lookup" does.

It is how the PHY framework finds a PHY, when the controller (say USB)requests a PHY from the PHY framework.

Quoted 30 lines
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines

In this case, it doesn't matter where the platform_device structures
are created or where the driver source code is. Let's take a simple
example. Suppose the system design includes a PHY named "foo". Then
the board file could contain:

struct phy_info { ... } phy_foo;
EXPORT_SYMBOL_GPL(phy_foo);

and a header file would contain:

extern struct phy_info phy_foo;

The PHY supplier could then call phy_create(&phy_foo), and the PHY client could call phy_find(&phy_foo). Or something like that; make up
your own structure tags and function names.

It's still possible to have conflicts, but now two PHYs with the same
name (or a misspelled name somewhere) will cause an error at link time.

Quoted 4 lines
Quoted 4 lines

This is incorrect, sorry. First of all it's a layering violation - you
export random driver-specific symbols from one driver to another. Then

Quoted 4 lines

No, that's not what I said. Neither the PHY driver nor the controller
driver exports anything to the other. Instead, both drivers use data exported by the board file.

I think instead we can use the same data while creating the platform data of the controller and the PHY.
The PHY driver while creating the PHY (using PHY framework) will also pass the *data* it actually got from the platform data to the framework. The PHY user driver (USB), while requesting for the PHY (from the PHY framework) will pass the *data* it got from its platform data.
The PHY framework can do a comparison of the *data* pointers it has and return the appropriate PHY to the controller.

Quoted 45 lines
Quoted 12 lines
Quoted 12 lines

imagine 4 SoCs - A, B, C, D. There are two PHY types PHY1 and PHY2 and
there are two types of consumer drivers (e.g. USB host controllers). Now
consider following mapping:

SoC PHY consumer
A PHY1 HOST1
B PHY1 HOST2
C PHY2 HOST1
D PHY2 HOST2

Quoted 6 lines
Quoted 6 lines

So we have to be able to use any of the PHYs with any of the host drivers. This means you would have to export symbol with the same name
from both PHY drivers, which obviously would not work in this case, because having both drivers enabled (in a multiplatform aware configuration) would lead to linking conflict.

You're right; the scheme was too simple. Instead, the board file must
export two types of data structures, one for PHYs and one for controllers. Like this:

struct phy_info {

	/* Info for the controller attached to this PHY */
	struct controller_info	*hinfo;

};

struct controller_info {

	/* Info for the PHY which this controller is attached to */
	struct phy_info		*pinfo;

};

The board file for SoC A would contain:

struct phy_info phy1 = {&host1);
EXPORT_SYMBOL(phy1);
struct controller_info host1 = {&phy1};
EXPORT_SYMBOL(host1);

Quoted 6 lines

The board file for SoC B would contain:

struct phy_info phy1 = {&host2);
EXPORT_SYMBOL(phy1);
struct controller_info host2 = {&phy1};
EXPORT_SYMBOL(host2);

I meant something like this
struct phy_info {

	const char *name;

};

struct phy_platform_data {

	.
	.
	struct phy_info *info;

};

struct usb_controller_platform_data {

	.
	.
	struct phy_info *info;

};

struct phy_info phy_info;

While creating the phy device

	struct phy_platform_data phy_data;
	phy_data.info = &info;
	platform_device_add_data(pdev, &phy_data, sizeof(*phy_data))
	platform_device_add();

While creating the controller device

	struct usb_controller_platform_data controller_data;
	controller_data.info = &info;
	platform_device_add_data(pdev, &controller_data,
	sizeof(*controller_data)) platform_device_add();

Then modify PHY framework API phy create

	phy_create((struct device *dev, const struct phy_ops *ops,
	
        void *priv)  {//API changed to take void pointer instead of
        label
		
		. //existing implementation
		.
		phy->priv = priv;
	
	}
	
	struct phy *phy_get(struct device *dev, const char *string, void
	*priv) {> 

//API changed to take an additional pointer

		phy_lookup(priv)
	
	}
	
	static struct phy *phy_lookup(void *priv) {
	
		.
		.
		if (phy->priv==priv) //instead of string comparison, we'll use
		pointer
		
			return phy;
	
	}

PHY driver should be like

	phy_create((dev, ops, pdata->info);

The controller driver would do

	phy_get(dev, NULL, pdata->info);
Quoted 8 lines
Quoted 4 lines

Now the PHY framework will check for a match of *priv* pointer and return the PHY.

I think this should be possible?

Ick, no. Why can't you just pass the pointer to the phy itself? If you had a "priv" pointer to search from, then you could have just passed the original phy pointer in the first place, right?

IMHO it would be better if you provided some code example, but let's try to check if I understood you correctly.

8><------------------------------------------------------------------------

[Board file]

static struct phy my_phy;

static struct platform_device phy_pdev = {
	/* ... */
	.platform_data = &my_phy;
	/* ... */
};
static struct platform_device phy_pdev = {
	/* ... */
	.platform_data = &my_phy;
	/* ... */
};

[Provider driver]

struct phy *phy = pdev->dev.platform_data;

ret = phy_create(phy);

[Consumer driver]

struct phy *phy = pdev->dev.platform_data;

ret = phy_get(&pdev->dev, phy);

------------------------------------------------------------------------><8

Is this what you mean?

Quoted 3 lines

The issue is that a string "name" is not going to scale at all, as it requires hard-coded information that will change over time (as the existing clock interface is already showing.)

I fully agree that a simple, single string will not scale even in some, not so uncommon cases, but there is already a lot of existing lookup solutions over the kernel and so there is no point in introducing another one.

Quoted 3 lines

Please just pass the real "phy" pointer around, that's what it is there for. Your "board binding" logic/code should be able to handle this, as it somehow was going to do the same thing with a "name".

It's technically correct, but quality of this solution isn't really nice, because it's a layering violation (at least if I understood what you mean). This is because you need to have full definition of struct phy in board file and a structure that is used as private data in PHY core comes from platform code.

Best regards,
Tomasz

maintainer
#33 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 6 lines · Tomasz Figa
Quoted 3 lines

Ick, no. Why can't you just pass the pointer to the phy itself? If you had a "priv" pointer to search from, then you could have just passed the original phy pointer in the first place, right?

IMHO it would be better if you provided some code example, but let's try to check if I understood you correctly.

It's not my code that I want to have added, so I don't have to write examples, I just get to complain about the existing stuff :)

Quoted 26 lines

8><------------------------------------------------------------------------

[Board file]

static struct phy my_phy;

static struct platform_device phy_pdev = {
	/* ... */
	.platform_data = &my_phy;
	/* ... */
};
static struct platform_device phy_pdev = {
	/* ... */
	.platform_data = &my_phy;
	/* ... */
};

[Provider driver]

struct phy *phy = pdev->dev.platform_data;

ret = phy_create(phy);

[Consumer driver]

Quoted 7 lines

struct phy *phy = pdev->dev.platform_data;

ret = phy_get(&pdev->dev, phy);

------------------------------------------------------------------------><8

Is this what you mean?

No. Well, kind of. What's wrong with using the platform data structure unique to the board to have the pointer?

For example (just randomly picking one), the ata-pxa driver would change include/linux/platform_data/ata-pxa.h to have a phy pointer in it:

struct phy;

struct  pata_pxa_pdata {
	/* PXA DMA DREQ<0:2> pin */
	uint32_t	dma_dreq;
	/* Register shift */
	uint32_t	reg_shift;
	/* IRQ flags */
	uint32_t	irq_flags;
	/* PHY */
	struct phy	*phy;
};

Then, when you create the platform, set the phy* pointer with a call to phy_create(). Then you can use that pointer wherever that plaform data is available (i.e. whereever platform_data is at).

Quoted 7 lines
Quoted 3 lines

The issue is that a string "name" is not going to scale at all, as it requires hard-coded information that will change over time (as the existing clock interface is already showing.)

I fully agree that a simple, single string will not scale even in some, not so uncommon cases, but there is already a lot of existing lookup solutions over the kernel and so there is no point in introducing another one.

I'm trying to get _rid_ of lookup "solutions" and just use a real pointer, as you should. I'll go tackle those other ones after this one is taken care of, to show how the others should be handled as well.

Quoted 9 lines
Quoted 3 lines

Please just pass the real "phy" pointer around, that's what it is there for. Your "board binding" logic/code should be able to handle this, as it somehow was going to do the same thing with a "name".

It's technically correct, but quality of this solution isn't really nice, because it's a layering violation (at least if I understood what you mean). This is because you need to have full definition of struct phy in board file and a structure that is used as private data in PHY core comes from platform code.

No, just a pointer, you don't need the "full" structure until you get to some .c code that actually manipulates the phy itself, for all other places, you are just dealing with a pointer and a structure you never reference.

Does that make more sense?

thanks,

greg k-h

#34 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 9 lines · Greg KH
Quoted 3 lines · Tomasz Figa

I fully agree that a simple, single string will not scale even in some, not so uncommon cases, but there is already a lot of existing lookup solutions over the kernel and so there is no point in introducing another one.

I'm trying to get _rid_ of lookup "solutions" and just use a real pointer, as you should. I'll go tackle those other ones after this one is taken care of, to show how the others should be handled as well.

What are the problems you are seeing with doing things with lookups?
Having to write platform data for everything gets old fast and the code
duplication is pretty tedious...
-------------- 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/20130723/5a9806af/attachment.sig>

maintainer
#35 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 7 lines · Mark Brown
Quoted 5 lines · Greg KH
Quoted 3 lines · Tomasz Figa

I fully agree that a simple, single string will not scale even in some, not so uncommon cases, but there is already a lot of existing lookup solutions over the kernel and so there is no point in introducing another one.

Quoted 5 lines
Quoted 3 lines

I'm trying to get _rid_ of lookup "solutions" and just use a real pointer, as you should. I'll go tackle those other ones after this one is taken care of, to show how the others should be handled as well.

What are the problems you are seeing with doing things with lookups?

You don't "know" the id of the device you are looking up, due to multiple devices being in the system (dynamic ids, look back earlier in this thread for details about that.)

Quoted 2 lines

Having to write platform data for everything gets old fast and the code duplication is pretty tedious...

Adding a single pointer is "tedious"? Where is the "name" that you are going to lookup going to come from? That code doesn't write itself...

thanks,

greg k-h

#36 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 7 lines · Greg KH
Quoted 1 line · Mark Brown

What are the problems you are seeing with doing things with lookups?

You don't "know" the id of the device you are looking up, due to multiple devices being in the system (dynamic ids, look back earlier in this thread for details about that.)

I got copied in very late so don't have most of the thread I'm afraid, I did try looking at web archives but didn't see a clear problem statement. In any case this is why the APIs doing lookups do the lookups in the context of the requesting device - devices ask for whatever name they use locally.

Quoted 5 lines
Quoted 2 lines

Having to write platform data for everything gets old fast and the code duplication is pretty tedious...

Adding a single pointer is "tedious"? Where is the "name" that you are going to lookup going to come from? That code doesn't write itself...

It's adding platform data in the first place that gets tedious - and of course there's also DT and ACPI to worry about, it's not just a case of platform data and then you're done. Pushing the lookup into library code means that drivers don't have to worry about any of this stuff.

For most of the APIs doing this there is a clear and unambiguous name in
the hardware that can be used (and for hardware process reasons is
unlikely to get changed). The major exception to this is the clock API
since it is relatively rare to have clear, segregated IP level
information for IPs baked into larger chips. The other APIs tend to be
establishing chip to chip links.
-------------- 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/20130723/3c3ea43f/attachment-0001.sig>

maintainer
#37 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 9 lines · Mark Brown
Quoted 3 lines

You don't "know" the id of the device you are looking up, due to multiple devices being in the system (dynamic ids, look back earlier in this thread for details about that.)

I got copied in very late so don't have most of the thread I'm afraid, I did try looking at web archives but didn't see a clear problem statement. In any case this is why the APIs doing lookups do the lookups in the context of the requesting device - devices ask for whatever name they use locally.

What do you mean by "locally"?

The problem with the api was that the phy core wanted a id and a name to create a phy, and then later other code was doing a "lookup" based on the name and id (mushed together), because it "knew" that this device was the one it wanted.

Just like the clock api, which, for multiple devices, has proven to cause problems. I don't want to see us accept an api that we know has issues in it now, I'd rather us fix it up properly.

Subsystems should be able to create ids how ever they want to, and not rely on the code calling them to specify the names of the devices that way, otherwise the api is just too fragile.

I think, that if you create a device, then just carry around the pointer to that device (in this case a phy) and pass it to whatever other code needs it. No need to do lookups on "known names" or anything else, just normal pointers, with no problems for multiple devices, busses, or naming issues.

Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

Having to write platform data for everything gets old fast and the code duplication is pretty tedious...

Adding a single pointer is "tedious"? Where is the "name" that you are going to lookup going to come from? That code doesn't write itself...

It's adding platform data in the first place that gets tedious - and of course there's also DT and ACPI to worry about, it's not just a case of platform data and then you're done. Pushing the lookup into library code means that drivers don't have to worry about any of this stuff.

I agree, so just pass around the pointer to the phy and all is good. No need to worry about DT or ACPI or anything else.

Quoted 6 lines

For most of the APIs doing this there is a clear and unambiguous name in the hardware that can be used (and for hardware process reasons is unlikely to get changed). The major exception to this is the clock API since it is relatively rare to have clear, segregated IP level information for IPs baked into larger chips. The other APIs tend to be establishing chip to chip links.

The clock api is having problems with multiple "names" due to dynamic devices from what I was told. I want to prevent the PHY interface from having that same issue.

thanks,

greg k-h

#38 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 27 lines · On Tuesday 23 of July 2013 12:44:23 Greg KH wrote:
Quoted 10 lines · Mark Brown
Quoted 4 lines

You don't "know" the id of the device you are looking up, due to multiple devices being in the system (dynamic ids, look back earlier in
this thread for details about that.)

I got copied in very late so don't have most of the thread I'm afraid, I did try looking at web archives but didn't see a clear problem statement. In any case this is why the APIs doing lookups do the lookups in the context of the requesting device - devices ask for whatever name they use locally.

What do you mean by "locally"?

The problem with the api was that the phy core wanted a id and a name to create a phy, and then later other code was doing a "lookup" based on the name and id (mushed together), because it "knew" that this device was the one it wanted.

Just like the clock api, which, for multiple devices, has proven to cause problems. I don't want to see us accept an api that we know has issues in it now, I'd rather us fix it up properly.

Subsystems should be able to create ids how ever they want to, and not rely on the code calling them to specify the names of the devices that way, otherwise the api is just too fragile.

Quoted 5 lines

I think, that if you create a device, then just carry around the pointer to that device (in this case a phy) and pass it to whatever other code needs it. No need to do lookups on "known names" or anything else, just normal pointers, with no problems for multiple devices, busses, or naming issues.

PHY object is not a device, it is something that a device driver creates (one or more instances of) when it is being probed. You don't have a clean way to export this PHY object to other driver, other than keeping this PHY on a list inside PHY core with some well-known ID (e.g. device name + consumer port name/index, like in regulator core) and then to use this well-known ID inside consumer driver as a lookup key passed to phy_get();

Actually I think for PHY case, exactly the same way as used for regulators might be completely fine:

1. Each PHY would have some kind of platform, non-unique name, that is just used to print some messages (like the platform/board name of a regulator).
2. Each PHY would have an array of consumers. Consumer specifier would consist of consumer device name and consumer port name - just like in regulator subsystem.
3. PHY driver receives an array of, let's say, phy_init_data inside its platform data that it would use to register its PHYs.
4. Consumer drivers would have constant consumer port names and wouldn't receive any information about PHYs from platform code.

Code example:

[Board file]

static const struct phy_consumer_data usb_20_phy0_consumers[] = {
	{
		.devname = "foo-ehci",
		.port = "usbphy",
	},
};
static const struct phy_consumer_data usb_20_phy1_consumers[] = {
	{
		.devname = "foo-otg",
		.port = "otgphy",
	},
};
static const struct phy_init_data my_phys[] = {
	{
		.name = "USB 2.0 PHY 0",
		.consumers = usb_20_phy0_consumers,
		.num_consumers = ARRAY_SIZE(usb_20_phy0_consumers),
	},
	{
		.name = "USB 2.0 PHY 1",
		.consumers = usb_20_phy1_consumers,
		.num_consumers = ARRAY_SIZE(usb_20_phy1_consumers),
	},
	{ }
};
static const struct platform_device usb_phy_pdev = {
	.name = "foo-usbphy",
	.id = -1,
	.dev = {
		.platform_data = my_phys,
	},
};

[PHY driver]

static int foo_usbphy_probe(pdev)

{
	struct foo_usbphy *foo;
	struct phy_init_data *init_data = pdev->dev.platform_data;
	/* ... */
	// for each PHY in init_data {
		phy_register(&foo->phy[i], &init_data[i]);
	// }
	/* ... */
}

[EHCI driver]

static int foo_ehci_probe(pdev)

{
	struct phy *phy;
	/* ... */
	phy = phy_get(&pdev->dev, "usbphy");
	/* ... */
}

[OTG driver]

static int foo_otg_probe(pdev)

{
	struct phy *phy;
	/* ... */
	phy = phy_get(&pdev->dev, "otgphy");
	/* ... */
}
Quoted 16 lines
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

Having to write platform data for everything gets old fast and the code
duplication is pretty tedious...

Adding a single pointer is "tedious"? Where is the "name" that you are
going to lookup going to come from? That code doesn't write itself...

Quoted 6 lines

It's adding platform data in the first place that gets tedious - and of
course there's also DT and ACPI to worry about, it's not just a case of
platform data and then you're done. Pushing the lookup into library code means that drivers don't have to worry about any of this stuff.

Quoted 2 lines

I agree, so just pass around the pointer to the phy and all is good. No need to worry about DT or ACPI or anything else.

With Device Tree we don't have board files anymore. How would you pass any pointers between provider and consumer drivers in this case?

Quoted 10 lines
Quoted 6 lines

For most of the APIs doing this there is a clear and unambiguous name in the hardware that can be used (and for hardware process reasons is unlikely to get changed). The major exception to this is the clock API since it is relatively rare to have clear, segregated IP level information for IPs baked into larger chips. The other APIs tend to be establishing chip to chip links.

The clock api is having problems with multiple "names" due to dynamic devices from what I was told. I want to prevent the PHY interface from having that same issue.

Yes, the clock API has a problem related to the clock namespace being global for all registered clock controllers. This is not a problem with lookup in general, but with wrong lookup key chosen.

Best regards,
Tomasz

maintainer
#39 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 28 lines · Tomasz Figa
Quoted 27 lines · On Tuesday 23 of July 2013 12:44:23 Greg KH wrote:
Quoted 10 lines · Mark Brown
Quoted 4 lines

You don't "know" the id of the device you are looking up, due to multiple devices being in the system (dynamic ids, look back earlier in
this thread for details about that.)

I got copied in very late so don't have most of the thread I'm afraid, I did try looking at web archives but didn't see a clear problem statement. In any case this is why the APIs doing lookups do the lookups in the context of the requesting device - devices ask for whatever name they use locally.

What do you mean by "locally"?

The problem with the api was that the phy core wanted a id and a name to create a phy, and then later other code was doing a "lookup" based on the name and id (mushed together), because it "knew" that this device was the one it wanted.

Just like the clock api, which, for multiple devices, has proven to cause problems. I don't want to see us accept an api that we know has issues in it now, I'd rather us fix it up properly.

Subsystems should be able to create ids how ever they want to, and not rely on the code calling them to specify the names of the devices that way, otherwise the api is just too fragile.

Quoted 8 lines
Quoted 5 lines

I think, that if you create a device, then just carry around the pointer to that device (in this case a phy) and pass it to whatever other code needs it. No need to do lookups on "known names" or anything else, just normal pointers, with no problems for multiple devices, busses, or naming issues.

PHY object is not a device, it is something that a device driver creates (one or more instances of) when it is being probed.

But you created a 'struct device' for it, so I think of it as a "device" be it "virtual" or "real" :)

Quoted 85 lines

You don't have a clean way to export this PHY object to other driver, other than keeping this PHY on a list inside PHY core with some well-known ID (e.g. device name + consumer port name/index, like in regulator core) and then to use this well-known ID inside consumer driver as a lookup key passed to phy_get();

Actually I think for PHY case, exactly the same way as used for regulators might be completely fine:

1. Each PHY would have some kind of platform, non-unique name, that is just used to print some messages (like the platform/board name of a regulator).
2. Each PHY would have an array of consumers. Consumer specifier would consist of consumer device name and consumer port name - just like in regulator subsystem.
3. PHY driver receives an array of, let's say, phy_init_data inside its platform data that it would use to register its PHYs.
4. Consumer drivers would have constant consumer port names and wouldn't receive any information about PHYs from platform code.

Code example:

[Board file]

static const struct phy_consumer_data usb_20_phy0_consumers[] = {
	{
		.devname = "foo-ehci",
		.port = "usbphy",
	},
};
static const struct phy_consumer_data usb_20_phy1_consumers[] = {
	{
		.devname = "foo-otg",
		.port = "otgphy",
	},
};
static const struct phy_init_data my_phys[] = {
	{
		.name = "USB 2.0 PHY 0",
		.consumers = usb_20_phy0_consumers,
		.num_consumers = ARRAY_SIZE(usb_20_phy0_consumers),
	},
	{
		.name = "USB 2.0 PHY 1",
		.consumers = usb_20_phy1_consumers,
		.num_consumers = ARRAY_SIZE(usb_20_phy1_consumers),
	},
	{ }
};
static const struct platform_device usb_phy_pdev = {
	.name = "foo-usbphy",
	.id = -1,
	.dev = {
		.platform_data = my_phys,
	},
};

[PHY driver]

static int foo_usbphy_probe(pdev)

{
	struct foo_usbphy *foo;
	struct phy_init_data *init_data = pdev->dev.platform_data;
	/* ... */
	// for each PHY in init_data {
		phy_register(&foo->phy[i], &init_data[i]);
	// }
	/* ... */
}

[EHCI driver]

static int foo_ehci_probe(pdev)

{
	struct phy *phy;
	/* ... */
	phy = phy_get(&pdev->dev, "usbphy");
	/* ... */
}

[OTG driver]

Quoted 7 lines

static int foo_otg_probe(pdev)

{
	struct phy *phy;
	/* ... */
	phy = phy_get(&pdev->dev, "otgphy");
	/* ... */
}

That's not so bad, as long as you let the phy core use whatever name it wants for the device when it registers it with sysfs. Use the name you are requesting as a "tag" or some such "hint" as to what the phy can be looked up by.

Good luck handling duplicate "tags" :)

thanks,

greg k-h

#40 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 40 lines · On Tuesday 23 of July 2013 13:50:07 Greg KH wrote:
Quoted 39 lines · Tomasz Figa
Quoted 37 lines · On Tuesday 23 of July 2013 12:44:23 Greg KH wrote:
Quoted 6 lines · Mark Brown
Quoted 5 lines

You don't "know" the id of the device you are looking up, due to multiple devices being in the system (dynamic ids, look back earlier
in
this thread for details about that.)

Quoted 6 lines

I got copied in very late so don't have most of the thread I'm afraid,
I did try looking at web archives but didn't see a clear problem statement. In any case this is why the APIs doing lookups do the lookups in the context of the requesting device - devices ask for whatever name they use locally.

What do you mean by "locally"?

The problem with the api was that the phy core wanted a id and a name to create a phy, and then later other code was doing a "lookup" based on the name and id (mushed together), because it "knew" that this device was the one it wanted.

Just like the clock api, which, for multiple devices, has proven to cause problems. I don't want to see us accept an api that we know has
issues in it now, I'd rather us fix it up properly.

Subsystems should be able to create ids how ever they want to, and not
rely on the code calling them to specify the names of the devices that
way, otherwise the api is just too fragile.

I think, that if you create a device, then just carry around the pointer to that device (in this case a phy) and pass it to whatever other code needs it. No need to do lookups on "known names" or anything else, just normal pointers, with no problems for multiple devices, busses, or naming issues.

Quoted 5 lines
Quoted 2 lines

PHY object is not a device, it is something that a device driver creates (one or more instances of) when it is being probed.

But you created a 'struct device' for it, so I think of it as a "device" be it "virtual" or "real" :)

Keep in mind that those virtual devices are created by PHY driver bound to a real device and one real device can have multiple virtual devices behind it.

Quoted 118 lines
Quoted 118 lines

You don't have a clean way to export this PHY object to other driver, other than keeping this PHY on a list inside PHY core with some well-known ID (e.g. device name + consumer port name/index, like in regulator core) and then to use this well-known ID inside consumer driver as a lookup key passed to phy_get();

Actually I think for PHY case, exactly the same way as used for regulators might be completely fine:

1. Each PHY would have some kind of platform, non-unique name, that is just used to print some messages (like the platform/board name of a regulator).
2. Each PHY would have an array of consumers. Consumer specifier would consist of consumer device name and consumer port name - just like in regulator subsystem.
3. PHY driver receives an array of, let's say, phy_init_data inside its
platform data that it would use to register its PHYs.
4. Consumer drivers would have constant consumer port names and wouldn't receive any information about PHYs from platform code.

Code example:

[Board file]

static const struct phy_consumer_data usb_20_phy0_consumers[] = {

	{
	
		.devname = "foo-ehci",
		.port = "usbphy",
	
	},

};

static const struct phy_consumer_data usb_20_phy1_consumers[] = {

	{
	
		.devname = "foo-otg",
		.port = "otgphy",
	
	},

};

static const struct phy_init_data my_phys[] = {

	{
	
		.name = "USB 2.0 PHY 0",
		.consumers = usb_20_phy0_consumers,
		.num_consumers = ARRAY_SIZE(usb_20_phy0_consumers),
	
	},
	{
	
		.name = "USB 2.0 PHY 1",
		.consumers = usb_20_phy1_consumers,
		.num_consumers = ARRAY_SIZE(usb_20_phy1_consumers),
	
	},
	{ }

};

static const struct platform_device usb_phy_pdev = {

	.name = "foo-usbphy",
	.id = -1,
	.dev = {
	
		.platform_data = my_phys,
	
	},

};

[PHY driver]

static int foo_usbphy_probe(pdev)
{

	struct foo_usbphy *foo;
	struct phy_init_data *init_data = pdev->dev.platform_data;
	/* ... */
	// for each PHY in init_data {
	
		phy_register(&foo->phy[i], &init_data[i]);
	
	// }
	/* ... */

}

[EHCI driver]

static int foo_ehci_probe(pdev)
{

	struct phy *phy;
	/* ... */
	phy = phy_get(&pdev->dev, "usbphy");
	/* ... */

}

[OTG driver]

static int foo_otg_probe(pdev)
{

	struct phy *phy;
	/* ... */
	phy = phy_get(&pdev->dev, "otgphy");
	/* ... */
Quoted 4 lines
Quoted 1 line

}

That's not so bad, as long as you let the phy core use whatever name it wants for the device when it registers it with sysfs.

Yes, in regulator core consumer names are completely separated from this. Regulator core simply assigns a sequential integer ID to each regulator and registers /sys/class/regulator/regulator.ID for each regulator.

Quoted 5 lines

Use the name you
are requesting as a "tag" or some such "hint" as to what the phy can be looked up by.

Good luck handling duplicate "tags" :)

The tag alone is not a key. Lookup key consists of two components, consumer device name and consumer tag. What kind of duplicate tags can be a problem here?

Best regards,
Tomasz

maintainer
#41 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 6 lines · Tomasz Figa
Quoted 2 lines

That's not so bad, as long as you let the phy core use whatever name it wants for the device when it registers it with sysfs.

Yes, in regulator core consumer names are completely separated from this. Regulator core simply assigns a sequential integer ID to each regulator and registers /sys/class/regulator/regulator.ID for each regulator.

Yes, that's fine.

Quoted 9 lines
Quoted 5 lines

Use the name you
are requesting as a "tag" or some such "hint" as to what the phy can be looked up by.

Good luck handling duplicate "tags" :)

The tag alone is not a key. Lookup key consists of two components, consumer device name and consumer tag. What kind of duplicate tags can be a problem here?

Ok, I didn't realize it looked at both parts, that makes sense, thanks.

greg k-h

#42 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

In reply to Greg KH
Quoted 7 lines · Greg KH
Quoted 3 lines · Mark Brown

statement. In any case this is why the APIs doing lookups do the lookups in the context of the requesting device - devices ask for whatever name they use locally.

What do you mean by "locally"?

Within themselves - for example a regulator consumer asks for a given supply on the device in terms of the supply names the device has.

Quoted 4 lines

The problem with the api was that the phy core wanted a id and a name to create a phy, and then later other code was doing a "lookup" based on the name and id (mushed together), because it "knew" that this device was the one it wanted.

Ah, that sounds like the API is missing a component to link things together. But I could be wrong. What I would expect to see is that the consumer says "I want the PHY called X" and the PHY driver says "I provide this set of PHYs" with a layer in between that plugs those together. This would normally involve talking about the parent device rather than the PHY itself.

Quoted 5 lines

I think, that if you create a device, then just carry around the pointer to that device (in this case a phy) and pass it to whatever other code needs it. No need to do lookups on "known names" or anything else, just normal pointers, with no problems for multiple devices, busses, or naming issues.

I think you're not really talking about the lookup API at all here but rather about one way in which the matching code can be written. What everything *really* wants to do is work in terms of resources namespaced within struct devices since every bit of hardware in the system should have one of those it can use and if you have a struct device you can do useful things like call dev_printk() and find the device tree data to do device tree based lookups.

Unfortunately for a number of buses even when statically registering the struct device doesn't get allocated until the device is probed so what everyone fell back on doing was using dev_name() in cases where the struct device wasn't there yet, or just always using it for consistency since for most of the affected buses dev_name() is fixed for human interface reasons. I think this is the issue you're concerned about here since if the dev_name() is dynamically allocated this breaks down. This only affects board files, DT and ACPI can both use their own data structures to do the mapping.

I had thought you were talking about picking the names that the consumers use (which isn't actually that big a deal, it's just a bit annoying for the clock API).

Quoted 7 lines
Quoted 4 lines

It's adding platform data in the first place that gets tedious - and of course there's also DT and ACPI to worry about, it's not just a case of platform data and then you're done. Pushing the lookup into library code means that drivers don't have to worry about any of this stuff.

I agree, so just pass around the pointer to the phy and all is good. No need to worry about DT or ACPI or anything else.

No, in practice passing around the pointer gets tricky if you're using something other than board files (or even are doing any kind of dynamic stuff with board files) since the two devices need to find each other and if you're using platform data then the code doing the matching has to know about the platform data for every device it might need to match which is just miserable.

Something would need to do something like allocate the PHY objects and then arrange for them to be passed to both provider and consumer devices prior to those being registered, knowing where to place the pointers in the platform data for each device. This is straightforward with board files but not otherwise, people have tried this before.

Quoted 10 lines
Quoted 6 lines

For most of the APIs doing this there is a clear and unambiguous name in the hardware that can be used (and for hardware process reasons is unlikely to get changed). The major exception to this is the clock API since it is relatively rare to have clear, segregated IP level information for IPs baked into larger chips. The other APIs tend to be establishing chip to chip links.

The clock api is having problems with multiple "names" due to dynamic devices from what I was told. I want to prevent the PHY interface from having that same issue.

I think the underlying issue here is that we don't have a good enough
general way for board files (or other C code but mostly them) to talk
about devices prior to their being registered - rather than have the
pointer you're talking about be the PHY object itself have the pointer
be something which allows us to match the struct device when it's
created. This should be transparent to drivers and would be usable by
all the existing APIs.
-------------- 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/20130724/937f4864/attachment.sig>

#43 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

In reply to Greg KH
Quoted 7 lines · On Tuesday 23 of July 2013 10:37:11 Greg KH wrote:
Quoted 6 lines · Tomasz Figa
Quoted 5 lines

Ick, no. Why can't you just pass the pointer to the phy itself? If you
had a "priv" pointer to search from, then you could have just passed the
original phy pointer in the first place, right?

Quoted 5 lines
Quoted 2 lines

IMHO it would be better if you provided some code example, but let's try to check if I understood you correctly.

It's not my code that I want to have added, so I don't have to write examples, I just get to complain about the existing stuff :)

Still, I think that some small code snippets illustrating the idea are really helpful.

Quoted 59 lines
Quoted 31 lines

8><--------------------------------------------------------------------
----

[Board file]

static struct phy my_phy;

static struct platform_device phy_pdev = {

	/* ... */
	.platform_data = &my_phy;
	/* ... */

};

static struct platform_device phy_pdev = {

	/* ... */
	.platform_data = &my_phy;
	/* ... */

};

[Provider driver]

struct phy *phy = pdev->dev.platform_data;

ret = phy_create(phy);

[Consumer driver]

Quoted 8 lines

struct phy *phy = pdev->dev.platform_data;

ret = phy_get(&pdev->dev, phy);

-----------------------------------------------------------------------
-><8

Is this what you mean?

No. Well, kind of. What's wrong with using the platform data structure unique to the board to have the pointer?

For example (just randomly picking one), the ata-pxa driver would change include/linux/platform_data/ata-pxa.h to have a phy pointer in it:

struct phy;

struct  pata_pxa_pdata {
	/* PXA DMA DREQ<0:2> pin */
	uint32_t	dma_dreq;
	/* Register shift */
	uint32_t	reg_shift;
	/* IRQ flags */
	uint32_t	irq_flags;
	/* PHY */
	struct phy	*phy;
};
Quoted 3 lines

Then, when you create the platform, set the phy* pointer with a call to phy_create(). Then you can use that pointer wherever that plaform data is available (i.e. whereever platform_data is at).

Hmm? So, do you suggest to call phy_create() from board file? What phy_ops struct and other hardware parameters would it take?

Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

The issue is that a string "name" is not going to scale at all, as it requires hard-coded information that will change over time (as the existing clock interface is already showing.)

I fully agree that a simple, single string will not scale even in some, not so uncommon cases, but there is already a lot of existing lookup solutions over the kernel and so there is no point in introducing another one.

I'm trying to get _rid_ of lookup "solutions" and just use a real pointer, as you should. I'll go tackle those other ones after this one is taken care of, to show how the others should be handled as well.

There was a reason for introducing lookup solutions. The reason was that in board file there is no way to get a pointer to something that is going to be created much later in time. We don't do time travel ;-).

Quoted 12 lines
Quoted 11 lines
Quoted 5 lines

Please just pass the real "phy" pointer around, that's what it is there
for. Your "board binding" logic/code should be able to handle this, as
it somehow was going to do the same thing with a "name".

It's technically correct, but quality of this solution isn't really nice, because it's a layering violation (at least if I understood what you mean). This is because you need to have full definition of struct phy in board file and a structure that is used as private data in PHY core comes from platform code.

Quoted 6 lines

No, just a pointer, you don't need the "full" structure until you get to some .c code that actually manipulates the phy itself, for all other places, you are just dealing with a pointer and a structure you never reference.

Does that make more sense?

Well, to the point that I think I now understood your suggestion. Unfortunately the suggestion alone isn't really something that can be done, considering how driver core and generic frameworks work.

Best regards,
Tomasz

maintainer
#44 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 116 lines · Tomasz Figa
Quoted 7 lines · On Tuesday 23 of July 2013 10:37:11 Greg KH wrote:
Quoted 6 lines · Tomasz Figa
Quoted 5 lines

Ick, no. Why can't you just pass the pointer to the phy itself? If you
had a "priv" pointer to search from, then you could have just passed the
original phy pointer in the first place, right?

Quoted 5 lines
Quoted 2 lines

IMHO it would be better if you provided some code example, but let's try to check if I understood you correctly.

It's not my code that I want to have added, so I don't have to write examples, I just get to complain about the existing stuff :)

Still, I think that some small code snippets illustrating the idea are really helpful.

Quoted 59 lines
Quoted 31 lines

8><--------------------------------------------------------------------
----

[Board file]

static struct phy my_phy;

static struct platform_device phy_pdev = {

	/* ... */
	.platform_data = &my_phy;
	/* ... */

};

static struct platform_device phy_pdev = {

	/* ... */
	.platform_data = &my_phy;
	/* ... */

};

[Provider driver]

struct phy *phy = pdev->dev.platform_data;

ret = phy_create(phy);

[Consumer driver]

Quoted 8 lines

struct phy *phy = pdev->dev.platform_data;

ret = phy_get(&pdev->dev, phy);

-----------------------------------------------------------------------
-><8

Is this what you mean?

No. Well, kind of. What's wrong with using the platform data structure unique to the board to have the pointer?

For example (just randomly picking one), the ata-pxa driver would change include/linux/platform_data/ata-pxa.h to have a phy pointer in it:

struct phy;

struct  pata_pxa_pdata {
	/* PXA DMA DREQ<0:2> pin */
	uint32_t	dma_dreq;
	/* Register shift */
	uint32_t	reg_shift;
	/* IRQ flags */
	uint32_t	irq_flags;
	/* PHY */
	struct phy	*phy;
};
Quoted 3 lines

Then, when you create the platform, set the phy* pointer with a call to phy_create(). Then you can use that pointer wherever that plaform data is available (i.e. whereever platform_data is at).

Hmm? So, do you suggest to call phy_create() from board file? What phy_ops struct and other hardware parameters would it take?

Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

The issue is that a string "name" is not going to scale at all, as it requires hard-coded information that will change over time (as the existing clock interface is already showing.)

I fully agree that a simple, single string will not scale even in some, not so uncommon cases, but there is already a lot of existing lookup solutions over the kernel and so there is no point in introducing another one.

I'm trying to get _rid_ of lookup "solutions" and just use a real pointer, as you should. I'll go tackle those other ones after this one is taken care of, to show how the others should be handled as well.

There was a reason for introducing lookup solutions. The reason was that in board file there is no way to get a pointer to something that is going to be created much later in time. We don't do time travel ;-).

Quoted 17 lines
Quoted 11 lines
Quoted 5 lines

Please just pass the real "phy" pointer around, that's what it is there
for. Your "board binding" logic/code should be able to handle this, as
it somehow was going to do the same thing with a "name".

It's technically correct, but quality of this solution isn't really nice, because it's a layering violation (at least if I understood what you mean). This is because you need to have full definition of struct phy in board file and a structure that is used as private data in PHY core comes from platform code.

No, just a pointer, you don't need the "full" structure until you get to some .c code that actually manipulates the phy itself, for all other places, you are just dealing with a pointer and a structure you never reference.

Quoted 5 lines
Quoted 1 line

Does that make more sense?

Well, to the point that I think I now understood your suggestion. Unfortunately the suggestion alone isn't really something that can be done, considering how driver core and generic frameworks work.

Ok, given that I seem to be totally confused as to exactly how the board-specific frameworks work, I'll take your word for it.

But again, I will not accept "lookup by name" type solutions, when the "name" is dynamic and will change. Because you are using a "name", you can deal with a pointer, putting it _somewhere_ in your board-specific data structures, as you are going to need to store it anyway (hint, you had to get that "name" from somewhere, right?)

And maybe the way that these "generic frameworks" are created is wrong, given that you don't feel that a generic pointer can be passed to the needed devices. That seems like a huge problem, one that has already been pointed out is causing issues with other subsystems.

So maybe they need to be fixed?

thanks,

greg k-h

#45 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 140 lines · On Tuesday 23 of July 2013 11:04:14 Greg KH wrote:
Quoted 139 lines · Tomasz Figa
Quoted 9 lines · On Tuesday 23 of July 2013 10:37:11 Greg KH wrote:
Quoted 8 lines · Tomasz Figa
Quoted 7 lines

Ick, no. Why can't you just pass the pointer to the phy itself?
If
you
had a "priv" pointer to search from, then you could have just passed
the
original phy pointer in the first place, right?

Quoted 6 lines
Quoted 3 lines

IMHO it would be better if you provided some code example, but let's
try to check if I understood you correctly.

It's not my code that I want to have added, so I don't have to write examples, I just get to complain about the existing stuff :)

Still, I think that some small code snippets illustrating the idea are really helpful.

Quoted 62 lines
Quoted 34 lines

8><---------------------------------------------------------------
-----
----

[Board file]

static struct phy my_phy;

static struct platform_device phy_pdev = {

	/* ... */
	.platform_data = &my_phy;
	/* ... */

};

static struct platform_device phy_pdev = {

	/* ... */
	.platform_data = &my_phy;
	/* ... */

};

[Provider driver]

struct phy *phy = pdev->dev.platform_data;

ret = phy_create(phy);

[Consumer driver]

struct phy *phy = pdev->dev.platform_data;

Quoted 7 lines

ret = phy_get(&pdev->dev, phy);

------------------------------------------------------------------
-----
-><8

Is this what you mean?

No. Well, kind of. What's wrong with using the platform data structure unique to the board to have the pointer?

For example (just randomly picking one), the ata-pxa driver would change include/linux/platform_data/ata-pxa.h to have a phy pointer in it:

struct phy;

struct pata_pxa_pdata {

	/* PXA DMA DREQ<0:2> pin */
	uint32_t	dma_dreq;
	/* Register shift */
	uint32_t	reg_shift;
	/* IRQ flags */
	uint32_t	irq_flags;
	/* PHY */
	struct phy	*phy;
Quoted 7 lines

};

Then, when you create the platform, set the phy* pointer with a call to
phy_create(). Then you can use that pointer wherever that plaform data
is available (i.e. whereever platform_data is at).

Hmm? So, do you suggest to call phy_create() from board file? What phy_ops struct and other hardware parameters would it take?

Quoted 13 lines
Quoted 6 lines
Quoted 5 lines

The issue is that a string "name" is not going to scale at all, as it
requires hard-coded information that will change over time (as the
existing clock interface is already showing.)

Quoted 6 lines

I fully agree that a simple, single string will not scale even in some,
not so uncommon cases, but there is already a lot of existing lookup
solutions over the kernel and so there is no point in introducing another one.

Quoted 4 lines

I'm trying to get _rid_ of lookup "solutions" and just use a real pointer, as you should. I'll go tackle those other ones after this one
is taken care of, to show how the others should be handled as well.

There was a reason for introducing lookup solutions. The reason was that in board file there is no way to get a pointer to something that is going to be created much later in time. We don't do time travel ;-).

Quoted 23 lines
Quoted 8 lines
Quoted 7 lines

Please just pass the real "phy" pointer around, that's what it is
there
for. Your "board binding" logic/code should be able to handle this,
as
it somehow was going to do the same thing with a "name".

Quoted 9 lines

It's technically correct, but quality of this solution isn't really
nice, because it's a layering violation (at least if I understood what
you mean). This is because you need to have full definition of struct
phy in board file and a structure that is used as private data in PHY
core comes from platform code.

No, just a pointer, you don't need the "full" structure until you get to some .c code that actually manipulates the phy itself, for all other places, you are just dealing with a pointer and a structure you never reference.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Does that make more sense?

Well, to the point that I think I now understood your suggestion. Unfortunately the suggestion alone isn't really something that can be done, considering how driver core and generic frameworks work.

Ok, given that I seem to be totally confused as to exactly how the board-specific frameworks work, I'll take your word for it.

Well, they are working in a way that keeps separation of layers, making things clean. Platform code should not (well, there might exist some in tree hacks, but this should not be propagated) used to exchange data between drivers, but rather to specify board specific parameters for generic drivers. If drivers need to cooperate, there must be a dedicated interface for this, like the PHY framework Kishon is introducing here.

Sure, with platform code you can do a lot of hacky things, for example you can simply provide PHY callbacks inside platform_data, like it was being done historically, but that's just ugly.

Anyway, board files should now be rather considered a historical thing. We are moving towards full DT-based description on ARM systems and so board files and related things, like name-based lookups, statically registered platform devices and so one are going away. Device Tree handles such provider-consumer links automatically using specifiers with phandles and lookup by node + provider-specific specifier args, so all the problems with binding things together just go away.

Quoted 5 lines

But again, I will not accept "lookup by name" type solutions, when the "name" is dynamic and will change. Because you are using a "name", you can deal with a pointer, putting it _somewhere_ in your board-specific data structures, as you are going to need to store it anyway (hint, you had to get that "name" from somewhere, right?)

Yes. This kind of artificial names passed to both provider and consumer isn't really a good way of lookup. This is just an example of bad lookup key, though. IMHO for a good example of lookup you should see regulator framework.

Quoted 4 lines

And maybe the way that these "generic frameworks" are created is wrong, given that you don't feel that a generic pointer can be passed to the needed devices. That seems like a huge problem, one that has already been pointed out is causing issues with other subsystems.

What problem are you talking about here? AFAIK frameworks using correctly designed lookup do work fine for most, if not all, people. See the regulator framework.

Quoted 1 line

So maybe they need to be fixed?

I don't really think anything is broken here, so there is nothing to fix.

Best regards,
Tomasz

#46 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

In reply to Tomasz Figa
Quoted 9 lines · Tomasz Figa

IMHO it would be better if you provided some code example, but let's try to check if I understood you correctly.

8><------------------------------------------------------------------------

[Board file]

static struct phy my_phy;

Quoted 7 lines
static struct platform_device phy_pdev = {
	/* ... */
	.platform_data = &my_phy;
	/* ... */
};

static struct platform_device phy_pdev = {

This should be controller_pdev, not phy_pdev, yes?

Quoted 9 lines
	/* ... */
	.platform_data = &my_phy;
	/* ... */
};

[Provider driver]

struct phy *phy = pdev->dev.platform_data;

Quoted 7 lines

ret = phy_create(phy);

[Consumer driver]

struct phy *phy = pdev->dev.platform_data;

ret = phy_get(&pdev->dev, phy);

Or even just phy_get(&pdev->dev), because phy_get() could be smart enough to to set phy = dev->platform_data.

Quoted 3 lines

------------------------------------------------------------------------><8

Is this what you mean?

That's what I was going to suggest too. The struct phy is defined in the board file, which already knows about all the PHYs that exist in the system. (Or perhaps it is allocated dynamically, so that when many board files are present in the same kernel, only the entries listed in the board file for the current system get created.) Then the structure's address is stored in the platform data and made available to both the provider and the consumer.

Even though the struct phy is defined (or allocated) in the board file, its contents don't get filled in until the PHY driver provides the details.

Quoted 5 lines

It's technically correct, but quality of this solution isn't really nice, because it's a layering violation (at least if I understood what you mean). This is because you need to have full definition of struct phy in board file and a structure that is used as private data in PHY core comes from platform code.

You don't have to have a full definition in the board file. Just a partial definition -- most of the contents can be filled in later, when the PHY driver is ready to store the private data.

It's not a layering violation for one region of the kernel to store private data in a structure defined by another part of the kernel. This happens all the time (e.g., dev_set_drvdata).

Alan Stern

#47 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 17 lines · On Tuesday 23 of July 2013 15:36:00 Alan Stern wrote:
Quoted 16 lines · Tomasz Figa

IMHO it would be better if you provided some code example, but let's try to check if I understood you correctly.

8><-------------------------------------------------------------------
-----

[Board file]

static struct phy my_phy;

static struct platform_device phy_pdev = {

	/* ... */
	.platform_data = &my_phy;
	/* ... */
Quoted 5 lines
Quoted 3 lines

};

static struct platform_device phy_pdev = {

This should be controller_pdev, not phy_pdev, yes?

Right. A copy-pasto.

Quoted 13 lines
Quoted 13 lines
	/* ... */
	.platform_data = &my_phy;
	/* ... */

};

[Provider driver]

struct phy *phy = pdev->dev.platform_data;

ret = phy_create(phy);

Quoted 8 lines
Quoted 5 lines

[Consumer driver]

struct phy *phy = pdev->dev.platform_data;

ret = phy_get(&pdev->dev, phy);

Or even just phy_get(&pdev->dev), because phy_get() could be smart enough to to set phy = dev->platform_data.

Unless you need more than one PHY in this driver...

Quoted 11 lines
Quoted 5 lines

----------------------------------------------------------------------
--><8

Is this what you mean?

That's what I was going to suggest too. The struct phy is defined in the board file, which already knows about all the PHYs that exist in the system. (Or perhaps it is allocated dynamically, so that when many board files are present in the same kernel, only the entries listed in the board file for the current system get created.)

Well, such dynamic allocation is a must. We don't accept non-multiplatform aware code anymore, not even saying about multiboard.

Quoted 3 lines

Then the
structure's address is stored in the platform data and made available to both the provider and the consumer.

Yes, technically this can work. You would still have to perform some kind of synchronization to make sure that the PHY bound to this structure is actually present. This is again technically doable (e.g. a list of registered struct phys inside PHY core).

Quoted 3 lines

Even though the struct phy is defined (or allocated) in the board file, its contents don't get filled in until the PHY driver provides the details.

You can't assure this. Board file is free to do whatever it wants with this struct. A clean solution would prevent this.

Quoted 6 lines
Quoted 5 lines

It's technically correct, but quality of this solution isn't really nice, because it's a layering violation (at least if I understood what you mean). This is because you need to have full definition of struct phy in board file and a structure that is used as private data in PHY core comes from platform code.

Quoted 7 lines

You don't have to have a full definition in the board file. Just a partial definition -- most of the contents can be filled in later, when the PHY driver is ready to store the private data.

It's not a layering violation for one region of the kernel to store private data in a structure defined by another part of the kernel. This happens all the time (e.g., dev_set_drvdata).

Not really. The phy struct is something that _is_ private data of PHY subsystem, not something that can store private data of PHY subsystem (sure it can store private data of particular PHY driver, but that's another story) and only PHY subsystem should have access to its contents.

By the way, we need to consider other cases here as well, for example it would be nice to have a single phy_get() function that works for both non- DT and DT cases to make the consumer driver not have to worry whether it's being probed from DT or not.

I'd suggest simply reusing the lookup method of regulator framework, just as I suggested here:

http://thread.gmane.org/gmane.linux.ports.arm.kernel/252813/focus=101661

Best regards,
Tomasz

#48 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 9 lines · Tomasz Figa
Quoted 5 lines

That's what I was going to suggest too. The struct phy is defined in the board file, which already knows about all the PHYs that exist in the system. (Or perhaps it is allocated dynamically, so that when many board files are present in the same kernel, only the entries listed in the board file for the current system get created.)

Well, such dynamic allocation is a must. We don't accept non-multiplatform aware code anymore, not even saying about multiboard.

Quoted 8 lines
Quoted 3 lines

Then the
structure's address is stored in the platform data and made available to both the provider and the consumer.

Yes, technically this can work. You would still have to perform some kind of synchronization to make sure that the PHY bound to this structure is actually present. This is again technically doable (e.g. a list of registered struct phys inside PHY core).

The synchronization takes place inside phy_get. If phy_create hasn't been called for this structure by the time phy_get runs, phy_get will return an error.

Quoted 6 lines
Quoted 3 lines

Even though the struct phy is defined (or allocated) in the board file, its contents don't get filled in until the PHY driver provides the details.

You can't assure this. Board file is free to do whatever it wants with this struct. A clean solution would prevent this.

I'm not sure what you mean here. Of course I can't prevent a board file from messing up a data structure. I can't prevent it from causing memory access violations either; in fact, I can't prevent any bugs in other people's code.

Besides, why do you say the board file is free to do whatever it wants with the struct phy? Currently the struct phy is created by the PHY provider and the PHY core, right? It's not even mentioned in the board file.

Quoted 10 lines
Quoted 10 lines
Quoted 5 lines

It's technically correct, but quality of this solution isn't really nice, because it's a layering violation (at least if I understood what you mean). This is because you need to have full definition of struct phy in board file and a structure that is used as private data in PHY core comes from platform code.

You don't have to have a full definition in the board file. Just a partial definition -- most of the contents can be filled in later, when the PHY driver is ready to store the private data.

Quoted 8 lines
Quoted 3 lines

It's not a layering violation for one region of the kernel to store private data in a structure defined by another part of the kernel. This happens all the time (e.g., dev_set_drvdata).

Not really. The phy struct is something that _is_ private data of PHY subsystem, not something that can store private data of PHY subsystem (sure it can store private data of particular PHY driver, but that's another story) and only PHY subsystem should have access to its contents.

If you want to keep the phy struct completely separate from the board file, there's an easy way to do it. Let's say the board file knows about N different PHYs in the system. Then you define an array of N pointers to phys:

struct phy *(phy_address[N]);

In the platform data for both PHY j and its controller, store &phy_address[j]. The PHY provider passes this cookie to phy_create:

	cookie = pdev->dev.platform_data;
	ret = phy_create(phy, cookie);

and phy_create simply stores: *cookie = phy. The PHY consumer does much the same the same thing:

	cookie = pdev->dev.platform_data;
	phy = phy_get(cookie);

phy_get returns *cookie if it isn't NULL, or an ERR_PTR otherwise.

Quoted 4 lines

By the way, we need to consider other cases here as well, for example it would be nice to have a single phy_get() function that works for both non- DT and DT cases to make the consumer driver not have to worry whether it's being probed from DT or not.

You ought to be able to adapt this scheme to work with DT. Maybe by having multiple "phy_address" arrays.

Alan Stern

#49 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 19 lines · On Tuesday 23 of July 2013 16:53:55 Alan Stern wrote:
Quoted 18 lines · Tomasz Figa
Quoted 8 lines

That's what I was going to suggest too. The struct phy is defined in
the board file, which already knows about all the PHYs that exist in the system. (Or perhaps it is allocated dynamically, so that when many
board files are present in the same kernel, only the entries listed in
the board file for the current system get created.)

Well, such dynamic allocation is a must. We don't accept non-multiplatform aware code anymore, not even saying about multiboard.

Quoted 4 lines

Then the
structure's address is stored in the platform data and made available
to both the provider and the consumer.

Quoted 8 lines
Quoted 4 lines

Yes, technically this can work. You would still have to perform some kind of synchronization to make sure that the PHY bound to this structure is actually present. This is again technically doable (e.g. a list of registered struct phys inside PHY core).

The synchronization takes place inside phy_get. If phy_create hasn't been called for this structure by the time phy_get runs, phy_get will return an error.

Yes, this is the solution that I had in mind when saying that this is doable.

Quoted 13 lines
Quoted 7 lines
Quoted 4 lines

Even though the struct phy is defined (or allocated) in the board file,
its contents don't get filled in until the PHY driver provides the details.

You can't assure this. Board file is free to do whatever it wants with this struct. A clean solution would prevent this.

I'm not sure what you mean here. Of course I can't prevent a board file from messing up a data structure. I can't prevent it from causing memory access violations either; in fact, I can't prevent any bugs in other people's code.

Quoted 4 lines

Besides, why do you say the board file is free to do whatever it wants with the struct phy? Currently the struct phy is created by the PHY provider and the PHY core, right? It's not even mentioned in the board file.

I mean, if you have a struct type of which full declaration is available for some code, this code can access any memeber of it without any hacks, which is not something that we want to have in board files. The phy struct should be opaque for them.

Quoted 36 lines
Quoted 18 lines
Quoted 9 lines
Quoted 8 lines

It's technically correct, but quality of this solution isn't really
nice, because it's a layering violation (at least if I understood what you mean). This is because you need to have full definition of
struct phy in board file and a structure that is used as private data
in PHY core comes from platform code.

Quoted 8 lines

You don't have to have a full definition in the board file. Just a partial definition -- most of the contents can be filled in later, when
the PHY driver is ready to store the private data.

It's not a layering violation for one region of the kernel to store private data in a structure defined by another part of the kernel. This happens all the time (e.g., dev_set_drvdata).

Quoted 5 lines

Not really. The phy struct is something that _is_ private data of PHY subsystem, not something that can store private data of PHY subsystem (sure it can store private data of particular PHY driver, but that's another story) and only PHY subsystem should have access to its contents.

If you want to keep the phy struct completely separate from the board file, there's an easy way to do it. Let's say the board file knows about N different PHYs in the system. Then you define an array of N pointers to phys:

struct phy *(phy_address[N]);

In the platform data for both PHY j and its controller, store &phy_address[j]. The PHY provider passes this cookie to phy_create:

	cookie = pdev->dev.platform_data;
	ret = phy_create(phy, cookie);
Quoted 7 lines

and phy_create simply stores: *cookie = phy. The PHY consumer does much the same the same thing:

	cookie = pdev->dev.platform_data;
	phy = phy_get(cookie);

phy_get returns *cookie if it isn't NULL, or an ERR_PTR otherwise.

OK, this can work. Again, just technically, because it's rather ugly.

Quoted 7 lines
Quoted 4 lines

By the way, we need to consider other cases here as well, for example it would be nice to have a single phy_get() function that works for both non- DT and DT cases to make the consumer driver not have to worry whether it's being probed from DT or not.

You ought to be able to adapt this scheme to work with DT. Maybe by having multiple "phy_address" arrays.

Where would you want to have those phy_address arrays stored? There are no board files when booting with DT. Not even saying that you don't need to use any hacky schemes like this when you have DT that nicely specifies relations between devices.

Anyway, board file should not be considered as a method to exchange data between drivers. It should be used only to pass data from it to drivers, not the other way. Ideally all data in a board file should be marked as const and __init and dropped after system initialization.

Best regards,
Tomasz

#50 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 16 lines · Tomasz Figa
Quoted 16 lines

If you want to keep the phy struct completely separate from the board file, there's an easy way to do it. Let's say the board file knows about N different PHYs in the system. Then you define an array of N pointers to phys:

struct phy *(phy_address[N]);

In the platform data for both PHY j and its controller, store &phy_address[j]. The PHY provider passes this cookie to phy_create:

	cookie = pdev->dev.platform_data;
	ret = phy_create(phy, cookie);

and phy_create simply stores: *cookie = phy. The PHY consumer does much the same the same thing:

Quoted 6 lines
Quoted 4 lines
	cookie = pdev->dev.platform_data;
	phy = phy_get(cookie);

phy_get returns *cookie if it isn't NULL, or an ERR_PTR otherwise.

OK, this can work. Again, just technically, because it's rather ugly.

There's no reason the phy_address things have to be arrays. A separate individual pointer for each PHY would work just as well.

Quoted 4 lines

Where would you want to have those phy_address arrays stored? There are no board files when booting with DT. Not even saying that you don't need to use any hacky schemes like this when you have DT that nicely specifies relations between devices.

If everybody agrees DT has a nice scheme for specifying relations between devices, why not use that same scheme in the PHY core?

Quoted 4 lines

Anyway, board file should not be considered as a method to exchange data between drivers. It should be used only to pass data from it to drivers, not the other way. Ideally all data in a board file should be marked as const and __init and dropped after system initialization.

The phy_address things don't have to be defined or allocated in the board file; they could be set up along with the platform data.

In any case, this was simply meant to be a suggestion to show that it is relatively easy to do what you need without using name or ID strings.

Alan Stern

#51 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 28 lines · On Tuesday 23 of July 2013 17:14:20 Alan Stern wrote:
Quoted 16 lines · Tomasz Figa
Quoted 16 lines

If you want to keep the phy struct completely separate from the board
file, there's an easy way to do it. Let's say the board file knows about N different PHYs in the system. Then you define an array of N pointers to phys:

struct phy *(phy_address[N]);

In the platform data for both PHY j and its controller, store

&phy_address[j]. The PHY provider passes this cookie to phy_create:

	cookie = pdev->dev.platform_data;
	ret = phy_create(phy, cookie);

and phy_create simply stores: *cookie = phy. The PHY consumer does

Quoted 7 lines
Quoted 5 lines

much the same the same thing:

	cookie = pdev->dev.platform_data;
	phy = phy_get(cookie);

phy_get returns *cookie if it isn't NULL, or an ERR_PTR otherwise.

OK, this can work. Again, just technically, because it's rather ugly.

There's no reason the phy_address things have to be arrays. A separate individual pointer for each PHY would work just as well.

Quoted 7 lines
Quoted 4 lines

Where would you want to have those phy_address arrays stored? There are no board files when booting with DT. Not even saying that you don't need to use any hacky schemes like this when you have DT that nicely specifies relations between devices.

If everybody agrees DT has a nice scheme for specifying relations between devices, why not use that same scheme in the PHY core?

It is already used, for cases when consumer device has a DT node attached. In non-DT case this kind lookup translates loosely to something that is being done in regulator framework - you can't bind devices by pointers, because you don't have those pointers, so you need to use device names.

Quoted 8 lines
Quoted 5 lines

Anyway, board file should not be considered as a method to exchange data between drivers. It should be used only to pass data from it to drivers, not the other way. Ideally all data in a board file should be marked as const and __init and dropped after system initialization.

The phy_address things don't have to be defined or allocated in the board file; they could be set up along with the platform data.

There is no platform data when booting with DT.

Quoted 3 lines

In any case, this was simply meant to be a suggestion to show that it is relatively easy to do what you need without using name or ID strings.

Sure. It's good to have different options discussed as well.

Best regards,
Tomasz

#52 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 7 lines · Tomasz Figa
Quoted 6 lines · On Tuesday 23 of July 2013 17:14:20 Alan Stern wrote:
Quoted 4 lines · Tomasz Figa

Where would you want to have those phy_address arrays stored? There are no board files when booting with DT. Not even saying that you don't need to use any hacky schemes like this when you have DT that nicely specifies relations between devices.

Quoted 8 lines
Quoted 2 lines

If everybody agrees DT has a nice scheme for specifying relations between devices, why not use that same scheme in the PHY core?

It is already used, for cases when consumer device has a DT node attached. In non-DT case this kind lookup translates loosely to something that is being done in regulator framework - you can't bind devices by pointers, because you don't have those pointers, so you need to use device names.

Sorry for jumping in to the middle of the discussion, but why does a *new* framework even bother defining an interface for board files?

Can't we just drop any interfaces for platform data passing in the phy framework and put the burden of adding those to anyone who actually needs them? All the platforms we are concerned with here (exynos and omap, plus new platforms) can be booted using DT anyway.

Arnd

#53 lore raw

PATCH 1/15 drivers: phy: add generic PHY framework

Hi,

Quoted 17 lines · Arnd Bergmann
Quoted 7 lines · Tomasz Figa
Quoted 6 lines · On Tuesday 23 of July 2013 17:14:20 Alan Stern wrote:
Quoted 4 lines · Tomasz Figa

Where would you want to have those phy_address arrays stored? There are no board files when booting with DT. Not even saying that you don't need to use any hacky schemes like this when you have DT that nicely specifies relations between devices.

Quoted 8 lines
Quoted 2 lines

If everybody agrees DT has a nice scheme for specifying relations between devices, why not use that same scheme in the PHY core?

It is already used, for cases when consumer device has a DT node attached. In non-DT case this kind lookup translates loosely to something that is being done in regulator framework - you can't bind devices by pointers, because you don't have those pointers, so you need to use device names.

Quoted 7 lines

Sorry for jumping in to the middle of the discussion, but why does a *new* framework even bother defining an interface for board files?

Can't we just drop any interfaces for platform data passing in the phy framework and put the burden of adding those to anyone who actually needs them? All the platforms we are concerned with here (exynos and omap, plus new platforms) can be booted using DT anyway.

The OMAP3 platforms still needs to be supported for non-dt :-s

Thanks
Kishon

#54 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 21 lines · Kishon Vijay Abraham I
Quoted 20 lines · Arnd Bergmann
Quoted 7 lines · Tomasz Figa
Quoted 6 lines · On Tuesday 23 of July 2013 17:14:20 Alan Stern wrote:
Quoted 4 lines · Tomasz Figa

Where would you want to have those phy_address arrays stored? There are no board files when booting with DT. Not even saying that you don't need to use any hacky schemes like this when you have DT that nicely specifies relations between devices.

Quoted 8 lines
Quoted 2 lines

If everybody agrees DT has a nice scheme for specifying relations between devices, why not use that same scheme in the PHY core?

It is already used, for cases when consumer device has a DT node attached. In non-DT case this kind lookup translates loosely to something that is being done in regulator framework - you can't bind devices by pointers, because you don't have those pointers, so you need to use device names.

Sorry for jumping in to the middle of the discussion, but why does a new framework even bother defining an interface for board files?

Quoted 6 lines
Quoted 4 lines

Can't we just drop any interfaces for platform data passing in the phy framework and put the burden of adding those to anyone who actually needs them? All the platforms we are concerned with here (exynos and omap, plus new platforms) can be booted using DT anyway.

The OMAP3 platforms still needs to be supported for non-dt :-s

Can't you leave the existing PHY handling for legacy OMAP3 USB PHY until they are all converted? I don't expect that to take a long time now that the OMAP4 board files have been removed. Are there still drivers without DT bindings that hold up the removal of the OMAP3 board files?

Otherwise I'd suggest delaying the phy subsystem by another merge window, until that is resolved.

Arnd

#55 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

In reply to Arnd Bergmann
Quoted 17 lines · Arnd Bergmann
Quoted 7 lines · Tomasz Figa
Quoted 6 lines · On Tuesday 23 of July 2013 17:14:20 Alan Stern wrote:
Quoted 4 lines · Tomasz Figa

Where would you want to have those phy_address arrays stored? There are no board files when booting with DT. Not even saying that you don't need to use any hacky schemes like this when you have DT that nicely specifies relations between devices.

Quoted 8 lines
Quoted 2 lines

If everybody agrees DT has a nice scheme for specifying relations between devices, why not use that same scheme in the PHY core?

It is already used, for cases when consumer device has a DT node attached. In non-DT case this kind lookup translates loosely to something that is being done in regulator framework - you can't bind devices by pointers, because you don't have those pointers, so you need to use device names.

Quoted 7 lines

Sorry for jumping in to the middle of the discussion, but why does a *new* framework even bother defining an interface for board files?

Can't we just drop any interfaces for platform data passing in the phy framework and put the burden of adding those to anyone who actually needs them? All the platforms we are concerned with here (exynos and omap, plus new platforms) can be booted using DT anyway.

Indeed, I was also a bit surprised we still need non-dt support, since migration to this generic PHY framework in case of exynos was solely part of migration of the whole platform to DT.

Two of the drivers that are being converted are also used on s5pv210, but there is currently no boards in mainline that would use devices covered by those drivers and s5pv210 will very likely get DT support in v3.13 anyway.

But it seems omap still needs non-dt support in the PHY framework.

---
Thanks,
Sylwester

#56 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

In reply to Arnd Bergmann
Quoted 7 lines · Arnd Bergmann

Sorry for jumping in to the middle of the discussion, but why does a *new* framework even bother defining an interface for board files?

Can't we just drop any interfaces for platform data passing in the phy framework and put the burden of adding those to anyone who actually needs them? All the platforms we are concerned with here (exynos and omap, plus new platforms) can be booted using DT anyway.

There's a bunch of non-DT architectures that are in active use (blackfin for example) and I'd really hope that this is useful for some of them.

The pushback here was about the fact that the subsystem was doing odd
things with selecting device names which is odd in itself, I don't know
if that had bled over into the DT bindings but it sounded like it
might've done so.
-------------- 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/20130725/51a7cbff/attachment.sig>

#57 lore raw

PATCH 1/15 drivers: phy: add generic PHY framework

Hi,

Quoted 10 lines · Mark Brown
Quoted 7 lines · Arnd Bergmann

Sorry for jumping in to the middle of the discussion, but why does a *new* framework even bother defining an interface for board files?

Can't we just drop any interfaces for platform data passing in the phy framework and put the burden of adding those to anyone who actually needs them? All the platforms we are concerned with here (exynos and omap, plus new platforms) can be booted using DT anyway.

Quoted 7 lines

There's a bunch of non-DT architectures that are in active use (blackfin for example) and I'd really hope that this is useful for some of them.

The pushback here was about the fact that the subsystem was doing odd things with selecting device names which is odd in itself, I don't know if that had bled over into the DT bindings but it sounded like it might've done so.

Not really. device names was specifically used for non-dt boot case. For dt, it uses the phandle mechanism which is pretty much used in all other subsystems. Anyway I'm fixing Greg's comments and will posting a new version soon.

Thanks
Kishon

#58 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

In reply to Arnd Bergmann

Hi Arnd,

Quoted 16 lines · On Wednesday 24 July 2013 20:32:03 Arnd Bergmann wrote:
Quoted 7 lines · Tomasz Figa
Quoted 6 lines · On Tuesday 23 of July 2013 17:14:20 Alan Stern wrote:
Quoted 4 lines · Tomasz Figa

Where would you want to have those phy_address arrays stored? There are no board files when booting with DT. Not even saying that you don't need to use any hacky schemes like this when you have DT that nicely specifies relations between devices.

Quoted 7 lines
Quoted 2 lines

If everybody agrees DT has a nice scheme for specifying relations between devices, why not use that same scheme in the PHY core?

It is already used, for cases when consumer device has a DT node attached. In non-DT case this kind lookup translates loosely to something that is being done in regulator framework - you can't bind devices by pointers, because you don't have those pointers, so you need to use device names.

Quoted 7 lines

Sorry for jumping in to the middle of the discussion, but why does a *new* framework even bother defining an interface for board files?

Can't we just drop any interfaces for platform data passing in the phy framework and put the burden of adding those to anyone who actually needs them? All the platforms we are concerned with here (exynos and omap, plus new platforms) can be booted using DT anyway.

What about non-DT architectures such as MIPS (still widely used in consumer networking equipments from what I've heard) ?

Signature · 3 lines
Regards,

Laurent Pinchart
#59 lore raw

PATCH 1/15 drivers: phy: add generic PHY framework

2013/7/25 Laurent Pinchart <[email protected]>:

Quoted 22 lines

Hi Arnd,

Quoted 19 lines · On Wednesday 24 July 2013 20:32:03 Arnd Bergmann wrote:
Quoted 7 lines · Tomasz Figa
Quoted 6 lines · On Tuesday 23 of July 2013 17:14:20 Alan Stern wrote:
Quoted 4 lines · Tomasz Figa

Where would you want to have those phy_address arrays stored? There are no board files when booting with DT. Not even saying that you don't need to use any hacky schemes like this when you have DT that nicely specifies relations between devices.

Quoted 7 lines
Quoted 2 lines

If everybody agrees DT has a nice scheme for specifying relations between devices, why not use that same scheme in the PHY core?

It is already used, for cases when consumer device has a DT node attached. In non-DT case this kind lookup translates loosely to something that is being done in regulator framework - you can't bind devices by pointers, because you don't have those pointers, so you need to use device names.

Sorry for jumping in to the middle of the discussion, but why does a *new* framework even bother defining an interface for board files?

Quoted 7 lines
Quoted 4 lines

Can't we just drop any interfaces for platform data passing in the phy framework and put the burden of adding those to anyone who actually needs them? All the platforms we are concerned with here (exynos and omap, plus new platforms) can be booted using DT anyway.

What about non-DT architectures such as MIPS (still widely used in consumer networking equipments from what I've heard) ?

Is there any specific MIPS platform you are thinking about which could benefit from this generic PHY framework? MIPS is also trying to make DT the standard for passing such information now.

Signature · 1 line
Florian
#60 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

In reply to Laurent Pinchart
Quoted 20 lines · Laurent Pinchart
Quoted 19 lines · On Wednesday 24 July 2013 20:32:03 Arnd Bergmann wrote:
Quoted 7 lines · Tomasz Figa
Quoted 6 lines · On Tuesday 23 of July 2013 17:14:20 Alan Stern wrote:
Quoted 4 lines · Tomasz Figa

Where would you want to have those phy_address arrays stored? There are no board files when booting with DT. Not even saying that you don't need to use any hacky schemes like this when you have DT that nicely specifies relations between devices.

Quoted 7 lines
Quoted 2 lines

If everybody agrees DT has a nice scheme for specifying relations between devices, why not use that same scheme in the PHY core?

It is already used, for cases when consumer device has a DT node attached. In non-DT case this kind lookup translates loosely to something that is being done in regulator framework - you can't bind devices by pointers, because you don't have those pointers, so you need to use device names.

Sorry for jumping in to the middle of the discussion, but why does a new framework even bother defining an interface for board files?

Quoted 7 lines
Quoted 4 lines

Can't we just drop any interfaces for platform data passing in the phy framework and put the burden of adding those to anyone who actually needs them? All the platforms we are concerned with here (exynos and omap, plus new platforms) can be booted using DT anyway.

What about non-DT architectures such as MIPS (still widely used in consumer networking equipments from what I've heard) ?

* Vendors of such equipment have started moving on to ARM (e.g. Broadcom bcm47xx)
* Some of the modern MIPS platforms are now using DT
* Legacy platforms probably won't migrate to either DT or the generic PHY framework

I'm not saying that we can't support legacy board files with the common PHY framework, but I'd expect things to be much easier if we focus on those platforms that are actively being worked on for now, to bring an end to the pointless API discussion.

Arnd

#61 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi Arnd,

Quoted 36 lines · On Thursday 25 July 2013 13:00:49 Arnd Bergmann wrote:
Quoted 21 lines · Laurent Pinchart
Quoted 20 lines · On Wednesday 24 July 2013 20:32:03 Arnd Bergmann wrote:
Quoted 7 lines · Tomasz Figa
Quoted 6 lines · On Tuesday 23 of July 2013 17:14:20 Alan Stern wrote:
Quoted 4 lines · Tomasz Figa

Where would you want to have those phy_address arrays stored? There are no board files when booting with DT. Not even saying that you don't need to use any hacky schemes like this when you have DT that nicely specifies relations between devices.

Quoted 8 lines
Quoted 2 lines

If everybody agrees DT has a nice scheme for specifying relations between devices, why not use that same scheme in the PHY core?

It is already used, for cases when consumer device has a DT node attached. In non-DT case this kind lookup translates loosely to something that is being done in regulator framework - you can't bind devices by pointers, because you don't have those pointers, so you need to use device names.

Sorry for jumping in to the middle of the discussion, but why does a new framework even bother defining an interface for board files?

Quoted 7 lines
Quoted 4 lines

Can't we just drop any interfaces for platform data passing in the phy framework and put the burden of adding those to anyone who actually needs them? All the platforms we are concerned with here (exynos and omap, plus new platforms) can be booted using DT anyway.

What about non-DT architectures such as MIPS (still widely used in consumer networking equipments from what I've heard) ?

* Vendors of such equipment have started moving on to ARM (e.g. Broadcom bcm47xx)
* Some of the modern MIPS platforms are now using DT
* Legacy platforms probably won't migrate to either DT or the generic PHY framework

Quoted 4 lines

I'm not saying that we can't support legacy board files with the common PHY framework, but I'd expect things to be much easier if we focus on those platforms that are actively being worked on for now, to bring an end to the pointless API discussion.

Fair enough :-)

Signature · 3 lines
Regards,

Laurent Pinchart
#62 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

In reply to Arnd Bergmann
Quoted 4 lines · Arnd Bergmann

I'm not saying that we can't support legacy board files with the common PHY framework, but I'd expect things to be much easier if we focus on those platforms that are actively being worked on for now, to bring an end to the pointless API discussion.

Well, it seemed like Greg's concerns had already been addressed anyway.
-------------- 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/20130725/d6b5153b/attachment-0001.sig>

#63 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

In reply to Alan Stern
Quoted 10 lines · Alan Stern
Quoted 3 lines · Tomasz Figa
Quoted 3 lines
Quoted 1 line

Okay. Are PHYs _always_ platform devices?

They can be i2c, spi or any other device types as well.

In those other cases, presumably there is no platform data associated with the PHY since it isn't a platform device. Then how does the kernel know which controller is attached to the PHY? Is this spelled out in platform data associated with the PHY's i2c/spi/whatever parent?

Platform data is nothing to do with the platform bus - it's board
specific data (ie, data for the platform) and can be done with any
device.
-------------- 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/20130723/9aafc3b9/attachment-0001.sig>

maintainer
#64 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

In reply to Kishon Vijay Abraham I
Quoted 10 lines · Kishon Vijay Abraham I
Quoted 9 lines

The issue (or one of the issues) in this discussion is that Greg does not like the idea of using names or IDs to associate PHYs with controllers, because they are too prone to duplications or other errors. Pointers are more reliable.

But pointers to what? Since the only data known to be available to both the PHY driver and controller driver is the platform data, the obvious answer is a pointer to platform data (either for the PHY or for the controller, or maybe both).

Quoted 6 lines

hmm.. it's not going to be simple though as the platform device for the PHY and controller can be created in entirely different places. e.g., in some cases the PHY device is a child of some mfd core device (the device will be created in drivers/mfd) and the controller driver (usually) is created in board file. I guess then we have to come up with something to share a pointer in two different files.

What's wrong with using the platform_data structure that is unique to all boards (see include/platform_data/ for examples)? Isn't that what this structure is there for?

greg k-h

#65 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi,

Quoted 18 lines · Greg KH
Quoted 10 lines · Kishon Vijay Abraham I
Quoted 9 lines

The issue (or one of the issues) in this discussion is that Greg does not like the idea of using names or IDs to associate PHYs with controllers, because they are too prone to duplications or other errors. Pointers are more reliable.

But pointers to what? Since the only data known to be available to both the PHY driver and controller driver is the platform data, the obvious answer is a pointer to platform data (either for the PHY or for the controller, or maybe both).

Quoted 6 lines

hmm.. it's not going to be simple though as the platform device for the PHY and controller can be created in entirely different places. e.g., in some cases the PHY device is a child of some mfd core device (the device will be created in drivers/mfd) and the controller driver (usually) is created in board file. I guess then we have to come up with something to share a pointer in two different files.

Quoted 3 lines

What's wrong with using the platform_data structure that is unique to all boards (see include/platform_data/ for examples)? Isn't that what this structure is there for?

Alright. I got some ideas from Alan Stern. I'll use it with platform_data and repost the series.

Thanks
Kishon

#66 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

In reply to Greg KH

Hi,

Quoted 36 lines · On Saturday 20 of July 2013 19:59:10 Greg KH wrote:
Quoted 28 lines · Alan Stern
Quoted 15 lines · Greg KH
Quoted 10 lines
Quoted 6 lines
Quoted 1 line

That should be passed using platform data.

Ick, don't pass strings around, pass pointers. If you have platform
data you can get to, then put the pointer there, don't use a "name".

I don't think I understood you here :-s We wont have phy pointer when we create the device for the controller no?(it'll be done in board file). Probably I'm missing something.

Why will you not have that pointer? You can't rely on the "name" as the device id will not match up, so you should be able to rely on the pointer being in the structure that the board sets up, right?

Quoted 5 lines

Don't use names, especially as ids can, and will, change, that is going
to cause big problems. Use pointers, this is C, we are supposed to be
doing that :)

Kishon, I think what Greg means is this: The name you are using must be stored somewhere in a data structure constructed by the board file, right? Or at least, associated with some data structure somehow. Otherwise the platform code wouldn't know which PHY hardware corresponded to a particular name.

Quoted 6 lines

Greg's suggestion is that you store the address of that data structure in the platform data instead of storing the name string. Have the consumer pass the data structure's address when it calls phy_create, instead of passing the name. Then you don't have to worry about two PHYs accidentally ending up with the same name or any other similar problems.

Quoted 4 lines

Close, but the issue is that whatever returns from phy_create() should then be used, no need to call any "find" functions, as you can just use the pointer that phy_create() returns. Much like all other class api functions in the kernel work.

I think there is a confusion here about who registers the PHYs.

All platform code does is registering a platform/i2c/whatever device, which causes a driver (located in drivers/phy/) to be instantiated. Such drivers call phy_create(), usually in their probe() callbacks, so platform_code has no way (and should have no way, for the sake of layering) to get what phy_create() returns.

IMHO we need a lookup method for PHYs, just like for clocks, regulators, PWMs or even i2c busses because there are complex cases when passing just a name using platform data will not work. I would second what Stephen said
[1] and define a structure doing things in a DT-like way.

Example;

[platform code]

static const struct phy_lookup my_phy_lookup[] = {
	PHY_LOOKUP("s3c-hsotg.0", "otg", "samsung-usbphy.1", "phy.2"),
	/* etc... */
};

static void my_machine_init(void)

{
	/* ... */
	phy_register_lookup(my_phy_lookup, ARRAY_SIZE(my_phy_lookup));
	/* ... */
}

/* Notice nothing stuffed in platform data. */

[provider code - samsung-usbphy driver]

static int samsung_usbphy_probe(...)

{
	/* ... */
		for (i = 0; i < PHY_COUNT; ++i) {
			usbphy->phy[i].name = "phy";
			usbphy->phy[i].id = i;
			/* ... */
			ret = phy_create(&usbphy->phy);
			/* err handling */
		}
	/* ... */
}

[consumer code - s3c-hsotg driver]

static int s3c_hsotg_probe(...)

{
	/* ... */
	phy = phy_get(&pdev->dev, "otg");
	/* ... */
}

[1] http://thread.gmane.org/gmane.linux.ports.arm.kernel/252813

Best regards,
Tomasz

#67 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi,

Quoted 44 lines · Tomasz Figa

Hi,

Quoted 36 lines · On Saturday 20 of July 2013 19:59:10 Greg KH wrote:
Quoted 28 lines · Alan Stern
Quoted 15 lines · Greg KH
Quoted 10 lines
Quoted 6 lines
Quoted 1 line

That should be passed using platform data.

Ick, don't pass strings around, pass pointers. If you have platform
data you can get to, then put the pointer there, don't use a "name".

I don't think I understood you here :-s We wont have phy pointer when we create the device for the controller no?(it'll be done in board file). Probably I'm missing something.

Why will you not have that pointer? You can't rely on the "name" as the device id will not match up, so you should be able to rely on the pointer being in the structure that the board sets up, right?

Quoted 5 lines

Don't use names, especially as ids can, and will, change, that is going
to cause big problems. Use pointers, this is C, we are supposed to be
doing that :)

Kishon, I think what Greg means is this: The name you are using must be stored somewhere in a data structure constructed by the board file, right? Or at least, associated with some data structure somehow. Otherwise the platform code wouldn't know which PHY hardware corresponded to a particular name.

Quoted 6 lines

Greg's suggestion is that you store the address of that data structure in the platform data instead of storing the name string. Have the consumer pass the data structure's address when it calls phy_create, instead of passing the name. Then you don't have to worry about two PHYs accidentally ending up with the same name or any other similar problems.

Quoted 4 lines

Close, but the issue is that whatever returns from phy_create() should then be used, no need to call any "find" functions, as you can just use the pointer that phy_create() returns. Much like all other class api functions in the kernel work.

Quoted 7 lines

I think there is a confusion here about who registers the PHYs.

All platform code does is registering a platform/i2c/whatever device, which causes a driver (located in drivers/phy/) to be instantiated. Such drivers call phy_create(), usually in their probe() callbacks, so platform_code has no way (and should have no way, for the sake of layering) to get what phy_create() returns.

right.

Quoted 6 lines

IMHO we need a lookup method for PHYs, just like for clocks, regulators, PWMs or even i2c busses because there are complex cases when passing just a name using platform data will not work. I would second what Stephen said
[1] and define a structure doing things in a DT-like way.

Quoted 6 lines

Example;

[platform code]

static const struct phy_lookup my_phy_lookup[] = {
	PHY_LOOKUP("s3c-hsotg.0", "otg", "samsung-usbphy.1", "phy.2"),

The only problem here is that if *PLATFORM_DEVID_AUTO* is used while creating the device, the ids in the device name would change and PHY_LOOKUP wont be useful.

Thanks
Kishon

#68 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 73 lines · On Sunday 21 of July 2013 16:37:33 Kishon Vijay Abraham I wrote:

Hi,

Quoted 50 lines · Tomasz Figa

Hi,

Quoted 40 lines · On Saturday 20 of July 2013 19:59:10 Greg KH wrote:
Quoted 31 lines · Alan Stern
Quoted 16 lines · Greg KH
Quoted 10 lines
Quoted 6 lines
Quoted 1 line

That should be passed using platform data.

Ick, don't pass strings around, pass pointers. If you have platform
data you can get to, then put the pointer there, don't use a "name".

I don't think I understood you here :-s We wont have phy pointer when we create the device for the controller no?(it'll be done in board file). Probably I'm missing something.

Why will you not have that pointer? You can't rely on the "name" as
the device id will not match up, so you should be able to rely on the pointer being in the structure that the board sets up, right?

Quoted 5 lines

Don't use names, especially as ids can, and will, change, that is going
to cause big problems. Use pointers, this is C, we are supposed to be
doing that :)

Kishon, I think what Greg means is this: The name you are using must
be stored somewhere in a data structure constructed by the board file,
right? Or at least, associated with some data structure somehow. Otherwise the platform code wouldn't know which PHY hardware corresponded to a particular name.

Quoted 7 lines

Greg's suggestion is that you store the address of that data structure
in the platform data instead of storing the name string. Have the consumer pass the data structure's address when it calls phy_create, instead of passing the name. Then you don't have to worry about two PHYs accidentally ending up with the same name or any other similar problems.

Quoted 6 lines

Close, but the issue is that whatever returns from phy_create() should
then be used, no need to call any "find" functions, as you can just use
the pointer that phy_create() returns. Much like all other class api functions in the kernel work.

Quoted 7 lines

I think there is a confusion here about who registers the PHYs.

All platform code does is registering a platform/i2c/whatever device, which causes a driver (located in drivers/phy/) to be instantiated. Such drivers call phy_create(), usually in their probe() callbacks, so platform_code has no way (and should have no way, for the sake of layering) to get what phy_create() returns.

right.

Quoted 10 lines

IMHO we need a lookup method for PHYs, just like for clocks, regulators, PWMs or even i2c busses because there are complex cases when passing just a name using platform data will not work. I would second what Stephen said [1] and define a structure doing things in a DT-like way.

Example;

[platform code]

Quoted 7 lines
Quoted 3 lines

static const struct phy_lookup my_phy_lookup[] = {

	PHY_LOOKUP("s3c-hsotg.0", "otg", "samsung-usbphy.1", "phy.2"),

The only problem here is that if *PLATFORM_DEVID_AUTO* is used while creating the device, the ids in the device name would change and PHY_LOOKUP wont be useful.

I don't think this is a problem. All the existing lookup methods already use ID to identify devices (see regulators, clkdev, PWMs, i2c, ...). You can simply add a requirement that the ID must be assigned manually, without using PLATFORM_DEVID_AUTO to use PHY lookup.

Best regards,
Tomasz

maintainer
#69 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 54 lines · Tomasz Figa
Quoted 53 lines · On Sunday 21 of July 2013 16:37:33 Kishon Vijay Abraham I wrote:

Hi,

Quoted 50 lines · Tomasz Figa

Hi,

Quoted 46 lines · On Saturday 20 of July 2013 19:59:10 Greg KH wrote:
Quoted 31 lines · Alan Stern
Quoted 16 lines · Greg KH
Quoted 10 lines
Quoted 6 lines
Quoted 1 line

That should be passed using platform data.

Ick, don't pass strings around, pass pointers. If you have platform
data you can get to, then put the pointer there, don't use a "name".

I don't think I understood you here :-s We wont have phy pointer when we create the device for the controller no?(it'll be done in board file). Probably I'm missing something.

Why will you not have that pointer? You can't rely on the "name" as
the device id will not match up, so you should be able to rely on the pointer being in the structure that the board sets up, right?

Quoted 5 lines

Don't use names, especially as ids can, and will, change, that is going
to cause big problems. Use pointers, this is C, we are supposed to be
doing that :)

Kishon, I think what Greg means is this: The name you are using must
be stored somewhere in a data structure constructed by the board file,
right? Or at least, associated with some data structure somehow. Otherwise the platform code wouldn't know which PHY hardware corresponded to a particular name.

Quoted 7 lines

Greg's suggestion is that you store the address of that data structure
in the platform data instead of storing the name string. Have the consumer pass the data structure's address when it calls phy_create, instead of passing the name. Then you don't have to worry about two PHYs accidentally ending up with the same name or any other similar problems.

Close, but the issue is that whatever returns from phy_create() should
then be used, no need to call any "find" functions, as you can just use
the pointer that phy_create() returns. Much like all other class api functions in the kernel work.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

I think there is a confusion here about who registers the PHYs.

All platform code does is registering a platform/i2c/whatever device, which causes a driver (located in drivers/phy/) to be instantiated. Such drivers call phy_create(), usually in their probe() callbacks, so platform_code has no way (and should have no way, for the sake of layering) to get what phy_create() returns.

Why not put pointers in the platform data structure that can hold these pointers? I thought that is why we created those structures in the first place. If not, what are they there for?

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

IMHO we need a lookup method for PHYs, just like for clocks, regulators, PWMs or even i2c busses because there are complex cases when passing just a name using platform data will not work. I would second what Stephen said [1] and define a structure doing things in a DT-like way.

Example;

[platform code]

static const struct phy_lookup my_phy_lookup[] = {

	PHY_LOOKUP("s3c-hsotg.0", "otg", "samsung-usbphy.1", "phy.2"),
Quoted 8 lines
Quoted 3 lines

The only problem here is that if *PLATFORM_DEVID_AUTO* is used while creating the device, the ids in the device name would change and PHY_LOOKUP wont be useful.

I don't think this is a problem. All the existing lookup methods already use ID to identify devices (see regulators, clkdev, PWMs, i2c, ...). You can simply add a requirement that the ID must be assigned manually, without using PLATFORM_DEVID_AUTO to use PHY lookup.

And I'm saying that this idea, of using a specific name and id, is frought with fragility and will break in the future in various ways when devices get added to systems, making these strings constantly have to be kept up to date with different board configurations.

People, NEVER, hardcode something like an id. The fact that this happens today with the clock code, doesn't make it right, it makes the clock code wrong. Others have already said that this is wrong there as well, as systems change and dynamic ids get used more and more.

Let's not repeat the same mistakes of the past just because we refuse to learn from them...

So again, the "find a phy by a string" functions should be removed, the device id should be automatically created by the phy core just to make things unique in sysfs, and no driver code should _ever_ be reliant on the number that is being created, and the pointer to the phy structure should be used everywhere instead.

With those types of changes, I will consider merging this subsystem, but without them, sorry, I will not.

thanks,

greg k-h

#70 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 63 lines · Greg KH
Quoted 54 lines · Tomasz Figa
Quoted 53 lines · On Sunday 21 of July 2013 16:37:33 Kishon Vijay Abraham I wrote:

Hi,

Quoted 50 lines · Tomasz Figa

Hi,

Quoted 46 lines · On Saturday 20 of July 2013 19:59:10 Greg KH wrote:
Quoted 31 lines · Alan Stern
Quoted 16 lines · Greg KH
Quoted 10 lines
Quoted 6 lines
Quoted 1 line

That should be passed using platform data.

Ick, don't pass strings around, pass pointers. If you have platform
data you can get to, then put the pointer there, don't use a "name".

I don't think I understood you here :-s We wont have phy pointer when we create the device for the controller no?(it'll be done in board file). Probably I'm missing something.

Why will you not have that pointer? You can't rely on the "name" as
the device id will not match up, so you should be able to rely on the pointer being in the structure that the board sets up, right?

Quoted 5 lines

Don't use names, especially as ids can, and will, change, that is going
to cause big problems. Use pointers, this is C, we are supposed to be
doing that :)

Kishon, I think what Greg means is this: The name you are using must
be stored somewhere in a data structure constructed by the board file,
right? Or at least, associated with some data structure somehow. Otherwise the platform code wouldn't know which PHY hardware corresponded to a particular name.

Quoted 7 lines

Greg's suggestion is that you store the address of that data structure
in the platform data instead of storing the name string. Have the consumer pass the data structure's address when it calls phy_create, instead of passing the name. Then you don't have to worry about two PHYs accidentally ending up with the same name or any other similar problems.

Close, but the issue is that whatever returns from phy_create() should
then be used, no need to call any "find" functions, as you can just use
the pointer that phy_create() returns. Much like all other class api functions in the kernel work.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

I think there is a confusion here about who registers the PHYs.

All platform code does is registering a platform/i2c/whatever device, which causes a driver (located in drivers/phy/) to be instantiated. Such drivers call phy_create(), usually in their probe() callbacks, so platform_code has no way (and should have no way, for the sake of layering) to get what phy_create() returns.

Quoted 3 lines

Why not put pointers in the platform data structure that can hold these pointers? I thought that is why we created those structures in the first place. If not, what are they there for?

heh, IMO we shouldn't pass pointers of any kind through platform_data, we want to pass data :-)

Allowing to pass pointers through that, is one of the reasons which got us in such a big mess in ARM land, well it was much easier for a board-file/driver writer to pass a function pointer then to create a generic framework :-)

Quoted 36 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

IMHO we need a lookup method for PHYs, just like for clocks, regulators, PWMs or even i2c busses because there are complex cases when passing just a name using platform data will not work. I would second what Stephen said [1] and define a structure doing things in a DT-like way.

Example;

[platform code]

static const struct phy_lookup my_phy_lookup[] = {

	PHY_LOOKUP("s3c-hsotg.0", "otg", "samsung-usbphy.1", "phy.2"),
Quoted 8 lines
Quoted 3 lines

The only problem here is that if *PLATFORM_DEVID_AUTO* is used while creating the device, the ids in the device name would change and PHY_LOOKUP wont be useful.

I don't think this is a problem. All the existing lookup methods already use ID to identify devices (see regulators, clkdev, PWMs, i2c, ...). You can simply add a requirement that the ID must be assigned manually, without using PLATFORM_DEVID_AUTO to use PHY lookup.

And I'm saying that this idea, of using a specific name and id, is frought with fragility and will break in the future in various ways when devices get added to systems, making these strings constantly have to be kept up to date with different board configurations.

People, NEVER, hardcode something like an id. The fact that this happens today with the clock code, doesn't make it right, it makes the clock code wrong. Others have already said that this is wrong there as well, as systems change and dynamic ids get used more and more.

Let's not repeat the same mistakes of the past just because we refuse to learn from them...

Quoted 8 lines

So again, the "find a phy by a string" functions should be removed, the device id should be automatically created by the phy core just to make things unique in sysfs, and no driver code should _ever_ be reliant on the number that is being created, and the pointer to the phy structure should be used everywhere instead.

With those types of changes, I will consider merging this subsystem, but without them, sorry, I will not.

I'll agree with Greg here, the very fact that we see people trying to add a requirement of *NOT* using PLATFORM_DEVID_AUTO already points to a big problem in the framework.

The fact is that if we don't allow PLATFORM_DEVID_AUTO we will end up adding similar infrastructure to the driver themselves to make sure we don't end up with duplicate names in sysfs in case we have multiple instances of the same IP in the SoC (or several of the same PCIe card). I really don't want to go back to that.

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/20130730/625b34cb/attachment-0001.sig>
#71 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi,

Quoted 125 lines · Felipe Balbi
Quoted 63 lines · Greg KH
Quoted 54 lines · Tomasz Figa
Quoted 53 lines · On Sunday 21 of July 2013 16:37:33 Kishon Vijay Abraham I wrote:

Hi,

Quoted 50 lines · Tomasz Figa

Hi,

Quoted 46 lines · On Saturday 20 of July 2013 19:59:10 Greg KH wrote:
Quoted 31 lines · Alan Stern
Quoted 16 lines · Greg KH
Quoted 10 lines
Quoted 6 lines
Quoted 1 line

That should be passed using platform data.

Ick, don't pass strings around, pass pointers. If you have platform
data you can get to, then put the pointer there, don't use a "name".

I don't think I understood you here :-s We wont have phy pointer when we create the device for the controller no?(it'll be done in board file). Probably I'm missing something.

Why will you not have that pointer? You can't rely on the "name" as
the device id will not match up, so you should be able to rely on the pointer being in the structure that the board sets up, right?

Quoted 5 lines

Don't use names, especially as ids can, and will, change, that is going
to cause big problems. Use pointers, this is C, we are supposed to be
doing that :)

Kishon, I think what Greg means is this: The name you are using must
be stored somewhere in a data structure constructed by the board file,
right? Or at least, associated with some data structure somehow. Otherwise the platform code wouldn't know which PHY hardware corresponded to a particular name.

Quoted 7 lines

Greg's suggestion is that you store the address of that data structure
in the platform data instead of storing the name string. Have the consumer pass the data structure's address when it calls phy_create, instead of passing the name. Then you don't have to worry about two PHYs accidentally ending up with the same name or any other similar problems.

Close, but the issue is that whatever returns from phy_create() should
then be used, no need to call any "find" functions, as you can just use
the pointer that phy_create() returns. Much like all other class api functions in the kernel work.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

I think there is a confusion here about who registers the PHYs.

All platform code does is registering a platform/i2c/whatever device, which causes a driver (located in drivers/phy/) to be instantiated. Such drivers call phy_create(), usually in their probe() callbacks, so platform_code has no way (and should have no way, for the sake of layering) to get what phy_create() returns.

Quoted 3 lines

Why not put pointers in the platform data structure that can hold these pointers? I thought that is why we created those structures in the first place. If not, what are they there for?

heh, IMO we shouldn't pass pointers of any kind through platform_data, we want to pass data :-)

Allowing to pass pointers through that, is one of the reasons which got us in such a big mess in ARM land, well it was much easier for a board-file/driver writer to pass a function pointer then to create a generic framework :-)

Quoted 36 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

IMHO we need a lookup method for PHYs, just like for clocks, regulators, PWMs or even i2c busses because there are complex cases when passing just a name using platform data will not work. I would second what Stephen said [1] and define a structure doing things in a DT-like way.

Example;

[platform code]

static const struct phy_lookup my_phy_lookup[] = {

	PHY_LOOKUP("s3c-hsotg.0", "otg", "samsung-usbphy.1", "phy.2"),
Quoted 8 lines
Quoted 3 lines

The only problem here is that if *PLATFORM_DEVID_AUTO* is used while creating the device, the ids in the device name would change and PHY_LOOKUP wont be useful.

I don't think this is a problem. All the existing lookup methods already use ID to identify devices (see regulators, clkdev, PWMs, i2c, ...). You can simply add a requirement that the ID must be assigned manually, without using PLATFORM_DEVID_AUTO to use PHY lookup.

And I'm saying that this idea, of using a specific name and id, is frought with fragility and will break in the future in various ways when devices get added to systems, making these strings constantly have to be kept up to date with different board configurations.

People, NEVER, hardcode something like an id. The fact that this happens today with the clock code, doesn't make it right, it makes the clock code wrong. Others have already said that this is wrong there as well, as systems change and dynamic ids get used more and more.

Let's not repeat the same mistakes of the past just because we refuse to learn from them...

Quoted 8 lines

So again, the "find a phy by a string" functions should be removed, the device id should be automatically created by the phy core just to make things unique in sysfs, and no driver code should _ever_ be reliant on the number that is being created, and the pointer to the phy structure should be used everywhere instead.

With those types of changes, I will consider merging this subsystem, but without them, sorry, I will not.

I'll agree with Greg here, the very fact that we see people trying to add a requirement of *NOT* using PLATFORM_DEVID_AUTO already points to a big problem in the framework.

Quoted 5 lines

The fact is that if we don't allow PLATFORM_DEVID_AUTO we will end up adding similar infrastructure to the driver themselves to make sure we don't end up with duplicate names in sysfs in case we have multiple instances of the same IP in the SoC (or several of the same PCIe card). I really don't want to go back to that.

If we are using PLATFORM_DEVID_AUTO, then I dont see any way we can give the correct binding information to the PHY framework. I think we can drop having this non-dt support in PHY framework? I see only one platform (OMAP3) going to be needing this non-dt support and we can use the USB PHY library for it.

Thanks
Kishon

#72 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi,

Quoted 55 lines · Kishon Vijay Abraham I
Quoted 49 lines
Quoted 36 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

IMHO we need a lookup method for PHYs, just like for clocks, regulators, PWMs or even i2c busses because there are complex cases when passing just a name using platform data will not work. I would second what Stephen said [1] and define a structure doing things in a DT-like way.

Example;

[platform code]

static const struct phy_lookup my_phy_lookup[] = {

	PHY_LOOKUP("s3c-hsotg.0", "otg", "samsung-usbphy.1", "phy.2"),
Quoted 8 lines
Quoted 3 lines

The only problem here is that if *PLATFORM_DEVID_AUTO* is used while creating the device, the ids in the device name would change and PHY_LOOKUP wont be useful.

I don't think this is a problem. All the existing lookup methods already use ID to identify devices (see regulators, clkdev, PWMs, i2c, ...). You can simply add a requirement that the ID must be assigned manually, without using PLATFORM_DEVID_AUTO to use PHY lookup.

And I'm saying that this idea, of using a specific name and id, is frought with fragility and will break in the future in various ways when devices get added to systems, making these strings constantly have to be kept up to date with different board configurations.

People, NEVER, hardcode something like an id. The fact that this happens today with the clock code, doesn't make it right, it makes the clock code wrong. Others have already said that this is wrong there as well, as systems change and dynamic ids get used more and more.

Let's not repeat the same mistakes of the past just because we refuse to learn from them...

Quoted 8 lines

So again, the "find a phy by a string" functions should be removed, the device id should be automatically created by the phy core just to make things unique in sysfs, and no driver code should _ever_ be reliant on the number that is being created, and the pointer to the phy structure should be used everywhere instead.

With those types of changes, I will consider merging this subsystem, but without them, sorry, I will not.

I'll agree with Greg here, the very fact that we see people trying to add a requirement of *NOT* using PLATFORM_DEVID_AUTO already points to a big problem in the framework.

Quoted 5 lines

The fact is that if we don't allow PLATFORM_DEVID_AUTO we will end up adding similar infrastructure to the driver themselves to make sure we don't end up with duplicate names in sysfs in case we have multiple instances of the same IP in the SoC (or several of the same PCIe card). I really don't want to go back to that.

Quoted 4 lines

If we are using PLATFORM_DEVID_AUTO, then I dont see any way we can give the correct binding information to the PHY framework. I think we can drop having this non-dt support in PHY framework? I see only one platform (OMAP3) going to be needing this non-dt support and we can use the USB PHY library for it.

you shouldn't drop support for non-DT platform, in any case we lived without DT (and still do) for years. Gotta find a better way ;-)

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/20130731/1e807bf5/attachment-0001.sig>
#73 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi,

Quoted 58 lines · Felipe Balbi

Hi,

Quoted 55 lines · Kishon Vijay Abraham I
Quoted 54 lines
Quoted 36 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

IMHO we need a lookup method for PHYs, just like for clocks, regulators, PWMs or even i2c busses because there are complex cases when passing just a name using platform data will not work. I would second what Stephen said [1] and define a structure doing things in a DT-like way.

Example;

[platform code]

static const struct phy_lookup my_phy_lookup[] = {

	PHY_LOOKUP("s3c-hsotg.0", "otg", "samsung-usbphy.1", "phy.2"),
Quoted 8 lines
Quoted 3 lines

The only problem here is that if *PLATFORM_DEVID_AUTO* is used while creating the device, the ids in the device name would change and PHY_LOOKUP wont be useful.

I don't think this is a problem. All the existing lookup methods already use ID to identify devices (see regulators, clkdev, PWMs, i2c, ...). You can simply add a requirement that the ID must be assigned manually, without using PLATFORM_DEVID_AUTO to use PHY lookup.

And I'm saying that this idea, of using a specific name and id, is frought with fragility and will break in the future in various ways when devices get added to systems, making these strings constantly have to be kept up to date with different board configurations.

People, NEVER, hardcode something like an id. The fact that this happens today with the clock code, doesn't make it right, it makes the clock code wrong. Others have already said that this is wrong there as well, as systems change and dynamic ids get used more and more.

Let's not repeat the same mistakes of the past just because we refuse to learn from them...

Quoted 8 lines

So again, the "find a phy by a string" functions should be removed, the device id should be automatically created by the phy core just to make things unique in sysfs, and no driver code should _ever_ be reliant on the number that is being created, and the pointer to the phy structure should be used everywhere instead.

With those types of changes, I will consider merging this subsystem, but without them, sorry, I will not.

I'll agree with Greg here, the very fact that we see people trying to add a requirement of *NOT* using PLATFORM_DEVID_AUTO already points to a big problem in the framework.

The fact is that if we don't allow PLATFORM_DEVID_AUTO we will end up adding similar infrastructure to the driver themselves to make sure we don't end up with duplicate names in sysfs in case we have multiple instances of the same IP in the SoC (or several of the same PCIe card). I really don't want to go back to that.

Quoted 7 lines
Quoted 4 lines

If we are using PLATFORM_DEVID_AUTO, then I dont see any way we can give the correct binding information to the PHY framework. I think we can drop having this non-dt support in PHY framework? I see only one platform (OMAP3) going to be needing this non-dt support and we can use the USB PHY library for it.

you shouldn't drop support for non-DT platform, in any case we lived without DT (and still do) for years. Gotta find a better way ;-)

hmm..

how about passing the device names of PHY in platform data of the controller? It should be deterministic as the PHY framework assigns its own id and we *don't* want to add any requirement that the ID must be assigned manually without using PLATFORM_DEVID_AUTO. We can get rid of *phy_init_data* in the v10 patch series.

Thanks
Kishon

Quoted 1 line
#74 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 88 lines · On Tuesday 13 of August 2013 16:14:44 Kishon Vijay Abraham I wrote:

Hi,

Quoted 77 lines · Felipe Balbi

Hi,

Quoted 74 lines · Kishon Vijay Abraham I
Quoted 73 lines
Quoted 57 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines

IMHO we need a lookup method for PHYs, just like for clocks, regulators, PWMs or even i2c busses because there are complex cases
when passing just a name using platform data will not work. I would
second what Stephen said [1] and define a structure doing things in a
DT-like way.

Example;

[platform code]

Quoted 8 lines
Quoted 3 lines

static const struct phy_lookup my_phy_lookup[] = {

	PHY_LOOKUP("s3c-hsotg.0", "otg", "samsung-usbphy.1", "phy.2"),

The only problem here is that if *PLATFORM_DEVID_AUTO* is used while
creating the device, the ids in the device name would change and PHY_LOOKUP wont be useful.

Quoted 6 lines

I don't think this is a problem. All the existing lookup methods already
use ID to identify devices (see regulators, clkdev, PWMs, i2c, ...). You
can simply add a requirement that the ID must be assigned manually, without using PLATFORM_DEVID_AUTO to use PHY lookup.

And I'm saying that this idea, of using a specific name and id, is frought with fragility and will break in the future in various ways when
devices get added to systems, making these strings constantly have to be
kept up to date with different board configurations.

People, NEVER, hardcode something like an id. The fact that this happens today with the clock code, doesn't make it right, it makes the
clock code wrong. Others have already said that this is wrong there as
well, as systems change and dynamic ids get used more and more.

Let's not repeat the same mistakes of the past just because we refuse to
learn from them...

So again, the "find a phy by a string" functions should be removed, the
device id should be automatically created by the phy core just to make
things unique in sysfs, and no driver code should _ever_ be reliant on
the number that is being created, and the pointer to the phy structure
should be used everywhere instead.

Quoted 3 lines

With those types of changes, I will consider merging this subsystem, but
without them, sorry, I will not.

I'll agree with Greg here, the very fact that we see people trying to add a requirement of *NOT* using PLATFORM_DEVID_AUTO already points to a
big problem in the framework.

The fact is that if we don't allow PLATFORM_DEVID_AUTO we will end up adding similar infrastructure to the driver themselves to make sure we
don't end up with duplicate names in sysfs in case we have multiple instances of the same IP in the SoC (or several of the same PCIe card).
I really don't want to go back to that.

Quoted 7 lines
Quoted 5 lines

If we are using PLATFORM_DEVID_AUTO, then I dont see any way we can give the correct binding information to the PHY framework. I think we can drop having this non-dt support in PHY framework? I see only one platform (OMAP3) going to be needing this non-dt support and we can use the USB PHY library for it.>

you shouldn't drop support for non-DT platform, in any case we lived without DT (and still do) for years. Gotta find a better way ;-)

Quoted 7 lines

hmm..

how about passing the device names of PHY in platform data of the controller? It should be deterministic as the PHY framework assigns its own id and we *don't* want to add any requirement that the ID must be assigned manually without using PLATFORM_DEVID_AUTO. We can get rid of *phy_init_data* in the v10 patch series.

What about slightly altering the concept of v9 to pass a pointer to struct device instead of device name inside phy_init_data?

Best regards,
Tomasz

#75 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 91 lines · Tomasz Figa
Quoted 90 lines · On Tuesday 13 of August 2013 16:14:44 Kishon Vijay Abraham I wrote:

Hi,

Quoted 77 lines · Felipe Balbi

Hi,

Quoted 74 lines · Kishon Vijay Abraham I
Quoted 73 lines
Quoted 57 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines

IMHO we need a lookup method for PHYs, just like for clocks, regulators, PWMs or even i2c busses because there are complex cases
when passing just a name using platform data will not work. I would
second what Stephen said [1] and define a structure doing things in a
DT-like way.

Example;

[platform code]

Quoted 8 lines
Quoted 3 lines

static const struct phy_lookup my_phy_lookup[] = {

	PHY_LOOKUP("s3c-hsotg.0", "otg", "samsung-usbphy.1", "phy.2"),

The only problem here is that if *PLATFORM_DEVID_AUTO* is used while
creating the device, the ids in the device name would change and PHY_LOOKUP wont be useful.

Quoted 6 lines

I don't think this is a problem. All the existing lookup methods already
use ID to identify devices (see regulators, clkdev, PWMs, i2c, ...). You
can simply add a requirement that the ID must be assigned manually, without using PLATFORM_DEVID_AUTO to use PHY lookup.

And I'm saying that this idea, of using a specific name and id, is frought with fragility and will break in the future in various ways when
devices get added to systems, making these strings constantly have to be
kept up to date with different board configurations.

People, NEVER, hardcode something like an id. The fact that this happens today with the clock code, doesn't make it right, it makes the
clock code wrong. Others have already said that this is wrong there as
well, as systems change and dynamic ids get used more and more.

Let's not repeat the same mistakes of the past just because we refuse to
learn from them...

So again, the "find a phy by a string" functions should be removed, the
device id should be automatically created by the phy core just to make
things unique in sysfs, and no driver code should _ever_ be reliant on
the number that is being created, and the pointer to the phy structure
should be used everywhere instead.

Quoted 3 lines

With those types of changes, I will consider merging this subsystem, but
without them, sorry, I will not.

I'll agree with Greg here, the very fact that we see people trying to add a requirement of *NOT* using PLATFORM_DEVID_AUTO already points to a
big problem in the framework.

The fact is that if we don't allow PLATFORM_DEVID_AUTO we will end up adding similar infrastructure to the driver themselves to make sure we
don't end up with duplicate names in sysfs in case we have multiple instances of the same IP in the SoC (or several of the same PCIe card).
I really don't want to go back to that.

Quoted 7 lines
Quoted 5 lines

If we are using PLATFORM_DEVID_AUTO, then I dont see any way we can give the correct binding information to the PHY framework. I think we can drop having this non-dt support in PHY framework? I see only one platform (OMAP3) going to be needing this non-dt support and we can use the USB PHY library for it.>

you shouldn't drop support for non-DT platform, in any case we lived without DT (and still do) for years. Gotta find a better way ;-)

hmm..

Quoted 8 lines
Quoted 5 lines

how about passing the device names of PHY in platform data of the controller? It should be deterministic as the PHY framework assigns its own id and we *don't* want to add any requirement that the ID must be assigned manually without using PLATFORM_DEVID_AUTO. We can get rid of *phy_init_data* in the v10 patch series.

What about slightly altering the concept of v9 to pass a pointer to struct device instead of device name inside phy_init_data?

The problem is device might be created very late. (For example in omap4, usb2 phy device gets created when ocp2scp bus is probed). And we have to pass the init data in board file.

Thanks
Kishon

#76 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

W dniu 2013-08-13 14:05, Kishon Vijay Abraham I pisze:

Quoted 85 lines · Tomasz Figa
Quoted 84 lines · On Tuesday 13 of August 2013 16:14:44 Kishon Vijay Abraham I wrote:
Quoted 83 lines · Felipe Balbi
Quoted 81 lines · Kishon Vijay Abraham I
Quoted 73 lines
Quoted 65 lines
Quoted 57 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines

IMHO we need a lookup method for PHYs, just like for clocks, regulators, PWMs or even i2c busses because there are complex cases
when passing just a name using platform data will not work. I would
second what Stephen said [1] and define a structure doing things in a
DT-like way.

Example;

[platform code]

Quoted 8 lines
Quoted 3 lines

static const struct phy_lookup my_phy_lookup[] = {

	PHY_LOOKUP("s3c-hsotg.0", "otg", "samsung-usbphy.1", "phy.2"),

The only problem here is that if *PLATFORM_DEVID_AUTO* is used while
creating the device, the ids in the device name would change and PHY_LOOKUP wont be useful.

Quoted 6 lines

I don't think this is a problem. All the existing lookup methods already
use ID to identify devices (see regulators, clkdev, PWMs, i2c, ...). You
can simply add a requirement that the ID must be assigned manually, without using PLATFORM_DEVID_AUTO to use PHY lookup.

And I'm saying that this idea, of using a specific name and id, is frought with fragility and will break in the future in various ways when
devices get added to systems, making these strings constantly have to be
kept up to date with different board configurations.

People, NEVER, hardcode something like an id. The fact that this happens today with the clock code, doesn't make it right, it makes the
clock code wrong. Others have already said that this is wrong there as
well, as systems change and dynamic ids get used more and more.

Let's not repeat the same mistakes of the past just because we refuse to
learn from them...

So again, the "find a phy by a string" functions should be removed, the
device id should be automatically created by the phy core just to make
things unique in sysfs, and no driver code should _ever_ be reliant on
the number that is being created, and the pointer to the phy structure
should be used everywhere instead.

Quoted 3 lines

With those types of changes, I will consider merging this subsystem, but
without them, sorry, I will not.

I'll agree with Greg here, the very fact that we see people trying to add a requirement of *NOT* using PLATFORM_DEVID_AUTO already points to a big problem in the framework.

Quoted 7 lines

The fact is that if we don't allow PLATFORM_DEVID_AUTO we will end up adding similar infrastructure to the driver themselves to make sure we
don't end up with duplicate names in sysfs in case we have multiple instances of the same IP in the SoC (or several of the same PCIe card).
I really don't want to go back to that.

Quoted 5 lines

If we are using PLATFORM_DEVID_AUTO, then I dont see any way we can give the correct binding information to the PHY framework. I think we can drop having this non-dt support in PHY framework? I see only one platform (OMAP3) going to be needing this non-dt support and we can use the USB PHY library for it.>

you shouldn't drop support for non-DT platform, in any case we lived without DT (and still do) for years. Gotta find a better way ;-)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

hmm..

how about passing the device names of PHY in platform data of the controller? It should be deterministic as the PHY framework assigns its own id and we *don't* want to add any requirement that the ID must be assigned manually without using PLATFORM_DEVID_AUTO. We can get rid of *phy_init_data* in the v10 patch series.

OK, so the PHY device name would have a fixed part, passed as platform data of the controller and a variable part appended by the PHY core, depending on the number of registered PHYs ?

Then same PHY names would be passed as the PHY provider driver's platform data ?

Then if there are 2 instances of the above (same names in platform data) how would be determined which PHY controller is linked to which PHY supplier ?

I guess you want each device instance to have different PHY device names already in platform data ? That might work. We probably will be focused mostly on DT anyway. It seem without DT we are trying to find some layer that would allow us to couple relevant devices and overcome driver core inconvenience that it provides to means to identify specific devices in advance. :) Your proposal sounds reasonable, however I might be missing some details or corner cases.

Quoted 2 lines
Quoted 2 lines

What about slightly altering the concept of v9 to pass a pointer to struct device instead of device name inside phy_init_data?

As Felipe said, we don't want to pass pointers in platform_data to/from random subsystems. We pass data, passing pointers would be a total mess IMHO.

Quoted 3 lines

The problem is device might be created very late. (For example in omap4, usb2 phy device gets created when ocp2scp bus is probed). And we have to pass the init data in board file.

Regards,
Sylwester

#77 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Quoted 5 lines · On Wednesday 14 of August 2013 00:19:28 Sylwester Nawrocki wrote:

W dniu 2013-08-13 14:05, Kishon Vijay Abraham I pisze:

Quoted 4 lines · Tomasz Figa
Quoted 3 lines · On Tuesday 13 of August 2013 16:14:44 Kishon Vijay Abraham I wrote:
Quoted 2 lines · Felipe Balbi
Quoted 1 line

On Wed, Jul 31, 2013 at 11:14:32AM +0530, Kishon Vijay Abraham I

Quoted 137 lines · wrote:
Quoted 109 lines
Quoted 109 lines
Quoted 109 lines
Quoted 103 lines
Quoted 93 lines
Quoted 82 lines
Quoted 71 lines
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines

IMHO we need a lookup method for PHYs, just like for clocks, regulators, PWMs or even i2c busses because there are complex cases
when passing just a name using platform data will not work. I would
second what Stephen said [1] and define a structure doing things
in a
DT-like way.

Example;

[platform code]

static const struct phy_lookup my_phy_lookup[] = {

Quoted 8 lines
Quoted 2 lines
	PHY_LOOKUP("s3c-hsotg.0", "otg", "samsung-usbphy.1",
	"phy.2"),

The only problem here is that if *PLATFORM_DEVID_AUTO* is used while
creating the device, the ids in the device name would change and
PHY_LOOKUP wont be useful.

Quoted 8 lines

I don't think this is a problem. All the existing lookup methods
already
use ID to identify devices (see regulators, clkdev, PWMs, i2c, ...). You
can simply add a requirement that the ID must be assigned manually,
without using PLATFORM_DEVID_AUTO to use PHY lookup.

And I'm saying that this idea, of using a specific name and id, is
frought with fragility and will break in the future in various ways
when
devices get added to systems, making these strings constantly have
to be
kept up to date with different board configurations.

People, NEVER, hardcode something like an id. The fact that this
happens today with the clock code, doesn't make it right, it makes
the
clock code wrong. Others have already said that this is wrong there
as
well, as systems change and dynamic ids get used more and more.

Let's not repeat the same mistakes of the past just because we refuse to
learn from them...

So again, the "find a phy by a string" functions should be removed,
the
device id should be automatically created by the phy core just to
make
things unique in sysfs, and no driver code should _ever_ be reliant
on
the number that is being created, and the pointer to the phy structure
should be used everywhere instead.

Quoted 4 lines

With those types of changes, I will consider merging this subsystem,
but
without them, sorry, I will not.

I'll agree with Greg here, the very fact that we see people trying to
add a requirement of *NOT* using PLATFORM_DEVID_AUTO already points
to a big problem in the framework.

Quoted 10 lines

The fact is that if we don't allow PLATFORM_DEVID_AUTO we will end up
adding similar infrastructure to the driver themselves to make sure
we
don't end up with duplicate names in sysfs in case we have multiple
instances of the same IP in the SoC (or several of the same PCIe card).
I really don't want to go back to that.

Quoted 9 lines

If we are using PLATFORM_DEVID_AUTO, then I dont see any way we can
give the correct binding information to the PHY framework. I think we
can drop having this non-dt support in PHY framework? I see only one
platform (OMAP3) going to be needing this non-dt support and we can
use the USB PHY library for it.>

Quoted 3 lines

you shouldn't drop support for non-DT platform, in any case we lived
without DT (and still do) for years. Gotta find a better way ;-)

hmm..

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

how about passing the device names of PHY in platform data of the controller? It should be deterministic as the PHY framework assigns its
own id and we *don't* want to add any requirement that the ID must be
assigned manually without using PLATFORM_DEVID_AUTO. We can get rid of
*phy_init_data* in the v10 patch series.

OK, so the PHY device name would have a fixed part, passed as platform data of the controller and a variable part appended by the PHY core, depending on the number of registered PHYs ?

Then same PHY names would be passed as the PHY provider driver's platform data ?

Then if there are 2 instances of the above (same names in platform data) how would be determined which PHY controller is linked to which PHY supplier ?

I guess you want each device instance to have different PHY device names already in platform data ? That might work. We probably will be focused mostly on DT anyway. It seem without DT we are trying to find some layer that would allow us to couple relevant devices and overcome driver core inconvenience that it provides to means to identify specific devices in advance. :) Your proposal sounds reasonable, however I might be missing some details or corner cases.

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

What about slightly altering the concept of v9 to pass a pointer to struct device instead of device name inside phy_init_data?

As Felipe said, we don't want to pass pointers in platform_data to/from random subsystems. We pass data, passing pointers would be a total mess IMHO.

Well, this is a total mess anyway... I don't really get the point of using PLATFORM_DEVID_AUTO. The only thing that comes to my mind is that you can use it if you don't care about the ID and so it can be assigned automatically.

However my understanding of the device ID is that it was supposed to provide a way to identify multiple instances of identical devices in a reliable way, to solve problems like the one we are trying to solve here...

So maybe let's stop solving an already solved problem and just state that you need to explicitly assign device ID to use this framework?

Best regards,
Tomasz

#78 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi,

Quoted 156 lines · Tomasz Figa
Quoted 5 lines · On Wednesday 14 of August 2013 00:19:28 Sylwester Nawrocki wrote:

W dniu 2013-08-13 14:05, Kishon Vijay Abraham I pisze:

Quoted 4 lines · Tomasz Figa
Quoted 3 lines · On Tuesday 13 of August 2013 16:14:44 Kishon Vijay Abraham I wrote:
Quoted 2 lines · Felipe Balbi
Quoted 1 line

On Wed, Jul 31, 2013 at 11:14:32AM +0530, Kishon Vijay Abraham I

Quoted 137 lines · wrote:
Quoted 109 lines
Quoted 109 lines
Quoted 109 lines
Quoted 103 lines
Quoted 93 lines
Quoted 82 lines
Quoted 71 lines
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines

IMHO we need a lookup method for PHYs, just like for clocks, regulators, PWMs or even i2c busses because there are complex cases
when passing just a name using platform data will not work. I would
second what Stephen said [1] and define a structure doing things
in a
DT-like way.

Example;

[platform code]

static const struct phy_lookup my_phy_lookup[] = {

Quoted 8 lines
Quoted 2 lines
	PHY_LOOKUP("s3c-hsotg.0", "otg", "samsung-usbphy.1",
	"phy.2"),

The only problem here is that if *PLATFORM_DEVID_AUTO* is used while
creating the device, the ids in the device name would change and
PHY_LOOKUP wont be useful.

Quoted 8 lines

I don't think this is a problem. All the existing lookup methods
already
use ID to identify devices (see regulators, clkdev, PWMs, i2c, ...). You
can simply add a requirement that the ID must be assigned manually,
without using PLATFORM_DEVID_AUTO to use PHY lookup.

And I'm saying that this idea, of using a specific name and id, is
frought with fragility and will break in the future in various ways
when
devices get added to systems, making these strings constantly have
to be
kept up to date with different board configurations.

People, NEVER, hardcode something like an id. The fact that this
happens today with the clock code, doesn't make it right, it makes
the
clock code wrong. Others have already said that this is wrong there
as
well, as systems change and dynamic ids get used more and more.

Let's not repeat the same mistakes of the past just because we refuse to
learn from them...

So again, the "find a phy by a string" functions should be removed,
the
device id should be automatically created by the phy core just to
make
things unique in sysfs, and no driver code should _ever_ be reliant
on
the number that is being created, and the pointer to the phy structure
should be used everywhere instead.

Quoted 4 lines

With those types of changes, I will consider merging this subsystem,
but
without them, sorry, I will not.

I'll agree with Greg here, the very fact that we see people trying to
add a requirement of *NOT* using PLATFORM_DEVID_AUTO already points
to a big problem in the framework.

Quoted 10 lines

The fact is that if we don't allow PLATFORM_DEVID_AUTO we will end up
adding similar infrastructure to the driver themselves to make sure
we
don't end up with duplicate names in sysfs in case we have multiple
instances of the same IP in the SoC (or several of the same PCIe card).
I really don't want to go back to that.

Quoted 9 lines

If we are using PLATFORM_DEVID_AUTO, then I dont see any way we can
give the correct binding information to the PHY framework. I think we
can drop having this non-dt support in PHY framework? I see only one
platform (OMAP3) going to be needing this non-dt support and we can
use the USB PHY library for it.>

Quoted 3 lines

you shouldn't drop support for non-DT platform, in any case we lived
without DT (and still do) for years. Gotta find a better way ;-)

hmm..

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

how about passing the device names of PHY in platform data of the controller? It should be deterministic as the PHY framework assigns its
own id and we *don't* want to add any requirement that the ID must be
assigned manually without using PLATFORM_DEVID_AUTO. We can get rid of
*phy_init_data* in the v10 patch series.

OK, so the PHY device name would have a fixed part, passed as platform data of the controller and a variable part appended by the PHY core, depending on the number of registered PHYs ?

Then same PHY names would be passed as the PHY provider driver's platform data ?

Then if there are 2 instances of the above (same names in platform data) how would be determined which PHY controller is linked to which PHY supplier ?

I guess you want each device instance to have different PHY device names already in platform data ? That might work. We probably will be focused mostly on DT anyway. It seem without DT we are trying to find some layer that would allow us to couple relevant devices and overcome driver core inconvenience that it provides to means to identify specific devices in advance. :) Your proposal sounds reasonable, however I might be missing some details or corner cases.

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

What about slightly altering the concept of v9 to pass a pointer to struct device instead of device name inside phy_init_data?

As Felipe said, we don't want to pass pointers in platform_data to/from random subsystems. We pass data, passing pointers would be a total mess IMHO.

Well, this is a total mess anyway... I don't really get the point of using PLATFORM_DEVID_AUTO. The only thing that comes to my mind is that you can use it if you don't care about the ID and so it can be assigned automatically.

Quoted 7 lines

However my understanding of the device ID is that it was supposed to provide a way to identify multiple instances of identical devices in a reliable way, to solve problems like the one we are trying to solve here...

So maybe let's stop solving an already solved problem and just state that you need to explicitly assign device ID to use this framework?

Felipe,
Can we have it the way I had in my v10 patch series till we find a better way? I think this *non-dt* stuff shouldn't be blocking as most of the users are dt only?

Thanks
Kishon

#79 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Felipe,

ping..

Quoted 174 lines · Kishon Vijay Abraham I

Hi,

Quoted 156 lines · Tomasz Figa
Quoted 5 lines · On Wednesday 14 of August 2013 00:19:28 Sylwester Nawrocki wrote:

W dniu 2013-08-13 14:05, Kishon Vijay Abraham I pisze:

Quoted 4 lines · Tomasz Figa
Quoted 3 lines · On Tuesday 13 of August 2013 16:14:44 Kishon Vijay Abraham I wrote:
Quoted 2 lines · Felipe Balbi
Quoted 1 line

On Wed, Jul 31, 2013 at 11:14:32AM +0530, Kishon Vijay Abraham I

Quoted 137 lines · wrote:
Quoted 109 lines
Quoted 109 lines
Quoted 109 lines
Quoted 103 lines
Quoted 93 lines
Quoted 82 lines
Quoted 71 lines
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines

IMHO we need a lookup method for PHYs, just like for clocks,
regulators, PWMs or even i2c busses because there are complex
cases
when passing just a name using platform data will not work. I
would
second what Stephen said [1] and define a structure doing
things
in a
DT-like way.

Example;

[platform code]

static const struct phy_lookup my_phy_lookup[] = {

Quoted 8 lines
Quoted 2 lines

PHY_LOOKUP("s3c-hsotg.0", "otg", "samsung-usbphy.1",
"phy.2"),

The only problem here is that if *PLATFORM_DEVID_AUTO* is used while
creating the device, the ids in the device name would change and
PHY_LOOKUP wont be useful.

Quoted 8 lines

I don't think this is a problem. All the existing lookup methods
already
use ID to identify devices (see regulators, clkdev, PWMs, i2c, ...). You
can simply add a requirement that the ID must be assigned manually,
without using PLATFORM_DEVID_AUTO to use PHY lookup.

And I'm saying that this idea, of using a specific name and id, is
frought with fragility and will break in the future in various ways
when
devices get added to systems, making these strings constantly have
to be
kept up to date with different board configurations.

People, NEVER, hardcode something like an id. The fact that this
happens today with the clock code, doesn't make it right, it makes
the
clock code wrong. Others have already said that this is wrong there
as
well, as systems change and dynamic ids get used more and more.

Let's not repeat the same mistakes of the past just because we refuse to
learn from them...

So again, the "find a phy by a string" functions should be removed,
the
device id should be automatically created by the phy core just to
make
things unique in sysfs, and no driver code should _ever_ be reliant
on
the number that is being created, and the pointer to the phy structure
should be used everywhere instead.

Quoted 4 lines

With those types of changes, I will consider merging this subsystem,
but
without them, sorry, I will not.

I'll agree with Greg here, the very fact that we see people trying to
add a requirement of *NOT* using PLATFORM_DEVID_AUTO already points
to a big problem in the framework.

Quoted 10 lines

The fact is that if we don't allow PLATFORM_DEVID_AUTO we will end up
adding similar infrastructure to the driver themselves to make sure
we
don't end up with duplicate names in sysfs in case we have multiple
instances of the same IP in the SoC (or several of the same PCIe card).
I really don't want to go back to that.

Quoted 9 lines

If we are using PLATFORM_DEVID_AUTO, then I dont see any way we can
give the correct binding information to the PHY framework. I think we
can drop having this non-dt support in PHY framework? I see only one
platform (OMAP3) going to be needing this non-dt support and we can
use the USB PHY library for it.>

Quoted 3 lines

you shouldn't drop support for non-DT platform, in any case we lived
without DT (and still do) for years. Gotta find a better way ;-)

hmm..

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

how about passing the device names of PHY in platform data of the controller? It should be deterministic as the PHY framework assigns its
own id and we *don't* want to add any requirement that the ID must be
assigned manually without using PLATFORM_DEVID_AUTO. We can get rid of
*phy_init_data* in the v10 patch series.

OK, so the PHY device name would have a fixed part, passed as platform data of the controller and a variable part appended by the PHY core, depending on the number of registered PHYs ?

Then same PHY names would be passed as the PHY provider driver's platform data ?

Then if there are 2 instances of the above (same names in platform data) how would be determined which PHY controller is linked to which PHY supplier ?

I guess you want each device instance to have different PHY device names already in platform data ? That might work. We probably will be focused mostly on DT anyway. It seem without DT we are trying to find some layer that would allow us to couple relevant devices and overcome driver core inconvenience that it provides to means to identify specific devices in advance. :) Your proposal sounds reasonable, however I might be missing some details or corner cases.

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

What about slightly altering the concept of v9 to pass a pointer to struct device instead of device name inside phy_init_data?

As Felipe said, we don't want to pass pointers in platform_data to/from random subsystems. We pass data, passing pointers would be a total mess IMHO.

Well, this is a total mess anyway... I don't really get the point of using PLATFORM_DEVID_AUTO. The only thing that comes to my mind is that you can use it if you don't care about the ID and so it can be assigned automatically.

Quoted 7 lines

However my understanding of the device ID is that it was supposed to provide a way to identify multiple instances of identical devices in a reliable way, to solve problems like the one we are trying to solve here...

So maybe let's stop solving an already solved problem and just state that you need to explicitly assign device ID to use this framework?

Felipe,
Can we have it the way I had in my v10 patch series till we find a better way? I think this *non-dt* stuff shouldn't be blocking as most of the users are dt only?

Thanks
Kishon

#80 lore raw

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

Hi,

Quoted 6 lines · Kishon Vijay Abraham I
Quoted 6 lines
Quoted 2 lines

So maybe let's stop solving an already solved problem and just state that you need to explicitly assign device ID to use this framework?

Felipe,
Can we have it the way I had in my v10 patch series till we find a better way? I think this *non-dt* stuff shouldn't be blocking as most of the users are dt only?

I don't have a lot of things against it, but preventing driver authors to use PLATFORM_DEVID_AUTO just to use the framework is likely going to piss some people off.

Perhaps we can start with this approach and fix things later ? At least it ungates all the PHY drivers which are depending on this framework (quite a few already). If everybody agrees with this approach, I'd be ok with it too.

cheers

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/20130820/3d97825d/attachment.sig>
#81 lore raw

PATCH 2/15 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/Kconfig         |    1 +
 drivers/usb/phy/phy-omap-usb2.c |   45 +++++++++++++++++++++++++++++++++++----
 2 files changed, 42 insertions(+), 4 deletions(-)
drivers/usb/phy/Kconfig +1 -0
index 3622fff..cc55993 100644
@@ -75,6 +75,7 @@ config OMAP_CONTROL_USB
 config OMAP_USB2
 	tristate "OMAP USB2 PHY Driver"
 	depends on ARCH_OMAP2PLUS
+	depends on GENERIC_PHY
 	select OMAP_CONTROL_USB
 	help
 	  Enable this to support the transceiver that is part of SOC. This
drivers/usb/phy/phy-omap-usb2.c +41 -4

79 lines not on this page · raw message

Signature · 1 line
1.7.10.4
maintainer
#82 lore raw

Re: [PATCH 02/15] usb: phy: omap-usb2: use the new generic PHY framework

Quoted 90 lines · 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/Kconfig         |    1 +
 drivers/usb/phy/phy-omap-usb2.c |   45 +++++++++++++++++++++++++++++++++++----
 2 files changed, 42 insertions(+), 4 deletions(-)
drivers/usb/phy/Kconfig +1 -0
index 3622fff..cc55993 100644
@@ -75,6 +75,7 @@ config OMAP_CONTROL_USB
 config OMAP_USB2
 	tristate "OMAP USB2 PHY Driver"
 	depends on ARCH_OMAP2PLUS
+	depends on GENERIC_PHY
 	select OMAP_CONTROL_USB
 	help
 	  Enable this to support the transceiver that is part of SOC. This
drivers/usb/phy/phy-omap-usb2.c +32 -0
index 844ab68..751b30f 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 = phy_get_drvdata(x);
+
+	omap_control_usb_phy_power(phy->control_dev, 0);
+
+	return 0;
+}
+
+static int omap_usb_power_on(struct phy *x)
+{
+	struct omap_usb *phy = phy_get_drvdata(x);
+
+	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,
+			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");

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

Quoted 9 lines
drivers/usb/phy/phy-omap-usb2.c +6 -0
@@ -159,6 +191,15 @@ static int omap_usb2_probe(struct platform_device *pdev)
 	otg->start_srp		= omap_usb_start_srp;
 	otg->phy		= &phy->phy;
 
+	platform_set_drvdata(pdev, phy);
+	pm_runtime_enable(phy->dev);
+
+	generic_phy = devm_phy_create(phy->dev, 0, &ops, "omap-usb2");
+	if (IS_ERR(generic_phy))
+		return PTR_ERR(generic_phy);

So, if I have two of these controllers in my system, I can't create the second phy because the name for it will be identical to the first? That's why the phy core should handle the id, and not rely on the drivers to set it, as they have no idea how many they have in the system.

thanks,

greg k-h

#83 lore raw

Re: [PATCH 02/15] usb: phy: omap-usb2: use the new generic PHY framework

Quoted 94 lines · Greg KH
Quoted 93 lines · 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/Kconfig         |    1 +
 drivers/usb/phy/phy-omap-usb2.c |   45 +++++++++++++++++++++++++++++++++++----
 2 files changed, 42 insertions(+), 4 deletions(-)
drivers/usb/phy/Kconfig +1 -0
index 3622fff..cc55993 100644
@@ -75,6 +75,7 @@ config OMAP_CONTROL_USB
 config OMAP_USB2
 	tristate "OMAP USB2 PHY Driver"
 	depends on ARCH_OMAP2PLUS
+	depends on GENERIC_PHY
 	select OMAP_CONTROL_USB
 	help
 	  Enable this to support the transceiver that is part of SOC. This
drivers/usb/phy/phy-omap-usb2.c +32 -0
index 844ab68..751b30f 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 = phy_get_drvdata(x);
+
+	omap_control_usb_phy_power(phy->control_dev, 0);
+
+	return 0;
+}
+
+static int omap_usb_power_on(struct phy *x)
+{
+	struct omap_usb *phy = phy_get_drvdata(x);
+
+	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,
+			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,15 @@ static int omap_usb2_probe(struct platform_device *pdev)
 	otg->start_srp		= omap_usb_start_srp;
 	otg->phy		= &phy->phy;
 
Quoted 12 lines

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

Quoted 6 lines
drivers/usb/phy/phy-omap-usb2.c +6 -0
+	platform_set_drvdata(pdev, phy);
+	pm_runtime_enable(phy->dev);
+
+	generic_phy = devm_phy_create(phy->dev, 0, &ops, "omap-usb2");
+	if (IS_ERR(generic_phy))
+		return PTR_ERR(generic_phy);

So, if I have two of these controllers in my system, I can't create the second phy because the name for it will be identical to the first? That's why the phy core should handle the id, and not rely on the drivers to set it, as they have no idea how many they have in the system.

hmm.. for such cases I'll have something like PLATFORM_DEVID_AUTO.

Thanks
Kishon

#84 lore raw

PATCH 3/15 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 |   50 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)
drivers/usb/phy/phy-twl4030-usb.c +49 -1
index 8f78d2d..9051756 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 = phy_get_drvdata(phy);
+
+	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 = phy_get_drvdata(phy);
+
+	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_resume(twl);
+	}
 
 	sysfs_notify(&twl->dev->kobj, NULL, "vbus");
 	return 0;
 }
 
+static int twl4030_phy_init(struct phy *phy)
+{
+	struct twl4030_usb *twl = phy_get_drvdata(phy);
+
+	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,19 @@ 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,
+		of_phy_simple_xlate);
+	if (IS_ERR(phy_provider))
+		return PTR_ERR(phy_provider);
+
+	phy = devm_phy_create(twl->dev, 0, &ops, "twl4030");
+	if (IS_ERR(phy)) {
+		dev_dbg(&pdev->dev, "Failed to create PHY\n");
+		return PTR_ERR(phy);
+	}
+
+	phy_set_drvdata(phy, twl);
+
 	/* init spinlock for workqueue */
 	spin_lock_init(&twl->lock);
 
Signature · 1 line
1.7.10.4
#85 lore raw

PATCH 4/15 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 |    3 +++
 include/linux/usb/musb.h       |    3 +++
 2 files changed, 6 insertions(+)
arch/arm/mach-omap2/usb-musb.c +3 -0
index 8c4de27..6aa7cbf 100644
@@ -85,6 +85,9 @@ 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_omap34xx())
+		musb_plat.phy_label = "twl4030";
+
 	if (soc_is_am35xx()) {
 		oh_name = "am35x_otg_hs";
 		name = "musb-am35x";
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
maintainer Acked-by on v1 4/15
#86 lore raw

Re: [PATCH 04/15] ARM: OMAP: USB: Add phy binding information

Quoted 17 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.

---
 arch/arm/mach-omap2/usb-musb.c |    3 +++
 include/linux/usb/musb.h       |    3 +++
 2 files changed, 6 insertions(+)
arch/arm/mach-omap2/usb-musb.c +0 -0
index 8c4de27..6aa7cbf 100644

arch/arm/mach-omap2/usb-musb.c void __init usb_musb_init(struct omap_musb_board_data *musb_board_data) · line 93

Quoted 9 lines
arch/arm/mach-omap2/usb-musb.c +3 -0
@@ -85,6 +85,9 @@ 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_omap34xx())
+		musb_plat.phy_label = "twl4030";
+
 	if (soc_is_am35xx()) {
 		oh_name = "am35x_otg_hs";
 		name = "musb-am35x";

I don't think there's a USB PHY on non-twl4030 chips, so this should be OK:

Quoted 17 lines
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
#87 lore raw

PATCH 5/15 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 57e71f6..825790d 100644
@@ -19,6 +19,9 @@ OMAP MUSB GLUE
  - power : Should be "50". This signifies the controller can supply up to
    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 afdb164..533b2da 100644
@@ -144,6 +144,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 7d4329d..4134dd0 100644
@@ -70,6 +70,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 8f1abec..a461d2f 100644
@@ -76,6 +76,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 22d9f2b..1e8e2fe 100644
@@ -520,6 +520,7 @@
 				compatible = "ti,omap-usb2";
 				reg = <0x4a0ad080 0x58>;
 				ctrl-module = <&omap_control_usb>;
+				#phy-cells = <0>;
 			};
 		};
 
@@ -658,6 +659,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
maintainer Acked-by on v1 5/15
#88 lore raw

Re: [PATCH 05/15] ARM: dts: omap: update usb_otg_hs data

Quoted 9 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

In general the .dts changes should be separate to avoid pointless merge conflicts. But sounds like things will stop working for USB unless we do it like this so:

Quoted 144 lines
---
 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 57e71f6..825790d 100644
@@ -19,6 +19,9 @@ OMAP MUSB GLUE
  - power : Should be "50". This signifies the controller can supply up to
    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 afdb164..533b2da 100644
@@ -144,6 +144,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 7d4329d..4134dd0 100644
@@ -70,6 +70,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 8f1abec..a461d2f 100644
@@ -76,6 +76,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 22d9f2b..1e8e2fe 100644
@@ -520,6 +520,7 @@
 				compatible = "ti,omap-usb2";
 				reg = <0x4a0ad080 0x58>;
 				ctrl-module = <&omap_control_usb>;
+				#phy-cells = <0>;
 			};
 		};
 
@@ -658,6 +659,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
#89 lore raw

PATCH 6/15 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 and power_off 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/Kconfig     |    1 +
 drivers/usb/musb/musb_core.c |    1 +
 drivers/usb/musb/musb_core.h |    3 +++
 drivers/usb/musb/omap2430.c  |   26 ++++++++++++++++++++------
 4 files changed, 25 insertions(+), 6 deletions(-)
drivers/usb/musb/Kconfig +1 -0
index 797e3fd..01381ac 100644
@@ -76,6 +76,7 @@ config USB_MUSB_TUSB6010
 config USB_MUSB_OMAP2PLUS
 	tristate "OMAP2430 and onwards"
 	depends on ARCH_OMAP2PLUS
+	depends on GENERIC_PHY
 
 config USB_MUSB_AM35X
 	tristate "AM35x"
drivers/usb/musb/musb_core.c +1 -0
index 29a24ce..cca12c0 100644
@@ -1814,6 +1814,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
 	musb->min_power = plat->min_power;
 	musb->ops = plat->platform_ops;
 	musb->port_mode = plat->mode;
+	musb->phy_label = plat->phy_label;
 
 	/* The musb_platform_init() call:
 	 *   - adjusts musb->mregs
drivers/usb/musb/musb_core.h +3 -0
index 7d341c3..8f017ab 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;
@@ -346,6 +347,7 @@ struct musb {
 	u16			int_tx;
 
 	struct usb_phy		*xceiv;
+	struct phy		*phy;
 
 	int nIrq;
 	unsigned		irq_wake:1;
@@ -424,6 +426,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 +20 -6
index 6708a3b..87dac0f 100644
@@ -348,11 +348,21 @@ 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);
@@ -364,6 +374,10 @@ static int omap2430_musb_init(struct musb *musb)
 		return -EPROBE_DEFER;
 	}
 
+	if (IS_ERR(musb->phy)) {
+		pr_err("HS USB OTG: no PHY configured\n");
+		return PTR_ERR(musb->phy);
+	}
 	musb->isr = omap2430_musb_interrupt;
 
 	status = pm_runtime_get_sync(dev);
@@ -397,7 +411,7 @@ 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);
 	return 0;
@@ -460,6 +474,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;
 }
@@ -633,7 +648,7 @@ 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);
 	}
 
 	return 0;
@@ -648,8 +663,7 @@ 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_power_on(musb->phy);
 	}
 
 	return 0;
Signature · 1 line
1.7.10.4
#90 lore raw

PATCH 7/15 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 |   25 -------------------------
 1 file changed, 25 deletions(-)
drivers/usb/phy/phy-omap-usb2.c +0 -25
index 751b30f..3f2b125 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 = phy_get_drvdata(x);
@@ -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;
 
@@ -182,7 +158,6 @@ static int omap_usb2_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
-	phy->is_suspended	= 1;
 	omap_control_usb_phy_power(phy->control_dev, 0);
 
 	otg->set_host		= omap_usb_set_host;
Signature · 1 line
1.7.10.4
#91 lore raw

PATCH 8/15 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 |   57 +++++++++----------------------------
 1 file changed, 13 insertions(+), 44 deletions(-)
drivers/usb/phy/phy-twl4030-usb.c +13 -44
index 9051756..44f8b1b 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 = phy_get_drvdata(phy);
+
 	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 = phy_get_drvdata(phy);
-
-	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 = phy_get_drvdata(phy);
+
 	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 = phy_get_drvdata(phy);
-
-	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 = phy_get_drvdata(phy);
 	enum omap_musb_vbus_id_status status;
 
 	/*
@@ -621,32 +611,13 @@ static int twl4030_usb_phy_init(struct usb_phy *phy)
 
 	if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID) {
 		omap_musb_mailbox(twl->linkstat);
-		twl4030_phy_resume(twl);
+		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 = phy_get_drvdata(phy);
-
-	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
#92 lore raw

PATCH 9/15 phy: Add driver for Exynos MIPI CSIS/DSIM DPHYs

In reply to Kishon Vijay Abraham I

From: Sylwester Nawrocki <[email protected]>

Add a PHY provider driver for the Samsung S5P/Exynos SoC MIPI CSI-2 receiver and MIPI DSI transmitter DPHYs.

---
 .../devicetree/bindings/phy/samsung-phy.txt        |   14 ++
 drivers/phy/Kconfig                                |    9 ++
 drivers/phy/Makefile                               |    3 +-
 drivers/phy/phy-exynos-mipi-video.c                |  169 ++++++++++++++++++++
 4 files changed, 194 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/phy/samsung-phy.txt
 create mode 100644 drivers/phy/phy-exynos-mipi-video.c
Documentation/devicetree/bindings/phy/samsung-phy.txt new file +14 -0
new file mode 100644
index 0000000..5ff208c
@@ -0,0 +1,14 @@
+Samsung S5P/EXYNOS SoC series MIPI CSIS/DSIM DPHY
+-------------------------------------------------
+
+Required properties:
+- compatible : should be "samsung,s5pv210-mipi-video-phy";
+- reg : offset and length of the MIPI DPHY register set;
+- #phy-cells : from the generic phy bindings, must be 1;
+
+For "samsung,s5pv210-mipi-video-phy" compatible PHYs the second cell in
+the PHY specifier identifies the PHY and its meaning is as follows:
+  0 - MIPI CSIS 0,
+  1 - MIPI DSIM 0,
+  2 - MIPI CSIS 1,
+  3 - MIPI DSIM 1.
drivers/phy/Kconfig +9 -0
index 5f85909..6f446d0 100644
@@ -11,3 +11,12 @@ menuconfig GENERIC_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.
+
+if GENERIC_PHY
+
+config PHY_EXYNOS_MIPI_VIDEO
+	tristate "S5P/EXYNOS SoC series MIPI CSI-2/DSI PHY driver"
+	help
+	  Support for MIPI CSI-2 and MIPI DSI DPHY found on Samsung
+	  S5P and EXYNOS SoCs.
+endif
drivers/phy/Makefile +2 -1
index 9e9560f..71d8841 100644
@@ -2,4 +2,5 @@
 # Makefile for the phy drivers.
 #
 
-obj-$(CONFIG_GENERIC_PHY)	+= phy-core.o
+obj-$(CONFIG_GENERIC_PHY)		+= phy-core.o
+obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO)	+= phy-exynos-mipi-video.o
drivers/phy/phy-exynos-mipi-video.c new file +169 -0

169 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#93 lore raw

PATCH 10/15 video: exynos_mipi_dsim: Use the generic PHY driver

In reply to Kishon Vijay Abraham I

From: Sylwester Nawrocki <[email protected]>

Use the generic PHY API instead of the platform callback to control the MIPI DSIM DPHY. The 'phy_label' field is added to the platform data structure to allow PHY lookup on non-dt platforms.

---
 drivers/video/exynos/exynos_mipi_dsi.c |   19 ++++++++++---------
 include/video/exynos_mipi_dsim.h       |    6 ++++--
 2 files changed, 14 insertions(+), 11 deletions(-)
drivers/video/exynos/exynos_mipi_dsi.c +10 -9
index 32e5406..248e444 100644
@@ -30,6 +30,7 @@
 #include <linux/interrupt.h>
 #include <linux/kthread.h>
 #include <linux/notifier.h>
+#include <linux/phy/phy.h>
 #include <linux/regulator/consumer.h>
 #include <linux/pm_runtime.h>
 #include <linux/err.h>
@@ -156,8 +157,7 @@ static int exynos_mipi_dsi_blank_mode(struct mipi_dsim_device *dsim, int power)
 		exynos_mipi_regulator_enable(dsim);
 
 		/* enable MIPI-DSI PHY. */
-		if (dsim->pd->phy_enable)
-			dsim->pd->phy_enable(pdev, true);
+		phy_power_on(dsim->phy);
 
 		clk_enable(dsim->clock);
 
@@ -373,6 +373,10 @@ static int exynos_mipi_dsi_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	dsim->phy = devm_phy_get(&pdev->dev, dsim_pd->phy_label);
+	if (IS_ERR(dsim->phy))
+		return PTR_ERR(dsim->phy);
+
 	dsim->clock = devm_clk_get(&pdev->dev, "dsim0");
 	if (IS_ERR(dsim->clock)) {
 		dev_err(&pdev->dev, "failed to get dsim clock source\n");
@@ -439,8 +443,7 @@ static int exynos_mipi_dsi_probe(struct platform_device *pdev)
 	exynos_mipi_regulator_enable(dsim);
 
 	/* enable MIPI-DSI PHY. */
-	if (dsim->pd->phy_enable)
-		dsim->pd->phy_enable(pdev, true);
+	phy_power_on(dsim->phy);
 
 	exynos_mipi_update_cfg(dsim);
 
@@ -504,9 +507,8 @@ static int exynos_mipi_dsi_suspend(struct device *dev)
 	if (client_drv && client_drv->suspend)
 		client_drv->suspend(client_dev);
 
-	/* enable MIPI-DSI PHY. */
-	if (dsim->pd->phy_enable)
-		dsim->pd->phy_enable(pdev, false);
+	/* disable MIPI-DSI PHY. */
+	phy_power_off(dsim->phy);
 
 	clk_disable(dsim->clock);
 
@@ -536,8 +538,7 @@ static int exynos_mipi_dsi_resume(struct device *dev)
 	exynos_mipi_regulator_enable(dsim);
 
 	/* enable MIPI-DSI PHY. */
-	if (dsim->pd->phy_enable)
-		dsim->pd->phy_enable(pdev, true);
+	phy_power_on(dsim->phy);
 
 	clk_enable(dsim->clock);
 
include/video/exynos_mipi_dsim.h +4 -2
index 89dc88a..0e7e43b 100644
@@ -216,6 +216,7 @@ struct mipi_dsim_config {
  *	automatically.
  * @e_clk_src: select byte clock source.
  * @pd: pointer to MIPI-DSI driver platform data.
+ * @phy: pointer to the generic PHY
  */
 struct mipi_dsim_device {
 	struct device			*dev;
@@ -236,6 +237,7 @@ struct mipi_dsim_device {
 	bool				suspended;
 
 	struct mipi_dsim_platform_data	*pd;
+	struct phy			*phy;
 };
 
 /*
@@ -248,7 +250,7 @@ struct mipi_dsim_device {
  * @enabled: indicate whether mipi controller got enabled or not.
  * @lcd_panel_info: pointer for lcd panel specific structure.
  *	this structure specifies width, height, timing and polarity and so on.
- * @phy_enable: pointer to a callback controlling D-PHY enable/reset
+ * @phy_label: the generic PHY label
  */
 struct mipi_dsim_platform_data {
 	char				lcd_panel_name[PANEL_NAME_SIZE];
@@ -257,7 +259,7 @@ struct mipi_dsim_platform_data {
 	unsigned int			enabled;
 	void				*lcd_panel_info;
 
-	int (*phy_enable)(struct platform_device *pdev, bool on);
+	const char			*phy_label;
 };
 
 /*
Signature · 1 line
1.7.10.4
#94 lore raw

PATCH 11/15 exynos4-is: Use the generic MIPI CSIS PHY driver

In reply to Kishon Vijay Abraham I

From: Sylwester Nawrocki <[email protected]>

Use the generic PHY API instead of the platform callback to control the MIPI CSIS DPHY. The 'phy_label' field is added to the platform data structure to allow PHY lookup on non-dt platforms

---
 drivers/media/platform/exynos4-is/mipi-csis.c |   16 +++++++++++++---
 include/linux/platform_data/mipi-csis.h       |   11 ++---------
 2 files changed, 15 insertions(+), 12 deletions(-)
drivers/media/platform/exynos4-is/mipi-csis.c +13 -3
index 0914230..94028ce 100644
@@ -20,6 +20,7 @@
 #include <linux/memory.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/phy/phy.h>
 #include <linux/platform_data/mipi-csis.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
@@ -180,6 +181,7 @@ struct csis_drvdata {
  * @sd: v4l2_subdev associated with CSIS device instance
  * @index: the hardware instance index
  * @pdev: CSIS platform device
+ * @phy: pointer to the CSIS generic PHY
  * @regs: mmaped I/O registers memory
  * @supplies: CSIS regulator supplies
  * @clock: CSIS clocks
@@ -203,6 +205,8 @@ struct csis_state {
 	struct v4l2_subdev sd;
 	u8 index;
 	struct platform_device *pdev;
+	struct phy *phy;
+	const char *phy_label;
 	void __iomem *regs;
 	struct regulator_bulk_data supplies[CSIS_NUM_SUPPLIES];
 	struct clk *clock[NUM_CSIS_CLOCKS];
@@ -742,6 +746,7 @@ static int s5pcsis_get_platform_data(struct platform_device *pdev,
 	state->index = max(0, pdev->id);
 	state->max_num_lanes = state->index ? CSIS1_MAX_LANES :
 					      CSIS0_MAX_LANES;
+	state->phy_label = pdata->phy_label;
 	return 0;
 }
 
@@ -779,8 +784,9 @@ static int s5pcsis_parse_dt(struct platform_device *pdev,
 					"samsung,csis-wclk");
 
 	state->num_lanes = endpoint.bus.mipi_csi2.num_data_lanes;
-
 	of_node_put(node);
+
+	state->phy_label = "csis";
 	return 0;
 }
 #else
@@ -829,6 +835,10 @@ static int s5pcsis_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
+	state->phy = devm_phy_get(dev, state->phy_label);
+	if (IS_ERR(state->phy))
+		return PTR_ERR(state->phy);
+
 	mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	state->regs = devm_ioremap_resource(dev, mem_res);
 	if (IS_ERR(state->regs))
@@ -922,7 +932,7 @@ static int s5pcsis_pm_suspend(struct device *dev, bool runtime)
 	mutex_lock(&state->lock);
 	if (state->flags & ST_POWERED) {
 		s5pcsis_stop_stream(state);
-		ret = s5p_csis_phy_enable(state->index, false);
+		ret = phy_power_off(state->phy);
 		if (ret)
 			goto unlock;
 		ret = regulator_bulk_disable(CSIS_NUM_SUPPLIES,
@@ -958,7 +968,7 @@ static int s5pcsis_pm_resume(struct device *dev, bool runtime)
 					    state->supplies);
 		if (ret)
 			goto unlock;
-		ret = s5p_csis_phy_enable(state->index, true);
+		ret = phy_power_on(state->phy);
 		if (!ret) {
 			state->flags |= ST_POWERED;
 		} else {
include/linux/platform_data/mipi-csis.h +2 -9
index bf34e17..9214317 100644
@@ -17,21 +17,14 @@
  * @wclk_source: CSI wrapper clock selection: 0 - bus clock, 1 - ext. SCLK_CAM
  * @lanes:       number of data lanes used
  * @hs_settle:   HS-RX settle time
+ * @phy_label:	 the generic PHY label
  */
 struct s5p_platform_mipi_csis {
 	unsigned long clk_rate;
 	u8 wclk_source;
 	u8 lanes;
 	u8 hs_settle;
+	const char *phy_label;
 };
 
-/**
- * s5p_csis_phy_enable - global MIPI-CSI receiver D-PHY control
- * @id:     MIPI-CSIS harware instance index (0...1)
- * @on:     true to enable D-PHY and deassert its reset
- *          false to disable D-PHY
- * @return: 0 on success, or negative error code on failure
- */
-int s5p_csis_phy_enable(int id, bool on);
-
 #endif /* __PLAT_SAMSUNG_MIPI_CSIS_H_ */
Signature · 1 line
1.7.10.4
#95 lore raw

PATCH 12/15 ARM: Samsung: Remove the MIPI PHY setup code

In reply to Kishon Vijay Abraham I

From: Sylwester Nawrocki <[email protected]>

Generic PHY drivers are used to handle the MIPI CSIS and MIPI DSIM DPHYs so we can remove now unused code at arch/arm/plat-samsung. In case there is any board file for S5PV210 platforms using MIPI CSIS/DSIM (not any upstream currently) it should use the generic PHY API to bind the PHYs to respective PHY consumer drivers and a platform device for the PHY provider should be defined.

---
 arch/arm/mach-exynos/include/mach/regs-pmu.h    |    5 --
 arch/arm/mach-s5pv210/include/mach/regs-clock.h |    4 --
 arch/arm/plat-samsung/Kconfig                   |    5 --
 arch/arm/plat-samsung/Makefile                  |    1 -
 arch/arm/plat-samsung/setup-mipiphy.c           |   60 -----------------------
 5 files changed, 75 deletions(-)
 delete mode 100644 arch/arm/plat-samsung/setup-mipiphy.c
arch/arm/mach-exynos/include/mach/regs-pmu.h +0 -5
index 57344b7..2cdb63e 100644
@@ -44,11 +44,6 @@
 #define S5P_DAC_PHY_CONTROL			S5P_PMUREG(0x070C)
 #define S5P_DAC_PHY_ENABLE			(1 << 0)
 
-#define S5P_MIPI_DPHY_CONTROL(n)		S5P_PMUREG(0x0710 + (n) * 4)
-#define S5P_MIPI_DPHY_ENABLE			(1 << 0)
-#define S5P_MIPI_DPHY_SRESETN			(1 << 1)
-#define S5P_MIPI_DPHY_MRESETN			(1 << 2)
-
 #define S5P_INFORM0				S5P_PMUREG(0x0800)
 #define S5P_INFORM1				S5P_PMUREG(0x0804)
 #define S5P_INFORM2				S5P_PMUREG(0x0808)
arch/arm/mach-s5pv210/include/mach/regs-clock.h +0 -4
index 032de66..e345584 100644
@@ -147,10 +147,6 @@
 #define S5P_HDMI_PHY_CONTROL	S5P_CLKREG(0xE804)
 #define S5P_USB_PHY_CONTROL	S5P_CLKREG(0xE80C)
 #define S5P_DAC_PHY_CONTROL	S5P_CLKREG(0xE810)
-#define S5P_MIPI_DPHY_CONTROL(x) S5P_CLKREG(0xE814)
-#define S5P_MIPI_DPHY_ENABLE	(1 << 0)
-#define S5P_MIPI_DPHY_SRESETN	(1 << 1)
-#define S5P_MIPI_DPHY_MRESETN	(1 << 2)
 
 #define S5P_INFORM0		S5P_CLKREG(0xF000)
 #define S5P_INFORM1		S5P_CLKREG(0xF004)
arch/arm/plat-samsung/Kconfig +0 -5
index 3dc5cbe..db2d814 100644
@@ -402,11 +402,6 @@ config S3C24XX_PWM
 	  Support for exporting the PWM timer blocks via the pwm device
 	  system
 
-config S5P_SETUP_MIPIPHY
-	bool
-	help
-	  Compile in common setup code for MIPI-CSIS and MIPI-DSIM devices
-
 config S3C_SETUP_CAMIF
 	bool
 	help
arch/arm/plat-samsung/Makefile +0 -1
index 98d07d8..98f1e31 100644
@@ -41,7 +41,6 @@ obj-$(CONFIG_S5P_DEV_UART)	+= s5p-dev-uart.o
 obj-$(CONFIG_SAMSUNG_DEV_BACKLIGHT)	+= dev-backlight.o
 
 obj-$(CONFIG_S3C_SETUP_CAMIF)	+= setup-camif.o
-obj-$(CONFIG_S5P_SETUP_MIPIPHY)	+= setup-mipiphy.o
 
 # DMA support
 
arch/arm/plat-samsung/setup-mipiphy.c deleted +0 -60

60 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#96 lore raw

PATCH 13/15 phy: Add driver for Exynos DP PHY

In reply to Kishon Vijay Abraham I

From: Jingoo Han <[email protected]>

Add a PHY provider driver for the Samsung Exynos SoC Display Port PHY.

---
 .../devicetree/bindings/phy/samsung-phy.txt        |    8 ++
 drivers/phy/Kconfig                                |    6 ++
 drivers/phy/Makefile                               |    1 +
 drivers/phy/phy-exynos-dp-video.c                  |  111 ++++++++++++++++++++
 4 files changed, 126 insertions(+)
 create mode 100644 drivers/phy/phy-exynos-dp-video.c
Documentation/devicetree/bindings/phy/samsung-phy.txt +8 -0
index 5ff208c..c0fccaa 100644
@@ -12,3 +12,11 @@ the PHY specifier identifies the PHY and its meaning is as follows:
   1 - MIPI DSIM 0,
   2 - MIPI CSIS 1,
   3 - MIPI DSIM 1.
+
+Samsung EXYNOS SoC series Display Port PHY
+-------------------------------------------------
+
+Required properties:
+- compatible : should be "samsung,exynos5250-dp-video-phy";
+- reg : offset and length of the Display Port PHY register set;
+- #phy-cells : from the generic PHY bindings, must be 0;
drivers/phy/Kconfig +6 -0
index 6f446d0..ed0b1b8 100644
@@ -19,4 +19,10 @@ config PHY_EXYNOS_MIPI_VIDEO
 	help
 	  Support for MIPI CSI-2 and MIPI DSI DPHY found on Samsung
 	  S5P and EXYNOS SoCs.
+
+config PHY_EXYNOS_DP_VIDEO
+	tristate "EXYNOS SoC series Display Port PHY driver"
+	depends on OF
+	help
+	  Support for Display Port PHY found on Samsung EXYNOS SoCs.
 endif
drivers/phy/Makefile +1 -0
index 71d8841..0fd1340 100644
@@ -4,3 +4,4 @@
 
 obj-$(CONFIG_GENERIC_PHY)		+= phy-core.o
 obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO)	+= phy-exynos-mipi-video.o
+obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO)	+= phy-exynos-dp-video.o
drivers/phy/phy-exynos-dp-video.c new file +111 -0

111 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#97 lore raw

PATCH 14/15 video: exynos_dp: remove non-DT support for Exynos Display Port

In reply to Kishon Vijay Abraham I

From: Jingoo Han <[email protected]>

Exynos Display Port can be used only for Exynos SoCs. In addition, non-DT for EXYNOS SoCs is not supported from v3.11; thus, there is no need to support non-DT for Exynos Display Port.

The 'include/video/exynos_dp.h' file has been used for non-DT support and the content of file include/video/exynos_dp.h is moved to drivers/video/exynos/exynos_dp_core.h. Thus, the 'exynos_dp.h' file is removed. Also, 'struct exynos_dp_platdata' is removed, because it is not used any more.

---
 drivers/video/exynos/Kconfig          |    2 +-
 drivers/video/exynos/exynos_dp_core.c |  116 +++++++----------------------
 drivers/video/exynos/exynos_dp_core.h |  109 +++++++++++++++++++++++++++
 drivers/video/exynos/exynos_dp_reg.c  |    2 -
 include/video/exynos_dp.h             |  131 ---------------------------------
 5 files changed, 135 insertions(+), 225 deletions(-)
 delete mode 100644 include/video/exynos_dp.h
drivers/video/exynos/Kconfig +1 -1
index 1b035b2..fab9019 100644
@@ -29,7 +29,7 @@ config EXYNOS_LCD_S6E8AX0
 
 config EXYNOS_DP
 	bool "EXYNOS DP driver support"
-	depends on ARCH_EXYNOS
+	depends on OF && ARCH_EXYNOS
 	default n
 	help
 	  This enables support for DP device.
drivers/video/exynos/exynos_dp_core.c +25 -91

211 lines not on this page · raw message

drivers/video/exynos/exynos_dp_core.h +109 -0

121 lines not on this page · raw message

drivers/video/exynos/exynos_dp_reg.c +0 -2
index 29d9d03..b70da50 100644
@@ -14,8 +14,6 @@
 #include <linux/io.h>
 #include <linux/delay.h>
 
-#include <video/exynos_dp.h>
-
 #include "exynos_dp_core.h"
 #include "exynos_dp_reg.h"
 
include/video/exynos_dp.h deleted +0 -131

131 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#98 lore raw

PATCH 15/15 video: exynos_dp: Use the generic PHY driver

In reply to Kishon Vijay Abraham I

From: Jingoo Han <[email protected]>

Use the generic PHY API to control the DP PHY.

---
 .../devicetree/bindings/video/exynos_dp.txt          |   18 +++++++++---------
 drivers/video/exynos/exynos_dp_core.c                |   16 ++++++++++++----
 drivers/video/exynos/exynos_dp_core.h                |    1 +
 3 files changed, 22 insertions(+), 13 deletions(-)
Documentation/devicetree/bindings/video/exynos_dp.txt +9 -9
index 84f10c1..2f56376 100644
@@ -6,10 +6,10 @@ We use two nodes:
 	-dptx-phy node(defined inside dp-controller node)
 
 For the DP-PHY initialization, we use the dptx-phy node.
-Required properties for dptx-phy:
-	-reg:
+Required properties for dptx-phy: deprecated, use phys and phy-names
+	-reg: deprecated
 		Base address of DP PHY register.
-	-samsung,enable-mask:
+	-samsung,enable-mask: deprecated
 		The bit-mask used to enable/disable DP PHY.
 
 For the Panel initialization, we read data from dp-controller node.
@@ -25,6 +25,10 @@ Required properties for dp-controller:
 		from common clock binding: handle to dp clock.
 	-clock-names:
 		from common clock binding: Shall be "dp".
+	-phys:
+		from general PHY binding: the phandle for the PHY device.
+	-phy-names:
+		from general PHY binding: Should be "dp".
 	-interrupt-parent:
 		phandle to Interrupt combiner node.
 	-samsung,color-space:
@@ -67,12 +71,8 @@ SOC specific portion:
 		interrupt-parent = <&combiner>;
 		clocks = <&clock 342>;
 		clock-names = "dp";
-
-		dptx-phy {
-			reg = <0x10040720>;
-			samsung,enable-mask = <1>;
-		};
-
+		phys = <&dp_phy>;
+		phy-names = "dp";
 	};
 
 Board Specific portion:
drivers/video/exynos/exynos_dp_core.c +12 -4
index 05fed7d..5e1a715 100644
@@ -19,6 +19,7 @@
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 #include <linux/of.h>
+#include <linux/phy/phy.h>
 
 #include "exynos_dp_core.h"
 
@@ -960,8 +961,11 @@ static int exynos_dp_dt_parse_phydata(struct exynos_dp_device *dp)
 
 	dp_phy_node = of_find_node_by_name(dp_phy_node, "dptx-phy");
 	if (!dp_phy_node) {
-		dev_err(dp->dev, "could not find dptx-phy node\n");
-		return -ENODEV;
+		dp->phy = devm_phy_get(dp->dev, "dp");
+		if (IS_ERR(dp->phy))
+			return PTR_ERR(dp->phy);
+		else
+			return 0;
 	}
 
 	if (of_property_read_u32(dp_phy_node, "reg", &phy_base)) {
@@ -992,7 +996,9 @@ err:
 
 static void exynos_dp_phy_init(struct exynos_dp_device *dp)
 {
-	if (dp->phy_addr) {
+	if (dp->phy) {
+		phy_power_on(dp->phy);
+	} else if (dp->phy_addr) {
 		u32 reg;
 
 		reg = __raw_readl(dp->phy_addr);
@@ -1003,7 +1009,9 @@ static void exynos_dp_phy_init(struct exynos_dp_device *dp)
 
 static void exynos_dp_phy_exit(struct exynos_dp_device *dp)
 {
-	if (dp->phy_addr) {
+	if (dp->phy) {
+		phy_power_off(dp->phy);
+	} else if (dp->phy_addr) {
 		u32 reg;
 
 		reg = __raw_readl(dp->phy_addr);
drivers/video/exynos/exynos_dp_core.h +1 -0
index 56cfec8..607e36d 100644
@@ -151,6 +151,7 @@ struct exynos_dp_device {
 	struct video_info	*video_info;
 	struct link_train	link_train;
 	struct work_struct	hotplug_work;
+	struct phy		*phy;
 };
 
 /* exynos_dp_reg.c */
Signature · 1 line
1.7.10.4