uart_bus_pci.c revision 158058
1139749Simp/*- 2119815Smarcel * Copyright (c) 2001 M. Warner Losh. All rights reserved. 3119815Smarcel * 4119815Smarcel * Redistribution and use in source and binary forms, with or without 5119815Smarcel * modification, are permitted provided that the following conditions 6119815Smarcel * are met: 7119815Smarcel * 1. Redistributions of source code must retain the above copyright 8119815Smarcel * notice, this list of conditions and the following disclaimer. 9119815Smarcel * 2. Redistributions in binary form must reproduce the above copyright 10119815Smarcel * notice, this list of conditions and the following disclaimer in the 11119815Smarcel * documentation and/or other materials provided with the distribution. 12119815Smarcel * 13119815Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14119815Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15119815Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16119815Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17119815Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18119815Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19119815Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20119815Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21119815Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22119815Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23119815Smarcel */ 24119815Smarcel 25119815Smarcel#include <sys/cdefs.h> 26119815Smarcel__FBSDID("$FreeBSD: head/sys/dev/uart/uart_bus_pci.c 158058 2006-04-26 21:31:31Z marcel $"); 27119815Smarcel 28119815Smarcel#include <sys/param.h> 29119815Smarcel#include <sys/systm.h> 30119815Smarcel#include <sys/bus.h> 31119815Smarcel#include <sys/conf.h> 32119815Smarcel#include <sys/kernel.h> 33119815Smarcel#include <sys/module.h> 34119815Smarcel#include <machine/bus.h> 35119815Smarcel#include <sys/rman.h> 36119815Smarcel#include <machine/resource.h> 37119815Smarcel 38119815Smarcel#include <dev/pci/pcivar.h> 39119815Smarcel 40119815Smarcel#include <dev/uart/uart.h> 41119815Smarcel#include <dev/uart/uart_bus.h> 42119815Smarcel 43158058Smarcel#define DEFAULT_RCLK 1843200 44158058Smarcel 45119815Smarcelstatic int uart_pci_probe(device_t dev); 46119815Smarcel 47119815Smarcelstatic device_method_t uart_pci_methods[] = { 48119815Smarcel /* Device interface */ 49119815Smarcel DEVMETHOD(device_probe, uart_pci_probe), 50119815Smarcel DEVMETHOD(device_attach, uart_bus_attach), 51119815Smarcel DEVMETHOD(device_detach, uart_bus_detach), 52119815Smarcel { 0, 0 } 53119815Smarcel}; 54119815Smarcel 55119815Smarcelstatic driver_t uart_pci_driver = { 56119815Smarcel uart_driver_name, 57119815Smarcel uart_pci_methods, 58119815Smarcel sizeof(struct uart_softc), 59119815Smarcel}; 60119815Smarcel 61119815Smarcelstruct pci_id { 62158058Smarcel uint16_t vendor; 63158058Smarcel uint16_t device; 64158058Smarcel uint16_t subven; 65158058Smarcel uint16_t subdev; 66119815Smarcel const char *desc; 67119815Smarcel int rid; 68158058Smarcel int rclk; 69119815Smarcel}; 70119815Smarcel 71119815Smarcelstatic struct pci_id pci_ns8250_ids[] = { 72158058Smarcel{ 0x1028, 0x0008, 0xffff, 0, "Dell Remote Access Card III", 0x14, 128 * DEFAULT_RCLK }, 73158058Smarcel{ 0x1028, 0x0012, 0xffff, 0, "Dell Remote Access Card 4 Daughter Card Virtual UART", 0x14, 128 * DEFAULT_RCLK }, 74158058Smarcel{ 0x1033, 0x0074, 0x1033, 0x8014, "NEC RCV56ACF 56k Voice Modem", 0x10 }, 75158058Smarcel{ 0x1033, 0x007d, 0x1033, 0x8012, "NEC RS232C", 0x10 }, 76158058Smarcel{ 0x11c1, 0x0480, 0xffff, 0, "Agere Systems Venus Modem (V90, 56KFlex)", 0x14 }, 77158058Smarcel{ 0x115d, 0x0103, 0xffff, 0, "Xircom Cardbus Ethernet + 56k Modem", 0x10 }, 78158058Smarcel{ 0x12b9, 0x1008, 0xffff, 0, "3Com 56K FaxModem Model 5610", 0x10 }, 79158058Smarcel{ 0x131f, 0x1000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x18 }, 80158058Smarcel{ 0x131f, 0x1001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x18 }, 81158058Smarcel{ 0x131f, 0x1002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x18 }, 82158058Smarcel{ 0x131f, 0x2000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x10 }, 83158058Smarcel{ 0x131f, 0x2001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x10 }, 84158058Smarcel{ 0x131f, 0x2002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x10 }, 85158058Smarcel{ 0x135c, 0x0190, 0xffff, 0, "Quatech SSCLP-100", 0x18 }, 86158058Smarcel{ 0x135c, 0x01c0, 0xffff, 0, "Quatech SSCLP-200/300", 0x18 }, 87158058Smarcel{ 0x135e, 0x7101, 0xffff, 0, "Sealevel Systems Single Port RS-232/422/485/530", 0x18 }, 88158058Smarcel{ 0x1407, 0x0110, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port A", 0x10 }, 89158058Smarcel{ 0x1407, 0x0111, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port B", 0x10 }, 90158058Smarcel{ 0x1415, 0x950b, 0xffff, 0, "Oxford Semiconductor OXCB950 Cardbus 16950 UART", 0x10, 16384000 }, 91158058Smarcel{ 0x151f, 0x0000, 0xffff, 0, "TOPIC Semiconductor TP560 Data/Fax/Voice 56k modem", 0x10 }, 92158058Smarcel{ 0xdeaf, 0x9051, 0xffff, 0, "Middle Digital PC Weasel Serial Port", 0x10 }, 93158058Smarcel{ 0xffff, 0, 0xffff, 0, NULL, 0, 0} 94119815Smarcel}; 95119815Smarcel 96119815Smarcelstatic struct pci_id * 97158058Smarceluart_pci_match(device_t dev, struct pci_id *id) 98119815Smarcel{ 99158058Smarcel uint16_t device, subdev, subven, vendor; 100119815Smarcel 101158058Smarcel vendor = pci_get_vendor(dev); 102158058Smarcel device = pci_get_device(dev); 103158058Smarcel while (id->vendor != 0xffff && 104158058Smarcel (id->vendor != vendor || id->device != device)) 105119815Smarcel id++; 106158058Smarcel if (id->vendor == 0xffff) 107158058Smarcel return (NULL); 108158058Smarcel if (id->subven == 0xffff) 109158058Smarcel return (id); 110158058Smarcel subven = pci_get_subvendor(dev); 111158058Smarcel subdev = pci_get_subdevice(dev); 112158058Smarcel while (id->vendor == vendor && id->device == device && 113158058Smarcel (id->subven != subven || id->subdev != subdev)) 114158058Smarcel id++; 115158058Smarcel return ((id->vendor == vendor && id->device == device) ? id : NULL); 116119815Smarcel} 117119815Smarcel 118119815Smarcelstatic int 119119815Smarceluart_pci_probe(device_t dev) 120119815Smarcel{ 121119815Smarcel struct uart_softc *sc; 122119815Smarcel struct pci_id *id; 123119815Smarcel 124119815Smarcel sc = device_get_softc(dev); 125119815Smarcel 126158058Smarcel id = uart_pci_match(dev, pci_ns8250_ids); 127119815Smarcel if (id != NULL) { 128119815Smarcel sc->sc_class = &uart_ns8250_class; 129119815Smarcel goto match; 130119815Smarcel } 131119815Smarcel /* Add checks for non-ns8250 IDs here. */ 132119815Smarcel return (ENXIO); 133119815Smarcel 134119815Smarcel match: 135119815Smarcel if (id->desc) 136119815Smarcel device_set_desc(dev, id->desc); 137158058Smarcel return (uart_bus_probe(dev, 0, id->rclk, id->rid, 0)); 138119815Smarcel} 139119815Smarcel 140119815SmarcelDRIVER_MODULE(uart, pci, uart_pci_driver, uart_devclass, 0, 0); 141123019SimpDRIVER_MODULE(uart, cardbus, uart_pci_driver, uart_devclass, 0, 0); 142