Home | History | Annotate | Line # | Download | only in dev
j6x0tp.c revision 1.7
      1 /*	$NetBSD: j6x0tp.c,v 1.7 2005/06/28 18:30:00 drochner Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2003 Valeriy E. Ushakov
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #include <sys/cdefs.h>
     31 __KERNEL_RCSID(0, "$NetBSD: j6x0tp.c,v 1.7 2005/06/28 18:30:00 drochner Exp $");
     32 
     33 #include <sys/param.h>
     34 #include <sys/kernel.h>
     35 #include <sys/device.h>
     36 #include <sys/malloc.h>
     37 #include <sys/systm.h>
     38 #include <sys/callout.h>
     39 #ifdef GPROF
     40 #include <sys/gmon.h>
     41 #endif
     42 
     43 #include "opt_j6x0tp.h"
     44 
     45 #include <dev/wscons/wsconsio.h>
     46 #include <dev/wscons/wsmousevar.h>
     47 #include <dev/wscons/wskbdvar.h>
     48 #include <dev/wscons/wsksymvar.h>
     49 #include <dev/wscons/wsksymdef.h>
     50 #include <dev/hpc/hpctpanelvar.h>
     51 
     52 #include <machine/platid.h>
     53 #include <machine/platid_mask.h>
     54 
     55 #include <machine/intr.h>
     56 
     57 #include <sh3/exception.h>
     58 #include <sh3/intcreg.h>
     59 #include <sh3/pfcreg.h>
     60 #include <sh3/adcreg.h>
     61 
     62 #include <sh3/dev/adcvar.h>
     63 
     64 
     65 #define J6X0TP_DEBUG
     66 #if 0 /* XXX: disabled in favor of local version that uses printf_nolog */
     67 #define DPRINTF_ENABLE
     68 #define DPRINTF_DEBUG	j6x0tp_debug
     69 #define DPRINTF_LEVEL	0
     70 #include <machine/debug.h>
     71 #else
     72 #ifdef J6X0TP_DEBUG
     73 volatile int j6x0tp_debug = 0;
     74 #define DPRINTF_PRINTF		printf_nolog
     75 #define DPRINTF(arg)		if (j6x0tp_debug) DPRINTF_PRINTF arg
     76 #define DPRINTFN(n, arg)	if (j6x0tp_debug > (n)) DPRINTF_PRINTF arg
     77 #else
     78 #define DPRINTF(arg)		((void)0)
     79 #define DPRINTFN(n, arg)	((void)0)
     80 #endif
     81 #endif
     82 
     83 
     84 /*
     85  * PFC bits pertinent to Jornada 6x0 touchpanel
     86  */
     87 #define PHDR_TP_PEN_DOWN	0x08
     88 
     89 #define SCPDR_TP_SCAN_ENABLE	0x20
     90 #define SCPDR_TP_SCAN_Y		0x02
     91 #define SCPDR_TP_SCAN_X		0x01
     92 
     93 /*
     94  * A/D converter channels to get x/y from
     95  */
     96 #define ADC_CHANNEL_TP_Y	1
     97 #define ADC_CHANNEL_TP_X	2
     98 
     99 /*
    100  * Default (read: my device :) raw X/Y values for framebuffer edges.
    101  * XXX: defopt these?
    102  */
    103 #define J6X0TP_FB_LEFT		 38
    104 #define J6X0TP_FB_RIGHT		950
    105 #define J6X0TP_FB_TOP		 80
    106 #define J6X0TP_FB_BOTTOM	900
    107 
    108 /*
    109  * Bottom of the n'th hard icon (n = 1..4)
    110  */
    111 #define J6X0TP_HARD_ICON_MAX_Y(n) \
    112 	(J6X0TP_FB_TOP + ((J6X0TP_FB_BOTTOM - J6X0TP_FB_TOP) / 4) * (n))
    113 
    114 
    115 struct j6x0tp_softc {
    116 	struct device sc_dev;
    117 
    118 #define J6X0TP_WSMOUSE_ENABLED	0x01
    119 #define J6X0TP_WSKBD_ENABLED	0x02
    120 	int sc_enabled;
    121 
    122 	int sc_hard_icon;
    123 
    124 	struct callout sc_touch_ch;
    125 
    126 	struct device *sc_wsmousedev;
    127 	struct device *sc_wskbddev;
    128 
    129 	struct tpcalib_softc sc_tpcalib; /* calibration info for wsmouse */
    130 };
    131 
    132 
    133 /* config machinery */
    134 static int	j6x0tp_match(struct device *, struct cfdata *, void *);
    135 static void	j6x0tp_attach(struct device *, struct device *, void *);
    136 
    137 /* wsmouse accessops */
    138 static int	j6x0tp_wsmouse_enable(void *);
    139 static int	j6x0tp_wsmouse_ioctl(void *, u_long, caddr_t, int,
    140 				     struct proc *);
    141 static void	j6x0tp_wsmouse_disable(void *);
    142 
    143 /* wskbd accessops */
    144 static int	j6x0tp_wskbd_enable(void *, int);
    145 static void	j6x0tp_wskbd_set_leds(void *, int);
    146 static int	j6x0tp_wskbd_ioctl(void *, u_long, caddr_t, int,
    147 				   struct proc *);
    148 
    149 /* internal driver routines */
    150 static void	j6x0tp_enable(struct j6x0tp_softc *);
    151 static void	j6x0tp_disable(struct j6x0tp_softc *);
    152 static int	j6x0tp_set_enable(struct j6x0tp_softc *, int, int);
    153 static int	j6x0tp_intr(void *);
    154 static void	j6x0tp_start_polling(void *);
    155 static void	j6x0tp_stop_polling(struct j6x0tp_softc *);
    156 static void	j6x0tp_callout_wsmouse(void *);
    157 static void	j6x0tp_callout_wskbd(void *);
    158 static void	j6x0tp_wsmouse_input(struct j6x0tp_softc *, int, int);
    159 static void	j6x0tp_get_raw_xy(int *, int *);
    160 static int	j6x0tp_get_hard_icon(int, int);
    161 
    162 
    163 const struct wsmouse_accessops j6x0tp_accessops = {
    164 	j6x0tp_wsmouse_enable,
    165 	j6x0tp_wsmouse_ioctl,
    166 	j6x0tp_wsmouse_disable
    167 };
    168 
    169 static const struct wsmouse_calibcoords j6x0tp_default_calib = {
    170 	0, 0, 639, 239,
    171 	4,
    172 	{{ J6X0TP_FB_LEFT,  J6X0TP_FB_TOP,      0,   0 },
    173 	 { J6X0TP_FB_RIGHT, J6X0TP_FB_TOP,    639,   0 },
    174 	 { J6X0TP_FB_LEFT,  J6X0TP_FB_BOTTOM,   0, 239 },
    175 	 { J6X0TP_FB_RIGHT, J6X0TP_FB_BOTTOM, 639, 239 }}
    176 };
    177 
    178 const struct wskbd_accessops j6x0tp_wskbd_accessops = {
    179 	j6x0tp_wskbd_enable,
    180 	j6x0tp_wskbd_set_leds,
    181 	j6x0tp_wskbd_ioctl
    182 };
    183 
    184 
    185 #ifndef J6X0TP_SETTINGS_ICON_KEYSYM
    186 #define J6X0TP_SETTINGS_ICON_KEYSYM	KS_Home
    187 #endif
    188 #ifndef J6X0TP_PGUP_ICON_KEYSYM
    189 #define J6X0TP_PGUP_ICON_KEYSYM		KS_Prior
    190 #endif
    191 #ifndef J6X0TP_PGDN_ICON_KEYSYM
    192 #define J6X0TP_PGDN_ICON_KEYSYM		KS_Next
    193 #endif
    194 #ifndef J6X0TP_SWITCH_ICON_KEYSYM
    195 #define J6X0TP_SWITCH_ICON_KEYSYM	KS_End
    196 #endif
    197 
    198 static const keysym_t j6x0tp_wskbd_keydesc[] = {
    199 	KS_KEYCODE(1), J6X0TP_SETTINGS_ICON_KEYSYM,
    200 	KS_KEYCODE(2), J6X0TP_PGUP_ICON_KEYSYM,
    201 	KS_KEYCODE(3), J6X0TP_PGDN_ICON_KEYSYM,
    202 	KS_KEYCODE(4), J6X0TP_SWITCH_ICON_KEYSYM
    203 };
    204 
    205 const struct wscons_keydesc j6x0tp_wskbd_keydesctab[] = {
    206 	{ KB_US, 0,
    207 	  sizeof(j6x0tp_wskbd_keydesc)/sizeof(keysym_t),
    208 	  j6x0tp_wskbd_keydesc
    209 	},
    210 	{0, 0, 0, 0}
    211 };
    212 
    213 const struct wskbd_mapdata j6x0tp_wskbd_keymapdata = {
    214         j6x0tp_wskbd_keydesctab, KB_US
    215 };
    216 
    217 
    218 CFATTACH_DECL(j6x0tp, sizeof(struct j6x0tp_softc),
    219     j6x0tp_match, j6x0tp_attach, NULL, NULL);
    220 
    221 
    222 static int
    223 j6x0tp_match(struct device *parent, struct cfdata *cf, void *aux)
    224 {
    225 
    226 	/*
    227 	 * XXX: does platid_mask_MACH_HP_LX matches _JORNADA_6XX too?
    228 	 * Is 620 wired similarly?
    229 	 */
    230 	if (!platid_match(&platid, &platid_mask_MACH_HP_JORNADA_6XX))
    231 		return (0);
    232 
    233 	if (strcmp(cf->cf_name, "j6x0tp") != 0)
    234 		return (0);
    235 
    236 	return (1);
    237 }
    238 
    239 
    240 /*
    241  * Attach the touch panel driver and its ws* children.
    242  *
    243  * Note that we have to use submatch to distinguish between children
    244  * because ws{kbd,mouse}_match match unconditionally.
    245  */
    246 static void
    247 j6x0tp_attach(struct device *parent, struct device *self, void *aux)
    248 {
    249 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
    250 	struct wsmousedev_attach_args wsma;
    251 	struct wskbddev_attach_args wska;
    252 
    253 	printf("\n");
    254 
    255 	sc->sc_enabled = 0;
    256 	sc->sc_hard_icon = 0;
    257 
    258 	/* touch-panel as a pointing device */
    259 	wsma.accessops = &j6x0tp_accessops;
    260 	wsma.accesscookie = sc;
    261 
    262 	sc->sc_wsmousedev = config_found_ia(self, "wsmousedev", &wsma,
    263 					    wsmousedevprint);
    264 	if (sc->sc_wsmousedev == NULL)
    265 		return;
    266 
    267 	/* on-screen "hard icons" as a keyboard device */
    268 	wska.console = 0;
    269 	wska.keymap = &j6x0tp_wskbd_keymapdata;
    270 	wska.accessops = &j6x0tp_wskbd_accessops;
    271 	wska.accesscookie = sc;
    272 
    273 	sc->sc_wskbddev = config_found_ia(self,"wskbddev",  &wska,
    274 					  wskbddevprint);
    275 
    276 	/* init calibration, set default parameters */
    277 	tpcalib_init(&sc->sc_tpcalib);
    278 	tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
    279 		      (caddr_t)__UNCONST(&j6x0tp_default_calib), 0, 0);
    280 
    281 	/* used when in polling mode */
    282 	callout_init(&sc->sc_touch_ch);
    283 
    284 	/* establish interrupt handler, but disable until opened */
    285 	intc_intr_establish(SH7709_INTEVT2_IRQ3, IST_EDGE, IPL_TTY,
    286 			    j6x0tp_intr, sc);
    287 	intc_intr_disable(SH7709_INTEVT2_IRQ3);
    288 }
    289 
    290 
    291 /*
    292  * Enable touch panel:  we start in interrupt mode.
    293  * Must be called as spltty().
    294  */
    295 static void
    296 j6x0tp_enable(struct j6x0tp_softc *sc)
    297 {
    298 
    299 	DPRINTFN(2, ("%s: enable\n", sc->sc_dev.dv_xname));
    300 	intc_intr_enable(SH7709_INTEVT2_IRQ3);
    301 }
    302 
    303 
    304 /*
    305  * Disable touch panel: disable interrupt, cancel pending callout.
    306  * Must be called as spltty().
    307  */
    308 static void
    309 j6x0tp_disable(struct j6x0tp_softc *sc)
    310 {
    311 
    312 	DPRINTFN(2, ("%s: disable\n", sc->sc_dev.dv_xname));
    313 	intc_intr_disable(SH7709_INTEVT2_IRQ3);
    314 	callout_stop(&sc->sc_touch_ch);
    315 }
    316 
    317 
    318 static int
    319 j6x0tp_set_enable(struct j6x0tp_softc *sc, int on, int child)
    320 {
    321 	int s = spltty();
    322 
    323 	if (on) {
    324 		if (!sc->sc_enabled)
    325 			j6x0tp_enable(sc);
    326 		sc->sc_enabled |= child;
    327 	} else {
    328 		sc->sc_enabled &= ~child;
    329 		if (!sc->sc_enabled)
    330 			j6x0tp_disable(sc);
    331 	}
    332 
    333 	splx(s);
    334 	return (0);
    335 }
    336 
    337 
    338 static int
    339 j6x0tp_wsmouse_enable(void *self)
    340 {
    341 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
    342 
    343 	DPRINTFN(1, ("%s: wsmouse enable\n", sc->sc_dev.dv_xname));
    344 	return (j6x0tp_set_enable(sc, 1, J6X0TP_WSMOUSE_ENABLED));
    345 }
    346 
    347 
    348 static void
    349 j6x0tp_wsmouse_disable(void *self)
    350 {
    351 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
    352 
    353 	DPRINTFN(1, ("%s: wsmouse disable\n", sc->sc_dev.dv_xname));
    354 	j6x0tp_set_enable(sc, 0, J6X0TP_WSMOUSE_ENABLED);
    355 }
    356 
    357 
    358 static int
    359 j6x0tp_wskbd_enable(void *self, int on)
    360 {
    361 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
    362 
    363 	DPRINTFN(1, ("%s: wskbd %sable\n", sc->sc_dev.dv_xname,
    364 		     on ? "en" : "dis"));
    365 	return (j6x0tp_set_enable(sc, on, J6X0TP_WSKBD_ENABLED));
    366 }
    367 
    368 
    369 static int
    370 j6x0tp_intr(void *self)
    371 {
    372 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
    373 
    374 	uint8_t irr0;
    375 	uint8_t phdr, touched;
    376 	unsigned int steady, tremor_timeout;
    377 
    378 	irr0 = _reg_read_1(SH7709_IRR0);
    379 	if ((irr0 & IRR0_IRQ3) == 0) {
    380 #ifdef DIAGNOSTIC
    381 		printf("%s: irr0 %02x?\n", sc->sc_dev.dv_xname, irr0);
    382 #endif
    383 		return (0);
    384 	}
    385 
    386 	if (!sc->sc_enabled) {
    387 		DPRINTFN(1, ("%s: intr: !sc_enabled\n", sc->sc_dev.dv_xname));
    388 		intc_intr_disable(SH7709_INTEVT2_IRQ3);
    389 		goto served;
    390 	}
    391 
    392 
    393 	/*
    394 	 * Number of times the "touched" bit should be read
    395 	 * consecutively.
    396 	 */
    397 #	define TREMOR_THRESHOLD 0x300
    398 
    399 	steady = 0;
    400 	tremor_timeout = TREMOR_THRESHOLD * 16;	/* XXX: arbitrary */
    401 	touched = PHDR_TP_PEN_DOWN;	/* we start with "touched" state */
    402 
    403 	do {
    404 		phdr = _reg_read_1(SH7709_PHDR);
    405 
    406 		if ((phdr & PHDR_TP_PEN_DOWN) == touched)
    407 			++steady;
    408 		else {
    409 			steady = 0;
    410 			touched = phdr & PHDR_TP_PEN_DOWN;
    411 		}
    412 
    413 		if (--tremor_timeout == 0) {
    414 			DPRINTF(("%s: tremor timeout!\n",
    415 				 sc->sc_dev.dv_xname));
    416 			goto served;
    417 		}
    418 	} while (steady < TREMOR_THRESHOLD);
    419 
    420 	if (touched) {
    421 		intc_intr_disable(SH7709_INTEVT2_IRQ3);
    422 
    423 		/*
    424 		 * ADC readings are not stable yet, so schedule
    425 		 * callout instead of accessing ADC from the interrupt
    426 		 * handler only to immediately delay().
    427 		 */
    428 		callout_reset(&sc->sc_touch_ch, hz/32,
    429 			      j6x0tp_start_polling, sc);
    430 	} else
    431 		DPRINTFN(1, ("%s: tremor\n", sc->sc_dev.dv_xname));
    432   served:
    433 	/* clear the interrupt (XXX: protect access?) */
    434 	_reg_write_1(SH7709_IRR0, irr0 & ~IRR0_IRQ3);
    435 
    436 	return (1);
    437 }
    438 
    439 
    440 /*
    441  * Called from the interrupt handler at spltty() upon first touch.
    442  * Decide if we are going to report this touch as a mouse click/drag
    443  * or as a key press.
    444  */
    445 static void
    446 j6x0tp_start_polling(void *self)
    447 {
    448 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
    449 	uint8_t phdr;
    450 	int do_mouse, do_kbd;
    451 	int rawx, rawy;
    452 	int icon;
    453 
    454 	phdr = _reg_read_1(SH7709_PHDR);
    455 	if ((phdr & PHDR_TP_PEN_DOWN) == 0) {
    456 		DPRINTFN(2, ("%s: start: pen is not down\n",
    457 			     sc->sc_dev.dv_xname));
    458 		j6x0tp_stop_polling(sc);
    459 	}
    460 
    461 	j6x0tp_get_raw_xy(&rawx, &rawy);
    462 	DPRINTFN(2, ("%s: start: %4d %4d -> ",
    463 		     sc->sc_dev.dv_xname, rawx, rawy));
    464 
    465 	do_mouse = sc->sc_enabled & J6X0TP_WSMOUSE_ENABLED;
    466 #ifdef J6X0TP_WSMOUSE_EXCLUSIVE
    467 	if (do_mouse)
    468 		do_kbd = 0;
    469 	else
    470 #endif
    471 		do_kbd = sc->sc_enabled & J6X0TP_WSKBD_ENABLED;
    472 
    473 	icon = 0;
    474 	if (do_kbd)
    475 		icon = j6x0tp_get_hard_icon(rawx, rawy);
    476 
    477 	if (icon != 0) {
    478 		DPRINTFN(2, ("icon %d\n", icon));
    479 		sc->sc_hard_icon = icon;
    480 		wskbd_input(sc->sc_wskbddev, WSCONS_EVENT_KEY_DOWN, icon);
    481 		callout_reset(&sc->sc_touch_ch, hz/32,
    482 			      j6x0tp_callout_wskbd, sc);
    483 	} else if (do_mouse) {
    484 		DPRINTFN(2, ("mouse\n"));
    485 		j6x0tp_wsmouse_input(sc, rawx, rawy);
    486 		callout_reset(&sc->sc_touch_ch, hz/32,
    487 			      j6x0tp_callout_wsmouse, sc);
    488 	} else {
    489 		DPRINTFN(2, ("ignore\n"));
    490 		j6x0tp_stop_polling(sc);
    491 	}
    492 }
    493 
    494 
    495 /*
    496  * Re-enable touch panel interrupt.
    497  * Called as spltty() when polling code detects pen-up.
    498  */
    499 static void
    500 j6x0tp_stop_polling(struct j6x0tp_softc *sc)
    501 {
    502 	uint8_t irr0;
    503 
    504 	DPRINTFN(2, ("%s: stop\n", sc->sc_dev.dv_xname));
    505 
    506 	/* clear pending interrupt signal before re-enabling the interrupt */
    507 	irr0 = _reg_read_1(SH7709_IRR0);
    508 	if ((irr0 & IRR0_IRQ3) != 0)
    509 		_reg_write_1(SH7709_IRR0, irr0 & ~IRR0_IRQ3);
    510 
    511 	intc_intr_enable(SH7709_INTEVT2_IRQ3);
    512 }
    513 
    514 
    515 /*
    516  * We are reporting this touch as a keyboard event.
    517  * Poll touch screen waiting for pen-up.
    518  */
    519 static void
    520 j6x0tp_callout_wskbd(void *self)
    521 {
    522 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
    523 	uint8_t phdr;
    524 	int s;
    525 
    526 	s = spltty();
    527 
    528 	if (!sc->sc_enabled) {
    529 		DPRINTFN(1, ("%s: wskbd callout: !sc_enabled\n",
    530 			     sc->sc_dev.dv_xname));
    531 		splx(s);
    532 		return;
    533 	}
    534 
    535 	phdr = _reg_read_1(SH7709_PHDR);
    536 	if ((phdr & PHDR_TP_PEN_DOWN) != 0) {
    537 		/*
    538 		 * Pen is still down, continue polling.  Wskbd's
    539 		 * auto-repeat takes care of repeating the key.
    540 		 */
    541 		callout_schedule(&sc->sc_touch_ch, hz/32);
    542 	} else {
    543 		wskbd_input(sc->sc_wskbddev,
    544 			    WSCONS_EVENT_KEY_UP, sc->sc_hard_icon);
    545 		j6x0tp_stop_polling(sc);
    546 	}
    547 	splx(s);
    548 }
    549 
    550 
    551 /*
    552  * We are reporting this touch as a mouse click/drag.
    553  */
    554 static void
    555 j6x0tp_callout_wsmouse(void *self)
    556 {
    557 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
    558 	uint8_t phdr;
    559 	int rawx, rawy;
    560 	int s;
    561 
    562 	s = spltty();
    563 
    564 	if (!sc->sc_enabled) {
    565 		DPRINTFN(1, ("%s: wsmouse callout: !sc_enabled\n",
    566 			     sc->sc_dev.dv_xname));
    567 		splx(s);
    568 		return;
    569 	}
    570 
    571 	phdr = _reg_read_1(SH7709_PHDR);
    572 	if ((phdr & PHDR_TP_PEN_DOWN) != 0) {
    573 		j6x0tp_get_raw_xy(&rawx, &rawy);
    574 		j6x0tp_wsmouse_input(sc, rawx, rawy); /* mouse dragged */
    575 		callout_schedule(&sc->sc_touch_ch, hz/32);
    576 	} else {
    577 		wsmouse_input(sc->sc_wsmousedev, 0, 0, 0, 0, /* button up */
    578 			      WSMOUSE_INPUT_DELTA);
    579 		j6x0tp_stop_polling(sc);
    580 	}
    581 	splx(s);
    582 }
    583 
    584 
    585 /*
    586  * Report mouse click/drag.
    587  */
    588 static void
    589 j6x0tp_wsmouse_input(struct j6x0tp_softc *sc, int rawx, int rawy)
    590 {
    591 	int x, y;
    592 
    593 	tpcalib_trans(&sc->sc_tpcalib, rawx, rawy, &x, &y);
    594 
    595 	DPRINTFN(3, ("%s: %4d %4d -> %3d %3d\n",
    596 		     sc->sc_dev.dv_xname, rawx, rawy, x, y));
    597 
    598 	wsmouse_input(sc->sc_wsmousedev,
    599 		      1,	/* button */
    600 		      x, y,
    601 		      0,	/* flags */
    602 		      WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
    603 }
    604 
    605 
    606 /*
    607  * Read raw X/Y coordinates from the ADC.
    608  * XXX: protect accesses to SCPDR?
    609  */
    610 static void
    611 j6x0tp_get_raw_xy(int *rawxp, int *rawyp)
    612 {
    613 	uint8_t scpdr;
    614 
    615 	/* Y axis */
    616 	scpdr = _reg_read_1(SH7709_SCPDR);
    617 	scpdr |=  SCPDR_TP_SCAN_ENABLE;
    618 	scpdr &= ~SCPDR_TP_SCAN_Y; /* pull low to scan */
    619 	_reg_write_1(SH7709_SCPDR, scpdr);
    620 	delay(10);
    621 
    622 	*rawyp = adc_sample_channel(ADC_CHANNEL_TP_Y);
    623 
    624 	/* X axis */
    625 	scpdr = _reg_read_1(SH7709_SCPDR);
    626 	scpdr |=  SCPDR_TP_SCAN_Y;
    627 	scpdr &= ~SCPDR_TP_SCAN_X; /* pull low to scan */
    628 	_reg_write_1(SH7709_SCPDR, scpdr);
    629 	delay(10);
    630 
    631 	*rawxp = adc_sample_channel(ADC_CHANNEL_TP_X);
    632 
    633 	/* restore SCPDR */
    634 	scpdr = _reg_read_1(SH7709_SCPDR);
    635 	scpdr |=  SCPDR_TP_SCAN_X;
    636 	scpdr &= ~SCPDR_TP_SCAN_ENABLE;
    637 	_reg_write_1(SH7709_SCPDR, scpdr);
    638 }
    639 
    640 
    641 /*
    642  * Check if the (rawx, rawy) is inside one of the 4 hard icons.
    643  * Return the icon number 1..4, or 0 if not inside an icon.
    644  */
    645 static int
    646 j6x0tp_get_hard_icon(int rawx, int rawy)
    647 {
    648 	if (rawx <= J6X0TP_FB_RIGHT)
    649 		return (0);
    650 
    651 	if (rawy < J6X0TP_HARD_ICON_MAX_Y(1))
    652 		return (1);
    653 	else if (rawy < J6X0TP_HARD_ICON_MAX_Y(2))
    654 		return (2);
    655 	else if (rawy < J6X0TP_HARD_ICON_MAX_Y(3))
    656 		return (3);
    657 	else
    658 		return (4);
    659 }
    660 
    661 
    662 static int
    663 j6x0tp_wsmouse_ioctl(void *self, u_long cmd, caddr_t data, int flag,
    664 		     struct proc *p)
    665 {
    666 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
    667 
    668 	return hpc_tpanel_ioctl(&sc->sc_tpcalib, cmd, data, flag, p);
    669 }
    670 
    671 
    672 static int
    673 j6x0tp_wskbd_ioctl(void *self, u_long cmd, caddr_t data, int flag,
    674 		     struct proc *p)
    675 {
    676 	/* struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self; */
    677 
    678 	switch (cmd) {
    679 	case WSKBDIO_GTYPE:
    680 		*(int *)data = WSKBD_TYPE_HPC_BTN; /* may be use new type? */
    681 		return (0);
    682 
    683 	case WSKBDIO_GETLEDS:
    684 		*(int *)data = 0;
    685 		return (0);
    686 
    687 	default:
    688 		return (EPASSTHROUGH);
    689 	}
    690 }
    691 
    692 
    693 static void
    694 j6x0tp_wskbd_set_leds(void *self, int leds)
    695 {
    696 
    697 	/* nothing to do*/
    698 	return;
    699 }
    700