mcfsmc.h 4.5 KB

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