j720tp.c revision 1.15 1 1.15 thorpej /* $NetBSD: j720tp.c,v 1.15 2023/12/20 14:50:02 thorpej Exp $ */
2 1.1 peter
3 1.1 peter /*-
4 1.1 peter * Copyright (c) 2006 The NetBSD Foundation, Inc.
5 1.1 peter * All rights reserved.
6 1.1 peter *
7 1.1 peter * This code is derived from software contributed to The NetBSD Foundation
8 1.1 peter * by IWAMOTO Toshihiro and Peter Postma.
9 1.1 peter *
10 1.1 peter * Redistribution and use in source and binary forms, with or without
11 1.1 peter * modification, are permitted provided that the following conditions
12 1.1 peter * are met:
13 1.1 peter * 1. Redistributions of source code must retain the above copyright
14 1.1 peter * notice, this list of conditions and the following disclaimer.
15 1.1 peter * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 peter * notice, this list of conditions and the following disclaimer in the
17 1.1 peter * documentation and/or other materials provided with the distribution.
18 1.1 peter *
19 1.1 peter * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 peter * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 peter * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 peter * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 peter * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 peter * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 peter * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 peter * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 peter * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 peter * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 peter * POSSIBILITY OF SUCH DAMAGE.
30 1.1 peter */
31 1.1 peter
32 1.1 peter /* Jornada 720 touch-panel driver. */
33 1.1 peter
34 1.1 peter #include <sys/cdefs.h>
35 1.15 thorpej __KERNEL_RCSID(0, "$NetBSD: j720tp.c,v 1.15 2023/12/20 14:50:02 thorpej Exp $");
36 1.3 peter
37 1.3 peter #ifdef _KERNEL_OPT
38 1.3 peter #include "opt_j720tp.h"
39 1.3 peter #include "opt_wsdisplay_compat.h"
40 1.3 peter #endif
41 1.1 peter
42 1.1 peter #include <sys/param.h>
43 1.1 peter #include <sys/systm.h>
44 1.1 peter #include <sys/device.h>
45 1.1 peter #include <sys/kernel.h>
46 1.1 peter #include <sys/ioctl.h>
47 1.1 peter #include <sys/callout.h>
48 1.3 peter #include <sys/sysctl.h>
49 1.1 peter
50 1.1 peter #include <machine/platid.h>
51 1.1 peter #include <machine/platid_mask.h>
52 1.1 peter
53 1.1 peter #include <arm/sa11x0/sa11x0_var.h>
54 1.1 peter #include <arm/sa11x0/sa11x0_gpioreg.h>
55 1.1 peter #include <arm/sa11x0/sa11x0_ppcreg.h>
56 1.1 peter #include <arm/sa11x0/sa11x0_sspreg.h>
57 1.1 peter
58 1.1 peter #include <dev/wscons/wsconsio.h>
59 1.1 peter #include <dev/wscons/wsmousevar.h>
60 1.3 peter #include <dev/wscons/wskbdvar.h>
61 1.3 peter #include <dev/wscons/wsksymvar.h>
62 1.3 peter #include <dev/wscons/wsksymdef.h>
63 1.1 peter #include <dev/hpc/hpctpanelvar.h>
64 1.1 peter
65 1.1 peter #include <hpcarm/dev/j720sspvar.h>
66 1.1 peter
67 1.3 peter #ifdef WSDISPLAY_COMPAT_RAWKBD
68 1.3 peter #include <dev/hpc/pckbd_encode.h>
69 1.3 peter #endif
70 1.3 peter
71 1.3 peter #define arraysize(ary) (sizeof(ary) / sizeof(ary[0]))
72 1.1 peter
73 1.1 peter #ifdef J720TP_DEBUG
74 1.3 peter int j720tp_debug = 0;
75 1.10 rjs #define DPRINTF(arg) if (j720tp_debug) aprint_normal arg
76 1.10 rjs #define DPRINTFN(n, arg) if (j720tp_debug >= (n)) aprint_normal arg
77 1.1 peter #else
78 1.3 peter #define DPRINTF(arg) /* nothing */
79 1.3 peter #define DPRINTFN(n, arg) /* nothing */
80 1.1 peter #endif
81 1.1 peter
82 1.1 peter struct j720tp_softc {
83 1.10 rjs device_t sc_dev;
84 1.1 peter
85 1.3 peter #define J720TP_WSMOUSE_ENABLED 0x01
86 1.3 peter #define J720TP_WSKBD_ENABLED 0x02
87 1.1 peter int sc_enabled;
88 1.3 peter int sc_hard_icon;
89 1.3 peter #ifdef WSDISPLAY_COMPAT_RAWKBD
90 1.3 peter int sc_rawkbd;
91 1.3 peter #endif
92 1.1 peter
93 1.1 peter struct callout sc_tpcallout;
94 1.1 peter struct j720ssp_softc *sc_ssp;
95 1.1 peter
96 1.10 rjs device_t sc_wsmousedev;
97 1.10 rjs device_t sc_wskbddev;
98 1.1 peter
99 1.1 peter struct tpcalib_softc sc_tpcalib;
100 1.1 peter };
101 1.1 peter
102 1.10 rjs static int j720tp_match(device_t, cfdata_t, void *);
103 1.10 rjs static void j720tp_attach(device_t, device_t, void *);
104 1.1 peter
105 1.1 peter static int j720tp_wsmouse_enable(void *);
106 1.5 christos static int j720tp_wsmouse_ioctl(void *, u_long, void *, int,
107 1.1 peter struct lwp *);
108 1.1 peter static void j720tp_wsmouse_disable(void *);
109 1.1 peter
110 1.3 peter static int j720tp_wskbd_enable(void *, int);
111 1.3 peter static void j720tp_wskbd_set_leds(void *, int);
112 1.5 christos static int j720tp_wskbd_ioctl(void *, u_long, void *, int, struct lwp *);
113 1.3 peter
114 1.1 peter static void j720tp_enable_intr(struct j720tp_softc *);
115 1.1 peter static void j720tp_disable_intr(struct j720tp_softc *);
116 1.1 peter static int j720tp_intr(void *);
117 1.1 peter static int j720tp_get_rawxy(struct j720tp_softc *, int *, int *);
118 1.3 peter static int j720tp_get_hard_icon(struct j720tp_softc *, int, int);
119 1.1 peter static void j720tp_wsmouse_input(struct j720tp_softc *, int, int);
120 1.1 peter static void j720tp_wsmouse_callout(void *);
121 1.3 peter static void j720tp_wskbd_input(struct j720tp_softc *, u_int);
122 1.3 peter static void j720tp_wskbd_callout(void *);
123 1.1 peter
124 1.1 peter const struct wsmouse_accessops j720tp_wsmouse_accessops = {
125 1.1 peter j720tp_wsmouse_enable,
126 1.1 peter j720tp_wsmouse_ioctl,
127 1.1 peter j720tp_wsmouse_disable
128 1.1 peter };
129 1.1 peter
130 1.1 peter static const struct wsmouse_calibcoords j720tp_default_calib = {
131 1.1 peter 0, 0, 639, 239,
132 1.1 peter 4,
133 1.1 peter {{ 988, 80, 0, 0 },
134 1.1 peter { 88, 84, 639, 0 },
135 1.1 peter { 988, 927, 0, 239 },
136 1.1 peter { 88, 940, 639, 239 }}
137 1.1 peter };
138 1.1 peter
139 1.3 peter const struct wskbd_accessops j720tp_wskbd_accessops = {
140 1.3 peter j720tp_wskbd_enable,
141 1.3 peter j720tp_wskbd_set_leds,
142 1.3 peter j720tp_wskbd_ioctl
143 1.3 peter };
144 1.3 peter
145 1.3 peter #ifndef J720TP_SETTINGS_ICON_KEYSYM
146 1.3 peter #define J720TP_SETTINGS_ICON_KEYSYM KS_Home
147 1.3 peter #endif
148 1.3 peter #ifndef J720TP_BACKUP_ICON_KEYSYM
149 1.3 peter #define J720TP_BACKUP_ICON_KEYSYM KS_Prior
150 1.3 peter #endif
151 1.3 peter #ifndef J720TP_DIALUP_ICON_KEYSYM
152 1.3 peter #define J720TP_DIALUP_ICON_KEYSYM KS_Next
153 1.3 peter #endif
154 1.3 peter #ifndef J720TP_MEDIA_ICON_KEYSYM
155 1.3 peter #define J720TP_MEDIA_ICON_KEYSYM KS_End
156 1.3 peter #endif
157 1.3 peter
158 1.3 peter /* Max Y value of the n'th hard icon. */
159 1.3 peter #define J720TP_HARD_ICON_MAX_Y(n) \
160 1.3 peter (((j720tp_hard_icon_bottom - j720tp_hard_icon_top) / 4) * (n)) + \
161 1.3 peter j720tp_hard_icon_top
162 1.3 peter
163 1.3 peter /* Default raw X/Y values of the hard icon area. */
164 1.3 peter static int j720tp_hard_icon_left = 70;
165 1.3 peter static int j720tp_hard_icon_right = 20;
166 1.3 peter static int j720tp_hard_icon_top = 70;
167 1.3 peter static int j720tp_hard_icon_bottom = 940;
168 1.3 peter
169 1.3 peter /* Maps the icon number to a raw keycode. */
170 1.3 peter static const int j720tp_wskbd_keys[] = {
171 1.3 peter /* Icon 1 */ 199,
172 1.3 peter /* Icon 2 */ 201,
173 1.3 peter /* Icon 3 */ 209,
174 1.3 peter /* Icon 4 */ 207
175 1.3 peter };
176 1.3 peter
177 1.3 peter static const keysym_t j720tp_wskbd_keydesc[] = {
178 1.3 peter KS_KEYCODE(199), J720TP_SETTINGS_ICON_KEYSYM,
179 1.3 peter KS_KEYCODE(201), J720TP_BACKUP_ICON_KEYSYM,
180 1.3 peter KS_KEYCODE(209), J720TP_DIALUP_ICON_KEYSYM,
181 1.3 peter KS_KEYCODE(207), J720TP_MEDIA_ICON_KEYSYM
182 1.3 peter };
183 1.3 peter
184 1.3 peter const struct wscons_keydesc j720tp_wskbd_keydesctab[] = {
185 1.3 peter { KB_US, 0,
186 1.3 peter sizeof(j720tp_wskbd_keydesc) / sizeof(keysym_t),
187 1.3 peter j720tp_wskbd_keydesc
188 1.3 peter },
189 1.3 peter { 0, 0, 0, 0 }
190 1.3 peter };
191 1.3 peter
192 1.3 peter const struct wskbd_mapdata j720tp_wskbd_keymapdata = {
193 1.3 peter j720tp_wskbd_keydesctab, KB_US
194 1.3 peter };
195 1.3 peter
196 1.10 rjs CFATTACH_DECL_NEW(j720tp, sizeof(struct j720tp_softc),
197 1.1 peter j720tp_match, j720tp_attach, NULL, NULL);
198 1.1 peter
199 1.1 peter
200 1.1 peter static int
201 1.10 rjs j720tp_match(device_t parent, cfdata_t cf, void *aux)
202 1.1 peter {
203 1.1 peter
204 1.1 peter if (!platid_match(&platid, &platid_mask_MACH_HP_JORNADA_7XX))
205 1.1 peter return 0;
206 1.1 peter if (strcmp(cf->cf_name, "j720tp") != 0)
207 1.1 peter return 0;
208 1.1 peter
209 1.1 peter return 1;
210 1.1 peter }
211 1.1 peter
212 1.1 peter static void
213 1.10 rjs j720tp_attach(device_t parent, device_t self, void *aux)
214 1.1 peter {
215 1.10 rjs struct j720tp_softc *sc = device_private(self);
216 1.1 peter struct wsmousedev_attach_args wsma;
217 1.3 peter struct wskbddev_attach_args wska;
218 1.1 peter
219 1.10 rjs aprint_normal("\n");
220 1.1 peter
221 1.10 rjs sc->sc_dev = self;
222 1.10 rjs sc->sc_ssp = device_private(parent);
223 1.1 peter sc->sc_enabled = 0;
224 1.3 peter sc->sc_hard_icon = 0;
225 1.14 rin #ifdef WSDISPLAY_COMPAT_RAWKBD
226 1.3 peter sc->sc_rawkbd = 0;
227 1.14 rin #endif
228 1.1 peter
229 1.1 peter /* Touch-panel as a pointing device. */
230 1.1 peter wsma.accessops = &j720tp_wsmouse_accessops;
231 1.1 peter wsma.accesscookie = sc;
232 1.1 peter
233 1.12 thorpej sc->sc_wsmousedev = config_found(self, &wsma, wsmousedevprint,
234 1.13 thorpej CFARGS(.iattr = "wsmousedev"));
235 1.3 peter if (sc->sc_wsmousedev == NULL)
236 1.3 peter return;
237 1.1 peter
238 1.1 peter /* Initialize calibration, set default parameters. */
239 1.1 peter tpcalib_init(&sc->sc_tpcalib);
240 1.1 peter tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
241 1.1 peter __UNCONST(&j720tp_default_calib), 0, 0);
242 1.1 peter
243 1.8 peter callout_init(&sc->sc_tpcallout, 0);
244 1.8 peter
245 1.1 peter j720tp_wsmouse_disable(sc);
246 1.1 peter
247 1.3 peter /* On-screen "hard icons" as a keyboard device. */
248 1.3 peter wska.console = 0;
249 1.3 peter wska.keymap = &j720tp_wskbd_keymapdata;
250 1.3 peter wska.accessops = &j720tp_wskbd_accessops;
251 1.3 peter wska.accesscookie = sc;
252 1.3 peter
253 1.12 thorpej sc->sc_wskbddev = config_found(self, &wska, wskbddevprint,
254 1.13 thorpej CFARGS(.iattr = "wskbddev"));
255 1.3 peter
256 1.1 peter /* Setup touch-panel interrupt. */
257 1.1 peter sa11x0_intr_establish(0, 9, 1, IPL_TTY, j720tp_intr, sc);
258 1.1 peter }
259 1.1 peter
260 1.1 peter static int
261 1.1 peter j720tp_wsmouse_enable(void *self)
262 1.1 peter {
263 1.1 peter struct j720tp_softc *sc = self;
264 1.1 peter int s;
265 1.1 peter
266 1.1 peter s = spltty();
267 1.1 peter
268 1.1 peter j720tp_enable_intr(sc);
269 1.1 peter
270 1.3 peter sc->sc_enabled |= J720TP_WSMOUSE_ENABLED;
271 1.1 peter
272 1.1 peter splx(s);
273 1.1 peter return 0;
274 1.1 peter }
275 1.1 peter
276 1.1 peter static int
277 1.5 christos j720tp_wsmouse_ioctl(void *self, u_long cmd, void *data, int flag,
278 1.1 peter struct lwp *l)
279 1.1 peter {
280 1.1 peter struct j720tp_softc *sc = self;
281 1.1 peter
282 1.1 peter return hpc_tpanel_ioctl(&sc->sc_tpcalib, cmd, data, flag, l);
283 1.1 peter }
284 1.1 peter
285 1.1 peter static void
286 1.1 peter j720tp_wsmouse_disable(void *self)
287 1.1 peter {
288 1.1 peter struct j720tp_softc *sc = self;
289 1.1 peter int s;
290 1.1 peter
291 1.1 peter s = spltty();
292 1.1 peter
293 1.1 peter j720tp_disable_intr(sc);
294 1.1 peter callout_stop(&sc->sc_tpcallout);
295 1.1 peter
296 1.3 peter sc->sc_enabled &= ~J720TP_WSMOUSE_ENABLED;
297 1.3 peter
298 1.3 peter splx(s);
299 1.3 peter }
300 1.3 peter
301 1.3 peter static int
302 1.3 peter j720tp_wskbd_enable(void *self, int on)
303 1.3 peter {
304 1.3 peter struct j720tp_softc *sc = self;
305 1.3 peter int s;
306 1.1 peter
307 1.3 peter s = spltty();
308 1.3 peter sc->sc_enabled |= J720TP_WSKBD_ENABLED;
309 1.1 peter splx(s);
310 1.3 peter
311 1.3 peter return 0;
312 1.3 peter }
313 1.3 peter
314 1.3 peter static void
315 1.3 peter j720tp_wskbd_set_leds(void *self, int leds)
316 1.3 peter {
317 1.3 peter /* nothing to do */
318 1.3 peter }
319 1.3 peter
320 1.3 peter static int
321 1.5 christos j720tp_wskbd_ioctl(void *self, u_long cmd, void *data, int flag,
322 1.3 peter struct lwp *l)
323 1.3 peter {
324 1.3 peter #ifdef WSDISPLAY_COMPAT_RAWKBD
325 1.3 peter struct j720tp_softc *sc = self;
326 1.3 peter #endif
327 1.3 peter
328 1.3 peter switch (cmd) {
329 1.3 peter case WSKBDIO_GTYPE:
330 1.3 peter *(int *)data = WSKBD_TYPE_HPC_BTN;
331 1.3 peter return 0;
332 1.3 peter case WSKBDIO_GETLEDS:
333 1.3 peter *(int *)data = 0;
334 1.3 peter return 0;
335 1.3 peter #ifdef WSDISPLAY_COMPAT_RAWKBD
336 1.3 peter case WSKBDIO_SETMODE:
337 1.3 peter sc->sc_rawkbd = (*(int *)data == WSKBD_RAW);
338 1.3 peter return 0;
339 1.3 peter #endif
340 1.3 peter }
341 1.3 peter
342 1.3 peter return EPASSTHROUGH;
343 1.1 peter }
344 1.1 peter
345 1.1 peter /*
346 1.1 peter * Enable touch-panel interrupt. Must be called at spltty().
347 1.1 peter */
348 1.1 peter static void
349 1.1 peter j720tp_enable_intr(struct j720tp_softc *sc)
350 1.1 peter {
351 1.1 peter struct j720ssp_softc *ssp = sc->sc_ssp;
352 1.1 peter uint32_t er;
353 1.1 peter
354 1.1 peter er = bus_space_read_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_FER);
355 1.1 peter er |= 1 << 9;
356 1.1 peter bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_FER, er);
357 1.1 peter }
358 1.1 peter
359 1.1 peter /*
360 1.1 peter * Disable touch-panel interrupt. Must be called at spltty().
361 1.1 peter */
362 1.1 peter static void
363 1.1 peter j720tp_disable_intr(struct j720tp_softc *sc)
364 1.1 peter {
365 1.1 peter struct j720ssp_softc *ssp = sc->sc_ssp;
366 1.1 peter uint32_t er;
367 1.1 peter
368 1.1 peter er = bus_space_read_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_FER);
369 1.1 peter er &= ~(1 << 9);
370 1.1 peter bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_FER, er);
371 1.1 peter }
372 1.1 peter
373 1.1 peter static int
374 1.1 peter j720tp_intr(void *arg)
375 1.1 peter {
376 1.1 peter struct j720tp_softc *sc = arg;
377 1.1 peter struct j720ssp_softc *ssp = sc->sc_ssp;
378 1.1 peter int rawx, rawy;
379 1.1 peter
380 1.1 peter bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_EDR, 1 << 9);
381 1.1 peter
382 1.3 peter if (!(sc->sc_enabled & J720TP_WSMOUSE_ENABLED)) {
383 1.1 peter DPRINTF(("j720tp_intr: !sc_enabled\n"));
384 1.1 peter return 0;
385 1.1 peter }
386 1.1 peter
387 1.1 peter j720tp_disable_intr(sc);
388 1.1 peter
389 1.3 peter if (j720tp_get_rawxy(sc, &rawx, &rawy)) {
390 1.3 peter sc->sc_hard_icon = j720tp_get_hard_icon(sc, rawx, rawy);
391 1.1 peter
392 1.3 peter if (sc->sc_hard_icon > 0) {
393 1.3 peter j720tp_wskbd_input(sc, WSCONS_EVENT_KEY_DOWN);
394 1.3 peter callout_reset(&sc->sc_tpcallout, hz / 32,
395 1.3 peter j720tp_wskbd_callout, sc);
396 1.3 peter } else {
397 1.3 peter j720tp_wsmouse_input(sc, rawx, rawy);
398 1.3 peter callout_reset(&sc->sc_tpcallout, hz / 32,
399 1.3 peter j720tp_wsmouse_callout, sc);
400 1.3 peter }
401 1.3 peter }
402 1.1 peter
403 1.1 peter return 1;
404 1.1 peter }
405 1.1 peter
406 1.1 peter static int
407 1.1 peter j720tp_get_rawxy(struct j720tp_softc *sc, int *rawx, int *rawy)
408 1.1 peter {
409 1.1 peter struct j720ssp_softc *ssp = sc->sc_ssp;
410 1.1 peter int buf[8], data, i;
411 1.1 peter
412 1.1 peter bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PCR, 0x2000000);
413 1.1 peter
414 1.1 peter /* Send read touch-panel command. */
415 1.2 peter if (j720ssp_readwrite(ssp, 1, 0xa0, &data, 100) < 0 || data != 0x11) {
416 1.1 peter DPRINTF(("j720tp_get_rawxy: no dummy received\n"));
417 1.1 peter goto out;
418 1.1 peter }
419 1.1 peter
420 1.1 peter for (i = 0; i < 8; i++) {
421 1.2 peter if (j720ssp_readwrite(ssp, 0, 0x11, &data, 100) < 0)
422 1.1 peter goto out;
423 1.1 peter buf[i] = data;
424 1.1 peter }
425 1.1 peter
426 1.1 peter bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PSR, 0x2000000);
427 1.1 peter
428 1.1 peter buf[6] <<= 8;
429 1.1 peter buf[7] <<= 8;
430 1.1 peter for (i = 0; i < 3; i++) {
431 1.1 peter buf[i] |= buf[6] & 0x300;
432 1.1 peter buf[6] >>= 2;
433 1.1 peter buf[i + 3] |= buf[7] & 0x300;
434 1.1 peter buf[7] >>= 2;
435 1.1 peter }
436 1.1 peter
437 1.3 peter DPRINTFN(2, ("j720tp_get_rawxy: %d:%d:%d:%d:%d:%d:%d:%d\n",
438 1.3 peter buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]));
439 1.1 peter
440 1.1 peter *rawx = buf[1];
441 1.1 peter *rawy = buf[4];
442 1.1 peter
443 1.1 peter return 1;
444 1.1 peter out:
445 1.1 peter bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PSR, 0x2000000);
446 1.1 peter
447 1.1 peter /* reset SSP */
448 1.1 peter bus_space_write_4(ssp->sc_iot, ssp->sc_ssph, SASSP_CR0, 0x307);
449 1.1 peter delay(100);
450 1.1 peter bus_space_write_4(ssp->sc_iot, ssp->sc_ssph, SASSP_CR0, 0x387);
451 1.1 peter
452 1.1 peter DPRINTF(("j720tp_get_rawxy: error %x\n", data));
453 1.1 peter return 0;
454 1.1 peter }
455 1.1 peter
456 1.3 peter static int
457 1.3 peter j720tp_get_hard_icon(struct j720tp_softc *sc, int rawx, int rawy)
458 1.3 peter {
459 1.3 peter int icon = 0;
460 1.3 peter
461 1.3 peter if (!(sc->sc_enabled & J720TP_WSKBD_ENABLED))
462 1.3 peter return 0;
463 1.3 peter /* Check if the touch was in the hard icons area. */
464 1.3 peter if (rawx > j720tp_hard_icon_left)
465 1.3 peter return 0;
466 1.3 peter
467 1.3 peter if (rawy < J720TP_HARD_ICON_MAX_Y(1))
468 1.3 peter icon = 1;
469 1.3 peter else if (rawy < J720TP_HARD_ICON_MAX_Y(2))
470 1.3 peter icon = 2;
471 1.3 peter else if (rawy < J720TP_HARD_ICON_MAX_Y(3))
472 1.3 peter icon = 3;
473 1.3 peter else if (rawy < J720TP_HARD_ICON_MAX_Y(4))
474 1.3 peter icon = 4;
475 1.3 peter
476 1.3 peter return icon;
477 1.3 peter }
478 1.3 peter
479 1.1 peter static void
480 1.1 peter j720tp_wsmouse_input(struct j720tp_softc *sc, int rawx, int rawy)
481 1.1 peter {
482 1.1 peter int x, y;
483 1.1 peter
484 1.1 peter tpcalib_trans(&sc->sc_tpcalib, rawx, rawy, &x, &y);
485 1.4 plunky wsmouse_input(sc->sc_wsmousedev, 1, x, y, 0, 0,
486 1.1 peter WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
487 1.1 peter }
488 1.1 peter
489 1.1 peter static void
490 1.1 peter j720tp_wsmouse_callout(void *arg)
491 1.1 peter {
492 1.1 peter struct j720tp_softc *sc = arg;
493 1.1 peter struct j720ssp_softc *ssp = sc->sc_ssp;
494 1.1 peter int rawx, rawy, s;
495 1.1 peter
496 1.1 peter s = spltty();
497 1.1 peter
498 1.3 peter if (!(sc->sc_enabled & J720TP_WSMOUSE_ENABLED)) {
499 1.1 peter DPRINTF(("j720tp_wsmouse_callout: !sc_enabled\n"));
500 1.1 peter splx(s);
501 1.1 peter return;
502 1.1 peter }
503 1.1 peter
504 1.1 peter if (bus_space_read_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PLR) & (1<<9)) {
505 1.4 plunky wsmouse_input(sc->sc_wsmousedev, 0, 0, 0, 0, 0, 0);
506 1.1 peter j720tp_enable_intr(sc);
507 1.1 peter } else {
508 1.1 peter if (j720tp_get_rawxy(sc, &rawx, &rawy))
509 1.1 peter j720tp_wsmouse_input(sc, rawx, rawy);
510 1.3 peter callout_schedule(&sc->sc_tpcallout, hz / 32);
511 1.3 peter }
512 1.3 peter
513 1.3 peter splx(s);
514 1.3 peter }
515 1.3 peter
516 1.3 peter static void
517 1.3 peter j720tp_wskbd_input(struct j720tp_softc *sc, u_int evtype)
518 1.3 peter {
519 1.3 peter int key = j720tp_wskbd_keys[sc->sc_hard_icon - 1];
520 1.3 peter
521 1.3 peter #ifdef WSDISPLAY_COMPAT_RAWKBD
522 1.3 peter if (sc->sc_rawkbd) {
523 1.3 peter int n;
524 1.3 peter u_char data[16];
525 1.3 peter
526 1.3 peter n = pckbd_encode(evtype, key, data);
527 1.3 peter wskbd_rawinput(sc->sc_wskbddev, data, n);
528 1.3 peter } else
529 1.3 peter #endif
530 1.3 peter wskbd_input(sc->sc_wskbddev, evtype, key);
531 1.3 peter }
532 1.3 peter
533 1.3 peter static void
534 1.3 peter j720tp_wskbd_callout(void *arg)
535 1.3 peter {
536 1.3 peter struct j720tp_softc *sc = arg;
537 1.3 peter struct j720ssp_softc *ssp = sc->sc_ssp;
538 1.3 peter int s;
539 1.3 peter
540 1.3 peter s = spltty();
541 1.3 peter
542 1.3 peter if (!sc->sc_enabled) {
543 1.3 peter DPRINTF(("j720tp_wskbd_callout: !sc_enabled\n"));
544 1.3 peter splx(s);
545 1.3 peter return;
546 1.3 peter }
547 1.1 peter
548 1.3 peter if (bus_space_read_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PLR) & (1<<9)) {
549 1.3 peter j720tp_wskbd_input(sc, WSCONS_EVENT_KEY_UP);
550 1.3 peter j720tp_enable_intr(sc);
551 1.3 peter } else {
552 1.1 peter callout_schedule(&sc->sc_tpcallout, hz / 32);
553 1.1 peter }
554 1.1 peter
555 1.1 peter splx(s);
556 1.1 peter }
557 1.3 peter
558 1.3 peter SYSCTL_SETUP(sysctl_j720tp, "sysctl j720tp subtree setup")
559 1.3 peter {
560 1.3 peter const struct sysctlnode *rnode;
561 1.3 peter int rc;
562 1.3 peter
563 1.3 peter if ((rc = sysctl_createv(clog, 0, NULL, &rnode,
564 1.3 peter CTLFLAG_PERMANENT, CTLTYPE_NODE, "j720tp",
565 1.3 peter SYSCTL_DESCR("Jornada 720 touch panel controls"),
566 1.11 pooka NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL)) != 0)
567 1.3 peter goto err;
568 1.3 peter
569 1.3 peter #ifdef J720TP_DEBUG
570 1.3 peter if ((rc = sysctl_createv(clog, 0, &rnode, NULL,
571 1.3 peter CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, "debug",
572 1.3 peter SYSCTL_DESCR("Verbosity of debugging messages"),
573 1.3 peter NULL, 0, &j720tp_debug, 0, CTL_CREATE, CTL_EOL)) != 0)
574 1.3 peter goto err;
575 1.3 peter #endif /* J720TP_DEBUG */
576 1.3 peter
577 1.3 peter if ((rc = sysctl_createv(clog, 0, &rnode, &rnode,
578 1.3 peter CTLFLAG_PERMANENT, CTLTYPE_NODE, "hard_icons",
579 1.3 peter SYSCTL_DESCR("Touch panel hard icons controls"),
580 1.3 peter NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
581 1.3 peter goto err;
582 1.3 peter
583 1.3 peter if ((rc = sysctl_createv(clog, 0, &rnode, NULL,
584 1.3 peter CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, "left",
585 1.3 peter SYSCTL_DESCR("Raw left X value of the hard icon area"),
586 1.3 peter NULL, 0, &j720tp_hard_icon_left, 0, CTL_CREATE, CTL_EOL)) != 0)
587 1.3 peter goto err;
588 1.3 peter
589 1.3 peter if ((rc = sysctl_createv(clog, 0, &rnode, NULL,
590 1.3 peter CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, "right",
591 1.3 peter SYSCTL_DESCR("Raw right X value of the hard icon area"),
592 1.3 peter NULL, 0, &j720tp_hard_icon_right, 0, CTL_CREATE, CTL_EOL)) != 0)
593 1.3 peter goto err;
594 1.3 peter
595 1.3 peter if ((rc = sysctl_createv(clog, 0, &rnode, NULL,
596 1.3 peter CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, "top",
597 1.3 peter SYSCTL_DESCR("Raw top Y value of the hard icon area"),
598 1.3 peter NULL, 0, &j720tp_hard_icon_top, 0, CTL_CREATE, CTL_EOL)) != 0)
599 1.3 peter goto err;
600 1.3 peter
601 1.3 peter if ((rc = sysctl_createv(clog, 0, &rnode, NULL,
602 1.3 peter CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, "bottom",
603 1.3 peter SYSCTL_DESCR("Raw bottom Y value of the hard icon area"),
604 1.3 peter NULL, 0, &j720tp_hard_icon_bottom, 0, CTL_CREATE, CTL_EOL)) != 0)
605 1.3 peter goto err;
606 1.3 peter
607 1.3 peter return;
608 1.3 peter err:
609 1.10 rjs aprint_normal("%s: sysctl_createv failed (rc = %d)\n", __func__, rc);
610 1.3 peter }
611