1 /*-
2 * Copyright (c) 2008 TAKAHASHI Yoshihiro
3 * Copyright (c) 2003 M. Warner Losh, Marcel Moolenaar
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/bus.h>
34
35 #include <machine/bus.h>
36
37 #include <dev/uart/uart.h>
38 #include <dev/uart/uart_cpu.h>
39
40 bus_space_tag_t uart_bus_space_io = X86_BUS_SPACE_IO;
41 bus_space_tag_t uart_bus_space_mem = X86_BUS_SPACE_MEM;
42
43 static struct {
44 u_long iobase;
45 struct uart_class *class;
46 } uart_pc98_devs[] = {
47 { 0x238, &uart_ns8250_class },
48 { 0, NULL }
49 };
50
51 struct uart_class *
52 uart_pc98_getdev(u_long port)
53 {
54 int i;
55
56 for (i = 0; uart_pc98_devs[i].iobase; i++) {
57 if (port == uart_pc98_devs[i].iobase)
58 return (uart_pc98_devs[i].class);
59 }
60 return (NULL);
61 }
62
63 int
64 uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2)
65 {
66
67 if (bus_space_compare(b1->bst, b1->bsh, b2->bst, b2->bsh) == 0)
68 return (1);
69
70 return (0);
71 }
72
73 int
74 uart_cpu_getdev(int devtype, struct uart_devinfo *di)
75 {
76 struct uart_class *class;
77 unsigned int i, ivar;
78
79 class = &uart_ns8250_class;
80 if (class == NULL)
81 return (ENXIO);
82
83 /* Check the environment. */
84 if (uart_getenv(devtype, di, class) == 0)
85 return (0);
86
87 /*
88 * There is a serial port on all pc98 hardware. It is 8251 or
89 * an enhance version of that. Some pc98 have the second serial
90 * port which is 16550A compatible.
91 */
92 for (i = 0; i < 2; i++) {
93 if (resource_int_value("uart", i, "flags", &ivar))
94 continue;
95 if (devtype == UART_DEV_CONSOLE && !UART_FLAGS_CONSOLE(ivar))
96 continue;
97 if (devtype == UART_DEV_DBGPORT && !UART_FLAGS_DBGPORT(ivar))
98 continue;
99 /*
100 * We have a possible device. Make sure it's enabled and
101 * that we have an I/O port.
102 */
103 if (resource_int_value("uart", i, "disabled", &ivar) == 0 &&
104 ivar != 0)
105 continue;
106 if (resource_int_value("uart", i, "port", &ivar) != 0 ||
107 ivar == 0)
108 continue;
109
110 class = uart_pc98_getdev(ivar);
111 if (class == NULL)
112 continue;
113
114 di->ops = uart_getops(class);
115 di->bas.chan = 0;
116 di->bas.bst = uart_bus_space_io;
117 if (bus_space_map(di->bas.bst, ivar, uart_getrange(class), 0,
118 &di->bas.bsh) != 0)
119 continue;
120 di->bas.regshft = 0;
121 di->bas.rclk = 0;
122 if (resource_int_value("uart", i, "baud", &ivar) != 0)
123 ivar = 0;
124 di->baudrate = ivar;
125 di->databits = 8;
126 di->stopbits = 1;
127 di->parity = UART_PARITY_NONE;
128 return (0);
129 }
130
131 return (ENXIO);
132 }
Cache object: e98e57042953cde913c40e53afd0eef8
|