2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2013 Ian Lepore
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "opt_platform.h"
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/sysctl.h>
40 #include <machine/bus.h>
42 #include <arm/ti/ti_prcm.h>
43 #include <arm/ti/ti_hwmods.h>
45 #include <dev/fdt/fdt_common.h>
46 #include <dev/ofw/ofw_bus.h>
47 #include <dev/ofw/ofw_bus_subr.h>
49 #include <dev/uart/uart.h>
50 #include <dev/uart/uart_cpu.h>
51 #include <dev/uart/uart_cpu_fdt.h>
52 #include <dev/uart/uart_bus.h>
53 #include <dev/uart/uart_dev_ns8250.h>
58 * High-level UART interface.
61 struct ns8250_softc ns8250_base;
66 #define MDR1_MODE_UART 0
67 #define MDR1_MODE_DISABLE 7
69 #define SYSCC_SOFTRESET (1 << 1)
71 #define SYSS_STATUS_RESETDONE (1 << 0)
74 ti8250_bus_probe(struct uart_softc *sc)
79 /* Enable clocks for this device. We can't continue if that fails. */
80 clkid = ti_hwmods_get_clock(sc->sc_dev);
81 if (clkid == INVALID_CLK_IDENT) {
82 device_printf(sc->sc_dev,
83 "failed to get clock based on hwmods\n");
84 clkid = UART1_CLK + device_get_unit(sc->sc_dev);
86 if ((status = ti_prcm_clk_enable(clkid)) != 0)
90 * Set the hardware to disabled mode, do a full device reset, then set
91 * it to uart mode. Most devices will be reset-and-disabled already,
92 * but you never know what a bootloader might have done.
94 uart_setreg(&sc->sc_bas, MDR1_REG, MDR1_MODE_DISABLE);
95 uart_setreg(&sc->sc_bas, SYSCC_REG, SYSCC_SOFTRESET);
96 while (uart_getreg(&sc->sc_bas, SYSS_REG) & SYSS_STATUS_RESETDONE)
98 uart_setreg(&sc->sc_bas, MDR1_REG, MDR1_MODE_UART);
100 status = ns8250_bus_probe(sc);
102 device_set_desc(sc->sc_dev, "TI UART (16550 compatible)");
107 static kobj_method_t ti8250_methods[] = {
108 KOBJMETHOD(uart_probe, ti8250_bus_probe),
110 KOBJMETHOD(uart_attach, ns8250_bus_attach),
111 KOBJMETHOD(uart_detach, ns8250_bus_detach),
112 KOBJMETHOD(uart_flush, ns8250_bus_flush),
113 KOBJMETHOD(uart_getsig, ns8250_bus_getsig),
114 KOBJMETHOD(uart_ioctl, ns8250_bus_ioctl),
115 KOBJMETHOD(uart_ipend, ns8250_bus_ipend),
116 KOBJMETHOD(uart_param, ns8250_bus_param),
117 KOBJMETHOD(uart_receive, ns8250_bus_receive),
118 KOBJMETHOD(uart_setsig, ns8250_bus_setsig),
119 KOBJMETHOD(uart_transmit, ns8250_bus_transmit),
123 static struct uart_class uart_ti8250_class = {
126 sizeof(struct ti8250_softc),
127 .uc_ops = &uart_ns8250_ops,
132 static struct ofw_compat_data compat_data[] = {
133 {"ti,ns16550", (uintptr_t)&uart_ti8250_class},
134 {"ti,omap3-uart", (uintptr_t)&uart_ti8250_class},
135 {"ti,omap4-uart", (uintptr_t)&uart_ti8250_class},
136 {NULL, (uintptr_t)NULL},
138 UART_FDT_CLASS_AND_DEVICE(compat_data);