1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2001 M. Warner Losh. All rights reserved.
5 * Copyright (c) 2003 Norikatsu Shigemura, Takenori Watanabe All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/bus.h>
34 #include <sys/conf.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <machine/bus.h>
38 #include <machine/resource.h>
39
40 #include <dev/pccard/pccard_cis.h>
41 #include <dev/pccard/pccardvar.h>
42
43 #include <dev/uart/uart.h>
44 #include <dev/uart/uart_bus.h>
45
46 #include "pccarddevs.h"
47
48 static int uart_pccard_probe(device_t dev);
49 static int uart_pccard_attach(device_t dev);
50
51 static device_method_t uart_pccard_methods[] = {
52 /* Device interface */
53 DEVMETHOD(device_probe, uart_pccard_probe),
54 DEVMETHOD(device_attach, uart_pccard_attach),
55 DEVMETHOD(device_detach, uart_bus_detach),
56
57 { 0, 0 }
58 };
59
60 static uint32_t uart_pccard_function = PCCARD_FUNCTION_SERIAL;
61
62 static driver_t uart_pccard_driver = {
63 uart_driver_name,
64 uart_pccard_methods,
65 sizeof(struct uart_softc),
66 };
67
68 static int
uart_pccard_probe(device_t dev)69 uart_pccard_probe(device_t dev)
70 {
71 int error;
72 uint32_t fcn;
73
74 fcn = PCCARD_FUNCTION_UNSPEC;
75 error = pccard_get_function(dev, &fcn);
76 if (error != 0)
77 return (error);
78 /*
79 * If a serial card, we are likely the right driver. However,
80 * some serial cards are better serviced by other drivers, so
81 * allow other drivers to claim it, if they want.
82 */
83 if (fcn == uart_pccard_function)
84 return (BUS_PROBE_GENERIC);
85
86 return (ENXIO);
87 }
88
89 static int
uart_pccard_attach(device_t dev)90 uart_pccard_attach(device_t dev)
91 {
92 struct uart_softc *sc;
93 int error;
94
95 sc = device_get_softc(dev);
96 sc->sc_class = &uart_ns8250_class;
97
98 error = uart_bus_probe(dev, 0, 0, 0, 0, 0, 0);
99 if (error > 0)
100 return (error);
101 return (uart_bus_attach(dev));
102 }
103
104 DRIVER_MODULE(uart, pccard, uart_pccard_driver, uart_devclass, 0, 0);
105 MODULE_PNP_INFO("U32:function_type;", pccard, uart, &uart_pccard_function,
106 1);
107