map_absent.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Common code to handle absent "placeholder" devices
  3. * Copyright 2001 Resilience Corporation <ebrower@resilience.com>
  4. *
  5. * This map driver is used to allocate "placeholder" MTD
  6. * devices on systems that have socketed/removable media.
  7. * Use of this driver as a fallback preserves the expected
  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. #include <linux/module.h>
  20. #include <linux/types.h>
  21. #include <linux/kernel.h>
  22. #include <linux/errno.h>
  23. #include <linux/slab.h>
  24. #include <linux/init.h>
  25. #include <linux/mtd/mtd.h>
  26. #include <linux/mtd/map.h>
  27. static int map_absent_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
  28. static int map_absent_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
  29. static int map_absent_erase (struct mtd_info *, struct erase_info *);
  30. static void map_absent_sync (struct mtd_info *);
  31. static struct mtd_info *map_absent_probe(struct map_info *map);
  32. static void map_absent_destroy (struct mtd_info *);
  33. static struct mtd_chip_driver map_absent_chipdrv = {
  34. .probe = map_absent_probe,
  35. .destroy = map_absent_destroy,
  36. .name = "map_absent",
  37. .module = THIS_MODULE
  38. };
  39. static struct mtd_info *map_absent_probe(struct map_info *map)
  40. {
  41. struct mtd_info *mtd;
  42. mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
  43. if (!mtd) {
  44. return NULL;
  45. }
  46. map->fldrv = &map_absent_chipdrv;
  47. mtd->priv = map;
  48. mtd->name = map->name;
  49. mtd->type = MTD_ABSENT;
  50. mtd->size = map->size;
  51. mtd->_erase = map_absent_erase;
  52. mtd->_read = map_absent_read;
  53. mtd->_write = map_absent_write;
  54. mtd->_sync = map_absent_sync;
  55. mtd->flags = 0;
  56. mtd->erasesize = PAGE_SIZE;
  57. mtd->writesize = 1;
  58. __module_get(THIS_MODULE);
  59. return mtd;
  60. }
  61. static int map_absent_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
  62. {
  63. return -ENODEV;
  64. }
  65. static int map_absent_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
  66. {
  67. return -ENODEV;
  68. }
  69. static int map_absent_erase(struct mtd_info *mtd, struct erase_info *instr)
  70. {
  71. return -ENODEV;
  72. }
  73. static void map_absent_sync(struct mtd_info *mtd)
  74. {
  75. /* nop */
  76. }
  77. static void map_absent_destroy(struct mtd_info *mtd)
  78. {
  79. /* nop */
  80. }
  81. static int __init map_absent_init(void)
  82. {
  83. register_mtd_chip_driver(&map_absent_chipdrv);
  84. return 0;
  85. }
  86. static void __exit map_absent_exit(void)
  87. {
  88. unregister_mtd_chip_driver(&map_absent_chipdrv);
  89. }
  90. module_init(map_absent_init);
  91. module_exit(map_absent_exit);
  92. MODULE_LICENSE("GPL");
  93. MODULE_AUTHOR("Resilience Corporation - Eric Brower <ebrower@resilience.com>");
  94. MODULE_DESCRIPTION("Placeholder MTD chip driver for 'absent' chips");