blob: f7a5bca92aefed6d9eeac776b7eaf334d49efd53 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Common code to handle absent "placeholder" devices
3 * Copyright 2001 Resilience Corporation <ebrower@resilience.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * This map driver is used to allocate "placeholder" MTD
Thomas Gleixner1f948b42005-11-07 11:15:37 +00006 * devices on systems that have socketed/removable media.
7 * Use of this driver as a fallback preserves the expected
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * registration of MTD device nodes regardless of probe outcome.
9 * A usage example is as follows:
10 *
11 * my_dev[i] = do_map_probe("cfi", &my_map[i]);
12 * if(NULL == my_dev[i]) {
13 * my_dev[i] = do_map_probe("map_absent", &my_map[i]);
14 * }
15 *
16 * Any device 'probed' with this driver will return -ENODEV
17 * upon open.
18 */
19
20#include <linux/module.h>
21#include <linux/types.h>
22#include <linux/kernel.h>
23#include <linux/errno.h>
24#include <linux/slab.h>
25#include <linux/init.h>
26#include <linux/mtd/mtd.h>
27#include <linux/mtd/map.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29static int map_absent_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
30static int map_absent_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
31static int map_absent_erase (struct mtd_info *, struct erase_info *);
32static void map_absent_sync (struct mtd_info *);
33static struct mtd_info *map_absent_probe(struct map_info *map);
34static void map_absent_destroy (struct mtd_info *);
35
36
37static struct mtd_chip_driver map_absent_chipdrv = {
38 .probe = map_absent_probe,
39 .destroy = map_absent_destroy,
40 .name = "map_absent",
41 .module = THIS_MODULE
42};
43
44static struct mtd_info *map_absent_probe(struct map_info *map)
45{
46 struct mtd_info *mtd;
47
Burman Yan95b93a02006-11-15 21:10:29 +020048 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 if (!mtd) {
50 return NULL;
51 }
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 map->fldrv = &map_absent_chipdrv;
54 mtd->priv = map;
55 mtd->name = map->name;
56 mtd->type = MTD_ABSENT;
57 mtd->size = map->size;
Artem Bityutskiy3c3c10b2012-01-30 14:58:32 +020058 mtd->_erase = map_absent_erase;
59 mtd->_read = map_absent_read;
60 mtd->_write = map_absent_write;
61 mtd->_sync = map_absent_sync;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 mtd->flags = 0;
Artem B. Bityutskiy17ffc7b2006-06-22 18:15:48 +040063 mtd->erasesize = PAGE_SIZE;
64 mtd->writesize = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 __module_get(THIS_MODULE);
67 return mtd;
68}
69
70
71static int map_absent_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
72{
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 return -ENODEV;
74}
75
76static int map_absent_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
77{
Thomas Gleixner1f948b42005-11-07 11:15:37 +000078 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
81static int map_absent_erase(struct mtd_info *mtd, struct erase_info *instr)
82{
83 return -ENODEV;
84}
85
86static void map_absent_sync(struct mtd_info *mtd)
87{
88 /* nop */
89}
90
91static void map_absent_destroy(struct mtd_info *mtd)
92{
93 /* nop */
94}
95
96static int __init map_absent_init(void)
97{
98 register_mtd_chip_driver(&map_absent_chipdrv);
99 return 0;
100}
101
102static void __exit map_absent_exit(void)
103{
104 unregister_mtd_chip_driver(&map_absent_chipdrv);
105}
106
107module_init(map_absent_init);
108module_exit(map_absent_exit);
109
110MODULE_LICENSE("GPL");
111MODULE_AUTHOR("Resilience Corporation - Eric Brower <ebrower@resilience.com>");
112MODULE_DESCRIPTION("Placeholder MTD chip driver for 'absent' chips");