PERFORCE change 35156 for review
Marcel Moolenaar
marcel at FreeBSD.org
Tue Jul 29 00:05:47 PDT 2003
http://perforce.freebsd.org/chv.cgi?CH=35156
Change 35156 by marcel at marcel_nfs on 2003/07/29 00:05:31
o Add method param for setting the line characteristics.
o Implement t_param.
o Revisit t_oproc and t_stop.
Affected files ...
.. //depot/projects/uart/dev/uart/uart_core.c#13 edit
.. //depot/projects/uart/dev/uart/uart_dev_ns8250.c#13 edit
.. //depot/projects/uart/dev/uart/uart_dev_sab82532.c#7 edit
.. //depot/projects/uart/dev/uart/uart_dev_z8530.c#3 edit
.. //depot/projects/uart/dev/uart/uart_if.m#7 edit
Differences ...
==== //depot/projects/uart/dev/uart/uart_core.c#13 (text+ko) ====
@@ -32,6 +32,7 @@
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/cons.h>
+#include <sys/fcntl.h>
#include <sys/interrupt.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
@@ -79,18 +80,6 @@
sc = tp->t_dev->si_drv1;
if (sc == NULL || sc->sc_leaving)
return;
-
- if (tp->t_state & TS_TBLOCK) {
- /* XXX clear RTS */
- } else {
- /* XXX set RTS */
- }
-
- if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
- ttwwakeup(tp);
- return;
- }
-
if (tp->t_outq.c_cc > 0 && !sc->sc_txbusy) {
sc->sc_txdatasz = q_to_b(&tp->t_outq, sc->sc_txbuf,
sc->sc_txfifosz);
@@ -103,6 +92,34 @@
static int
uart_tty_param(struct tty *tp, struct termios *t)
{
+ struct uart_softc *sc;
+ int databits, parity, stopbits;
+
+ sc = tp->t_dev->si_drv1;
+ if (sc == NULL || sc->sc_leaving)
+ return (ENODEV);
+ if (t->c_ispeed != t->c_ospeed && t->c_ospeed != 0)
+ return (EINVAL);
+ if (t->c_ospeed == 0) {
+ UART_SETSIG(sc, UART_SIG_DDTR | UART_SIG_DRTS);
+ return (0);
+ }
+ switch (t->c_cflag & CSIZE) {
+ case CS5: databits = 5; break;
+ case CS6: databits = 6; break;
+ case CS7: databits = 7; break;
+ default: databits = 8; break;
+ }
+ stopbits = (t->c_cflag & CSTOPB) ? 2 : 1;
+ if (t->c_cflag & PARENB)
+ parity = (t->c_cflag & PARODD) ? UART_PARITY_ODD
+ : UART_PARITY_EVEN;
+ else
+ parity = UART_PARITY_NONE;
+ UART_PARAM(sc, t->c_ospeed, databits, stopbits, parity);
+ UART_SETSIG(sc, UART_SIG_DDTR | UART_SIG_DTR);
+ if ((t->c_cflag & CRTS_IFLOW) == 0)
+ UART_SETSIG(sc, UART_SIG_DRTS | UART_SIG_RTS);
return (0);
}
@@ -114,6 +131,17 @@
sc = tp->t_dev->si_drv1;
if (sc == NULL || sc->sc_leaving)
return;
+ if (rw & FWRITE) {
+ if (sc->sc_txbusy) {
+ sc->sc_txbusy = 0;
+ UART_FLUSH(sc, UART_FLUSH_TRANSMITTER);
+ }
+ tp->t_state &= ~TS_BUSY;
+ }
+ if (rw & FREAD) {
+ UART_FLUSH(sc, UART_FLUSH_RECEIVER);
+ sc->sc_rxget = sc->sc_rxput = 0;
+ }
}
void
==== //depot/projects/uart/dev/uart/uart_dev_ns8250.c#13 (text+ko) ====
@@ -146,6 +146,43 @@
uart_barrier(bas);
}
+static int
+ns8250_param(struct uart_bas *bas, int baudrate, int databits, int stopbits,
+ int parity)
+{
+ int divisor;
+ uint8_t lcr;
+
+ lcr = 0;
+ if (databits >= 8)
+ lcr |= LCR_8BITS;
+ else if (databits == 7)
+ lcr |= LCR_7BITS;
+ else if (databits == 6)
+ lcr |= LCR_6BITS;
+ else
+ lcr |= LCR_5BITS;
+ if (stopbits > 1)
+ lcr |= LCR_STOPB;
+ lcr |= parity << 3;
+
+ /* Set baudrate. */
+ if (baudrate > 0) {
+ uart_setreg(bas, REG_LCR, lcr | LCR_DLAB);
+ uart_barrier(bas);
+ divisor = ns8250_divisor(bas->rclk, baudrate);
+ if (divisor == 0)
+ return (EINVAL);
+ uart_setdreg(bas, REG_DL, divisor);
+ uart_barrier(bas);
+ }
+
+ /* Set LCR and clear DLAB. */
+ uart_setreg(bas, REG_LCR, lcr);
+ uart_barrier(bas);
+ return (0);
+}
+
/*
* Low-level UART interface.
*/
@@ -201,35 +238,10 @@
ns8250_init(struct uart_bas *bas, int baudrate, int databits, int stopbits,
int parity)
{
- int divisor;
- u_char iir, lcr;
+ uint8_t iir;
- lcr = 0;
- if (databits >= 8)
- lcr |= LCR_8BITS;
- else if (databits == 7)
- lcr |= LCR_7BITS;
- else if (databits == 6)
- lcr |= LCR_6BITS;
- else
- lcr |= LCR_5BITS;
- if (stopbits > 1)
- lcr |= LCR_STOPB;
- lcr |= parity << 3;
+ ns8250_param(bas, baudrate, databits, stopbits, parity);
- /* Set baudrate. */
- if (baudrate != 0UL) {
- uart_setreg(bas, REG_LCR, lcr | LCR_DLAB);
- uart_barrier(bas);
- divisor = ns8250_divisor(bas->rclk, baudrate);
- uart_setdreg(bas, REG_DL, divisor);
- uart_barrier(bas);
- }
-
- /* Set LCR and clear DLAB. */
- uart_setreg(bas, REG_LCR, lcr);
- uart_barrier(bas);
-
/* Disable all interrupt sources. */
uart_setreg(bas, REG_IER, 0);
uart_barrier(bas);
@@ -325,6 +337,7 @@
static int ns8250_bus_flush(struct uart_softc *, int);
static int ns8250_bus_getsig(struct uart_softc *);
static int ns8250_bus_ipend(struct uart_softc *);
+static int ns8250_bus_param(struct uart_softc *, int, int, int, int);
static int ns8250_bus_probe(struct uart_softc *);
static int ns8250_bus_receive(struct uart_softc *);
static int ns8250_bus_setsig(struct uart_softc *, int);
@@ -336,6 +349,7 @@
KOBJMETHOD(uart_flush, ns8250_bus_flush),
KOBJMETHOD(uart_getsig, ns8250_bus_getsig),
KOBJMETHOD(uart_ipend, ns8250_bus_ipend),
+ KOBJMETHOD(uart_param, ns8250_bus_param),
KOBJMETHOD(uart_probe, ns8250_bus_probe),
KOBJMETHOD(uart_receive, ns8250_bus_receive),
KOBJMETHOD(uart_setsig, ns8250_bus_setsig),
@@ -452,6 +466,16 @@
}
static int
+ns8250_bus_param(struct uart_softc *sc, int baudrate, int databits,
+ int stopbits, int parity)
+{
+ struct uart_bas *bas;
+
+ bas = &sc->sc_bas;
+ return (ns8250_param(bas, baudrate, databits, stopbits, parity));
+}
+
+static int
ns8250_bus_probe(struct uart_softc *sc)
{
struct uart_bas *bas;
==== //depot/projects/uart/dev/uart/uart_dev_sab82532.c#7 (text+ko) ====
@@ -120,6 +120,7 @@
static int sab82532_bus_flush(struct uart_softc *, int);
static int sab82532_bus_getsig(struct uart_softc *);
static int sab82532_bus_ipend(struct uart_softc *);
+static int sab82532_bus_param(struct uart_softc *, int, int, int, int);
static int sab82532_bus_probe(struct uart_softc *);
static int sab82532_bus_receive(struct uart_softc *);
static int sab82532_bus_setsig(struct uart_softc *, int);
@@ -131,6 +132,7 @@
KOBJMETHOD(uart_flush, sab82532_bus_flush),
KOBJMETHOD(uart_getsig, sab82532_bus_getsig),
KOBJMETHOD(uart_ipend, sab82532_bus_ipend),
+ KOBJMETHOD(uart_param, sab82532_bus_param),
KOBJMETHOD(uart_probe, sab82532_bus_probe),
KOBJMETHOD(uart_receive, sab82532_bus_receive),
KOBJMETHOD(uart_setsig, sab82532_bus_setsig),
@@ -198,6 +200,14 @@
}
static int
+sab82532_bus_param(struct uart_softc *sc, int baudrate, int databits,
+ int stopbits, int parity)
+{
+
+ return (0);
+}
+
+static int
sab82532_bus_probe(struct uart_softc *sc)
{
char buf[80];
==== //depot/projects/uart/dev/uart/uart_dev_z8530.c#3 (text+ko) ====
@@ -108,6 +108,7 @@
static int z8530_bus_flush(struct uart_softc *, int);
static int z8530_bus_getsig(struct uart_softc *);
static int z8530_bus_ipend(struct uart_softc *);
+static int z8530_bus_param(struct uart_softc *, int, int, int, int);
static int z8530_bus_probe(struct uart_softc *);
static int z8530_bus_receive(struct uart_softc *);
static int z8530_bus_setsig(struct uart_softc *, int);
@@ -119,6 +120,7 @@
KOBJMETHOD(uart_flush, z8530_bus_flush),
KOBJMETHOD(uart_getsig, z8530_bus_getsig),
KOBJMETHOD(uart_ipend, z8530_bus_ipend),
+ KOBJMETHOD(uart_param, z8530_bus_param),
KOBJMETHOD(uart_probe, z8530_bus_probe),
KOBJMETHOD(uart_receive, z8530_bus_receive),
KOBJMETHOD(uart_setsig, z8530_bus_setsig),
@@ -170,6 +172,14 @@
}
static int
+z8530_bus_param(struct uart_softc *sc, int baudrate, int databits,
+ int stopbits, int parity)
+{
+
+ return (0);
+}
+
+static int
z8530_bus_probe(struct uart_softc *sc)
{
==== //depot/projects/uart/dev/uart/uart_if.m#7 (text+ko) ====
@@ -50,7 +50,7 @@
# XXX needs explanation.
METHOD int flush {
struct uart_softc *this;
- int what;
+ int what;
};
# getsig() - get line and modem signals.
@@ -77,6 +77,16 @@
struct uart_softc *this;
}
+# param()
+# XXX needs explanation.
+METHOD int param {
+ struct uart_softc *this;
+ int baudrate;
+ int databits;
+ int stopbits;
+ int parity;
+};
+
# probe()
# XXX needs explanation.
METHOD int probe {
@@ -97,7 +107,7 @@
# DTE delta bits set of those DTE signals that did change by this method.
METHOD int setsig {
struct uart_softc *this;
- int sig;
+ int sig;
};
# transmit() - move data from the transmit buffer to the transmit FIFO.
More information about the p4-projects
mailing list