Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 312827
b: refs/heads/master
c: 5aa7dad
h: refs/heads/master
i:
  312825: ca93142
  312823: 95d1642
v: v3
  • Loading branch information
Guennadi Liakhovetski authored and Chris Ball committed Jul 21, 2012
1 parent 41180a1 commit c728b35
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a7d1a1ebd8f5858a812ac3d5fbbc178b4959a63b
refs/heads/master: 5aa7dad305594ea30d21e23b3036565042adf50c
52 changes: 51 additions & 1 deletion trunk/drivers/mmc/core/slot-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#include <linux/slab.h>

struct mmc_gpio {
int ro_gpio;
int cd_gpio;
char *ro_label;
char cd_label[0];
};

Expand All @@ -43,11 +45,14 @@ static int mmc_gpio_alloc(struct mmc_host *host)
* before device_add(), i.e., between mmc_alloc_host() and
* mmc_add_host()
*/
ctx = devm_kzalloc(&host->class_dev, sizeof(*ctx) + len,
ctx = devm_kzalloc(&host->class_dev, sizeof(*ctx) + 2 * len,
GFP_KERNEL);
if (ctx) {
ctx->ro_label = ctx->cd_label + len;
snprintf(ctx->cd_label, len, "%s cd", dev_name(host->parent));
snprintf(ctx->ro_label, len, "%s ro", dev_name(host->parent));
ctx->cd_gpio = -EINVAL;
ctx->ro_gpio = -EINVAL;
host->slot.handler_priv = ctx;
}
}
Expand All @@ -57,6 +62,18 @@ static int mmc_gpio_alloc(struct mmc_host *host)
return ctx ? 0 : -ENOMEM;
}

int mmc_gpio_get_ro(struct mmc_host *host)
{
struct mmc_gpio *ctx = host->slot.handler_priv;

if (!ctx || !gpio_is_valid(ctx->ro_gpio))
return -ENOSYS;

return !gpio_get_value_cansleep(ctx->ro_gpio) ^
!!(host->caps2 & MMC_CAP2_RO_ACTIVE_HIGH);
}
EXPORT_SYMBOL(mmc_gpio_get_ro);

int mmc_gpio_get_cd(struct mmc_host *host)
{
struct mmc_gpio *ctx = host->slot.handler_priv;
Expand All @@ -69,6 +86,24 @@ int mmc_gpio_get_cd(struct mmc_host *host)
}
EXPORT_SYMBOL(mmc_gpio_get_cd);

int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio)
{
struct mmc_gpio *ctx;
int ret;

if (!gpio_is_valid(gpio))
return -EINVAL;

ret = mmc_gpio_alloc(host);
if (ret < 0)
return ret;

ctx = host->slot.handler_priv;

return gpio_request_one(gpio, GPIOF_DIR_IN, ctx->ro_label);
}
EXPORT_SYMBOL(mmc_gpio_request_ro);

int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio)
{
struct mmc_gpio *ctx;
Expand Down Expand Up @@ -117,6 +152,21 @@ int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio)
}
EXPORT_SYMBOL(mmc_gpio_request_cd);

void mmc_gpio_free_ro(struct mmc_host *host)
{
struct mmc_gpio *ctx = host->slot.handler_priv;
int gpio;

if (!ctx || !gpio_is_valid(ctx->ro_gpio))
return;

gpio = ctx->ro_gpio;
ctx->ro_gpio = -EINVAL;

gpio_free(gpio);
}
EXPORT_SYMBOL(mmc_gpio_free_ro);

void mmc_gpio_free_cd(struct mmc_host *host)
{
struct mmc_gpio *ctx = host->slot.handler_priv;
Expand Down
4 changes: 4 additions & 0 deletions trunk/include/linux/mmc/slot-gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

struct mmc_host;

int mmc_gpio_get_ro(struct mmc_host *host);
int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio);
void mmc_gpio_free_ro(struct mmc_host *host);

int mmc_gpio_get_cd(struct mmc_host *host);
int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio);
void mmc_gpio_free_cd(struct mmc_host *host);
Expand Down

0 comments on commit c728b35

Please sign in to comment.