Browse files

mmc: JZ4770: Use slot-gpio implementations of read-only and change de…

…tect

Also updated GPIO labels to use the same name that slot-gpio does
(device name instead of host name).
  • Loading branch information...
1 parent 547c78b commit 1e725fac79e3d8fc1b30b35d1d0323f24c2cef39 @mthuurne mthuurne committed May 27, 2013
View
2 drivers/mmc/host/jzmmc/include/jz_mmc_host.h
@@ -80,8 +80,6 @@ struct jz_mmc_host {
int card_detect_irq;
/* labels for gpio pins */
- char *label_card_detect;
- char *label_read_only;
char *label_power;
};
View
132 drivers/mmc/host/jzmmc/jz_mmc_gpio.c
@@ -11,6 +11,7 @@
#include <linux/gpio.h>
#include <linux/kernel.h>
#include <linux/mmc/host.h>
+#include <linux/mmc/slot-gpio.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
@@ -23,43 +24,12 @@
#include "include/jz_mmc_msc.h"
-static irqreturn_t jz_mmc_detect_irq(int irq, void *devid)
-{
- struct jz_mmc_host *host = devid;
-
- mmc_detect_change(host->mmc, HZ / 2);
-
- return IRQ_HANDLED;
-}
-
-static int jz_mmc_request_gpio(struct device *dev, int gpio, const char *name,
- bool output, int value)
-{
- int ret;
-
- if (!gpio_is_valid(gpio))
- return 0;
-
- ret = devm_gpio_request(dev, gpio, name);
- if (ret) {
- dev_err(dev, "Failed to request %s gpio: %d\n", name, ret);
- return ret;
- }
-
- if (output)
- gpio_direction_output(gpio, value);
- else
- gpio_direction_input(gpio);
-
- return 0;
-}
-
static int jz_mmc_request_card_gpios(struct platform_device *pdev,
struct jz_mmc_host *host)
{
struct device *dev = &pdev->dev;
struct jz_mmc_platform_data *pdata = dev->platform_data;
- const char *hostname = mmc_hostname(host->mmc);
+ const char *name = dev_name(dev);
int port;
unsigned int mask;
unsigned int i;
@@ -96,7 +66,7 @@ static int jz_mmc_request_card_gpios(struct platform_device *pdev,
for (i = 0; i < 32; i++) {
if (mask & BIT(i)) {
unsigned int pin = port * 32 + i;
- int ret = devm_gpio_request(dev, pin, hostname);
+ int ret = devm_gpio_request(dev, pin, name);
if (ret) {
dev_err(dev,
"Failed to request gpio pin %d: %d\n",
@@ -133,91 +103,55 @@ static int jz_mmc_request_card_gpios(struct platform_device *pdev,
return 0;
}
-static int jz_mmc_request_gpios(struct platform_device *pdev,
- struct jz_mmc_host *host)
+static int jz_mmc_request_power_gpio(struct platform_device *pdev,
+ struct jz_mmc_host *host)
{
struct device *dev = &pdev->dev;
struct jz_mmc_platform_data *pdata = dev->platform_data;
- const char *hostname = mmc_hostname(host->mmc);
- int ret;
-
- host->label_card_detect = kasprintf(GFP_KERNEL, "%s detect change",
- hostname);
- ret = jz_mmc_request_gpio(dev, pdata->gpio_card_detect,
- host->label_card_detect, false, 0);
- if (ret)
- goto err;
-
- host->label_read_only = kasprintf(GFP_KERNEL, "%s read only", hostname);
- ret = jz_mmc_request_gpio(dev, pdata->gpio_read_only,
- host->label_read_only, false, 0);
- if (ret)
- goto err;
-
- host->label_power = kasprintf(GFP_KERNEL, "%s power", hostname);
- ret = jz_mmc_request_gpio(dev, pdata->gpio_power, host->label_power,
- true, pdata->power_active_low);
- if (ret)
- goto err;
-
- return 0;
-
-err:
- kfree(host->label_card_detect);
- kfree(host->label_read_only);
- kfree(host->label_power);
- return ret;
-}
-
-static int jz_mmc_request_cd_irq(struct platform_device *pdev,
- struct jz_mmc_host *host)
-{
- struct jz_mmc_platform_data *pdata = pdev->dev.platform_data;
- int irq;
+ char *label = kasprintf(GFP_KERNEL, "%s power", dev_name(dev));
int ret;
- host->card_detect_irq = -1;
-
- if (!gpio_is_valid(pdata->gpio_card_detect)) {
- dev_info(&pdev->dev, "No card detect facilities available\n");
- return 0;
- }
-
- irq = gpio_to_irq(pdata->gpio_card_detect);
- if (irq < 0) {
- dev_warn(&pdev->dev,
- "Failed to look up card detect IRQ: %d\n", irq);
- return 0;
- }
-
- ret = devm_request_irq(&pdev->dev, irq, jz_mmc_detect_irq,
- IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
- host->label_card_detect, host);
- if (ret < 0) {
- dev_warn(&pdev->dev,
- "Failed to request card detect IRQ: %d\n", ret);
+ ret = devm_gpio_request(dev, pdata->gpio_power, label);
+ if (ret) {
+ dev_err(dev, "Failed to request power gpio: %d\n", ret);
+ kfree(label);
return ret;
}
- host->card_detect_irq = irq;
+ host->label_power = label;
+
+ gpio_direction_output(pdata->gpio_power, pdata->power_active_low);
return 0;
}
int jz_mmc_gpio_init(struct jz_mmc_host *host, struct platform_device *pdev)
{
+ struct jz_mmc_platform_data *pdata = pdev->dev.platform_data;
int ret;
ret = jz_mmc_request_card_gpios(pdev, host);
if (ret)
return ret;
- ret = jz_mmc_request_gpios(pdev, host);
- if (ret)
- return ret;
+ if (gpio_is_valid(pdata->gpio_power)) {
+ ret = jz_mmc_request_power_gpio(pdev, host);
+ if (ret)
+ return ret;
+ }
- ret = jz_mmc_request_cd_irq(pdev, host);
- if (ret)
- return ret;
+ if (gpio_is_valid(pdata->gpio_read_only)) {
+ ret = mmc_gpio_request_ro(host->mmc, pdata->gpio_read_only);
+ if (ret)
+ return ret;
+ }
+
+ if (gpio_is_valid(pdata->gpio_card_detect)) {
+ ret = mmc_gpio_request_cd(host->mmc, pdata->gpio_card_detect);
+ if (ret)
+ return ret;
+ } else {
+ dev_info(&pdev->dev, "No card detect facilities available\n");
+ }
return 0;
}
@@ -229,7 +163,5 @@ void jz_mmc_gpio_deinit(struct jz_mmc_host *host, struct platform_device *pdev)
device_init_wakeup(&pdev->dev, 0);
}
- kfree(host->label_card_detect);
- kfree(host->label_read_only);
kfree(host->label_power);
}
View
29 drivers/mmc/host/jzmmc/jz_mmc_main.c
@@ -22,6 +22,7 @@
#include <linux/mmc/sd.h>
#include <linux/mmc/sdio.h>
#include <linux/mmc/card.h>
+#include <linux/mmc/slot-gpio.h>
#include <linux/mm.h>
#include <linux/signal.h>
#include <linux/pm.h>
@@ -68,26 +69,6 @@ static void jz_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
jz_mmc_finish_request(host, mrq);
}
-static int jz_mmc_get_ro(struct mmc_host *mmc)
-{
- struct jz_mmc_host *host = mmc_priv(mmc);
- if (!gpio_is_valid(host->pdata->gpio_read_only))
- return -ENOSYS;
-
- return gpio_get_value(host->pdata->gpio_read_only) ^
- host->pdata->read_only_active_low;
-}
-
-static int jz_mmc_get_cd(struct mmc_host *mmc)
-{
- struct jz_mmc_host *host = mmc_priv(mmc);
- if (!gpio_is_valid(host->pdata->gpio_card_detect))
- return -ENOSYS;
-
- return gpio_get_value(host->pdata->gpio_card_detect) ^
- host->pdata->card_detect_active_low;
-}
-
/* set clock and power */
static void jz_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
{
@@ -139,9 +120,9 @@ static void jz_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
static const struct mmc_host_ops jz_mmc_ops = {
.request = jz_mmc_request,
- .get_ro = jz_mmc_get_ro,
.set_ios = jz_mmc_set_ios,
- .get_cd = jz_mmc_get_cd,
+ .get_cd = mmc_gpio_get_cd,
+ .get_ro = mmc_gpio_get_ro,
};
static int jz_mmc_probe(struct platform_device *pdev)
@@ -217,6 +198,10 @@ static int jz_mmc_probe(struct platform_device *pdev)
mmc->caps |= MMC_CAP_4_BIT_DATA;
if (pdata->bus_width >= 8)
mmc->caps |= MMC_CAP_8_BIT_DATA;
+ if (!pdata->card_detect_active_low)
+ mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
+ if (!pdata->read_only_active_low)
+ mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
mmc->max_blk_size = 4095;
mmc->max_blk_count = 65535;

0 comments on commit 1e725fa

Please sign in to comment.