Skip to contentSkip to conversation

phy: fixes for 3.16 -rc cycle

GIT PULL In review Kishon Vijay Abraham I 2 participants 17 messages Jul 7, 2014 – Jul 10, 2014

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

Hi Greg,

Please find the pull requeust for 3.16 -rc cycle for PHY subsystem.

It contains few fixes in phy-core and few other PHY drivers. It also adds regulatore support in PHY core which is needed to get USB and SATA working in DRA7xx.

Please consider merging this for this -rc cylce. Let me know if I have to change something.

Cheers
Kishon

The following changes since commit a497c3ba1d97fc69c1e78e7b96435ba8c2cb42ee:

Linux 3.16-rc2 (2014-06-21 19:02:54 -1000)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/kishon/linux-phy.git tags/for-3.16-rc

for you to fetch changes up to 59a7ada8f05269172aa80cf92017a35abe6a0339:

phy: omap-usb2: Balance pm_runtime_enable() on probe failure and remove (2014-07-04 20:43:26 +0530)

----------------------------------------------------------------
for 3.16-rc

Contains fixes in phy-core and other minor fixes in some of the other PHY drivers. It also adds regulator support in PHY core needed to get USB and SATA working in DRA7x. (These regulators were always on previously).

----------------------------------------------------------------
Himangi Saraogi (1):
usb: phy: omap-usb2: fix devm_ioremap_resource error detection code

Kamil Debski (1):
phy: phy-samsung-usb2: Change phy power on/power off sequence

Maxime Ripard (1):
phy: sun4i: depend on RESET_CONTROLLER

Roger Quadros (4):
phy: core: Fix error path in phy_create()
phy: core: Support regulator supply for PHY power
phy: core: Add phy-supply to DT binding documentation
phy: omap-usb2: Balance pm_runtime_enable() on probe failure and remove

Sjoerd Simons (1):
drivers: phy: phy-samsung-usb2.c: Add missing MODULE_DEVICE_TABLE

 .../devicetree/bindings/phy/phy-bindings.txt       |    4 +
 drivers/phy/Kconfig                                |    1 +
 drivers/phy/phy-core.c                             |   33 +++++-
 drivers/phy/phy-exynos4x12-usb2.c                  |  112 +++++++++++++-------
 drivers/phy/phy-exynos5250-usb2.c                  |    2 -
 drivers/phy/phy-omap-usb2.c                        |   11 +-
 drivers/phy/phy-samsung-usb2.c                     |    1 +
 drivers/phy/phy-samsung-usb2.h                     |    3 +-
 include/linux/phy/phy.h                            |    2 +
 9 files changed, 122 insertions(+), 47 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/8 phy: sun4i: depend on RESET_CONTROLLER

From: Maxime Ripard <[email protected]>

The driver depend on the reset framework in a mandatory way. Make sure reset_control_get is defined by adding this dependency in Kconfig

---
 drivers/phy/Kconfig |    1 +
 1 file changed, 1 insertion(+)
drivers/phy/Kconfig +1 -0
index 16a2f06..1d8099a 100644
@@ -112,6 +112,7 @@ config PHY_EXYNOS5250_SATA
 config PHY_SUN4I_USB
 	tristate "Allwinner sunxi SoC USB PHY driver"
 	depends on ARCH_SUNXI && HAS_IOMEM && OF
+	depends on RESET_CONTROLLER
 	select GENERIC_PHY
 	help
 	  Enable this to support the transceiver that is part of Allwinner
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/8 usb: phy: omap-usb2: fix devm_ioremap_resource error detection code

In reply to Kishon Vijay Abraham I

From: Himangi Saraogi <[email protected]>

devm_ioremap_resource returns an ERR_PTR value, not NULL, on failure.

A simplified version of the semantic match that finds this problem is as follows:

// <smpl>
@@
expression e,e1;
statement S;
@@

*e = devm_ioremap_resource(...);
if (!e1) S

// </smpl>

---
 drivers/phy/phy-omap-usb2.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/phy/phy-omap-usb2.c +2 -2
index 7007c11..2063d54 100644
@@ -233,8 +233,8 @@ static int omap_usb2_probe(struct platform_device *pdev)
 	if (phy_data->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
 		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 		phy->phy_base = devm_ioremap_resource(&pdev->dev, res);
-		if (!phy->phy_base)
-			return -ENOMEM;
+		if (IS_ERR(phy->phy_base))
+			return PTR_ERR(phy->phy_base);
 		phy->flags |= OMAP_USB2_CALIBRATE_FALSE_DISCONNECT;
 	}
 
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 3/8 phy: phy-samsung-usb2: Change phy power on/power off sequence

In reply to Kishon Vijay Abraham I

From: Kamil Debski <[email protected]>

The Exynos4412 USB 2.0 PHY hardware differs from the description provided in the documentation. Some register bits have different function. This patch fixes the defines of register bits and changes the way how phys are powered on and off.

---
 drivers/phy/phy-exynos4x12-usb2.c |  112 +++++++++++++++++++++++++------------
 drivers/phy/phy-exynos5250-usb2.c |    2 -
 drivers/phy/phy-samsung-usb2.h    |    3 +-
 3 files changed, 77 insertions(+), 40 deletions(-)
drivers/phy/phy-exynos4x12-usb2.c +75 -37
index d92a7cc..63134d8 100644
@@ -86,13 +86,23 @@
 #define EXYNOS_4x12_URSTCON_OTG_HLINK		BIT(1)
 #define EXYNOS_4x12_URSTCON_OTG_PHYLINK		BIT(2)
 #define EXYNOS_4x12_URSTCON_HOST_PHY		BIT(3)
+/* The following bit defines are presented in the
+ * order taken from the Exynos4412 reference manual.
+ *
+ * During experiments with the hardware and debugging
+ * it was determined that the hardware behaves contrary
+ * to the manual.
+ *
+ * The following bit values were chaned accordingly to the
+ * results of real hardware experiments.
+ */
 #define EXYNOS_4x12_URSTCON_PHY1		BIT(4)
-#define EXYNOS_4x12_URSTCON_HSIC0		BIT(5)
-#define EXYNOS_4x12_URSTCON_HSIC1		BIT(6)
+#define EXYNOS_4x12_URSTCON_HSIC0		BIT(6)
+#define EXYNOS_4x12_URSTCON_HSIC1		BIT(5)
 #define EXYNOS_4x12_URSTCON_HOST_LINK_ALL	BIT(7)
-#define EXYNOS_4x12_URSTCON_HOST_LINK_P0	BIT(8)
+#define EXYNOS_4x12_URSTCON_HOST_LINK_P0	BIT(10)
 #define EXYNOS_4x12_URSTCON_HOST_LINK_P1	BIT(9)
-#define EXYNOS_4x12_URSTCON_HOST_LINK_P2	BIT(10)
+#define EXYNOS_4x12_URSTCON_HOST_LINK_P2	BIT(8)
 
 /* Isolation, configured in the power management unit */
 #define EXYNOS_4x12_USB_ISOL_OFFSET		0x704
@@ -188,6 +198,7 @@ static void exynos4x12_setup_clk(struct samsung_usb2_phy_instance *inst)
 	clk = readl(drv->reg_phy + EXYNOS_4x12_UPHYCLK);
 	clk &= ~EXYNOS_4x12_UPHYCLK_PHYFSEL_MASK;
 	clk |= drv->ref_reg_val << EXYNOS_4x12_UPHYCLK_PHYFSEL_OFFSET;
+	clk |= EXYNOS_4x12_UPHYCLK_PHY1_COMMON_ON;
 	writel(clk, drv->reg_phy + EXYNOS_4x12_UPHYCLK);
 }
 
@@ -198,27 +209,22 @@ static void exynos4x12_phy_pwr(struct samsung_usb2_phy_instance *inst, bool on)
 	u32 phypwr = 0;
 	u32 rst;
 	u32 pwr;
-	u32 mode = 0;
-	u32 switch_mode = 0;
 
 	switch (inst->cfg->id) {
 	case EXYNOS4x12_DEVICE:
 		phypwr =	EXYNOS_4x12_UPHYPWR_PHY0;
 		rstbits =	EXYNOS_4x12_URSTCON_PHY0;
-		mode =		EXYNOS_4x12_MODE_SWITCH_DEVICE;
-		switch_mode =	1;
 		break;
 	case EXYNOS4x12_HOST:
 		phypwr =	EXYNOS_4x12_UPHYPWR_PHY1;
-		rstbits =	EXYNOS_4x12_URSTCON_HOST_PHY;
-		mode =		EXYNOS_4x12_MODE_SWITCH_HOST;
-		switch_mode =	1;
+		rstbits =	EXYNOS_4x12_URSTCON_HOST_PHY |
+				EXYNOS_4x12_URSTCON_PHY1 |
+				EXYNOS_4x12_URSTCON_HOST_LINK_P0;
 		break;
 	case EXYNOS4x12_HSIC0:
 		phypwr =	EXYNOS_4x12_UPHYPWR_HSIC0;
-		rstbits =	EXYNOS_4x12_URSTCON_HSIC1 |
-				EXYNOS_4x12_URSTCON_HOST_LINK_P0 |
-				EXYNOS_4x12_URSTCON_HOST_PHY;
+		rstbits =	EXYNOS_4x12_URSTCON_HSIC0 |
+				EXYNOS_4x12_URSTCON_HOST_LINK_P1;
 		break;
 	case EXYNOS4x12_HSIC1:
 		phypwr =	EXYNOS_4x12_UPHYPWR_HSIC1;
@@ -228,11 +234,6 @@ static void exynos4x12_phy_pwr(struct samsung_usb2_phy_instance *inst, bool on)
 	};
 
 	if (on) {
-		if (switch_mode)
-			regmap_update_bits(drv->reg_sys,
-					   EXYNOS_4x12_MODE_SWITCH_OFFSET,
-					   EXYNOS_4x12_MODE_SWITCH_MASK, mode);
-
 		pwr = readl(drv->reg_phy + EXYNOS_4x12_UPHYPWR);
 		pwr &= ~phypwr;
 		writel(pwr, drv->reg_phy + EXYNOS_4x12_UPHYPWR);
@@ -253,41 +254,78 @@ static void exynos4x12_phy_pwr(struct samsung_usb2_phy_instance *inst, bool on)
 	}
 }
 
-static int exynos4x12_power_on(struct samsung_usb2_phy_instance *inst)
+static void exynos4x12_power_on_int(struct samsung_usb2_phy_instance *inst)
 {
-	struct samsung_usb2_phy_driver *drv = inst->drv;
+	if (inst->int_cnt++ > 0)
+		return;
 
-	inst->enabled = 1;
 	exynos4x12_setup_clk(inst);
-	exynos4x12_phy_pwr(inst, 1);
 	exynos4x12_isol(inst, 0);
+	exynos4x12_phy_pwr(inst, 1);
+}
+
+static int exynos4x12_power_on(struct samsung_usb2_phy_instance *inst)
+{
+	struct samsung_usb2_phy_driver *drv = inst->drv;
+
+	if (inst->ext_cnt++ > 0)
+		return 0;
 
-	/* Power on the device, as it is necessary for HSIC to work */
-	if (inst->cfg->id == EXYNOS4x12_HSIC0) {
-		struct samsung_usb2_phy_instance *device =
-					&drv->instances[EXYNOS4x12_DEVICE];
-		exynos4x12_phy_pwr(device, 1);
-		exynos4x12_isol(device, 0);
+	if (inst->cfg->id == EXYNOS4x12_HOST) {
+		regmap_update_bits(drv->reg_sys, EXYNOS_4x12_MODE_SWITCH_OFFSET,
+						EXYNOS_4x12_MODE_SWITCH_MASK,
+						EXYNOS_4x12_MODE_SWITCH_HOST);
+		exynos4x12_power_on_int(&drv->instances[EXYNOS4x12_DEVICE]);
 	}
 
+	if (inst->cfg->id == EXYNOS4x12_DEVICE)
+		regmap_update_bits(drv->reg_sys, EXYNOS_4x12_MODE_SWITCH_OFFSET,
+						EXYNOS_4x12_MODE_SWITCH_MASK,
+						EXYNOS_4x12_MODE_SWITCH_DEVICE);
+
+	if (inst->cfg->id == EXYNOS4x12_HSIC0 ||
+		inst->cfg->id == EXYNOS4x12_HSIC1) {
+		exynos4x12_power_on_int(&drv->instances[EXYNOS4x12_DEVICE]);
+		exynos4x12_power_on_int(&drv->instances[EXYNOS4x12_HOST]);
+	}
+
+	exynos4x12_power_on_int(inst);
+
 	return 0;
 }
 
-static int exynos4x12_power_off(struct samsung_usb2_phy_instance *inst)
+static void exynos4x12_power_off_int(struct samsung_usb2_phy_instance *inst)
 {
-	struct samsung_usb2_phy_driver *drv = inst->drv;
-	struct samsung_usb2_phy_instance *device =
-					&drv->instances[EXYNOS4x12_DEVICE];
+	if (inst->int_cnt-- > 1)
+		return;
 
-	inst->enabled = 0;
 	exynos4x12_isol(inst, 1);
 	exynos4x12_phy_pwr(inst, 0);
+}
 
-	if (inst->cfg->id == EXYNOS4x12_HSIC0 && !device->enabled) {
-		exynos4x12_isol(device, 1);
-		exynos4x12_phy_pwr(device, 0);
+static int exynos4x12_power_off(struct samsung_usb2_phy_instance *inst)
+{
+	struct samsung_usb2_phy_driver *drv = inst->drv;
+
+	if (inst->ext_cnt-- > 1)
+		return 0;
+
+	if (inst->cfg->id == EXYNOS4x12_DEVICE)
+		regmap_update_bits(drv->reg_sys, EXYNOS_4x12_MODE_SWITCH_OFFSET,
+						EXYNOS_4x12_MODE_SWITCH_MASK,
+						EXYNOS_4x12_MODE_SWITCH_HOST);
+
+	if (inst->cfg->id == EXYNOS4x12_HOST)
+		exynos4x12_power_off_int(&drv->instances[EXYNOS4x12_DEVICE]);
+
+	if (inst->cfg->id == EXYNOS4x12_HSIC0 ||
+		inst->cfg->id == EXYNOS4x12_HSIC1) {
+		exynos4x12_power_off_int(&drv->instances[EXYNOS4x12_DEVICE]);
+		exynos4x12_power_off_int(&drv->instances[EXYNOS4x12_HOST]);
 	}
 
+	exynos4x12_power_off_int(inst);
+
 	return 0;
 }
 
drivers/phy/phy-exynos5250-usb2.c +0 -2
index 94179af..1c139aa 100644
@@ -318,7 +318,6 @@ static int exynos5250_power_on(struct samsung_usb2_phy_instance *inst)
 
 		break;
 	}
-	inst->enabled = 1;
 	exynos5250_isol(inst, 0);
 
 	return 0;
@@ -331,7 +330,6 @@ static int exynos5250_power_off(struct samsung_usb2_phy_instance *inst)
 	u32 otg;
 	u32 hsic;
 
-	inst->enabled = 0;
 	exynos5250_isol(inst, 1);
 
 	switch (inst->cfg->id) {
drivers/phy/phy-samsung-usb2.h +2 -1
index 45b3170..9188478 100644
@@ -29,7 +29,8 @@ struct samsung_usb2_phy_instance {
 	const struct samsung_usb2_common_phy *cfg;
 	struct phy *phy;
 	struct samsung_usb2_phy_driver *drv;
-	bool enabled;
+	int int_cnt;
+	int ext_cnt;
 };
 
 struct samsung_usb2_phy_driver {
Signature · 1 line
1.7.9.5
#4 lore raw

Re: [PATCH 3/8] phy: phy-samsung-usb2: Change phy power on/power off sequence

Quoted 11 lines · Kishon Vijay Abraham I

From: Kamil Debski <[email protected]>

The Exynos4412 USB 2.0 PHY hardware differs from the description provided in the documentation. Some register bits have different function. This patch fixes the defines of register bits and changes the way how phys are powered on and off.

Quoted 6 lines
---
 drivers/phy/phy-exynos4x12-usb2.c |  112 +++++++++++++++++++++++++------------
 drivers/phy/phy-exynos5250-usb2.c |    2 -
 drivers/phy/phy-samsung-usb2.h    |    3 +-
 3 files changed, 77 insertions(+), 40 deletions(-)

This doesn't look like a regression fix for 3.16-final, it looks like a "new feature" to me :(

sorry, I can't take this pull request, want me to pick the individual patches instead?

thanks,

greg k-h

#5 lore raw

Re: [PATCH 3/8] phy: phy-samsung-usb2: Change phy power on/power off sequence

Hi Greg,

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

From: Kamil Debski <[email protected]>

The Exynos4412 USB 2.0 PHY hardware differs from the description provided in the documentation. Some register bits have different function. This patch fixes the defines of register bits and changes the way how phys are powered on and off.

Quoted 6 lines
---
 drivers/phy/phy-exynos4x12-usb2.c |  112 +++++++++++++++++++++++++------------
 drivers/phy/phy-exynos5250-usb2.c |    2 -
 drivers/phy/phy-samsung-usb2.h    |    3 +-
 3 files changed, 77 insertions(+), 40 deletions(-)
Quoted 2 lines

This doesn't look like a regression fix for 3.16-final, it looks like a "new feature" to me :(

This patch was primarily due to the incorrectly documented register bits in the manual. So thought this would qualify as fix and should be in 3.16.

Thanks
Kishon

#6 lore raw

Re: [PATCH 3/8] phy: phy-samsung-usb2: Change phy power on/power off sequence

Quoted 22 lines · Kishon Vijay Abraham I

Hi Greg,

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

From: Kamil Debski <[email protected]>

The Exynos4412 USB 2.0 PHY hardware differs from the description provided in the documentation. Some register bits have different function. This patch fixes the defines of register bits and changes the way how phys are powered on and off.

---
 drivers/phy/phy-exynos4x12-usb2.c |  112 +++++++++++++++++++++++++------------
 drivers/phy/phy-exynos5250-usb2.c |    2 -
 drivers/phy/phy-samsung-usb2.h    |    3 +-
 3 files changed, 77 insertions(+), 40 deletions(-)
Quoted 5 lines
Quoted 2 lines

This doesn't look like a regression fix for 3.16-final, it looks like a "new feature" to me :(

This patch was primarily due to the incorrectly documented register bits in the manual. So thought this would qualify as fix and should be in 3.16.

Sorry, that's really big for a patch so late in the -rc cycle. There should only be real regressions or reported bugfixes now.

Care to redo this whole series based on these responses? I can't take it as-is.

thanks,

greg k-h

#7 lore raw

Re: [PATCH 3/8] phy: phy-samsung-usb2: Change phy power on/power off sequence

Quoted 23 lines · Greg KH
Quoted 22 lines · Kishon Vijay Abraham I

Hi Greg,

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

From: Kamil Debski <[email protected]>

The Exynos4412 USB 2.0 PHY hardware differs from the description provided in the documentation. Some register bits have different function. This patch fixes the defines of register bits and changes the way how phys are powered on and off.

---
 drivers/phy/phy-exynos4x12-usb2.c |  112 +++++++++++++++++++++++++------------
 drivers/phy/phy-exynos5250-usb2.c |    2 -
 drivers/phy/phy-samsung-usb2.h    |    3 +-
 3 files changed, 77 insertions(+), 40 deletions(-)
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

This doesn't look like a regression fix for 3.16-final, it looks like a "new feature" to me :(

This patch was primarily due to the incorrectly documented register bits in the manual. So thought this would qualify as fix and should be in 3.16.

Sorry, that's really big for a patch so late in the -rc cycle. There should only be real regressions or reported bugfixes now.

Okay sure. Will send it.

Thanks
Kishon

#8 lore raw

PATCH 4/8 drivers: phy: phy-samsung-usb2.c: Add missing MODULE_DEVICE_TABLE

In reply to Kishon Vijay Abraham I

From: Sjoerd Simons <[email protected]>

Allow phy-exynos-usb2 to be autoloaded based on devicetree information. Tested on Odroid X2 with its USB subsystem build as modules.

---
 drivers/phy/phy-samsung-usb2.c |    1 +
 1 file changed, 1 insertion(+)
drivers/phy/phy-samsung-usb2.c +1 -0
index 8a8c6bc..1e69a32 100644
@@ -107,6 +107,7 @@ static const struct of_device_id samsung_usb2_phy_of_match[] = {
 #endif
 	{ },
 };
+MODULE_DEVICE_TABLE(of, samsung_usb2_phy_of_match);
 
 static int samsung_usb2_phy_probe(struct platform_device *pdev)
 {
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH 5/8 phy: core: Fix error path in phy_create()

In reply to Kishon Vijay Abraham I

From: Roger Quadros <[email protected]>

Prevent resources from being freed twice in case device_add() call fails within phy_create(). Also use ida_simple_remove() instead of ida_remove() as we had used ida_simple_get() to allocate the ida.

---
 drivers/phy/phy-core.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/phy/phy-core.c +4 -3
index c64a2f3..49c4465 100644
@@ -614,8 +614,9 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
 	return phy;
 
 put_dev:
-	put_device(&phy->dev);
-	ida_remove(&phy_ida, phy->id);
+	put_device(&phy->dev);  /* calls phy_release() which frees resources */
+	return ERR_PTR(ret);
+
 free_phy:
 	kfree(phy);
 	return ERR_PTR(ret);
@@ -799,7 +800,7 @@ static void phy_release(struct device *dev)
 
 	phy = to_phy(dev);
 	dev_vdbg(dev, "releasing '%s'\n", dev_name(dev));
-	ida_remove(&phy_ida, phy->id);
+	ida_simple_remove(&phy_ida, phy->id);
 	kfree(phy);
 }
 
Signature · 1 line
1.7.9.5
#10 lore raw

Re: [PATCH 5/8] phy: core: Fix error path in phy_create()

Quoted 11 lines · Kishon Vijay Abraham I

From: Roger Quadros <[email protected]>

Prevent resources from being freed twice in case device_add() call fails within phy_create(). Also use ida_simple_remove() instead of ida_remove() as we had used ida_simple_get() to allocate the ida.

---
 drivers/phy/phy-core.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Is this a problem in older kernels as well?

thanks,

greg k-h

#11 lore raw

Re: [PATCH 5/8] phy: core: Fix error path in phy_create()

Hi,

Quoted 7 lines · Greg KH
Quoted 6 lines · Kishon Vijay Abraham I

From: Roger Quadros <[email protected]>

Prevent resources from being freed twice in case device_add() call fails within phy_create(). Also use ida_simple_remove() instead of ida_remove() as we had used ida_simple_get() to allocate the ida.

Quoted 7 lines
Quoted 5 lines
---
 drivers/phy/phy-core.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Is this a problem in older kernels as well?

yeah. Will send it for stable kernel.

Thanks
Kishon

#12 lore raw

PATCH 6/8 phy: core: Support regulator supply for PHY power

In reply to Kishon Vijay Abraham I

From: Roger Quadros <[email protected]>

Some PHYs can be powered by an external power regulator. e.g. USB_HS PHY on DRA7 SoC. Make the PHY core support a power regulator.

---
 drivers/phy/phy-core.c  |   26 ++++++++++++++++++++++++++
 include/linux/phy/phy.h |    2 ++
 2 files changed, 28 insertions(+)
drivers/phy/phy-core.c +26 -0
index 49c4465..75c9739 100644
@@ -21,6 +21,7 @@
 #include <linux/phy/phy.h>
 #include <linux/idr.h>
 #include <linux/pm_runtime.h>
+#include <linux/regulator/consumer.h>
 
 static struct class *phy_class;
 static DEFINE_MUTEX(phy_provider_mutex);
@@ -226,6 +227,12 @@ int phy_power_on(struct phy *phy)
 	if (!phy)
 		return 0;
 
+	if (phy->pwr) {
+		ret = regulator_enable(phy->pwr);
+		if (ret)
+			return ret;
+	}
+
 	ret = phy_pm_runtime_get_sync(phy);
 	if (ret < 0 && ret != -ENOTSUPP)
 		return ret;
@@ -247,6 +254,8 @@ int phy_power_on(struct phy *phy)
 out:
 	mutex_unlock(&phy->mutex);
 	phy_pm_runtime_put_sync(phy);
+	if (phy->pwr)
+		regulator_disable(phy->pwr);
 
 	return ret;
 }
@@ -272,6 +281,9 @@ int phy_power_off(struct phy *phy)
 	mutex_unlock(&phy->mutex);
 	phy_pm_runtime_put(phy);
 
+	if (phy->pwr)
+		regulator_disable(phy->pwr);
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(phy_power_off);
@@ -588,6 +600,16 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
 		goto free_phy;
 	}
 
+	/* phy-supply */
+	phy->pwr = regulator_get_optional(dev, "phy");
+	if (IS_ERR(phy->pwr)) {
+		if (PTR_ERR(phy->pwr) == -EPROBE_DEFER) {
+			ret = -EPROBE_DEFER;
+			goto free_ida;
+		}
+		phy->pwr = NULL;
+	}
+
 	device_initialize(&phy->dev);
 	mutex_init(&phy->mutex);
 
@@ -617,6 +639,9 @@ put_dev:
 	put_device(&phy->dev);  /* calls phy_release() which frees resources */
 	return ERR_PTR(ret);
 
+free_ida:
+	ida_simple_remove(&phy_ida, phy->id);
+
 free_phy:
 	kfree(phy);
 	return ERR_PTR(ret);
@@ -800,6 +825,7 @@ static void phy_release(struct device *dev)
 
 	phy = to_phy(dev);
 	dev_vdbg(dev, "releasing '%s'\n", dev_name(dev));
+	regulator_put(phy->pwr);
 	ida_simple_remove(&phy_ida, phy->id);
 	kfree(phy);
 }
include/linux/phy/phy.h +2 -0
index 2760744..9a86945 100644
@@ -18,6 +18,7 @@
 #include <linux/of.h>
 #include <linux/device.h>
 #include <linux/pm_runtime.h>
+#include <linux/regulator/consumer.h>
 
 struct phy;
 
@@ -65,6 +66,7 @@ struct phy {
 	int			init_count;
 	int			power_count;
 	struct phy_attrs	attrs;
+	struct regulator	*pwr;
 };
 
 /**
Signature · 1 line
1.7.9.5
#13 lore raw

Re: [PATCH 6/8] phy: core: Support regulator supply for PHY power

Quoted 6 lines · Kishon Vijay Abraham I

From: Roger Quadros <[email protected]>

Some PHYs can be powered by an external power regulator. e.g. USB_HS PHY on DRA7 SoC. Make the PHY core support a power regulator.

Quoted 6 lines
---
 drivers/phy/phy-core.c  |   26 ++++++++++++++++++++++++++
 include/linux/phy/phy.h |    2 ++
 2 files changed, 28 insertions(+)

This looks like a new feature :(

again, I can't take that for 3.16-final, you know better...

greg k-h

#14 lore raw

Re: [PATCH 6/8] phy: core: Support regulator supply for PHY power

Hi Greg,

Quoted 14 lines · Greg KH
Quoted 6 lines · Kishon Vijay Abraham I

From: Roger Quadros <[email protected]>

Some PHYs can be powered by an external power regulator. e.g. USB_HS PHY on DRA7 SoC. Make the PHY core support a power regulator.

Quoted 6 lines
---
 drivers/phy/phy-core.c  |   26 ++++++++++++++++++++++++++
 include/linux/phy/phy.h |    2 ++
 2 files changed, 28 insertions(+)
Quoted 3 lines

This looks like a new feature :(

again, I can't take that for 3.16-final, you know better...

In the outset it looks like a new feature (which actually is) but it actually is needed to get USB and SATA working in DRA7xx. It was working before since these regulators were *always on* before. But now the the users of these regulators should explicitly enable it.

Thanks
Kishon

#15 lore raw

PATCH 7/8 phy: core: Add phy-supply to DT binding documentation

In reply to Kishon Vijay Abraham I

From: Roger Quadros <[email protected]>

phy-supply is a phandle to the regulator that provides power to the PHY. This regulator is managed during the PHY power on/off sequence by the phy core driver.

---
 .../devicetree/bindings/phy/phy-bindings.txt       |    4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/phy/phy-bindings.txt +4 -0
index 8ae844f..2aa1840 100644
@@ -10,6 +10,10 @@ Required Properties:
 		provider can use the values in cells to find the appropriate
 		PHY.
 
+Optional Properties:
+phy-supply:	Phandle to a regulator that provides power to the PHY. This
+		regulator will be managed during the PHY power on/off sequence.
+
 For example:
 
 phys: phy {
Signature · 1 line
1.7.9.5
#16 lore raw

PATCH 8/8 phy: omap-usb2: Balance pm_runtime_enable() on probe failure and remove

In reply to Kishon Vijay Abraham I

From: Roger Quadros <[email protected]>

If probe fails then we need to call pm_runtime_disable() to balance out the previous pm_runtime_enable() call. Else it will cause unbalanced pm_runtime_enable() call in the succeding probe call.

This anomaly was observed when the call to devm_phy_create() failed with -EPROBE_DEFER.

Balance out the pm_runtime_enable() call in .remove() as well.

---
 drivers/phy/phy-omap-usb2.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/phy/phy-omap-usb2.c +5 -2
index 2063d54..34b3961 100644
@@ -262,7 +262,6 @@ static int omap_usb2_probe(struct platform_device *pdev)
 	otg->phy		= &phy->phy;
 
 	platform_set_drvdata(pdev, phy);
-	pm_runtime_enable(phy->dev);
 
 	generic_phy = devm_phy_create(phy->dev, &ops, NULL);
 	if (IS_ERR(generic_phy))
@@ -270,10 +269,13 @@ static int omap_usb2_probe(struct platform_device *pdev)
 
 	phy_set_drvdata(generic_phy, phy);
 
+	pm_runtime_enable(phy->dev);
 	phy_provider = devm_of_phy_provider_register(phy->dev,
 			of_phy_simple_xlate);
-	if (IS_ERR(phy_provider))
+	if (IS_ERR(phy_provider)) {
+		pm_runtime_disable(phy->dev);
 		return PTR_ERR(phy_provider);
+	}
 
 	phy->wkupclk = devm_clk_get(phy->dev, "wkupclk");
 	if (IS_ERR(phy->wkupclk)) {
@@ -317,6 +319,7 @@ static int omap_usb2_remove(struct platform_device *pdev)
 	if (!IS_ERR(phy->optclk))
 		clk_unprepare(phy->optclk);
 	usb_remove_phy(&phy->phy);
+	pm_runtime_disable(phy->dev);
 
 	return 0;
 }
Signature · 1 line
1.7.9.5