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>
This commit is contained in:
		
					parent
					
						
							
								0f506a9669
							
						
					
				
			
			
				commit
				
					
						fd0ea65d3e
					
				
			
		
					 4 changed files with 32 additions and 32 deletions
				
			
		| 
						 | 
					@ -7,6 +7,6 @@ mmc_core-y			:= core.o bus.o host.o \
 | 
				
			||||||
				   mmc.o mmc_ops.o sd.o sd_ops.o \
 | 
									   mmc.o mmc_ops.o sd.o sd_ops.o \
 | 
				
			||||||
				   sdio.o sdio_ops.o sdio_bus.o \
 | 
									   sdio.o sdio_ops.o sdio_bus.o \
 | 
				
			||||||
				   sdio_cis.o sdio_io.o sdio_irq.o \
 | 
									   sdio_cis.o sdio_io.o sdio_irq.o \
 | 
				
			||||||
				   quirks.o cd-gpio.o
 | 
									   quirks.o slot-gpio.o
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mmc_core-$(CONFIG_DEBUG_FS)	+= debugfs.o
 | 
					mmc_core-$(CONFIG_DEBUG_FS)	+= debugfs.o
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,72 +12,72 @@
 | 
				
			||||||
#include <linux/gpio.h>
 | 
					#include <linux/gpio.h>
 | 
				
			||||||
#include <linux/interrupt.h>
 | 
					#include <linux/interrupt.h>
 | 
				
			||||||
#include <linux/jiffies.h>
 | 
					#include <linux/jiffies.h>
 | 
				
			||||||
#include <linux/mmc/cd-gpio.h>
 | 
					 | 
				
			||||||
#include <linux/mmc/host.h>
 | 
					#include <linux/mmc/host.h>
 | 
				
			||||||
 | 
					#include <linux/mmc/slot-gpio.h>
 | 
				
			||||||
#include <linux/module.h>
 | 
					#include <linux/module.h>
 | 
				
			||||||
#include <linux/slab.h>
 | 
					#include <linux/slab.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct mmc_cd_gpio {
 | 
					struct mmc_gpio {
 | 
				
			||||||
	unsigned int gpio;
 | 
						unsigned int cd_gpio;
 | 
				
			||||||
	char label[0];
 | 
						char cd_label[0];
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static irqreturn_t mmc_cd_gpio_irqt(int irq, void *dev_id)
 | 
					static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/* Schedule a card detection after a debounce timeout */
 | 
						/* Schedule a card detection after a debounce timeout */
 | 
				
			||||||
	mmc_detect_change(dev_id, msecs_to_jiffies(100));
 | 
						mmc_detect_change(dev_id, msecs_to_jiffies(100));
 | 
				
			||||||
	return IRQ_HANDLED;
 | 
						return IRQ_HANDLED;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int mmc_cd_gpio_request(struct mmc_host *host, unsigned int gpio)
 | 
					int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	size_t len = strlen(dev_name(host->parent)) + 4;
 | 
						size_t len = strlen(dev_name(host->parent)) + 4;
 | 
				
			||||||
	struct mmc_cd_gpio *cd;
 | 
						struct mmc_gpio *ctx;
 | 
				
			||||||
	int irq = gpio_to_irq(gpio);
 | 
						int irq = gpio_to_irq(gpio);
 | 
				
			||||||
	int ret;
 | 
						int ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (irq < 0)
 | 
						if (irq < 0)
 | 
				
			||||||
		return irq;
 | 
							return irq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cd = kmalloc(sizeof(*cd) + len, GFP_KERNEL);
 | 
						ctx = kmalloc(sizeof(*ctx) + len, GFP_KERNEL);
 | 
				
			||||||
	if (!cd)
 | 
						if (!ctx)
 | 
				
			||||||
		return -ENOMEM;
 | 
							return -ENOMEM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	snprintf(cd->label, len, "%s cd", dev_name(host->parent));
 | 
						snprintf(ctx->cd_label, len, "%s cd", dev_name(host->parent));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = gpio_request_one(gpio, GPIOF_DIR_IN, cd->label);
 | 
						ret = gpio_request_one(gpio, GPIOF_DIR_IN, ctx->cd_label);
 | 
				
			||||||
	if (ret < 0)
 | 
						if (ret < 0)
 | 
				
			||||||
		goto egpioreq;
 | 
							goto egpioreq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = request_threaded_irq(irq, NULL, mmc_cd_gpio_irqt,
 | 
						ret = request_threaded_irq(irq, NULL, mmc_gpio_cd_irqt,
 | 
				
			||||||
				   IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
 | 
								IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
 | 
				
			||||||
				   IRQF_ONESHOT, cd->label, host);
 | 
								ctx->cd_label, host);
 | 
				
			||||||
	if (ret < 0)
 | 
						if (ret < 0)
 | 
				
			||||||
		goto eirqreq;
 | 
							goto eirqreq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cd->gpio = gpio;
 | 
						ctx->cd_gpio = gpio;
 | 
				
			||||||
	host->hotplug.irq = irq;
 | 
						host->hotplug.irq = irq;
 | 
				
			||||||
	host->hotplug.handler_priv = cd;
 | 
						host->hotplug.handler_priv = ctx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
eirqreq:
 | 
					eirqreq:
 | 
				
			||||||
	gpio_free(gpio);
 | 
						gpio_free(gpio);
 | 
				
			||||||
egpioreq:
 | 
					egpioreq:
 | 
				
			||||||
	kfree(cd);
 | 
						kfree(ctx);
 | 
				
			||||||
	return ret;
 | 
						return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL(mmc_cd_gpio_request);
 | 
					EXPORT_SYMBOL(mmc_gpio_request_cd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mmc_cd_gpio_free(struct mmc_host *host)
 | 
					void mmc_gpio_free_cd(struct mmc_host *host)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct mmc_cd_gpio *cd = host->hotplug.handler_priv;
 | 
						struct mmc_gpio *ctx = host->hotplug.handler_priv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!cd)
 | 
						if (!ctx)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	free_irq(host->hotplug.irq, host);
 | 
						free_irq(host->hotplug.irq, host);
 | 
				
			||||||
	gpio_free(cd->gpio);
 | 
						gpio_free(ctx->cd_gpio);
 | 
				
			||||||
	kfree(cd);
 | 
						kfree(ctx);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL(mmc_cd_gpio_free);
 | 
					EXPORT_SYMBOL(mmc_gpio_free_cd);
 | 
				
			||||||
| 
						 | 
					@ -34,9 +34,9 @@
 | 
				
			||||||
#include <linux/io.h>
 | 
					#include <linux/io.h>
 | 
				
			||||||
#include <linux/irq.h>
 | 
					#include <linux/irq.h>
 | 
				
			||||||
#include <linux/mfd/tmio.h>
 | 
					#include <linux/mfd/tmio.h>
 | 
				
			||||||
#include <linux/mmc/cd-gpio.h>
 | 
					 | 
				
			||||||
#include <linux/mmc/host.h>
 | 
					#include <linux/mmc/host.h>
 | 
				
			||||||
#include <linux/mmc/mmc.h>
 | 
					#include <linux/mmc/mmc.h>
 | 
				
			||||||
 | 
					#include <linux/mmc/slot-gpio.h>
 | 
				
			||||||
#include <linux/mmc/tmio.h>
 | 
					#include <linux/mmc/tmio.h>
 | 
				
			||||||
#include <linux/module.h>
 | 
					#include <linux/module.h>
 | 
				
			||||||
#include <linux/pagemap.h>
 | 
					#include <linux/pagemap.h>
 | 
				
			||||||
| 
						 | 
					@ -977,7 +977,7 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
 | 
				
			||||||
	tmio_mmc_enable_mmc_irqs(_host, irq_mask);
 | 
						tmio_mmc_enable_mmc_irqs(_host, irq_mask);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (pdata->flags & TMIO_MMC_USE_GPIO_CD) {
 | 
						if (pdata->flags & TMIO_MMC_USE_GPIO_CD) {
 | 
				
			||||||
		ret = mmc_cd_gpio_request(mmc, pdata->cd_gpio);
 | 
							ret = mmc_gpio_request_cd(mmc, pdata->cd_gpio);
 | 
				
			||||||
		if (ret < 0) {
 | 
							if (ret < 0) {
 | 
				
			||||||
			tmio_mmc_host_remove(_host);
 | 
								tmio_mmc_host_remove(_host);
 | 
				
			||||||
			return ret;
 | 
								return ret;
 | 
				
			||||||
| 
						 | 
					@ -1009,7 +1009,7 @@ void tmio_mmc_host_remove(struct tmio_mmc_host *host)
 | 
				
			||||||
		 * This means we can miss a card-eject, but this is anyway
 | 
							 * This means we can miss a card-eject, but this is anyway
 | 
				
			||||||
		 * possible, because of delayed processing of hotplug events.
 | 
							 * possible, because of delayed processing of hotplug events.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		mmc_cd_gpio_free(mmc);
 | 
							mmc_gpio_free_cd(mmc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!host->native_hotplug)
 | 
						if (!host->native_hotplug)
 | 
				
			||||||
		pm_runtime_get_sync(&pdev->dev);
 | 
							pm_runtime_get_sync(&pdev->dev);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,11 +8,11 @@
 | 
				
			||||||
 * published by the Free Software Foundation.
 | 
					 * published by the Free Software Foundation.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef MMC_CD_GPIO_H
 | 
					#ifndef MMC_SLOT_GPIO_H
 | 
				
			||||||
#define MMC_CD_GPIO_H
 | 
					#define MMC_SLOT_GPIO_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct mmc_host;
 | 
					struct mmc_host;
 | 
				
			||||||
int mmc_cd_gpio_request(struct mmc_host *host, unsigned int gpio);
 | 
					int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio);
 | 
				
			||||||
void mmc_cd_gpio_free(struct mmc_host *host);
 | 
					void mmc_gpio_free_cd(struct mmc_host *host);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue