1139749Simp/*- 2182159Snyan * Copyright (c) 2008 TAKAHASHI Yoshihiro 3119822Simp * Copyright (c) 2003 M. Warner Losh, Marcel Moolenaar 4119822Simp * All rights reserved. 5119822Simp * 6119822Simp * Redistribution and use in source and binary forms, with or without 7119822Simp * modification, are permitted provided that the following conditions 8119822Simp * are met: 9119822Simp * 10119822Simp * 1. Redistributions of source code must retain the above copyright 11119822Simp * notice, this list of conditions and the following disclaimer. 12119822Simp * 2. Redistributions in binary form must reproduce the above copyright 13119822Simp * notice, this list of conditions and the following disclaimer in the 14119822Simp * documentation and/or other materials provided with the distribution. 15119822Simp * 16119822Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17119822Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18119822Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19119822Simp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20119822Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21119822Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22119822Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23119822Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24119822Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25119822Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26119822Simp */ 27119822Simp 28119822Simp#include <sys/cdefs.h> 29119822Simp__FBSDID("$FreeBSD$"); 30119822Simp 31119822Simp#include <sys/param.h> 32119822Simp#include <sys/systm.h> 33119822Simp#include <sys/bus.h> 34119822Simp 35119822Simp#include <machine/bus.h> 36119822Simp 37119822Simp#include <dev/uart/uart.h> 38119822Simp#include <dev/uart/uart_cpu.h> 39119822Simp 40216592Stijlbus_space_tag_t uart_bus_space_io = X86_BUS_SPACE_IO; 41216592Stijlbus_space_tag_t uart_bus_space_mem = X86_BUS_SPACE_MEM; 42127215Smarcel 43182159Snyanstatic struct { 44182159Snyan u_long iobase; 45182159Snyan struct uart_class *class; 46182159Snyan} uart_pc98_devs[] = { 47182159Snyan { 0x238, &uart_ns8250_class }, 48182159Snyan { 0, NULL } 49182159Snyan}; 50182159Snyan 51182159Snyanstruct uart_class * 52182159Snyanuart_pc98_getdev(u_long port) 53182159Snyan{ 54182159Snyan int i; 55182159Snyan 56182159Snyan for (i = 0; uart_pc98_devs[i].iobase; i++) { 57182159Snyan if (port == uart_pc98_devs[i].iobase) 58182159Snyan return (uart_pc98_devs[i].class); 59182159Snyan } 60182159Snyan return (NULL); 61182159Snyan} 62182159Snyan 63119822Simpint 64119866Smarceluart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2) 65119866Smarcel{ 66119866Smarcel 67182837Snyan if (bus_space_compare(b1->bst, b1->bsh, b2->bst, b2->bsh) == 0) 68182159Snyan return (1); 69182159Snyan 70182159Snyan return (0); 71119866Smarcel} 72119866Smarcel 73119866Smarcelint 74119822Simpuart_cpu_getdev(int devtype, struct uart_devinfo *di) 75119822Simp{ 76168281Smarcel struct uart_class *class; 77182159Snyan unsigned int i, ivar; 78119822Simp 79168281Smarcel class = &uart_ns8250_class; 80168281Smarcel if (class == NULL) 81168281Smarcel return (ENXIO); 82168281Smarcel 83127215Smarcel /* Check the environment. */ 84168281Smarcel if (uart_getenv(devtype, di, class) == 0) 85127215Smarcel return (0); 86127215Smarcel 87119822Simp /* 88129276Snyan * There is a serial port on all pc98 hardware. It is 8251 or 89129276Snyan * an enhance version of that. Some pc98 have the second serial 90182159Snyan * port which is 16550A compatible. 91119822Simp */ 92182159Snyan for (i = 0; i < 2; i++) { 93182159Snyan if (resource_int_value("uart", i, "flags", &ivar)) 94119822Simp continue; 95182159Snyan if (devtype == UART_DEV_CONSOLE && !UART_FLAGS_CONSOLE(ivar)) 96119822Simp continue; 97182159Snyan if (devtype == UART_DEV_DBGPORT && !UART_FLAGS_DBGPORT(ivar)) 98119822Simp continue; 99119822Simp /* 100119822Simp * We have a possible device. Make sure it's enabled and 101119822Simp * that we have an I/O port. 102119822Simp */ 103119822Simp if (resource_int_value("uart", i, "disabled", &ivar) == 0 && 104119822Simp ivar != 0) 105119822Simp continue; 106119822Simp if (resource_int_value("uart", i, "port", &ivar) != 0 || 107119822Simp ivar == 0) 108119822Simp continue; 109137972Snyan 110182159Snyan class = uart_pc98_getdev(ivar); 111182159Snyan if (class == NULL) 112182159Snyan continue; 113182159Snyan 114168281Smarcel di->ops = uart_getops(class); 115120452Smarcel di->bas.chan = 0; 116127215Smarcel di->bas.bst = uart_bus_space_io; 117168281Smarcel if (bus_space_map(di->bas.bst, ivar, uart_getrange(class), 0, 118168281Smarcel &di->bas.bsh) != 0) 119120381Snyan continue; 120119822Simp di->bas.regshft = 0; 121119822Simp di->bas.rclk = 0; 122119822Simp if (resource_int_value("uart", i, "baud", &ivar) != 0) 123119822Simp ivar = 0; 124119822Simp di->baudrate = ivar; 125119822Simp di->databits = 8; 126119822Simp di->stopbits = 1; 127119822Simp di->parity = UART_PARITY_NONE; 128119822Simp return (0); 129119822Simp } 130119822Simp 131119822Simp return (ENXIO); 132119822Simp} 133