cdb89712.c 5.8 KB

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