diff --git a/sys/dev/uart/uart_dev_ns8250.c b/sys/dev/uart/uart_dev_ns8250.c --- a/sys/dev/uart/uart_dev_ns8250.c +++ b/sys/dev/uart/uart_dev_ns8250.c @@ -126,11 +126,11 @@ } } -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 @@ 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 @@ 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;