4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #define GPIO_ENABLE (MPC5XXX_WU_GPIO)
30 /* Open Drain Emulation Register */
31 #define GPIO_ODR (MPC5XXX_WU_GPIO + 0x04)
33 /* Data Direction Register */
34 #define GPIO_DDR (MPC5XXX_WU_GPIO + 0x08)
36 /* Data Value Out Register */
37 #define GPIO_DVOR (MPC5XXX_WU_GPIO + 0x0C)
39 /* Interrupt Enable Register */
40 #define GPIO_IER (MPC5XXX_WU_GPIO + 0x10)
42 /* Individual Interrupt Enable Register */
43 #define GPIO_IIER (MPC5XXX_WU_GPIO + 0x14)
45 /* Interrupt Type Register */
46 #define GPIO_ITR (MPC5XXX_WU_GPIO + 0x18)
48 /* Master Enable Register */
49 #define GPIO_MER (MPC5XXX_WU_GPIO + 0x1C)
51 /* Data Input Value Register */
52 #define GPIO_DIVR (MPC5XXX_WU_GPIO + 0x20)
55 #define GPIO_SR (MPC5XXX_WU_GPIO + 0x24)
57 #define PSC6_0 0x10000000
58 #define WKUP_7 0x80000000
60 /* For NS4 A/B board define WKUP_7, for V38B board PSC_6 */
61 #define GPIO_PIN PSC6_0
64 #define ERR_NO_NUMBER 1
65 #define ERR_BAD_NUMBER 2
67 typedef volatile unsigned long GPIO_REG;
68 typedef GPIO_REG *GPIO_REG_PTR;
70 static int is_high(void);
71 static int check_device(void);
72 static void io_out(int value);
73 static void io_input(void);
74 static void io_output(void);
75 static void init_gpio(void);
76 static void read_byte(unsigned char *data);
77 static void write_byte(unsigned char command);
79 void read_2501_memory(unsigned char *psernum, unsigned char *perr);
80 void board_get_enetaddr(uchar *enetaddr);
84 return (* ((vu_long *) GPIO_DIVR) & GPIO_PIN);
87 static void io_out(int value)
90 *((vu_long *) GPIO_DVOR) |= GPIO_PIN;
92 *((vu_long *) GPIO_DVOR) &= ~GPIO_PIN;
95 static void io_input()
97 *((vu_long *) GPIO_DDR) &= ~GPIO_PIN;
98 udelay(3); /* allow input to settle */
101 static void io_output()
103 *((vu_long *) GPIO_DDR) |= GPIO_PIN;
106 static void init_gpio()
108 *((vu_long *) GPIO_ENABLE) |= GPIO_PIN; /* Enable appropriate pin */
111 void read_2501_memory(unsigned char *psernum, unsigned char *perr)
114 unsigned char crcval, i;
115 unsigned char buf[NBYTES];
120 for (i=0; i<NBYTES; i++)
124 *perr = ERR_NO_NUMBER;
127 write_byte(0xCC); /* skip ROM (0xCC) */
128 write_byte(0xF0); /* Read memory command 0xF0 */
129 write_byte(0x00); /* Address TA1=0, TA2=0 */
131 read_byte(&crcval); /* Read CRC of address and command */
133 for (i=0; i<NBYTES; i++)
134 read_byte( &buf[i] );
136 if (strncmp((const char*) &buf[11], "MAREL IEEE 802.3", 16)) {
137 *perr = ERR_BAD_NUMBER;
155 static int check_device()
161 udelay(500); /* must be at least 480 us low pulse */
166 found = (is_high() == 0) ? 1 : 0;
167 udelay(500); /* must be at least 480 us low pulse */
172 static void write_byte(unsigned char command)
176 for (i=0; i<8; i++) {
177 /* 1 us to 15 us low pulse starts bit slot */
178 /* Start with high pulse for 3 us */
188 if (command & 0x01) {
189 /* 60 us high for 1-bit */
194 /* 60 us low for 0-bit */
197 /* Leave pin as input */
200 command = command >> 1;
204 static void read_byte(unsigned char *data)
206 unsigned char i, rdat = 0;
208 for (i=0; i<8; i++) {
209 /* read one bit from one-wire device */
211 /* 1 - 15 us low starts bit slot */
216 /* allow line to be pulled high */
222 /* now sample input status */
224 rdat = (rdat >> 1) | 0x80;
228 udelay(60); /* at least 60 us */
230 /* copy the return value */
234 void board_get_enetaddr(uchar *enetaddr)
236 unsigned char sn[6], err=NO_ERROR;
240 read_2501_memory(sn, &err);
242 if (err == NO_ERROR) {
243 sprintf(enetaddr, "%02x:%02x:%02x:%02x:%02x:%02x",
244 sn[0], sn[1], sn[2], sn[3], sn[4], sn[5]);
245 printf("MAC address: %s\n", enetaddr);
246 setenv("ethaddr", enetaddr);
249 sprintf(enetaddr, "00:01:02:03:04:05");
250 printf("Error reading MAC address.\n");
251 printf("Setting default to %s\n", enetaddr);
252 setenv("ethaddr", enetaddr);