diff mbox

[U-Boot,07/10] dm: mmc: Try to honour the sequence order

Message ID 1451391772-6203-8-git-send-email-sjg@chromium.org
State Accepted
Commit 4a1db6d8ab4d5e4565bda079710a028ada12ddbe
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass Dec. 29, 2015, 12:22 p.m. UTC
At present we add driver-model MMC devices in the order we find them. The
'alias' order is not honoured.

It is difficult to fix this for the case where we have holes in the
sequence. But for the common case where the devices are numbered from 0
without any gaps, we can add the devices to the internal data structures
in this order.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/mmc/mmc.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

Comments

Simon Glass Jan. 16, 2016, 1:25 a.m. UTC | #1
On 29 December 2015 at 05:22, Simon Glass <sjg@chromium.org> wrote:
> At present we add driver-model MMC devices in the order we find them. The
> 'alias' order is not honoured.
>
> It is difficult to fix this for the case where we have holes in the
> sequence. But for the common case where the devices are numbered from 0
> without any gaps, we can add the devices to the internal data structures
> in this order.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  drivers/mmc/mmc.c | 20 +++++++++++++++-----
>  1 file changed, 15 insertions(+), 5 deletions(-)

Applied to u-boot-dm
diff mbox

Patch

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 3a34028..ae24b63 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -1772,18 +1772,28 @@  static int mmc_probe(bd_t *bis)
 #elif defined(CONFIG_DM_MMC)
 static int mmc_probe(bd_t *bis)
 {
-	int ret;
+	int ret, i;
 	struct uclass *uc;
-	struct udevice *m;
+	struct udevice *dev;
 
 	ret = uclass_get(UCLASS_MMC, &uc);
 	if (ret)
 		return ret;
 
-	uclass_foreach_dev(m, uc) {
-		ret = device_probe(m);
+	/*
+	 * Try to add them in sequence order. Really with driver model we
+	 * should allow holes, but the current MMC list does not allow that.
+	 * So if we request 0, 1, 3 we will get 0, 1, 2.
+	 */
+	for (i = 0; ; i++) {
+		ret = uclass_get_device_by_seq(UCLASS_MMC, i, &dev);
+		if (ret == -ENODEV)
+			break;
+	}
+	uclass_foreach_dev(dev, uc) {
+		ret = device_probe(dev);
 		if (ret)
-			printf("%s - probe failed: %d\n", m->name, ret);
+			printf("%s - probe failed: %d\n", dev->name, ret);
 	}
 
 	return 0;