dc21285.c 5.6 KB

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