ucbtp.c revision 1.5 1 1.5 uch /* $NetBSD: ucbtp.c,v 1.5 2001/02/22 18:38:02 uch Exp $ */
2 1.1 uch
3 1.4 uch /*-
4 1.5 uch * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
5 1.5 uch * All rights reserved.
6 1.5 uch *
7 1.5 uch * This code is derived from software contributed to The NetBSD Foundation
8 1.5 uch * by UCHIYAMA Yasushi.
9 1.1 uch *
10 1.1 uch * Redistribution and use in source and binary forms, with or without
11 1.1 uch * modification, are permitted provided that the following conditions
12 1.1 uch * are met:
13 1.1 uch * 1. Redistributions of source code must retain the above copyright
14 1.1 uch * notice, this list of conditions and the following disclaimer.
15 1.4 uch * 2. Redistributions in binary form must reproduce the above copyright
16 1.4 uch * notice, this list of conditions and the following disclaimer in the
17 1.4 uch * documentation and/or other materials provided with the distribution.
18 1.5 uch * 3. All advertising materials mentioning features or use of this software
19 1.5 uch * must display the following acknowledgement:
20 1.5 uch * This product includes software developed by the NetBSD
21 1.5 uch * Foundation, Inc. and its contributors.
22 1.5 uch * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.5 uch * contributors may be used to endorse or promote products derived
24 1.5 uch * from this software without specific prior written permission.
25 1.1 uch *
26 1.5 uch * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.5 uch * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.5 uch * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.5 uch * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.5 uch * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.5 uch * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.5 uch * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.5 uch * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.5 uch * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.5 uch * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.5 uch * POSSIBILITY OF SUCH DAMAGE.
37 1.1 uch */
38 1.1 uch
39 1.1 uch /*
40 1.1 uch * Device driver for PHILIPS UCB1200 Advanced modem/audio analog front-end
41 1.1 uch * Touch panel part.
42 1.1 uch */
43 1.1 uch #define UCBTPDEBUG
44 1.1 uch
45 1.1 uch #include "opt_tx39_debug.h"
46 1.1 uch #include "opt_use_poll.h"
47 1.1 uch
48 1.1 uch #include <sys/param.h>
49 1.1 uch #include <sys/systm.h>
50 1.1 uch #include <sys/device.h>
51 1.1 uch
52 1.1 uch #include <machine/bus.h>
53 1.1 uch #include <machine/intr.h>
54 1.1 uch #include <machine/bootinfo.h> /* bootinfo */
55 1.1 uch
56 1.1 uch #include <dev/wscons/wsconsio.h>
57 1.1 uch #include <dev/wscons/wsmousevar.h>
58 1.1 uch
59 1.5 uch #include <dev/hpc/tpcalibvar.h>
60 1.1 uch
61 1.1 uch #include <hpcmips/tx/tx39var.h>
62 1.1 uch #include <hpcmips/tx/tx39sibvar.h>
63 1.1 uch #include <hpcmips/tx/tx39sibreg.h>
64 1.1 uch #include <hpcmips/tx/tx39icureg.h>
65 1.1 uch
66 1.1 uch #include <hpcmips/dev/ucb1200var.h>
67 1.1 uch #include <hpcmips/dev/ucb1200reg.h>
68 1.1 uch
69 1.1 uch #include <hpcmips/tx/txsnd.h>
70 1.5 uch #include <dev/hpc/video_subr.h> /* debug */
71 1.1 uch
72 1.1 uch #ifdef UCBTPDEBUG
73 1.4 uch int ucbtp_debug = 0;
74 1.1 uch #define DPRINTF(arg) if (ucbtp_debug) printf arg;
75 1.1 uch #define DPRINTFN(n, arg) if (ucbtp_debug > (n)) printf arg;
76 1.1 uch #else
77 1.1 uch #define DPRINTF(arg)
78 1.1 uch #define DPRINTFN(n, arg)
79 1.1 uch #endif
80 1.1 uch
81 1.1 uch enum ucbts_stat {
82 1.1 uch UCBTS_STAT_DISABLE,
83 1.1 uch UCBTS_STAT_RELEASE,
84 1.1 uch UCBTS_STAT_TOUCH,
85 1.1 uch UCBTS_STAT_DRAG,
86 1.1 uch };
87 1.1 uch
88 1.1 uch #define UCBTS_POSX 1
89 1.1 uch #define UCBTS_POSY 2
90 1.1 uch #define UCBTS_PRESS 3
91 1.1 uch
92 1.3 uch #define UCBTS_PRESS_THRESHOLD 80
93 1.1 uch #define UCBTS_TAP_THRESHOLD 5
94 1.1 uch
95 1.1 uch enum ucbadc_state {
96 1.1 uch /* 0 */ UCBADC_IDLE,
97 1.1 uch /* 1 */ UCBADC_ADC_INIT,
98 1.1 uch /* 2 */ UCBADC_ADC_FINI,
99 1.1 uch /* 3 */ UCBADC_MEASUMENT_INIT,
100 1.1 uch /* 4 */ UCBADC_MEASUMENT_FINI,
101 1.1 uch /* 5 */ UCBADC_ADC_ENABLE,
102 1.1 uch /* 6 */ UCBADC_ADC_START0,
103 1.1 uch /* 7 */ UCBADC_ADC_START1,
104 1.1 uch /* 8 */ UCBADC_ADC_DATAREAD,
105 1.1 uch /* 9 */ UCBADC_ADC_DATAREAD_WAIT,
106 1.1 uch /*10 */ UCBADC_ADC_DISABLE,
107 1.1 uch /*11 */ UCBADC_ADC_INTRMODE,
108 1.1 uch /*12 */ UCBADC_ADC_INPUT,
109 1.1 uch /*13 */ UCBADC_INTR_ACK0,
110 1.1 uch /*14 */ UCBADC_INTR_ACK1,
111 1.1 uch /*15 */ UCBADC_INTR_ACK2,
112 1.1 uch /*16 */ UCBADC_REGREAD,
113 1.1 uch /*17 */ UCBADC_REGWRITE
114 1.1 uch };
115 1.1 uch
116 1.1 uch struct ucbtp_softc {
117 1.4 uch struct device sc_dev;
118 1.4 uch struct device *sc_sib; /* parent (TX39 SIB module) */
119 1.4 uch struct device *sc_ucb; /* parent (UCB1200 module) */
120 1.4 uch tx_chipset_tag_t sc_tc;
121 1.1 uch
122 1.1 uch enum ucbts_stat sc_stat;
123 1.1 uch int sc_polling;
124 1.1 uch int sc_polling_finish;
125 1.1 uch void *sc_pollh;
126 1.1 uch
127 1.1 uch struct tpcalib_softc sc_tpcalib;
128 1.1 uch int sc_calibrated;
129 1.1 uch
130 1.1 uch /* measurement value */
131 1.1 uch int sc_x, sc_y, sc_p;
132 1.1 uch int sc_ox, sc_oy;
133 1.4 uch int sc_xy_reverse; /* some platform pin connect interchanged */
134 1.1 uch
135 1.1 uch /*
136 1.1 uch * touch panel state machine
137 1.1 uch */
138 1.4 uch void *sm_ih; /* TX39 SIB subframe 0 interrupt handler */
139 1.1 uch
140 1.4 uch int sm_addr; /* UCB1200 register address */
141 1.4 uch u_int32_t sm_reg; /* UCB1200 register data & TX39 SIB header */
142 1.4 uch int sm_tmpreg;
143 1.3 uch #define UCBADC_RETRY_DEFAULT 200
144 1.4 uch int sm_retry; /* retry counter */
145 1.1 uch
146 1.1 uch enum ucbadc_state sm_state;
147 1.1 uch int sm_measurement; /* X, Y, Pressure */
148 1.1 uch #define UCBADC_MEASUREMENT_X 0
149 1.1 uch #define UCBADC_MEASUREMENT_Y 1
150 1.1 uch #define UCBADC_MEASUREMENT_PRESSURE 2
151 1.4 uch int sm_returnstate;
152 1.1 uch
153 1.4 uch int sm_read_state, sm_write_state;
154 1.4 uch int sm_writing; /* writing state flag */
155 1.4 uch u_int32_t sm_write_val; /* temporary buffer */
156 1.1 uch
157 1.4 uch int sm_rw_retry; /* retry counter for r/w */
158 1.1 uch
159 1.1 uch /* wsmouse */
160 1.1 uch struct device *sc_wsmousedev;
161 1.1 uch };
162 1.1 uch
163 1.1 uch int ucbtp_match __P((struct device*, struct cfdata*, void*));
164 1.1 uch void ucbtp_attach __P((struct device*, struct device*, void*));
165 1.1 uch
166 1.1 uch int ucbtp_sibintr __P((void*));
167 1.1 uch int ucbtp_poll __P((void*));
168 1.1 uch int ucbtp_adc_async __P((void*));
169 1.1 uch int ucbtp_input __P((struct ucbtp_softc*));
170 1.1 uch int ucbtp_busy __P((void*));
171 1.1 uch
172 1.1 uch int ucbtp_enable __P((void*));
173 1.1 uch int ucbtp_ioctl __P((void*, u_long, caddr_t, int, struct proc*));
174 1.1 uch void ucbtp_disable __P((void*));
175 1.1 uch
176 1.1 uch struct cfattach ucbtp_ca = {
177 1.1 uch sizeof(struct ucbtp_softc), ucbtp_match, ucbtp_attach
178 1.1 uch };
179 1.1 uch
180 1.1 uch const struct wsmouse_accessops ucbtp_accessops = {
181 1.1 uch ucbtp_enable,
182 1.1 uch ucbtp_ioctl,
183 1.1 uch ucbtp_disable,
184 1.1 uch };
185 1.1 uch
186 1.1 uch /*
187 1.1 uch * XXX currently no calibration method. this is temporary hack.
188 1.1 uch */
189 1.1 uch #include <machine/platid.h>
190 1.1 uch
191 1.1 uch struct wsmouse_calibcoords *calibration_sample_lookup __P((void));
192 1.1 uch int ucbtp_calibration __P((struct ucbtp_softc*));
193 1.1 uch
194 1.1 uch struct calibration_sample_table {
195 1.1 uch platid_t cst_platform;
196 1.1 uch struct wsmouse_calibcoords cst_sample;
197 1.1 uch } calibration_sample_table[] = {
198 1.1 uch {{{PLATID_WILD, PLATID_MACH_COMPAQ_C_8XX}}, /* uch machine */
199 1.1 uch { 0, 0, 639, 239, 5,
200 1.1 uch {{ 507, 510, 320, 120 },
201 1.1 uch { 898, 757, 40, 40 },
202 1.1 uch { 900, 255, 40, 200 },
203 1.1 uch { 109, 249, 600, 200 },
204 1.1 uch { 110, 753, 600, 40 }}}},
205 1.1 uch
206 1.1 uch {{{PLATID_WILD, PLATID_MACH_COMPAQ_C_2010}}, /* uch machine */
207 1.1 uch { 0, 0, 639, 239, 5,
208 1.1 uch {{ 506, 487, 320, 120 },
209 1.1 uch { 880, 250, 40, 40 },
210 1.1 uch { 880, 718, 40, 200 },
211 1.1 uch { 140, 726, 600, 200 },
212 1.1 uch { 137, 250, 600, 40 }}}},
213 1.1 uch
214 1.1 uch {{{PLATID_WILD, PLATID_MACH_SHARP_MOBILON_HC4100}}, /* uch machine */
215 1.1 uch { 0, 0, 639, 239, 5,
216 1.1 uch {{ 497, 501, 320, 120 },
217 1.1 uch { 752, 893, 40, 40 },
218 1.1 uch { 242, 891, 40, 200 },
219 1.1 uch { 241, 115, 600, 200 },
220 1.1 uch { 747, 101, 600, 40 }}}},
221 1.1 uch
222 1.4 uch {{{PLATID_WILD, PLATID_MACH_SHARP_TELIOS_HCAJ1}}, /* uch machine */
223 1.4 uch { 0, 0, 799, 479, 5,
224 1.4 uch {{ 850, 150, 1, 1 },
225 1.4 uch { 850, 880, 1, 479 },
226 1.4 uch { 850, 880, 1, 479 },
227 1.4 uch { 85, 880, 799, 479 },
228 1.4 uch { 85, 150, 799, 1 }}}},
229 1.4 uch
230 1.1 uch {{{PLATID_UNKNOWN, PLATID_UNKNOWN}},
231 1.1 uch { 0, 0, 639, 239, 5,
232 1.1 uch {{0, 0, 0, 0},
233 1.1 uch {0, 0, 0, 0},
234 1.1 uch {0, 0, 0, 0},
235 1.1 uch {0, 0, 0, 0},
236 1.1 uch {0, 0, 0, 0}}}},
237 1.1 uch };
238 1.1 uch
239 1.1 uch struct wsmouse_calibcoords *
240 1.1 uch calibration_sample_lookup()
241 1.1 uch {
242 1.1 uch struct calibration_sample_table *tab;
243 1.1 uch platid_mask_t mask;
244 1.1 uch
245 1.1 uch for (tab = calibration_sample_table;
246 1.1 uch tab->cst_platform.dw.dw1 != PLATID_UNKNOWN; tab++) {
247 1.1 uch
248 1.1 uch mask = PLATID_DEREF(&tab->cst_platform);
249 1.1 uch
250 1.1 uch if (platid_match(&platid, &mask)) {
251 1.4 uch return (&tab->cst_sample);
252 1.1 uch }
253 1.1 uch }
254 1.1 uch
255 1.4 uch return (0);
256 1.1 uch }
257 1.1 uch
258 1.1 uch int
259 1.1 uch ucbtp_calibration(sc)
260 1.1 uch struct ucbtp_softc *sc;
261 1.1 uch {
262 1.1 uch struct wsmouse_calibcoords *cs;
263 1.4 uch
264 1.4 uch if (sc->sc_tc->tc_videot)
265 1.4 uch video_calibration_pattern(sc->sc_tc->tc_videot); /* debug */
266 1.4 uch
267 1.1 uch tpcalib_init(&sc->sc_tpcalib);
268 1.1 uch
269 1.1 uch if (!(cs = calibration_sample_lookup())) {
270 1.4 uch DPRINTF(("no calibration data"));
271 1.4 uch return (1);
272 1.1 uch }
273 1.1 uch
274 1.1 uch sc->sc_calibrated =
275 1.1 uch tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
276 1.1 uch (caddr_t)cs, 0, 0) == 0 ? 1 : 0;
277 1.1 uch
278 1.1 uch if (!sc->sc_calibrated)
279 1.1 uch printf("not ");
280 1.1 uch printf("calibrated");
281 1.1 uch
282 1.4 uch return (0);
283 1.1 uch }
284 1.1 uch
285 1.1 uch int
286 1.1 uch ucbtp_match(parent, cf, aux)
287 1.1 uch struct device *parent;
288 1.1 uch struct cfdata *cf;
289 1.1 uch void *aux;
290 1.1 uch {
291 1.4 uch return (1);
292 1.1 uch }
293 1.1 uch
294 1.1 uch void
295 1.1 uch ucbtp_attach(parent, self, aux)
296 1.1 uch struct device *parent;
297 1.1 uch struct device *self;
298 1.1 uch void *aux;
299 1.1 uch {
300 1.1 uch struct ucb1200_attach_args *ucba = aux;
301 1.1 uch struct ucbtp_softc *sc = (void*)self;
302 1.1 uch struct wsmousedev_attach_args wsmaa;
303 1.1 uch tx_chipset_tag_t tc;
304 1.1 uch
305 1.1 uch tc = sc->sc_tc = ucba->ucba_tc;
306 1.1 uch sc->sc_sib = ucba->ucba_sib;
307 1.1 uch sc->sc_ucb = ucba->ucba_ucb;
308 1.1 uch
309 1.1 uch printf(": ");
310 1.1 uch /* touch panel interrupt */
311 1.1 uch tx_intr_establish(tc, MAKEINTR(1, TX39_INTRSTATUS1_SIBIRQPOSINT),
312 1.1 uch IST_EDGE, IPL_TTY, ucbtp_sibintr, sc);
313 1.1 uch
314 1.1 uch /* attempt to calibrate touch panel */
315 1.1 uch ucbtp_calibration(sc);
316 1.4 uch #ifdef TX392X /* hack for Telios HC-VJ1C */
317 1.4 uch sc->sc_xy_reverse = 1;
318 1.4 uch #endif
319 1.4 uch
320 1.1 uch printf("\n");
321 1.1 uch
322 1.1 uch wsmaa.accessops = &ucbtp_accessops;
323 1.1 uch wsmaa.accesscookie = sc;
324 1.1 uch
325 1.1 uch ucb1200_state_install(parent, ucbtp_busy, self, UCB1200_TP_MODULE);
326 1.1 uch
327 1.1 uch /*
328 1.1 uch * attach the wsmouse
329 1.1 uch */
330 1.1 uch sc->sc_wsmousedev = config_found(self, &wsmaa, wsmousedevprint);
331 1.1 uch }
332 1.1 uch
333 1.1 uch int
334 1.1 uch ucbtp_busy(arg)
335 1.1 uch void *arg;
336 1.1 uch {
337 1.1 uch struct ucbtp_softc *sc = arg;
338 1.1 uch
339 1.4 uch return (sc->sm_state != UCBADC_IDLE);
340 1.1 uch }
341 1.1 uch
342 1.1 uch int
343 1.1 uch ucbtp_poll(arg)
344 1.1 uch void *arg;
345 1.1 uch {
346 1.1 uch struct ucbtp_softc *sc = arg;
347 1.1 uch
348 1.1 uch if (!ucb1200_state_idle(sc->sc_ucb)) /* subframe0 busy */
349 1.4 uch return (POLL_CONT);
350 1.1 uch
351 1.1 uch if (sc->sc_polling_finish) {
352 1.1 uch sc->sc_polling_finish = 0;
353 1.4 uch return (POLL_END);
354 1.1 uch }
355 1.1 uch
356 1.1 uch /* execute A-D converter */
357 1.1 uch sc->sm_state = UCBADC_ADC_INIT;
358 1.1 uch ucbtp_adc_async(sc);
359 1.1 uch
360 1.4 uch return (POLL_CONT);
361 1.1 uch }
362 1.1 uch
363 1.1 uch int
364 1.1 uch ucbtp_sibintr(arg)
365 1.1 uch void *arg;
366 1.1 uch {
367 1.1 uch struct ucbtp_softc *sc = arg;
368 1.1 uch
369 1.1 uch sc->sc_stat = UCBTS_STAT_TOUCH;
370 1.1 uch
371 1.1 uch /* click! */
372 1.1 uch tx_sound_click(sc->sc_tc);
373 1.1 uch
374 1.1 uch /* invoke touch panel polling */
375 1.1 uch if (!sc->sc_polling) {
376 1.1 uch sc->sc_pollh = tx39_poll_establish(sc->sc_tc, 1, IST_EDGE,
377 1.1 uch ucbtp_poll, sc);
378 1.1 uch if (!sc->sc_pollh) {
379 1.1 uch printf("%s: can't poll\n", sc->sc_dev.dv_xname);
380 1.1 uch }
381 1.1 uch }
382 1.1 uch
383 1.1 uch /* don't acknoledge interrupt until polling finish */
384 1.1 uch
385 1.4 uch return (0);
386 1.1 uch }
387 1.1 uch
388 1.4 uch #define REGWRITE(addr, reg, ret) ( \
389 1.4 uch sc->sm_addr = (addr), \
390 1.4 uch sc->sm_reg = (reg), \
391 1.4 uch sc->sm_returnstate = (ret), \
392 1.1 uch sc->sm_state = UCBADC_REGWRITE)
393 1.4 uch #define REGREAD(addr, ret) ( \
394 1.4 uch sc->sm_addr = (addr), \
395 1.4 uch sc->sm_returnstate = (ret), \
396 1.1 uch sc->sm_state = UCBADC_REGREAD)
397 1.1 uch
398 1.1 uch int
399 1.1 uch ucbtp_adc_async(arg)
400 1.1 uch void *arg;
401 1.1 uch {
402 1.1 uch struct ucbtp_softc *sc = arg;
403 1.1 uch tx_chipset_tag_t tc = sc->sc_tc;
404 1.1 uch txreg_t reg;
405 1.1 uch u_int16_t reg16;
406 1.1 uch
407 1.1 uch DPRINTFN(9, ("state: %d\n", sc->sm_state));
408 1.1 uch
409 1.1 uch switch (sc->sm_state) {
410 1.1 uch default:
411 1.1 uch panic("ucbtp_adc: invalid state %d", sc->sm_state);
412 1.1 uch /* NOTREACHED */
413 1.1 uch break;
414 1.1 uch
415 1.1 uch case UCBADC_IDLE:
416 1.1 uch /* nothing to do */
417 1.1 uch break;
418 1.1 uch
419 1.1 uch case UCBADC_ADC_INIT:
420 1.1 uch sc->sc_polling++;
421 1.1 uch sc->sc_stat = UCBTS_STAT_DRAG;
422 1.1 uch /* enable heart beat of this state machine */
423 1.1 uch sc->sm_ih = tx_intr_establish(
424 1.1 uch tc,
425 1.1 uch MAKEINTR(1, TX39_INTRSTATUS1_SIBSF0INT),
426 1.1 uch IST_EDGE, IPL_TTY, ucbtp_adc_async, sc);
427 1.1 uch
428 1.1 uch sc->sm_state = UCBADC_MEASUMENT_INIT;
429 1.1 uch break;
430 1.1 uch
431 1.1 uch case UCBADC_ADC_FINI:
432 1.1 uch /* disable heart beat of this state machine */
433 1.1 uch tx_intr_disestablish(tc, sc->sm_ih);
434 1.1 uch sc->sm_state = UCBADC_IDLE;
435 1.1 uch break;
436 1.1 uch
437 1.1 uch case UCBADC_MEASUMENT_INIT:
438 1.1 uch switch (sc->sm_measurement) {
439 1.1 uch default:
440 1.1 uch panic("unknown measurement spec.");
441 1.1 uch /* NOTREACHED */
442 1.1 uch break;
443 1.1 uch case UCBADC_MEASUREMENT_X:
444 1.1 uch REGWRITE(UCB1200_TSCTRL_REG,
445 1.1 uch UCB1200_TSCTRL_XPOSITION,
446 1.1 uch UCBADC_ADC_ENABLE);
447 1.1 uch break;
448 1.1 uch case UCBADC_MEASUREMENT_Y:
449 1.1 uch REGWRITE(UCB1200_TSCTRL_REG,
450 1.1 uch UCB1200_TSCTRL_YPOSITION,
451 1.1 uch UCBADC_ADC_ENABLE);
452 1.1 uch break;
453 1.1 uch case UCBADC_MEASUREMENT_PRESSURE:
454 1.1 uch REGWRITE(UCB1200_TSCTRL_REG,
455 1.1 uch UCB1200_TSCTRL_PRESSURE,
456 1.1 uch UCBADC_ADC_ENABLE);
457 1.1 uch break;
458 1.1 uch }
459 1.1 uch break;
460 1.1 uch
461 1.1 uch case UCBADC_MEASUMENT_FINI:
462 1.1 uch switch (sc->sm_measurement) {
463 1.1 uch case UCBADC_MEASUREMENT_X:
464 1.1 uch sc->sm_measurement = UCBADC_MEASUREMENT_Y;
465 1.1 uch sc->sm_state = UCBADC_MEASUMENT_INIT;
466 1.1 uch break;
467 1.1 uch case UCBADC_MEASUREMENT_Y:
468 1.1 uch sc->sm_measurement = UCBADC_MEASUREMENT_PRESSURE;
469 1.1 uch sc->sm_state = UCBADC_MEASUMENT_INIT;
470 1.1 uch break;
471 1.1 uch case UCBADC_MEASUREMENT_PRESSURE:
472 1.1 uch sc->sm_measurement = UCBADC_MEASUREMENT_X;
473 1.1 uch /* measument complete. pass down to wsmouse_input */
474 1.1 uch sc->sm_state = UCBADC_ADC_INPUT;
475 1.1 uch break;
476 1.1 uch }
477 1.1 uch break;
478 1.1 uch
479 1.1 uch case UCBADC_ADC_ENABLE:
480 1.1 uch switch (sc->sm_measurement) {
481 1.1 uch case UCBADC_MEASUREMENT_PRESSURE:
482 1.1 uch /* FALLTHROUGH */
483 1.1 uch case UCBADC_MEASUREMENT_X:
484 1.1 uch sc->sm_tmpreg = UCB1200_ADCCTRL_INPUT_SET(
485 1.1 uch UCB1200_ADCCTRL_ENABLE,
486 1.1 uch UCB1200_ADCCTRL_INPUT_TSPX);
487 1.1 uch REGWRITE(UCB1200_ADCCTRL_REG, sc->sm_tmpreg,
488 1.1 uch UCBADC_ADC_START0);
489 1.1 uch break;
490 1.1 uch case UCBADC_MEASUREMENT_Y:
491 1.1 uch sc->sm_tmpreg = UCB1200_ADCCTRL_INPUT_SET(
492 1.1 uch UCB1200_ADCCTRL_ENABLE,
493 1.1 uch UCB1200_ADCCTRL_INPUT_TSPY);
494 1.1 uch REGWRITE(UCB1200_ADCCTRL_REG, sc->sm_tmpreg,
495 1.1 uch UCBADC_ADC_START0);
496 1.1 uch break;
497 1.1 uch }
498 1.1 uch break;
499 1.1 uch
500 1.1 uch case UCBADC_ADC_START0:
501 1.1 uch REGWRITE(UCB1200_ADCCTRL_REG,
502 1.1 uch sc->sm_tmpreg | UCB1200_ADCCTRL_START,
503 1.1 uch UCBADC_ADC_START1);
504 1.1 uch break;
505 1.1 uch
506 1.1 uch case UCBADC_ADC_START1:
507 1.1 uch REGWRITE(UCB1200_ADCCTRL_REG,
508 1.1 uch sc->sm_tmpreg,
509 1.1 uch UCBADC_ADC_DATAREAD);
510 1.3 uch sc->sm_retry = UCBADC_RETRY_DEFAULT;
511 1.1 uch break;
512 1.1 uch
513 1.1 uch case UCBADC_ADC_DATAREAD:
514 1.1 uch REGREAD(UCB1200_ADCDATA_REG, UCBADC_ADC_DATAREAD_WAIT);
515 1.1 uch break;
516 1.1 uch
517 1.1 uch case UCBADC_ADC_DATAREAD_WAIT:
518 1.1 uch reg16 = TX39_SIBSF0_REGDATA(sc->sm_reg);
519 1.1 uch if (!(reg16 & UCB1200_ADCDATA_INPROGRESS) &&
520 1.1 uch --sc->sm_retry > 0) {
521 1.1 uch sc->sm_state = UCBADC_ADC_DATAREAD;
522 1.1 uch } else {
523 1.1 uch if (sc->sm_retry <= 0) {
524 1.1 uch printf("dataread failed\n");
525 1.1 uch sc->sm_state = UCBADC_ADC_FINI;
526 1.1 uch break;
527 1.1 uch }
528 1.1 uch
529 1.1 uch switch (sc->sm_measurement) {
530 1.1 uch case UCBADC_MEASUREMENT_X:
531 1.1 uch sc->sc_x = UCB1200_ADCDATA(reg16);
532 1.1 uch DPRINTFN(9, ("x=%d\n", sc->sc_x));
533 1.1 uch break;
534 1.1 uch case UCBADC_MEASUREMENT_Y:
535 1.1 uch sc->sc_y = UCB1200_ADCDATA(reg16);
536 1.1 uch DPRINTFN(9, ("y=%d\n", sc->sc_y));
537 1.1 uch break;
538 1.1 uch case UCBADC_MEASUREMENT_PRESSURE:
539 1.1 uch sc->sc_p = UCB1200_ADCDATA(reg16);
540 1.1 uch DPRINTFN(9, ("p=%d\n", sc->sc_p));
541 1.1 uch break;
542 1.1 uch }
543 1.1 uch
544 1.1 uch sc->sm_state = UCBADC_ADC_DISABLE;
545 1.1 uch }
546 1.1 uch
547 1.1 uch break;
548 1.1 uch
549 1.1 uch case UCBADC_ADC_DISABLE:
550 1.1 uch REGWRITE(UCB1200_ADCCTRL_REG, 0, UCBADC_ADC_INTRMODE);
551 1.1 uch
552 1.1 uch break;
553 1.1 uch case UCBADC_ADC_INTRMODE:
554 1.1 uch REGWRITE(UCB1200_TSCTRL_REG, UCB1200_TSCTRL_INTERRUPT,
555 1.1 uch UCBADC_MEASUMENT_FINI);
556 1.1 uch break;
557 1.1 uch
558 1.1 uch case UCBADC_ADC_INPUT:
559 1.1 uch if (ucbtp_input(sc) == 0)
560 1.1 uch sc->sm_state = UCBADC_ADC_FINI;
561 1.1 uch else
562 1.1 uch sc->sm_state = UCBADC_INTR_ACK0;
563 1.1 uch break;
564 1.1 uch
565 1.1 uch case UCBADC_INTR_ACK0:
566 1.1 uch REGREAD(UCB1200_INTSTAT_REG, UCBADC_INTR_ACK1);
567 1.1 uch break;
568 1.1 uch
569 1.1 uch case UCBADC_INTR_ACK1:
570 1.1 uch REGWRITE(UCB1200_INTSTAT_REG, sc->sm_reg, UCBADC_INTR_ACK2);
571 1.1 uch break;
572 1.1 uch
573 1.1 uch case UCBADC_INTR_ACK2:
574 1.1 uch sc->sc_polling_finish = 1;
575 1.1 uch REGWRITE(UCB1200_INTSTAT_REG, 0, UCBADC_ADC_FINI);
576 1.1 uch break;
577 1.1 uch
578 1.1 uch /*
579 1.1 uch * UCB1200 register access state
580 1.1 uch */
581 1.1 uch case UCBADC_REGREAD:
582 1.1 uch /*
583 1.1 uch * In : sc->sm_addr
584 1.1 uch * Out : sc->sm_reg (with SIBtag)
585 1.1 uch */
586 1.1 uch #define TXSIB_REGREAD_INIT 0
587 1.1 uch #define TXSIB_REGREAD_READ 1
588 1.1 uch switch (sc->sm_read_state) {
589 1.1 uch case TXSIB_REGREAD_INIT:
590 1.1 uch reg = TX39_SIBSF0_REGADDR_SET(0, sc->sm_addr);
591 1.1 uch tx_conf_write(tc, TX39_SIBSF0CTRL_REG, reg);
592 1.3 uch sc->sm_rw_retry = UCBADC_RETRY_DEFAULT;
593 1.1 uch sc->sm_read_state = TXSIB_REGREAD_READ;
594 1.1 uch break;
595 1.1 uch case TXSIB_REGREAD_READ:
596 1.1 uch reg = tx_conf_read(tc, TX39_SIBSF0STAT_REG);
597 1.1 uch if ((TX39_SIBSF0_REGADDR(reg) != sc->sm_addr) &&
598 1.1 uch --sc->sm_rw_retry > 0) {
599 1.1 uch break;
600 1.1 uch }
601 1.1 uch
602 1.1 uch if (sc->sm_rw_retry <= 0) {
603 1.1 uch printf("sf0read: command failed\n");
604 1.1 uch sc->sm_state = UCBADC_ADC_FINI;
605 1.1 uch } else {
606 1.1 uch sc->sm_reg = reg;
607 1.1 uch sc->sm_read_state = TXSIB_REGREAD_INIT;
608 1.1 uch DPRINTFN(9, ("%08x\n", reg));
609 1.1 uch if (sc->sm_writing)
610 1.1 uch sc->sm_state = UCBADC_REGWRITE;
611 1.1 uch else
612 1.1 uch sc->sm_state = sc->sm_returnstate;
613 1.1 uch }
614 1.1 uch break;
615 1.1 uch }
616 1.1 uch break;
617 1.1 uch
618 1.1 uch case UCBADC_REGWRITE:
619 1.1 uch /*
620 1.1 uch * In : sc->sm_addr, sc->sm_reg (lower 16bit only)
621 1.1 uch */
622 1.1 uch #define TXSIB_REGWRITE_INIT 0
623 1.1 uch #define TXSIB_REGWRITE_WRITE 1
624 1.1 uch switch (sc->sm_write_state) {
625 1.1 uch case TXSIB_REGWRITE_INIT:
626 1.1 uch sc->sm_writing = 1;
627 1.1 uch sc->sm_write_state = TXSIB_REGWRITE_WRITE;
628 1.1 uch sc->sm_state = UCBADC_REGREAD;
629 1.1 uch
630 1.1 uch sc->sm_write_val = sc->sm_reg;
631 1.1 uch break;
632 1.1 uch case TXSIB_REGWRITE_WRITE:
633 1.1 uch sc->sm_writing = 0;
634 1.1 uch sc->sm_write_state = TXSIB_REGWRITE_INIT;
635 1.1 uch sc->sm_state = sc->sm_returnstate;
636 1.1 uch
637 1.1 uch reg = sc->sm_reg;
638 1.1 uch reg |= TX39_SIBSF0_WRITE;
639 1.1 uch TX39_SIBSF0_REGDATA_CLR(reg);
640 1.1 uch reg = TX39_SIBSF0_REGDATA_SET(reg, sc->sm_write_val);
641 1.1 uch tx_conf_write(tc, TX39_SIBSF0CTRL_REG, reg);
642 1.1 uch break;
643 1.1 uch }
644 1.1 uch break;
645 1.1 uch }
646 1.1 uch
647 1.4 uch return (0);
648 1.1 uch }
649 1.1 uch
650 1.1 uch int
651 1.1 uch ucbtp_input(sc)
652 1.1 uch struct ucbtp_softc *sc;
653 1.1 uch {
654 1.4 uch int rx, ry, x, y, p;
655 1.4 uch
656 1.4 uch rx = sc->sc_x;
657 1.4 uch ry = sc->sc_y;
658 1.4 uch p = sc->sc_p;
659 1.1 uch
660 1.3 uch if (!sc->sc_calibrated) {
661 1.4 uch DPRINTFN(2, ("x=%4d y=%4d p=%4d\n", rx, ry, p));
662 1.4 uch DPRINTF(("ucbtp_input: no calibration data\n"));
663 1.1 uch }
664 1.1 uch
665 1.4 uch if (p < UCBTS_PRESS_THRESHOLD || rx == 0x3ff || ry == 0x3ff ||
666 1.4 uch rx == 0 || ry == 0) {
667 1.1 uch sc->sc_stat = UCBTS_STAT_RELEASE;
668 1.1 uch if (sc->sc_polling < UCBTS_TAP_THRESHOLD) {
669 1.3 uch DPRINTFN(2, ("TAP!\n"));
670 1.1 uch /* button 0 DOWN */
671 1.1 uch wsmouse_input(sc->sc_wsmousedev, 1, 0, 0, 0, 0);
672 1.1 uch /* button 0 UP */
673 1.1 uch wsmouse_input(sc->sc_wsmousedev, 0, 0, 0, 0, 0);
674 1.1 uch } else {
675 1.1 uch wsmouse_input(sc->sc_wsmousedev, 0,
676 1.1 uch sc->sc_ox, sc->sc_oy, 0,
677 1.1 uch WSMOUSE_INPUT_ABSOLUTE_X |
678 1.1 uch WSMOUSE_INPUT_ABSOLUTE_Y);
679 1.1 uch
680 1.3 uch DPRINTFN(2, ("RELEASE\n"));
681 1.1 uch }
682 1.1 uch sc->sc_polling = 0;
683 1.1 uch
684 1.4 uch return (1);
685 1.4 uch }
686 1.4 uch
687 1.4 uch if (sc->sc_xy_reverse)
688 1.4 uch tpcalib_trans(&sc->sc_tpcalib, ry, rx, &x, &y);
689 1.4 uch else
690 1.4 uch tpcalib_trans(&sc->sc_tpcalib, rx, ry, &x, &y);
691 1.4 uch
692 1.4 uch DPRINTFN(2, ("x: %4d->%4d y: %4d->%4d pressure=%4d\n",
693 1.4 uch rx, x, ry, y, p));
694 1.4 uch
695 1.4 uch /* debug draw */
696 1.4 uch if (sc->sc_tc->tc_videot) {
697 1.4 uch if (sc->sc_polling == 1)
698 1.4 uch video_dot(sc->sc_tc->tc_videot, x, y);
699 1.4 uch else
700 1.4 uch video_line(sc->sc_tc->tc_videot, sc->sc_ox,
701 1.4 uch sc->sc_oy, x, y);
702 1.1 uch }
703 1.1 uch
704 1.1 uch sc->sc_ox = x, sc->sc_oy = y;
705 1.4 uch
706 1.1 uch wsmouse_input(sc->sc_wsmousedev, 1, x, y, 0,
707 1.1 uch WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
708 1.1 uch
709 1.4 uch return (0);
710 1.1 uch }
711 1.1 uch
712 1.1 uch /*
713 1.1 uch * access ops.
714 1.1 uch */
715 1.1 uch
716 1.1 uch int
717 1.1 uch ucbtp_enable(v)
718 1.1 uch void *v;
719 1.1 uch {
720 1.1 uch /* not yet */
721 1.4 uch return (0);
722 1.1 uch }
723 1.1 uch
724 1.1 uch void
725 1.1 uch ucbtp_disable(v)
726 1.1 uch void *v;
727 1.1 uch {
728 1.1 uch /* not yet */
729 1.1 uch }
730 1.1 uch
731 1.1 uch int
732 1.1 uch ucbtp_ioctl(v, cmd, data, flag, p)
733 1.1 uch void *v;
734 1.1 uch u_long cmd;
735 1.1 uch caddr_t data;
736 1.1 uch int flag;
737 1.1 uch struct proc *p;
738 1.1 uch {
739 1.1 uch struct ucbtp_softc *sc = v;
740 1.1 uch
741 1.1 uch DPRINTF(("%s(%d): ucbtp_ioctl(%08lx)\n", __FILE__, __LINE__, cmd));
742 1.1 uch
743 1.1 uch switch (cmd) {
744 1.1 uch case WSMOUSEIO_GTYPE:
745 1.1 uch *(u_int *)data = WSMOUSE_TYPE_TPANEL;
746 1.1 uch break;
747 1.1 uch
748 1.1 uch case WSMOUSEIO_SRES:
749 1.1 uch printf("%s(%d): WSMOUSRIO_SRES is not supported",
750 1.1 uch __FILE__, __LINE__);
751 1.1 uch break;
752 1.1 uch
753 1.1 uch case WSMOUSEIO_SCALIBCOORDS:
754 1.1 uch case WSMOUSEIO_GCALIBCOORDS:
755 1.1 uch return tpcalib_ioctl(&sc->sc_tpcalib, cmd, data, flag, p);
756 1.1 uch
757 1.1 uch default:
758 1.1 uch return (-1);
759 1.1 uch }
760 1.4 uch
761 1.1 uch return (0);
762 1.1 uch }
763