xref: /netbsd-src/sys/arch/hpcsh/dev/j6x0tp.c (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: j6x0tp.c,v 1.21 2007/10/17 19:54:30 garbled 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 2007/10/17 19:54:30 garbled 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 	struct device 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 	struct device *sc_wsmousedev;
123 	struct device *sc_wskbddev;
124 
125 	struct tpcalib_softc sc_tpcalib; /* calibration info for wsmouse */
126 };
127 
128 
129 /* config machinery */
130 static int	j6x0tp_match(struct device *, struct cfdata *, void *);
131 static void	j6x0tp_attach(struct device *, struct device *, void *);
132 
133 /* wsmouse accessops */
134 static int	j6x0tp_wsmouse_enable(void *);
135 static int	j6x0tp_wsmouse_ioctl(void *, u_long, void *, int,
136 				     struct lwp *);
137 static void	j6x0tp_wsmouse_disable(void *);
138 
139 /* wskbd accessops */
140 static int	j6x0tp_wskbd_enable(void *, int);
141 static void	j6x0tp_wskbd_set_leds(void *, int);
142 static int	j6x0tp_wskbd_ioctl(void *, u_long, void *, int,
143 				   struct lwp *);
144 
145 /* internal driver routines */
146 static void	j6x0tp_enable(struct j6x0tp_softc *);
147 static void	j6x0tp_disable(struct j6x0tp_softc *);
148 static int	j6x0tp_enable_child(struct j6x0tp_softc *, int, int);
149 static int	j6x0tp_intr(void *);
150 static void	j6x0tp_start_polling(void *);
151 static void	j6x0tp_stop_polling(struct j6x0tp_softc *);
152 static void	j6x0tp_callout_wsmouse(void *);
153 static void	j6x0tp_callout_wskbd(void *);
154 static void	j6x0tp_wsmouse_input(struct j6x0tp_softc *, int, int);
155 static void	j6x0tp_get_raw_xy(int *, int *);
156 static int	j6x0tp_get_hard_icon(int, int);
157 
158 
159 static const struct wsmouse_accessops j6x0tp_accessops = {
160 	j6x0tp_wsmouse_enable,
161 	j6x0tp_wsmouse_ioctl,
162 	j6x0tp_wsmouse_disable
163 };
164 
165 static const struct wsmouse_calibcoords j6x0tp_default_calib = {
166 	0, 0, 639, 239,
167 	4,
168 	{{ J6X0TP_FB_LEFT,  J6X0TP_FB_TOP,      0,   0 },
169 	 { J6X0TP_FB_RIGHT, J6X0TP_FB_TOP,    639,   0 },
170 	 { J6X0TP_FB_LEFT,  J6X0TP_FB_BOTTOM,   0, 239 },
171 	 { J6X0TP_FB_RIGHT, J6X0TP_FB_BOTTOM, 639, 239 }}
172 };
173 
174 static const struct wskbd_accessops j6x0tp_wskbd_accessops = {
175 	j6x0tp_wskbd_enable,
176 	j6x0tp_wskbd_set_leds,
177 	j6x0tp_wskbd_ioctl
178 };
179 
180 
181 #ifndef J6X0TP_SETTINGS_ICON_KEYSYM
182 #define J6X0TP_SETTINGS_ICON_KEYSYM	KS_Home
183 #endif
184 #ifndef J6X0TP_PGUP_ICON_KEYSYM
185 #define J6X0TP_PGUP_ICON_KEYSYM		KS_Prior
186 #endif
187 #ifndef J6X0TP_PGDN_ICON_KEYSYM
188 #define J6X0TP_PGDN_ICON_KEYSYM		KS_Next
189 #endif
190 #ifndef J6X0TP_SWITCH_ICON_KEYSYM
191 #define J6X0TP_SWITCH_ICON_KEYSYM	KS_End
192 #endif
193 
194 static const keysym_t j6x0tp_wskbd_keydesc[] = {
195 	KS_KEYCODE(1), J6X0TP_SETTINGS_ICON_KEYSYM,
196 	KS_KEYCODE(2), J6X0TP_PGUP_ICON_KEYSYM,
197 	KS_KEYCODE(3), J6X0TP_PGDN_ICON_KEYSYM,
198 	KS_KEYCODE(4), J6X0TP_SWITCH_ICON_KEYSYM
199 };
200 
201 static const struct wscons_keydesc j6x0tp_wskbd_keydesctab[] = {
202 	{ KB_US, 0,
203 	  sizeof(j6x0tp_wskbd_keydesc)/sizeof(keysym_t),
204 	  j6x0tp_wskbd_keydesc
205 	},
206 	{0, 0, 0, 0}
207 };
208 
209 static const struct wskbd_mapdata j6x0tp_wskbd_keymapdata = {
210         j6x0tp_wskbd_keydesctab, KB_US
211 };
212 
213 
214 CFATTACH_DECL(j6x0tp, sizeof(struct j6x0tp_softc),
215     j6x0tp_match, j6x0tp_attach, NULL, NULL);
216 
217 
218 static int
219 j6x0tp_match(struct device *parent, struct cfdata *cf, void *aux)
220 {
221 
222 	/*
223 	 * XXX: platid_mask_MACH_HP_LX also matches 360LX.  It's not
224 	 * confirmed whether touch panel in 360LX is connected this
225 	 * way.  We may need to regroup platid masks.
226 	 */
227 	if (!platid_match(&platid, &platid_mask_MACH_HP_JORNADA_6XX)
228 	    && !platid_match(&platid, &platid_mask_MACH_HP_LX))
229 		return (0);
230 
231 	if (strcmp(cf->cf_name, "j6x0tp") != 0)
232 		return (0);
233 
234 	return (1);
235 }
236 
237 
238 static void
239 j6x0tp_attach(struct device *parent, struct device *self, void *aux)
240 {
241 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
242 	struct wsmousedev_attach_args wsma;
243 	struct wskbddev_attach_args wska;
244 
245 	printf("\n");
246 
247 	sc->sc_enabled = 0;
248 	sc->sc_hard_icon = 0;
249 
250 	/* touch-panel as a pointing device */
251 	wsma.accessops = &j6x0tp_accessops;
252 	wsma.accesscookie = sc;
253 
254 	sc->sc_wsmousedev = config_found_ia(self, "wsmousedev", &wsma,
255 					    wsmousedevprint);
256 	if (sc->sc_wsmousedev == NULL)
257 		return;
258 
259 	/* on-screen "hard icons" as a keyboard device */
260 	wska.console = 0;
261 	wska.keymap = &j6x0tp_wskbd_keymapdata;
262 	wska.accessops = &j6x0tp_wskbd_accessops;
263 	wska.accesscookie = sc;
264 
265 	sc->sc_wskbddev = config_found_ia(self, "wskbddev", &wska,
266 					  wskbddevprint);
267 
268 	/* init calibration, set default parameters */
269 	tpcalib_init(&sc->sc_tpcalib);
270 	tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
271 		      (void *)__UNCONST(&j6x0tp_default_calib), 0, 0);
272 
273 	/* used when in polling mode */
274 	callout_init(&sc->sc_touch_ch, 0);
275 
276 	/* establish interrupt handler, but disable until opened */
277 	intc_intr_establish(SH7709_INTEVT2_IRQ3, IST_EDGE, IPL_TTY,
278 			    j6x0tp_intr, sc);
279 	intc_intr_disable(SH7709_INTEVT2_IRQ3);
280 }
281 
282 
283 /*
284  * Enable touch panel:  we start in interrupt mode.
285  * Must be called as spltty().
286  */
287 static void
288 j6x0tp_enable(struct j6x0tp_softc *sc)
289 {
290 
291 	DPRINTFN(2, ("%s: enable\n", device_xname(&sc->sc_dev)));
292 	intc_intr_enable(SH7709_INTEVT2_IRQ3);
293 }
294 
295 
296 /*
297  * Disable touch panel: disable interrupt, cancel pending callout.
298  * Must be called as spltty().
299  */
300 static void
301 j6x0tp_disable(struct j6x0tp_softc *sc)
302 {
303 
304 	DPRINTFN(2, ("%s: disable\n", device_xname(&sc->sc_dev)));
305 	intc_intr_disable(SH7709_INTEVT2_IRQ3);
306 	callout_stop(&sc->sc_touch_ch);
307 }
308 
309 
310 static int
311 j6x0tp_enable_child(struct j6x0tp_softc *sc, int child, int on)
312 {
313 	int s = spltty();
314 
315 	if (on) {
316 		if (!sc->sc_enabled)
317 			j6x0tp_enable(sc);
318 		sc->sc_enabled |= child;
319 	} else {
320 		sc->sc_enabled &= ~child;
321 		if (!sc->sc_enabled)
322 			j6x0tp_disable(sc);
323 	}
324 
325 	splx(s);
326 	return (0);
327 }
328 
329 
330 static int
331 j6x0tp_wsmouse_enable(void *self)
332 {
333 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
334 
335 	DPRINTFN(1, ("%s: wsmouse enable\n", device_xname(&sc->sc_dev)));
336 	return (j6x0tp_enable_child(sc, J6X0TP_WSMOUSE_ENABLED, 1));
337 }
338 
339 
340 static void
341 j6x0tp_wsmouse_disable(void *self)
342 {
343 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
344 
345 	DPRINTFN(1, ("%s: wsmouse disable\n", device_xname(&sc->sc_dev)));
346 	j6x0tp_enable_child(sc, J6X0TP_WSMOUSE_ENABLED, 0);
347 }
348 
349 
350 static int
351 j6x0tp_wskbd_enable(void *self, int on)
352 {
353 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
354 
355 	DPRINTFN(1, ("%s: wskbd %sable\n", device_xname(&sc->sc_dev),
356 		     on ? "en" : "dis"));
357 	return (j6x0tp_enable_child(sc, J6X0TP_WSKBD_ENABLED, on));
358 }
359 
360 
361 static int
362 j6x0tp_intr(void *self)
363 {
364 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
365 
366 	uint8_t irr0;
367 	uint8_t phdr, touched;
368 	unsigned int steady, tremor_timeout;
369 
370 	irr0 = _reg_read_1(SH7709_IRR0);
371 	if ((irr0 & IRR0_IRQ3) == 0) {
372 #ifdef DIAGNOSTIC
373 		printf("%s: irr0 %02x?\n", device_xname(&sc->sc_dev), irr0);
374 #endif
375 		return (0);
376 	}
377 
378 	if (!sc->sc_enabled) {
379 		DPRINTFN(1, ("%s: intr: !sc_enabled\n",
380 			     device_xname(&sc->sc_dev)));
381 		intc_intr_disable(SH7709_INTEVT2_IRQ3);
382 		goto served;
383 	}
384 
385 
386 	/*
387 	 * Number of times the "touched" bit should be read
388 	 * consecutively.
389 	 */
390 #	define TREMOR_THRESHOLD 0x300
391 
392 	steady = 0;
393 	tremor_timeout = TREMOR_THRESHOLD * 16;	/* XXX: arbitrary */
394 	touched = PHDR_TP_PEN_DOWN;	/* we start with "touched" state */
395 
396 	do {
397 		phdr = _reg_read_1(SH7709_PHDR);
398 
399 		if ((phdr & PHDR_TP_PEN_DOWN) == touched)
400 			++steady;
401 		else {
402 			steady = 0;
403 			touched = phdr & PHDR_TP_PEN_DOWN;
404 		}
405 
406 		if (--tremor_timeout == 0) {
407 			DPRINTF(("%s: tremor timeout!\n",
408 				 device_xname(&sc->sc_dev)));
409 			goto served;
410 		}
411 	} while (steady < TREMOR_THRESHOLD);
412 
413 	if (touched) {
414 		intc_intr_disable(SH7709_INTEVT2_IRQ3);
415 
416 		/*
417 		 * ADC readings are not stable yet, so schedule
418 		 * callout instead of accessing ADC from the interrupt
419 		 * handler only to immediately delay().
420 		 */
421 		callout_reset(&sc->sc_touch_ch, hz/32,
422 			      j6x0tp_start_polling, sc);
423 	} else
424 		DPRINTFN(1, ("%s: tremor\n", device_xname(&sc->sc_dev)));
425   served:
426 	/* clear the interrupt (XXX: protect access?) */
427 	_reg_write_1(SH7709_IRR0, irr0 & ~IRR0_IRQ3);
428 
429 	return (1);
430 }
431 
432 
433 /*
434  * Called from the interrupt handler at spltty() upon first touch.
435  * Decide if we are going to report this touch as a mouse click/drag
436  * or as a key press.
437  */
438 static void
439 j6x0tp_start_polling(void *self)
440 {
441 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
442 	uint8_t phdr;
443 	int do_mouse, do_kbd;
444 	int rawx, rawy;
445 	int icon;
446 
447 	phdr = _reg_read_1(SH7709_PHDR);
448 	if ((phdr & PHDR_TP_PEN_DOWN) == 0) {
449 		DPRINTFN(2, ("%s: start: pen is not down\n",
450 			     device_xname(&sc->sc_dev)));
451 		j6x0tp_stop_polling(sc);
452 	}
453 
454 	j6x0tp_get_raw_xy(&rawx, &rawy);
455 	DPRINTFN(2, ("%s: start: %4d %4d -> ",
456 		     device_xname(&sc->sc_dev), rawx, rawy));
457 
458 	do_mouse = sc->sc_enabled & J6X0TP_WSMOUSE_ENABLED;
459 #ifdef J6X0TP_WSMOUSE_EXCLUSIVE
460 	if (do_mouse)
461 		do_kbd = 0;
462 	else
463 #endif
464 		do_kbd = sc->sc_enabled & J6X0TP_WSKBD_ENABLED;
465 
466 	icon = 0;
467 	if (do_kbd)
468 		icon = j6x0tp_get_hard_icon(rawx, rawy);
469 
470 	if (icon != 0) {
471 		DPRINTFN(2, ("icon %d\n", icon));
472 		sc->sc_hard_icon = icon;
473 		wskbd_input(sc->sc_wskbddev, WSCONS_EVENT_KEY_DOWN, icon);
474 		callout_reset(&sc->sc_touch_ch, hz/32,
475 			      j6x0tp_callout_wskbd, sc);
476 	} else if (do_mouse) {
477 		DPRINTFN(2, ("mouse\n"));
478 		j6x0tp_wsmouse_input(sc, rawx, rawy);
479 		callout_reset(&sc->sc_touch_ch, hz/32,
480 			      j6x0tp_callout_wsmouse, sc);
481 	} else {
482 		DPRINTFN(2, ("ignore\n"));
483 		j6x0tp_stop_polling(sc);
484 	}
485 }
486 
487 
488 /*
489  * Re-enable touch panel interrupt.
490  * Called as spltty() when polling code detects pen-up.
491  */
492 static void
493 j6x0tp_stop_polling(struct j6x0tp_softc *sc)
494 {
495 	uint8_t irr0;
496 
497 	DPRINTFN(2, ("%s: stop\n", device_xname(&sc->sc_dev)));
498 
499 	/* clear pending interrupt signal before re-enabling the interrupt */
500 	irr0 = _reg_read_1(SH7709_IRR0);
501 	if ((irr0 & IRR0_IRQ3) != 0)
502 		_reg_write_1(SH7709_IRR0, irr0 & ~IRR0_IRQ3);
503 
504 	intc_intr_enable(SH7709_INTEVT2_IRQ3);
505 }
506 
507 
508 /*
509  * We are reporting this touch as a keyboard event.
510  * Poll touch screen waiting for pen-up.
511  */
512 static void
513 j6x0tp_callout_wskbd(void *self)
514 {
515 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
516 	uint8_t phdr;
517 	int s;
518 
519 	s = spltty();
520 
521 	if (!sc->sc_enabled) {
522 		DPRINTFN(1, ("%s: wskbd callout: !sc_enabled\n",
523 			     device_xname(&sc->sc_dev)));
524 		splx(s);
525 		return;
526 	}
527 
528 	phdr = _reg_read_1(SH7709_PHDR);
529 	if ((phdr & PHDR_TP_PEN_DOWN) != 0) {
530 		/*
531 		 * Pen is still down, continue polling.  Wskbd's
532 		 * auto-repeat takes care of repeating the key.
533 		 */
534 		callout_schedule(&sc->sc_touch_ch, hz/32);
535 	} else {
536 		wskbd_input(sc->sc_wskbddev,
537 			    WSCONS_EVENT_KEY_UP, sc->sc_hard_icon);
538 		j6x0tp_stop_polling(sc);
539 	}
540 	splx(s);
541 }
542 
543 
544 /*
545  * We are reporting this touch as a mouse click/drag.
546  */
547 static void
548 j6x0tp_callout_wsmouse(void *self)
549 {
550 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
551 	uint8_t phdr;
552 	int rawx, rawy;
553 	int s;
554 
555 	s = spltty();
556 
557 	if (!sc->sc_enabled) {
558 		DPRINTFN(1, ("%s: wsmouse callout: !sc_enabled\n",
559 			     device_xname(&sc->sc_dev)));
560 		splx(s);
561 		return;
562 	}
563 
564 	phdr = _reg_read_1(SH7709_PHDR);
565 	if ((phdr & PHDR_TP_PEN_DOWN) != 0) {
566 		j6x0tp_get_raw_xy(&rawx, &rawy);
567 		j6x0tp_wsmouse_input(sc, rawx, rawy); /* mouse dragged */
568 		callout_schedule(&sc->sc_touch_ch, hz/32);
569 	} else {
570 		wsmouse_input(sc->sc_wsmousedev, 0, 0, 0, 0, 0, /* button up */
571 			      WSMOUSE_INPUT_DELTA);
572 		j6x0tp_stop_polling(sc);
573 	}
574 	splx(s);
575 }
576 
577 
578 /*
579  * Report mouse click/drag.
580  */
581 static void
582 j6x0tp_wsmouse_input(struct j6x0tp_softc *sc, int rawx, int rawy)
583 {
584 	int x, y;
585 
586 	tpcalib_trans(&sc->sc_tpcalib, rawx, rawy, &x, &y);
587 
588 	DPRINTFN(3, ("%s: %4d %4d -> %3d %3d\n",
589 		     device_xname(&sc->sc_dev), rawx, rawy, x, y));
590 
591 	wsmouse_input(sc->sc_wsmousedev,
592 			1,	/* button */
593 			x, y, 0, 0,
594 			WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
595 }
596 
597 
598 /*
599  * Read raw X/Y coordinates from the ADC.
600  * XXX: protect accesses to SCPDR?
601  */
602 static void
603 j6x0tp_get_raw_xy(int *rawxp, int *rawyp)
604 {
605 	uint8_t scpdr;
606 
607 	/* Y axis */
608 	scpdr = _reg_read_1(SH7709_SCPDR);
609 	scpdr |=  SCPDR_TP_SCAN_ENABLE;
610 	scpdr &= ~SCPDR_TP_SCAN_Y; /* pull low to scan */
611 	_reg_write_1(SH7709_SCPDR, scpdr);
612 	delay(10);
613 
614 	*rawyp = adc_sample_channel(ADC_CHANNEL_TP_Y);
615 
616 	/* X axis */
617 	scpdr = _reg_read_1(SH7709_SCPDR);
618 	scpdr |=  SCPDR_TP_SCAN_Y;
619 	scpdr &= ~SCPDR_TP_SCAN_X; /* pull low to scan */
620 	_reg_write_1(SH7709_SCPDR, scpdr);
621 	delay(10);
622 
623 	*rawxp = adc_sample_channel(ADC_CHANNEL_TP_X);
624 
625 	/* restore SCPDR */
626 	scpdr = _reg_read_1(SH7709_SCPDR);
627 	scpdr |=  SCPDR_TP_SCAN_X;
628 	scpdr &= ~SCPDR_TP_SCAN_ENABLE;
629 	_reg_write_1(SH7709_SCPDR, scpdr);
630 }
631 
632 
633 /*
634  * Check if the (rawx, rawy) is inside one of the 4 hard icons.
635  * Return the icon number 1..4, or 0 if not inside an icon.
636  */
637 static int
638 j6x0tp_get_hard_icon(int rawx, int rawy)
639 {
640 	if (rawx <= J6X0TP_FB_RIGHT)
641 		return (0);
642 
643 	if (rawy < J6X0TP_HARD_ICON_MAX_Y(1))
644 		return (1);
645 	else if (rawy < J6X0TP_HARD_ICON_MAX_Y(2))
646 		return (2);
647 	else if (rawy < J6X0TP_HARD_ICON_MAX_Y(3))
648 		return (3);
649 	else
650 		return (4);
651 }
652 
653 
654 static int
655 j6x0tp_wsmouse_ioctl(void *self, u_long cmd, void *data, int flag,
656 		     struct lwp *l)
657 {
658 	struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
659 
660 	return hpc_tpanel_ioctl(&sc->sc_tpcalib, cmd, data, flag, l);
661 }
662 
663 
664 static int
665 j6x0tp_wskbd_ioctl(void *self, u_long cmd, void *data, int flag,
666 		     struct lwp *l)
667 {
668 	/* struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self; */
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 *self, int leds)
687 {
688 
689 	/* nothing to do*/
690 	return;
691 }
692