1
0
Fork 0

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.

Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
5.4-rM2-2.2.x-imx-squashed
Haibo Chen 2019-01-28 18:07:15 +08:00 committed by Dong Aisheng
parent 084c5fd0ed
commit 8282097452
5 changed files with 87 additions and 3 deletions

View File

@ -52,6 +52,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.
@ -2467,10 +2469,46 @@ void mmc_unregister_pm_notifier(struct mmc_host *host)
}
#endif
/*
* 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;

View File

@ -76,7 +76,8 @@ int mmc_detect_card_removed(struct mmc_host *host);
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;

View File

@ -401,6 +401,7 @@ EXPORT_SYMBOL(mmc_of_parse_voltage);
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);
@ -409,8 +410,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;
@ -420,7 +429,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);

View File

@ -1981,6 +1981,37 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np,
ap->alias, ap->stem, ap->id, np);
}
/*
* of_alias_max_index() - get the maximum index for a given alias stem
* @stem: The alias stem for which the maximum index is searched for
*
* Given an alias stem (the alias without the number) this function
* returns the maximum number for which an alias exists.
*
* Return: The maximum existing alias index or -ENODEV if no alias
* exists for this stem.
*/
int of_alias_max_index(const char *stem)
{
struct alias_prop *app;
int max = -ENODEV;
mutex_lock(&of_mutex);
list_for_each_entry(app, &aliases_lookup, link) {
if (strcmp(app->stem, stem))
continue;
if (app->id > max)
max = app->id;
}
mutex_unlock(&of_mutex);
return max;
}
EXPORT_SYMBOL_GPL(of_alias_max_index);
/**
* of_alias_scan - Scan all properties of the 'aliases' node
*

View File

@ -391,6 +391,7 @@ extern int of_phandle_iterator_args(struct of_phandle_iterator *it,
extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern int of_alias_get_highest_id(const char *stem);
extern int of_alias_max_index(const char *stem);
extern int of_alias_get_alias_list(const struct of_device_id *matches,
const char *stem, unsigned long *bitmap,
unsigned int nbits);
@ -911,6 +912,11 @@ static inline int of_alias_get_alias_list(const struct of_device_id *matches,
return -ENOSYS;
}
static inline int of_alias_max_index(const char *stem)
{
return -ENODEV;
}
static inline int of_machine_is_compatible(const char *compat)
{
return 0;