octagon-5066.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /* ######################################################################
  2. Octagon 5066 MTD Driver.
  3. The Octagon 5066 is a SBC based on AMD's 586-WB running at 133 MHZ. It
  4. comes with a builtin AMD 29F016 flash chip and a socketed EEPROM that
  5. is replacable by flash. Both units are mapped through a multiplexer
  6. into a 32k memory window at 0xe8000. The control register for the
  7. multiplexing unit is located at IO 0x208 with a bit map of
  8. 0-5 Page Selection in 32k increments
  9. 6-7 Device selection:
  10. 00 SSD off
  11. 01 SSD 0 (Socket)
  12. 10 SSD 1 (Flash chip)
  13. 11 undefined
  14. On each SSD, the first 128k is reserved for use by the bios
  15. (actually it IS the bios..) This only matters if you are booting off the
  16. flash, you must not put a file system starting there.
  17. The driver tries to do a detection algorithm to guess what sort of devices
  18. are plugged into the sockets.
  19. ##################################################################### */
  20. #include <linux/module.h>
  21. #include <linux/ioport.h>
  22. #include <linux/init.h>
  23. #include <asm/io.h>
  24. #include <linux/mtd/map.h>
  25. #include <linux/mtd/mtd.h>
  26. #define WINDOW_START 0xe8000
  27. #define WINDOW_LENGTH 0x8000
  28. #define WINDOW_SHIFT 27
  29. #define WINDOW_MASK 0x7FFF
  30. #define PAGE_IO 0x208
  31. static volatile char page_n_dev = 0;
  32. static unsigned long iomapadr;
  33. static DEFINE_SPINLOCK(oct5066_spin);
  34. /*
  35. * We use map_priv_1 to identify which device we are.
  36. */
  37. static void __oct5066_page(struct map_info *map, __u8 byte)
  38. {
  39. outb(byte,PAGE_IO);
  40. page_n_dev = byte;
  41. }
  42. static inline void oct5066_page(struct map_info *map, unsigned long ofs)
  43. {
  44. __u8 byte = map->map_priv_1 | (ofs >> WINDOW_SHIFT);
  45. if (page_n_dev != byte)
  46. __oct5066_page(map, byte);
  47. }
  48. static map_word oct5066_read8(struct map_info *map, unsigned long ofs)
  49. {
  50. map_word ret;
  51. spin_lock(&oct5066_spin);
  52. oct5066_page(map, ofs);
  53. ret.x[0] = readb(iomapadr + (ofs & WINDOW_MASK));
  54. spin_unlock(&oct5066_spin);
  55. return ret;
  56. }
  57. static void oct5066_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
  58. {
  59. while(len) {
  60. unsigned long thislen = len;
  61. if (len > (WINDOW_LENGTH - (from & WINDOW_MASK)))
  62. thislen = WINDOW_LENGTH-(from & WINDOW_MASK);
  63. spin_lock(&oct5066_spin);
  64. oct5066_page(map, from);
  65. memcpy_fromio(to, iomapadr + from, thislen);
  66. spin_unlock(&oct5066_spin);
  67. to += thislen;
  68. from += thislen;
  69. len -= thislen;
  70. }
  71. }
  72. static void oct5066_write8(struct map_info *map, map_word d, unsigned long adr)
  73. {
  74. spin_lock(&oct5066_spin);
  75. oct5066_page(map, adr);
  76. writeb(d.x[0], iomapadr + (adr & WINDOW_MASK));
  77. spin_unlock(&oct5066_spin);
  78. }
  79. static void oct5066_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
  80. {
  81. while(len) {
  82. unsigned long thislen = len;
  83. if (len > (WINDOW_LENGTH - (to & WINDOW_MASK)))
  84. thislen = WINDOW_LENGTH-(to & WINDOW_MASK);
  85. spin_lock(&oct5066_spin);
  86. oct5066_page(map, to);
  87. memcpy_toio(iomapadr + to, from, thislen);
  88. spin_unlock(&oct5066_spin);
  89. to += thislen;
  90. from += thislen;
  91. len -= thislen;
  92. }
  93. }
  94. static struct map_info oct5066_map[2] = {
  95. {
  96. .name = "Octagon 5066 Socket",
  97. .phys = NO_XIP,
  98. .size = 512 * 1024,
  99. .bankwidth = 1,
  100. .read = oct5066_read8,
  101. .copy_from = oct5066_copy_from,
  102. .write = oct5066_write8,
  103. .copy_to = oct5066_copy_to,
  104. .map_priv_1 = 1<<6
  105. },
  106. {
  107. .name = "Octagon 5066 Internal Flash",
  108. .phys = NO_XIP,
  109. .size = 2 * 1024 * 1024,
  110. .bankwidth = 1,
  111. .read = oct5066_read8,
  112. .copy_from = oct5066_copy_from,
  113. .write = oct5066_write8,
  114. .copy_to = oct5066_copy_to,
  115. .map_priv_1 = 2<<6
  116. }
  117. };
  118. static struct mtd_info *oct5066_mtd[2] = {NULL, NULL};
  119. // OctProbe - Sense if this is an octagon card
  120. // ---------------------------------------------------------------------
  121. /* Perform a simple validity test, we map the window select SSD0 and
  122. change pages while monitoring the window. A change in the window,
  123. controlled by the PAGE_IO port is a functioning 5066 board. This will
  124. fail if the thing in the socket is set to a uniform value. */
  125. static int __init OctProbe(void)
  126. {
  127. unsigned int Base = (1 << 6);
  128. unsigned long I;
  129. unsigned long Values[10];
  130. for (I = 0; I != 20; I++)
  131. {
  132. outb(Base + (I%10),PAGE_IO);
  133. if (I < 10)
  134. {
  135. // Record the value and check for uniqueness
  136. Values[I%10] = readl(iomapadr);
  137. if (I > 0 && Values[I%10] == Values[0])
  138. return -EAGAIN;
  139. }
  140. else
  141. {
  142. // Make sure we get the same values on the second pass
  143. if (Values[I%10] != readl(iomapadr))
  144. return -EAGAIN;
  145. }
  146. }
  147. return 0;
  148. }
  149. void cleanup_oct5066(void)
  150. {
  151. int i;
  152. for (i=0; i<2; i++) {
  153. if (oct5066_mtd[i]) {
  154. mtd_device_unregister(oct5066_mtd[i]);
  155. map_destroy(oct5066_mtd[i]);
  156. }
  157. }
  158. iounmap((void *)iomapadr);
  159. release_region(PAGE_IO, 1);
  160. }
  161. static int __init init_oct5066(void)
  162. {
  163. int i;
  164. int ret = 0;
  165. // Do an autoprobe sequence
  166. if (!request_region(PAGE_IO,1,"Octagon SSD")) {
  167. printk(KERN_NOTICE "5066: Page Register in Use\n");
  168. return -EAGAIN;
  169. }
  170. iomapadr = (unsigned long)ioremap(WINDOW_START, WINDOW_LENGTH);
  171. if (!iomapadr) {
  172. printk(KERN_NOTICE "Failed to ioremap memory region\n");
  173. ret = -EIO;
  174. goto out_rel;
  175. }
  176. if (OctProbe() != 0) {
  177. printk(KERN_NOTICE "5066: Octagon Probe Failed, is this an Octagon 5066 SBC?\n");
  178. iounmap((void *)iomapadr);
  179. ret = -EAGAIN;
  180. goto out_unmap;
  181. }
  182. // Print out our little header..
  183. printk("Octagon 5066 SSD IO:0x%x MEM:0x%x-0x%x\n",PAGE_IO,WINDOW_START,
  184. WINDOW_START+WINDOW_LENGTH);
  185. for (i=0; i<2; i++) {
  186. oct5066_mtd[i] = do_map_probe("cfi_probe", &oct5066_map[i]);
  187. if (!oct5066_mtd[i])
  188. oct5066_mtd[i] = do_map_probe("jedec", &oct5066_map[i]);
  189. if (!oct5066_mtd[i])
  190. oct5066_mtd[i] = do_map_probe("map_ram", &oct5066_map[i]);
  191. if (!oct5066_mtd[i])
  192. oct5066_mtd[i] = do_map_probe("map_rom", &oct5066_map[i]);
  193. if (oct5066_mtd[i]) {
  194. oct5066_mtd[i]->owner = THIS_MODULE;
  195. mtd_device_register(oct5066_mtd[i], NULL, 0);
  196. }
  197. }
  198. if (!oct5066_mtd[0] && !oct5066_mtd[1]) {
  199. cleanup_oct5066();
  200. return -ENXIO;
  201. }
  202. return 0;
  203. out_unmap:
  204. iounmap((void *)iomapadr);
  205. out_rel:
  206. release_region(PAGE_IO, 1);
  207. return ret;
  208. }
  209. module_init(init_oct5066);
  210. module_exit(cleanup_oct5066);
  211. MODULE_LICENSE("GPL");
  212. MODULE_AUTHOR("Jason Gunthorpe <jgg@deltatee.com>, David Woodhouse <dwmw2@infradead.org>");
  213. MODULE_DESCRIPTION("MTD map driver for Octagon 5066 Single Board Computer");