aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc
diff options
context:
space:
mode:
authorShawn Guo <shawn.guo@linaro.org>2012-11-26 01:39:43 -0500
committerChris Ball <cjb@laptop.org>2012-12-06 13:55:06 -0500
commite3af31c6c61fd036af459e5d3c1260a6cbb7810e (patch)
tree54c88098681f86346537d8ac7f35003bc611a974 /drivers/mmc
parent8ed765aac31b473e1881986d9fe2b6386f49f933 (diff)
mmc: sdhci-imx-esdhc: use more devm_* functions
Use devm_kzalloc, devm_gpio_request_one and devm_request_irq to make cleanup path simpler. Signed-off-by: Shawn Guo <shawn.guo@linaro.org> Signed-off-by: Chris Ball <cjb@laptop.org>
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/host/sdhci-esdhc-imx.c56
1 files changed, 18 insertions, 38 deletions
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index effc2acfe778..1849461c39ee 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -456,10 +456,10 @@ static int __devinit sdhci_esdhc_imx_probe(struct platform_device *pdev)
456 456
457 pltfm_host = sdhci_priv(host); 457 pltfm_host = sdhci_priv(host);
458 458
459 imx_data = kzalloc(sizeof(struct pltfm_imx_data), GFP_KERNEL); 459 imx_data = devm_kzalloc(&pdev->dev, sizeof(*imx_data), GFP_KERNEL);
460 if (!imx_data) { 460 if (!imx_data) {
461 err = -ENOMEM; 461 err = -ENOMEM;
462 goto err_imx_data; 462 goto free_sdhci;
463 } 463 }
464 464
465 if (of_id) 465 if (of_id)
@@ -470,19 +470,19 @@ static int __devinit sdhci_esdhc_imx_probe(struct platform_device *pdev)
470 imx_data->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); 470 imx_data->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
471 if (IS_ERR(imx_data->clk_ipg)) { 471 if (IS_ERR(imx_data->clk_ipg)) {
472 err = PTR_ERR(imx_data->clk_ipg); 472 err = PTR_ERR(imx_data->clk_ipg);
473 goto err_clk_get; 473 goto free_sdhci;
474 } 474 }
475 475
476 imx_data->clk_ahb = devm_clk_get(&pdev->dev, "ahb"); 476 imx_data->clk_ahb = devm_clk_get(&pdev->dev, "ahb");
477 if (IS_ERR(imx_data->clk_ahb)) { 477 if (IS_ERR(imx_data->clk_ahb)) {
478 err = PTR_ERR(imx_data->clk_ahb); 478 err = PTR_ERR(imx_data->clk_ahb);
479 goto err_clk_get; 479 goto free_sdhci;
480 } 480 }
481 481
482 imx_data->clk_per = devm_clk_get(&pdev->dev, "per"); 482 imx_data->clk_per = devm_clk_get(&pdev->dev, "per");
483 if (IS_ERR(imx_data->clk_per)) { 483 if (IS_ERR(imx_data->clk_per)) {
484 err = PTR_ERR(imx_data->clk_per); 484 err = PTR_ERR(imx_data->clk_per);
485 goto err_clk_get; 485 goto free_sdhci;
486 } 486 }
487 487
488 pltfm_host->clk = imx_data->clk_per; 488 pltfm_host->clk = imx_data->clk_per;
@@ -494,7 +494,7 @@ static int __devinit sdhci_esdhc_imx_probe(struct platform_device *pdev)
494 imx_data->pinctrl = devm_pinctrl_get_select_default(&pdev->dev); 494 imx_data->pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
495 if (IS_ERR(imx_data->pinctrl)) { 495 if (IS_ERR(imx_data->pinctrl)) {
496 err = PTR_ERR(imx_data->pinctrl); 496 err = PTR_ERR(imx_data->pinctrl);
497 goto pin_err; 497 goto disable_clk;
498 } 498 }
499 499
500 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL; 500 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
@@ -519,7 +519,7 @@ static int __devinit sdhci_esdhc_imx_probe(struct platform_device *pdev)
519 if (!host->mmc->parent->platform_data) { 519 if (!host->mmc->parent->platform_data) {
520 dev_err(mmc_dev(host->mmc), "no board data!\n"); 520 dev_err(mmc_dev(host->mmc), "no board data!\n");
521 err = -EINVAL; 521 err = -EINVAL;
522 goto no_board_data; 522 goto disable_clk;
523 } 523 }
524 imx_data->boarddata = *((struct esdhc_platform_data *) 524 imx_data->boarddata = *((struct esdhc_platform_data *)
525 host->mmc->parent->platform_data); 525 host->mmc->parent->platform_data);
@@ -527,7 +527,8 @@ static int __devinit sdhci_esdhc_imx_probe(struct platform_device *pdev)
527 527
528 /* write_protect */ 528 /* write_protect */
529 if (boarddata->wp_type == ESDHC_WP_GPIO) { 529 if (boarddata->wp_type == ESDHC_WP_GPIO) {
530 err = gpio_request_one(boarddata->wp_gpio, GPIOF_IN, "ESDHC_WP"); 530 err = devm_gpio_request_one(&pdev->dev, boarddata->wp_gpio,
531 GPIOF_IN, "ESDHC_WP");
531 if (err) { 532 if (err) {
532 dev_warn(mmc_dev(host->mmc), 533 dev_warn(mmc_dev(host->mmc),
533 "no write-protect pin available!\n"); 534 "no write-protect pin available!\n");
@@ -543,19 +544,21 @@ static int __devinit sdhci_esdhc_imx_probe(struct platform_device *pdev)
543 544
544 switch (boarddata->cd_type) { 545 switch (boarddata->cd_type) {
545 case ESDHC_CD_GPIO: 546 case ESDHC_CD_GPIO:
546 err = gpio_request_one(boarddata->cd_gpio, GPIOF_IN, "ESDHC_CD"); 547 err = devm_gpio_request_one(&pdev->dev, boarddata->cd_gpio,
548 GPIOF_IN, "ESDHC_CD");
547 if (err) { 549 if (err) {
548 dev_err(mmc_dev(host->mmc), 550 dev_err(mmc_dev(host->mmc),
549 "no card-detect pin available!\n"); 551 "no card-detect pin available!\n");
550 goto no_card_detect_pin; 552 goto disable_clk;
551 } 553 }
552 554
553 err = request_irq(gpio_to_irq(boarddata->cd_gpio), cd_irq, 555 err = devm_request_irq(&pdev->dev,
556 gpio_to_irq(boarddata->cd_gpio), cd_irq,
554 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, 557 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
555 mmc_hostname(host->mmc), host); 558 mmc_hostname(host->mmc), host);
556 if (err) { 559 if (err) {
557 dev_err(mmc_dev(host->mmc), "request irq error\n"); 560 dev_err(mmc_dev(host->mmc), "request irq error\n");
558 goto no_card_detect_irq; 561 goto disable_clk;
559 } 562 }
560 /* fall through */ 563 /* fall through */
561 564
@@ -574,27 +577,15 @@ static int __devinit sdhci_esdhc_imx_probe(struct platform_device *pdev)
574 577
575 err = sdhci_add_host(host); 578 err = sdhci_add_host(host);
576 if (err) 579 if (err)
577 goto err_add_host; 580 goto disable_clk;
578 581
579 return 0; 582 return 0;
580 583
581err_add_host: 584disable_clk:
582 if (gpio_is_valid(boarddata->cd_gpio))
583 free_irq(gpio_to_irq(boarddata->cd_gpio), host);
584no_card_detect_irq:
585 if (gpio_is_valid(boarddata->cd_gpio))
586 gpio_free(boarddata->cd_gpio);
587 if (gpio_is_valid(boarddata->wp_gpio))
588 gpio_free(boarddata->wp_gpio);
589no_card_detect_pin:
590no_board_data:
591pin_err:
592 clk_disable_unprepare(imx_data->clk_per); 585 clk_disable_unprepare(imx_data->clk_per);
593 clk_disable_unprepare(imx_data->clk_ipg); 586 clk_disable_unprepare(imx_data->clk_ipg);
594 clk_disable_unprepare(imx_data->clk_ahb); 587 clk_disable_unprepare(imx_data->clk_ahb);
595err_clk_get: 588free_sdhci:
596 kfree(imx_data);
597err_imx_data:
598 sdhci_pltfm_free(pdev); 589 sdhci_pltfm_free(pdev);
599 return err; 590 return err;
600} 591}
@@ -604,25 +595,14 @@ static int __devexit sdhci_esdhc_imx_remove(struct platform_device *pdev)
604 struct sdhci_host *host = platform_get_drvdata(pdev); 595 struct sdhci_host *host = platform_get_drvdata(pdev);
605 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 596 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
606 struct pltfm_imx_data *imx_data = pltfm_host->priv; 597 struct pltfm_imx_data *imx_data = pltfm_host->priv;
607 struct esdhc_platform_data *boarddata = &imx_data->boarddata;
608 int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff); 598 int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
609 599
610 sdhci_remove_host(host, dead); 600 sdhci_remove_host(host, dead);
611 601
612 if (gpio_is_valid(boarddata->wp_gpio))
613 gpio_free(boarddata->wp_gpio);
614
615 if (gpio_is_valid(boarddata->cd_gpio)) {
616 free_irq(gpio_to_irq(boarddata->cd_gpio), host);
617 gpio_free(boarddata->cd_gpio);
618 }
619
620 clk_disable_unprepare(imx_data->clk_per); 602 clk_disable_unprepare(imx_data->clk_per);
621 clk_disable_unprepare(imx_data->clk_ipg); 603 clk_disable_unprepare(imx_data->clk_ipg);
622 clk_disable_unprepare(imx_data->clk_ahb); 604 clk_disable_unprepare(imx_data->clk_ahb);
623 605
624 kfree(imx_data);
625
626 sdhci_pltfm_free(pdev); 606 sdhci_pltfm_free(pdev);
627 607
628 return 0; 608 return 0;