]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/sio/sio_pccard.c
MFV r347989:
[FreeBSD/FreeBSD.git] / sys / dev / sio / sio_pccard.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2001 M. Warner Losh.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/bus.h>
33 #include <sys/conf.h>
34 #include <sys/kernel.h>
35 #include <sys/lock.h>
36 #include <sys/malloc.h>
37 #include <sys/mutex.h>
38 #include <sys/module.h>
39 #include <sys/tty.h>
40 #include <machine/bus.h>
41 #include <machine/resource.h>
42 #include <sys/timepps.h>
43
44 #include <dev/pccard/pccard_cis.h>
45 #include <dev/pccard/pccardvar.h>
46
47 #include <dev/sio/siovar.h>
48
49 static  int     sio_pccard_attach(device_t dev);
50 static  int     sio_pccard_probe(device_t dev);
51
52 static device_method_t sio_pccard_methods[] = {
53         /* Device interface */
54         DEVMETHOD(device_probe,         sio_pccard_probe),
55         DEVMETHOD(device_attach,        sio_pccard_attach),
56         DEVMETHOD(device_detach,        siodetach),
57
58         { 0, 0 }
59 };
60
61 static driver_t sio_pccard_driver = {
62         sio_driver_name,
63         sio_pccard_methods,
64         0,
65 };
66
67 static int
68 sio_pccard_probe(device_t dev)
69 {
70         int             error = 0;
71         u_int32_t       fcn = PCCARD_FUNCTION_UNSPEC;
72
73         error = pccard_get_function(dev, &fcn);
74         if (error != 0)
75                 return (error);
76
77         /*
78          * If a serial card, we are likely the right driver.  However,
79          * some serial cards are better servered by other drivers, so
80          * allow other drivers to claim it, if they want.
81          */
82         if (fcn == PCCARD_FUNCTION_SERIAL)
83                 return (-100);
84         return (ENXIO);
85 }
86
87 static int
88 sio_pccard_attach(device_t dev)
89 {
90         int err;
91
92         /* Do not probe IRQ - pccard doesn't turn on the interrupt line */
93         /* until bus_setup_intr */
94         if ((err = sioprobe(dev, 0, 0UL, 1)) > 0)
95                 return (err);
96         return (sioattach(dev, 0, 0UL));
97 }
98
99 DRIVER_MODULE(sio, pccard, sio_pccard_driver, sio_devclass, 0, 0);