uart_bus_pci.c revision 228947
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: head/sys/dev/uart/uart_bus_pci.c 228947 2011-12-29 08:27:37Z kib $"); 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), 54119815Smarcel { 0, 0 } 55119815Smarcel}; 56119815Smarcel 57119815Smarcelstatic driver_t uart_pci_driver = { 58119815Smarcel uart_driver_name, 59119815Smarcel uart_pci_methods, 60119815Smarcel sizeof(struct uart_softc), 61119815Smarcel}; 62119815Smarcel 63119815Smarcelstruct pci_id { 64158058Smarcel uint16_t vendor; 65158058Smarcel uint16_t device; 66158058Smarcel uint16_t subven; 67158058Smarcel uint16_t subdev; 68119815Smarcel const char *desc; 69119815Smarcel int rid; 70158058Smarcel int rclk; 71119815Smarcel}; 72119815Smarcel 73119815Smarcelstatic struct pci_id pci_ns8250_ids[] = { 74158078Smarcel{ 0x1028, 0x0008, 0xffff, 0, "Dell Remote Access Card III", 0x14, 75158078Smarcel 128 * DEFAULT_RCLK }, 76158078Smarcel{ 0x1028, 0x0012, 0xffff, 0, "Dell RAC 4 Daughter Card Virtual UART", 0x14, 77158078Smarcel 128 * DEFAULT_RCLK }, 78158058Smarcel{ 0x1033, 0x0074, 0x1033, 0x8014, "NEC RCV56ACF 56k Voice Modem", 0x10 }, 79158058Smarcel{ 0x1033, 0x007d, 0x1033, 0x8012, "NEC RS232C", 0x10 }, 80158078Smarcel{ 0x103c, 0x1048, 0x103c, 0x1227, "HP Diva Serial [GSP] UART - Powerbar SP2", 81158078Smarcel 0x10 }, 82169646Smarcel{ 0x103c, 0x1048, 0x103c, 0x1301, "HP Diva RMP3", 0x14 }, 83158078Smarcel{ 0x103c, 0x1290, 0xffff, 0, "HP Auxiliary Diva Serial Port", 0x18 }, 84158058Smarcel{ 0x11c1, 0x0480, 0xffff, 0, "Agere Systems Venus Modem (V90, 56KFlex)", 0x14 }, 85158058Smarcel{ 0x115d, 0x0103, 0xffff, 0, "Xircom Cardbus Ethernet + 56k Modem", 0x10 }, 86223874Sjhb{ 0x1282, 0x6585, 0xffff, 0, "Davicom 56PDV PCI Modem", 0x10 }, 87158058Smarcel{ 0x12b9, 0x1008, 0xffff, 0, "3Com 56K FaxModem Model 5610", 0x10 }, 88158058Smarcel{ 0x131f, 0x1000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x18 }, 89158058Smarcel{ 0x131f, 0x1001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x18 }, 90158058Smarcel{ 0x131f, 0x1002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x18 }, 91158058Smarcel{ 0x131f, 0x2000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x10 }, 92158058Smarcel{ 0x131f, 0x2001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x10 }, 93158058Smarcel{ 0x131f, 0x2002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x10 }, 94158058Smarcel{ 0x135c, 0x0190, 0xffff, 0, "Quatech SSCLP-100", 0x18 }, 95158058Smarcel{ 0x135c, 0x01c0, 0xffff, 0, "Quatech SSCLP-200/300", 0x18 }, 96158078Smarcel{ 0x135e, 0x7101, 0xffff, 0, "Sealevel Systems Single Port RS-232/422/485/530", 97158078Smarcel 0x18 }, 98158058Smarcel{ 0x1407, 0x0110, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port A", 0x10 }, 99158058Smarcel{ 0x1407, 0x0111, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port B", 0x10 }, 100188472Skaiw{ 0x1407, 0x0510, 0xffff, 0, "Lava SP Serial 550 PCI", 0x10 }, 101158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x4025, "Timedia Technology Serial Port", 0x10, 102158078Smarcel 8 * DEFAULT_RCLK }, 103158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x4027, "Timedia Technology Serial Port", 0x10, 104158078Smarcel 8 * DEFAULT_RCLK }, 105158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x4028, "Timedia Technology Serial Port", 0x10, 106158078Smarcel 8 * DEFAULT_RCLK }, 107158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x5025, "Timedia Technology Serial Port", 0x10, 108158078Smarcel 8 * DEFAULT_RCLK }, 109158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x5027, "Timedia Technology Serial Port", 0x10, 110158078Smarcel 8 * DEFAULT_RCLK }, 111158078Smarcel{ 0x1415, 0x950b, 0xffff, 0, "Oxford Semiconductor OXCB950 Cardbus 16950 UART", 112158078Smarcel 0x10, 16384000 }, 113158078Smarcel{ 0x151f, 0x0000, 0xffff, 0, "TOPIC Semiconductor TP560 56k modem", 0x10 }, 114228947Skib{ 0x8086, 0x1c3d, 0xffff, 0, "Intel AMT - KT Controller", 0x10 }, 115200257Smav{ 0x9710, 0x9820, 0x1000, 1, "NetMos NM9820 Serial Port", 0x10 }, 116189407Sjhb{ 0x9710, 0x9835, 0x1000, 1, "NetMos NM9835 Serial Port", 0x10 }, 117200230Smarcel{ 0x9710, 0x9865, 0xa000, 0x1000, "NetMos NM9865 Serial Port", 0x10 }, 118223672Shselasky{ 0x9710, 0x9900, 0xa000, 0x1000, 119223672Shselasky "MosChip MCS9900 PCIe to Peripheral Controller", 0x10 }, 120204533Sdelphij{ 0x9710, 0x9901, 0xa000, 0x1000, 121204533Sdelphij "MosChip MCS9901 PCIe to Peripheral Controller", 0x10 }, 122158058Smarcel{ 0xdeaf, 0x9051, 0xffff, 0, "Middle Digital PC Weasel Serial Port", 0x10 }, 123158058Smarcel{ 0xffff, 0, 0xffff, 0, NULL, 0, 0} 124119815Smarcel}; 125119815Smarcel 126119815Smarcelstatic struct pci_id * 127158058Smarceluart_pci_match(device_t dev, struct pci_id *id) 128119815Smarcel{ 129158058Smarcel uint16_t device, subdev, subven, vendor; 130119815Smarcel 131158058Smarcel vendor = pci_get_vendor(dev); 132158058Smarcel device = pci_get_device(dev); 133158058Smarcel while (id->vendor != 0xffff && 134158058Smarcel (id->vendor != vendor || id->device != device)) 135119815Smarcel id++; 136158058Smarcel if (id->vendor == 0xffff) 137158058Smarcel return (NULL); 138158058Smarcel if (id->subven == 0xffff) 139158058Smarcel return (id); 140158058Smarcel subven = pci_get_subvendor(dev); 141158058Smarcel subdev = pci_get_subdevice(dev); 142158058Smarcel while (id->vendor == vendor && id->device == device && 143158058Smarcel (id->subven != subven || id->subdev != subdev)) 144158058Smarcel id++; 145158058Smarcel return ((id->vendor == vendor && id->device == device) ? id : NULL); 146119815Smarcel} 147119815Smarcel 148119815Smarcelstatic int 149119815Smarceluart_pci_probe(device_t dev) 150119815Smarcel{ 151119815Smarcel struct uart_softc *sc; 152119815Smarcel struct pci_id *id; 153119815Smarcel 154119815Smarcel sc = device_get_softc(dev); 155119815Smarcel 156158058Smarcel id = uart_pci_match(dev, pci_ns8250_ids); 157119815Smarcel if (id != NULL) { 158119815Smarcel sc->sc_class = &uart_ns8250_class; 159119815Smarcel goto match; 160119815Smarcel } 161119815Smarcel /* Add checks for non-ns8250 IDs here. */ 162119815Smarcel return (ENXIO); 163119815Smarcel 164119815Smarcel match: 165119815Smarcel if (id->desc) 166119815Smarcel device_set_desc(dev, id->desc); 167158058Smarcel return (uart_bus_probe(dev, 0, id->rclk, id->rid, 0)); 168119815Smarcel} 169119815Smarcel 170119815SmarcelDRIVER_MODULE(uart, pci, uart_pci_driver, uart_devclass, 0, 0); 171