Commit 85796843 authored by Vishwanathrao Badarkhe, Manish's avatar Vishwanathrao Badarkhe, Manish Committed by Wolfram Sang

i2c: davinci: update to devm_* API

Update the code to use devm_* API so that driver core will manage
resources.
Signed-off-by: default avatarVishwanathrao Badarkhe, Manish <manishv.b@ti.com>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent adf68acf
...@@ -643,7 +643,7 @@ static int davinci_i2c_probe(struct platform_device *pdev) ...@@ -643,7 +643,7 @@ static int davinci_i2c_probe(struct platform_device *pdev)
{ {
struct davinci_i2c_dev *dev; struct davinci_i2c_dev *dev;
struct i2c_adapter *adap; struct i2c_adapter *adap;
struct resource *mem, *irq, *ioarea; struct resource *mem, *irq;
int r; int r;
/* NOTE: driver uses the static register mapping */ /* NOTE: driver uses the static register mapping */
...@@ -659,17 +659,11 @@ static int davinci_i2c_probe(struct platform_device *pdev) ...@@ -659,17 +659,11 @@ static int davinci_i2c_probe(struct platform_device *pdev)
return -ENODEV; return -ENODEV;
} }
ioarea = request_mem_region(mem->start, resource_size(mem), dev = devm_kzalloc(&pdev->dev, sizeof(struct davinci_i2c_dev),
pdev->name); GFP_KERNEL);
if (!ioarea) {
dev_err(&pdev->dev, "I2C region already claimed\n");
return -EBUSY;
}
dev = kzalloc(sizeof(struct davinci_i2c_dev), GFP_KERNEL);
if (!dev) { if (!dev) {
r = -ENOMEM; dev_err(&pdev->dev, "Memory allocation failed\n");
goto err_release_region; return -ENOMEM;
} }
init_completion(&dev->cmd_complete); init_completion(&dev->cmd_complete);
...@@ -699,22 +693,23 @@ static int davinci_i2c_probe(struct platform_device *pdev) ...@@ -699,22 +693,23 @@ static int davinci_i2c_probe(struct platform_device *pdev)
dev->pdata = &davinci_i2c_platform_data_default; dev->pdata = &davinci_i2c_platform_data_default;
} }
dev->clk = clk_get(&pdev->dev, NULL); dev->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(dev->clk)) { if (IS_ERR(dev->clk)) {
r = -ENODEV; r = -ENODEV;
goto err_free_mem; goto err_free_mem;
} }
clk_prepare_enable(dev->clk); clk_prepare_enable(dev->clk);
dev->base = ioremap(mem->start, resource_size(mem)); dev->base = devm_ioremap_resource(&pdev->dev, mem);
if (!dev->base) { if (IS_ERR(dev->base)) {
r = -EBUSY; r = PTR_ERR(dev->base);
goto err_mem_ioremap; goto err_unuse_clocks;
} }
i2c_davinci_init(dev); i2c_davinci_init(dev);
r = request_irq(dev->irq, i2c_davinci_isr, 0, pdev->name, dev); r = devm_request_irq(&pdev->dev, dev->irq, i2c_davinci_isr, 0,
pdev->name, dev);
if (r) { if (r) {
dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq);
goto err_unuse_clocks; goto err_unuse_clocks;
...@@ -723,7 +718,7 @@ static int davinci_i2c_probe(struct platform_device *pdev) ...@@ -723,7 +718,7 @@ static int davinci_i2c_probe(struct platform_device *pdev)
r = i2c_davinci_cpufreq_register(dev); r = i2c_davinci_cpufreq_register(dev);
if (r) { if (r) {
dev_err(&pdev->dev, "failed to register cpufreq\n"); dev_err(&pdev->dev, "failed to register cpufreq\n");
goto err_free_irq; goto err_unuse_clocks;
} }
adap = &dev->adapter; adap = &dev->adapter;
...@@ -740,25 +735,17 @@ static int davinci_i2c_probe(struct platform_device *pdev) ...@@ -740,25 +735,17 @@ static int davinci_i2c_probe(struct platform_device *pdev)
r = i2c_add_numbered_adapter(adap); r = i2c_add_numbered_adapter(adap);
if (r) { if (r) {
dev_err(&pdev->dev, "failure adding adapter\n"); dev_err(&pdev->dev, "failure adding adapter\n");
goto err_free_irq; goto err_unuse_clocks;
} }
of_i2c_register_devices(adap); of_i2c_register_devices(adap);
return 0; return 0;
err_free_irq:
free_irq(dev->irq, dev);
err_unuse_clocks: err_unuse_clocks:
iounmap(dev->base);
err_mem_ioremap:
clk_disable_unprepare(dev->clk); clk_disable_unprepare(dev->clk);
clk_put(dev->clk);
dev->clk = NULL; dev->clk = NULL;
err_free_mem: err_free_mem:
put_device(&pdev->dev); put_device(&pdev->dev);
kfree(dev);
err_release_region:
release_mem_region(mem->start, resource_size(mem));
return r; return r;
} }
...@@ -766,7 +753,6 @@ static int davinci_i2c_probe(struct platform_device *pdev) ...@@ -766,7 +753,6 @@ static int davinci_i2c_probe(struct platform_device *pdev)
static int davinci_i2c_remove(struct platform_device *pdev) static int davinci_i2c_remove(struct platform_device *pdev)
{ {
struct davinci_i2c_dev *dev = platform_get_drvdata(pdev); struct davinci_i2c_dev *dev = platform_get_drvdata(pdev);
struct resource *mem;
i2c_davinci_cpufreq_deregister(dev); i2c_davinci_cpufreq_deregister(dev);
...@@ -774,16 +760,10 @@ static int davinci_i2c_remove(struct platform_device *pdev) ...@@ -774,16 +760,10 @@ static int davinci_i2c_remove(struct platform_device *pdev)
put_device(&pdev->dev); put_device(&pdev->dev);
clk_disable_unprepare(dev->clk); clk_disable_unprepare(dev->clk);
clk_put(dev->clk);
dev->clk = NULL; dev->clk = NULL;
davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0); davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0);
free_irq(dev->irq, dev);
iounmap(dev->base);
kfree(dev);
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(mem->start, resource_size(mem));
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