diff options
| author | Warner Losh <imp@FreeBSD.org> | 2024-10-14 21:57:44 +0000 |
|---|---|---|
| committer | Warner Losh <imp@FreeBSD.org> | 2024-10-14 22:03:58 +0000 |
| commit | 4097cd06ca49a4a212c25177007509838c7d04a9 (patch) | |
| tree | d5d83dd4965a4caf4f647f0fe3990717306f6434 /sys/dev/uart | |
| parent | db4a3bae6e2d00cfa64fc9aed5f76e128ab0386a (diff) | |
Diffstat (limited to 'sys/dev/uart')
| -rw-r--r-- | sys/dev/uart/uart_dev_ns8250.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/sys/dev/uart/uart_dev_ns8250.c b/sys/dev/uart/uart_dev_ns8250.c index 9f88a43f462a..d43a48f319e4 100644 --- a/sys/dev/uart/uart_dev_ns8250.c +++ b/sys/dev/uart/uart_dev_ns8250.c @@ -126,11 +126,11 @@ ns8250_clrint(struct uart_bas *bas) } } -static int -ns8250_delay(struct uart_bas *bas) +static uint32_t +ns8250_get_divisor(struct uart_bas *bas) { - int divisor; - u_char lcr; + uint32_t divisor; + uint8_t lcr; lcr = uart_getreg(bas, REG_LCR); uart_setreg(bas, REG_LCR, lcr | LCR_DLAB); @@ -140,6 +140,16 @@ ns8250_delay(struct uart_bas *bas) uart_setreg(bas, REG_LCR, lcr); uart_barrier(bas); + return (divisor); +} + +static int +ns8250_delay(struct uart_bas *bas) +{ + int divisor; + + divisor = ns8250_get_divisor(bas); + /* 1/10th the time to transmit 1 character (estimate). */ if (divisor <= 134) return (16000000 * divisor / bas->rclk); @@ -727,14 +737,7 @@ ns8250_bus_ioctl(struct uart_softc *sc, int request, intptr_t data) uart_barrier(bas); break; case UART_IOCTL_BAUD: - lcr = uart_getreg(bas, REG_LCR); - uart_setreg(bas, REG_LCR, lcr | LCR_DLAB); - uart_barrier(bas); - divisor = uart_getreg(bas, REG_DLL) | - (uart_getreg(bas, REG_DLH) << 8); - uart_barrier(bas); - uart_setreg(bas, REG_LCR, lcr); - uart_barrier(bas); + divisor = ns8250_get_divisor(bas); baudrate = (divisor > 0) ? bas->rclk / divisor / 16 : 0; if (baudrate > 0) *(int*)data = baudrate; |
