mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] mci: stm32_sdmmc2: add detect function
@ 2020-05-13 12:08 Lucas Stach
  2020-05-13 18:38 ` Ahmad Fatoum
  0 siblings, 1 reply; 3+ messages in thread
From: Lucas Stach @ 2020-05-13 12:08 UTC (permalink / raw)
  To: barebox

This way we can avoid probing for the SD/MMC devices at startup
and just detect them when actually needed.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/mci/stm32_sdmmc2.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/mci/stm32_sdmmc2.c b/drivers/mci/stm32_sdmmc2.c
index 3ce3bb0f89d2..ac52b62fa0b7 100644
--- a/drivers/mci/stm32_sdmmc2.c
+++ b/drivers/mci/stm32_sdmmc2.c
@@ -571,6 +571,13 @@ static void stm32_sdmmc2_set_ios(struct mci_host *mci, struct mci_ios *ios)
 	       priv->base + SDMMC_CLKCR);
 }
 
+static int stm32_sdmmc2_detect(struct device_d *dev)
+{
+	struct stm32_sdmmc2_priv *priv = dev->priv;
+
+	return mci_detect_card(&priv->mci);
+}
+
 static int stm32_sdmmc2_probe(struct amba_device *adev,
 			      const struct amba_id *id)
 {
@@ -591,6 +598,9 @@ static int stm32_sdmmc2_probe(struct amba_device *adev,
 	mci->init = stm32_sdmmc2_reset;
 	mci->hw_dev = dev;
 
+	dev->priv = priv;
+	dev->detect = stm32_sdmmc2_detect;
+
 	priv->clk = clk_get(dev, NULL);
 	if (IS_ERR(priv->clk)) {
 		ret = PTR_ERR(priv->clk);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] mci: stm32_sdmmc2: add detect function
  2020-05-13 12:08 [PATCH] mci: stm32_sdmmc2: add detect function Lucas Stach
@ 2020-05-13 18:38 ` Ahmad Fatoum
  2020-05-15  8:21   ` Lucas Stach
  0 siblings, 1 reply; 3+ messages in thread
From: Ahmad Fatoum @ 2020-05-13 18:38 UTC (permalink / raw)
  To: Lucas Stach, barebox

Hello Lucas,

On 5/13/20 2:08 PM, Lucas Stach wrote:
> This way we can avoid probing for the SD/MMC devices at startup
> and just detect them when actually needed.

Is there a reason we can't have mci_register do it for every MCI.hw_dev
at registration time?

Out of 17 MCI drivers, 8 already have the same wrapper around mci_detect_card.

> 
> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> ---
>  drivers/mci/stm32_sdmmc2.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/mci/stm32_sdmmc2.c b/drivers/mci/stm32_sdmmc2.c
> index 3ce3bb0f89d2..ac52b62fa0b7 100644
> --- a/drivers/mci/stm32_sdmmc2.c
> +++ b/drivers/mci/stm32_sdmmc2.c
> @@ -571,6 +571,13 @@ static void stm32_sdmmc2_set_ios(struct mci_host *mci, struct mci_ios *ios)
>  	       priv->base + SDMMC_CLKCR);
>  }
>  
> +static int stm32_sdmmc2_detect(struct device_d *dev)
> +{
> +	struct stm32_sdmmc2_priv *priv = dev->priv;
> +
> +	return mci_detect_card(&priv->mci);
> +}
> +
>  static int stm32_sdmmc2_probe(struct amba_device *adev,
>  			      const struct amba_id *id)
>  {
> @@ -591,6 +598,9 @@ static int stm32_sdmmc2_probe(struct amba_device *adev,
>  	mci->init = stm32_sdmmc2_reset;
>  	mci->hw_dev = dev;
>  
> +	dev->priv = priv;
> +	dev->detect = stm32_sdmmc2_detect;
> +
>  	priv->clk = clk_get(dev, NULL);
>  	if (IS_ERR(priv->clk)) {
>  		ret = PTR_ERR(priv->clk);
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] mci: stm32_sdmmc2: add detect function
  2020-05-13 18:38 ` Ahmad Fatoum
@ 2020-05-15  8:21   ` Lucas Stach
  0 siblings, 0 replies; 3+ messages in thread
From: Lucas Stach @ 2020-05-15  8:21 UTC (permalink / raw)
  To: Ahmad Fatoum, barebox

Hi Ahmad,

Am Mittwoch, den 13.05.2020, 20:38 +0200 schrieb Ahmad Fatoum:
> Hello Lucas,
> 
> On 5/13/20 2:08 PM, Lucas Stach wrote:
> > This way we can avoid probing for the SD/MMC devices at startup
> > and just detect them when actually needed.
> 
> Is there a reason we can't have mci_register do it for every MCI.hw_dev
> at registration time?
> 
> Out of 17 MCI drivers, 8 already have the same wrapper around mci_detect_card.

I've looked at this, but it's not easily possible. We already have a
detect function implemented by the mci core on the mci device, but this
doesn't suffice to allow detection of the card when called on the
controller device, which is needed for example when the environment is
located on the mmc device.

To implement the detect callback one needs to pass some data through
the driver private data and the mci core has no business of changing
this data on the controller device struct.

Regards,
Lucas

> > Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> > ---
> >  drivers/mci/stm32_sdmmc2.c | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> > 
> > diff --git a/drivers/mci/stm32_sdmmc2.c b/drivers/mci/stm32_sdmmc2.c
> > index 3ce3bb0f89d2..ac52b62fa0b7 100644
> > --- a/drivers/mci/stm32_sdmmc2.c
> > +++ b/drivers/mci/stm32_sdmmc2.c
> > @@ -571,6 +571,13 @@ static void stm32_sdmmc2_set_ios(struct mci_host *mci, struct mci_ios *ios)
> >  	       priv->base + SDMMC_CLKCR);
> >  }
> >  
> > +static int stm32_sdmmc2_detect(struct device_d *dev)
> > +{
> > +	struct stm32_sdmmc2_priv *priv = dev->priv;
> > +
> > +	return mci_detect_card(&priv->mci);
> > +}
> > +
> >  static int stm32_sdmmc2_probe(struct amba_device *adev,
> >  			      const struct amba_id *id)
> >  {
> > @@ -591,6 +598,9 @@ static int stm32_sdmmc2_probe(struct amba_device *adev,
> >  	mci->init = stm32_sdmmc2_reset;
> >  	mci->hw_dev = dev;
> >  
> > +	dev->priv = priv;
> > +	dev->detect = stm32_sdmmc2_detect;
> > +
> >  	priv->clk = clk_get(dev, NULL);
> >  	if (IS_ERR(priv->clk)) {
> >  		ret = PTR_ERR(priv->clk);
> > 


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2020-05-15  8:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-13 12:08 [PATCH] mci: stm32_sdmmc2: add detect function Lucas Stach
2020-05-13 18:38 ` Ahmad Fatoum
2020-05-15  8:21   ` Lucas Stach

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox