i2c-ocores: Use devres for resource allocation
This patch converts the i2c-cores driver to use devres routines for resource allocation. Signed-off-by: Jonas Bonn <jonas@southpole.se> Signed-off-by: Ben Dooks <ben-linux@fluff.org>
This commit is contained in:
parent
049bb69d82
commit
47def5b80f
|
@ -253,22 +253,21 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
|
||||||
if (!res2)
|
if (!res2)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
|
i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL);
|
||||||
if (!i2c)
|
if (!i2c)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (!request_mem_region(res->start, resource_size(res),
|
if (!devm_request_mem_region(&pdev->dev, res->start,
|
||||||
pdev->name)) {
|
resource_size(res), pdev->name)) {
|
||||||
dev_err(&pdev->dev, "Memory region busy\n");
|
dev_err(&pdev->dev, "Memory region busy\n");
|
||||||
ret = -EBUSY;
|
return -EBUSY;
|
||||||
goto request_mem_failed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c->base = ioremap(res->start, resource_size(res));
|
i2c->base = devm_ioremap_nocache(&pdev->dev, res->start,
|
||||||
|
resource_size(res));
|
||||||
if (!i2c->base) {
|
if (!i2c->base) {
|
||||||
dev_err(&pdev->dev, "Unable to map registers\n");
|
dev_err(&pdev->dev, "Unable to map registers\n");
|
||||||
ret = -EIO;
|
return -EIO;
|
||||||
goto map_failed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pdata = pdev->dev.platform_data;
|
pdata = pdev->dev.platform_data;
|
||||||
|
@ -284,10 +283,11 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
|
||||||
ocores_init(i2c);
|
ocores_init(i2c);
|
||||||
|
|
||||||
init_waitqueue_head(&i2c->wait);
|
init_waitqueue_head(&i2c->wait);
|
||||||
ret = request_irq(res2->start, ocores_isr, 0, pdev->name, i2c);
|
ret = devm_request_irq(&pdev->dev, res2->start, ocores_isr, 0,
|
||||||
|
pdev->name, i2c);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(&pdev->dev, "Cannot claim IRQ\n");
|
dev_err(&pdev->dev, "Cannot claim IRQ\n");
|
||||||
goto request_irq_failed;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hook up driver to tree */
|
/* hook up driver to tree */
|
||||||
|
@ -303,7 +303,7 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
|
||||||
ret = i2c_add_adapter(&i2c->adap);
|
ret = i2c_add_adapter(&i2c->adap);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(&pdev->dev, "Failed to add adapter\n");
|
dev_err(&pdev->dev, "Failed to add adapter\n");
|
||||||
goto add_adapter_failed;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add in known devices to the bus */
|
/* add in known devices to the bus */
|
||||||
|
@ -313,23 +313,11 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
add_adapter_failed:
|
|
||||||
free_irq(res2->start, i2c);
|
|
||||||
request_irq_failed:
|
|
||||||
iounmap(i2c->base);
|
|
||||||
map_failed:
|
|
||||||
release_mem_region(res->start, resource_size(res));
|
|
||||||
request_mem_failed:
|
|
||||||
kfree(i2c);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __devexit ocores_i2c_remove(struct platform_device* pdev)
|
static int __devexit ocores_i2c_remove(struct platform_device* pdev)
|
||||||
{
|
{
|
||||||
struct ocores_i2c *i2c = platform_get_drvdata(pdev);
|
struct ocores_i2c *i2c = platform_get_drvdata(pdev);
|
||||||
struct resource *res;
|
|
||||||
|
|
||||||
/* disable i2c logic */
|
/* disable i2c logic */
|
||||||
oc_setreg(i2c, OCI2C_CONTROL, oc_getreg(i2c, OCI2C_CONTROL)
|
oc_setreg(i2c, OCI2C_CONTROL, oc_getreg(i2c, OCI2C_CONTROL)
|
||||||
|
@ -339,18 +327,6 @@ static int __devexit ocores_i2c_remove(struct platform_device* pdev)
|
||||||
i2c_del_adapter(&i2c->adap);
|
i2c_del_adapter(&i2c->adap);
|
||||||
platform_set_drvdata(pdev, NULL);
|
platform_set_drvdata(pdev, NULL);
|
||||||
|
|
||||||
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
|
||||||
if (res)
|
|
||||||
free_irq(res->start, i2c);
|
|
||||||
|
|
||||||
iounmap(i2c->base);
|
|
||||||
|
|
||||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
||||||
if (res)
|
|
||||||
release_mem_region(res->start, resource_size(res));
|
|
||||||
|
|
||||||
kfree(i2c);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue