Home | History | Annotate | Line # | Download | only in dev
j6x0tp.c revision 1.24
      1 /*	$NetBSD: j6x0tp.c,v 1.24 2021/04/24 23:36:38 thorpej 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.24 2021/04/24 23:36:38 thorpej 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 
     40 #include "opt_j6x0tp.h"
     41 
     42 #include <dev/wscons/wsconsio.h>
     43 #include <dev/wscons/wsmousevar.h>
     44 #include <dev/wscons/wskbdvar.h>
     45 #include <dev/wscons/wsksymvar.h>
     46 #include <dev/wscons/wsksymdef.h>
     47 #include <dev/hpc/hpctpanelvar.h>
     48 
     49 #include <machine/platid.h>
     50 #include <machine/platid_mask.h>
     51 
     52 #include <machine/intr.h>
     53 
     54 #include <sh3/exception.h>
     55 #include <sh3/intcreg.h>
     56 #include <sh3/pfcreg.h>
     57 #include <sh3/adcreg.h>
     58 
     59 #include <sh3/dev/adcvar.h>
     60 
     61 
     62 #if 0 /* XXX: disabled in favor of local version that uses printf_nolog */
     63 #define DPRINTF_ENABLE
     64 #define DPRINTF_DEBUG	j6x0tp_debug
     65 #define DPRINTF_LEVEL	0
     66 #include <machine/debug.h>
     67 #else
     68 #ifdef J6X0TP_DEBUG
     69 volatile int j6x0tp_debug = 0;
     70 #define DPRINTF_PRINTF		printf_nolog
     71 #define DPRINTF(arg)		if (j6x0tp_debug) DPRINTF_PRINTF arg
     72 #define DPRINTFN(n, arg)	if (j6x0tp_debug > (n)) DPRINTF_PRINTF arg
     73 #else
     74 #define DPRINTF(arg)		((void)0)
     75 #define DPRINTFN(n, arg)	((void)0)
     76 #endif
     77 #endif
     78 
     79 
     80 /*
     81  * PFC bits pertinent to Jornada 6x0 touchpanel
     82  */
     83 #define PHDR_TP_PEN_DOWN	0x08
     84 
     85 #define SCPDR_TP_SCAN_ENABLE	0x20
     86 #define SCPDR_TP_SCAN_Y		0x02
     87 #define SCPDR_TP_SCAN_X		0x01
     88 
     89 /*
     90  * A/D converter channels to get x/y from
     91  */
     92 #define ADC_CHANNEL_TP_Y	1
     93 #define ADC_CHANNEL_TP_X	2
     94 
     95 /*
     96  * Default (read: my device :) raw X/Y values for framebuffer edges.
     97  * XXX: defopt these?
     98  */
     99 #define J6X0TP_FB_LEFT		 38
    100 #define J6X0TP_FB_RIGHT		950
    101 #define J6X0TP_FB_TOP		 80
    102 #define J6X0TP_FB_BOTTOM	900
    103 
    104 /*
    105  * Bottom of the n'th hard icon (n = 1..4)
    106  */
    107 #define J6X0TP_HARD_ICON_MAX_Y(n) \
    108 	(J6X0TP_FB_TOP + ((J6X0TP_FB_BOTTOM - J6X0TP_FB_TOP) / 4) * (n))
    109 
    110 
    111 struct j6x0tp_softc {
    112 	device_t sc_dev;
    113 
    114 #define J6X0TP_WSMOUSE_ENABLED	0x01
    115 #define J6X0TP_WSKBD_ENABLED	0x02
    116 	int sc_enabled;
    117 
    118 	int sc_hard_icon;
    119 
    120 	struct callout sc_touch_ch;
    121 
    122 	device_t sc_wsmousedev;
    123 	device_t sc_wskbddev;
    124 
    125 	struct tpcalib_softc sc_tpcalib; /* calibration info for wsmouse */
    126 };
    127 
    128 
    129 /* config machinery */
    130 static int	j6x0tp_match(device_t, cfdata_t, void *);
    131 static void	j6x0tp_attach(device_t, device_t, void *);
    132 
    133 /* wsmouse accessops */
    134 static int	j6x0tp_wsmouse_enable(void *);
    135 static int	j6x0tp_wsmouse_ioctl(void *, u_long, void *, int, lwp_t *);
    136 static void	j6x0tp_wsmouse_disable(void *);
    137 
    138 /* wskbd accessops */
    139 static int	j6x0tp_wskbd_enable(void *, int);
    140 static void	j6x0tp_wskbd_set_leds(void *, int);
    141 static int	j6x0tp_wskbd_ioctl(void *, u_long, void *, int, lwp_t *);
    142 
    143 /* internal driver routines */
    144 static void	j6x0tp_enable(struct j6x0tp_softc *);
    145 static void	j6x0tp_disable(struct j6x0tp_softc *);
    146 static int	j6x0tp_enable_child(struct j6x0tp_softc *, int, int);
    147 static int	j6x0tp_intr(void *);
    148 static void	j6x0tp_start_polling(void *);
    149 static void	j6x0tp_stop_polling(struct j6x0tp_softc *);
    150 static void	j6x0tp_callout_wsmouse(void *);
    151 static void	j6x0tp_callout_wskbd(void *);
    152 static void	j6x0tp_wsmouse_input(struct j6x0tp_softc *, int, int);
    153 static void	j6x0tp_get_raw_xy(int *, int *);
    154 static int	j6x0tp_get_hard_icon(int, int);
    155 
    156 
    157 static const struct wsmouse_accessops j6x0tp_accessops = {
    158 	j6x0tp_wsmouse_enable,
    159 	j6x0tp_wsmouse_ioctl,
    160 	j6x0tp_wsmouse_disable
    161 };
    162 
    163 static const struct wsmouse_calibcoords j6x0tp_default_calib = {
    164 	0, 0, 639, 239,
    165 	4,
    166 	{{ J6X0TP_FB_LEFT,  J6X0TP_FB_TOP,      0,   0 },
    167 	 { J6X0TP_FB_RIGHT, J6X0TP_FB_TOP,    639,   0 },
    168 	 { J6X0TP_FB_LEFT,  J6X0TP_FB_BOTTOM,   0, 239 },
    169 	 { J6X0TP_FB_RIGHT, J6X0TP_FB_BOTTOM, 639, 239 }}
    170 };
    171 
    172 static const struct wskbd_accessops j6x0tp_wskbd_accessops = {
    173 	j6x0tp_wskbd_enable,
    174 	j6x0tp_wskbd_set_leds,
    175 	j6x0tp_wskbd_ioctl
    176 };
    177 
    178 
    179 #ifndef J6X0TP_SETTINGS_ICON_KEYSYM
    180 #define J6X0TP_SETTINGS_ICON_KEYSYM	KS_Home
    181 #endif
    182 #ifndef J6X0TP_PGUP_ICON_KEYSYM
    183 #define J6X0TP_PGUP_ICON_KEYSYM		KS_Prior
    184 #endif
    185 #ifndef J6X0TP_PGDN_ICON_KEYSYM
    186 #define J6X0TP_PGDN_ICON_KEYSYM		KS_Next
    187 #endif
    188 #ifndef J6X0TP_SWITCH_ICON_KEYSYM
    189 #define J6X0TP_SWITCH_ICON_KEYSYM	KS_End
    190 #endif
    191 
    192 static const keysym_t j6x0tp_wskbd_keydesc[] = {
    193 	KS_KEYCODE(1), J6X0TP_SETTINGS_ICON_KEYSYM,
    194 	KS_KEYCODE(2), J6X0TP_PGUP_ICON_KEYSYM,
    195 	KS_KEYCODE(3), J6X0TP_PGDN_ICON_KEYSYM,
    196 	KS_KEYCODE(4), J6X0TP_SWITCH_ICON_KEYSYM
    197 };
    198 
    199 static const struct wscons_keydesc j6x0tp_wskbd_keydesctab[] = {
    200 	{ KB_US, 0,
    201 	  sizeof(j6x0tp_wskbd_keydesc)/sizeof(keysym_t),
    202 	  j6x0tp_wskbd_keydesc
    203 	},
    204 	{0, 0, 0, 0}
    205 };
    206 
    207 static const struct wskbd_mapdata j6x0tp_wskbd_keymapdata = {
    208         j6x0tp_wskbd_keydesctab, KB_US
    209 };
    210 
    211 
    212 CFATTACH_DECL_NEW(j6x0tp, sizeof(struct j6x0tp_softc),
    213     j6x0tp_match, j6x0tp_attach, NULL, NULL);
    214 
    215 
    216 static int
    217 j6x0tp_match(device_t parent, cfdata_t cf, void *aux)
    218 {
    219 
    220 	/*
    221 	 * XXX: platid_mask_MACH_HP_LX also matches 360LX.  It's not
    222 	 * confirmed whether touch panel in 360LX is connected this
    223 	 * way.  We may need to regroup platid masks.
    224 	 */
    225 	if (!platid_match(&platid, &platid_mask_MACH_HP_JORNADA_6XX)
    226 	    && !platid_match(&platid, &platid_mask_MACH_HP_LX))
    227 		return (0);
    228 
    229 	if (strcmp(cf->cf_name, "j6x0tp") != 0)
    230 		return (0);
    231 
    232 	return (1);
    233 }
    234 
    235 
    236 static void
    237 j6x0tp_attach(device_t parent, device_t self, void *aux)
    238 {
    239 	struct j6x0tp_softc *sc;
    240 	struct wsmousedev_attach_args wsma;
    241 	struct wskbddev_attach_args wska;
    242 
    243 	aprint_naive("\n");
    244 	aprint_normal("\n");
    245 
    246 	sc = device_private(self);
    247 	sc->sc_dev = self;
    248 
    249 	sc->sc_enabled = 0;
    250 	sc->sc_hard_icon = 0;
    251 
    252 	/* touch-panel as a pointing device */
    253 	wsma.accessops = &j6x0tp_accessops;
    254 	wsma.accesscookie = sc;
    255 
    256 	sc->sc_wsmousedev = config_found(self, &wsma, wsmousedevprint,
    257 	    CFARG_IATTR, "wsmousedev",
    258 	    CFARG_EOL);
    259 	if (sc->sc_wsmousedev == NULL)
    260 		return;
    261 
    262 	/* on-screen "hard icons" as a keyboard device */
    263 	wska.console = 0;
    264 	wska.keymap = &j6x0tp_wskbd_keymapdata;
    265 	wska.accessops = &j6x0tp_wskbd_accessops;
    266 	wska.accesscookie = sc;
    267 
    268 	sc->sc_wskbddev = config_found(self, &wska, wskbddevprint,
    269 	    CFARG_IATTR, "wskbddev",
    270 	    CFARG_EOL);
    271 
    272 	/* init calibration, set default parameters */
    273 	tpcalib_init(&sc->sc_tpcalib);
    274 	tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
    275 		      (void *)__UNCONST(&j6x0tp_default_calib), 0, 0);
    276 
    277 	/* used when in polling mode */
    278 	callout_init(&sc->sc_touch_ch, 0);
    279 
    280 	/* establish interrupt handler, but disable until opened */
    281 	intc_intr_establish(SH7709_INTEVT2_IRQ3, IST_EDGE, IPL_TTY,
    282 			    j6x0tp_intr, sc);
    283 	intc_intr_disable(SH7709_INTEVT2_IRQ3);
    284 
    285 	if (!pmf_device_register(self, NULL, NULL))
    286 		aprint_error_dev(self, "unable to establish power handler\n");
    287 }
    288 
    289 
    290 /*
    291  * Enable touch panel:  we start in interrupt mode.
    292  * Must be called as spltty().
    293  */
    294 static void
    295 j6x0tp_enable(struct j6x0tp_softc *sc)
    296 {
    297 
    298 	DPRINTFN(2, ("%s: enable\n", device_xname(sc->sc_dev)));
    299 	intc_intr_enable(SH7709_INTEVT2_IRQ3);
    300 }
    301 
    302 
    303 /*
    304  * Disable touch panel: disable interrupt, cancel pending callout.
    305  * Must be called as spltty().
    306  */
    307 static void
    308 j6x0tp_disable(struct j6x0tp_softc *sc)
    309 {
    310 
    311 	DPRINTFN(2, ("%s: disable\n", device_xname(sc->sc_dev)));
    312 	intc_intr_disable(SH7709_INTEVT2_IRQ3);
    313 	callout_stop(&sc->sc_touch_ch);
    314 }
    315 
    316 
    317 static int
    318 j6x0tp_enable_child(struct j6x0tp_softc *sc, int child, int on)
    319 {
    320 	int s = spltty();
    321 
    322 	if (on) {
    323 		if (!sc->sc_enabled)
    324 			j6x0tp_enable(sc);
    325 		sc->sc_enabled |= child;
    326 	} else {
    327 		sc->sc_enabled &= ~child;
    328 		if (!sc->sc_enabled)
    329 			j6x0tp_disable(sc);
    330 	}
    331 
    332 	splx(s);
    333 	return (0);
    334 }
    335 
    336 
    337 static int
    338 j6x0tp_wsmouse_enable(void *arg)
    339 {
    340 	struct j6x0tp_softc *sc = arg;
    341 
    342 	DPRINTFN(1, ("%s: wsmouse enable\n", device_xname(sc->sc_dev)));
    343 	return (j6x0tp_enable_child(sc, J6X0TP_WSMOUSE_ENABLED, 1));
    344 }
    345 
    346 
    347 static void
    348 j6x0tp_wsmouse_disable(void *arg)
    349 {
    350 	struct j6x0tp_softc *sc = arg;
    351 
    352 	DPRINTFN(1, ("%s: wsmouse disable\n", device_xname(sc->sc_dev)));
    353 	j6x0tp_enable_child(sc, J6X0TP_WSMOUSE_ENABLED, 0);
    354 }
    355 
    356 
    357 static int
    358 j6x0tp_wskbd_enable(void *arg, int on)
    359 {
    360 	struct j6x0tp_softc *sc = arg;
    361 
    362 	DPRINTFN(1, ("%s: wskbd %sable\n", device_xname(sc->sc_dev),
    363 		     on ? "en" : "dis"));
    364 	return (j6x0tp_enable_child(sc, J6X0TP_WSKBD_ENABLED, on));
    365 }
    366 
    367 
    368 static int
    369 j6x0tp_intr(void *arg)
    370 {
    371 	struct j6x0tp_softc *sc = arg;
    372 
    373 	uint8_t irr0;
    374 	uint8_t phdr, touched;
    375 	unsigned int steady, tremor_timeout;
    376 
    377 	irr0 = _reg_read_1(SH7709_IRR0);
    378 	if ((irr0 & IRR0_IRQ3) == 0) {
    379 #ifdef DIAGNOSTIC
    380 		printf("%s: irr0 %02x?\n", device_xname(sc->sc_dev), irr0);
    381 #endif
    382 		return (0);
    383 	}
    384 
    385 	if (!sc->sc_enabled) {
    386 		DPRINTFN(1, ("%s: intr: !sc_enabled\n",
    387 			     device_xname(sc->sc_dev)));
    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 				 device_xname(sc->sc_dev)));
    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", device_xname(sc->sc_dev)));
    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 *arg)
    447 {
    448 	struct j6x0tp_softc *sc = arg;
    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 			     device_xname(sc->sc_dev)));
    458 		j6x0tp_stop_polling(sc);
    459 	}
    460 
    461 	j6x0tp_get_raw_xy(&rawx, &rawy);
    462 	DPRINTFN(2, ("%s: start: %4d %4d -> ",
    463 		     device_xname(sc->sc_dev), 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", device_xname(sc->sc_dev)));
    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 *arg)
    521 {
    522 	struct j6x0tp_softc *sc = arg;
    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 			     device_xname(sc->sc_dev)));
    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 *arg)
    556 {
    557 	struct j6x0tp_softc *sc = arg;
    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 			     device_xname(sc->sc_dev)));
    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, 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 		     device_xname(sc->sc_dev), rawx, rawy, x, y));
    597 
    598 	wsmouse_input(sc->sc_wsmousedev,
    599 			1,	/* button */
    600 			x, y, 0, 0,
    601 			WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
    602 }
    603 
    604 
    605 /*
    606  * Read raw X/Y coordinates from the ADC.
    607  * XXX: protect accesses to SCPDR?
    608  */
    609 static void
    610 j6x0tp_get_raw_xy(int *rawxp, int *rawyp)
    611 {
    612 	uint8_t scpdr;
    613 
    614 	/* Y axis */
    615 	scpdr = _reg_read_1(SH7709_SCPDR);
    616 	scpdr |=  SCPDR_TP_SCAN_ENABLE;
    617 	scpdr &= ~SCPDR_TP_SCAN_Y; /* pull low to scan */
    618 	_reg_write_1(SH7709_SCPDR, scpdr);
    619 	delay(10);
    620 
    621 	*rawyp = adc_sample_channel(ADC_CHANNEL_TP_Y);
    622 
    623 	/* X axis */
    624 	scpdr = _reg_read_1(SH7709_SCPDR);
    625 	scpdr |=  SCPDR_TP_SCAN_Y;
    626 	scpdr &= ~SCPDR_TP_SCAN_X; /* pull low to scan */
    627 	_reg_write_1(SH7709_SCPDR, scpdr);
    628 	delay(10);
    629 
    630 	*rawxp = adc_sample_channel(ADC_CHANNEL_TP_X);
    631 
    632 	/* restore SCPDR */
    633 	scpdr = _reg_read_1(SH7709_SCPDR);
    634 	scpdr |=  SCPDR_TP_SCAN_X;
    635 	scpdr &= ~SCPDR_TP_SCAN_ENABLE;
    636 	_reg_write_1(SH7709_SCPDR, scpdr);
    637 }
    638 
    639 
    640 /*
    641  * Check if the (rawx, rawy) is inside one of the 4 hard icons.
    642  * Return the icon number 1..4, or 0 if not inside an icon.
    643  */
    644 static int
    645 j6x0tp_get_hard_icon(int rawx, int rawy)
    646 {
    647 	if (rawx <= J6X0TP_FB_RIGHT)
    648 		return (0);
    649 
    650 	if (rawy < J6X0TP_HARD_ICON_MAX_Y(1))
    651 		return (1);
    652 	else if (rawy < J6X0TP_HARD_ICON_MAX_Y(2))
    653 		return (2);
    654 	else if (rawy < J6X0TP_HARD_ICON_MAX_Y(3))
    655 		return (3);
    656 	else
    657 		return (4);
    658 }
    659 
    660 
    661 static int
    662 j6x0tp_wsmouse_ioctl(void *arg, u_long cmd, void *data, int flag, lwp_t *l)
    663 {
    664 	struct j6x0tp_softc *sc = arg;
    665 
    666 	return hpc_tpanel_ioctl(&sc->sc_tpcalib, cmd, data, flag, l);
    667 }
    668 
    669 
    670 static int
    671 j6x0tp_wskbd_ioctl(void *arg, u_long cmd, void *data, int flag, lwp_t *l)
    672 {
    673 	/* struct j6x0tp_softc *sc = arg; */
    674 
    675 	switch (cmd) {
    676 	case WSKBDIO_GTYPE:
    677 		*(int *)data = WSKBD_TYPE_HPC_BTN; /* may be use new type? */
    678 		return (0);
    679 
    680 	case WSKBDIO_GETLEDS:
    681 		*(int *)data = 0;
    682 		return (0);
    683 
    684 	default:
    685 		return (EPASSTHROUGH);
    686 	}
    687 }
    688 
    689 
    690 static void
    691 j6x0tp_wskbd_set_leds(void *arg, int leds)
    692 {
    693 
    694 	/* nothing to do*/
    695 	return;
    696 }
    697