if_ne_obio.c revision 1.1.8.2 1 1.1.8.2 kent /* $NetBSD: if_ne_obio.c,v 1.1.8.2 2005/04/29 11:28:07 kent Exp $ */
2 1.1.8.2 kent
3 1.1.8.2 kent /*
4 1.1.8.2 kent * Copyright (c) 2002, 2003 Genetec corp. All rights reserved.
5 1.1.8.2 kent * Written by Hiroyuki Bessho for Genetec corp.
6 1.1.8.2 kent *
7 1.1.8.2 kent * Redistribution and use in source and binary forms, with or without
8 1.1.8.2 kent * modification, are permitted provided that the following conditions
9 1.1.8.2 kent * are met:
10 1.1.8.2 kent * 1. Redistributions of source code must retain the above copyright
11 1.1.8.2 kent * notice, this list of conditions and the following disclaimer.
12 1.1.8.2 kent * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.8.2 kent * notice, this list of conditions and the following disclaimer in the
14 1.1.8.2 kent * documentation and/or other materials provided with the distribution.
15 1.1.8.2 kent * 3. The name of Genetec corp. may not be used to endorse
16 1.1.8.2 kent * or promote products derived from this software without specific prior
17 1.1.8.2 kent * written permission.
18 1.1.8.2 kent *
19 1.1.8.2 kent * THIS SOFTWARE IS PROVIDED BY GENETEC CORP. ``AS IS'' AND
20 1.1.8.2 kent * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1.8.2 kent * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1.8.2 kent * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORP.
23 1.1.8.2 kent * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1.8.2 kent * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1.8.2 kent * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1.8.2 kent * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1.8.2 kent * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1.8.2 kent * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1.8.2 kent * POSSIBILITY OF SUCH DAMAGE.
30 1.1.8.2 kent */
31 1.1.8.2 kent
32 1.1.8.2 kent #include <sys/cdefs.h>
33 1.1.8.2 kent __KERNEL_RCSID(0, "$NetBSD: if_ne_obio.c,v 1.1.8.2 2005/04/29 11:28:07 kent Exp $");
34 1.1.8.2 kent
35 1.1.8.2 kent #include <sys/param.h>
36 1.1.8.2 kent #include <sys/systm.h>
37 1.1.8.2 kent #include <sys/mbuf.h>
38 1.1.8.2 kent #include <sys/socket.h>
39 1.1.8.2 kent #include <sys/ioctl.h>
40 1.1.8.2 kent #include <sys/errno.h>
41 1.1.8.2 kent #include <sys/syslog.h>
42 1.1.8.2 kent #include <sys/select.h>
43 1.1.8.2 kent #include <sys/device.h>
44 1.1.8.2 kent
45 1.1.8.2 kent #include <net/if.h>
46 1.1.8.2 kent #include <net/if_dl.h>
47 1.1.8.2 kent #include <net/if_ether.h>
48 1.1.8.2 kent #include <net/if_media.h>
49 1.1.8.2 kent
50 1.1.8.2 kent #include <machine/intr.h>
51 1.1.8.2 kent #include <machine/bus.h>
52 1.1.8.2 kent
53 1.1.8.2 kent #include <dev/mii/mii.h>
54 1.1.8.2 kent #include <dev/mii/miivar.h>
55 1.1.8.2 kent
56 1.1.8.2 kent #include <dev/ic/dp8390reg.h>
57 1.1.8.2 kent #include <dev/ic/dp8390var.h>
58 1.1.8.2 kent #include <dev/ic/ne2000reg.h>
59 1.1.8.2 kent #include <dev/ic/ne2000var.h>
60 1.1.8.2 kent
61 1.1.8.2 kent #include <evbarm/g42xxeb/g42xxeb_var.h>
62 1.1.8.2 kent #include <arm/xscale/pxa2x0var.h>
63 1.1.8.2 kent
64 1.1.8.2 kent struct ne_obio_softc {
65 1.1.8.2 kent struct ne2000_softc nsc;
66 1.1.8.2 kent
67 1.1.8.2 kent void *sc_ih; /* interrupt handler */
68 1.1.8.2 kent int intr_no;
69 1.1.8.2 kent };
70 1.1.8.2 kent
71 1.1.8.2 kent int ne_obio_match( struct device *, struct cfdata *, void * );
72 1.1.8.2 kent void ne_obio_attach( struct device *, struct device *, void * );
73 1.1.8.2 kent
74 1.1.8.2 kent
75 1.1.8.2 kent CFATTACH_DECL(ne_obio, sizeof (struct ne_obio_softc), ne_obio_match, ne_obio_attach,
76 1.1.8.2 kent NULL, NULL);
77 1.1.8.2 kent
78 1.1.8.2 kent //#define DEBUG_GPIO 2
79 1.1.8.2 kent //#define DEBUG_GPIO2 5
80 1.1.8.2 kent
81 1.1.8.2 kent #if 1
82 1.1.8.2 kent #define intr_handler dp8390_intr
83 1.1.8.2 kent #else
84 1.1.8.2 kent #define intr_handler ne_obio_intr
85 1.1.8.2 kent
86 1.1.8.2 kent static int
87 1.1.8.2 kent ne_obio_intr(void *arg)
88 1.1.8.2 kent {
89 1.1.8.2 kent int rv=1;
90 1.1.8.2 kent
91 1.1.8.2 kent #ifdef DEBUG_GPIO
92 1.1.8.2 kent //printf( "ne_obio_intr arg=%p\n", arg );
93 1.1.8.2 kent bus_space_write_4( pxa2x0_softc->saip.sc_iot,
94 1.1.8.2 kent pxa2x0_softc->saip.sc_gpioh,
95 1.1.8.2 kent GPIO_GPSR0, 1U<<DEBUG_GPIO );
96 1.1.8.2 kent #endif
97 1.1.8.2 kent
98 1.1.8.2 kent #if 0
99 1.1.8.2 kent while( (rv = dp8390_intr(arg)) != 0)
100 1.1.8.2 kent /*continue*/;
101 1.1.8.2 kent #else
102 1.1.8.2 kent rv = dp8390_intr(arg);
103 1.1.8.2 kent #endif
104 1.1.8.2 kent
105 1.1.8.2 kent #ifdef DEBUG_GPIO
106 1.1.8.2 kent bus_space_write_4( pxa2x0_softc->saip.sc_iot,
107 1.1.8.2 kent pxa2x0_softc->saip.sc_gpioh,
108 1.1.8.2 kent GPIO_GPCR0, 1U<<DEBUG_GPIO );
109 1.1.8.2 kent #endif
110 1.1.8.2 kent return rv;
111 1.1.8.2 kent }
112 1.1.8.2 kent #endif
113 1.1.8.2 kent
114 1.1.8.2 kent static int
115 1.1.8.2 kent ne_obio_enable(struct dp8390_softc *dsc)
116 1.1.8.2 kent {
117 1.1.8.2 kent struct ne_obio_softc *sc = (struct ne_obio_softc *)dsc;
118 1.1.8.2 kent struct obio_softc *psc;
119 1.1.8.2 kent
120 1.1.8.2 kent printf("%s: enabled\n", dsc->sc_dev.dv_xname);
121 1.1.8.2 kent
122 1.1.8.2 kent psc = (struct obio_softc *)dsc->sc_dev.dv_parent;
123 1.1.8.2 kent
124 1.1.8.2 kent /* Establish the interrupt handler. */
125 1.1.8.2 kent sc->sc_ih = obio_intr_establish(psc, sc->intr_no, IPL_NET,
126 1.1.8.2 kent IST_LEVEL_LOW,
127 1.1.8.2 kent intr_handler,
128 1.1.8.2 kent sc);
129 1.1.8.2 kent
130 1.1.8.2 kent return 0;
131 1.1.8.2 kent }
132 1.1.8.2 kent
133 1.1.8.2 kent
134 1.1.8.2 kent int
135 1.1.8.2 kent ne_obio_match( struct device *parent, struct cfdata *match, void *aux )
136 1.1.8.2 kent {
137 1.1.8.2 kent /* XXX: probe? */
138 1.1.8.2 kent return 1;
139 1.1.8.2 kent }
140 1.1.8.2 kent
141 1.1.8.2 kent void
142 1.1.8.2 kent ne_obio_attach( struct device *parent, struct device *self, void *aux )
143 1.1.8.2 kent {
144 1.1.8.2 kent struct ne_obio_softc *sc = (struct ne_obio_softc *)self;
145 1.1.8.2 kent struct obio_attach_args *oba = aux;
146 1.1.8.2 kent bus_space_tag_t iot = oba->oba_iot;
147 1.1.8.2 kent bus_space_handle_t nioh, aioh;
148 1.1.8.2 kent uint8_t my_ea[ETHER_ADDR_LEN];
149 1.1.8.2 kent int i;
150 1.1.8.2 kent
151 1.1.8.2 kent printf("\n");
152 1.1.8.2 kent
153 1.1.8.2 kent /* Map i/o space. */
154 1.1.8.2 kent if (bus_space_map(iot, oba->oba_addr, NE2000_NPORTS, 0, &nioh))
155 1.1.8.2 kent return;
156 1.1.8.2 kent
157 1.1.8.2 kent if (bus_space_subregion(iot, nioh, NE2000_ASIC_OFFSET,
158 1.1.8.2 kent NE2000_ASIC_NPORTS, &aioh))
159 1.1.8.2 kent goto out2;
160 1.1.8.2 kent
161 1.1.8.2 kent sc->nsc.sc_dp8390.sc_regt = iot;
162 1.1.8.2 kent sc->nsc.sc_dp8390.sc_regh = nioh;
163 1.1.8.2 kent
164 1.1.8.2 kent sc->nsc.sc_asict = iot;
165 1.1.8.2 kent sc->nsc.sc_asich = aioh;
166 1.1.8.2 kent
167 1.1.8.2 kent /*
168 1.1.8.2 kent * XXX:
169 1.1.8.2 kent * AX88796's reset register doesn't seem to work, and
170 1.1.8.2 kent * ne2000_detect() fails. We hardcord NIC type here.
171 1.1.8.2 kent */
172 1.1.8.2 kent sc->nsc.sc_type = NE2000_TYPE_NE2000; /* XXX _AX88796 ? */
173 1.1.8.2 kent sc->nsc.sc_dp8390.sc_flags = DP8390_NO_REMOTE_DMA_COMPLETE;
174 1.1.8.2 kent /* DP8390_NO_MULTI_BUFFERING; XXX */
175 1.1.8.2 kent
176 1.1.8.2 kent /* G4250EBX doesn't have EEPROM hooked to AX88796. Read MAC
177 1.1.8.2 kent * address set by Redboot and don't let ne2000_atthch() try to
178 1.1.8.2 kent * read MAC from hardware. (current ne2000 driver doesn't
179 1.1.8.2 kent * support AX88796's EEPROM interface)
180 1.1.8.2 kent */
181 1.1.8.2 kent
182 1.1.8.2 kent bus_space_write_1( iot, nioh, ED_P0_CR, ED_CR_RD2|ED_CR_PAGE_1 );
183 1.1.8.2 kent
184 1.1.8.2 kent for( i=0; i < ETHER_ADDR_LEN; ++i )
185 1.1.8.2 kent my_ea[i] = bus_space_read_1( iot, nioh, ED_P1_PAR0+i );
186 1.1.8.2 kent
187 1.1.8.2 kent bus_space_write_1( iot, nioh, ED_P0_CR, ED_CR_RD2|ED_CR_PAGE_0 );
188 1.1.8.2 kent
189 1.1.8.2 kent /* disable all interrupts */
190 1.1.8.2 kent bus_space_write_1(iot, nioh, ED_P0_IMR, 0);
191 1.1.8.2 kent
192 1.1.8.2 kent #ifdef DEBUG_GPIO
193 1.1.8.2 kent bus_space_write_4( pxa2x0_softc->saip.sc_iot,
194 1.1.8.2 kent pxa2x0_softc->saip.sc_gpioh,
195 1.1.8.2 kent GPIO_GPDR0, (0x01<<DEBUG_GPIO) | (0x01<<DEBUG_GPIO2) |
196 1.1.8.2 kent bus_space_read_4(pxa2x0_softc->saip.sc_iot, pxa2x0_softc->saip.sc_gpioh,
197 1.1.8.2 kent GPIO_GPDR0));
198 1.1.8.2 kent
199 1.1.8.2 kent #endif
200 1.1.8.2 kent /* delay intr_establish until this IF is enabled
201 1.1.8.2 kent to avoid spurious interrupts. */
202 1.1.8.2 kent sc->nsc.sc_dp8390.sc_enabled = 0;
203 1.1.8.2 kent sc->nsc.sc_dp8390.sc_enable = ne_obio_enable;
204 1.1.8.2 kent sc->intr_no = oba->oba_intr;
205 1.1.8.2 kent
206 1.1.8.2 kent if( ne2000_attach( &sc->nsc, my_ea ) )
207 1.1.8.2 kent goto out;
208 1.1.8.2 kent
209 1.1.8.2 kent #ifndef ED_DCR_RDCR
210 1.1.8.2 kent #define ED_DCR_RDCR 0
211 1.1.8.2 kent #endif
212 1.1.8.2 kent
213 1.1.8.2 kent bus_space_write_1(iot, nioh, ED_P0_DCR, ED_DCR_RDCR|ED_DCR_WTS);
214 1.1.8.2 kent
215 1.1.8.2 kent return;
216 1.1.8.2 kent
217 1.1.8.2 kent out:
218 1.1.8.2 kent bus_space_unmap( iot, aioh, NE2000_ASIC_NPORTS );
219 1.1.8.2 kent out2:
220 1.1.8.2 kent bus_space_unmap( iot, nioh, NE2000_NPORTS );
221 1.1.8.2 kent return;
222 1.1.8.2 kent }
223 1.1.8.2 kent
224 1.1.8.2 kent #if 0
225 1.1.8.2 kent void debug_obio_ne(struct dp8390_softc *);
226 1.1.8.2 kent void
227 1.1.8.2 kent debug_obio_ne(struct dp8390_softc *sc)
228 1.1.8.2 kent {
229 1.1.8.2 kent struct obio_softc *osc = (struct obio_softc *)(sc->sc_dev.dv_parent);
230 1.1.8.2 kent struct pxa2x0_softc *psc = (struct pxa2x0_softc *)(osc->sc_dev.dv_parent);
231 1.1.8.2 kent
232 1.1.8.2 kent printf( "ISR=%02x obio: pending=(%x,%x) mask=%x pending=%x mask=%x\n",
233 1.1.8.2 kent bus_space_read_1(sc->sc_regt, sc->sc_regh,
234 1.1.8.2 kent ED_P0_ISR ),
235 1.1.8.2 kent bus_space_read_2(osc->sc_iot, osc->sc_obioreg_ioh, G4250EBX_INTSTS1),
236 1.1.8.2 kent bus_space_read_2(osc->sc_iot, osc->sc_obioreg_ioh, G4250EBX_INTSTS2),
237 1.1.8.2 kent bus_space_read_2(osc->sc_iot, osc->sc_obioreg_ioh, G4250EBX_INTMASK),
238 1.1.8.2 kent osc->sc_intr_pending,
239 1.1.8.2 kent osc->sc_intr_mask );
240 1.1.8.2 kent
241 1.1.8.2 kent printf( "intc: mask=%08x pending=%08x\n",
242 1.1.8.2 kent bus_space_read_4(psc->saip.sc_iot, psc->saip.sc_ioh, SAIPIC_MR ),
243 1.1.8.2 kent bus_space_read_4(psc->saip.sc_iot, psc->saip.sc_ioh, SAIPIC_IP ) );
244 1.1.8.2 kent }
245 1.1.8.2 kent #endif
246 1.1.8.2 kent
247 1.1.8.2 kent #ifdef DEBUG_GPIO2
248 1.1.8.2 kent void dp8390_debug_overrun(void);
249 1.1.8.2 kent void dp8390_debug_overrun(void)
250 1.1.8.2 kent {
251 1.1.8.2 kent static int toggle=0;
252 1.1.8.2 kent
253 1.1.8.2 kent //printf( "ne_obio_intr arg=%p\n", arg );
254 1.1.8.2 kent bus_space_write_4( pxa2x0_softc->saip.sc_iot,
255 1.1.8.2 kent pxa2x0_softc->saip.sc_gpioh,
256 1.1.8.2 kent toggle ? GPIO_GPCR0 : GPIO_GPSR0,
257 1.1.8.2 kent 1U<<DEBUG_GPIO2 );
258 1.1.8.2 kent toggle ^= 1;
259 1.1.8.2 kent
260 1.1.8.2 kent }
261 1.1.8.2 kent #endif
262