cdb89712.c 5.5 KB

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