dc21285.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * MTD map driver for flash on the DC21285 (the StrongARM-110 companion chip)
  3. *
  4. * (C) 2000 Nicolas Pitre <nico@cam.org>
  5. *
  6. * This code is GPL
  7. */
  8. #include <linux/module.h>
  9. #include <linux/types.h>
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/delay.h>
  13. #include <linux/slab.h>
  14. #include <linux/mtd/mtd.h>
  15. #include <linux/mtd/map.h>
  16. #include <linux/mtd/partitions.h>
  17. #include <asm/io.h>
  18. #include <asm/hardware/dec21285.h>
  19. #include <asm/mach-types.h>
  20. static struct mtd_info *dc21285_mtd;
  21. #ifdef CONFIG_ARCH_NETWINDER
  22. /*
  23. * This is really ugly, but it seams to be the only
  24. * realiable way to do it, as the cpld state machine
  25. * is unpredictible. So we have a 25us penalty per
  26. * write access.
  27. */
  28. static void nw_en_write(void)
  29. {
  30. extern spinlock_t gpio_lock;
  31. unsigned long flags;
  32. /*
  33. * we want to write a bit pattern XXX1 to Xilinx to enable
  34. * the write gate, which will be open for about the next 2ms.
  35. */
  36. spin_lock_irqsave(&gpio_lock, flags);
  37. cpld_modify(1, 1);
  38. spin_unlock_irqrestore(&gpio_lock, flags);
  39. /*
  40. * let the ISA bus to catch on...
  41. */
  42. udelay(25);
  43. }
  44. #else
  45. #define nw_en_write() do { } while (0)
  46. #endif
  47. static map_word dc21285_read8(struct map_info *map, unsigned long ofs)
  48. {
  49. map_word val;
  50. val.x[0] = *(uint8_t*)(map->virt + ofs);
  51. return val;
  52. }
  53. static map_word dc21285_read16(struct map_info *map, unsigned long ofs)
  54. {
  55. map_word val;
  56. val.x[0] = *(uint16_t*)(map->virt + ofs);
  57. return val;
  58. }
  59. static map_word dc21285_read32(struct map_info *map, unsigned long ofs)
  60. {
  61. map_word val;
  62. val.x[0] = *(uint32_t*)(map->virt + ofs);
  63. return val;
  64. }
  65. static void dc21285_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
  66. {
  67. memcpy(to, (void*)(map->virt + from), len);
  68. }
  69. static void dc21285_write8(struct map_info *map, const map_word d, unsigned long adr)
  70. {
  71. if (machine_is_netwinder())
  72. nw_en_write();
  73. *CSR_ROMWRITEREG = adr & 3;
  74. adr &= ~3;
  75. *(uint8_t*)(map->virt + adr) = d.x[0];
  76. }
  77. static void dc21285_write16(struct map_info *map, const map_word d, unsigned long adr)
  78. {
  79. if (machine_is_netwinder())
  80. nw_en_write();
  81. *CSR_ROMWRITEREG = adr & 3;
  82. adr &= ~3;
  83. *(uint16_t*)(map->virt + adr) = d.x[0];
  84. }
  85. static void dc21285_write32(struct map_info *map, const map_word d, unsigned long adr)
  86. {
  87. if (machine_is_netwinder())
  88. nw_en_write();
  89. *(uint32_t*)(map->virt + adr) = d.x[0];
  90. }
  91. static void dc21285_copy_to_32(struct map_info *map, unsigned long to, const void *from, ssize_t len)
  92. {
  93. while (len > 0) {
  94. map_word d;
  95. d.x[0] = *((uint32_t*)from);
  96. dc21285_write32(map, d, to);
  97. from += 4;
  98. to += 4;
  99. len -= 4;
  100. }
  101. }
  102. static void dc21285_copy_to_16(struct map_info *map, unsigned long to, const void *from, ssize_t len)
  103. {
  104. while (len > 0) {
  105. map_word d;
  106. d.x[0] = *((uint16_t*)from);
  107. dc21285_write16(map, d, to);
  108. from += 2;
  109. to += 2;
  110. len -= 2;
  111. }
  112. }
  113. static void dc21285_copy_to_8(struct map_info *map, unsigned long to, const void *from, ssize_t len)
  114. {
  115. map_word d;
  116. d.x[0] = *((uint8_t*)from);
  117. dc21285_write8(map, d, to);
  118. from++;
  119. to++;
  120. len--;
  121. }
  122. static struct map_info dc21285_map = {
  123. .name = "DC21285 flash",
  124. .phys = NO_XIP,
  125. .size = 16*1024*1024,
  126. .copy_from = dc21285_copy_from,
  127. };
  128. /* Partition stuff */
  129. #ifdef CONFIG_MTD_PARTITIONS
  130. static struct mtd_partition *dc21285_parts;
  131. static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
  132. #endif
  133. static int __init init_dc21285(void)
  134. {
  135. #ifdef CONFIG_MTD_PARTITIONS
  136. int nrparts;
  137. #endif
  138. /* Determine bankwidth */
  139. switch (*CSR_SA110_CNTL & (3<<14)) {
  140. case SA110_CNTL_ROMWIDTH_8:
  141. dc21285_map.bankwidth = 1;
  142. dc21285_map.read = dc21285_read8;
  143. dc21285_map.write = dc21285_write8;
  144. dc21285_map.copy_to = dc21285_copy_to_8;
  145. break;
  146. case SA110_CNTL_ROMWIDTH_16:
  147. dc21285_map.bankwidth = 2;
  148. dc21285_map.read = dc21285_read16;
  149. dc21285_map.write = dc21285_write16;
  150. dc21285_map.copy_to = dc21285_copy_to_16;
  151. break;
  152. case SA110_CNTL_ROMWIDTH_32:
  153. dc21285_map.bankwidth = 4;
  154. dc21285_map.read = dc21285_read32;
  155. dc21285_map.write = dc21285_write32;
  156. dc21285_map.copy_to = dc21285_copy_to_32;
  157. break;
  158. default:
  159. printk (KERN_ERR "DC21285 flash: undefined bankwidth\n");
  160. return -ENXIO;
  161. }
  162. printk (KERN_NOTICE "DC21285 flash support (%d-bit bankwidth)\n",
  163. dc21285_map.bankwidth*8);
  164. /* Let's map the flash area */
  165. dc21285_map.virt = ioremap(DC21285_FLASH, 16*1024*1024);
  166. if (!dc21285_map.virt) {
  167. printk("Failed to ioremap\n");
  168. return -EIO;
  169. }
  170. if (machine_is_ebsa285()) {
  171. dc21285_mtd = do_map_probe("cfi_probe", &dc21285_map);
  172. } else {
  173. dc21285_mtd = do_map_probe("jedec_probe", &dc21285_map);
  174. }
  175. if (!dc21285_mtd) {
  176. iounmap(dc21285_map.virt);
  177. return -ENXIO;
  178. }
  179. dc21285_mtd->owner = THIS_MODULE;
  180. #ifdef CONFIG_MTD_PARTITIONS
  181. nrparts = parse_mtd_partitions(dc21285_mtd, probes, &dc21285_parts, 0);
  182. if (nrparts > 0)
  183. add_mtd_partitions(dc21285_mtd, dc21285_parts, nrparts);
  184. else
  185. #endif
  186. add_mtd_device(dc21285_mtd);
  187. if(machine_is_ebsa285()) {
  188. /*
  189. * Flash timing is determined with bits 19-16 of the
  190. * CSR_SA110_CNTL. The value is the number of wait cycles, or
  191. * 0 for 16 cycles (the default). Cycles are 20 ns.
  192. * Here we use 7 for 140 ns flash chips.
  193. */
  194. /* access time */
  195. *CSR_SA110_CNTL = ((*CSR_SA110_CNTL & ~0x000f0000) | (7 << 16));
  196. /* burst time */
  197. *CSR_SA110_CNTL = ((*CSR_SA110_CNTL & ~0x00f00000) | (7 << 20));
  198. /* tristate time */
  199. *CSR_SA110_CNTL = ((*CSR_SA110_CNTL & ~0x0f000000) | (7 << 24));
  200. }
  201. return 0;
  202. }
  203. static void __exit cleanup_dc21285(void)
  204. {
  205. #ifdef CONFIG_MTD_PARTITIONS
  206. if (dc21285_parts) {
  207. del_mtd_partitions(dc21285_mtd);
  208. kfree(dc21285_parts);
  209. } else
  210. #endif
  211. del_mtd_device(dc21285_mtd);
  212. map_destroy(dc21285_mtd);
  213. iounmap(dc21285_map.virt);
  214. }
  215. module_init(init_dc21285);
  216. module_exit(cleanup_dc21285);
  217. MODULE_LICENSE("GPL");
  218. MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>");
  219. MODULE_DESCRIPTION("MTD map driver for DC21285 boards");