From: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
To: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-samsung-soc@vger.kernel.org
Cc: w.sang@pengutronix.de, khali@linux-fr.org, ben-linux@fluff.org,
grant.likely@secretlab.ca, devicetree-discuss@lists.ozlabs.org,
sjg@chromium.org, grundler@chromium.org, naveen@chromium.org,
broonie@opensource.wolfsonmicro.com
Subject: [PATCH 2/2] i2c-s3c2410: Add GPIO based bus arbitration functionality
Date: Fri, 14 Dec 2012 11:20:54 +0530 [thread overview]
Message-ID: <1355464254-12768-3-git-send-email-ch.naveen@samsung.com> (raw)
In-Reply-To: <1355464254-12768-1-git-send-email-ch.naveen@samsung.com>
Makes use of the generic fucntions in of_i2c.c to parse arbitration
timing information and GPIOs for arbitration.
Also uses devm_gpio_request() instead of gpio_request() and
removes the gpio_free() calls
Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
---
drivers/i2c/busses/i2c-s3c2410.c | 79 +++++++++++++++++++++++---------------
1 file changed, 47 insertions(+), 32 deletions(-)
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index e93e7d6..d055cf8 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -855,54 +855,61 @@ static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c)
#endif
#ifdef CONFIG_OF
-static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c)
+static int of_i2c_parse_gpio(struct device *dev, const char *name,
+ int gpios[], size_t count, bool required)
{
- int idx, gpio, ret;
-
- if (i2c->quirks & QUIRK_NO_GPIO)
- return 0;
+ struct device_node *dn = dev->of_node;
+ int idx, gpio;
- for (idx = 0; idx < 2; idx++) {
- gpio = of_get_gpio(i2c->dev->of_node, idx);
+ for (idx = 0; idx < count; idx++) {
+ gpio = of_get_named_gpio(dn, name, idx);
if (!gpio_is_valid(gpio)) {
- dev_err(i2c->dev, "invalid gpio[%d]: %d\n", idx, gpio);
- goto free_gpio;
+ dev_dbg(dev, "invalid gpio[%d]: %d\n", idx, gpio);
+ if (idx || required) {
+ dev_err(dev, "invalid gpio[%d]: %d\n",
+ idx, gpio);
+ }
+ return -EINVAL;
}
- i2c->gpios[idx] = gpio;
+ gpios[idx] = gpio;
- ret = gpio_request(gpio, "i2c-bus");
- if (ret) {
- dev_err(i2c->dev, "gpio [%d] request failed\n", gpio);
- goto free_gpio;
+ if (devm_gpio_request(dev, gpio, "i2c-bus")) {
+ dev_err(dev, "gpio [%d] request failed\n", gpio);
+ return -EINVAL;
}
}
return 0;
-
-free_gpio:
- while (--idx >= 0)
- gpio_free(i2c->gpios[idx]);
- return -EINVAL;
}
-static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c)
+static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c)
{
- unsigned int idx;
+ int ret = 0;
if (i2c->quirks & QUIRK_NO_GPIO)
- return;
+ goto out;
+
+ if (of_i2c_parse_gpio(i2c->dev, "gpios", i2c->gpios, 2, true)) {
+ ret = -EINVAL;
+ goto out;
+ }
- for (idx = 0; idx < 2; idx++)
- gpio_free(i2c->gpios[idx]);
+ if (i2c->adap.gpio_arbit) {
+ if (!of_i2c_parse_gpio(i2c->dev, "bus-arbitration-gpios",
+ i2c->adap.gpio_arbit->arb_gpios, I2C_ARB_GPIO_COUNT,
+ false)) {
+ dev_warn(i2c->dev, "GPIO-based arbitration enabled");
+ } else
+ ret = -EINVAL;
+ }
+
+ out:
+ return ret;
}
#else
static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c)
{
return 0;
}
-
-static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c)
-{
-}
#endif
/* s3c24xx_i2c_init
@@ -981,6 +988,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
{
struct s3c24xx_i2c *i2c;
struct s3c2410_platform_i2c *pdata = NULL;
+ struct i2c_gpio_arbit *arbit = NULL;
struct resource *res;
int ret;
@@ -1004,11 +1012,21 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
goto err_noclk;
}
+ arbit = devm_kzalloc(&pdev->dev, sizeof(*arbit), GFP_KERNEL);
+ if (!arbit) {
+ ret = -ENOMEM;
+ goto err_noclk;
+ }
+
i2c->quirks = s3c24xx_get_device_quirks(pdev);
if (pdata)
memcpy(i2c->pdata, pdata, sizeof(*pdata));
- else
+ else {
s3c24xx_i2c_parse_dt(pdev->dev.of_node, i2c);
+ /* Arbitration parameters */
+ i2c->adap.gpio_arbit = of_get_arbitrator_info(
+ pdev->dev.of_node, arbit);
+ }
strlcpy(i2c->adap.name, "s3c2410-i2c", sizeof(i2c->adap.name));
i2c->adap.owner = THIS_MODULE;
@@ -1158,9 +1176,6 @@ static int s3c24xx_i2c_remove(struct platform_device *pdev)
clk_disable_unprepare(i2c->clk);
clk_put(i2c->clk);
- if (pdev->dev.of_node && IS_ERR(i2c->pctrl))
- s3c24xx_i2c_dt_gpio_free(i2c);
-
return 0;
}
--
1.7.9.5
prev parent reply other threads:[~2012-12-14 5:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-14 5:50 [PATCH 0/2] i2c: Implement generic gpio based bus arbitration Naveen Krishna Chatradhi
[not found] ` <1355464254-12768-1-git-send-email-ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-12-14 5:50 ` [PATCH 1/2] i2c-core: Add gpio based bus arbitration implementation Naveen Krishna Chatradhi
2012-12-14 16:06 ` Stephen Warren
2012-12-15 14:21 ` Mark Brown
[not found] ` <20121215142135.GB22033-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2013-01-24 11:13 ` Wolfram Sang
[not found] ` <20130124111329.GC12933-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-01-24 11:18 ` Mark Brown
[not found] ` <20130124111845.GO4955-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2013-01-24 11:39 ` Wolfram Sang
[not found] ` <20130124113948.GD12933-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-01-26 5:00 ` Mark Brown
[not found] ` <1355464254-12768-2-git-send-email-ch.naveen-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-12-19 12:32 ` Grant Likely
2012-12-19 17:14 ` Mark Brown
2012-12-20 0:17 ` Simon Glass
[not found] ` <CAPnjgZ30MQS1OT3GOFLG9HntoD8NrzNw6bB_d1fiJEgHcMDGUA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-12-20 0:58 ` Grant Likely
[not found] ` <20121219171423.GW4985-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-12-20 0:53 ` Grant Likely
2012-12-14 5:50 ` Naveen Krishna Chatradhi [this message]
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=1355464254-12768-3-git-send-email-ch.naveen@samsung.com \
--to=ch.naveen@samsung.com \
--cc=ben-linux@fluff.org \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=grant.likely@secretlab.ca \
--cc=grundler@chromium.org \
--cc=khali@linux-fr.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=naveen@chromium.org \
--cc=sjg@chromium.org \
--cc=w.sang@pengutronix.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).