dc21285.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. raw_spin_lock_irqsave(&nw_gpio_lock, flags);
  36. nw_cpld_modify(CPLD_FLASH_WR_ENABLE, CPLD_FLASH_WR_ENABLE);
  37. raw_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 const char * const probes[] = { "RedBoot", "cmdlinepart", NULL };
  129. static int __init init_dc21285(void)
  130. {
  131. /* Determine bankwidth */
  132. switch (*CSR_SA110_CNTL & (3<<14)) {
  133. case SA110_CNTL_ROMWIDTH_8:
  134. dc21285_map.bankwidth = 1;
  135. dc21285_map.read = dc21285_read8;
  136. dc21285_map.write = dc21285_write8;
  137. dc21285_map.copy_to = dc21285_copy_to_8;
  138. break;
  139. case SA110_CNTL_ROMWIDTH_16:
  140. dc21285_map.bankwidth = 2;
  141. dc21285_map.read = dc21285_read16;
  142. dc21285_map.write = dc21285_write16;
  143. dc21285_map.copy_to = dc21285_copy_to_16;
  144. break;
  145. case SA110_CNTL_ROMWIDTH_32:
  146. dc21285_map.bankwidth = 4;
  147. dc21285_map.read = dc21285_read32;
  148. dc21285_map.write = dc21285_write32;
  149. dc21285_map.copy_to = dc21285_copy_to_32;
  150. break;
  151. default:
  152. printk (KERN_ERR "DC21285 flash: undefined bankwidth\n");
  153. return -ENXIO;
  154. }
  155. printk (KERN_NOTICE "DC21285 flash support (%d-bit bankwidth)\n",
  156. dc21285_map.bankwidth*8);
  157. /* Let's map the flash area */
  158. dc21285_map.virt = ioremap(DC21285_FLASH, 16*1024*1024);
  159. if (!dc21285_map.virt) {
  160. printk("Failed to ioremap\n");
  161. return -EIO;
  162. }
  163. if (machine_is_ebsa285()) {
  164. dc21285_mtd = do_map_probe("cfi_probe", &dc21285_map);
  165. } else {
  166. dc21285_mtd = do_map_probe("jedec_probe", &dc21285_map);
  167. }
  168. if (!dc21285_mtd) {
  169. iounmap(dc21285_map.virt);
  170. return -ENXIO;
  171. }
  172. dc21285_mtd->owner = THIS_MODULE;
  173. mtd_device_parse_register(dc21285_mtd, probes, NULL, NULL, 0);
  174. if(machine_is_ebsa285()) {
  175. /*
  176. * Flash timing is determined with bits 19-16 of the
  177. * CSR_SA110_CNTL. The value is the number of wait cycles, or
  178. * 0 for 16 cycles (the default). Cycles are 20 ns.
  179. * Here we use 7 for 140 ns flash chips.
  180. */
  181. /* access time */
  182. *CSR_SA110_CNTL = ((*CSR_SA110_CNTL & ~0x000f0000) | (7 << 16));
  183. /* burst time */
  184. *CSR_SA110_CNTL = ((*CSR_SA110_CNTL & ~0x00f00000) | (7 << 20));
  185. /* tristate time */
  186. *CSR_SA110_CNTL = ((*CSR_SA110_CNTL & ~0x0f000000) | (7 << 24));
  187. }
  188. return 0;
  189. }
  190. static void __exit cleanup_dc21285(void)
  191. {
  192. mtd_device_unregister(dc21285_mtd);
  193. map_destroy(dc21285_mtd);
  194. iounmap(dc21285_map.virt);
  195. }
  196. module_init(init_dc21285);
  197. module_exit(cleanup_dc21285);
  198. MODULE_LICENSE("GPL");
  199. MODULE_AUTHOR("Nicolas Pitre <nico@fluxnic.net>");
  200. MODULE_DESCRIPTION("MTD map driver for DC21285 boards");