Commit 1cb715ca authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Wolfram Sang

i2c-designware: move to managed functions (devm_*)

This makes the error handling much more simpler than open-coding everything
and in addition makes the probe function smaller and tidier.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent e5a7074a
...@@ -92,7 +92,7 @@ static int dw_i2c_probe(struct platform_device *pdev) ...@@ -92,7 +92,7 @@ static int dw_i2c_probe(struct platform_device *pdev)
{ {
struct dw_i2c_dev *dev; struct dw_i2c_dev *dev;
struct i2c_adapter *adap; struct i2c_adapter *adap;
struct resource *mem, *ioarea; struct resource *mem;
int irq, r; int irq, r;
/* NOTE: driver uses the static register mapping */ /* NOTE: driver uses the static register mapping */
...@@ -108,32 +108,25 @@ static int dw_i2c_probe(struct platform_device *pdev) ...@@ -108,32 +108,25 @@ static int dw_i2c_probe(struct platform_device *pdev)
return irq; /* -ENXIO */ return irq; /* -ENXIO */
} }
ioarea = request_mem_region(mem->start, resource_size(mem), dev = devm_kzalloc(&pdev->dev, sizeof(struct dw_i2c_dev), GFP_KERNEL);
pdev->name); if (!dev)
if (!ioarea) { return -ENOMEM;
dev_err(&pdev->dev, "I2C region already claimed\n");
return -EBUSY;
}
dev = kzalloc(sizeof(struct dw_i2c_dev), GFP_KERNEL); dev->base = devm_ioremap_resource(&pdev->dev, mem);
if (!dev) { if (IS_ERR(dev->base))
r = -ENOMEM; return PTR_ERR(dev->base);
goto err_release_region;
}
init_completion(&dev->cmd_complete); init_completion(&dev->cmd_complete);
mutex_init(&dev->lock); mutex_init(&dev->lock);
dev->dev = get_device(&pdev->dev); dev->dev = &pdev->dev;
dev->irq = irq; dev->irq = irq;
platform_set_drvdata(pdev, dev); platform_set_drvdata(pdev, dev);
dev->clk = clk_get(&pdev->dev, NULL); dev->clk = devm_clk_get(&pdev->dev, NULL);
dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz;
if (IS_ERR(dev->clk)) { if (IS_ERR(dev->clk))
r = -ENODEV; return PTR_ERR(dev->clk);
goto err_free_mem;
}
clk_prepare_enable(dev->clk); clk_prepare_enable(dev->clk);
dev->functionality = dev->functionality =
...@@ -146,13 +139,6 @@ static int dw_i2c_probe(struct platform_device *pdev) ...@@ -146,13 +139,6 @@ static int dw_i2c_probe(struct platform_device *pdev)
dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST; DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST;
dev->base = ioremap(mem->start, resource_size(mem));
if (dev->base == NULL) {
dev_err(&pdev->dev, "failure mapping io resources\n");
r = -EBUSY;
goto err_unuse_clocks;
}
/* Try first if we can configure the device from ACPI */ /* Try first if we can configure the device from ACPI */
r = dw_i2c_acpi_configure(pdev); r = dw_i2c_acpi_configure(pdev);
if (r) { if (r) {
...@@ -164,13 +150,14 @@ static int dw_i2c_probe(struct platform_device *pdev) ...@@ -164,13 +150,14 @@ static int dw_i2c_probe(struct platform_device *pdev)
} }
r = i2c_dw_init(dev); r = i2c_dw_init(dev);
if (r) if (r)
goto err_iounmap; return r;
i2c_dw_disable_int(dev); i2c_dw_disable_int(dev);
r = request_irq(dev->irq, i2c_dw_isr, IRQF_SHARED, pdev->name, dev); r = devm_request_irq(&pdev->dev, dev->irq, i2c_dw_isr, IRQF_SHARED,
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_iounmap; return r;
} }
adap = &dev->adapter; adap = &dev->adapter;
...@@ -187,57 +174,35 @@ static int dw_i2c_probe(struct platform_device *pdev) ...@@ -187,57 +174,35 @@ static int dw_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; return r;
} }
of_i2c_register_devices(adap); of_i2c_register_devices(adap);
acpi_i2c_register_devices(adap); acpi_i2c_register_devices(adap);
/* Increase reference counter */
get_device(&pdev->dev);
pm_runtime_set_active(&pdev->dev); pm_runtime_set_active(&pdev->dev);
pm_runtime_enable(&pdev->dev); pm_runtime_enable(&pdev->dev);
pm_runtime_put(&pdev->dev); pm_runtime_put(&pdev->dev);
return 0; return 0;
err_free_irq:
free_irq(dev->irq, dev);
err_iounmap:
iounmap(dev->base);
err_unuse_clocks:
clk_disable_unprepare(dev->clk);
clk_put(dev->clk);
dev->clk = NULL;
err_free_mem:
put_device(&pdev->dev);
kfree(dev);
err_release_region:
release_mem_region(mem->start, resource_size(mem));
return r;
} }
static int dw_i2c_remove(struct platform_device *pdev) static int dw_i2c_remove(struct platform_device *pdev)
{ {
struct dw_i2c_dev *dev = platform_get_drvdata(pdev); struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
struct resource *mem;
pm_runtime_get_sync(&pdev->dev); pm_runtime_get_sync(&pdev->dev);
i2c_del_adapter(&dev->adapter); i2c_del_adapter(&dev->adapter);
put_device(&pdev->dev); put_device(&pdev->dev);
clk_disable_unprepare(dev->clk);
clk_put(dev->clk);
dev->clk = NULL;
i2c_dw_disable(dev); i2c_dw_disable(dev);
free_irq(dev->irq, dev);
kfree(dev);
pm_runtime_put(&pdev->dev); pm_runtime_put(&pdev->dev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->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