Home | History | Annotate | Line # | Download | only in dev
j6x0tp.c revision 1.23
      1 /*	$NetBSD: j6x0tp.c,v 1.23 2009/04/05 02:19:57 uwe 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.23 2009/04/05 02:19:57 uwe 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_ia(self, "wsmousedev", &wsma,
    257 					    wsmousedevprint);
    258 	if (sc->sc_wsmousedev == NULL)
    259 		return;
    260 
    261 	/* on-screen "hard icons" as a keyboard device */
    262 	wska.console = 0;
    263 	wska.keymap = &j6x0tp_wskbd_keymapdata;
    264 	wska.accessops = &j6x0tp_wskbd_accessops;
    265 	wska.accesscookie = sc;
    266 
    267 	sc->sc_wskbddev = config_found_ia(self, "wskbddev", &wska,
    268 					  wskbddevprint);
    269 
    270 	/* init calibration, set default parameters */
    271 	tpcalib_init(&sc->sc_tpcalib);
    272 	tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
    273 		      (void *)__UNCONST(&j6x0tp_default_calib), 0, 0);
    274 
    275 	/* used when in polling mode */
    276 	callout_init(&sc->sc_touch_ch, 0);
    277 
    278 	/* establish interrupt handler, but disable until opened */
    279 	intc_intr_establish(SH7709_INTEVT2_IRQ3, IST_EDGE, IPL_TTY,
    280 			    j6x0tp_intr, sc);
    281 	intc_intr_disable(SH7709_INTEVT2_IRQ3);
    282 
    283 	if (!pmf_device_register(self, NULL, NULL))
    284 		aprint_error_dev(self, "unable to establish power handler\n");
    285 }
    286 
    287 
    288 /*
    289  * Enable touch panel:  we start in interrupt mode.
    290  * Must be called as spltty().
    291  */
    292 static void
    293 j6x0tp_enable(struct j6x0tp_softc *sc)
    294 {
    295 
    296 	DPRINTFN(2, ("%s: enable\n", device_xname(sc->sc_dev)));
    297 	intc_intr_enable(SH7709_INTEVT2_IRQ3);
    298 }
    299 
    300 
    301 /*
    302  * Disable touch panel: disable interrupt, cancel pending callout.
    303  * Must be called as spltty().
    304  */
    305 static void
    306 j6x0tp_disable(struct j6x0tp_softc *sc)
    307 {
    308 
    309 	DPRINTFN(2, ("%s: disable\n", device_xname(sc->sc_dev)));
    310 	intc_intr_disable(SH7709_INTEVT2_IRQ3);
    311 	callout_stop(&sc->sc_touch_ch);
    312 }
    313 
    314 
    315 static int
    316 j6x0tp_enable_child(struct j6x0tp_softc *sc, int child, int on)
    317 {
    318 	int s = spltty();
    319 
    320 	if (on) {
    321 		if (!sc->sc_enabled)
    322 			j6x0tp_enable(sc);
    323 		sc->sc_enabled |= child;
    324 	} else {
    325 		sc->sc_enabled &= ~child;
    326 		if (!sc->sc_enabled)
    327 			j6x0tp_disable(sc);
    328 	}
    329 
    330 	splx(s);
    331 	return (0);
    332 }
    333 
    334 
    335 static int
    336 j6x0tp_wsmouse_enable(void *arg)
    337 {
    338 	struct j6x0tp_softc *sc = arg;
    339 
    340 	DPRINTFN(1, ("%s: wsmouse enable\n", device_xname(sc->sc_dev)));
    341 	return (j6x0tp_enable_child(sc, J6X0TP_WSMOUSE_ENABLED, 1));
    342 }
    343 
    344 
    345 static void
    346 j6x0tp_wsmouse_disable(void *arg)
    347 {
    348 	struct j6x0tp_softc *sc = arg;
    349 
    350 	DPRINTFN(1, ("%s: wsmouse disable\n", device_xname(sc->sc_dev)));
    351 	j6x0tp_enable_child(sc, J6X0TP_WSMOUSE_ENABLED, 0);
    352 }
    353 
    354 
    355 static int
    356 j6x0tp_wskbd_enable(void *arg, int on)
    357 {
    358 	struct j6x0tp_softc *sc = arg;
    359 
    360 	DPRINTFN(1, ("%s: wskbd %sable\n", device_xname(sc->sc_dev),
    361 		     on ? "en" : "dis"));
    362 	return (j6x0tp_enable_child(sc, J6X0TP_WSKBD_ENABLED, on));
    363 }
    364 
    365 
    366 static int
    367 j6x0tp_intr(void *arg)
    368 {
    369 	struct j6x0tp_softc *sc = arg;
    370 
    371 	uint8_t irr0;
    372 	uint8_t phdr, touched;
    373 	unsigned int steady, tremor_timeout;
    374 
    375 	irr0 = _reg_read_1(SH7709_IRR0);
    376 	if ((irr0 & IRR0_IRQ3) == 0) {
    377 #ifdef DIAGNOSTIC
    378 		printf("%s: irr0 %02x?\n", device_xname(sc->sc_dev), irr0);
    379 #endif
    380 		return (0);
    381 	}
    382 
    383 	if (!sc->sc_enabled) {
    384 		DPRINTFN(1, ("%s: intr: !sc_enabled\n",
    385 			     device_xname(sc->sc_dev)));
    386 		intc_intr_disable(SH7709_INTEVT2_IRQ3);
    387 		goto served;
    388 	}
    389 
    390 
    391 	/*
    392 	 * Number of times the "touched" bit should be read
    393 	 * consecutively.
    394 	 */
    395 #	define TREMOR_THRESHOLD 0x300
    396 
    397 	steady = 0;
    398 	tremor_timeout = TREMOR_THRESHOLD * 16;	/* XXX: arbitrary */
    399 	touched = PHDR_TP_PEN_DOWN;	/* we start with "touched" state */
    400 
    401 	do {
    402 		phdr = _reg_read_1(SH7709_PHDR);
    403 
    404 		if ((phdr & PHDR_TP_PEN_DOWN) == touched)
    405 			++steady;
    406 		else {
    407 			steady = 0;
    408 			touched = phdr & PHDR_TP_PEN_DOWN;
    409 		}
    410 
    411 		if (--tremor_timeout == 0) {
    412 			DPRINTF(("%s: tremor timeout!\n",
    413 				 device_xname(sc->sc_dev)));
    414 			goto served;
    415 		}
    416 	} while (steady < TREMOR_THRESHOLD);
    417 
    418 	if (touched) {
    419 		intc_intr_disable(SH7709_INTEVT2_IRQ3);
    420 
    421 		/*
    422 		 * ADC readings are not stable yet, so schedule
    423 		 * callout instead of accessing ADC from the interrupt
    424 		 * handler only to immediately delay().
    425 		 */
    426 		callout_reset(&sc->sc_touch_ch, hz/32,
    427 			      j6x0tp_start_polling, sc);
    428 	} else
    429 		DPRINTFN(1, ("%s: tremor\n", device_xname(sc->sc_dev)));
    430   served:
    431 	/* clear the interrupt (XXX: protect access?) */
    432 	_reg_write_1(SH7709_IRR0, irr0 & ~IRR0_IRQ3);
    433 
    434 	return (1);
    435 }
    436 
    437 
    438 /*
    439  * Called from the interrupt handler at spltty() upon first touch.
    440  * Decide if we are going to report this touch as a mouse click/drag
    441  * or as a key press.
    442  */
    443 static void
    444 j6x0tp_start_polling(void *arg)
    445 {
    446 	struct j6x0tp_softc *sc = arg;
    447 	uint8_t phdr;
    448 	int do_mouse, do_kbd;
    449 	int rawx, rawy;
    450 	int icon;
    451 
    452 	phdr = _reg_read_1(SH7709_PHDR);
    453 	if ((phdr & PHDR_TP_PEN_DOWN) == 0) {
    454 		DPRINTFN(2, ("%s: start: pen is not down\n",
    455 			     device_xname(sc->sc_dev)));
    456 		j6x0tp_stop_polling(sc);
    457 	}
    458 
    459 	j6x0tp_get_raw_xy(&rawx, &rawy);
    460 	DPRINTFN(2, ("%s: start: %4d %4d -> ",
    461 		     device_xname(sc->sc_dev), rawx, rawy));
    462 
    463 	do_mouse = sc->sc_enabled & J6X0TP_WSMOUSE_ENABLED;
    464 #ifdef J6X0TP_WSMOUSE_EXCLUSIVE
    465 	if (do_mouse)
    466 		do_kbd = 0;
    467 	else
    468 #endif
    469 		do_kbd = sc->sc_enabled & J6X0TP_WSKBD_ENABLED;
    470 
    471 	icon = 0;
    472 	if (do_kbd)
    473 		icon = j6x0tp_get_hard_icon(rawx, rawy);
    474 
    475 	if (icon != 0) {
    476 		DPRINTFN(2, ("icon %d\n", icon));
    477 		sc->sc_hard_icon = icon;
    478 		wskbd_input(sc->sc_wskbddev, WSCONS_EVENT_KEY_DOWN, icon);
    479 		callout_reset(&sc->sc_touch_ch, hz/32,
    480 			      j6x0tp_callout_wskbd, sc);
    481 	} else if (do_mouse) {
    482 		DPRINTFN(2, ("mouse\n"));
    483 		j6x0tp_wsmouse_input(sc, rawx, rawy);
    484 		callout_reset(&sc->sc_touch_ch, hz/32,
    485 			      j6x0tp_callout_wsmouse, sc);
    486 	} else {
    487 		DPRINTFN(2, ("ignore\n"));
    488 		j6x0tp_stop_polling(sc);
    489 	}
    490 }
    491 
    492 
    493 /*
    494  * Re-enable touch panel interrupt.
    495  * Called as spltty() when polling code detects pen-up.
    496  */
    497 static void
    498 j6x0tp_stop_polling(struct j6x0tp_softc *sc)
    499 {
    500 	uint8_t irr0;
    501 
    502 	DPRINTFN(2, ("%s: stop\n", device_xname(sc->sc_dev)));
    503 
    504 	/* clear pending interrupt signal before re-enabling the interrupt */
    505 	irr0 = _reg_read_1(SH7709_IRR0);
    506 	if ((irr0 & IRR0_IRQ3) != 0)
    507 		_reg_write_1(SH7709_IRR0, irr0 & ~IRR0_IRQ3);
    508 
    509 	intc_intr_enable(SH7709_INTEVT2_IRQ3);
    510 }
    511 
    512 
    513 /*
    514  * We are reporting this touch as a keyboard event.
    515  * Poll touch screen waiting for pen-up.
    516  */
    517 static void
    518 j6x0tp_callout_wskbd(void *arg)
    519 {
    520 	struct j6x0tp_softc *sc = arg;
    521 	uint8_t phdr;
    522 	int s;
    523 
    524 	s = spltty();
    525 
    526 	if (!sc->sc_enabled) {
    527 		DPRINTFN(1, ("%s: wskbd callout: !sc_enabled\n",
    528 			     device_xname(sc->sc_dev)));
    529 		splx(s);
    530 		return;
    531 	}
    532 
    533 	phdr = _reg_read_1(SH7709_PHDR);
    534 	if ((phdr & PHDR_TP_PEN_DOWN) != 0) {
    535 		/*
    536 		 * Pen is still down, continue polling.  Wskbd's
    537 		 * auto-repeat takes care of repeating the key.
    538 		 */
    539 		callout_schedule(&sc->sc_touch_ch, hz/32);
    540 	} else {
    541 		wskbd_input(sc->sc_wskbddev,
    542 			    WSCONS_EVENT_KEY_UP, sc->sc_hard_icon);
    543 		j6x0tp_stop_polling(sc);
    544 	}
    545 	splx(s);
    546 }
    547 
    548 
    549 /*
    550  * We are reporting this touch as a mouse click/drag.
    551  */
    552 static void
    553 j6x0tp_callout_wsmouse(void *arg)
    554 {
    555 	struct j6x0tp_softc *sc = arg;
    556 	uint8_t phdr;
    557 	int rawx, rawy;
    558 	int s;
    559 
    560 	s = spltty();
    561 
    562 	if (!sc->sc_enabled) {
    563 		DPRINTFN(1, ("%s: wsmouse callout: !sc_enabled\n",
    564 			     device_xname(sc->sc_dev)));
    565 		splx(s);
    566 		return;
    567 	}
    568 
    569 	phdr = _reg_read_1(SH7709_PHDR);
    570 	if ((phdr & PHDR_TP_PEN_DOWN) != 0) {
    571 		j6x0tp_get_raw_xy(&rawx, &rawy);
    572 		j6x0tp_wsmouse_input(sc, rawx, rawy); /* mouse dragged */
    573 		callout_schedule(&sc->sc_touch_ch, hz/32);
    574 	} else {
    575 		wsmouse_input(sc->sc_wsmousedev, 0, 0, 0, 0, 0, /* button up */
    576 			      WSMOUSE_INPUT_DELTA);
    577 		j6x0tp_stop_polling(sc);
    578 	}
    579 	splx(s);
    580 }
    581 
    582 
    583 /*
    584  * Report mouse click/drag.
    585  */
    586 static void
    587 j6x0tp_wsmouse_input(struct j6x0tp_softc *sc, int rawx, int rawy)
    588 {
    589 	int x, y;
    590 
    591 	tpcalib_trans(&sc->sc_tpcalib, rawx, rawy, &x, &y);
    592 
    593 	DPRINTFN(3, ("%s: %4d %4d -> %3d %3d\n",
    594 		     device_xname(sc->sc_dev), rawx, rawy, x, y));
    595 
    596 	wsmouse_input(sc->sc_wsmousedev,
    597 			1,	/* button */
    598 			x, y, 0, 0,
    599 			WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
    600 }
    601 
    602 
    603 /*
    604  * Read raw X/Y coordinates from the ADC.
    605  * XXX: protect accesses to SCPDR?
    606  */
    607 static void
    608 j6x0tp_get_raw_xy(int *rawxp, int *rawyp)
    609 {
    610 	uint8_t scpdr;
    611 
    612 	/* Y axis */
    613 	scpdr = _reg_read_1(SH7709_SCPDR);
    614 	scpdr |=  SCPDR_TP_SCAN_ENABLE;
    615 	scpdr &= ~SCPDR_TP_SCAN_Y; /* pull low to scan */
    616 	_reg_write_1(SH7709_SCPDR, scpdr);
    617 	delay(10);
    618 
    619 	*rawyp = adc_sample_channel(ADC_CHANNEL_TP_Y);
    620 
    621 	/* X axis */
    622 	scpdr = _reg_read_1(SH7709_SCPDR);
    623 	scpdr |=  SCPDR_TP_SCAN_Y;
    624 	scpdr &= ~SCPDR_TP_SCAN_X; /* pull low to scan */
    625 	_reg_write_1(SH7709_SCPDR, scpdr);
    626 	delay(10);
    627 
    628 	*rawxp = adc_sample_channel(ADC_CHANNEL_TP_X);
    629 
    630 	/* restore SCPDR */
    631 	scpdr = _reg_read_1(SH7709_SCPDR);
    632 	scpdr |=  SCPDR_TP_SCAN_X;
    633 	scpdr &= ~SCPDR_TP_SCAN_ENABLE;
    634 	_reg_write_1(SH7709_SCPDR, scpdr);
    635 }
    636 
    637 
    638 /*
    639  * Check if the (rawx, rawy) is inside one of the 4 hard icons.
    640  * Return the icon number 1..4, or 0 if not inside an icon.
    641  */
    642 static int
    643 j6x0tp_get_hard_icon(int rawx, int rawy)
    644 {
    645 	if (rawx <= J6X0TP_FB_RIGHT)
    646 		return (0);
    647 
    648 	if (rawy < J6X0TP_HARD_ICON_MAX_Y(1))
    649 		return (1);
    650 	else if (rawy < J6X0TP_HARD_ICON_MAX_Y(2))
    651 		return (2);
    652 	else if (rawy < J6X0TP_HARD_ICON_MAX_Y(3))
    653 		return (3);
    654 	else
    655 		return (4);
    656 }
    657 
    658 
    659 static int
    660 j6x0tp_wsmouse_ioctl(void *arg, u_long cmd, void *data, int flag, lwp_t *l)
    661 {
    662 	struct j6x0tp_softc *sc = arg;
    663 
    664 	return hpc_tpanel_ioctl(&sc->sc_tpcalib, cmd, data, flag, l);
    665 }
    666 
    667 
    668 static int
    669 j6x0tp_wskbd_ioctl(void *arg, u_long cmd, void *data, int flag, lwp_t *l)
    670 {
    671 	/* struct j6x0tp_softc *sc = arg; */
    672 
    673 	switch (cmd) {
    674 	case WSKBDIO_GTYPE:
    675 		*(int *)data = WSKBD_TYPE_HPC_BTN; /* may be use new type? */
    676 		return (0);
    677 
    678 	case WSKBDIO_GETLEDS:
    679 		*(int *)data = 0;
    680 		return (0);
    681 
    682 	default:
    683 		return (EPASSTHROUGH);
    684 	}
    685 }
    686 
    687 
    688 static void
    689 j6x0tp_wskbd_set_leds(void *arg, int leds)
    690 {
    691 
    692 	/* nothing to do*/
    693 	return;
    694 }
    695