* [PATCH 2/2] mmc: Allow setting slot index via devicetree alias
2014-05-22 15:30 adding aliases to mmc ... again Sascha Hauer
@ 2014-05-22 15:30 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2014-05-22 15:30 UTC (permalink / raw)
To: linux-mmc; +Cc: Dirk Behme, Fabio Estevam, ptx, Stephen Warren, Sascha Hauer
As with gpio, uart and others, allow specifying the name_idx via the
aliases-node in the devicetree.
On embedded devices, there is often a combination of removable (e.g.
SD card) and non-removable mmc devices (e.g. eMMC).
Therefore the name_idx might change depending on
- host of removable device
- removable card present or not
This makes it difficult to hard code the root device, if it is on the
non-removable device. E.g. if SD card is present eMMC will be mmcblk1,
if SD card is not present at boot, eMMC will be mmcblk0.
If the aliases-node is not found, the driver will act as before.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mmc/card/block.c | 11 ++++++++++-
drivers/mmc/core/core.c | 37 +++++++++++++++++++++++++++++++++++++
drivers/mmc/core/host.c | 17 +++++++++++++++--
include/linux/mmc/core.h | 3 +++
4 files changed, 65 insertions(+), 3 deletions(-)
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 29d5d98..9735252 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -32,6 +32,7 @@
#include <linux/scatterlist.h>
#include <linux/string_helpers.h>
#include <linux/delay.h>
+#include <linux/of.h>
#include <linux/capability.h>
#include <linux/compat.h>
#include <linux/pm_runtime.h>
@@ -2044,7 +2045,15 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
* index anymore so we keep track of a name index.
*/
if (!subname) {
- md->name_idx = find_first_zero_bit(name_use, max_devices);
+ int idx;
+
+ idx = mmc_get_reserved_index(card->host);
+ if (idx >= 0 && !test_bit(idx, name_use))
+ md->name_idx = idx;
+ else
+ md->name_idx = find_next_zero_bit(name_use, max_devices,
+ mmc_first_nonreserved_index());
+
__set_bit(md->name_idx, name_use);
} else
md->name_idx = ((struct mmc_blk_data *)
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 57a2b40..c959d41 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -2711,6 +2711,41 @@ void mmc_init_context_info(struct mmc_host *host)
init_waitqueue_head(&host->context_info.wait);
}
+static int __mmc_max_reserved_idx = -1;
+
+/**
+ * mmc_first_nonreserved_index() - get the first index that is not reserved
+ */
+int mmc_first_nonreserved_index(void)
+{
+ return __mmc_max_reserved_idx + 1;
+}
+
+/**
+ * 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");
+}
+
+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;
@@ -2719,6 +2754,8 @@ static int __init mmc_init(void)
if (!workqueue)
return -ENOMEM;
+ mmc_of_reserve_idx();
+
ret = mmc_register_bus();
if (ret)
goto destroy_workqueue;
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 49bc403..ef1e0a8 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -439,6 +439,8 @@ out:
EXPORT_SYMBOL(mmc_of_parse);
+int mmc_max_reserved_idx(void);
+
/**
* mmc_alloc_host - initialise the per-host structure.
* @extra: sizeof private data structure
@@ -450,6 +452,7 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
{
int err;
struct mmc_host *host;
+ int alias_id, min_idx, max_idx;
host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
if (!host)
@@ -459,7 +462,18 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
host->rescan_disable = 1;
idr_preload(GFP_KERNEL);
spin_lock(&mmc_host_lock);
- err = idr_alloc(&mmc_host_idr, host, 0, 0, GFP_NOWAIT);
+
+ host->parent = dev;
+ alias_id = mmc_get_reserved_index(host);
+ if (alias_id >= 0) {
+ min_idx = alias_id;
+ max_idx = alias_id;
+ } else {
+ min_idx = mmc_first_nonreserved_index();
+ max_idx = 0;
+ }
+
+ err = idr_alloc(&mmc_host_idr, host, min_idx, max_idx, GFP_NOWAIT);
if (err >= 0)
host->index = err;
spin_unlock(&mmc_host_lock);
@@ -469,7 +483,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/include/linux/mmc/core.h b/include/linux/mmc/core.h
index 87079fc..96fb4f2 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -197,6 +197,9 @@ extern int mmc_flush_cache(struct mmc_card *);
extern int mmc_detect_card_removed(struct mmc_host *host);
+int mmc_first_nonreserved_index(void);
+int mmc_get_reserved_index(struct mmc_host *host);
+
/**
* mmc_claim_host - exclusively claim a host
* @host: mmc host to claim
--
2.0.0.rc0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 2/2] mmc: Allow setting slot index via devicetree alias
@ 2014-10-08 10:53 Philippe De Muyter
0 siblings, 0 replies; 2+ messages in thread
From: Philippe De Muyter @ 2014-10-08 10:53 UTC (permalink / raw)
To: linux-mmc, Sascha Hauer, Dong Aisheng
Hi Sascha and Dong,
On 2014-05-22 15:30:23, Sascha Hauer wrote:
> If the aliases-node is not found, the driver will act as before.
and the commit (5f9447e5d97060207c4742d5a06e5548de45972d, by Dong Aisheng)
in imx_3.10.31_1.1.0_beta adds :
The original patch is from here:
https://www.mail-archive.com/linux-mmc@vger.kernel.org/msg26472.html
The patch requires additional alias_id fix or it won't work.
Because according to function definition the max_idx parameter of idx_alloc
is exclusive, so need add 1 or it will be unable to find the proper idx
within an invalid range.
I have just upgraded my imx kernel from imx_3.10.17_1.0.0_beta
to imx_3.10.31_1.1.0_beta, but now my new kernel refuses to boot because
it does not find its root fs, because the numbering of the mmc devices
has changed, although I did not add alias id's in my dts file.
Here is what I get :
Kernel command line: console=ttymxc0,115200 root=/dev/mmcblk0p2 rootwait rw
...
with old method, idx would have been 0
with new method, idx is 1
mmcblk1: mmc1:1234 SA04G 3.63 GiB
mmcblk1: p1 p2
mmc3: BKOPS_EN bit is not set
mmc3: new high speed DDR MMC card at address 0001
with old method, idx would have been 1
with new method, idx is 3
mmcblk3: mmc3:0001 MMC04G 3.57 GiB
mmcblk3boot0: mmc3:0001 MMC04G partition 1 2.00 MiB
mmcblk3boot1: mmc3:0001 MMC04G partition 2 2.00 MiB
mmcblk3rpmb: mmc3:0001 MMC04G partition 3 128 KiB
mmcblk3: unknown partition table
mmcblk3boot1: unknown partition table
mmcblk3boot0: unknown partition table
...
Waiting for root device /dev/mmcblk0p2...
Additional debug is mine.
Is there a fix available to preserve the old numbering if no alias has been
defined ?
TIA
Philippe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-10-08 11:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-08 10:53 [PATCH 2/2] mmc: Allow setting slot index via devicetree alias Philippe De Muyter
-- strict thread matches above, loose matches on Subject: below --
2014-05-22 15:30 adding aliases to mmc ... again Sascha Hauer
2014-05-22 15:30 ` [PATCH 2/2] mmc: Allow setting slot index via devicetree alias Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox