Skip to content

Commit df66e71

Browse files
stroesedwmw2
authored andcommitted
[MTD] physmap.c: Add support for multiple resources
This patch extends the physmap mapping driver to support multiple resources for non-identical NOR chips that will be concatenated together when selected. This is needed for example for Intel 48F4400 512MBit chips, since they consist of 2 single different NOR chips with different geometries. The first (lower) one has botton boot sectors and the 2nd (upper) has top boot sectors. This currently isn't handled correctly by calling the physmap driver once with only one resource covering both chips in one memory region. The same geometrie is used for both chips. With this patch the following resource structure can be used to describe the 48F4400 chip correctly: static struct resource board_nor_resource[] = { [0] = { .start = 0xf8000000, .end = 0xfbffffff, .flags = IORESOURCE_MEM, }, [1] = { .start = 0xfc000000, .end = 0xffffffff, .flags = IORESOURCE_MEM, } }; Signed-off-by: Stefan Roese <sr@denx.de> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
1 parent 1c45f60 commit df66e71

1 file changed

Lines changed: 104 additions & 58 deletions

File tree

‎drivers/mtd/maps/physmap.c‎

Lines changed: 104 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,27 @@
2020
#include <linux/mtd/map.h>
2121
#include <linux/mtd/partitions.h>
2222
#include <linux/mtd/physmap.h>
23+
#include <linux/mtd/concat.h>
2324
#include <asm/io.h>
2425

26+
#define MAX_RESOURCES 4
27+
2528
struct physmap_flash_info {
26-
struct mtd_info *mtd;
27-
struct map_info map;
29+
struct mtd_info *mtd[MAX_RESOURCES];
30+
struct mtd_info *cmtd;
31+
struct map_info map[MAX_RESOURCES];
2832
struct resource *res;
2933
#ifdef CONFIG_MTD_PARTITIONS
3034
int nr_parts;
3135
struct mtd_partition *parts;
3236
#endif
3337
};
3438

35-
3639
static int physmap_flash_remove(struct platform_device *dev)
3740
{
3841
struct physmap_flash_info *info;
3942
struct physmap_flash_data *physmap_data;
43+
int i;
4044

4145
info = platform_get_drvdata(dev);
4246
if (info == NULL)
@@ -45,24 +49,33 @@ static int physmap_flash_remove(struct platform_device *dev)
4549

4650
physmap_data = dev->dev.platform_data;
4751

48-
if (info->mtd != NULL) {
52+
#ifdef CONFIG_MTD_CONCAT
53+
if (info->cmtd != info->mtd[0]) {
54+
del_mtd_device(info->cmtd);
55+
mtd_concat_destroy(info->cmtd);
56+
}
57+
#endif
58+
59+
for (i = 0; i < MAX_RESOURCES; i++) {
60+
if (info->mtd[i] != NULL) {
4961
#ifdef CONFIG_MTD_PARTITIONS
50-
if (info->nr_parts) {
51-
del_mtd_partitions(info->mtd);
52-
kfree(info->parts);
53-
} else if (physmap_data->nr_parts) {
54-
del_mtd_partitions(info->mtd);
55-
} else {
56-
del_mtd_device(info->mtd);
57-
}
62+
if (info->nr_parts) {
63+
del_mtd_partitions(info->mtd[i]);
64+
kfree(info->parts);
65+
} else if (physmap_data->nr_parts) {
66+
del_mtd_partitions(info->mtd[i]);
67+
} else {
68+
del_mtd_device(info->mtd[i]);
69+
}
5870
#else
59-
del_mtd_device(info->mtd);
71+
del_mtd_device(info->mtd[i]);
6072
#endif
61-
map_destroy(info->mtd);
62-
}
73+
map_destroy(info->mtd[i]);
74+
}
6375

64-
if (info->map.virt != NULL)
65-
iounmap(info->map.virt);
76+
if (info->map[i].virt != NULL)
77+
iounmap(info->map[i].virt);
78+
}
6679

6780
if (info->res != NULL) {
6881
release_resource(info->res);
@@ -82,16 +95,14 @@ static int physmap_flash_probe(struct platform_device *dev)
8295
struct physmap_flash_data *physmap_data;
8396
struct physmap_flash_info *info;
8497
const char **probe_type;
85-
int err;
98+
int err = 0;
99+
int i;
100+
int devices_found = 0;
86101

87102
physmap_data = dev->dev.platform_data;
88103
if (physmap_data == NULL)
89104
return -ENODEV;
90105

91-
printk(KERN_NOTICE "physmap platform flash device: %.8llx at %.8llx\n",
92-
(unsigned long long)(dev->resource->end - dev->resource->start + 1),
93-
(unsigned long long)dev->resource->start);
94-
95106
info = kzalloc(sizeof(struct physmap_flash_info), GFP_KERNEL);
96107
if (info == NULL) {
97108
err = -ENOMEM;
@@ -100,56 +111,83 @@ static int physmap_flash_probe(struct platform_device *dev)
100111

101112
platform_set_drvdata(dev, info);
102113

103-
info->res = request_mem_region(dev->resource->start,
104-
dev->resource->end - dev->resource->start + 1,
105-
dev->dev.bus_id);
106-
if (info->res == NULL) {
107-
dev_err(&dev->dev, "Could not reserve memory region\n");
108-
err = -ENOMEM;
109-
goto err_out;
110-
}
114+
for (i = 0; i < dev->num_resources; i++) {
115+
printk(KERN_NOTICE "physmap platform flash device: %.8llx at %.8llx\n",
116+
(unsigned long long)(dev->resource[i].end - dev->resource[i].start + 1),
117+
(unsigned long long)dev->resource[i].start);
118+
119+
info->res = request_mem_region(dev->resource[i].start,
120+
dev->resource[i].end - dev->resource[i].start + 1,
121+
dev->dev.bus_id);
122+
if (info->res == NULL) {
123+
dev_err(&dev->dev, "Could not reserve memory region\n");
124+
err = -ENOMEM;
125+
goto err_out;
126+
}
111127

112-
info->map.name = dev->dev.bus_id;
113-
info->map.phys = dev->resource->start;
114-
info->map.size = dev->resource->end - dev->resource->start + 1;
115-
info->map.bankwidth = physmap_data->width;
116-
info->map.set_vpp = physmap_data->set_vpp;
128+
info->map[i].name = dev->dev.bus_id;
129+
info->map[i].phys = dev->resource[i].start;
130+
info->map[i].size = dev->resource[i].end - dev->resource[i].start + 1;
131+
info->map[i].bankwidth = physmap_data->width;
132+
info->map[i].set_vpp = physmap_data->set_vpp;
133+
134+
info->map[i].virt = ioremap(info->map[i].phys, info->map[i].size);
135+
if (info->map[i].virt == NULL) {
136+
dev_err(&dev->dev, "Failed to ioremap flash region\n");
137+
err = EIO;
138+
goto err_out;
139+
}
117140

118-
info->map.virt = ioremap(info->map.phys, info->map.size);
119-
if (info->map.virt == NULL) {
120-
dev_err(&dev->dev, "Failed to ioremap flash region\n");
121-
err = EIO;
122-
goto err_out;
123-
}
141+
simple_map_init(&info->map[i]);
124142

125-
simple_map_init(&info->map);
143+
probe_type = rom_probe_types;
144+
for (; info->mtd[i] == NULL && *probe_type != NULL; probe_type++)
145+
info->mtd[i] = do_map_probe(*probe_type, &info->map[i]);
146+
if (info->mtd[i] == NULL) {
147+
dev_err(&dev->dev, "map_probe failed\n");
148+
err = -ENXIO;
149+
goto err_out;
150+
} else {
151+
devices_found++;
152+
}
153+
info->mtd[i]->owner = THIS_MODULE;
154+
}
126155

127-
probe_type = rom_probe_types;
128-
for (; info->mtd == NULL && *probe_type != NULL; probe_type++)
129-
info->mtd = do_map_probe(*probe_type, &info->map);
130-
if (info->mtd == NULL) {
131-
dev_err(&dev->dev, "map_probe failed\n");
156+
if (devices_found == 1) {
157+
info->cmtd = info->mtd[0];
158+
} else if (devices_found > 1) {
159+
/*
160+
* We detected multiple devices. Concatenate them together.
161+
*/
162+
#ifdef CONFIG_MTD_CONCAT
163+
info->cmtd = mtd_concat_create(info->mtd, devices_found, dev->dev.bus_id);
164+
if (info->cmtd == NULL)
165+
err = -ENXIO;
166+
#else
167+
printk(KERN_ERR "physmap-flash: multiple devices "
168+
"found but MTD concat support disabled.\n");
132169
err = -ENXIO;
133-
goto err_out;
170+
#endif
134171
}
135-
info->mtd->owner = THIS_MODULE;
172+
if (err)
173+
goto err_out;
136174

137175
#ifdef CONFIG_MTD_PARTITIONS
138-
err = parse_mtd_partitions(info->mtd, part_probe_types, &info->parts, 0);
176+
err = parse_mtd_partitions(info->cmtd, part_probe_types, &info->parts, 0);
139177
if (err > 0) {
140-
add_mtd_partitions(info->mtd, info->parts, err);
178+
add_mtd_partitions(info->cmtd, info->parts, err);
141179
return 0;
142180
}
143181

144182
if (physmap_data->nr_parts) {
145183
printk(KERN_NOTICE "Using physmap partition information\n");
146-
add_mtd_partitions(info->mtd, physmap_data->parts,
147-
physmap_data->nr_parts);
184+
add_mtd_partitions(info->cmtd, physmap_data->parts,
185+
physmap_data->nr_parts);
148186
return 0;
149187
}
150188
#endif
151189

152-
add_mtd_device(info->mtd);
190+
add_mtd_device(info->cmtd);
153191
return 0;
154192

155193
err_out:
@@ -162,26 +200,34 @@ static int physmap_flash_suspend(struct platform_device *dev, pm_message_t state
162200
{
163201
struct physmap_flash_info *info = platform_get_drvdata(dev);
164202
int ret = 0;
203+
int i;
165204

166205
if (info)
167-
ret = info->mtd->suspend(info->mtd);
206+
for (i = 0; i < MAX_RESOURCES; i++)
207+
ret |= info->mtd[i].suspend(info->mtd[i]);
168208

169209
return ret;
170210
}
171211

172212
static int physmap_flash_resume(struct platform_device *dev)
173213
{
174214
struct physmap_flash_info *info = platform_get_drvdata(dev);
215+
int i;
216+
175217
if (info)
176-
info->mtd->resume(info->mtd);
218+
for (i = 0; i < MAX_RESOURCES; i++)
219+
info->mtd[i].resume(info->mtd[i]);
177220
return 0;
178221
}
179222

180223
static void physmap_flash_shutdown(struct platform_device *dev)
181224
{
182225
struct physmap_flash_info *info = platform_get_drvdata(dev);
183-
if (info && info->mtd->suspend(info->mtd) == 0)
184-
info->mtd->resume(info->mtd);
226+
int i;
227+
228+
for (i = 0; i < MAX_RESOURCES; i++)
229+
if (info && info->mtd[i].suspend(info->mtd[i]) == 0)
230+
info->mtd[i].resume(info->mtd[i]);
185231
}
186232
#endif
187233

0 commit comments

Comments
 (0)