All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mmc: spi: Fix card detection during probe
@ 2019-02-10 17:31 Jonathan Neuschäfer
  2019-02-11  8:27 ` Linus Walleij
  2019-02-26  8:18 ` Ulf Hansson
  0 siblings, 2 replies; 4+ messages in thread
From: Jonathan Neuschäfer @ 2019-02-10 17:31 UTC (permalink / raw)
  To: linux-mmc
  Cc: Jonathan Neuschäfer, Ulf Hansson, Linus Walleij,
	Laurent Pinchart, linux-kernel

When using the mmc_spi driver with a card-detect pin, I noticed that the
card was not detected immediately after probe, but only after it was
unplugged and plugged back in (and the CD IRQ fired).

The call tree looks something like this:

mmc_spi_probe
  mmc_add_host
    mmc_start_host
      _mmc_detect_change
        mmc_schedule_delayed_work(&host->detect, 0)
          mmc_rescan
            host->bus_ops->detect(host)
              mmc_detect
                _mmc_detect_card_removed
                  host->ops->get_cd(host)
                    mmc_gpio_get_cd -> -ENOSYS (ctx->cd_gpio not set)
  mmc_gpiod_request_cd
    ctx->cd_gpio = desc

To fix this issue, call mmc_detect_change after the card-detect GPIO/IRQ
is registered.

Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
---
 drivers/mmc/host/mmc_spi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index 10ba46b728e8..8ade14fb2148 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -1450,6 +1450,7 @@ static int mmc_spi_probe(struct spi_device *spi)
 		mmc->caps &= ~MMC_CAP_NEEDS_POLL;
 		mmc_gpiod_request_cd_irq(mmc);
 	}
+	mmc_detect_change(mmc, 0);
 
 	/* Index 1 is write protect/read only */
 	status = mmc_gpiod_request_ro(mmc, NULL, 1, false, 0, NULL);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mmc: spi: Fix card detection during probe
  2019-02-10 17:31 [PATCH] mmc: spi: Fix card detection during probe Jonathan Neuschäfer
@ 2019-02-11  8:27 ` Linus Walleij
  2019-02-26  8:18 ` Ulf Hansson
  1 sibling, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2019-02-11  8:27 UTC (permalink / raw)
  To: Jonathan Neuschäfer
  Cc: linux-mmc, Ulf Hansson, Laurent Pinchart, linux-kernel

On Sun, Feb 10, 2019 at 6:31 PM Jonathan Neuschäfer
<j.neuschaefer@gmx.net> wrote:

> When using the mmc_spi driver with a card-detect pin, I noticed that the
> card was not detected immediately after probe, but only after it was
> unplugged and plugged back in (and the CD IRQ fired).
>
> The call tree looks something like this:
>
> mmc_spi_probe
>   mmc_add_host
>     mmc_start_host
>       _mmc_detect_change
>         mmc_schedule_delayed_work(&host->detect, 0)
>           mmc_rescan
>             host->bus_ops->detect(host)
>               mmc_detect
>                 _mmc_detect_card_removed
>                   host->ops->get_cd(host)
>                     mmc_gpio_get_cd -> -ENOSYS (ctx->cd_gpio not set)
>   mmc_gpiod_request_cd
>     ctx->cd_gpio = desc
>
> To fix this issue, call mmc_detect_change after the card-detect GPIO/IRQ
> is registered.
>
> Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>

Seems correct!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mmc: spi: Fix card detection during probe
  2019-02-10 17:31 [PATCH] mmc: spi: Fix card detection during probe Jonathan Neuschäfer
  2019-02-11  8:27 ` Linus Walleij
@ 2019-02-26  8:18 ` Ulf Hansson
  2019-02-26 11:29   ` Jonathan Neuschäfer
  1 sibling, 1 reply; 4+ messages in thread
From: Ulf Hansson @ 2019-02-26  8:18 UTC (permalink / raw)
  To: Jonathan Neuschäfer
  Cc: linux-mmc, Linus Walleij, Laurent Pinchart, Linux Kernel Mailing List

On Sun, 10 Feb 2019 at 18:31, Jonathan Neuschäfer <j.neuschaefer@gmx.net> wrote:
>
> When using the mmc_spi driver with a card-detect pin, I noticed that the
> card was not detected immediately after probe, but only after it was
> unplugged and plugged back in (and the CD IRQ fired).
>
> The call tree looks something like this:
>
> mmc_spi_probe
>   mmc_add_host
>     mmc_start_host
>       _mmc_detect_change
>         mmc_schedule_delayed_work(&host->detect, 0)
>           mmc_rescan
>             host->bus_ops->detect(host)
>               mmc_detect
>                 _mmc_detect_card_removed
>                   host->ops->get_cd(host)
>                     mmc_gpio_get_cd -> -ENOSYS (ctx->cd_gpio not set)
>   mmc_gpiod_request_cd
>     ctx->cd_gpio = desc
>
> To fix this issue, call mmc_detect_change after the card-detect GPIO/IRQ
> is registered.
>
> Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>

This works well as fix and for stable! However, we should probably
clean up the code in ->probe() to avoid this thing altogether. Anyway,
I send a patch for that - on top.

Applied for fixes and added a stable tag, thanks!

Kind regards
Uffe


> ---
>  drivers/mmc/host/mmc_spi.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
> index 10ba46b728e8..8ade14fb2148 100644
> --- a/drivers/mmc/host/mmc_spi.c
> +++ b/drivers/mmc/host/mmc_spi.c
> @@ -1450,6 +1450,7 @@ static int mmc_spi_probe(struct spi_device *spi)
>                 mmc->caps &= ~MMC_CAP_NEEDS_POLL;
>                 mmc_gpiod_request_cd_irq(mmc);
>         }
> +       mmc_detect_change(mmc, 0);
>
>         /* Index 1 is write protect/read only */
>         status = mmc_gpiod_request_ro(mmc, NULL, 1, false, 0, NULL);
> --
> 2.20.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mmc: spi: Fix card detection during probe
  2019-02-26  8:18 ` Ulf Hansson
@ 2019-02-26 11:29   ` Jonathan Neuschäfer
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Neuschäfer @ 2019-02-26 11:29 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Jonathan Neuschäfer, linux-mmc, Linus Walleij,
	Laurent Pinchart, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 1615 bytes --]

On Tue, Feb 26, 2019 at 09:18:06AM +0100, Ulf Hansson wrote:
> On Sun, 10 Feb 2019 at 18:31, Jonathan Neuschäfer <j.neuschaefer@gmx.net> wrote:
> >
> > When using the mmc_spi driver with a card-detect pin, I noticed that the
> > card was not detected immediately after probe, but only after it was
> > unplugged and plugged back in (and the CD IRQ fired).
> >
> > The call tree looks something like this:
> >
> > mmc_spi_probe
> >   mmc_add_host
> >     mmc_start_host
> >       _mmc_detect_change
> >         mmc_schedule_delayed_work(&host->detect, 0)
> >           mmc_rescan
> >             host->bus_ops->detect(host)
> >               mmc_detect
> >                 _mmc_detect_card_removed
> >                   host->ops->get_cd(host)
> >                     mmc_gpio_get_cd -> -ENOSYS (ctx->cd_gpio not set)
> >   mmc_gpiod_request_cd
> >     ctx->cd_gpio = desc
> >
> > To fix this issue, call mmc_detect_change after the card-detect GPIO/IRQ
> > is registered.
> >
> > Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
> 
> This works well as fix and for stable! However, we should probably
> clean up the code in ->probe() to avoid this thing altogether.

I figured that calling mmc_gpiod_request_cd before mmc_add_host *should*
avoid the 'return -ENOSYS' in mmc_gpio_get_cd. However it turned out to
be not as simple as swapping around a few lines in mmc_spi_probe, when I
wrote/tested this patch.

> Anyway, I send a patch for that - on top.

Thanks!

> Applied for fixes and added a stable tag, thanks!

Great.


Thanks,
Jonathan Neuschäfer

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-02-26 11:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-10 17:31 [PATCH] mmc: spi: Fix card detection during probe Jonathan Neuschäfer
2019-02-11  8:27 ` Linus Walleij
2019-02-26  8:18 ` Ulf Hansson
2019-02-26 11:29   ` Jonathan Neuschäfer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.