3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 /* For the V38B board the pin is GPIO_PSC_6 */
28 #define GPIO_PIN GPIO_PSC6_0
31 #define ERR_NO_NUMBER 1
32 #define ERR_BAD_NUMBER 2
34 static int is_high(void);
35 static int check_device(void);
36 static void io_out(int value);
37 static void io_input(void);
38 static void io_output(void);
39 static void init_gpio(void);
40 static void read_byte(unsigned char *data);
41 static void write_byte(unsigned char command);
43 void read_2501_memory(unsigned char *psernum, unsigned char *perr);
44 void board_get_enetaddr(uchar *enetaddr);
49 return (*((vu_long *) MPC5XXX_WU_GPIO_DATA_I) & GPIO_PIN);
52 static void io_out(int value)
55 *((vu_long *) MPC5XXX_WU_GPIO_DATA_O) |= GPIO_PIN;
57 *((vu_long *) MPC5XXX_WU_GPIO_DATA_O) &= ~GPIO_PIN;
60 static void io_input()
62 *((vu_long *) MPC5XXX_WU_GPIO_DIR) &= ~GPIO_PIN;
63 udelay(3); /* allow input to settle */
66 static void io_output()
68 *((vu_long *) MPC5XXX_WU_GPIO_DIR) |= GPIO_PIN;
71 static void init_gpio()
73 *((vu_long *) MPC5XXX_WU_GPIO_ENABLE) |= GPIO_PIN; /* Enable appropriate pin */
76 void read_2501_memory(unsigned char *psernum, unsigned char *perr)
79 unsigned char crcval, i;
80 unsigned char buf[NBYTES];
85 for (i = 0; i < NBYTES; i++)
89 *perr = ERR_NO_NUMBER;
92 write_byte(0xCC); /* skip ROM (0xCC) */
93 write_byte(0xF0); /* Read memory command 0xF0 */
94 write_byte(0x00); /* Address TA1=0, TA2=0 */
96 read_byte(&crcval); /* Read CRC of address and command */
98 for (i = 0; i < NBYTES; i++)
101 if (strncmp((const char *) &buf[11], "MAREL IEEE 802.3", 16)) {
102 *perr = ERR_BAD_NUMBER;
119 static int check_device()
125 udelay(500); /* must be at least 480 us low pulse */
130 found = (is_high() == 0) ? 1 : 0;
131 udelay(500); /* must be at least 480 us low pulse */
136 static void write_byte(unsigned char command)
140 for (i = 0; i < 8; i++) {
141 /* 1 us to 15 us low pulse starts bit slot */
142 /* Start with high pulse for 3 us */
150 if (command & 0x01) {
151 /* 60 us high for 1-bit */
155 /* 60 us low for 0-bit */
157 /* Leave pin as input */
160 command = command >> 1;
164 static void read_byte(unsigned char *data)
166 unsigned char i, rdat = 0;
168 for (i = 0; i < 8; i++) {
169 /* read one bit from one-wire device */
171 /* 1 - 15 us low starts bit slot */
176 /* allow line to be pulled high */
182 /* now sample input status */
184 rdat = (rdat >> 1) | 0x80;
188 udelay(60); /* at least 60 us */
190 /* copy the return value */
194 void board_get_enetaddr(uchar *enetaddr)
196 unsigned char sn[6], err = NO_ERROR;
200 read_2501_memory(sn, &err);
202 if (err == NO_ERROR) {
203 sprintf((char *)enetaddr, "%02x:%02x:%02x:%02x:%02x:%02x",
204 sn[0], sn[1], sn[2], sn[3], sn[4], sn[5]);
205 printf("MAC address: %s\n", enetaddr);
206 setenv("ethaddr", (char *)enetaddr);
208 sprintf((char *)enetaddr, "00:01:02:03:04:05");
209 printf("Error reading MAC address.\n");
210 printf("Setting default to %s\n", enetaddr);
211 setenv("ethaddr", (char *)enetaddr);