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