Home | History | Annotate | Line # | Download | only in hpcarm
      1 /*	$NetBSD: netbookpro_machdep.c,v 1.4 2023/09/09 07:07:03 andvar Exp $	*/
      2 /*
      3  * Copyright (c) 2011 KIYOHARA Takashi
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     23  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     24  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  * POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 #include <sys/cdefs.h>
     28 __KERNEL_RCSID(0, "$NetBSD: netbookpro_machdep.c,v 1.4 2023/09/09 07:07:03 andvar Exp $");
     29 
     30 #include <sys/systm.h>
     31 #include <sys/device.h>
     32 #include <sys/mutex.h>
     33 #include <sys/param.h>
     34 
     35 #include <uvm/uvm.h>
     36 
     37 #include <machine/bootconfig.h>
     38 #include <machine/pmap.h>
     39 
     40 #include <arm/xscale/pxa2x0_gpio.h>
     41 
     42 #include <hpcarm/dev/nbppconvar.h>
     43 
     44 #include <dev/cons.h>
     45 #include <dev/i2c/i2cvar.h>
     46 
     47 #include "nbppcon.h"
     48 
     49 #include "biconsdev.h"
     50 #if NBICONSDEV > 0
     51 #include <dev/hpc/bicons.h>
     52 cons_decl(bicons);
     53 #endif
     54 #include "wsdisplay.h"
     55 #if NWSDISPLAY == 0
     56 #include <dev/wscons/wskbdvar.h>
     57 #endif
     58 
     59 static void netbookpro_reset(void);
     60 void pxa2x0_machdep_init(void);
     61 
     62 static int __unused enable_console(void (*)(struct consdev *),
     63 				   void (*)(struct consdev *));
     64 static void disable_consoles(void);
     65 static void cn_nonprobe(struct consdev *);
     66 
     67 const struct pmap_devmap machdep_devmap[] = {
     68 	/* Framebuffer */
     69 	DEVMAP_ENTRY(
     70 		0x14000000,
     71 		0x14000000,
     72 		0x00400000
     73 	),
     74 	DEVMAP_ENTRY_END
     75 };
     76 
     77 static struct pxa2x0_gpioconf netbookpro_boarddep_gpioconf[] = {
     78 	{  6, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* MMCCLK */
     79 	{  8, GPIO_CLR | GPIO_ALT_FN_1_OUT },	/* MMCCS0 */
     80 	{ 52, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* nPCE1 */
     81 	{ 53, GPIO_CLR | GPIO_ALT_FN_2_OUT },	/* nPCE2 */
     82 	{ -1 }
     83 };
     84 
     85 static struct pxa2x0_gpioconf *netbookpro_gpioconf[] = {
     86 	pxa25x_pcic_gpioconf,
     87 	netbookpro_boarddep_gpioconf,
     88 	NULL
     89 };
     90 
     91 static void
     92 netbookpro_reset(void)
     93 {
     94 	device_t pcon;
     95 
     96 	pcon = device_find_by_xname("nbppcon0");
     97 #if NNBPPCON > 0
     98 	if (pcon != NULL)
     99 		nbppcon_pwr_hwreset(pcon);
    100 #endif
    101 
    102 	while (1 /*CONSTCOND*/);
    103 
    104 	/* NOTREACHED */
    105 }
    106 
    107 void
    108 pxa2x0_machdep_init(void)
    109 {
    110 	extern void (*__cpu_reset)(void);
    111 	extern void (*__sleep_func)(void *);
    112 	extern BootConfig bootconfig;		/* Boot config storage */
    113 
    114 
    115 	__cpu_reset = netbookpro_reset;
    116 	__sleep_func = NULL;
    117 	bootconfig.dram[0].pages = 32768; /* 128MiB */
    118 
    119 	pxa2x0_gpio_config(netbookpro_gpioconf);
    120 }
    121 
    122 void
    123 consinit(void)
    124 {
    125 	static int consinit_called = 0;
    126 
    127 	if (consinit_called != 0)
    128 		return;
    129 
    130 	consinit_called = 1;
    131 
    132 	disable_consoles();
    133 
    134 #if NBICONSDEV > 0
    135 	enable_console(biconscninit, biconscnprobe);
    136 	bicons_set_priority(CN_INTERNAL);
    137 	cninit();
    138 #if NWSDISPLAY == 0
    139 	if (cn_tab != NULL) {	/* XXXX */
    140 		cn_tab->cn_getc = wskbd_cngetc;
    141 		cn_tab->cn_pollc = wskbd_cnpollc;
    142 		cn_tab->cn_bell = wskbd_cnbell;
    143 	}
    144 #endif
    145 #endif
    146 }
    147 
    148 static int __unused
    149 enable_console(void (*init)(struct consdev *), void (*probe)(struct consdev *))
    150 {
    151 	struct consdev *cp;
    152 
    153 	for (cp = constab; cp->cn_probe; cp++) {
    154 		if (cp->cn_init == init) {
    155 			cp->cn_probe = probe;
    156 			return 1;
    157 		}
    158 	}
    159 	return 0;
    160 }
    161 
    162 static void
    163 disable_consoles(void)
    164 {
    165 	struct consdev *cp;
    166 
    167 	for (cp = constab; cp->cn_probe; cp++)
    168 		cp->cn_probe = cn_nonprobe;
    169 }
    170 
    171 static void
    172 cn_nonprobe(struct consdev *cp)
    173 {
    174 
    175 	cp->cn_pri = CN_DEAD;
    176 }
    177