lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-id: <1421419194-1849-3-git-send-email-p.osmialowsk@samsung.com>
Date:	Fri, 16 Jan 2015 15:39:54 +0100
From:	Paul Osmialowski <p.osmialowsk@...sung.com>
To:	Wolfram Sang <wsa@...-dreams.de>, Jonathan Corbet <corbet@....net>,
	Mark Brown <broonie@...nel.org>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Kukjin Kim <kgene@...nel.org>, linux-i2c@...r.kernel.org,
	linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
	linux-samsung-soc@...r.kernel.org
Cc:	Paul Osmialowski <p.osmialowsk@...sung.com>
Subject: [RFC 3/3] i2c: s3c2410: Adopt i2c-s3c2410 driver for new enhancement
 of i2c API

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@...sung.com>
---
 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@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ