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