Message ID | 1511540697-27387-11-git-send-email-yamada.masahiro@socionext.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Geert Uytterhoeven |
Headers | show |
> +static int tmio_mmc_get_cd(struct mmc_host *mmc) > +{ > + struct tmio_mmc_host *host = mmc_priv(mmc); > + int ret; > + > + ret = mmc_gpio_get_cd(mmc); > + if (ret >= 0) > + return ret; > + > + return !!(sd_ctrl_read16_and_16_as_32(host, CTL_STATUS) & > + TMIO_STAT_SIGSTATE); > +} I wonder if we shouldn't do something like: if (mmc_can_gpio_cd()) return mmc_gpio_get_cd() else return !!(sd_ctrl_read16_and_16_as_32...) If we have a GPIO CD defined, I think we want the value of mmc_gpio_get_cd() in all cases. It makes clearer that this is an 'either-or' case and not a fallback mechanism.
2017-12-05 0:13 GMT+09:00 Wolfram Sang <wsa@the-dreams.de>: >> +static int tmio_mmc_get_cd(struct mmc_host *mmc) >> +{ >> + struct tmio_mmc_host *host = mmc_priv(mmc); >> + int ret; >> + >> + ret = mmc_gpio_get_cd(mmc); >> + if (ret >= 0) >> + return ret; >> + >> + return !!(sd_ctrl_read16_and_16_as_32(host, CTL_STATUS) & >> + TMIO_STAT_SIGSTATE); >> +} I just followed tmio_mmc_get_ro() implementation. If we do not care the symmetry between _get_ro() and _get_cd() hooks, yes, your suggestion makes sense. > I wonder if we shouldn't do something like: > > if (mmc_can_gpio_cd()) > return mmc_gpio_get_cd() > else > return !!(sd_ctrl_read16_and_16_as_32...) > > If we have a GPIO CD defined, I think we want the value of > mmc_gpio_get_cd() in all cases. It makes clearer that this is an > 'either-or' case and not a fallback mechanism. > Another possibility would select this in _probe(). We would need to evaluate mmc_can_gpio_cd() only once when probing. I will follow your suggestion, though. Either way is fine with me. static int tmio_mmc_get_cd(struct mmc_host *mmc) { struct tmio_mmc_host *host = mmc_priv(mmc); return !!(sd_ctrl_read16_and_16_as_32(host, CTL_STATUS) & TMIO_STAT_SIGSTATE); } static const struct mmc_host_ops tmio_mmc_ops = { ... .get_cd = tmio_mmc_get_cd, ... }; int tmio_mmc_host_probe( ... ) { .... /* replace get_cd hook when we use GPIO for card detection */ if (mmc_can_gpio_cd(mmc)) _host->ops.get_cd = mmc_gpio_get_cd; }
> Another possibility would select this in _probe(). > We would need to evaluate mmc_can_gpio_cd() only once when probing. I like this, too. Maybe like this to be more obvious: if (mmc_can_gpio_cd(mmc)) _host->ops.get_cd = mmc_gpio_get_cd; else _host->ops.get_cd = tmio... ?
On Sat, Nov 25, 2017 at 01:24:45AM +0900, Masahiro Yamada wrote: > A card detect GPIO is set up only for platforms with "cd-gpios" > DT property or TMIO_MMC_USE_GPIO_CD flag. However, the driver > core always uses mmc_gpio_get_cd, which just fails with -ENOSYS > if ctx->cd_gpio is unset. > > The bit 5 of the status register provides the current signal level > of the CD line. Allow to use it if the GPIO is unused. > > Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> As mentioned before (sorry, I lost this thread :( ), I like the refactoring to select in probe() which function to call depending on GPIO usage or not. If you like, we can do the same for read_only, too. Thanks!
diff --git a/drivers/mmc/host/tmio_mmc_core.c b/drivers/mmc/host/tmio_mmc_core.c index 610f26f..b51bb06 100644 --- a/drivers/mmc/host/tmio_mmc_core.c +++ b/drivers/mmc/host/tmio_mmc_core.c @@ -1087,6 +1087,19 @@ static int tmio_mmc_get_ro(struct mmc_host *mmc) return ret; } +static int tmio_mmc_get_cd(struct mmc_host *mmc) +{ + struct tmio_mmc_host *host = mmc_priv(mmc); + int ret; + + ret = mmc_gpio_get_cd(mmc); + if (ret >= 0) + return ret; + + return !!(sd_ctrl_read16_and_16_as_32(host, CTL_STATUS) & + TMIO_STAT_SIGSTATE); +} + static int tmio_multi_io_quirk(struct mmc_card *card, unsigned int direction, int blk_size) { @@ -1102,7 +1115,7 @@ static const struct mmc_host_ops tmio_mmc_ops = { .request = tmio_mmc_request, .set_ios = tmio_mmc_set_ios, .get_ro = tmio_mmc_get_ro, - .get_cd = mmc_gpio_get_cd, + .get_cd = tmio_mmc_get_cd, .enable_sdio_irq = tmio_mmc_enable_sdio_irq, .multi_io_quirk = tmio_multi_io_quirk, .hw_reset = tmio_mmc_hw_reset,
A card detect GPIO is set up only for platforms with "cd-gpios" DT property or TMIO_MMC_USE_GPIO_CD flag. However, the driver core always uses mmc_gpio_get_cd, which just fails with -ENOSYS if ctx->cd_gpio is unset. The bit 5 of the status register provides the current signal level of the CD line. Allow to use it if the GPIO is unused. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> --- Changes in v2: None drivers/mmc/host/tmio_mmc_core.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)