Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177650493
D61611.1794946533.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None
D61611.1794946533.diff
View Options
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);
+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,16 @@
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() must change 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,18 @@
}
static int
-ns8250_delay(struct uart_bas *bas)
+ns8250_delay(struct ns8250_softc *ns8250)
{
+ struct uart_bas *bas;
uint32_t divisor;
- divisor = ns8250_get_divisor(bas);
+ bas = &ns8250->base.sc_bas;
+
+ /* While probing, the softc is not yet an ns8250_softc. */
+ if ((bas->flags & UART_BAS_IN_PROBE) != 0)
+ divisor = ns8250_get_divisor(bas);
+ else
+ divisor = ns8250->get_divisor(bas);
/* 1/10th the time to transmit 1 character (estimate): one bit. */
return ((uint64_t)divisor * (1000000 / NS8250_DIVISOR_SCALE) /
@@ -258,11 +265,13 @@
}
static int
-ns8250_drain(struct uart_bas *bas, int what)
+ns8250_drain(struct ns8250_softc *ns8250, int what)
{
+ struct uart_bas *bas;
int delay, limit;
- delay = ns8250_delay(bas);
+ bas = &ns8250->base.sc_bas;
+ delay = ns8250_delay(ns8250);
if (what & UART_DRAIN_TRANSMITTER) {
/*
@@ -315,12 +324,14 @@
* drained. WARNING: this function clobbers the FIFO setting!
*/
static void
-ns8250_flush(struct uart_bas *bas, int what)
+ns8250_flush(struct ns8250_softc *ns8250, int what)
{
+ struct uart_bas *bas;
uint8_t fcr;
uint8_t lsr;
int drain = 0;
+ bas = &ns8250->base.sc_bas;
fcr = FCR_ENABLE;
if (what & UART_FLUSH_TRANSMITTER)
fcr |= FCR_XMT_RST;
@@ -343,13 +354,13 @@
drain |= UART_DRAIN_RECEIVER;
if (drain != 0) {
printf("uart: ns8250: UART FCR is broken (%#x)\n", drain);
- ns8250_drain(bas, drain);
+ ns8250_drain(ns8250, drain);
}
}
static int
ns8250_param(struct uart_bas *bas, int baudrate, int databits, int stopbits,
- int parity)
+ int parity, ns8250_set_baudrate_t *set_baudrate)
{
int error;
uint8_t lcr;
@@ -373,7 +384,7 @@
/* Set baudrate if we know a rclk and both are not 0. */
if (baudrate > 0 && bas->rclk > 0) {
- error = ns8250_set_baudrate(bas, baudrate);
+ error = set_baudrate(bas, baudrate);
if (error != 0)
return (error);
}
@@ -463,7 +474,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);
@@ -655,6 +667,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;
@@ -746,12 +765,12 @@
bas = &sc->sc_bas;
uart_lock(sc->sc_hwmtx);
if (sc->sc_rxfifosz > 1) {
- ns8250_flush(bas, what);
+ ns8250_flush(ns8250, what);
uart_setreg(bas, REG_FCR, ns8250->fcr);
uart_barrier(bas);
error = 0;
} else
- error = ns8250_drain(bas, what);
+ error = ns8250_drain(ns8250, what);
uart_unlock(sc->sc_hwmtx);
return (error);
}
@@ -796,6 +815,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;
@@ -844,7 +864,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
@@ -937,7 +957,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);
}
@@ -945,6 +966,8 @@
int
ns8250_bus_probe(struct uart_softc *sc)
{
+ /* Not an ns8250_softc yet; the helpers check UART_BAS_IN_PROBE. */
+ struct ns8250_softc *ns8250 = (struct ns8250_softc *)sc;
struct uart_bas *bas;
int count, delay, error, limit;
uint8_t lsr, mcr, ier;
@@ -962,7 +985,7 @@
} else
mcr |= MCR_DTR | MCR_RTS;
- error = ns8250_drain(bas, UART_DRAIN_TRANSMITTER);
+ error = ns8250_drain(ns8250, UART_DRAIN_TRANSMITTER);
if (error)
return (error);
@@ -998,10 +1021,11 @@
uart_barrier(bas);
count = 0;
- delay = ns8250_delay(bas);
+ delay = ns8250_delay(ns8250);
/* We have FIFOs. Drain the transmitter and receiver. */
- error = ns8250_drain(bas, UART_DRAIN_RECEIVER|UART_DRAIN_TRANSMITTER);
+ error = ns8250_drain(ns8250,
+ UART_DRAIN_RECEIVER|UART_DRAIN_TRANSMITTER);
if (error) {
uart_setreg(bas, REG_MCR, mcr);
uart_setreg(bas, REG_FCR, 0);
@@ -1055,7 +1079,7 @@
uart_setreg(bas, REG_MCR, mcr);
/* Reset FIFOs. */
- ns8250_flush(bas, UART_FLUSH_RECEIVER|UART_FLUSH_TRANSMITTER);
+ ns8250_flush(ns8250, UART_FLUSH_RECEIVER|UART_FLUSH_TRANSMITTER);
describe:
if (count >= 14 && count <= 16) {
@@ -1198,7 +1222,7 @@
uart_setreg(bas, REG_IER, ns8250->ier);
uart_barrier(bas);
if (broken_txfifo)
- ns8250_drain(bas, UART_DRAIN_TRANSMITTER);
+ ns8250_drain(ns8250, UART_DRAIN_TRANSMITTER);
else
sc->sc_txbusy = 1;
uart_unlock(sc->sc_hwmtx);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 17, 8:15 PM (3 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41800352
Default Alt Text
D61611.1794946533.diff (6 KB)
Attached To
Mode
D61611: uart: Let ns8250 drivers provide their own baud rate generator
Attached
Detach File
Event Timeline