diff mbox

[U-Boot,2/8] mmc: Probe DM based mmc devices in u-boot

Message ID 1439726516-5461-3-git-send-email-sjoerd.simons@collabora.co.uk
State Superseded
Delegated to: Simon Glass
Headers show

Commit Message

Sjoerd Simons Aug. 16, 2015, 12:01 p.m. UTC
During mmc initialize probe all devices with the MMC Uclass if build
with CONFIG_DM_MMC

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
---

 drivers/mmc/mmc.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

Comments

Simon Glass Aug. 23, 2015, 9:23 p.m. UTC | #1
Hi Sjoerd,

On 16 August 2015 at 06:01, Sjoerd Simons <sjoerd.simons@collabora.co.uk> wrote:
> During mmc initialize probe all devices with the MMC Uclass if build
> with CONFIG_DM_MMC
>
> Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
> ---
>
>  drivers/mmc/mmc.c | 32 ++++++++++++++++++++++++++++----
>  1 file changed, 28 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
> index da47037..a366933 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -10,6 +10,8 @@
>  #include <config.h>
>  #include <common.h>
>  #include <command.h>
> +#include <dm.h>
> +#include <dm/device-internal.h>
>  #include <errno.h>
>  #include <mmc.h>
>  #include <part.h>
> @@ -1759,16 +1761,38 @@ static void do_preinit(void)
>         }
>  }
>
> +#if defined(CONFIG_DM_MMC) && defined(CONFIG_SPL_BUILD)
> +static void mmc_probe(bd_t *bis)
> +{
> +}
> +#elif defined(CONFIG_DM_MMC)
> +static void mmc_probe(bd_t *bis)

This function should return an int error.

> +{
> +       int ret;
> +       struct uclass *uc;
> +       struct udevice *m;
> +
> +       uclass_get(UCLASS_MMC, &uc);

Please error-check this and bail if you see an error. It does
sometimes happen that someone disables enough options that a uclass is
missing, and we want to fail gracefully.

> +       uclass_foreach_dev(m, uc) {
> +               ret = device_probe(m);
> +               if (ret)
> +                       printf("%s - probe failed: %d\n", m->name, ret);
> +       }
> +}
> +#else
> +static void mmc_probe(bd_t *bis)
> +{
> +       if (board_mmc_init(bis) < 0)
> +               cpu_mmc_init(bis);
> +}
> +#endif
>
>  int mmc_initialize(bd_t *bis)
>  {
>         INIT_LIST_HEAD (&mmc_devices);
>         cur_dev_num = 0;
>
> -#ifndef CONFIG_DM_MMC
> -       if (board_mmc_init(bis) < 0)
> -               cpu_mmc_init(bis);
> -#endif
> +       mmc_probe(bis);

Error check

>
>  #ifndef CONFIG_SPL_BUILD
>         print_mmc_devices(',');
> --
> 2.5.0
>

BTW please see an earlier patch:

http://patchwork.ozlabs.org/patch/501315/

which seems to do a similar thing.

Regards,
Simon
diff mbox

Patch

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index da47037..a366933 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -10,6 +10,8 @@ 
 #include <config.h>
 #include <common.h>
 #include <command.h>
+#include <dm.h>
+#include <dm/device-internal.h>
 #include <errno.h>
 #include <mmc.h>
 #include <part.h>
@@ -1759,16 +1761,38 @@  static void do_preinit(void)
 	}
 }
 
+#if defined(CONFIG_DM_MMC) && defined(CONFIG_SPL_BUILD)
+static void mmc_probe(bd_t *bis)
+{
+}
+#elif defined(CONFIG_DM_MMC)
+static void mmc_probe(bd_t *bis)
+{
+	int ret;
+	struct uclass *uc;
+	struct udevice *m;
+
+	uclass_get(UCLASS_MMC, &uc);
+	uclass_foreach_dev(m, uc) {
+		ret = device_probe(m);
+		if (ret)
+			printf("%s - probe failed: %d\n", m->name, ret);
+	}
+}
+#else
+static void mmc_probe(bd_t *bis)
+{
+	if (board_mmc_init(bis) < 0)
+		cpu_mmc_init(bis);
+}
+#endif
 
 int mmc_initialize(bd_t *bis)
 {
 	INIT_LIST_HEAD (&mmc_devices);
 	cur_dev_num = 0;
 
-#ifndef CONFIG_DM_MMC
-	if (board_mmc_init(bis) < 0)
-		cpu_mmc_init(bis);
-#endif
+	mmc_probe(bis);
 
 #ifndef CONFIG_SPL_BUILD
 	print_mmc_devices(',');