WIP FPC-III support
[linux/fpc-iii.git] / drivers / mtd / chips / map_absent.c
blobfc68557f49c03d0a4cca5d42bc9e36f00636af05
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Common code to handle absent "placeholder" devices
4 * Copyright 2001 Resilience Corporation <ebrower@resilience.com>
6 * This map driver is used to allocate "placeholder" MTD
7 * devices on systems that have socketed/removable media.
8 * Use of this driver as a fallback preserves the expected
9 * registration of MTD device nodes regardless of probe outcome.
10 * A usage example is as follows:
12 * my_dev[i] = do_map_probe("cfi", &my_map[i]);
13 * if(NULL == my_dev[i]) {
14 * my_dev[i] = do_map_probe("map_absent", &my_map[i]);
15 * }
17 * Any device 'probed' with this driver will return -ENODEV
18 * upon open.
21 #include <linux/module.h>
22 #include <linux/types.h>
23 #include <linux/kernel.h>
24 #include <linux/errno.h>
25 #include <linux/slab.h>
26 #include <linux/init.h>
27 #include <linux/mtd/mtd.h>
28 #include <linux/mtd/map.h>
30 static int map_absent_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
31 static int map_absent_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
32 static int map_absent_erase (struct mtd_info *, struct erase_info *);
33 static void map_absent_sync (struct mtd_info *);
34 static struct mtd_info *map_absent_probe(struct map_info *map);
35 static void map_absent_destroy (struct mtd_info *);
38 static struct mtd_chip_driver map_absent_chipdrv = {
39 .probe = map_absent_probe,
40 .destroy = map_absent_destroy,
41 .name = "map_absent",
42 .module = THIS_MODULE
45 static struct mtd_info *map_absent_probe(struct map_info *map)
47 struct mtd_info *mtd;
49 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
50 if (!mtd) {
51 return NULL;
54 map->fldrv = &map_absent_chipdrv;
55 mtd->priv = map;
56 mtd->name = map->name;
57 mtd->type = MTD_ABSENT;
58 mtd->size = map->size;
59 mtd->_erase = map_absent_erase;
60 mtd->_read = map_absent_read;
61 mtd->_write = map_absent_write;
62 mtd->_sync = map_absent_sync;
63 mtd->flags = 0;
64 mtd->erasesize = PAGE_SIZE;
65 mtd->writesize = 1;
67 __module_get(THIS_MODULE);
68 return mtd;
72 static int map_absent_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
74 return -ENODEV;
77 static int map_absent_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
79 return -ENODEV;
82 static int map_absent_erase(struct mtd_info *mtd, struct erase_info *instr)
84 return -ENODEV;
87 static void map_absent_sync(struct mtd_info *mtd)
89 /* nop */
92 static void map_absent_destroy(struct mtd_info *mtd)
94 /* nop */
97 static int __init map_absent_init(void)
99 register_mtd_chip_driver(&map_absent_chipdrv);
100 return 0;
103 static void __exit map_absent_exit(void)
105 unregister_mtd_chip_driver(&map_absent_chipdrv);
108 module_init(map_absent_init);
109 module_exit(map_absent_exit);
111 MODULE_LICENSE("GPL");
112 MODULE_AUTHOR("Resilience Corporation - Eric Brower <ebrower@resilience.com>");
113 MODULE_DESCRIPTION("Placeholder MTD chip driver for 'absent' chips");