Commit 36546cf63074d1ddd31838e9e3f513c2cbe54115

Authored by Eric Lee
1 parent ee52728ee9

Support the fixed index for mmcblk with aliases nodes

Showing 3 changed files with 36 additions and 4 deletions Side-by-side Diff

arch/arm/boot/dts/am335x-smarc-common.dtsi
... ... @@ -92,6 +92,8 @@
92 92 aliases {
93 93 rtc0 = &s35390a;
94 94 rtc1 = &rtc;
  95 + mmc0 = &mmc2; /* Fixed to mmcblk0 for &mmc2 */
  96 + mmc1 = &mmc1; /* Fixed to mmcblk1 for &mmc1 */
95 97 };
96 98  
97 99 cpus {
... ... @@ -125,7 +127,7 @@
125 127 status = "okay";
126 128 pinctrl-names = "default";
127 129 pinctrl-0 = <&lcd_pins_default>;
128   - enable-gpios = <&gpio1 23 0>;
  130 + enable-gpios = <&gpio1 23 0>; /* Enable LCD_VDD_EN pin */
129 131 panel-info {
130 132 ac-bias = <255>;
131 133 ac-bias-intrpt = <0>;
arch/arm/boot/dts/am33xx.dtsi
... ... @@ -36,8 +36,6 @@
36 36 phy1 = &usb1_phy;
37 37 ethernet0 = &cpsw_emac0;
38 38 ethernet1 = &cpsw_emac1;
39   - mmc1 = &mmc1; /* Fixed to mmcblk1 for &mmc1 */
40   - mmc0 = &mmc2; /* Fixed to mmcblk0 for &mmc2 */
41 39 };
42 40  
43 41 cpus {
drivers/mmc/card/block.c
... ... @@ -36,6 +36,7 @@
36 36 #include <linux/compat.h>
37 37 #include <linux/pm_runtime.h>
38 38 #include <linux/idr.h>
  39 +#include <linux/of.h>
39 40  
40 41 #include <linux/mmc/ioctl.h>
41 42 #include <linux/mmc/card.h>
... ... @@ -86,6 +87,8 @@
86 87  
87 88 #define MAX_DEVICES 256
88 89  
  90 +static DECLARE_BITMAP(name_use, MAX_DEVICES);
  91 +
89 92 static DEFINE_IDA(mmc_blk_ida);
90 93 static DEFINE_SPINLOCK(mmc_blk_lock);
91 94  
... ... @@ -107,6 +110,7 @@
107 110 unsigned int usage;
108 111 unsigned int read_only;
109 112 unsigned int part_type;
  113 + unsigned int name_idx;
110 114 unsigned int reset_done;
111 115 #define MMC_BLK_READ BIT(0)
112 116 #define MMC_BLK_WRITE BIT(1)
... ... @@ -2219,6 +2223,7 @@
2219 2223 {
2220 2224 struct mmc_blk_data *md;
2221 2225 int devidx, ret;
  2226 + int idx = 0;
2222 2227  
2223 2228 again:
2224 2229 if (!ida_pre_get(&mmc_blk_ida, GFP_KERNEL))
... ... @@ -2244,6 +2249,32 @@
2244 2249 goto out;
2245 2250 }
2246 2251  
  2252 + /*
  2253 + * !subname implies we are creating main mmc_blk_data that will be
  2254 + * associated with mmc_card with dev_set_drvdata. Due to device
  2255 + * partitions, devidx will not coincide with a per-physical card
  2256 + * index anymore so we keep track of a name index.
  2257 + */
  2258 + if (!subname) {
  2259 + if (card->dev.parent->parent->of_node)
  2260 + idx = of_alias_get_id(card->dev.parent->parent->of_node,
  2261 + "mmc");
  2262 +
  2263 + if (idx < 0)
  2264 + md->name_idx = find_first_zero_bit(name_use,
  2265 + max_devices);
  2266 + else {
  2267 + if (test_bit(idx, name_use))
  2268 + md->name_idx = find_first_zero_bit(name_use,
  2269 + max_devices);
  2270 + else
  2271 + md->name_idx = (unsigned int)idx;
  2272 + }
  2273 + __set_bit(md->name_idx, name_use);
  2274 + } else
  2275 + md->name_idx = ((struct mmc_blk_data *)
  2276 + dev_to_disk(parent)->private_data)->name_idx;
  2277 +
2247 2278 md->area_type = area_type;
2248 2279  
2249 2280 /*
... ... @@ -2292,7 +2323,7 @@
2292 2323 */
2293 2324  
2294 2325 snprintf(md->disk->disk_name, sizeof(md->disk->disk_name),
2295   - "mmcblk%u%s", card->host->index, subname ? subname : "");
  2326 + "mmcblk%u%s", md->name_idx, subname ? subname : "");
2296 2327  
2297 2328 if (mmc_card_mmc(card))
2298 2329 blk_queue_logical_block_size(md->queue.queue,
... ... @@ -2450,6 +2481,7 @@
2450 2481 struct list_head *pos, *q;
2451 2482 struct mmc_blk_data *part_md;
2452 2483  
  2484 + __clear_bit(md->name_idx, name_use);
2453 2485 list_for_each_safe(pos, q, &md->part) {
2454 2486 part_md = list_entry(pos, struct mmc_blk_data, part);
2455 2487 list_del(pos);