* [PATCH] mmc: host: sdhci-esdhc-imx: add wakeup feature for GPIO CD pin
@ 2020-05-26 8:30 haibo.chen
2020-05-26 11:43 ` Ulf Hansson
0 siblings, 1 reply; 3+ messages in thread
From: haibo.chen @ 2020-05-26 8:30 UTC (permalink / raw)
To: adrian.hunter, ulf.hansson, linux-mmc
Cc: linux-imx, haibo.chen, shawnguo, s.hauer, kernel, festevam
From: Haibo Chen <haibo.chen@nxp.com>
When use the specific GPIO to detect the card insert/remove, we can
also add the GPIO as a wakeup source. When system suspend, insert or
remove the card can wakeup the system.
Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
---
drivers/mmc/host/sdhci-esdhc-imx.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index 5398af4824c3..7af9d87d4245 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -1599,6 +1599,11 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
if (esdhc_is_usdhc(imx_data)) {
host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
host->mmc->caps |= MMC_CAP_1_8V_DDR | MMC_CAP_3_3V_DDR;
+
+ /* GPIO CD can be set as a wakeup source */
+ host->mmc->caps |= MMC_CAP_CD_WAKE;
+ device_init_wakeup(&pdev->dev, true);
+
if (!(imx_data->socdata->flags & ESDHC_FLAG_HS200))
host->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200;
@@ -1734,8 +1739,15 @@ static int sdhci_esdhc_suspend(struct device *dev)
mmc_retune_needed(host->mmc);
ret = sdhci_suspend_host(host);
- if (!ret)
- return pinctrl_pm_select_sleep_state(dev);
+ if (ret)
+ return ret;
+
+ ret = pinctrl_pm_select_sleep_state(dev);
+ if (ret)
+ return ret;
+
+ if (device_may_wakeup(dev))
+ ret = mmc_gpio_set_cd_wake(host->mmc, true);
return ret;
}
@@ -1759,6 +1771,9 @@ static int sdhci_esdhc_resume(struct device *dev)
if (host->mmc->caps2 & MMC_CAP2_CQE)
ret = cqhci_resume(host->mmc);
+ if (!ret && device_may_wakeup(dev))
+ ret = mmc_gpio_set_cd_wake(host->mmc, false);
+
return ret;
}
#endif
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mmc: host: sdhci-esdhc-imx: add wakeup feature for GPIO CD pin
2020-05-26 8:30 [PATCH] mmc: host: sdhci-esdhc-imx: add wakeup feature for GPIO CD pin haibo.chen
@ 2020-05-26 11:43 ` Ulf Hansson
2020-05-27 2:32 ` BOUGH CHEN
0 siblings, 1 reply; 3+ messages in thread
From: Ulf Hansson @ 2020-05-26 11:43 UTC (permalink / raw)
To: Haibo Chen
Cc: Adrian Hunter, linux-mmc, dl-linux-imx, Shawn Guo, Sascha Hauer,
Sascha Hauer, Fabio Estevam, Linux PM, Rafael J. Wysocki
+ Rafael, linux-pm
On Tue, 26 May 2020 at 10:41, <haibo.chen@nxp.com> wrote:
>
> From: Haibo Chen <haibo.chen@nxp.com>
>
> When use the specific GPIO to detect the card insert/remove, we can
> also add the GPIO as a wakeup source. When system suspend, insert or
> remove the card can wakeup the system.
Yes, this makes perfect sense! However...
>
> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
> ---
> drivers/mmc/host/sdhci-esdhc-imx.c | 19 +++++++++++++++++--
> 1 file changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
> index 5398af4824c3..7af9d87d4245 100644
> --- a/drivers/mmc/host/sdhci-esdhc-imx.c
> +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
> @@ -1599,6 +1599,11 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
> if (esdhc_is_usdhc(imx_data)) {
> host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
> host->mmc->caps |= MMC_CAP_1_8V_DDR | MMC_CAP_3_3V_DDR;
> +
> + /* GPIO CD can be set as a wakeup source */
> + host->mmc->caps |= MMC_CAP_CD_WAKE;
> + device_init_wakeup(&pdev->dev, true);
> +
... if the device is attached to a genpd (a PM domain), this may cause
it to stay powered on in the system suspend state. Not sure if that
can cause a problem for you? Wasting energy?
In any case, I think it's wrong to make "&pdev->dev" wakeup capable,
like this. Especially as at it's the GPIO controller that manages the
system wakeup irq.
> if (!(imx_data->socdata->flags & ESDHC_FLAG_HS200))
> host->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200;
>
> @@ -1734,8 +1739,15 @@ static int sdhci_esdhc_suspend(struct device *dev)
> mmc_retune_needed(host->mmc);
>
> ret = sdhci_suspend_host(host);
> - if (!ret)
> - return pinctrl_pm_select_sleep_state(dev);
> + if (ret)
> + return ret;
> +
> + ret = pinctrl_pm_select_sleep_state(dev);
> + if (ret)
> + return ret;
> +
> + if (device_may_wakeup(dev))
> + ret = mmc_gpio_set_cd_wake(host->mmc, true);
With the above said, I think the best available approach at this
point, is to just call mmc_gpio_set_cd_wake() - and just skip checking
device_may_wakeup().
BTW, mmc_gpio_set_cd_wake() calls enable_irq_wake(), which doesn't
require the "dev" to be wakeup capable. So this is fine!
Yes, it means that the IRQ will be configured as a system wakeup,
without letting user space to have a say about it. I guess we can live
with that limitation.
>
> return ret;
> }
> @@ -1759,6 +1771,9 @@ static int sdhci_esdhc_resume(struct device *dev)
> if (host->mmc->caps2 & MMC_CAP2_CQE)
> ret = cqhci_resume(host->mmc);
>
> + if (!ret && device_may_wakeup(dev))
> + ret = mmc_gpio_set_cd_wake(host->mmc, false);
> +
> return ret;
> }
> #endif
> --
> 2.17.1
>
Kind regards
Uffe
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] mmc: host: sdhci-esdhc-imx: add wakeup feature for GPIO CD pin
2020-05-26 11:43 ` Ulf Hansson
@ 2020-05-27 2:32 ` BOUGH CHEN
0 siblings, 0 replies; 3+ messages in thread
From: BOUGH CHEN @ 2020-05-27 2:32 UTC (permalink / raw)
To: Ulf Hansson
Cc: Adrian Hunter, linux-mmc, dl-linux-imx, Shawn Guo, Sascha Hauer,
Sascha Hauer, Fabio Estevam, Linux PM, Rafael J. Wysocki
> -----Original Message-----
> From: Ulf Hansson <ulf.hansson@linaro.org>
> Sent: 2020年5月26日 19:43
> To: BOUGH CHEN <haibo.chen@nxp.com>
> Cc: Adrian Hunter <adrian.hunter@intel.com>; linux-mmc@vger.kernel.org;
> dl-linux-imx <linux-imx@nxp.com>; Shawn Guo <shawnguo@kernel.org>;
> Sascha Hauer <s.hauer@pengutronix.de>; Sascha Hauer
> <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>; Linux PM
> <linux-pm@vger.kernel.org>; Rafael J. Wysocki <rjw@rjwysocki.net>
> Subject: Re: [PATCH] mmc: host: sdhci-esdhc-imx: add wakeup feature for GPIO
> CD pin
>
> + Rafael, linux-pm
>
> On Tue, 26 May 2020 at 10:41, <haibo.chen@nxp.com> wrote:
> >
> > From: Haibo Chen <haibo.chen@nxp.com>
> >
> > When use the specific GPIO to detect the card insert/remove, we can
> > also add the GPIO as a wakeup source. When system suspend, insert or
> > remove the card can wakeup the system.
>
> Yes, this makes perfect sense! However...
>
> >
> > Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
> > ---
> > drivers/mmc/host/sdhci-esdhc-imx.c | 19 +++++++++++++++++--
> > 1 file changed, 17 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c
> > b/drivers/mmc/host/sdhci-esdhc-imx.c
> > index 5398af4824c3..7af9d87d4245 100644
> > --- a/drivers/mmc/host/sdhci-esdhc-imx.c
> > +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
> > @@ -1599,6 +1599,11 @@ static int sdhci_esdhc_imx_probe(struct
> platform_device *pdev)
> > if (esdhc_is_usdhc(imx_data)) {
> > host->quirks2 |=
> SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
> > host->mmc->caps |= MMC_CAP_1_8V_DDR |
> > MMC_CAP_3_3V_DDR;
> > +
> > + /* GPIO CD can be set as a wakeup source */
> > + host->mmc->caps |= MMC_CAP_CD_WAKE;
> > + device_init_wakeup(&pdev->dev, true);
> > +
>
> ... if the device is attached to a genpd (a PM domain), this may cause it to stay
> powered on in the system suspend state. Not sure if that can cause a problem
> for you? Wasting energy?
>
> In any case, I think it's wrong to make "&pdev->dev" wakeup capable, like this.
> Especially as at it's the GPIO controller that manages the system wakeup irq.
Yes, that's reasonable.
>
> > if (!(imx_data->socdata->flags & ESDHC_FLAG_HS200))
> > host->quirks2 |=
> SDHCI_QUIRK2_BROKEN_HS200;
> >
> > @@ -1734,8 +1739,15 @@ static int sdhci_esdhc_suspend(struct device
> *dev)
> > mmc_retune_needed(host->mmc);
> >
> > ret = sdhci_suspend_host(host);
> > - if (!ret)
> > - return pinctrl_pm_select_sleep_state(dev);
> > + if (ret)
> > + return ret;
> > +
> > + ret = pinctrl_pm_select_sleep_state(dev);
> > + if (ret)
> > + return ret;
> > +
> > + if (device_may_wakeup(dev))
> > + ret = mmc_gpio_set_cd_wake(host->mmc, true);
>
> With the above said, I think the best available approach at this point, is to just
> call mmc_gpio_set_cd_wake() - and just skip checking device_may_wakeup().
>
> BTW, mmc_gpio_set_cd_wake() calls enable_irq_wake(), which doesn't require
> the "dev" to be wakeup capable. So this is fine!
>
> Yes, it means that the IRQ will be configured as a system wakeup, without
> letting user space to have a say about it. I guess we can live with that
> limitation.
>
Okay, I will send a v2 patch according to your suggestion.
Thanks!
Haibo Chen
> >
> > return ret;
> > }
> > @@ -1759,6 +1771,9 @@ static int sdhci_esdhc_resume(struct device *dev)
> > if (host->mmc->caps2 & MMC_CAP2_CQE)
> > ret = cqhci_resume(host->mmc);
> >
> > + if (!ret && device_may_wakeup(dev))
> > + ret = mmc_gpio_set_cd_wake(host->mmc, false);
> > +
> > return ret;
> > }
> > #endif
> > --
> > 2.17.1
> >
>
> Kind regards
> Uffe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-05-27 2:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-26 8:30 [PATCH] mmc: host: sdhci-esdhc-imx: add wakeup feature for GPIO CD pin haibo.chen
2020-05-26 11:43 ` Ulf Hansson
2020-05-27 2:32 ` BOUGH CHEN
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).