mcfsmc.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /****************************************************************************/
  2. /*
  3. * mcfsmc.h -- SMC ethernet support for ColdFire environments.
  4. *
  5. * (C) Copyright 1999-2002, Greg Ungerer (gerg@snapgear.com)
  6. * (C) Copyright 2000, Lineo Inc. (www.lineo.com)
  7. */
  8. /****************************************************************************/
  9. #ifndef mcfsmc_h
  10. #define mcfsmc_h
  11. /****************************************************************************/
  12. /*
  13. * None of the current ColdFire targets that use the SMC91x111
  14. * allow 8 bit accesses. So this code is 16bit access only.
  15. */
  16. #undef outb
  17. #undef inb
  18. #undef outw
  19. #undef outwd
  20. #undef inw
  21. #undef outl
  22. #undef inl
  23. #undef outsb
  24. #undef outsw
  25. #undef outsl
  26. #undef insb
  27. #undef insw
  28. #undef insl
  29. /*
  30. * Re-defines for ColdFire environment... The SMC part is
  31. * mapped into memory space, so remap the PC-style in/out
  32. * routines to handle that.
  33. */
  34. #define outb smc_outb
  35. #define inb smc_inb
  36. #define outw smc_outw
  37. #define outwd smc_outwd
  38. #define inw smc_inw
  39. #define outl smc_outl
  40. #define inl smc_inl
  41. #define outsb smc_outsb
  42. #define outsw smc_outsw
  43. #define outsl smc_outsl
  44. #define insb smc_insb
  45. #define insw smc_insw
  46. #define insl smc_insl
  47. static inline int smc_inb(unsigned int addr)
  48. {
  49. register unsigned short w;
  50. w = *((volatile unsigned short *) (addr & ~0x1));
  51. return(((addr & 0x1) ? w : (w >> 8)) & 0xff);
  52. }
  53. static inline void smc_outw(unsigned int val, unsigned int addr)
  54. {
  55. *((volatile unsigned short *) addr) = (val << 8) | (val >> 8);
  56. }
  57. static inline int smc_inw(unsigned int addr)
  58. {
  59. register unsigned short w;
  60. w = *((volatile unsigned short *) addr);
  61. return(((w << 8) | (w >> 8)) & 0xffff);
  62. }
  63. static inline void smc_outl(unsigned long val, unsigned int addr)
  64. {
  65. *((volatile unsigned long *) addr) =
  66. ((val << 8) & 0xff000000) | ((val >> 8) & 0x00ff0000) |
  67. ((val << 8) & 0x0000ff00) | ((val >> 8) & 0x000000ff);
  68. }
  69. static inline void smc_outwd(unsigned int val, unsigned int addr)
  70. {
  71. *((volatile unsigned short *) addr) = val;
  72. }
  73. /*
  74. * The rep* functions are used to feed the data port with
  75. * raw data. So we do not byte swap them when copying.
  76. */
  77. static inline void smc_insb(unsigned int addr, void *vbuf, int unsigned long len)
  78. {
  79. volatile unsigned short *rp;
  80. unsigned short *buf, *ebuf;
  81. buf = (unsigned short *) vbuf;
  82. rp = (volatile unsigned short *) addr;
  83. /* Copy as words for as long as possible */
  84. for (ebuf = buf + (len >> 1); (buf < ebuf); )
  85. *buf++ = *rp;
  86. /* Lastly, handle left over byte */
  87. if (len & 0x1)
  88. *((unsigned char *) buf) = (*rp >> 8) & 0xff;
  89. }
  90. static inline void smc_insw(unsigned int addr, void *vbuf, unsigned long len)
  91. {
  92. volatile unsigned short *rp;
  93. unsigned short *buf, *ebuf;
  94. buf = (unsigned short *) vbuf;
  95. rp = (volatile unsigned short *) addr;
  96. for (ebuf = buf + len; (buf < ebuf); )
  97. *buf++ = *rp;
  98. }
  99. static inline void smc_insl(unsigned int addr, void *vbuf, unsigned long len)
  100. {
  101. volatile unsigned long *rp;
  102. unsigned long *buf, *ebuf;
  103. buf = (unsigned long *) vbuf;
  104. rp = (volatile unsigned long *) addr;
  105. for (ebuf = buf + len; (buf < ebuf); )
  106. *buf++ = *rp;
  107. }
  108. static inline void smc_outsw(unsigned int addr, const void *vbuf, unsigned long len)
  109. {
  110. volatile unsigned short *rp;
  111. unsigned short *buf, *ebuf;
  112. buf = (unsigned short *) vbuf;
  113. rp = (volatile unsigned short *) addr;
  114. for (ebuf = buf + len; (buf < ebuf); )
  115. *rp = *buf++;
  116. }
  117. static inline void smc_outsl(unsigned int addr, void *vbuf, unsigned long len)
  118. {
  119. volatile unsigned long *rp;
  120. unsigned long *buf, *ebuf;
  121. buf = (unsigned long *) vbuf;
  122. rp = (volatile unsigned long *) addr;
  123. for (ebuf = buf + len; (buf < ebuf); )
  124. *rp = *buf++;
  125. }
  126. #ifdef CONFIG_NETtel
  127. /*
  128. * Re-map the address space of at least one of the SMC ethernet
  129. * parts. Both parts power up decoding the same address, so we
  130. * need to move one of them first, before doing enything else.
  131. *
  132. * We also increase the number of wait states for this part by one.
  133. */
  134. void smc_remap(unsigned int ioaddr)
  135. {
  136. static int once = 0;
  137. extern unsigned short ppdata;
  138. if (once++ == 0) {
  139. *((volatile unsigned short *)(MCF_MBAR+MCFSIM_PADDR)) = 0x00ec;
  140. ppdata |= 0x0080;
  141. *((volatile unsigned short *)(MCF_MBAR+MCFSIM_PADAT)) = ppdata;
  142. outw(0x0001, ioaddr + BANK_SELECT);
  143. outw(0x0001, ioaddr + BANK_SELECT);
  144. outw(0x0067, ioaddr + BASE);
  145. ppdata &= ~0x0080;
  146. *((volatile unsigned short *)(MCF_MBAR+MCFSIM_PADAT)) = ppdata;
  147. }
  148. *((volatile unsigned short *)(MCF_MBAR+MCFSIM_CSCR3)) = 0x1180;
  149. }
  150. #endif
  151. /****************************************************************************/
  152. #endif /* mcfsmc_h */