if_cs_pccard.c revision 86394
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 * $FreeBSD: head/sys/dev/cs/if_cs_pccard.c 86394 2001-11-15 07:52:49Z imp $
26 */
27
28#include <sys/param.h>
29#include <sys/systm.h>
30#include <sys/kernel.h>
31#include <sys/socket.h>
32
33#include <sys/module.h>
34#include <sys/bus.h>
35
36#include <machine/bus.h>
37#include <machine/resource.h>
38
39#include <net/ethernet.h>
40#include <net/if.h>
41#include <net/if_arp.h>
42
43#include <dev/cs/if_csvar.h>
44#include <dev/cs/if_csreg.h>
45#include <dev/pccard/pccardvar.h>
46#include <dev/pccard/pccarddevs.h>
47
48#include "card_if.h"
49
50static const struct pccard_product cs_pccard_products[] = {
51	PCMCIA_CARD(IBM, ETHERJET, 0),
52	{ NULL }
53};
54static int
55cs_pccard_match(device_t dev)
56{
57	const struct pccard_product *pp;
58
59	if ((pp = pccard_product_lookup(dev, cs_pccard_products,
60	    sizeof(cs_pccard_products[0]), NULL)) != NULL) {
61		device_set_desc(dev, pp->pp_name);
62		return 0;
63	}
64	return EIO;
65}
66
67static int
68cs_pccard_probe(device_t dev)
69{
70	int error;
71
72	error = cs_cs89x0_probe(dev);
73        cs_release_resources(dev);
74        return (error);
75}
76
77static int
78cs_pccard_attach(device_t dev)
79{
80        struct cs_softc *sc = device_get_softc(dev);
81        int flags = device_get_flags(dev);
82        int error;
83
84	error = cs_alloc_port(dev, sc->port_rid, CS_89x0_IO_PORTS);
85	if (error != 0)
86		goto bad;
87        error = cs_alloc_irq(dev, sc->irq_rid, 0);
88	if (error != 0)
89		goto bad;
90        error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
91	    csintr, sc, &sc->irq_handle);
92        if (error != 0)
93		goto bad;
94
95        return (cs_attach(sc, device_get_unit(dev), flags));
96bad:
97	cs_release_resources(dev);
98	return (error);
99}
100
101static device_method_t cs_pccard_methods[] = {
102	/* Device interface */
103	DEVMETHOD(device_probe,		pccard_compat_probe),
104	DEVMETHOD(device_attach,	pccard_compat_attach),
105#ifdef CS_HAS_DETACH
106	DEVMETHOD(device_detach,	cs_detach),
107#endif
108
109	/* Card interface */
110	DEVMETHOD(card_compat_match,	cs_pccard_match),
111	DEVMETHOD(card_compat_probe,	cs_pccard_probe),
112	DEVMETHOD(card_compat_attach,	cs_pccard_attach),
113
114	{ 0, 0 }
115};
116
117static driver_t cs_pccard_driver = {
118	"cs",
119	cs_pccard_methods,
120	sizeof(struct cs_softc),
121};
122
123extern devclass_t cs_devclass;
124
125DRIVER_MODULE(if_cs, pccard, cs_pccard_driver, cs_devclass, 0, 0);
126MODULE_DEPEND(if_cs, pccard, 1, 1, 1);
127