Commit 58e300af authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Chris Ball

mmc: jz4740: Use slot-gpio helpers

Use the slot-gpio helpers to handle the write protect and card detect
GPIO pins instead of re-implementing the same functionality in the driver.
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarChris Ball <cjb@laptop.org>
parent 5d5c0350
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
#include <linux/mmc/host.h> #include <linux/mmc/host.h>
#include <linux/mmc/slot-gpio.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/irq.h> #include <linux/irq.h>
...@@ -653,35 +654,6 @@ static void jz4740_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) ...@@ -653,35 +654,6 @@ static void jz4740_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
} }
} }
static int jz4740_mmc_get_ro(struct mmc_host *mmc)
{
struct jz4740_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 jz4740_mmc_get_cd(struct mmc_host *mmc)
{
struct jz4740_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;
}
static irqreturn_t jz4740_mmc_card_detect_irq(int irq, void *devid)
{
struct jz4740_mmc_host *host = devid;
mmc_detect_change(host->mmc, HZ / 2);
return IRQ_HANDLED;
}
static void jz4740_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable) static void jz4740_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
{ {
struct jz4740_mmc_host *host = mmc_priv(mmc); struct jz4740_mmc_host *host = mmc_priv(mmc);
...@@ -691,8 +663,8 @@ static void jz4740_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable) ...@@ -691,8 +663,8 @@ static void jz4740_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
static const struct mmc_host_ops jz4740_mmc_ops = { static const struct mmc_host_ops jz4740_mmc_ops = {
.request = jz4740_mmc_request, .request = jz4740_mmc_request,
.set_ios = jz4740_mmc_set_ios, .set_ios = jz4740_mmc_set_ios,
.get_ro = jz4740_mmc_get_ro, .get_ro = mmc_gpio_get_ro,
.get_cd = jz4740_mmc_get_cd, .get_cd = mmc_gpio_get_cd,
.enable_sdio_irq = jz4740_mmc_enable_sdio_irq, .enable_sdio_irq = jz4740_mmc_enable_sdio_irq,
}; };
...@@ -727,58 +699,34 @@ static int jz4740_mmc_request_gpio(struct device *dev, int gpio, ...@@ -727,58 +699,34 @@ static int jz4740_mmc_request_gpio(struct device *dev, int gpio,
return 0; return 0;
} }
static int jz4740_mmc_request_gpios(struct platform_device *pdev) static int jz4740_mmc_request_gpios(struct mmc_host *mmc,
struct platform_device *pdev)
{ {
int ret;
struct jz4740_mmc_platform_data *pdata = pdev->dev.platform_data; struct jz4740_mmc_platform_data *pdata = pdev->dev.platform_data;
int ret = 0;
if (!pdata) if (!pdata)
return 0; return 0;
ret = jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_card_detect, if (!pdata->card_detect_active_low)
"MMC detect change", false, 0); mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
if (ret) if (!pdata->read_only_active_low)
goto err; mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
ret = jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_read_only,
"MMC read only", false, 0);
if (ret)
goto err_free_gpio_card_detect;
ret = jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_power, if (gpio_is_valid(pdata->gpio_card_detect)) {
"MMC read only", true, pdata->power_active_low); ret = mmc_gpio_request_cd(mmc, pdata->gpio_card_detect);
if (ret) if (ret)
goto err_free_gpio_read_only; return ret;
}
return 0;
err_free_gpio_read_only:
if (gpio_is_valid(pdata->gpio_read_only))
gpio_free(pdata->gpio_read_only);
err_free_gpio_card_detect:
if (gpio_is_valid(pdata->gpio_card_detect))
gpio_free(pdata->gpio_card_detect);
err:
return ret;
}
static int jz4740_mmc_request_cd_irq(struct platform_device *pdev,
struct jz4740_mmc_host *host)
{
struct jz4740_mmc_platform_data *pdata = pdev->dev.platform_data;
if (!gpio_is_valid(pdata->gpio_card_detect))
return 0;
host->card_detect_irq = gpio_to_irq(pdata->gpio_card_detect); if (gpio_is_valid(pdata->gpio_read_only)) {
if (host->card_detect_irq < 0) { ret = mmc_gpio_request_ro(mmc, pdata->gpio_read_only);
dev_warn(&pdev->dev, "Failed to get card detect irq\n"); if (ret)
return 0; return ret;
} }
return request_irq(host->card_detect_irq, jz4740_mmc_card_detect_irq, return jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_power,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "MMC read only", true, pdata->power_active_low);
"MMC card detect", host);
} }
static void jz4740_mmc_free_gpios(struct platform_device *pdev) static void jz4740_mmc_free_gpios(struct platform_device *pdev)
...@@ -790,10 +738,6 @@ static void jz4740_mmc_free_gpios(struct platform_device *pdev) ...@@ -790,10 +738,6 @@ static void jz4740_mmc_free_gpios(struct platform_device *pdev)
if (gpio_is_valid(pdata->gpio_power)) if (gpio_is_valid(pdata->gpio_power))
gpio_free(pdata->gpio_power); gpio_free(pdata->gpio_power);
if (gpio_is_valid(pdata->gpio_read_only))
gpio_free(pdata->gpio_read_only);
if (gpio_is_valid(pdata->gpio_card_detect))
gpio_free(pdata->gpio_card_detect);
} }
static inline size_t jz4740_mmc_num_pins(struct jz4740_mmc_host *host) static inline size_t jz4740_mmc_num_pins(struct jz4740_mmc_host *host)
...@@ -865,7 +809,7 @@ static int jz4740_mmc_probe(struct platform_device* pdev) ...@@ -865,7 +809,7 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
goto err_iounmap; goto err_iounmap;
} }
ret = jz4740_mmc_request_gpios(pdev); ret = jz4740_mmc_request_gpios(mmc, pdev);
if (ret) if (ret)
goto err_gpio_bulk_free; goto err_gpio_bulk_free;
...@@ -888,17 +832,11 @@ static int jz4740_mmc_probe(struct platform_device* pdev) ...@@ -888,17 +832,11 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
spin_lock_init(&host->lock); spin_lock_init(&host->lock);
host->irq_mask = 0xffff; host->irq_mask = 0xffff;
ret = jz4740_mmc_request_cd_irq(pdev, host);
if (ret) {
dev_err(&pdev->dev, "Failed to request card detect irq\n");
goto err_free_gpios;
}
ret = request_threaded_irq(host->irq, jz_mmc_irq, jz_mmc_irq_worker, 0, ret = request_threaded_irq(host->irq, jz_mmc_irq, jz_mmc_irq_worker, 0,
dev_name(&pdev->dev), host); dev_name(&pdev->dev), host);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to request irq: %d\n", ret); dev_err(&pdev->dev, "Failed to request irq: %d\n", ret);
goto err_free_card_detect_irq; goto err_free_gpios;
} }
jz4740_mmc_reset(host); jz4740_mmc_reset(host);
...@@ -921,9 +859,6 @@ static int jz4740_mmc_probe(struct platform_device* pdev) ...@@ -921,9 +859,6 @@ static int jz4740_mmc_probe(struct platform_device* pdev)
err_free_irq: err_free_irq:
free_irq(host->irq, host); free_irq(host->irq, host);
err_free_card_detect_irq:
if (host->card_detect_irq >= 0)
free_irq(host->card_detect_irq, host);
err_free_gpios: err_free_gpios:
jz4740_mmc_free_gpios(pdev); jz4740_mmc_free_gpios(pdev);
err_gpio_bulk_free: err_gpio_bulk_free:
...@@ -951,8 +886,6 @@ static int jz4740_mmc_remove(struct platform_device *pdev) ...@@ -951,8 +886,6 @@ static int jz4740_mmc_remove(struct platform_device *pdev)
mmc_remove_host(host->mmc); mmc_remove_host(host->mmc);
free_irq(host->irq, host); free_irq(host->irq, host);
if (host->card_detect_irq >= 0)
free_irq(host->card_detect_irq, host);
jz4740_mmc_free_gpios(pdev); jz4740_mmc_free_gpios(pdev);
jz_gpio_bulk_free(jz4740_mmc_pins, jz4740_mmc_num_pins(host)); jz_gpio_bulk_free(jz4740_mmc_pins, jz4740_mmc_num_pins(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