Home | History | Annotate | Line # | Download | only in dev
j720ssp.c revision 1.1
      1  1.1  toshii /* $NetBSD: j720ssp.c,v 1.1 2001/06/23 09:20:05 toshii Exp $ */
      2  1.1  toshii 
      3  1.1  toshii /*-
      4  1.1  toshii  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
      5  1.1  toshii  * All rights reserved.
      6  1.1  toshii  *
      7  1.1  toshii  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  toshii  * by Charles M. Hannum.
      9  1.1  toshii  *
     10  1.1  toshii  * Redistribution and use in source and binary forms, with or without
     11  1.1  toshii  * modification, are permitted provided that the following conditions
     12  1.1  toshii  * are met:
     13  1.1  toshii  * 1. Redistributions of source code must retain the above copyright
     14  1.1  toshii  *    notice, this list of conditions and the following disclaimer.
     15  1.1  toshii  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  toshii  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  toshii  *    documentation and/or other materials provided with the distribution.
     18  1.1  toshii  * 3. All advertising materials mentioning features or use of this software
     19  1.1  toshii  *    must display the following acknowledgement:
     20  1.1  toshii  *        This product includes software developed by the NetBSD
     21  1.1  toshii  *        Foundation, Inc. and its contributors.
     22  1.1  toshii  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  toshii  *    contributors may be used to endorse or promote products derived
     24  1.1  toshii  *    from this software without specific prior written permission.
     25  1.1  toshii  *
     26  1.1  toshii  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  toshii  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  toshii  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  toshii  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  toshii  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  toshii  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  toshii  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  toshii  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  toshii  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  toshii  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  toshii  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  toshii  */
     38  1.1  toshii 
     39  1.1  toshii /*-
     40  1.1  toshii  * Copyright (c) 1990 The Regents of the University of California.
     41  1.1  toshii  * All rights reserved.
     42  1.1  toshii  *
     43  1.1  toshii  * This code is derived from software contributed to Berkeley by
     44  1.1  toshii  * William Jolitz and Don Ahn.
     45  1.1  toshii  *
     46  1.1  toshii  * Redistribution and use in source and binary forms, with or without
     47  1.1  toshii  * modification, are permitted provided that the following conditions
     48  1.1  toshii  * are met:
     49  1.1  toshii  * 1. Redistributions of source code must retain the above copyright
     50  1.1  toshii  *    notice, this list of conditions and the following disclaimer.
     51  1.1  toshii  * 2. Redistributions in binary form must reproduce the above copyright
     52  1.1  toshii  *    notice, this list of conditions and the following disclaimer in the
     53  1.1  toshii  *    documentation and/or other materials provided with the distribution.
     54  1.1  toshii  * 3. All advertising materials mentioning features or use of this software
     55  1.1  toshii  *    must display the following acknowledgement:
     56  1.1  toshii  *	This product includes software developed by the University of
     57  1.1  toshii  *	California, Berkeley and its contributors.
     58  1.1  toshii  * 4. Neither the name of the University nor the names of its contributors
     59  1.1  toshii  *    may be used to endorse or promote products derived from this software
     60  1.1  toshii  *    without specific prior written permission.
     61  1.1  toshii  *
     62  1.1  toshii  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     63  1.1  toshii  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     64  1.1  toshii  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     65  1.1  toshii  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     66  1.1  toshii  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     67  1.1  toshii  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     68  1.1  toshii  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     69  1.1  toshii  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     70  1.1  toshii  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     71  1.1  toshii  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     72  1.1  toshii  * SUCH DAMAGE.
     73  1.1  toshii  *
     74  1.1  toshii  *	@(#)pccons.c	5.11 (Berkeley) 5/21/91
     75  1.1  toshii  */
     76  1.1  toshii 
     77  1.1  toshii #include <sys/param.h>
     78  1.1  toshii #include <sys/systm.h>
     79  1.1  toshii #include <sys/device.h>
     80  1.1  toshii #include <sys/kernel.h>
     81  1.1  toshii #include <sys/malloc.h>
     82  1.1  toshii #include <sys/ioctl.h>
     83  1.1  toshii 
     84  1.1  toshii #include <machine/bus.h>
     85  1.1  toshii #include <machine/config_hook.h>
     86  1.1  toshii 
     87  1.1  toshii #include <hpc/hpc/config_hook.h>
     88  1.1  toshii #include <hpcarm/dev/sed1356var.h>
     89  1.1  toshii #include <hpcarm/sa11x0/sa11x0_var.h>
     90  1.1  toshii #include <hpcarm/sa11x0/sa11x0_gpioreg.h>
     91  1.1  toshii #include <hpcarm/sa11x0/sa11x0_ppcreg.h>
     92  1.1  toshii #include <hpcarm/sa11x0/sa11x0_sspreg.h>
     93  1.1  toshii 
     94  1.1  toshii #include <dev/wscons/wsconsio.h>
     95  1.1  toshii #include <dev/wscons/wskbdvar.h>
     96  1.1  toshii #include <dev/wscons/wsksymdef.h>
     97  1.1  toshii #include <dev/wscons/wsksymvar.h>
     98  1.1  toshii 
     99  1.1  toshii extern const struct wscons_keydesc j720kbd_keydesctab[];
    100  1.1  toshii 
    101  1.1  toshii struct j720ssp_softc {
    102  1.1  toshii         struct device sc_dev;
    103  1.1  toshii 
    104  1.1  toshii 	bus_space_tag_t sc_iot;
    105  1.1  toshii 	bus_space_handle_t sc_gpioh;
    106  1.1  toshii 	bus_space_handle_t sc_ssph;
    107  1.1  toshii 
    108  1.1  toshii 	struct device *sc_wskbddev;
    109  1.1  toshii 
    110  1.1  toshii 	void *sc_si;
    111  1.1  toshii 	int sc_enabled;
    112  1.1  toshii };
    113  1.1  toshii 
    114  1.1  toshii int j720kbd_intr(void *);
    115  1.1  toshii void j720kbdsoft(void *);
    116  1.1  toshii int j720lcdparam(void *, int, long, void *);
    117  1.1  toshii static void j720kbd_read(struct j720ssp_softc *, char *);
    118  1.1  toshii static int j720ssp_readwrite(struct j720ssp_softc *, int, int, int *);
    119  1.1  toshii 
    120  1.1  toshii int j720sspprobe(struct device *, struct cfdata *, void *);
    121  1.1  toshii void j720sspattach(struct device *, struct device *, void *);
    122  1.1  toshii 
    123  1.1  toshii int j720kbd_enable(void *, int);
    124  1.1  toshii void j720kbd_set_leds(void *, int);
    125  1.1  toshii int j720kbd_ioctl(void *, u_long, caddr_t, int, struct proc *);
    126  1.1  toshii 
    127  1.1  toshii struct cfattach j720ssp_ca = {
    128  1.1  toshii 	sizeof(struct j720ssp_softc), j720sspprobe, j720sspattach,
    129  1.1  toshii };
    130  1.1  toshii 
    131  1.1  toshii const struct wskbd_accessops j720kbd_accessops = {
    132  1.1  toshii 	j720kbd_enable,
    133  1.1  toshii 	j720kbd_set_leds,
    134  1.1  toshii 	j720kbd_ioctl,
    135  1.1  toshii };
    136  1.1  toshii 
    137  1.1  toshii void j720kbd_cngetc(void *, u_int *, int *);
    138  1.1  toshii void j720kbd_cnpollc(void *, int);
    139  1.1  toshii void j720kbd_cnbell(void *, u_int, u_int, u_int);
    140  1.1  toshii 
    141  1.1  toshii const struct wskbd_consops j720kbd_consops = {
    142  1.1  toshii 	j720kbd_cngetc,
    143  1.1  toshii 	j720kbd_cnpollc,
    144  1.1  toshii 	j720kbd_cnbell,
    145  1.1  toshii };
    146  1.1  toshii 
    147  1.1  toshii const struct wskbd_mapdata j720kbd_keymapdata = {
    148  1.1  toshii 	j720kbd_keydesctab,
    149  1.1  toshii #ifdef J720KBD_LAYOUT
    150  1.1  toshii 	J720KBD_LAYOUT,
    151  1.1  toshii #else
    152  1.1  toshii 	KB_US,
    153  1.1  toshii #endif
    154  1.1  toshii };
    155  1.1  toshii 
    156  1.1  toshii static int j720ssp_powerstate = 1;
    157  1.1  toshii 
    158  1.1  toshii static struct j720ssp_softc j720kbdcons_sc;
    159  1.1  toshii 
    160  1.1  toshii #define DEBUG
    161  1.1  toshii #ifdef DEBUG
    162  1.1  toshii int j720sspwaitcnt;
    163  1.1  toshii int j720sspwaittime;
    164  1.1  toshii extern int gettick();
    165  1.1  toshii #endif
    166  1.1  toshii 
    167  1.1  toshii #define BIT_INVERT(x)	do {					\
    168  1.1  toshii 	(x) = ((((x) & 0xf0) >> 4) | (((x) & 0x0f) << 4));	\
    169  1.1  toshii 	(x) = ((((x) & 0xcc) >> 2) | (((x) & 0x33) << 2));	\
    170  1.1  toshii 	(x) = ((((x) & 0xaa) >> 1) | (((x) & 0x55) << 1));	\
    171  1.1  toshii 	} while(0)
    172  1.1  toshii 
    173  1.1  toshii int
    174  1.1  toshii j720sspprobe(struct device *parent, struct cfdata *cf, void *aux)
    175  1.1  toshii {
    176  1.1  toshii 	return (1);
    177  1.1  toshii }
    178  1.1  toshii 
    179  1.1  toshii void
    180  1.1  toshii j720sspattach(struct device *parent, struct device *self, void *aux)
    181  1.1  toshii {
    182  1.1  toshii 	struct j720ssp_softc *sc = (void *)self;
    183  1.1  toshii 	struct sa11x0_softc *psc = (void *)parent;
    184  1.1  toshii 	struct sa11x0_attach_args *sa = aux;
    185  1.1  toshii 	struct wskbddev_attach_args a;
    186  1.1  toshii 
    187  1.1  toshii 	sc->sc_iot = psc->sc_iot;
    188  1.1  toshii 	sc->sc_gpioh = psc->sc_gpioh;
    189  1.1  toshii 	if (bus_space_map(sc->sc_iot, sa->sa_addr, sa->sa_size, 0,
    190  1.1  toshii 			  &sc->sc_ssph)) {
    191  1.1  toshii 		printf("%s: unable to map SSP registers\n",
    192  1.1  toshii 		       sc->sc_dev.dv_xname);
    193  1.1  toshii 		return;
    194  1.1  toshii 	}
    195  1.1  toshii 
    196  1.1  toshii 	sc->sc_si = softintr_establish(IPL_SOFTCLOCK, j720kbdsoft, sc);
    197  1.1  toshii 
    198  1.1  toshii 	sc->sc_enabled = 0;
    199  1.1  toshii 
    200  1.1  toshii 	a.console = 0;
    201  1.1  toshii 
    202  1.1  toshii 	a.keymap = &j720kbd_keymapdata;
    203  1.1  toshii 
    204  1.1  toshii 	a.accessops = &j720kbd_accessops;
    205  1.1  toshii 	a.accesscookie = sc;
    206  1.1  toshii 
    207  1.1  toshii 	/*
    208  1.1  toshii 	 * Attach the wskbd, saving a handle to it.
    209  1.1  toshii 	 * XXX XXX XXX
    210  1.1  toshii 	 */
    211  1.1  toshii 	sc->sc_wskbddev = config_found(self, &a, wskbddevprint);
    212  1.1  toshii 
    213  1.1  toshii #ifdef DEBUG
    214  1.1  toshii 	/* Zero the stat counters */
    215  1.1  toshii 	j720sspwaitcnt = 0;
    216  1.1  toshii 	j720sspwaittime = 0;
    217  1.1  toshii #endif
    218  1.1  toshii 
    219  1.1  toshii 	/* LCD control is on the same bus */
    220  1.1  toshii 	config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS,
    221  1.1  toshii 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    222  1.1  toshii 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS,
    223  1.1  toshii 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    224  1.1  toshii 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS_MAX,
    225  1.1  toshii 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    226  1.1  toshii 
    227  1.1  toshii 	config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST,
    228  1.1  toshii 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    229  1.1  toshii 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST,
    230  1.1  toshii 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    231  1.1  toshii 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST_MAX,
    232  1.1  toshii 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    233  1.1  toshii }
    234  1.1  toshii 
    235  1.1  toshii int
    236  1.1  toshii j720kbd_enable(void *v, int on)
    237  1.1  toshii {
    238  1.1  toshii 	struct j720ssp_softc *sc = v;
    239  1.1  toshii 
    240  1.1  toshii 	if (! sc->sc_enabled) {
    241  1.1  toshii 		sc->sc_enabled = 1;
    242  1.1  toshii 
    243  1.1  toshii 		sa11x0_intr_establish(0, 0, 1, IPL_BIO, j720kbd_intr, sc);
    244  1.1  toshii 	}
    245  1.1  toshii 	/* XXX */
    246  1.1  toshii 	return (0);
    247  1.1  toshii }
    248  1.1  toshii 
    249  1.1  toshii void
    250  1.1  toshii j720kbd_set_leds(void *v, int on)
    251  1.1  toshii {
    252  1.1  toshii 	/* XXX */
    253  1.1  toshii 	return;
    254  1.1  toshii }
    255  1.1  toshii 
    256  1.1  toshii int
    257  1.1  toshii j720kbd_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
    258  1.1  toshii {
    259  1.1  toshii 	return (-1);
    260  1.1  toshii }
    261  1.1  toshii 
    262  1.1  toshii int
    263  1.1  toshii j720kbd_intr(void *arg)
    264  1.1  toshii {
    265  1.1  toshii 	struct j720ssp_softc *sc = arg;
    266  1.1  toshii 
    267  1.1  toshii 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 1);
    268  1.1  toshii 
    269  1.1  toshii 	/*
    270  1.1  toshii 	 * Schedule a soft interrupt to process at lower priority,
    271  1.1  toshii 	 * as reading keycodes takes time.
    272  1.1  toshii 	 *
    273  1.1  toshii 	 * Interrupts are generated every 25-33ms as long as there
    274  1.1  toshii 	 * are unprocessed key events.  So it is not a good idea to
    275  1.1  toshii 	 * use callout to call j720kbdsoft after some delay in hope
    276  1.1  toshii 	 * of reducing interrupts.
    277  1.1  toshii 	 */
    278  1.1  toshii 	softintr_schedule(sc->sc_si);
    279  1.1  toshii 
    280  1.1  toshii 	return (1);
    281  1.1  toshii }
    282  1.1  toshii 
    283  1.1  toshii void
    284  1.1  toshii j720kbdsoft(void *arg)
    285  1.1  toshii {
    286  1.1  toshii 	struct j720ssp_softc *sc = arg;
    287  1.1  toshii 	int s, type, value;
    288  1.1  toshii 	char buf[9], *p;
    289  1.1  toshii 
    290  1.1  toshii 	j720kbd_read(sc, buf);
    291  1.1  toshii 
    292  1.1  toshii 	for(p = buf; *p; p++) {
    293  1.1  toshii 		type = *p & 0x80 ? WSCONS_EVENT_KEY_UP :
    294  1.1  toshii 		    WSCONS_EVENT_KEY_DOWN;
    295  1.1  toshii 		value = *p & 0x7f;
    296  1.1  toshii 		s = spltty();
    297  1.1  toshii 		wskbd_input(sc->sc_wskbddev, type, value);
    298  1.1  toshii 		splx(s);
    299  1.1  toshii 		if (type == WSCONS_EVENT_KEY_DOWN &&
    300  1.1  toshii 		    value == 0x7f) {
    301  1.1  toshii 			j720ssp_powerstate = ! j720ssp_powerstate;
    302  1.1  toshii 			config_hook_call(CONFIG_HOOK_POWERCONTROL,
    303  1.1  toshii 					 CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
    304  1.1  toshii 					 (void *)j720ssp_powerstate);
    305  1.1  toshii 		}
    306  1.1  toshii 	}
    307  1.1  toshii 
    308  1.1  toshii 	return;
    309  1.1  toshii }
    310  1.1  toshii 
    311  1.1  toshii void
    312  1.1  toshii j720kbd_read(struct j720ssp_softc *sc, char *buf)
    313  1.1  toshii {
    314  1.1  toshii 	int data, count;
    315  1.1  toshii #ifdef DEBUG
    316  1.1  toshii 	u_int32_t oscr;
    317  1.1  toshii 
    318  1.1  toshii 	oscr = gettick();
    319  1.1  toshii #endif
    320  1.1  toshii 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
    321  1.1  toshii 
    322  1.1  toshii 	/* send scan keycode command */
    323  1.1  toshii 	if (j720ssp_readwrite(sc, 1, 0x900, &data) < 0 ||
    324  1.1  toshii 	    data != 0x88)
    325  1.1  toshii 		goto out;
    326  1.1  toshii 
    327  1.1  toshii 	/* read numbers of scancode available */
    328  1.1  toshii 	if (j720ssp_readwrite(sc, 0, 0x8800, &data) < 0)
    329  1.1  toshii 		goto out;
    330  1.1  toshii 	BIT_INVERT(data);
    331  1.1  toshii 	count = data;
    332  1.1  toshii 
    333  1.1  toshii 	for(; count; count--) {
    334  1.1  toshii 		if (j720ssp_readwrite(sc, 0, 0x8800, &data) < 0)
    335  1.1  toshii 			goto out;
    336  1.1  toshii 		BIT_INVERT(data);
    337  1.1  toshii 		*buf++ = data;
    338  1.1  toshii 	}
    339  1.1  toshii 	*buf = 0;
    340  1.1  toshii 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    341  1.1  toshii 
    342  1.1  toshii #ifdef DEBUG
    343  1.1  toshii 	oscr = (u_int32_t)gettick() - oscr;
    344  1.1  toshii 	j720sspwaitcnt++;
    345  1.1  toshii 	j720sspwaittime += oscr;
    346  1.1  toshii #endif
    347  1.1  toshii 
    348  1.1  toshii 	return;
    349  1.1  toshii 
    350  1.1  toshii out:
    351  1.1  toshii 	*buf = 0;
    352  1.1  toshii 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    353  1.1  toshii 
    354  1.1  toshii 	/* reset SSP */
    355  1.1  toshii 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
    356  1.1  toshii 	delay(100);
    357  1.1  toshii 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
    358  1.1  toshii printf("j720kbd_read: error %x\n", data);
    359  1.1  toshii }
    360  1.1  toshii 
    361  1.1  toshii int
    362  1.1  toshii j720lcdparam(void *ctx, int type, long id, void *msg)
    363  1.1  toshii {
    364  1.1  toshii 	struct j720ssp_softc *sc = ctx;
    365  1.1  toshii 	int i, s;
    366  1.1  toshii 	u_int32_t data[2], len;
    367  1.1  toshii 
    368  1.1  toshii 	switch (type) {
    369  1.1  toshii 	case CONFIG_HOOK_GET:
    370  1.1  toshii 		switch (id) {
    371  1.1  toshii 		case CONFIG_HOOK_BRIGHTNESS_MAX:
    372  1.1  toshii 		case CONFIG_HOOK_CONTRAST_MAX:
    373  1.1  toshii 			*(int *)msg = 255;
    374  1.1  toshii 			return 1;
    375  1.1  toshii 		case CONFIG_HOOK_BRIGHTNESS:
    376  1.1  toshii 			data[0] = 0x6b00;
    377  1.1  toshii 			data[1] = 0x8800;
    378  1.1  toshii 			len = 2;
    379  1.1  toshii 			break;
    380  1.1  toshii 		case CONFIG_HOOK_CONTRAST:
    381  1.1  toshii 			data[0] = 0x2b00;
    382  1.1  toshii 			data[1] = 0x8800;
    383  1.1  toshii 			len = 2;
    384  1.1  toshii 			break;
    385  1.1  toshii 		default:
    386  1.1  toshii 			return 0;
    387  1.1  toshii 		}
    388  1.1  toshii 		break;
    389  1.1  toshii 
    390  1.1  toshii 	case CONFIG_HOOK_SET:
    391  1.1  toshii 		switch (id) {
    392  1.1  toshii 		case CONFIG_HOOK_BRIGHTNESS:
    393  1.1  toshii 			if (*(int *)msg >= 0) {
    394  1.1  toshii 				data[0] = 0xcb00;
    395  1.1  toshii 				data[1] = *(int *)msg;
    396  1.1  toshii 				BIT_INVERT(data[1]);
    397  1.1  toshii 				data[1] <<= 8;
    398  1.1  toshii 				len = 2;
    399  1.1  toshii 			} else {
    400  1.1  toshii 				/* XXX hack */
    401  1.1  toshii 				data[0] = 0xfb00;
    402  1.1  toshii 				len = 1;
    403  1.1  toshii 			}
    404  1.1  toshii 			break;
    405  1.1  toshii 		case CONFIG_HOOK_CONTRAST:
    406  1.1  toshii 			data[0] = 0x8b00;
    407  1.1  toshii 			data[1] = *(int *)msg;
    408  1.1  toshii 			BIT_INVERT(data[1]);
    409  1.1  toshii 			data[1] <<= 8;
    410  1.1  toshii 			len = 2;
    411  1.1  toshii 			break;
    412  1.1  toshii 		default:
    413  1.1  toshii 			return 0;
    414  1.1  toshii 		}
    415  1.1  toshii 	}
    416  1.1  toshii 
    417  1.1  toshii 	s = splbio();
    418  1.1  toshii 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
    419  1.1  toshii 
    420  1.1  toshii 	for (i = 0; i < len; i++) {
    421  1.1  toshii 		if (j720ssp_readwrite(sc, 1, data[i], &data[i]) < 0)
    422  1.1  toshii 			goto out;
    423  1.1  toshii 	}
    424  1.1  toshii 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    425  1.1  toshii 	splx(s);
    426  1.1  toshii 
    427  1.1  toshii 	if (type == CONFIG_HOOK_SET)
    428  1.1  toshii 		return 1;
    429  1.1  toshii 
    430  1.1  toshii 	BIT_INVERT(data[1]);
    431  1.1  toshii 	*(int *)msg = data[1];
    432  1.1  toshii 
    433  1.1  toshii 	return 1;
    434  1.1  toshii 
    435  1.1  toshii out:
    436  1.1  toshii 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    437  1.1  toshii 
    438  1.1  toshii 	/* reset SSP */
    439  1.1  toshii 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
    440  1.1  toshii 	delay(100);
    441  1.1  toshii 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
    442  1.1  toshii 	splx(s);
    443  1.1  toshii 	return 0;
    444  1.1  toshii }
    445  1.1  toshii 
    446  1.1  toshii static int
    447  1.1  toshii j720ssp_readwrite(struct j720ssp_softc *sc, int drainfifo, int in, int *out)
    448  1.1  toshii {
    449  1.1  toshii 	int timo;
    450  1.1  toshii 
    451  1.1  toshii 	timo = 100000;
    452  1.1  toshii 	while(bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PLR) & 0x400)
    453  1.1  toshii 		if (--timo == 0) {
    454  1.1  toshii 			printf("timo0\n");
    455  1.1  toshii 			return -1;
    456  1.1  toshii 		}
    457  1.1  toshii 	if (drainfifo) {
    458  1.1  toshii 		while(bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) &
    459  1.1  toshii 		      SR_RNE)
    460  1.1  toshii 			bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
    461  1.1  toshii #if 1
    462  1.1  toshii 		delay(5000);
    463  1.1  toshii #endif
    464  1.1  toshii 	}
    465  1.1  toshii 
    466  1.1  toshii 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_DR, in);
    467  1.1  toshii 
    468  1.1  toshii 	delay(5000);
    469  1.1  toshii 	timo = 100000;
    470  1.1  toshii 	while(! (bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) & SR_RNE))
    471  1.1  toshii 		if (--timo == 0) {
    472  1.1  toshii 			printf("timo1\n");
    473  1.1  toshii 			return -1;
    474  1.1  toshii 		}
    475  1.1  toshii 
    476  1.1  toshii 	*out = bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
    477  1.1  toshii 
    478  1.1  toshii 	return 0;
    479  1.1  toshii }
    480  1.1  toshii 
    481  1.1  toshii 
    482  1.1  toshii #if 0
    483  1.1  toshii int
    484  1.1  toshii j720kbd_cnattach()
    485  1.1  toshii {
    486  1.1  toshii 	/* XXX */
    487  1.1  toshii }
    488  1.1  toshii #endif
    489  1.1  toshii 
    490  1.1  toshii /* ARGSUSED */
    491  1.1  toshii void
    492  1.1  toshii j720kbd_cngetc(void *v, u_int *type, int *data)
    493  1.1  toshii {
    494  1.1  toshii 	char buf[9];
    495  1.1  toshii 
    496  1.1  toshii 	for (;;) {
    497  1.1  toshii 		j720kbd_read(&j720kbdcons_sc, buf);
    498  1.1  toshii 
    499  1.1  toshii 		if (buf[0] != 0) {
    500  1.1  toshii 			/* XXX we are discarding buffer contents */
    501  1.1  toshii 			*type = buf[0] & 0x80 ? WSCONS_EVENT_KEY_UP :
    502  1.1  toshii 			    WSCONS_EVENT_KEY_DOWN;
    503  1.1  toshii 			*data = buf[0] & 0x7f;
    504  1.1  toshii 			return;
    505  1.1  toshii 		}
    506  1.1  toshii 	}
    507  1.1  toshii }
    508  1.1  toshii 
    509  1.1  toshii void
    510  1.1  toshii j720kbd_cnpollc(void *v, int on)
    511  1.1  toshii {
    512  1.1  toshii #if 0
    513  1.1  toshii 	/* XXX */
    514  1.1  toshii 	struct j720kbd_internal *t = v;
    515  1.1  toshii 
    516  1.1  toshii 	pckbc_set_poll(t->t_kbctag, t->t_kbcslot, on);
    517  1.1  toshii #endif
    518  1.1  toshii }
    519  1.1  toshii 
    520  1.1  toshii void
    521  1.1  toshii j720kbd_cnbell(void *v, u_int pitch, u_int period, u_int volume)
    522  1.1  toshii {
    523  1.1  toshii }
    524  1.1  toshii 
    525  1.1  toshii int
    526  1.1  toshii j720lcdpower(void *ctx, int type, long id, void *msg)
    527  1.1  toshii {
    528  1.1  toshii 	struct sed1356_softc *sc = ctx;
    529  1.1  toshii 	struct sa11x0_softc *psc = sc->sc_parent;
    530  1.1  toshii 	int val;
    531  1.1  toshii 	u_int32_t reg;
    532  1.1  toshii 
    533  1.1  toshii 	if (type != CONFIG_HOOK_POWERCONTROL ||
    534  1.1  toshii 	    id != CONFIG_HOOK_POWERCONTROL_LCDLIGHT)
    535  1.1  toshii 		return 0;
    536  1.1  toshii 
    537  1.1  toshii 	sed1356_init_brightness(sc, 0);
    538  1.1  toshii 	sed1356_init_contrast(sc, 0);
    539  1.1  toshii 
    540  1.1  toshii 	if (msg) {
    541  1.1  toshii 		bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 0);
    542  1.1  toshii 
    543  1.1  toshii 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    544  1.1  toshii 		reg |= 0x1;
    545  1.1  toshii 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    546  1.1  toshii 		delay(50000);
    547  1.1  toshii 
    548  1.1  toshii 		val = sc->sc_contrast;
    549  1.1  toshii 		config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
    550  1.1  toshii 		delay(100000);
    551  1.1  toshii 
    552  1.1  toshii 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    553  1.1  toshii 		reg |= 0x4;
    554  1.1  toshii 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    555  1.1  toshii 
    556  1.1  toshii 		val = sc->sc_brightness;
    557  1.1  toshii 		config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
    558  1.1  toshii 
    559  1.1  toshii 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    560  1.1  toshii 		reg |= 0x2;
    561  1.1  toshii 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    562  1.1  toshii 	} else {
    563  1.1  toshii 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    564  1.1  toshii 		reg &= ~0x2;
    565  1.1  toshii 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    566  1.1  toshii 		reg &= ~0x4;
    567  1.1  toshii 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    568  1.1  toshii 		delay(100000);
    569  1.1  toshii 
    570  1.1  toshii 		val = -2;
    571  1.1  toshii 		config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
    572  1.1  toshii 
    573  1.1  toshii 		bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 1);
    574  1.1  toshii 
    575  1.1  toshii 		delay(100000);
    576  1.1  toshii 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    577  1.1  toshii 		reg &= ~0x1;
    578  1.1  toshii 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    579  1.1  toshii 	}
    580  1.1  toshii 	return 1;
    581  1.1  toshii }
    582