mpcsa_machdep.c revision 1.1.16.2 1 1.1.16.1 mjf /* $Id: mpcsa_machdep.c,v 1.1.16.2 2009/01/17 13:27:58 mjf Exp $ */
2 1.1.16.1 mjf /* $NetBSD: mpcsa_machdep.c,v 1.1.16.2 2009/01/17 13:27:58 mjf Exp $ */
3 1.1.16.1 mjf
4 1.1.16.1 mjf /*
5 1.1.16.1 mjf * Copyright (c) 2007 Embedtronics Oy
6 1.1.16.1 mjf * Based on tsarm_machdep.c
7 1.1.16.1 mjf *
8 1.1.16.1 mjf * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
9 1.1.16.1 mjf * All rights reserved.
10 1.1.16.1 mjf *
11 1.1.16.1 mjf * Based on code written by Jason R. Thorpe and Steve C. Woodford for
12 1.1.16.1 mjf * Wasabi Systems, Inc.
13 1.1.16.1 mjf *
14 1.1.16.1 mjf * Redistribution and use in source and binary forms, with or without
15 1.1.16.1 mjf * modification, are permitted provided that the following conditions
16 1.1.16.1 mjf * are met:
17 1.1.16.1 mjf * 1. Redistributions of source code must retain the above copyright
18 1.1.16.1 mjf * notice, this list of conditions and the following disclaimer.
19 1.1.16.1 mjf * 2. Redistributions in binary form must reproduce the above copyright
20 1.1.16.1 mjf * notice, this list of conditions and the following disclaimer in the
21 1.1.16.1 mjf * documentation and/or other materials provided with the distribution.
22 1.1.16.1 mjf * 3. All advertising materials mentioning features or use of this software
23 1.1.16.1 mjf * must display the following acknowledgement:
24 1.1.16.1 mjf * This product includes software developed for the NetBSD Project by
25 1.1.16.1 mjf * Wasabi Systems, Inc.
26 1.1.16.1 mjf * 4. The name of Wasabi Systems, Inc. may not be used to endorse
27 1.1.16.1 mjf * or promote products derived from this software without specific prior
28 1.1.16.1 mjf * written permission.
29 1.1.16.1 mjf *
30 1.1.16.1 mjf * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
31 1.1.16.1 mjf * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32 1.1.16.1 mjf * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 1.1.16.1 mjf * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
34 1.1.16.1 mjf * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 1.1.16.1 mjf * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 1.1.16.1 mjf * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 1.1.16.1 mjf * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 1.1.16.1 mjf * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 1.1.16.1 mjf * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 1.1.16.1 mjf * POSSIBILITY OF SUCH DAMAGE.
41 1.1.16.1 mjf */
42 1.1.16.1 mjf
43 1.1.16.1 mjf /*
44 1.1.16.1 mjf * Copyright (c) 1997,1998 Mark Brinicombe.
45 1.1.16.1 mjf * Copyright (c) 1997,1998 Causality Limited.
46 1.1.16.1 mjf * All rights reserved.
47 1.1.16.1 mjf *
48 1.1.16.1 mjf * Redistribution and use in source and binary forms, with or without
49 1.1.16.1 mjf * modification, are permitted provided that the following conditions
50 1.1.16.1 mjf * are met:
51 1.1.16.1 mjf * 1. Redistributions of source code must retain the above copyright
52 1.1.16.1 mjf * notice, this list of conditions and the following disclaimer.
53 1.1.16.1 mjf * 2. Redistributions in binary form must reproduce the above copyright
54 1.1.16.1 mjf * notice, this list of conditions and the following disclaimer in the
55 1.1.16.1 mjf * documentation and/or other materials provided with the distribution.
56 1.1.16.1 mjf * 3. All advertising materials mentioning features or use of this software
57 1.1.16.1 mjf * must display the following acknowledgement:
58 1.1.16.1 mjf * This product includes software developed by Mark Brinicombe
59 1.1.16.1 mjf * for the NetBSD Project.
60 1.1.16.1 mjf * 4. The name of the company nor the name of the author may be used to
61 1.1.16.1 mjf * endorse or promote products derived from this software without specific
62 1.1.16.1 mjf * prior written permission.
63 1.1.16.1 mjf *
64 1.1.16.1 mjf * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
65 1.1.16.1 mjf * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
66 1.1.16.1 mjf * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
67 1.1.16.1 mjf * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
68 1.1.16.1 mjf * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
69 1.1.16.1 mjf * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
70 1.1.16.1 mjf * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 1.1.16.1 mjf * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 1.1.16.1 mjf * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 1.1.16.1 mjf * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 1.1.16.1 mjf * SUCH DAMAGE.
75 1.1.16.1 mjf *
76 1.1.16.1 mjf * Machine dependant functions for kernel setup for Iyonix.
77 1.1.16.1 mjf */
78 1.1.16.1 mjf
79 1.1.16.1 mjf #include <sys/cdefs.h>
80 1.1.16.1 mjf __KERNEL_RCSID(0, "$NetBSD: mpcsa_machdep.c,v 1.1.16.2 2009/01/17 13:27:58 mjf Exp $");
81 1.1.16.1 mjf
82 1.1.16.1 mjf #include "opt_ddb.h"
83 1.1.16.1 mjf #include "opt_kgdb.h"
84 1.1.16.1 mjf #include "opt_pmap_debug.h"
85 1.1.16.1 mjf
86 1.1.16.1 mjf #include <sys/param.h>
87 1.1.16.1 mjf #include <sys/device.h>
88 1.1.16.1 mjf #include <sys/systm.h>
89 1.1.16.1 mjf #include <sys/kernel.h>
90 1.1.16.1 mjf #include <sys/exec.h>
91 1.1.16.1 mjf #include <sys/proc.h>
92 1.1.16.1 mjf #include <sys/msgbuf.h>
93 1.1.16.1 mjf #include <sys/reboot.h>
94 1.1.16.1 mjf #include <sys/termios.h>
95 1.1.16.1 mjf #include <sys/ksyms.h>
96 1.1.16.1 mjf
97 1.1.16.1 mjf #include <uvm/uvm_extern.h>
98 1.1.16.1 mjf
99 1.1.16.1 mjf #include <dev/cons.h>
100 1.1.16.1 mjf
101 1.1.16.1 mjf #include <machine/db_machdep.h>
102 1.1.16.1 mjf #include <ddb/db_sym.h>
103 1.1.16.1 mjf #include <ddb/db_extern.h>
104 1.1.16.1 mjf
105 1.1.16.1 mjf #define DRAM_BLOCKS 1
106 1.1.16.1 mjf #include <machine/bootconfig.h>
107 1.1.16.1 mjf #include <machine/bus.h>
108 1.1.16.1 mjf #include <machine/cpu.h>
109 1.1.16.1 mjf #include <machine/frame.h>
110 1.1.16.1 mjf #include <arm/undefined.h>
111 1.1.16.1 mjf
112 1.1.16.1 mjf #include <arm/arm32/machdep.h>
113 1.1.16.1 mjf
114 1.1.16.1 mjf #include <arm/at91/at91reg.h>
115 1.1.16.1 mjf #include <arm/at91/at91var.h>
116 1.1.16.1 mjf
117 1.1.16.1 mjf #include <dev/ic/comreg.h>
118 1.1.16.1 mjf #include <dev/ic/comvar.h>
119 1.1.16.1 mjf
120 1.1.16.1 mjf #include <machine/autoconf.h>
121 1.1.16.1 mjf
122 1.1.16.1 mjf #include "seeprom.h"
123 1.1.16.1 mjf #if NSEEPROM > 0
124 1.1.16.1 mjf #include <net/if.h>
125 1.1.16.1 mjf #include <net/if_ether.h>
126 1.1.16.1 mjf #include <dev/i2c/i2cvar.h>
127 1.1.16.1 mjf #include <dev/i2c/at24cxxvar.h>
128 1.1.16.1 mjf #endif
129 1.1.16.1 mjf #include <arm/at91/at91twivar.h>
130 1.1.16.1 mjf
131 1.1.16.1 mjf #if TODO
132 1.1.16.1 mjf #include "epcom.h"
133 1.1.16.1 mjf #if NEPCOM > 0
134 1.1.16.1 mjf #include <arm/ep93xx/epcomvar.h>
135 1.1.16.1 mjf #endif
136 1.1.16.1 mjf
137 1.1.16.1 mjf #include "isa.h"
138 1.1.16.1 mjf #if NISA > 0
139 1.1.16.1 mjf #include <dev/isa/isareg.h>
140 1.1.16.1 mjf #include <dev/isa/isavar.h>
141 1.1.16.1 mjf #endif
142 1.1.16.1 mjf
143 1.1.16.1 mjf #include <machine/isa_machdep.h>
144 1.1.16.1 mjf
145 1.1.16.1 mjf #include <evbarm/mpcsa/mpcsareg.h>
146 1.1.16.1 mjf #endif // TODO
147 1.1.16.1 mjf
148 1.1.16.1 mjf #include <arm/at91/at91rm9200reg.h>
149 1.1.16.1 mjf #include <arm/at91/at91rm9200busvar.h>
150 1.1.16.1 mjf
151 1.1.16.1 mjf #include "opt_ipkdb.h"
152 1.1.16.1 mjf #include "ksyms.h"
153 1.1.16.1 mjf
154 1.1.16.1 mjf #include <arm/at91/at91busvar.h>
155 1.1.16.1 mjf #include <arm/at91/at91pdcreg.h>
156 1.1.16.1 mjf #include <arm/at91/at91dbgureg.h>
157 1.1.16.1 mjf #include <arm/at91/at91reg.h>
158 1.1.16.1 mjf #include <arm/at91/at91streg.h>
159 1.1.16.1 mjf
160 1.1.16.1 mjf /*
161 1.1.16.1 mjf * Address to call from cpu_reset() to reset the machine.
162 1.1.16.1 mjf * This is machine architecture dependant as it varies depending
163 1.1.16.1 mjf * on where the ROM appears when you turn the MMU off.
164 1.1.16.1 mjf */
165 1.1.16.1 mjf
166 1.1.16.1 mjf u_int cpu_reset_address = 0x00000000;
167 1.1.16.1 mjf
168 1.1.16.1 mjf
169 1.1.16.1 mjf /* boot configuration: */
170 1.1.16.1 mjf BootConfig bootconfig; /* Boot config storage */
171 1.1.16.1 mjf char *boot_args = NULL;
172 1.1.16.1 mjf char *boot_file = NULL;
173 1.1.16.1 mjf
174 1.1.16.1 mjf /* hmmm */
175 1.1.16.1 mjf static struct arm32_dma_range mpcsa_dma_ranges[4];
176 1.1.16.1 mjf static struct at91bus_machdep mpcsabus;
177 1.1.16.1 mjf static at91bus_tag_t old_at91bus_tag;
178 1.1.16.1 mjf
179 1.1.16.1 mjf /* Prototypes */
180 1.1.16.1 mjf static void mpcsa_device_register(device_t dev, void *aux);
181 1.1.16.1 mjf static void mpcsabus_init(struct at91bus_clocks *);
182 1.1.16.1 mjf static void mpcsabus_peripheral_clock(int pid, int enable);
183 1.1.16.1 mjf static uint32_t mpcsabus_gpio_mask(int pid);
184 1.1.16.1 mjf
185 1.1.16.1 mjf
186 1.1.16.1 mjf /*
187 1.1.16.1 mjf * void cpu_reboot(int howto, char *bootstr)
188 1.1.16.1 mjf *
189 1.1.16.1 mjf * Reboots the system
190 1.1.16.1 mjf *
191 1.1.16.1 mjf * Deal with any syncing, unmounting, dumping and shutdown hooks,
192 1.1.16.1 mjf * then reset the CPU.
193 1.1.16.1 mjf */
194 1.1.16.1 mjf void
195 1.1.16.1 mjf cpu_reboot(int howto, char *bootstr)
196 1.1.16.1 mjf {
197 1.1.16.1 mjf
198 1.1.16.1 mjf /*
199 1.1.16.1 mjf * If we are still cold then hit the air brakes
200 1.1.16.1 mjf * and crash to earth fast
201 1.1.16.1 mjf */
202 1.1.16.1 mjf if (cold) {
203 1.1.16.1 mjf doshutdownhooks();
204 1.1.16.2 mjf pmf_system_shutdown(boothowto);
205 1.1.16.1 mjf printf("\r\n");
206 1.1.16.1 mjf printf("The operating system has halted.\r\n");
207 1.1.16.1 mjf printf("Please press any key to reboot.\r\n");
208 1.1.16.1 mjf cngetc();
209 1.1.16.1 mjf printf("\r\nrebooting...\r\n");
210 1.1.16.1 mjf goto reset;
211 1.1.16.1 mjf }
212 1.1.16.1 mjf
213 1.1.16.1 mjf /* Disable console buffering */
214 1.1.16.1 mjf
215 1.1.16.1 mjf /*
216 1.1.16.1 mjf * If RB_NOSYNC was not specified sync the discs.
217 1.1.16.1 mjf * Note: Unless cold is set to 1 here, syslogd will die during the
218 1.1.16.1 mjf * unmount. It looks like syslogd is getting woken up only to find
219 1.1.16.1 mjf * that it cannot page part of the binary in as the filesystem has
220 1.1.16.1 mjf * been unmounted.
221 1.1.16.1 mjf */
222 1.1.16.1 mjf if (!(howto & RB_NOSYNC))
223 1.1.16.1 mjf bootsync();
224 1.1.16.1 mjf
225 1.1.16.1 mjf /* Say NO to interrupts */
226 1.1.16.1 mjf splhigh();
227 1.1.16.1 mjf
228 1.1.16.1 mjf /* Do a dump if requested. */
229 1.1.16.1 mjf if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
230 1.1.16.1 mjf dumpsys();
231 1.1.16.1 mjf
232 1.1.16.1 mjf /* Run any shutdown hooks */
233 1.1.16.1 mjf doshutdownhooks();
234 1.1.16.1 mjf
235 1.1.16.2 mjf pmf_system_shutdown(boothowto);
236 1.1.16.2 mjf
237 1.1.16.1 mjf /* Make sure IRQ's are disabled */
238 1.1.16.1 mjf IRQdisable;
239 1.1.16.1 mjf
240 1.1.16.1 mjf if (howto & RB_HALT) {
241 1.1.16.1 mjf printf("\r\n");
242 1.1.16.1 mjf printf("The operating system has halted.\r\n");
243 1.1.16.1 mjf printf("Please press any key to reboot.\r\n");
244 1.1.16.1 mjf cngetc();
245 1.1.16.1 mjf }
246 1.1.16.1 mjf
247 1.1.16.1 mjf printf("\r\nrebooting...\r\n");
248 1.1.16.1 mjf reset:
249 1.1.16.1 mjf /*
250 1.1.16.1 mjf * Make really really sure that all interrupts are disabled,
251 1.1.16.1 mjf * and poke the Internal Bus and Peripheral Bus reset lines.
252 1.1.16.1 mjf */
253 1.1.16.1 mjf (void) disable_interrupts(I32_bit|F32_bit);
254 1.1.16.1 mjf STREG(ST_WDMR) = ST_WDMR_EXTEN | ST_WDMR_RSTEN | 1;
255 1.1.16.1 mjf STREG(ST_CR) = ST_CR_WDRST;
256 1.1.16.1 mjf for (;;);
257 1.1.16.1 mjf }
258 1.1.16.1 mjf
259 1.1.16.1 mjf /*
260 1.1.16.1 mjf * u_int initarm(...)
261 1.1.16.1 mjf *
262 1.1.16.1 mjf * Initial entry point on startup. This gets called before main() is
263 1.1.16.1 mjf * entered.
264 1.1.16.1 mjf * It should be responsible for setting up everything that must be
265 1.1.16.1 mjf * in place when main is called.
266 1.1.16.1 mjf * This includes
267 1.1.16.1 mjf * Taking a copy of the boot configuration structure.
268 1.1.16.1 mjf * Initialising the physical console so characters can be printed.
269 1.1.16.1 mjf * Setting up page tables for the kernel
270 1.1.16.1 mjf * Initialising interrupt controllers to a sane default state
271 1.1.16.1 mjf */
272 1.1.16.1 mjf u_int
273 1.1.16.1 mjf initarm(void *arg)
274 1.1.16.1 mjf {
275 1.1.16.1 mjf u_int ret;
276 1.1.16.1 mjf /*
277 1.1.16.1 mjf * basic AT91 initialization:
278 1.1.16.1 mjf */
279 1.1.16.1 mjf if (at91bus_init())
280 1.1.16.1 mjf panic("%s: at91bus_init() failed", __FUNCTION__);
281 1.1.16.1 mjf
282 1.1.16.1 mjf if (AT91_CHIP_ID() == AT91RM9200_CHIP_ID) {
283 1.1.16.1 mjf memcpy(&mpcsabus, at91bus_tag, sizeof(mpcsabus));
284 1.1.16.1 mjf mpcsabus.init = mpcsabus_init;
285 1.1.16.1 mjf mpcsabus.peripheral_clock = mpcsabus_peripheral_clock;
286 1.1.16.1 mjf mpcsabus.gpio_mask = mpcsabus_gpio_mask;
287 1.1.16.1 mjf old_at91bus_tag = at91bus_tag;
288 1.1.16.1 mjf at91bus_tag = &mpcsabus;
289 1.1.16.1 mjf }
290 1.1.16.1 mjf
291 1.1.16.1 mjf /* Fake bootconfig structure for the benefit of pmap.c */
292 1.1.16.1 mjf /* XXX must make the memory description h/w independent */
293 1.1.16.1 mjf bootconfig.dramblocks = 1;
294 1.1.16.1 mjf bootconfig.dram[0].address = 0x20000000UL;
295 1.1.16.1 mjf bootconfig.dram[0].pages = 0x04000000UL / PAGE_SIZE;
296 1.1.16.1 mjf ret = at91bus_setup(&bootconfig);
297 1.1.16.1 mjf
298 1.1.16.1 mjf if (AT91_CHIP_ID() != AT91RM9200_CHIP_ID)
299 1.1.16.1 mjf panic("%s: processor is not AT91RM9200", __FUNCTION__);
300 1.1.16.1 mjf
301 1.1.16.1 mjf /* we've a specific device_register routine */
302 1.1.16.1 mjf evbarm_device_register = mpcsa_device_register;
303 1.1.16.1 mjf
304 1.1.16.1 mjf /* We return the new stack pointer address */
305 1.1.16.1 mjf return ret;
306 1.1.16.1 mjf }
307 1.1.16.1 mjf
308 1.1.16.1 mjf
309 1.1.16.1 mjf bus_dma_tag_t
310 1.1.16.1 mjf at91_bus_dma_init(struct arm32_bus_dma_tag *dma_tag_template)
311 1.1.16.1 mjf {
312 1.1.16.1 mjf int i;
313 1.1.16.1 mjf struct arm32_bus_dma_tag *dmat;
314 1.1.16.1 mjf
315 1.1.16.1 mjf for (i = 0; i < bootconfig.dramblocks; i++) {
316 1.1.16.1 mjf mpcsa_dma_ranges[i].dr_sysbase = bootconfig.dram[i].address;
317 1.1.16.1 mjf mpcsa_dma_ranges[i].dr_busbase = bootconfig.dram[i].address;
318 1.1.16.1 mjf mpcsa_dma_ranges[i].dr_len = bootconfig.dram[i].pages *
319 1.1.16.1 mjf PAGE_SIZE;
320 1.1.16.1 mjf }
321 1.1.16.1 mjf
322 1.1.16.1 mjf dmat = dma_tag_template;
323 1.1.16.1 mjf
324 1.1.16.1 mjf dmat->_ranges = mpcsa_dma_ranges;
325 1.1.16.1 mjf dmat->_nranges = bootconfig.dramblocks;
326 1.1.16.1 mjf
327 1.1.16.1 mjf return dmat;
328 1.1.16.1 mjf }
329 1.1.16.1 mjf
330 1.1.16.1 mjf void mpcsabus_init(struct at91bus_clocks *clocks)
331 1.1.16.1 mjf {
332 1.1.16.1 mjf (*old_at91bus_tag->init)(clocks);
333 1.1.16.1 mjf }
334 1.1.16.1 mjf
335 1.1.16.1 mjf uint32_t mpcsabus_gpio_mask(int pid)
336 1.1.16.1 mjf {
337 1.1.16.1 mjf switch (pid) {
338 1.1.16.1 mjf case PID_PIOA: return ~0x00000300U;
339 1.1.16.1 mjf case PID_PIOB: return ~0x0000783FU;
340 1.1.16.1 mjf case PID_PIOC: return ~0x00000000U;
341 1.1.16.1 mjf case PID_PIOD: return ~0x0003F000U;
342 1.1.16.1 mjf default: return ~0x00000000U;
343 1.1.16.1 mjf }
344 1.1.16.1 mjf }
345 1.1.16.1 mjf
346 1.1.16.1 mjf void mpcsabus_peripheral_clock(int pid, int enable)
347 1.1.16.1 mjf {
348 1.1.16.1 mjf switch (pid) {
349 1.1.16.1 mjf case PID_TWI:
350 1.1.16.1 mjf if (enable) {
351 1.1.16.1 mjf PIOA_WRITE(PIO_ASR, 0x06000000); // assign to peripheral A
352 1.1.16.1 mjf PIOA_WRITE(PIO_PDR, 0x06000000); // assign to peripherals
353 1.1.16.1 mjf PIOA_WRITE(PIO_MDER, 0x06000000); // I2C pins in open-drain mode
354 1.1.16.1 mjf }
355 1.1.16.1 mjf break;
356 1.1.16.1 mjf
357 1.1.16.1 mjf case PID_SPI:
358 1.1.16.1 mjf if (enable) {
359 1.1.16.1 mjf PIOA_WRITE(PIO_ASR, 0x00000007); // assign to peripheral A
360 1.1.16.1 mjf PIOA_WRITE(PIO_PDR, 0x00000007); // assign to peripherals
361 1.1.16.1 mjf }
362 1.1.16.1 mjf break;
363 1.1.16.1 mjf }
364 1.1.16.1 mjf (*old_at91bus_tag->peripheral_clock)(pid, enable);
365 1.1.16.1 mjf }
366 1.1.16.1 mjf
367 1.1.16.1 mjf
368 1.1.16.1 mjf static void mpcsa_device_register(device_t dev, void *aux)
369 1.1.16.1 mjf {
370 1.1.16.1 mjf static uint8_t eth_addr[ETHER_ADDR_LEN];
371 1.1.16.1 mjf
372 1.1.16.1 mjf if (device_is_a(dev, "at91emac")) {
373 1.1.16.1 mjf cfdriver_t cd = config_cfdriver_lookup("at91twi");
374 1.1.16.1 mjf device_t twi_dev = 0;
375 1.1.16.1 mjf i2c_tag_t i2c = 0;
376 1.1.16.1 mjf if (cd && (twi_dev = device_lookup(cd, 0)) != NULL) {
377 1.1.16.1 mjf struct at91twi_softc *sc = (struct at91twi_softc *)twi_dev;
378 1.1.16.1 mjf i2c = &sc->sc_i2c;
379 1.1.16.1 mjf }
380 1.1.16.1 mjf if (i2c && seeprom_bootstrap_read(i2c, 0x50, 0x00, 4096,
381 1.1.16.1 mjf eth_addr, ETHER_ADDR_LEN) == 0) {
382 1.1.16.1 mjf prop_data_t pd = prop_data_create_data_nocopy(
383 1.1.16.1 mjf eth_addr, ETHER_ADDR_LEN);
384 1.1.16.1 mjf KASSERT(pd != NULL);
385 1.1.16.1 mjf if (prop_dictionary_set(device_properties(dev),
386 1.1.16.1 mjf "mac-addr", pd) == FALSE) {
387 1.1.16.1 mjf printf("WARNING: unable to set mac-addr property "
388 1.1.16.1 mjf "for %s\n", dev->dv_xname);
389 1.1.16.1 mjf }
390 1.1.16.1 mjf } else {
391 1.1.16.1 mjf printf("%s: WARNING: unable to read MAC address from SEEPROM\n",
392 1.1.16.1 mjf dev->dv_xname);
393 1.1.16.1 mjf }
394 1.1.16.1 mjf }
395 1.1.16.1 mjf }
396 1.1.16.1 mjf
397