| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Common code to handle absent "placeholder" devices | 
|  | 3 | * Copyright 2001 Resilience Corporation <ebrower@resilience.com> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * | 
|  | 5 | * This map driver is used to allocate "placeholder" MTD | 
| Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 6 | * devices on systems that have socketed/removable media. | 
|  | 7 | * Use of this driver as a fallback preserves the expected | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * 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> | 
|  | 28 | #include <linux/mtd/compatmac.h> | 
|  | 29 |  | 
|  | 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 *); | 
|  | 36 |  | 
|  | 37 |  | 
|  | 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 | 
|  | 43 | }; | 
|  | 44 |  | 
|  | 45 | static struct mtd_info *map_absent_probe(struct map_info *map) | 
|  | 46 | { | 
|  | 47 | struct mtd_info *mtd; | 
|  | 48 |  | 
| Burman Yan | 95b93a0 | 2006-11-15 21:10:29 +0200 | [diff] [blame] | 49 | mtd = kzalloc(sizeof(*mtd), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | if (!mtd) { | 
|  | 51 | return NULL; | 
|  | 52 | } | 
|  | 53 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; | 
| Artem B. Bityutskiy | 17ffc7b | 2006-06-22 18:15:48 +0400 | [diff] [blame] | 64 | mtd->erasesize  = PAGE_SIZE; | 
|  | 65 | mtd->writesize  = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 |  | 
|  | 67 | __module_get(THIS_MODULE); | 
|  | 68 | return mtd; | 
|  | 69 | } | 
|  | 70 |  | 
|  | 71 |  | 
|  | 72 | static int map_absent_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) | 
|  | 73 | { | 
|  | 74 | *retlen = 0; | 
|  | 75 | return -ENODEV; | 
|  | 76 | } | 
|  | 77 |  | 
|  | 78 | static int map_absent_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) | 
|  | 79 | { | 
|  | 80 | *retlen = 0; | 
| Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 81 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } | 
|  | 83 |  | 
|  | 84 | static int map_absent_erase(struct mtd_info *mtd, struct erase_info *instr) | 
|  | 85 | { | 
|  | 86 | return -ENODEV; | 
|  | 87 | } | 
|  | 88 |  | 
|  | 89 | static void map_absent_sync(struct mtd_info *mtd) | 
|  | 90 | { | 
|  | 91 | /* nop */ | 
|  | 92 | } | 
|  | 93 |  | 
|  | 94 | static void map_absent_destroy(struct mtd_info *mtd) | 
|  | 95 | { | 
|  | 96 | /* nop */ | 
|  | 97 | } | 
|  | 98 |  | 
|  | 99 | static int __init map_absent_init(void) | 
|  | 100 | { | 
|  | 101 | register_mtd_chip_driver(&map_absent_chipdrv); | 
|  | 102 | return 0; | 
|  | 103 | } | 
|  | 104 |  | 
|  | 105 | static void __exit map_absent_exit(void) | 
|  | 106 | { | 
|  | 107 | unregister_mtd_chip_driver(&map_absent_chipdrv); | 
|  | 108 | } | 
|  | 109 |  | 
|  | 110 | module_init(map_absent_init); | 
|  | 111 | module_exit(map_absent_exit); | 
|  | 112 |  | 
|  | 113 | MODULE_LICENSE("GPL"); | 
|  | 114 | MODULE_AUTHOR("Resilience Corporation - Eric Brower <ebrower@resilience.com>"); | 
|  | 115 | MODULE_DESCRIPTION("Placeholder MTD chip driver for 'absent' chips"); |