mmc: core: Rework wp-gpio handling
authorMichał Mirosław <mirq-linux@rere.qmqm.pl>
Wed, 11 Dec 2019 02:40:55 +0000 (03:40 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Feb 2020 18:53:10 +0000 (19:53 +0100)
[ Upstream commit 9073d10b098973519044f5fcdc25586810b435da ]

Use MMC_CAP2_RO_ACTIVE_HIGH flag as indicator if GPIO line is to be
inverted compared to DT/platform-specified polarity. The flag is not used
after init in GPIO mode anyway. No functional changes intended.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Link: https://lore.kernel.org/r/a60f563f11bbff821da2fa2949ca82922b144860.1576031637.git.mirq-linux@rere.qmqm.pl
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpio/gpiolib-of.c
drivers/mmc/core/host.c
drivers/mmc/core/slot-gpio.c
drivers/mmc/host/pxamci.c
drivers/mmc/host/sdhci-esdhc-imx.c

index 7ee5b7f..3ece591 100644 (file)
@@ -146,10 +146,6 @@ static void of_gpio_flags_quirks(struct device_node *np,
                        if (of_property_read_bool(np, "cd-inverted"))
                                *flags ^= OF_GPIO_ACTIVE_LOW;
                }
-               if (!strcmp(propname, "wp-gpios")) {
-                       if (of_property_read_bool(np, "wp-inverted"))
-                               *flags ^= OF_GPIO_ACTIVE_LOW;
-               }
        }
        /*
         * Some GPIO fixed regulator quirks.
index 105b7a7..b3484de 100644 (file)
@@ -176,7 +176,6 @@ int mmc_of_parse(struct mmc_host *host)
        u32 bus_width, drv_type, cd_debounce_delay_ms;
        int ret;
        bool cd_cap_invert, cd_gpio_invert = false;
-       bool ro_cap_invert, ro_gpio_invert = false;
 
        if (!dev || !dev_fwnode(dev))
                return 0;
@@ -255,9 +254,11 @@ int mmc_of_parse(struct mmc_host *host)
        }
 
        /* Parse Write Protection */
-       ro_cap_invert = device_property_read_bool(dev, "wp-inverted");
 
-       ret = mmc_gpiod_request_ro(host, "wp", 0, 0, &ro_gpio_invert);
+       if (device_property_read_bool(dev, "wp-inverted"))
+               host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
+
+       ret = mmc_gpiod_request_ro(host, "wp", 0, 0, NULL);
        if (!ret)
                dev_info(host->parent, "Got WP GPIO\n");
        else if (ret != -ENOENT && ret != -ENOSYS)
@@ -266,10 +267,6 @@ int mmc_of_parse(struct mmc_host *host)
        if (device_property_read_bool(dev, "disable-wp"))
                host->caps2 |= MMC_CAP2_NO_WRITE_PROTECT;
 
-       /* See the comment on CD inversion above */
-       if (ro_cap_invert ^ ro_gpio_invert)
-               host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
-
        if (device_property_read_bool(dev, "cap-sd-highspeed"))
                host->caps |= MMC_CAP_SD_HIGHSPEED;
        if (device_property_read_bool(dev, "cap-mmc-highspeed"))
index da2596c..582ec3d 100644 (file)
@@ -241,6 +241,9 @@ int mmc_gpiod_request_ro(struct mmc_host *host, const char *con_id,
                        return ret;
        }
 
+       if (host->caps2 & MMC_CAP2_RO_ACTIVE_HIGH)
+               gpiod_toggle_active_low(desc);
+
        if (gpio_invert)
                *gpio_invert = !gpiod_is_active_low(desc);
 
index 024acc1..b2bbcb0 100644 (file)
@@ -740,16 +740,16 @@ static int pxamci_probe(struct platform_device *pdev)
                        goto out;
                }
 
+               if (!host->pdata->gpio_card_ro_invert)
+                       mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
+
                ret = mmc_gpiod_request_ro(mmc, "wp", 0, 0, NULL);
                if (ret && ret != -ENOENT) {
                        dev_err(dev, "Failed requesting gpio_ro\n");
                        goto out;
                }
-               if (!ret) {
+               if (!ret)
                        host->use_ro_gpio = true;
-                       mmc->caps2 |= host->pdata->gpio_card_ro_invert ?
-                               0 : MMC_CAP2_RO_ACTIVE_HIGH;
-               }
 
                if (host->pdata->init)
                        host->pdata->init(dev, pxamci_detect_irq, mmc);
index 1c988d6..dccb4df 100644 (file)
@@ -1381,13 +1381,14 @@ static int sdhci_esdhc_imx_probe_nondt(struct platform_device *pdev,
                                host->mmc->parent->platform_data);
        /* write_protect */
        if (boarddata->wp_type == ESDHC_WP_GPIO) {
+               host->mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
+
                err = mmc_gpiod_request_ro(host->mmc, "wp", 0, 0, NULL);
                if (err) {
                        dev_err(mmc_dev(host->mmc),
                                "failed to request write-protect gpio!\n");
                        return err;
                }
-               host->mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
        }
 
        /* card_detect */