j6x0tp.c revision 1.15 1 /* $NetBSD: j6x0tp.c,v 1.15 2006/11/12 19:00:42 plunky 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.15 2006/11/12 19:00:42 plunky 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 #define J6X0TP_DEBUG
63 #if 0 /* XXX: disabled in favor of local version that uses printf_nolog */
64 #define DPRINTF_ENABLE
65 #define DPRINTF_DEBUG j6x0tp_debug
66 #define DPRINTF_LEVEL 0
67 #include <machine/debug.h>
68 #else
69 #ifdef J6X0TP_DEBUG
70 volatile int j6x0tp_debug = 0;
71 #define DPRINTF_PRINTF printf_nolog
72 #define DPRINTF(arg) if (j6x0tp_debug) DPRINTF_PRINTF arg
73 #define DPRINTFN(n, arg) if (j6x0tp_debug > (n)) DPRINTF_PRINTF arg
74 #else
75 #define DPRINTF(arg) ((void)0)
76 #define DPRINTFN(n, arg) ((void)0)
77 #endif
78 #endif
79
80
81 /*
82 * PFC bits pertinent to Jornada 6x0 touchpanel
83 */
84 #define PHDR_TP_PEN_DOWN 0x08
85
86 #define SCPDR_TP_SCAN_ENABLE 0x20
87 #define SCPDR_TP_SCAN_Y 0x02
88 #define SCPDR_TP_SCAN_X 0x01
89
90 /*
91 * A/D converter channels to get x/y from
92 */
93 #define ADC_CHANNEL_TP_Y 1
94 #define ADC_CHANNEL_TP_X 2
95
96 /*
97 * Default (read: my device :) raw X/Y values for framebuffer edges.
98 * XXX: defopt these?
99 */
100 #define J6X0TP_FB_LEFT 38
101 #define J6X0TP_FB_RIGHT 950
102 #define J6X0TP_FB_TOP 80
103 #define J6X0TP_FB_BOTTOM 900
104
105 /*
106 * Bottom of the n'th hard icon (n = 1..4)
107 */
108 #define J6X0TP_HARD_ICON_MAX_Y(n) \
109 (J6X0TP_FB_TOP + ((J6X0TP_FB_BOTTOM - J6X0TP_FB_TOP) / 4) * (n))
110
111
112 struct j6x0tp_softc {
113 struct device sc_dev;
114
115 #define J6X0TP_WSMOUSE_ENABLED 0x01
116 #define J6X0TP_WSKBD_ENABLED 0x02
117 int sc_enabled;
118
119 int sc_hard_icon;
120
121 struct callout sc_touch_ch;
122
123 struct device *sc_wsmousedev;
124 struct device *sc_wskbddev;
125
126 struct tpcalib_softc sc_tpcalib; /* calibration info for wsmouse */
127 };
128
129
130 /* config machinery */
131 static int j6x0tp_match(struct device *, struct cfdata *, void *);
132 static void j6x0tp_attach(struct device *, struct device *, void *);
133
134 /* wsmouse accessops */
135 static int j6x0tp_wsmouse_enable(void *);
136 static int j6x0tp_wsmouse_ioctl(void *, u_long, caddr_t, int,
137 struct lwp *);
138 static void j6x0tp_wsmouse_disable(void *);
139
140 /* wskbd accessops */
141 static int j6x0tp_wskbd_enable(void *, int);
142 static void j6x0tp_wskbd_set_leds(void *, int);
143 static int j6x0tp_wskbd_ioctl(void *, u_long, caddr_t, int,
144 struct lwp *);
145
146 /* internal driver routines */
147 static void j6x0tp_enable(struct j6x0tp_softc *);
148 static void j6x0tp_disable(struct j6x0tp_softc *);
149 static int j6x0tp_set_enable(struct j6x0tp_softc *, int, int);
150 static int j6x0tp_intr(void *);
151 static void j6x0tp_start_polling(void *);
152 static void j6x0tp_stop_polling(struct j6x0tp_softc *);
153 static void j6x0tp_callout_wsmouse(void *);
154 static void j6x0tp_callout_wskbd(void *);
155 static void j6x0tp_wsmouse_input(struct j6x0tp_softc *, int, int);
156 static void j6x0tp_get_raw_xy(int *, int *);
157 static int j6x0tp_get_hard_icon(int, int);
158
159
160 static const struct wsmouse_accessops j6x0tp_accessops = {
161 j6x0tp_wsmouse_enable,
162 j6x0tp_wsmouse_ioctl,
163 j6x0tp_wsmouse_disable
164 };
165
166 static const struct wsmouse_calibcoords j6x0tp_default_calib = {
167 0, 0, 639, 239,
168 4,
169 {{ J6X0TP_FB_LEFT, J6X0TP_FB_TOP, 0, 0 },
170 { J6X0TP_FB_RIGHT, J6X0TP_FB_TOP, 639, 0 },
171 { J6X0TP_FB_LEFT, J6X0TP_FB_BOTTOM, 0, 239 },
172 { J6X0TP_FB_RIGHT, J6X0TP_FB_BOTTOM, 639, 239 }}
173 };
174
175 static const struct wskbd_accessops j6x0tp_wskbd_accessops = {
176 j6x0tp_wskbd_enable,
177 j6x0tp_wskbd_set_leds,
178 j6x0tp_wskbd_ioctl
179 };
180
181
182 #ifndef J6X0TP_SETTINGS_ICON_KEYSYM
183 #define J6X0TP_SETTINGS_ICON_KEYSYM KS_Home
184 #endif
185 #ifndef J6X0TP_PGUP_ICON_KEYSYM
186 #define J6X0TP_PGUP_ICON_KEYSYM KS_Prior
187 #endif
188 #ifndef J6X0TP_PGDN_ICON_KEYSYM
189 #define J6X0TP_PGDN_ICON_KEYSYM KS_Next
190 #endif
191 #ifndef J6X0TP_SWITCH_ICON_KEYSYM
192 #define J6X0TP_SWITCH_ICON_KEYSYM KS_End
193 #endif
194
195 static const keysym_t j6x0tp_wskbd_keydesc[] = {
196 KS_KEYCODE(1), J6X0TP_SETTINGS_ICON_KEYSYM,
197 KS_KEYCODE(2), J6X0TP_PGUP_ICON_KEYSYM,
198 KS_KEYCODE(3), J6X0TP_PGDN_ICON_KEYSYM,
199 KS_KEYCODE(4), J6X0TP_SWITCH_ICON_KEYSYM
200 };
201
202 static const struct wscons_keydesc j6x0tp_wskbd_keydesctab[] = {
203 { KB_US, 0,
204 sizeof(j6x0tp_wskbd_keydesc)/sizeof(keysym_t),
205 j6x0tp_wskbd_keydesc
206 },
207 {0, 0, 0, 0}
208 };
209
210 static const struct wskbd_mapdata j6x0tp_wskbd_keymapdata = {
211 j6x0tp_wskbd_keydesctab, KB_US
212 };
213
214
215 CFATTACH_DECL(j6x0tp, sizeof(struct j6x0tp_softc),
216 j6x0tp_match, j6x0tp_attach, NULL, NULL);
217
218
219 static int
220 j6x0tp_match(struct device *parent, struct cfdata *cf, void *aux)
221 {
222
223 /*
224 * XXX: platid_mask_MACH_HP_LX also matches 360LX. It's not
225 * confirmed whether touch panel in 360LX is connected this
226 * way. We may need to regroup platid masks.
227 */
228 if (!platid_match(&platid, &platid_mask_MACH_HP_JORNADA_6XX)
229 && !platid_match(&platid, &platid_mask_MACH_HP_LX))
230 return (0);
231
232 if (strcmp(cf->cf_name, "j6x0tp") != 0)
233 return (0);
234
235 return (1);
236 }
237
238
239 /*
240 * Attach the touch panel driver and its ws* children.
241 *
242 * Note that we have to use submatch to distinguish between children
243 * because ws{kbd,mouse}_match match unconditionally.
244 */
245 static void
246 j6x0tp_attach(struct device *parent, struct device *self, void *aux)
247 {
248 struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
249 struct wsmousedev_attach_args wsma;
250 struct wskbddev_attach_args wska;
251
252 printf("\n");
253
254 sc->sc_enabled = 0;
255 sc->sc_hard_icon = 0;
256
257 /* touch-panel as a pointing device */
258 wsma.accessops = &j6x0tp_accessops;
259 wsma.accesscookie = sc;
260
261 sc->sc_wsmousedev = config_found_ia(self, "wsmousedev", &wsma,
262 wsmousedevprint);
263 if (sc->sc_wsmousedev == NULL)
264 return;
265
266 /* on-screen "hard icons" as a keyboard device */
267 wska.console = 0;
268 wska.keymap = &j6x0tp_wskbd_keymapdata;
269 wska.accessops = &j6x0tp_wskbd_accessops;
270 wska.accesscookie = sc;
271
272 sc->sc_wskbddev = config_found_ia(self, "wskbddev", &wska,
273 wskbddevprint);
274
275 /* init calibration, set default parameters */
276 tpcalib_init(&sc->sc_tpcalib);
277 tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
278 (caddr_t)__UNCONST(&j6x0tp_default_calib), 0, 0);
279
280 /* used when in polling mode */
281 callout_init(&sc->sc_touch_ch);
282
283 /* establish interrupt handler, but disable until opened */
284 intc_intr_establish(SH7709_INTEVT2_IRQ3, IST_EDGE, IPL_TTY,
285 j6x0tp_intr, sc);
286 intc_intr_disable(SH7709_INTEVT2_IRQ3);
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", sc->sc_dev.dv_xname));
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", sc->sc_dev.dv_xname));
312 intc_intr_disable(SH7709_INTEVT2_IRQ3);
313 callout_stop(&sc->sc_touch_ch);
314 }
315
316
317 static int
318 j6x0tp_set_enable(struct j6x0tp_softc *sc, int on, int child)
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 *self)
339 {
340 struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
341
342 DPRINTFN(1, ("%s: wsmouse enable\n", sc->sc_dev.dv_xname));
343 return (j6x0tp_set_enable(sc, 1, J6X0TP_WSMOUSE_ENABLED));
344 }
345
346
347 static void
348 j6x0tp_wsmouse_disable(void *self)
349 {
350 struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
351
352 DPRINTFN(1, ("%s: wsmouse disable\n", sc->sc_dev.dv_xname));
353 j6x0tp_set_enable(sc, 0, J6X0TP_WSMOUSE_ENABLED);
354 }
355
356
357 static int
358 j6x0tp_wskbd_enable(void *self, int on)
359 {
360 struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
361
362 DPRINTFN(1, ("%s: wskbd %sable\n", sc->sc_dev.dv_xname,
363 on ? "en" : "dis"));
364 return (j6x0tp_set_enable(sc, on, J6X0TP_WSKBD_ENABLED));
365 }
366
367
368 static int
369 j6x0tp_intr(void *self)
370 {
371 struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
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", sc->sc_dev.dv_xname, irr0);
381 #endif
382 return (0);
383 }
384
385 if (!sc->sc_enabled) {
386 DPRINTFN(1, ("%s: intr: !sc_enabled\n", sc->sc_dev.dv_xname));
387 intc_intr_disable(SH7709_INTEVT2_IRQ3);
388 goto served;
389 }
390
391
392 /*
393 * Number of times the "touched" bit should be read
394 * consecutively.
395 */
396 # define TREMOR_THRESHOLD 0x300
397
398 steady = 0;
399 tremor_timeout = TREMOR_THRESHOLD * 16; /* XXX: arbitrary */
400 touched = PHDR_TP_PEN_DOWN; /* we start with "touched" state */
401
402 do {
403 phdr = _reg_read_1(SH7709_PHDR);
404
405 if ((phdr & PHDR_TP_PEN_DOWN) == touched)
406 ++steady;
407 else {
408 steady = 0;
409 touched = phdr & PHDR_TP_PEN_DOWN;
410 }
411
412 if (--tremor_timeout == 0) {
413 DPRINTF(("%s: tremor timeout!\n",
414 sc->sc_dev.dv_xname));
415 goto served;
416 }
417 } while (steady < TREMOR_THRESHOLD);
418
419 if (touched) {
420 intc_intr_disable(SH7709_INTEVT2_IRQ3);
421
422 /*
423 * ADC readings are not stable yet, so schedule
424 * callout instead of accessing ADC from the interrupt
425 * handler only to immediately delay().
426 */
427 callout_reset(&sc->sc_touch_ch, hz/32,
428 j6x0tp_start_polling, sc);
429 } else
430 DPRINTFN(1, ("%s: tremor\n", sc->sc_dev.dv_xname));
431 served:
432 /* clear the interrupt (XXX: protect access?) */
433 _reg_write_1(SH7709_IRR0, irr0 & ~IRR0_IRQ3);
434
435 return (1);
436 }
437
438
439 /*
440 * Called from the interrupt handler at spltty() upon first touch.
441 * Decide if we are going to report this touch as a mouse click/drag
442 * or as a key press.
443 */
444 static void
445 j6x0tp_start_polling(void *self)
446 {
447 struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
448 uint8_t phdr;
449 int do_mouse, do_kbd;
450 int rawx, rawy;
451 int icon;
452
453 phdr = _reg_read_1(SH7709_PHDR);
454 if ((phdr & PHDR_TP_PEN_DOWN) == 0) {
455 DPRINTFN(2, ("%s: start: pen is not down\n",
456 sc->sc_dev.dv_xname));
457 j6x0tp_stop_polling(sc);
458 }
459
460 j6x0tp_get_raw_xy(&rawx, &rawy);
461 DPRINTFN(2, ("%s: start: %4d %4d -> ",
462 sc->sc_dev.dv_xname, rawx, rawy));
463
464 do_mouse = sc->sc_enabled & J6X0TP_WSMOUSE_ENABLED;
465 #ifdef J6X0TP_WSMOUSE_EXCLUSIVE
466 if (do_mouse)
467 do_kbd = 0;
468 else
469 #endif
470 do_kbd = sc->sc_enabled & J6X0TP_WSKBD_ENABLED;
471
472 icon = 0;
473 if (do_kbd)
474 icon = j6x0tp_get_hard_icon(rawx, rawy);
475
476 if (icon != 0) {
477 DPRINTFN(2, ("icon %d\n", icon));
478 sc->sc_hard_icon = icon;
479 wskbd_input(sc->sc_wskbddev, WSCONS_EVENT_KEY_DOWN, icon);
480 callout_reset(&sc->sc_touch_ch, hz/32,
481 j6x0tp_callout_wskbd, sc);
482 } else if (do_mouse) {
483 DPRINTFN(2, ("mouse\n"));
484 j6x0tp_wsmouse_input(sc, rawx, rawy);
485 callout_reset(&sc->sc_touch_ch, hz/32,
486 j6x0tp_callout_wsmouse, sc);
487 } else {
488 DPRINTFN(2, ("ignore\n"));
489 j6x0tp_stop_polling(sc);
490 }
491 }
492
493
494 /*
495 * Re-enable touch panel interrupt.
496 * Called as spltty() when polling code detects pen-up.
497 */
498 static void
499 j6x0tp_stop_polling(struct j6x0tp_softc *sc)
500 {
501 uint8_t irr0;
502
503 DPRINTFN(2, ("%s: stop\n", sc->sc_dev.dv_xname));
504
505 /* clear pending interrupt signal before re-enabling the interrupt */
506 irr0 = _reg_read_1(SH7709_IRR0);
507 if ((irr0 & IRR0_IRQ3) != 0)
508 _reg_write_1(SH7709_IRR0, irr0 & ~IRR0_IRQ3);
509
510 intc_intr_enable(SH7709_INTEVT2_IRQ3);
511 }
512
513
514 /*
515 * We are reporting this touch as a keyboard event.
516 * Poll touch screen waiting for pen-up.
517 */
518 static void
519 j6x0tp_callout_wskbd(void *self)
520 {
521 struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
522 uint8_t phdr;
523 int s;
524
525 s = spltty();
526
527 if (!sc->sc_enabled) {
528 DPRINTFN(1, ("%s: wskbd callout: !sc_enabled\n",
529 sc->sc_dev.dv_xname));
530 splx(s);
531 return;
532 }
533
534 phdr = _reg_read_1(SH7709_PHDR);
535 if ((phdr & PHDR_TP_PEN_DOWN) != 0) {
536 /*
537 * Pen is still down, continue polling. Wskbd's
538 * auto-repeat takes care of repeating the key.
539 */
540 callout_schedule(&sc->sc_touch_ch, hz/32);
541 } else {
542 wskbd_input(sc->sc_wskbddev,
543 WSCONS_EVENT_KEY_UP, sc->sc_hard_icon);
544 j6x0tp_stop_polling(sc);
545 }
546 splx(s);
547 }
548
549
550 /*
551 * We are reporting this touch as a mouse click/drag.
552 */
553 static void
554 j6x0tp_callout_wsmouse(void *self)
555 {
556 struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
557 uint8_t phdr;
558 int rawx, rawy;
559 int s;
560
561 s = spltty();
562
563 if (!sc->sc_enabled) {
564 DPRINTFN(1, ("%s: wsmouse callout: !sc_enabled\n",
565 sc->sc_dev.dv_xname));
566 splx(s);
567 return;
568 }
569
570 phdr = _reg_read_1(SH7709_PHDR);
571 if ((phdr & PHDR_TP_PEN_DOWN) != 0) {
572 j6x0tp_get_raw_xy(&rawx, &rawy);
573 j6x0tp_wsmouse_input(sc, rawx, rawy); /* mouse dragged */
574 callout_schedule(&sc->sc_touch_ch, hz/32);
575 } else {
576 wsmouse_input(sc->sc_wsmousedev, 0, 0, 0, 0, 0, /* button up */
577 WSMOUSE_INPUT_DELTA);
578 j6x0tp_stop_polling(sc);
579 }
580 splx(s);
581 }
582
583
584 /*
585 * Report mouse click/drag.
586 */
587 static void
588 j6x0tp_wsmouse_input(struct j6x0tp_softc *sc, int rawx, int rawy)
589 {
590 int x, y;
591
592 tpcalib_trans(&sc->sc_tpcalib, rawx, rawy, &x, &y);
593
594 DPRINTFN(3, ("%s: %4d %4d -> %3d %3d\n",
595 sc->sc_dev.dv_xname, rawx, rawy, x, y));
596
597 wsmouse_input(sc->sc_wsmousedev,
598 1, /* button */
599 x, y, 0, 0,
600 WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
601 }
602
603
604 /*
605 * Read raw X/Y coordinates from the ADC.
606 * XXX: protect accesses to SCPDR?
607 */
608 static void
609 j6x0tp_get_raw_xy(int *rawxp, int *rawyp)
610 {
611 uint8_t scpdr;
612
613 /* Y axis */
614 scpdr = _reg_read_1(SH7709_SCPDR);
615 scpdr |= SCPDR_TP_SCAN_ENABLE;
616 scpdr &= ~SCPDR_TP_SCAN_Y; /* pull low to scan */
617 _reg_write_1(SH7709_SCPDR, scpdr);
618 delay(10);
619
620 *rawyp = adc_sample_channel(ADC_CHANNEL_TP_Y);
621
622 /* X axis */
623 scpdr = _reg_read_1(SH7709_SCPDR);
624 scpdr |= SCPDR_TP_SCAN_Y;
625 scpdr &= ~SCPDR_TP_SCAN_X; /* pull low to scan */
626 _reg_write_1(SH7709_SCPDR, scpdr);
627 delay(10);
628
629 *rawxp = adc_sample_channel(ADC_CHANNEL_TP_X);
630
631 /* restore SCPDR */
632 scpdr = _reg_read_1(SH7709_SCPDR);
633 scpdr |= SCPDR_TP_SCAN_X;
634 scpdr &= ~SCPDR_TP_SCAN_ENABLE;
635 _reg_write_1(SH7709_SCPDR, scpdr);
636 }
637
638
639 /*
640 * Check if the (rawx, rawy) is inside one of the 4 hard icons.
641 * Return the icon number 1..4, or 0 if not inside an icon.
642 */
643 static int
644 j6x0tp_get_hard_icon(int rawx, int rawy)
645 {
646 if (rawx <= J6X0TP_FB_RIGHT)
647 return (0);
648
649 if (rawy < J6X0TP_HARD_ICON_MAX_Y(1))
650 return (1);
651 else if (rawy < J6X0TP_HARD_ICON_MAX_Y(2))
652 return (2);
653 else if (rawy < J6X0TP_HARD_ICON_MAX_Y(3))
654 return (3);
655 else
656 return (4);
657 }
658
659
660 static int
661 j6x0tp_wsmouse_ioctl(void *self, u_long cmd, caddr_t data, int flag,
662 struct lwp *l)
663 {
664 struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
665
666 return hpc_tpanel_ioctl(&sc->sc_tpcalib, cmd, data, flag, l);
667 }
668
669
670 static int
671 j6x0tp_wskbd_ioctl(void *self, u_long cmd, caddr_t data, int flag,
672 struct lwp *l)
673 {
674 /* struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self; */
675
676 switch (cmd) {
677 case WSKBDIO_GTYPE:
678 *(int *)data = WSKBD_TYPE_HPC_BTN; /* may be use new type? */
679 return (0);
680
681 case WSKBDIO_GETLEDS:
682 *(int *)data = 0;
683 return (0);
684
685 default:
686 return (EPASSTHROUGH);
687 }
688 }
689
690
691 static void
692 j6x0tp_wskbd_set_leds(void *self, int leds)
693 {
694
695 /* nothing to do*/
696 return;
697 }
698