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

mmc: extend and rename cd-gpio helpers to handle more slot GPIO functions

GPIOs can be used in MMC/SD-card slots not only for hotplug detection, but
also to implement the write-protection pin. Rename cd-gpio helpers to
slot-gpio to make addition of further slot GPIO functions possible.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Chris Ball <cjb@laptop.org>

authored by

Guennadi Liakhovetski and committed by
Chris Ball
fd0ea65d 0f506a96

+32 -32
+1 -1
drivers/mmc/core/Makefile
··· 7 7 mmc.o mmc_ops.o sd.o sd_ops.o \ 8 8 sdio.o sdio_ops.o sdio_bus.o \ 9 9 sdio_cis.o sdio_io.o sdio_irq.o \ 10 - quirks.o cd-gpio.o 10 + quirks.o slot-gpio.o 11 11 12 12 mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o
+24 -24
drivers/mmc/core/cd-gpio.c drivers/mmc/core/slot-gpio.c
··· 12 12 #include <linux/gpio.h> 13 13 #include <linux/interrupt.h> 14 14 #include <linux/jiffies.h> 15 - #include <linux/mmc/cd-gpio.h> 16 15 #include <linux/mmc/host.h> 16 + #include <linux/mmc/slot-gpio.h> 17 17 #include <linux/module.h> 18 18 #include <linux/slab.h> 19 19 20 - struct mmc_cd_gpio { 21 - unsigned int gpio; 22 - char label[0]; 20 + struct mmc_gpio { 21 + unsigned int cd_gpio; 22 + char cd_label[0]; 23 23 }; 24 24 25 - static irqreturn_t mmc_cd_gpio_irqt(int irq, void *dev_id) 25 + static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id) 26 26 { 27 27 /* Schedule a card detection after a debounce timeout */ 28 28 mmc_detect_change(dev_id, msecs_to_jiffies(100)); 29 29 return IRQ_HANDLED; 30 30 } 31 31 32 - int mmc_cd_gpio_request(struct mmc_host *host, unsigned int gpio) 32 + int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio) 33 33 { 34 34 size_t len = strlen(dev_name(host->parent)) + 4; 35 - struct mmc_cd_gpio *cd; 35 + struct mmc_gpio *ctx; 36 36 int irq = gpio_to_irq(gpio); 37 37 int ret; 38 38 39 39 if (irq < 0) 40 40 return irq; 41 41 42 - cd = kmalloc(sizeof(*cd) + len, GFP_KERNEL); 43 - if (!cd) 42 + ctx = kmalloc(sizeof(*ctx) + len, GFP_KERNEL); 43 + if (!ctx) 44 44 return -ENOMEM; 45 45 46 - snprintf(cd->label, len, "%s cd", dev_name(host->parent)); 46 + snprintf(ctx->cd_label, len, "%s cd", dev_name(host->parent)); 47 47 48 - ret = gpio_request_one(gpio, GPIOF_DIR_IN, cd->label); 48 + ret = gpio_request_one(gpio, GPIOF_DIR_IN, ctx->cd_label); 49 49 if (ret < 0) 50 50 goto egpioreq; 51 51 52 - ret = request_threaded_irq(irq, NULL, mmc_cd_gpio_irqt, 53 - IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | 54 - IRQF_ONESHOT, cd->label, host); 52 + ret = request_threaded_irq(irq, NULL, mmc_gpio_cd_irqt, 53 + IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 54 + ctx->cd_label, host); 55 55 if (ret < 0) 56 56 goto eirqreq; 57 57 58 - cd->gpio = gpio; 58 + ctx->cd_gpio = gpio; 59 59 host->hotplug.irq = irq; 60 - host->hotplug.handler_priv = cd; 60 + host->hotplug.handler_priv = ctx; 61 61 62 62 return 0; 63 63 64 64 eirqreq: 65 65 gpio_free(gpio); 66 66 egpioreq: 67 - kfree(cd); 67 + kfree(ctx); 68 68 return ret; 69 69 } 70 - EXPORT_SYMBOL(mmc_cd_gpio_request); 70 + EXPORT_SYMBOL(mmc_gpio_request_cd); 71 71 72 - void mmc_cd_gpio_free(struct mmc_host *host) 72 + void mmc_gpio_free_cd(struct mmc_host *host) 73 73 { 74 - struct mmc_cd_gpio *cd = host->hotplug.handler_priv; 74 + struct mmc_gpio *ctx = host->hotplug.handler_priv; 75 75 76 - if (!cd) 76 + if (!ctx) 77 77 return; 78 78 79 79 free_irq(host->hotplug.irq, host); 80 - gpio_free(cd->gpio); 81 - kfree(cd); 80 + gpio_free(ctx->cd_gpio); 81 + kfree(ctx); 82 82 } 83 - EXPORT_SYMBOL(mmc_cd_gpio_free); 83 + EXPORT_SYMBOL(mmc_gpio_free_cd);
+3 -3
drivers/mmc/host/tmio_mmc_pio.c
··· 34 34 #include <linux/io.h> 35 35 #include <linux/irq.h> 36 36 #include <linux/mfd/tmio.h> 37 - #include <linux/mmc/cd-gpio.h> 38 37 #include <linux/mmc/host.h> 39 38 #include <linux/mmc/mmc.h> 39 + #include <linux/mmc/slot-gpio.h> 40 40 #include <linux/mmc/tmio.h> 41 41 #include <linux/module.h> 42 42 #include <linux/pagemap.h> ··· 977 977 tmio_mmc_enable_mmc_irqs(_host, irq_mask); 978 978 979 979 if (pdata->flags & TMIO_MMC_USE_GPIO_CD) { 980 - ret = mmc_cd_gpio_request(mmc, pdata->cd_gpio); 980 + ret = mmc_gpio_request_cd(mmc, pdata->cd_gpio); 981 981 if (ret < 0) { 982 982 tmio_mmc_host_remove(_host); 983 983 return ret; ··· 1009 1009 * This means we can miss a card-eject, but this is anyway 1010 1010 * possible, because of delayed processing of hotplug events. 1011 1011 */ 1012 - mmc_cd_gpio_free(mmc); 1012 + mmc_gpio_free_cd(mmc); 1013 1013 1014 1014 if (!host->native_hotplug) 1015 1015 pm_runtime_get_sync(&pdev->dev);
+4 -4
include/linux/mmc/cd-gpio.h include/linux/mmc/slot-gpio.h
··· 8 8 * published by the Free Software Foundation. 9 9 */ 10 10 11 - #ifndef MMC_CD_GPIO_H 12 - #define MMC_CD_GPIO_H 11 + #ifndef MMC_SLOT_GPIO_H 12 + #define MMC_SLOT_GPIO_H 13 13 14 14 struct mmc_host; 15 - int mmc_cd_gpio_request(struct mmc_host *host, unsigned int gpio); 16 - void mmc_cd_gpio_free(struct mmc_host *host); 15 + int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio); 16 + void mmc_gpio_free_cd(struct mmc_host *host); 17 17 18 18 #endif