1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2008 Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
9 static unsigned char *PCI_MEMR;
11 static void mac_delay(unsigned int cnt)
16 static void mac_pci_setup(void)
18 unsigned long pci_data;
24 PCI_PDR = pci_data | 0x00000007;
27 PCI_MEMR = (unsigned char *)((PCI_PDR | 0xFE240050) & 0xFFFFFFF0);
30 static void EECS(int level)
32 unsigned char data = *PCI_MEMR;
35 *PCI_MEMR = data | 0x08;
37 *PCI_MEMR = data & 0xf7;
40 static void EECLK(int level)
42 unsigned char data = *PCI_MEMR;
45 *PCI_MEMR = data | 0x04;
47 *PCI_MEMR = data & 0xfb;
50 static void EEDI(int level)
52 unsigned char data = *PCI_MEMR;
55 *PCI_MEMR = data | 0x02;
57 *PCI_MEMR = data & 0xfd;
60 static inline void sh7785lcr_bitset(unsigned short bit)
74 static inline unsigned char sh7785lcr_bitget(void)
80 bit = *PCI_MEMR & 0x01;
87 static inline void sh7785lcr_setcmd(unsigned char command)
89 sh7785lcr_bitset(BIT_DUMMY);
121 static inline unsigned short sh7785lcr_getdt(void)
123 unsigned short data = 0;
126 sh7785lcr_bitget(); /* DUMMY */
127 for (i = 0 ; i < 16 ; i++) {
129 data |= sh7785lcr_bitget();
134 static inline void sh7785lcr_setadd(unsigned short address)
136 sh7785lcr_bitset(address & 0x0020); /* A5 */
137 sh7785lcr_bitset(address & 0x0010); /* A4 */
138 sh7785lcr_bitset(address & 0x0008); /* A3 */
139 sh7785lcr_bitset(address & 0x0004); /* A2 */
140 sh7785lcr_bitset(address & 0x0002); /* A1 */
141 sh7785lcr_bitset(address & 0x0001); /* A0 */
144 static inline void sh7785lcr_setdata(unsigned short data)
146 sh7785lcr_bitset(data & 0x8000);
147 sh7785lcr_bitset(data & 0x4000);
148 sh7785lcr_bitset(data & 0x2000);
149 sh7785lcr_bitset(data & 0x1000);
150 sh7785lcr_bitset(data & 0x0800);
151 sh7785lcr_bitset(data & 0x0400);
152 sh7785lcr_bitset(data & 0x0200);
153 sh7785lcr_bitset(data & 0x0100);
154 sh7785lcr_bitset(data & 0x0080);
155 sh7785lcr_bitset(data & 0x0040);
156 sh7785lcr_bitset(data & 0x0020);
157 sh7785lcr_bitset(data & 0x0010);
158 sh7785lcr_bitset(data & 0x0008);
159 sh7785lcr_bitset(data & 0x0004);
160 sh7785lcr_bitset(data & 0x0002);
161 sh7785lcr_bitset(data & 0x0001);
164 static void sh7785lcr_datawrite(const unsigned short *data, unsigned short address,
169 for (i = 0; i < count; i++) {
174 sh7785lcr_setcmd(MAC_EEP_WRITE);
175 sh7785lcr_setadd(address++);
176 sh7785lcr_setdata(*(data + i));
185 static void sh7785lcr_macerase(void)
188 unsigned short pci_address = 7;
190 for (i = 0; i < 3; i++) {
194 sh7785lcr_setcmd(MAC_EEP_ERACE);
195 sh7785lcr_setadd(pci_address++);
204 printf("\n\nErace End\n");
205 for (i = 0; i < 10; i++)
209 static void sh7785lcr_macwrite(unsigned short *data)
211 sh7785lcr_macerase();
213 sh7785lcr_datawrite(EEPROM_W_Data_8169_A, 0x0000, 7);
214 sh7785lcr_datawrite(data, PCI_EEP_ADDRESS, PCI_MAC_ADDRESS_SIZE);
215 sh7785lcr_datawrite(EEPROM_W_Data_8169_B, 0x000a, 54);
218 void sh7785lcr_macdtrd(unsigned char *buf, unsigned short address, unsigned int count)
223 for (i = 0 ; i < count; i++) {
227 sh7785lcr_setcmd(MAC_EEP_READ);
228 sh7785lcr_setadd(address++);
229 wk = sh7785lcr_getdt();
231 *buf++ = (unsigned char)(wk & 0xff);
232 *buf++ = (unsigned char)((wk >> 8) & 0xff);
239 static void sh7785lcr_macadrd(unsigned char *buf)
241 *PCI_MEMR = PCI_PROG;
243 sh7785lcr_macdtrd(buf, PCI_EEP_ADDRESS, PCI_MAC_ADDRESS_SIZE);
246 static void sh7785lcr_eepewen(void)
248 *PCI_MEMR = PCI_PROG;
256 sh7785lcr_setcmd(MAC_EEP_EWEN);
259 sh7785lcr_bitset(BIT_DUMMY);
260 sh7785lcr_bitset(BIT_DUMMY);
261 sh7785lcr_bitset(BIT_DUMMY);
262 sh7785lcr_bitset(BIT_DUMMY);
270 void mac_write(unsigned short *data)
274 sh7785lcr_macwrite(data);
279 unsigned char data[6];
282 sh7785lcr_macadrd(data);
283 printf("Mac = %02x:%02x:%02x:%02x:%02x:%02x\n",
284 data[0], data[1], data[2], data[3], data[4], data[5]);
287 int do_set_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
290 unsigned char mac[6];
294 return cmd_usage(cmdtp);
298 for (i = 0; i < 6; i++) {
299 mac[i] = s ? simple_strtoul(s, &e, 16) : 0;
301 s = (*e) ? e + 1 : e;
303 mac_write((unsigned short *)mac);
309 setmac, 2, 1, do_set_mac,
310 "write MAC address for RTL8110SCL",
312 "setmac <mac address> - write MAC address for RTL8110SCL"
315 int do_print_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
318 return cmd_usage(cmdtp);
326 printmac, 1, 1, do_print_mac,
327 "print MAC address for RTL8110",
329 " - print MAC address for RTL8110"