mcfne.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /****************************************************************************/
  2. /*
  3. * mcfne.h -- NE2000 in ColdFire eval boards.
  4. *
  5. * (C) Copyright 1999-2000, Greg Ungerer (gerg@snapgear.com)
  6. * (C) Copyright 2000, Lineo (www.lineo.com)
  7. * (C) Copyright 2001, SnapGear (www.snapgear.com)
  8. *
  9. * 19990409 David W. Miller Converted from m5206ne.h for 5307 eval board
  10. *
  11. * Hacked support for m5206e Cadre III evaluation board
  12. * Fred Stevens (fred.stevens@pemstar.com) 13 April 1999
  13. */
  14. /****************************************************************************/
  15. #ifndef mcfne_h
  16. #define mcfne_h
  17. /****************************************************************************/
  18. #include <linux/config.h>
  19. /*
  20. * Support for NE2000 clones devices in ColdFire based boards.
  21. * Not all boards address these parts the same way, some use a
  22. * direct addressing method, others use a side-band address space
  23. * to access odd address registers, some require byte swapping
  24. * others do not.
  25. */
  26. #define BSWAP(w) (((w) << 8) | ((w) >> 8))
  27. #define RSWAP(w) (w)
  28. /*
  29. * Define the basic hardware resources of NE2000 boards.
  30. */
  31. #if defined(CONFIG_M5206) && defined(CONFIG_ARNEWSH)
  32. #define NE2000_ADDR 0x40000300
  33. #define NE2000_ODDOFFSET 0x00010000
  34. #define NE2000_IRQ_VECTOR 0xf0
  35. #define NE2000_IRQ_PRIORITY 2
  36. #define NE2000_IRQ_LEVEL 4
  37. #define NE2000_BYTE volatile unsigned short
  38. #endif
  39. #if defined(CONFIG_M5206e) && defined(CONFIG_MOTOROLA)
  40. #define NE2000_ADDR 0x40000300
  41. #define NE2000_ODDOFFSET 0x00010000
  42. #define NE2000_IRQ_VECTOR 0x1c
  43. #define NE2000_IRQ_PRIORITY 2
  44. #define NE2000_IRQ_LEVEL 4
  45. #define NE2000_BYTE volatile unsigned short
  46. #endif
  47. #if defined(CONFIG_M5206e) && defined(CONFIG_NETtel)
  48. #define NE2000_ADDR 0x30000300
  49. #define NE2000_IRQ_VECTOR 25
  50. #define NE2000_IRQ_PRIORITY 1
  51. #define NE2000_IRQ_LEVEL 3
  52. #define NE2000_BYTE volatile unsigned char
  53. #endif
  54. #if defined(CONFIG_M5206e) && defined(CONFIG_CFV240)
  55. #define NE2000_ADDR 0x40010000
  56. #define NE2000_ADDR1 0x40010001
  57. #define NE2000_ODDOFFSET 0x00000000
  58. #define NE2000_IRQ 1
  59. #define NE2000_IRQ_VECTOR 0x19
  60. #define NE2000_IRQ_PRIORITY 2
  61. #define NE2000_IRQ_LEVEL 1
  62. #define NE2000_BYTE volatile unsigned char
  63. #endif
  64. #if defined(CONFIG_M5307) && defined(CONFIG_MOTOROLA)
  65. #define NE2000_ADDR 0x40000300
  66. #define NE2000_ODDOFFSET 0x00010000
  67. #define NE2000_IRQ_VECTOR 0x1b
  68. #define NE2000_BYTE volatile unsigned short
  69. #endif
  70. #if defined(CONFIG_M5272) && defined(CONFIG_NETtel)
  71. #define NE2000_ADDR 0x30600300
  72. #define NE2000_ODDOFFSET 0x00008000
  73. #define NE2000_IRQ_VECTOR 67
  74. #undef BSWAP
  75. #define BSWAP(w) (w)
  76. #define NE2000_BYTE volatile unsigned short
  77. #undef RSWAP
  78. #define RSWAP(w) (((w) << 8) | ((w) >> 8))
  79. #endif
  80. #if defined(CONFIG_M5307) && defined(CONFIG_NETtel)
  81. #define NE2000_ADDR0 0x30600300
  82. #define NE2000_ADDR1 0x30800300
  83. #define NE2000_ODDOFFSET 0x00008000
  84. #define NE2000_IRQ_VECTOR0 27
  85. #define NE2000_IRQ_VECTOR1 29
  86. #undef BSWAP
  87. #define BSWAP(w) (w)
  88. #define NE2000_BYTE volatile unsigned short
  89. #undef RSWAP
  90. #define RSWAP(w) (((w) << 8) | ((w) >> 8))
  91. #endif
  92. #if defined(CONFIG_M5307) && defined(CONFIG_SECUREEDGEMP3)
  93. #define NE2000_ADDR 0x30600300
  94. #define NE2000_ODDOFFSET 0x00008000
  95. #define NE2000_IRQ_VECTOR 27
  96. #undef BSWAP
  97. #define BSWAP(w) (w)
  98. #define NE2000_BYTE volatile unsigned short
  99. #undef RSWAP
  100. #define RSWAP(w) (((w) << 8) | ((w) >> 8))
  101. #endif
  102. #if defined(CONFIG_M5307) && defined(CONFIG_ARNEWSH)
  103. #define NE2000_ADDR 0xfe600300
  104. #define NE2000_ODDOFFSET 0x00010000
  105. #define NE2000_IRQ_VECTOR 0x1b
  106. #define NE2000_IRQ_PRIORITY 2
  107. #define NE2000_IRQ_LEVEL 3
  108. #define NE2000_BYTE volatile unsigned short
  109. #endif
  110. #if defined(CONFIG_M5407)
  111. #define NE2000_ADDR 0x40000300
  112. #define NE2000_ODDOFFSET 0x00010000
  113. #define NE2000_IRQ_VECTOR 0x1b
  114. #define NE2000_BYTE volatile unsigned short
  115. #endif
  116. /****************************************************************************/
  117. /*
  118. * Side-band address space for odd address requires re-mapping
  119. * many of the standard ISA access functions.
  120. */
  121. #ifdef NE2000_ODDOFFSET
  122. #undef outb
  123. #undef outb_p
  124. #undef inb
  125. #undef inb_p
  126. #undef outsb
  127. #undef outsw
  128. #undef insb
  129. #undef insw
  130. #define outb ne2000_outb
  131. #define inb ne2000_inb
  132. #define outb_p ne2000_outb
  133. #define inb_p ne2000_inb
  134. #define outsb ne2000_outsb
  135. #define outsw ne2000_outsw
  136. #define insb ne2000_insb
  137. #define insw ne2000_insw
  138. #ifndef COLDFIRE_NE2000_FUNCS
  139. void ne2000_outb(unsigned int val, unsigned int addr);
  140. int ne2000_inb(unsigned int addr);
  141. void ne2000_insb(unsigned int addr, void *vbuf, int unsigned long len);
  142. void ne2000_insw(unsigned int addr, void *vbuf, unsigned long len);
  143. void ne2000_outsb(unsigned int addr, void *vbuf, unsigned long len);
  144. void ne2000_outsw(unsigned int addr, void *vbuf, unsigned long len);
  145. #else
  146. /*
  147. * This macro converts a conventional register address into the
  148. * real memory pointer of the mapped NE2000 device.
  149. * On most NE2000 implementations on ColdFire boards the chip is
  150. * mapped in kinda funny, due to its ISA heritage.
  151. */
  152. #ifdef CONFIG_CFV240
  153. #define NE2000_PTR(addr) (NE2000_ADDR + ((addr & 0x3f) << 1) + 1)
  154. #define NE2000_DATA_PTR(addr) (NE2000_ADDR + ((addr & 0x3f) << 1))
  155. #else
  156. #define NE2000_PTR(addr) ((addr&0x1)?(NE2000_ODDOFFSET+addr-1):(addr))
  157. #define NE2000_DATA_PTR(addr) (addr)
  158. #endif
  159. void ne2000_outb(unsigned int val, unsigned int addr)
  160. {
  161. NE2000_BYTE *rp;
  162. rp = (NE2000_BYTE *) NE2000_PTR(addr);
  163. *rp = RSWAP(val);
  164. }
  165. int ne2000_inb(unsigned int addr)
  166. {
  167. NE2000_BYTE *rp, val;
  168. rp = (NE2000_BYTE *) NE2000_PTR(addr);
  169. val = *rp;
  170. return((int) ((NE2000_BYTE) RSWAP(val)));
  171. }
  172. void ne2000_insb(unsigned int addr, void *vbuf, int unsigned long len)
  173. {
  174. NE2000_BYTE *rp, val;
  175. unsigned char *buf;
  176. buf = (unsigned char *) vbuf;
  177. rp = (NE2000_BYTE *) NE2000_DATA_PTR(addr);
  178. for (; (len > 0); len--) {
  179. val = *rp;
  180. *buf++ = RSWAP(val);
  181. }
  182. }
  183. void ne2000_insw(unsigned int addr, void *vbuf, unsigned long len)
  184. {
  185. volatile unsigned short *rp;
  186. unsigned short w, *buf;
  187. buf = (unsigned short *) vbuf;
  188. rp = (volatile unsigned short *) NE2000_DATA_PTR(addr);
  189. for (; (len > 0); len--) {
  190. w = *rp;
  191. *buf++ = BSWAP(w);
  192. }
  193. }
  194. void ne2000_outsb(unsigned int addr, const void *vbuf, unsigned long len)
  195. {
  196. NE2000_BYTE *rp, val;
  197. unsigned char *buf;
  198. buf = (unsigned char *) vbuf;
  199. rp = (NE2000_BYTE *) NE2000_DATA_PTR(addr);
  200. for (; (len > 0); len--) {
  201. val = *buf++;
  202. *rp = RSWAP(val);
  203. }
  204. }
  205. void ne2000_outsw(unsigned int addr, const void *vbuf, unsigned long len)
  206. {
  207. volatile unsigned short *rp;
  208. unsigned short w, *buf;
  209. buf = (unsigned short *) vbuf;
  210. rp = (volatile unsigned short *) NE2000_DATA_PTR(addr);
  211. for (; (len > 0); len--) {
  212. w = *buf++;
  213. *rp = BSWAP(w);
  214. }
  215. }
  216. #endif /* COLDFIRE_NE2000_FUNCS */
  217. #endif /* NE2000_OFFOFFSET */
  218. /****************************************************************************/
  219. #ifdef COLDFIRE_NE2000_FUNCS
  220. /*
  221. * Lastly the interrupt set up code...
  222. * Minor differences between the different board types.
  223. */
  224. #if defined(CONFIG_M5206) && defined(CONFIG_ARNEWSH)
  225. void ne2000_irqsetup(int irq)
  226. {
  227. volatile unsigned char *icrp;
  228. icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_ICR4);
  229. *icrp = MCFSIM_ICR_LEVEL4 | MCFSIM_ICR_PRI2;
  230. mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_EINT4);
  231. }
  232. #endif
  233. #if defined(CONFIG_M5206e) && defined(CONFIG_MOTOROLA)
  234. void ne2000_irqsetup(int irq)
  235. {
  236. volatile unsigned char *icrp;
  237. icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_ICR4);
  238. *icrp = MCFSIM_ICR_LEVEL4 | MCFSIM_ICR_PRI2 | MCFSIM_ICR_AUTOVEC;
  239. mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_EINT4);
  240. }
  241. #endif
  242. #if defined(CONFIG_M5206e) && defined(CONFIG_CFV240)
  243. void ne2000_irqsetup(int irq)
  244. {
  245. volatile unsigned char *icrp;
  246. icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_ICR1);
  247. *icrp = MCFSIM_ICR_LEVEL1 | MCFSIM_ICR_PRI2 | MCFSIM_ICR_AUTOVEC;
  248. mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_EINT1);
  249. }
  250. #endif
  251. #if defined(CONFIG_M5206e) && defined(CONFIG_NETtel)
  252. void ne2000_irqsetup(int irq)
  253. {
  254. mcf_autovector(irq);
  255. }
  256. #endif
  257. #if defined(CONFIG_M5272) && defined(CONFIG_NETtel)
  258. void ne2000_irqsetup(int irq)
  259. {
  260. volatile unsigned long *icrp;
  261. volatile unsigned long *pitr;
  262. /* The NE2000 device uses external IRQ3 */
  263. icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
  264. *icrp = (*icrp & 0x77077777) | 0x00d00000;
  265. pitr = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PITR);
  266. *pitr = *pitr | 0x20000000;
  267. }
  268. void ne2000_irqack(int irq)
  269. {
  270. volatile unsigned long *icrp;
  271. /* The NE2000 device uses external IRQ3 */
  272. icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
  273. *icrp = (*icrp & 0x77777777) | 0x00800000;
  274. }
  275. #endif
  276. #if defined(CONFIG_M5307) || defined(CONFIG_M5407)
  277. #if defined(CONFIG_NETtel) || defined(CONFIG_SECUREEDGEMP3)
  278. void ne2000_irqsetup(int irq)
  279. {
  280. mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_EINT3);
  281. mcf_autovector(irq);
  282. }
  283. #else
  284. void ne2000_irqsetup(int irq)
  285. {
  286. mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_EINT3);
  287. }
  288. #endif /* ! CONFIG_NETtel || CONFIG_SECUREEDGEMP3 */
  289. #endif /* CONFIG_M5307 || CONFIG_M5407 */
  290. #endif /* COLDFIRE_NE2000_FUNCS */
  291. /****************************************************************************/
  292. #endif /* mcfne_h */