Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Sascha Hauer and committed by
Chris Ball
abd37ccc 6c3331d3

+11 -23
+11 -23
drivers/mmc/host/mxs-mmc.c
··· 38 38 #include <linux/mmc/host.h> 39 39 #include <linux/mmc/mmc.h> 40 40 #include <linux/mmc/sdio.h> 41 + #include <linux/mmc/slot-gpio.h> 41 42 #include <linux/gpio.h> 42 43 #include <linux/regulator/consumer.h> 43 44 #include <linux/module.h> ··· 70 69 unsigned char bus_width; 71 70 spinlock_t lock; 72 71 int sdio_irq_en; 73 - int wp_gpio; 74 - bool wp_inverted; 75 72 }; 76 - 77 - static int mxs_mmc_get_ro(struct mmc_host *mmc) 78 - { 79 - struct mxs_mmc_host *host = mmc_priv(mmc); 80 - int ret; 81 - 82 - if (!gpio_is_valid(host->wp_gpio)) 83 - return -EINVAL; 84 - 85 - ret = gpio_get_value(host->wp_gpio); 86 - 87 - if (host->wp_inverted) 88 - ret = !ret; 89 - 90 - return ret; 91 - } 92 73 93 74 static int mxs_mmc_get_cd(struct mmc_host *mmc) 94 75 { ··· 534 551 535 552 static const struct mmc_host_ops mxs_mmc_ops = { 536 553 .request = mxs_mmc_request, 537 - .get_ro = mxs_mmc_get_ro, 554 + .get_ro = mmc_gpio_get_ro, 538 555 .get_cd = mxs_mmc_get_cd, 539 556 .set_ios = mxs_mmc_set_ios, 540 557 .enable_sdio_irq = mxs_mmc_enable_sdio_irq, ··· 568 585 struct mxs_mmc_host *host; 569 586 struct mmc_host *mmc; 570 587 struct resource *iores; 571 - int ret = 0, irq_err; 588 + int ret = 0, irq_err, gpio; 572 589 struct regulator *reg_vmmc; 573 590 enum of_gpio_flags flags; 574 591 struct mxs_ssp *ssp; ··· 642 659 mmc->caps |= MMC_CAP_NEEDS_POLL; 643 660 if (of_property_read_bool(np, "non-removable")) 644 661 mmc->caps |= MMC_CAP_NONREMOVABLE; 645 - host->wp_gpio = of_get_named_gpio_flags(np, "wp-gpios", 0, &flags); 646 - if (flags & OF_GPIO_ACTIVE_LOW) 647 - host->wp_inverted = 1; 662 + gpio = of_get_named_gpio_flags(np, "wp-gpios", 0, &flags); 663 + if (gpio_is_valid(gpio)) { 664 + ret = mmc_gpio_request_ro(mmc, gpio); 665 + if (ret) 666 + goto out_clk_disable; 667 + if (!(flags & OF_GPIO_ACTIVE_LOW)) 668 + mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; 669 + } 648 670 649 671 if (of_property_read_bool(np, "cd-inverted")) 650 672 mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;