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