Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

at91_mci: use generic GPIO calls

Update the AT91 MMC driver to use the generic GPIO calls instead of the
AT91-specific calls; and to request (and release) those GPIO signals.

That required updating the probe() fault cleanup codepaths. Now there
is a single sequence for freeing resources, in reverse order of their
allocation. Also that code uses use dev_*() for messaging, and has less
abuse of KERN_ERR.

Likewise with updating remove() cleanup. This had to free the GPIOs,
and while adding that code I noticed and fixed two other problems: it
was poking at a workqueue owned by the mmc core; and in one (rare)
case would try freeing an IRQ that it didn't allocate.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>

authored by

David Brownell and committed by
Pierre Ossman
6e996ee8 541ceb5b

+80 -34
+80 -34
drivers/mmc/host/at91_mci.c
··· 70 70 71 71 #include <asm/io.h> 72 72 #include <asm/irq.h> 73 + #include <asm/gpio.h> 74 + 73 75 #include <asm/mach/mmc.h> 74 76 #include <asm/arch/board.h> 75 77 #include <asm/arch/cpu.h> 76 - #include <asm/arch/gpio.h> 77 78 #include <asm/arch/at91_mci.h> 78 79 79 80 #define DRIVER_NAME "at91_mci" ··· 660 659 if (host->board->vcc_pin) { 661 660 switch (ios->power_mode) { 662 661 case MMC_POWER_OFF: 663 - at91_set_gpio_value(host->board->vcc_pin, 0); 662 + gpio_set_value(host->board->vcc_pin, 0); 664 663 break; 665 664 case MMC_POWER_UP: 666 665 case MMC_POWER_ON: 667 - at91_set_gpio_value(host->board->vcc_pin, 1); 666 + gpio_set_value(host->board->vcc_pin, 1); 668 667 break; 669 668 } 670 669 } ··· 769 768 static irqreturn_t at91_mmc_det_irq(int irq, void *_host) 770 769 { 771 770 struct at91mci_host *host = _host; 772 - int present = !at91_get_gpio_value(irq); 771 + int present = !gpio_get_value(irq_to_gpio(irq)); 773 772 774 773 /* 775 774 * we expect this irq on both insert and remove, ··· 794 793 struct at91mci_host *host = mmc_priv(mmc); 795 794 796 795 if (host->board->wp_pin) { 797 - read_only = at91_get_gpio_value(host->board->wp_pin); 796 + read_only = gpio_get_value(host->board->wp_pin); 798 797 printk(KERN_WARNING "%s: card is %s\n", mmc_hostname(mmc), 799 798 (read_only ? "read-only" : "read-write") ); 800 799 } ··· 821 820 struct resource *res; 822 821 int ret; 823 822 824 - pr_debug("Probe MCI devices\n"); 825 - 826 823 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 827 824 if (!res) 828 825 return -ENXIO; ··· 830 831 831 832 mmc = mmc_alloc_host(sizeof(struct at91mci_host), &pdev->dev); 832 833 if (!mmc) { 833 - pr_debug("Failed to allocate mmc host\n"); 834 - release_mem_region(res->start, res->end - res->start + 1); 835 - return -ENOMEM; 834 + ret = -ENOMEM; 835 + dev_dbg(&pdev->dev, "couldn't allocate mmc host\n"); 836 + goto fail6; 836 837 } 837 838 838 839 mmc->ops = &at91_mci_ops; ··· 852 853 if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) 853 854 mmc->caps |= MMC_CAP_4_BIT_DATA; 854 855 else 855 - printk("AT91 MMC: 4 wire bus mode not supported" 856 + dev_warn(&pdev->dev, "4 wire bus mode not supported" 856 857 " - using 1 wire\n"); 858 + } 859 + 860 + /* 861 + * Reserve GPIOs ... board init code makes sure these pins are set 862 + * up as GPIOs with the right direction (input, except for vcc) 863 + */ 864 + if (host->board->det_pin) { 865 + ret = gpio_request(host->board->det_pin, "mmc_detect"); 866 + if (ret < 0) { 867 + dev_dbg(&pdev->dev, "couldn't claim card detect pin\n"); 868 + goto fail5; 869 + } 870 + } 871 + if (host->board->wp_pin) { 872 + ret = gpio_request(host->board->wp_pin, "mmc_wp"); 873 + if (ret < 0) { 874 + dev_dbg(&pdev->dev, "couldn't claim wp sense pin\n"); 875 + goto fail4; 876 + } 877 + } 878 + if (host->board->vcc_pin) { 879 + ret = gpio_request(host->board->vcc_pin, "mmc_vcc"); 880 + if (ret < 0) { 881 + dev_dbg(&pdev->dev, "couldn't claim vcc switch pin\n"); 882 + goto fail3; 883 + } 857 884 } 858 885 859 886 /* ··· 887 862 */ 888 863 host->mci_clk = clk_get(&pdev->dev, "mci_clk"); 889 864 if (IS_ERR(host->mci_clk)) { 890 - printk(KERN_ERR "AT91 MMC: no clock defined.\n"); 891 - mmc_free_host(mmc); 892 - release_mem_region(res->start, res->end - res->start + 1); 893 - return -ENODEV; 865 + ret = -ENODEV; 866 + dev_dbg(&pdev->dev, "no mci_clk?\n"); 867 + goto fail2; 894 868 } 895 869 896 870 /* ··· 897 873 */ 898 874 host->baseaddr = ioremap(res->start, res->end - res->start + 1); 899 875 if (!host->baseaddr) { 900 - clk_put(host->mci_clk); 901 - mmc_free_host(mmc); 902 - release_mem_region(res->start, res->end - res->start + 1); 903 - return -ENOMEM; 876 + ret = -ENOMEM; 877 + goto fail1; 904 878 } 905 879 906 880 /* ··· 912 890 * Allocate the MCI interrupt 913 891 */ 914 892 host->irq = platform_get_irq(pdev, 0); 915 - ret = request_irq(host->irq, at91_mci_irq, IRQF_SHARED, DRIVER_NAME, host); 893 + ret = request_irq(host->irq, at91_mci_irq, IRQF_SHARED, 894 + mmc_hostname(mmc), host); 916 895 if (ret) { 917 - printk(KERN_ERR "AT91 MMC: Failed to request MCI interrupt\n"); 918 - clk_disable(host->mci_clk); 919 - clk_put(host->mci_clk); 920 - mmc_free_host(mmc); 921 - iounmap(host->baseaddr); 922 - release_mem_region(res->start, res->end - res->start + 1); 923 - return ret; 896 + dev_dbg(&pdev->dev, "request MCI interrupt failed\n"); 897 + goto fail0; 924 898 } 925 899 926 900 platform_set_drvdata(pdev, mmc); ··· 925 907 * Add host to MMC layer 926 908 */ 927 909 if (host->board->det_pin) { 928 - host->present = !at91_get_gpio_value(host->board->det_pin); 929 - device_init_wakeup(&pdev->dev, 1); 910 + host->present = !gpio_get_value(host->board->det_pin); 930 911 } 931 912 else 932 913 host->present = -1; ··· 936 919 * monitor card insertion/removal if we can 937 920 */ 938 921 if (host->board->det_pin) { 939 - ret = request_irq(host->board->det_pin, at91_mmc_det_irq, 940 - 0, DRIVER_NAME, host); 922 + ret = request_irq(gpio_to_irq(host->board->det_pin), 923 + at91_mmc_det_irq, 0, mmc_hostname(mmc), host); 941 924 if (ret) 942 - printk(KERN_ERR "AT91 MMC: Couldn't allocate MMC detect irq\n"); 925 + dev_warn(&pdev->dev, "request MMC detect irq failed\n"); 926 + else 927 + device_init_wakeup(&pdev->dev, 1); 943 928 } 944 929 945 930 pr_debug("Added MCI driver\n"); 946 931 947 932 return 0; 933 + 934 + fail0: 935 + clk_disable(host->mci_clk); 936 + iounmap(host->baseaddr); 937 + fail1: 938 + clk_put(host->mci_clk); 939 + fail2: 940 + if (host->board->vcc_pin) 941 + gpio_free(host->board->vcc_pin); 942 + fail3: 943 + if (host->board->wp_pin) 944 + gpio_free(host->board->wp_pin); 945 + fail4: 946 + if (host->board->det_pin) 947 + gpio_free(host->board->det_pin); 948 + fail5: 949 + mmc_free_host(mmc); 950 + fail6: 951 + release_mem_region(res->start, res->end - res->start + 1); 952 + dev_err(&pdev->dev, "probe failed, err %d\n", ret); 953 + return ret; 948 954 } 949 955 950 956 /* ··· 985 945 host = mmc_priv(mmc); 986 946 987 947 if (host->board->det_pin) { 948 + if (device_can_wakeup(&pdev->dev)) 949 + free_irq(gpio_to_irq(host->board->det_pin), host); 988 950 device_init_wakeup(&pdev->dev, 0); 989 - free_irq(host->board->det_pin, host); 990 - cancel_delayed_work(&host->mmc->detect); 951 + gpio_free(host->board->det_pin); 991 952 } 992 953 993 954 at91_mci_disable(host); ··· 997 956 998 957 clk_disable(host->mci_clk); /* Disable the peripheral clock */ 999 958 clk_put(host->mci_clk); 959 + 960 + if (host->board->vcc_pin) 961 + gpio_free(host->board->vcc_pin); 962 + if (host->board->wp_pin) 963 + gpio_free(host->board->wp_pin); 1000 964 1001 965 iounmap(host->baseaddr); 1002 966 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);