mmc: core: Rework wp-gpio handling

[ Upstream commit 9073d10b09 ]

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>
This commit is contained in:
Michał Mirosław 2019-12-11 03:40:55 +01:00 committed by Greg Kroah-Hartman
parent b0ad23142a
commit c10cfc131c
5 changed files with 13 additions and 16 deletions

View file

@ -146,10 +146,6 @@ static void of_gpio_flags_quirks(struct device_node *np,
if (of_property_read_bool(np, "cd-inverted")) if (of_property_read_bool(np, "cd-inverted"))
*flags ^= OF_GPIO_ACTIVE_LOW; *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. * Some GPIO fixed regulator quirks.

View file

@ -176,7 +176,6 @@ int mmc_of_parse(struct mmc_host *host)
u32 bus_width, drv_type, cd_debounce_delay_ms; u32 bus_width, drv_type, cd_debounce_delay_ms;
int ret; int ret;
bool cd_cap_invert, cd_gpio_invert = false; bool cd_cap_invert, cd_gpio_invert = false;
bool ro_cap_invert, ro_gpio_invert = false;
if (!dev || !dev_fwnode(dev)) if (!dev || !dev_fwnode(dev))
return 0; return 0;
@ -255,9 +254,11 @@ int mmc_of_parse(struct mmc_host *host)
} }
/* Parse Write Protection */ /* 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) if (!ret)
dev_info(host->parent, "Got WP GPIO\n"); dev_info(host->parent, "Got WP GPIO\n");
else if (ret != -ENOENT && ret != -ENOSYS) 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")) if (device_property_read_bool(dev, "disable-wp"))
host->caps2 |= MMC_CAP2_NO_WRITE_PROTECT; 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")) if (device_property_read_bool(dev, "cap-sd-highspeed"))
host->caps |= MMC_CAP_SD_HIGHSPEED; host->caps |= MMC_CAP_SD_HIGHSPEED;
if (device_property_read_bool(dev, "cap-mmc-highspeed")) if (device_property_read_bool(dev, "cap-mmc-highspeed"))

View file

@ -241,6 +241,9 @@ int mmc_gpiod_request_ro(struct mmc_host *host, const char *con_id,
return ret; return ret;
} }
if (host->caps2 & MMC_CAP2_RO_ACTIVE_HIGH)
gpiod_toggle_active_low(desc);
if (gpio_invert) if (gpio_invert)
*gpio_invert = !gpiod_is_active_low(desc); *gpio_invert = !gpiod_is_active_low(desc);

View file

@ -740,16 +740,16 @@ static int pxamci_probe(struct platform_device *pdev)
goto out; 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); ret = mmc_gpiod_request_ro(mmc, "wp", 0, 0, NULL);
if (ret && ret != -ENOENT) { if (ret && ret != -ENOENT) {
dev_err(dev, "Failed requesting gpio_ro\n"); dev_err(dev, "Failed requesting gpio_ro\n");
goto out; goto out;
} }
if (!ret) { if (!ret)
host->use_ro_gpio = true; host->use_ro_gpio = true;
mmc->caps2 |= host->pdata->gpio_card_ro_invert ?
0 : MMC_CAP2_RO_ACTIVE_HIGH;
}
if (host->pdata->init) if (host->pdata->init)
host->pdata->init(dev, pxamci_detect_irq, mmc); host->pdata->init(dev, pxamci_detect_irq, mmc);

View file

@ -1381,13 +1381,14 @@ static int sdhci_esdhc_imx_probe_nondt(struct platform_device *pdev,
host->mmc->parent->platform_data); host->mmc->parent->platform_data);
/* write_protect */ /* write_protect */
if (boarddata->wp_type == ESDHC_WP_GPIO) { 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); err = mmc_gpiod_request_ro(host->mmc, "wp", 0, 0, NULL);
if (err) { if (err) {
dev_err(mmc_dev(host->mmc), dev_err(mmc_dev(host->mmc),
"failed to request write-protect gpio!\n"); "failed to request write-protect gpio!\n");
return err; return err;
} }
host->mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
} }
/* card_detect */ /* card_detect */