diff options
author | Haibo Chen <haibo.chen@nxp.com> | 2018-02-26 15:12:18 +0800 |
---|---|---|
committer | Leonard Crestez <leonard.crestez@nxp.com> | 2018-08-24 12:41:33 +0300 |
commit | 2cca9221d074b6a788a86c8954753bcdd641b8e3 (patch) | |
tree | 7b5fe492639804ad45b1d6a839dc5ee54ec6647c | |
parent | 40f63206f94e9a95e5ed78052e27f2c457f661a0 (diff) |
MLK-17621-2 mmc: add feature of setting slot index via devicetree alias
Add feature of setting slot index via devicetree alias, to hard code the
mmc/sd root device.
The patch requires additional alias_id fix or it won't work.
Note: minor device number keep independent with this device alias.
Refer to the commit 35928d6c6a76 ("mmc: Allow setting slot index via
devicetree alias").
Acked-by: Leonard Crestez <leonard.crestez@nxp.com>
Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
-rw-r--r-- | drivers/mmc/core/core.c | 38 | ||||
-rw-r--r-- | drivers/mmc/core/core.h | 2 | ||||
-rw-r--r-- | drivers/mmc/core/host.c | 12 | ||||
-rw-r--r-- | drivers/of/base.c | 1 |
4 files changed, 51 insertions, 2 deletions
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 4d322dbc19df..f57d97ff41f0 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -64,6 +64,8 @@ static const unsigned freqs[] = { 400000, 300000, 200000, 100000 }; +static int __mmc_max_reserved_idx = -1; + /* * Enabling software CRCs on the data blocks can be a significant (30%) * performance cost, and for other reasons may not always be desired. @@ -3173,10 +3175,46 @@ void mmc_init_context_info(struct mmc_host *host) init_waitqueue_head(&host->context_info.wait); } +/* + * mmc_first_nonreserved_index() - get the first index that + * is not reserved + */ +int mmc_first_nonreserved_index(void) +{ + return __mmc_max_reserved_idx + 1; +} +EXPORT_SYMBOL(mmc_first_nonreserved_index); + +/* + * mmc_get_reserved_index() - get the index reserved for this host + * Return: The index reserved for this host or negative error value + * if no index is reserved for this host + */ +int mmc_get_reserved_index(struct mmc_host *host) +{ + return of_alias_get_id(host->parent->of_node, "mmc"); +} +EXPORT_SYMBOL(mmc_get_reserved_index); + +static void mmc_of_reserve_idx(void) +{ + int max; + + max = of_alias_max_index("mmc"); + if (max < 0) + return; + + __mmc_max_reserved_idx = max; + pr_debug("MMC: reserving %d slots for of aliases\n", + __mmc_max_reserved_idx + 1); +} + static int __init mmc_init(void) { int ret; + mmc_of_reserve_idx(); + ret = mmc_register_bus(); if (ret) return ret; diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h index 55f543fd37c4..222f588706e7 100644 --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h @@ -80,6 +80,8 @@ int mmc_attach_mmc(struct mmc_host *host); int mmc_attach_sd(struct mmc_host *host); int mmc_attach_sdio(struct mmc_host *host); +int mmc_first_nonreserved_index(void); +int mmc_get_reserved_index(struct mmc_host *host); /* Module parameters */ extern bool use_spi_crc; diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index f56b4902424e..aa4afba7ab1e 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -353,6 +353,7 @@ EXPORT_SYMBOL(mmc_of_parse); struct mmc_host *mmc_alloc_host(int extra, struct device *dev) { int err; + int alias_id; struct mmc_host *host; host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL); @@ -361,8 +362,16 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) /* scanning will be enabled when we're ready */ host->rescan_disable = 1; + host->parent = dev; - err = ida_simple_get(&mmc_host_ida, 0, 0, GFP_KERNEL); + alias_id = mmc_get_reserved_index(host); + if (alias_id >= 0) + err = ida_simple_get(&mmc_host_ida, alias_id, + alias_id + 1, GFP_KERNEL); + else + err = ida_simple_get(&mmc_host_ida, + mmc_first_nonreserved_index(), + 0, GFP_KERNEL); if (err < 0) { kfree(host); return NULL; @@ -372,7 +381,6 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) dev_set_name(&host->class_dev, "mmc%d", host->index); - host->parent = dev; host->class_dev.parent = dev; host->class_dev.class = &mmc_host_class; device_initialize(&host->class_dev); diff --git a/drivers/of/base.c b/drivers/of/base.c index 42073482ab64..36f6bb39de5b 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2077,6 +2077,7 @@ int of_alias_max_index(const char *stem) return max; } +EXPORT_SYMBOL_GPL(of_alias_max_index); /** * of_alias_scan - Scan all properties of the 'aliases' node |