aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/maps/Kconfig17
-rw-r--r--drivers/mtd/maps/pismo.c320
-rw-r--r--drivers/mtd/mtdoops.c2
-rw-r--r--drivers/mtd/tests/mtd_readtest.c6
-rw-r--r--drivers/mtd/tests/mtd_speedtest.c7
-rw-r--r--drivers/mtd/tests/mtd_stresstest.c6
-rw-r--r--drivers/mtd/ubi/cdev.c1
-rw-r--r--drivers/mtd/ubi/kapi.c15
-rw-r--r--drivers/mtd/ubi/upd.c1
-rw-r--r--drivers/mtd/ubi/vtbl.c1
10 files changed, 363 insertions, 13 deletions
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index 4c364d44ad59..2de0cc823d60 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -549,4 +549,21 @@ config MTD_VMU
549 To build this as a module select M here, the module will be called 549 To build this as a module select M here, the module will be called
550 vmu-flash. 550 vmu-flash.
551 551
552config MTD_PISMO
553 tristate "MTD discovery driver for PISMO modules"
554 depends on I2C
555 depends on ARCH_VERSATILE
556 help
557 This driver allows for discovery of PISMO modules - see
558 <http://www.pismoworld.org/>. These are small modules containing
559 up to five memory devices (eg, SRAM, flash, DOC) described by an
560 I2C EEPROM.
561
562 This driver does not create any MTD maps itself; instead it
563 creates MTD physmap and MTD SRAM platform devices. If you
564 enable this option, you should consider enabling MTD_PHYSMAP
565 and/or MTD_PLATRAM according to the devices on your module.
566
567 When built as a module, it will be called pismo.ko
568
552endmenu 569endmenu
diff --git a/drivers/mtd/maps/pismo.c b/drivers/mtd/maps/pismo.c
new file mode 100644
index 000000000000..c48cad271f5d
--- /dev/null
+++ b/drivers/mtd/maps/pismo.c
@@ -0,0 +1,320 @@
1/*
2 * PISMO memory driver - http://www.pismoworld.org/
3 *
4 * For ARM Realview and Versatile platforms
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License.
9 */
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/i2c.h>
13#include <linux/platform_device.h>
14#include <linux/spinlock.h>
15#include <linux/mutex.h>
16#include <linux/mtd/physmap.h>
17#include <linux/mtd/plat-ram.h>
18#include <linux/mtd/pismo.h>
19
20#define PISMO_NUM_CS 5
21
22struct pismo_cs_block {
23 u8 type;
24 u8 width;
25 __le16 access;
26 __le32 size;
27 u32 reserved[2];
28 char device[32];
29} __packed;
30
31struct pismo_eeprom {
32 struct pismo_cs_block cs[PISMO_NUM_CS];
33 char board[15];
34 u8 sum;
35} __packed;
36
37struct pismo_mem {
38 phys_addr_t base;
39 u32 size;
40 u16 access;
41 u8 width;
42 u8 type;
43};
44
45struct pismo_data {
46 struct i2c_client *client;
47 void (*vpp)(void *, int);
48 void *vpp_data;
49 struct platform_device *dev[PISMO_NUM_CS];
50};
51
52/* FIXME: set_vpp could do with a better calling convention */
53static struct pismo_data *vpp_pismo;
54static DEFINE_MUTEX(pismo_mutex);
55
56static int pismo_setvpp_probe_fix(struct pismo_data *pismo)
57{
58 mutex_lock(&pismo_mutex);
59 if (vpp_pismo) {
60 mutex_unlock(&pismo_mutex);
61 kfree(pismo);
62 return -EBUSY;
63 }
64 vpp_pismo = pismo;
65 mutex_unlock(&pismo_mutex);
66 return 0;
67}
68
69static void pismo_setvpp_remove_fix(struct pismo_data *pismo)
70{
71 mutex_lock(&pismo_mutex);
72 if (vpp_pismo == pismo)
73 vpp_pismo = NULL;
74 mutex_unlock(&pismo_mutex);
75}
76
77static void pismo_set_vpp(struct map_info *map, int on)
78{
79 struct pismo_data *pismo = vpp_pismo;
80
81 pismo->vpp(pismo->vpp_data, on);
82}
83/* end of hack */
84
85
86static unsigned int __devinit pismo_width_to_bytes(unsigned int width)
87{
88 width &= 15;
89 if (width > 2)
90 return 0;
91 return 1 << width;
92}
93
94static int __devinit pismo_eeprom_read(struct i2c_client *client, void *buf,
95 u8 addr, size_t size)
96{
97 int ret;
98 struct i2c_msg msg[] = {
99 {
100 .addr = client->addr,
101 .len = sizeof(addr),
102 .buf = &addr,
103 }, {
104 .addr = client->addr,
105 .flags = I2C_M_RD,
106 .len = size,
107 .buf = buf,
108 },
109 };
110
111 ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
112
113 return ret == ARRAY_SIZE(msg) ? size : -EIO;
114}
115
116static int __devinit pismo_add_device(struct pismo_data *pismo, int i,
117 struct pismo_mem *region, const char *name, void *pdata, size_t psize)
118{
119 struct platform_device *dev;
120 struct resource res = { };
121 phys_addr_t base = region.base;
122 int ret;
123
124 if (base == ~0)
125 return -ENXIO;
126
127 res.start = base;
128 res.end = base + region->size - 1;
129 res.flags = IORESOURCE_MEM;
130
131 dev = platform_device_alloc(name, i);
132 if (!dev)
133 return -ENOMEM;
134 dev->dev.parent = &pismo->client->dev;
135
136 do {
137 ret = platform_device_add_resources(dev, &res, 1);
138 if (ret)
139 break;
140
141 ret = platform_device_add_data(dev, pdata, psize);
142 if (ret)
143 break;
144
145 ret = platform_device_add(dev);
146 if (ret)
147 break;
148
149 pismo->dev[i] = dev;
150 return 0;
151 } while (0);
152
153 platform_device_put(dev);
154 return ret;
155}
156
157static int __devinit pismo_add_nor(struct pismo_data *pismo, int i,
158 struct pismo_mem *region)
159{
160 struct physmap_flash_data data = {
161 .width = region->width,
162 };
163
164 if (pismo->vpp)
165 data.set_vpp = pismo_set_vpp;
166
167 return pismo_add_device(pismo, i, region, "physmap-flash",
168 &data, sizeof(data));
169}
170
171static int __devinit pismo_add_sram(struct pismo_data *pismo, int i,
172 struct pismo_mem *region)
173{
174 struct platdata_mtd_ram data = {
175 .bankwidth = region->width,
176 };
177
178 return pismo_add_device(pismo, i, region, "mtd-ram",
179 &data, sizeof(data));
180}
181
182static void __devinit pismo_add_one(struct pismo_data *pismo, int i,
183 const struct pismo_cs_block *cs, phys_addr_t base)
184{
185 struct device *dev = &pismo->client->dev;
186 struct pismo_mem region;
187
188 region.base = base;
189 region.type = cs->type;
190 region.width = pismo_width_to_bytes(cs->width);
191 region.access = le16_to_cpu(cs->access);
192 region.size = le32_to_cpu(cs->size);
193
194 if (region.width == 0) {
195 dev_err(dev, "cs%u: bad width: %02x, ignoring\n", i, cs->width);
196 return;
197 }
198
199 /*
200 * FIXME: may need to the platforms memory controller here, but at
201 * the moment we assume that it has already been correctly setup.
202 * The memory controller can also tell us the base address as well.
203 */
204
205 dev_info(dev, "cs%u: %.32s: type %02x access %u00ps size %uK\n",
206 i, cs->device, region.type, region.access, region.size / 1024);
207
208 switch (region.type) {
209 case 0:
210 break;
211 case 1:
212 /* static DOC */
213 break;
214 case 2:
215 /* static NOR */
216 pismo_add_nor(pismo, i, &region);
217 break;
218 case 3:
219 /* static RAM */
220 pismo_add_sram(pismo, i, &region);
221 break;
222 }
223}
224
225static int __devexit pismo_remove(struct i2c_client *client)
226{
227 struct pismo_data *pismo = i2c_get_clientdata(client);
228 int i;
229
230 for (i = 0; i < ARRAY_SIZE(pismo->dev); i++)
231 platform_device_unregister(pismo->dev[i]);
232
233 /* FIXME: set_vpp needs saner arguments */
234 pismo_setvpp_remove_fix(pismo);
235
236 kfree(pismo);
237
238 return 0;
239}
240
241static int __devinit pismo_probe(struct i2c_client *client,
242 const struct i2c_device_id *id)
243{
244 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
245 struct pismo_pdata *pdata = client->dev.platform_data;
246 struct pismo_eeprom eeprom;
247 struct pismo_data *pismo;
248 int ret, i;
249
250 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
251 dev_err(&client->dev, "functionality mismatch\n");
252 return -EIO;
253 }
254
255 pismo = kzalloc(sizeof(*pismo), GFP_KERNEL);
256 if (!pismo)
257 return -ENOMEM;
258
259 /* FIXME: set_vpp needs saner arguments */
260 ret = pismo_setvpp_probe_fix(pismo);
261 if (ret)
262 return ret;
263
264 pismo->client = client;
265 if (pdata) {
266 pismo->vpp = pdata->set_vpp;
267 pismo->vpp_data = pdata->vpp_data;
268 }
269 i2c_set_clientdata(client, pismo);
270
271 ret = pismo_eeprom_read(client, &eeprom, 0, sizeof(eeprom));
272 if (ret < 0) {
273 dev_err(&client->dev, "error reading EEPROM: %d\n", ret);
274 return ret;
275 }
276
277 dev_info(&client->dev, "%.15s board found\n", eeprom.board);
278
279 for (i = 0; i < ARRAY_SIZE(eeprom.cs); i++)
280 if (eeprom.cs[i].type != 0xff)
281 pismo_add_one(pismo, i, &eeprom.cs[i],
282 pdata->cs_addrs[i]);
283
284 return 0;
285}
286
287static const struct i2c_device_id pismo_id[] = {
288 { "pismo" },
289 { },
290};
291MODULE_DEVICE_TABLE(i2c, pismo_id);
292
293static struct i2c_driver pismo_driver = {
294 .driver = {
295 .name = "pismo",
296 .owner = THIS_MODULE,
297 },
298 .probe = pismo_probe,
299 .remove = __devexit_p(pismo_remove),
300 .id_table = pismo_id,
301};
302
303static int __init pismo_init(void)
304{
305 BUILD_BUG_ON(sizeof(struct pismo_cs_block) != 48);
306 BUILD_BUG_ON(sizeof(struct pismo_eeprom) != 256);
307
308 return i2c_add_driver(&pismo_driver);
309}
310module_init(pismo_init);
311
312static void __exit pismo_exit(void)
313{
314 i2c_del_driver(&pismo_driver);
315}
316module_exit(pismo_exit);
317
318MODULE_AUTHOR("Russell King <linux@arm.linux.org.uk>");
319MODULE_DESCRIPTION("PISMO memory driver");
320MODULE_LICENSE("GPL");
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index a714ec482761..92e12df0917f 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -322,7 +322,7 @@ static void mtdoops_do_dump(struct kmsg_dumper *dumper,
322 memcpy(dst + l1_cpy, s2 + s2_start, l2_cpy); 322 memcpy(dst + l1_cpy, s2 + s2_start, l2_cpy);
323 323
324 /* Panics must be written immediately */ 324 /* Panics must be written immediately */
325 if (reason == KMSG_DUMP_PANIC) { 325 if (reason != KMSG_DUMP_OOPS) {
326 if (!cxt->mtd->panic_write) 326 if (!cxt->mtd->panic_write)
327 printk(KERN_ERR "mtdoops: Cannot write from panic without panic_write\n"); 327 printk(KERN_ERR "mtdoops: Cannot write from panic without panic_write\n");
328 else 328 else
diff --git a/drivers/mtd/tests/mtd_readtest.c b/drivers/mtd/tests/mtd_readtest.c
index 79fc4530987b..25c5dd03a837 100644
--- a/drivers/mtd/tests/mtd_readtest.c
+++ b/drivers/mtd/tests/mtd_readtest.c
@@ -147,6 +147,10 @@ static int scan_for_bad_eraseblocks(void)
147 } 147 }
148 memset(bbt, 0 , ebcnt); 148 memset(bbt, 0 , ebcnt);
149 149
150 /* NOR flash does not implement block_isbad */
151 if (mtd->block_isbad == NULL)
152 return 0;
153
150 printk(PRINT_PREF "scanning for bad eraseblocks\n"); 154 printk(PRINT_PREF "scanning for bad eraseblocks\n");
151 for (i = 0; i < ebcnt; ++i) { 155 for (i = 0; i < ebcnt; ++i) {
152 bbt[i] = is_block_bad(i) ? 1 : 0; 156 bbt[i] = is_block_bad(i) ? 1 : 0;
@@ -184,7 +188,7 @@ static int __init mtd_readtest_init(void)
184 tmp = mtd->size; 188 tmp = mtd->size;
185 do_div(tmp, mtd->erasesize); 189 do_div(tmp, mtd->erasesize);
186 ebcnt = tmp; 190 ebcnt = tmp;
187 pgcnt = mtd->erasesize / mtd->writesize; 191 pgcnt = mtd->erasesize / pgsize;
188 192
189 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " 193 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, "
190 "page size %u, count of eraseblocks %u, pages per " 194 "page size %u, count of eraseblocks %u, pages per "
diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c
index 141363a7e805..7fbb51d4eabe 100644
--- a/drivers/mtd/tests/mtd_speedtest.c
+++ b/drivers/mtd/tests/mtd_speedtest.c
@@ -301,6 +301,10 @@ static int scan_for_bad_eraseblocks(void)
301 } 301 }
302 memset(bbt, 0 , ebcnt); 302 memset(bbt, 0 , ebcnt);
303 303
304 /* NOR flash does not implement block_isbad */
305 if (mtd->block_isbad == NULL)
306 goto out;
307
304 printk(PRINT_PREF "scanning for bad eraseblocks\n"); 308 printk(PRINT_PREF "scanning for bad eraseblocks\n");
305 for (i = 0; i < ebcnt; ++i) { 309 for (i = 0; i < ebcnt; ++i) {
306 bbt[i] = is_block_bad(i) ? 1 : 0; 310 bbt[i] = is_block_bad(i) ? 1 : 0;
@@ -309,6 +313,7 @@ static int scan_for_bad_eraseblocks(void)
309 cond_resched(); 313 cond_resched();
310 } 314 }
311 printk(PRINT_PREF "scanned %d eraseblocks, %d are bad\n", i, bad); 315 printk(PRINT_PREF "scanned %d eraseblocks, %d are bad\n", i, bad);
316out:
312 goodebcnt = ebcnt - bad; 317 goodebcnt = ebcnt - bad;
313 return 0; 318 return 0;
314} 319}
@@ -340,7 +345,7 @@ static int __init mtd_speedtest_init(void)
340 tmp = mtd->size; 345 tmp = mtd->size;
341 do_div(tmp, mtd->erasesize); 346 do_div(tmp, mtd->erasesize);
342 ebcnt = tmp; 347 ebcnt = tmp;
343 pgcnt = mtd->erasesize / mtd->writesize; 348 pgcnt = mtd->erasesize / pgsize;
344 349
345 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " 350 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, "
346 "page size %u, count of eraseblocks %u, pages per " 351 "page size %u, count of eraseblocks %u, pages per "
diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c
index 63920476b57a..a99d3cd737d8 100644
--- a/drivers/mtd/tests/mtd_stresstest.c
+++ b/drivers/mtd/tests/mtd_stresstest.c
@@ -227,6 +227,10 @@ static int scan_for_bad_eraseblocks(void)
227 } 227 }
228 memset(bbt, 0 , ebcnt); 228 memset(bbt, 0 , ebcnt);
229 229
230 /* NOR flash does not implement block_isbad */
231 if (mtd->block_isbad == NULL)
232 return 0;
233
230 printk(PRINT_PREF "scanning for bad eraseblocks\n"); 234 printk(PRINT_PREF "scanning for bad eraseblocks\n");
231 for (i = 0; i < ebcnt; ++i) { 235 for (i = 0; i < ebcnt; ++i) {
232 bbt[i] = is_block_bad(i) ? 1 : 0; 236 bbt[i] = is_block_bad(i) ? 1 : 0;
@@ -265,7 +269,7 @@ static int __init mtd_stresstest_init(void)
265 tmp = mtd->size; 269 tmp = mtd->size;
266 do_div(tmp, mtd->erasesize); 270 do_div(tmp, mtd->erasesize);
267 ebcnt = tmp; 271 ebcnt = tmp;
268 pgcnt = mtd->erasesize / mtd->writesize; 272 pgcnt = mtd->erasesize / pgsize;
269 273
270 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " 274 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, "
271 "page size %u, count of eraseblocks %u, pages per " 275 "page size %u, count of eraseblocks %u, pages per "
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index f237ddbb2713..111ea41c4ecd 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -853,7 +853,6 @@ static long ubi_cdev_ioctl(struct file *file, unsigned int cmd,
853 break; 853 break;
854 } 854 }
855 855
856 req.name[req.name_len] = '\0';
857 err = verify_mkvol_req(ubi, &req); 856 err = verify_mkvol_req(ubi, &req);
858 if (err) 857 if (err)
859 break; 858 break;
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index 277786ebaa2c..1361574e2b00 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -291,8 +291,7 @@ EXPORT_SYMBOL_GPL(ubi_open_volume_nm);
291 */ 291 */
292struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode) 292struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode)
293{ 293{
294 int error, ubi_num, vol_id; 294 int error, ubi_num, vol_id, mod;
295 struct ubi_volume_desc *ret;
296 struct inode *inode; 295 struct inode *inode;
297 struct path path; 296 struct path path;
298 297
@@ -306,16 +305,16 @@ struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode)
306 return ERR_PTR(error); 305 return ERR_PTR(error);
307 306
308 inode = path.dentry->d_inode; 307 inode = path.dentry->d_inode;
308 mod = inode->i_mode;
309 ubi_num = ubi_major2num(imajor(inode)); 309 ubi_num = ubi_major2num(imajor(inode));
310 vol_id = iminor(inode) - 1; 310 vol_id = iminor(inode) - 1;
311 path_put(&path);
311 312
313 if (!S_ISCHR(mod))
314 return ERR_PTR(-EINVAL);
312 if (vol_id >= 0 && ubi_num >= 0) 315 if (vol_id >= 0 && ubi_num >= 0)
313 ret = ubi_open_volume(ubi_num, vol_id, mode); 316 return ubi_open_volume(ubi_num, vol_id, mode);
314 else 317 return ERR_PTR(-ENODEV);
315 ret = ERR_PTR(-ENODEV);
316
317 path_put(&path);
318 return ret;
319} 318}
320EXPORT_SYMBOL_GPL(ubi_open_volume_path); 319EXPORT_SYMBOL_GPL(ubi_open_volume_path);
321 320
diff --git a/drivers/mtd/ubi/upd.c b/drivers/mtd/ubi/upd.c
index c1d7b880c795..425bf5a3edd4 100644
--- a/drivers/mtd/ubi/upd.c
+++ b/drivers/mtd/ubi/upd.c
@@ -155,6 +155,7 @@ int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol,
155 if (err) 155 if (err)
156 return err; 156 return err;
157 vol->updating = 0; 157 vol->updating = 0;
158 return 0;
158 } 159 }
159 160
160 vol->upd_buf = vmalloc(ubi->leb_size); 161 vol->upd_buf = vmalloc(ubi->leb_size);
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 1afc61e7455d..40044028d682 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -566,6 +566,7 @@ static int init_volumes(struct ubi_device *ubi, const struct ubi_scan_info *si,
566 vol->reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs); 566 vol->reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs);
567 vol->alignment = be32_to_cpu(vtbl[i].alignment); 567 vol->alignment = be32_to_cpu(vtbl[i].alignment);
568 vol->data_pad = be32_to_cpu(vtbl[i].data_pad); 568 vol->data_pad = be32_to_cpu(vtbl[i].data_pad);
569 vol->upd_marker = vtbl[i].upd_marker;
569 vol->vol_type = vtbl[i].vol_type == UBI_VID_DYNAMIC ? 570 vol->vol_type = vtbl[i].vol_type == UBI_VID_DYNAMIC ?
570 UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME; 571 UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME;
571 vol->name_len = be16_to_cpu(vtbl[i].name_len); 572 vol->name_len = be16_to_cpu(vtbl[i].name_len);