uart_bus_pci.c revision 261998
1139749Simp/*- 2158078Smarcel * Copyright (c) 2006 Marcel Moolenaar 3158078Smarcel * Copyright (c) 2001 M. Warner Losh 4158078Smarcel * All rights reserved. 5119815Smarcel * 6119815Smarcel * Redistribution and use in source and binary forms, with or without 7119815Smarcel * modification, are permitted provided that the following conditions 8119815Smarcel * are met: 9119815Smarcel * 1. Redistributions of source code must retain the above copyright 10119815Smarcel * notice, this list of conditions and the following disclaimer. 11119815Smarcel * 2. Redistributions in binary form must reproduce the above copyright 12119815Smarcel * notice, this list of conditions and the following disclaimer in the 13119815Smarcel * documentation and/or other materials provided with the distribution. 14119815Smarcel * 15119815Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16119815Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17119815Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18119815Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19119815Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20119815Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21119815Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22119815Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23119815Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24119815Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25119815Smarcel */ 26119815Smarcel 27119815Smarcel#include <sys/cdefs.h> 28119815Smarcel__FBSDID("$FreeBSD: stable/10/sys/dev/uart/uart_bus_pci.c 261998 2014-02-16 20:45:12Z marcel $"); 29119815Smarcel 30119815Smarcel#include <sys/param.h> 31119815Smarcel#include <sys/systm.h> 32119815Smarcel#include <sys/bus.h> 33119815Smarcel#include <sys/conf.h> 34119815Smarcel#include <sys/kernel.h> 35119815Smarcel#include <sys/module.h> 36119815Smarcel#include <machine/bus.h> 37119815Smarcel#include <sys/rman.h> 38119815Smarcel#include <machine/resource.h> 39119815Smarcel 40119815Smarcel#include <dev/pci/pcivar.h> 41119815Smarcel 42119815Smarcel#include <dev/uart/uart.h> 43119815Smarcel#include <dev/uart/uart_bus.h> 44119815Smarcel 45158058Smarcel#define DEFAULT_RCLK 1843200 46158058Smarcel 47119815Smarcelstatic int uart_pci_probe(device_t dev); 48119815Smarcel 49119815Smarcelstatic device_method_t uart_pci_methods[] = { 50119815Smarcel /* Device interface */ 51119815Smarcel DEVMETHOD(device_probe, uart_pci_probe), 52119815Smarcel DEVMETHOD(device_attach, uart_bus_attach), 53119815Smarcel DEVMETHOD(device_detach, uart_bus_detach), 54246243Savg DEVMETHOD(device_resume, uart_bus_resume), 55246300Smarius DEVMETHOD_END 56119815Smarcel}; 57119815Smarcel 58119815Smarcelstatic driver_t uart_pci_driver = { 59119815Smarcel uart_driver_name, 60119815Smarcel uart_pci_methods, 61119815Smarcel sizeof(struct uart_softc), 62119815Smarcel}; 63119815Smarcel 64119815Smarcelstruct pci_id { 65158058Smarcel uint16_t vendor; 66158058Smarcel uint16_t device; 67158058Smarcel uint16_t subven; 68158058Smarcel uint16_t subdev; 69119815Smarcel const char *desc; 70119815Smarcel int rid; 71158058Smarcel int rclk; 72119815Smarcel}; 73119815Smarcel 74246300Smariusstatic const struct pci_id pci_ns8250_ids[] = { 75158078Smarcel{ 0x1028, 0x0008, 0xffff, 0, "Dell Remote Access Card III", 0x14, 76158078Smarcel 128 * DEFAULT_RCLK }, 77158078Smarcel{ 0x1028, 0x0012, 0xffff, 0, "Dell RAC 4 Daughter Card Virtual UART", 0x14, 78158078Smarcel 128 * DEFAULT_RCLK }, 79158058Smarcel{ 0x1033, 0x0074, 0x1033, 0x8014, "NEC RCV56ACF 56k Voice Modem", 0x10 }, 80158058Smarcel{ 0x1033, 0x007d, 0x1033, 0x8012, "NEC RS232C", 0x10 }, 81158078Smarcel{ 0x103c, 0x1048, 0x103c, 0x1227, "HP Diva Serial [GSP] UART - Powerbar SP2", 82158078Smarcel 0x10 }, 83169646Smarcel{ 0x103c, 0x1048, 0x103c, 0x1301, "HP Diva RMP3", 0x14 }, 84158078Smarcel{ 0x103c, 0x1290, 0xffff, 0, "HP Auxiliary Diva Serial Port", 0x18 }, 85261998Smarcel{ 0x103c, 0x3301, 0xffff, 0, "HP iLO serial port", 0x10 }, 86158058Smarcel{ 0x11c1, 0x0480, 0xffff, 0, "Agere Systems Venus Modem (V90, 56KFlex)", 0x14 }, 87158058Smarcel{ 0x115d, 0x0103, 0xffff, 0, "Xircom Cardbus Ethernet + 56k Modem", 0x10 }, 88223874Sjhb{ 0x1282, 0x6585, 0xffff, 0, "Davicom 56PDV PCI Modem", 0x10 }, 89158058Smarcel{ 0x12b9, 0x1008, 0xffff, 0, "3Com 56K FaxModem Model 5610", 0x10 }, 90158058Smarcel{ 0x131f, 0x1000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x18 }, 91158058Smarcel{ 0x131f, 0x1001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x18 }, 92158058Smarcel{ 0x131f, 0x1002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x18 }, 93158058Smarcel{ 0x131f, 0x2000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x10 }, 94158058Smarcel{ 0x131f, 0x2001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x10 }, 95158058Smarcel{ 0x131f, 0x2002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x10 }, 96158058Smarcel{ 0x135c, 0x0190, 0xffff, 0, "Quatech SSCLP-100", 0x18 }, 97158058Smarcel{ 0x135c, 0x01c0, 0xffff, 0, "Quatech SSCLP-200/300", 0x18 }, 98158078Smarcel{ 0x135e, 0x7101, 0xffff, 0, "Sealevel Systems Single Port RS-232/422/485/530", 99158078Smarcel 0x18 }, 100158058Smarcel{ 0x1407, 0x0110, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port A", 0x10 }, 101158058Smarcel{ 0x1407, 0x0111, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port B", 0x10 }, 102188472Skaiw{ 0x1407, 0x0510, 0xffff, 0, "Lava SP Serial 550 PCI", 0x10 }, 103158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x4025, "Timedia Technology Serial Port", 0x10, 104158078Smarcel 8 * DEFAULT_RCLK }, 105158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x4027, "Timedia Technology Serial Port", 0x10, 106158078Smarcel 8 * DEFAULT_RCLK }, 107158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x4028, "Timedia Technology Serial Port", 0x10, 108158078Smarcel 8 * DEFAULT_RCLK }, 109158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x5025, "Timedia Technology Serial Port", 0x10, 110158078Smarcel 8 * DEFAULT_RCLK }, 111158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x5027, "Timedia Technology Serial Port", 0x10, 112158078Smarcel 8 * DEFAULT_RCLK }, 113158078Smarcel{ 0x1415, 0x950b, 0xffff, 0, "Oxford Semiconductor OXCB950 Cardbus 16950 UART", 114158078Smarcel 0x10, 16384000 }, 115230327Seadler{ 0x14e4, 0x4344, 0xffff, 0, "Sony Ericsson GC89 PC Card", 0x10}, 116158078Smarcel{ 0x151f, 0x0000, 0xffff, 0, "TOPIC Semiconductor TP560 56k modem", 0x10 }, 117228947Skib{ 0x8086, 0x1c3d, 0xffff, 0, "Intel AMT - KT Controller", 0x10 }, 118249803Seadler{ 0x8086, 0x1d3d, 0xffff, 0, "Intel C600/X79 Series Chipset KT Controller", 0x10 }, 119232967Skib{ 0x8086, 0x2e17, 0xffff, 0, "4 Series Chipset Serial KT Controller", 0x10 }, 120229971Skib{ 0x8086, 0x3b67, 0xffff, 0, "5 Series/3400 Series Chipset KT Controller", 121229971Skib 0x10 }, 122229379Skevlo{ 0x8086, 0x8811, 0xffff, 0, "Intel EG20T Serial Port 0", 0x10 }, 123229379Skevlo{ 0x8086, 0x8812, 0xffff, 0, "Intel EG20T Serial Port 1", 0x10 }, 124229379Skevlo{ 0x8086, 0x8813, 0xffff, 0, "Intel EG20T Serial Port 2", 0x10 }, 125229379Skevlo{ 0x8086, 0x8814, 0xffff, 0, "Intel EG20T Serial Port 3", 0x10 }, 126200257Smav{ 0x9710, 0x9820, 0x1000, 1, "NetMos NM9820 Serial Port", 0x10 }, 127189407Sjhb{ 0x9710, 0x9835, 0x1000, 1, "NetMos NM9835 Serial Port", 0x10 }, 128200230Smarcel{ 0x9710, 0x9865, 0xa000, 0x1000, "NetMos NM9865 Serial Port", 0x10 }, 129223672Shselasky{ 0x9710, 0x9900, 0xa000, 0x1000, 130223672Shselasky "MosChip MCS9900 PCIe to Peripheral Controller", 0x10 }, 131204533Sdelphij{ 0x9710, 0x9901, 0xa000, 0x1000, 132204533Sdelphij "MosChip MCS9901 PCIe to Peripheral Controller", 0x10 }, 133232639Sremko{ 0x9710, 0x9904, 0xa000, 0x1000, 134232639Sremko "MosChip MCS9904 PCIe to Peripheral Controller", 0x10 }, 135158058Smarcel{ 0xdeaf, 0x9051, 0xffff, 0, "Middle Digital PC Weasel Serial Port", 0x10 }, 136158058Smarcel{ 0xffff, 0, 0xffff, 0, NULL, 0, 0} 137119815Smarcel}; 138119815Smarcel 139246300Smariusconst static struct pci_id * 140246300Smariusuart_pci_match(device_t dev, const struct pci_id *id) 141119815Smarcel{ 142158058Smarcel uint16_t device, subdev, subven, vendor; 143119815Smarcel 144158058Smarcel vendor = pci_get_vendor(dev); 145158058Smarcel device = pci_get_device(dev); 146158058Smarcel while (id->vendor != 0xffff && 147158058Smarcel (id->vendor != vendor || id->device != device)) 148119815Smarcel id++; 149158058Smarcel if (id->vendor == 0xffff) 150158058Smarcel return (NULL); 151158058Smarcel if (id->subven == 0xffff) 152158058Smarcel return (id); 153158058Smarcel subven = pci_get_subvendor(dev); 154158058Smarcel subdev = pci_get_subdevice(dev); 155158058Smarcel while (id->vendor == vendor && id->device == device && 156158058Smarcel (id->subven != subven || id->subdev != subdev)) 157158058Smarcel id++; 158158058Smarcel return ((id->vendor == vendor && id->device == device) ? id : NULL); 159119815Smarcel} 160119815Smarcel 161119815Smarcelstatic int 162119815Smarceluart_pci_probe(device_t dev) 163119815Smarcel{ 164119815Smarcel struct uart_softc *sc; 165246300Smarius const struct pci_id *id; 166253654Smarcel int result; 167119815Smarcel 168119815Smarcel sc = device_get_softc(dev); 169119815Smarcel 170158058Smarcel id = uart_pci_match(dev, pci_ns8250_ids); 171119815Smarcel if (id != NULL) { 172119815Smarcel sc->sc_class = &uart_ns8250_class; 173119815Smarcel goto match; 174119815Smarcel } 175119815Smarcel /* Add checks for non-ns8250 IDs here. */ 176119815Smarcel return (ENXIO); 177119815Smarcel 178119815Smarcel match: 179253654Smarcel result = uart_bus_probe(dev, 0, id->rclk, id->rid, 0); 180253654Smarcel /* Bail out on error. */ 181253654Smarcel if (result > 0) 182253654Smarcel return (result); 183253654Smarcel /* Set/override the device description. */ 184119815Smarcel if (id->desc) 185119815Smarcel device_set_desc(dev, id->desc); 186253654Smarcel return (result); 187119815Smarcel} 188119815Smarcel 189246300SmariusDRIVER_MODULE(uart, pci, uart_pci_driver, uart_devclass, NULL, NULL); 190