cdb89712.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * Flash on Cirrus CDB89712
  3. *
  4. */
  5. #include <linux/module.h>
  6. #include <linux/types.h>
  7. #include <linux/kernel.h>
  8. #include <linux/ioport.h>
  9. #include <linux/init.h>
  10. #include <asm/io.h>
  11. #include <mach/hardware.h>
  12. #include <linux/mtd/mtd.h>
  13. #include <linux/mtd/map.h>
  14. #include <linux/mtd/partitions.h>
  15. static struct mtd_info *flash_mtd;
  16. struct map_info cdb89712_flash_map = {
  17. .name = "flash",
  18. .size = FLASH_SIZE,
  19. .bankwidth = FLASH_WIDTH,
  20. .phys = FLASH_START,
  21. };
  22. struct resource cdb89712_flash_resource = {
  23. .name = "Flash",
  24. .start = FLASH_START,
  25. .end = FLASH_START + FLASH_SIZE - 1,
  26. .flags = IORESOURCE_IO | IORESOURCE_BUSY,
  27. };
  28. static int __init init_cdb89712_flash (void)
  29. {
  30. int err;
  31. if (request_resource (&ioport_resource, &cdb89712_flash_resource)) {
  32. printk(KERN_NOTICE "Failed to reserve Cdb89712 FLASH space\n");
  33. err = -EBUSY;
  34. goto out;
  35. }
  36. cdb89712_flash_map.virt = ioremap(FLASH_START, FLASH_SIZE);
  37. if (!cdb89712_flash_map.virt) {
  38. printk(KERN_NOTICE "Failed to ioremap Cdb89712 FLASH space\n");
  39. err = -EIO;
  40. goto out_resource;
  41. }
  42. simple_map_init(&cdb89712_flash_map);
  43. flash_mtd = do_map_probe("cfi_probe", &cdb89712_flash_map);
  44. if (!flash_mtd) {
  45. flash_mtd = do_map_probe("map_rom", &cdb89712_flash_map);
  46. if (flash_mtd)
  47. flash_mtd->erasesize = 0x10000;
  48. }
  49. if (!flash_mtd) {
  50. printk("FLASH probe failed\n");
  51. err = -ENXIO;
  52. goto out_ioremap;
  53. }
  54. flash_mtd->owner = THIS_MODULE;
  55. if (add_mtd_device(flash_mtd)) {
  56. printk("FLASH device addition failed\n");
  57. err = -ENOMEM;
  58. goto out_probe;
  59. }
  60. return 0;
  61. out_probe:
  62. map_destroy(flash_mtd);
  63. flash_mtd = 0;
  64. out_ioremap:
  65. iounmap((void *)cdb89712_flash_map.virt);
  66. out_resource:
  67. release_resource (&cdb89712_flash_resource);
  68. out:
  69. return err;
  70. }
  71. static struct mtd_info *sram_mtd;
  72. struct map_info cdb89712_sram_map = {
  73. .name = "SRAM",
  74. .size = SRAM_SIZE,
  75. .bankwidth = SRAM_WIDTH,
  76. .phys = SRAM_START,
  77. };
  78. struct resource cdb89712_sram_resource = {
  79. .name = "SRAM",
  80. .start = SRAM_START,
  81. .end = SRAM_START + SRAM_SIZE - 1,
  82. .flags = IORESOURCE_IO | IORESOURCE_BUSY,
  83. };
  84. static int __init init_cdb89712_sram (void)
  85. {
  86. int err;
  87. if (request_resource (&ioport_resource, &cdb89712_sram_resource)) {
  88. printk(KERN_NOTICE "Failed to reserve Cdb89712 SRAM space\n");
  89. err = -EBUSY;
  90. goto out;
  91. }
  92. cdb89712_sram_map.virt = ioremap(SRAM_START, SRAM_SIZE);
  93. if (!cdb89712_sram_map.virt) {
  94. printk(KERN_NOTICE "Failed to ioremap Cdb89712 SRAM space\n");
  95. err = -EIO;
  96. goto out_resource;
  97. }
  98. simple_map_init(&cdb89712_sram_map);
  99. sram_mtd = do_map_probe("map_ram", &cdb89712_sram_map);
  100. if (!sram_mtd) {
  101. printk("SRAM probe failed\n");
  102. err = -ENXIO;
  103. goto out_ioremap;
  104. }
  105. sram_mtd->owner = THIS_MODULE;
  106. sram_mtd->erasesize = 16;
  107. if (add_mtd_device(sram_mtd)) {
  108. printk("SRAM device addition failed\n");
  109. err = -ENOMEM;
  110. goto out_probe;
  111. }
  112. return 0;
  113. out_probe:
  114. map_destroy(sram_mtd);
  115. sram_mtd = 0;
  116. out_ioremap:
  117. iounmap((void *)cdb89712_sram_map.virt);
  118. out_resource:
  119. release_resource (&cdb89712_sram_resource);
  120. out:
  121. return err;
  122. }
  123. static struct mtd_info *bootrom_mtd;
  124. struct map_info cdb89712_bootrom_map = {
  125. .name = "BootROM",
  126. .size = BOOTROM_SIZE,
  127. .bankwidth = BOOTROM_WIDTH,
  128. .phys = BOOTROM_START,
  129. };
  130. struct resource cdb89712_bootrom_resource = {
  131. .name = "BootROM",
  132. .start = BOOTROM_START,
  133. .end = BOOTROM_START + BOOTROM_SIZE - 1,
  134. .flags = IORESOURCE_IO | IORESOURCE_BUSY,
  135. };
  136. static int __init init_cdb89712_bootrom (void)
  137. {
  138. int err;
  139. if (request_resource (&ioport_resource, &cdb89712_bootrom_resource)) {
  140. printk(KERN_NOTICE "Failed to reserve Cdb89712 BOOTROM space\n");
  141. err = -EBUSY;
  142. goto out;
  143. }
  144. cdb89712_bootrom_map.virt = ioremap(BOOTROM_START, BOOTROM_SIZE);
  145. if (!cdb89712_bootrom_map.virt) {
  146. printk(KERN_NOTICE "Failed to ioremap Cdb89712 BootROM space\n");
  147. err = -EIO;
  148. goto out_resource;
  149. }
  150. simple_map_init(&cdb89712_bootrom_map);
  151. bootrom_mtd = do_map_probe("map_rom", &cdb89712_bootrom_map);
  152. if (!bootrom_mtd) {
  153. printk("BootROM probe failed\n");
  154. err = -ENXIO;
  155. goto out_ioremap;
  156. }
  157. bootrom_mtd->owner = THIS_MODULE;
  158. bootrom_mtd->erasesize = 0x10000;
  159. if (add_mtd_device(bootrom_mtd)) {
  160. printk("BootROM device addition failed\n");
  161. err = -ENOMEM;
  162. goto out_probe;
  163. }
  164. return 0;
  165. out_probe:
  166. map_destroy(bootrom_mtd);
  167. bootrom_mtd = 0;
  168. out_ioremap:
  169. iounmap((void *)cdb89712_bootrom_map.virt);
  170. out_resource:
  171. release_resource (&cdb89712_bootrom_resource);
  172. out:
  173. return err;
  174. }
  175. static int __init init_cdb89712_maps(void)
  176. {
  177. printk(KERN_INFO "Cirrus CDB89712 MTD mappings:\n Flash 0x%x at 0x%x\n SRAM 0x%x at 0x%x\n BootROM 0x%x at 0x%x\n",
  178. FLASH_SIZE, FLASH_START, SRAM_SIZE, SRAM_START, BOOTROM_SIZE, BOOTROM_START);
  179. init_cdb89712_flash();
  180. init_cdb89712_sram();
  181. init_cdb89712_bootrom();
  182. return 0;
  183. }
  184. static void __exit cleanup_cdb89712_maps(void)
  185. {
  186. if (sram_mtd) {
  187. del_mtd_device(sram_mtd);
  188. map_destroy(sram_mtd);
  189. iounmap((void *)cdb89712_sram_map.virt);
  190. release_resource (&cdb89712_sram_resource);
  191. }
  192. if (flash_mtd) {
  193. del_mtd_device(flash_mtd);
  194. map_destroy(flash_mtd);
  195. iounmap((void *)cdb89712_flash_map.virt);
  196. release_resource (&cdb89712_flash_resource);
  197. }
  198. if (bootrom_mtd) {
  199. del_mtd_device(bootrom_mtd);
  200. map_destroy(bootrom_mtd);
  201. iounmap((void *)cdb89712_bootrom_map.virt);
  202. release_resource (&cdb89712_bootrom_resource);
  203. }
  204. }
  205. module_init(init_cdb89712_maps);
  206. module_exit(cleanup_cdb89712_maps);
  207. MODULE_AUTHOR("Ray L");
  208. MODULE_DESCRIPTION("ARM CDB89712 map driver");
  209. MODULE_LICENSE("GPL");