aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2013-06-09 15:10:04 -0400
committerChris Ball <cjb@laptop.org>2013-06-27 12:39:13 -0400
commit58e300af8192d2f33d0e2dd47c9e31fb5d50c417 (patch)
treeaf111e0c5ea4f32f841bb4ee6b6b572ea29c9fa8
parent5d5c0350fc9533a1af3a43ee2331fec412679fcf (diff)
mmc: jz4740: Use slot-gpio helpers
Use the slot-gpio helpers to handle the write protect and card detect GPIO pins instead of re-implementing the same functionality in the driver. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Chris Ball <cjb@laptop.org>
-rw-r--r--drivers/mmc/host/jz4740_mmc.c113
1 files changed, 23 insertions, 90 deletions
diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
index c97ef6dd5fb6..e904e6e57e9b 100644
--- a/drivers/mmc/host/jz4740_mmc.c
+++ b/drivers/mmc/host/jz4740_mmc.c
@@ -14,6 +14,7 @@
14 */ 14 */
15 15
16#include <linux/mmc/host.h> 16#include <linux/mmc/host.h>
17#include <linux/mmc/slot-gpio.h>
17#include <linux/err.h> 18#include <linux/err.h>
18#include <linux/io.h> 19#include <linux/io.h>
19#include <linux/irq.h> 20#include <linux/irq.h>
@@ -653,35 +654,6 @@ static void jz4740_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
653 } 654 }
654} 655}
655 656
656static int jz4740_mmc_get_ro(struct mmc_host *mmc)
657{
658 struct jz4740_mmc_host *host = mmc_priv(mmc);
659 if (!gpio_is_valid(host->pdata->gpio_read_only))
660 return -ENOSYS;
661
662 return gpio_get_value(host->pdata->gpio_read_only) ^
663 host->pdata->read_only_active_low;
664}
665
666static int jz4740_mmc_get_cd(struct mmc_host *mmc)
667{
668 struct jz4740_mmc_host *host = mmc_priv(mmc);
669 if (!gpio_is_valid(host->pdata->gpio_card_detect))
670 return -ENOSYS;
671
672 return gpio_get_value(host->pdata->gpio_card_detect) ^
673 host->pdata->card_detect_active_low;
674}
675
676static irqreturn_t jz4740_mmc_card_detect_irq(int irq, void *devid)
677{
678 struct jz4740_mmc_host *host = devid;
679
680 mmc_detect_change(host->mmc, HZ / 2);
681
682 return IRQ_HANDLED;
683}
684
685static void jz4740_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable) 657static void jz4740_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
686{ 658{
687 struct jz4740_mmc_host *host = mmc_priv(mmc); 659 struct jz4740_mmc_host *host = mmc_priv(mmc);
@@ -691,8 +663,8 @@ static void jz4740_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
691static const struct mmc_host_ops jz4740_mmc_ops = { 663static const struct mmc_host_ops jz4740_mmc_ops = {
692 .request = jz4740_mmc_request, 664 .request = jz4740_mmc_request,
693 .set_ios = jz4740_mmc_set_ios, 665 .set_ios = jz4740_mmc_set_ios,
694 .get_ro = jz4740_mmc_get_ro, 666 .get_ro = mmc_gpio_get_ro,
695 .get_cd = jz4740_mmc_get_cd, 667 .get_cd = mmc_gpio_get_cd,
696 .enable_sdio_irq = jz4740_mmc_enable_sdio_irq, 668 .enable_sdio_irq = jz4740_mmc_enable_sdio_irq,
697}; 669};
698 670
@@ -727,58 +699,34 @@ static int jz4740_mmc_request_gpio(struct device *dev, int gpio,
727 return 0; 699 return 0;
728} 700}
729 701
730static int jz4740_mmc_request_gpios(struct platform_device *pdev) 702static int jz4740_mmc_request_gpios(struct mmc_host *mmc,
703 struct platform_device *pdev)
731{ 704{
732 int ret;
733 struct jz4740_mmc_platform_data *pdata = pdev->dev.platform_data; 705 struct jz4740_mmc_platform_data *pdata = pdev->dev.platform_data;
706 int ret = 0;
734 707
735 if (!pdata) 708 if (!pdata)
736 return 0; 709 return 0;
737 710
738 ret = jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_card_detect, 711 if (!pdata->card_detect_active_low)
739 "MMC detect change", false, 0); 712 mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
740 if (ret) 713 if (!pdata->read_only_active_low)
741 goto err; 714 mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
742
743 ret = jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_read_only,
744 "MMC read only", false, 0);
745 if (ret)
746 goto err_free_gpio_card_detect;
747 715
748 ret = jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_power, 716 if (gpio_is_valid(pdata->gpio_card_detect)) {
749 "MMC read only", true, pdata->power_active_low); 717 ret = mmc_gpio_request_cd(mmc, pdata->gpio_card_detect);
750 if (ret) 718 if (ret)
751 goto err_free_gpio_read_only; 719 return ret;
752 720 }
753 return 0;
754
755err_free_gpio_read_only:
756 if (gpio_is_valid(pdata->gpio_read_only))
757 gpio_free(pdata->gpio_read_only);
758err_free_gpio_card_detect:
759 if (gpio_is_valid(pdata->gpio_card_detect))
760 gpio_free(pdata->gpio_card_detect);
761err:
762 return ret;
763}
764
765static int jz4740_mmc_request_cd_irq(struct platform_device *pdev,
766 struct jz4740_mmc_host *host)
767{
768 struct jz4740_mmc_platform_data *pdata = pdev->dev.platform_data;
769
770 if (!gpio_is_valid(pdata->gpio_card_detect))
771 return 0;
772 721
773 host->card_detect_irq = gpio_to_irq(pdata->gpio_card_detect); 722 if (gpio_is_valid(pdata->gpio_read_only)) {
774 if (host->card_detect_irq < 0) { 723 ret = mmc_gpio_request_ro(mmc, pdata->gpio_read_only);
775 dev_warn(&pdev->dev, "Failed to get card detect irq\n"); 724 if (ret)
776 return 0; 725 return ret;
777 } 726 }
778 727
779 return request_irq(host->card_detect_irq, jz4740_mmc_card_detect_irq, 728 return jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_power,
780 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 729 "MMC read only", true, pdata->power_active_low);
781 "MMC card detect", host);
782} 730}
783 731
784static void jz4740_mmc_free_gpios(struct platform_device *pdev) 732static void jz4740_mmc_free_gpios(struct platform_device *pdev)
@@ -790,10 +738,6 @@ static void jz4740_mmc_free_gpios(struct platform_device *pdev)
790 738
791 if (gpio_is_valid(pdata->gpio_power)) 739 if (gpio_is_valid(pdata->gpio_power))
792 gpio_free(pdata->gpio_power); 740 gpio_free(pdata->gpio_power);
793 if (gpio_is_valid(pdata->gpio_read_only))
794 gpio_free(pdata->gpio_read_only);
795 if (gpio_is_valid(pdata->gpio_card_detect))
796 gpio_free(pdata->gpio_card_detect);
797} 741}
798 742
799static inline size_t jz4740_mmc_num_pins(struct jz4740_mmc_host *host) 743static inline size_t jz4740_mmc_num_pins(struct jz4740_mmc_host *host)
@@ -865,7 +809,7 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
865 goto err_iounmap; 809 goto err_iounmap;
866 } 810 }
867 811
868 ret = jz4740_mmc_request_gpios(pdev); 812 ret = jz4740_mmc_request_gpios(mmc, pdev);
869 if (ret) 813 if (ret)
870 goto err_gpio_bulk_free; 814 goto err_gpio_bulk_free;
871 815
@@ -888,17 +832,11 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
888 spin_lock_init(&host->lock); 832 spin_lock_init(&host->lock);
889 host->irq_mask = 0xffff; 833 host->irq_mask = 0xffff;
890 834
891 ret = jz4740_mmc_request_cd_irq(pdev, host);
892 if (ret) {
893 dev_err(&pdev->dev, "Failed to request card detect irq\n");
894 goto err_free_gpios;
895 }
896
897 ret = request_threaded_irq(host->irq, jz_mmc_irq, jz_mmc_irq_worker, 0, 835 ret = request_threaded_irq(host->irq, jz_mmc_irq, jz_mmc_irq_worker, 0,
898 dev_name(&pdev->dev), host); 836 dev_name(&pdev->dev), host);
899 if (ret) { 837 if (ret) {
900 dev_err(&pdev->dev, "Failed to request irq: %d\n", ret); 838 dev_err(&pdev->dev, "Failed to request irq: %d\n", ret);
901 goto err_free_card_detect_irq; 839 goto err_free_gpios;
902 } 840 }
903 841
904 jz4740_mmc_reset(host); 842 jz4740_mmc_reset(host);
@@ -921,9 +859,6 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
921 859
922err_free_irq: 860err_free_irq:
923 free_irq(host->irq, host); 861 free_irq(host->irq, host);
924err_free_card_detect_irq:
925 if (host->card_detect_irq >= 0)
926 free_irq(host->card_detect_irq, host);
927err_free_gpios: 862err_free_gpios:
928 jz4740_mmc_free_gpios(pdev); 863 jz4740_mmc_free_gpios(pdev);
929err_gpio_bulk_free: 864err_gpio_bulk_free:
@@ -951,8 +886,6 @@ static int jz4740_mmc_remove(struct platform_device *pdev)
951 mmc_remove_host(host->mmc); 886 mmc_remove_host(host->mmc);
952 887
953 free_irq(host->irq, host); 888 free_irq(host->irq, host);
954 if (host->card_detect_irq >= 0)
955 free_irq(host->card_detect_irq, host);
956 889
957 jz4740_mmc_free_gpios(pdev); 890 jz4740_mmc_free_gpios(pdev);
958 jz_gpio_bulk_free(jz4740_mmc_pins, jz4740_mmc_num_pins(host)); 891 jz_gpio_bulk_free(jz4740_mmc_pins, jz4740_mmc_num_pins(host));