xref: /netbsd-src/sys/dev/podulebus/if_ea.c (revision 3b01aba77a7a698587faaae455bbfe740923c1f5)
1 /* $NetBSD: if_ea.c,v 1.3 2001/03/24 23:37:34 bjh21 Exp $ */
2 
3 /*
4  * Copyright (c) 2000, 2001 Ben Harris
5  * Copyright (c) 1995 Mark Brinicombe
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following 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  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by Mark Brinicombe.
19  * 4. The name of the company nor the name of the author may be used to
20  *    endorse or promote products derived from this software without specific
21  *    prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 /*
36  * if_ea.c - Ether3 device driver
37  */
38 
39 #include <sys/param.h>
40 
41 __RCSID("$NetBSD: if_ea.c,v 1.3 2001/03/24 23:37:34 bjh21 Exp $");
42 
43 #include <sys/device.h>
44 #include <sys/socket.h>
45 #include <sys/systm.h>
46 
47 #include <machine/bus.h>
48 #include <machine/intr.h>
49 
50 #include <net/if.h>
51 #include <net/if_ether.h>
52 
53 #include <dev/podulebus/podulebus.h>
54 #include <dev/podulebus/podules.h>
55 
56 #include <dev/podulebus/if_eareg.h>
57 #include <dev/ic/seeq8005var.h>
58 
59 /*
60  * per-line info and status
61  */
62 
63 struct ea_softc {
64 	struct seeq8005_softc	sc_8005;
65 	void	*sc_ih;
66 	struct evcnt sc_intrcnt;
67 };
68 
69 /*
70  * prototypes
71  */
72 
73 int eaprobe(struct device *, struct cfdata *, void *);
74 void eaattach(struct device *, struct device *, void *);
75 
76 /* driver structure for autoconf */
77 
78 struct cfattach ea_ca = {
79 	sizeof(struct ea_softc), eaprobe, eaattach
80 };
81 
82 /*
83  * Probe routine.
84  */
85 
86 /*
87  * Probe for the ether3 podule.
88  */
89 
90 int
91 eaprobe(struct device *parent, struct cfdata *cf, void *aux)
92 {
93 	struct podulebus_attach_args *pa = aux;
94 
95 	if ((matchpodule(pa, MANUFACTURER_ATOMWIDE,
96 			 PODULE_ATOMWIDE_ETHER3, -1) == 0)
97 	    && (matchpodule(pa, MANUFACTURER_ACORN,
98 			    PODULE_ACORN_ETHER3XXX, -1) == 0)
99 	    && (matchpodule(pa, MANUFACTURER_ANT, PODULE_ANT_ETHER3, -1) == 0))
100 		return 0;
101 
102 	return 1;
103 }
104 
105 
106 /*
107  * Attach podule.
108  */
109 
110 void
111 eaattach(struct device *parent, struct device *self, void *aux)
112 {
113 	struct ea_softc *sc = (void *)self;
114 	struct podulebus_attach_args *pa = aux;
115 	u_int8_t myaddr[ETHER_ADDR_LEN];
116 	char *ptr;
117 	int i;
118 
119 /*	dprintf(("Attaching %s...\n", sc->sc_dev.dv_xname));*/
120 
121 	/* Set the address of the controller for easy access */
122 	podulebus_shift_tag(pa->pa_mod_t, EA_8005_SHIFT, &sc->sc_8005.sc_iot);
123 	bus_space_map(sc->sc_8005.sc_iot, pa->pa_mod_base, /* XXX */ 0, 0,
124 	    &sc->sc_8005.sc_ioh);
125 
126 	/* Get the Ethernet address from the device description string. */
127 	if (pa->pa_descr == NULL) {
128 		printf(": No description for Ethernet address\n");
129 		return;
130 	}
131 	ptr = strchr(pa->pa_descr, '(');
132 	if (ptr == NULL) {
133 		printf(": Ethernet address not found in description\n");
134 		return;
135 	}
136 	ptr++;
137 	for (i = 0; i < ETHER_ADDR_LEN; i++) {
138 		myaddr[i] = strtoul(ptr, &ptr, 16);
139 		if (*ptr++ != (i == ETHER_ADDR_LEN - 1 ? ')' : ':')) {
140 			printf(": Bad Ethernet address found in "
141 			       "description\n");
142 			return;
143 		}
144 	}
145 
146 	printf(":");
147 	seeq8005_attach(&sc->sc_8005, myaddr, NULL, 0, 0);
148 
149 	/* Claim a podule interrupt */
150 
151 	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
152 	    self->dv_xname, "intr");
153 	sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_NET, seeq8005intr,
154 	    sc, &sc->sc_intrcnt);
155 }
156 
157 /* End of if_ea.c */
158