i2c: tegra: Add stub runtime power management
Laxman Dewangan [Wed, 29 Aug 2012 10:11:37 +0000 (15:11 +0530)]
Add stub runtime_pm calls which go through the flow of enabling and
disabling but don't actually do anything with the device itself as
there's nothing useful we can do. This provides the core PM framework
with information about when the device is idle, enabling chip wide
power savings.
The change is based on change done by Mark Brown for s3c2410 i2c bus
driver.
----------
Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
    i2c-s3c2410: Add stub runtime power management
----------

Change-Id: Icb92129c4f79a1642b2b73d14578b05928d745a8
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/128151

drivers/i2c/busses/i2c-tegra.c

index 28896fd..b3c7a76 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/io.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
+#include <linux/pm_runtime.h>
 #include <linux/slab.h>
 #include <linux/i2c-tegra.h>
 #include <linux/of_i2c.h>
@@ -813,6 +814,7 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
        i2c_dev->msgs = msgs;
        i2c_dev->msgs_num = num;
 
+       pm_runtime_get_sync(&adap->dev);
        tegra_i2c_clock_enable(i2c_dev);
 
        for (i = 0; i < num; i++) {
@@ -829,6 +831,7 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
        }
 
        tegra_i2c_clock_disable(i2c_dev);
+       pm_runtime_put(&adap->dev);
 
        rt_mutex_unlock(&i2c_dev->dev_lock);
 
@@ -992,6 +995,7 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev)
                return ret;
        }
 
+       pm_runtime_enable(&pdev->dev);
 
        for (i = 0; i < nbus; i++) {
                struct tegra_i2c_bus *i2c_bus = &i2c_dev->busses[i];
@@ -1028,10 +1032,12 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev)
                        goto err_del_bus;
                }
                of_i2c_register_devices(&i2c_bus->adapter);
+               pm_runtime_enable(&i2c_bus->adapter.dev);
 
                i2c_dev->bus_count++;
        }
 
+
        return 0;
 
 err_del_bus:
@@ -1044,11 +1050,14 @@ static int __devexit tegra_i2c_remove(struct platform_device *pdev)
 {
        struct tegra_i2c_dev *i2c_dev = platform_get_drvdata(pdev);
 
-       while (i2c_dev->bus_count--)
+       while (i2c_dev->bus_count--) {
                i2c_del_adapter(&i2c_dev->busses[i2c_dev->bus_count].adapter);
+               pm_runtime_disable(&i2c_dev->busses[i2c_dev->bus_count].adapter.dev);
+       }
 
        if (i2c_dev->is_clkon_always)
                tegra_i2c_clock_disable(i2c_dev);
+       pm_runtime_disable(&pdev->dev);
        return 0;
 }