2 * Copyright (C) 2008 Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
4 * SPDX-License-Identifier: GPL-2.0+
10 static unsigned char *PCI_MEMR;
12 static void mac_delay(unsigned int cnt)
17 static void mac_pci_setup(void)
19 unsigned long pci_data;
25 PCI_PDR = pci_data | 0x00000007;
28 PCI_MEMR = (unsigned char *)((PCI_PDR | 0xFE240050) & 0xFFFFFFF0);
31 static void EECS(int level)
33 unsigned char data = *PCI_MEMR;
36 *PCI_MEMR = data | 0x08;
38 *PCI_MEMR = data & 0xf7;
41 static void EECLK(int level)
43 unsigned char data = *PCI_MEMR;
46 *PCI_MEMR = data | 0x04;
48 *PCI_MEMR = data & 0xfb;
51 static void EEDI(int level)
53 unsigned char data = *PCI_MEMR;
56 *PCI_MEMR = data | 0x02;
58 *PCI_MEMR = data & 0xfd;
61 static inline void sh7785lcr_bitset(unsigned short bit)
75 static inline unsigned char sh7785lcr_bitget(void)
81 bit = *PCI_MEMR & 0x01;
88 static inline void sh7785lcr_setcmd(unsigned char command)
90 sh7785lcr_bitset(BIT_DUMMY);
122 static inline unsigned short sh7785lcr_getdt(void)
124 unsigned short data = 0;
127 sh7785lcr_bitget(); /* DUMMY */
128 for (i = 0 ; i < 16 ; i++) {
130 data |= sh7785lcr_bitget();
135 static inline void sh7785lcr_setadd(unsigned short address)
137 sh7785lcr_bitset(address & 0x0020); /* A5 */
138 sh7785lcr_bitset(address & 0x0010); /* A4 */
139 sh7785lcr_bitset(address & 0x0008); /* A3 */
140 sh7785lcr_bitset(address & 0x0004); /* A2 */
141 sh7785lcr_bitset(address & 0x0002); /* A1 */
142 sh7785lcr_bitset(address & 0x0001); /* A0 */
145 static inline void sh7785lcr_setdata(unsigned short data)
147 sh7785lcr_bitset(data & 0x8000);
148 sh7785lcr_bitset(data & 0x4000);
149 sh7785lcr_bitset(data & 0x2000);
150 sh7785lcr_bitset(data & 0x1000);
151 sh7785lcr_bitset(data & 0x0800);
152 sh7785lcr_bitset(data & 0x0400);
153 sh7785lcr_bitset(data & 0x0200);
154 sh7785lcr_bitset(data & 0x0100);
155 sh7785lcr_bitset(data & 0x0080);
156 sh7785lcr_bitset(data & 0x0040);
157 sh7785lcr_bitset(data & 0x0020);
158 sh7785lcr_bitset(data & 0x0010);
159 sh7785lcr_bitset(data & 0x0008);
160 sh7785lcr_bitset(data & 0x0004);
161 sh7785lcr_bitset(data & 0x0002);
162 sh7785lcr_bitset(data & 0x0001);
165 static void sh7785lcr_datawrite(const unsigned short *data, unsigned short address,
170 for (i = 0; i < count; i++) {
175 sh7785lcr_setcmd(MAC_EEP_WRITE);
176 sh7785lcr_setadd(address++);
177 sh7785lcr_setdata(*(data + i));
186 static void sh7785lcr_macerase(void)
189 unsigned short pci_address = 7;
191 for (i = 0; i < 3; i++) {
195 sh7785lcr_setcmd(MAC_EEP_ERACE);
196 sh7785lcr_setadd(pci_address++);
205 printf("\n\nErace End\n");
206 for (i = 0; i < 10; i++)
210 static void sh7785lcr_macwrite(unsigned short *data)
212 sh7785lcr_macerase();
214 sh7785lcr_datawrite(EEPROM_W_Data_8169_A, 0x0000, 7);
215 sh7785lcr_datawrite(data, PCI_EEP_ADDRESS, PCI_MAC_ADDRESS_SIZE);
216 sh7785lcr_datawrite(EEPROM_W_Data_8169_B, 0x000a, 54);
219 void sh7785lcr_macdtrd(unsigned char *buf, unsigned short address, unsigned int count)
224 for (i = 0 ; i < count; i++) {
228 sh7785lcr_setcmd(MAC_EEP_READ);
229 sh7785lcr_setadd(address++);
230 wk = sh7785lcr_getdt();
232 *buf++ = (unsigned char)(wk & 0xff);
233 *buf++ = (unsigned char)((wk >> 8) & 0xff);
240 static void sh7785lcr_macadrd(unsigned char *buf)
242 *PCI_MEMR = PCI_PROG;
244 sh7785lcr_macdtrd(buf, PCI_EEP_ADDRESS, PCI_MAC_ADDRESS_SIZE);
247 static void sh7785lcr_eepewen(void)
249 *PCI_MEMR = PCI_PROG;
257 sh7785lcr_setcmd(MAC_EEP_EWEN);
260 sh7785lcr_bitset(BIT_DUMMY);
261 sh7785lcr_bitset(BIT_DUMMY);
262 sh7785lcr_bitset(BIT_DUMMY);
263 sh7785lcr_bitset(BIT_DUMMY);
271 void mac_write(unsigned short *data)
275 sh7785lcr_macwrite(data);
280 unsigned char data[6];
283 sh7785lcr_macadrd(data);
284 printf("Mac = %02x:%02x:%02x:%02x:%02x:%02x\n",
285 data[0], data[1], data[2], data[3], data[4], data[5]);
288 int do_set_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
291 unsigned char mac[6];
295 return cmd_usage(cmdtp);
299 for (i = 0; i < 6; i++) {
300 mac[i] = s ? simple_strtoul(s, &e, 16) : 0;
302 s = (*e) ? e + 1 : e;
304 mac_write((unsigned short *)mac);
310 setmac, 2, 1, do_set_mac,
311 "write MAC address for RTL8110SCL",
313 "setmac <mac address> - write MAC address for RTL8110SCL"
316 int do_print_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
319 return cmd_usage(cmdtp);
327 printmac, 1, 1, do_print_mac,
328 "print MAC address for RTL8110",
330 " - print MAC address for RTL8110"