j720tp.c revision 1.1.8.2 1 1.1.8.2 simonb /* $NetBSD: j720tp.c,v 1.1.8.2 2006/04/22 11:37:28 simonb Exp $ */
2 1.1.8.2 simonb
3 1.1.8.2 simonb /*-
4 1.1.8.2 simonb * Copyright (c) 2006 The NetBSD Foundation, Inc.
5 1.1.8.2 simonb * All rights reserved.
6 1.1.8.2 simonb *
7 1.1.8.2 simonb * This code is derived from software contributed to The NetBSD Foundation
8 1.1.8.2 simonb * by IWAMOTO Toshihiro and Peter Postma.
9 1.1.8.2 simonb *
10 1.1.8.2 simonb * Redistribution and use in source and binary forms, with or without
11 1.1.8.2 simonb * modification, are permitted provided that the following conditions
12 1.1.8.2 simonb * are met:
13 1.1.8.2 simonb * 1. Redistributions of source code must retain the above copyright
14 1.1.8.2 simonb * notice, this list of conditions and the following disclaimer.
15 1.1.8.2 simonb * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.8.2 simonb * notice, this list of conditions and the following disclaimer in the
17 1.1.8.2 simonb * documentation and/or other materials provided with the distribution.
18 1.1.8.2 simonb * 3. All advertising materials mentioning features or use of this software
19 1.1.8.2 simonb * must display the following acknowledgement:
20 1.1.8.2 simonb * This product includes software developed by the NetBSD
21 1.1.8.2 simonb * Foundation, Inc. and its contributors.
22 1.1.8.2 simonb * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.8.2 simonb * contributors may be used to endorse or promote products derived
24 1.1.8.2 simonb * from this software without specific prior written permission.
25 1.1.8.2 simonb *
26 1.1.8.2 simonb * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.8.2 simonb * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.8.2 simonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.8.2 simonb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.8.2 simonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.8.2 simonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.8.2 simonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.8.2 simonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.8.2 simonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.8.2 simonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.8.2 simonb * POSSIBILITY OF SUCH DAMAGE.
37 1.1.8.2 simonb */
38 1.1.8.2 simonb
39 1.1.8.2 simonb /* Jornada 720 touch-panel driver. */
40 1.1.8.2 simonb
41 1.1.8.2 simonb #include <sys/cdefs.h>
42 1.1.8.2 simonb __KERNEL_RCSID(0, "$NetBSD: j720tp.c,v 1.1.8.2 2006/04/22 11:37:28 simonb Exp $");
43 1.1.8.2 simonb
44 1.1.8.2 simonb #include <sys/param.h>
45 1.1.8.2 simonb #include <sys/systm.h>
46 1.1.8.2 simonb #include <sys/device.h>
47 1.1.8.2 simonb #include <sys/kernel.h>
48 1.1.8.2 simonb #include <sys/malloc.h>
49 1.1.8.2 simonb #include <sys/ioctl.h>
50 1.1.8.2 simonb #include <sys/callout.h>
51 1.1.8.2 simonb
52 1.1.8.2 simonb #include <machine/platid.h>
53 1.1.8.2 simonb #include <machine/platid_mask.h>
54 1.1.8.2 simonb
55 1.1.8.2 simonb #include <arm/sa11x0/sa11x0_var.h>
56 1.1.8.2 simonb #include <arm/sa11x0/sa11x0_gpioreg.h>
57 1.1.8.2 simonb #include <arm/sa11x0/sa11x0_ppcreg.h>
58 1.1.8.2 simonb #include <arm/sa11x0/sa11x0_sspreg.h>
59 1.1.8.2 simonb
60 1.1.8.2 simonb #include <dev/wscons/wsconsio.h>
61 1.1.8.2 simonb #include <dev/wscons/wsmousevar.h>
62 1.1.8.2 simonb #include <dev/hpc/hpctpanelvar.h>
63 1.1.8.2 simonb
64 1.1.8.2 simonb #include <hpcarm/dev/j720sspvar.h>
65 1.1.8.2 simonb
66 1.1.8.2 simonb #include "opt_j720tp.h"
67 1.1.8.2 simonb
68 1.1.8.2 simonb #ifdef J720TP_DEBUG
69 1.1.8.2 simonb #define DPRINTF(arg) printf arg
70 1.1.8.2 simonb #else
71 1.1.8.2 simonb #define DPRINTF(arg) /* nothing */
72 1.1.8.2 simonb #endif
73 1.1.8.2 simonb
74 1.1.8.2 simonb struct j720tp_softc {
75 1.1.8.2 simonb struct device sc_dev;
76 1.1.8.2 simonb
77 1.1.8.2 simonb int sc_enabled;
78 1.1.8.2 simonb
79 1.1.8.2 simonb struct callout sc_tpcallout;
80 1.1.8.2 simonb struct j720ssp_softc *sc_ssp;
81 1.1.8.2 simonb
82 1.1.8.2 simonb struct device *sc_wsmousedev;
83 1.1.8.2 simonb
84 1.1.8.2 simonb struct tpcalib_softc sc_tpcalib;
85 1.1.8.2 simonb };
86 1.1.8.2 simonb
87 1.1.8.2 simonb static int j720tp_match(struct device *, struct cfdata *, void *);
88 1.1.8.2 simonb static void j720tp_attach(struct device *, struct device *, void *);
89 1.1.8.2 simonb
90 1.1.8.2 simonb static int j720tp_wsmouse_enable(void *);
91 1.1.8.2 simonb static int j720tp_wsmouse_ioctl(void *, u_long, caddr_t, int,
92 1.1.8.2 simonb struct lwp *);
93 1.1.8.2 simonb static void j720tp_wsmouse_disable(void *);
94 1.1.8.2 simonb
95 1.1.8.2 simonb static void j720tp_enable_intr(struct j720tp_softc *);
96 1.1.8.2 simonb static void j720tp_disable_intr(struct j720tp_softc *);
97 1.1.8.2 simonb static int j720tp_intr(void *);
98 1.1.8.2 simonb static int j720tp_get_rawxy(struct j720tp_softc *, int *, int *);
99 1.1.8.2 simonb static void j720tp_wsmouse_input(struct j720tp_softc *, int, int);
100 1.1.8.2 simonb static void j720tp_wsmouse_callout(void *);
101 1.1.8.2 simonb
102 1.1.8.2 simonb
103 1.1.8.2 simonb const struct wsmouse_accessops j720tp_wsmouse_accessops = {
104 1.1.8.2 simonb j720tp_wsmouse_enable,
105 1.1.8.2 simonb j720tp_wsmouse_ioctl,
106 1.1.8.2 simonb j720tp_wsmouse_disable
107 1.1.8.2 simonb };
108 1.1.8.2 simonb
109 1.1.8.2 simonb static const struct wsmouse_calibcoords j720tp_default_calib = {
110 1.1.8.2 simonb 0, 0, 639, 239,
111 1.1.8.2 simonb 4,
112 1.1.8.2 simonb {{ 988, 80, 0, 0 },
113 1.1.8.2 simonb { 88, 84, 639, 0 },
114 1.1.8.2 simonb { 988, 927, 0, 239 },
115 1.1.8.2 simonb { 88, 940, 639, 239 }}
116 1.1.8.2 simonb };
117 1.1.8.2 simonb
118 1.1.8.2 simonb CFATTACH_DECL(j720tp, sizeof(struct j720tp_softc),
119 1.1.8.2 simonb j720tp_match, j720tp_attach, NULL, NULL);
120 1.1.8.2 simonb
121 1.1.8.2 simonb
122 1.1.8.2 simonb static int
123 1.1.8.2 simonb j720tp_match(struct device *parent, struct cfdata *cf, void *aux)
124 1.1.8.2 simonb {
125 1.1.8.2 simonb
126 1.1.8.2 simonb if (!platid_match(&platid, &platid_mask_MACH_HP_JORNADA_7XX))
127 1.1.8.2 simonb return 0;
128 1.1.8.2 simonb if (strcmp(cf->cf_name, "j720tp") != 0)
129 1.1.8.2 simonb return 0;
130 1.1.8.2 simonb
131 1.1.8.2 simonb return 1;
132 1.1.8.2 simonb }
133 1.1.8.2 simonb
134 1.1.8.2 simonb static void
135 1.1.8.2 simonb j720tp_attach(struct device *parent, struct device *self, void *aux)
136 1.1.8.2 simonb {
137 1.1.8.2 simonb struct j720tp_softc *sc = (struct j720tp_softc *)self;
138 1.1.8.2 simonb struct wsmousedev_attach_args wsma;
139 1.1.8.2 simonb
140 1.1.8.2 simonb printf("\n");
141 1.1.8.2 simonb
142 1.1.8.2 simonb sc->sc_ssp = (struct j720ssp_softc *)parent;
143 1.1.8.2 simonb sc->sc_enabled = 0;
144 1.1.8.2 simonb
145 1.1.8.2 simonb /* Touch-panel as a pointing device. */
146 1.1.8.2 simonb wsma.accessops = &j720tp_wsmouse_accessops;
147 1.1.8.2 simonb wsma.accesscookie = sc;
148 1.1.8.2 simonb
149 1.1.8.2 simonb sc->sc_wsmousedev = config_found_ia(self, "wsmousedev", &wsma,
150 1.1.8.2 simonb wsmousedevprint);
151 1.1.8.2 simonb
152 1.1.8.2 simonb /* Initialize calibration, set default parameters. */
153 1.1.8.2 simonb tpcalib_init(&sc->sc_tpcalib);
154 1.1.8.2 simonb tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
155 1.1.8.2 simonb __UNCONST(&j720tp_default_calib), 0, 0);
156 1.1.8.2 simonb
157 1.1.8.2 simonb j720tp_wsmouse_disable(sc);
158 1.1.8.2 simonb callout_init(&sc->sc_tpcallout);
159 1.1.8.2 simonb
160 1.1.8.2 simonb /* Setup touch-panel interrupt. */
161 1.1.8.2 simonb sa11x0_intr_establish(0, 9, 1, IPL_TTY, j720tp_intr, sc);
162 1.1.8.2 simonb }
163 1.1.8.2 simonb
164 1.1.8.2 simonb static int
165 1.1.8.2 simonb j720tp_wsmouse_enable(void *self)
166 1.1.8.2 simonb {
167 1.1.8.2 simonb struct j720tp_softc *sc = self;
168 1.1.8.2 simonb int s;
169 1.1.8.2 simonb
170 1.1.8.2 simonb s = spltty();
171 1.1.8.2 simonb
172 1.1.8.2 simonb j720tp_enable_intr(sc);
173 1.1.8.2 simonb
174 1.1.8.2 simonb sc->sc_enabled = 1;
175 1.1.8.2 simonb
176 1.1.8.2 simonb splx(s);
177 1.1.8.2 simonb return 0;
178 1.1.8.2 simonb }
179 1.1.8.2 simonb
180 1.1.8.2 simonb static int
181 1.1.8.2 simonb j720tp_wsmouse_ioctl(void *self, u_long cmd, caddr_t data, int flag,
182 1.1.8.2 simonb struct lwp *l)
183 1.1.8.2 simonb {
184 1.1.8.2 simonb struct j720tp_softc *sc = self;
185 1.1.8.2 simonb
186 1.1.8.2 simonb return hpc_tpanel_ioctl(&sc->sc_tpcalib, cmd, data, flag, l);
187 1.1.8.2 simonb }
188 1.1.8.2 simonb
189 1.1.8.2 simonb static void
190 1.1.8.2 simonb j720tp_wsmouse_disable(void *self)
191 1.1.8.2 simonb {
192 1.1.8.2 simonb struct j720tp_softc *sc = self;
193 1.1.8.2 simonb int s;
194 1.1.8.2 simonb
195 1.1.8.2 simonb s = spltty();
196 1.1.8.2 simonb
197 1.1.8.2 simonb j720tp_disable_intr(sc);
198 1.1.8.2 simonb callout_stop(&sc->sc_tpcallout);
199 1.1.8.2 simonb
200 1.1.8.2 simonb sc->sc_enabled = 0;
201 1.1.8.2 simonb
202 1.1.8.2 simonb splx(s);
203 1.1.8.2 simonb }
204 1.1.8.2 simonb
205 1.1.8.2 simonb /*
206 1.1.8.2 simonb * Enable touch-panel interrupt. Must be called at spltty().
207 1.1.8.2 simonb */
208 1.1.8.2 simonb static void
209 1.1.8.2 simonb j720tp_enable_intr(struct j720tp_softc *sc)
210 1.1.8.2 simonb {
211 1.1.8.2 simonb struct j720ssp_softc *ssp = sc->sc_ssp;
212 1.1.8.2 simonb uint32_t er;
213 1.1.8.2 simonb
214 1.1.8.2 simonb er = bus_space_read_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_FER);
215 1.1.8.2 simonb er |= 1 << 9;
216 1.1.8.2 simonb bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_FER, er);
217 1.1.8.2 simonb }
218 1.1.8.2 simonb
219 1.1.8.2 simonb /*
220 1.1.8.2 simonb * Disable touch-panel interrupt. Must be called at spltty().
221 1.1.8.2 simonb */
222 1.1.8.2 simonb static void
223 1.1.8.2 simonb j720tp_disable_intr(struct j720tp_softc *sc)
224 1.1.8.2 simonb {
225 1.1.8.2 simonb struct j720ssp_softc *ssp = sc->sc_ssp;
226 1.1.8.2 simonb uint32_t er;
227 1.1.8.2 simonb
228 1.1.8.2 simonb er = bus_space_read_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_FER);
229 1.1.8.2 simonb er &= ~(1 << 9);
230 1.1.8.2 simonb bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_FER, er);
231 1.1.8.2 simonb }
232 1.1.8.2 simonb
233 1.1.8.2 simonb static int
234 1.1.8.2 simonb j720tp_intr(void *arg)
235 1.1.8.2 simonb {
236 1.1.8.2 simonb struct j720tp_softc *sc = arg;
237 1.1.8.2 simonb struct j720ssp_softc *ssp = sc->sc_ssp;
238 1.1.8.2 simonb int rawx, rawy;
239 1.1.8.2 simonb
240 1.1.8.2 simonb bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_EDR, 1 << 9);
241 1.1.8.2 simonb
242 1.1.8.2 simonb if (!sc->sc_enabled) {
243 1.1.8.2 simonb DPRINTF(("j720tp_intr: !sc_enabled\n"));
244 1.1.8.2 simonb return 0;
245 1.1.8.2 simonb }
246 1.1.8.2 simonb
247 1.1.8.2 simonb j720tp_disable_intr(sc);
248 1.1.8.2 simonb
249 1.1.8.2 simonb if (j720tp_get_rawxy(sc, &rawx, &rawy))
250 1.1.8.2 simonb j720tp_wsmouse_input(sc, rawx, rawy);
251 1.1.8.2 simonb
252 1.1.8.2 simonb callout_reset(&sc->sc_tpcallout, hz / 32, j720tp_wsmouse_callout, sc);
253 1.1.8.2 simonb
254 1.1.8.2 simonb return 1;
255 1.1.8.2 simonb }
256 1.1.8.2 simonb
257 1.1.8.2 simonb static int
258 1.1.8.2 simonb j720tp_get_rawxy(struct j720tp_softc *sc, int *rawx, int *rawy)
259 1.1.8.2 simonb {
260 1.1.8.2 simonb struct j720ssp_softc *ssp = sc->sc_ssp;
261 1.1.8.2 simonb int buf[8], data, i;
262 1.1.8.2 simonb
263 1.1.8.2 simonb bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PCR, 0x2000000);
264 1.1.8.2 simonb
265 1.1.8.2 simonb /* Send read touch-panel command. */
266 1.1.8.2 simonb if (j720ssp_readwrite(ssp, 1, 0x500, &data, 100) < 0 || data != 0x88) {
267 1.1.8.2 simonb DPRINTF(("j720tp_get_rawxy: no dummy received\n"));
268 1.1.8.2 simonb goto out;
269 1.1.8.2 simonb }
270 1.1.8.2 simonb
271 1.1.8.2 simonb for (i = 0; i < 8; i++) {
272 1.1.8.2 simonb if (j720ssp_readwrite(ssp, 0, 0x8800, &data, 100) < 0)
273 1.1.8.2 simonb goto out;
274 1.1.8.2 simonb J720SSP_INVERT(data);
275 1.1.8.2 simonb buf[i] = data;
276 1.1.8.2 simonb }
277 1.1.8.2 simonb
278 1.1.8.2 simonb bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PSR, 0x2000000);
279 1.1.8.2 simonb
280 1.1.8.2 simonb buf[6] <<= 8;
281 1.1.8.2 simonb buf[7] <<= 8;
282 1.1.8.2 simonb for (i = 0; i < 3; i++) {
283 1.1.8.2 simonb buf[i] |= buf[6] & 0x300;
284 1.1.8.2 simonb buf[6] >>= 2;
285 1.1.8.2 simonb buf[i + 3] |= buf[7] & 0x300;
286 1.1.8.2 simonb buf[7] >>= 2;
287 1.1.8.2 simonb }
288 1.1.8.2 simonb
289 1.1.8.2 simonb #if 0
290 1.1.8.2 simonb DPRINTF(("j720tp_get_rawxy: %d:%d:%d:%d:%d:%d:%d:%d\n", buf[0], buf[1],
291 1.1.8.2 simonb buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]));
292 1.1.8.2 simonb #endif
293 1.1.8.2 simonb
294 1.1.8.2 simonb *rawx = buf[1];
295 1.1.8.2 simonb *rawy = buf[4];
296 1.1.8.2 simonb
297 1.1.8.2 simonb return 1;
298 1.1.8.2 simonb out:
299 1.1.8.2 simonb bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PSR, 0x2000000);
300 1.1.8.2 simonb
301 1.1.8.2 simonb /* reset SSP */
302 1.1.8.2 simonb bus_space_write_4(ssp->sc_iot, ssp->sc_ssph, SASSP_CR0, 0x307);
303 1.1.8.2 simonb delay(100);
304 1.1.8.2 simonb bus_space_write_4(ssp->sc_iot, ssp->sc_ssph, SASSP_CR0, 0x387);
305 1.1.8.2 simonb
306 1.1.8.2 simonb DPRINTF(("j720tp_get_rawxy: error %x\n", data));
307 1.1.8.2 simonb return 0;
308 1.1.8.2 simonb }
309 1.1.8.2 simonb
310 1.1.8.2 simonb static void
311 1.1.8.2 simonb j720tp_wsmouse_input(struct j720tp_softc *sc, int rawx, int rawy)
312 1.1.8.2 simonb {
313 1.1.8.2 simonb int x, y;
314 1.1.8.2 simonb
315 1.1.8.2 simonb tpcalib_trans(&sc->sc_tpcalib, rawx, rawy, &x, &y);
316 1.1.8.2 simonb wsmouse_input(sc->sc_wsmousedev, 1, x, y, 0,
317 1.1.8.2 simonb WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
318 1.1.8.2 simonb }
319 1.1.8.2 simonb
320 1.1.8.2 simonb static void
321 1.1.8.2 simonb j720tp_wsmouse_callout(void *arg)
322 1.1.8.2 simonb {
323 1.1.8.2 simonb struct j720tp_softc *sc = arg;
324 1.1.8.2 simonb struct j720ssp_softc *ssp = sc->sc_ssp;
325 1.1.8.2 simonb int rawx, rawy, s;
326 1.1.8.2 simonb
327 1.1.8.2 simonb s = spltty();
328 1.1.8.2 simonb
329 1.1.8.2 simonb if (!sc->sc_enabled) {
330 1.1.8.2 simonb DPRINTF(("j720tp_wsmouse_callout: !sc_enabled\n"));
331 1.1.8.2 simonb splx(s);
332 1.1.8.2 simonb return;
333 1.1.8.2 simonb }
334 1.1.8.2 simonb
335 1.1.8.2 simonb if (bus_space_read_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PLR) & (1<<9)) {
336 1.1.8.2 simonb wsmouse_input(sc->sc_wsmousedev, 0, 0, 0, 0, 0);
337 1.1.8.2 simonb j720tp_enable_intr(sc);
338 1.1.8.2 simonb } else {
339 1.1.8.2 simonb if (j720tp_get_rawxy(sc, &rawx, &rawy))
340 1.1.8.2 simonb j720tp_wsmouse_input(sc, rawx, rawy);
341 1.1.8.2 simonb
342 1.1.8.2 simonb callout_schedule(&sc->sc_tpcallout, hz / 32);
343 1.1.8.2 simonb }
344 1.1.8.2 simonb
345 1.1.8.2 simonb splx(s);
346 1.1.8.2 simonb }
347