uart_bus_pci.c revision 139749
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 139749 2005-01-06 01:43:34Z imp $");
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
43119815Smarcelstatic int uart_pci_probe(device_t dev);
44119815Smarcel
45119815Smarcelstatic device_method_t uart_pci_methods[] = {
46119815Smarcel	/* Device interface */
47119815Smarcel	DEVMETHOD(device_probe,		uart_pci_probe),
48119815Smarcel	DEVMETHOD(device_attach,	uart_bus_attach),
49119815Smarcel	DEVMETHOD(device_detach,	uart_bus_detach),
50119815Smarcel	{ 0, 0 }
51119815Smarcel};
52119815Smarcel
53119815Smarcelstatic driver_t uart_pci_driver = {
54119815Smarcel	uart_driver_name,
55119815Smarcel	uart_pci_methods,
56119815Smarcel	sizeof(struct uart_softc),
57119815Smarcel};
58119815Smarcel
59119815Smarcelstruct pci_id {
60119815Smarcel	uint32_t	type;
61119815Smarcel	const char	*desc;
62119815Smarcel	int		rid;
63119815Smarcel};
64119815Smarcel
65119815Smarcelstatic struct pci_id pci_ns8250_ids[] = {
66119815Smarcel	{ 0x100812b9, "3COM PCI FaxModem", 0x10 },
67119815Smarcel	{ 0x2000131f, "CyberSerial (1-port) 16550", 0x10 },
68119815Smarcel	{ 0x01101407, "Koutech IOFLEX-2S PCI Dual Port Serial", 0x10 },
69119815Smarcel	{ 0x01111407, "Koutech IOFLEX-2S PCI Dual Port Serial", 0x10 },
70119815Smarcel	{ 0x048011c1, "Lucent kermit based PCI Modem", 0x14 },
71119815Smarcel	{ 0x95211415, "Oxford Semiconductor PCI Dual Port Serial", 0x10 },
72119815Smarcel	{ 0x7101135e, "SeaLevel Ultra 530.PCI Single Port Serial", 0x18 },
73119815Smarcel	{ 0x0000151f, "SmartLink 5634PCV SurfRider", 0x10 },
74119815Smarcel	{ 0x0103115d, "Xircom Cardbus modem", 0x10 },
75119815Smarcel	{ 0x98459710, "Netmos Nm9845 PCI Bridge with Dual UART", 0x10 },
76119815Smarcel	{ 0x01c0135c, "Quatech SSCLP-200/300", 0x18
77119815Smarcel		/*
78119815Smarcel		 * NB: You must mount the "SPAD" jumper to correctly detect
79119815Smarcel		 * the FIFO on the UART.  Set the options on the jumpers,
80119815Smarcel		 * we do not support the extra registers on the Quatech.
81119815Smarcel		 */
82119815Smarcel	},
83119815Smarcel	{ 0x00000000, NULL, 0 }
84119815Smarcel};
85119815Smarcel
86119815Smarcelstatic struct pci_id *
87119815Smarceluart_pci_match(uint32_t type, struct pci_id *id)
88119815Smarcel{
89119815Smarcel
90119815Smarcel	while (id->type && id->type != type)
91119815Smarcel		id++;
92119815Smarcel	return ((id->type) ? id : NULL);
93119815Smarcel}
94119815Smarcel
95119815Smarcelstatic int
96119815Smarceluart_pci_probe(device_t dev)
97119815Smarcel{
98119815Smarcel	struct uart_softc *sc;
99119815Smarcel	struct pci_id *id;
100119815Smarcel
101119815Smarcel	sc = device_get_softc(dev);
102119815Smarcel
103119815Smarcel	id = uart_pci_match(pci_get_devid(dev), pci_ns8250_ids);
104119815Smarcel	if (id != NULL) {
105119815Smarcel		sc->sc_class = &uart_ns8250_class;
106119815Smarcel		goto match;
107119815Smarcel	}
108119815Smarcel	/* Add checks for non-ns8250 IDs here. */
109119815Smarcel	return (ENXIO);
110119815Smarcel
111119815Smarcel match:
112119815Smarcel	if (id->desc)
113119815Smarcel		device_set_desc(dev, id->desc);
114120452Smarcel	return (uart_bus_probe(dev, 0, 0, id->rid, 0));
115119815Smarcel}
116119815Smarcel
117119815SmarcelDRIVER_MODULE(uart, pci, uart_pci_driver, uart_devclass, 0, 0);
118123019SimpDRIVER_MODULE(uart, cardbus, uart_pci_driver, uart_devclass, 0, 0);
119