From 54d9cf9443519b1596a91ec18e6f2269889bcfd6 Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Tue, 29 Mar 2016 19:43:34 +0900 Subject: [PATCH] mmc: block: Support the fixed index for mmcblk with aliases nodes Now, index of mmcblk is allocated in accordance with probing time. If want to use the mmcblk1 for some device, it can use alias. aliases { mmc0 = &mmc0; /* mmcblk0 for eMMC */ mmc1 = &mmc2; /* mmcblk1 for SD */ mmc2 = &mmc1; /* mmcblk2 for SDIO*/ }; If there are no corresponding values, it might be allocated with existing scheme. Signed-off-by: Jaehoon Chung [sw0312.kim: port to v4.14 - apply to host index instead of name_idx because host index is used in this version ] Signed-off-by: Seung-Woo Kim Change-Id: I44673d62e546ea0aeedd9cac314dbfd31fdcce66 --- Documentation/devicetree/bindings/mmc/mmc.txt | 12 ++++++++++++ drivers/mmc/core/host.c | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/mmc/mmc.txt b/Documentation/devicetree/bindings/mmc/mmc.txt index b32ade645ad9..a6f51dd49c16 100644 --- a/Documentation/devicetree/bindings/mmc/mmc.txt +++ b/Documentation/devicetree/bindings/mmc/mmc.txt @@ -76,6 +76,11 @@ Optional SDIO properties: - wakeup-source: Enables wake up of host system on SDIO IRQ assertion (Legacy property supported: "enable-sdio-wakeup") +Aliases (Optional): +- If you want to use the fixed index for block device like mmcblkX, should be +represented in the aliases node using following format "mmc(X)". +(X is an unique number for the alias.) + MMC power --------- @@ -162,3 +167,10 @@ mmc3: mmc@01c12000 { interrupt-names = "host-wake"; }; }; + +Example with aliases nodes: + +aliases { + mmc0 = &mmc0; /* Fixed to mmcblk0 for &mmc0 */ + mmc1 = &mmc2; /* Fixed to mmcblk1 for &mmc2 */ +}; diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index ad88deb2e8f3..390e676ebbbe 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -349,6 +349,7 @@ EXPORT_SYMBOL(mmc_of_parse); struct mmc_host *mmc_alloc_host(int extra, struct device *dev) { int err; + int idx = 0; struct mmc_host *host; host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL); @@ -358,7 +359,10 @@ 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); + if (dev->of_node) + idx = of_alias_get_id(dev->of_node, "mmc"); + + err = ida_simple_get(&mmc_host_ida, (idx < 0) ? 0 : idx, 0, GFP_KERNEL); if (err < 0) { kfree(host); return NULL; -- 2.34.1