i2c: sh_mobile: devm conversion, irq setup
This is what devm was made for. No rollback mechanism needed, remove the hook parameter from the irq setup function and simplify it. While we are here change some variables to proper types. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
This commit is contained in:
parent
4fd31c2eb7
commit
7fe8a99933
|
@ -611,42 +611,25 @@ static struct i2c_algorithm sh_mobile_i2c_algorithm = {
|
||||||
.master_xfer = sh_mobile_i2c_xfer,
|
.master_xfer = sh_mobile_i2c_xfer,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook)
|
static int sh_mobile_i2c_hook_irqs(struct platform_device *dev)
|
||||||
{
|
{
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
int ret = -ENXIO;
|
resource_size_t n;
|
||||||
int n, k = 0;
|
int k = 0, ret;
|
||||||
|
|
||||||
while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) {
|
while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) {
|
||||||
for (n = res->start; hook && n <= res->end; n++) {
|
for (n = res->start; n <= res->end; n++) {
|
||||||
if (request_irq(n, sh_mobile_i2c_isr, 0,
|
ret = devm_request_irq(&dev->dev, n, sh_mobile_i2c_isr,
|
||||||
dev_name(&dev->dev), dev)) {
|
0, dev_name(&dev->dev), dev);
|
||||||
for (n--; n >= res->start; n--)
|
if (ret) {
|
||||||
free_irq(n, dev);
|
dev_err(&dev->dev, "cannot request IRQ %pa\n", &n);
|
||||||
|
return ret;
|
||||||
goto rollback;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hook)
|
return k > 0 ? 0 : -ENOENT;
|
||||||
return k > 0 ? 0 : -ENOENT;
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
rollback:
|
|
||||||
k--;
|
|
||||||
|
|
||||||
while (k >= 0) {
|
|
||||||
res = platform_get_resource(dev, IORESOURCE_IRQ, k);
|
|
||||||
for (n = res->start; n <= res->end; n++)
|
|
||||||
free_irq(n, dev);
|
|
||||||
|
|
||||||
k--;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sh_mobile_i2c_probe(struct platform_device *dev)
|
static int sh_mobile_i2c_probe(struct platform_device *dev)
|
||||||
|
@ -668,11 +651,9 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
|
||||||
return PTR_ERR(pd->clk);
|
return PTR_ERR(pd->clk);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = sh_mobile_i2c_hook_irqs(dev, 1);
|
ret = sh_mobile_i2c_hook_irqs(dev);
|
||||||
if (ret) {
|
if (ret)
|
||||||
dev_err(&dev->dev, "cannot request IRQ\n");
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
pd->dev = &dev->dev;
|
pd->dev = &dev->dev;
|
||||||
platform_set_drvdata(dev, pd);
|
platform_set_drvdata(dev, pd);
|
||||||
|
@ -680,10 +661,8 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
|
||||||
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
|
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
|
||||||
|
|
||||||
pd->reg = devm_ioremap_resource(&dev->dev, res);
|
pd->reg = devm_ioremap_resource(&dev->dev, res);
|
||||||
if (IS_ERR(pd->reg)) {
|
if (IS_ERR(pd->reg))
|
||||||
ret = PTR_ERR(pd->reg);
|
return PTR_ERR(pd->reg);
|
||||||
goto err_irq;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Use platform data bus speed or STANDARD_MODE */
|
/* Use platform data bus speed or STANDARD_MODE */
|
||||||
ret = of_property_read_u32(dev->dev.of_node, "clock-frequency", &bus_speed);
|
ret = of_property_read_u32(dev->dev.of_node, "clock-frequency", &bus_speed);
|
||||||
|
@ -735,7 +714,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_irq;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev_info(&dev->dev,
|
dev_info(&dev->dev,
|
||||||
|
@ -743,10 +722,6 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
|
||||||
adap->nr, pd->bus_speed, pd->iccl, pd->icch);
|
adap->nr, pd->bus_speed, pd->iccl, pd->icch);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_irq:
|
|
||||||
sh_mobile_i2c_hook_irqs(dev, 0);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sh_mobile_i2c_remove(struct platform_device *dev)
|
static int sh_mobile_i2c_remove(struct platform_device *dev)
|
||||||
|
@ -754,7 +729,6 @@ 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);
|
||||||
sh_mobile_i2c_hook_irqs(dev, 0);
|
|
||||||
pm_runtime_disable(&dev->dev);
|
pm_runtime_disable(&dev->dev);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue