j6x0tp.c revision 1.5.2.4 1 1.5.2.4 skrll /* $NetBSD: j6x0tp.c,v 1.5.2.4 2004/09/21 13:16:24 skrll Exp $ */
2 1.5.2.2 skrll
3 1.5.2.2 skrll /*
4 1.5.2.2 skrll * Copyright (c) 2003 Valeriy E. Ushakov
5 1.5.2.2 skrll * All rights reserved.
6 1.5.2.2 skrll *
7 1.5.2.2 skrll * Redistribution and use in source and binary forms, with or without
8 1.5.2.2 skrll * modification, are permitted provided that the following conditions
9 1.5.2.2 skrll * are met:
10 1.5.2.2 skrll * 1. Redistributions of source code must retain the above copyright
11 1.5.2.2 skrll * notice, this list of conditions and the following disclaimer.
12 1.5.2.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
13 1.5.2.2 skrll * notice, this list of conditions and the following disclaimer in the
14 1.5.2.2 skrll * documentation and/or other materials provided with the distribution.
15 1.5.2.2 skrll * 3. The name of the author may not be used to endorse or promote products
16 1.5.2.2 skrll * derived from this software without specific prior written permission
17 1.5.2.2 skrll *
18 1.5.2.2 skrll * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.5.2.2 skrll * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.5.2.2 skrll * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.5.2.2 skrll * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.5.2.2 skrll * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.5.2.2 skrll * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.5.2.2 skrll * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.5.2.2 skrll * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.5.2.2 skrll * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.5.2.2 skrll * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.5.2.2 skrll */
29 1.5.2.2 skrll
30 1.5.2.2 skrll #include <sys/cdefs.h>
31 1.5.2.4 skrll __KERNEL_RCSID(0, "$NetBSD: j6x0tp.c,v 1.5.2.4 2004/09/21 13:16:24 skrll Exp $");
32 1.5.2.2 skrll
33 1.5.2.2 skrll #include <sys/param.h>
34 1.5.2.2 skrll #include <sys/kernel.h>
35 1.5.2.2 skrll #include <sys/device.h>
36 1.5.2.2 skrll #include <sys/malloc.h>
37 1.5.2.2 skrll #include <sys/systm.h>
38 1.5.2.2 skrll #include <sys/callout.h>
39 1.5.2.2 skrll #ifdef GPROF
40 1.5.2.2 skrll #include <sys/gmon.h>
41 1.5.2.2 skrll #endif
42 1.5.2.2 skrll
43 1.5.2.2 skrll #include "opt_j6x0tp.h"
44 1.5.2.2 skrll
45 1.5.2.2 skrll #include <dev/wscons/wsconsio.h>
46 1.5.2.2 skrll #include <dev/wscons/wsmousevar.h>
47 1.5.2.2 skrll #include <dev/wscons/wskbdvar.h>
48 1.5.2.2 skrll #include <dev/wscons/wsksymvar.h>
49 1.5.2.2 skrll #include <dev/wscons/wsksymdef.h>
50 1.5.2.2 skrll #include <dev/hpc/hpctpanelvar.h>
51 1.5.2.2 skrll
52 1.5.2.2 skrll #include <machine/platid.h>
53 1.5.2.2 skrll #include <machine/platid_mask.h>
54 1.5.2.2 skrll
55 1.5.2.2 skrll #include <machine/intr.h>
56 1.5.2.2 skrll
57 1.5.2.2 skrll #include <sh3/exception.h>
58 1.5.2.2 skrll #include <sh3/intcreg.h>
59 1.5.2.2 skrll #include <sh3/pfcreg.h>
60 1.5.2.2 skrll #include <sh3/adcreg.h>
61 1.5.2.2 skrll
62 1.5.2.2 skrll #include <sh3/dev/adcvar.h>
63 1.5.2.2 skrll
64 1.5.2.2 skrll
65 1.5.2.2 skrll #define J6X0TP_DEBUG
66 1.5.2.2 skrll #if 0 /* XXX: disabled in favor of local version that uses printf_nolog */
67 1.5.2.2 skrll #define DPRINTF_ENABLE
68 1.5.2.2 skrll #define DPRINTF_DEBUG j6x0tp_debug
69 1.5.2.2 skrll #define DPRINTF_LEVEL 0
70 1.5.2.2 skrll #include <machine/debug.h>
71 1.5.2.2 skrll #else
72 1.5.2.2 skrll #ifdef J6X0TP_DEBUG
73 1.5.2.2 skrll volatile int j6x0tp_debug = 0;
74 1.5.2.2 skrll #define DPRINTF_PRINTF printf_nolog
75 1.5.2.2 skrll #define DPRINTF(arg) if (j6x0tp_debug) DPRINTF_PRINTF arg
76 1.5.2.2 skrll #define DPRINTFN(n, arg) if (j6x0tp_debug > (n)) DPRINTF_PRINTF arg
77 1.5.2.2 skrll #else
78 1.5.2.2 skrll #define DPRINTF(arg) ((void)0)
79 1.5.2.2 skrll #define DPRINTFN(n, arg) ((void)0)
80 1.5.2.2 skrll #endif
81 1.5.2.2 skrll #endif
82 1.5.2.2 skrll
83 1.5.2.2 skrll
84 1.5.2.2 skrll /*
85 1.5.2.2 skrll * PFC bits pertinent to Jornada 6x0 touchpanel
86 1.5.2.2 skrll */
87 1.5.2.2 skrll #define PHDR_TP_PEN_DOWN 0x08
88 1.5.2.2 skrll
89 1.5.2.2 skrll #define SCPDR_TP_SCAN_ENABLE 0x20
90 1.5.2.2 skrll #define SCPDR_TP_SCAN_Y 0x02
91 1.5.2.2 skrll #define SCPDR_TP_SCAN_X 0x01
92 1.5.2.2 skrll
93 1.5.2.2 skrll /*
94 1.5.2.2 skrll * A/D converter channels to get x/y from
95 1.5.2.2 skrll */
96 1.5.2.2 skrll #define ADC_CHANNEL_TP_Y 1
97 1.5.2.2 skrll #define ADC_CHANNEL_TP_X 2
98 1.5.2.2 skrll
99 1.5.2.2 skrll /*
100 1.5.2.2 skrll * Default (read: my device :) raw X/Y values for framebuffer edges.
101 1.5.2.2 skrll * XXX: defopt these?
102 1.5.2.2 skrll */
103 1.5.2.2 skrll #define J6X0TP_FB_LEFT 38
104 1.5.2.2 skrll #define J6X0TP_FB_RIGHT 950
105 1.5.2.2 skrll #define J6X0TP_FB_TOP 80
106 1.5.2.2 skrll #define J6X0TP_FB_BOTTOM 900
107 1.5.2.2 skrll
108 1.5.2.2 skrll /*
109 1.5.2.2 skrll * Bottom of the n'th hard icon (n = 1..4)
110 1.5.2.2 skrll */
111 1.5.2.2 skrll #define J6X0TP_HARD_ICON_MAX_Y(n) \
112 1.5.2.2 skrll (J6X0TP_FB_TOP + ((J6X0TP_FB_BOTTOM - J6X0TP_FB_TOP) / 4) * (n))
113 1.5.2.2 skrll
114 1.5.2.2 skrll
115 1.5.2.2 skrll struct j6x0tp_softc {
116 1.5.2.2 skrll struct device sc_dev;
117 1.5.2.2 skrll
118 1.5.2.2 skrll #define J6X0TP_WSMOUSE_ENABLED 0x01
119 1.5.2.2 skrll #define J6X0TP_WSKBD_ENABLED 0x02
120 1.5.2.2 skrll int sc_enabled;
121 1.5.2.2 skrll
122 1.5.2.2 skrll int sc_hard_icon;
123 1.5.2.2 skrll
124 1.5.2.2 skrll struct callout sc_touch_ch;
125 1.5.2.2 skrll
126 1.5.2.2 skrll struct device *sc_wsmousedev;
127 1.5.2.2 skrll struct device *sc_wskbddev;
128 1.5.2.2 skrll
129 1.5.2.2 skrll struct tpcalib_softc sc_tpcalib; /* calibration info for wsmouse */
130 1.5.2.2 skrll };
131 1.5.2.2 skrll
132 1.5.2.2 skrll
133 1.5.2.2 skrll /* config machinery */
134 1.5.2.2 skrll static int j6x0tp_match(struct device *, struct cfdata *, void *);
135 1.5.2.2 skrll static void j6x0tp_attach(struct device *, struct device *, void *);
136 1.5.2.2 skrll static int j6x0tp_wsmouse_submatch(struct device *, struct cfdata *,
137 1.5.2.2 skrll void *);
138 1.5.2.2 skrll static int j6x0tp_wskbd_submatch(struct device *, struct cfdata *,
139 1.5.2.2 skrll void *);
140 1.5.2.2 skrll
141 1.5.2.2 skrll /* wsmouse accessops */
142 1.5.2.2 skrll static int j6x0tp_wsmouse_enable(void *);
143 1.5.2.2 skrll static int j6x0tp_wsmouse_ioctl(void *, u_long, caddr_t, int,
144 1.5.2.2 skrll struct proc *);
145 1.5.2.2 skrll static void j6x0tp_wsmouse_disable(void *);
146 1.5.2.2 skrll
147 1.5.2.2 skrll /* wskbd accessops */
148 1.5.2.2 skrll static int j6x0tp_wskbd_enable(void *, int);
149 1.5.2.2 skrll static void j6x0tp_wskbd_set_leds(void *, int);
150 1.5.2.2 skrll static int j6x0tp_wskbd_ioctl(void *, u_long, caddr_t, int,
151 1.5.2.2 skrll struct proc *);
152 1.5.2.2 skrll
153 1.5.2.2 skrll /* internal driver routines */
154 1.5.2.2 skrll static void j6x0tp_enable(struct j6x0tp_softc *);
155 1.5.2.2 skrll static void j6x0tp_disable(struct j6x0tp_softc *);
156 1.5.2.2 skrll static int j6x0tp_set_enable(struct j6x0tp_softc *, int, int);
157 1.5.2.2 skrll static int j6x0tp_intr(void *);
158 1.5.2.2 skrll static void j6x0tp_start_polling(void *);
159 1.5.2.2 skrll static void j6x0tp_stop_polling(struct j6x0tp_softc *);
160 1.5.2.2 skrll static void j6x0tp_callout_wsmouse(void *);
161 1.5.2.2 skrll static void j6x0tp_callout_wskbd(void *);
162 1.5.2.2 skrll static void j6x0tp_wsmouse_input(struct j6x0tp_softc *, int, int);
163 1.5.2.2 skrll static void j6x0tp_get_raw_xy(int *, int *);
164 1.5.2.2 skrll static int j6x0tp_get_hard_icon(int, int);
165 1.5.2.2 skrll
166 1.5.2.2 skrll
167 1.5.2.2 skrll const struct wsmouse_accessops j6x0tp_accessops = {
168 1.5.2.2 skrll j6x0tp_wsmouse_enable,
169 1.5.2.2 skrll j6x0tp_wsmouse_ioctl,
170 1.5.2.2 skrll j6x0tp_wsmouse_disable
171 1.5.2.2 skrll };
172 1.5.2.2 skrll
173 1.5.2.2 skrll static const struct wsmouse_calibcoords j6x0tp_default_calib = {
174 1.5.2.2 skrll 0, 0, 639, 239,
175 1.5.2.2 skrll 4,
176 1.5.2.2 skrll {{ J6X0TP_FB_LEFT, J6X0TP_FB_TOP, 0, 0 },
177 1.5.2.2 skrll { J6X0TP_FB_RIGHT, J6X0TP_FB_TOP, 639, 0 },
178 1.5.2.2 skrll { J6X0TP_FB_LEFT, J6X0TP_FB_BOTTOM, 0, 239 },
179 1.5.2.2 skrll { J6X0TP_FB_RIGHT, J6X0TP_FB_BOTTOM, 639, 239 }}
180 1.5.2.2 skrll };
181 1.5.2.2 skrll
182 1.5.2.2 skrll const struct wskbd_accessops j6x0tp_wskbd_accessops = {
183 1.5.2.2 skrll j6x0tp_wskbd_enable,
184 1.5.2.2 skrll j6x0tp_wskbd_set_leds,
185 1.5.2.2 skrll j6x0tp_wskbd_ioctl
186 1.5.2.2 skrll };
187 1.5.2.2 skrll
188 1.5.2.2 skrll
189 1.5.2.2 skrll #ifndef J6X0TP_SETTINGS_ICON_KEYSYM
190 1.5.2.2 skrll #define J6X0TP_SETTINGS_ICON_KEYSYM KS_Home
191 1.5.2.2 skrll #endif
192 1.5.2.2 skrll #ifndef J6X0TP_PGUP_ICON_KEYSYM
193 1.5.2.2 skrll #define J6X0TP_PGUP_ICON_KEYSYM KS_Prior
194 1.5.2.2 skrll #endif
195 1.5.2.2 skrll #ifndef J6X0TP_PGDN_ICON_KEYSYM
196 1.5.2.2 skrll #define J6X0TP_PGDN_ICON_KEYSYM KS_Next
197 1.5.2.2 skrll #endif
198 1.5.2.2 skrll #ifndef J6X0TP_SWITCH_ICON_KEYSYM
199 1.5.2.2 skrll #define J6X0TP_SWITCH_ICON_KEYSYM KS_End
200 1.5.2.2 skrll #endif
201 1.5.2.2 skrll
202 1.5.2.2 skrll static const keysym_t j6x0tp_wskbd_keydesc[] = {
203 1.5.2.2 skrll KS_KEYCODE(1), J6X0TP_SETTINGS_ICON_KEYSYM,
204 1.5.2.2 skrll KS_KEYCODE(2), J6X0TP_PGUP_ICON_KEYSYM,
205 1.5.2.2 skrll KS_KEYCODE(3), J6X0TP_PGDN_ICON_KEYSYM,
206 1.5.2.2 skrll KS_KEYCODE(4), J6X0TP_SWITCH_ICON_KEYSYM
207 1.5.2.2 skrll };
208 1.5.2.2 skrll
209 1.5.2.2 skrll const struct wscons_keydesc j6x0tp_wskbd_keydesctab[] = {
210 1.5.2.2 skrll { KB_US, 0,
211 1.5.2.2 skrll sizeof(j6x0tp_wskbd_keydesc)/sizeof(keysym_t),
212 1.5.2.2 skrll j6x0tp_wskbd_keydesc
213 1.5.2.2 skrll },
214 1.5.2.2 skrll {0, 0, 0, 0}
215 1.5.2.2 skrll };
216 1.5.2.2 skrll
217 1.5.2.2 skrll const struct wskbd_mapdata j6x0tp_wskbd_keymapdata = {
218 1.5.2.2 skrll j6x0tp_wskbd_keydesctab, KB_US
219 1.5.2.2 skrll };
220 1.5.2.2 skrll
221 1.5.2.2 skrll
222 1.5.2.2 skrll CFATTACH_DECL(j6x0tp, sizeof(struct j6x0tp_softc),
223 1.5.2.2 skrll j6x0tp_match, j6x0tp_attach, NULL, NULL);
224 1.5.2.2 skrll
225 1.5.2.2 skrll
226 1.5.2.2 skrll static int
227 1.5.2.2 skrll j6x0tp_match(struct device *parent, struct cfdata *cf, void *aux)
228 1.5.2.2 skrll {
229 1.5.2.2 skrll
230 1.5.2.2 skrll /*
231 1.5.2.2 skrll * XXX: does platid_mask_MACH_HP_LX matches _JORNADA_6XX too?
232 1.5.2.2 skrll * Is 620 wired similarly?
233 1.5.2.2 skrll */
234 1.5.2.2 skrll if (!platid_match(&platid, &platid_mask_MACH_HP_JORNADA_6XX))
235 1.5.2.2 skrll return (0);
236 1.5.2.2 skrll
237 1.5.2.2 skrll if (strcmp(cf->cf_name, "j6x0tp") != 0)
238 1.5.2.2 skrll return (0);
239 1.5.2.2 skrll
240 1.5.2.2 skrll return (1);
241 1.5.2.2 skrll }
242 1.5.2.2 skrll
243 1.5.2.2 skrll
244 1.5.2.2 skrll /*
245 1.5.2.2 skrll * Attach the touch panel driver and its ws* children.
246 1.5.2.2 skrll *
247 1.5.2.2 skrll * Note that we have to use submatch to distinguish between children
248 1.5.2.2 skrll * because ws{kbd,mouse}_match match unconditionally.
249 1.5.2.2 skrll */
250 1.5.2.2 skrll static void
251 1.5.2.2 skrll j6x0tp_attach(struct device *parent, struct device *self, void *aux)
252 1.5.2.2 skrll {
253 1.5.2.2 skrll struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
254 1.5.2.2 skrll struct wsmousedev_attach_args wsma;
255 1.5.2.2 skrll struct wskbddev_attach_args wska;
256 1.5.2.2 skrll
257 1.5.2.2 skrll printf("\n");
258 1.5.2.2 skrll
259 1.5.2.2 skrll sc->sc_enabled = 0;
260 1.5.2.2 skrll sc->sc_hard_icon = 0;
261 1.5.2.2 skrll
262 1.5.2.2 skrll /* touch-panel as a pointing device */
263 1.5.2.2 skrll wsma.accessops = &j6x0tp_accessops;
264 1.5.2.2 skrll wsma.accesscookie = sc;
265 1.5.2.2 skrll
266 1.5.2.2 skrll sc->sc_wsmousedev = config_found_sm(self, &wsma, wsmousedevprint,
267 1.5.2.2 skrll j6x0tp_wsmouse_submatch);
268 1.5.2.2 skrll if (sc->sc_wsmousedev == NULL)
269 1.5.2.2 skrll return;
270 1.5.2.2 skrll
271 1.5.2.2 skrll /* on-screen "hard icons" as a keyboard device */
272 1.5.2.2 skrll wska.console = 0;
273 1.5.2.2 skrll wska.keymap = &j6x0tp_wskbd_keymapdata;
274 1.5.2.2 skrll wska.accessops = &j6x0tp_wskbd_accessops;
275 1.5.2.2 skrll wska.accesscookie = sc;
276 1.5.2.2 skrll
277 1.5.2.2 skrll sc->sc_wskbddev = config_found_sm(self, &wska, wskbddevprint,
278 1.5.2.2 skrll j6x0tp_wskbd_submatch);
279 1.5.2.2 skrll
280 1.5.2.2 skrll /* init calibration, set default parameters */
281 1.5.2.2 skrll tpcalib_init(&sc->sc_tpcalib);
282 1.5.2.2 skrll tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
283 1.5.2.2 skrll (caddr_t)&j6x0tp_default_calib, 0, 0);
284 1.5.2.2 skrll
285 1.5.2.2 skrll /* used when in polling mode */
286 1.5.2.2 skrll callout_init(&sc->sc_touch_ch);
287 1.5.2.2 skrll
288 1.5.2.2 skrll /* establish interrupt handler, but disable until opened */
289 1.5.2.2 skrll intc_intr_establish(SH7709_INTEVT2_IRQ3, IST_EDGE, IPL_TTY,
290 1.5.2.2 skrll j6x0tp_intr, sc);
291 1.5.2.2 skrll intc_intr_disable(SH7709_INTEVT2_IRQ3);
292 1.5.2.2 skrll }
293 1.5.2.2 skrll
294 1.5.2.2 skrll
295 1.5.2.2 skrll static int
296 1.5.2.2 skrll j6x0tp_wsmouse_submatch(struct device *parent, struct cfdata *cf, void *aux)
297 1.5.2.2 skrll {
298 1.5.2.2 skrll
299 1.5.2.2 skrll return (!strcmp(cf->cf_name, "wsmouse"));
300 1.5.2.2 skrll }
301 1.5.2.2 skrll
302 1.5.2.2 skrll
303 1.5.2.2 skrll static int
304 1.5.2.2 skrll j6x0tp_wskbd_submatch(struct device *parent, struct cfdata *cf, void *aux)
305 1.5.2.2 skrll {
306 1.5.2.2 skrll
307 1.5.2.2 skrll return (!strcmp(cf->cf_name, "wskbd"));
308 1.5.2.2 skrll }
309 1.5.2.2 skrll
310 1.5.2.2 skrll
311 1.5.2.2 skrll /*
312 1.5.2.2 skrll * Enable touch panel: we start in interrupt mode.
313 1.5.2.2 skrll * Must be called as spltty().
314 1.5.2.2 skrll */
315 1.5.2.2 skrll static void
316 1.5.2.2 skrll j6x0tp_enable(struct j6x0tp_softc *sc)
317 1.5.2.2 skrll {
318 1.5.2.2 skrll
319 1.5.2.2 skrll DPRINTFN(2, ("%s: enable\n", sc->sc_dev.dv_xname));
320 1.5.2.2 skrll intc_intr_enable(SH7709_INTEVT2_IRQ3);
321 1.5.2.2 skrll }
322 1.5.2.2 skrll
323 1.5.2.2 skrll
324 1.5.2.2 skrll /*
325 1.5.2.2 skrll * Disable touch panel: disable interrupt, cancel pending callout.
326 1.5.2.2 skrll * Must be called as spltty().
327 1.5.2.2 skrll */
328 1.5.2.2 skrll static void
329 1.5.2.2 skrll j6x0tp_disable(struct j6x0tp_softc *sc)
330 1.5.2.2 skrll {
331 1.5.2.2 skrll
332 1.5.2.2 skrll DPRINTFN(2, ("%s: disable\n", sc->sc_dev.dv_xname));
333 1.5.2.2 skrll intc_intr_disable(SH7709_INTEVT2_IRQ3);
334 1.5.2.2 skrll callout_stop(&sc->sc_touch_ch);
335 1.5.2.2 skrll }
336 1.5.2.2 skrll
337 1.5.2.2 skrll
338 1.5.2.2 skrll static int
339 1.5.2.2 skrll j6x0tp_set_enable(struct j6x0tp_softc *sc, int on, int child)
340 1.5.2.2 skrll {
341 1.5.2.2 skrll int s = spltty();
342 1.5.2.2 skrll
343 1.5.2.2 skrll if (on) {
344 1.5.2.2 skrll if (!sc->sc_enabled)
345 1.5.2.2 skrll j6x0tp_enable(sc);
346 1.5.2.2 skrll sc->sc_enabled |= child;
347 1.5.2.2 skrll } else {
348 1.5.2.2 skrll sc->sc_enabled &= ~child;
349 1.5.2.2 skrll if (!sc->sc_enabled)
350 1.5.2.2 skrll j6x0tp_disable(sc);
351 1.5.2.2 skrll }
352 1.5.2.2 skrll
353 1.5.2.2 skrll splx(s);
354 1.5.2.2 skrll return (0);
355 1.5.2.2 skrll }
356 1.5.2.2 skrll
357 1.5.2.2 skrll
358 1.5.2.2 skrll static int
359 1.5.2.2 skrll j6x0tp_wsmouse_enable(void *self)
360 1.5.2.2 skrll {
361 1.5.2.2 skrll struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
362 1.5.2.2 skrll
363 1.5.2.2 skrll DPRINTFN(1, ("%s: wsmouse enable\n", sc->sc_dev.dv_xname));
364 1.5.2.2 skrll return (j6x0tp_set_enable(sc, 1, J6X0TP_WSMOUSE_ENABLED));
365 1.5.2.2 skrll }
366 1.5.2.2 skrll
367 1.5.2.2 skrll
368 1.5.2.2 skrll static void
369 1.5.2.2 skrll j6x0tp_wsmouse_disable(void *self)
370 1.5.2.2 skrll {
371 1.5.2.2 skrll struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
372 1.5.2.2 skrll
373 1.5.2.2 skrll DPRINTFN(1, ("%s: wsmouse disable\n", sc->sc_dev.dv_xname));
374 1.5.2.2 skrll j6x0tp_set_enable(sc, 0, J6X0TP_WSMOUSE_ENABLED);
375 1.5.2.2 skrll }
376 1.5.2.2 skrll
377 1.5.2.2 skrll
378 1.5.2.2 skrll static int
379 1.5.2.2 skrll j6x0tp_wskbd_enable(void *self, int on)
380 1.5.2.2 skrll {
381 1.5.2.2 skrll struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
382 1.5.2.2 skrll
383 1.5.2.2 skrll DPRINTFN(1, ("%s: wskbd %sable\n", sc->sc_dev.dv_xname,
384 1.5.2.2 skrll on ? "en" : "dis"));
385 1.5.2.2 skrll return (j6x0tp_set_enable(sc, on, J6X0TP_WSKBD_ENABLED));
386 1.5.2.2 skrll }
387 1.5.2.2 skrll
388 1.5.2.2 skrll
389 1.5.2.2 skrll static int
390 1.5.2.2 skrll j6x0tp_intr(void *self)
391 1.5.2.2 skrll {
392 1.5.2.2 skrll struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
393 1.5.2.2 skrll
394 1.5.2.2 skrll uint8_t irr0;
395 1.5.2.2 skrll uint8_t phdr, touched;
396 1.5.2.2 skrll unsigned int steady, tremor_timeout;
397 1.5.2.2 skrll
398 1.5.2.2 skrll irr0 = _reg_read_1(SH7709_IRR0);
399 1.5.2.2 skrll if ((irr0 & IRR0_IRQ3) == 0) {
400 1.5.2.2 skrll #ifdef DIAGNOSTIC
401 1.5.2.2 skrll printf("%s: irr0 %02x?\n", sc->sc_dev.dv_xname, irr0);
402 1.5.2.2 skrll #endif
403 1.5.2.2 skrll return (0);
404 1.5.2.2 skrll }
405 1.5.2.2 skrll
406 1.5.2.2 skrll if (!sc->sc_enabled) {
407 1.5.2.2 skrll DPRINTFN(1, ("%s: intr: !sc_enabled\n", sc->sc_dev.dv_xname));
408 1.5.2.2 skrll intc_intr_disable(SH7709_INTEVT2_IRQ3);
409 1.5.2.2 skrll goto served;
410 1.5.2.2 skrll }
411 1.5.2.2 skrll
412 1.5.2.2 skrll
413 1.5.2.2 skrll /*
414 1.5.2.2 skrll * Number of times the "touched" bit should be read
415 1.5.2.2 skrll * consecutively.
416 1.5.2.2 skrll */
417 1.5.2.2 skrll # define TREMOR_THRESHOLD 0x300
418 1.5.2.2 skrll
419 1.5.2.2 skrll steady = 0;
420 1.5.2.2 skrll tremor_timeout = TREMOR_THRESHOLD * 16; /* XXX: arbitrary */
421 1.5.2.2 skrll touched = PHDR_TP_PEN_DOWN; /* we start with "touched" state */
422 1.5.2.2 skrll
423 1.5.2.2 skrll do {
424 1.5.2.2 skrll phdr = _reg_read_1(SH7709_PHDR);
425 1.5.2.2 skrll
426 1.5.2.2 skrll if ((phdr & PHDR_TP_PEN_DOWN) == touched)
427 1.5.2.2 skrll ++steady;
428 1.5.2.2 skrll else {
429 1.5.2.2 skrll steady = 0;
430 1.5.2.2 skrll touched = phdr & PHDR_TP_PEN_DOWN;
431 1.5.2.2 skrll }
432 1.5.2.2 skrll
433 1.5.2.2 skrll if (--tremor_timeout == 0) {
434 1.5.2.2 skrll DPRINTF(("%s: tremor timeout!\n",
435 1.5.2.2 skrll sc->sc_dev.dv_xname));
436 1.5.2.2 skrll goto served;
437 1.5.2.2 skrll }
438 1.5.2.2 skrll } while (steady < TREMOR_THRESHOLD);
439 1.5.2.2 skrll
440 1.5.2.2 skrll if (touched) {
441 1.5.2.2 skrll intc_intr_disable(SH7709_INTEVT2_IRQ3);
442 1.5.2.2 skrll
443 1.5.2.2 skrll /*
444 1.5.2.2 skrll * ADC readings are not stable yet, so schedule
445 1.5.2.2 skrll * callout instead of accessing ADC from the interrupt
446 1.5.2.2 skrll * handler only to immediately delay().
447 1.5.2.2 skrll */
448 1.5.2.2 skrll callout_reset(&sc->sc_touch_ch, hz/32,
449 1.5.2.2 skrll j6x0tp_start_polling, sc);
450 1.5.2.2 skrll } else
451 1.5.2.2 skrll DPRINTFN(1, ("%s: tremor\n", sc->sc_dev.dv_xname));
452 1.5.2.2 skrll served:
453 1.5.2.2 skrll /* clear the interrupt (XXX: protect access?) */
454 1.5.2.2 skrll _reg_write_1(SH7709_IRR0, irr0 & ~IRR0_IRQ3);
455 1.5.2.2 skrll
456 1.5.2.2 skrll return (1);
457 1.5.2.2 skrll }
458 1.5.2.2 skrll
459 1.5.2.2 skrll
460 1.5.2.2 skrll /*
461 1.5.2.2 skrll * Called from the interrupt handler at spltty() upon first touch.
462 1.5.2.2 skrll * Decide if we are going to report this touch as a mouse click/drag
463 1.5.2.2 skrll * or as a key press.
464 1.5.2.2 skrll */
465 1.5.2.2 skrll static void
466 1.5.2.2 skrll j6x0tp_start_polling(void *self)
467 1.5.2.2 skrll {
468 1.5.2.2 skrll struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
469 1.5.2.2 skrll uint8_t phdr;
470 1.5.2.2 skrll int do_mouse, do_kbd;
471 1.5.2.2 skrll int rawx, rawy;
472 1.5.2.2 skrll int icon;
473 1.5.2.2 skrll
474 1.5.2.2 skrll phdr = _reg_read_1(SH7709_PHDR);
475 1.5.2.2 skrll if ((phdr & PHDR_TP_PEN_DOWN) == 0) {
476 1.5.2.2 skrll DPRINTFN(2, ("%s: start: pen is not down\n",
477 1.5.2.2 skrll sc->sc_dev.dv_xname));
478 1.5.2.2 skrll j6x0tp_stop_polling(sc);
479 1.5.2.2 skrll }
480 1.5.2.2 skrll
481 1.5.2.2 skrll j6x0tp_get_raw_xy(&rawx, &rawy);
482 1.5.2.2 skrll DPRINTFN(2, ("%s: start: %4d %4d -> ",
483 1.5.2.2 skrll sc->sc_dev.dv_xname, rawx, rawy));
484 1.5.2.2 skrll
485 1.5.2.2 skrll do_mouse = sc->sc_enabled & J6X0TP_WSMOUSE_ENABLED;
486 1.5.2.2 skrll #ifdef J6X0TP_WSMOUSE_EXCLUSIVE
487 1.5.2.2 skrll if (do_mouse)
488 1.5.2.2 skrll do_kbd = 0;
489 1.5.2.2 skrll else
490 1.5.2.2 skrll #endif
491 1.5.2.2 skrll do_kbd = sc->sc_enabled & J6X0TP_WSKBD_ENABLED;
492 1.5.2.2 skrll
493 1.5.2.2 skrll icon = 0;
494 1.5.2.2 skrll if (do_kbd)
495 1.5.2.2 skrll icon = j6x0tp_get_hard_icon(rawx, rawy);
496 1.5.2.2 skrll
497 1.5.2.2 skrll if (icon != 0) {
498 1.5.2.2 skrll DPRINTFN(2, ("icon %d\n", icon));
499 1.5.2.2 skrll sc->sc_hard_icon = icon;
500 1.5.2.2 skrll wskbd_input(sc->sc_wskbddev, WSCONS_EVENT_KEY_DOWN, icon);
501 1.5.2.2 skrll callout_reset(&sc->sc_touch_ch, hz/32,
502 1.5.2.2 skrll j6x0tp_callout_wskbd, sc);
503 1.5.2.2 skrll } else if (do_mouse) {
504 1.5.2.2 skrll DPRINTFN(2, ("mouse\n"));
505 1.5.2.2 skrll j6x0tp_wsmouse_input(sc, rawx, rawy);
506 1.5.2.2 skrll callout_reset(&sc->sc_touch_ch, hz/32,
507 1.5.2.2 skrll j6x0tp_callout_wsmouse, sc);
508 1.5.2.2 skrll } else {
509 1.5.2.2 skrll DPRINTFN(2, ("ignore\n"));
510 1.5.2.2 skrll j6x0tp_stop_polling(sc);
511 1.5.2.2 skrll }
512 1.5.2.2 skrll }
513 1.5.2.2 skrll
514 1.5.2.2 skrll
515 1.5.2.2 skrll /*
516 1.5.2.2 skrll * Re-enable touch panel interrupt.
517 1.5.2.2 skrll * Called as spltty() when polling code detects pen-up.
518 1.5.2.2 skrll */
519 1.5.2.2 skrll static void
520 1.5.2.2 skrll j6x0tp_stop_polling(struct j6x0tp_softc *sc)
521 1.5.2.2 skrll {
522 1.5.2.2 skrll uint8_t irr0;
523 1.5.2.2 skrll
524 1.5.2.2 skrll DPRINTFN(2, ("%s: stop\n", sc->sc_dev.dv_xname));
525 1.5.2.2 skrll
526 1.5.2.2 skrll /* clear pending interrupt signal before re-enabling the interrupt */
527 1.5.2.2 skrll irr0 = _reg_read_1(SH7709_IRR0);
528 1.5.2.2 skrll if ((irr0 & IRR0_IRQ3) != 0)
529 1.5.2.2 skrll _reg_write_1(SH7709_IRR0, irr0 & ~IRR0_IRQ3);
530 1.5.2.2 skrll
531 1.5.2.2 skrll intc_intr_enable(SH7709_INTEVT2_IRQ3);
532 1.5.2.2 skrll }
533 1.5.2.2 skrll
534 1.5.2.2 skrll
535 1.5.2.2 skrll /*
536 1.5.2.2 skrll * We are reporting this touch as a keyboard event.
537 1.5.2.2 skrll * Poll touch screen waiting for pen-up.
538 1.5.2.2 skrll */
539 1.5.2.2 skrll static void
540 1.5.2.2 skrll j6x0tp_callout_wskbd(void *self)
541 1.5.2.2 skrll {
542 1.5.2.2 skrll struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
543 1.5.2.2 skrll uint8_t phdr;
544 1.5.2.2 skrll int s;
545 1.5.2.2 skrll
546 1.5.2.2 skrll s = spltty();
547 1.5.2.2 skrll
548 1.5.2.2 skrll if (!sc->sc_enabled) {
549 1.5.2.2 skrll DPRINTFN(1, ("%s: wskbd callout: !sc_enabled\n",
550 1.5.2.2 skrll sc->sc_dev.dv_xname));
551 1.5.2.2 skrll splx(s);
552 1.5.2.2 skrll return;
553 1.5.2.2 skrll }
554 1.5.2.2 skrll
555 1.5.2.2 skrll phdr = _reg_read_1(SH7709_PHDR);
556 1.5.2.2 skrll if ((phdr & PHDR_TP_PEN_DOWN) != 0) {
557 1.5.2.2 skrll /*
558 1.5.2.2 skrll * Pen is still down, continue polling. Wskbd's
559 1.5.2.2 skrll * auto-repeat takes care of repeating the key.
560 1.5.2.2 skrll */
561 1.5.2.2 skrll callout_schedule(&sc->sc_touch_ch, hz/32);
562 1.5.2.2 skrll } else {
563 1.5.2.2 skrll wskbd_input(sc->sc_wskbddev,
564 1.5.2.2 skrll WSCONS_EVENT_KEY_UP, sc->sc_hard_icon);
565 1.5.2.2 skrll j6x0tp_stop_polling(sc);
566 1.5.2.2 skrll }
567 1.5.2.2 skrll splx(s);
568 1.5.2.2 skrll }
569 1.5.2.2 skrll
570 1.5.2.2 skrll
571 1.5.2.2 skrll /*
572 1.5.2.2 skrll * We are reporting this touch as a mouse click/drag.
573 1.5.2.2 skrll */
574 1.5.2.2 skrll static void
575 1.5.2.2 skrll j6x0tp_callout_wsmouse(void *self)
576 1.5.2.2 skrll {
577 1.5.2.2 skrll struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
578 1.5.2.2 skrll uint8_t phdr;
579 1.5.2.2 skrll int rawx, rawy;
580 1.5.2.2 skrll int s;
581 1.5.2.2 skrll
582 1.5.2.2 skrll s = spltty();
583 1.5.2.2 skrll
584 1.5.2.2 skrll if (!sc->sc_enabled) {
585 1.5.2.2 skrll DPRINTFN(1, ("%s: wsmouse callout: !sc_enabled\n",
586 1.5.2.2 skrll sc->sc_dev.dv_xname));
587 1.5.2.2 skrll splx(s);
588 1.5.2.2 skrll return;
589 1.5.2.2 skrll }
590 1.5.2.2 skrll
591 1.5.2.2 skrll phdr = _reg_read_1(SH7709_PHDR);
592 1.5.2.2 skrll if ((phdr & PHDR_TP_PEN_DOWN) != 0) {
593 1.5.2.2 skrll j6x0tp_get_raw_xy(&rawx, &rawy);
594 1.5.2.2 skrll j6x0tp_wsmouse_input(sc, rawx, rawy); /* mouse dragged */
595 1.5.2.2 skrll callout_schedule(&sc->sc_touch_ch, hz/32);
596 1.5.2.2 skrll } else {
597 1.5.2.2 skrll wsmouse_input(sc->sc_wsmousedev, 0, 0, 0, 0, /* button up */
598 1.5.2.2 skrll WSMOUSE_INPUT_DELTA);
599 1.5.2.2 skrll j6x0tp_stop_polling(sc);
600 1.5.2.2 skrll }
601 1.5.2.2 skrll splx(s);
602 1.5.2.2 skrll }
603 1.5.2.2 skrll
604 1.5.2.2 skrll
605 1.5.2.2 skrll /*
606 1.5.2.2 skrll * Report mouse click/drag.
607 1.5.2.2 skrll */
608 1.5.2.2 skrll static void
609 1.5.2.2 skrll j6x0tp_wsmouse_input(struct j6x0tp_softc *sc, int rawx, int rawy)
610 1.5.2.2 skrll {
611 1.5.2.2 skrll int x, y;
612 1.5.2.2 skrll
613 1.5.2.2 skrll tpcalib_trans(&sc->sc_tpcalib, rawx, rawy, &x, &y);
614 1.5.2.2 skrll
615 1.5.2.2 skrll DPRINTFN(3, ("%s: %4d %4d -> %3d %3d\n",
616 1.5.2.2 skrll sc->sc_dev.dv_xname, rawx, rawy, x, y));
617 1.5.2.2 skrll
618 1.5.2.2 skrll wsmouse_input(sc->sc_wsmousedev,
619 1.5.2.2 skrll 1, /* button */
620 1.5.2.2 skrll x, y,
621 1.5.2.2 skrll 0, /* flags */
622 1.5.2.2 skrll WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
623 1.5.2.2 skrll }
624 1.5.2.2 skrll
625 1.5.2.2 skrll
626 1.5.2.2 skrll /*
627 1.5.2.2 skrll * Read raw X/Y coordinates from the ADC.
628 1.5.2.2 skrll * XXX: protect accesses to SCPDR?
629 1.5.2.2 skrll */
630 1.5.2.2 skrll static void
631 1.5.2.2 skrll j6x0tp_get_raw_xy(int *rawxp, int *rawyp)
632 1.5.2.2 skrll {
633 1.5.2.2 skrll uint8_t scpdr;
634 1.5.2.2 skrll
635 1.5.2.2 skrll /* Y axis */
636 1.5.2.2 skrll scpdr = _reg_read_1(SH7709_SCPDR);
637 1.5.2.2 skrll scpdr |= SCPDR_TP_SCAN_ENABLE;
638 1.5.2.2 skrll scpdr &= ~SCPDR_TP_SCAN_Y; /* pull low to scan */
639 1.5.2.2 skrll _reg_write_1(SH7709_SCPDR, scpdr);
640 1.5.2.2 skrll delay(10);
641 1.5.2.2 skrll
642 1.5.2.2 skrll *rawyp = adc_sample_channel(ADC_CHANNEL_TP_Y);
643 1.5.2.2 skrll
644 1.5.2.2 skrll /* X axis */
645 1.5.2.2 skrll scpdr = _reg_read_1(SH7709_SCPDR);
646 1.5.2.2 skrll scpdr |= SCPDR_TP_SCAN_Y;
647 1.5.2.2 skrll scpdr &= ~SCPDR_TP_SCAN_X; /* pull low to scan */
648 1.5.2.2 skrll _reg_write_1(SH7709_SCPDR, scpdr);
649 1.5.2.2 skrll delay(10);
650 1.5.2.2 skrll
651 1.5.2.2 skrll *rawxp = adc_sample_channel(ADC_CHANNEL_TP_X);
652 1.5.2.2 skrll
653 1.5.2.2 skrll /* restore SCPDR */
654 1.5.2.2 skrll scpdr = _reg_read_1(SH7709_SCPDR);
655 1.5.2.2 skrll scpdr |= SCPDR_TP_SCAN_X;
656 1.5.2.2 skrll scpdr &= ~SCPDR_TP_SCAN_ENABLE;
657 1.5.2.2 skrll _reg_write_1(SH7709_SCPDR, scpdr);
658 1.5.2.2 skrll }
659 1.5.2.2 skrll
660 1.5.2.2 skrll
661 1.5.2.2 skrll /*
662 1.5.2.2 skrll * Check if the (rawx, rawy) is inside one of the 4 hard icons.
663 1.5.2.2 skrll * Return the icon number 1..4, or 0 if not inside an icon.
664 1.5.2.2 skrll */
665 1.5.2.2 skrll static int
666 1.5.2.2 skrll j6x0tp_get_hard_icon(int rawx, int rawy)
667 1.5.2.2 skrll {
668 1.5.2.2 skrll if (rawx <= J6X0TP_FB_RIGHT)
669 1.5.2.2 skrll return (0);
670 1.5.2.2 skrll
671 1.5.2.2 skrll if (rawy < J6X0TP_HARD_ICON_MAX_Y(1))
672 1.5.2.2 skrll return (1);
673 1.5.2.2 skrll else if (rawy < J6X0TP_HARD_ICON_MAX_Y(2))
674 1.5.2.2 skrll return (2);
675 1.5.2.2 skrll else if (rawy < J6X0TP_HARD_ICON_MAX_Y(3))
676 1.5.2.2 skrll return (3);
677 1.5.2.2 skrll else
678 1.5.2.2 skrll return (4);
679 1.5.2.2 skrll }
680 1.5.2.2 skrll
681 1.5.2.2 skrll
682 1.5.2.2 skrll static int
683 1.5.2.2 skrll j6x0tp_wsmouse_ioctl(void *self, u_long cmd, caddr_t data, int flag,
684 1.5.2.2 skrll struct proc *p)
685 1.5.2.2 skrll {
686 1.5.2.2 skrll struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self;
687 1.5.2.2 skrll
688 1.5.2.2 skrll return hpc_tpanel_ioctl(&sc->sc_tpcalib, cmd, data, flag, p);
689 1.5.2.2 skrll }
690 1.5.2.2 skrll
691 1.5.2.2 skrll
692 1.5.2.2 skrll static int
693 1.5.2.2 skrll j6x0tp_wskbd_ioctl(void *self, u_long cmd, caddr_t data, int flag,
694 1.5.2.2 skrll struct proc *p)
695 1.5.2.2 skrll {
696 1.5.2.2 skrll /* struct j6x0tp_softc *sc = (struct j6x0tp_softc *)self; */
697 1.5.2.2 skrll
698 1.5.2.2 skrll switch (cmd) {
699 1.5.2.2 skrll case WSKBDIO_GTYPE:
700 1.5.2.2 skrll *(int *)data = WSKBD_TYPE_HPC_BTN; /* may be use new type? */
701 1.5.2.2 skrll return (0);
702 1.5.2.2 skrll
703 1.5.2.2 skrll case WSKBDIO_GETLEDS:
704 1.5.2.2 skrll *(int *)data = 0;
705 1.5.2.2 skrll return (0);
706 1.5.2.2 skrll
707 1.5.2.2 skrll default:
708 1.5.2.2 skrll return (EPASSTHROUGH);
709 1.5.2.2 skrll }
710 1.5.2.2 skrll }
711 1.5.2.2 skrll
712 1.5.2.2 skrll
713 1.5.2.2 skrll static void
714 1.5.2.2 skrll j6x0tp_wskbd_set_leds(void *self, int leds)
715 1.5.2.2 skrll {
716 1.5.2.2 skrll
717 1.5.2.2 skrll /* nothing to do*/
718 1.5.2.2 skrll return;
719 1.5.2.2 skrll }
720