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