uart_cpu_pc98.c revision 129276
1119822Simp/*
2119822Simp * Copyright (c) 2003 M. Warner Losh, Marcel Moolenaar
3119822Simp * All rights reserved.
4119822Simp *
5119822Simp * Redistribution and use in source and binary forms, with or without
6119822Simp * modification, are permitted provided that the following conditions
7119822Simp * are met:
8119822Simp *
9119822Simp * 1. Redistributions of source code must retain the above copyright
10119822Simp *    notice, this list of conditions and the following disclaimer.
11119822Simp * 2. Redistributions in binary form must reproduce the above copyright
12119822Simp *    notice, this list of conditions and the following disclaimer in the
13119822Simp *    documentation and/or other materials provided with the distribution.
14119822Simp *
15119822Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16119822Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17119822Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18119822Simp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19119822Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20119822Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21119822Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22119822Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23119822Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24119822Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25119822Simp */
26119822Simp
27119822Simp#include <sys/cdefs.h>
28119822Simp__FBSDID("$FreeBSD: head/sys/dev/uart/uart_cpu_pc98.c 129276 2004-05-16 14:12:05Z nyan $");
29119822Simp
30119822Simp#include <sys/param.h>
31119822Simp#include <sys/systm.h>
32119822Simp#include <sys/bus.h>
33119822Simp
34119822Simp#include <machine/bus.h>
35119822Simp
36119822Simp#include <dev/uart/uart.h>
37119822Simp#include <dev/uart/uart_cpu.h>
38119822Simp
39129276Snyanbus_space_tag_t uart_bus_space_io = I386_BUS_SPACE_IO;
40129276Snyanbus_space_tag_t uart_bus_space_mem = I386_BUS_SPACE_MEM;
41127215Smarcel
42119822Simpint
43119866Smarceluart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2)
44119866Smarcel{
45119866Smarcel
46120452Smarcel	return (0);		/* XXX */
47119866Smarcel}
48119866Smarcel
49119866Smarcelint
50119822Simpuart_cpu_getdev(int devtype, struct uart_devinfo *di)
51119822Simp{
52119822Simp	unsigned int i, ivar, flags;
53119822Simp
54127215Smarcel	/* Check the environment. */
55127215Smarcel	if (uart_getenv(devtype, di) == 0)
56127215Smarcel		return (0);
57127215Smarcel
58119822Simp	/*
59129276Snyan	 * There is a serial port on all pc98 hardware.  It is 8251 or
60129276Snyan	 * an enhance version of that.  Some pc98 have the second serial
61129276Snyan	 * port which is 16550A compatible.  However, for the sio driver,
62129276Snyan	 * flags selected which type of uart was in the sytem.  We use
63129276Snyan	 * something similar to sort things out.
64119822Simp	 */
65119822Simp	for (i = 0; i < 1; i++) {
66119822Simp		if (resource_int_value("uart", i, "flags", &flags))
67119822Simp			continue;
68119822Simp		if (devtype == UART_DEV_CONSOLE && !UART_FLAGS_CONSOLE(flags))
69119822Simp			continue;
70119822Simp		if (devtype == UART_DEV_DBGPORT && !UART_FLAGS_DBGPORT(flags))
71119822Simp			continue;
72119822Simp		/*
73119822Simp		 * We have a possible device. Make sure it's enabled and
74119822Simp		 * that we have an I/O port.
75119822Simp		 */
76119822Simp		if (resource_int_value("uart", i, "disabled", &ivar) == 0 &&
77119822Simp		    ivar != 0)
78119822Simp			continue;
79119822Simp		if (resource_int_value("uart", i, "port", &ivar) != 0 ||
80119822Simp		    ivar == 0)
81119822Simp			continue;
82119822Simp		/*
83119822Simp		 * Got it. Fill in the instance and return it. We have
84119822Simp		 * both i8251 an ns8250 and successors on pc98.
85119822Simp		 */
86119822Simp		if (flags & 0x100)
87119822Simp			di->ops = uart_ns8250_ops;
88119822Simp		else
89119822Simp			di->ops = uart_i8251_ops;
90120452Smarcel		di->bas.chan = 0;
91127215Smarcel		di->bas.bst = uart_bus_space_io;
92120376Snyan		if (bus_space_map(di->bas.bst, ivar, 8, 0, &di->bas.bsh) != 0)
93120381Snyan			continue;
94119822Simp		di->bas.regshft = 0;
95119822Simp		di->bas.rclk = 0;
96119822Simp		if (resource_int_value("uart", i, "baud", &ivar) != 0)
97119822Simp			ivar = 0;
98119822Simp		di->baudrate = ivar;
99119822Simp		di->databits = 8;
100119822Simp		di->stopbits = 1;
101119822Simp		di->parity = UART_PARITY_NONE;
102119822Simp		return (0);
103119822Simp	}
104119822Simp
105119822Simp	return (ENXIO);
106119822Simp}
107