diff mbox series

mmc: Allow setting slot index via devicetree alias

Message ID dac73f0ed3a3ed5416dcecd3ac5fdcff3d4232fd.1558864586.git.mirq-linux@rere.qmqm.pl (mailing list archive)
State New, archived
Headers show
Series mmc: Allow setting slot index via devicetree alias | expand

Commit Message

Michał Mirosław May 26, 2019, 9:59 a.m. UTC
As with gpio, uart and others, allow specifying the name_idx via the
aliases-node in the devicetree.

Since commit 9aaf3437aa72 mmcblkX nodes are fixed against mmcX host.
This extension allows embedded devices to keep the same rootfs device
index between board versions using different MMC controllers.

Rewritten for current kernel version from original patch by Sascha Hauer.
> https://www.mail-archive.com/linux-mmc@vger.kernel.org/msg26472.html

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
against v5.1.5
---
 drivers/mmc/core/host.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 3a4402a79904..0ffab498b66f 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -411,7 +411,17 @@  struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
 	/* scanning will be enabled when we're ready */
 	host->rescan_disable = 1;
 
-	err = ida_simple_get(&mmc_host_ida, 0, 0, GFP_KERNEL);
+	err = of_alias_get_id(dev->of_node, "mmc");
+	if (err >= 0)
+		err = ida_alloc_range(&mmc_host_ida, err, err, GFP_KERNEL);
+	if (err < 0) {
+		err = of_alias_get_highest_id("mmc");
+		if (err < 0)
+			err = 0;
+		else
+			++err;
+		err = ida_alloc_min(&mmc_host_ida, err, GFP_KERNEL);
+	}
 	if (err < 0) {
 		kfree(host);
 		return NULL;