map_rom.c 2.1 KB

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