[RFC 3/3] i2c: s3c2410: Adopt i2c-s3c2410 driver for new enhancement of i2c API
From: Paul Osmialowski
Date: Fri Jan 16 2015 - 09:41:36 EST
This adopts i2c-s3c2410 driver for new enhancement of i2c API that
exposes preparation and unpreparation stages of i2c transfer.
Signed-off-by: Paul Osmialowski <p.osmialowsk@xxxxxxxxxxx>
---
drivers/i2c/busses/i2c-s3c2410.c | 69 ++++++++++++++++++++++++++++++++++++----
1 file changed, 63 insertions(+), 6 deletions(-)
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index bff20a5..4af8a9c 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -130,6 +130,8 @@ struct s3c24xx_i2c {
#endif
struct regmap *sysreg;
unsigned int sys_i2c_cfg;
+
+ int xfer_prepared;
};
static struct platform_device_id s3c24xx_driver_ids[] = {
@@ -771,6 +773,58 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c,
return ret;
}
+/* s3c24xx_i2c_prepare_xfer
+ *
+ * prepare for transferring message across the i2c bus (may sleep)
+ *
+ * returns 0 on success
+ */
+
+static int s3c24xx_i2c_prepare_xfer(struct i2c_adapter *adap)
+{
+ struct s3c24xx_i2c *i2c = (struct s3c24xx_i2c *)adap->algo_data;
+
+ if (i2c->xfer_prepared == 0) {
+ int ret;
+
+ pm_runtime_get_sync(&adap->dev);
+
+ ret = clk_prepare_enable(i2c->clk);
+ if (ret) {
+ pm_runtime_put(&adap->dev);
+ return ret;
+ }
+
+ }
+
+ i2c->xfer_prepared++;
+
+ return 0;
+}
+
+/* s3c24xx_i2c_unprepare_xfer
+ *
+ * unprepare after transferring message across the i2c bus (may sleep)
+ */
+
+static void s3c24xx_i2c_unprepare_xfer(struct i2c_adapter *adap)
+{
+ struct s3c24xx_i2c *i2c = (struct s3c24xx_i2c *)adap->algo_data;
+
+ if (i2c->xfer_prepared == 1) {
+ clk_disable_unprepare(i2c->clk);
+ pm_runtime_put(&adap->dev);
+ }
+
+ i2c->xfer_prepared--;
+
+ if (unlikely(i2c->xfer_prepared < 0)) {
+ pr_err("%s: i2c->xfer_prepared = %d < 0\n",
+ __func__, i2c->xfer_prepared);
+ i2c->xfer_prepared = 0;
+ }
+}
+
/* s3c24xx_i2c_xfer
*
* first port of call from the i2c bus code when an message needs
@@ -784,16 +838,16 @@ static int s3c24xx_i2c_xfer(struct i2c_adapter *adap,
int retry;
int ret;
- pm_runtime_get_sync(&adap->dev);
- clk_prepare_enable(i2c->clk);
+ ret = s3c24xx_i2c_prepare_xfer(adap);
+ if (ret)
+ return ret;
for (retry = 0; retry < adap->retries; retry++) {
ret = s3c24xx_i2c_doxfer(i2c, msgs, num);
if (ret != -EAGAIN) {
- clk_disable_unprepare(i2c->clk);
- pm_runtime_put(&adap->dev);
+ s3c24xx_i2c_unprepare_xfer(adap);
return ret;
}
@@ -802,8 +856,8 @@ static int s3c24xx_i2c_xfer(struct i2c_adapter *adap,
udelay(100);
}
- clk_disable_unprepare(i2c->clk);
- pm_runtime_put(&adap->dev);
+ s3c24xx_i2c_unprepare_xfer(adap);
+
return -EREMOTEIO;
}
@@ -818,6 +872,8 @@ static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
static const struct i2c_algorithm s3c24xx_i2c_algorithm = {
.master_xfer = s3c24xx_i2c_xfer,
+ .master_prepare_xfer = s3c24xx_i2c_prepare_xfer,
+ .master_unprepare_xfer = s3c24xx_i2c_unprepare_xfer,
.functionality = s3c24xx_i2c_func,
};
@@ -1152,6 +1208,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
i2c->adap.retries = 2;
i2c->adap.class = I2C_CLASS_DEPRECATED;
i2c->tx_setup = 50;
+ i2c->xfer_prepared = 0;
init_waitqueue_head(&i2c->wait);
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/