1139969Simp/*- 21556Srgrimes * Copyright (c) 2006 Marcel Moolenaar 31556Srgrimes * Copyright (c) 2001 M. Warner Losh 41556Srgrimes * All rights reserved. 51556Srgrimes * 61556Srgrimes * Redistribution and use in source and binary forms, with or without 71556Srgrimes * modification, are permitted provided that the following conditions 81556Srgrimes * are met: 91556Srgrimes * 1. Redistributions of source code must retain the above copyright 101556Srgrimes * notice, this list of conditions and the following disclaimer. 111556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 121556Srgrimes * notice, this list of conditions and the following disclaimer in the 131556Srgrimes * documentation and/or other materials provided with the distribution. 141556Srgrimes * 151556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 161556Srgrimes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 171556Srgrimes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 181556Srgrimes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 191556Srgrimes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 201556Srgrimes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 211556Srgrimes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 221556Srgrimes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 231556Srgrimes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 241556Srgrimes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 251556Srgrimes */ 261556Srgrimes 271556Srgrimes#include <sys/cdefs.h> 281556Srgrimes__FBSDID("$FreeBSD$"); 291556Srgrimes 301556Srgrimes#include <sys/param.h> 311556Srgrimes#include <sys/systm.h> 321556Srgrimes#include <sys/bus.h> 3390153Smarkm#include <sys/conf.h> 341556Srgrimes#include <sys/kernel.h> 3527967Ssteve#include <sys/module.h> 3690153Smarkm#include <machine/bus.h> 3727967Ssteve#include <sys/rman.h> 3899109Sobrien#include <machine/resource.h> 3999109Sobrien 401556Srgrimes#include <dev/pci/pcivar.h> 411556Srgrimes 421556Srgrimes#include <dev/uart/uart.h> 43106371Stjr#include <dev/uart/uart_bus.h> 441556Srgrimes 451556Srgrimes#define DEFAULT_RCLK 1843200 461556Srgrimes 471556Srgrimesstatic int uart_pci_probe(device_t dev); 4874566Sache 49129719Spjdstatic device_method_t uart_pci_methods[] = { 501556Srgrimes /* Device interface */ 51225847Sed DEVMETHOD(device_probe, uart_pci_probe), 521556Srgrimes DEVMETHOD(device_attach, uart_bus_attach), 531556Srgrimes DEVMETHOD(device_detach, uart_bus_detach), 5491212Sbde DEVMETHOD(device_resume, uart_bus_resume), 551556Srgrimes DEVMETHOD_END 5661294Sache}; 5761294Sache 5861294Sachestatic driver_t uart_pci_driver = { 5961294Sache uart_driver_name, 6061294Sache uart_pci_methods, 611556Srgrimes sizeof(struct uart_softc), 621556Srgrimes}; 631556Srgrimes 641556Srgrimesstruct pci_id { 65114583Smarkm uint16_t vendor; 66202945Sjh uint16_t device; 67105780Smarkm uint16_t subven; 6890110Simp uint16_t subdev; 6990110Simp const char *desc; 7090110Simp int rid; 7161321Sache int rclk; 7290110Simp}; 7390110Simp 7461321Sachestatic const struct pci_id pci_ns8250_ids[] = { 75196712Strasz{ 0x1028, 0x0008, 0xffff, 0, "Dell Remote Access Card III", 0x14, 761556Srgrimes 128 * DEFAULT_RCLK }, 771556Srgrimes{ 0x1028, 0x0012, 0xffff, 0, "Dell RAC 4 Daughter Card Virtual UART", 0x14, 781556Srgrimes 128 * DEFAULT_RCLK }, 7961268Sjoe{ 0x1033, 0x0074, 0x1033, 0x8014, "NEC RCV56ACF 56k Voice Modem", 0x10 }, 8061178Sjoe{ 0x1033, 0x007d, 0x1033, 0x8012, "NEC RS232C", 0x10 }, 8161178Sjoe{ 0x103c, 0x1048, 0x103c, 0x1227, "HP Diva Serial [GSP] UART - Powerbar SP2", 8288602Sjoe 0x10 }, 8388602Sjoe{ 0x103c, 0x1048, 0x103c, 0x1301, "HP Diva RMP3", 0x14 }, 8488602Sjoe{ 0x103c, 0x1290, 0xffff, 0, "HP Auxiliary Diva Serial Port", 0x18 }, 8588602Sjoe{ 0x103c, 0x3301, 0xffff, 0, "HP iLO serial port", 0x10 }, 8688602Sjoe{ 0x11c1, 0x0480, 0xffff, 0, "Agere Systems Venus Modem (V90, 56KFlex)", 0x14 }, 8788602Sjoe{ 0x115d, 0x0103, 0xffff, 0, "Xircom Cardbus Ethernet + 56k Modem", 0x10 }, 8888602Sjoe{ 0x1282, 0x6585, 0xffff, 0, "Davicom 56PDV PCI Modem", 0x10 }, 8988602Sjoe{ 0x12b9, 0x1008, 0xffff, 0, "3Com 56K FaxModem Model 5610", 0x10 }, 9088602Sjoe{ 0x131f, 0x1000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x18 }, 9188602Sjoe{ 0x131f, 0x1001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x18 }, 9288602Sjoe{ 0x131f, 0x1002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x18 }, 9388602Sjoe{ 0x131f, 0x2000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x10 }, 9488602Sjoe{ 0x131f, 0x2001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x10 }, 9588602Sjoe{ 0x131f, 0x2002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x10 }, 9688586Sjoe{ 0x135c, 0x0190, 0xffff, 0, "Quatech SSCLP-100", 0x18 }, 9761178Sjoe{ 0x135c, 0x01c0, 0xffff, 0, "Quatech SSCLP-200/300", 0x18 }, 9890150Smarkm{ 0x135e, 0x7101, 0xffff, 0, "Sealevel Systems Single Port RS-232/422/485/530", 9961178Sjoe 0x18 }, 10088583Sjoe{ 0x1407, 0x0110, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port A", 0x10 }, 10188583Sjoe{ 0x1407, 0x0111, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port B", 0x10 }, 10288586Sjoe{ 0x1407, 0x0510, 0xffff, 0, "Lava SP Serial 550 PCI", 0x10 }, 10388586Sjoe{ 0x1409, 0x7168, 0x1409, 0x4025, "Timedia Technology Serial Port", 0x10, 10488583Sjoe 8 * DEFAULT_RCLK }, 10561268Sjoe{ 0x1409, 0x7168, 0x1409, 0x4027, "Timedia Technology Serial Port", 0x10, 10661178Sjoe 8 * DEFAULT_RCLK }, 1071556Srgrimes{ 0x1409, 0x7168, 0x1409, 0x4028, "Timedia Technology Serial Port", 0x10, 108114583Smarkm 8 * DEFAULT_RCLK }, 1091556Srgrimes{ 0x1409, 0x7168, 0x1409, 0x5025, "Timedia Technology Serial Port", 0x10, 11088594Sjoe 8 * DEFAULT_RCLK }, 1111556Srgrimes{ 0x1409, 0x7168, 0x1409, 0x5027, "Timedia Technology Serial Port", 0x10, 1121556Srgrimes 8 * DEFAULT_RCLK }, 1131556Srgrimes{ 0x1415, 0x950b, 0xffff, 0, "Oxford Semiconductor OXCB950 Cardbus 16950 UART", 1141556Srgrimes 0x10, 16384000 }, 1151556Srgrimes{ 0x14e4, 0x4344, 0xffff, 0, "Sony Ericsson GC89 PC Card", 0x10}, 1161556Srgrimes{ 0x151f, 0x0000, 0xffff, 0, "TOPIC Semiconductor TP560 56k modem", 0x10 }, 1171556Srgrimes{ 0x1fd4, 0x1999, 0x1fd4, 0x0001, "Sunix SER5xxxx Serial Port", 0x10, 1181556Srgrimes 8 * DEFAULT_RCLK }, 1191556Srgrimes{ 0x8086, 0x1c3d, 0xffff, 0, "Intel AMT - KT Controller", 0x10 }, 12062597Sassar{ 0x8086, 0x1d3d, 0xffff, 0, "Intel C600/X79 Series Chipset KT Controller", 0x10 }, 12162597Sassar{ 0x8086, 0x2e17, 0xffff, 0, "4 Series Chipset Serial KT Controller", 0x10 }, 12262597Sassar{ 0x8086, 0x3b67, 0xffff, 0, "5 Series/3400 Series Chipset KT Controller", 123105390Stjr 0x10 }, 12490110Simp{ 0x8086, 0x8811, 0xffff, 0, "Intel EG20T Serial Port 0", 0x10 }, 12562597Sassar{ 0x8086, 0x8812, 0xffff, 0, "Intel EG20T Serial Port 1", 0x10 }, 12662597Sassar{ 0x8086, 0x8813, 0xffff, 0, "Intel EG20T Serial Port 2", 0x10 }, 12762597Sassar{ 0x8086, 0x8814, 0xffff, 0, "Intel EG20T Serial Port 3", 0x10 }, 12862597Sassar{ 0x8086, 0x8c3d, 0xffff, 0, "Intel Lynx Point KT Controller", 0x10 }, 12962597Sassar{ 0x9710, 0x9820, 0x1000, 1, "NetMos NM9820 Serial Port", 0x10 }, 13062597Sassar{ 0x9710, 0x9835, 0x1000, 1, "NetMos NM9835 Serial Port", 0x10 }, 131128823Stjr{ 0x9710, 0x9865, 0xa000, 0x1000, "NetMos NM9865 Serial Port", 0x10 }, 13262597Sassar{ 0x9710, 0x9900, 0xa000, 0x1000, 13362597Sassar "MosChip MCS9900 PCIe to Peripheral Controller", 0x10 }, 1341556Srgrimes{ 0x9710, 0x9901, 0xa000, 0x1000, 135114583Smarkm "MosChip MCS9901 PCIe to Peripheral Controller", 0x10 }, 1361556Srgrimes{ 0x9710, 0x9904, 0xa000, 0x1000, 1371556Srgrimes "MosChip MCS9904 PCIe to Peripheral Controller", 0x10 }, 13888594Sjoe{ 0xdeaf, 0x9051, 0xffff, 0, "Middle Digital PC Weasel Serial Port", 0x10 }, 13988594Sjoe{ 0xffff, 0, 0xffff, 0, NULL, 0, 0} 14088594Sjoe}; 14161292Sache 14288594Sjoeconst static struct pci_id * 14361292Sacheuart_pci_match(device_t dev, const struct pci_id *id) 1441556Srgrimes{ 145130236Sdas uint16_t device, subdev, subven, vendor; 146130236Sdas 1471556Srgrimes vendor = pci_get_vendor(dev); 148130236Sdas device = pci_get_device(dev); 1491556Srgrimes while (id->vendor != 0xffff && 1501556Srgrimes (id->vendor != vendor || id->device != device)) 1511556Srgrimes id++; 1521556Srgrimes if (id->vendor == 0xffff) 1531556Srgrimes return (NULL); 1541556Srgrimes if (id->subven == 0xffff) 155241014Smdf return (id); 156241014Smdf subven = pci_get_subvendor(dev); 1571556Srgrimes subdev = pci_get_subdevice(dev); 158114583Smarkm while (id->vendor == vendor && id->device == device && 1591556Srgrimes (id->subven != subven || id->subdev != subdev)) 16090150Smarkm id++; 161196712Strasz return ((id->vendor == vendor && id->device == device) ? id : NULL); 1621556Srgrimes} 163242840Speter 1641556Srgrimesstatic int 1651556Srgrimesuart_pci_probe(device_t dev) 1661556Srgrimes{ 1671556Srgrimes struct uart_softc *sc; 168105832Srwatson const struct pci_id *id; 169105832Srwatson int result; 1701556Srgrimes 171202945Sjh sc = device_get_softc(dev); 1721556Srgrimes 17388591Sjoe id = uart_pci_match(dev, pci_ns8250_ids); 1741556Srgrimes if (id != NULL) { 1751556Srgrimes sc->sc_class = &uart_ns8250_class; 176157098Sjhb goto match; 177157098Sjhb } 1781556Srgrimes /* Add checks for non-ns8250 IDs here. */ 1791556Srgrimes return (ENXIO); 1801556Srgrimes 1811556Srgrimes match: 18261268Sjoe result = uart_bus_probe(dev, 0, id->rclk, id->rid, 0); 18361178Sjoe /* Bail out on error. */ 18461291Sache if (result > 0) 18561268Sjoe return (result); 18662597Sassar /* Set/override the device description. */ 18761268Sjoe if (id->desc) 18861291Sache device_set_desc(dev, id->desc); 18961321Sache return (result); 19061268Sjoe} 1911556Srgrimes 1921556SrgrimesDRIVER_MODULE(uart, pci, uart_pci_driver, uart_devclass, NULL, NULL); 1931556Srgrimes