uart_bus_pci.c revision 204533
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 204533 2010-03-01 20:41:27Z delphij $");
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 },
86158058Smarcel{ 0x12b9, 0x1008, 0xffff, 0, "3Com 56K FaxModem Model 5610", 0x10 },
87158058Smarcel{ 0x131f, 0x1000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x18 },
88158058Smarcel{ 0x131f, 0x1001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x18 },
89158058Smarcel{ 0x131f, 0x1002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x18 },
90158058Smarcel{ 0x131f, 0x2000, 0xffff, 0, "Siig CyberSerial (1-port) 16550", 0x10 },
91158058Smarcel{ 0x131f, 0x2001, 0xffff, 0, "Siig CyberSerial (1-port) 16650", 0x10 },
92158058Smarcel{ 0x131f, 0x2002, 0xffff, 0, "Siig CyberSerial (1-port) 16850", 0x10 },
93158058Smarcel{ 0x135c, 0x0190, 0xffff, 0, "Quatech SSCLP-100", 0x18 },
94158058Smarcel{ 0x135c, 0x01c0, 0xffff, 0, "Quatech SSCLP-200/300", 0x18 },
95158078Smarcel{ 0x135e, 0x7101, 0xffff, 0, "Sealevel Systems Single Port RS-232/422/485/530",
96158078Smarcel	0x18 },
97158058Smarcel{ 0x1407, 0x0110, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port A", 0x10 },
98158058Smarcel{ 0x1407, 0x0111, 0xffff, 0, "Lava Computer mfg DSerial-PCI Port B", 0x10 },
99188472Skaiw{ 0x1407, 0x0510, 0xffff, 0, "Lava SP Serial 550 PCI", 0x10 },
100158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x4025, "Timedia Technology Serial Port", 0x10,
101158078Smarcel	8 * DEFAULT_RCLK },
102158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x4027, "Timedia Technology Serial Port", 0x10,
103158078Smarcel	8 * DEFAULT_RCLK },
104158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x4028, "Timedia Technology Serial Port", 0x10,
105158078Smarcel	8 * DEFAULT_RCLK },
106158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x5025, "Timedia Technology Serial Port", 0x10,
107158078Smarcel	8 * DEFAULT_RCLK },
108158078Smarcel{ 0x1409, 0x7168, 0x1409, 0x5027, "Timedia Technology Serial Port", 0x10,
109158078Smarcel	8 * DEFAULT_RCLK },
110158078Smarcel{ 0x1415, 0x950b, 0xffff, 0, "Oxford Semiconductor OXCB950 Cardbus 16950 UART",
111158078Smarcel	0x10, 16384000 },
112158078Smarcel{ 0x151f, 0x0000, 0xffff, 0, "TOPIC Semiconductor TP560 56k modem", 0x10 },
113200257Smav{ 0x9710, 0x9820, 0x1000, 1, "NetMos NM9820 Serial Port", 0x10 },
114189407Sjhb{ 0x9710, 0x9835, 0x1000, 1, "NetMos NM9835 Serial Port", 0x10 },
115200230Smarcel{ 0x9710, 0x9865, 0xa000, 0x1000, "NetMos NM9865 Serial Port", 0x10 },
116204533Sdelphij{ 0x9710, 0x9901, 0xa000, 0x1000,
117204533Sdelphij	"MosChip MCS9901 PCIe to Peripheral Controller", 0x10 },
118158058Smarcel{ 0xdeaf, 0x9051, 0xffff, 0, "Middle Digital PC Weasel Serial Port", 0x10 },
119158058Smarcel{ 0xffff, 0, 0xffff, 0, NULL, 0, 0}
120119815Smarcel};
121119815Smarcel
122119815Smarcelstatic struct pci_id *
123158058Smarceluart_pci_match(device_t dev, struct pci_id *id)
124119815Smarcel{
125158058Smarcel	uint16_t device, subdev, subven, vendor;
126119815Smarcel
127158058Smarcel	vendor = pci_get_vendor(dev);
128158058Smarcel	device = pci_get_device(dev);
129158058Smarcel	while (id->vendor != 0xffff &&
130158058Smarcel	    (id->vendor != vendor || id->device != device))
131119815Smarcel		id++;
132158058Smarcel	if (id->vendor == 0xffff)
133158058Smarcel		return (NULL);
134158058Smarcel	if (id->subven == 0xffff)
135158058Smarcel		return (id);
136158058Smarcel	subven = pci_get_subvendor(dev);
137158058Smarcel	subdev = pci_get_subdevice(dev);
138158058Smarcel	while (id->vendor == vendor && id->device == device &&
139158058Smarcel	    (id->subven != subven || id->subdev != subdev))
140158058Smarcel		id++;
141158058Smarcel	return ((id->vendor == vendor && id->device == device) ? id : NULL);
142119815Smarcel}
143119815Smarcel
144119815Smarcelstatic int
145119815Smarceluart_pci_probe(device_t dev)
146119815Smarcel{
147119815Smarcel	struct uart_softc *sc;
148119815Smarcel	struct pci_id *id;
149119815Smarcel
150119815Smarcel	sc = device_get_softc(dev);
151119815Smarcel
152158058Smarcel	id = uart_pci_match(dev, pci_ns8250_ids);
153119815Smarcel	if (id != NULL) {
154119815Smarcel		sc->sc_class = &uart_ns8250_class;
155119815Smarcel		goto match;
156119815Smarcel	}
157119815Smarcel	/* Add checks for non-ns8250 IDs here. */
158119815Smarcel	return (ENXIO);
159119815Smarcel
160119815Smarcel match:
161119815Smarcel	if (id->desc)
162119815Smarcel		device_set_desc(dev, id->desc);
163158058Smarcel	return (uart_bus_probe(dev, 0, id->rclk, id->rid, 0));
164119815Smarcel}
165119815Smarcel
166119815SmarcelDRIVER_MODULE(uart, pci, uart_pci_driver, uart_devclass, 0, 0);
167