Home | History | Annotate | Line # | Download | only in dev
j720ssp.c revision 1.2.8.2
      1  1.2.8.2  nathanw /* $NetBSD: j720ssp.c,v 1.2.8.2 2002/01/08 00:24:51 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.2  nathanw #include <sys/param.h>
     78  1.2.8.2  nathanw #include <sys/systm.h>
     79  1.2.8.2  nathanw #include <sys/device.h>
     80  1.2.8.2  nathanw #include <sys/kernel.h>
     81  1.2.8.2  nathanw #include <sys/malloc.h>
     82  1.2.8.2  nathanw #include <sys/ioctl.h>
     83  1.2.8.2  nathanw 
     84  1.2.8.2  nathanw #include <machine/bus.h>
     85  1.2.8.2  nathanw #include <machine/config_hook.h>
     86  1.2.8.2  nathanw 
     87  1.2.8.2  nathanw #include <hpc/hpc/bootinfo.h>
     88  1.2.8.2  nathanw #include <hpc/hpc/config_hook.h>
     89  1.2.8.2  nathanw #include <hpcarm/dev/sed1356var.h>
     90  1.2.8.2  nathanw #include <hpcarm/sa11x0/sa11x0_var.h>
     91  1.2.8.2  nathanw #include <hpcarm/sa11x0/sa11x0_gpioreg.h>
     92  1.2.8.2  nathanw #include <hpcarm/sa11x0/sa11x0_ppcreg.h>
     93  1.2.8.2  nathanw #include <hpcarm/sa11x0/sa11x0_sspreg.h>
     94  1.2.8.2  nathanw 
     95  1.2.8.2  nathanw #include <dev/wscons/wsconsio.h>
     96  1.2.8.2  nathanw #include <dev/wscons/wskbdvar.h>
     97  1.2.8.2  nathanw #include <dev/wscons/wsksymdef.h>
     98  1.2.8.2  nathanw #include <dev/wscons/wsksymvar.h>
     99  1.2.8.2  nathanw 
    100  1.2.8.2  nathanw extern const struct wscons_keydesc j720kbd_keydesctab[];
    101  1.2.8.2  nathanw 
    102  1.2.8.2  nathanw struct j720ssp_softc {
    103  1.2.8.2  nathanw         struct device sc_dev;
    104  1.2.8.2  nathanw 
    105  1.2.8.2  nathanw 	bus_space_tag_t sc_iot;
    106  1.2.8.2  nathanw 	bus_space_handle_t sc_gpioh;
    107  1.2.8.2  nathanw 	bus_space_handle_t sc_ssph;
    108  1.2.8.2  nathanw 
    109  1.2.8.2  nathanw 	struct device *sc_wskbddev;
    110  1.2.8.2  nathanw 
    111  1.2.8.2  nathanw 	void *sc_si;
    112  1.2.8.2  nathanw 	int sc_enabled;
    113  1.2.8.2  nathanw };
    114  1.2.8.2  nathanw 
    115  1.2.8.2  nathanw int j720kbd_intr(void *);
    116  1.2.8.2  nathanw void j720kbdsoft(void *);
    117  1.2.8.2  nathanw int j720lcdparam(void *, int, long, void *);
    118  1.2.8.2  nathanw static void j720kbd_read(struct j720ssp_softc *, char *);
    119  1.2.8.2  nathanw static int j720ssp_readwrite(struct j720ssp_softc *, int, int, int *);
    120  1.2.8.2  nathanw 
    121  1.2.8.2  nathanw int j720sspprobe(struct device *, struct cfdata *, void *);
    122  1.2.8.2  nathanw void j720sspattach(struct device *, struct device *, void *);
    123  1.2.8.2  nathanw 
    124  1.2.8.2  nathanw int j720kbd_enable(void *, int);
    125  1.2.8.2  nathanw void j720kbd_set_leds(void *, int);
    126  1.2.8.2  nathanw int j720kbd_ioctl(void *, u_long, caddr_t, int, struct proc *);
    127  1.2.8.2  nathanw 
    128  1.2.8.2  nathanw struct cfattach j720ssp_ca = {
    129  1.2.8.2  nathanw 	sizeof(struct j720ssp_softc), j720sspprobe, j720sspattach,
    130  1.2.8.2  nathanw };
    131  1.2.8.2  nathanw 
    132  1.2.8.2  nathanw const struct wskbd_accessops j720kbd_accessops = {
    133  1.2.8.2  nathanw 	j720kbd_enable,
    134  1.2.8.2  nathanw 	j720kbd_set_leds,
    135  1.2.8.2  nathanw 	j720kbd_ioctl,
    136  1.2.8.2  nathanw };
    137  1.2.8.2  nathanw 
    138  1.2.8.2  nathanw void j720kbd_cngetc(void *, u_int *, int *);
    139  1.2.8.2  nathanw void j720kbd_cnpollc(void *, int);
    140  1.2.8.2  nathanw void j720kbd_cnbell(void *, u_int, u_int, u_int);
    141  1.2.8.2  nathanw 
    142  1.2.8.2  nathanw const struct wskbd_consops j720kbd_consops = {
    143  1.2.8.2  nathanw 	j720kbd_cngetc,
    144  1.2.8.2  nathanw 	j720kbd_cnpollc,
    145  1.2.8.2  nathanw 	j720kbd_cnbell,
    146  1.2.8.2  nathanw };
    147  1.2.8.2  nathanw 
    148  1.2.8.2  nathanw const struct wskbd_mapdata j720kbd_keymapdata = {
    149  1.2.8.2  nathanw 	j720kbd_keydesctab,
    150  1.2.8.2  nathanw #ifdef J720KBD_LAYOUT
    151  1.2.8.2  nathanw 	J720KBD_LAYOUT,
    152  1.2.8.2  nathanw #else
    153  1.2.8.2  nathanw 	KB_US,
    154  1.2.8.2  nathanw #endif
    155  1.2.8.2  nathanw };
    156  1.2.8.2  nathanw 
    157  1.2.8.2  nathanw static int j720ssp_powerstate = 1;
    158  1.2.8.2  nathanw 
    159  1.2.8.2  nathanw static struct j720ssp_softc j720kbdcons_sc;
    160  1.2.8.2  nathanw static int j720kbdcons_initstate = 0;
    161  1.2.8.2  nathanw 
    162  1.2.8.2  nathanw #define DEBUG
    163  1.2.8.2  nathanw #ifdef DEBUG
    164  1.2.8.2  nathanw int j720sspwaitcnt;
    165  1.2.8.2  nathanw int j720sspwaittime;
    166  1.2.8.2  nathanw extern int gettick();
    167  1.2.8.2  nathanw #endif
    168  1.2.8.2  nathanw 
    169  1.2.8.2  nathanw #define BIT_INVERT(x)	do {					\
    170  1.2.8.2  nathanw 	(x) = ((((x) & 0xf0) >> 4) | (((x) & 0x0f) << 4));	\
    171  1.2.8.2  nathanw 	(x) = ((((x) & 0xcc) >> 2) | (((x) & 0x33) << 2));	\
    172  1.2.8.2  nathanw 	(x) = ((((x) & 0xaa) >> 1) | (((x) & 0x55) << 1));	\
    173  1.2.8.2  nathanw 	} while(0)
    174  1.2.8.2  nathanw 
    175  1.2.8.2  nathanw int
    176  1.2.8.2  nathanw j720sspprobe(struct device *parent, struct cfdata *cf, void *aux)
    177  1.2.8.2  nathanw {
    178  1.2.8.2  nathanw 	return (1);
    179  1.2.8.2  nathanw }
    180  1.2.8.2  nathanw 
    181  1.2.8.2  nathanw void
    182  1.2.8.2  nathanw j720sspattach(struct device *parent, struct device *self, void *aux)
    183  1.2.8.2  nathanw {
    184  1.2.8.2  nathanw 	struct j720ssp_softc *sc = (void *)self;
    185  1.2.8.2  nathanw 	struct sa11x0_softc *psc = (void *)parent;
    186  1.2.8.2  nathanw 	struct sa11x0_attach_args *sa = aux;
    187  1.2.8.2  nathanw 	struct wskbddev_attach_args a;
    188  1.2.8.2  nathanw 
    189  1.2.8.2  nathanw 	printf("\n");
    190  1.2.8.2  nathanw 
    191  1.2.8.2  nathanw 	sc->sc_iot = psc->sc_iot;
    192  1.2.8.2  nathanw 	sc->sc_gpioh = psc->sc_gpioh;
    193  1.2.8.2  nathanw 	if (bus_space_map(sc->sc_iot, sa->sa_addr, sa->sa_size, 0,
    194  1.2.8.2  nathanw 			  &sc->sc_ssph)) {
    195  1.2.8.2  nathanw 		printf("%s: unable to map SSP registers\n",
    196  1.2.8.2  nathanw 		       sc->sc_dev.dv_xname);
    197  1.2.8.2  nathanw 		return;
    198  1.2.8.2  nathanw 	}
    199  1.2.8.2  nathanw 
    200  1.2.8.2  nathanw 	sc->sc_si = softintr_establish(IPL_SOFTCLOCK, j720kbdsoft, sc);
    201  1.2.8.2  nathanw 
    202  1.2.8.2  nathanw 	sc->sc_enabled = 0;
    203  1.2.8.2  nathanw 
    204  1.2.8.2  nathanw 	a.console = 0;
    205  1.2.8.2  nathanw 
    206  1.2.8.2  nathanw 	a.keymap = &j720kbd_keymapdata;
    207  1.2.8.2  nathanw 
    208  1.2.8.2  nathanw 	a.accessops = &j720kbd_accessops;
    209  1.2.8.2  nathanw 	a.accesscookie = sc;
    210  1.2.8.2  nathanw 
    211  1.2.8.2  nathanw 	/* Do console initialization */
    212  1.2.8.2  nathanw 	if (! (bootinfo->bi_cnuse & BI_CNUSE_SERIAL)) {
    213  1.2.8.2  nathanw 		j720kbdcons_sc = *sc;
    214  1.2.8.2  nathanw 		a.console = 1;
    215  1.2.8.2  nathanw 
    216  1.2.8.2  nathanw 		wskbd_cnattach(&j720kbd_consops, NULL, &j720kbd_keymapdata);
    217  1.2.8.2  nathanw 		j720kbdcons_initstate = 1;
    218  1.2.8.2  nathanw 	}
    219  1.2.8.2  nathanw 
    220  1.2.8.2  nathanw 	/*
    221  1.2.8.2  nathanw 	 * Attach the wskbd, saving a handle to it.
    222  1.2.8.2  nathanw 	 * XXX XXX XXX
    223  1.2.8.2  nathanw 	 */
    224  1.2.8.2  nathanw 	sc->sc_wskbddev = config_found(self, &a, wskbddevprint);
    225  1.2.8.2  nathanw 
    226  1.2.8.2  nathanw #ifdef DEBUG
    227  1.2.8.2  nathanw 	/* Zero the stat counters */
    228  1.2.8.2  nathanw 	j720sspwaitcnt = 0;
    229  1.2.8.2  nathanw 	j720sspwaittime = 0;
    230  1.2.8.2  nathanw #endif
    231  1.2.8.2  nathanw 
    232  1.2.8.2  nathanw 	if (j720kbdcons_initstate == 1)
    233  1.2.8.2  nathanw 		j720kbd_enable(sc, 1);
    234  1.2.8.2  nathanw 
    235  1.2.8.2  nathanw 	/* LCD control is on the same bus */
    236  1.2.8.2  nathanw 	config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS,
    237  1.2.8.2  nathanw 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    238  1.2.8.2  nathanw 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS,
    239  1.2.8.2  nathanw 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    240  1.2.8.2  nathanw 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS_MAX,
    241  1.2.8.2  nathanw 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    242  1.2.8.2  nathanw 
    243  1.2.8.2  nathanw 	config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST,
    244  1.2.8.2  nathanw 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    245  1.2.8.2  nathanw 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST,
    246  1.2.8.2  nathanw 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    247  1.2.8.2  nathanw 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST_MAX,
    248  1.2.8.2  nathanw 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    249  1.2.8.2  nathanw }
    250  1.2.8.2  nathanw 
    251  1.2.8.2  nathanw int
    252  1.2.8.2  nathanw j720kbd_enable(void *v, int on)
    253  1.2.8.2  nathanw {
    254  1.2.8.2  nathanw 	struct j720ssp_softc *sc = v;
    255  1.2.8.2  nathanw 
    256  1.2.8.2  nathanw 	if (! sc->sc_enabled) {
    257  1.2.8.2  nathanw 		sc->sc_enabled = 1;
    258  1.2.8.2  nathanw 
    259  1.2.8.2  nathanw 		sa11x0_intr_establish(0, 0, 1, IPL_BIO, j720kbd_intr, sc);
    260  1.2.8.2  nathanw 	}
    261  1.2.8.2  nathanw 	/* XXX */
    262  1.2.8.2  nathanw 	return (0);
    263  1.2.8.2  nathanw }
    264  1.2.8.2  nathanw 
    265  1.2.8.2  nathanw void
    266  1.2.8.2  nathanw j720kbd_set_leds(void *v, int on)
    267  1.2.8.2  nathanw {
    268  1.2.8.2  nathanw 	/* XXX */
    269  1.2.8.2  nathanw 	return;
    270  1.2.8.2  nathanw }
    271  1.2.8.2  nathanw 
    272  1.2.8.2  nathanw int
    273  1.2.8.2  nathanw j720kbd_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
    274  1.2.8.2  nathanw {
    275  1.2.8.2  nathanw 	return (-1);
    276  1.2.8.2  nathanw }
    277  1.2.8.2  nathanw 
    278  1.2.8.2  nathanw int
    279  1.2.8.2  nathanw j720kbd_intr(void *arg)
    280  1.2.8.2  nathanw {
    281  1.2.8.2  nathanw 	struct j720ssp_softc *sc = arg;
    282  1.2.8.2  nathanw 
    283  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 1);
    284  1.2.8.2  nathanw 
    285  1.2.8.2  nathanw 	/*
    286  1.2.8.2  nathanw 	 * Schedule a soft interrupt to process at lower priority,
    287  1.2.8.2  nathanw 	 * as reading keycodes takes time.
    288  1.2.8.2  nathanw 	 *
    289  1.2.8.2  nathanw 	 * Interrupts are generated every 25-33ms as long as there
    290  1.2.8.2  nathanw 	 * are unprocessed key events.  So it is not a good idea to
    291  1.2.8.2  nathanw 	 * use callout to call j720kbdsoft after some delay in hope
    292  1.2.8.2  nathanw 	 * of reducing interrupts.
    293  1.2.8.2  nathanw 	 */
    294  1.2.8.2  nathanw 	softintr_schedule(sc->sc_si);
    295  1.2.8.2  nathanw 
    296  1.2.8.2  nathanw 	return (1);
    297  1.2.8.2  nathanw }
    298  1.2.8.2  nathanw 
    299  1.2.8.2  nathanw void
    300  1.2.8.2  nathanw j720kbdsoft(void *arg)
    301  1.2.8.2  nathanw {
    302  1.2.8.2  nathanw 	struct j720ssp_softc *sc = arg;
    303  1.2.8.2  nathanw 	int s, type, value;
    304  1.2.8.2  nathanw 	char buf[9], *p;
    305  1.2.8.2  nathanw 
    306  1.2.8.2  nathanw 	j720kbd_read(sc, buf);
    307  1.2.8.2  nathanw 
    308  1.2.8.2  nathanw 	for(p = buf; *p; p++) {
    309  1.2.8.2  nathanw 		type = *p & 0x80 ? WSCONS_EVENT_KEY_UP :
    310  1.2.8.2  nathanw 		    WSCONS_EVENT_KEY_DOWN;
    311  1.2.8.2  nathanw 		value = *p & 0x7f;
    312  1.2.8.2  nathanw 		s = spltty();
    313  1.2.8.2  nathanw 		wskbd_input(sc->sc_wskbddev, type, value);
    314  1.2.8.2  nathanw 		splx(s);
    315  1.2.8.2  nathanw 		if (type == WSCONS_EVENT_KEY_DOWN &&
    316  1.2.8.2  nathanw 		    value == 0x7f) {
    317  1.2.8.2  nathanw 			j720ssp_powerstate = ! j720ssp_powerstate;
    318  1.2.8.2  nathanw 			config_hook_call(CONFIG_HOOK_POWERCONTROL,
    319  1.2.8.2  nathanw 					 CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
    320  1.2.8.2  nathanw 					 (void *)j720ssp_powerstate);
    321  1.2.8.2  nathanw 		}
    322  1.2.8.2  nathanw 	}
    323  1.2.8.2  nathanw 
    324  1.2.8.2  nathanw 	return;
    325  1.2.8.2  nathanw }
    326  1.2.8.2  nathanw 
    327  1.2.8.2  nathanw void
    328  1.2.8.2  nathanw j720kbd_read(struct j720ssp_softc *sc, char *buf)
    329  1.2.8.2  nathanw {
    330  1.2.8.2  nathanw 	int data, count;
    331  1.2.8.2  nathanw #ifdef DEBUG
    332  1.2.8.2  nathanw 	u_int32_t oscr;
    333  1.2.8.2  nathanw 
    334  1.2.8.2  nathanw 	oscr = gettick();
    335  1.2.8.2  nathanw #endif
    336  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
    337  1.2.8.2  nathanw 
    338  1.2.8.2  nathanw 	/* send scan keycode command */
    339  1.2.8.2  nathanw 	if (j720ssp_readwrite(sc, 1, 0x900, &data) < 0 ||
    340  1.2.8.2  nathanw 	    data != 0x88)
    341  1.2.8.2  nathanw 		goto out;
    342  1.2.8.2  nathanw 
    343  1.2.8.2  nathanw 	/* read numbers of scancode available */
    344  1.2.8.2  nathanw 	if (j720ssp_readwrite(sc, 0, 0x8800, &data) < 0)
    345  1.2.8.2  nathanw 		goto out;
    346  1.2.8.2  nathanw 	BIT_INVERT(data);
    347  1.2.8.2  nathanw 	count = data;
    348  1.2.8.2  nathanw 
    349  1.2.8.2  nathanw 	for(; count; count--) {
    350  1.2.8.2  nathanw 		if (j720ssp_readwrite(sc, 0, 0x8800, &data) < 0)
    351  1.2.8.2  nathanw 			goto out;
    352  1.2.8.2  nathanw 		BIT_INVERT(data);
    353  1.2.8.2  nathanw 		*buf++ = data;
    354  1.2.8.2  nathanw 	}
    355  1.2.8.2  nathanw 	*buf = 0;
    356  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    357  1.2.8.2  nathanw 
    358  1.2.8.2  nathanw #ifdef DEBUG
    359  1.2.8.2  nathanw 	oscr = (u_int32_t)gettick() - oscr;
    360  1.2.8.2  nathanw 	j720sspwaitcnt++;
    361  1.2.8.2  nathanw 	j720sspwaittime += oscr;
    362  1.2.8.2  nathanw #endif
    363  1.2.8.2  nathanw 
    364  1.2.8.2  nathanw 	return;
    365  1.2.8.2  nathanw 
    366  1.2.8.2  nathanw out:
    367  1.2.8.2  nathanw 	*buf = 0;
    368  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    369  1.2.8.2  nathanw 
    370  1.2.8.2  nathanw 	/* reset SSP */
    371  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
    372  1.2.8.2  nathanw 	delay(100);
    373  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
    374  1.2.8.2  nathanw printf("j720kbd_read: error %x\n", data);
    375  1.2.8.2  nathanw }
    376  1.2.8.2  nathanw 
    377  1.2.8.2  nathanw int
    378  1.2.8.2  nathanw j720lcdparam(void *ctx, int type, long id, void *msg)
    379  1.2.8.2  nathanw {
    380  1.2.8.2  nathanw 	struct j720ssp_softc *sc = ctx;
    381  1.2.8.2  nathanw 	int i, s;
    382  1.2.8.2  nathanw 	u_int32_t data[2], len;
    383  1.2.8.2  nathanw 
    384  1.2.8.2  nathanw 	switch (type) {
    385  1.2.8.2  nathanw 	case CONFIG_HOOK_GET:
    386  1.2.8.2  nathanw 		switch (id) {
    387  1.2.8.2  nathanw 		case CONFIG_HOOK_BRIGHTNESS_MAX:
    388  1.2.8.2  nathanw 		case CONFIG_HOOK_CONTRAST_MAX:
    389  1.2.8.2  nathanw 			*(int *)msg = 255;
    390  1.2.8.2  nathanw 			return 1;
    391  1.2.8.2  nathanw 		case CONFIG_HOOK_BRIGHTNESS:
    392  1.2.8.2  nathanw 			data[0] = 0x6b00;
    393  1.2.8.2  nathanw 			data[1] = 0x8800;
    394  1.2.8.2  nathanw 			len = 2;
    395  1.2.8.2  nathanw 			break;
    396  1.2.8.2  nathanw 		case CONFIG_HOOK_CONTRAST:
    397  1.2.8.2  nathanw 			data[0] = 0x2b00;
    398  1.2.8.2  nathanw 			data[1] = 0x8800;
    399  1.2.8.2  nathanw 			len = 2;
    400  1.2.8.2  nathanw 			break;
    401  1.2.8.2  nathanw 		default:
    402  1.2.8.2  nathanw 			return 0;
    403  1.2.8.2  nathanw 		}
    404  1.2.8.2  nathanw 		break;
    405  1.2.8.2  nathanw 
    406  1.2.8.2  nathanw 	case CONFIG_HOOK_SET:
    407  1.2.8.2  nathanw 		switch (id) {
    408  1.2.8.2  nathanw 		case CONFIG_HOOK_BRIGHTNESS:
    409  1.2.8.2  nathanw 			if (*(int *)msg >= 0) {
    410  1.2.8.2  nathanw 				data[0] = 0xcb00;
    411  1.2.8.2  nathanw 				data[1] = *(int *)msg;
    412  1.2.8.2  nathanw 				BIT_INVERT(data[1]);
    413  1.2.8.2  nathanw 				data[1] <<= 8;
    414  1.2.8.2  nathanw 				len = 2;
    415  1.2.8.2  nathanw 			} else {
    416  1.2.8.2  nathanw 				/* XXX hack */
    417  1.2.8.2  nathanw 				data[0] = 0xfb00;
    418  1.2.8.2  nathanw 				len = 1;
    419  1.2.8.2  nathanw 			}
    420  1.2.8.2  nathanw 			break;
    421  1.2.8.2  nathanw 		case CONFIG_HOOK_CONTRAST:
    422  1.2.8.2  nathanw 			data[0] = 0x8b00;
    423  1.2.8.2  nathanw 			data[1] = *(int *)msg;
    424  1.2.8.2  nathanw 			BIT_INVERT(data[1]);
    425  1.2.8.2  nathanw 			data[1] <<= 8;
    426  1.2.8.2  nathanw 			len = 2;
    427  1.2.8.2  nathanw 			break;
    428  1.2.8.2  nathanw 		default:
    429  1.2.8.2  nathanw 			return 0;
    430  1.2.8.2  nathanw 		}
    431  1.2.8.2  nathanw 	}
    432  1.2.8.2  nathanw 
    433  1.2.8.2  nathanw 	s = splbio();
    434  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
    435  1.2.8.2  nathanw 
    436  1.2.8.2  nathanw 	for (i = 0; i < len; i++) {
    437  1.2.8.2  nathanw 		if (j720ssp_readwrite(sc, 1, data[i], &data[i]) < 0)
    438  1.2.8.2  nathanw 			goto out;
    439  1.2.8.2  nathanw 	}
    440  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    441  1.2.8.2  nathanw 	splx(s);
    442  1.2.8.2  nathanw 
    443  1.2.8.2  nathanw 	if (type == CONFIG_HOOK_SET)
    444  1.2.8.2  nathanw 		return 1;
    445  1.2.8.2  nathanw 
    446  1.2.8.2  nathanw 	BIT_INVERT(data[1]);
    447  1.2.8.2  nathanw 	*(int *)msg = data[1];
    448  1.2.8.2  nathanw 
    449  1.2.8.2  nathanw 	return 1;
    450  1.2.8.2  nathanw 
    451  1.2.8.2  nathanw out:
    452  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    453  1.2.8.2  nathanw 
    454  1.2.8.2  nathanw 	/* reset SSP */
    455  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
    456  1.2.8.2  nathanw 	delay(100);
    457  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
    458  1.2.8.2  nathanw 	splx(s);
    459  1.2.8.2  nathanw 	return 0;
    460  1.2.8.2  nathanw }
    461  1.2.8.2  nathanw 
    462  1.2.8.2  nathanw static int
    463  1.2.8.2  nathanw j720ssp_readwrite(struct j720ssp_softc *sc, int drainfifo, int in, int *out)
    464  1.2.8.2  nathanw {
    465  1.2.8.2  nathanw 	int timo;
    466  1.2.8.2  nathanw 
    467  1.2.8.2  nathanw 	timo = 100000;
    468  1.2.8.2  nathanw 	while(bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PLR) & 0x400)
    469  1.2.8.2  nathanw 		if (--timo == 0) {
    470  1.2.8.2  nathanw 			printf("timo0\n");
    471  1.2.8.2  nathanw 			return -1;
    472  1.2.8.2  nathanw 		}
    473  1.2.8.2  nathanw 	if (drainfifo) {
    474  1.2.8.2  nathanw 		while(bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) &
    475  1.2.8.2  nathanw 		      SR_RNE)
    476  1.2.8.2  nathanw 			bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
    477  1.2.8.2  nathanw #if 1
    478  1.2.8.2  nathanw 		delay(5000);
    479  1.2.8.2  nathanw #endif
    480  1.2.8.2  nathanw 	}
    481  1.2.8.2  nathanw 
    482  1.2.8.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_DR, in);
    483  1.2.8.2  nathanw 
    484  1.2.8.2  nathanw 	delay(5000);
    485  1.2.8.2  nathanw 	timo = 100000;
    486  1.2.8.2  nathanw 	while(! (bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) & SR_RNE))
    487  1.2.8.2  nathanw 		if (--timo == 0) {
    488  1.2.8.2  nathanw 			printf("timo1\n");
    489  1.2.8.2  nathanw 			return -1;
    490  1.2.8.2  nathanw 		}
    491  1.2.8.2  nathanw 
    492  1.2.8.2  nathanw 	*out = bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
    493  1.2.8.2  nathanw 
    494  1.2.8.2  nathanw 	return 0;
    495  1.2.8.2  nathanw }
    496  1.2.8.2  nathanw 
    497  1.2.8.2  nathanw #if 0
    498  1.2.8.2  nathanw int
    499  1.2.8.2  nathanw j720kbd_cnattach()
    500  1.2.8.2  nathanw {
    501  1.2.8.2  nathanw 	/* XXX defer initialization till j720sspattach */
    502  1.2.8.2  nathanw 
    503  1.2.8.2  nathanw 	return (0);
    504  1.2.8.2  nathanw }
    505  1.2.8.2  nathanw #endif
    506  1.2.8.2  nathanw 
    507  1.2.8.2  nathanw /* ARGSUSED */
    508  1.2.8.2  nathanw void
    509  1.2.8.2  nathanw j720kbd_cngetc(void *v, u_int *type, int *data)
    510  1.2.8.2  nathanw {
    511  1.2.8.2  nathanw 	char buf[9];
    512  1.2.8.2  nathanw 
    513  1.2.8.2  nathanw 	if (j720kbdcons_initstate < 1)
    514  1.2.8.2  nathanw 		return;
    515  1.2.8.2  nathanw 
    516  1.2.8.2  nathanw 	for (;;) {
    517  1.2.8.2  nathanw 		j720kbd_read(&j720kbdcons_sc, buf);
    518  1.2.8.2  nathanw 
    519  1.2.8.2  nathanw 		if (buf[0] != 0) {
    520  1.2.8.2  nathanw 			/* XXX we are discarding buffer contents */
    521  1.2.8.2  nathanw 			*type = buf[0] & 0x80 ? WSCONS_EVENT_KEY_UP :
    522  1.2.8.2  nathanw 			    WSCONS_EVENT_KEY_DOWN;
    523  1.2.8.2  nathanw 			*data = buf[0] & 0x7f;
    524  1.2.8.2  nathanw 			return;
    525  1.2.8.2  nathanw 		}
    526  1.2.8.2  nathanw 	}
    527  1.2.8.2  nathanw }
    528  1.2.8.2  nathanw 
    529  1.2.8.2  nathanw void
    530  1.2.8.2  nathanw j720kbd_cnpollc(void *v, int on)
    531  1.2.8.2  nathanw {
    532  1.2.8.2  nathanw #if 0
    533  1.2.8.2  nathanw 	/* XXX */
    534  1.2.8.2  nathanw 	struct j720kbd_internal *t = v;
    535  1.2.8.2  nathanw 
    536  1.2.8.2  nathanw 	pckbc_set_poll(t->t_kbctag, t->t_kbcslot, on);
    537  1.2.8.2  nathanw #endif
    538  1.2.8.2  nathanw }
    539  1.2.8.2  nathanw 
    540  1.2.8.2  nathanw void
    541  1.2.8.2  nathanw j720kbd_cnbell(void *v, u_int pitch, u_int period, u_int volume)
    542  1.2.8.2  nathanw {
    543  1.2.8.2  nathanw }
    544  1.2.8.2  nathanw 
    545  1.2.8.2  nathanw int
    546  1.2.8.2  nathanw j720lcdpower(void *ctx, int type, long id, void *msg)
    547  1.2.8.2  nathanw {
    548  1.2.8.2  nathanw 	struct sed1356_softc *sc = ctx;
    549  1.2.8.2  nathanw 	struct sa11x0_softc *psc = sc->sc_parent;
    550  1.2.8.2  nathanw 	int val;
    551  1.2.8.2  nathanw 	u_int32_t reg;
    552  1.2.8.2  nathanw 
    553  1.2.8.2  nathanw 	if (type != CONFIG_HOOK_POWERCONTROL ||
    554  1.2.8.2  nathanw 	    id != CONFIG_HOOK_POWERCONTROL_LCDLIGHT)
    555  1.2.8.2  nathanw 		return 0;
    556  1.2.8.2  nathanw 
    557  1.2.8.2  nathanw 	sed1356_init_brightness(sc, 0);
    558  1.2.8.2  nathanw 	sed1356_init_contrast(sc, 0);
    559  1.2.8.2  nathanw 
    560  1.2.8.2  nathanw 	if (msg) {
    561  1.2.8.2  nathanw 		bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 0);
    562  1.2.8.2  nathanw 
    563  1.2.8.2  nathanw 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    564  1.2.8.2  nathanw 		reg |= 0x1;
    565  1.2.8.2  nathanw 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    566  1.2.8.2  nathanw 		delay(50000);
    567  1.2.8.2  nathanw 
    568  1.2.8.2  nathanw 		val = sc->sc_contrast;
    569  1.2.8.2  nathanw 		config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
    570  1.2.8.2  nathanw 		delay(100000);
    571  1.2.8.2  nathanw 
    572  1.2.8.2  nathanw 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    573  1.2.8.2  nathanw 		reg |= 0x4;
    574  1.2.8.2  nathanw 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    575  1.2.8.2  nathanw 
    576  1.2.8.2  nathanw 		val = sc->sc_brightness;
    577  1.2.8.2  nathanw 		config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
    578  1.2.8.2  nathanw 
    579  1.2.8.2  nathanw 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    580  1.2.8.2  nathanw 		reg |= 0x2;
    581  1.2.8.2  nathanw 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    582  1.2.8.2  nathanw 	} else {
    583  1.2.8.2  nathanw 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    584  1.2.8.2  nathanw 		reg &= ~0x2;
    585  1.2.8.2  nathanw 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    586  1.2.8.2  nathanw 		reg &= ~0x4;
    587  1.2.8.2  nathanw 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    588  1.2.8.2  nathanw 		delay(100000);
    589  1.2.8.2  nathanw 
    590  1.2.8.2  nathanw 		val = -2;
    591  1.2.8.2  nathanw 		config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
    592  1.2.8.2  nathanw 
    593  1.2.8.2  nathanw 		bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 1);
    594  1.2.8.2  nathanw 
    595  1.2.8.2  nathanw 		delay(100000);
    596  1.2.8.2  nathanw 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    597  1.2.8.2  nathanw 		reg &= ~0x1;
    598  1.2.8.2  nathanw 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    599  1.2.8.2  nathanw 	}
    600  1.2.8.2  nathanw 	return 1;
    601  1.2.8.2  nathanw }
    602