aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc
diff options
context:
space:
mode:
authorPramod Gurav <pramod.gurav@smartplayin.com>2014-09-23 08:51:48 -0400
committerUlf Hansson <ulf.hansson@linaro.org>2014-09-24 04:37:40 -0400
commit7bca646e0fc34b19cd84e14ed474d1c95830cc80 (patch)
treeca1afd5719e1ca2d730c6aa0cfb556d5e4b51b93 /drivers/mmc
parentdfa5d19658a308b373ce0cb9f6be9338c16ce14f (diff)
mmc: atmel-mci: Switch to using managed resource in probe
This change uses managed resource APIs to allocate resources such as, clk, gpio, io in order to simplify the driver unload or failure cases. Hence does away with release statements of the same resources in error labels and remove function. Signed-off-by: Pramod Gurav <pramod.gurav@smartplayin.com> Acked-by: Ludovic Desroches <ludovic.desroches@atmel.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/host/atmel-mci.c41
1 files changed, 14 insertions, 27 deletions
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index fde6a6fc732c..f32a51ee0fe3 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -17,6 +17,7 @@
17#include <linux/gpio.h> 17#include <linux/gpio.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/io.h>
20#include <linux/ioport.h> 21#include <linux/ioport.h>
21#include <linux/module.h> 22#include <linux/module.h>
22#include <linux/of.h> 23#include <linux/of.h>
@@ -2195,7 +2196,8 @@ static int __init atmci_init_slot(struct atmel_mci *host,
2195 /* Assume card is present initially */ 2196 /* Assume card is present initially */
2196 set_bit(ATMCI_CARD_PRESENT, &slot->flags); 2197 set_bit(ATMCI_CARD_PRESENT, &slot->flags);
2197 if (gpio_is_valid(slot->detect_pin)) { 2198 if (gpio_is_valid(slot->detect_pin)) {
2198 if (gpio_request(slot->detect_pin, "mmc_detect")) { 2199 if (devm_gpio_request(&host->pdev->dev, slot->detect_pin,
2200 "mmc_detect")) {
2199 dev_dbg(&mmc->class_dev, "no detect pin available\n"); 2201 dev_dbg(&mmc->class_dev, "no detect pin available\n");
2200 slot->detect_pin = -EBUSY; 2202 slot->detect_pin = -EBUSY;
2201 } else if (gpio_get_value(slot->detect_pin) ^ 2203 } else if (gpio_get_value(slot->detect_pin) ^
@@ -2208,7 +2210,8 @@ static int __init atmci_init_slot(struct atmel_mci *host,
2208 mmc->caps |= MMC_CAP_NEEDS_POLL; 2210 mmc->caps |= MMC_CAP_NEEDS_POLL;
2209 2211
2210 if (gpio_is_valid(slot->wp_pin)) { 2212 if (gpio_is_valid(slot->wp_pin)) {
2211 if (gpio_request(slot->wp_pin, "mmc_wp")) { 2213 if (devm_gpio_request(&host->pdev->dev, slot->wp_pin,
2214 "mmc_wp")) {
2212 dev_dbg(&mmc->class_dev, "no WP pin available\n"); 2215 dev_dbg(&mmc->class_dev, "no WP pin available\n");
2213 slot->wp_pin = -EBUSY; 2216 slot->wp_pin = -EBUSY;
2214 } 2217 }
@@ -2232,7 +2235,6 @@ static int __init atmci_init_slot(struct atmel_mci *host,
2232 dev_dbg(&mmc->class_dev, 2235 dev_dbg(&mmc->class_dev,
2233 "could not request IRQ %d for detect pin\n", 2236 "could not request IRQ %d for detect pin\n",
2234 gpio_to_irq(slot->detect_pin)); 2237 gpio_to_irq(slot->detect_pin));
2235 gpio_free(slot->detect_pin);
2236 slot->detect_pin = -EBUSY; 2238 slot->detect_pin = -EBUSY;
2237 } 2239 }
2238 } 2240 }
@@ -2257,10 +2259,7 @@ static void __exit atmci_cleanup_slot(struct atmel_mci_slot *slot,
2257 2259
2258 free_irq(gpio_to_irq(pin), slot); 2260 free_irq(gpio_to_irq(pin), slot);
2259 del_timer_sync(&slot->detect_timer); 2261 del_timer_sync(&slot->detect_timer);
2260 gpio_free(pin);
2261 } 2262 }
2262 if (gpio_is_valid(slot->wp_pin))
2263 gpio_free(slot->wp_pin);
2264 2263
2265 slot->host->slot[id] = NULL; 2264 slot->host->slot[id] = NULL;
2266 mmc_free_host(slot->mmc); 2265 mmc_free_host(slot->mmc);
@@ -2396,7 +2395,7 @@ static int __init atmci_probe(struct platform_device *pdev)
2396 if (irq < 0) 2395 if (irq < 0)
2397 return irq; 2396 return irq;
2398 2397
2399 host = kzalloc(sizeof(struct atmel_mci), GFP_KERNEL); 2398 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
2400 if (!host) 2399 if (!host)
2401 return -ENOMEM; 2400 return -ENOMEM;
2402 2401
@@ -2404,20 +2403,18 @@ static int __init atmci_probe(struct platform_device *pdev)
2404 spin_lock_init(&host->lock); 2403 spin_lock_init(&host->lock);
2405 INIT_LIST_HEAD(&host->queue); 2404 INIT_LIST_HEAD(&host->queue);
2406 2405
2407 host->mck = clk_get(&pdev->dev, "mci_clk"); 2406 host->mck = devm_clk_get(&pdev->dev, "mci_clk");
2408 if (IS_ERR(host->mck)) { 2407 if (IS_ERR(host->mck))
2409 ret = PTR_ERR(host->mck); 2408 return PTR_ERR(host->mck);
2410 goto err_clk_get;
2411 }
2412 2409
2413 ret = -ENOMEM; 2410 host->regs = devm_ioremap(&pdev->dev, regs->start, resource_size(regs));
2414 host->regs = ioremap(regs->start, resource_size(regs));
2415 if (!host->regs) 2411 if (!host->regs)
2416 goto err_ioremap; 2412 return -ENOMEM;
2417 2413
2418 ret = clk_prepare_enable(host->mck); 2414 ret = clk_prepare_enable(host->mck);
2419 if (ret) 2415 if (ret)
2420 goto err_request_irq; 2416 return ret;
2417
2421 atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST); 2418 atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
2422 host->bus_hz = clk_get_rate(host->mck); 2419 host->bus_hz = clk_get_rate(host->mck);
2423 clk_disable_unprepare(host->mck); 2420 clk_disable_unprepare(host->mck);
@@ -2428,7 +2425,7 @@ static int __init atmci_probe(struct platform_device *pdev)
2428 2425
2429 ret = request_irq(irq, atmci_interrupt, 0, dev_name(&pdev->dev), host); 2426 ret = request_irq(irq, atmci_interrupt, 0, dev_name(&pdev->dev), host);
2430 if (ret) 2427 if (ret)
2431 goto err_request_irq; 2428 return ret;
2432 2429
2433 /* Get MCI capabilities and set operations according to it */ 2430 /* Get MCI capabilities and set operations according to it */
2434 atmci_get_cap(host); 2431 atmci_get_cap(host);
@@ -2500,12 +2497,6 @@ err_init_slot:
2500 if (host->dma.chan) 2497 if (host->dma.chan)
2501 dma_release_channel(host->dma.chan); 2498 dma_release_channel(host->dma.chan);
2502 free_irq(irq, host); 2499 free_irq(irq, host);
2503err_request_irq:
2504 iounmap(host->regs);
2505err_ioremap:
2506 clk_put(host->mck);
2507err_clk_get:
2508 kfree(host);
2509 return ret; 2500 return ret;
2510} 2501}
2511 2502
@@ -2533,10 +2524,6 @@ static int __exit atmci_remove(struct platform_device *pdev)
2533 dma_release_channel(host->dma.chan); 2524 dma_release_channel(host->dma.chan);
2534 2525
2535 free_irq(platform_get_irq(pdev, 0), host); 2526 free_irq(platform_get_irq(pdev, 0), host);
2536 iounmap(host->regs);
2537
2538 clk_put(host->mck);
2539 kfree(host);
2540 2527
2541 return 0; 2528 return 0;
2542} 2529}