1 /****************************************************************************/
4 * mcfsmc.h -- SMC ethernet support for ColdFire environments.
6 * (C) Copyright 1999-2002, Greg Ungerer (gerg@snapgear.com)
7 * (C) Copyright 2000, Lineo Inc. (www.lineo.com)
10 /****************************************************************************/
13 /****************************************************************************/
16 * None of the current ColdFire targets that use the SMC91x111
17 * allow 8 bit accesses. So this code is 16bit access only.
20 #include <linux/config.h>
26 * Re-defines for ColdFire environment... The SMC part is
27 * mapped into memory space, so remap the PC-style in/out
28 * routines to handle that.
33 #define outwd smc_outwd
38 #define outsb smc_outsb
39 #define outsw smc_outsw
40 #define outsl smc_outsl
46 static inline int smc_inb(unsigned int addr)
48 register unsigned short w;
49 w = *((volatile unsigned short *) (addr & ~0x1));
50 return(((addr & 0x1) ? w : (w >> 8)) & 0xff);
53 static inline void smc_outw(unsigned int val, unsigned int addr)
55 *((volatile unsigned short *) addr) = (val << 8) | (val >> 8);
58 static inline int smc_inw(unsigned int addr)
60 register unsigned short w;
61 w = *((volatile unsigned short *) addr);
62 return(((w << 8) | (w >> 8)) & 0xffff);
65 static inline void smc_outl(unsigned long val, unsigned int addr)
67 *((volatile unsigned long *) addr) =
68 ((val << 8) & 0xff000000) | ((val >> 8) & 0x00ff0000) |
69 ((val << 8) & 0x0000ff00) | ((val >> 8) & 0x000000ff);
72 static inline void smc_outwd(unsigned int val, unsigned int addr)
74 *((volatile unsigned short *) addr) = val;
79 * The rep* functions are used to feed the data port with
80 * raw data. So we do not byte swap them when copying.
83 static inline void smc_insb(unsigned int addr, void *vbuf, int unsigned long len)
85 volatile unsigned short *rp;
86 unsigned short *buf, *ebuf;
88 buf = (unsigned short *) vbuf;
89 rp = (volatile unsigned short *) addr;
91 /* Copy as words for as long as possible */
92 for (ebuf = buf + (len >> 1); (buf < ebuf); )
95 /* Lastly, handle left over byte */
97 *((unsigned char *) buf) = (*rp >> 8) & 0xff;
100 static inline void smc_insw(unsigned int addr, void *vbuf, unsigned long len)
102 volatile unsigned short *rp;
103 unsigned short *buf, *ebuf;
105 buf = (unsigned short *) vbuf;
106 rp = (volatile unsigned short *) addr;
107 for (ebuf = buf + len; (buf < ebuf); )
111 static inline void smc_insl(unsigned int addr, void *vbuf, unsigned long len)
113 volatile unsigned long *rp;
114 unsigned long *buf, *ebuf;
116 buf = (unsigned long *) vbuf;
117 rp = (volatile unsigned long *) addr;
118 for (ebuf = buf + len; (buf < ebuf); )
122 static inline void smc_outsw(unsigned int addr, const void *vbuf, unsigned long len)
124 volatile unsigned short *rp;
125 unsigned short *buf, *ebuf;
127 buf = (unsigned short *) vbuf;
128 rp = (volatile unsigned short *) addr;
129 for (ebuf = buf + len; (buf < ebuf); )
133 static inline void smc_outsl(unsigned int addr, void *vbuf, unsigned long len)
135 volatile unsigned long *rp;
136 unsigned long *buf, *ebuf;
138 buf = (unsigned long *) vbuf;
139 rp = (volatile unsigned long *) addr;
140 for (ebuf = buf + len; (buf < ebuf); )
147 * Re-map the address space of at least one of the SMC ethernet
148 * parts. Both parts power up decoding the same address, so we
149 * need to move one of them first, before doing enything else.
151 * We also increase the number of wait states for this part by one.
154 void smc_remap(unsigned int ioaddr)
157 extern unsigned short ppdata;
159 *((volatile unsigned short *)(MCF_MBAR+MCFSIM_PADDR)) = 0x00ec;
161 *((volatile unsigned short *)(MCF_MBAR+MCFSIM_PADAT)) = ppdata;
162 outw(0x0001, ioaddr + BANK_SELECT);
163 outw(0x0001, ioaddr + BANK_SELECT);
164 outw(0x0067, ioaddr + BASE);
167 *((volatile unsigned short *)(MCF_MBAR+MCFSIM_PADAT)) = ppdata;
170 *((volatile unsigned short *)(MCF_MBAR+MCFSIM_CSCR3)) = 0x1180;
175 /****************************************************************************/
176 #endif /* mcfsmc_h */