blob: fc68557f49c03d0a4cca5d42bc9e36f00636af05 [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Common code to handle absent "placeholder" devices
4 * Copyright 2001 Resilience Corporation <ebrower@resilience.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * This map driver is used to allocate "placeholder" MTD
Thomas Gleixner1f948b42005-11-07 11:15:37 +00007 * devices on systems that have socketed/removable media.
8 * Use of this driver as a fallback preserves the expected
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * registration of MTD device nodes regardless of probe outcome.
10 * A usage example is as follows:
11 *
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 * }
16 *
17 * Any device 'probed' with this driver will return -ENODEV
18 * upon open.
19 */
20
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30static int map_absent_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
31static int map_absent_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
32static int map_absent_erase (struct mtd_info *, struct erase_info *);
33static void map_absent_sync (struct mtd_info *);
34static struct mtd_info *map_absent_probe(struct map_info *map);
35static void map_absent_destroy (struct mtd_info *);
36
37
38static 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
43};
44
45static struct mtd_info *map_absent_probe(struct map_info *map)
46{
47 struct mtd_info *mtd;
48
Burman Yan95b93a02006-11-15 21:10:29 +020049 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 if (!mtd) {
51 return NULL;
52 }
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 map->fldrv = &map_absent_chipdrv;
55 mtd->priv = map;
56 mtd->name = map->name;
57 mtd->type = MTD_ABSENT;
58 mtd->size = map->size;
Artem Bityutskiy3c3c10b2012-01-30 14:58:32 +020059 mtd->_erase = map_absent_erase;
60 mtd->_read = map_absent_read;
61 mtd->_write = map_absent_write;
62 mtd->_sync = map_absent_sync;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 mtd->flags = 0;
Artem B. Bityutskiy17ffc7b2006-06-22 18:15:48 +040064 mtd->erasesize = PAGE_SIZE;
65 mtd->writesize = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67 __module_get(THIS_MODULE);
68 return mtd;
69}
70
71
72static int map_absent_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
73{
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 return -ENODEV;
75}
76
77static int map_absent_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
78{
Thomas Gleixner1f948b42005-11-07 11:15:37 +000079 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
82static int map_absent_erase(struct mtd_info *mtd, struct erase_info *instr)
83{
84 return -ENODEV;
85}
86
87static void map_absent_sync(struct mtd_info *mtd)
88{
89 /* nop */
90}
91
92static void map_absent_destroy(struct mtd_info *mtd)
93{
94 /* nop */
95}
96
97static int __init map_absent_init(void)
98{
99 register_mtd_chip_driver(&map_absent_chipdrv);
100 return 0;
101}
102
103static void __exit map_absent_exit(void)
104{
105 unregister_mtd_chip_driver(&map_absent_chipdrv);
106}
107
108module_init(map_absent_init);
109module_exit(map_absent_exit);
110
111MODULE_LICENSE("GPL");
112MODULE_AUTHOR("Resilience Corporation - Eric Brower <ebrower@resilience.com>");
113MODULE_DESCRIPTION("Placeholder MTD chip driver for 'absent' chips");