map_rom.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Common code to handle map devices which are simple ROM
  3. * (C) 2000 Red Hat. GPL'd.
  4. */
  5. #include <linux/module.h>
  6. #include <linux/types.h>
  7. #include <linux/kernel.h>
  8. #include <asm/io.h>
  9. #include <asm/byteorder.h>
  10. #include <linux/errno.h>
  11. #include <linux/slab.h>
  12. #include <linux/init.h>
  13. #include <linux/mtd/mtd.h>
  14. #include <linux/mtd/map.h>
  15. #include <linux/mtd/compatmac.h>
  16. static int maprom_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
  17. static int maprom_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
  18. static void maprom_nop (struct mtd_info *);
  19. static struct mtd_info *map_rom_probe(struct map_info *map);
  20. static struct mtd_chip_driver maprom_chipdrv = {
  21. .probe = map_rom_probe,
  22. .name = "map_rom",
  23. .module = THIS_MODULE
  24. };
  25. static struct mtd_info *map_rom_probe(struct map_info *map)
  26. {
  27. struct mtd_info *mtd;
  28. mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
  29. if (!mtd)
  30. return NULL;
  31. map->fldrv = &maprom_chipdrv;
  32. mtd->priv = map;
  33. mtd->name = map->name;
  34. mtd->type = MTD_ROM;
  35. mtd->size = map->size;
  36. mtd->read = maprom_read;
  37. mtd->write = maprom_write;
  38. mtd->sync = maprom_nop;
  39. mtd->flags = MTD_CAP_ROM;
  40. mtd->erasesize = map->size;
  41. mtd->writesize = 1;
  42. __module_get(THIS_MODULE);
  43. return mtd;
  44. }
  45. static int maprom_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
  46. {
  47. struct map_info *map = mtd->priv;
  48. map_copy_from(map, buf, from, len);
  49. *retlen = len;
  50. return 0;
  51. }
  52. static void maprom_nop(struct mtd_info *mtd)
  53. {
  54. /* Nothing to see here */
  55. }
  56. static int maprom_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
  57. {
  58. printk(KERN_NOTICE "maprom_write called\n");
  59. return -EIO;
  60. }
  61. static int __init map_rom_init(void)
  62. {
  63. register_mtd_chip_driver(&maprom_chipdrv);
  64. return 0;
  65. }
  66. static void __exit map_rom_exit(void)
  67. {
  68. unregister_mtd_chip_driver(&maprom_chipdrv);
  69. }
  70. module_init(map_rom_init);
  71. module_exit(map_rom_exit);
  72. MODULE_LICENSE("GPL");
  73. MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  74. MODULE_DESCRIPTION("MTD chip driver for ROM chips");