Home | History | Annotate | Line # | Download | only in dev
j720ssp.c revision 1.5.4.1
      1  1.5.4.1  gehenna /* $NetBSD: j720ssp.c,v 1.5.4.1 2002/07/21 13:00:37 gehenna 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.5.4.1  gehenna #include <sys/callout.h>
     81      1.1   toshii #include <sys/kernel.h>
     82      1.1   toshii #include <sys/malloc.h>
     83      1.1   toshii #include <sys/ioctl.h>
     84      1.1   toshii 
     85      1.1   toshii #include <machine/bus.h>
     86      1.1   toshii #include <machine/config_hook.h>
     87      1.4      uch #include <machine/bootinfo.h>
     88      1.1   toshii 
     89      1.1   toshii #include <hpcarm/dev/sed1356var.h>
     90  1.5.4.1  gehenna 
     91  1.5.4.1  gehenna #include <arm/sa11x0/sa11x0_var.h>
     92  1.5.4.1  gehenna #include <arm/sa11x0/sa11x0_gpioreg.h>
     93  1.5.4.1  gehenna #include <arm/sa11x0/sa11x0_ppcreg.h>
     94  1.5.4.1  gehenna #include <arm/sa11x0/sa11x0_sspreg.h>
     95      1.1   toshii 
     96      1.1   toshii #include <dev/wscons/wsconsio.h>
     97      1.1   toshii #include <dev/wscons/wskbdvar.h>
     98      1.1   toshii #include <dev/wscons/wsksymdef.h>
     99      1.1   toshii #include <dev/wscons/wsksymvar.h>
    100  1.5.4.1  gehenna #include <dev/wscons/wsmousevar.h>
    101  1.5.4.1  gehenna #include <dev/hpc/tpcalibvar.h>
    102      1.1   toshii 
    103      1.1   toshii extern const struct wscons_keydesc j720kbd_keydesctab[];
    104      1.1   toshii 
    105      1.1   toshii struct j720ssp_softc {
    106      1.1   toshii         struct device sc_dev;
    107      1.1   toshii 
    108      1.1   toshii 	bus_space_tag_t sc_iot;
    109      1.1   toshii 	bus_space_handle_t sc_gpioh;
    110      1.1   toshii 	bus_space_handle_t sc_ssph;
    111      1.1   toshii 
    112      1.1   toshii 	struct device *sc_wskbddev;
    113  1.5.4.1  gehenna 	struct device *sc_wsmousedev;
    114  1.5.4.1  gehenna 	struct tpcalib_softc sc_tpcalib;
    115      1.1   toshii 
    116  1.5.4.1  gehenna 	void *sc_kbdsi;
    117  1.5.4.1  gehenna 	void *sc_tpsi;
    118  1.5.4.1  gehenna 	struct callout sc_tptimeout;
    119      1.1   toshii 	int sc_enabled;
    120      1.1   toshii };
    121      1.1   toshii 
    122      1.1   toshii int j720kbd_intr(void *);
    123  1.5.4.1  gehenna int j720tp_intr(void *);
    124      1.1   toshii void j720kbdsoft(void *);
    125  1.5.4.1  gehenna void j720tpsoft(void *);
    126  1.5.4.1  gehenna void j720tp_timeout(void *);
    127      1.1   toshii int j720lcdparam(void *, int, long, void *);
    128      1.1   toshii static void j720kbd_read(struct j720ssp_softc *, char *);
    129      1.1   toshii static int j720ssp_readwrite(struct j720ssp_softc *, int, int, int *);
    130      1.1   toshii 
    131      1.1   toshii int j720sspprobe(struct device *, struct cfdata *, void *);
    132      1.1   toshii void j720sspattach(struct device *, struct device *, void *);
    133      1.1   toshii 
    134  1.5.4.1  gehenna int j720kbd_submatch(struct device *, struct cfdata *, void *);
    135  1.5.4.1  gehenna int j720tp_submatch(struct device *, struct cfdata *, void *);
    136  1.5.4.1  gehenna 
    137      1.1   toshii int j720kbd_enable(void *, int);
    138      1.1   toshii void j720kbd_set_leds(void *, int);
    139      1.1   toshii int j720kbd_ioctl(void *, u_long, caddr_t, int, struct proc *);
    140      1.1   toshii 
    141      1.1   toshii struct cfattach j720ssp_ca = {
    142      1.1   toshii 	sizeof(struct j720ssp_softc), j720sspprobe, j720sspattach,
    143      1.1   toshii };
    144      1.1   toshii 
    145      1.1   toshii const struct wskbd_accessops j720kbd_accessops = {
    146      1.1   toshii 	j720kbd_enable,
    147      1.1   toshii 	j720kbd_set_leds,
    148      1.1   toshii 	j720kbd_ioctl,
    149      1.1   toshii };
    150      1.1   toshii 
    151      1.1   toshii void j720kbd_cngetc(void *, u_int *, int *);
    152      1.1   toshii void j720kbd_cnpollc(void *, int);
    153      1.1   toshii void j720kbd_cnbell(void *, u_int, u_int, u_int);
    154      1.1   toshii 
    155      1.1   toshii const struct wskbd_consops j720kbd_consops = {
    156      1.1   toshii 	j720kbd_cngetc,
    157      1.1   toshii 	j720kbd_cnpollc,
    158      1.1   toshii 	j720kbd_cnbell,
    159      1.1   toshii };
    160      1.1   toshii 
    161      1.1   toshii const struct wskbd_mapdata j720kbd_keymapdata = {
    162      1.1   toshii 	j720kbd_keydesctab,
    163      1.1   toshii #ifdef J720KBD_LAYOUT
    164      1.1   toshii 	J720KBD_LAYOUT,
    165      1.1   toshii #else
    166      1.1   toshii 	KB_US,
    167      1.1   toshii #endif
    168      1.1   toshii };
    169      1.1   toshii 
    170  1.5.4.1  gehenna static int j720tp_enable(void *);
    171  1.5.4.1  gehenna static int j720tp_ioctl(void *, u_long, caddr_t, int, struct proc *);
    172  1.5.4.1  gehenna static void j720tp_disable(void *);
    173  1.5.4.1  gehenna 
    174  1.5.4.1  gehenna const struct wsmouse_accessops j720tp_accessops = {
    175  1.5.4.1  gehenna 	j720tp_enable,
    176  1.5.4.1  gehenna 	j720tp_ioctl,
    177  1.5.4.1  gehenna 	j720tp_disable,
    178  1.5.4.1  gehenna };
    179  1.5.4.1  gehenna 
    180      1.1   toshii static int j720ssp_powerstate = 1;
    181      1.1   toshii 
    182      1.1   toshii static struct j720ssp_softc j720kbdcons_sc;
    183      1.3   toshii static int j720kbdcons_initstate = 0;
    184      1.1   toshii 
    185      1.1   toshii #define DEBUG
    186      1.1   toshii #ifdef DEBUG
    187      1.1   toshii int j720sspwaitcnt;
    188      1.1   toshii int j720sspwaittime;
    189      1.1   toshii extern int gettick();
    190      1.1   toshii #endif
    191      1.1   toshii 
    192      1.1   toshii #define BIT_INVERT(x)	do {					\
    193      1.1   toshii 	(x) = ((((x) & 0xf0) >> 4) | (((x) & 0x0f) << 4));	\
    194      1.1   toshii 	(x) = ((((x) & 0xcc) >> 2) | (((x) & 0x33) << 2));	\
    195      1.1   toshii 	(x) = ((((x) & 0xaa) >> 1) | (((x) & 0x55) << 1));	\
    196      1.1   toshii 	} while(0)
    197      1.1   toshii 
    198      1.1   toshii int
    199      1.1   toshii j720sspprobe(struct device *parent, struct cfdata *cf, void *aux)
    200      1.1   toshii {
    201      1.1   toshii 	return (1);
    202      1.1   toshii }
    203      1.1   toshii 
    204      1.1   toshii void
    205      1.1   toshii j720sspattach(struct device *parent, struct device *self, void *aux)
    206      1.1   toshii {
    207      1.1   toshii 	struct j720ssp_softc *sc = (void *)self;
    208      1.1   toshii 	struct sa11x0_softc *psc = (void *)parent;
    209      1.1   toshii 	struct sa11x0_attach_args *sa = aux;
    210      1.1   toshii 	struct wskbddev_attach_args a;
    211  1.5.4.1  gehenna 	struct wsmousedev_attach_args ma;
    212      1.2   toshii 
    213      1.2   toshii 	printf("\n");
    214      1.1   toshii 
    215      1.1   toshii 	sc->sc_iot = psc->sc_iot;
    216      1.1   toshii 	sc->sc_gpioh = psc->sc_gpioh;
    217      1.1   toshii 	if (bus_space_map(sc->sc_iot, sa->sa_addr, sa->sa_size, 0,
    218      1.1   toshii 			  &sc->sc_ssph)) {
    219      1.1   toshii 		printf("%s: unable to map SSP registers\n",
    220      1.1   toshii 		       sc->sc_dev.dv_xname);
    221      1.1   toshii 		return;
    222      1.1   toshii 	}
    223      1.1   toshii 
    224  1.5.4.1  gehenna 	sc->sc_kbdsi = softintr_establish(IPL_SOFTCLOCK, j720kbdsoft, sc);
    225      1.1   toshii 
    226      1.1   toshii 	sc->sc_enabled = 0;
    227      1.1   toshii 
    228      1.1   toshii 	a.console = 0;
    229      1.1   toshii 
    230      1.1   toshii 	a.keymap = &j720kbd_keymapdata;
    231      1.1   toshii 
    232      1.1   toshii 	a.accessops = &j720kbd_accessops;
    233      1.1   toshii 	a.accesscookie = sc;
    234      1.1   toshii 
    235      1.3   toshii 	/* Do console initialization */
    236      1.3   toshii 	if (! (bootinfo->bi_cnuse & BI_CNUSE_SERIAL)) {
    237      1.3   toshii 		j720kbdcons_sc = *sc;
    238      1.3   toshii 		a.console = 1;
    239      1.3   toshii 
    240      1.3   toshii 		wskbd_cnattach(&j720kbd_consops, NULL, &j720kbd_keymapdata);
    241      1.3   toshii 		j720kbdcons_initstate = 1;
    242      1.3   toshii 	}
    243      1.3   toshii 
    244      1.1   toshii 	/*
    245      1.1   toshii 	 * Attach the wskbd, saving a handle to it.
    246      1.1   toshii 	 * XXX XXX XXX
    247      1.1   toshii 	 */
    248  1.5.4.1  gehenna 	sc->sc_wskbddev = config_found_sm(self, &a, wskbddevprint,
    249  1.5.4.1  gehenna 	    j720kbd_submatch);
    250      1.1   toshii 
    251      1.1   toshii #ifdef DEBUG
    252      1.1   toshii 	/* Zero the stat counters */
    253      1.1   toshii 	j720sspwaitcnt = 0;
    254      1.1   toshii 	j720sspwaittime = 0;
    255      1.1   toshii #endif
    256      1.1   toshii 
    257      1.3   toshii 	if (j720kbdcons_initstate == 1)
    258      1.3   toshii 		j720kbd_enable(sc, 1);
    259      1.3   toshii 
    260  1.5.4.1  gehenna 	ma.accessops = &j720tp_accessops;
    261  1.5.4.1  gehenna 	ma.accesscookie = sc;
    262  1.5.4.1  gehenna 
    263  1.5.4.1  gehenna 	sc->sc_wsmousedev = config_found_sm(self, &ma, wsmousedevprint,
    264  1.5.4.1  gehenna 	    j720tp_submatch);
    265  1.5.4.1  gehenna 	tpcalib_init(&sc->sc_tpcalib);
    266  1.5.4.1  gehenna 
    267  1.5.4.1  gehenna 	/* XXX fill in "default" calibrate param */
    268  1.5.4.1  gehenna 	{
    269  1.5.4.1  gehenna 		static const struct wsmouse_calibcoords j720_default_calib = {
    270  1.5.4.1  gehenna 			0, 0, 639, 239,
    271  1.5.4.1  gehenna 			4,
    272  1.5.4.1  gehenna 			{ { 988,  80,   0,   0 },
    273  1.5.4.1  gehenna 			  {  88,  84, 639,   0 },
    274  1.5.4.1  gehenna 			  { 988, 927,   0, 239 },
    275  1.5.4.1  gehenna 			  {  88, 940, 639, 239 } } };
    276  1.5.4.1  gehenna 		tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
    277  1.5.4.1  gehenna 		    (caddr_t)&j720_default_calib, 0, 0);
    278  1.5.4.1  gehenna 	}
    279  1.5.4.1  gehenna 
    280  1.5.4.1  gehenna 	j720tp_disable(sc);
    281  1.5.4.1  gehenna 	callout_init(&sc->sc_tptimeout);
    282  1.5.4.1  gehenna 
    283  1.5.4.1  gehenna 	/* Setup touchpad interrupt */
    284  1.5.4.1  gehenna 	sc->sc_tpsi = softintr_establish(IPL_SOFTCLOCK, j720tpsoft, sc);
    285  1.5.4.1  gehenna 	sa11x0_intr_establish(0, 9, 1, IPL_BIO, j720tp_intr, sc);
    286  1.5.4.1  gehenna 
    287      1.1   toshii 	/* LCD control is on the same bus */
    288      1.1   toshii 	config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS,
    289      1.1   toshii 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    290      1.1   toshii 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS,
    291      1.1   toshii 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    292      1.1   toshii 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS_MAX,
    293      1.1   toshii 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    294      1.1   toshii 
    295      1.1   toshii 	config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST,
    296      1.1   toshii 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    297      1.1   toshii 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST,
    298      1.1   toshii 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    299      1.1   toshii 	config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST_MAX,
    300      1.1   toshii 		    CONFIG_HOOK_SHARE, j720lcdparam, sc);
    301      1.1   toshii }
    302      1.1   toshii 
    303      1.1   toshii int
    304  1.5.4.1  gehenna j720kbd_submatch(struct device *parant, struct cfdata *cf, void *aux) {
    305  1.5.4.1  gehenna 
    306  1.5.4.1  gehenna 	if (strcmp(cf->cf_driver->cd_name, "wskbd") == 0)
    307  1.5.4.1  gehenna 		return (1);
    308  1.5.4.1  gehenna 	return (0);
    309  1.5.4.1  gehenna }
    310  1.5.4.1  gehenna 
    311  1.5.4.1  gehenna int
    312  1.5.4.1  gehenna j720tp_submatch(struct device *parant, struct cfdata *cf, void *aux) {
    313  1.5.4.1  gehenna 
    314  1.5.4.1  gehenna 	if (strcmp(cf->cf_driver->cd_name, "wsmouse") == 0)
    315  1.5.4.1  gehenna 		return (1);
    316  1.5.4.1  gehenna 	return (0);
    317  1.5.4.1  gehenna }
    318  1.5.4.1  gehenna 
    319  1.5.4.1  gehenna int
    320      1.1   toshii j720kbd_enable(void *v, int on)
    321      1.1   toshii {
    322      1.1   toshii 	struct j720ssp_softc *sc = v;
    323      1.1   toshii 
    324      1.1   toshii 	if (! sc->sc_enabled) {
    325      1.1   toshii 		sc->sc_enabled = 1;
    326      1.1   toshii 
    327      1.1   toshii 		sa11x0_intr_establish(0, 0, 1, IPL_BIO, j720kbd_intr, sc);
    328      1.1   toshii 	}
    329      1.1   toshii 	/* XXX */
    330      1.1   toshii 	return (0);
    331      1.1   toshii }
    332      1.1   toshii 
    333      1.1   toshii void
    334      1.1   toshii j720kbd_set_leds(void *v, int on)
    335      1.1   toshii {
    336      1.1   toshii 	/* XXX */
    337      1.1   toshii 	return;
    338      1.1   toshii }
    339      1.1   toshii 
    340      1.1   toshii int
    341      1.1   toshii j720kbd_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
    342      1.1   toshii {
    343      1.5   atatat 	return (EPASSTHROUGH);
    344      1.1   toshii }
    345      1.1   toshii 
    346      1.1   toshii int
    347      1.1   toshii j720kbd_intr(void *arg)
    348      1.1   toshii {
    349      1.1   toshii 	struct j720ssp_softc *sc = arg;
    350      1.1   toshii 
    351      1.1   toshii 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 1);
    352      1.1   toshii 
    353      1.1   toshii 	/*
    354      1.1   toshii 	 * Schedule a soft interrupt to process at lower priority,
    355      1.1   toshii 	 * as reading keycodes takes time.
    356      1.1   toshii 	 *
    357      1.1   toshii 	 * Interrupts are generated every 25-33ms as long as there
    358      1.1   toshii 	 * are unprocessed key events.  So it is not a good idea to
    359      1.1   toshii 	 * use callout to call j720kbdsoft after some delay in hope
    360      1.1   toshii 	 * of reducing interrupts.
    361      1.1   toshii 	 */
    362  1.5.4.1  gehenna 	softintr_schedule(sc->sc_kbdsi);
    363  1.5.4.1  gehenna 
    364  1.5.4.1  gehenna 	return (1);
    365  1.5.4.1  gehenna }
    366  1.5.4.1  gehenna 
    367  1.5.4.1  gehenna int
    368  1.5.4.1  gehenna j720tp_intr(void *arg)
    369  1.5.4.1  gehenna {
    370  1.5.4.1  gehenna 	struct j720ssp_softc *sc = arg;
    371  1.5.4.1  gehenna 
    372  1.5.4.1  gehenna 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 1 << 9);
    373  1.5.4.1  gehenna 
    374  1.5.4.1  gehenna 	softintr_schedule(sc->sc_tpsi);
    375      1.1   toshii 
    376      1.1   toshii 	return (1);
    377      1.1   toshii }
    378      1.1   toshii 
    379      1.1   toshii void
    380      1.1   toshii j720kbdsoft(void *arg)
    381      1.1   toshii {
    382      1.1   toshii 	struct j720ssp_softc *sc = arg;
    383      1.1   toshii 	int s, type, value;
    384      1.1   toshii 	char buf[9], *p;
    385      1.1   toshii 
    386      1.1   toshii 	j720kbd_read(sc, buf);
    387      1.1   toshii 
    388      1.1   toshii 	for(p = buf; *p; p++) {
    389      1.1   toshii 		type = *p & 0x80 ? WSCONS_EVENT_KEY_UP :
    390      1.1   toshii 		    WSCONS_EVENT_KEY_DOWN;
    391      1.1   toshii 		value = *p & 0x7f;
    392      1.1   toshii 		s = spltty();
    393      1.1   toshii 		wskbd_input(sc->sc_wskbddev, type, value);
    394      1.1   toshii 		splx(s);
    395      1.1   toshii 		if (type == WSCONS_EVENT_KEY_DOWN &&
    396      1.1   toshii 		    value == 0x7f) {
    397      1.1   toshii 			j720ssp_powerstate = ! j720ssp_powerstate;
    398      1.1   toshii 			config_hook_call(CONFIG_HOOK_POWERCONTROL,
    399      1.1   toshii 					 CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
    400      1.1   toshii 					 (void *)j720ssp_powerstate);
    401      1.1   toshii 		}
    402      1.1   toshii 	}
    403      1.1   toshii 
    404      1.1   toshii 	return;
    405      1.1   toshii }
    406      1.1   toshii 
    407      1.1   toshii void
    408      1.1   toshii j720kbd_read(struct j720ssp_softc *sc, char *buf)
    409      1.1   toshii {
    410      1.1   toshii 	int data, count;
    411      1.1   toshii #ifdef DEBUG
    412      1.1   toshii 	u_int32_t oscr;
    413      1.1   toshii 
    414      1.1   toshii 	oscr = gettick();
    415      1.1   toshii #endif
    416      1.1   toshii 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
    417      1.1   toshii 
    418      1.1   toshii 	/* send scan keycode command */
    419      1.1   toshii 	if (j720ssp_readwrite(sc, 1, 0x900, &data) < 0 ||
    420      1.1   toshii 	    data != 0x88)
    421      1.1   toshii 		goto out;
    422      1.1   toshii 
    423      1.1   toshii 	/* read numbers of scancode available */
    424      1.1   toshii 	if (j720ssp_readwrite(sc, 0, 0x8800, &data) < 0)
    425      1.1   toshii 		goto out;
    426      1.1   toshii 	BIT_INVERT(data);
    427      1.1   toshii 	count = data;
    428      1.1   toshii 
    429      1.1   toshii 	for(; count; count--) {
    430      1.1   toshii 		if (j720ssp_readwrite(sc, 0, 0x8800, &data) < 0)
    431      1.1   toshii 			goto out;
    432      1.1   toshii 		BIT_INVERT(data);
    433      1.1   toshii 		*buf++ = data;
    434      1.1   toshii 	}
    435      1.1   toshii 	*buf = 0;
    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 #ifdef DEBUG
    439      1.1   toshii 	oscr = (u_int32_t)gettick() - oscr;
    440      1.1   toshii 	j720sspwaitcnt++;
    441      1.1   toshii 	j720sspwaittime += oscr;
    442      1.1   toshii #endif
    443      1.1   toshii 
    444      1.1   toshii 	return;
    445      1.1   toshii 
    446      1.1   toshii out:
    447      1.1   toshii 	*buf = 0;
    448      1.1   toshii 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    449      1.1   toshii 
    450      1.1   toshii 	/* reset SSP */
    451      1.1   toshii 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
    452      1.1   toshii 	delay(100);
    453      1.1   toshii 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
    454      1.1   toshii printf("j720kbd_read: error %x\n", data);
    455  1.5.4.1  gehenna }
    456  1.5.4.1  gehenna 
    457  1.5.4.1  gehenna void
    458  1.5.4.1  gehenna j720tpsoft(void *arg)
    459  1.5.4.1  gehenna {
    460  1.5.4.1  gehenna 	struct j720ssp_softc *sc = arg;
    461  1.5.4.1  gehenna 	int buf[8], data, i, x, y;
    462  1.5.4.1  gehenna 
    463  1.5.4.1  gehenna 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
    464  1.5.4.1  gehenna 
    465  1.5.4.1  gehenna 	/* send read touchpanel command */
    466  1.5.4.1  gehenna 	if (j720ssp_readwrite(sc, 1, 0x500, &data) < 0 ||
    467  1.5.4.1  gehenna 	    data != 0x88)
    468  1.5.4.1  gehenna 		goto out;
    469  1.5.4.1  gehenna 
    470  1.5.4.1  gehenna 	for(i = 0; i < 8; i++) {
    471  1.5.4.1  gehenna 		if (j720ssp_readwrite(sc, 0, 0x8800, &data) < 0)
    472  1.5.4.1  gehenna 			goto out;
    473  1.5.4.1  gehenna 		BIT_INVERT(data);
    474  1.5.4.1  gehenna 		buf[i] = data;
    475  1.5.4.1  gehenna 	}
    476  1.5.4.1  gehenna 
    477  1.5.4.1  gehenna 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    478  1.5.4.1  gehenna 
    479  1.5.4.1  gehenna 	buf[6] <<= 8;
    480  1.5.4.1  gehenna 	buf[7] <<= 8;
    481  1.5.4.1  gehenna 	for(i = 0; i < 3; i++) {
    482  1.5.4.1  gehenna 		buf[i] |= buf[6] & 0x300;
    483  1.5.4.1  gehenna 		buf[6] >>= 2;
    484  1.5.4.1  gehenna 		buf[i + 3] |= buf[7] & 0x300;
    485  1.5.4.1  gehenna 		buf[7] >>= 2;
    486  1.5.4.1  gehenna 	}
    487  1.5.4.1  gehenna #if 0
    488  1.5.4.1  gehenna 	printf("j720tpsoft: %d %d %d  %d %d %d\n", buf[0], buf[1], buf[2],
    489  1.5.4.1  gehenna 	    buf[3], buf[4], buf[5]);
    490  1.5.4.1  gehenna #endif
    491  1.5.4.1  gehenna 
    492  1.5.4.1  gehenna 	/* XXX buf[1], buf[2], ... should also be used */
    493  1.5.4.1  gehenna 	tpcalib_trans(&sc->sc_tpcalib, buf[1], buf[4], &x, &y);
    494  1.5.4.1  gehenna 	wsmouse_input(sc->sc_wsmousedev, 1, x, y, 0,
    495  1.5.4.1  gehenna 	    WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
    496  1.5.4.1  gehenna 
    497  1.5.4.1  gehenna 	callout_reset(&sc->sc_tptimeout, hz / 10, j720tp_timeout, sc);
    498  1.5.4.1  gehenna 
    499  1.5.4.1  gehenna 	return;
    500  1.5.4.1  gehenna 
    501  1.5.4.1  gehenna out:
    502  1.5.4.1  gehenna 	*buf = 0;
    503  1.5.4.1  gehenna 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    504  1.5.4.1  gehenna 
    505  1.5.4.1  gehenna 	/* reset SSP */
    506  1.5.4.1  gehenna 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
    507  1.5.4.1  gehenna 	delay(100);
    508  1.5.4.1  gehenna 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
    509  1.5.4.1  gehenna 	printf("j720tpsoft: error %x\n", data);
    510  1.5.4.1  gehenna }
    511  1.5.4.1  gehenna 
    512  1.5.4.1  gehenna void
    513  1.5.4.1  gehenna j720tp_timeout(void *arg)
    514  1.5.4.1  gehenna {
    515  1.5.4.1  gehenna 	struct j720ssp_softc *sc = arg;
    516  1.5.4.1  gehenna 
    517  1.5.4.1  gehenna #if 0
    518  1.5.4.1  gehenna 	/* XXX I don't this this is necessary (untested) */
    519  1.5.4.1  gehenna 	if (bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PLR) &
    520  1.5.4.1  gehenna 	    (1 << 9)) {
    521  1.5.4.1  gehenna 		/* Touchpad is still pressed */
    522  1.5.4.1  gehenna 		callout_reset(&sc->sc_tptimeout, hz / 10, j720tp_timeout, sc);
    523  1.5.4.1  gehenna 		return;
    524  1.5.4.1  gehenna 	}
    525  1.5.4.1  gehenna #endif
    526  1.5.4.1  gehenna 
    527  1.5.4.1  gehenna 	wsmouse_input(sc->sc_wsmousedev, 0, 0, 0, 0, 0);
    528  1.5.4.1  gehenna }
    529  1.5.4.1  gehenna 
    530  1.5.4.1  gehenna static int
    531  1.5.4.1  gehenna j720tp_enable(void *arg) {
    532  1.5.4.1  gehenna 	struct j720ssp_softc *sc = arg;
    533  1.5.4.1  gehenna 	int er, s;
    534  1.5.4.1  gehenna 
    535  1.5.4.1  gehenna 	s = splhigh();
    536  1.5.4.1  gehenna 	er = bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER);
    537  1.5.4.1  gehenna 	er |= 1 << 9;
    538  1.5.4.1  gehenna 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER, er);
    539  1.5.4.1  gehenna 	splx(s);
    540  1.5.4.1  gehenna 
    541  1.5.4.1  gehenna 	return (0);
    542  1.5.4.1  gehenna }
    543  1.5.4.1  gehenna 
    544  1.5.4.1  gehenna static void
    545  1.5.4.1  gehenna j720tp_disable(void *arg) {
    546  1.5.4.1  gehenna 	struct j720ssp_softc *sc = arg;
    547  1.5.4.1  gehenna 	int er, s;
    548  1.5.4.1  gehenna 
    549  1.5.4.1  gehenna 	s = splhigh();
    550  1.5.4.1  gehenna 	er = bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER);
    551  1.5.4.1  gehenna 	er &= ~(1 << 9);
    552  1.5.4.1  gehenna 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER, er);
    553  1.5.4.1  gehenna 	splx(s);
    554  1.5.4.1  gehenna }
    555  1.5.4.1  gehenna 
    556  1.5.4.1  gehenna static int
    557  1.5.4.1  gehenna j720tp_ioctl(void *arg, u_long cmd, caddr_t data, int flag, struct proc *p) {
    558  1.5.4.1  gehenna 	struct j720ssp_softc *sc = arg;
    559  1.5.4.1  gehenna 
    560  1.5.4.1  gehenna 	switch (cmd) {
    561  1.5.4.1  gehenna 	case WSMOUSEIO_GTYPE:
    562  1.5.4.1  gehenna 		*(u_int *)data = WSMOUSE_TYPE_TPANEL;
    563  1.5.4.1  gehenna 		return (0);
    564  1.5.4.1  gehenna 
    565  1.5.4.1  gehenna 	case WSMOUSEIO_SCALIBCOORDS:
    566  1.5.4.1  gehenna 	case WSMOUSEIO_GCALIBCOORDS:
    567  1.5.4.1  gehenna 		return tpcalib_ioctl(&sc->sc_tpcalib, cmd, data, flag, p);
    568  1.5.4.1  gehenna 
    569  1.5.4.1  gehenna 	default:
    570  1.5.4.1  gehenna 		return (EPASSTHROUGH);
    571  1.5.4.1  gehenna 	}
    572      1.1   toshii }
    573      1.1   toshii 
    574      1.1   toshii int
    575      1.1   toshii j720lcdparam(void *ctx, int type, long id, void *msg)
    576      1.1   toshii {
    577      1.1   toshii 	struct j720ssp_softc *sc = ctx;
    578      1.1   toshii 	int i, s;
    579      1.1   toshii 	u_int32_t data[2], len;
    580      1.1   toshii 
    581      1.1   toshii 	switch (type) {
    582      1.1   toshii 	case CONFIG_HOOK_GET:
    583      1.1   toshii 		switch (id) {
    584      1.1   toshii 		case CONFIG_HOOK_BRIGHTNESS_MAX:
    585      1.1   toshii 		case CONFIG_HOOK_CONTRAST_MAX:
    586      1.1   toshii 			*(int *)msg = 255;
    587      1.1   toshii 			return 1;
    588      1.1   toshii 		case CONFIG_HOOK_BRIGHTNESS:
    589      1.1   toshii 			data[0] = 0x6b00;
    590      1.1   toshii 			data[1] = 0x8800;
    591      1.1   toshii 			len = 2;
    592      1.1   toshii 			break;
    593      1.1   toshii 		case CONFIG_HOOK_CONTRAST:
    594      1.1   toshii 			data[0] = 0x2b00;
    595      1.1   toshii 			data[1] = 0x8800;
    596      1.1   toshii 			len = 2;
    597      1.1   toshii 			break;
    598      1.1   toshii 		default:
    599      1.1   toshii 			return 0;
    600      1.1   toshii 		}
    601      1.1   toshii 		break;
    602      1.1   toshii 
    603      1.1   toshii 	case CONFIG_HOOK_SET:
    604      1.1   toshii 		switch (id) {
    605      1.1   toshii 		case CONFIG_HOOK_BRIGHTNESS:
    606      1.1   toshii 			if (*(int *)msg >= 0) {
    607      1.1   toshii 				data[0] = 0xcb00;
    608      1.1   toshii 				data[1] = *(int *)msg;
    609      1.1   toshii 				BIT_INVERT(data[1]);
    610      1.1   toshii 				data[1] <<= 8;
    611      1.1   toshii 				len = 2;
    612      1.1   toshii 			} else {
    613      1.1   toshii 				/* XXX hack */
    614      1.1   toshii 				data[0] = 0xfb00;
    615      1.1   toshii 				len = 1;
    616      1.1   toshii 			}
    617      1.1   toshii 			break;
    618      1.1   toshii 		case CONFIG_HOOK_CONTRAST:
    619      1.1   toshii 			data[0] = 0x8b00;
    620      1.1   toshii 			data[1] = *(int *)msg;
    621      1.1   toshii 			BIT_INVERT(data[1]);
    622      1.1   toshii 			data[1] <<= 8;
    623      1.1   toshii 			len = 2;
    624      1.1   toshii 			break;
    625      1.1   toshii 		default:
    626      1.1   toshii 			return 0;
    627      1.1   toshii 		}
    628      1.1   toshii 	}
    629      1.1   toshii 
    630      1.1   toshii 	s = splbio();
    631      1.1   toshii 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
    632      1.1   toshii 
    633      1.1   toshii 	for (i = 0; i < len; i++) {
    634      1.1   toshii 		if (j720ssp_readwrite(sc, 1, data[i], &data[i]) < 0)
    635      1.1   toshii 			goto out;
    636      1.1   toshii 	}
    637      1.1   toshii 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    638      1.1   toshii 	splx(s);
    639      1.1   toshii 
    640      1.1   toshii 	if (type == CONFIG_HOOK_SET)
    641      1.1   toshii 		return 1;
    642      1.1   toshii 
    643      1.1   toshii 	BIT_INVERT(data[1]);
    644      1.1   toshii 	*(int *)msg = data[1];
    645      1.1   toshii 
    646      1.1   toshii 	return 1;
    647      1.1   toshii 
    648      1.1   toshii out:
    649      1.1   toshii 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
    650      1.1   toshii 
    651      1.1   toshii 	/* reset SSP */
    652      1.1   toshii 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
    653      1.1   toshii 	delay(100);
    654      1.1   toshii 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
    655      1.1   toshii 	splx(s);
    656      1.1   toshii 	return 0;
    657      1.1   toshii }
    658      1.1   toshii 
    659      1.1   toshii static int
    660      1.1   toshii j720ssp_readwrite(struct j720ssp_softc *sc, int drainfifo, int in, int *out)
    661      1.1   toshii {
    662      1.1   toshii 	int timo;
    663      1.1   toshii 
    664      1.1   toshii 	timo = 100000;
    665      1.1   toshii 	while(bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PLR) & 0x400)
    666      1.1   toshii 		if (--timo == 0) {
    667      1.1   toshii 			printf("timo0\n");
    668      1.1   toshii 			return -1;
    669      1.1   toshii 		}
    670      1.1   toshii 	if (drainfifo) {
    671      1.1   toshii 		while(bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) &
    672      1.1   toshii 		      SR_RNE)
    673      1.1   toshii 			bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
    674      1.1   toshii #if 1
    675      1.1   toshii 		delay(5000);
    676      1.1   toshii #endif
    677      1.1   toshii 	}
    678      1.1   toshii 
    679      1.1   toshii 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_DR, in);
    680      1.1   toshii 
    681      1.1   toshii 	delay(5000);
    682      1.1   toshii 	timo = 100000;
    683      1.1   toshii 	while(! (bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) & SR_RNE))
    684      1.1   toshii 		if (--timo == 0) {
    685      1.1   toshii 			printf("timo1\n");
    686      1.1   toshii 			return -1;
    687      1.1   toshii 		}
    688      1.1   toshii 
    689      1.1   toshii 	*out = bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
    690      1.1   toshii 
    691      1.1   toshii 	return 0;
    692      1.1   toshii }
    693      1.1   toshii 
    694      1.1   toshii #if 0
    695      1.1   toshii int
    696      1.1   toshii j720kbd_cnattach()
    697      1.1   toshii {
    698      1.3   toshii 	/* XXX defer initialization till j720sspattach */
    699      1.3   toshii 
    700      1.3   toshii 	return (0);
    701      1.1   toshii }
    702      1.1   toshii #endif
    703      1.1   toshii 
    704      1.1   toshii /* ARGSUSED */
    705      1.1   toshii void
    706      1.1   toshii j720kbd_cngetc(void *v, u_int *type, int *data)
    707      1.1   toshii {
    708      1.1   toshii 	char buf[9];
    709      1.3   toshii 
    710      1.3   toshii 	if (j720kbdcons_initstate < 1)
    711      1.3   toshii 		return;
    712      1.1   toshii 
    713      1.1   toshii 	for (;;) {
    714      1.1   toshii 		j720kbd_read(&j720kbdcons_sc, buf);
    715      1.1   toshii 
    716      1.1   toshii 		if (buf[0] != 0) {
    717      1.1   toshii 			/* XXX we are discarding buffer contents */
    718      1.1   toshii 			*type = buf[0] & 0x80 ? WSCONS_EVENT_KEY_UP :
    719      1.1   toshii 			    WSCONS_EVENT_KEY_DOWN;
    720      1.1   toshii 			*data = buf[0] & 0x7f;
    721      1.1   toshii 			return;
    722      1.1   toshii 		}
    723      1.1   toshii 	}
    724      1.1   toshii }
    725      1.1   toshii 
    726      1.1   toshii void
    727      1.1   toshii j720kbd_cnpollc(void *v, int on)
    728      1.1   toshii {
    729      1.1   toshii #if 0
    730      1.1   toshii 	/* XXX */
    731      1.1   toshii 	struct j720kbd_internal *t = v;
    732      1.1   toshii 
    733      1.1   toshii 	pckbc_set_poll(t->t_kbctag, t->t_kbcslot, on);
    734      1.1   toshii #endif
    735      1.1   toshii }
    736      1.1   toshii 
    737      1.1   toshii void
    738      1.1   toshii j720kbd_cnbell(void *v, u_int pitch, u_int period, u_int volume)
    739      1.1   toshii {
    740      1.1   toshii }
    741      1.1   toshii 
    742      1.1   toshii int
    743      1.1   toshii j720lcdpower(void *ctx, int type, long id, void *msg)
    744      1.1   toshii {
    745      1.1   toshii 	struct sed1356_softc *sc = ctx;
    746      1.1   toshii 	struct sa11x0_softc *psc = sc->sc_parent;
    747      1.1   toshii 	int val;
    748      1.1   toshii 	u_int32_t reg;
    749      1.1   toshii 
    750      1.1   toshii 	if (type != CONFIG_HOOK_POWERCONTROL ||
    751      1.1   toshii 	    id != CONFIG_HOOK_POWERCONTROL_LCDLIGHT)
    752      1.1   toshii 		return 0;
    753      1.1   toshii 
    754      1.1   toshii 	sed1356_init_brightness(sc, 0);
    755      1.1   toshii 	sed1356_init_contrast(sc, 0);
    756      1.1   toshii 
    757      1.1   toshii 	if (msg) {
    758      1.1   toshii 		bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 0);
    759      1.1   toshii 
    760      1.1   toshii 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    761      1.1   toshii 		reg |= 0x1;
    762      1.1   toshii 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    763      1.1   toshii 		delay(50000);
    764      1.1   toshii 
    765      1.1   toshii 		val = sc->sc_contrast;
    766      1.1   toshii 		config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
    767      1.1   toshii 		delay(100000);
    768      1.1   toshii 
    769      1.1   toshii 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    770      1.1   toshii 		reg |= 0x4;
    771      1.1   toshii 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    772      1.1   toshii 
    773      1.1   toshii 		val = sc->sc_brightness;
    774      1.1   toshii 		config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
    775      1.1   toshii 
    776      1.1   toshii 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    777      1.1   toshii 		reg |= 0x2;
    778      1.1   toshii 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    779      1.1   toshii 	} else {
    780      1.1   toshii 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    781      1.1   toshii 		reg &= ~0x2;
    782      1.1   toshii 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    783      1.1   toshii 		reg &= ~0x4;
    784      1.1   toshii 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    785      1.1   toshii 		delay(100000);
    786      1.1   toshii 
    787      1.1   toshii 		val = -2;
    788      1.1   toshii 		config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
    789      1.1   toshii 
    790      1.1   toshii 		bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 1);
    791      1.1   toshii 
    792      1.1   toshii 		delay(100000);
    793      1.1   toshii 		reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
    794      1.1   toshii 		reg &= ~0x1;
    795      1.1   toshii 		bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
    796      1.1   toshii 	}
    797      1.1   toshii 	return 1;
    798      1.1   toshii }
    799