Commit 9cbb6b2b authored by Laxman Dewangan's avatar Laxman Dewangan Committed by Wolfram Sang

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: default avatarLaxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: default avatarWolfram Sang <w.sang@pengutronix.de>
parent c8f5af2f
...@@ -598,7 +598,6 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev) ...@@ -598,7 +598,6 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev)
struct tegra_i2c_dev *i2c_dev; struct tegra_i2c_dev *i2c_dev;
struct tegra_i2c_platform_data *pdata = pdev->dev.platform_data; struct tegra_i2c_platform_data *pdata = pdev->dev.platform_data;
struct resource *res; struct resource *res;
struct resource *iomem;
struct clk *clk; struct clk *clk;
struct clk *i2c_clk; struct clk *i2c_clk;
const unsigned int *prop; const unsigned int *prop;
...@@ -611,50 +610,41 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev) ...@@ -611,50 +610,41 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "no mem resource\n"); dev_err(&pdev->dev, "no mem resource\n");
return -EINVAL; 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) { if (!base) {
dev_err(&pdev->dev, "Cannot ioremap I2C region\n"); dev_err(&pdev->dev, "Cannot request/ioremap I2C registers\n");
return -ENOMEM; return -EADDRNOTAVAIL;
} }
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (!res) { if (!res) {
dev_err(&pdev->dev, "no irq resource\n"); dev_err(&pdev->dev, "no irq resource\n");
ret = -EINVAL; return -EINVAL;
goto err_iounmap;
} }
irq = res->start; irq = res->start;
clk = clk_get(&pdev->dev, NULL); clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(clk)) { if (IS_ERR(clk)) {
dev_err(&pdev->dev, "missing controller clock"); dev_err(&pdev->dev, "missing controller clock");
ret = PTR_ERR(clk); return PTR_ERR(clk);
goto err_release_region;
} }
i2c_clk = clk_get(&pdev->dev, "i2c"); i2c_clk = devm_clk_get(&pdev->dev, "i2c");
if (IS_ERR(i2c_clk)) { if (IS_ERR(i2c_clk)) {
dev_err(&pdev->dev, "missing bus clock"); dev_err(&pdev->dev, "missing bus clock");
ret = PTR_ERR(i2c_clk); return PTR_ERR(i2c_clk);
goto err_clk_put;
} }
i2c_dev = kzalloc(sizeof(struct tegra_i2c_dev), GFP_KERNEL); i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL);
if (!i2c_dev) { if (!i2c_dev) {
ret = -ENOMEM; dev_err(&pdev->dev, "Could not allocate struct tegra_i2c_dev");
goto err_i2c_clk_put; return -ENOMEM;
} }
i2c_dev->base = base; i2c_dev->base = base;
i2c_dev->clk = clk; i2c_dev->clk = clk;
i2c_dev->i2c_clk = i2c_clk; i2c_dev->i2c_clk = i2c_clk;
i2c_dev->iomem = iomem;
i2c_dev->adapter.algo = &tegra_i2c_algo; i2c_dev->adapter.algo = &tegra_i2c_algo;
i2c_dev->irq = irq; i2c_dev->irq = irq;
i2c_dev->cont_id = pdev->id; i2c_dev->cont_id = pdev->id;
...@@ -683,13 +673,14 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev) ...@@ -683,13 +673,14 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev)
ret = tegra_i2c_init(i2c_dev); ret = tegra_i2c_init(i2c_dev);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to initialize i2c controller"); dev_err(&pdev->dev, "Failed to initialize i2c controller");
goto err_free; 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) { if (ret) {
dev_err(&pdev->dev, "Failed to request irq %i\n", i2c_dev->irq); dev_err(&pdev->dev, "Failed to request irq %i\n", i2c_dev->irq);
goto err_free; return ret;
} }
clk_enable(i2c_dev->i2c_clk); clk_enable(i2c_dev->i2c_clk);
...@@ -707,38 +698,19 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev) ...@@ -707,38 +698,19 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev)
ret = i2c_add_numbered_adapter(&i2c_dev->adapter); ret = i2c_add_numbered_adapter(&i2c_dev->adapter);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to add I2C adapter\n"); dev_err(&pdev->dev, "Failed to add I2C adapter\n");
goto err_free_irq; clk_disable(i2c_dev->i2c_clk);
return ret;
} }
of_i2c_register_devices(&i2c_dev->adapter); of_i2c_register_devices(&i2c_dev->adapter);
return 0; return 0;
err_free_irq:
free_irq(i2c_dev->irq, i2c_dev);
err_free:
kfree(i2c_dev);
err_i2c_clk_put:
clk_put(i2c_clk);
err_clk_put:
clk_put(clk);
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) static int __devexit tegra_i2c_remove(struct platform_device *pdev)
{ {
struct tegra_i2c_dev *i2c_dev = platform_get_drvdata(pdev); struct tegra_i2c_dev *i2c_dev = platform_get_drvdata(pdev);
i2c_del_adapter(&i2c_dev->adapter); i2c_del_adapter(&i2c_dev->adapter);
free_irq(i2c_dev->irq, i2c_dev);
clk_put(i2c_dev->i2c_clk);
clk_put(i2c_dev->clk);
release_mem_region(i2c_dev->iomem->start,
resource_size(i2c_dev->iomem));
iounmap(i2c_dev->base);
kfree(i2c_dev);
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