i2c: xilinx: Use devm_* functions
Simplified the probe and remove functions using devm_* functions Signed-off-by: Kedareswara rao Appana <appanad@xilinx.com> Signed-off-by: Michal Simek <michal.simek@xilinx.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
This commit is contained in:
parent
617bdcbc3c
commit
168e722dcb
@ -32,6 +32,7 @@
|
|||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/errno.h>
|
#include <linux/errno.h>
|
||||||
|
#include <linux/err.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/i2c.h>
|
#include <linux/i2c.h>
|
||||||
@ -697,32 +698,20 @@ static int xiic_i2c_probe(struct platform_device *pdev)
|
|||||||
int ret, irq;
|
int ret, irq;
|
||||||
u8 i;
|
u8 i;
|
||||||
|
|
||||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL);
|
||||||
if (!res)
|
|
||||||
goto resource_missing;
|
|
||||||
|
|
||||||
irq = platform_get_irq(pdev, 0);
|
|
||||||
if (irq < 0)
|
|
||||||
goto resource_missing;
|
|
||||||
|
|
||||||
pdata = dev_get_platdata(&pdev->dev);
|
|
||||||
|
|
||||||
i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
|
|
||||||
if (!i2c)
|
if (!i2c)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||||
dev_err(&pdev->dev, "Memory region busy\n");
|
i2c->base = devm_ioremap_resource(&pdev->dev, res);
|
||||||
ret = -EBUSY;
|
if (IS_ERR(i2c->base))
|
||||||
goto request_mem_failed;
|
return PTR_ERR(i2c->base);
|
||||||
}
|
|
||||||
|
|
||||||
i2c->base = ioremap(res->start, resource_size(res));
|
irq = platform_get_irq(pdev, 0);
|
||||||
if (!i2c->base) {
|
if (irq < 0)
|
||||||
dev_err(&pdev->dev, "Unable to map registers\n");
|
return irq;
|
||||||
ret = -EIO;
|
|
||||||
goto map_failed;
|
pdata = dev_get_platdata(&pdev->dev);
|
||||||
}
|
|
||||||
|
|
||||||
/* hook up driver to tree */
|
/* hook up driver to tree */
|
||||||
platform_set_drvdata(pdev, i2c);
|
platform_set_drvdata(pdev, i2c);
|
||||||
@ -733,10 +722,11 @@ static int xiic_i2c_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
spin_lock_init(&i2c->lock);
|
spin_lock_init(&i2c->lock);
|
||||||
init_waitqueue_head(&i2c->wait);
|
init_waitqueue_head(&i2c->wait);
|
||||||
ret = request_irq(irq, xiic_isr, 0, pdev->name, i2c);
|
|
||||||
if (ret) {
|
ret = devm_request_irq(&pdev->dev, irq, xiic_isr, 0, pdev->name, i2c);
|
||||||
|
if (ret < 0) {
|
||||||
dev_err(&pdev->dev, "Cannot claim IRQ\n");
|
dev_err(&pdev->dev, "Cannot claim IRQ\n");
|
||||||
goto request_irq_failed;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
xiic_reinit(i2c);
|
xiic_reinit(i2c);
|
||||||
@ -745,7 +735,8 @@ static int xiic_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;
|
xiic_deinit(i2c);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdata) {
|
if (pdata) {
|
||||||
@ -755,43 +746,17 @@ static int xiic_i2c_probe(struct platform_device *pdev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
add_adapter_failed:
|
|
||||||
free_irq(irq, i2c);
|
|
||||||
request_irq_failed:
|
|
||||||
xiic_deinit(i2c);
|
|
||||||
iounmap(i2c->base);
|
|
||||||
map_failed:
|
|
||||||
release_mem_region(res->start, resource_size(res));
|
|
||||||
request_mem_failed:
|
|
||||||
kfree(i2c);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
resource_missing:
|
|
||||||
dev_err(&pdev->dev, "IRQ or Memory resource is missing\n");
|
|
||||||
return -ENOENT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int xiic_i2c_remove(struct platform_device *pdev)
|
static int xiic_i2c_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct xiic_i2c *i2c = platform_get_drvdata(pdev);
|
struct xiic_i2c *i2c = platform_get_drvdata(pdev);
|
||||||
struct resource *res;
|
|
||||||
|
|
||||||
/* remove adapter & data */
|
/* remove adapter & data */
|
||||||
i2c_del_adapter(&i2c->adap);
|
i2c_del_adapter(&i2c->adap);
|
||||||
|
|
||||||
xiic_deinit(i2c);
|
xiic_deinit(i2c);
|
||||||
|
|
||||||
free_irq(platform_get_irq(pdev, 0), 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
Block a user