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

mmc: spi: Convert to use GPIO descriptors

Switch the SPI MMC driver to use GPIO descriptors internally
and just look those up using the standard slot GPIO
functions mmc_gpiod_request_cd() and mmc_gpiod_request_ro().
Make sure to request index 0 and 1 in accordance with the
SPI MMC DT binding, and add the same GPIOs in machine
descriptor tables on all boards that use SPI MMC in
board files.

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: Hartley Sweeten <hsweeten@visionengravers.com> # Vision EP9307
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Linus Walleij and committed by
Ulf Hansson
5716fb9b b0d06f1c

+53 -71
+11 -3
arch/arm/mach-ep93xx/simone.c
··· 25 25 #include <linux/platform_data/video-ep93xx.h> 26 26 #include <linux/platform_data/spi-ep93xx.h> 27 27 #include <linux/gpio.h> 28 + #include <linux/gpio/machine.h> 28 29 29 30 #include <mach/hardware.h> 30 31 #include <mach/gpio-ep93xx.h> ··· 46 45 static struct mmc_spi_platform_data simone_mmc_spi_data = { 47 46 .detect_delay = 500, 48 47 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, 49 - .flags = MMC_SPI_USE_CD_GPIO, 50 - .cd_gpio = EP93XX_GPIO_LINE_EGPIO0, 51 - .cd_debounce = 1, 48 + }; 49 + 50 + static struct gpiod_lookup_table simone_mmc_spi_gpio_table = { 51 + .dev_id = "mmc_spi.0", /* "mmc_spi" @ CS0 */ 52 + .table = { 53 + /* Card detect */ 54 + GPIO_LOOKUP_IDX("A", 0, NULL, 0, GPIO_ACTIVE_LOW), 55 + { }, 56 + }, 52 57 }; 53 58 54 59 static struct spi_board_info simone_spi_devices[] __initdata = { ··· 112 105 ep93xx_register_fb(&simone_fb_info); 113 106 ep93xx_register_i2c(simone_i2c_board_info, 114 107 ARRAY_SIZE(simone_i2c_board_info)); 108 + gpiod_add_lookup_table(&simone_mmc_spi_gpio_table); 115 109 ep93xx_register_spi(&simone_spi_info, simone_spi_devices, 116 110 ARRAY_SIZE(simone_spi_devices)); 117 111 simone_register_audio();
+13 -4
arch/arm/mach-ep93xx/vision_ep9307.c
··· 18 18 #include <linux/platform_device.h> 19 19 #include <linux/irq.h> 20 20 #include <linux/gpio.h> 21 + #include <linux/gpio/machine.h> 21 22 #include <linux/fb.h> 22 23 #include <linux/io.h> 23 24 #include <linux/mtd/partitions.h> ··· 203 202 .detect_delay = 100, 204 203 .powerup_msecs = 100, 205 204 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, 206 - .flags = MMC_SPI_USE_CD_GPIO | MMC_SPI_USE_RO_GPIO, 207 - .cd_gpio = EP93XX_GPIO_LINE_EGPIO15, 208 - .cd_debounce = 1, 209 - .ro_gpio = EP93XX_GPIO_LINE_F(0), 210 205 .caps2 = MMC_CAP2_RO_ACTIVE_HIGH, 206 + }; 207 + 208 + static struct gpiod_lookup_table vision_spi_mmc_gpio_table = { 209 + .dev_id = "mmc_spi.2", /* "mmc_spi @ CS2 */ 210 + .table = { 211 + /* Card detect */ 212 + GPIO_LOOKUP_IDX("B", 7, NULL, 0, GPIO_ACTIVE_LOW), 213 + /* Write protect */ 214 + GPIO_LOOKUP_IDX("F", 0, NULL, 1, GPIO_ACTIVE_HIGH), 215 + { }, 216 + }, 211 217 }; 212 218 213 219 /************************************************************************* ··· 294 286 295 287 ep93xx_register_i2c(vision_i2c_info, 296 288 ARRAY_SIZE(vision_i2c_info)); 289 + gpiod_add_lookup_table(&vision_spi_mmc_gpio_table); 297 290 ep93xx_register_spi(&vision_spi_master, vision_spi_board_info, 298 291 ARRAY_SIZE(vision_spi_board_info)); 299 292 vision_register_i2s();
+14 -3
arch/sh/boards/mach-ecovec24/setup.c
··· 776 776 .caps2 = MMC_CAP2_RO_ACTIVE_HIGH, 777 777 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, /* 3.3V only */ 778 778 .setpower = mmc_spi_setpower, 779 - .flags = MMC_SPI_USE_CD_GPIO | MMC_SPI_USE_RO_GPIO, 780 - .cd_gpio = GPIO_PTY7, 781 - .ro_gpio = GPIO_PTY6, 779 + }; 780 + 781 + static struct gpiod_lookup_table mmc_spi_gpio_table = { 782 + .dev_id = "mmc_spi.0", /* device "mmc_spi" @ CS0 */ 783 + .table = { 784 + /* Card detect */ 785 + GPIO_LOOKUP_IDX("sh7724_pfc", GPIO_PTY7, NULL, 0, 786 + GPIO_ACTIVE_LOW), 787 + /* Write protect */ 788 + GPIO_LOOKUP_IDX("sh7724_pfc", GPIO_PTY6, NULL, 1, 789 + GPIO_ACTIVE_HIGH), 790 + { }, 791 + }, 782 792 }; 783 793 784 794 static struct spi_board_info spi_bus[] = { ··· 1292 1282 gpio_request(GPIO_PTB6, NULL); /* 3.3V power control */ 1293 1283 gpio_direction_output(GPIO_PTB6, 0); /* disable power by default */ 1294 1284 1285 + gpiod_add_lookup_table(&mmc_spi_gpio_table); 1295 1286 spi_register_board_info(spi_bus, ARRAY_SIZE(spi_bus)); 1296 1287 #endif 1297 1288
+15 -12
drivers/mmc/host/mmc_spi.c
··· 1434 1434 if (status != 0) 1435 1435 goto fail_add_host; 1436 1436 1437 - if (host->pdata && host->pdata->flags & MMC_SPI_USE_CD_GPIO) { 1438 - status = mmc_gpio_request_cd(mmc, host->pdata->cd_gpio, 1439 - host->pdata->cd_debounce); 1440 - if (status != 0) 1441 - goto fail_add_host; 1442 - 1443 - /* The platform has a CD GPIO signal that may support 1437 + /* 1438 + * Index 0 is card detect 1439 + * Old boardfiles were specifying 1 ms as debounce 1440 + */ 1441 + status = mmc_gpiod_request_cd(mmc, NULL, 0, false, 1, NULL); 1442 + if (status == -EPROBE_DEFER) 1443 + goto fail_add_host; 1444 + if (!status) { 1445 + /* 1446 + * The platform has a CD GPIO signal that may support 1444 1447 * interrupts, so let mmc_gpiod_request_cd_irq() decide 1445 1448 * if polling is needed or not. 1446 1449 */ ··· 1451 1448 mmc_gpiod_request_cd_irq(mmc); 1452 1449 } 1453 1450 1454 - if (host->pdata && host->pdata->flags & MMC_SPI_USE_RO_GPIO) { 1451 + /* Index 1 is write protect/read only */ 1452 + status = mmc_gpiod_request_ro(mmc, NULL, 1, false, 0, NULL); 1453 + if (status == -EPROBE_DEFER) 1454 + goto fail_add_host; 1455 + if (!status) 1455 1456 has_ro = true; 1456 - status = mmc_gpio_request_ro(mmc, host->pdata->ro_gpio); 1457 - if (status != 0) 1458 - goto fail_add_host; 1459 - } 1460 1457 1461 1458 dev_info(&spi->dev, "SD/MMC host %s%s%s%s%s\n", 1462 1459 dev_name(&mmc->class_dev),
-34
drivers/mmc/host/of_mmc_spi.c
··· 16 16 #include <linux/device.h> 17 17 #include <linux/slab.h> 18 18 #include <linux/irq.h> 19 - #include <linux/gpio.h> 20 19 #include <linux/of.h> 21 - #include <linux/of_gpio.h> 22 20 #include <linux/of_irq.h> 23 21 #include <linux/spi/spi.h> 24 22 #include <linux/spi/mmc_spi.h> ··· 30 32 31 33 MODULE_LICENSE("GPL"); 32 34 33 - enum { 34 - CD_GPIO = 0, 35 - WP_GPIO, 36 - NUM_GPIOS, 37 - }; 38 - 39 35 struct of_mmc_spi { 40 - int gpios[NUM_GPIOS]; 41 - bool alow_gpios[NUM_GPIOS]; 42 36 int detect_irq; 43 37 struct mmc_spi_platform_data pdata; 44 38 }; ··· 90 100 goto err_ocr; 91 101 } 92 102 oms->pdata.ocr_mask |= mask; 93 - } 94 - 95 - for (i = 0; i < ARRAY_SIZE(oms->gpios); i++) { 96 - enum of_gpio_flags gpio_flags; 97 - 98 - oms->gpios[i] = of_get_gpio_flags(np, i, &gpio_flags); 99 - if (!gpio_is_valid(oms->gpios[i])) 100 - continue; 101 - 102 - if (gpio_flags & OF_GPIO_ACTIVE_LOW) 103 - oms->alow_gpios[i] = true; 104 - } 105 - 106 - if (gpio_is_valid(oms->gpios[CD_GPIO])) { 107 - oms->pdata.cd_gpio = oms->gpios[CD_GPIO]; 108 - oms->pdata.flags |= MMC_SPI_USE_CD_GPIO; 109 - if (!oms->alow_gpios[CD_GPIO]) 110 - oms->pdata.caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; 111 - } 112 - if (gpio_is_valid(oms->gpios[WP_GPIO])) { 113 - oms->pdata.ro_gpio = oms->gpios[WP_GPIO]; 114 - oms->pdata.flags |= MMC_SPI_USE_RO_GPIO; 115 - if (!oms->alow_gpios[WP_GPIO]) 116 - oms->pdata.caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; 117 103 } 118 104 119 105 oms->detect_irq = irq_of_parse_and_map(np, 0);
-15
include/linux/spi/mmc_spi.h
··· 8 8 struct device; 9 9 struct mmc_host; 10 10 11 - #define MMC_SPI_USE_CD_GPIO (1 << 0) 12 - #define MMC_SPI_USE_RO_GPIO (1 << 1) 13 - #define MMC_SPI_CD_GPIO_ACTIVE_LOW (1 << 2) 14 - #define MMC_SPI_RO_GPIO_ACTIVE_LOW (1 << 3) 15 - 16 11 /* Put this in platform_data of a device being used to manage an MMC/SD 17 12 * card slot. (Modeled after PXA mmc glue; see that for usage examples.) 18 13 * ··· 21 26 irqreturn_t (*)(int, void *), 22 27 void *); 23 28 void (*exit)(struct device *, void *); 24 - 25 - /* 26 - * Card Detect and Read Only GPIOs. To enable debouncing on the card 27 - * detect GPIO, set the cd_debounce to the debounce time in 28 - * microseconds. 29 - */ 30 - unsigned int flags; 31 - unsigned int cd_gpio; 32 - unsigned int cd_debounce; 33 - unsigned int ro_gpio; 34 29 35 30 /* Capabilities to pass into mmc core (e.g. MMC_CAP_NEEDS_POLL). */ 36 31 unsigned long caps;