map_rom.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 = kmalloc(sizeof(*mtd), GFP_KERNEL);
  30. if (!mtd)
  31. return NULL;
  32. memset(mtd, 0, sizeof(*mtd));
  33. map->fldrv = &maprom_chipdrv;
  34. mtd->priv = map;
  35. mtd->name = map->name;
  36. mtd->type = MTD_ROM;
  37. mtd->size = map->size;
  38. mtd->read = maprom_read;
  39. mtd->write = maprom_write;
  40. mtd->sync = maprom_nop;
  41. mtd->flags = MTD_CAP_ROM;
  42. mtd->erasesize = 131072;
  43. while(mtd->size & (mtd->erasesize - 1))
  44. mtd->erasesize >>= 1;
  45. __module_get(THIS_MODULE);
  46. return mtd;
  47. }
  48. static int maprom_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
  49. {
  50. struct map_info *map = mtd->priv;
  51. map_copy_from(map, buf, from, len);
  52. *retlen = len;
  53. return 0;
  54. }
  55. static void maprom_nop(struct mtd_info *mtd)
  56. {
  57. /* Nothing to see here */
  58. }
  59. static int maprom_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
  60. {
  61. printk(KERN_NOTICE "maprom_write called\n");
  62. return -EIO;
  63. }
  64. static int __init map_rom_init(void)
  65. {
  66. register_mtd_chip_driver(&maprom_chipdrv);
  67. return 0;
  68. }
  69. static void __exit map_rom_exit(void)
  70. {
  71. unregister_mtd_chip_driver(&maprom_chipdrv);
  72. }
  73. module_init(map_rom_init);
  74. module_exit(map_rom_exit);
  75. MODULE_LICENSE("GPL");
  76. MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  77. MODULE_DESCRIPTION("MTD chip driver for ROM chips");