cf0d18cf06344df977cb3eff70c1f6e3937c1f3a
[openwrt/staging/wigyori.git] /
1 From 45ff6c340ddfc2dade74d5b7a8962c778ab7042c Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Thu, 3 Oct 2024 00:11:44 +0200
4 Subject: [PATCH 4/5] mmc: block: attach partitions fwnode if found in mmc-card
5
6 Attach partitions fwnode if found in mmc-card and register disk with it.
7
8 This permits block partition to reference the node and register a
9 partition table defined in DT for the special case for embedded device
10 that doesn't have a partition table flashed but have an hardcoded
11 partition table passed from the system.
12
13 JEDEC BOOT partition boot0/boot1 are supported but in DT we refer with
14 the JEDEC name of boot1 and boot2 to better adhere to documentation.
15
16 Also JEDEC GP partition gp0/1/2/3 are supported but in DT we refer with
17 the JEDEC name of gp1/2/3/4 to better adhere to documentration.
18
19 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
20 Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
21 Link: https://lore.kernel.org/r/20241002221306.4403-5-ansuelsmth@gmail.com
22 Signed-off-by: Jens Axboe <axboe@kernel.dk>
23 ---
24 drivers/mmc/core/block.c | 55 +++++++++++++++++++++++++++++++++++++++-
25 1 file changed, 54 insertions(+), 1 deletion(-)
26
27 --- a/drivers/mmc/core/block.c
28 +++ b/drivers/mmc/core/block.c
29 @@ -2455,6 +2455,56 @@ static inline int mmc_blk_readonly(struc
30 !(card->csd.cmdclass & CCC_BLOCK_WRITE);
31 }
32
33 +/*
34 + * Search for a declared partitions node for the disk in mmc-card related node.
35 + *
36 + * This is to permit support for partition table defined in DT in special case
37 + * where a partition table is not written in the disk and is expected to be
38 + * passed from the running system.
39 + *
40 + * For the user disk, "partitions" node is searched.
41 + * For the special HW disk, "partitions-" node with the appended name is used
42 + * following this conversion table (to adhere to JEDEC naming)
43 + * - boot0 -> partitions-boot1
44 + * - boot1 -> partitions-boot2
45 + * - gp0 -> partitions-gp1
46 + * - gp1 -> partitions-gp2
47 + * - gp2 -> partitions-gp3
48 + * - gp3 -> partitions-gp4
49 + */
50 +static struct fwnode_handle *mmc_blk_get_partitions_node(struct device *mmc_dev,
51 + const char *subname)
52 +{
53 + const char *node_name = "partitions";
54 +
55 + if (subname) {
56 + mmc_dev = mmc_dev->parent;
57 +
58 + /*
59 + * Check if we are allocating a BOOT disk boot0/1 disk.
60 + * In DT we use the JEDEC naming boot1/2.
61 + */
62 + if (!strcmp(subname, "boot0"))
63 + node_name = "partitions-boot1";
64 + if (!strcmp(subname, "boot1"))
65 + node_name = "partitions-boot2";
66 + /*
67 + * Check if we are allocating a GP disk gp0/1/2/3 disk.
68 + * In DT we use the JEDEC naming gp1/2/3/4.
69 + */
70 + if (!strcmp(subname, "gp0"))
71 + node_name = "partitions-gp1";
72 + if (!strcmp(subname, "gp1"))
73 + node_name = "partitions-gp2";
74 + if (!strcmp(subname, "gp2"))
75 + node_name = "partitions-gp3";
76 + if (!strcmp(subname, "gp3"))
77 + node_name = "partitions-gp4";
78 + }
79 +
80 + return device_get_named_child_node(mmc_dev, node_name);
81 +}
82 +
83 static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
84 struct device *parent,
85 sector_t size,
86 @@ -2463,6 +2513,7 @@ static struct mmc_blk_data *mmc_blk_allo
87 int area_type,
88 unsigned int part_type)
89 {
90 + struct fwnode_handle *disk_fwnode;
91 struct mmc_blk_data *md;
92 int devidx, ret;
93 char cap_str[10];
94 @@ -2568,7 +2619,9 @@ static struct mmc_blk_data *mmc_blk_allo
95 /* used in ->open, must be set before add_disk: */
96 if (area_type == MMC_BLK_DATA_AREA_MAIN)
97 dev_set_drvdata(&card->dev, md);
98 - ret = device_add_disk(md->parent, md->disk, mmc_disk_attr_groups);
99 + disk_fwnode = mmc_blk_get_partitions_node(parent, subname);
100 + ret = add_disk_fwnode(md->parent, md->disk, mmc_disk_attr_groups,
101 + disk_fwnode);
102 if (ret)
103 goto err_put_disk;
104 return md;