dc21285.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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/module.h>
  11. #include <linux/types.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/delay.h>
  15. #include <linux/slab.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. from += 4;
  100. to += 4;
  101. len -= 4;
  102. }
  103. }
  104. static void dc21285_copy_to_16(struct map_info *map, unsigned long to, const void *from, ssize_t len)
  105. {
  106. while (len > 0) {
  107. map_word d;
  108. d.x[0] = *((uint16_t*)from);
  109. dc21285_write16(map, d, to);
  110. from += 2;
  111. to += 2;
  112. len -= 2;
  113. }
  114. }
  115. static void dc21285_copy_to_8(struct map_info *map, unsigned long to, const void *from, ssize_t len)
  116. {
  117. map_word d;
  118. d.x[0] = *((uint8_t*)from);
  119. dc21285_write8(map, d, to);
  120. from++;
  121. to++;
  122. len--;
  123. }
  124. static struct map_info dc21285_map = {
  125. .name = "DC21285 flash",
  126. .phys = NO_XIP,
  127. .size = 16*1024*1024,
  128. .copy_from = dc21285_copy_from,
  129. };
  130. /* Partition stuff */
  131. #ifdef CONFIG_MTD_PARTITIONS
  132. static struct mtd_partition *dc21285_parts;
  133. static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
  134. #endif
  135. static int __init init_dc21285(void)
  136. {
  137. #ifdef CONFIG_MTD_PARTITIONS
  138. int nrparts;
  139. #endif
  140. /* Determine bankwidth */
  141. switch (*CSR_SA110_CNTL & (3<<14)) {
  142. case SA110_CNTL_ROMWIDTH_8:
  143. dc21285_map.bankwidth = 1;
  144. dc21285_map.read = dc21285_read8;
  145. dc21285_map.write = dc21285_write8;
  146. dc21285_map.copy_to = dc21285_copy_to_8;
  147. break;
  148. case SA110_CNTL_ROMWIDTH_16:
  149. dc21285_map.bankwidth = 2;
  150. dc21285_map.read = dc21285_read16;
  151. dc21285_map.write = dc21285_write16;
  152. dc21285_map.copy_to = dc21285_copy_to_16;
  153. break;
  154. case SA110_CNTL_ROMWIDTH_32:
  155. dc21285_map.bankwidth = 4;
  156. dc21285_map.read = dc21285_read32;
  157. dc21285_map.write = dc21285_write32;
  158. dc21285_map.copy_to = dc21285_copy_to_32;
  159. break;
  160. default:
  161. printk (KERN_ERR "DC21285 flash: undefined bankwidth\n");
  162. return -ENXIO;
  163. }
  164. printk (KERN_NOTICE "DC21285 flash support (%d-bit bankwidth)\n",
  165. dc21285_map.bankwidth*8);
  166. /* Let's map the flash area */
  167. dc21285_map.virt = ioremap(DC21285_FLASH, 16*1024*1024);
  168. if (!dc21285_map.virt) {
  169. printk("Failed to ioremap\n");
  170. return -EIO;
  171. }
  172. if (machine_is_ebsa285()) {
  173. dc21285_mtd = do_map_probe("cfi_probe", &dc21285_map);
  174. } else {
  175. dc21285_mtd = do_map_probe("jedec_probe", &dc21285_map);
  176. }
  177. if (!dc21285_mtd) {
  178. iounmap(dc21285_map.virt);
  179. return -ENXIO;
  180. }
  181. dc21285_mtd->owner = THIS_MODULE;
  182. #ifdef CONFIG_MTD_PARTITIONS
  183. nrparts = parse_mtd_partitions(dc21285_mtd, probes, &dc21285_parts, 0);
  184. if (nrparts > 0)
  185. add_mtd_partitions(dc21285_mtd, dc21285_parts, nrparts);
  186. else
  187. #endif
  188. add_mtd_device(dc21285_mtd);
  189. if(machine_is_ebsa285()) {
  190. /*
  191. * Flash timing is determined with bits 19-16 of the
  192. * CSR_SA110_CNTL. The value is the number of wait cycles, or
  193. * 0 for 16 cycles (the default). Cycles are 20 ns.
  194. * Here we use 7 for 140 ns flash chips.
  195. */
  196. /* access time */
  197. *CSR_SA110_CNTL = ((*CSR_SA110_CNTL & ~0x000f0000) | (7 << 16));
  198. /* burst time */
  199. *CSR_SA110_CNTL = ((*CSR_SA110_CNTL & ~0x00f00000) | (7 << 20));
  200. /* tristate time */
  201. *CSR_SA110_CNTL = ((*CSR_SA110_CNTL & ~0x0f000000) | (7 << 24));
  202. }
  203. return 0;
  204. }
  205. static void __exit cleanup_dc21285(void)
  206. {
  207. #ifdef CONFIG_MTD_PARTITIONS
  208. if (dc21285_parts) {
  209. del_mtd_partitions(dc21285_mtd);
  210. kfree(dc21285_parts);
  211. } else
  212. #endif
  213. del_mtd_device(dc21285_mtd);
  214. map_destroy(dc21285_mtd);
  215. iounmap(dc21285_map.virt);
  216. }
  217. module_init(init_dc21285);
  218. module_exit(cleanup_dc21285);
  219. MODULE_LICENSE("GPL");
  220. MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>");
  221. MODULE_DESCRIPTION("MTD map driver for DC21285 boards");