From 15a1196be81c6bfc847a58dc65151ce439630f7d Mon Sep 17 00:00:00 2001
From: Simon Glass <sjg@chromium.org>
Date: Wed, 16 Dec 2020 21:20:17 -0700
Subject: [PATCH] dm: core: Allow manual sequence numbering

Some buses have their own rules which require assigning sequence numbers
with a bus-specific algorithm. For example, PCI requires that sub-buses
are numbered higher than their parent buses, meaning effectively that
parent buses must be numbered only after all of their child buses have
been numbered.

Add a uclass flag to indicate that driver model should not assign sequence
numbers. In this case, the uclass must do it.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 drivers/core/device.c | 2 +-
 include/dm/uclass.h   | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 1e681333d3..d2cf05c8c4 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -103,7 +103,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,
 			dev->req_seq = uclass_find_next_free_req_seq(uc);
 		}
 	}
-	if (auto_seq)
+	if (auto_seq && !(uc->uc_drv->flags & DM_UC_FLAG_NO_AUTO_SEQ))
 		dev->sqq = uclass_find_next_free_req_seq(uc);
 
 	if (drv->plat_auto) {
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index 068e8ea8bf..c4cd58349e 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -44,6 +44,9 @@ struct udevice;
 /* Members of this uclass sequence themselves with aliases */
 #define DM_UC_FLAG_SEQ_ALIAS			(1 << 0)
 
+/* Members of this uclass without aliases don't get a sequence number */
+#define DM_UC_FLAG_NO_AUTO_SEQ			(1 << 1)
+
 /* Same as DM_FLAG_ALLOC_PRIV_DMA */
 #define DM_UC_FLAG_ALLOC_PRIV_DMA		(1 << 5)
 
-- 
2.39.5