diff mbox series

mmc: stm32_sdmmc2: Use mmc_of_parse() to read host capabilities

Message ID 20200909215402.366561-1-mr.nuke.me@gmail.com
State Accepted
Commit c981d67a0444cf31e5a16fe4be79d785eb182385
Delegated to: Patrice Chotard
Headers show
Series mmc: stm32_sdmmc2: Use mmc_of_parse() to read host capabilities | expand

Commit Message

Alex G. Sept. 9, 2020, 9:54 p.m. UTC
mmc_of_parse() can populate the 'f_max' and 'host_caps' fields of
struct mmc_config from devicetree.
The same logic is duplicated in stm32_sdmmc2_probe(). Use
mmc_of_parse(), which is more generic.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
---
 drivers/mmc/stm32_sdmmc2.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)

Comments

Patrice CHOTARD Sept. 10, 2020, 7:52 a.m. UTC | #1
Hi Alexandru

On 9/9/20 11:54 PM, Alexandru Gagniuc wrote:
> mmc_of_parse() can populate the 'f_max' and 'host_caps' fields of
> struct mmc_config from devicetree.
> The same logic is duplicated in stm32_sdmmc2_probe(). Use
> mmc_of_parse(), which is more generic.
>
> Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
> ---
>  drivers/mmc/stm32_sdmmc2.c | 18 ++----------------
>  1 file changed, 2 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/mmc/stm32_sdmmc2.c b/drivers/mmc/stm32_sdmmc2.c
> index 6d50356217..77871d5afc 100644
> --- a/drivers/mmc/stm32_sdmmc2.c
> +++ b/drivers/mmc/stm32_sdmmc2.c
> @@ -676,27 +676,13 @@ static int stm32_sdmmc2_probe(struct udevice *dev)
>  			     GPIOD_IS_IN);
>  
>  	cfg->f_min = 400000;
> -	cfg->f_max = dev_read_u32_default(dev, "max-frequency", 52000000);
>  	cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
>  	cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
>  	cfg->name = "STM32 SD/MMC";
>  
>  	cfg->host_caps = 0;
> -	if (cfg->f_max > 25000000)
> -		cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
> -
> -	switch (dev_read_u32_default(dev, "bus-width", 1)) {
> -	case 8:
> -		cfg->host_caps |= MMC_MODE_8BIT;
> -		/* fall through */
> -	case 4:
> -		cfg->host_caps |= MMC_MODE_4BIT;
> -		break;
> -	case 1:
> -		break;
> -	default:
> -		pr_err("invalid \"bus-width\" property, force to 1\n");
> -	}
> +	cfg->f_max = 52000000;
> +	mmc_of_parse(dev, cfg);
>  
>  	upriv->mmc = &plat->mmc;

Reviewed-by: Patrice Chotard <patrice.chotard@st.com>

Patrice

Thanks

>
Patrick DELAUNAY Sept. 10, 2020, 4:04 p.m. UTC | #2
Hi Alexandru,

> Sent: mercredi 9 septembre 2020 23:54
> To: uboot-stm32@st-md-mailman.stormreply.com
> Cc: Alexandru Gagniuc <mr.nuke.me@gmail.com>; Patrick DELAUNAY
> <patrick.delaunay@st.com>; Patrice CHOTARD <patrice.chotard@st.com>; Peng
> Fan <peng.fan@nxp.com>; u-boot@lists.denx.de
> Subject: [PATCH] mmc: stm32_sdmmc2: Use mmc_of_parse() to read host
> capabilities
> Importance: High
> 
> mmc_of_parse() can populate the 'f_max' and 'host_caps' fields of struct
> mmc_config from devicetree.
> The same logic is duplicated in stm32_sdmmc2_probe(). Use mmc_of_parse(),
> which is more generic.
> 
> Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
> ---

Thanks for the patch, I miss the addition of this new API.

>  drivers/mmc/stm32_sdmmc2.c | 18 ++----------------
>  1 file changed, 2 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/mmc/stm32_sdmmc2.c b/drivers/mmc/stm32_sdmmc2.c index
> 6d50356217..77871d5afc 100644
> --- a/drivers/mmc/stm32_sdmmc2.c
> +++ b/drivers/mmc/stm32_sdmmc2.c
> @@ -676,27 +676,13 @@ static int stm32_sdmmc2_probe(struct udevice *dev)
>  			     GPIOD_IS_IN);
> 
>  	cfg->f_min = 400000;
> -	cfg->f_max = dev_read_u32_default(dev, "max-frequency", 52000000);
>  	cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 |
> MMC_VDD_165_195;
>  	cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
>  	cfg->name = "STM32 SD/MMC";
> 
>  	cfg->host_caps = 0;
> -	if (cfg->f_max > 25000000)
> -		cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
> -
> -	switch (dev_read_u32_default(dev, "bus-width", 1)) {
> -	case 8:
> -		cfg->host_caps |= MMC_MODE_8BIT;
> -		/* fall through */
> -	case 4:
> -		cfg->host_caps |= MMC_MODE_4BIT;
> -		break;
> -	case 1:
> -		break;
> -	default:
> -		pr_err("invalid \"bus-width\" property, force to 1\n");
> -	}
> +	cfg->f_max = 52000000;
> +	mmc_of_parse(dev, cfg);

Result of mmc_of_parse is not tested ?

I proposed:

+	ret = mmc_of_parse(dev, cfg);
+	if (ret)
+		return ret;

> 
>  	upriv->mmc = &plat->mmc;
> 
> --
> 2.25.4

I test this patch with a trace in stm32_sdmmc2_probe on STM32MP157C-EV1

Before the patch :
cfg->host_caps = 0x2000000e (SD card)
cfg->host_caps = 0x6000000e (eMMC)

After the patch:
cfg->host_caps = 0x300001e6 (SD card)
cfg->host_caps = 0x70004006 (eMMC)


I see 2 problem here :

1/ MMC_MODE_HS_52MHz = MMC_CAP(MMC_HS_52) is removed
    and the eMMC on EV1 use only at 26MHz instead 52MHz before the patch

	Mode: MMC High Speed (52MHz)
	=>
	Mode: MMC High Speed (26MHz)

The "cap-mmc-highspeed" is used in Linux for MMC HS at 26MHz or 52MHz

./Documentation/devicetree/bindings/mmc/mmc-controller.yaml:122: 
cap-mmc-highspeed:
    $ref: /schemas/types.yaml#/definitions/flag
    description:
      MMC high-speed timing is supported.

And in Linux mmc/core/mmc.c
	static void mmc_select_card_type(struct mmc_card *card)
	{
	.....

	if (caps & MMC_CAP_MMC_HIGHSPEED &&
	    card_type & EXT_CSD_CARD_TYPE_HS_26) {
		hs_max_dtr = MMC_HIGH_26_MAX_DTR;
		avail_type |= EXT_CSD_CARD_TYPE_HS_26;
	}

	if (caps & MMC_CAP_MMC_HIGHSPEED &&
	    card_type & EXT_CSD_CARD_TYPE_HS_52) {
		hs_max_dtr = MMC_HIGH_52_MAX_DTR;
		avail_type |= EXT_CSD_CARD_TYPE_HS_52;
	}
	....

include/linux/mmc/mmc.h:347:
	#define EXT_CSD_CARD_TYPE_HS_26	(1<<0)	/* Card can run at 26MHz */
	#define EXT_CSD_CARD_TYPE_HS_52	(1<<1)	/* Card can run at 52MHz */

I think that it is a issue U-Boot, in mmc uclass in mmc_of_parse():

	if (dev_read_bool(dev, "cap-mmc-highspeed"))
-		cfg->host_caps |= MMC_CAP(MMC_HS);
+		cfg->host_caps |= MMC_CAP(MMC_HS) | MMC_CAP(MMC_HS_52);

In U-Boot this capability is splitted in 2 bits = one for 26MHz one for 52MHz
And  for card side it is managed on card side by mmc_get_capabilities()

include/mmc.h:254:
	#define EXT_CSD_CARD_TYPE_26	(1 << 0)	/* Card can run at 26MHz */
	#define EXT_CSD_CARD_TYPE_52	(1 << 1)	/* Card can run at 52MHz */

A other solution is to only impact the sdmmc driver..... 
and to activate 52MHZ mode support is frequency is >= 26MHz

	cfg->f_max = 52000000;
	ret = mmc_of_parse(dev, cfg);
	if (ret)
		return ret;

	if ((cfg->host_caps & MMC_HS) && 
	    cfg->f_max > 26000000)
		cfg->host_caps |= MMC_HS_52;

but I prefer the previous generic solution in u-class.


2) some host caps can be added in device tree (they are supported by SOC and by Linux driver)
    but they are not supported by U-Boot driver, for example:

#define MMC_MODE_DDR_52MHz	MMC_CAP(MMC_DDR_52)
#define MMC_MODE_HS200		MMC_CAP(MMC_HS_200)
#define MMC_MODE_HS400		MMC_CAP(MMC_HS_400)
#define MMC_MODE_HS400_ES	MMC_CAP(MMC_HS_400_ES)

MMC_CAP(UHS_SDR12)
MMC_CAP(UHS_SDR25) 
MMC_CAP(UHS_SDR50)
MMC_CAP(UHS_SDR104)
MMC_CAP(UHS_DDR50)

I afraid (I don't sure) that this added caps change the mmc core behavior in U-Boot =
U-Boot try to select  the high speed mode even if not supported by driver....

The host_caps bitfield should be limited by the supported features in the driver  (or remove the unsupported features)

#define SDMMC_SUPPORTED_CAPS (MMC_MODE_1BIT | MMC_MODE_4BIT | MMC_MODE_8BIT | MMC_CAP_CD_ACTIVE_HIGH | MMC_CAP_NEEDS_POLL |  MMC_CAP_NONREMOVABLE | MMC_MODE_HS | MMC_MODE_HS_52MHz)
or
#define SDMMC_UNSUPPORTED_CAPS (MMC_MODE_DDR_52MHz | MMC_MODE_HS200 | MMC_MODE_HS400 | MMC_MODE_HS400_ES | UHS_CAPS)
 
	cfg->f_max = 52000000;
	ret = mmc_of_parse(dev, cfg);
	if (ret)
		return ret;

	cfg->host_caps &= SDMMC_SUPPORTED_CAPS;
or 
	cfg->host_caps |= ~SDMMC_UNSUPPORTED_CAPS;


Best Regards

Patrick
Alex G. Sept. 10, 2020, 8:10 p.m. UTC | #3
On 9/10/20 11:04 AM, Patrick DELAUNAY wrote:
> Hi Alexandru,

Hi

[snip]

>> +	cfg->f_max = 52000000;
>> +	mmc_of_parse(dev, cfg);
> 
> Result of mmc_of_parse is not tested ?
> 
> I proposed:
> 
> +	ret = mmc_of_parse(dev, cfg);
> +	if (ret)
> +		return ret;

You're right. I'll get that updated.


> I test this patch with a trace in stm32_sdmmc2_probe on STM32MP157C-EV1
[snip]
> I think that it is a issue U-Boot, in mmc uclass in mmc_of_parse():
> 
> 	if (dev_read_bool(dev, "cap-mmc-highspeed"))
> -		cfg->host_caps |= MMC_CAP(MMC_HS);
> +		cfg->host_caps |= MMC_CAP(MMC_HS) | MMC_CAP(MMC_HS_52);
> 
> In U-Boot this capability is splitted in 2 bits = one for 26MHz one for 52MHz
> And  for card side it is managed on card side by mmc_get_capabilities()

I agree. I am preparing a patch to address this.


[snip]
> 2) some host caps can be added in device tree (they are supported by SOC and by Linux driver)
>      but they are not supported by U-Boot driver, for example:
> 
> #define MMC_MODE_DDR_52MHz	MMC_CAP(MMC_DDR_52)
> #define MMC_MODE_HS200		MMC_CAP(MMC_HS_200)
> #define MMC_MODE_HS400		MMC_CAP(MMC_HS_400)
> #define MMC_MODE_HS400_ES	MMC_CAP(MMC_HS_400_ES)
> 
> 
> I afraid (I don't sure) that this added caps change the mmc core behavior in U-Boot =
> U-Boot try to select  the high speed mode even if not supported by driver....

Two issues here. The first is when devicetree enables an unsupported 
mode, say "mmc-hs400-1_2v". That's a devicetree bug, and not something 
we should fix in the code. Hypothetical exam: DT says
	bus-width = <8>;
but only four lines are routed on the board.

The second issue is what happens when somebody plugs in a UHS SD card? 
UHS support is not enabled by default in the stm32mp1 defconfigs, so the 
mmc core won't try to run it at UHS.

Now if somebody were to enable UHS manually:
	CONFIG_MMC_IO_VOLTAGE=y
	CONFIG_MMC_UHS_SUPPORT=y
Then yes, the UHS switch will be attempted, fail, and the card will not 
be detected.

To work around that, one could implement a .wait_dat0() that returns an 
error other than -ENOSYS. This would cause mmc_switch_voltage() to fail, 
making the mmc core to leave the card at default speeds.

My argument is that it takes conscious effort to break things in the 
first place, so it's not a situation we should worry about.


> The host_caps bitfield should be limited by the supported features in the driver  (or remove the unsupported features)
[snip]
> 	cfg->host_caps &= SDMMC_SUPPORTED_CAPS;
> or
> 	cfg->host_caps |= ~SDMMC_UNSUPPORTED_CAPS;

I think this sort of playing with the flags will cause more confusion. 
People would expect this to come from DT. For example, somebody sets 
"sd-uhs-ddr52" in devicetree. It's more confusing to check host_caps, 
and find that MMC_MODE_DDR_52MHz is not set than it is to see the driver 
trying to place the card in DDR52 and failing.

Alex
Jaehoon Chung Sept. 11, 2020, 7:49 a.m. UTC | #4
On 9/10/20 6:54 AM, Alexandru Gagniuc wrote:
> mmc_of_parse() can populate the 'f_max' and 'host_caps' fields of
> struct mmc_config from devicetree.
> The same logic is duplicated in stm32_sdmmc2_probe(). Use
> mmc_of_parse(), which is more generic.
> 
> Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
> ---
>  drivers/mmc/stm32_sdmmc2.c | 18 ++----------------
>  1 file changed, 2 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/mmc/stm32_sdmmc2.c b/drivers/mmc/stm32_sdmmc2.c
> index 6d50356217..77871d5afc 100644
> --- a/drivers/mmc/stm32_sdmmc2.c
> +++ b/drivers/mmc/stm32_sdmmc2.c
> @@ -676,27 +676,13 @@ static int stm32_sdmmc2_probe(struct udevice *dev)
>  			     GPIOD_IS_IN);
>  
>  	cfg->f_min = 400000;
> -	cfg->f_max = dev_read_u32_default(dev, "max-frequency", 52000000);
>  	cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
>  	cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
>  	cfg->name = "STM32 SD/MMC";
>  
>  	cfg->host_caps = 0;
> -	if (cfg->f_max > 25000000)
> -		cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
> -
> -	switch (dev_read_u32_default(dev, "bus-width", 1)) {
> -	case 8:
> -		cfg->host_caps |= MMC_MODE_8BIT;
> -		/* fall through */
> -	case 4:
> -		cfg->host_caps |= MMC_MODE_4BIT;
> -		break;
> -	case 1:
> -		break;
> -	default:
> -		pr_err("invalid \"bus-width\" property, force to 1\n");
> -	}
> +	cfg->f_max = 52000000;

cfg->f_max can be also removed?

Best Regards,
Jaehoon Chung

> +	mmc_of_parse(dev, cfg);
>  
>  	upriv->mmc = &plat->mmc;
>  
>
Patrick DELAUNAY Sept. 11, 2020, 9 a.m. UTC | #5
Hi Alex,

> From: Alex G. <mr.nuke.me@gmail.com>
> Sent: jeudi 10 septembre 2020 22:10
> 
> On 9/10/20 11:04 AM, Patrick DELAUNAY wrote:
> > Hi Alexandru,
> 
> Hi
> 
> [snip]
> 
> >> +	cfg->f_max = 52000000;
> >> +	mmc_of_parse(dev, cfg);
> >
> > Result of mmc_of_parse is not tested ?
> >
> > I proposed:
> >
> > +	ret = mmc_of_parse(dev, cfg);
> > +	if (ret)
> > +		return ret;
> 
> You're right. I'll get that updated.

Thanks;
 
> 
> > I test this patch with a trace in stm32_sdmmc2_probe on
> > STM32MP157C-EV1
> [snip]
> > I think that it is a issue U-Boot, in mmc uclass in mmc_of_parse():
> >
> > 	if (dev_read_bool(dev, "cap-mmc-highspeed"))
> > -		cfg->host_caps |= MMC_CAP(MMC_HS);
> > +		cfg->host_caps |= MMC_CAP(MMC_HS) |
> MMC_CAP(MMC_HS_52);
> >
> > In U-Boot this capability is splitted in 2 bits = one for 26MHz one
> > for 52MHz And  for card side it is managed on card side by
> > mmc_get_capabilities()
> 
> I agree. I am preparing a patch to address this.

Thanks;
 
> 
> [snip]
> > 2) some host caps can be added in device tree (they are supported by SOC and
> by Linux driver)
> >      but they are not supported by U-Boot driver, for example:
> >
> > #define MMC_MODE_DDR_52MHz	MMC_CAP(MMC_DDR_52)
> > #define MMC_MODE_HS200		MMC_CAP(MMC_HS_200)
> > #define MMC_MODE_HS400		MMC_CAP(MMC_HS_400)
> > #define MMC_MODE_HS400_ES	MMC_CAP(MMC_HS_400_ES)
> >
> >
> > I afraid (I don't sure) that this added caps change the mmc core
> > behavior in U-Boot = U-Boot try to select  the high speed mode even if not
> supported by driver....
> 
> Two issues here. The first is when devicetree enables an unsupported mode, say
> "mmc-hs400-1_2v". That's a devicetree bug, and not something we should fix in
> the code. Hypothetical exam: DT says
> 	bus-width = <8>;
> but only four lines are routed on the board.

Yes it is a device tree issue when the mode is not supported by board / SOC.

But high mode is supported by the STM32MP15x SOC but only if additional
Operation are done (IO configuration to support higher speed) 

It is not supported in U-Boot driver (yet ?) but it is supported by Linux driver...

> The second issue is what happens when somebody plugs in a UHS SD card?
> UHS support is not enabled by default in the stm32mp1 defconfigs, so the mmc
> core won't try to run it at UHS.
> 
> Now if somebody were to enable UHS manually:
> 	CONFIG_MMC_IO_VOLTAGE=y
> 	CONFIG_MMC_UHS_SUPPORT=y
> Then yes, the UHS switch will be attempted, fail, and the card will not be detected.
> 
> To work around that, one could implement a .wait_dat0() that returns an error
> other than -ENOSYS. This would cause mmc_switch_voltage() to fail, making the
> mmc core to leave the card at default speeds.
> 
> My argument is that it takes conscious effort to break things in the first place, so
> it's not a situation we should worry about.
> 

Yes  we should have issue only if UHS defconfig was activated
(CONFIG_MMC_UHS_SUPPORT, CONFIG_MMC_HS*_SUPPORT)....

And it is not the case today in stm32*defconfig
And my proposal is protection (over).

> > The host_caps bitfield should be limited by the supported features in the driver
> (or remove the unsupported features)
> [snip]
> > 	cfg->host_caps &= SDMMC_SUPPORTED_CAPS;
> > or
> > 	cfg->host_caps |= ~SDMMC_UNSUPPORTED_CAPS;
> 
> I think this sort of playing with the flags will cause more confusion.
> People would expect this to come from DT. For example, somebody sets
> "sd-uhs-ddr52" in devicetree. It's more confusing to check host_caps,
> and find that MMC_MODE_DDR_52MHz is not set than it is to see the driver
> trying to place the card in DDR52 and failing.

- card_caps = CARD capacity

For you
- host_caps is SOC capacity (read from DT)

For me 
- host_caps is SOC capacity (read from DT) AND driver capacity

=> then in mmc u-class, the real capacity is  host_caps | card_caps

I already see this kind of limitation in one driver 
omap_hsmmc.c:1939:		cfg->host_caps &= ~fixups->unsupported_caps;

But I agree it is today an over protection on host_caps and it can be confusing
so you can forget this point....

> Alex

Regards

Patrick
Patrick DELAUNAY Sept. 11, 2020, 11:46 a.m. UTC | #6
Hi Jaehoon

> From: Jaehoon Chung <jh80.chung@samsung.com>
> Sent: vendredi 11 septembre 2020 09:50
> 
> On 9/10/20 6:54 AM, Alexandru Gagniuc wrote:
> > mmc_of_parse() can populate the 'f_max' and 'host_caps' fields of
> > struct mmc_config from devicetree.
> > The same logic is duplicated in stm32_sdmmc2_probe(). Use
> > mmc_of_parse(), which is more generic.
> >
> > Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
> > ---
> >  drivers/mmc/stm32_sdmmc2.c | 18 ++----------------
> >  1 file changed, 2 insertions(+), 16 deletions(-)
> >
> > diff --git a/drivers/mmc/stm32_sdmmc2.c b/drivers/mmc/stm32_sdmmc2.c
> > index 6d50356217..77871d5afc 100644
> > --- a/drivers/mmc/stm32_sdmmc2.c
> > +++ b/drivers/mmc/stm32_sdmmc2.c
> > @@ -676,27 +676,13 @@ static int stm32_sdmmc2_probe(struct udevice *dev)
> >  			     GPIOD_IS_IN);
> >
> >  	cfg->f_min = 400000;
> > -	cfg->f_max = dev_read_u32_default(dev, "max-frequency", 52000000);
> >  	cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 |
> MMC_VDD_165_195;
> >  	cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
> >  	cfg->name = "STM32 SD/MMC";
> >
> >  	cfg->host_caps = 0;
> > -	if (cfg->f_max > 25000000)
> > -		cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
> > -
> > -	switch (dev_read_u32_default(dev, "bus-width", 1)) {
> > -	case 8:
> > -		cfg->host_caps |= MMC_MODE_8BIT;
> > -		/* fall through */
> > -	case 4:
> > -		cfg->host_caps |= MMC_MODE_4BIT;
> > -		break;
> > -	case 1:
> > -		break;
> > -	default:
> > -		pr_err("invalid \"bus-width\" property, force to 1\n");
> > -	}
> > +	cfg->f_max = 52000000;
> 
> cfg->f_max can be also removed?
> 
> Best Regards,
> Jaehoon Chung

I don't think because " max-frequency" is optional in device tree (only "reg" is required)

Here 52MHz is a default value when it is absent in device tree
That avoids cfg->f_max = 0 after mmc_of_parse() call.

> 
> > +	mmc_of_parse(dev, cfg);
> >
> >  	upriv->mmc = &plat->mmc;
> >
> >

Patrick
Jaehoon Chung Sept. 16, 2020, 1:50 a.m. UTC | #7
On 9/11/20 8:46 PM, Patrick DELAUNAY wrote:
> Hi Jaehoon
> 
>> From: Jaehoon Chung <jh80.chung@samsung.com>
>> Sent: vendredi 11 septembre 2020 09:50
>>
>> On 9/10/20 6:54 AM, Alexandru Gagniuc wrote:
>>> mmc_of_parse() can populate the 'f_max' and 'host_caps' fields of
>>> struct mmc_config from devicetree.
>>> The same logic is duplicated in stm32_sdmmc2_probe(). Use
>>> mmc_of_parse(), which is more generic.
>>>
>>> Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>

Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

Best Regards,
Jaehoon Chung

>>> ---
>>>  drivers/mmc/stm32_sdmmc2.c | 18 ++----------------
>>>  1 file changed, 2 insertions(+), 16 deletions(-)
>>>
>>> diff --git a/drivers/mmc/stm32_sdmmc2.c b/drivers/mmc/stm32_sdmmc2.c
>>> index 6d50356217..77871d5afc 100644
>>> --- a/drivers/mmc/stm32_sdmmc2.c
>>> +++ b/drivers/mmc/stm32_sdmmc2.c
>>> @@ -676,27 +676,13 @@ static int stm32_sdmmc2_probe(struct udevice *dev)
>>>  			     GPIOD_IS_IN);
>>>
>>>  	cfg->f_min = 400000;
>>> -	cfg->f_max = dev_read_u32_default(dev, "max-frequency", 52000000);
>>>  	cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 |
>> MMC_VDD_165_195;
>>>  	cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
>>>  	cfg->name = "STM32 SD/MMC";
>>>
>>>  	cfg->host_caps = 0;
>>> -	if (cfg->f_max > 25000000)
>>> -		cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
>>> -
>>> -	switch (dev_read_u32_default(dev, "bus-width", 1)) {
>>> -	case 8:
>>> -		cfg->host_caps |= MMC_MODE_8BIT;
>>> -		/* fall through */
>>> -	case 4:
>>> -		cfg->host_caps |= MMC_MODE_4BIT;
>>> -		break;
>>> -	case 1:
>>> -		break;
>>> -	default:
>>> -		pr_err("invalid \"bus-width\" property, force to 1\n");
>>> -	}
>>> +	cfg->f_max = 52000000;
>>
>> cfg->f_max can be also removed?
>>
>> Best Regards,
>> Jaehoon Chung
> 
> I don't think because " max-frequency" is optional in device tree (only "reg" is required)
> 
> Here 52MHz is a default value when it is absent in device tree
> That avoids cfg->f_max = 0 after mmc_of_parse() call.
> 
>>
>>> +	mmc_of_parse(dev, cfg);
>>>
>>>  	upriv->mmc = &plat->mmc;
>>>
>>>
> 
> Patrick
>
diff mbox series

Patch

diff --git a/drivers/mmc/stm32_sdmmc2.c b/drivers/mmc/stm32_sdmmc2.c
index 6d50356217..77871d5afc 100644
--- a/drivers/mmc/stm32_sdmmc2.c
+++ b/drivers/mmc/stm32_sdmmc2.c
@@ -676,27 +676,13 @@  static int stm32_sdmmc2_probe(struct udevice *dev)
 			     GPIOD_IS_IN);
 
 	cfg->f_min = 400000;
-	cfg->f_max = dev_read_u32_default(dev, "max-frequency", 52000000);
 	cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
 	cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
 	cfg->name = "STM32 SD/MMC";
 
 	cfg->host_caps = 0;
-	if (cfg->f_max > 25000000)
-		cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
-
-	switch (dev_read_u32_default(dev, "bus-width", 1)) {
-	case 8:
-		cfg->host_caps |= MMC_MODE_8BIT;
-		/* fall through */
-	case 4:
-		cfg->host_caps |= MMC_MODE_4BIT;
-		break;
-	case 1:
-		break;
-	default:
-		pr_err("invalid \"bus-width\" property, force to 1\n");
-	}
+	cfg->f_max = 52000000;
+	mmc_of_parse(dev, cfg);
 
 	upriv->mmc = &plat->mmc;