mcfne.h 7.9 KB

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