summaryrefslogtreecommitdiffstats
path: root/sys/dev/uart
diff options
context:
space:
mode:
authormarius <marius@FreeBSD.org>2007-01-18 22:01:19 +0000
committermarius <marius@FreeBSD.org>2007-01-18 22:01:19 +0000
commit545a381d5f5917c12078fc06b779fab7711c053e (patch)
tree9d40efb79e6c86a1071e9763b706b391d9e9c487 /sys/dev/uart
parent6f6da4e54a1b02d5dd2237063607a3b22d39e819 (diff)
downloadFreeBSD-src-545a381d5f5917c12078fc06b779fab7711c053e.zip
FreeBSD-src-545a381d5f5917c12078fc06b779fab7711c053e.tar.gz
- Add a uart_rxready() and corresponding device-specific implementations
that can be used to check whether receive data is ready, i.e. whether the subsequent call of uart_poll() should return a char, and unlike uart_poll() doesn't actually receive data. - Remove the device-specific implementations of uart_poll() and implement uart_poll() in terms of uart_getc() and the newly added uart_rxready() in order to minimize code duplication. - In sunkbd(4) take advantage of uart_rxready() and use it to implement the polled mode part of sunkbd_check() so we don't need to buffer a potentially read char in the softc. - Fix some mis-indentation in sunkbd_read_char(). Discussed with: marcel
Diffstat (limited to 'sys/dev/uart')
-rw-r--r--sys/dev/uart/uart_cpu.h18
-rw-r--r--sys/dev/uart/uart_dev_ns8250.c10
-rw-r--r--sys/dev/uart/uart_dev_sab82532.c10
-rw-r--r--sys/dev/uart/uart_dev_z8530.c10
-rw-r--r--sys/dev/uart/uart_kbd_sun.c22
5 files changed, 35 insertions, 35 deletions
diff --git a/sys/dev/uart/uart_cpu.h b/sys/dev/uart/uart_cpu.h
index a3f0dcb..b41ed50 100644
--- a/sys/dev/uart/uart_cpu.h
+++ b/sys/dev/uart/uart_cpu.h
@@ -41,7 +41,7 @@ struct uart_ops {
void (*init)(struct uart_bas *, int, int, int, int);
void (*term)(struct uart_bas *);
void (*putc)(struct uart_bas *, int);
- int (*poll)(struct uart_bas *);
+ int (*rxready)(struct uart_bas *);
int (*getc)(struct uart_bas *, struct mtx *);
};
@@ -137,12 +137,26 @@ uart_putc(struct uart_devinfo *di, int c)
}
static __inline int
+uart_rxready(struct uart_devinfo *di)
+{
+ int res;
+
+ uart_lock(di->hwmtx);
+ res = di->ops.rxready(&di->bas);
+ uart_unlock(di->hwmtx);
+ return (res);
+}
+
+static __inline int
uart_poll(struct uart_devinfo *di)
{
int res;
uart_lock(di->hwmtx);
- res = di->ops.poll(&di->bas);
+ if (di->ops.rxready(&di->bas))
+ res = di->ops.getc(&di->bas, NULL);
+ else
+ res = -1;
uart_unlock(di->hwmtx);
return (res);
}
diff --git a/sys/dev/uart/uart_dev_ns8250.c b/sys/dev/uart/uart_dev_ns8250.c
index ba16b55..4262f8d 100644
--- a/sys/dev/uart/uart_dev_ns8250.c
+++ b/sys/dev/uart/uart_dev_ns8250.c
@@ -217,7 +217,7 @@ static int ns8250_probe(struct uart_bas *bas);
static void ns8250_init(struct uart_bas *bas, int, int, int, int);
static void ns8250_term(struct uart_bas *bas);
static void ns8250_putc(struct uart_bas *bas, int);
-static int ns8250_poll(struct uart_bas *bas);
+static int ns8250_rxready(struct uart_bas *bas);
static int ns8250_getc(struct uart_bas *bas, struct mtx *);
struct uart_ops uart_ns8250_ops = {
@@ -225,7 +225,7 @@ struct uart_ops uart_ns8250_ops = {
.init = ns8250_init,
.term = ns8250_term,
.putc = ns8250_putc,
- .poll = ns8250_poll,
+ .rxready = ns8250_rxready,
.getc = ns8250_getc,
};
@@ -299,12 +299,10 @@ ns8250_putc(struct uart_bas *bas, int c)
}
static int
-ns8250_poll(struct uart_bas *bas)
+ns8250_rxready(struct uart_bas *bas)
{
- if (uart_getreg(bas, REG_LSR) & LSR_RXRDY)
- return (uart_getreg(bas, REG_DATA));
- return (-1);
+ return ((uart_getreg(bas, REG_LSR) & LSR_RXRDY) != 0 ? 1 : 0);
}
static int
diff --git a/sys/dev/uart/uart_dev_sab82532.c b/sys/dev/uart/uart_dev_sab82532.c
index 9ef0bd1..e10ae17 100644
--- a/sys/dev/uart/uart_dev_sab82532.c
+++ b/sys/dev/uart/uart_dev_sab82532.c
@@ -173,7 +173,7 @@ static int sab82532_probe(struct uart_bas *bas);
static void sab82532_init(struct uart_bas *bas, int, int, int, int);
static void sab82532_term(struct uart_bas *bas);
static void sab82532_putc(struct uart_bas *bas, int);
-static int sab82532_poll(struct uart_bas *bas);
+static int sab82532_rxready(struct uart_bas *bas);
static int sab82532_getc(struct uart_bas *bas, struct mtx *);
struct uart_ops uart_sab82532_ops = {
@@ -181,7 +181,7 @@ struct uart_ops uart_sab82532_ops = {
.init = sab82532_init,
.term = sab82532_term,
.putc = sab82532_putc,
- .poll = sab82532_poll,
+ .rxready = sab82532_rxready,
.getc = sab82532_getc,
};
@@ -303,12 +303,10 @@ sab82532_putc(struct uart_bas *bas, int c)
}
static int
-sab82532_poll(struct uart_bas *bas)
+sab82532_rxready(struct uart_bas *bas)
{
- if (uart_getreg(bas, SAB_STAR) & SAB_STAR_RFNE)
- return (sab82532_getc(bas, NULL));
- return (-1);
+ return ((uart_getreg(bas, SAB_STAR) & SAB_STAR_RFNE) != 0 ? 1 : 0);
}
static int
diff --git a/sys/dev/uart/uart_dev_z8530.c b/sys/dev/uart/uart_dev_z8530.c
index 04ebc69..8509718 100644
--- a/sys/dev/uart/uart_dev_z8530.c
+++ b/sys/dev/uart/uart_dev_z8530.c
@@ -192,7 +192,7 @@ static int z8530_probe(struct uart_bas *bas);
static void z8530_init(struct uart_bas *bas, int, int, int, int);
static void z8530_term(struct uart_bas *bas);
static void z8530_putc(struct uart_bas *bas, int);
-static int z8530_poll(struct uart_bas *bas);
+static int z8530_rxready(struct uart_bas *bas);
static int z8530_getc(struct uart_bas *bas, struct mtx *);
struct uart_ops uart_z8530_ops = {
@@ -200,7 +200,7 @@ struct uart_ops uart_z8530_ops = {
.init = z8530_init,
.term = z8530_term,
.putc = z8530_putc,
- .poll = z8530_poll,
+ .rxready = z8530_rxready,
.getc = z8530_getc,
};
@@ -235,12 +235,10 @@ z8530_putc(struct uart_bas *bas, int c)
}
static int
-z8530_poll(struct uart_bas *bas)
+z8530_rxready(struct uart_bas *bas)
{
- if (!(uart_getreg(bas, REG_CTRL) & BES_RXA))
- return (-1);
- return (uart_getreg(bas, REG_DATA));
+ return ((uart_getreg(bas, REG_CTRL) & BES_RXA) != 0 ? 1 : 0);
}
static int
diff --git a/sys/dev/uart/uart_kbd_sun.c b/sys/dev/uart/uart_kbd_sun.c
index 201761d..7395f9d 100644
--- a/sys/dev/uart/uart_kbd_sun.c
+++ b/sys/dev/uart/uart_kbd_sun.c
@@ -72,8 +72,6 @@ struct sunkbd_softc {
struct uart_softc *sc_uart;
struct uart_devinfo *sc_sysdev;
- int sc_checked_key;
-
struct callout sc_repeat_callout;
int sc_repeat_key;
@@ -403,7 +401,7 @@ sunkbd_check(keyboard_t *kbd)
return (TRUE);
if (sc->sc_polling != 0 && sc->sc_sysdev != NULL &&
- (sc->sc_checked_key = uart_poll(sc->sc_sysdev)) != -1)
+ uart_rxready(sc->sc_sysdev))
return (TRUE);
return (FALSE);
@@ -441,12 +439,6 @@ sunkbd_read_char(keyboard_t *kbd, int wait)
goto process_code;
}
- if (sc->sc_checked_key != -1) {
- suncode = sc->sc_checked_key;
- sc->sc_checked_key = -1;
- goto process_code;
- }
-
for (;;) {
next_code:
if (!(sc->sc_flags & KPCOMPOSE) && (sc->sc_composed_char > 0)) {
@@ -472,7 +464,6 @@ sunkbd_read_char(keyboard_t *kbd, int wait)
case SKBD_RSP_IDLE:
break;
default:
-
process_code:
++kbd->kb_count;
key = SKBD_KEY_CHAR(suncode);
@@ -565,10 +556,12 @@ sunkbd_read_char(keyboard_t *kbd, int wait)
if (key == 0x13) { /* left alt (KP compose key) */
#endif
if (release != 0) {
- if (sc->sc_flags & KPCOMPOSE) {
- sc->sc_flags &= ~KPCOMPOSE;
- if (sc->sc_composed_char > UCHAR_MAX)
- sc->sc_composed_char = 0;
+ if (sc->sc_flags & KPCOMPOSE) {
+ sc->sc_flags &= ~KPCOMPOSE;
+ if (sc->sc_composed_char >
+ UCHAR_MAX)
+ sc->sc_composed_char =
+ 0;
}
} else {
if (!(sc->sc_flags & KPCOMPOSE)) {
@@ -768,7 +761,6 @@ sunkbd_clear_state(keyboard_t *kbd)
struct sunkbd_softc *sc;
sc = (struct sunkbd_softc *)kbd;
- sc->sc_checked_key = -1;
sc->sc_repeat_key = -1;
sc->sc_accents = 0;
sc->sc_composed_char = 0;
OpenPOWER on IntegriCloud