1 --- a/drivers/mtd/maps/lantiq-flash.c
2 +++ b/drivers/mtd/maps/lantiq-flash.c
4 #include <linux/mtd/cfi.h>
5 #include <linux/platform_device.h>
6 #include <linux/mtd/physmap.h>
7 +#include <linux/mtd/concat.h>
10 #include <lantiq_soc.h>
11 @@ -38,13 +39,16 @@ enum {
15 +#define MAX_RESOURCES 4
18 - struct resource *res;
19 - struct mtd_info *mtd;
20 - struct map_info *map;
21 + struct mtd_info *mtd[MAX_RESOURCES];
22 + struct mtd_info *cmtd;
23 + struct map_info map[MAX_RESOURCES];
26 static const char ltq_map_name[] = "ltq_nor";
27 +static const char * const ltq_probe_types[] = { "cmdlinepart", "ofpart", NULL };
30 ltq_read16(struct map_info *map, unsigned long adr)
31 @@ -108,12 +112,44 @@ ltq_copy_to(struct map_info *map, unsign
35 +ltq_mtd_remove(struct platform_device *pdev)
37 + struct ltq_mtd *ltq_mtd = platform_get_drvdata(pdev);
40 + if (ltq_mtd == NULL)
43 + if (ltq_mtd->cmtd) {
44 + mtd_device_unregister(ltq_mtd->cmtd);
45 + if (ltq_mtd->cmtd != ltq_mtd->mtd[0])
46 + mtd_concat_destroy(ltq_mtd->cmtd);
49 + for (i = 0; i < MAX_RESOURCES; i++) {
50 + if (ltq_mtd->mtd[i] != NULL)
51 + map_destroy(ltq_mtd->mtd[i]);
60 ltq_mtd_probe(struct platform_device *pdev)
62 struct mtd_part_parser_data ppdata;
63 struct ltq_mtd *ltq_mtd;
64 struct cfi_private *cfi;
68 + int devices_found = 0;
70 + static const char *rom_probe_types[] = {
71 + "cfi_probe", "jedec_probe", NULL
75 if (of_machine_is_compatible("lantiq,falcon") &&
76 (ltq_boot_select() != BS_FLASH)) {
77 @@ -127,75 +163,90 @@ ltq_mtd_probe(struct platform_device *pd
79 platform_set_drvdata(pdev, ltq_mtd);
81 - ltq_mtd->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
82 - if (!ltq_mtd->res) {
83 - dev_err(&pdev->dev, "failed to get memory resource\n");
85 + for (i = 0; i < pdev->num_resources; i++) {
86 + printk(KERN_NOTICE "lantiq nor flash device: %.8llx at %.8llx\n",
87 + (unsigned long long)resource_size(&pdev->resource[i]),
88 + (unsigned long long)pdev->resource[i].start);
90 + if (!devm_request_mem_region(&pdev->dev,
91 + pdev->resource[i].start,
92 + resource_size(&pdev->resource[i]),
93 + dev_name(&pdev->dev))) {
94 + dev_err(&pdev->dev, "Could not reserve memory region\n");
98 + ltq_mtd->map[i].name = ltq_map_name;
99 + ltq_mtd->map[i].bankwidth = 2;
100 + ltq_mtd->map[i].read = ltq_read16;
101 + ltq_mtd->map[i].write = ltq_write16;
102 + ltq_mtd->map[i].copy_from = ltq_copy_from;
103 + ltq_mtd->map[i].copy_to = ltq_copy_to;
105 + if (of_find_property(pdev->dev.of_node, "lantiq,noxip", NULL))
106 + ltq_mtd->map[i].phys = NO_XIP;
108 + ltq_mtd->map[i].phys = pdev->resource[i].start;
109 + ltq_mtd->map[i].size = resource_size(&pdev->resource[i]);
110 + ltq_mtd->map[i].virt = devm_ioremap(&pdev->dev, pdev->resource[i].start,
111 + ltq_mtd->map[i].size);
112 + if (IS_ERR(ltq_mtd->map[i].virt))
113 + return PTR_ERR(ltq_mtd->map[i].virt);
115 + if (ltq_mtd->map[i].virt == NULL) {
116 + dev_err(&pdev->dev, "Failed to ioremap flash region\n");
117 + err = PTR_ERR(ltq_mtd->map[i].virt);
121 + ltq_mtd->map[i].map_priv_1 = LTQ_NOR_PROBING;
122 + for (type = rom_probe_types; !ltq_mtd->mtd[i] && *type; type++)
123 + ltq_mtd->mtd[i] = do_map_probe(*type, <q_mtd->map[i]);
124 + ltq_mtd->map[i].map_priv_1 = LTQ_NOR_NORMAL;
126 + if (!ltq_mtd->mtd[i]) {
127 + dev_err(&pdev->dev, "probing failed\n");
133 + ltq_mtd->mtd[i]->owner = THIS_MODULE;
134 + ltq_mtd->mtd[i]->dev.parent = &pdev->dev;
136 + cfi = ltq_mtd->map[i].fldrv_priv;
137 + cfi->addr_unlock1 ^= 1;
138 + cfi->addr_unlock2 ^= 1;
141 - ltq_mtd->map = devm_kzalloc(&pdev->dev, sizeof(struct map_info),
145 + if (devices_found == 1) {
146 + ltq_mtd->cmtd = ltq_mtd->mtd[0];
147 + } else if (devices_found > 1) {
149 + * We detected multiple devices. Concatenate them together.
151 + ltq_mtd->cmtd = mtd_concat_create(ltq_mtd->mtd, devices_found, dev_name(&pdev->dev));
152 + if (ltq_mtd->cmtd == NULL)
156 - if (of_find_property(pdev->dev.of_node, "lantiq,noxip", NULL))
157 - ltq_mtd->map->phys = NO_XIP;
159 - ltq_mtd->map->phys = ltq_mtd->res->start;
160 - ltq_mtd->res->start;
161 - ltq_mtd->map->size = resource_size(ltq_mtd->res);
162 - ltq_mtd->map->virt = devm_ioremap_resource(&pdev->dev, ltq_mtd->res);
163 - if (IS_ERR(ltq_mtd->map->virt))
164 - return PTR_ERR(ltq_mtd->map->virt);
166 - ltq_mtd->map->name = ltq_map_name;
167 - ltq_mtd->map->bankwidth = 2;
168 - ltq_mtd->map->read = ltq_read16;
169 - ltq_mtd->map->write = ltq_write16;
170 - ltq_mtd->map->copy_from = ltq_copy_from;
171 - ltq_mtd->map->copy_to = ltq_copy_to;
173 - ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
174 - ltq_mtd->mtd = do_map_probe("cfi_probe", ltq_mtd->map);
175 - ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;
177 - if (!ltq_mtd->mtd) {
178 - dev_err(&pdev->dev, "probing failed\n");
182 - ltq_mtd->mtd->dev.parent = &pdev->dev;
184 - cfi = ltq_mtd->map->fldrv_priv;
185 - cfi->addr_unlock1 ^= 1;
186 - cfi->addr_unlock2 ^= 1;
187 + ltq_mtd->cmtd->dev.parent = &pdev->dev;
189 ppdata.of_node = pdev->dev.of_node;
190 - err = mtd_device_parse_register(ltq_mtd->mtd, NULL, &ppdata, NULL, 0);
191 + err = mtd_device_parse_register(ltq_mtd->cmtd, ltq_probe_types,
194 dev_err(&pdev->dev, "failed to add partitions\n");
202 - map_destroy(ltq_mtd->mtd);
204 + ltq_mtd_remove(pdev);
209 -ltq_mtd_remove(struct platform_device *pdev)
211 - struct ltq_mtd *ltq_mtd = platform_get_drvdata(pdev);
213 - if (ltq_mtd && ltq_mtd->mtd) {
214 - mtd_device_unregister(ltq_mtd->mtd);
215 - map_destroy(ltq_mtd->mtd);
220 static const struct of_device_id ltq_mtd_match[] = {
221 { .compatible = "lantiq,nor" },