f2c9dec2b274178ebeeb0c0ca0a25fdf33eccf55
[dragonfly.git] / sys / dev / misc / cmx / cmx_pccard.c
1 /*-
2  * Copyright (c) 2006-2007 Daniel Roethlisberger <daniel@roe.ch>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice unmodified, this list of conditions, and the following
10  *    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 AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD: src/sys/dev/cmx/cmx_pccard.c,v 1.1 2008/03/06 08:09:45 rink Exp $
28  * $DragonFly: src/sys/dev/misc/cmx/cmx_pccard.c,v 1.1 2008/04/23 08:57:10 hasso Exp $
29  */
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/socket.h>
35 #include <sys/selinfo.h>
36 #include <sys/lock.h>
37
38 #include <sys/module.h>
39 #include <sys/bus.h>
40 #include <sys/resource.h>
41 #include <sys/rman.h>
42
43 #include "cmxvar.h"
44
45 #include <bus/pccard/pccardvar.h>
46 #include <bus/pccard/pccard_cis.h>
47 #include <bus/pccard/pccarddevs.h>
48
49 static const struct pccard_product cmx_pccard_products[] = {
50         PCMCIA_CARD(OMNIKEY, CM4040, 0),
51         { NULL }
52 };
53
54 /*
55  * Probe for the card.
56  */
57 static int
58 cmx_pccard_probe(device_t dev)
59 {
60         const struct pccard_product *pp;
61         if ((pp = pccard_product_lookup(dev, cmx_pccard_products,
62             sizeof(cmx_pccard_products[0]), NULL)) != NULL) {
63                 if (pp->pp_name != NULL)
64                         device_set_desc(dev, pp->pp_name);
65                 return 0;
66         }
67         return EIO;
68 }
69
70 /*
71  * Attach to the pccard, and call bus independant attach and
72  * resource allocation routines.
73  */
74 static int
75 cmx_pccard_attach(device_t dev)
76 {
77         int rv = 0;
78         cmx_init_softc(dev);
79
80         if ((rv = cmx_alloc_resources(dev)) != 0) {
81                 device_printf(dev, "cmx_alloc_resources() failed!\n");
82                 cmx_release_resources(dev);
83                 return rv;
84         }
85
86         if ((rv = cmx_attach(dev)) != 0) {
87                 device_printf(dev, "cmx_attach() failed!\n");
88                 cmx_release_resources(dev);
89                 return rv;
90         }
91
92         device_printf(dev, "attached\n");
93         return 0;
94 }
95
96 static device_method_t cmx_pccard_methods[] = {
97         DEVMETHOD(device_probe, cmx_pccard_probe),
98         DEVMETHOD(device_attach, cmx_pccard_attach),
99         DEVMETHOD(device_detach, cmx_detach),
100
101         { 0, 0 }
102 };
103
104 static driver_t cmx_pccard_driver = {
105         "cmx",
106         cmx_pccard_methods,
107         sizeof(struct cmx_softc),
108 };
109
110 DRIVER_MODULE(cmx, pccard, cmx_pccard_driver, cmx_devclass, 0, 0);
111