Commit 4fd31c2e authored by Wolfram Sang's avatar Wolfram Sang Committed by Wolfram Sang

i2c: sh_mobile: devm conversion, low hanging fruits

Convert the easy parts to devm. irqs will be converted in a seperate
patch to keep diffs readable.
Signed-off-by: default avatarWolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent 5aacb666
...@@ -655,45 +655,33 @@ static int sh_mobile_i2c_probe(struct platform_device *dev) ...@@ -655,45 +655,33 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
struct sh_mobile_i2c_data *pd; struct sh_mobile_i2c_data *pd;
struct i2c_adapter *adap; struct i2c_adapter *adap;
struct resource *res; struct resource *res;
int size;
int ret; int ret;
u32 bus_speed; u32 bus_speed;
pd = kzalloc(sizeof(struct sh_mobile_i2c_data), GFP_KERNEL); pd = devm_kzalloc(&dev->dev, sizeof(struct sh_mobile_i2c_data), GFP_KERNEL);
if (pd == NULL) { if (!pd)
dev_err(&dev->dev, "cannot allocate private data\n");
return -ENOMEM; return -ENOMEM;
}
pd->clk = clk_get(&dev->dev, NULL); pd->clk = devm_clk_get(&dev->dev, NULL);
if (IS_ERR(pd->clk)) { if (IS_ERR(pd->clk)) {
dev_err(&dev->dev, "cannot get clock\n"); dev_err(&dev->dev, "cannot get clock\n");
ret = PTR_ERR(pd->clk); return PTR_ERR(pd->clk);
goto err;
} }
ret = sh_mobile_i2c_hook_irqs(dev, 1); ret = sh_mobile_i2c_hook_irqs(dev, 1);
if (ret) { if (ret) {
dev_err(&dev->dev, "cannot request IRQ\n"); dev_err(&dev->dev, "cannot request IRQ\n");
goto err_clk; return ret;
} }
pd->dev = &dev->dev; pd->dev = &dev->dev;
platform_set_drvdata(dev, pd); platform_set_drvdata(dev, pd);
res = platform_get_resource(dev, IORESOURCE_MEM, 0); res = platform_get_resource(dev, IORESOURCE_MEM, 0);
if (res == NULL) {
dev_err(&dev->dev, "cannot find IO resource\n");
ret = -ENOENT;
goto err_irq;
}
size = resource_size(res); pd->reg = devm_ioremap_resource(&dev->dev, res);
if (IS_ERR(pd->reg)) {
pd->reg = ioremap(res->start, size); ret = PTR_ERR(pd->reg);
if (pd->reg == NULL) {
dev_err(&dev->dev, "cannot map IO\n");
ret = -ENXIO;
goto err_irq; goto err_irq;
} }
...@@ -710,7 +698,7 @@ static int sh_mobile_i2c_probe(struct platform_device *dev) ...@@ -710,7 +698,7 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
/* The IIC blocks on SH-Mobile ARM processors /* The IIC blocks on SH-Mobile ARM processors
* come with two new bits in ICIC. * come with two new bits in ICIC.
*/ */
if (size > 0x17) if (resource_size(res) > 0x17)
pd->flags |= IIC_FLAG_HAS_ICIC67; pd->flags |= IIC_FLAG_HAS_ICIC67;
sh_mobile_i2c_init(pd); sh_mobile_i2c_init(pd);
...@@ -747,7 +735,7 @@ static int sh_mobile_i2c_probe(struct platform_device *dev) ...@@ -747,7 +735,7 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
ret = i2c_add_numbered_adapter(adap); ret = i2c_add_numbered_adapter(adap);
if (ret < 0) { if (ret < 0) {
dev_err(&dev->dev, "cannot add numbered adapter\n"); dev_err(&dev->dev, "cannot add numbered adapter\n");
goto err_all; goto err_irq;
} }
dev_info(&dev->dev, dev_info(&dev->dev,
...@@ -756,14 +744,8 @@ static int sh_mobile_i2c_probe(struct platform_device *dev) ...@@ -756,14 +744,8 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
return 0; return 0;
err_all:
iounmap(pd->reg);
err_irq: err_irq:
sh_mobile_i2c_hook_irqs(dev, 0); sh_mobile_i2c_hook_irqs(dev, 0);
err_clk:
clk_put(pd->clk);
err:
kfree(pd);
return ret; return ret;
} }
...@@ -772,11 +754,8 @@ static int sh_mobile_i2c_remove(struct platform_device *dev) ...@@ -772,11 +754,8 @@ static int sh_mobile_i2c_remove(struct platform_device *dev)
struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev); struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev);
i2c_del_adapter(&pd->adap); i2c_del_adapter(&pd->adap);
iounmap(pd->reg);
sh_mobile_i2c_hook_irqs(dev, 0); sh_mobile_i2c_hook_irqs(dev, 0);
clk_put(pd->clk);
pm_runtime_disable(&dev->dev); pm_runtime_disable(&dev->dev);
kfree(pd);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment