]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/renesas/sh7785lcr/rtl8169_mac.c
2 * Copyright (C) 2008 Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 static unsigned char *PCI_MEMR
;
25 static void mac_delay(unsigned int cnt
)
30 static void mac_pci_setup(void)
32 unsigned long pci_data
;
38 PCI_PDR
= pci_data
| 0x00000007;
41 PCI_MEMR
= (unsigned char *)((PCI_PDR
| 0xFE240050) & 0xFFFFFFF0);
44 static void EECS(int level
)
46 unsigned char data
= *PCI_MEMR
;
49 *PCI_MEMR
= data
| 0x08;
51 *PCI_MEMR
= data
& 0xf7;
54 static void EECLK(int level
)
56 unsigned char data
= *PCI_MEMR
;
59 *PCI_MEMR
= data
| 0x04;
61 *PCI_MEMR
= data
& 0xfb;
64 static void EEDI(int level
)
66 unsigned char data
= *PCI_MEMR
;
69 *PCI_MEMR
= data
| 0x02;
71 *PCI_MEMR
= data
& 0xfd;
74 static inline void sh7785lcr_bitset(unsigned short bit
)
88 static inline unsigned char sh7785lcr_bitget(void)
94 bit
= *PCI_MEMR
& 0x01;
101 static inline void sh7785lcr_setcmd(unsigned char command
)
103 sh7785lcr_bitset(BIT_DUMMY
);
135 static inline unsigned short sh7785lcr_getdt(void)
137 unsigned short data
= 0;
140 sh7785lcr_bitget(); /* DUMMY */
141 for (i
= 0 ; i
< 16 ; i
++) {
143 data
|= sh7785lcr_bitget();
148 static inline void sh7785lcr_setadd(unsigned short address
)
150 sh7785lcr_bitset(address
& 0x0020); /* A5 */
151 sh7785lcr_bitset(address
& 0x0010); /* A4 */
152 sh7785lcr_bitset(address
& 0x0008); /* A3 */
153 sh7785lcr_bitset(address
& 0x0004); /* A2 */
154 sh7785lcr_bitset(address
& 0x0002); /* A1 */
155 sh7785lcr_bitset(address
& 0x0001); /* A0 */
158 static inline void sh7785lcr_setdata(unsigned short data
)
160 sh7785lcr_bitset(data
& 0x8000);
161 sh7785lcr_bitset(data
& 0x4000);
162 sh7785lcr_bitset(data
& 0x2000);
163 sh7785lcr_bitset(data
& 0x1000);
164 sh7785lcr_bitset(data
& 0x0800);
165 sh7785lcr_bitset(data
& 0x0400);
166 sh7785lcr_bitset(data
& 0x0200);
167 sh7785lcr_bitset(data
& 0x0100);
168 sh7785lcr_bitset(data
& 0x0080);
169 sh7785lcr_bitset(data
& 0x0040);
170 sh7785lcr_bitset(data
& 0x0020);
171 sh7785lcr_bitset(data
& 0x0010);
172 sh7785lcr_bitset(data
& 0x0008);
173 sh7785lcr_bitset(data
& 0x0004);
174 sh7785lcr_bitset(data
& 0x0002);
175 sh7785lcr_bitset(data
& 0x0001);
178 static void sh7785lcr_datawrite(const unsigned short *data
, unsigned short address
,
183 for (i
= 0; i
< count
; i
++) {
188 sh7785lcr_setcmd(MAC_EEP_WRITE
);
189 sh7785lcr_setadd(address
++);
190 sh7785lcr_setdata(*(data
+ i
));
199 static void sh7785lcr_macerase(void)
202 unsigned short pci_address
= 7;
204 for (i
= 0; i
< 3; i
++) {
208 sh7785lcr_setcmd(MAC_EEP_ERACE
);
209 sh7785lcr_setadd(pci_address
++);
218 printf("\n\nErace End\n");
219 for (i
= 0; i
< 10; i
++)
223 static void sh7785lcr_macwrite(unsigned short *data
)
225 sh7785lcr_macerase();
227 sh7785lcr_datawrite(EEPROM_W_Data_8169_A
, 0x0000, 7);
228 sh7785lcr_datawrite(data
, PCI_EEP_ADDRESS
, PCI_MAC_ADDRESS_SIZE
);
229 sh7785lcr_datawrite(EEPROM_W_Data_8169_B
, 0x000a, 54);
232 void sh7785lcr_macdtrd(unsigned char *buf
, unsigned short address
, unsigned int count
)
237 for (i
= 0 ; i
< count
; i
++) {
241 sh7785lcr_setcmd(MAC_EEP_READ
);
242 sh7785lcr_setadd(address
++);
243 wk
= sh7785lcr_getdt();
245 *buf
++ = (unsigned char)(wk
& 0xff);
246 *buf
++ = (unsigned char)((wk
>> 8) & 0xff);
253 static void sh7785lcr_macadrd(unsigned char *buf
)
255 *PCI_MEMR
= PCI_PROG
;
257 sh7785lcr_macdtrd(buf
, PCI_EEP_ADDRESS
, PCI_MAC_ADDRESS_SIZE
);
260 static void sh7785lcr_eepewen(void)
262 *PCI_MEMR
= PCI_PROG
;
270 sh7785lcr_setcmd(MAC_EEP_EWEN
);
273 sh7785lcr_bitset(BIT_DUMMY
);
274 sh7785lcr_bitset(BIT_DUMMY
);
275 sh7785lcr_bitset(BIT_DUMMY
);
276 sh7785lcr_bitset(BIT_DUMMY
);
284 void mac_write(unsigned short *data
)
288 sh7785lcr_macwrite(data
);
293 unsigned char data
[6];
296 sh7785lcr_macadrd(data
);
297 printf("Mac = %02x:%02x:%02x:%02x:%02x:%02x\n",
298 data
[0], data
[1], data
[2], data
[3], data
[4], data
[5]);
301 int do_set_mac(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
304 unsigned char mac
[6];
308 return cmd_usage(cmdtp
);
312 for (i
= 0; i
< 6; i
++) {
313 mac
[i
] = s
? simple_strtoul(s
, &e
, 16) : 0;
315 s
= (*e
) ? e
+ 1 : e
;
317 mac_write((unsigned short *)mac
);
323 setmac
, 2, 1, do_set_mac
,
324 "write MAC address for RTL8110SCL",
326 "setmac <mac address> - write MAC address for RTL8110SCL"
329 int do_print_mac(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
332 return cmd_usage(cmdtp
);
340 printmac
, 1, 1, do_print_mac
,
341 "print MAC address for RTL8110",
343 " - print MAC address for RTL8110"