]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
i2c-mpc: avoid I2C abnormal after resuming from deep sleep
authorZhao Chenhui <chenhui.zhao@freescale.com>
Thu, 19 Apr 2012 09:51:34 +0000 (17:51 +0800)
committerWolfram Sang <w.sang@pengutronix.de>
Sat, 12 May 2012 12:28:12 +0000 (14:28 +0200)
When entering deep sleep, the value in the registers I2CFDR and
I2CDFSRR are lost. This causes I2C access to fail after resuming.

Add suspend/resume routines to save/restore the registers
I2CFDR and I2CDFSRR.

Signed-off-by: Zhao Chenhui <chenhui.zhao@freescale.com>
Signed-off-by: Li Yang <leoli@freescale.com>
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
drivers/i2c/busses/i2c-mpc.c

index 206caacd30d7fb52d65f59207bc82a4f7fc3912b..b76731edbf106cfbe505173a677da38df02c146b 100644 (file)
@@ -64,6 +64,9 @@ struct mpc_i2c {
        struct i2c_adapter adap;
        int irq;
        u32 real_clk;
+#ifdef CONFIG_PM
+       u8 fdr, dfsrr;
+#endif
 };
 
 struct mpc_i2c_divider {
@@ -703,6 +706,30 @@ static int __devexit fsl_i2c_remove(struct platform_device *op)
        return 0;
 };
 
+#ifdef CONFIG_PM
+static int mpc_i2c_suspend(struct device *dev)
+{
+       struct mpc_i2c *i2c = dev_get_drvdata(dev);
+
+       i2c->fdr = readb(i2c->base + MPC_I2C_FDR);
+       i2c->dfsrr = readb(i2c->base + MPC_I2C_DFSRR);
+
+       return 0;
+}
+
+static int mpc_i2c_resume(struct device *dev)
+{
+       struct mpc_i2c *i2c = dev_get_drvdata(dev);
+
+       writeb(i2c->fdr, i2c->base + MPC_I2C_FDR);
+       writeb(i2c->dfsrr, i2c->base + MPC_I2C_DFSRR);
+
+       return 0;
+}
+
+SIMPLE_DEV_PM_OPS(mpc_i2c_pm_ops, mpc_i2c_suspend, mpc_i2c_resume);
+#endif
+
 static struct mpc_i2c_data mpc_i2c_data_512x __devinitdata = {
        .setup = mpc_i2c_setup_512x,
 };
@@ -747,6 +774,9 @@ static struct platform_driver mpc_i2c_driver = {
                .owner = THIS_MODULE,
                .name = DRV_NAME,
                .of_match_table = mpc_i2c_of_match,
+#ifdef CONFIG_PM
+               .pm = &mpc_i2c_pm_ops,
+#endif
        },
 };