Page MenuHomeFreeBSD

D61611.1794917196.diff
No OneTemporary

Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None

D61611.1794917196.diff

diff --git a/sys/dev/uart/uart_dev_ns8250.h b/sys/dev/uart/uart_dev_ns8250.h
--- a/sys/dev/uart/uart_dev_ns8250.h
+++ b/sys/dev/uart/uart_dev_ns8250.h
@@ -35,6 +35,10 @@
*/
#define NS8250_DIVISOR_SCALE 100
+typedef int ns8250_set_baudrate_t(struct uart_bas *, int, uint8_t);
+typedef int ns8250_get_baudrate_t(struct uart_bas *);
+typedef uint32_t ns8250_get_divisor_t(struct uart_bas *);
+
/*
* High-level UART interface.
*/
@@ -48,6 +52,18 @@
uint8_t ier_rxbits;
uint8_t busy_detect;
int noise_count;
+
+ /*
+ * The baud rate generator. A UART with a generator of its own sets
+ * these before ns8250_bus_attach(), which sets the ones left NULL to
+ * the 16550 versions. set_baudrate() sets the rate for the frame
+ * format in its LCR value argument and leaves LCR set to it; it
+ * changes nothing if it fails. get_baudrate() and get_divisor() must
+ * agree.
+ */
+ ns8250_set_baudrate_t *set_baudrate;
+ ns8250_get_baudrate_t *get_baudrate;
+ ns8250_get_divisor_t *get_divisor;
};
extern struct uart_ops uart_ns8250_ops;
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
@@ -190,11 +190,11 @@
}
static int
-ns8250_delay(struct uart_bas *bas)
+ns8250_delay(struct uart_bas *bas, ns8250_get_divisor_t *get_divisor)
{
uint32_t divisor;
- divisor = ns8250_get_divisor(bas);
+ divisor = get_divisor(bas);
/* 1/10th the time to transmit 1 character (estimate): one bit. */
return ((uint64_t)divisor * (1000000 / NS8250_DIVISOR_SCALE) /
@@ -259,11 +259,11 @@
}
static int
-ns8250_drain(struct uart_bas *bas, int what)
+ns8250_drain(struct uart_bas *bas, int what, ns8250_get_divisor_t *get_divisor)
{
int delay, limit;
- delay = ns8250_delay(bas);
+ delay = ns8250_delay(bas, get_divisor);
if (what & UART_DRAIN_TRANSMITTER) {
/*
@@ -316,7 +316,7 @@
* drained. WARNING: this function clobbers the FIFO setting!
*/
static void
-ns8250_flush(struct uart_bas *bas, int what)
+ns8250_flush(struct uart_bas *bas, int what, ns8250_get_divisor_t *get_divisor)
{
uint8_t fcr;
uint8_t lsr;
@@ -344,13 +344,13 @@
drain |= UART_DRAIN_RECEIVER;
if (drain != 0) {
printf("uart: ns8250: UART FCR is broken (%#x)\n", drain);
- ns8250_drain(bas, drain);
+ ns8250_drain(bas, drain, get_divisor);
}
}
static int
ns8250_param(struct uart_bas *bas, int baudrate, int databits, int stopbits,
- int parity)
+ int parity, ns8250_set_baudrate_t *set_baudrate)
{
uint8_t lcr;
@@ -373,7 +373,7 @@
/* Set baudrate if we know a rclk and both are not 0. */
if (baudrate > 0 && bas->rclk > 0)
- return (ns8250_set_baudrate(bas, baudrate, lcr));
+ return (set_baudrate(bas, baudrate, lcr));
/* Set LCR and clear DLAB. */
uart_setreg(bas, REG_LCR, lcr);
@@ -460,7 +460,8 @@
if (bas->rclk == 0 && baudrate != 0)
bas->rclk = DEFAULT_RCLK;
- ns8250_param(bas, baudrate, databits, stopbits, parity);
+ ns8250_param(bas, baudrate, databits, stopbits, parity,
+ ns8250_set_baudrate);
/* Disable the FIFO (if present). */
uart_setreg(bas, REG_FCR, 0);
@@ -652,6 +653,13 @@
bas = &sc->sc_bas;
+ if (ns8250->set_baudrate == NULL)
+ ns8250->set_baudrate = ns8250_set_baudrate;
+ if (ns8250->get_baudrate == NULL)
+ ns8250->get_baudrate = ns8250_get_baudrate;
+ if (ns8250->get_divisor == NULL)
+ ns8250->get_divisor = ns8250_get_divisor;
+
ns8250->busy_detect = bas->busy_detect;
ns8250->mcr = uart_getreg(bas, REG_MCR);
ns8250->fcr = FCR_ENABLE;
@@ -743,12 +751,12 @@
bas = &sc->sc_bas;
uart_lock(sc->sc_hwmtx);
if (sc->sc_rxfifosz > 1) {
- ns8250_flush(bas, what);
+ ns8250_flush(bas, what, ns8250->get_divisor);
uart_setreg(bas, REG_FCR, ns8250->fcr);
uart_barrier(bas);
error = 0;
} else
- error = ns8250_drain(bas, what);
+ error = ns8250_drain(bas, what, ns8250->get_divisor);
uart_unlock(sc->sc_hwmtx);
return (error);
}
@@ -793,6 +801,7 @@
int
ns8250_bus_ioctl(struct uart_softc *sc, int request, intptr_t data)
{
+ struct ns8250_softc *ns8250 = (struct ns8250_softc *)sc;
struct uart_bas *bas;
int baudrate, error;
uint8_t efr, lcr;
@@ -841,7 +850,7 @@
uart_barrier(bas);
break;
case UART_IOCTL_BAUD:
- baudrate = ns8250_get_baudrate(bas);
+ baudrate = ns8250->get_baudrate(bas);
if (baudrate > 0)
*(int*)data = baudrate;
else
@@ -934,7 +943,8 @@
}
}
- error = ns8250_param(bas, baudrate, databits, stopbits, parity);
+ error = ns8250_param(bas, baudrate, databits, stopbits, parity,
+ ns8250->set_baudrate);
uart_unlock(sc->sc_hwmtx);
return (error);
}
@@ -959,7 +969,11 @@
} else
mcr |= MCR_DTR | MCR_RTS;
- error = ns8250_drain(bas, UART_DRAIN_TRANSMITTER);
+ /*
+ * While probing, the softc is not yet an ns8250_softc, so the 16550
+ * baud rate generator functions are used.
+ */
+ error = ns8250_drain(bas, UART_DRAIN_TRANSMITTER, ns8250_get_divisor);
if (error)
return (error);
@@ -995,10 +1009,11 @@
uart_barrier(bas);
count = 0;
- delay = ns8250_delay(bas);
+ delay = ns8250_delay(bas, ns8250_get_divisor);
/* We have FIFOs. Drain the transmitter and receiver. */
- error = ns8250_drain(bas, UART_DRAIN_RECEIVER|UART_DRAIN_TRANSMITTER);
+ error = ns8250_drain(bas, UART_DRAIN_RECEIVER|UART_DRAIN_TRANSMITTER,
+ ns8250_get_divisor);
if (error) {
uart_setreg(bas, REG_MCR, mcr);
uart_setreg(bas, REG_FCR, 0);
@@ -1052,7 +1067,8 @@
uart_setreg(bas, REG_MCR, mcr);
/* Reset FIFOs. */
- ns8250_flush(bas, UART_FLUSH_RECEIVER|UART_FLUSH_TRANSMITTER);
+ ns8250_flush(bas, UART_FLUSH_RECEIVER|UART_FLUSH_TRANSMITTER,
+ ns8250_get_divisor);
describe:
if (count >= 14 && count <= 16) {
@@ -1195,7 +1211,8 @@
uart_setreg(bas, REG_IER, ns8250->ier);
uart_barrier(bas);
if (broken_txfifo)
- ns8250_drain(bas, UART_DRAIN_TRANSMITTER);
+ ns8250_drain(bas, UART_DRAIN_TRANSMITTER,
+ ns8250->get_divisor);
else
sc->sc_txbusy = 1;
uart_unlock(sc->sc_hwmtx);

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 17, 12:06 PM (23 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41797265
Default Alt Text
D61611.1794917196.diff (5 KB)

Event Timeline