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

mmc: mmc_spi: Support CD/RO GPIOs

Add support for passing CD/RO GPIO numbers directly to the mmc_spi
driver instead of relying solely on board code callbacks to retrieve the
CD/RO signals values. The driver will enable debouncing on the card
detect GPIO if the cd_debounce field is set to a non-zero value.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Chris Ball <cjb@laptop.org>

authored by

Laurent Pinchart and committed by
Chris Ball
bf287a90 214fc309

+52 -43
+24 -9
drivers/mmc/host/mmc_spi.c
··· 36 36 37 37 #include <linux/mmc/host.h> 38 38 #include <linux/mmc/mmc.h> /* for R1_SPI_* bit values */ 39 + #include <linux/mmc/slot-gpio.h> 39 40 40 41 #include <linux/spi/spi.h> 41 42 #include <linux/spi/mmc_spi.h> ··· 1279 1278 1280 1279 if (host->pdata && host->pdata->get_ro) 1281 1280 return !!host->pdata->get_ro(mmc->parent); 1282 - /* 1283 - * Board doesn't support read only detection; let the mmc core 1284 - * decide what to do. 1285 - */ 1286 - return -ENOSYS; 1281 + else 1282 + return mmc_gpio_get_ro(mmc); 1287 1283 } 1288 1284 1289 1285 static int mmc_spi_get_cd(struct mmc_host *mmc) ··· 1289 1291 1290 1292 if (host->pdata && host->pdata->get_cd) 1291 1293 return !!host->pdata->get_cd(mmc->parent); 1292 - return -ENOSYS; 1294 + else 1295 + return mmc_gpio_get_cd(mmc); 1293 1296 } 1294 1297 1295 1298 static const struct mmc_host_ops mmc_spi_ops = { ··· 1323 1324 struct mmc_host *mmc; 1324 1325 struct mmc_spi_host *host; 1325 1326 int status; 1327 + bool has_ro = false; 1326 1328 1327 1329 /* We rely on full duplex transfers, mostly to reduce 1328 1330 * per-transfer overheads (by making fewer transfers). ··· 1448 1448 } 1449 1449 1450 1450 /* pass platform capabilities, if any */ 1451 - if (host->pdata) 1451 + if (host->pdata) { 1452 1452 mmc->caps |= host->pdata->caps; 1453 + mmc->caps2 |= host->pdata->caps2; 1454 + } 1453 1455 1454 1456 status = mmc_add_host(mmc); 1455 1457 if (status != 0) 1456 1458 goto fail_add_host; 1457 1459 1460 + if (host->pdata && host->pdata->flags & MMC_SPI_USE_CD_GPIO) { 1461 + status = mmc_gpio_request_cd(mmc, host->pdata->cd_gpio, 1462 + host->pdata->cd_debounce); 1463 + if (status != 0) 1464 + goto fail_add_host; 1465 + } 1466 + 1467 + if (host->pdata && host->pdata->flags & MMC_SPI_USE_RO_GPIO) { 1468 + has_ro = true; 1469 + status = mmc_gpio_request_ro(mmc, host->pdata->ro_gpio); 1470 + if (status != 0) 1471 + goto fail_add_host; 1472 + } 1473 + 1458 1474 dev_info(&spi->dev, "SD/MMC host %s%s%s%s%s\n", 1459 1475 dev_name(&mmc->class_dev), 1460 1476 host->dma_dev ? "" : ", no DMA", 1461 - (host->pdata && host->pdata->get_ro) 1462 - ? "" : ", no WP", 1477 + has_ro ? "" : ", no WP", 1463 1478 (host->pdata && host->pdata->setpower) 1464 1479 ? "" : ", no poweroff", 1465 1480 (mmc->caps & MMC_CAP_NEEDS_POLL)
+12 -34
drivers/mmc/host/of_mmc_spi.c
··· 50 50 return container_of(dev->platform_data, struct of_mmc_spi, pdata); 51 51 } 52 52 53 - static int of_mmc_spi_read_gpio(struct device *dev, int gpio_num) 54 - { 55 - struct of_mmc_spi *oms = to_of_mmc_spi(dev); 56 - bool active_low = oms->alow_gpios[gpio_num]; 57 - bool value = gpio_get_value(oms->gpios[gpio_num]); 58 - 59 - return active_low ^ value; 60 - } 61 - 62 - static int of_mmc_spi_get_cd(struct device *dev) 63 - { 64 - return of_mmc_spi_read_gpio(dev, CD_GPIO); 65 - } 66 - 67 - static int of_mmc_spi_get_ro(struct device *dev) 68 - { 69 - return of_mmc_spi_read_gpio(dev, WP_GPIO); 70 - } 71 - 72 53 static int of_mmc_spi_init(struct device *dev, 73 54 irqreturn_t (*irqhandler)(int, void *), void *mmc) 74 55 { ··· 111 130 if (!gpio_is_valid(oms->gpios[i])) 112 131 continue; 113 132 114 - ret = gpio_request(oms->gpios[i], dev_name(dev)); 115 - if (ret < 0) { 116 - oms->gpios[i] = -EINVAL; 117 - continue; 118 - } 119 - 120 133 if (gpio_flags & OF_GPIO_ACTIVE_LOW) 121 134 oms->alow_gpios[i] = true; 122 135 } 123 136 124 - if (gpio_is_valid(oms->gpios[CD_GPIO])) 125 - oms->pdata.get_cd = of_mmc_spi_get_cd; 126 - if (gpio_is_valid(oms->gpios[WP_GPIO])) 127 - oms->pdata.get_ro = of_mmc_spi_get_ro; 137 + if (gpio_is_valid(oms->gpios[CD_GPIO])) { 138 + oms->pdata.cd_gpio = oms->gpios[CD_GPIO]; 139 + oms->pdata.flags |= MMC_SPI_USE_CD_GPIO; 140 + if (!oms->alow_gpios[CD_GPIO]) 141 + oms->pdata.caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; 142 + } 143 + if (gpio_is_valid(oms->gpios[WP_GPIO])) { 144 + oms->pdata.ro_gpio = oms->gpios[WP_GPIO]; 145 + oms->pdata.flags |= MMC_SPI_USE_RO_GPIO; 146 + if (!oms->alow_gpios[WP_GPIO]) 147 + oms->pdata.caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; 148 + } 128 149 129 150 oms->detect_irq = irq_of_parse_and_map(np, 0); 130 151 if (oms->detect_irq != 0) { ··· 149 166 struct device *dev = &spi->dev; 150 167 struct device_node *np = dev->of_node; 151 168 struct of_mmc_spi *oms = to_of_mmc_spi(dev); 152 - int i; 153 169 154 170 if (!dev->platform_data || !np) 155 171 return; 156 172 157 - for (i = 0; i < ARRAY_SIZE(oms->gpios); i++) { 158 - if (gpio_is_valid(oms->gpios[i])) 159 - gpio_free(oms->gpios[i]); 160 - } 161 173 kfree(oms); 162 174 dev->platform_data = NULL; 163 175 }
+16
include/linux/spi/mmc_spi.h
··· 7 7 struct device; 8 8 struct mmc_host; 9 9 10 + #define MMC_SPI_USE_CD_GPIO (1 << 0) 11 + #define MMC_SPI_USE_RO_GPIO (1 << 1) 12 + #define MMC_SPI_CD_GPIO_ACTIVE_LOW (1 << 2) 13 + #define MMC_SPI_RO_GPIO_ACTIVE_LOW (1 << 3) 14 + 10 15 /* Put this in platform_data of a device being used to manage an MMC/SD 11 16 * card slot. (Modeled after PXA mmc glue; see that for usage examples.) 12 17 * ··· 35 30 */ 36 31 int (*get_cd)(struct device *); 37 32 33 + /* 34 + * Card Detect and Read Only GPIOs. To enable debouncing on the card 35 + * detect GPIO, set the cd_debounce to the debounce time in 36 + * microseconds. 37 + */ 38 + unsigned int flags; 39 + unsigned int cd_gpio; 40 + unsigned int cd_debounce; 41 + unsigned int ro_gpio; 42 + 38 43 /* Capabilities to pass into mmc core (e.g. MMC_CAP_NEEDS_POLL). */ 39 44 unsigned long caps; 45 + unsigned long caps2; 40 46 41 47 /* how long to debounce card detect, in msecs */ 42 48 u16 detect_delay;