1 /*-
2 * Copyright (c) 1999 M. Warner Losh <imp@village.org>
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, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/socket.h>
34
35 #include <sys/module.h>
36 #include <sys/bus.h>
37
38 #include <machine/bus.h>
39 #include <machine/resource.h>
40
41 #include <net/ethernet.h>
42 #include <net/if.h>
43 #include <net/if_arp.h>
44
45 #include <dev/cs/if_csvar.h>
46 #include <dev/cs/if_csreg.h>
47 #include <dev/pccard/pccardvar.h>
48 #include <dev/pccard/pccard_cis.h>
49
50 #include "card_if.h"
51 #include "pccarddevs.h"
52
53 static const struct pccard_product cs_pccard_products[] = {
54 PCMCIA_CARD(IBM, ETHERJET, 0),
55 { NULL }
56 };
57 static int
58 cs_pccard_match(device_t dev)
59 {
60 const struct pccard_product *pp;
61 int error;
62 uint32_t fcn = PCCARD_FUNCTION_UNSPEC;
63
64 /* Make sure we're a network function */
65 error = pccard_get_function(dev, &fcn);
66 if (error != 0)
67 return (error);
68 if (fcn != PCCARD_FUNCTION_NETWORK)
69 return (ENXIO);
70
71 if ((pp = pccard_product_lookup(dev, cs_pccard_products,
72 sizeof(cs_pccard_products[0]), NULL)) != NULL) {
73 if (pp->pp_name != NULL)
74 device_set_desc(dev, pp->pp_name);
75 return 0;
76 }
77 return EIO;
78 }
79
80 static int
81 cs_pccard_probe(device_t dev)
82 {
83 struct cs_softc *sc = device_get_softc(dev);
84 int error;
85
86 sc->flags |= CS_NO_IRQ;
87 error = cs_cs89x0_probe(dev);
88 cs_release_resources(dev);
89 return (error);
90 }
91
92 static int
93 cs_pccard_attach(device_t dev)
94 {
95 struct cs_softc *sc = device_get_softc(dev);
96 int error;
97
98 error = cs_alloc_port(dev, sc->port_rid, CS_89x0_IO_PORTS);
99 if (error != 0)
100 goto bad;
101 error = cs_alloc_irq(dev, sc->irq_rid, 0);
102 if (error != 0)
103 goto bad;
104 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
105 csintr, sc, &sc->irq_handle);
106 if (error != 0)
107 goto bad;
108
109 return (cs_attach(dev));
110 bad:
111 cs_release_resources(dev);
112 return (error);
113 }
114
115 static device_method_t cs_pccard_methods[] = {
116 /* Device interface */
117 DEVMETHOD(device_probe, pccard_compat_probe),
118 DEVMETHOD(device_attach, pccard_compat_attach),
119 DEVMETHOD(device_detach, cs_detach),
120
121 /* Card interface */
122 DEVMETHOD(card_compat_match, cs_pccard_match),
123 DEVMETHOD(card_compat_probe, cs_pccard_probe),
124 DEVMETHOD(card_compat_attach, cs_pccard_attach),
125
126 { 0, 0 }
127 };
128
129 static driver_t cs_pccard_driver = {
130 "cs",
131 cs_pccard_methods,
132 sizeof(struct cs_softc),
133 };
134
135 extern devclass_t cs_devclass;
136
137 DRIVER_MODULE(cs, pccard, cs_pccard_driver, cs_devclass, 0, 0);
138 MODULE_DEPEND(cs, ether, 1, 1, 1);
Cache object: 8acd616a92d2b855edb117ae06627ffe
|