uart_bus_pci.c revision 223874
1261046Smav/*-
2261046Smav * Copyright (c) 2006 Marcel Moolenaar
3261046Smav * Copyright (c) 2001 M. Warner Losh
48858Srgrimes * All rights reserved.
5261046Smav *
6261046Smav * Redistribution and use in source and binary forms, with or without
7261046Smav * modification, are permitted provided that the following conditions
8261046Smav * are met:
9261046Smav * 1. Redistributions of source code must retain the above copyright
10261046Smav *    notice, this list of conditions and the following disclaimer.
11261046Smav * 2. Redistributions in binary form must reproduce the above copyright
12261046Smav *    notice, this list of conditions and the following disclaimer in the
13261046Smav *    documentation and/or other materials provided with the distribution.
14261046Smav *
158858Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16261046Smav * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17261046Smav * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18261046Smav * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19261046Smav * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20261046Smav * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21261046Smav * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22261046Smav * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23261046Smav * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24261046Smav * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25261046Smav */
26261046Smav
278858Srgrimes#include <sys/cdefs.h>
281903Swollman__FBSDID("$FreeBSD: head/sys/dev/uart/uart_bus_pci.c 223874 2011-07-08 17:45:38Z jhb $");
291903Swollman
3050473Speter#include <sys/param.h>
311839Swollman#include <sys/systm.h>
321839Swollman#include <sys/bus.h>
331839Swollman#include <sys/conf.h>
341839Swollman#include <sys/kernel.h>
351839Swollman#include <sys/module.h>
361839Swollman#include <machine/bus.h>
371839Swollman#include <sys/rman.h>
381839Swollman#include <machine/resource.h>
391839Swollman
401839Swollman#include <dev/pci/pcivar.h>
411839Swollman
421839Swollman#include <dev/uart/uart.h>
431839Swollman#include <dev/uart/uart_bus.h>
441839Swollman
451839Swollman#define	DEFAULT_RCLK	1843200
461903Swollman
471903Swollmanstatic int uart_pci_probe(device_t dev);
481903Swollman
491903Swollmanstatic device_method_t uart_pci_methods[] = {
501839Swollman	/* Device interface */
511839Swollman	DEVMETHOD(device_probe,		uart_pci_probe),
521839Swollman	DEVMETHOD(device_attach,	uart_bus_attach),
531839Swollman	DEVMETHOD(device_detach,	uart_bus_detach),
541839Swollman	{ 0, 0 }
551839Swollman};
561839Swollman
571839Swollmanstatic driver_t uart_pci_driver = {
581839Swollman	uart_driver_name,
591839Swollman	uart_pci_methods,
601839Swollman	sizeof(struct uart_softc),
611839Swollman};
62241181Spfg
63241181Spfgstruct pci_id {
641839Swollman	uint16_t	vendor;
65241181Spfg	uint16_t	device;
661839Swollman	uint16_t	subven;
671839Swollman	uint16_t	subdev;
6826211Swpaul	const char	*desc;
6926211Swpaul	int		rid;
701903Swollman	int		rclk;
7193032Simp};
721903Swollman
731839Swollmanstatic struct pci_id pci_ns8250_ids[] = {
748858Srgrimes{ 0x1028, 0x0008, 0xffff, 0, "Dell Remote Access Card III", 0x14,
758858Srgrimes	128 * DEFAULT_RCLK },
761839Swollman{ 0x1028, 0x0012, 0xffff, 0, "Dell RAC 4 Daughter Card Virtual UART", 0x14,
771839Swollman	128 * DEFAULT_RCLK },
781839Swollman{ 0x1033, 0x0074, 0x1033, 0x8014, "NEC RCV56ACF 56k Voice Modem", 0x10 },
791839Swollman{ 0x1033, 0x007d, 0x1033, 0x8012, "NEC RS232C", 0x10 },
801839Swollman{ 0x103c, 0x1048, 0x103c, 0x1227, "HP Diva Serial [GSP] UART - Powerbar SP2",
811839Swollman	0x10 },
821903Swollman{ 0x103c, 0x1048, 0x103c, 0x1301, "HP Diva RMP3", 0x14 },
831903Swollman{ 0x103c, 0x1290, 0xffff, 0, "HP Auxiliary Diva Serial Port", 0x18 },
84{ 0x11c1, 0x0480, 0xffff, 0, "Agere Systems Venus Modem (V90, 56KFlex)", 0x14 },
85{ 0x115d, 0x0103, 0xffff, 0, "Xircom Cardbus Ethernet + 56k Modem", 0x10 },
86{ 0x1282, 0x6585, 0xffff, 0, "Davicom 56PDV PCI Modem", 0x10 },
87{ 0x12b9, 0x1008, 0xffff, 0, "3Com 56K FaxModem Model 5610", 0x10 },
88{ 0x131f, 0x1000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x18 },
89{ 0x131f, 0x1001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x18 },
90{ 0x131f, 0x1002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x18 },
91{ 0x131f, 0x2000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x10 },
92{ 0x131f, 0x2001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x10 },
93{ 0x131f, 0x2002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x10 },
94{ 0x135c, 0x0190, 0xffff, 0, "Quatech SSCLP-100", 0x18 },
95{ 0x135c, 0x01c0, 0xffff, 0, "Quatech SSCLP-200/300", 0x18 },
96{ 0x135e, 0x7101, 0xffff, 0, "Sealevel Systems Single Port RS-232/422/485/530",
97	0x18 },
98{ 0x1407, 0x0110, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port A", 0x10 },
99{ 0x1407, 0x0111, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port B", 0x10 },
100{ 0x1407, 0x0510, 0xffff, 0, "Lava SP Serial 550 PCI", 0x10 },
101{ 0x1409, 0x7168, 0x1409, 0x4025, "Timedia Technology Serial Port", 0x10,
102	8 * DEFAULT_RCLK },
103{ 0x1409, 0x7168, 0x1409, 0x4027, "Timedia Technology Serial Port", 0x10,
104	8 * DEFAULT_RCLK },
105{ 0x1409, 0x7168, 0x1409, 0x4028, "Timedia Technology Serial Port", 0x10,
106	8 * DEFAULT_RCLK },
107{ 0x1409, 0x7168, 0x1409, 0x5025, "Timedia Technology Serial Port", 0x10,
108	8 * DEFAULT_RCLK },
109{ 0x1409, 0x7168, 0x1409, 0x5027, "Timedia Technology Serial Port", 0x10,
110	8 * DEFAULT_RCLK },
111{ 0x1415, 0x950b, 0xffff, 0, "Oxford Semiconductor OXCB950 Cardbus 16950 UART",
112	0x10, 16384000 },
113{ 0x151f, 0x0000, 0xffff, 0, "TOPIC Semiconductor TP560 56k modem", 0x10 },
114{ 0x9710, 0x9820, 0x1000, 1, "NetMos NM9820 Serial Port", 0x10 },
115{ 0x9710, 0x9835, 0x1000, 1, "NetMos NM9835 Serial Port", 0x10 },
116{ 0x9710, 0x9865, 0xa000, 0x1000, "NetMos NM9865 Serial Port", 0x10 },
117{ 0x9710, 0x9900, 0xa000, 0x1000,
118	"MosChip MCS9900 PCIe to Peripheral Controller", 0x10 },
119{ 0x9710, 0x9901, 0xa000, 0x1000,
120	"MosChip MCS9901 PCIe to Peripheral Controller", 0x10 },
121{ 0xdeaf, 0x9051, 0xffff, 0, "Middle Digital PC Weasel Serial Port", 0x10 },
122{ 0xffff, 0, 0xffff, 0, NULL, 0, 0}
123};
124
125static struct pci_id *
126uart_pci_match(device_t dev, struct pci_id *id)
127{
128	uint16_t device, subdev, subven, vendor;
129
130	vendor = pci_get_vendor(dev);
131	device = pci_get_device(dev);
132	while (id->vendor != 0xffff &&
133	    (id->vendor != vendor || id->device != device))
134		id++;
135	if (id->vendor == 0xffff)
136		return (NULL);
137	if (id->subven == 0xffff)
138		return (id);
139	subven = pci_get_subvendor(dev);
140	subdev = pci_get_subdevice(dev);
141	while (id->vendor == vendor && id->device == device &&
142	    (id->subven != subven || id->subdev != subdev))
143		id++;
144	return ((id->vendor == vendor && id->device == device) ? id : NULL);
145}
146
147static int
148uart_pci_probe(device_t dev)
149{
150	struct uart_softc *sc;
151	struct pci_id *id;
152
153	sc = device_get_softc(dev);
154
155	id = uart_pci_match(dev, pci_ns8250_ids);
156	if (id != NULL) {
157		sc->sc_class = &uart_ns8250_class;
158		goto match;
159	}
160	/* Add checks for non-ns8250 IDs here. */
161	return (ENXIO);
162
163 match:
164	if (id->desc)
165		device_set_desc(dev, id->desc);
166	return (uart_bus_probe(dev, 0, id->rclk, id->rid, 0));
167}
168
169DRIVER_MODULE(uart, pci, uart_pci_driver, uart_devclass, 0, 0);
170