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