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