]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/uart/uart_dev_ti8250.c
bus: Make BUS_TRANSLATE_RESOURCE behave more like other bus methods
[FreeBSD/FreeBSD.git] / sys / dev / uart / uart_dev_ti8250.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2013 Ian Lepore
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
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.
16  *
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.
27  */
28
29 #include "opt_platform.h"
30
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/bus.h>
37 #include <sys/conf.h>
38 #include <sys/kernel.h>
39 #include <sys/sysctl.h>
40 #include <machine/bus.h>
41
42 #include <dev/fdt/fdt_common.h>
43 #include <dev/ofw/ofw_bus.h>
44 #include <dev/ofw/ofw_bus_subr.h>
45
46 #include <dev/uart/uart.h>
47 #include <dev/uart/uart_cpu.h>
48 #include <dev/uart/uart_cpu_fdt.h>
49 #include <dev/uart/uart_bus.h>
50 #include <dev/uart/uart_dev_ns8250.h>
51
52 #include <arm/ti/ti_sysc.h>
53
54 #include "uart_if.h"
55
56 /*
57  * High-level UART interface.
58  */
59 struct ti8250_softc {
60         struct ns8250_softc ns8250_base;
61         /*uint32_t      mystuff;*/
62 };
63
64 #define MDR1_REG                8
65 #define   MDR1_MODE_UART        0
66 #define   MDR1_MODE_DISABLE     7
67 #define SYSCC_REG               15
68 #define   SYSCC_SOFTRESET       (1 << 1)
69 #define SYSS_REG                16
70 #define   SYSS_STATUS_RESETDONE (1 << 0)
71
72 static int
73 ti8250_bus_probe(struct uart_softc *sc)
74 {
75         int status;
76
77         if ((status = ti_sysc_clock_enable(device_get_parent(sc->sc_dev))) != 0)
78                 return (status);
79
80         /*
81          * Set the hardware to disabled mode, do a full device reset, then set
82          * it to uart mode.  Most devices will be reset-and-disabled already,
83          * but you never know what a bootloader might have done.
84          */
85         uart_setreg(&sc->sc_bas, MDR1_REG, MDR1_MODE_DISABLE);
86         uart_setreg(&sc->sc_bas, SYSCC_REG, SYSCC_SOFTRESET);
87         while (uart_getreg(&sc->sc_bas, SYSS_REG) & SYSS_STATUS_RESETDONE)
88                 continue;
89         uart_setreg(&sc->sc_bas, MDR1_REG, MDR1_MODE_UART);
90
91         status = ns8250_bus_probe(sc); 
92         if (status == 0)
93                 device_set_desc(sc->sc_dev, "TI UART (16550 compatible)");
94
95         return (status);
96 }
97
98 static kobj_method_t ti8250_methods[] = {
99         KOBJMETHOD(uart_probe,          ti8250_bus_probe),
100
101         KOBJMETHOD(uart_attach,         ns8250_bus_attach),
102         KOBJMETHOD(uart_detach,         ns8250_bus_detach),
103         KOBJMETHOD(uart_flush,          ns8250_bus_flush),
104         KOBJMETHOD(uart_getsig,         ns8250_bus_getsig),
105         KOBJMETHOD(uart_ioctl,          ns8250_bus_ioctl),
106         KOBJMETHOD(uart_ipend,          ns8250_bus_ipend),
107         KOBJMETHOD(uart_param,          ns8250_bus_param),
108         KOBJMETHOD(uart_receive,        ns8250_bus_receive),
109         KOBJMETHOD(uart_setsig,         ns8250_bus_setsig),
110         KOBJMETHOD(uart_transmit,       ns8250_bus_transmit),
111         KOBJMETHOD_END
112 };
113
114 static struct uart_class uart_ti8250_class = {
115         "ti8250",
116         ti8250_methods,
117         sizeof(struct ti8250_softc),
118         .uc_ops = &uart_ns8250_ops,
119         .uc_range = 0x88,
120         .uc_rclk = 48000000,
121         .uc_rshift = 2
122 };
123 static struct ofw_compat_data compat_data[] = {
124         {"ti,ns16550",          (uintptr_t)&uart_ti8250_class},
125         {"ti,omap3-uart",       (uintptr_t)&uart_ti8250_class},
126         {"ti,omap4-uart",       (uintptr_t)&uart_ti8250_class},
127         {NULL,                  (uintptr_t)NULL},
128 };
129 UART_FDT_CLASS_AND_DEVICE(compat_data);