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$");
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 },
117264761Smarius{ 0x1fd4, 0x1999, 0x1fd4, 0x0001, "Sunix SER5xxxx Serial Port", 0x10,
118264761Smarius	8 * DEFAULT_RCLK },
119228947Skib{ 0x8086, 0x1c3d, 0xffff, 0, "Intel AMT - KT Controller", 0x10 },
120249803Seadler{ 0x8086, 0x1d3d, 0xffff, 0, "Intel C600/X79 Series Chipset KT Controller", 0x10 },
121232967Skib{ 0x8086, 0x2e17, 0xffff, 0, "4 Series Chipset Serial KT Controller", 0x10 },
122229971Skib{ 0x8086, 0x3b67, 0xffff, 0, "5 Series/3400 Series Chipset KT Controller",
123229971Skib	0x10 },
124229379Skevlo{ 0x8086, 0x8811, 0xffff, 0, "Intel EG20T Serial Port 0", 0x10 },
125229379Skevlo{ 0x8086, 0x8812, 0xffff, 0, "Intel EG20T Serial Port 1", 0x10 },
126229379Skevlo{ 0x8086, 0x8813, 0xffff, 0, "Intel EG20T Serial Port 2", 0x10 },
127229379Skevlo{ 0x8086, 0x8814, 0xffff, 0, "Intel EG20T Serial Port 3", 0x10 },
128266436Smarius{ 0x8086, 0x8c3d, 0xffff, 0, "Intel Lynx Point KT Controller", 0x10 },
129200257Smav{ 0x9710, 0x9820, 0x1000, 1, "NetMos NM9820 Serial Port", 0x10 },
130189407Sjhb{ 0x9710, 0x9835, 0x1000, 1, "NetMos NM9835 Serial Port", 0x10 },
131200230Smarcel{ 0x9710, 0x9865, 0xa000, 0x1000, "NetMos NM9865 Serial Port", 0x10 },
132223672Shselasky{ 0x9710, 0x9900, 0xa000, 0x1000,
133223672Shselasky	"MosChip MCS9900 PCIe to Peripheral Controller", 0x10 },
134204533Sdelphij{ 0x9710, 0x9901, 0xa000, 0x1000,
135204533Sdelphij	"MosChip MCS9901 PCIe to Peripheral Controller", 0x10 },
136232639Sremko{ 0x9710, 0x9904, 0xa000, 0x1000,
137232639Sremko	"MosChip MCS9904 PCIe to Peripheral Controller", 0x10 },
138158058Smarcel{ 0xdeaf, 0x9051, 0xffff, 0, "Middle Digital PC Weasel Serial Port", 0x10 },
139158058Smarcel{ 0xffff, 0, 0xffff, 0, NULL, 0, 0}
140119815Smarcel};
141119815Smarcel
142246300Smariusconst static struct pci_id *
143246300Smariusuart_pci_match(device_t dev, const struct pci_id *id)
144119815Smarcel{
145158058Smarcel	uint16_t device, subdev, subven, vendor;
146119815Smarcel
147158058Smarcel	vendor = pci_get_vendor(dev);
148158058Smarcel	device = pci_get_device(dev);
149158058Smarcel	while (id->vendor != 0xffff &&
150158058Smarcel	    (id->vendor != vendor || id->device != device))
151119815Smarcel		id++;
152158058Smarcel	if (id->vendor == 0xffff)
153158058Smarcel		return (NULL);
154158058Smarcel	if (id->subven == 0xffff)
155158058Smarcel		return (id);
156158058Smarcel	subven = pci_get_subvendor(dev);
157158058Smarcel	subdev = pci_get_subdevice(dev);
158158058Smarcel	while (id->vendor == vendor && id->device == device &&
159158058Smarcel	    (id->subven != subven || id->subdev != subdev))
160158058Smarcel		id++;
161158058Smarcel	return ((id->vendor == vendor && id->device == device) ? id : NULL);
162119815Smarcel}
163119815Smarcel
164119815Smarcelstatic int
165119815Smarceluart_pci_probe(device_t dev)
166119815Smarcel{
167119815Smarcel	struct uart_softc *sc;
168246300Smarius	const struct pci_id *id;
169253654Smarcel	int result;
170119815Smarcel
171119815Smarcel	sc = device_get_softc(dev);
172119815Smarcel
173158058Smarcel	id = uart_pci_match(dev, pci_ns8250_ids);
174119815Smarcel	if (id != NULL) {
175119815Smarcel		sc->sc_class = &uart_ns8250_class;
176119815Smarcel		goto match;
177119815Smarcel	}
178119815Smarcel	/* Add checks for non-ns8250 IDs here. */
179119815Smarcel	return (ENXIO);
180119815Smarcel
181119815Smarcel match:
182253654Smarcel	result = uart_bus_probe(dev, 0, id->rclk, id->rid, 0);
183253654Smarcel	/* Bail out on error. */
184253654Smarcel	if (result > 0)
185253654Smarcel		return (result);
186253654Smarcel	/* Set/override the device description. */
187119815Smarcel	if (id->desc)
188119815Smarcel		device_set_desc(dev, id->desc);
189253654Smarcel	return (result);
190119815Smarcel}
191119815Smarcel
192246300SmariusDRIVER_MODULE(uart, pci, uart_pci_driver, uart_devclass, NULL, NULL);
193