Home | History | Annotate | Line # | Download | only in dev
j720ssp.c revision 1.2.8.8
      1  1.2.8.8  nathanw /* $NetBSD: j720ssp.c,v 1.2.8.8 2002/11/11 21:58:37 nathanw Exp $ */
      2  1.2.8.2  nathanw 
      3  1.2.8.2  nathanw /*-
      4  1.2.8.2  nathanw  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
      5  1.2.8.2  nathanw  * All rights reserved.
      6  1.2.8.2  nathanw  *
      7  1.2.8.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.8.2  nathanw  * by Charles M. Hannum.
      9  1.2.8.2  nathanw  *
     10  1.2.8.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.2.8.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.2.8.2  nathanw  * are met:
     13  1.2.8.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.2.8.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.2.8.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2.8.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.2.8.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.2.8.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.2.8.2  nathanw  *    must display the following acknowledgement:
     20  1.2.8.2  nathanw  *        This product includes software developed by the NetBSD
     21  1.2.8.2  nathanw  *        Foundation, Inc. and its contributors.
     22  1.2.8.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2.8.2  nathanw  *    contributors may be used to endorse or promote products derived
     24  1.2.8.2  nathanw  *    from this software without specific prior written permission.
     25  1.2.8.2  nathanw  *
     26  1.2.8.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2.8.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2.8.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2.8.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2.8.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2.8.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2.8.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2.8.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2.8.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2.8.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2.8.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.2.8.2  nathanw  */
     38  1.2.8.2  nathanw 
     39  1.2.8.2  nathanw /*-
     40  1.2.8.2  nathanw  * Copyright (c) 1990 The Regents of the University of California.
     41  1.2.8.2  nathanw  * All rights reserved.
     42  1.2.8.2  nathanw  *
     43  1.2.8.2  nathanw  * This code is derived from software contributed to Berkeley by
     44  1.2.8.2  nathanw  * William Jolitz and Don Ahn.
     45  1.2.8.2  nathanw  *
     46  1.2.8.2  nathanw  * Redistribution and use in source and binary forms, with or without
     47  1.2.8.2  nathanw  * modification, are permitted provided that the following conditions
     48  1.2.8.2  nathanw  * are met:
     49  1.2.8.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     50  1.2.8.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     51  1.2.8.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     52  1.2.8.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     53  1.2.8.2  nathanw  *    documentation and/or other materials provided with the distribution.
     54  1.2.8.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     55  1.2.8.2  nathanw  *    must display the following acknowledgement:
     56  1.2.8.2  nathanw  *	This product includes software developed by the University of
     57  1.2.8.2  nathanw  *	California, Berkeley and its contributors.
     58  1.2.8.2  nathanw  * 4. Neither the name of the University nor the names of its contributors
     59  1.2.8.2  nathanw  *    may be used to endorse or promote products derived from this software
     60  1.2.8.2  nathanw  *    without specific prior written permission.
     61  1.2.8.2  nathanw  *
     62  1.2.8.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     63  1.2.8.2  nathanw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     64  1.2.8.2  nathanw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     65  1.2.8.2  nathanw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     66  1.2.8.2  nathanw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     67  1.2.8.2  nathanw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     68  1.2.8.2  nathanw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     69  1.2.8.2  nathanw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     70  1.2.8.2  nathanw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     71  1.2.8.2  nathanw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     72  1.2.8.2  nathanw  * SUCH DAMAGE.
     73  1.2.8.2  nathanw  *
     74  1.2.8.2  nathanw  *	@(#)pccons.c	5.11 (Berkeley) 5/21/91
     75  1.2.8.2  nathanw  */
     76  1.2.8.2  nathanw 
     77  1.2.8.7  nathanw #include "apm.h"
     78  1.2.8.7  nathanw 
     79  1.2.8.2  nathanw #include <sys/param.h>
     80  1.2.8.2  nathanw #include <sys/systm.h>
     81  1.2.8.2  nathanw #include <sys/device.h>
     82  1.2.8.2  nathanw #include <sys/kernel.h>
     83  1.2.8.2  nathanw #include <sys/malloc.h>
     84  1.2.8.2  nathanw #include <sys/ioctl.h>
     85  1.2.8.6  nathanw #include <sys/kthread.h>
     86  1.2.8.6  nathanw #include <sys/lock.h>
     87  1.2.8.2  nathanw 
     88  1.2.8.2  nathanw #include <machine/bus.h>
     89  1.2.8.2  nathanw #include <machine/config_hook.h>
     90  1.2.8.3  nathanw #include <machine/bootinfo.h>
     91  1.2.8.7  nathanw #include <machine/apmvar.h>
     92  1.2.8.2  nathanw 
     93  1.2.8.2  nathanw #include <hpcarm/dev/sed1356var.h>
     94  1.2.8.5  nathanw 
     95  1.2.8.5  nathanw #include <arm/sa11x0/sa11x0_var.h>
     96  1.2.8.5  nathanw #include <arm/sa11x0/sa11x0_gpioreg.h>
     97  1.2.8.5  nathanw #include <arm/sa11x0/sa11x0_ppcreg.h>
     98  1.2.8.5  nathanw #include <arm/sa11x0/sa11x0_sspreg.h>
     99  1.2.8.2  nathanw 
    100  1.2.8.2  nathanw #include <dev/wscons/wsconsio.h>
    101  1.2.8.2  nathanw #include <dev/wscons/wskbdvar.h>
    102  1.2.8.2  nathanw #include <dev/wscons/wsksymdef.h>
    103  1.2.8.2  nathanw #include <dev/wscons/wsksymvar.h>
    104  1.2.8.5  nathanw #include <dev/wscons/wsmousevar.h>
    105  1.2.8.5  nathanw #include <dev/hpc/tpcalibvar.h>
    106  1.2.8.2  nathanw 
    107  1.2.8.2  nathanw extern const struct wscons_keydesc j720kbd_keydesctab[];
    108  1.2.8.2  nathanw 
    109  1.2.8.2  nathanw struct j720ssp_softc {
    110  1.2.8.2  nathanw         struct device sc_dev;
    111  1.2.8.2  nathanw 
    112  1.2.8.2  nathanw 	bus_space_tag_t sc_iot;
    113  1.2.8.2  nathanw 	bus_space_handle_t sc_gpioh;
    114  1.2.8.2  nathanw 	bus_space_handle_t sc_ssph;
    115  1.2.8.2  nathanw 
    116  1.2.8.2  nathanw 	struct device *sc_wskbddev;
    117  1.2.8.5  nathanw 	struct device *sc_wsmousedev;
    118  1.2.8.5  nathanw 	struct tpcalib_softc sc_tpcalib;
    119  1.2.8.2  nathanw 
    120  1.2.8.5  nathanw 	void *sc_kbdsi;
    121  1.2.8.5  nathanw 	void *sc_tpsi;
    122  1.2.8.2  nathanw 	int sc_enabled;
    123  1.2.8.6  nathanw 
    124  1.2.8.6  nathanw 	struct proc *sc_ssp_kthread;
    125  1.2.8.6  nathanw 	int sc_ssp_status;
    126  1.2.8.6  nathanw 	struct simplelock sc_ssp_status_lock;
    127  1.2.8.2  nathanw };
    128  1.2.8.6  nathanw /* Values for struct softc's sc_ssp_status */
    129  1.2.8.6  nathanw #define J720_SSP_STATUS_NONE	0
    130  1.2.8.6  nathanw #define J720_SSP_STATUS_TP	1
    131  1.2.8.6  nathanw #define J720_SSP_STATUS_KBD	2
    132  1.2.8.2  nathanw 
    133  1.2.8.7  nathanw void j720ssp_create_kthread __P((void *));
    134  1.2.8.7  nathanw void j720ssp_kthread __P((void *));
    135  1.2.8.7  nathanw int  j720kbd_intr __P((void *));
    136  1.2.8.7  nathanw int  j720tp_intr __P((void *));
    137  1.2.8.7  nathanw void j720kbd_poll __P((void *));
    138  1.2.8.7  nathanw int  j720tp_poll __P((void *));
    139  1.2.8.7  nathanw 
    140  1.2.8.7  nathanw int  j720lcdparam __P((void *, int, long, void *));
    141  1.2.8.7  nathanw static void j720kbd_read __P((struct j720ssp_softc *, char *));
    142  1.2.8.7  nathanw static int  j720ssp_readwrite __P((struct j720ssp_softc *, int,
    143  1.2.8.7  nathanw 	int, int *, int));
    144  1.2.8.7  nathanw 
    145  1.2.8.7  nathanw int  j720sspprobe __P((struct device *, struct cfdata *, void *));
    146  1.2.8.7  nathanw void j720sspattach __P((struct device *, struct device *, void *));
    147  1.2.8.7  nathanw 
    148  1.2.8.7  nathanw int  j720kbd_submatch __P((struct device *, struct cfdata *, void *));
    149  1.2.8.7  nathanw int  j720tp_submatch __P((struct device *, struct cfdata *, void *));
    150  1.2.8.7  nathanw int  apm_submatch __P((struct device *, struct cfdata *, void *));
    151  1.2.8.7  nathanw 
    152  1.2.8.7  nathanw int  j720kbd_enable __P((void *, int));
    153  1.2.8.7  nathanw void j720kbd_set_leds __P((void *, int));
    154  1.2.8.7  nathanw int  j720kbd_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
    155  1.2.8.2  nathanw 
    156  1.2.8.7  nathanw int  j720lcdpower(void *, int, long, void *);
    157  1.2.8.7  nathanw int  hpcarm_apm_getpower __P((struct apm_power_info *, void *));
    158  1.2.8.7  nathanw 
    159  1.2.8.7  nathanw CFATTACH_DECL(j720ssp, sizeof(struct j720ssp_softc),
    160  1.2.8.7  nathanw     j720sspprobe, j720sspattach, NULL, NULL);
    161  1.2.8.2  nathanw 
    162  1.2.8.2  nathanw const struct wskbd_accessops j720kbd_accessops = {
    163  1.2.8.2  nathanw 	j720kbd_enable,
    164  1.2.8.2  nathanw 	j720kbd_set_leds,
    165  1.2.8.2  nathanw 	j720kbd_ioctl,
    166  1.2.8.2  nathanw };
    167  1.2.8.2  nathanw 
    168  1.2.8.7  nathanw void j720kbd_cngetc __P((void *, u_int *, int *));
    169  1.2.8.7  nathanw void j720kbd_cnpollc __P((void *, int));
    170  1.2.8.7  nathanw void j720kbd_cnbell __P((void *, u_int, u_int, u_int));
    171  1.2.8.2  nathanw 
    172  1.2.8.2  nathanw const struct wskbd_consops j720kbd_consops = {
    173  1.2.8.2  nathanw 	j720kbd_cngetc,
    174  1.2.8.2  nathanw 	j720kbd_cnpollc,
    175  1.2.8.2  nathanw 	j720kbd_cnbell,
    176  1.2.8.2  nathanw };
    177  1.2.8.2  nathanw 
    178  1.2.8.2  nathanw const struct wskbd_mapdata j720kbd_keymapdata = {
    179  1.2.8.2  nathanw 	j720kbd_keydesctab,
    180  1.2.8.2  nathanw #ifdef J720KBD_LAYOUT
    181  1.2.8.2  nathanw 	J720KBD_LAYOUT,
    182  1.2.8.2  nathanw #else
    183  1.2.8.2  nathanw 	KB_US,
    184  1.2.8.2  nathanw #endif
    185  1.2.8.2  nathanw };
    186  1.2.8.2  nathanw 
    187  1.2.8.7  nathanw static int  j720tp_enable __P((void *));
    188  1.2.8.7  nathanw static int  j720tp_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
    189  1.2.8.7  nathanw static void j720tp_disable __P((void *));
    190  1.2.8.5  nathanw 
    191  1.2.8.5  nathanw const struct wsmouse_accessops j720tp_accessops = {
    192  1.2.8.5  nathanw 	j720tp_enable,
    193  1.2.8.5  nathanw 	j720tp_ioctl,
    194  1.2.8.5  nathanw 	j720tp_disable,
    195  1.2.8.5  nathanw };
    196  1.2.8.5  nathanw 
    197  1.2.8.2  nathanw static int j720ssp_powerstate = 1;
    198  1.2.8.2  nathanw 
    199  1.2.8.2  nathanw static struct j720ssp_softc j720kbdcons_sc;
    200  1.2.8.2  nathanw static int j720kbdcons_initstate = 0;
    201  1.2.8.2  nathanw 
    202  1.2.8.2  nathanw #define DEBUG
    203  1.2.8.2  nathanw #ifdef DEBUG
    204  1.2.8.2  nathanw int j720sspwaitcnt;
    205  1.2.8.2  nathanw int j720sspwaittime;
    206  1.2.8.7  nathanw extern int gettick(void);
    207  1.2.8.2  nathanw #endif
    208  1.2.8.2  nathanw 
    209  1.2.8.2  nathanw #define BIT_INVERT(x)	do {					\
    210  1.2.8.2  nathanw 	(x) = ((((x) & 0xf0) >> 4) | (((x) & 0x0f) << 4));	\
    211  1.2.8.2  nathanw 	(x) = ((((x) & 0xcc) >> 2) | (((x) & 0x33) << 2));	\
    212  1.2.8.2  nathanw 	(x) = ((((x) & 0xaa) >> 1) | (((x) & 0x55) << 1));	\
    213  1.2.8.2  nathanw 	} while(0)
    214  1.2.8.2  nathanw 
    215  1.2.8.7  nathanw 
    216  1.2.8.2  nathanw int
    217  1.2.8.7  nathanw j720sspprobe(parent, cf, aux)
    218  1.2.8.7  nathanw 	struct device *parent;
    219  1.2.8.7  nathanw 	struct cfdata *cf;
    220  1.2.8.7  nathanw 	void *aux;
    221  1.2.8.2  nathanw {
    222  1.2.8.2  nathanw 	return (1);
    223  1.2.8.2  nathanw }
    224  1.2.8.2  nathanw 
    225  1.2.8.2  nathanw void
    226  1.2.8.7  nathanw j720sspattach(parent, self, aux)
    227  1.2.8.7  nathanw 	struct device *parent;
    228  1.2.8.7  nathanw 	struct device *self;
    229  1.2.8.7  nathanw 	void *aux;
    230  1.2.8.2  nathanw {
    231  1.2.8.2  nathanw 	struct j720ssp_softc *sc = (void *)self;
    232  1.2.8.2  nathanw 	struct sa11x0_softc *psc = (void *)parent;
    233  1.2.8.2  nathanw 	struct sa11x0_attach_args *sa = aux;
    234  1.2.8.7  nathanw 	struct wskbddev_attach_args kbd_args;
    235  1.2.8.7  nathanw 	struct wsmousedev_attach_args mouse_args;
    236  1.2.8.7  nathanw #if NAPM > 0
    237  1.2.8.7  nathanw 	struct apm_attach_args apm_args;
    238  1.2.8.7  nathanw #endif
    239  1.2.8.2  nathanw 
    240  1.2.8.2  nathanw 	printf("\n");
    241  1.2.8.2  nathanw 
    242  1.2.8.2  nathanw 	sc->sc_iot = psc->sc_iot;
    243  1.2.8.2  nathanw 	sc->sc_gpioh = psc->sc_gpioh;
    244  1.2.8.2  nathanw 	if (bus_space_map(sc->sc_iot, sa->sa_addr, sa->sa_size, 0,
    245  1.2.8.2  nathanw 			  &sc->sc_ssph)) {
    246  1.2.8.2  nathanw 		printf("%s: unable to map SSP registers\n",
    247  1.2.8.2  nathanw 		       sc->sc_dev.dv_xname);
    248  1.2.8.2  nathanw 		return;
    249  1.2.8.2  nathanw 	}
    250  1.2.8.2  nathanw 
    251  1.2.8.6  nathanw 	sc->sc_ssp_status = J720_SSP_STATUS_NONE;
    252  1.2.8.6  nathanw 	simple_lock_init(&sc->sc_ssp_status_lock);
    253  1.2.8.6  nathanw 	kthread_create(j720ssp_create_kthread, sc);
    254  1.2.8.2  nathanw 
    255  1.2.8.2  nathanw 	sc->sc_enabled = 0;
    256  1.2.8.2  nathanw 
    257  1.2.8.7  nathanw 	kbd_args.console = 0;
    258  1.2.8.2  nathanw 
    259  1.2.8.7  nathanw 	kbd_args.keymap = &j720kbd_keymapdata;
    260  1.2.8.2  nathanw 
    261  1.2.8.7  nathanw 	kbd_args.accessops = &j720kbd_accessops;
    262  1.2.8.7  nathanw 	kbd_args.accesscookie = sc;
    263  1.2.8.2  nathanw 
    264  1.2.8.2  nathanw 	/* Do console initialization */
    265  1.2.8.2  nathanw 	if (! (bootinfo->bi_cnuse & BI_CNUSE_SERIAL)) {
    266  1.2.8.2  nathanw 		j720kbdcons_sc = *sc;
    267  1.2.8.7  nathanw 		kbd_args.console = 1;
    268  1.2.8.2  nathanw 
    269  1.2.8.2  nathanw 		wskbd_cnattach(&j720kbd_consops, NULL, &j720kbd_keymapdata);
    270  1.2.8.2  nathanw 		j720kbdcons_initstate = 1;
    271  1.2.8.2  nathanw 	}
    272  1.2.8.2  nathanw 
    273  1.2.8.2  nathanw 	/*
    274  1.2.8.2  nathanw 	 * Attach the wskbd, saving a handle to it.
    275  1.2.8.2  nathanw 	 * XXX XXX XXX
    276  1.2.8.2  nathanw 	 */
    277  1.2.8.7  nathanw 	sc->sc_wskbddev = config_found_sm(self, &kbd_args, wskbddevprint,
    278  1.2.8.5  nathanw 	    j720kbd_submatch);
    279  1.2.8.2  nathanw 
    280  1.2.8.2  nathanw #ifdef DEBUG
    281  1.2.8.2  nathanw 	/* Zero the stat counters */
    282  1.2.8.2  nathanw 	j720sspwaitcnt = 0;
    283  1.2.8.2  nathanw 	j720sspwaittime = 0;
    284  1.2.8.2  nathanw #endif
    285  1.2.8.2  nathanw 
    286  1.2.8.2  nathanw 	if (j720kbdcons_initstate == 1)
    287  1.2.8.2  nathanw 		j720kbd_enable(sc, 1);
    288  1.2.8.2  nathanw 
    289  1.2.8.7  nathanw 	mouse_args.accessops = &j720tp_accessops;
    290  1.2.8.7  nathanw 	mouse_args.accesscookie = sc;
    291  1.2.8.5  nathanw 
    292  1.2.8.7  nathanw 	sc->sc_wsmousedev = config_found_sm(self, &mouse_args,
    293  1.2.8.7  nathanw 	    wsmousedevprint, j720tp_submatch);
    294  1.2.8.5  nathanw 	tpcalib_init(&sc->sc_tpcalib);
    295  1.2.8.5  nathanw 
    296  1.2.8.5  nathanw 	/* XXX fill in "default" calibrate param */
    297  1.2.8.5  nathanw 	{
    298  1.2.8.5  nathanw 		static const struct wsmouse_calibcoords j720_default_calib = {
    299  1.2.8.5  nathanw 			0, 0, 639, 239,
    300  1.2.8.5  nathanw 			4,
    301  1.2.8.5  nathanw 			{ { 988,  80,   0,   0 },
    302  1.2.8.5  nathanw 			  {  88,  84, 639,   0 },
    303  1.2.8.5  nathanw 			  { 988, 927,   0, 239 },
    304  1.2.8.5  nathanw 			  {  88, 940, 639, 239 } } };
    305  1.2.8.5  nathanw 		tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
    306  1.2.8.5  nathanw 		    (caddr_t)&j720_default_calib, 0, 0);
    307  1.2.8.5  nathanw 	}
    308  1.2.8.5  nathanw 
    309  1.2.8.5  nathanw 	j720tp_disable(sc);
    310  1.2.8.5  nathanw 
    311  1.2.8.5  nathanw 	/* Setup touchpad interrupt */
    312  1.2.8.5  nathanw 	sa11x0_intr_establish(0, 9, 1, IPL_BIO, j720tp_intr, sc);
    313  1.2.8.5  nathanw 
    314  1.2.8.2  nathanw 	/* LCD control is on the same bus */
    315  1.2.8.2  nathanw 	config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS,
    316  1.2.8.2  nathanw 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    317  1.2.8.2  nathanw 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS,
    318  1.2.8.2  nathanw 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    319  1.2.8.2  nathanw 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS_MAX,
    320  1.2.8.2  nathanw 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    321  1.2.8.2  nathanw 
    322  1.2.8.2  nathanw 	config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST,
    323  1.2.8.2  nathanw 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    324  1.2.8.2  nathanw 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST,
    325  1.2.8.2  nathanw 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    326  1.2.8.2  nathanw 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST_MAX,
    327  1.2.8.2  nathanw 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    328  1.2.8.7  nathanw 
    329  1.2.8.7  nathanw #if NAPM > 0
    330  1.2.8.7  nathanw 	/* attach APM emulation */
    331  1.2.8.7  nathanw 	apm_args.aaa_magic = APM_ATTACH_ARGS_MAGIC; /* magic number */
    332  1.2.8.7  nathanw 	(void)config_found_sm(self, &apm_args, NULL, apm_submatch);
    333  1.2.8.7  nathanw #endif
    334  1.2.8.7  nathanw 
    335  1.2.8.7  nathanw 	return;
    336  1.2.8.2  nathanw }
    337  1.2.8.2  nathanw 
    338  1.2.8.6  nathanw void
    339  1.2.8.6  nathanw j720ssp_create_kthread(arg)
    340  1.2.8.6  nathanw 	void *arg;
    341  1.2.8.6  nathanw {
    342  1.2.8.6  nathanw 	struct j720ssp_softc *sc = arg;
    343  1.2.8.6  nathanw 
    344  1.2.8.6  nathanw 	if (kthread_create1(j720ssp_kthread, sc,
    345  1.2.8.6  nathanw 	    &sc->sc_ssp_kthread, "j720ssp"))
    346  1.2.8.6  nathanw 		panic("j720ssp_create_kthread");
    347  1.2.8.6  nathanw 
    348  1.2.8.6  nathanw 	return;
    349  1.2.8.6  nathanw }
    350  1.2.8.6  nathanw 
    351  1.2.8.6  nathanw void
    352  1.2.8.6  nathanw j720ssp_kthread(arg)
    353  1.2.8.6  nathanw 	void *arg;
    354  1.2.8.6  nathanw {
    355  1.2.8.6  nathanw 	struct j720ssp_softc *sc = arg;
    356  1.2.8.6  nathanw 	int ssp_status;
    357  1.2.8.6  nathanw 
    358  1.2.8.6  nathanw 	while (1) {
    359  1.2.8.6  nathanw 		if (ssp_status & J720_SSP_STATUS_TP)
    360  1.2.8.6  nathanw 			tsleep(&sc->sc_ssp_kthread, PRIBIO, "j720ssp", hz / 25);
    361  1.2.8.6  nathanw 		else
    362  1.2.8.6  nathanw 			tsleep(&sc->sc_ssp_kthread, PRIBIO, "j720ssp", 0);
    363  1.2.8.6  nathanw 
    364  1.2.8.6  nathanw 		simple_lock(&sc->sc_ssp_status_lock);
    365  1.2.8.6  nathanw 		ssp_status = sc->sc_ssp_status;
    366  1.2.8.6  nathanw 		sc->sc_ssp_status &= ~J720_SSP_STATUS_KBD;
    367  1.2.8.6  nathanw 		simple_unlock(&sc->sc_ssp_status_lock);
    368  1.2.8.6  nathanw 
    369  1.2.8.6  nathanw 		if (ssp_status & J720_SSP_STATUS_KBD)
    370  1.2.8.6  nathanw 			j720kbd_poll(sc);
    371  1.2.8.6  nathanw 
    372  1.2.8.6  nathanw 		if (ssp_status & J720_SSP_STATUS_TP) {
    373  1.2.8.6  nathanw 			if (j720tp_poll(sc) == 0) {
    374  1.2.8.6  nathanw 				simple_lock(&sc->sc_ssp_status_lock);
    375  1.2.8.6  nathanw 				sc->sc_ssp_status &= ~J720_SSP_STATUS_TP;
    376  1.2.8.6  nathanw 				simple_unlock(&sc->sc_ssp_status_lock);
    377  1.2.8.6  nathanw 			}
    378  1.2.8.6  nathanw 		}
    379  1.2.8.6  nathanw 	}
    380  1.2.8.6  nathanw 
    381  1.2.8.6  nathanw 	/* NOTREACHED */
    382  1.2.8.6  nathanw }
    383  1.2.8.6  nathanw 
    384  1.2.8.6  nathanw 
    385  1.2.8.2  nathanw int
    386  1.2.8.7  nathanw j720kbd_submatch(parent, cf, aux)
    387  1.2.8.7  nathanw 	struct device *parent;
    388  1.2.8.7  nathanw 	struct cfdata *cf;
    389  1.2.8.7  nathanw 	void *aux;
    390  1.2.8.7  nathanw {
    391  1.2.8.7  nathanw 	if (strcmp(cf->cf_name, "wskbd") == 0)
    392  1.2.8.5  nathanw 		return (1);
    393  1.2.8.5  nathanw 	return (0);
    394  1.2.8.5  nathanw }
    395  1.2.8.5  nathanw 
    396  1.2.8.5  nathanw int
    397  1.2.8.7  nathanw j720tp_submatch(parent, cf, aux)
    398  1.2.8.7  nathanw 	struct device *parent;
    399  1.2.8.7  nathanw 	struct cfdata *cf;
    400  1.2.8.7  nathanw 	void *aux;
    401  1.2.8.7  nathanw {
    402  1.2.8.7  nathanw 	if (strcmp(cf->cf_name, "wsmouse") == 0)
    403  1.2.8.7  nathanw 		return (1);
    404  1.2.8.7  nathanw 	return (0);
    405  1.2.8.7  nathanw }
    406  1.2.8.5  nathanw 
    407  1.2.8.7  nathanw int
    408  1.2.8.7  nathanw apm_submatch(parent, cf, aux)
    409  1.2.8.7  nathanw 	struct device *parent;
    410  1.2.8.7  nathanw 	struct cfdata *cf;
    411  1.2.8.7  nathanw 	void *aux;
    412  1.2.8.7  nathanw {
    413  1.2.8.7  nathanw 	if (strcmp(cf->cf_name, "apm") == 0)
    414  1.2.8.5  nathanw 		return (1);
    415  1.2.8.5  nathanw 	return (0);
    416  1.2.8.5  nathanw }
    417  1.2.8.5  nathanw 
    418  1.2.8.5  nathanw int
    419  1.2.8.7  nathanw j720kbd_enable(v, on)
    420  1.2.8.7  nathanw 	void *v;
    421  1.2.8.7  nathanw 	int on;
    422  1.2.8.2  nathanw {
    423  1.2.8.2  nathanw 	struct j720ssp_softc *sc = v;
    424  1.2.8.2  nathanw 
    425  1.2.8.2  nathanw 	if (! sc->sc_enabled) {
    426  1.2.8.2  nathanw 		sc->sc_enabled = 1;
    427  1.2.8.2  nathanw 
    428  1.2.8.2  nathanw 		sa11x0_intr_establish(0, 0, 1, IPL_BIO, j720kbd_intr, sc);
    429  1.2.8.2  nathanw 	}
    430  1.2.8.2  nathanw 	/* XXX */
    431  1.2.8.2  nathanw 	return (0);
    432  1.2.8.2  nathanw }
    433  1.2.8.2  nathanw 
    434  1.2.8.2  nathanw void
    435  1.2.8.7  nathanw j720kbd_set_leds(v, on)
    436  1.2.8.7  nathanw 	void *v;
    437  1.2.8.7  nathanw 	int on;
    438  1.2.8.2  nathanw {
    439  1.2.8.2  nathanw 	/* XXX */
    440  1.2.8.2  nathanw 	return;
    441  1.2.8.2  nathanw }
    442  1.2.8.2  nathanw 
    443  1.2.8.2  nathanw int
    444  1.2.8.5  nathanw j720kbd_ioctl(v, cmd, data, flag, p)
    445  1.2.8.5  nathanw 	void *v;
    446  1.2.8.5  nathanw 	u_long cmd;
    447  1.2.8.5  nathanw 	caddr_t data;
    448  1.2.8.5  nathanw 	int flag;
    449  1.2.8.5  nathanw 	struct proc *p;
    450  1.2.8.5  nathanw {
    451  1.2.8.5  nathanw 	switch (cmd) {
    452  1.2.8.5  nathanw 	case WSKBDIO_GTYPE:
    453  1.2.8.5  nathanw 		*(int *)data = WSKBD_TYPE_HPC_KBD;
    454  1.2.8.5  nathanw 		return 0;
    455  1.2.8.5  nathanw 	}
    456  1.2.8.5  nathanw 
    457  1.2.8.4  nathanw 	return (EPASSTHROUGH);
    458  1.2.8.2  nathanw }
    459  1.2.8.2  nathanw 
    460  1.2.8.2  nathanw int
    461  1.2.8.7  nathanw j720kbd_intr(arg)
    462  1.2.8.7  nathanw 	void *arg;
    463  1.2.8.2  nathanw {
    464  1.2.8.2  nathanw 	struct j720ssp_softc *sc = arg;
    465  1.2.8.2  nathanw 
    466  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 1);
    467  1.2.8.2  nathanw 
    468  1.2.8.6  nathanw 	simple_lock(&sc->sc_ssp_status_lock);
    469  1.2.8.6  nathanw 	sc->sc_ssp_status |= J720_SSP_STATUS_KBD;
    470  1.2.8.6  nathanw 	simple_unlock(&sc->sc_ssp_status_lock);
    471  1.2.8.6  nathanw 
    472  1.2.8.6  nathanw 	wakeup(&sc->sc_ssp_kthread);
    473  1.2.8.5  nathanw 
    474  1.2.8.5  nathanw 	return (1);
    475  1.2.8.5  nathanw }
    476  1.2.8.5  nathanw 
    477  1.2.8.5  nathanw int
    478  1.2.8.7  nathanw j720tp_intr(arg)
    479  1.2.8.7  nathanw 	void *arg;
    480  1.2.8.5  nathanw {
    481  1.2.8.5  nathanw 	struct j720ssp_softc *sc = arg;
    482  1.2.8.5  nathanw 
    483  1.2.8.5  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 1 << 9);
    484  1.2.8.5  nathanw 
    485  1.2.8.6  nathanw 	simple_lock(&sc->sc_ssp_status_lock);
    486  1.2.8.6  nathanw 	sc->sc_ssp_status |= J720_SSP_STATUS_TP;
    487  1.2.8.6  nathanw 	simple_unlock(&sc->sc_ssp_status_lock);
    488  1.2.8.6  nathanw 
    489  1.2.8.6  nathanw 	j720tp_disable(sc);
    490  1.2.8.6  nathanw 	wakeup(&sc->sc_ssp_kthread);
    491  1.2.8.2  nathanw 
    492  1.2.8.2  nathanw 	return (1);
    493  1.2.8.2  nathanw }
    494  1.2.8.2  nathanw 
    495  1.2.8.2  nathanw void
    496  1.2.8.7  nathanw j720kbd_poll(arg)
    497  1.2.8.7  nathanw 	void *arg;
    498  1.2.8.2  nathanw {
    499  1.2.8.2  nathanw 	struct j720ssp_softc *sc = arg;
    500  1.2.8.2  nathanw 	int s, type, value;
    501  1.2.8.2  nathanw 	char buf[9], *p;
    502  1.2.8.2  nathanw 
    503  1.2.8.2  nathanw 	j720kbd_read(sc, buf);
    504  1.2.8.2  nathanw 
    505  1.2.8.2  nathanw 	for(p = buf; *p; p++) {
    506  1.2.8.2  nathanw 		type = *p & 0x80 ? WSCONS_EVENT_KEY_UP :
    507  1.2.8.2  nathanw 		    WSCONS_EVENT_KEY_DOWN;
    508  1.2.8.2  nathanw 		value = *p & 0x7f;
    509  1.2.8.2  nathanw 		s = spltty();
    510  1.2.8.2  nathanw 		wskbd_input(sc->sc_wskbddev, type, value);
    511  1.2.8.2  nathanw 		splx(s);
    512  1.2.8.2  nathanw 		if (type == WSCONS_EVENT_KEY_DOWN &&
    513  1.2.8.2  nathanw 		    value == 0x7f) {
    514  1.2.8.2  nathanw 			j720ssp_powerstate = ! j720ssp_powerstate;
    515  1.2.8.2  nathanw 			config_hook_call(CONFIG_HOOK_POWERCONTROL,
    516  1.2.8.2  nathanw 					 CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
    517  1.2.8.2  nathanw 					 (void *)j720ssp_powerstate);
    518  1.2.8.2  nathanw 		}
    519  1.2.8.2  nathanw 	}
    520  1.2.8.2  nathanw 
    521  1.2.8.2  nathanw 	return;
    522  1.2.8.2  nathanw }
    523  1.2.8.2  nathanw 
    524  1.2.8.2  nathanw void
    525  1.2.8.7  nathanw j720kbd_read(sc, buf)
    526  1.2.8.7  nathanw 	struct j720ssp_softc *sc;
    527  1.2.8.7  nathanw 	char *buf;
    528  1.2.8.2  nathanw {
    529  1.2.8.2  nathanw 	int data, count;
    530  1.2.8.2  nathanw #ifdef DEBUG
    531  1.2.8.2  nathanw 	u_int32_t oscr;
    532  1.2.8.2  nathanw 
    533  1.2.8.2  nathanw 	oscr = gettick();
    534  1.2.8.2  nathanw #endif
    535  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
    536  1.2.8.2  nathanw 
    537  1.2.8.2  nathanw 	/* send scan keycode command */
    538  1.2.8.6  nathanw 	if (j720ssp_readwrite(sc, 1, 0x900, &data, 100) < 0 ||
    539  1.2.8.2  nathanw 	    data != 0x88)
    540  1.2.8.2  nathanw 		goto out;
    541  1.2.8.2  nathanw 
    542  1.2.8.2  nathanw 	/* read numbers of scancode available */
    543  1.2.8.6  nathanw 	if (j720ssp_readwrite(sc, 0, 0x8800, &data, 100) < 0)
    544  1.2.8.2  nathanw 		goto out;
    545  1.2.8.2  nathanw 	BIT_INVERT(data);
    546  1.2.8.2  nathanw 	count = data;
    547  1.2.8.2  nathanw 
    548  1.2.8.2  nathanw 	for(; count; count--) {
    549  1.2.8.6  nathanw 		if (j720ssp_readwrite(sc, 0, 0x8800, &data, 100) < 0)
    550  1.2.8.2  nathanw 			goto out;
    551  1.2.8.2  nathanw 		BIT_INVERT(data);
    552  1.2.8.2  nathanw 		*buf++ = data;
    553  1.2.8.2  nathanw 	}
    554  1.2.8.2  nathanw 	*buf = 0;
    555  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    556  1.2.8.2  nathanw 
    557  1.2.8.2  nathanw #ifdef DEBUG
    558  1.2.8.2  nathanw 	oscr = (u_int32_t)gettick() - oscr;
    559  1.2.8.2  nathanw 	j720sspwaitcnt++;
    560  1.2.8.2  nathanw 	j720sspwaittime += oscr;
    561  1.2.8.2  nathanw #endif
    562  1.2.8.2  nathanw 
    563  1.2.8.2  nathanw 	return;
    564  1.2.8.2  nathanw 
    565  1.2.8.2  nathanw out:
    566  1.2.8.2  nathanw 	*buf = 0;
    567  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    568  1.2.8.2  nathanw 
    569  1.2.8.2  nathanw 	/* reset SSP */
    570  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
    571  1.2.8.2  nathanw 	delay(100);
    572  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
    573  1.2.8.7  nathanw 
    574  1.2.8.7  nathanw 	printf("j720kbd_read: error %x\n", data);
    575  1.2.8.7  nathanw 	return;
    576  1.2.8.2  nathanw }
    577  1.2.8.2  nathanw 
    578  1.2.8.6  nathanw int
    579  1.2.8.7  nathanw j720tp_poll(arg)
    580  1.2.8.7  nathanw 	void *arg;
    581  1.2.8.5  nathanw {
    582  1.2.8.5  nathanw 	struct j720ssp_softc *sc = arg;
    583  1.2.8.5  nathanw 	int buf[8], data, i, x, y;
    584  1.2.8.5  nathanw 
    585  1.2.8.6  nathanw 	/*
    586  1.2.8.6  nathanw 	 * If touch panel is not touched anymore,
    587  1.2.8.6  nathanw 	 * stop polling and re-enable interrupt
    588  1.2.8.6  nathanw 	 */
    589  1.2.8.6  nathanw 	if (bus_space_read_4(sc->sc_iot,
    590  1.2.8.6  nathanw 	    sc->sc_gpioh, SAGPIO_PLR) & (1 << 9)) {
    591  1.2.8.6  nathanw 		wsmouse_input(sc->sc_wsmousedev, 0, 0, 0, 0, 0);
    592  1.2.8.6  nathanw 		j720tp_enable(sc);
    593  1.2.8.6  nathanw 		return 0;
    594  1.2.8.6  nathanw 	}
    595  1.2.8.6  nathanw 
    596  1.2.8.5  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
    597  1.2.8.5  nathanw 
    598  1.2.8.5  nathanw 	/* send read touchpanel command */
    599  1.2.8.6  nathanw 	if (j720ssp_readwrite(sc, 1, 0x500, &data, 100) < 0 ||
    600  1.2.8.5  nathanw 	    data != 0x88)
    601  1.2.8.5  nathanw 		goto out;
    602  1.2.8.5  nathanw 
    603  1.2.8.5  nathanw 	for(i = 0; i < 8; i++) {
    604  1.2.8.6  nathanw 		if (j720ssp_readwrite(sc, 0, 0x8800, &data, 100) < 0)
    605  1.2.8.5  nathanw 			goto out;
    606  1.2.8.5  nathanw 		BIT_INVERT(data);
    607  1.2.8.5  nathanw 		buf[i] = data;
    608  1.2.8.5  nathanw 	}
    609  1.2.8.5  nathanw 
    610  1.2.8.5  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    611  1.2.8.5  nathanw 
    612  1.2.8.5  nathanw 	buf[6] <<= 8;
    613  1.2.8.5  nathanw 	buf[7] <<= 8;
    614  1.2.8.5  nathanw 	for(i = 0; i < 3; i++) {
    615  1.2.8.5  nathanw 		buf[i] |= buf[6] & 0x300;
    616  1.2.8.5  nathanw 		buf[6] >>= 2;
    617  1.2.8.5  nathanw 		buf[i + 3] |= buf[7] & 0x300;
    618  1.2.8.5  nathanw 		buf[7] >>= 2;
    619  1.2.8.5  nathanw 	}
    620  1.2.8.5  nathanw #if 0
    621  1.2.8.6  nathanw 	printf("j720tp_poll: %d %d %d  %d %d %d\n", buf[0], buf[1], buf[2],
    622  1.2.8.5  nathanw 	    buf[3], buf[4], buf[5]);
    623  1.2.8.5  nathanw #endif
    624  1.2.8.5  nathanw 
    625  1.2.8.5  nathanw 	/* XXX buf[1], buf[2], ... should also be used */
    626  1.2.8.5  nathanw 	tpcalib_trans(&sc->sc_tpcalib, buf[1], buf[4], &x, &y);
    627  1.2.8.5  nathanw 	wsmouse_input(sc->sc_wsmousedev, 1, x, y, 0,
    628  1.2.8.5  nathanw 	    WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
    629  1.2.8.5  nathanw 
    630  1.2.8.6  nathanw 	return 1;
    631  1.2.8.5  nathanw 
    632  1.2.8.5  nathanw out:
    633  1.2.8.5  nathanw 	*buf = 0;
    634  1.2.8.5  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    635  1.2.8.5  nathanw 
    636  1.2.8.5  nathanw 	/* reset SSP */
    637  1.2.8.5  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
    638  1.2.8.5  nathanw 	delay(100);
    639  1.2.8.5  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
    640  1.2.8.6  nathanw 	printf("j720tp_poll: error %x\n", data);
    641  1.2.8.5  nathanw 
    642  1.2.8.6  nathanw 	return 0;
    643  1.2.8.5  nathanw }
    644  1.2.8.5  nathanw 
    645  1.2.8.5  nathanw static int
    646  1.2.8.7  nathanw j720tp_enable(arg)
    647  1.2.8.7  nathanw 	void *arg;
    648  1.2.8.7  nathanw {
    649  1.2.8.5  nathanw 	struct j720ssp_softc *sc = arg;
    650  1.2.8.5  nathanw 	int er, s;
    651  1.2.8.5  nathanw 
    652  1.2.8.5  nathanw 	s = splhigh();
    653  1.2.8.5  nathanw 	er = bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER);
    654  1.2.8.5  nathanw 	er |= 1 << 9;
    655  1.2.8.5  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER, er);
    656  1.2.8.5  nathanw 	splx(s);
    657  1.2.8.5  nathanw 
    658  1.2.8.5  nathanw 	return (0);
    659  1.2.8.5  nathanw }
    660  1.2.8.5  nathanw 
    661  1.2.8.5  nathanw static void
    662  1.2.8.7  nathanw j720tp_disable(arg)
    663  1.2.8.7  nathanw 	void *arg;
    664  1.2.8.7  nathanw {
    665  1.2.8.5  nathanw 	struct j720ssp_softc *sc = arg;
    666  1.2.8.5  nathanw 	int er, s;
    667  1.2.8.5  nathanw 
    668  1.2.8.5  nathanw 	s = splhigh();
    669  1.2.8.5  nathanw 	er = bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER);
    670  1.2.8.5  nathanw 	er &= ~(1 << 9);
    671  1.2.8.5  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER, er);
    672  1.2.8.5  nathanw 	splx(s);
    673  1.2.8.5  nathanw }
    674  1.2.8.5  nathanw 
    675  1.2.8.5  nathanw static int
    676  1.2.8.7  nathanw j720tp_ioctl(arg, cmd, data, flag, p)
    677  1.2.8.7  nathanw 	void *arg;
    678  1.2.8.7  nathanw 	u_long cmd;
    679  1.2.8.7  nathanw 	caddr_t data;
    680  1.2.8.7  nathanw 	int flag;
    681  1.2.8.7  nathanw 	struct proc *p;
    682  1.2.8.7  nathanw {
    683  1.2.8.5  nathanw 	struct j720ssp_softc *sc = arg;
    684  1.2.8.5  nathanw 
    685  1.2.8.5  nathanw 	switch (cmd) {
    686  1.2.8.5  nathanw 	case WSMOUSEIO_GTYPE:
    687  1.2.8.5  nathanw 		*(u_int *)data = WSMOUSE_TYPE_TPANEL;
    688  1.2.8.5  nathanw 		return (0);
    689  1.2.8.5  nathanw 
    690  1.2.8.5  nathanw 	case WSMOUSEIO_SCALIBCOORDS:
    691  1.2.8.5  nathanw 	case WSMOUSEIO_GCALIBCOORDS:
    692  1.2.8.5  nathanw 		return tpcalib_ioctl(&sc->sc_tpcalib, cmd, data, flag, p);
    693  1.2.8.5  nathanw 
    694  1.2.8.5  nathanw 	default:
    695  1.2.8.5  nathanw 		return (EPASSTHROUGH);
    696  1.2.8.5  nathanw 	}
    697  1.2.8.5  nathanw }
    698  1.2.8.5  nathanw 
    699  1.2.8.2  nathanw int
    700  1.2.8.7  nathanw j720lcdparam(ctx, type, id, msg)
    701  1.2.8.7  nathanw 	void *ctx;
    702  1.2.8.7  nathanw 	int type;
    703  1.2.8.7  nathanw 	long id;
    704  1.2.8.7  nathanw 	void *msg;
    705  1.2.8.2  nathanw {
    706  1.2.8.2  nathanw 	struct j720ssp_softc *sc = ctx;
    707  1.2.8.2  nathanw 	int i, s;
    708  1.2.8.2  nathanw 	u_int32_t data[2], len;
    709  1.2.8.2  nathanw 
    710  1.2.8.2  nathanw 	switch (type) {
    711  1.2.8.2  nathanw 	case CONFIG_HOOK_GET:
    712  1.2.8.2  nathanw 		switch (id) {
    713  1.2.8.2  nathanw 		case CONFIG_HOOK_BRIGHTNESS_MAX:
    714  1.2.8.2  nathanw 		case CONFIG_HOOK_CONTRAST_MAX:
    715  1.2.8.2  nathanw 			*(int *)msg = 255;
    716  1.2.8.2  nathanw 			return 1;
    717  1.2.8.2  nathanw 		case CONFIG_HOOK_BRIGHTNESS:
    718  1.2.8.2  nathanw 			data[0] = 0x6b00;
    719  1.2.8.2  nathanw 			data[1] = 0x8800;
    720  1.2.8.2  nathanw 			len = 2;
    721  1.2.8.2  nathanw 			break;
    722  1.2.8.2  nathanw 		case CONFIG_HOOK_CONTRAST:
    723  1.2.8.2  nathanw 			data[0] = 0x2b00;
    724  1.2.8.2  nathanw 			data[1] = 0x8800;
    725  1.2.8.2  nathanw 			len = 2;
    726  1.2.8.2  nathanw 			break;
    727  1.2.8.2  nathanw 		default:
    728  1.2.8.2  nathanw 			return 0;
    729  1.2.8.2  nathanw 		}
    730  1.2.8.2  nathanw 		break;
    731  1.2.8.2  nathanw 
    732  1.2.8.2  nathanw 	case CONFIG_HOOK_SET:
    733  1.2.8.2  nathanw 		switch (id) {
    734  1.2.8.2  nathanw 		case CONFIG_HOOK_BRIGHTNESS:
    735  1.2.8.2  nathanw 			if (*(int *)msg >= 0) {
    736  1.2.8.2  nathanw 				data[0] = 0xcb00;
    737  1.2.8.2  nathanw 				data[1] = *(int *)msg;
    738  1.2.8.2  nathanw 				BIT_INVERT(data[1]);
    739  1.2.8.2  nathanw 				data[1] <<= 8;
    740  1.2.8.2  nathanw 				len = 2;
    741  1.2.8.2  nathanw 			} else {
    742  1.2.8.2  nathanw 				/* XXX hack */
    743  1.2.8.2  nathanw 				data[0] = 0xfb00;
    744  1.2.8.2  nathanw 				len = 1;
    745  1.2.8.2  nathanw 			}
    746  1.2.8.2  nathanw 			break;
    747  1.2.8.2  nathanw 		case CONFIG_HOOK_CONTRAST:
    748  1.2.8.2  nathanw 			data[0] = 0x8b00;
    749  1.2.8.2  nathanw 			data[1] = *(int *)msg;
    750  1.2.8.2  nathanw 			BIT_INVERT(data[1]);
    751  1.2.8.2  nathanw 			data[1] <<= 8;
    752  1.2.8.2  nathanw 			len = 2;
    753  1.2.8.2  nathanw 			break;
    754  1.2.8.2  nathanw 		default:
    755  1.2.8.2  nathanw 			return 0;
    756  1.2.8.2  nathanw 		}
    757  1.2.8.2  nathanw 	}
    758  1.2.8.2  nathanw 
    759  1.2.8.2  nathanw 	s = splbio();
    760  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
    761  1.2.8.2  nathanw 
    762  1.2.8.2  nathanw 	for (i = 0; i < len; i++) {
    763  1.2.8.6  nathanw 		if (j720ssp_readwrite(sc, 1, data[i], &data[i], 500) < 0)
    764  1.2.8.2  nathanw 			goto out;
    765  1.2.8.2  nathanw 	}
    766  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    767  1.2.8.2  nathanw 	splx(s);
    768  1.2.8.2  nathanw 
    769  1.2.8.2  nathanw 	if (type == CONFIG_HOOK_SET)
    770  1.2.8.2  nathanw 		return 1;
    771  1.2.8.2  nathanw 
    772  1.2.8.2  nathanw 	BIT_INVERT(data[1]);
    773  1.2.8.2  nathanw 	*(int *)msg = data[1];
    774  1.2.8.2  nathanw 
    775  1.2.8.2  nathanw 	return 1;
    776  1.2.8.2  nathanw 
    777  1.2.8.2  nathanw out:
    778  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    779  1.2.8.2  nathanw 
    780  1.2.8.2  nathanw 	/* reset SSP */
    781  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
    782  1.2.8.2  nathanw 	delay(100);
    783  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
    784  1.2.8.2  nathanw 	splx(s);
    785  1.2.8.2  nathanw 	return 0;
    786  1.2.8.2  nathanw }
    787  1.2.8.2  nathanw 
    788  1.2.8.2  nathanw static int
    789  1.2.8.6  nathanw j720ssp_readwrite(sc, drainfifo, in, out, wait)
    790  1.2.8.6  nathanw 	struct j720ssp_softc *sc;
    791  1.2.8.6  nathanw 	int drainfifo;
    792  1.2.8.6  nathanw 	int in;
    793  1.2.8.6  nathanw 	int *out;
    794  1.2.8.6  nathanw 	int wait;
    795  1.2.8.2  nathanw {
    796  1.2.8.2  nathanw 	int timo;
    797  1.2.8.2  nathanw 
    798  1.2.8.2  nathanw 	timo = 100000;
    799  1.2.8.2  nathanw 	while(bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PLR) & 0x400)
    800  1.2.8.2  nathanw 		if (--timo == 0) {
    801  1.2.8.2  nathanw 			printf("timo0\n");
    802  1.2.8.2  nathanw 			return -1;
    803  1.2.8.2  nathanw 		}
    804  1.2.8.2  nathanw 	if (drainfifo) {
    805  1.2.8.2  nathanw 		while(bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) &
    806  1.2.8.2  nathanw 		      SR_RNE)
    807  1.2.8.2  nathanw 			bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
    808  1.2.8.2  nathanw #if 1
    809  1.2.8.6  nathanw 		delay(wait);
    810  1.2.8.2  nathanw #endif
    811  1.2.8.2  nathanw 	}
    812  1.2.8.2  nathanw 
    813  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_DR, in);
    814  1.2.8.2  nathanw 
    815  1.2.8.6  nathanw 	delay(wait);
    816  1.2.8.2  nathanw 	timo = 100000;
    817  1.2.8.2  nathanw 	while(! (bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) & SR_RNE))
    818  1.2.8.2  nathanw 		if (--timo == 0) {
    819  1.2.8.2  nathanw 			printf("timo1\n");
    820  1.2.8.2  nathanw 			return -1;
    821  1.2.8.2  nathanw 		}
    822  1.2.8.2  nathanw 
    823  1.2.8.2  nathanw 	*out = bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
    824  1.2.8.2  nathanw 
    825  1.2.8.2  nathanw 	return 0;
    826  1.2.8.2  nathanw }
    827  1.2.8.2  nathanw 
    828  1.2.8.2  nathanw #if 0
    829  1.2.8.2  nathanw int
    830  1.2.8.7  nathanw j720kbd_cnattach(void)
    831  1.2.8.2  nathanw {
    832  1.2.8.2  nathanw 	/* XXX defer initialization till j720sspattach */
    833  1.2.8.2  nathanw 
    834  1.2.8.2  nathanw 	return (0);
    835  1.2.8.2  nathanw }
    836  1.2.8.2  nathanw #endif
    837  1.2.8.2  nathanw 
    838  1.2.8.2  nathanw /* ARGSUSED */
    839  1.2.8.2  nathanw void
    840  1.2.8.7  nathanw j720kbd_cngetc(v, type, data)
    841  1.2.8.7  nathanw 	void *v;
    842  1.2.8.7  nathanw 	u_int *type;
    843  1.2.8.7  nathanw 	int *data;
    844  1.2.8.2  nathanw {
    845  1.2.8.2  nathanw 	char buf[9];
    846  1.2.8.2  nathanw 
    847  1.2.8.2  nathanw 	if (j720kbdcons_initstate < 1)
    848  1.2.8.2  nathanw 		return;
    849  1.2.8.2  nathanw 
    850  1.2.8.2  nathanw 	for (;;) {
    851  1.2.8.2  nathanw 		j720kbd_read(&j720kbdcons_sc, buf);
    852  1.2.8.2  nathanw 
    853  1.2.8.2  nathanw 		if (buf[0] != 0) {
    854  1.2.8.2  nathanw 			/* XXX we are discarding buffer contents */
    855  1.2.8.2  nathanw 			*type = buf[0] & 0x80 ? WSCONS_EVENT_KEY_UP :
    856  1.2.8.2  nathanw 			    WSCONS_EVENT_KEY_DOWN;
    857  1.2.8.2  nathanw 			*data = buf[0] & 0x7f;
    858  1.2.8.2  nathanw 			return;
    859  1.2.8.2  nathanw 		}
    860  1.2.8.2  nathanw 	}
    861  1.2.8.2  nathanw }
    862  1.2.8.2  nathanw 
    863  1.2.8.2  nathanw void
    864  1.2.8.7  nathanw j720kbd_cnpollc(v, on)
    865  1.2.8.7  nathanw 	void *v;
    866  1.2.8.7  nathanw 	int on;
    867  1.2.8.2  nathanw {
    868  1.2.8.2  nathanw #if 0
    869  1.2.8.2  nathanw 	/* XXX */
    870  1.2.8.2  nathanw 	struct j720kbd_internal *t = v;
    871  1.2.8.2  nathanw 
    872  1.2.8.2  nathanw 	pckbc_set_poll(t->t_kbctag, t->t_kbcslot, on);
    873  1.2.8.2  nathanw #endif
    874  1.2.8.2  nathanw }
    875  1.2.8.2  nathanw 
    876  1.2.8.2  nathanw void
    877  1.2.8.7  nathanw j720kbd_cnbell(v, pitch, period, volume)
    878  1.2.8.7  nathanw 	void *v;
    879  1.2.8.7  nathanw 	u_int pitch;
    880  1.2.8.7  nathanw 	u_int period;
    881  1.2.8.7  nathanw 	u_int volume;
    882  1.2.8.2  nathanw {
    883  1.2.8.2  nathanw }
    884  1.2.8.2  nathanw 
    885  1.2.8.2  nathanw int
    886  1.2.8.7  nathanw j720lcdpower(ctx, type, id, msg)
    887  1.2.8.7  nathanw 	void *ctx;
    888  1.2.8.7  nathanw 	int type;
    889  1.2.8.7  nathanw 	long id;
    890  1.2.8.7  nathanw 	void *msg;
    891  1.2.8.2  nathanw {
    892  1.2.8.2  nathanw 	struct sed1356_softc *sc = ctx;
    893  1.2.8.2  nathanw 	struct sa11x0_softc *psc = sc->sc_parent;
    894  1.2.8.2  nathanw 	int val;
    895  1.2.8.2  nathanw 	u_int32_t reg;
    896  1.2.8.2  nathanw 
    897  1.2.8.2  nathanw 	if (type != CONFIG_HOOK_POWERCONTROL ||
    898  1.2.8.2  nathanw 	    id != CONFIG_HOOK_POWERCONTROL_LCDLIGHT)
    899  1.2.8.2  nathanw 		return 0;
    900  1.2.8.2  nathanw 
    901  1.2.8.2  nathanw 	sed1356_init_brightness(sc, 0);
    902  1.2.8.2  nathanw 	sed1356_init_contrast(sc, 0);
    903  1.2.8.2  nathanw 
    904  1.2.8.2  nathanw 	if (msg) {
    905  1.2.8.2  nathanw 		bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 0);
    906  1.2.8.2  nathanw 
    907  1.2.8.2  nathanw 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    908  1.2.8.2  nathanw 		reg |= 0x1;
    909  1.2.8.2  nathanw 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    910  1.2.8.2  nathanw 		delay(50000);
    911  1.2.8.2  nathanw 
    912  1.2.8.2  nathanw 		val = sc->sc_contrast;
    913  1.2.8.2  nathanw 		config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
    914  1.2.8.2  nathanw 		delay(100000);
    915  1.2.8.2  nathanw 
    916  1.2.8.2  nathanw 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    917  1.2.8.2  nathanw 		reg |= 0x4;
    918  1.2.8.2  nathanw 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    919  1.2.8.2  nathanw 
    920  1.2.8.2  nathanw 		val = sc->sc_brightness;
    921  1.2.8.2  nathanw 		config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
    922  1.2.8.2  nathanw 
    923  1.2.8.2  nathanw 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    924  1.2.8.2  nathanw 		reg |= 0x2;
    925  1.2.8.2  nathanw 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    926  1.2.8.2  nathanw 	} else {
    927  1.2.8.2  nathanw 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    928  1.2.8.2  nathanw 		reg &= ~0x2;
    929  1.2.8.2  nathanw 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    930  1.2.8.2  nathanw 		reg &= ~0x4;
    931  1.2.8.2  nathanw 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    932  1.2.8.2  nathanw 		delay(100000);
    933  1.2.8.2  nathanw 
    934  1.2.8.2  nathanw 		val = -2;
    935  1.2.8.2  nathanw 		config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
    936  1.2.8.2  nathanw 
    937  1.2.8.2  nathanw 		bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 1);
    938  1.2.8.2  nathanw 
    939  1.2.8.2  nathanw 		delay(100000);
    940  1.2.8.2  nathanw 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    941  1.2.8.2  nathanw 		reg &= ~0x1;
    942  1.2.8.2  nathanw 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    943  1.2.8.2  nathanw 	}
    944  1.2.8.2  nathanw 	return 1;
    945  1.2.8.2  nathanw }
    946  1.2.8.7  nathanw 
    947  1.2.8.7  nathanw int
    948  1.2.8.7  nathanw hpcarm_apm_getpower(api, parent)
    949  1.2.8.7  nathanw 	struct apm_power_info *api;
    950  1.2.8.7  nathanw 	void *parent;
    951  1.2.8.7  nathanw {
    952  1.2.8.7  nathanw 	int data, pmdata[3], i;
    953  1.2.8.7  nathanw 	struct j720ssp_softc *sc = (struct j720ssp_softc *)parent;
    954  1.2.8.7  nathanw 
    955  1.2.8.7  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
    956  1.2.8.7  nathanw 
    957  1.2.8.7  nathanw 	if (j720ssp_readwrite(sc, 1, 0x300, &data, 100) < 0 || data != 0x88)
    958  1.2.8.7  nathanw 		goto out;
    959  1.2.8.7  nathanw 
    960  1.2.8.7  nathanw 	for (i = 0; i < 3; i++) {
    961  1.2.8.7  nathanw 		if (j720ssp_readwrite(sc, 0, 0x8800, &pmdata[i], 500) < 0)
    962  1.2.8.7  nathanw 			goto out;
    963  1.2.8.7  nathanw 		BIT_INVERT(pmdata[i]);
    964  1.2.8.7  nathanw 	}
    965  1.2.8.7  nathanw 
    966  1.2.8.7  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    967  1.2.8.7  nathanw 
    968  1.2.8.7  nathanw 	bzero(api, sizeof(struct apm_power_info));
    969  1.2.8.7  nathanw 	api->ac_state = APM_AC_UNKNOWN;
    970  1.2.8.7  nathanw 
    971  1.2.8.7  nathanw 	/*
    972  1.2.8.7  nathanw 	 * pmdata[0] is the main battery level
    973  1.2.8.7  nathanw 	 * pmdata[1] is the backup battery level
    974  1.2.8.7  nathanw 	 * pmdata[2] tells which battery is present
    975  1.2.8.7  nathanw 	 */
    976  1.2.8.7  nathanw 	switch(pmdata[2]) {
    977  1.2.8.7  nathanw 	case 14: /* backup battery present */
    978  1.2.8.7  nathanw 	case 2:  /* backup battery absent */
    979  1.2.8.7  nathanw 		api->battery_state = APM_BATT_CHARGING;
    980  1.2.8.7  nathanw 		api->minutes_left = (pmdata[0] * 840) / 170;
    981  1.2.8.7  nathanw 		api->battery_life = (pmdata[0] * 100) / 170;
    982  1.2.8.7  nathanw 		api->nbattery = 1;
    983  1.2.8.7  nathanw 		break;
    984  1.2.8.7  nathanw 	case 15: /* backup battery present */
    985  1.2.8.7  nathanw 	case 3:  /* backup battery absent */
    986  1.2.8.7  nathanw 		api->battery_state = APM_BATT_ABSENT;
    987  1.2.8.7  nathanw 		api->battery_life = 0;
    988  1.2.8.7  nathanw 		api->nbattery = 0;
    989  1.2.8.7  nathanw 		break;
    990  1.2.8.7  nathanw 	default:
    991  1.2.8.7  nathanw 		api->battery_state = APM_BATT_UNKNOWN;
    992  1.2.8.7  nathanw 		break;
    993  1.2.8.7  nathanw 	}
    994  1.2.8.7  nathanw 
    995  1.2.8.7  nathanw 	return 0;
    996  1.2.8.7  nathanw 
    997  1.2.8.7  nathanw out:
    998  1.2.8.7  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    999  1.2.8.7  nathanw 
   1000  1.2.8.7  nathanw 	/* reset SSP */
   1001  1.2.8.7  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
   1002  1.2.8.7  nathanw 	delay(100);
   1003  1.2.8.7  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
   1004  1.2.8.7  nathanw 
   1005  1.2.8.7  nathanw 	printf("hpcarm_apm_getpower: error %x\n", data);
   1006  1.2.8.7  nathanw 	return EIO;
   1007  1.2.8.7  nathanw }
   1008