linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Osmialowski <p.osmialowsk@samsung.com>
To: Wolfram Sang <wsa@the-dreams.de>,
	Jonathan Corbet <corbet@lwn.net>, Mark Brown <broonie@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Kukjin Kim <kgene@kernel.org>,
	linux-i2c@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org
Cc: Paul Osmialowski <p.osmialowsk@samsung.com>
Subject: [RFC 3/3] i2c: s3c2410: Adopt i2c-s3c2410 driver for new enhancement of i2c API
Date: Fri, 16 Jan 2015 15:39:54 +0100	[thread overview]
Message-ID: <1421419194-1849-3-git-send-email-p.osmialowsk@samsung.com> (raw)
In-Reply-To: <1421419194-1849-1-git-send-email-p.osmialowsk@samsung.com>

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@samsung.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

  parent reply	other threads:[~2015-01-16 14:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-16 14:39 [RFC 1/3] i2c: Enhancement of i2c API to address circular lock dependency problem Paul Osmialowski
2015-01-16 14:39 ` [RFC 2/3] regmap: Use the enhancement of i2c API to address circular " Paul Osmialowski
2015-01-16 16:23   ` Mark Brown
2015-01-16 17:36     ` Paul Osmialowski
     [not found]       ` <alpine.DEB.2.10.1501161811280.21618-rWxBz+Dn3+580y0nlK0+ubjjLBE8jN/0@public.gmane.org>
2015-01-16 18:36         ` Mark Brown
2015-01-19  9:31           ` Paul Osmialowski
2015-01-19 19:25             ` Mark Brown
2015-01-20 11:14               ` Paul Osmialowski
     [not found]                 ` <alpine.DEB.2.10.1501201214200.8428-rWxBz+Dn3+580y0nlK0+ubjjLBE8jN/0@public.gmane.org>
2015-01-27 18:12                   ` Mark Brown
2015-01-16 14:39 ` Paul Osmialowski [this message]
     [not found]   ` <1421419194-1849-3-git-send-email-p.osmialowsk-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-01-16 16:28     ` [RFC 3/3] i2c: s3c2410: Adopt i2c-s3c2410 driver for new enhancement of i2c API Mark Brown
     [not found] ` <1421419194-1849-1-git-send-email-p.osmialowsk-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-01-18  6:30   ` [RFC 1/3] i2c: Enhancement of i2c API to address circular lock dependency problem Tomasz Figa
2015-01-18 10:54     ` Krzysztof Kozlowski
2015-01-18 13:41       ` Mark Brown
2015-02-25 19:47         ` Mike Turquette

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1421419194-1849-3-git-send-email-p.osmialowsk@samsung.com \
    --to=p.osmialowsk@samsung.com \
    --cc=broonie@kernel.org \
    --cc=corbet@lwn.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=kgene@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).