uart_dev_sab82532.c revision 119815
1/* 2 * Copyright (c) 2003 Marcel Moolenaar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> 28__FBSDID("$FreeBSD: head/sys/dev/uart/uart_dev_sab82532.c 119815 2003-09-06 23:13:47Z marcel $"); 29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/bus.h> 33#include <sys/conf.h> 34#include <machine/bus.h> 35 36#include <dev/uart/uart.h> 37#include <dev/uart/uart_cpu.h> 38#include <dev/uart/uart_bus.h> 39#include <dev/uart/uart_dev_sab82532.h> 40 41#include "uart_if.h" 42 43#define DEFAULT_RCLK 29491200 44 45#define IS_CHANNEL_A(bas) (((bas)->bsh & 0x40) == 0x00) 46#define IS_CHANNEL_B(bas) (((bas)->bsh & 0x40) == 0x40) 47 48/* 49 * NOTE: To allow us to read the baudrate divisor from the chip, we 50 * copy the value written to the write-only BGR register to an unused 51 * read-write register. We use TCR for that. 52 */ 53 54static int 55sab82532_delay(struct uart_bas *bas) 56{ 57 int divisor, m, n; 58 uint8_t bgr, ccr2; 59 60 bgr = uart_getreg(bas, SAB_TCR); 61 ccr2 = uart_getreg(bas, SAB_CCR2); 62 n = (bgr & 0x3f) + 1; 63 m = (bgr >> 6) | ((ccr2 >> 4) & 0xC); 64 divisor = n * (1<<m); 65 66 /* 1/10th the time to transmit 1 character (estimate). */ 67 return (16000000 * divisor / bas->rclk); 68} 69 70static int 71sab82532_divisor(int rclk, int baudrate) 72{ 73 int act_baud, act_div, divisor; 74 int error, m, n; 75 76 if (baudrate == 0) 77 return (0); 78 79 divisor = (rclk / (baudrate << 3) + 1) >> 1; 80 if (divisor < 2 || divisor >= 1048576) 81 return (0); 82 83 /* Find the best (N+1,M) pair. */ 84 for (m = 1; m < 15; m++) { 85 n = divisor / (1<<m); 86 if (n < 1 || n > 63) 87 continue; 88 act_div = n * (1<<m); 89 act_baud = rclk / (act_div << 4); 90 91 /* 10 times error in percent: */ 92 error = ((act_baud - baudrate) * 2000 / baudrate + 1) >> 1; 93 94 /* 3.0% maximum error tolerance: */ 95 if (error < -30 || error > 30) 96 continue; 97 98 /* Got it. */ 99 return ((n - 1) | (m << 6)); 100 } 101 102 return (0); 103} 104 105static void 106sab82532_flush(struct uart_bas *bas, int what) 107{ 108 109 if (what & UART_FLUSH_TRANSMITTER) { 110 while (uart_getreg(bas, SAB_STAR) & SAB_STAR_CEC) 111 ; 112 uart_setreg(bas, SAB_CMDR, SAB_CMDR_XRES); 113 uart_barrier(bas); 114 } 115 if (what & UART_FLUSH_RECEIVER) { 116 while (uart_getreg(bas, SAB_STAR) & SAB_STAR_CEC) 117 ; 118 uart_setreg(bas, SAB_CMDR, SAB_CMDR_RRES); 119 uart_barrier(bas); 120 } 121} 122 123static int 124sab82532_param(struct uart_bas *bas, int baudrate, int databits, int stopbits, 125 int parity) 126{ 127 int divisor; 128 uint8_t ccr2, dafo; 129 130 if (databits >= 8) 131 dafo = SAB_DAFO_CHL_CS8; 132 else if (databits == 7) 133 dafo = SAB_DAFO_CHL_CS7; 134 else if (databits == 6) 135 dafo = SAB_DAFO_CHL_CS6; 136 else 137 dafo = SAB_DAFO_CHL_CS5; 138 if (stopbits > 1) 139 dafo |= SAB_DAFO_STOP; 140 switch (parity) { 141 case UART_PARITY_EVEN: dafo |= SAB_DAFO_PAR_EVEN; break; 142 case UART_PARITY_MARK: dafo |= SAB_DAFO_PAR_MARK; break; 143 case UART_PARITY_NONE: dafo |= SAB_DAFO_PAR_NONE; break; 144 case UART_PARITY_ODD: dafo |= SAB_DAFO_PAR_ODD; break; 145 case UART_PARITY_SPACE: dafo |= SAB_DAFO_PAR_SPACE; break; 146 default: return (EINVAL); 147 } 148 149 /* Set baudrate. */ 150 if (baudrate > 0) { 151 divisor = sab82532_divisor(bas->rclk, baudrate); 152 if (divisor == 0) 153 return (EINVAL); 154 uart_setreg(bas, SAB_BGR, divisor & 0xff); 155 uart_barrier(bas); 156 /* Allow reading the (n-1,m) tuple from the chip. */ 157 uart_setreg(bas, SAB_TCR, divisor & 0xff); 158 uart_barrier(bas); 159 ccr2 = uart_getreg(bas, SAB_CCR2); 160 ccr2 &= ~(SAB_CCR2_BR9 | SAB_CCR2_BR8); 161 ccr2 |= (divisor >> 2) & (SAB_CCR2_BR9 | SAB_CCR2_BR8); 162 uart_setreg(bas, SAB_CCR2, ccr2); 163 uart_barrier(bas); 164 } 165 166 uart_setreg(bas, SAB_DAFO, dafo); 167 uart_barrier(bas); 168 return (0); 169} 170 171/* 172 * Low-level UART interface. 173 */ 174static int sab82532_probe(struct uart_bas *bas); 175static void sab82532_init(struct uart_bas *bas, int, int, int, int); 176static void sab82532_term(struct uart_bas *bas); 177static void sab82532_putc(struct uart_bas *bas, int); 178static int sab82532_poll(struct uart_bas *bas); 179static int sab82532_getc(struct uart_bas *bas); 180 181struct uart_ops uart_sab82532_ops = { 182 .probe = sab82532_probe, 183 .init = sab82532_init, 184 .term = sab82532_term, 185 .putc = sab82532_putc, 186 .poll = sab82532_poll, 187 .getc = sab82532_getc, 188}; 189 190static int 191sab82532_probe(struct uart_bas *bas) 192{ 193 194 return (0); 195} 196 197static void 198sab82532_init(struct uart_bas *bas, int baudrate, int databits, int stopbits, 199 int parity) 200{ 201 uint8_t ccr0, pvr; 202 203 if (bas->rclk == 0) 204 bas->rclk = DEFAULT_RCLK; 205 206 /* 207 * Set all pins, except the DTR pins (pin 1 and 2) to be inputs. 208 * Pin 4 is magical, meaning that I don't know what it does, but 209 * it too has to be set to output. 210 */ 211 uart_setreg(bas, SAB_PCR, 212 ~(SAB_PVR_DTR_A|SAB_PVR_DTR_B|SAB_PVR_MAGIC)); 213 uart_barrier(bas); 214 /* Disable port interrupts. */ 215 uart_setreg(bas, SAB_PIM, 0xff); 216 uart_barrier(bas); 217 /* Interrupts are active low. */ 218 uart_setreg(bas, SAB_IPC, SAB_IPC_ICPL); 219 uart_barrier(bas); 220 /* Set DTR. */ 221 pvr = uart_getreg(bas, SAB_PVR); 222 pvr &= IS_CHANNEL_A(bas) ? ~SAB_PVR_DTR_A : ~SAB_PVR_DTR_B; 223 uart_setreg(bas, SAB_PVR, pvr | SAB_PVR_MAGIC); 224 uart_barrier(bas); 225 226 /* power down */ 227 uart_setreg(bas, SAB_CCR0, 0); 228 uart_barrier(bas); 229 230 /* set basic configuration */ 231 ccr0 = SAB_CCR0_MCE|SAB_CCR0_SC_NRZ|SAB_CCR0_SM_ASYNC; 232 uart_setreg(bas, SAB_CCR0, ccr0); 233 uart_barrier(bas); 234 uart_setreg(bas, SAB_CCR1, SAB_CCR1_ODS|SAB_CCR1_BCR|SAB_CCR1_CM_7); 235 uart_barrier(bas); 236 uart_setreg(bas, SAB_CCR2, SAB_CCR2_BDF|SAB_CCR2_SSEL|SAB_CCR2_TOE); 237 uart_barrier(bas); 238 uart_setreg(bas, SAB_CCR3, 0); 239 uart_barrier(bas); 240 uart_setreg(bas, SAB_CCR4, SAB_CCR4_MCK4|SAB_CCR4_EBRG|SAB_CCR4_ICD); 241 uart_barrier(bas); 242 uart_setreg(bas, SAB_MODE, SAB_MODE_FCTS|SAB_MODE_RTS|SAB_MODE_RAC); 243 uart_barrier(bas); 244 uart_setreg(bas, SAB_RFC, SAB_RFC_DPS|SAB_RFC_RFDF| 245 SAB_RFC_RFTH_32CHAR); 246 uart_barrier(bas); 247 248 sab82532_param(bas, baudrate, databits, stopbits, parity); 249 250 /* Clear interrupts. */ 251 uart_setreg(bas, SAB_IMR0, 0xff); 252 uart_setreg(bas, SAB_IMR1, 0xff); 253 uart_barrier(bas); 254 uart_getreg(bas, SAB_ISR0); 255 uart_getreg(bas, SAB_ISR1); 256 uart_barrier(bas); 257 258 sab82532_flush(bas, UART_FLUSH_TRANSMITTER|UART_FLUSH_RECEIVER); 259 260 /* Power up. */ 261 uart_setreg(bas, SAB_CCR0, ccr0|SAB_CCR0_PU); 262 uart_barrier(bas); 263} 264 265static void 266sab82532_term(struct uart_bas *bas) 267{ 268 uint8_t pvr; 269 270 pvr = uart_getreg(bas, SAB_PVR); 271 pvr |= IS_CHANNEL_A(bas) ? SAB_PVR_DTR_A : SAB_PVR_DTR_B; 272 uart_setreg(bas, SAB_PVR, pvr); 273 uart_barrier(bas); 274} 275 276static void 277sab82532_putc(struct uart_bas *bas, int c) 278{ 279 int delay, limit; 280 281 /* 1/10th the time to transmit 1 character (estimate). */ 282 delay = sab82532_delay(bas); 283 284 limit = 20; 285 while ((uart_getreg(bas, SAB_STAR) & SAB_STAR_TEC) && --limit) 286 DELAY(delay); 287 uart_setreg(bas, SAB_TIC, c); 288 limit = 20; 289 while ((uart_getreg(bas, SAB_STAR) & SAB_STAR_TEC) && --limit) 290 DELAY(delay); 291} 292 293static int 294sab82532_poll(struct uart_bas *bas) 295{ 296 297 if (uart_getreg(bas, SAB_STAR) & SAB_STAR_RFNE) 298 return (sab82532_getc(bas)); 299 return (-1); 300} 301 302static int 303sab82532_getc(struct uart_bas *bas) 304{ 305 int c, delay; 306 307 /* 1/10th the time to transmit 1 character (estimate). */ 308 delay = sab82532_delay(bas); 309 310 while (!(uart_getreg(bas, SAB_STAR) & SAB_STAR_RFNE)) 311 DELAY(delay); 312 313 while (uart_getreg(bas, SAB_STAR) & SAB_STAR_CEC) 314 ; 315 uart_setreg(bas, SAB_CMDR, SAB_CMDR_RFRD); 316 uart_barrier(bas); 317 318 while (!(uart_getreg(bas, SAB_ISR0) & SAB_ISR0_TCD)) 319 DELAY(delay); 320 321 c = uart_getreg(bas, SAB_RFIFO); 322 uart_barrier(bas); 323 324 /* Blow away everything left in the FIFO... */ 325 while (uart_getreg(bas, SAB_STAR) & SAB_STAR_CEC) 326 ; 327 uart_setreg(bas, SAB_CMDR, SAB_CMDR_RMC); 328 uart_barrier(bas); 329 return (c); 330} 331 332/* 333 * High-level UART interface. 334 */ 335struct sab82532_softc { 336 struct uart_softc base; 337}; 338 339static int sab82532_bus_attach(struct uart_softc *); 340static int sab82532_bus_detach(struct uart_softc *); 341static int sab82532_bus_flush(struct uart_softc *, int); 342static int sab82532_bus_getsig(struct uart_softc *); 343static int sab82532_bus_ioctl(struct uart_softc *, int, intptr_t); 344static int sab82532_bus_ipend(struct uart_softc *); 345static int sab82532_bus_param(struct uart_softc *, int, int, int, int); 346static int sab82532_bus_probe(struct uart_softc *); 347static int sab82532_bus_receive(struct uart_softc *); 348static int sab82532_bus_setsig(struct uart_softc *, int); 349static int sab82532_bus_transmit(struct uart_softc *); 350 351static kobj_method_t sab82532_methods[] = { 352 KOBJMETHOD(uart_attach, sab82532_bus_attach), 353 KOBJMETHOD(uart_detach, sab82532_bus_detach), 354 KOBJMETHOD(uart_flush, sab82532_bus_flush), 355 KOBJMETHOD(uart_getsig, sab82532_bus_getsig), 356 KOBJMETHOD(uart_ioctl, sab82532_bus_ioctl), 357 KOBJMETHOD(uart_ipend, sab82532_bus_ipend), 358 KOBJMETHOD(uart_param, sab82532_bus_param), 359 KOBJMETHOD(uart_probe, sab82532_bus_probe), 360 KOBJMETHOD(uart_receive, sab82532_bus_receive), 361 KOBJMETHOD(uart_setsig, sab82532_bus_setsig), 362 KOBJMETHOD(uart_transmit, sab82532_bus_transmit), 363 { 0, 0 } 364}; 365 366struct uart_class uart_sab82532_class = { 367 "sab82532 class", 368 sab82532_methods, 369 sizeof(struct sab82532_softc), 370 .uc_range = 64, 371 .uc_rclk = DEFAULT_RCLK 372}; 373 374#define SIGCHG(c, i, s, d) \ 375 if (c) { \ 376 i |= (i & s) ? s : s | d; \ 377 } else { \ 378 i = (i & s) ? (i & ~s) | d : i; \ 379 } 380 381static int 382sab82532_bus_attach(struct uart_softc *sc) 383{ 384 struct uart_bas *bas; 385 uint8_t imr0, imr1; 386 387 bas = &sc->sc_bas; 388 if (sc->sc_sysdev == NULL) 389 sab82532_init(bas, 9600, 8, 1, UART_PARITY_NONE); 390 391 sc->sc_rxfifosz = 32; 392 sc->sc_txfifosz = 32; 393 394 imr0 = SAB_IMR0_TCD|SAB_IMR0_TIME|SAB_IMR0_CDSC|SAB_IMR0_RFO| 395 SAB_IMR0_RPF; 396 uart_setreg(bas, SAB_IMR0, 0xff & ~imr0); 397 imr1 = SAB_IMR1_BRKT|SAB_IMR1_ALLS|SAB_IMR1_CSC; 398 uart_setreg(bas, SAB_IMR1, 0xff & ~imr1); 399 uart_barrier(bas); 400 401 if (sc->sc_sysdev == NULL) 402 sab82532_bus_setsig(sc, UART_SIG_DDTR|UART_SIG_DRTS); 403 (void)sab82532_bus_getsig(sc); 404 return (0); 405} 406 407static int 408sab82532_bus_detach(struct uart_softc *sc) 409{ 410 struct uart_bas *bas; 411 412 bas = &sc->sc_bas; 413 uart_setreg(bas, SAB_IMR0, 0xff); 414 uart_setreg(bas, SAB_IMR1, 0xff); 415 uart_barrier(bas); 416 uart_getreg(bas, SAB_ISR0); 417 uart_getreg(bas, SAB_ISR1); 418 uart_barrier(bas); 419 uart_setreg(bas, SAB_CCR0, 0); 420 uart_barrier(bas); 421 return (0); 422} 423 424static int 425sab82532_bus_flush(struct uart_softc *sc, int what) 426{ 427 428 sab82532_flush(&sc->sc_bas, what); 429 return (0); 430} 431 432static int 433sab82532_bus_getsig(struct uart_softc *sc) 434{ 435 struct uart_bas *bas; 436 uint32_t new, old, sig; 437 uint8_t pvr, star, vstr; 438 439 bas = &sc->sc_bas; 440 do { 441 old = sc->sc_hwsig; 442 sig = old; 443 star = uart_getreg(bas, SAB_STAR); 444 SIGCHG(star & SAB_STAR_CTS, sig, UART_SIG_CTS, UART_SIG_DCTS); 445 vstr = uart_getreg(bas, SAB_VSTR); 446 SIGCHG(vstr & SAB_VSTR_CD, sig, UART_SIG_DCD, UART_SIG_DDCD); 447 pvr = uart_getreg(bas, SAB_PVR); 448 pvr &= (IS_CHANNEL_A(bas)) ? SAB_PVR_DSR_A : SAB_PVR_DSR_B; 449 SIGCHG(~pvr, sig, UART_SIG_DSR, UART_SIG_DDSR); 450 new = sig & ~UART_SIGMASK_DELTA; 451 } while (!atomic_cmpset_32(&sc->sc_hwsig, old, new)); 452 return (sig); 453} 454 455static int 456sab82532_bus_ioctl(struct uart_softc *sc, int request, intptr_t data) 457{ 458 struct uart_bas *bas; 459 uint8_t dafo, mode; 460 461 bas = &sc->sc_bas; 462 switch (request) { 463 case UART_IOCTL_BREAK: 464 dafo = uart_getreg(bas, SAB_DAFO); 465 if (data) 466 dafo |= SAB_DAFO_XBRK; 467 else 468 dafo &= ~SAB_DAFO_XBRK; 469 uart_setreg(bas, SAB_DAFO, dafo); 470 uart_barrier(bas); 471 break; 472 case UART_IOCTL_IFLOW: 473 mode = uart_getreg(bas, SAB_MODE); 474 if (data) { 475 mode &= ~SAB_MODE_RTS; 476 mode |= SAB_MODE_FRTS; 477 } else { 478 mode |= SAB_MODE_RTS; 479 mode &= ~SAB_MODE_FRTS; 480 } 481 uart_setreg(bas, SAB_MODE, mode); 482 uart_barrier(bas); 483 break; 484 case UART_IOCTL_OFLOW: 485 mode = uart_getreg(bas, SAB_MODE); 486 if (data) 487 mode &= ~SAB_MODE_FCTS; 488 else 489 mode |= SAB_MODE_FCTS; 490 uart_setreg(bas, SAB_MODE, mode); 491 uart_barrier(bas); 492 break; 493 default: 494 return (EINVAL); 495 } 496 return (0); 497} 498 499static int 500sab82532_bus_ipend(struct uart_softc *sc) 501{ 502 struct uart_bas *bas; 503 int ipend; 504 uint8_t isr0, isr1; 505 506 bas = &sc->sc_bas; 507 isr0 = uart_getreg(bas, SAB_ISR0); 508 isr1 = uart_getreg(bas, SAB_ISR1); 509 uart_barrier(bas); 510 511 if (isr0 & SAB_ISR0_TIME) { 512 while (uart_getreg(bas, SAB_STAR) & SAB_STAR_CEC) 513 ; 514 uart_setreg(bas, SAB_CMDR, SAB_CMDR_RFRD); 515 uart_barrier(bas); 516 } 517 518 ipend = 0; 519 if (isr1 & SAB_ISR1_BRKT) 520 ipend |= UART_IPEND_BREAK; 521 if (isr0 & SAB_ISR0_RFO) 522 ipend |= UART_IPEND_OVERRUN; 523 if (isr0 & (SAB_ISR0_TCD|SAB_ISR0_RPF)) 524 ipend |= UART_IPEND_RXREADY; 525 if ((isr0 & SAB_ISR0_CDSC) || (isr1 & SAB_ISR1_CSC)) 526 ipend |= UART_IPEND_SIGCHG; 527 if (isr1 & SAB_ISR1_ALLS) 528 ipend |= UART_IPEND_TXIDLE; 529 530 return (ipend); 531} 532 533static int 534sab82532_bus_param(struct uart_softc *sc, int baudrate, int databits, 535 int stopbits, int parity) 536{ 537 struct uart_bas *bas; 538 539 bas = &sc->sc_bas; 540 return (sab82532_param(bas, baudrate, databits, stopbits, parity)); 541} 542 543static int 544sab82532_bus_probe(struct uart_softc *sc) 545{ 546 char buf[80]; 547 const char *ch, *vstr; 548 int error; 549 550 error = sab82532_probe(&sc->sc_bas); 551 if (error) 552 return (error); 553 554 /* Assume the address range is naturally aligned. */ 555 ch = IS_CHANNEL_A(&sc->sc_bas) ? "A" : "B"; 556 557 switch (uart_getreg(&sc->sc_bas, SAB_VSTR) & SAB_VSTR_VMASK) { 558 case SAB_VSTR_V_1: 559 vstr = "v1"; 560 break; 561 case SAB_VSTR_V_2: 562 vstr = "v2"; 563 break; 564 case SAB_VSTR_V_32: 565 vstr = "v3.2"; 566 sc->sc_hwiflow = 0; /* CTS doesn't work with RFC:RFDF. */ 567 sc->sc_hwoflow = 1; 568 break; 569 default: 570 vstr = "v4?"; 571 break; 572 } 573 574 snprintf(buf, sizeof(buf), "SAB 82532 %s, channel %s", vstr, ch); 575 device_set_desc_copy(sc->sc_dev, buf); 576 return (0); 577} 578 579static int 580sab82532_bus_receive(struct uart_softc *sc) 581{ 582 struct uart_bas *bas; 583 int i, rbcl, xc; 584 uint8_t s; 585 586 bas = &sc->sc_bas; 587 if (uart_getreg(bas, SAB_STAR) & SAB_STAR_RFNE) { 588 rbcl = uart_getreg(bas, SAB_RBCL) & 31; 589 if (rbcl == 0) 590 rbcl = 32; 591 for (i = 0; i < rbcl; i += 2) { 592 if (uart_rx_full(sc)) { 593 sc->sc_rxbuf[sc->sc_rxput] = UART_STAT_OVERRUN; 594 break; 595 } 596 xc = uart_getreg(bas, SAB_RFIFO); 597 s = uart_getreg(bas, SAB_RFIFO + 1); 598 if (s & SAB_RSTAT_FE) 599 xc |= UART_STAT_FRAMERR; 600 if (s & SAB_RSTAT_PE) 601 xc |= UART_STAT_PARERR; 602 uart_rx_put(sc, xc); 603 } 604 } 605 606 while (uart_getreg(bas, SAB_STAR) & SAB_STAR_CEC) 607 ; 608 uart_setreg(bas, SAB_CMDR, SAB_CMDR_RMC); 609 uart_barrier(bas); 610 return (0); 611} 612 613static int 614sab82532_bus_setsig(struct uart_softc *sc, int sig) 615{ 616 struct uart_bas *bas; 617 uint32_t new, old; 618 uint8_t mode, pvr; 619 620 bas = &sc->sc_bas; 621 do { 622 old = sc->sc_hwsig; 623 new = old; 624 if (sig & UART_SIG_DDTR) { 625 SIGCHG(sig & UART_SIG_DTR, new, UART_SIG_DTR, 626 UART_SIG_DDTR); 627 } 628 if (sig & UART_SIG_DRTS) { 629 SIGCHG(sig & UART_SIG_RTS, new, UART_SIG_RTS, 630 UART_SIG_DRTS); 631 } 632 } while (!atomic_cmpset_32(&sc->sc_hwsig, old, new)); 633 634 /* Set DTR pin. */ 635 pvr = uart_getreg(bas, SAB_PVR); 636 if (new & UART_SIG_DTR) 637 pvr &= (IS_CHANNEL_A(bas)) ? ~SAB_PVR_DTR_A : ~SAB_PVR_DTR_B; 638 else 639 pvr |= (IS_CHANNEL_A(bas)) ? SAB_PVR_DTR_A : SAB_PVR_DTR_B; 640 uart_setreg(bas, SAB_PVR, pvr); 641 642 /* Set RTS pin. */ 643 mode = uart_getreg(bas, SAB_MODE); 644 if (new & UART_SIG_RTS) 645 mode &= ~SAB_MODE_FRTS; 646 else 647 mode |= SAB_MODE_FRTS; 648 uart_setreg(bas, SAB_MODE, mode); 649 uart_barrier(bas); 650 return (0); 651} 652 653static int 654sab82532_bus_transmit(struct uart_softc *sc) 655{ 656 struct uart_bas *bas; 657 int i; 658 659 bas = &sc->sc_bas; 660 while (!(uart_getreg(bas, SAB_STAR) & SAB_STAR_XFW)) 661 ; 662 for (i = 0; i < sc->sc_txdatasz; i++) 663 uart_setreg(bas, SAB_XFIFO + i, sc->sc_txbuf[i]); 664 uart_barrier(bas); 665 while (uart_getreg(bas, SAB_STAR) & SAB_STAR_CEC) 666 ; 667 uart_setreg(bas, SAB_CMDR, SAB_CMDR_XF); 668 sc->sc_txbusy = 1; 669 return (0); 670} 671