Skip to contentSkip to conversation

PHY: Fixes for 3.17 -rc cycle

GIT PULL New Kishon Vijay Abraham I 2 participants 9 messages Aug 28, 2014 – Sep 4, 2014

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

Hi Greg,

Please find the pull request for this -rc cycle. It consistes of a regression fix to runtime PM on OMAP (cc'ed stable) and few other minor fixes.

Please consider merging it in this -rc cycle.
Let me know If I have to make any changes.

Cheers
Kishon

The following changes since commit 451fd72219dd6f3355e2d036c598544c760ee532:

Merge tag 'pwm/for-3.17-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm (2014-08-22 14:50:21 -0700)

are available in the git repository at:

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

for you to fetch changes up to fbb1a770039d3900f5130bab949b757f6f7fb373:

phy: miphy365x: Select GENERIC_PHY instead of depending on it (2014-08-28 11:17:43 +0530)

----------------------------------------------------------------
for_3.17-rc

Fix regressions to runtime PM on OMAP and other minor fixes.

----------------------------------------------------------------
Kamil Debski (1):
MAINTAINERS: add entry for the Samsung USB2 PHY driver

Lee Jones (1):
phy: miphy365x: Select GENERIC_PHY instead of depending on it

Sjoerd Simons (1):
phy: exynos5-usbdrd: Add MODULE_DEVICE_TABLE entry

Tony Lindgren (2):
usb: phy: twl4030-usb: Fix regressions to runtime PM on omaps
usb: phy: twl4030-usb: Fix lost interrupts after ID pin goes down

 MAINTAINERS                      |   13 ++++
 drivers/phy/Kconfig              |    2 +-
 drivers/phy/phy-exynos5-usbdrd.c |    1 +
 drivers/phy/phy-twl4030-usb.c    |  121 +++++++++++++++++++++++---------------
 4 files changed, 88 insertions(+), 49 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/5 usb: phy: twl4030-usb: Fix regressions to runtime PM on omaps

From: Tony Lindgren <[email protected]>

Commit 30a70b026b4cd ("usb: musb: fix obex in g_nokia.ko causing kernel panic") attempted to fix runtime PM handling for PHYs that are on the I2C bus. Commit 3063a12be2b0 ("usb: musb: fix PHY power on/off") then changed things around to enable of PHYs that rely on runtime PM.

These changes however broke idling of the PHY and causes at least 100 mW extra power consumption on omaps, which is a lot with the idle power consumption being below 10 mW range on many devices.

As calling phy_power_on/off from runtime PM calls in the USB causes complicated issues with I2C connected PHYs, let's just let the PHY do it's own runtime PM as needed. This leaves out the dependency between PHYs and USB controller drivers for runtime PM.

Let's fix the regression for twl4030-usb by adding minimal runtime PM support. This allows idling the PHY on disconnect.

Note that we are changing to use standard runtime PM handling for twl4030_phy_init() as that function just checks the state and does not initialize the PHY. The PHY won't get initialized until in twl4030_phy_power_on().

Fixes 30a70b026b4cd ("usb: musb: fix obex in g_nokia.ko causing kernel panic")
Fixes 3063a12be2b0 ("usb: musb: fix PHY power on/off")
Cc [email protected] # v3.15+
---
 drivers/phy/phy-twl4030-usb.c |   88 +++++++++++++++++++++++++++++------------
 1 file changed, 63 insertions(+), 25 deletions(-)
drivers/phy/phy-twl4030-usb.c +63 -25
index e1a6623..0cb872b 100644
@@ -34,6 +34,7 @@
 #include <linux/delay.h>
 #include <linux/usb/otg.h>
 #include <linux/phy/phy.h>
+#include <linux/pm_runtime.h>
 #include <linux/usb/musb-omap.h>
 #include <linux/usb/ulpi.h>
 #include <linux/i2c/twl.h>
@@ -422,37 +423,55 @@ static void twl4030_phy_power(struct twl4030_usb *twl, int on)
 	}
 }
 
-static int twl4030_phy_power_off(struct phy *phy)
+static int twl4030_usb_runtime_suspend(struct device *dev)
 {
-	struct twl4030_usb *twl = phy_get_drvdata(phy);
+	struct twl4030_usb *twl = dev_get_drvdata(dev);
 
+	dev_dbg(twl->dev, "%s\n", __func__);
 	if (twl->asleep)
 		return 0;
 
 	twl4030_phy_power(twl, 0);
 	twl->asleep = 1;
-	dev_dbg(twl->dev, "%s\n", __func__);
+
 	return 0;
 }
 
-static void __twl4030_phy_power_on(struct twl4030_usb *twl)
+static int twl4030_usb_runtime_resume(struct device *dev)
 {
+	struct twl4030_usb *twl = dev_get_drvdata(dev);
+
+	dev_dbg(twl->dev, "%s\n", __func__);
+	if (!twl->asleep)
+		return 0;
+
 	twl4030_phy_power(twl, 1);
-	twl4030_i2c_access(twl, 1);
-	twl4030_usb_set_mode(twl, twl->usb_mode);
-	if (twl->usb_mode == T2_USB_MODE_ULPI)
-		twl4030_i2c_access(twl, 0);
+	twl->asleep = 0;
+
+	return 0;
+}
+
+static int twl4030_phy_power_off(struct phy *phy)
+{
+	struct twl4030_usb *twl = phy_get_drvdata(phy);
+
+	dev_dbg(twl->dev, "%s\n", __func__);
+	pm_runtime_mark_last_busy(twl->dev);
+	pm_runtime_put_autosuspend(twl->dev);
+
+	return 0;
 }
 
 static int twl4030_phy_power_on(struct phy *phy)
 {
 	struct twl4030_usb *twl = phy_get_drvdata(phy);
 
-	if (!twl->asleep)
-		return 0;
-	__twl4030_phy_power_on(twl);
-	twl->asleep = 0;
 	dev_dbg(twl->dev, "%s\n", __func__);
+	pm_runtime_get_sync(twl->dev);
+	twl4030_i2c_access(twl, 1);
+	twl4030_usb_set_mode(twl, twl->usb_mode);
+	if (twl->usb_mode == T2_USB_MODE_ULPI)
+		twl4030_i2c_access(twl, 0);
 
 	/*
 	 * XXX When VBUS gets driven after musb goes to A mode,
@@ -558,6 +577,16 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
 		 * USB_LINK_VBUS state.  musb_hdrc won't care until it
 		 * starts to handle softconnect right.
 		 */
+		if ((status == OMAP_MUSB_VBUS_VALID) ||
+		    (status == OMAP_MUSB_ID_GROUND)) {
+			if (twl->asleep)
+				pm_runtime_get_sync(twl->dev);
+		} else {
+			if (!twl->asleep) {
+				pm_runtime_mark_last_busy(twl->dev);
+				pm_runtime_put_autosuspend(twl->dev);
+			}
+		}
 		omap_musb_mailbox(status);
 	}
 	sysfs_notify(&twl->dev->kobj, NULL, "vbus");
@@ -599,22 +628,17 @@ static int twl4030_phy_init(struct phy *phy)
 	struct twl4030_usb *twl = phy_get_drvdata(phy);
 	enum omap_musb_vbus_id_status status;
 
-	/*
-	 * Start in sleep state, we'll get called through set_suspend()
-	 * callback when musb is runtime resumed and it's time to start.
-	 */
-	__twl4030_phy_power(twl, 0);
-	twl->asleep = 1;
-
+	pm_runtime_get_sync(twl->dev);
 	status = twl4030_usb_linkstat(twl);
 	twl->linkstat = status;
 
-	if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID) {
+	if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID)
 		omap_musb_mailbox(twl->linkstat);
-		twl4030_phy_power_on(phy);
-	}
 
 	sysfs_notify(&twl->dev->kobj, NULL, "vbus");
+	pm_runtime_mark_last_busy(twl->dev);
+	pm_runtime_put_autosuspend(twl->dev);
+
 	return 0;
 }
 
@@ -650,6 +674,11 @@ static const struct phy_ops ops = {
 	.owner		= THIS_MODULE,
 };
 
+static const struct dev_pm_ops twl4030_usb_pm_ops = {
+	SET_RUNTIME_PM_OPS(twl4030_usb_runtime_suspend,
+			   twl4030_usb_runtime_resume, NULL)
+};
+
 static int twl4030_usb_probe(struct platform_device *pdev)
 {
 	struct twl4030_usb_data *pdata = dev_get_platdata(&pdev->dev);
@@ -726,6 +755,11 @@ static int twl4030_usb_probe(struct platform_device *pdev)
 
 	ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier);
 
+	pm_runtime_use_autosuspend(&pdev->dev);
+	pm_runtime_set_autosuspend_delay(&pdev->dev, 2000);
+	pm_runtime_enable(&pdev->dev);
+	pm_runtime_get_sync(&pdev->dev);
+
 	/* Our job is to use irqs and status from the power module
 	 * to keep the transceiver disabled when nothing's connected.
 	 *
@@ -744,6 +778,9 @@ static int twl4030_usb_probe(struct platform_device *pdev)
 		return status;
 	}
 
+	pm_runtime_mark_last_busy(&pdev->dev);
+	pm_runtime_put_autosuspend(twl->dev);
+
 	dev_info(&pdev->dev, "Initialized TWL4030 USB module\n");
 	return 0;
 }
@@ -753,6 +790,7 @@ static int twl4030_usb_remove(struct platform_device *pdev)
 	struct twl4030_usb *twl = platform_get_drvdata(pdev);
 	int val;
 
+	pm_runtime_get_sync(twl->dev);
 	cancel_delayed_work(&twl->id_workaround_work);
 	device_remove_file(twl->dev, &dev_attr_vbus);
 
@@ -772,9 +810,8 @@ static int twl4030_usb_remove(struct platform_device *pdev)
 
 	/* disable complete OTG block */
 	twl4030_usb_clear_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB);
-
-	if (!twl->asleep)
-		twl4030_phy_power(twl, 0);
+	pm_runtime_mark_last_busy(twl->dev);
+	pm_runtime_put(twl->dev);
 
 	return 0;
 }
@@ -792,6 +829,7 @@ static struct platform_driver twl4030_usb_driver = {
 	.remove		= twl4030_usb_remove,
 	.driver		= {
 		.name	= "twl4030_usb",
+		.pm	= &twl4030_usb_pm_ops,
 		.owner	= THIS_MODULE,
 		.of_match_table = of_match_ptr(twl4030_usb_id_table),
 	},
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/5 usb: phy: twl4030-usb: Fix lost interrupts after ID pin goes down

In reply to Kishon Vijay Abraham I

From: Tony Lindgren <[email protected]>

Commit 249751f22380 ("usb: phy: twl4030-usb: poll for ID disconnect") added twl4030_id_workaround_work() to deal with lost interrupts after ID pin goes down. Looks like commit f1ddc24c9e33 ("usb: phy:
twl4030-usb: remove *set_suspend* and *phy_init* ops") changed things around for the generic phy framework, and delayed work no longer got called except initially during boot.

The PHY connect and disconnect interrupts for twl4030-usb are not working after disconnecting a USB-A cable from the board, and the deeper idle states for omap are blocked as the USB controller stays busy.

The issue can be solved by calling delayed work from twl4030_usb_irq() when ID pin is down and the PHY is not asleep like we already do in twl4030_id_workaround_work().

But as both twl4030_usb_irq() and twl4030_id_workaround_work() already do pretty much the same thing, let's call twl4030_usb_irq() from twl4030_id_workaround_work() instead of adding some more duplicate code. We also must call sysfs_notify() only when we have an interrupt and not from the delayed work as notified by Grazvydas Ignotas <[email protected]>.

Fixes f1ddc24c9e33 ("usb: phy: twl4030-usb: remove *set_suspend* and *phy_init* ops")
Cc [email protected] # v3.13+
---
 drivers/phy/phy-twl4030-usb.c |   33 ++++++++++-----------------------
 1 file changed, 10 insertions(+), 23 deletions(-)
drivers/phy/phy-twl4030-usb.c +10 -23
index 0cb872b..9cd33a4 100644
@@ -589,7 +589,15 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
 		}
 		omap_musb_mailbox(status);
 	}
-	sysfs_notify(&twl->dev->kobj, NULL, "vbus");
+
+	/* don't schedule during sleep - irq works right then */
+	if (status == OMAP_MUSB_ID_GROUND && !twl->asleep) {
+		cancel_delayed_work(&twl->id_workaround_work);
+		schedule_delayed_work(&twl->id_workaround_work, HZ);
+	}
+
+	if (irq)
+		sysfs_notify(&twl->dev->kobj, NULL, "vbus");
 
 	return IRQ_HANDLED;
 }
@@ -598,29 +606,8 @@ static void twl4030_id_workaround_work(struct work_struct *work)
 {
 	struct twl4030_usb *twl = container_of(work, struct twl4030_usb,
 		id_workaround_work.work);
-	enum omap_musb_vbus_id_status status;
-	bool status_changed = false;
-
-	status = twl4030_usb_linkstat(twl);
-
-	spin_lock_irq(&twl->lock);
-	if (status >= 0 && status != twl->linkstat) {
-		twl->linkstat = status;
-		status_changed = true;
-	}
-	spin_unlock_irq(&twl->lock);
-
-	if (status_changed) {
-		dev_dbg(twl->dev, "handle missing status change to %d\n",
-				status);
-		omap_musb_mailbox(status);
-	}
 
-	/* don't schedule during sleep - irq works right then */
-	if (status == OMAP_MUSB_ID_GROUND && !twl->asleep) {
-		cancel_delayed_work(&twl->id_workaround_work);
-		schedule_delayed_work(&twl->id_workaround_work, HZ);
-	}
+	twl4030_usb_irq(0, twl);
 }
 
 static int twl4030_phy_init(struct phy *phy)
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 3/5 phy: exynos5-usbdrd: Add MODULE_DEVICE_TABLE entry

In reply to Kishon Vijay Abraham I

From: Sjoerd Simons <[email protected]>

Add a MODULE_DEVICE_TABLE call for OF match tables. This allows the module to be autoloaded based on devicetree information.

---
 drivers/phy/phy-exynos5-usbdrd.c |    1 +
 1 file changed, 1 insertion(+)
drivers/phy/phy-exynos5-usbdrd.c +1 -0
index b05302b..392101c 100644
@@ -542,6 +542,7 @@ static const struct of_device_id exynos5_usbdrd_phy_of_match[] = {
 	},
 	{ },
 };
+MODULE_DEVICE_TABLE(of, exynos5_usbdrd_phy_of_match);
 
 static int exynos5_usbdrd_phy_probe(struct platform_device *pdev)
 {
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH 4/5 MAINTAINERS: add entry for the Samsung USB2 PHY driver

In reply to Kishon Vijay Abraham I

From: Kamil Debski <[email protected]>

Add MAINTAINERS entry for the Samsung USB2 PHY driver.

---
 MAINTAINERS |   13 +++++++++++++
 1 file changed, 13 insertions(+)
MAINTAINERS +13 -0
index f01f54f2..a12a126 100644
@@ -7895,6 +7895,19 @@ S:	Supported
 L:	[email protected]
 F:	drivers/net/ethernet/samsung/sxgbe/
 
+SAMSUNG USB2 PHY DRIVER
+M:	Kamil Debski <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	Documentation/devicetree/bindings/phy/samsung-phy.txt
+F:	Documentation/phy/samsung-usb2.txt
+F:	drivers/phy/phy-exynos4210-usb2.c
+F:	drivers/phy/phy-exynos4x12-usb2.c
+F:	drivers/phy/phy-exynos5250-usb2.c
+F:	drivers/phy/phy-s5pv210-usb2.c
+F:	drivers/phy/phy-samsung-usb2.c
+F:	drivers/phy/phy-samsung-usb2.h
+
 SERIAL DRIVERS
 M:	Greg Kroah-Hartman <[email protected]>
 L:	[email protected]
Signature · 1 line
1.7.9.5
#5 lore raw

PATCH 5/5 phy: miphy365x: Select GENERIC_PHY instead of depending on it

In reply to Kishon Vijay Abraham I

From: Lee Jones <[email protected]>

Enabling GENERIC_PHY in the shared (by most ARM sub-architectures) defconfig multi_v7_defconfig is prohibited. Instead, we'll enable it from the Kconfig whenever PHY_MIPHY365X is enabled.

---
 drivers/phy/Kconfig |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/Kconfig +1 -1
index 0dd7427..4ff8cbb 100644
@@ -41,9 +41,9 @@ config PHY_MVEBU_SATA
 config PHY_MIPHY365X
 	tristate "STMicroelectronics MIPHY365X PHY driver for STiH41x series"
 	depends on ARCH_STI
-	depends on GENERIC_PHY
 	depends on HAS_IOMEM
 	depends on OF
+	select GENERIC_PHY
 	help
 	  Enable this to support the miphy transceiver (for SATA/PCIE)
 	  that is part of STMicroelectronics STiH41x SoC series.
Signature · 1 line
1.7.9.5
#6 lore raw
In reply to Kishon Vijay Abraham I

Hi Greg,

Quoted 7 lines · Kishon Vijay Abraham I

Hi Greg,

Please find the pull request for this -rc cycle. It consistes of a regression fix to runtime PM on OMAP (cc'ed stable) and few other minor fixes.

Please consider merging it in this -rc cycle.
Let me know If I have to make any changes.

Can we have this merged in this -rc cycle?

Thanks
Kishon

Quoted 42 lines

Cheers
Kishon

The following changes since commit 451fd72219dd6f3355e2d036c598544c760ee532:

Merge tag 'pwm/for-3.17-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm (2014-08-22 14:50:21 -0700)

are available in the git repository at:

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

for you to fetch changes up to fbb1a770039d3900f5130bab949b757f6f7fb373:

phy: miphy365x: Select GENERIC_PHY instead of depending on it (2014-08-28 11:17:43 +0530)

----------------------------------------------------------------
for_3.17-rc

Fix regressions to runtime PM on OMAP and other minor fixes.

----------------------------------------------------------------
Kamil Debski (1):
MAINTAINERS: add entry for the Samsung USB2 PHY driver

Lee Jones (1):
phy: miphy365x: Select GENERIC_PHY instead of depending on it

Sjoerd Simons (1):
phy: exynos5-usbdrd: Add MODULE_DEVICE_TABLE entry

Tony Lindgren (2):
usb: phy: twl4030-usb: Fix regressions to runtime PM on omaps
usb: phy: twl4030-usb: Fix lost interrupts after ID pin goes down

 MAINTAINERS                      |   13 ++++
 drivers/phy/Kconfig              |    2 +-
 drivers/phy/phy-exynos5-usbdrd.c |    1 +
 drivers/phy/phy-twl4030-usb.c    |  121 +++++++++++++++++++++++---------------
 4 files changed, 88 insertions(+), 49 deletions(-)
#7 lore raw
Quoted 5 lines · Kishon Vijay Abraham I

Hi Greg,

Quoted 2 lines · Kishon Vijay Abraham I

Hi Greg,

Quoted 7 lines
Quoted 5 lines

Please find the pull request for this -rc cycle. It consistes of a regression fix to runtime PM on OMAP (cc'ed stable) and few other minor fixes.

Please consider merging it in this -rc cycle.
Let me know If I have to make any changes.

Can we have this merged in this -rc cycle?

Sorry for the delay, now merged.

greg k-h

#8 lore raw
Quoted 9 lines · Greg KH
Quoted 8 lines · Kishon Vijay Abraham I

Hi Greg,

Quoted 5 lines · Kishon Vijay Abraham I

Hi Greg,

Please find the pull request for this -rc cycle. It consistes of a regression fix to runtime PM on OMAP (cc'ed stable) and few other minor fixes.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Please consider merging it in this -rc cycle.
Let me know If I have to make any changes.

Can we have this merged in this -rc cycle?

Sorry for the delay, now merged.

Thanks Greg :-)

-Kishon