avr32: some mmc/sd cleanups
authorDavid Brownell <dbrownell@users.sourceforge.net>
Sun, 27 Jul 2008 09:34:45 +0000 (02:34 -0700)
committerHaavard Skinnemoen <haavard.skinnemoen@atmel.com>
Sun, 27 Jul 2008 11:57:36 +0000 (13:57 +0200)
Minor cleanups for the MMC/SD support on avr32:

 - Make at32_add_device_mci() properly initialize "missing"
   platform data ... so boards like STK1002 won't try GPIO 0.

 - Switch over to gpio_is_valid() instead of testing for only
   one designated value.

 - Provide STK1002 platform data for the unlikely case that
   switches are set so first Ethernet controller isn't in use.
   (That's the only way to get card detect and writeprotect
   switch sensing on the STK1000.)

And get rid of one "unused variable" warning.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>
arch/avr32/boards/atstk1000/atstk1002.c
arch/avr32/mach-at32ap/at32ap700x.c
drivers/mmc/host/atmel-mci.c

index 14dc5a1436957a1a40869d8fbd437b6e0d8dde13..8538ba75ef92c8a1def6ee96caea4557618ae061 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <asm/io.h>
 #include <asm/setup.h>
+#include <asm/atmel-mci.h>
+
 #include <asm/arch/at32ap700x.h>
 #include <asm/arch/board.h>
 #include <asm/arch/init.h>
@@ -260,6 +262,21 @@ void __init setup_board(void)
        at32_setup_serial_console(0);
 }
 
+#ifndef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
+
+/* MMC card detect requires MACB0 *NOT* be used */
+#ifdef CONFIG_BOARD_ATSTK1002_SW6_CUSTOM
+static struct mci_platform_data __initdata mci0_data = {
+       .detect_pin     = GPIO_PIN_PC(14),      /* gpio30/sdcd */
+       .wp_pin         = GPIO_PIN_PC(15),      /* gpio31/sdwp */
+};
+#define MCI_PDATA      &mci0_data
+#else
+#define MCI_PDATA      NULL
+#endif /* SW6 for sd{cd,wp} routing */
+
+#endif /* SW2 for MMC signal routing */
+
 static int __init atstk1002_init(void)
 {
        /*
@@ -309,7 +326,7 @@ static int __init atstk1002_init(void)
        at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
 #endif
 #ifndef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
-       at32_add_device_mci(0, NULL);
+       at32_add_device_mci(0, MCI_PDATA);
 #endif
 #ifdef CONFIG_BOARD_ATSTK1002_SW5_CUSTOM
        set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
index 5f30b353a27f8cc610fbade30db0f650865505d8..1617048c86c5955bb549d84be9d1bf77ca90c6af 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
+#include <linux/gpio.h>
 #include <linux/spi/spi.h>
 #include <linux/usb/atmel_usba_udc.h>
 
@@ -1299,7 +1300,7 @@ at32_add_device_mci(unsigned int id, struct mci_platform_data *data)
 
        if (!data) {
                data = &_data;
-               memset(data, 0, sizeof(struct mci_platform_data));
+               memset(data, -1, sizeof(struct mci_platform_data));
                data->detect_pin = GPIO_PIN_NONE;
                data->wp_pin = GPIO_PIN_NONE;
        }
@@ -1315,9 +1316,9 @@ at32_add_device_mci(unsigned int id, struct mci_platform_data *data)
        select_peripheral(PA(14), PERIPH_A, 0); /* DATA2 */
        select_peripheral(PA(15), PERIPH_A, 0); /* DATA3 */
 
-       if (data->detect_pin != GPIO_PIN_NONE)
+       if (gpio_is_valid(data->detect_pin))
                at32_select_gpio(data->detect_pin, 0);
-       if (data->wp_pin != GPIO_PIN_NONE)
+       if (gpio_is_valid(data->wp_pin))
                at32_select_gpio(data->wp_pin, 0);
 
        atmel_mci0_pclk.dev = &pdev->dev;
@@ -1852,11 +1853,11 @@ at32_add_device_cf(unsigned int id, unsigned int extint,
        if (at32_init_ide_or_cf(pdev, data->cs, extint))
                goto fail;
 
-       if (data->detect_pin != GPIO_PIN_NONE)
+       if (gpio_is_valid(data->detect_pin))
                at32_select_gpio(data->detect_pin, AT32_GPIOF_DEGLITCH);
-       if (data->reset_pin != GPIO_PIN_NONE)
+       if (gpio_is_valid(data->reset_pin))
                at32_select_gpio(data->reset_pin, 0);
-       if (data->vcc_pin != GPIO_PIN_NONE)
+       if (gpio_is_valid(data->vcc_pin))
                at32_select_gpio(data->vcc_pin, 0);
        /* READY is used as extint, so we can't select it as gpio */
 
index 82bbbe99816920eb182443e8eff375f03698473c..992b4beb757c6593f4a790a0a749fcac5af8d165 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/debugfs.h>
 #include <linux/device.h>
 #include <linux/err.h>
+#include <linux/gpio.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/ioport.h>
@@ -28,7 +29,6 @@
 #include <asm/unaligned.h>
 
 #include <asm/arch/board.h>
-#include <asm/arch/gpio.h>
 
 #include "atmel-mci-regs.h"
 
@@ -574,7 +574,7 @@ static int atmci_get_ro(struct mmc_host *mmc)
        int                     read_only = 0;
        struct atmel_mci        *host = mmc_priv(mmc);
 
-       if (host->wp_pin >= 0) {
+       if (gpio_is_valid(host->wp_pin)) {
                read_only = gpio_get_value(host->wp_pin);
                dev_dbg(&mmc->class_dev, "card is %s\n",
                                read_only ? "read-only" : "read-write");
@@ -636,7 +636,7 @@ static void atmci_detect_change(unsigned long data)
         * been freed.
         */
        smp_rmb();
-       if (host->detect_pin < 0)
+       if (!gpio_is_valid(host->detect_pin))
                return;
 
        enable_irq(gpio_to_irq(host->detect_pin));
@@ -1051,7 +1051,7 @@ static int __init atmci_probe(struct platform_device *pdev)
 
        /* Assume card is present if we don't have a detect pin */
        host->present = 1;
-       if (host->detect_pin >= 0) {
+       if (gpio_is_valid(host->detect_pin)) {
                if (gpio_request(host->detect_pin, "mmc_detect")) {
                        dev_dbg(&mmc->class_dev, "no detect pin available\n");
                        host->detect_pin = -1;
@@ -1059,7 +1059,7 @@ static int __init atmci_probe(struct platform_device *pdev)
                        host->present = !gpio_get_value(host->detect_pin);
                }
        }
-       if (host->wp_pin >= 0) {
+       if (gpio_is_valid(host->wp_pin)) {
                if (gpio_request(host->wp_pin, "mmc_wp")) {
                        dev_dbg(&mmc->class_dev, "no WP pin available\n");
                        host->wp_pin = -1;
@@ -1070,7 +1070,7 @@ static int __init atmci_probe(struct platform_device *pdev)
 
        mmc_add_host(mmc);
 
-       if (host->detect_pin >= 0) {
+       if (gpio_is_valid(host->detect_pin)) {
                setup_timer(&host->detect_timer, atmci_detect_change,
                                (unsigned long)host);
 
@@ -1113,7 +1113,7 @@ static int __exit atmci_remove(struct platform_device *pdev)
        if (host) {
                /* Debugfs stuff is cleaned up by mmc core */
 
-               if (host->detect_pin >= 0) {
+               if (gpio_is_valid(host->detect_pin)) {
                        int pin = host->detect_pin;
 
                        /* Make sure the timer doesn't enable the interrupt */
@@ -1133,7 +1133,7 @@ static int __exit atmci_remove(struct platform_device *pdev)
                mci_readl(host, SR);
                clk_disable(host->mck);
 
-               if (host->wp_pin >= 0)
+               if (gpio_is_valid(host->wp_pin))
                        gpio_free(host->wp_pin);
 
                free_irq(platform_get_irq(pdev, 0), host->mmc);