1169691Skan/*- 2169691Skan * Copyright (c) 2008 TAKAHASHI Yoshihiro 3169691Skan * Copyright (c) 2003 M. Warner Losh, Marcel Moolenaar 4169691Skan * All rights reserved. 5169691Skan * 6169691Skan * Redistribution and use in source and binary forms, with or without 7169691Skan * modification, are permitted provided that the following conditions 8169691Skan * are met: 9169691Skan * 10169691Skan * 1. Redistributions of source code must retain the above copyright 11169691Skan * notice, this list of conditions and the following disclaimer. 12169691Skan * 2. Redistributions in binary form must reproduce the above copyright 13169691Skan * notice, this list of conditions and the following disclaimer in the 14169691Skan * documentation and/or other materials provided with the distribution. 15169691Skan * 16169691Skan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17169691Skan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18169691Skan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19169691Skan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20169691Skan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21169691Skan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22169691Skan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23169691Skan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24169691Skan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25169691Skan * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26169691Skan */ 27169691Skan 28169691Skan#include <sys/cdefs.h> 29169691Skan__FBSDID("$FreeBSD: releng/11.0/sys/dev/uart/uart_cpu_pc98.c 216592 2010-12-20 16:39:43Z tijl $"); 30169691Skan 31169691Skan#include <sys/param.h> 32169691Skan#include <sys/systm.h> 33169691Skan#include <sys/bus.h> 34169691Skan 35169691Skan#include <machine/bus.h> 36169691Skan 37169691Skan#include <dev/uart/uart.h> 38169691Skan#include <dev/uart/uart_cpu.h> 39169691Skan 40169691Skanbus_space_tag_t uart_bus_space_io = X86_BUS_SPACE_IO; 41169691Skanbus_space_tag_t uart_bus_space_mem = X86_BUS_SPACE_MEM; 42169691Skan 43169691Skanstatic struct { 44169691Skan u_long iobase; 45169691Skan struct uart_class *class; 46169691Skan} uart_pc98_devs[] = { 47169691Skan { 0x238, &uart_ns8250_class }, 48169691Skan { 0, NULL } 49169691Skan}; 50169691Skan 51169691Skanstruct uart_class * 52169691Skanuart_pc98_getdev(u_long port) 53169691Skan{ 54169691Skan int i; 55169691Skan 56169691Skan for (i = 0; uart_pc98_devs[i].iobase; i++) { 57169691Skan if (port == uart_pc98_devs[i].iobase) 58169691Skan return (uart_pc98_devs[i].class); 59169691Skan } 60169691Skan return (NULL); 61169691Skan} 62169691Skan 63169691Skanint 64169691Skanuart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2) 65169691Skan{ 66169691Skan 67169691Skan if (bus_space_compare(b1->bst, b1->bsh, b2->bst, b2->bsh) == 0) 68169691Skan return (1); 69169691Skan 70169691Skan return (0); 71169691Skan} 72169691Skan 73169691Skanint 74169691Skanuart_cpu_getdev(int devtype, struct uart_devinfo *di) 75169691Skan{ 76169691Skan struct uart_class *class; 77169691Skan unsigned int i, ivar; 78169691Skan 79169691Skan class = &uart_ns8250_class; 80169691Skan 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} 133