diff options
Diffstat (limited to 'drivers/power/jz4740-battery.c')
-rw-r--r-- | drivers/power/jz4740-battery.c | 51 |
1 files changed, 12 insertions, 39 deletions
diff --git a/drivers/power/jz4740-battery.c b/drivers/power/jz4740-battery.c index ffbed5e5b94..bf914893c6f 100644 --- a/drivers/power/jz4740-battery.c +++ b/drivers/power/jz4740-battery.c @@ -33,7 +33,6 @@ struct jz_battery { struct jz_battery_platform_data *pdata; struct platform_device *pdev; - struct resource *mem; void __iomem *base; int irq; @@ -238,19 +237,20 @@ static void jz_battery_work(struct work_struct *work) schedule_delayed_work(&jz_battery->work, interval); } -static int __devinit jz_battery_probe(struct platform_device *pdev) +static int jz_battery_probe(struct platform_device *pdev) { int ret = 0; struct jz_battery_platform_data *pdata = pdev->dev.parent->platform_data; struct jz_battery *jz_battery; struct power_supply *battery; + struct resource *mem; if (!pdata) { dev_err(&pdev->dev, "No platform_data supplied\n"); return -ENXIO; } - jz_battery = kzalloc(sizeof(*jz_battery), GFP_KERNEL); + jz_battery = devm_kzalloc(&pdev->dev, sizeof(*jz_battery), GFP_KERNEL); if (!jz_battery) { dev_err(&pdev->dev, "Failed to allocate driver structure\n"); return -ENOMEM; @@ -260,33 +260,15 @@ static int __devinit jz_battery_probe(struct platform_device *pdev) jz_battery->irq = platform_get_irq(pdev, 0); if (jz_battery->irq < 0) { - ret = jz_battery->irq; dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret); - goto err_free; + return jz_battery->irq; } - jz_battery->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!jz_battery->mem) { - ret = -ENOENT; - dev_err(&pdev->dev, "Failed to get platform mmio resource\n"); - goto err_free; - } + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); - jz_battery->mem = request_mem_region(jz_battery->mem->start, - resource_size(jz_battery->mem), pdev->name); - if (!jz_battery->mem) { - ret = -EBUSY; - dev_err(&pdev->dev, "Failed to request mmio memory region\n"); - goto err_free; - } - - jz_battery->base = ioremap_nocache(jz_battery->mem->start, - resource_size(jz_battery->mem)); - if (!jz_battery->base) { - ret = -EBUSY; - dev_err(&pdev->dev, "Failed to ioremap mmio memory\n"); - goto err_release_mem_region; - } + jz_battery->base = devm_request_and_ioremap(&pdev->dev, mem); + if (!jz_battery->base) + return -EBUSY; battery = &jz_battery->battery; battery->name = pdata->info.name; @@ -309,7 +291,7 @@ static int __devinit jz_battery_probe(struct platform_device *pdev) jz_battery); if (ret) { dev_err(&pdev->dev, "Failed to request irq %d\n", ret); - goto err_iounmap; + goto err; } disable_irq(jz_battery->irq); @@ -366,17 +348,12 @@ err_free_gpio: gpio_free(jz_battery->pdata->gpio_charge); err_free_irq: free_irq(jz_battery->irq, jz_battery); -err_iounmap: +err: platform_set_drvdata(pdev, NULL); - iounmap(jz_battery->base); -err_release_mem_region: - release_mem_region(jz_battery->mem->start, resource_size(jz_battery->mem)); -err_free: - kfree(jz_battery); return ret; } -static int __devexit jz_battery_remove(struct platform_device *pdev) +static int jz_battery_remove(struct platform_device *pdev) { struct jz_battery *jz_battery = platform_get_drvdata(pdev); @@ -392,10 +369,6 @@ static int __devexit jz_battery_remove(struct platform_device *pdev) free_irq(jz_battery->irq, jz_battery); - iounmap(jz_battery->base); - release_mem_region(jz_battery->mem->start, resource_size(jz_battery->mem)); - kfree(jz_battery); - return 0; } @@ -431,7 +404,7 @@ static const struct dev_pm_ops jz_battery_pm_ops = { static struct platform_driver jz_battery_driver = { .probe = jz_battery_probe, - .remove = __devexit_p(jz_battery_remove), + .remove = jz_battery_remove, .driver = { .name = "jz4740-battery", .owner = THIS_MODULE, |