diff mbox series

[3/3] dm: mmc: fix driver rebinding in the case of dtb reloading

Message ID 20240627113546.100333-3-mikhail.kshevetskiy@iopsys.eu
State Changes Requested
Headers show
Series [1/3] fit_dtb: relocate whole fit dtb image instead of selected dtb only | expand

Commit Message

Mikhail Kshevetskiy June 27, 2024, 11:35 a.m. UTC
Rebinding of the mmc driver causes reregistration of block device.
Thus second mmc device appears and the first becomes broken.

Fix an issue by using already registered block device instead of
registering a new one.

Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
---
 drivers/mmc/mmc-uclass.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

Comments

Caleb Connolly June 27, 2024, 11:57 p.m. UTC | #1
Hi Mikhail,

On 27/06/2024 13:35, Mikhail Kshevetskiy wrote:
> Rebinding of the mmc driver causes reregistration of block device.
> Thus second mmc device appears and the first becomes broken.
> 
> Fix an issue by using already registered block device instead of
> registering a new one.
> 
> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
> ---
>   drivers/mmc/mmc-uclass.c | 16 +++++++++++-----
>   1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c
> index 24170c59ecc..403d20dad53 100644
> --- a/drivers/mmc/mmc-uclass.c
> +++ b/drivers/mmc/mmc-uclass.c
> @@ -420,11 +420,17 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
>   	/* Use the fixed index with aliases node's index */
>   	debug("%s: alias devnum=%d\n", __func__, dev_seq(dev));
>   
> -	ret = blk_create_devicef(dev, "mmc_blk", "blk", UCLASS_MMC,
> -				 dev_seq(dev), DEFAULT_BLKSZ, 0, &bdev);
> -	if (ret) {
> -		debug("Cannot create block device\n");
> -		return ret;
> +#if CONFIG_IS_ENABLED(MULTI_DTB_FIT_RESCAN)
> +	device_find_first_child_by_uclass(dev, UCLASS_BLK, &bdev);
> +	if (!bdev)

What about boards with multiple block devices (e.g. ufs + sdcard or mmc 
+ sdcard)?
> +#endif
> +	{
> +		ret = blk_create_devicef(dev, "mmc_blk", "blk", UCLASS_MMC,
> +					 dev_seq(dev), DEFAULT_BLKSZ, 0, &bdev);
> +		if (ret) {
> +			debug("Cannot create block device\n");
> +			return ret;
> +		}
>   	}
>   	bdesc = dev_get_uclass_plat(bdev);
>   	mmc->cfg = cfg;
Simon Glass June 28, 2024, 7:32 a.m. UTC | #2
Hi Mikhail,

On Thu, 27 Jun 2024 at 12:35, Mikhail Kshevetskiy
<mikhail.kshevetskiy@iopsys.eu> wrote:
>
> Rebinding of the mmc driver causes reregistration of block device.
> Thus second mmc device appears and the first becomes broken.
>
> Fix an issue by using already registered block device instead of
> registering a new one.
>
> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
> ---
>  drivers/mmc/mmc-uclass.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c
> index 24170c59ecc..403d20dad53 100644
> --- a/drivers/mmc/mmc-uclass.c
> +++ b/drivers/mmc/mmc-uclass.c
> @@ -420,11 +420,17 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
>         /* Use the fixed index with aliases node's index */
>         debug("%s: alias devnum=%d\n", __func__, dev_seq(dev));
>
> -       ret = blk_create_devicef(dev, "mmc_blk", "blk", UCLASS_MMC,
> -                                dev_seq(dev), DEFAULT_BLKSZ, 0, &bdev);
> -       if (ret) {
> -               debug("Cannot create block device\n");
> -               return ret;
> +#if CONFIG_IS_ENABLED(MULTI_DTB_FIT_RESCAN)
> +       device_find_first_child_by_uclass(dev, UCLASS_BLK, &bdev);
> +       if (!bdev)
> +#endif
> +       {
> +               ret = blk_create_devicef(dev, "mmc_blk", "blk", UCLASS_MMC,
> +                                        dev_seq(dev), DEFAULT_BLKSZ, 0, &bdev);
> +               if (ret) {
> +                       debug("Cannot create block device\n");
> +                       return ret;
> +               }
>         }
>         bdesc = dev_get_uclass_plat(bdev);
>         mmc->cfg = cfg;
> --
> 2.43.0
>

There is a mmc_unbind() function which is supposed to handle unbinding
the mmc block device Can you got into a little more detail as to what
is going wrong?

Regards,
Simon
diff mbox series

Patch

diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c
index 24170c59ecc..403d20dad53 100644
--- a/drivers/mmc/mmc-uclass.c
+++ b/drivers/mmc/mmc-uclass.c
@@ -420,11 +420,17 @@  int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
 	/* Use the fixed index with aliases node's index */
 	debug("%s: alias devnum=%d\n", __func__, dev_seq(dev));
 
-	ret = blk_create_devicef(dev, "mmc_blk", "blk", UCLASS_MMC,
-				 dev_seq(dev), DEFAULT_BLKSZ, 0, &bdev);
-	if (ret) {
-		debug("Cannot create block device\n");
-		return ret;
+#if CONFIG_IS_ENABLED(MULTI_DTB_FIT_RESCAN)
+	device_find_first_child_by_uclass(dev, UCLASS_BLK, &bdev);
+	if (!bdev)
+#endif
+	{
+		ret = blk_create_devicef(dev, "mmc_blk", "blk", UCLASS_MMC,
+					 dev_seq(dev), DEFAULT_BLKSZ, 0, &bdev);
+		if (ret) {
+			debug("Cannot create block device\n");
+			return ret;
+		}
 	}
 	bdesc = dev_get_uclass_plat(bdev);
 	mmc->cfg = cfg;