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)
committerUlf Hansson <ulf.hansson@linaro.org>
Wed, 18 Dec 2019 12:36:40 +0000 (13:36 +0100)
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>
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 dc27b1a88e9343a8a029832cef5c6095a7be6238..b0b77e52e26112a192bd036c58605b64e62c5684 100644 (file)
@@ -120,10 +120,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 105b7a7c025133b8afbf3a3221376caa16015ce8..b3484def0a8b0e15e70518c9866d681d3b81b074 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 da2596c5fa28dba4fd5d8a92b2f399864d7b4ffa..582ec3d720f64fc8eb2305682c538ae169e313e4 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 024acc1b0a2eab59f51246123c7bd6eb6019ad97..b2bbcb09a49e68bf724ad16441651c3a09bf0068 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 43628c9c05ac626ae791532da267bb2b526b86c4..3be9739fec30a6bb067406453cf709520a34f7b5 100644 (file)
@@ -1379,13 +1379,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 */