Skip to contentSkip to conversation

ARM: OMAP: omap_device: keep track of driver bound status

PATCH Superseded Kevin Hilman 2 participants 5 messages Jul 10, 2012 – Aug 7, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 ARM: OMAP: omap_device: keep track of driver bound status

Use the bus notifier to keep track of driver bound status by adding a new internal field to struct omap_device: _driver_staus.

This will be useful for follow-up patches which need to know whether or not a driver is bound in order to make intelligent omap_device enable/idle decisions.

---
 arch/arm/plat-omap/include/plat/omap_device.h |    2 ++
 arch/arm/plat-omap/omap_device.c              |   14 +++++++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)
arch/arm/plat-omap/include/plat/omap_device.h +2 -0
index 4327b2c..e0486cb 100644
@@ -60,6 +60,7 @@ extern struct dev_pm_domain omap_device_pm_domain;
  * @_dev_wakeup_lat_limit: dev wakeup latency limit in nsec - set by OMAP PM
  * @_state: one of OMAP_DEVICE_STATE_* (see above)
  * @flags: device flags
+ * @_driver_status: one of BUS_NOTIFY_*_DRIVER from <linux/device.h>
  *
  * Integrates omap_hwmod data into Linux platform_device.
  *
@@ -78,6 +79,7 @@ struct omap_device {
 	u8				hwmods_cnt;
 	u8				_state;
 	u8                              flags;
+	u8				_driver_status;
 };
 
 /* Device driver interface (call via platform_data fn ptrs) */
arch/arm/plat-omap/omap_device.c +9 -5
index c490240..1d1b5ff 100644
@@ -385,17 +385,21 @@ static int _omap_device_notifier_call(struct notifier_block *nb,
 				      unsigned long event, void *dev)
 {
 	struct platform_device *pdev = to_platform_device(dev);
+	struct omap_device *od;
 
 	switch (event) {
-	case BUS_NOTIFY_ADD_DEVICE:
-		if (pdev->dev.of_node)
-			omap_device_build_from_dt(pdev);
-		break;
-
 	case BUS_NOTIFY_DEL_DEVICE:
 		if (pdev->archdata.od)
 			omap_device_delete(pdev->archdata.od);
 		break;
+	case BUS_NOTIFY_ADD_DEVICE:
+		if (pdev->dev.of_node)
+			omap_device_build_from_dt(pdev);
+		/* fall through */
+	default:
+		od = to_omap_device(pdev);
+		if (od)
+			od->_driver_status = event;
 	}
 
 	return NOTIFY_DONE;
Signature · 1 line
1.7.9.2
#1 lore raw

PATCH 2/3 ARM: OMAP: omap_device: don't attempt late suspend if no driver bound

Currently, the omap_device PM domain layer uses the late suspend and early resume callbacks to ensure devices are in their low power states.

However, this is attempted even in cases where a driver probe has failed. If a driver's ->probe() method fails, the driver is likely in a state where it is not expecting its runtime PM callbacks to be called, yet currently the omap_device PM domain code attempts to call the drivers callbacks.

To fix, use the omap_device driver_status field to check whether a driver is bound to the omap_device before attempting to trigger driver callbacks.

---
 arch/arm/plat-omap/omap_device.c |    4 ++++
 1 file changed, 4 insertions(+)
arch/arm/plat-omap/omap_device.c +4 -0
index 1d1b5ff..150112e 100644
@@ -756,6 +756,10 @@ static int _od_suspend_noirq(struct device *dev)
 	struct omap_device *od = to_omap_device(pdev);
 	int ret;
 
+	/* Don't attempt late suspend on a driver that is not bound */
+	if (od->_driver_status != BUS_NOTIFY_BOUND_DRIVER)
+		return 0;
+
 	ret = pm_generic_suspend_noirq(dev);
 
 	if (!ret && !pm_runtime_status_suspended(dev)) {
Signature · 1 line
1.7.9.2
#2 lore raw

PATCH 3/3 ARM: OMAP: omap_device: idle devices with no driver bound

In reply to Kevin Hilman

Under some circumstances, drivers may leave an omap_device enabled due to driver programming errors, or due to a failure in the drivers probe method.

Using the recently added omap_device driver_status field, we can detect conditions where an omap_device is enabled but has no driver bound and then ensure that the device is properly idled until it can be probed again.

The goal of this feature is not only to detect and warn on these error conditions, but also to ensure that devices are properly put in low-power states so they do not prevent SoC-wide low-power states.

---
 arch/arm/plat-omap/omap_device.c |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
arch/arm/plat-omap/omap_device.c +30 -0
index 150112e..28ab6af 100644
@@ -1133,3 +1133,33 @@ static int __init omap_device_init(void)
 	return 0;
 }
 core_initcall(omap_device_init);
+
+static int __init omap_device_late_idle(struct device *dev, void *data)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct omap_device *od = to_omap_device(pdev);
+	
+	if (!od)
+		return 0;
+
+	/* 
+	 * If omap_device state is enabled, but has no driver bound,
+	 * idle it.
+	 */
+	if (od->_driver_status != BUS_NOTIFY_BOUND_DRIVER) {
+		if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
+			dev_warn(dev, "%s: enabled but no driver.  Idling\n",
+				__func__);
+			omap_device_idle(pdev);
+		}
+	}
+
+	return 0; 
+}
+
+static int __init omap_device_late_init(void)
+{
+	bus_for_each_dev(&platform_bus_type, NULL, NULL, omap_device_late_idle);
+	return 0;
+}
+late_initcall(omap_device_late_init);
Signature · 1 line
1.7.9.2
#3 lore raw

PATCH 1/3 ARM: OMAP: omap_device: keep track of driver bound status

In reply to Kevin Hilman

Hi Kevin

a couple of minor comments

Quoted 2 lines · Kevin Hilman

Use the bus notifier to keep track of driver bound status by adding a new internal field to struct omap_device: _driver_staus.

"_driver_status"

Quoted 49 lines

This will be useful for follow-up patches which need to know whether or not a driver is bound in order to make intelligent omap_device enable/idle decisions.

---
 arch/arm/plat-omap/include/plat/omap_device.h |    2 ++
 arch/arm/plat-omap/omap_device.c              |   14 +++++++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)
arch/arm/plat-omap/include/plat/omap_device.h +2 -0
index 4327b2c..e0486cb 100644
@@ -60,6 +60,7 @@ extern struct dev_pm_domain omap_device_pm_domain;
  * @_dev_wakeup_lat_limit: dev wakeup latency limit in nsec - set by OMAP PM
  * @_state: one of OMAP_DEVICE_STATE_* (see above)
  * @flags: device flags
+ * @_driver_status: one of BUS_NOTIFY_*_DRIVER from <linux/device.h>
  *
  * Integrates omap_hwmod data into Linux platform_device.
  *
@@ -78,6 +79,7 @@ struct omap_device {
 	u8				hwmods_cnt;
 	u8				_state;
 	u8                              flags;
+	u8				_driver_status;
 };
 
 /* Device driver interface (call via platform_data fn ptrs) */
arch/arm/plat-omap/omap_device.c +1 -5
index c490240..1d1b5ff 100644
@@ -385,17 +385,21 @@ static int _omap_device_notifier_call(struct notifier_block *nb,
 				      unsigned long event, void *dev)
 {
 	struct platform_device *pdev = to_platform_device(dev);
+	struct omap_device *od;
 
 	switch (event) {
-	case BUS_NOTIFY_ADD_DEVICE:
-		if (pdev->dev.of_node)
-			omap_device_build_from_dt(pdev);
-		break;
-
 	case BUS_NOTIFY_DEL_DEVICE:
 		if (pdev->archdata.od)

arch/arm/plat-omap/omap_device.c static int _omap_device_notifier_call(struct notifier_block *nb, · line 402

Quoted 10 lines
arch/arm/plat-omap/omap_device.c +8 -0
 			omap_device_delete(pdev->archdata.od);
 		break;
+	case BUS_NOTIFY_ADD_DEVICE:
+		if (pdev->dev.of_node)
+			omap_device_build_from_dt(pdev);
+		/* fall through */
+	default:
+		od = to_omap_device(pdev);
+		if (od)
+			od->_driver_status = event;

_driver_status is a u8, but event is an unsigned long. Might be worth adding a WARN() to complain if event is greater than (2^8)-1.

Quoted 6 lines
arch/arm/plat-omap/omap_device.c +0 -0
 	}
 
 	return NOTIFY_DONE;
Signature · 1 line
1.7.9.2

- Paul

#4 lore raw

PATCH 1/3 ARM: OMAP: omap_device: keep track of driver bound status

Quoted 65 lines · Paul Walmsley

Hi Kevin

a couple of minor comments

Quoted 2 lines · Kevin Hilman

Use the bus notifier to keep track of driver bound status by adding a new internal field to struct omap_device: _driver_staus.

"_driver_status"

Quoted 54 lines

This will be useful for follow-up patches which need to know whether or not a driver is bound in order to make intelligent omap_device enable/idle decisions.

---
 arch/arm/plat-omap/include/plat/omap_device.h |    2 ++
 arch/arm/plat-omap/omap_device.c              |   14 +++++++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)
arch/arm/plat-omap/include/plat/omap_device.h +2 -0
index 4327b2c..e0486cb 100644
@@ -60,6 +60,7 @@ extern struct dev_pm_domain omap_device_pm_domain;
  * @_dev_wakeup_lat_limit: dev wakeup latency limit in nsec - set by OMAP PM
  * @_state: one of OMAP_DEVICE_STATE_* (see above)
  * @flags: device flags
+ * @_driver_status: one of BUS_NOTIFY_*_DRIVER from <linux/device.h>
  *
  * Integrates omap_hwmod data into Linux platform_device.
  *
@@ -78,6 +79,7 @@ struct omap_device {
 	u8				hwmods_cnt;
 	u8				_state;
 	u8                              flags;
+	u8				_driver_status;
 };
 
 /* Device driver interface (call via platform_data fn ptrs) */
arch/arm/plat-omap/omap_device.c +4 -5
index c490240..1d1b5ff 100644
@@ -385,17 +385,21 @@ static int _omap_device_notifier_call(struct notifier_block *nb,
 				      unsigned long event, void *dev)
 {
 	struct platform_device *pdev = to_platform_device(dev);
+	struct omap_device *od;
 
 	switch (event) {
-	case BUS_NOTIFY_ADD_DEVICE:
-		if (pdev->dev.of_node)
-			omap_device_build_from_dt(pdev);
-		break;
-
 	case BUS_NOTIFY_DEL_DEVICE:
 		if (pdev->archdata.od)
 			omap_device_delete(pdev->archdata.od);
 		break;
+	case BUS_NOTIFY_ADD_DEVICE:
+		if (pdev->dev.of_node)
+			omap_device_build_from_dt(pdev);
Quoted 9 lines

arch/arm/plat-omap/omap_device.c static int _omap_device_notifier_call(struct notifier_block *nb, · line 402

Quoted 5 lines
arch/arm/plat-omap/omap_device.c +5 -0
+		/* fall through */
+	default:
+		od = to_omap_device(pdev);
+		if (od)
+			od->_driver_status = event;

_driver_status is a u8, but event is an unsigned long. Might be worth adding a WARN() to complain if event is greater than (2^8)-1.

It's probably more future proof if I just make _driver_status an unsigned long, in case the values of those events ever change in the driver core.

Thanks for the review,

Kevin