diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-12-05 08:34:50 -0500 |
---|---|---|
committer | Chris Ball <chris@printf.net> | 2014-01-13 12:48:20 -0500 |
commit | abd37cccd47fe950e893578da12e7dc0604078de (patch) | |
tree | 92258751556d0ea51d11aadf47c090f4aa815bf1 | |
parent | 6c3331d3ace7989688fa59f541f5e722e44ac373 (diff) |
mmc: mxs: use mmc_gpio_get_ro for detecting read-only status
This also fixes that the read-only gpio was used without being
requested.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Chris Ball <cjb@laptop.org>
-rw-r--r-- | drivers/mmc/host/mxs-mmc.c | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/drivers/mmc/host/mxs-mmc.c b/drivers/mmc/host/mxs-mmc.c index 3dd2f4c867e6..13016e2cccad 100644 --- a/drivers/mmc/host/mxs-mmc.c +++ b/drivers/mmc/host/mxs-mmc.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include <linux/mmc/host.h> | 38 | #include <linux/mmc/host.h> |
39 | #include <linux/mmc/mmc.h> | 39 | #include <linux/mmc/mmc.h> |
40 | #include <linux/mmc/sdio.h> | 40 | #include <linux/mmc/sdio.h> |
41 | #include <linux/mmc/slot-gpio.h> | ||
41 | #include <linux/gpio.h> | 42 | #include <linux/gpio.h> |
42 | #include <linux/regulator/consumer.h> | 43 | #include <linux/regulator/consumer.h> |
43 | #include <linux/module.h> | 44 | #include <linux/module.h> |
@@ -69,26 +70,8 @@ struct mxs_mmc_host { | |||
69 | unsigned char bus_width; | 70 | unsigned char bus_width; |
70 | spinlock_t lock; | 71 | spinlock_t lock; |
71 | int sdio_irq_en; | 72 | int sdio_irq_en; |
72 | int wp_gpio; | ||
73 | bool wp_inverted; | ||
74 | }; | 73 | }; |
75 | 74 | ||
76 | static int mxs_mmc_get_ro(struct mmc_host *mmc) | ||
77 | { | ||
78 | struct mxs_mmc_host *host = mmc_priv(mmc); | ||
79 | int ret; | ||
80 | |||
81 | if (!gpio_is_valid(host->wp_gpio)) | ||
82 | return -EINVAL; | ||
83 | |||
84 | ret = gpio_get_value(host->wp_gpio); | ||
85 | |||
86 | if (host->wp_inverted) | ||
87 | ret = !ret; | ||
88 | |||
89 | return ret; | ||
90 | } | ||
91 | |||
92 | static int mxs_mmc_get_cd(struct mmc_host *mmc) | 75 | static int mxs_mmc_get_cd(struct mmc_host *mmc) |
93 | { | 76 | { |
94 | struct mxs_mmc_host *host = mmc_priv(mmc); | 77 | struct mxs_mmc_host *host = mmc_priv(mmc); |
@@ -551,7 +534,7 @@ static void mxs_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable) | |||
551 | 534 | ||
552 | static const struct mmc_host_ops mxs_mmc_ops = { | 535 | static const struct mmc_host_ops mxs_mmc_ops = { |
553 | .request = mxs_mmc_request, | 536 | .request = mxs_mmc_request, |
554 | .get_ro = mxs_mmc_get_ro, | 537 | .get_ro = mmc_gpio_get_ro, |
555 | .get_cd = mxs_mmc_get_cd, | 538 | .get_cd = mxs_mmc_get_cd, |
556 | .set_ios = mxs_mmc_set_ios, | 539 | .set_ios = mxs_mmc_set_ios, |
557 | .enable_sdio_irq = mxs_mmc_enable_sdio_irq, | 540 | .enable_sdio_irq = mxs_mmc_enable_sdio_irq, |
@@ -585,7 +568,7 @@ static int mxs_mmc_probe(struct platform_device *pdev) | |||
585 | struct mxs_mmc_host *host; | 568 | struct mxs_mmc_host *host; |
586 | struct mmc_host *mmc; | 569 | struct mmc_host *mmc; |
587 | struct resource *iores; | 570 | struct resource *iores; |
588 | int ret = 0, irq_err; | 571 | int ret = 0, irq_err, gpio; |
589 | struct regulator *reg_vmmc; | 572 | struct regulator *reg_vmmc; |
590 | enum of_gpio_flags flags; | 573 | enum of_gpio_flags flags; |
591 | struct mxs_ssp *ssp; | 574 | struct mxs_ssp *ssp; |
@@ -659,9 +642,14 @@ static int mxs_mmc_probe(struct platform_device *pdev) | |||
659 | mmc->caps |= MMC_CAP_NEEDS_POLL; | 642 | mmc->caps |= MMC_CAP_NEEDS_POLL; |
660 | if (of_property_read_bool(np, "non-removable")) | 643 | if (of_property_read_bool(np, "non-removable")) |
661 | mmc->caps |= MMC_CAP_NONREMOVABLE; | 644 | mmc->caps |= MMC_CAP_NONREMOVABLE; |
662 | host->wp_gpio = of_get_named_gpio_flags(np, "wp-gpios", 0, &flags); | 645 | gpio = of_get_named_gpio_flags(np, "wp-gpios", 0, &flags); |
663 | if (flags & OF_GPIO_ACTIVE_LOW) | 646 | if (gpio_is_valid(gpio)) { |
664 | host->wp_inverted = 1; | 647 | ret = mmc_gpio_request_ro(mmc, gpio); |
648 | if (ret) | ||
649 | goto out_clk_disable; | ||
650 | if (!(flags & OF_GPIO_ACTIVE_LOW)) | ||
651 | mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; | ||
652 | } | ||
665 | 653 | ||
666 | if (of_property_read_bool(np, "cd-inverted")) | 654 | if (of_property_read_bool(np, "cd-inverted")) |
667 | mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; | 655 | mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; |