diff options
author | Laxman Dewangan <ldewangan@nvidia.com> | 2012-06-13 15:42:39 +0530 |
---|---|---|
committer | Varun Wadekar <vwadekar@nvidia.com> | 2012-07-30 16:04:18 +0530 |
commit | 4e81000c5a0b4f7c114a18bfbd5cde2966a9acff (patch) | |
tree | 863eeaf2422d70068c94c86ca42673d8ce2d8059 /drivers/i2c | |
parent | 2fc201a5da151d376ebf84dd4baea43380a7ccd7 (diff) |
i2c: tegra: make all resource allocation through devm_*
Use the devm_* for the memory region allocation, interrupt request,
clock handler request.
By doing this, it does not require to explicitly free it and hence
saving some code.
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Cherry-picked from mainline
9cbb6b2b92d0fdade0fe00cc00e3658b44c86676
Change-Id: I0bc86dbd2bd4e460c75f6d425131f9e27bdace71
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/116468
Reviewed-by: Bitan Biswas <bbiswas@nvidia.com>
Tested-by: Bandi Krishna Chaitanya <bandik@nvidia.com>
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/busses/i2c-tegra.c | 63 |
1 files changed, 18 insertions, 45 deletions
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 7e051df6bdab..2f0bcb5e64be 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -948,7 +948,6 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev) struct tegra_i2c_dev *i2c_dev; struct tegra_i2c_platform_data *plat = pdev->dev.platform_data; struct resource *res; - struct resource *iomem; struct clk *div_clk; struct clk *fast_clk = NULL; const unsigned int *prop; @@ -984,52 +983,45 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev) dev_err(&pdev->dev, "no mem resource\n"); return -EINVAL; } - iomem = request_mem_region(res->start, resource_size(res), pdev->name); - if (!iomem) { - dev_err(&pdev->dev, "I2C region already claimed\n"); - return -EBUSY; - } - base = ioremap(iomem->start, resource_size(iomem)); + base = devm_request_and_ioremap(&pdev->dev, res); if (!base) { - dev_err(&pdev->dev, "Cannot ioremap I2C region\n"); - return -ENOMEM; + dev_err(&pdev->dev, "Cannot request/ioremap I2C registers\n"); + return -EADDRNOTAVAIL; } res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (!res) { dev_err(&pdev->dev, "no irq resource\n"); - ret = -EINVAL; - goto err_iounmap; + return -EINVAL; } irq = res->start; - i2c_dev = kzalloc(sizeof(struct tegra_i2c_dev) + + i2c_dev = devm_kzalloc(&pdev->dev, sizeof(struct tegra_i2c_dev) + (nbus-1) * sizeof(struct tegra_i2c_bus), GFP_KERNEL); if (!i2c_dev) { - ret = -ENOMEM; - goto err_release_region; + dev_err(&pdev->dev, "Could not allocate struct tegra_i2c_dev"); + return -ENOMEM; } i2c_dev->chipdata = chip_data; if (!i2c_dev->chipdata) { dev_err(&pdev->dev, "Error: Chip data is not valid\n"); - goto err_free; + return -ENOMEM; } - div_clk = clk_get(&pdev->dev, "i2c-div"); + div_clk = devm_clk_get(&pdev->dev, "i2c-div"); if (IS_ERR(div_clk)) { dev_err(&pdev->dev, "missing controller clock"); - ret = PTR_ERR(div_clk); - goto err_free; + return PTR_ERR(div_clk); } + if (i2c_dev->chipdata->has_fast_clock) { - fast_clk = clk_get(&pdev->dev, "i2c-fast"); + fast_clk = devm_clk_get(&pdev->dev, "i2c-fast"); if (IS_ERR(fast_clk)) { dev_err(&pdev->dev, "missing controller fast clock"); - ret = PTR_ERR(fast_clk); - goto fast_clk_err; + return PTR_ERR(fast_clk); } } @@ -1037,7 +1029,6 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev) i2c_dev->div_clk = div_clk; if (i2c_dev->chipdata->has_fast_clock) i2c_dev->fast_clk = fast_clk; - i2c_dev->iomem = iomem; i2c_dev->irq = irq; i2c_dev->cont_id = pdev->id; i2c_dev->dev = &pdev->dev; @@ -1088,13 +1079,14 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev) ret = tegra_i2c_init(i2c_dev); if (ret) { dev_err(&pdev->dev, "Failed to initialize i2c controller"); - goto err_clk_put; + return ret; } - ret = request_irq(i2c_dev->irq, tegra_i2c_isr, 0, pdev->name, i2c_dev); + ret = devm_request_irq(&pdev->dev, i2c_dev->irq, + tegra_i2c_isr, 0, pdev->name, i2c_dev); if (ret) { dev_err(&pdev->dev, "Failed to request irq %i\n", i2c_dev->irq); - goto err_clk_put; + return ret; } @@ -1144,38 +1136,19 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev) err_del_bus: while (i2c_dev->bus_count--) i2c_del_adapter(&i2c_dev->busses[i2c_dev->bus_count].adapter); - free_irq(i2c_dev->irq, i2c_dev); -err_clk_put: - if (i2c_dev->chipdata->has_fast_clock) - clk_put(fast_clk); -fast_clk_err: - clk_put(div_clk); -err_free: - kfree(i2c_dev); -err_release_region: - release_mem_region(iomem->start, resource_size(iomem)); -err_iounmap: - iounmap(base); return ret; } static int __devexit tegra_i2c_remove(struct platform_device *pdev) { struct tegra_i2c_dev *i2c_dev = platform_get_drvdata(pdev); + while (i2c_dev->bus_count--) i2c_del_adapter(&i2c_dev->busses[i2c_dev->bus_count].adapter); if (i2c_dev->is_clkon_always) tegra_i2c_clock_disable(i2c_dev); - free_irq(i2c_dev->irq, i2c_dev); - clk_put(i2c_dev->div_clk); - if (i2c_dev->chipdata->has_fast_clock) - clk_put(i2c_dev->fast_clk); - release_mem_region(i2c_dev->iomem->start, - resource_size(i2c_dev->iomem)); - iounmap(i2c_dev->base); - kfree(i2c_dev); return 0; } |