aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/mtdcore.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/mtdcore.c')
-rw-r--r--drivers/mtd/mtdcore.c81
1 files changed, 23 insertions, 58 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 4c611871d7e6..0ec4d6ea1e4b 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -43,33 +43,7 @@
43 43
44#include "mtdcore.h" 44#include "mtdcore.h"
45 45
46/* 46static struct backing_dev_info mtd_bdi = {
47 * backing device capabilities for non-mappable devices (such as NAND flash)
48 * - permits private mappings, copies are taken of the data
49 */
50static struct backing_dev_info mtd_bdi_unmappable = {
51 .capabilities = BDI_CAP_MAP_COPY,
52};
53
54/*
55 * backing device capabilities for R/O mappable devices (such as ROM)
56 * - permits private mappings, copies are taken of the data
57 * - permits non-writable shared mappings
58 */
59static struct backing_dev_info mtd_bdi_ro_mappable = {
60 .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
61 BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP),
62};
63
64/*
65 * backing device capabilities for writable mappable devices (such as RAM)
66 * - permits private mappings, copies are taken of the data
67 * - permits non-writable shared mappings
68 */
69static struct backing_dev_info mtd_bdi_rw_mappable = {
70 .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
71 BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP |
72 BDI_CAP_WRITE_MAP),
73}; 47};
74 48
75static int mtd_cls_suspend(struct device *dev, pm_message_t state); 49static int mtd_cls_suspend(struct device *dev, pm_message_t state);
@@ -365,6 +339,23 @@ static struct device_type mtd_devtype = {
365 .release = mtd_release, 339 .release = mtd_release,
366}; 340};
367 341
342#ifndef CONFIG_MMU
343unsigned mtd_mmap_capabilities(struct mtd_info *mtd)
344{
345 switch (mtd->type) {
346 case MTD_RAM:
347 return NOMMU_MAP_COPY | NOMMU_MAP_DIRECT | NOMMU_MAP_EXEC |
348 NOMMU_MAP_READ | NOMMU_MAP_WRITE;
349 case MTD_ROM:
350 return NOMMU_MAP_COPY | NOMMU_MAP_DIRECT | NOMMU_MAP_EXEC |
351 NOMMU_MAP_READ;
352 default:
353 return NOMMU_MAP_COPY;
354 }
355}
356EXPORT_SYMBOL_GPL(mtd_mmap_capabilities);
357#endif
358
368/** 359/**
369 * add_mtd_device - register an MTD device 360 * add_mtd_device - register an MTD device
370 * @mtd: pointer to new MTD device info structure 361 * @mtd: pointer to new MTD device info structure
@@ -380,19 +371,7 @@ int add_mtd_device(struct mtd_info *mtd)
380 struct mtd_notifier *not; 371 struct mtd_notifier *not;
381 int i, error; 372 int i, error;
382 373
383 if (!mtd->backing_dev_info) { 374 mtd->backing_dev_info = &mtd_bdi;
384 switch (mtd->type) {
385 case MTD_RAM:
386 mtd->backing_dev_info = &mtd_bdi_rw_mappable;
387 break;
388 case MTD_ROM:
389 mtd->backing_dev_info = &mtd_bdi_ro_mappable;
390 break;
391 default:
392 mtd->backing_dev_info = &mtd_bdi_unmappable;
393 break;
394 }
395 }
396 375
397 BUG_ON(mtd->writesize == 0); 376 BUG_ON(mtd->writesize == 0);
398 mutex_lock(&mtd_table_mutex); 377 mutex_lock(&mtd_table_mutex);
@@ -1237,17 +1216,9 @@ static int __init init_mtd(void)
1237 if (ret) 1216 if (ret)
1238 goto err_reg; 1217 goto err_reg;
1239 1218
1240 ret = mtd_bdi_init(&mtd_bdi_unmappable, "mtd-unmap"); 1219 ret = mtd_bdi_init(&mtd_bdi, "mtd");
1241 if (ret)
1242 goto err_bdi1;
1243
1244 ret = mtd_bdi_init(&mtd_bdi_ro_mappable, "mtd-romap");
1245 if (ret)
1246 goto err_bdi2;
1247
1248 ret = mtd_bdi_init(&mtd_bdi_rw_mappable, "mtd-rwmap");
1249 if (ret) 1220 if (ret)
1250 goto err_bdi3; 1221 goto err_bdi;
1251 1222
1252 proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops); 1223 proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops);
1253 1224
@@ -1260,11 +1231,7 @@ static int __init init_mtd(void)
1260out_procfs: 1231out_procfs:
1261 if (proc_mtd) 1232 if (proc_mtd)
1262 remove_proc_entry("mtd", NULL); 1233 remove_proc_entry("mtd", NULL);
1263err_bdi3: 1234err_bdi:
1264 bdi_destroy(&mtd_bdi_ro_mappable);
1265err_bdi2:
1266 bdi_destroy(&mtd_bdi_unmappable);
1267err_bdi1:
1268 class_unregister(&mtd_class); 1235 class_unregister(&mtd_class);
1269err_reg: 1236err_reg:
1270 pr_err("Error registering mtd class or bdi: %d\n", ret); 1237 pr_err("Error registering mtd class or bdi: %d\n", ret);
@@ -1277,9 +1244,7 @@ static void __exit cleanup_mtd(void)
1277 if (proc_mtd) 1244 if (proc_mtd)
1278 remove_proc_entry("mtd", NULL); 1245 remove_proc_entry("mtd", NULL);
1279 class_unregister(&mtd_class); 1246 class_unregister(&mtd_class);
1280 bdi_destroy(&mtd_bdi_unmappable); 1247 bdi_destroy(&mtd_bdi);
1281 bdi_destroy(&mtd_bdi_ro_mappable);
1282 bdi_destroy(&mtd_bdi_rw_mappable);
1283} 1248}
1284 1249
1285module_init(init_mtd); 1250module_init(init_mtd);