dc21285.c 5.8 KB

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