xref: /netbsd-src/sys/dev/isapnp/if_fmv_isapnp.c (revision aaf4ece63a859a04e37cf3a7229b5fab0157cc06)
1 /*	$NetBSD: if_fmv_isapnp.c,v 1.5 2005/12/11 12:22:16 christos Exp $	*/
2 
3 /*-
4  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9  * NASA Ames Research Center and Matt Thomas of the 3am Software Foundry.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *      This product includes software developed by the NetBSD
22  *      Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: if_fmv_isapnp.c,v 1.5 2005/12/11 12:22:16 christos Exp $");
42 
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
46 
47 #include <net/if.h>
48 #include <net/if_ether.h>
49 #include <net/if_media.h>
50 
51 #include <machine/bus.h>
52 #include <machine/intr.h>
53 
54 #include <dev/ic/mb86960reg.h>
55 #include <dev/ic/mb86960var.h>
56 #include <dev/ic/fmvreg.h>
57 #include <dev/ic/fmvvar.h>
58 
59 #include <dev/isa/isavar.h>
60 
61 #include <dev/isapnp/isapnpreg.h>
62 #include <dev/isapnp/isapnpvar.h>
63 #include <dev/isapnp/isapnpdevs.h>
64 
65 int	fmv_isapnp_match(struct device *, struct cfdata *, void *);
66 void	fmv_isapnp_attach(struct device *, struct device *, void *);
67 
68 struct fmv_isapnp_softc {
69 	struct	mb86960_softc sc_mb86960;	/* real "mb86960" softc */
70 
71 	/* ISAPnP-specific goo. */
72 	void	*sc_ih;				/* interrupt cookie */
73 };
74 
75 CFATTACH_DECL(fmv_isapnp, sizeof(struct fmv_isapnp_softc),
76     fmv_isapnp_match, fmv_isapnp_attach, NULL, NULL);
77 
78 int
79 fmv_isapnp_match(struct device *parent, struct cfdata *match, void *aux)
80 {
81 	int pri, variant;
82 
83 	pri = isapnp_devmatch(aux, &isapnp_fmv_devinfo, &variant);
84 	if (pri && variant > 0)
85 		pri = 0;
86 	return pri;
87 }
88 
89 void
90 fmv_isapnp_attach(struct device *parent, struct device *self, void *aux)
91 {
92 	struct fmv_isapnp_softc *isc = (struct fmv_isapnp_softc *)self;
93 	struct mb86960_softc *sc = &isc->sc_mb86960;
94 	struct isapnp_attach_args * const ipa = aux;
95 
96 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
97 		printf(": can't configure isapnp resources\n");
98 		return;
99 	}
100 
101 	sc->sc_bst = ipa->ipa_iot;
102 	sc->sc_bsh = ipa->ipa_io[0].h;
103 
104 	fmv_attach(sc);
105 
106 	/* Establish the interrupt handler. */
107 	isc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
108 	    ipa->ipa_irq[0].type, IPL_NET, mb86960_intr, sc);
109 	if (isc->sc_ih == NULL)
110 		printf("%s: couldn't establish interrupt handler\n",
111 		    sc->sc_dev.dv_xname);
112 }
113