mmc: s3cmci: Use the slot GPIO descriptor
authorLinus Walleij <linus.walleij@linaro.org>
Sun, 2 Dec 2018 08:43:20 +0000 (09:43 +0100)
committerUlf Hansson <ulf.hansson@linaro.org>
Mon, 17 Dec 2018 07:26:24 +0000 (08:26 +0100)
Simplify things by making the S3CMCI driver just use
slot GPIO with descriptors instead of passing around the
global GPIO numbers that we want to get rid of.

Getting the names of the GPIO chips into the machine
descriptor tables was a bit of a challenge but I think
I have them right.

The platform data supports passing in inversion flags, but
no platform is using them, and it is highly unlikely
that we will add more, so drop them. The long term plan
is to let the inversion flags on the GPIO machine
descriptor do the job.

The lines are flagged as GPIO_ACTIVE_[LOW|HIGH] as that is
what they are, and since we can now rely on the descriptors
to have the right polarity, we set the
"override_active_level" to false in mmc_gpiod_request_cd()
and mmc_gpiod_request_ro().

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
Cc: Sergio Prado <sergio.prado@e-labworks.com>
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
arch/arm/mach-s3c24xx/mach-at2440evb.c
arch/arm/mach-s3c24xx/mach-h1940.c
arch/arm/mach-s3c24xx/mach-mini2440.c
arch/arm/mach-s3c24xx/mach-n30.c
arch/arm/mach-s3c24xx/mach-rx1950.c
drivers/mmc/host/s3cmci.c
include/linux/platform_data/mmc-s3cmci.h

index 68a4fa94257a221aa2e733395e343bb21f8d7c4e..58c5ef3cf1d7e583a4bb49172aad1e7938e318eb 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <linux/kernel.h>
 #include <linux/types.h>
 
 #include <linux/kernel.h>
 #include <linux/types.h>
-#include <linux/gpio.h>
+#include <linux/gpio/machine.h>
 #include <linux/interrupt.h>
 #include <linux/list.h>
 #include <linux/timer.h>
 #include <linux/interrupt.h>
 #include <linux/list.h>
 #include <linux/timer.h>
@@ -136,7 +136,16 @@ static struct platform_device at2440evb_device_eth = {
 };
 
 static struct s3c24xx_mci_pdata at2440evb_mci_pdata __initdata = {
 };
 
 static struct s3c24xx_mci_pdata at2440evb_mci_pdata __initdata = {
-       .gpio_detect    = S3C2410_GPG(10),
+       /* Intentionally left blank */
+};
+
+static struct gpiod_lookup_table at2440evb_mci_gpio_table = {
+       .dev_id = "s3c2410-sdi",
+       .table = {
+               /* Card detect S3C2410_GPG(10) */
+               GPIO_LOOKUP("GPG", 10, "cd", GPIO_ACTIVE_LOW),
+               { },
+       },
 };
 
 /* 7" LCD panel */
 };
 
 /* 7" LCD panel */
@@ -200,6 +209,7 @@ static void __init at2440evb_init_time(void)
 static void __init at2440evb_init(void)
 {
        s3c24xx_fb_set_platdata(&at2440evb_fb_info);
 static void __init at2440evb_init(void)
 {
        s3c24xx_fb_set_platdata(&at2440evb_fb_info);
+       gpiod_add_lookup_table(&at2440evb_mci_gpio_table);
        s3c24xx_mci_set_platdata(&at2440evb_mci_pdata);
        s3c_nand_set_platdata(&at2440evb_nand_info);
        s3c_i2c0_set_platdata(NULL);
        s3c24xx_mci_set_platdata(&at2440evb_mci_pdata);
        s3c_nand_set_platdata(&at2440evb_nand_info);
        s3c_i2c0_set_platdata(NULL);
index e064c73a57d3a7be05e5575568fd7ce8849ad38e..74d6b68e91c7437aa756cdf453644968818d883e 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/gpio.h>
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/gpio.h>
+#include <linux/gpio/machine.h>
 #include <linux/input.h>
 #include <linux/gpio_keys.h>
 #include <linux/pwm.h>
 #include <linux/input.h>
 #include <linux/gpio_keys.h>
 #include <linux/pwm.h>
@@ -459,12 +460,21 @@ static void h1940_set_mmc_power(unsigned char power_mode, unsigned short vdd)
 }
 
 static struct s3c24xx_mci_pdata h1940_mmc_cfg __initdata = {
 }
 
 static struct s3c24xx_mci_pdata h1940_mmc_cfg __initdata = {
-       .gpio_detect   = S3C2410_GPF(5),
-       .gpio_wprotect = S3C2410_GPH(8),
        .set_power     = h1940_set_mmc_power,
        .ocr_avail     = MMC_VDD_32_33,
 };
 
        .set_power     = h1940_set_mmc_power,
        .ocr_avail     = MMC_VDD_32_33,
 };
 
+static struct gpiod_lookup_table h1940_mmc_gpio_table = {
+       .dev_id = "s3c2410-sdi",
+       .table = {
+               /* Card detect S3C2410_GPF(5) */
+               GPIO_LOOKUP("GPF", 5, "cd", GPIO_ACTIVE_LOW),
+               /* Write protect S3C2410_GPH(8) */
+               GPIO_LOOKUP("GPH", 8, "wp", GPIO_ACTIVE_LOW),
+               { },
+       },
+};
+
 static struct pwm_lookup h1940_pwm_lookup[] = {
        PWM_LOOKUP("samsung-pwm", 0, "pwm-backlight", NULL, 36296,
                   PWM_POLARITY_NORMAL),
 static struct pwm_lookup h1940_pwm_lookup[] = {
        PWM_LOOKUP("samsung-pwm", 0, "pwm-backlight", NULL, 36296,
                   PWM_POLARITY_NORMAL),
@@ -680,6 +690,7 @@ static void __init h1940_init(void)
        u32 tmp;
 
        s3c24xx_fb_set_platdata(&h1940_fb_info);
        u32 tmp;
 
        s3c24xx_fb_set_platdata(&h1940_fb_info);
+       gpiod_add_lookup_table(&h1940_mmc_gpio_table);
        s3c24xx_mci_set_platdata(&h1940_mmc_cfg);
        s3c24xx_udc_set_platdata(&h1940_udc_cfg);
        s3c24xx_ts_set_platdata(&h1940_ts_cfg);
        s3c24xx_mci_set_platdata(&h1940_mmc_cfg);
        s3c24xx_udc_set_platdata(&h1940_udc_cfg);
        s3c24xx_ts_set_platdata(&h1940_ts_cfg);
index 50d67d760efdeef7f3878e00f63195df67336fbf..9035f868fb34e9e70ea656e1e0514dd9dcccde5b 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/timer.h>
 #include <linux/init.h>
 #include <linux/gpio.h>
 #include <linux/timer.h>
 #include <linux/init.h>
 #include <linux/gpio.h>
+#include <linux/gpio/machine.h>
 #include <linux/input.h>
 #include <linux/io.h>
 #include <linux/serial_core.h>
 #include <linux/input.h>
 #include <linux/io.h>
 #include <linux/serial_core.h>
@@ -234,13 +235,22 @@ static struct s3c2410fb_mach_info mini2440_fb_info __initdata = {
 /* MMC/SD  */
 
 static struct s3c24xx_mci_pdata mini2440_mmc_cfg __initdata = {
 /* MMC/SD  */
 
 static struct s3c24xx_mci_pdata mini2440_mmc_cfg __initdata = {
-       .gpio_detect            = S3C2410_GPG(8),
-       .gpio_wprotect          = S3C2410_GPH(8),
        .wprotect_invert        = 1,
        .set_power              = NULL,
        .ocr_avail              = MMC_VDD_32_33|MMC_VDD_33_34,
 };
 
        .wprotect_invert        = 1,
        .set_power              = NULL,
        .ocr_avail              = MMC_VDD_32_33|MMC_VDD_33_34,
 };
 
+static struct gpiod_lookup_table mini2440_mmc_gpio_table = {
+       .dev_id = "s3c2410-sdi",
+       .table = {
+               /* Card detect S3C2410_GPG(8) */
+               GPIO_LOOKUP("GPG", 8, "cd", GPIO_ACTIVE_LOW),
+               /* Write protect S3C2410_GPH(8) */
+               GPIO_LOOKUP("GPH", 8, "wp", GPIO_ACTIVE_HIGH),
+               { },
+       },
+};
+
 /* NAND Flash on MINI2440 board */
 
 static struct mtd_partition mini2440_default_nand_part[] __initdata = {
 /* NAND Flash on MINI2440 board */
 
 static struct mtd_partition mini2440_default_nand_part[] __initdata = {
@@ -696,6 +706,7 @@ static void __init mini2440_init(void)
        }
 
        s3c24xx_udc_set_platdata(&mini2440_udc_cfg);
        }
 
        s3c24xx_udc_set_platdata(&mini2440_udc_cfg);
+       gpiod_add_lookup_table(&mini2440_mmc_gpio_table);
        s3c24xx_mci_set_platdata(&mini2440_mmc_cfg);
        s3c_nand_set_platdata(&mini2440_nand_info);
        s3c_i2c0_set_platdata(NULL);
        s3c24xx_mci_set_platdata(&mini2440_mmc_cfg);
        s3c_nand_set_platdata(&mini2440_nand_info);
        s3c_i2c0_set_platdata(NULL);
index eec51fadb14a3429e012dd19649162ce52ad78e2..d856f23939affd8acc5611f246be722b7d39ff75 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/gpio_keys.h>
 #include <linux/init.h>
 #include <linux/gpio.h>
 #include <linux/gpio_keys.h>
 #include <linux/init.h>
 #include <linux/gpio.h>
+#include <linux/gpio/machine.h>
 #include <linux/input.h>
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/input.h>
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
@@ -350,12 +351,21 @@ static void n30_sdi_set_power(unsigned char power_mode, unsigned short vdd)
 }
 
 static struct s3c24xx_mci_pdata n30_mci_cfg __initdata = {
 }
 
 static struct s3c24xx_mci_pdata n30_mci_cfg __initdata = {
-       .gpio_detect    = S3C2410_GPF(1),
-       .gpio_wprotect  = S3C2410_GPG(10),
        .ocr_avail      = MMC_VDD_32_33,
        .set_power      = n30_sdi_set_power,
 };
 
        .ocr_avail      = MMC_VDD_32_33,
        .set_power      = n30_sdi_set_power,
 };
 
+static struct gpiod_lookup_table n30_mci_gpio_table = {
+       .dev_id = "s3c2410-sdi",
+       .table = {
+               /* Card detect S3C2410_GPF(1) */
+               GPIO_LOOKUP("GPF", 1, "cd", GPIO_ACTIVE_LOW),
+               /* Write protect S3C2410_GPG(10) */
+               GPIO_LOOKUP("GPG", 10, "wp", GPIO_ACTIVE_LOW),
+               { },
+       },
+};
+
 static struct platform_device *n30_devices[] __initdata = {
        &s3c_device_lcd,
        &s3c_device_wdt,
 static struct platform_device *n30_devices[] __initdata = {
        &s3c_device_lcd,
        &s3c_device_wdt,
@@ -549,6 +559,7 @@ static void __init n30_init(void)
 
        s3c24xx_fb_set_platdata(&n30_fb_info);
        s3c24xx_udc_set_platdata(&n30_udc_cfg);
 
        s3c24xx_fb_set_platdata(&n30_fb_info);
        s3c24xx_udc_set_platdata(&n30_udc_cfg);
+       gpiod_add_lookup_table(&n30_mci_gpio_table);
        s3c24xx_mci_set_platdata(&n30_mci_cfg);
        s3c_i2c0_set_platdata(&n30_i2ccfg);
 
        s3c24xx_mci_set_platdata(&n30_mci_cfg);
        s3c_i2c0_set_platdata(&n30_i2ccfg);
 
index 7f5a18fa305b9bb60a659234f2b5a210492cf589..29f9b345a5311ffe8879b98f15e1c401a7adf203 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/timer.h>
 #include <linux/init.h>
 #include <linux/gpio.h>
 #include <linux/timer.h>
 #include <linux/init.h>
 #include <linux/gpio.h>
+#include <linux/gpio/machine.h>
 #include <linux/platform_device.h>
 #include <linux/serial_core.h>
 #include <linux/serial_s3c.h>
 #include <linux/platform_device.h>
 #include <linux/serial_core.h>
 #include <linux/serial_s3c.h>
@@ -558,12 +559,21 @@ static void rx1950_set_mmc_power(unsigned char power_mode, unsigned short vdd)
 }
 
 static struct s3c24xx_mci_pdata rx1950_mmc_cfg __initdata = {
 }
 
 static struct s3c24xx_mci_pdata rx1950_mmc_cfg __initdata = {
-       .gpio_detect = S3C2410_GPF(5),
-       .gpio_wprotect = S3C2410_GPH(8),
        .set_power = rx1950_set_mmc_power,
        .ocr_avail = MMC_VDD_32_33,
 };
 
        .set_power = rx1950_set_mmc_power,
        .ocr_avail = MMC_VDD_32_33,
 };
 
+static struct gpiod_lookup_table rx1950_mmc_gpio_table = {
+       .dev_id = "s3c2410-sdi",
+       .table = {
+               /* Card detect S3C2410_GPF(5) */
+               GPIO_LOOKUP("GPF", 5, "cd", GPIO_ACTIVE_LOW),
+               /* Write protect S3C2410_GPH(8) */
+               GPIO_LOOKUP("GPH", 8, "wp", GPIO_ACTIVE_LOW),
+               { },
+       },
+};
+
 static struct mtd_partition rx1950_nand_part[] = {
        [0] = {
                        .name = "Boot0",
 static struct mtd_partition rx1950_nand_part[] = {
        [0] = {
                        .name = "Boot0",
@@ -762,6 +772,7 @@ static void __init rx1950_init_machine(void)
        s3c24xx_fb_set_platdata(&rx1950_lcd_cfg);
        s3c24xx_udc_set_platdata(&rx1950_udc_cfg);
        s3c24xx_ts_set_platdata(&rx1950_ts_cfg);
        s3c24xx_fb_set_platdata(&rx1950_lcd_cfg);
        s3c24xx_udc_set_platdata(&rx1950_udc_cfg);
        s3c24xx_ts_set_platdata(&rx1950_ts_cfg);
+       gpiod_add_lookup_table(&rx1950_mmc_gpio_table);
        s3c24xx_mci_set_platdata(&rx1950_mmc_cfg);
        s3c_i2c0_set_platdata(NULL);
        s3c_nand_set_platdata(&rx1950_nand_info);
        s3c24xx_mci_set_platdata(&rx1950_mmc_cfg);
        s3c_i2c0_set_platdata(NULL);
        s3c_nand_set_platdata(&rx1950_nand_info);
index f77493604312941d8b7985c756d7a94f93af1bc6..e1811ffd7b703230f080abd7ccd8f36cea2917b6 100644 (file)
@@ -26,7 +26,6 @@
 #include <linux/io.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/io.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
-#include <linux/of_gpio.h>
 #include <linux/mmc/slot-gpio.h>
 
 #include <plat/gpio-cfg.h>
 #include <linux/mmc/slot-gpio.h>
 
 #include <plat/gpio-cfg.h>
@@ -1545,25 +1544,19 @@ static int s3cmci_probe_pdata(struct s3cmci_host *host)
        if (pdata->wprotect_invert)
                mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
 
        if (pdata->wprotect_invert)
                mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
 
-       if (pdata->detect_invert)
-                mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
-
-       if (gpio_is_valid(pdata->gpio_detect)) {
-               ret = mmc_gpio_request_cd(mmc, pdata->gpio_detect, 0);
-               if (ret) {
-                       dev_err(&pdev->dev, "error requesting GPIO for CD %d\n",
-                               ret);
-                       return ret;
-               }
+       /* If we get -ENOENT we have no card detect GPIO line */
+       ret = mmc_gpiod_request_cd(mmc, "cd", 0, false, 0, NULL);
+       if (ret != -ENOENT) {
+               dev_err(&pdev->dev, "error requesting GPIO for CD %d\n",
+                       ret);
+               return ret;
        }
 
        }
 
-       if (gpio_is_valid(pdata->gpio_wprotect)) {
-               ret = mmc_gpio_request_ro(mmc, pdata->gpio_wprotect);
-               if (ret) {
-                       dev_err(&pdev->dev, "error requesting GPIO for WP %d\n",
-                               ret);
-                       return ret;
-               }
+       ret = mmc_gpiod_request_ro(host->mmc, "wp", 0, false, 0, NULL);
+       if (ret != -ENOENT) {
+               dev_err(&pdev->dev, "error requesting GPIO for WP %d\n",
+                       ret);
+               return ret;
        }
 
        return 0;
        }
 
        return 0;
index b68d9f0bdd9ebddc114982a157956b3b8bf80e31..33310b11cbddcf442122917a5e92a900ef7710e5 100644 (file)
@@ -7,7 +7,6 @@
  * @no_wprotect: Set this to indicate there is no write-protect switch.
  * @no_detect: Set this if there is no detect switch.
  * @wprotect_invert: Invert the default sense of the write protect switch.
  * @no_wprotect: Set this to indicate there is no write-protect switch.
  * @no_detect: Set this if there is no detect switch.
  * @wprotect_invert: Invert the default sense of the write protect switch.
- * @detect_invert: Invert the default sense of the write protect switch.
  * @use_dma: Set to allow the use of DMA.
  * @gpio_detect: GPIO number for the card detect line.
  * @gpio_wprotect: GPIO number for the write protect line.
  * @use_dma: Set to allow the use of DMA.
  * @gpio_detect: GPIO number for the card detect line.
  * @gpio_wprotect: GPIO number for the write protect line.
@@ -31,11 +30,8 @@ struct s3c24xx_mci_pdata {
        unsigned int    no_wprotect:1;
        unsigned int    no_detect:1;
        unsigned int    wprotect_invert:1;
        unsigned int    no_wprotect:1;
        unsigned int    no_detect:1;
        unsigned int    wprotect_invert:1;
-       unsigned int    detect_invert:1;        /* set => detect active high */
        unsigned int    use_dma:1;
 
        unsigned int    use_dma:1;
 
-       unsigned int    gpio_detect;
-       unsigned int    gpio_wprotect;
        unsigned long   ocr_avail;
        void            (*set_power)(unsigned char power_mode,
                                     unsigned short vdd);
        unsigned long   ocr_avail;
        void            (*set_power)(unsigned char power_mode,
                                     unsigned short vdd);