dc21285.c 5.9 KB

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