Commit befe4048 authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Chris Ball

mmc: add CD GPIO polling support to slot functions

A simple extension of mmc slot functions add support for CD GPIO polling
for cases where the GPIO cannot produce interrupts, or where this is not
desired for some reason.
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: default avatarChris Ball <cjb@laptop.org>
parent 5c08d7fa
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <linux/slab.h> #include <linux/slab.h>
struct mmc_gpio { struct mmc_gpio {
unsigned int cd_gpio; int cd_gpio;
char cd_label[0]; char cd_label[0];
}; };
...@@ -29,6 +29,18 @@ static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id) ...@@ -29,6 +29,18 @@ static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
int mmc_gpio_get_cd(struct mmc_host *host)
{
struct mmc_gpio *ctx = host->slot.handler_priv;
if (!ctx || !gpio_is_valid(ctx->cd_gpio))
return -ENOSYS;
return !gpio_get_value_cansleep(ctx->cd_gpio) ^
!!(host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH);
}
EXPORT_SYMBOL(mmc_gpio_get_cd);
int mmc_gpio_request_cd(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;
...@@ -36,9 +48,6 @@ int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio) ...@@ -36,9 +48,6 @@ int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio)
int irq = gpio_to_irq(gpio); int irq = gpio_to_irq(gpio);
int ret; int ret;
if (irq < 0)
return irq;
ctx = kmalloc(sizeof(*ctx) + len, GFP_KERNEL); ctx = kmalloc(sizeof(*ctx) + len, GFP_KERNEL);
if (!ctx) if (!ctx)
return -ENOMEM; return -ENOMEM;
...@@ -49,20 +58,32 @@ int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio) ...@@ -49,20 +58,32 @@ int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio)
if (ret < 0) if (ret < 0)
goto egpioreq; goto egpioreq;
ret = request_threaded_irq(irq, NULL, mmc_gpio_cd_irqt, /*
* Even if gpio_to_irq() returns a valid IRQ number, the platform might
* still prefer to poll, e.g., because that IRQ number is already used
* by another unit and cannot be shared.
*/
if (irq >= 0 && host->caps & MMC_CAP_NEEDS_POLL)
irq = -EINVAL;
if (irq >= 0) {
ret = request_threaded_irq(irq, NULL, mmc_gpio_cd_irqt,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
ctx->cd_label, host); ctx->cd_label, host);
if (ret < 0) if (ret < 0)
goto eirqreq; irq = ret;
}
ctx->cd_gpio = gpio;
host->slot.cd_irq = irq; host->slot.cd_irq = irq;
if (irq < 0)
host->caps |= MMC_CAP_NEEDS_POLL;
ctx->cd_gpio = gpio;
host->slot.handler_priv = ctx; host->slot.handler_priv = ctx;
return 0; return 0;
eirqreq:
gpio_free(gpio);
egpioreq: egpioreq:
kfree(ctx); kfree(ctx);
return ret; return ret;
...@@ -72,12 +93,21 @@ EXPORT_SYMBOL(mmc_gpio_request_cd); ...@@ -72,12 +93,21 @@ EXPORT_SYMBOL(mmc_gpio_request_cd);
void mmc_gpio_free_cd(struct mmc_host *host) void mmc_gpio_free_cd(struct mmc_host *host)
{ {
struct mmc_gpio *ctx = host->slot.handler_priv; struct mmc_gpio *ctx = host->slot.handler_priv;
int gpio;
if (!ctx) if (!ctx || !gpio_is_valid(ctx->cd_gpio))
return; return;
free_irq(host->slot.cd_irq, host); if (host->slot.cd_irq >= 0) {
gpio_free(ctx->cd_gpio); free_irq(host->slot.cd_irq, host);
host->slot.cd_irq = -EINVAL;
}
gpio = ctx->cd_gpio;
ctx->cd_gpio = -EINVAL;
gpio_free(gpio);
host->slot.handler_priv = NULL;
kfree(ctx); kfree(ctx);
} }
EXPORT_SYMBOL(mmc_gpio_free_cd); EXPORT_SYMBOL(mmc_gpio_free_cd);
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#define MMC_SLOT_GPIO_H #define MMC_SLOT_GPIO_H
struct mmc_host; struct mmc_host;
int mmc_gpio_get_cd(struct mmc_host *host);
int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio); int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio);
void mmc_gpio_free_cd(struct mmc_host *host); void mmc_gpio_free_cd(struct mmc_host *host);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment