linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 0/4] i2c: s3c2410: Add devm_* apis and cleanup
@ 2012-11-23  8:41 Tushar Behera
  2012-11-23  8:41 ` [PATCH RESEND 1/4] i2c: s3c2410: Remove unnecessary label err_noclk Tushar Behera
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Tushar Behera @ 2012-11-23  8:41 UTC (permalink / raw)
  To: linux-kernel, linux-i2c, linux-samsung-soc; +Cc: w.sang, kgene.kim, patches

This patchset cleans up the probe function of i2c-s3c2410 driver.
These have been tested on Exynos4210 based Origen board.

Changes since V1:
  * devm_request_mem_region and devm_ioremap calls were replaced by
devm_request_and_ioremap() call.
  * All devm_* related modifications (earlier patches 2-5) were merged
to a single patch.

Tushar Behera (4):
  i2c: s3c2410: Remove unnecessary label err_noclk
  i2c: s3c2410: Convert to use devm_* APIs
  i2c: s3c2410: Move location of clk_prepare_enable() call in probe
    function
  i2c: s3c2410: Remove err_cpufreq label

 drivers/i2c/busses/i2c-s3c2410.c |   83 ++++++++++---------------------------
 1 files changed, 23 insertions(+), 60 deletions(-)

-- 
1.7.4.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH RESEND 1/4] i2c: s3c2410: Remove unnecessary label err_noclk
  2012-11-23  8:41 [PATCH V2 0/4] i2c: s3c2410: Add devm_* apis and cleanup Tushar Behera
@ 2012-11-23  8:41 ` Tushar Behera
  2012-11-23  8:41 ` [PATCH V2 2/4] i2c: s3c2410: Convert to use devm_* APIs Tushar Behera
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tushar Behera @ 2012-11-23  8:41 UTC (permalink / raw)
  To: linux-kernel, linux-i2c, linux-samsung-soc; +Cc: w.sang, kgene.kim, patches

err_noclk label redirects to a simple return statement. Move the
return statement to the caller location and remove the label.

Signed-off-by: Tushar Behera <tushar.behera@linaro.org>
---
 drivers/i2c/busses/i2c-s3c2410.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 3e0335f..7522f40 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -945,8 +945,8 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
 
 	i2c->pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
 	if (!i2c->pdata) {
-		ret = -ENOMEM;
-		goto err_noclk;
+		dev_err(&pdev->dev, "no memory for platform data\n");
+		return -ENOMEM;
 	}
 
 	i2c->quirks = s3c24xx_get_device_quirks(pdev);
@@ -971,8 +971,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
 	i2c->clk = clk_get(&pdev->dev, "i2c");
 	if (IS_ERR(i2c->clk)) {
 		dev_err(&pdev->dev, "cannot get clock\n");
-		ret = -ENOENT;
-		goto err_noclk;
+		return -ENOENT;
 	}
 
 	dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk);
@@ -1084,8 +1083,6 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
  err_clk:
 	clk_disable_unprepare(i2c->clk);
 	clk_put(i2c->clk);
-
- err_noclk:
 	return ret;
 }
 
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH V2 2/4] i2c: s3c2410: Convert to use devm_* APIs
  2012-11-23  8:41 [PATCH V2 0/4] i2c: s3c2410: Add devm_* apis and cleanup Tushar Behera
  2012-11-23  8:41 ` [PATCH RESEND 1/4] i2c: s3c2410: Remove unnecessary label err_noclk Tushar Behera
@ 2012-11-23  8:41 ` Tushar Behera
  2012-11-23  8:41 ` [PATCH V2 3/4] i2c: s3c2410: Move location of clk_prepare_enable() call in probe function Tushar Behera
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tushar Behera @ 2012-11-23  8:41 UTC (permalink / raw)
  To: linux-kernel, linux-i2c, linux-samsung-soc; +Cc: w.sang, kgene.kim, patches

i2c-s3c2410 driver is modified to use devm_clk_get(),
devm_request_and_ioremap() (combining request_mem_region() and
ioremap()) and devm_request_irq(). This also simplifies the
return path in driver's probe.

Signed-off-by: Tushar Behera <tushar.behera@linaro.org>
---
Changes since V1:
  * devm_request_mem_region and devm_ioremap calls were replaced by
devm_request_and_ioremap() call.
  * All devm_* related modifications (earlier patches 2-5) were merged
to a single patch.

 drivers/i2c/busses/i2c-s3c2410.c |   51 +++++++++-----------------------------
 1 files changed, 12 insertions(+), 39 deletions(-)

diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 7522f40..a203917 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -78,7 +78,6 @@ struct s3c24xx_i2c {
 	void __iomem		*regs;
 	struct clk		*clk;
 	struct device		*dev;
-	struct resource		*ioarea;
 	struct i2c_adapter	adap;
 
 	struct s3c2410_platform_i2c	*pdata;
@@ -968,7 +967,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
 	/* find the clock and enable it */
 
 	i2c->dev = &pdev->dev;
-	i2c->clk = clk_get(&pdev->dev, "i2c");
+	i2c->clk = devm_clk_get(&pdev->dev, "i2c");
 	if (IS_ERR(i2c->clk)) {
 		dev_err(&pdev->dev, "cannot get clock\n");
 		return -ENOENT;
@@ -987,25 +986,16 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
 		goto err_clk;
 	}
 
-	i2c->ioarea = request_mem_region(res->start, resource_size(res),
-					 pdev->name);
-
-	if (i2c->ioarea == NULL) {
-		dev_err(&pdev->dev, "cannot request IO\n");
-		ret = -ENXIO;
-		goto err_clk;
-	}
-
-	i2c->regs = ioremap(res->start, resource_size(res));
+	i2c->regs = devm_request_and_ioremap(&pdev->dev, res);
 
 	if (i2c->regs == NULL) {
-		dev_err(&pdev->dev, "cannot map IO\n");
+		dev_err(&pdev->dev, "cannot request and map IO\n");
 		ret = -ENXIO;
-		goto err_ioarea;
+		goto err_clk;
 	}
 
-	dev_dbg(&pdev->dev, "registers %p (%p, %p)\n",
-		i2c->regs, i2c->ioarea, res);
+	dev_dbg(&pdev->dev, "registers %p (%p)\n",
+		i2c->regs, res);
 
 	/* setup info block for the i2c core */
 
@@ -1016,7 +1006,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
 
 	ret = s3c24xx_i2c_init(i2c);
 	if (ret != 0)
-		goto err_iomap;
+		goto err_clk;
 
 	/* find the IRQ for this unit (note, this relies on the init call to
 	 * ensure no current IRQs pending
@@ -1025,21 +1015,21 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
 	i2c->irq = ret = platform_get_irq(pdev, 0);
 	if (ret <= 0) {
 		dev_err(&pdev->dev, "cannot find IRQ\n");
-		goto err_iomap;
+		goto err_clk;
 	}
 
-	ret = request_irq(i2c->irq, s3c24xx_i2c_irq, 0,
-			  dev_name(&pdev->dev), i2c);
+	ret = devm_request_irq(&pdev->dev, i2c->irq, s3c24xx_i2c_irq, 0,
+			       dev_name(&pdev->dev), i2c);
 
 	if (ret != 0) {
 		dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq);
-		goto err_iomap;
+		goto err_clk;
 	}
 
 	ret = s3c24xx_i2c_register_cpufreq(i2c);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "failed to register cpufreq notifier\n");
-		goto err_irq;
+		goto err_clk;
 	}
 
 	/* Note, previous versions of the driver used i2c_add_adapter()
@@ -1070,19 +1060,8 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
  err_cpufreq:
 	s3c24xx_i2c_deregister_cpufreq(i2c);
 
- err_irq:
-	free_irq(i2c->irq, i2c);
-
- err_iomap:
-	iounmap(i2c->regs);
-
- err_ioarea:
-	release_resource(i2c->ioarea);
-	kfree(i2c->ioarea);
-
  err_clk:
 	clk_disable_unprepare(i2c->clk);
-	clk_put(i2c->clk);
 	return ret;
 }
 
@@ -1101,16 +1080,10 @@ static int s3c24xx_i2c_remove(struct platform_device *pdev)
 	s3c24xx_i2c_deregister_cpufreq(i2c);
 
 	i2c_del_adapter(&i2c->adap);
-	free_irq(i2c->irq, i2c);
 
 	clk_disable_unprepare(i2c->clk);
-	clk_put(i2c->clk);
-
-	iounmap(i2c->regs);
 
-	release_resource(i2c->ioarea);
 	s3c24xx_i2c_dt_gpio_free(i2c);
-	kfree(i2c->ioarea);
 
 	return 0;
 }
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH V2 3/4] i2c: s3c2410: Move location of clk_prepare_enable() call in probe function
  2012-11-23  8:41 [PATCH V2 0/4] i2c: s3c2410: Add devm_* apis and cleanup Tushar Behera
  2012-11-23  8:41 ` [PATCH RESEND 1/4] i2c: s3c2410: Remove unnecessary label err_noclk Tushar Behera
  2012-11-23  8:41 ` [PATCH V2 2/4] i2c: s3c2410: Convert to use devm_* APIs Tushar Behera
@ 2012-11-23  8:41 ` Tushar Behera
  2012-11-23  8:41 ` [PATCH V2 4/4] i2c: s3c2410: Remove err_cpufreq label Tushar Behera
  2013-01-24  7:26 ` [PATCH V2 0/4] i2c: s3c2410: Add devm_* apis and cleanup Wolfram Sang
  4 siblings, 0 replies; 6+ messages in thread
From: Tushar Behera @ 2012-11-23  8:41 UTC (permalink / raw)
  To: linux-kernel, linux-i2c, linux-samsung-soc; +Cc: w.sang, kgene.kim, patches

In i2c-s3c2410 driver probe, only s3c24xx_i2c_init() needs the I2C clock
to be enabled. Moving clk_prepare_enable() and clk_disable_unprepare()
calls to around this function simplifies the return path of probe call.

Signed-off-by: Tushar Behera <tushar.behera@linaro.org>
---
Changes since V1:
  * Rebased as per the V2 patch series.

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

diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index a203917..3f2d632 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -975,23 +975,20 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
 
 	dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk);
 
-	clk_prepare_enable(i2c->clk);
 
 	/* map the registers */
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (res == NULL) {
 		dev_err(&pdev->dev, "cannot find IO resource\n");
-		ret = -ENOENT;
-		goto err_clk;
+		return -ENOENT;
 	}
 
 	i2c->regs = devm_request_and_ioremap(&pdev->dev, res);
 
 	if (i2c->regs == NULL) {
 		dev_err(&pdev->dev, "cannot request and map IO\n");
-		ret = -ENXIO;
-		goto err_clk;
+		return -ENXIO;
 	}
 
 	dev_dbg(&pdev->dev, "registers %p (%p)\n",
@@ -1004,10 +1001,13 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
 
 	/* initialise the i2c controller */
 
+	clk_prepare_enable(i2c->clk);
 	ret = s3c24xx_i2c_init(i2c);
-	if (ret != 0)
-		goto err_clk;
-
+	clk_disable_unprepare(i2c->clk);
+	if (ret != 0) {
+		dev_err(&pdev->dev, "I2C controller init failed\n");
+		return ret;
+	}
 	/* find the IRQ for this unit (note, this relies on the init call to
 	 * ensure no current IRQs pending
 	 */
@@ -1015,7 +1015,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
 	i2c->irq = ret = platform_get_irq(pdev, 0);
 	if (ret <= 0) {
 		dev_err(&pdev->dev, "cannot find IRQ\n");
-		goto err_clk;
+		return ret;
 	}
 
 	ret = devm_request_irq(&pdev->dev, i2c->irq, s3c24xx_i2c_irq, 0,
@@ -1023,13 +1023,13 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
 
 	if (ret != 0) {
 		dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq);
-		goto err_clk;
+		return ret;
 	}
 
 	ret = s3c24xx_i2c_register_cpufreq(i2c);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "failed to register cpufreq notifier\n");
-		goto err_clk;
+		return ret;
 	}
 
 	/* Note, previous versions of the driver used i2c_add_adapter()
@@ -1054,14 +1054,10 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
 	pm_runtime_enable(&i2c->adap.dev);
 
 	dev_info(&pdev->dev, "%s: S3C I2C adapter\n", dev_name(&i2c->adap.dev));
-	clk_disable_unprepare(i2c->clk);
 	return 0;
 
  err_cpufreq:
 	s3c24xx_i2c_deregister_cpufreq(i2c);
-
- err_clk:
-	clk_disable_unprepare(i2c->clk);
 	return ret;
 }
 
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH V2 4/4] i2c: s3c2410: Remove err_cpufreq label
  2012-11-23  8:41 [PATCH V2 0/4] i2c: s3c2410: Add devm_* apis and cleanup Tushar Behera
                   ` (2 preceding siblings ...)
  2012-11-23  8:41 ` [PATCH V2 3/4] i2c: s3c2410: Move location of clk_prepare_enable() call in probe function Tushar Behera
@ 2012-11-23  8:41 ` Tushar Behera
  2013-01-24  7:26 ` [PATCH V2 0/4] i2c: s3c2410: Add devm_* apis and cleanup Wolfram Sang
  4 siblings, 0 replies; 6+ messages in thread
From: Tushar Behera @ 2012-11-23  8:41 UTC (permalink / raw)
  To: linux-kernel, linux-i2c, linux-samsung-soc; +Cc: w.sang, kgene.kim, patches

err_cpufreq label is now used only once. It can be removed and related
code can be moved to the caller location.

Signed-off-by: Tushar Behera <tushar.behera@linaro.org>
---
Changes since V1:
  * Rebased as per the V2 patch series.

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

diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 3f2d632..ff4408d 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -1044,7 +1044,8 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
 	ret = i2c_add_numbered_adapter(&i2c->adap);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "failed to add bus to i2c core\n");
-		goto err_cpufreq;
+		s3c24xx_i2c_deregister_cpufreq(i2c);
+		return ret;
 	}
 
 	of_i2c_register_devices(&i2c->adap);
@@ -1055,10 +1056,6 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
 
 	dev_info(&pdev->dev, "%s: S3C I2C adapter\n", dev_name(&i2c->adap.dev));
 	return 0;
-
- err_cpufreq:
-	s3c24xx_i2c_deregister_cpufreq(i2c);
-	return ret;
 }
 
 /* s3c24xx_i2c_remove
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH V2 0/4] i2c: s3c2410: Add devm_* apis and cleanup
  2012-11-23  8:41 [PATCH V2 0/4] i2c: s3c2410: Add devm_* apis and cleanup Tushar Behera
                   ` (3 preceding siblings ...)
  2012-11-23  8:41 ` [PATCH V2 4/4] i2c: s3c2410: Remove err_cpufreq label Tushar Behera
@ 2013-01-24  7:26 ` Wolfram Sang
  4 siblings, 0 replies; 6+ messages in thread
From: Wolfram Sang @ 2013-01-24  7:26 UTC (permalink / raw)
  To: Tushar Behera
  Cc: linux-kernel, linux-i2c, linux-samsung-soc, kgene.kim, patches

On Fri, Nov 23, 2012 at 02:11:51PM +0530, Tushar Behera wrote:
> This patchset cleans up the probe function of i2c-s3c2410 driver.
> These have been tested on Exynos4210 based Origen board.
> 
> Changes since V1:
>   * devm_request_mem_region and devm_ioremap calls were replaced by
> devm_request_and_ioremap() call.
>   * All devm_* related modifications (earlier patches 2-5) were merged
> to a single patch.
> 

Patch series looks good. Can you rebase to 3.8-rc4?


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-01-24  7:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-23  8:41 [PATCH V2 0/4] i2c: s3c2410: Add devm_* apis and cleanup Tushar Behera
2012-11-23  8:41 ` [PATCH RESEND 1/4] i2c: s3c2410: Remove unnecessary label err_noclk Tushar Behera
2012-11-23  8:41 ` [PATCH V2 2/4] i2c: s3c2410: Convert to use devm_* APIs Tushar Behera
2012-11-23  8:41 ` [PATCH V2 3/4] i2c: s3c2410: Move location of clk_prepare_enable() call in probe function Tushar Behera
2012-11-23  8:41 ` [PATCH V2 4/4] i2c: s3c2410: Remove err_cpufreq label Tushar Behera
2013-01-24  7:26 ` [PATCH V2 0/4] i2c: s3c2410: Add devm_* apis and cleanup Wolfram Sang

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).