xref: /netbsd-src/sys/arch/evbarm/netwalker/netwalker_machdep.c (revision f3cfa6f6ce31685c6c4a758bc430e69eb99f50a4)
1 /*	$NetBSD: netwalker_machdep.c,v 1.23 2019/01/21 07:47:30 skrll Exp $	*/
2 
3 /*
4  * Copyright (c) 2002, 2003, 2005, 2010  Genetec Corporation.
5  * All rights reserved.
6  * Written by Hiroyuki Bessho for Genetec Corporation.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Machine dependent functions for kernel setup for Sharp Netwalker.
30  * Based on iq80310_machhdep.c
31  */
32 /*
33  * Copyright (c) 2001 Wasabi Systems, Inc.
34  * All rights reserved.
35  *
36  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. All advertising materials mentioning features or use of this software
47  *    must display the following acknowledgement:
48  *	This product includes software developed for the NetBSD Project by
49  *	Wasabi Systems, Inc.
50  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
51  *    or promote products derived from this software without specific prior
52  *    written permission.
53  *
54  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
55  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
56  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
58  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64  * POSSIBILITY OF SUCH DAMAGE.
65  */
66 
67 /*
68  * Copyright (c) 1997,1998 Mark Brinicombe.
69  * Copyright (c) 1997,1998 Causality Limited.
70  * All rights reserved.
71  *
72  * Redistribution and use in source and binary forms, with or without
73  * modification, are permitted provided that the following conditions
74  * are met:
75  * 1. Redistributions of source code must retain the above copyright
76  *    notice, this list of conditions and the following disclaimer.
77  * 2. Redistributions in binary form must reproduce the above copyright
78  *    notice, this list of conditions and the following disclaimer in the
79  *    documentation and/or other materials provided with the distribution.
80  * 3. All advertising materials mentioning features or use of this software
81  *    must display the following acknowledgement:
82  *	This product includes software developed by Mark Brinicombe
83  *	for the NetBSD Project.
84  * 4. The name of the company nor the name of the author may be used to
85  *    endorse or promote products derived from this software without specific
86  *    prior written permission.
87  *
88  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
89  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
90  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
91  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
92  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
93  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
94  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
95  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
96  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
97  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
98  * SUCH DAMAGE.
99  *
100  * Machine dependent functions for kernel setup for Intel IQ80310 evaluation
101  * boards using RedBoot firmware.
102  */
103 
104 #include <sys/cdefs.h>
105 __KERNEL_RCSID(0, "$NetBSD: netwalker_machdep.c,v 1.23 2019/01/21 07:47:30 skrll Exp $");
106 
107 #include "opt_evbarm_boardtype.h"
108 #include "opt_arm_debug.h"
109 #include "opt_console.h"
110 #include "opt_cputypes.h"
111 #include "opt_ddb.h"
112 #include "opt_kgdb.h"
113 #include "opt_md.h"
114 #include "opt_com.h"
115 #include "imxuart.h"
116 #include "opt_imxuart.h"
117 #include "opt_imx.h"
118 #include "opt_imx51_ipuv3.h"
119 #include "opt_machdep.h"
120 
121 #include <sys/param.h>
122 #include <sys/device.h>
123 #include <sys/reboot.h>
124 #include <sys/termios.h>
125 #include <sys/bus.h>
126 
127 #include "genfb.h"
128 #include "netwalker_backlight.h"
129 #include "netwalker_backlightvar.h"
130 
131 #include <machine/db_machdep.h>
132 #ifdef KGDB
133 #include <sys/kgdb.h>
134 #endif
135 
136 #include <machine/bootconfig.h>
137 #include <machine/autoconf.h>
138 
139 #include <arm/arm32/machdep.h>
140 
141 #include <arm/imx/imx51reg.h>
142 #include <arm/imx/imx51var.h>
143 #include <arm/imx/imxgpioreg.h>
144 #include <arm/imx/imxwdogreg.h>
145 #include <arm/imx/imxuartreg.h>
146 #include <arm/imx/imxuartvar.h>
147 #include <arm/imx/imx51_iomuxreg.h>
148 #include <arm/imx/imxgpiovar.h>
149 
150 #include <evbarm/netwalker/netwalker_reg.h>
151 #include <evbarm/netwalker/netwalker.h>
152 
153 #include "ukbd.h"
154 #if (NUKBD > 0)
155 #include <dev/usb/ukbdvar.h>
156 #endif
157 
158 /* Kernel text starts 1MB in from the bottom of the kernel address space. */
159 #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00100000)
160 
161 BootConfig bootconfig;		/* Boot config storage */
162 static char bootargs[MAX_BOOT_STRING] = BOOT_ARGS;
163 char *boot_args = NULL;
164 
165 extern char KERNEL_BASE_phys[];
166 
167 extern int cpu_do_powersave;
168 
169 /*
170  * Macros to translate between physical and virtual for a subset of the
171  * kernel address space.  *Not* for general use.
172  */
173 #define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys)
174 
175 
176 /* Prototypes */
177 
178 void consinit(void);
179 
180 #ifdef KGDB
181 void	kgdb_port_init(void);
182 #endif
183 
184 static void init_clocks(void);
185 static void setup_ioports(void);
186 
187 static void netwalker_device_register(device_t, void *);
188 
189 #ifndef CONSPEED
190 #define CONSPEED B115200	/* What RedBoot uses */
191 #endif
192 #ifndef CONMODE
193 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
194 #endif
195 
196 int comcnspeed = CONSPEED;
197 int comcnmode = CONMODE;
198 
199 /*
200  * Static device mappings. These peripheral registers are mapped at
201  * fixed virtual addresses very early in netwalker_start() so that we
202  * can use them while booting the kernel, and stay at the same address
203  * throughout whole kernel's life time.
204  *
205  * We use this table twice; once with bootstrap page table, and once
206  * with kernel's page table which we build up in initarm().
207  */
208 
209 #define _A(a)   ((a) & ~L1_S_OFFSET)
210 #define _S(s)   (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
211 
212 static const struct pmap_devmap netwalker_devmap[] = {
213 	{
214 		/* for UART1, IOMUXC */
215 		.pd_va = _A(NETWALKER_IO_VBASE0),
216 		.pd_pa = _A(NETWALKER_IO_PBASE0),
217 		.pd_size = _S(L1_S_SIZE * 4),
218 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
219 		.pd_cache = PTE_NOCACHE
220 	},
221 	{0}
222 };
223 
224 #undef	_A
225 #undef	_S
226 
227 #ifndef MEMSTART
228 #define MEMSTART	0x90000000
229 #endif
230 #ifndef MEMSIZE
231 #define MEMSIZE		512
232 #endif
233 
234 /*
235  * u_int initarm(...)
236  *
237  * Initial entry point on startup. This gets called before main() is
238  * entered.
239  * It should be responsible for setting up everything that must be
240  * in place when main is called.
241  * This includes
242  *   Taking a copy of the boot configuration structure.
243  *   Initialising the physical console so characters can be printed.
244  *   Setting up page tables for the kernel
245  *   Relocating the kernel to the bottom of physical memory
246  */
247 u_int
248 initarm(void *arg)
249 {
250 	/*
251 	 * Heads up ... Setup the CPU / MMU / TLB functions
252 	 */
253 	if (set_cpufuncs())
254 		panic("cpu not recognized!");
255 
256 	/* map some peripheral registers */
257 	pmap_devmap_bootstrap((vaddr_t)armreg_ttbr_read() & -L1_TABLE_SIZE,
258 	    netwalker_devmap);
259 
260 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
261 
262 	setup_ioports();
263 
264 	consinit();
265 
266 #ifdef	NO_POWERSAVE
267 	cpu_do_powersave=0;
268 #endif
269 
270 	init_clocks();
271 
272 #ifdef KGDB
273 	kgdb_port_init();
274 #endif
275 
276 	/* Talk to the user */
277 	printf("\nNetBSD/evbarm (" ___STRING(EVBARM_BOARDTYPE) ") booting ...\n");
278 
279 #ifdef BOOT_ARGS
280 	char mi_bootargs[] = BOOT_ARGS;
281 	parse_mi_bootargs(mi_bootargs);
282 #endif
283 
284 #if defined(VERBOSE_INIT_ARM) || 1
285 	printf("initarm: Configuring system");
286 	printf(", CLIDR=%010o CTR=%#x",
287 	    armreg_clidr_read(), armreg_ctr_read());
288 	printf("\n");
289 #endif
290 	/*
291 	 * Ok we have the following memory map
292 	 *
293 	 * Physical Address Range     Description
294 	 * -----------------------    ----------------------------------
295 	 *
296 	 * 0x90000000 - 0xAFFFFFFF    DDR SDRAM (512MByte)
297 	 *
298 	 * The initarm() has the responsibility for creating the kernel
299 	 * page tables.
300 	 * It must also set up various memory pointers that are used
301 	 * by pmap etc.
302 	 */
303 
304 #ifdef VERBOSE_INIT_ARM
305 	printf("initarm: Configuring system ...\n");
306 #endif
307 	/* Fake bootconfig structure for the benefit of pmap.c */
308 	/* XXX must make the memory description h/w independent */
309 	bootconfig.dramblocks = 1;
310 	bootconfig.dram[0].address = MEMSTART;
311 	bootconfig.dram[0].pages = (MEMSIZE * 1024 * 1024) / PAGE_SIZE;
312 
313 	psize_t ram_size = bootconfig.dram[0].pages * PAGE_SIZE;
314 
315 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
316 	if (ram_size > KERNEL_VM_BASE - KERNEL_BASE) {
317 		printf("%s: dropping RAM size from %luMB to %uMB\n",
318 		    __func__, (unsigned long) (ram_size >> 20),
319 		    (KERNEL_VM_BASE - KERNEL_BASE) >> 20);
320 		ram_size = KERNEL_VM_BASE - KERNEL_BASE;
321 	}
322 #endif
323 
324 	arm32_bootmem_init(bootconfig.dram[0].address, ram_size,
325 	    KERNEL_BASE_PHYS);
326 
327 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
328 	const bool mapallmem_p = true;
329 	KASSERT(ram_size <= KERNEL_VM_BASE - KERNEL_BASE);
330 #else
331 	const bool mapallmem_p = false;
332 #endif
333 
334 	arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0,
335 	    netwalker_devmap, mapallmem_p);
336 
337 	/* disable power down counter in watch dog,
338 	   This must be done within 16 seconds of start-up. */
339 	ioreg16_write(NETWALKER_WDOG_VBASE + IMX_WDOG_WMCR, 0);
340 
341 #ifdef BOOTHOWTO
342 	boothowto |= BOOTHOWTO;
343 #endif
344 
345 	boot_args = bootargs;
346 	parse_mi_bootargs(boot_args);
347 	printf("boot_args : %s\n", boot_args);
348 
349 	/* we've a specific device_register routine */
350 	evbarm_device_register = netwalker_device_register;
351 
352 #ifdef VERBOSE_INIT_ARM
353 	printf("initarm done.\n");
354 #endif
355 	return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0);
356 }
357 
358 
359 static void
360 init_clocks(void)
361 {
362 	cortex_pmc_ccnt_init();
363 }
364 
365 struct iomux_setup {
366 	/* iomux registers are 32-bit wide, but upper 16 bits are not
367 	 * used. */
368 	uint16_t	reg;
369 	uint16_t	val;
370 };
371 
372 #define	IOMUX_M(padname, mux)		\
373 	IOMUX_DATA(__CONCAT(IOMUXC_SW_MUX_CTL_PAD_,padname), mux)
374 
375 #define	IOMUX_P(padname, pad)		\
376 	IOMUX_DATA(__CONCAT(IOMUXC_SW_PAD_CTL_PAD_,padname), pad)
377 
378 #define	IOMUX_MP(padname, mux, pad)	\
379 	IOMUX_M(padname, mux), \
380 	IOMUX_P(padname, pad)
381 
382 
383 #define	IOMUX_DATA(offset, value)	\
384 	{				\
385 		.reg = (offset),	\
386 		.val = (value),		\
387 	}
388 
389 
390 /*
391  * set same values to IOMUX registers as linux kernel does
392  */
393 const struct iomux_setup iomux_setup_data[] = {
394 #define	HYS	PAD_CTL_HYS
395 #define	ODE	PAD_CTL_ODE
396 #define	DSEHIGH	PAD_CTL_DSE_HIGH
397 #define	DSEMID	PAD_CTL_DSE_MID
398 #define	DSELOW	PAD_CTL_DSE_LOW
399 #define	DSEMAX	PAD_CTL_DSE_MAX
400 #define	SRE	PAD_CTL_SRE
401 #define	KEEPER	PAD_CTL_KEEPER
402 #define	PULL	PAD_CTL_PULL
403 #define	PU_22K	PAD_CTL_PUS_22K_PU
404 #define	PU_47K	PAD_CTL_PUS_47K_PU
405 #define	PU_100K	PAD_CTL_PUS_100K_PU
406 #define	PD_100K	PAD_CTL_PUS_100K_PD
407 #define	HVE	PAD_CTL_HVE	/* Low output voltage */
408 
409 #define	ALT0	IOMUX_CONFIG_ALT0
410 #define	ALT1	IOMUX_CONFIG_ALT1
411 #define	ALT2	IOMUX_CONFIG_ALT2
412 #define	ALT3	IOMUX_CONFIG_ALT3
413 #define	ALT4	IOMUX_CONFIG_ALT4
414 #define	ALT5	IOMUX_CONFIG_ALT5
415 #define	ALT6	IOMUX_CONFIG_ALT6
416 #define	ALT7	IOMUX_CONFIG_ALT7
417 #define	SION	IOMUX_CONFIG_SION
418 
419 	/* left button */
420 	IOMUX_MP(EIM_EB2, ALT1, HYS),
421 	/* right button */
422 	IOMUX_MP(EIM_EB3, ALT1, HYS),
423 
424 	/* UART1 */
425 	IOMUX_MP(UART1_RXD, ALT0, HYS | PULL | DSEHIGH | SRE),
426 	IOMUX_MP(UART1_TXD, ALT0, HYS | PULL | DSEHIGH | SRE),
427 	IOMUX_MP(UART1_RTS, ALT0, HYS | PULL | DSEHIGH),
428 	IOMUX_MP(UART1_CTS, ALT0, HYS | PULL | DSEHIGH),
429 
430 	/* LCD Display */
431 	IOMUX_M(DI1_PIN2, ALT0),
432 	IOMUX_M(DI1_PIN3, ALT0),
433 
434 	IOMUX_DATA(IOMUXC_SW_PAD_CTL_GRP_DISP1_PKE0, PAD_CTL_PKE),
435 #if 0
436 	IOMUX_MP(DISP1_DAT0, ALT0, SRE | DSEMAX | PULL),
437 	IOMUX_MP(DISP1_DAT1, ALT0, SRE | DSEMAX | PULL),
438 	IOMUX_MP(DISP1_DAT2, ALT0, SRE | DSEMAX | PULL),
439 	IOMUX_MP(DISP1_DAT3, ALT0, SRE | DSEMAX | PULL),
440 	IOMUX_MP(DISP1_DAT4, ALT0, SRE | DSEMAX | PULL),
441 	IOMUX_MP(DISP1_DAT5, ALT0, SRE | DSEMAX | PULL),
442 #endif
443 	IOMUX_M(DISP1_DAT6, ALT0),
444 	IOMUX_M(DISP1_DAT7, ALT0),
445 	IOMUX_M(DISP1_DAT8, ALT0),
446 	IOMUX_M(DISP1_DAT9, ALT0),
447 	IOMUX_M(DISP1_DAT10, ALT0),
448 	IOMUX_M(DISP1_DAT11, ALT0),
449 	IOMUX_M(DISP1_DAT12, ALT0),
450 	IOMUX_M(DISP1_DAT13, ALT0),
451 	IOMUX_M(DISP1_DAT14, ALT0),
452 	IOMUX_M(DISP1_DAT15, ALT0),
453 	IOMUX_M(DISP1_DAT16, ALT0),
454 	IOMUX_M(DISP1_DAT17, ALT0),
455 	IOMUX_M(DISP1_DAT18, ALT0),
456 	IOMUX_M(DISP1_DAT19, ALT0),
457 	IOMUX_M(DISP1_DAT20, ALT0),
458 	IOMUX_M(DISP1_DAT21, ALT0),
459 	IOMUX_M(DISP1_DAT22, ALT0),
460 	IOMUX_M(DISP1_DAT23, ALT0),
461 
462 	IOMUX_MP(DI1_D0_CS, ALT4, KEEPER | DSEHIGH | SRE), /* GPIO3_3 */
463 	IOMUX_DATA(IOMUXC_GPIO3_IPP_IND_G_IN_3_SELECT_INPUT, INPUT_DAISY_0),
464 	IOMUX_MP(CSI2_D12, ALT3, KEEPER | DSEHIGH | SRE), /* GPIO4_9 */
465 	IOMUX_MP(CSI2_D13, ALT3, KEEPER | DSEHIGH | SRE),
466 	IOMUX_MP(GPIO1_2, ALT1, DSEHIGH | ODE),	/* LCD backlight by PWM */
467 
468 	IOMUX_MP(EIM_A19, ALT1, SRE | DSEHIGH),	/* GPIO2_13 */
469 
470 	/* XXX VGA pins */
471 	IOMUX_M(DI_GP4, ALT4),
472 	IOMUX_MP(GPIO1_8, SION | ALT0, HYS | DSEMID | PU_100K),
473 
474 	/* I2C1 */
475 	IOMUX_MP(EIM_D16, SION | ALT4, HYS | ODE | DSEHIGH | SRE),	/* SDA */
476 	IOMUX_MP(EIM_D19, SION | ALT4, SRE),			       	/* SCL */
477 	IOMUX_DATA(IOMUXC_I2C1_IPP_SDA_IN_SELECT_INPUT, INPUT_DAISY_0),
478 	IOMUX_DATA(IOMUXC_I2C1_IPP_SCL_IN_SELECT_INPUT, INPUT_DAISY_0),
479 
480 	IOMUX_M(EIM_A23, ALT1),	/* GPIO2_17 */
481 
482 	/* BT */
483 	IOMUX_M(EIM_D20, ALT1),	/* GPIO2_4 BT host wakeup */
484 	IOMUX_M(EIM_D22, ALT1),	/* GPIO2_6 BT RESET */
485 	IOMUX_M(EIM_D23, ALT1),	/* GPIO2_7 BT wakeup */
486 
487 	/* UART3 */
488 	IOMUX_MP(EIM_D24, ALT3, KEEPER | PU_100K | DSEHIGH | SRE),
489 	IOMUX_MP(EIM_D25, ALT3, KEEPER | PU_100K | DSEHIGH | SRE), /* CTS */
490 	IOMUX_MP(EIM_D26, ALT3, KEEPER | PU_100K | DSEHIGH | SRE), /* TXD */
491 	IOMUX_MP(EIM_D27, ALT3, KEEPER | PU_100K | DSEHIGH | SRE), /* RTS */
492 	IOMUX_M(NANDF_D15, ALT3),	/* GPIO3_25 */
493 	IOMUX_MP(NANDF_D14, ALT3, HYS | PULL | PU_100K ),	/* GPIO3_26 */
494 	IOMUX_DATA(IOMUXC_UART3_IPP_UART_RTS_B_SELECT_INPUT, INPUT_DAISY_3),
495 
496 	/* OJ6SH-T25 */
497 	IOMUX_M(CSI1_D9, ALT3),			/* GPIO3_13 */
498 	IOMUX_M(CSI1_VSYNC, ALT3),		/* GPIO3_14 */
499 	IOMUX_M(CSI1_HSYNC, ALT3),		/* GPIO3_15 */
500 
501 	/* audio pins */
502 	IOMUX_MP(AUD3_BB_TXD, ALT0, DSEHIGH | PU_100K | SRE),
503 		/* XXX: linux code:
504 		   (PAD_CTL_SRE_FAST	     | PAD_CTL_DRV_HIGH |
505 		   PAD_CTL_100K_PU	     | PAD_CTL_HYS_NONE |
506 		   PAD_CTL_DDR_INPUT_CMOS | PAD_CTL_DRV_VOT_LOW), */
507 
508 	IOMUX_MP(AUD3_BB_RXD, ALT0, KEEPER | DSEHIGH | SRE),
509 	IOMUX_MP(AUD3_BB_CK, ALT0, KEEPER | DSEHIGH | SRE),
510 	IOMUX_MP(AUD3_BB_FS, ALT0, KEEPER | DSEHIGH | SRE),
511 
512 	/* headphone detect */
513 	IOMUX_MP(NANDF_D14, ALT3, HYS | PULL | PU_100K),
514 	IOMUX_MP(CSPI1_RDY, ALT3, SRE | DSEHIGH),
515 	/* XXX more audio pins ? */
516 
517 	/* CSPI */
518 	IOMUX_MP(CSPI1_MOSI, ALT0, HYS | PULL | PD_100K | DSEHIGH | SRE),
519 	IOMUX_MP(CSPI1_MISO, ALT0, HYS | PULL | PD_100K | DSEHIGH | SRE),
520 	IOMUX_MP(CSPI1_SCLK, ALT0, HYS | PULL | PD_100K | DSEHIGH | SRE),
521 
522 	/* SPI CS */
523 	IOMUX_MP(CSPI1_SS0, ALT3, HYS | KEEPER | DSEHIGH | SRE), /* GPIO4[24] */
524 	IOMUX_MP(CSPI1_SS1, ALT3, HYS | KEEPER | DSEHIGH | SRE), /* GPIO4[25] */
525 	IOMUX_MP(DI1_PIN11, ALT4, HYS | PULL | DSEHIGH | SRE),   /* GPIO3[0] */
526 
527 	/* 26M Osc */
528 	IOMUX_MP(DI1_PIN12, ALT4, KEEPER | DSEHIGH | SRE), /* GPIO3_1 */
529 
530 	/* I2C2 */
531 	IOMUX_MP(KEY_COL5, SION | ALT3, HYS | ODE | DSEHIGH | SRE),	/* SDA */
532 	IOMUX_MP(KEY_COL4, SION | ALT3, SRE),				/* SCL */
533 	IOMUX_DATA(IOMUXC_I2C2_IPP_SCL_IN_SELECT_INPUT, INPUT_DAISY_1),
534 	IOMUX_DATA(IOMUXC_I2C2_IPP_SDA_IN_SELECT_INPUT, INPUT_DAISY_1),
535 
536 	/* NAND */
537 	IOMUX_MP(NANDF_WE_B, ALT0, HVE | DSEHIGH | PULL | PU_47K),
538 	IOMUX_MP(NANDF_RE_B, ALT0, HVE | DSEHIGH | PULL | PU_47K),
539 	IOMUX_MP(NANDF_ALE, ALT0, HVE | DSEHIGH | KEEPER),
540 	IOMUX_MP(NANDF_CLE, ALT0, HVE | DSEHIGH | KEEPER),
541 	IOMUX_MP(NANDF_WP_B, ALT0, HVE | DSEHIGH | PULL | PU_100K),
542 	IOMUX_MP(NANDF_RB0, ALT0, HVE | DSELOW | PULL | PU_100K),
543 	IOMUX_MP(NANDF_RB1, ALT0, HVE | DSELOW | PULL | PU_100K),
544 	IOMUX_MP(NANDF_D7, ALT0, HVE | DSEHIGH | KEEPER | PU_100K),
545 	IOMUX_MP(NANDF_D6, ALT0, HVE | DSEHIGH | KEEPER | PU_100K),
546 	IOMUX_MP(NANDF_D5, ALT0, HVE | DSEHIGH | KEEPER | PU_100K),
547 	IOMUX_MP(NANDF_D4, ALT0, HVE | DSEHIGH | KEEPER | PU_100K),
548 	IOMUX_MP(NANDF_D3, ALT0, HVE | DSEHIGH | KEEPER | PU_100K),
549 	IOMUX_MP(NANDF_D2, ALT0, HVE | DSEHIGH | KEEPER | PU_100K),
550 	IOMUX_MP(NANDF_D1, ALT0, HVE | DSEHIGH | KEEPER | PU_100K),
551 	IOMUX_MP(NANDF_D0, ALT0, HVE | DSEHIGH | KEEPER | PU_100K),
552 
553 	/* Batttery pins */
554 	IOMUX_MP(NANDF_D13, ALT3, HYS | DSEHIGH),
555 	IOMUX_MP(NANDF_D12, ALT3, HYS | DSEHIGH),
556 #if 0
557 	IOMUX_MP(NANDF_D11, ALT3, HYS | DSEHIGH),
558 #endif
559 	IOMUX_MP(NANDF_D10, ALT3, HYS | DSEHIGH),
560 
561 	/* SD1 */
562 	IOMUX_MP(SD1_CMD, SION | ALT0, DSEHIGH | SRE),
563 	IOMUX_MP(SD1_CLK, SION | ALT0, KEEPER | PU_47K | DSEHIGH),
564 	IOMUX_MP(SD1_DATA0, ALT0, DSEHIGH | SRE),
565 	IOMUX_MP(SD1_DATA1, ALT0, DSEHIGH | SRE),
566 	IOMUX_MP(SD1_DATA2, ALT0, DSEHIGH | SRE),
567 	IOMUX_MP(SD1_DATA3, ALT0, DSEHIGH | SRE),
568 	IOMUX_MP(GPIO1_0, SION | ALT0, HYS | PU_100K),
569 
570 	/* SD2 */
571 	IOMUX_P(SD2_CMD, HVE | PU_22K | DSEMAX | SRE),
572 	IOMUX_P(SD2_CLK, HVE | PU_22K | DSEMAX | SRE),
573 	IOMUX_P(SD2_DATA0, HVE | PU_22K | DSEMAX | SRE),
574 	IOMUX_P(SD2_DATA1, HVE | PU_22K | DSEMAX | SRE),
575 	IOMUX_P(SD2_DATA2, HVE | PU_22K | DSEMAX | SRE),
576 	IOMUX_P(SD2_DATA3, HVE | PU_22K | DSEMAX | SRE),
577 
578 	/* USB */
579 	IOMUX_MP(USBH1_CLK, ALT0, HYS | KEEPER | DSEHIGH | SRE),
580 	IOMUX_MP(USBH1_DIR, ALT0, HYS | KEEPER | DSEHIGH | SRE),
581 	IOMUX_MP(USBH1_STP, ALT0, HYS | KEEPER | DSEHIGH | SRE),
582 	IOMUX_MP(USBH1_NXT, ALT0, HYS | KEEPER | PU_100K | DSEHIGH | SRE),
583 	IOMUX_MP(USBH1_DATA0, ALT0, HYS | KEEPER | DSEHIGH | SRE),
584 	IOMUX_MP(USBH1_DATA1, ALT0, HYS | KEEPER | DSEHIGH | SRE),
585 	IOMUX_MP(USBH1_DATA2, ALT0, HYS | KEEPER | DSEHIGH | SRE),
586 	IOMUX_MP(USBH1_DATA3, ALT0, HYS | KEEPER | DSEHIGH | SRE),
587 	IOMUX_MP(USBH1_DATA4, ALT0, HYS | KEEPER | DSEHIGH | SRE),
588 	IOMUX_MP(USBH1_DATA5, ALT0, HYS | KEEPER | DSEHIGH | SRE),
589 	IOMUX_MP(USBH1_DATA6, ALT0, HYS | KEEPER | DSEHIGH | SRE),
590 	IOMUX_MP(USBH1_DATA7, ALT0, HYS | KEEPER | DSEHIGH | SRE),
591 	IOMUX_MP(EIM_D17, ALT1, KEEPER | DSEHIGH | SRE),
592 	IOMUX_MP(EIM_D21, ALT1, KEEPER | DSEHIGH | SRE),
593 	IOMUX_P(GPIO1_7, /*ALT0,*/ DSEHIGH | SRE),	/* USB Hub reset */
594 
595 #undef	ODE
596 #undef	HYS
597 #undef	SRE
598 #undef	PULL
599 #undef	KEEPER
600 #undef	PU_22K
601 #undef	PU_47K
602 #undef	PU_100K
603 #undef	PD_100K
604 #undef	HVE
605 #undef	DSEMAX
606 #undef	DSEHIGH
607 #undef	DSEMID
608 #undef	DSELOW
609 
610 #undef	ALT0
611 #undef	ALT1
612 #undef	ALT2
613 #undef	ALT3
614 #undef	ALT4
615 #undef	ALT5
616 #undef	ALT6
617 #undef	ALT7
618 #undef	SION
619 };
620 
621 static void
622 setup_ioports(void)
623 {
624 	int i;
625 	const struct iomux_setup *p;
626 
627 	/* Initialize all IOMUX registers */
628 	for (i=0; i < __arraycount(iomux_setup_data); ++i) {
629 		p = iomux_setup_data + i;
630 
631 		ioreg_write(NETWALKER_IOMUXC_VBASE + p->reg,
632 			    p->val);
633 	}
634 }
635 
636 
637 #ifdef	CONSDEVNAME
638 const char consdevname[] = CONSDEVNAME;
639 
640 #ifndef	CONMODE
641 #define	CONMODE	((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
642 #endif
643 #ifndef	CONSPEED
644 #define	CONSPEED	115200
645 #endif
646 
647 int consmode = CONMODE;
648 int consrate = CONSPEED;
649 
650 #endif	/* CONSDEVNAME */
651 
652 #ifndef	IMXUART_FREQ
653 #define	IMXUART_FREQ	66500000
654 #endif
655 
656 void
657 consinit(void)
658 {
659 	static int consinit_called = 0;
660 
661 	if (consinit_called)
662 		return;
663 
664 	consinit_called = 1;
665 
666 #ifdef	CONSDEVNAME
667 
668 #if NIMXUART > 0
669 	imxuart_set_frequency(IMXUART_FREQ, 2);
670 #endif
671 
672 #if (NIMXUART > 0) && defined(IMXUARTCONSOLE)
673 	if (strcmp(consdevname, "imxuart") == 0) {
674 		paddr_t consaddr;
675 #ifdef	CONADDR
676 		consaddr = CONADDR;
677 #else
678 		consaddr = IMX51_UART1_BASE;
679 #endif
680 		imxuart_cnattach(&armv7_generic_bs_tag, consaddr, consrate, consmode);
681 		return;
682 	}
683 #endif
684 #endif
685 }
686 
687 static void
688 netwalker_device_register(device_t self, void *aux)
689 {
690 	prop_dictionary_t dict = device_properties(self);
691 
692 #if NGENFB > 0
693 	if (device_is_a(self, "genfb")) {
694 		char *ptr;
695 		if (get_bootconf_option(boot_args, "console",
696 		    BOOTOPT_TYPE_STRING, &ptr) && strncmp(ptr, "fb", 2) == 0) {
697 			prop_dictionary_set_bool(dict, "is_console", true);
698 #if NUKBD > 0
699 			ukbd_cnattach();
700 #endif
701 		} else {
702 			prop_dictionary_set_bool(dict, "is_console", false);
703 		}
704 #if NNETWALKER_BACKLIGHT > 0
705 		netwalker_backlight_genfb_parameter_set(dict);
706 #endif
707 	}
708 #endif
709 }
710 
711 #ifdef KGDB
712 #ifndef KGDB_DEVNAME
713 #define KGDB_DEVNAME "imxuart"
714 #endif
715 #ifndef KGDB_DEVMODE
716 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
717 #endif
718 
719 const char kgdb_devname[20] = KGDB_DEVNAME;
720 int kgdb_mode = KGDB_DEVMODE;
721 int kgdb_addr = KGDB_DEVADDR;
722 extern int kgdb_rate;	/* defined in kgdb_stub.c */
723 
724 void
725 kgdb_port_init(void)
726 {
727 #if (NIMXUART > 0)
728 	if (strcmp(kgdb_devname, "imxuart") == 0) {
729 		imxuart_kgdb_attach(&armv7_generic_bs_tag, kgdb_addr,
730 		kgdb_rate, kgdb_mode);
731 	    return;
732 	}
733 
734 #endif
735 }
736 #endif
737 
738 
739