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