]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/cmx/cmx_pccard.c
ZFS: MFV 2.0-rc1-ga00c61
[FreeBSD/FreeBSD.git] / sys / dev / cmx / cmx_pccard.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2006-2007 Daniel Roethlisberger <daniel@roe.ch>
5  * 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 unmodified, this list of conditions, and the following
12  *    disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/socket.h>
37 #include <sys/selinfo.h>
38 #include <sys/lock.h>
39 #include <sys/mutex.h>
40
41 #include <sys/module.h>
42 #include <sys/bus.h>
43
44 #include <machine/bus.h>
45 #include <machine/resource.h>
46 #include <sys/rman.h>
47
48 #include <dev/cmx/cmxvar.h>
49
50 #include <dev/pccard/pccardvar.h>
51 #include <dev/pccard/pccard_cis.h>
52
53 #include "pccarddevs.h"
54
55 static const struct pccard_product cmx_pccard_products[] = {
56         PCMCIA_CARD(OMNIKEY, CM4040),
57         { NULL }
58 };
59
60 /*
61  * Probe for the card.
62  */
63 static int
64 cmx_pccard_probe(device_t dev)
65 {
66         const struct pccard_product *pp;
67         if ((pp = pccard_product_lookup(dev, cmx_pccard_products,
68             sizeof(cmx_pccard_products[0]), NULL)) != NULL) {
69                 if (pp->pp_name != NULL)
70                         device_set_desc(dev, pp->pp_name);
71                 return 0;
72         }
73         return EIO;
74 }
75
76 /*
77  * Attach to the pccard, and call bus independent attach and
78  * resource allocation routines.
79  */
80 static int
81 cmx_pccard_attach(device_t dev)
82 {
83         int rv = 0;
84         cmx_init_softc(dev);
85
86         if ((rv = cmx_alloc_resources(dev)) != 0) {
87                 device_printf(dev, "cmx_alloc_resources() failed!\n");
88                 cmx_release_resources(dev);
89                 return rv;
90         }
91
92         if ((rv = cmx_attach(dev)) != 0) {
93                 device_printf(dev, "cmx_attach() failed!\n");
94                 cmx_release_resources(dev);
95                 return rv;
96         }
97
98         gone_in_dev(dev, 13, "pccard removed");
99         return 0;
100 }
101
102 static device_method_t cmx_pccard_methods[] = {
103         DEVMETHOD(device_probe, cmx_pccard_probe),
104         DEVMETHOD(device_attach, cmx_pccard_attach),
105         DEVMETHOD(device_detach, cmx_detach),
106
107         { 0, 0 }
108 };
109
110 static driver_t cmx_pccard_driver = {
111         "cmx",
112         cmx_pccard_methods,
113         sizeof(struct cmx_softc),
114 };
115
116 DRIVER_MODULE(cmx, pccard, cmx_pccard_driver, cmx_devclass, 0, 0);
117 PCCARD_PNP_INFO(cmx_pccard_products);