Deleted Added
full compact
uart_dev_ns8250.c (246016) uart_dev_ns8250.c (247519)
1/*-
2 * Copyright (c) 2003 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *

--- 10 unchanged lines hidden (view full) ---

19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
1/*-
2 * Copyright (c) 2003 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *

--- 10 unchanged lines hidden (view full) ---

19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "opt_platform.h"
28
27#include <sys/cdefs.h>
29#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/uart/uart_dev_ns8250.c 246016 2013-01-27 23:33:42Z cperciva $");
30__FBSDID("$FreeBSD: head/sys/dev/uart/uart_dev_ns8250.c 247519 2013-03-01 01:42:31Z ganbold $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/bus.h>
33#include <sys/conf.h>
34#include <sys/kernel.h>
35#include <sys/sysctl.h>
36#include <machine/bus.h>
37
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/bus.h>
35#include <sys/conf.h>
36#include <sys/kernel.h>
37#include <sys/sysctl.h>
38#include <machine/bus.h>
39
40#ifdef FDT
41#include <dev/fdt/fdt_common.h>
42#include <dev/ofw/ofw_bus.h>
43#include <dev/ofw/ofw_bus_subr.h>
44#endif
45
38#include <dev/uart/uart.h>
39#include <dev/uart/uart_cpu.h>
40#include <dev/uart/uart_bus.h>
41
42#include <dev/ic/ns16550.h>
43
44#include "uart_if.h"
45
46#define DEFAULT_RCLK 1843200
47
46#include <dev/uart/uart.h>
47#include <dev/uart/uart_cpu.h>
48#include <dev/uart/uart_bus.h>
49
50#include <dev/ic/ns16550.h>
51
52#include "uart_if.h"
53
54#define DEFAULT_RCLK 1843200
55
56static int broken_txfifo = 0;
57SYSCTL_INT(_hw, OID_AUTO, broken_txfifo, CTLFLAG_RW | CTLFLAG_TUN,
58 &broken_txfifo, 0, "UART FIFO has QEMU emulation bug");
59TUNABLE_INT("hw.broken_txfifo", &broken_txfifo);
60
48/*
49 * Clear pending interrupts. THRE is cleared by reading IIR. Data
50 * that may have been received gets lost here.
51 */
52static void
53ns8250_clrint(struct uart_bas *bas)
54{
55 uint8_t iir, lsr;

--- 289 unchanged lines hidden (view full) ---

345struct ns8250_softc {
346 struct uart_softc base;
347 uint8_t fcr;
348 uint8_t ier;
349 uint8_t mcr;
350
351 uint8_t ier_mask;
352 uint8_t ier_rxbits;
61/*
62 * Clear pending interrupts. THRE is cleared by reading IIR. Data
63 * that may have been received gets lost here.
64 */
65static void
66ns8250_clrint(struct uart_bas *bas)
67{
68 uint8_t iir, lsr;

--- 289 unchanged lines hidden (view full) ---

358struct ns8250_softc {
359 struct uart_softc base;
360 uint8_t fcr;
361 uint8_t ier;
362 uint8_t mcr;
363
364 uint8_t ier_mask;
365 uint8_t ier_rxbits;
366 uint8_t busy_detect;
353};
354
355static int ns8250_bus_attach(struct uart_softc *);
356static int ns8250_bus_detach(struct uart_softc *);
357static int ns8250_bus_flush(struct uart_softc *, int);
358static int ns8250_bus_getsig(struct uart_softc *);
359static int ns8250_bus_ioctl(struct uart_softc *, int, intptr_t);
360static int ns8250_bus_ipend(struct uart_softc *);

--- 35 unchanged lines hidden (view full) ---

396 }
397
398static int
399ns8250_bus_attach(struct uart_softc *sc)
400{
401 struct ns8250_softc *ns8250 = (struct ns8250_softc*)sc;
402 struct uart_bas *bas;
403 unsigned int ivar;
367};
368
369static int ns8250_bus_attach(struct uart_softc *);
370static int ns8250_bus_detach(struct uart_softc *);
371static int ns8250_bus_flush(struct uart_softc *, int);
372static int ns8250_bus_getsig(struct uart_softc *);
373static int ns8250_bus_ioctl(struct uart_softc *, int, intptr_t);
374static int ns8250_bus_ipend(struct uart_softc *);

--- 35 unchanged lines hidden (view full) ---

410 }
411
412static int
413ns8250_bus_attach(struct uart_softc *sc)
414{
415 struct ns8250_softc *ns8250 = (struct ns8250_softc*)sc;
416 struct uart_bas *bas;
417 unsigned int ivar;
418#ifdef FDT
419 phandle_t node;
420 pcell_t cell;
421#endif
404
422
423 ns8250->busy_detect = 0;
424
425#ifdef FDT
426 /*
427 * Check whether uart requires to read USR reg when IIR_BUSY and
428 * has broken txfifo.
429 */
430 node = ofw_bus_get_node(sc->sc_dev);
431 if ((OF_getprop(node, "busy-detect", &cell, sizeof(cell))) > 0)
432 ns8250->busy_detect = 1;
433 if ((OF_getprop(node, "broken-txfifo", &cell, sizeof(cell))) > 0)
434 broken_txfifo = 1;
435#endif
436
405 bas = &sc->sc_bas;
406
407 ns8250->mcr = uart_getreg(bas, REG_MCR);
408 ns8250->fcr = FCR_ENABLE;
409 if (!resource_int_value("uart", device_get_unit(sc->sc_dev), "flags",
410 &ivar)) {
411 if (UART_FLAGS_FCR_RX_LOW(ivar))
412 ns8250->fcr |= FCR_RX_LOW;

--- 174 unchanged lines hidden (view full) ---

587 struct ns8250_softc *ns8250;
588 int ipend;
589 uint8_t iir, lsr;
590
591 ns8250 = (struct ns8250_softc *)sc;
592 bas = &sc->sc_bas;
593 uart_lock(sc->sc_hwmtx);
594 iir = uart_getreg(bas, REG_IIR);
437 bas = &sc->sc_bas;
438
439 ns8250->mcr = uart_getreg(bas, REG_MCR);
440 ns8250->fcr = FCR_ENABLE;
441 if (!resource_int_value("uart", device_get_unit(sc->sc_dev), "flags",
442 &ivar)) {
443 if (UART_FLAGS_FCR_RX_LOW(ivar))
444 ns8250->fcr |= FCR_RX_LOW;

--- 174 unchanged lines hidden (view full) ---

619 struct ns8250_softc *ns8250;
620 int ipend;
621 uint8_t iir, lsr;
622
623 ns8250 = (struct ns8250_softc *)sc;
624 bas = &sc->sc_bas;
625 uart_lock(sc->sc_hwmtx);
626 iir = uart_getreg(bas, REG_IIR);
627
628 if (ns8250->busy_detect && (iir & IIR_BUSY) == IIR_BUSY) {
629 (void)uart_getreg(bas, DW_REG_USR);
630 uart_unlock(sc->sc_hwmtx);
631 return (0);
632 }
595 if (iir & IIR_NOPEND) {
596 uart_unlock(sc->sc_hwmtx);
597 return (0);
598 }
599 ipend = 0;
600 if (iir & IIR_RXRDY) {
601 lsr = uart_getreg(bas, REG_LSR);
602 if (lsr & LSR_OE)

--- 239 unchanged lines hidden (view full) ---

842 if (new & SER_RTS)
843 ns8250->mcr |= MCR_RTS;
844 uart_setreg(bas, REG_MCR, ns8250->mcr);
845 uart_barrier(bas);
846 uart_unlock(sc->sc_hwmtx);
847 return (0);
848}
849
633 if (iir & IIR_NOPEND) {
634 uart_unlock(sc->sc_hwmtx);
635 return (0);
636 }
637 ipend = 0;
638 if (iir & IIR_RXRDY) {
639 lsr = uart_getreg(bas, REG_LSR);
640 if (lsr & LSR_OE)

--- 239 unchanged lines hidden (view full) ---

880 if (new & SER_RTS)
881 ns8250->mcr |= MCR_RTS;
882 uart_setreg(bas, REG_MCR, ns8250->mcr);
883 uart_barrier(bas);
884 uart_unlock(sc->sc_hwmtx);
885 return (0);
886}
887
850static int broken_txfifo = 0;
851SYSCTL_INT(_hw, OID_AUTO, broken_txfifo, CTLFLAG_RW | CTLFLAG_TUN,
852 &broken_txfifo, 0, "UART FIFO has QEMU emulation bug");
853TUNABLE_INT("hw.broken_txfifo", &broken_txfifo);
854
855static int
856ns8250_bus_transmit(struct uart_softc *sc)
857{
858 struct ns8250_softc *ns8250 = (struct ns8250_softc*)sc;
859 struct uart_bas *bas;
860 int i;
861
862 bas = &sc->sc_bas;

--- 18 unchanged lines hidden ---
888static int
889ns8250_bus_transmit(struct uart_softc *sc)
890{
891 struct ns8250_softc *ns8250 = (struct ns8250_softc*)sc;
892 struct uart_bas *bas;
893 int i;
894
895 bas = &sc->sc_bas;

--- 18 unchanged lines hidden ---