[PATCH] i2c: s3c2410: Fix code to free gpios

2012-11-19 Thread Abhilash Kesavan
Store the requested gpios so that they can be freed on error/removal.

Signed-off-by: Abhilash Kesavan 
---
 drivers/i2c/busses/i2c-s3c2410.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index dea4cb2..5d5e9cb 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -856,6 +856,7 @@ static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c 
*i2c)
dev_err(i2c->dev, "invalid gpio[%d]: %d\n", idx, gpio);
goto free_gpio;
}
+   i2c->gpios[idx] = gpio;
 
ret = gpio_request(gpio, "i2c-bus");
if (ret) {
-- 
1.6.6.1

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3] i2c: s3c2410: Add fix for i2c suspend/resume

2012-11-19 Thread Abhilash Kesavan
The I2C driver makes a gpio_request during initialization. This request
happens again on resume and fails due to the earlier successful request.
Re-factor the code to only initialize the gpios during probe.

Errors on resume without this:
[   16.02] s3c-i2c s3c2440-i2c.0: gpio [42] request failed
[   16.02] s3c-i2c s3c2440-i2c.1: gpio [44] request failed
[   16.02] s3c-i2c s3c2440-i2c.2: gpio [6] request failed

Signed-off-by: Abhilash Kesavan 
---
Changes from v1:
Refactor code to initialize gpios only during probe
Changes from v2:
Split an unrelated bug fix
Removed the new function added in v1

 drivers/i2c/busses/i2c-s3c2410.c |   16 +---
 1 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 081e261..dea4cb2 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -907,13 +907,6 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
 
pdata = i2c->pdata;
 
-   /* inititalise the gpio */
-
-   if (pdata->cfg_gpio)
-   pdata->cfg_gpio(to_platform_device(i2c->dev));
-   else if (IS_ERR(i2c->pctrl) && s3c24xx_i2c_parse_dt_gpio(i2c))
-   return -EINVAL;
-
/* write slave address */
 
writeb(pdata->slave_addr, i2c->regs + S3C2410_IICADD);
@@ -1054,6 +1047,15 @@ static int s3c24xx_i2c_probe(struct platform_device 
*pdev)
 
i2c->pctrl = devm_pinctrl_get_select_default(i2c->dev);
 
+   /* inititalise the i2c gpio lines */
+
+   if (i2c->pdata->cfg_gpio) {
+   i2c->pdata->cfg_gpio(to_platform_device(i2c->dev));
+   } else if (IS_ERR(i2c->pctrl) && s3c24xx_i2c_parse_dt_gpio(i2c)) {
+   ret = -EINVAL;
+   goto err_clk;
+   }
+
/* initialise the i2c controller */
 
ret = s3c24xx_i2c_init(i2c);
-- 
1.6.6.1

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] i2c: s3c2410: Add fix for i2c suspend/resume

2012-11-19 Thread Abhilash Kesavan
The I2C driver makes a gpio_request during initialization. This request
happens again on resume and fails due to the earlier successful request.
Re-factor the code to only initialize the gpios during probe.

Errors on resume without this:
[   16.02] s3c-i2c s3c2440-i2c.0: gpio [42] request failed
[   16.02] s3c-i2c s3c2440-i2c.1: gpio [44] request failed
[   16.02] s3c-i2c s3c2440-i2c.2: gpio [6] request failed

Signed-off-by: Abhilash Kesavan 
---
Changes from v1:
Refactor code to initialize gpios only during probe

 drivers/i2c/busses/i2c-s3c2410.c |   26 +++---
 1 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 081e261..0ca321b 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -856,6 +856,7 @@ static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c 
*i2c)
dev_err(i2c->dev, "invalid gpio[%d]: %d\n", idx, gpio);
goto free_gpio;
}
+   i2c->gpios[idx] = gpio;
 
ret = gpio_request(gpio, "i2c-bus");
if (ret) {
@@ -892,6 +893,18 @@ static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c 
*i2c)
 }
 #endif
 
+static int s3c24xx_i2c_cfg_gpio(struct s3c24xx_i2c *i2c)
+{
+   struct s3c2410_platform_i2c *pdata = i2c->pdata;
+
+   if (pdata->cfg_gpio)
+   pdata->cfg_gpio(to_platform_device(i2c->dev));
+   else if (IS_ERR(i2c->pctrl) && s3c24xx_i2c_parse_dt_gpio(i2c))
+   return -EINVAL;
+
+   return 0;
+}
+
 /* s3c24xx_i2c_init
  *
  * initialise the controller, set the IO lines and frequency
@@ -907,13 +920,6 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
 
pdata = i2c->pdata;
 
-   /* inititalise the gpio */
-
-   if (pdata->cfg_gpio)
-   pdata->cfg_gpio(to_platform_device(i2c->dev));
-   else if (IS_ERR(i2c->pctrl) && s3c24xx_i2c_parse_dt_gpio(i2c))
-   return -EINVAL;
-
/* write slave address */
 
writeb(pdata->slave_addr, i2c->regs + S3C2410_IICADD);
@@ -1054,6 +1060,12 @@ static int s3c24xx_i2c_probe(struct platform_device 
*pdev)
 
i2c->pctrl = devm_pinctrl_get_select_default(i2c->dev);
 
+   /* inititalise the i2c gpio lines */
+
+   ret = s3c24xx_i2c_cfg_gpio(i2c);
+   if (ret != 0)
+   goto err_clk;
+
/* initialise the i2c controller */
 
ret = s3c24xx_i2c_init(i2c);
-- 
1.6.6.1

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] i2c: s3c2410: Add fix for i2c suspend/resume

2012-11-13 Thread Abhilash Kesavan
Hi,

Any comments on this fix ?

Abhilash
On Tue, Nov 6, 2012 at 1:08 PM, Abhilash Kesavan
 wrote:
> Hi Shubhrajyoti,
>
> On Tue, Nov 6, 2012 at 11:42 AM, Shubhrajyoti Datta
>  wrote:
>> On Tue, Nov 6, 2012 at 11:40 AM, Abhilash Kesavan  
>> wrote:
>>> The I2C driver makes a gpio_request during initialization. This request
>>> happens again on resume
>>
>> Do you know why request and free is needed across the suspend and resume?
>
> Other than the way the code is structured where the same
> initialization code is called at
> probe and resume, there isn't a need for the request/free.
>
> Abhilash
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] i2c: s3c2410: Add fix for i2c suspend/resume

2012-11-05 Thread Abhilash Kesavan
Hi Shubhrajyoti,

On Tue, Nov 6, 2012 at 11:42 AM, Shubhrajyoti Datta
 wrote:
> On Tue, Nov 6, 2012 at 11:40 AM, Abhilash Kesavan  
> wrote:
>> The I2C driver makes a gpio_request during initialization. This request
>> happens again on resume
>
> Do you know why request and free is needed across the suspend and resume?

Other than the way the code is structured where the same
initialization code is called at
probe and resume, there isn't a need for the request/free.

Abhilash
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] i2c: s3c2410: Add fix for i2c suspend/resume

2012-11-05 Thread Abhilash Kesavan
The I2C driver makes a gpio_request during initialization. This request
happens again on resume and fails due to the earlier successful request.
Modify the suspend code to free the earlier requested gpios.

Errors on resume without this:
[   16.02] s3c-i2c s3c2440-i2c.0: gpio [42] request failed
[   16.02] s3c-i2c s3c2440-i2c.1: gpio [44] request failed
[   16.02] s3c-i2c s3c2440-i2c.2: gpio [6] request failed

Signed-off-by: Abhilash Kesavan 
---
 drivers/i2c/busses/i2c-s3c2410.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 3e0335f..9bec49e 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -806,6 +806,7 @@ static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c 
*i2c)
dev_err(i2c->dev, "invalid gpio[%d]: %d\n", idx, gpio);
goto free_gpio;
}
+   i2c->gpios[idx] = gpio;
 
ret = gpio_request(gpio, "i2c-bus");
if (ret) {
@@ -1125,6 +1126,7 @@ static int s3c24xx_i2c_suspend_noirq(struct device *dev)
struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
 
i2c->suspended = 1;
+   s3c24xx_i2c_dt_gpio_free(i2c);
 
return 0;
 }
-- 
1.6.6.1

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html