Skip to contentSkip to conversation

drivers: MMC: initialize MMC devices using the device model

PATCH New Andre Przywara 3 participants 3 messages Jul 28, 2015 – Aug 24, 2015 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: MMC: initialize MMC devices using the device model

So far every MMC driver is relying on a board specific init routine, but as the Rockchip MMC driver is the first MMC device model user, it requires a generic DM MMC init routine.

Add that to the MMC init path to enable the Rockchip driver.

---
Hi Simon,

this goes on top of your rockchip-working branch in the u-boot-dm repo.
Not fully satisfied with this one, but the best I could come up with without reading the whole of the device model code ;-) This makes the SD card visible to U-Boot on my RK3288 dev board, I can see partitions and load files from it. It gives me information about the eMMC as well, but I haven't tested this so far except for that mmc info.

Cheers,
Andre.

 drivers/mmc/mmc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/mmc/mmc.c +8 -1
index da47037..52e82b5 100644
@@ -17,6 +17,7 @@
 #include <linux/list.h>
 #include <div64.h>
 #include "mmc_private.h"
+#include <dm.h>
 
 static struct list_head mmc_devices;
 static int cur_dev_num = -1;
@@ -1765,7 +1766,13 @@ int mmc_initialize(bd_t *bis)
 	INIT_LIST_HEAD (&mmc_devices);
 	cur_dev_num = 0;
 
-#ifndef CONFIG_DM_MMC
+#ifdef CONFIG_DM_MMC
+	struct udevice *udev;
+
+	for (;;cur_dev_num++)
+		if (uclass_get_device(UCLASS_MMC, cur_dev_num, &udev))
+			break;
+#else
 	if (board_mmc_init(bis) < 0)
 		cpu_mmc_init(bis);
 #endif
Signature · 1 line
2.3.5
#1 lore raw

PATCH 1/1 drivers: MMC: initialize MMC devices using the device model

Hi Andre,

Quoted 19 lines · Andre Przywara

So far every MMC driver is relying on a board specific init routine, but as the Rockchip MMC driver is the first MMC device model user, it requires a generic DM MMC init routine.

Add that to the MMC init path to enable the Rockchip driver.

---
Hi Simon,

this goes on top of your rockchip-working branch in the u-boot-dm repo.
Not fully satisfied with this one, but the best I could come up with without reading the whole of the device model code ;-) This makes the SD card visible to U-Boot on my RK3288 dev board, I can see partitions and load files from it. It gives me information about the eMMC as well, but I haven't tested this so far except for that mmc info.

Quoted 5 lines

Cheers,
Andre.

 drivers/mmc/mmc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Thanks for the patch and sorry for ignoring it so long. I'm finally getting close to getting the rockchip patches applied.

See also this one:

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

Quoted 14 lines
drivers/mmc/mmc.c +1 -0
index da47037..52e82b5 100644
@@ -17,6 +17,7 @@
 #include <linux/list.h>
 #include <div64.h>
 #include "mmc_private.h"
+#include <dm.h>
 
 static struct list_head mmc_devices;
 static int cur_dev_num = -1;

drivers/mmc/mmc.c int mmc_initialize(bd_t *bis) · line 1774

Quoted 10 lines
drivers/mmc/mmc.c +6 -1
@@ -1765,7 +1766,13 @@ int mmc_initialize(bd_t *bis)
        INIT_LIST_HEAD (&mmc_devices);
        cur_dev_num = 0;
 
-#ifndef CONFIG_DM_MMC
+#ifdef CONFIG_DM_MMC
+       struct udevice *udev;
+
+       for (;;cur_dev_num++)
+               if (uclass_get_device(UCLASS_MMC, cur_dev_num, &udev))
+                       break;

Do you have to increase cur_dev_num? I thought it might happen automatically when a device is probed and calls mmc_create().

Do you think it would work if instead we changed get_mmc_num() to do this?

With driver model we are trying to make it so that devices a probed when they are used, not before. I.e. mmc_initialize() should ideally be a nop.

Quoted 7 lines
drivers/mmc/mmc.c +1 -1
+#else
        if (board_mmc_init(bis) < 0)
                cpu_mmc_init(bis);
 #endif
--

2.3.5

Regards,
Simon

#2 lore raw

PATCH 1/1 drivers: MMC: initialize MMC devices using the device model

Quoted 31 lines · Simon Glass

Hi Andre,

Quoted 21 lines · Andre Przywara

So far every MMC driver is relying on a board specific init routine,
but as the Rockchip MMC driver is the first MMC device model user, it requires a generic DM MMC init routine.

Add that to the MMC init path to enable the Rockchip driver.

---
Hi Simon,

this goes on top of your rockchip-working branch in the u-boot-dm repo.
Not fully satisfied with this one, but the best I could come up with
without reading the whole of the device model code ;-) This makes the SD card visible to U-Boot on my RK3288 dev board, I can see partitions and load files from it. It gives me information about the eMMC as well, but I haven't tested this so far except for that mmc info.

Quoted 5 lines

Cheers,
Andre.

 drivers/mmc/mmc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
Quoted 6 lines

Thanks for the patch and sorry for ignoring it so long. I'm finally getting close to getting the rockchip patches applied.

See also this one:

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

As the author of that one, i missed this one :/

Quoted 17 lines
Quoted 17 lines
drivers/mmc/mmc.c +1 -0
index da47037..52e82b5 100644
@@ -17,6 +17,7 @@
 #include <linux/list.h>
 #include <div64.h>
 #include "mmc_private.h"
+#include <dm.h>
 
 static struct list_head mmc_devices;
 static int cur_dev_num = -1;
@@ -1765,7 +1766,13 @@ int mmc_initialize(bd_t *bis)
        INIT_LIST_HEAD (&mmc_devices);
        cur_dev_num = 0;
 
Quoted 11 lines

drivers/mmc/mmc.c int mmc_initialize(bd_t *bis) · line 1774

Quoted 8 lines
drivers/mmc/mmc.c +6 -1
-#ifndef CONFIG_DM_MMC
+#ifdef CONFIG_DM_MMC
+       struct udevice *udev;
+
+       for (;;cur_dev_num++)
+               if (uclass_get_device(UCLASS_MMC, cur_dev_num, 
 &udev))
+                       break;

Do you have to increase cur_dev_num? I thought it might happen automatically when a device is probed and calls mmc_create().

Yes mmc_create increases it so this way is buggy.. I think my patch is nicer here wrt. using uclass_foreach_device. Also i was under the impression that in principle there could be gaps in the device numbers in DM ? (maybe thats not the case for the MMC ones though)

Quoted 6 lines

Do you think it would work if instead we changed get_mmc_num() to do this?

With driver model we are trying to make it so that devices a probed when they are used, not before. I.e. mmc_initialize() should ideally be a nop.

The key here is that functions like print_mmc_devices and find_mmc_device simply iterate the mmc_devices list, so i don't think you can key on get_mmc_num at the moment.

Ofcourse a nicer long-term solution would be to make those functions be DM aware so that the mmc_devices list can disappear, but either this patch or mine seems like a reasonable first small step :)

Quoted 14 lines
Quoted 7 lines
drivers/mmc/mmc.c +1 -0
+#else
        if (board_mmc_init(bis) < 0)
                cpu_mmc_init(bis);

#endif
--
2.3.5

Regards,
Simon
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Signature · 2 lines
Sjoerd Simons <[email protected]>
Collabora Ltd.