No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / evbarm / lubbock / if_sm_obio.c
blobae3a8c37df4e879995c32092dae7a5e028e46a1e
1 /* $NetBSD: if_sm_obio.c,v 1.2 2008/04/28 20:23:17 martin Exp $ */
3 /*
4 * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved.
5 * Written by Hiroyuki Bessho for Genetec Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of Genetec Corporation may not be used to endorse or
16 * promote products derived from this software without specific prior
17 * written permission.
19 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 * attach sm driver to Lubbock on-board bus
32 * based on sys/dev/isa/if_sm_isa.c
36 /*-
37 * Copyright (c) 1997 The NetBSD Foundation, Inc.
38 * All rights reserved.
40 * This code is derived from software contributed to The NetBSD Foundation
41 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
42 * NASA Ames Research Center.
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
53 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
54 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
55 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
57 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
58 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
59 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
60 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
61 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
62 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
63 * POSSIBILITY OF SUCH DAMAGE.
66 #include <sys/cdefs.h>
67 __KERNEL_RCSID(0, "$NetBSD: if_sm_obio.c,v 1.2 2008/04/28 20:23:17 martin Exp $");
69 #include <sys/param.h>
70 #include <sys/systm.h>
71 #include <sys/mbuf.h>
72 #include <sys/socket.h>
73 #include <sys/ioctl.h>
74 #include <sys/errno.h>
75 #include <sys/syslog.h>
76 #include <sys/select.h>
77 #include <sys/device.h>
79 #include <net/if.h>
80 #include <net/if_dl.h>
81 #include <net/if_ether.h>
82 #include <net/if_media.h>
84 #include <machine/intr.h>
85 #include <machine/bus.h>
87 #include <dev/mii/mii.h>
88 #include <dev/mii/miivar.h>
90 #include <dev/ic/smc91cxxreg.h>
91 #include <dev/ic/smc91cxxvar.h>
93 #include <evbarm/lubbock/lubbock_var.h>
95 #include "opt_lubbock.h" /* LUBBOCK_SMC91C96_16BIT */
97 int sm_obio_match(struct device *, struct cfdata *, void *);
98 void sm_obio_attach(struct device *, struct device *, void *);
100 struct sm_obio_softc {
101 struct smc91cxx_softc sc_smc; /* real "smc" softc */
103 /* OBIO-specific goo. */
104 void *sc_ih; /* interrupt handler */
107 CFATTACH_DECL(sm_obio, sizeof(struct sm_obio_softc), sm_obio_match,
108 sm_obio_attach, NULL, NULL);
110 extern struct bus_space smobio8_bs_tag;
112 #ifndef SM_OBIO_INTR_PARANOIA
113 # define smintr smc91cxx_intr
114 #else
115 # define smintr smc_obio_intr
117 static int
118 smc_obio_intr(void *arg)
120 while (smc91cxx_intr(arg))
122 return 1;
124 #endif /* SM_OBIO_INTR_PARANOIA */
127 sm_obio_match(device_t parent, cfdata_t match, void *aux)
129 struct obio_attach_args *oba = aux;
130 bus_space_tag_t iot = &smobio8_bs_tag;
131 bus_space_handle_t ioh;
132 u_int16_t tmp;
133 int rv = 0;
134 extern const char *smc91cxx_idstrs[];
137 /* Map i/o space. */
138 if (bus_space_map(iot, oba->oba_addr, SMC_IOSIZE, 0, &ioh))
139 return (0);
142 /* Check that high byte of BANK_SELECT is what we expect. */
143 tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
144 if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
145 goto out;
148 * Switch to bank 0 and perform the test again.
149 * XXX INVASIVE!
151 bus_space_write_1(iot, ioh, BANK_SELECT_REG_W, 0);
152 tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
153 if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
154 goto out;
157 * Check for a recognized chip id.
158 * XXX INVASIVE!
160 bus_space_write_1(iot, ioh, BANK_SELECT_REG_W, 3);
161 tmp = bus_space_read_2(iot, ioh, REVISION_REG_W);
162 if (smc91cxx_idstrs[RR_ID(tmp)] == NULL)
163 goto out;
166 * Assume we have an SMC91Cxx.
169 rv = 1;
171 out:
172 bus_space_unmap(iot, ioh, SMC_IOSIZE);
173 if (!rv) {
174 printf("on-board SMC probe failed\n");
176 return (rv);
179 void
180 sm_obio_attach(device_t parent, device_t self, void *aux)
182 struct sm_obio_softc *isc = (struct sm_obio_softc *)self;
183 struct smc91cxx_softc *sc = &isc->sc_smc;
184 struct obio_attach_args *oba = aux;
185 bus_space_handle_t ioh;
186 #ifdef LUBBOCK_SMC91C96_16BIT
187 bus_space_tag_t iot = &pxa2x0_a4x_bs_tag;
188 #else
189 bus_space_tag_t iot = &smobio8_bs_tag;
190 #endif
193 printf("\n");
195 /* Map i/o space. */
196 if (bus_space_map(iot, oba->oba_addr, SMC_IOSIZE, 0, &ioh))
197 panic("sm_obio_attach: can't map i/o space");
199 #ifdef LUBBOCK_SMC91C96_16BIT
200 /* RedBoot initializes on-board SMSC91C96 in 8-bit mode.
201 we take it back to 16-bit by clearing ECSR.IOIs8 */
203 int tmp;
205 bus_space_write_1(&smobio8_bs_tag, ioh, BANK_SELECT_REG_W, 4);
206 tmp = bus_space_read_1(&smobio8_bs_tag, ioh, ECSR_REG_B);
207 bus_space_write_1(&smobio8_bs_tag, ioh,
208 ECSR_REG_B, tmp & ~ECSR_IOIS8);
211 obio16_write(LUBBOCK_MISCWR,
212 obio16_read(LUBBOCK_MISCWR) & ~MISCWR_ENETEN16 );
214 #else
215 /* Force 8bit mode */
216 obio16_write(LUBBOCK_MISCWR,
217 obio16_read(LUBBOCK_MISCWR) | MISCWR_ENETEN16);
219 #endif /* LUBBOCK_SMC91C96_16BIT */
221 sc->sc_bst = iot;
222 sc->sc_bsh = ioh;
224 /* should always be enabled */
225 sc->sc_flags |= SMC_FLAGS_ENABLED;
227 /* Perform generic intialization. */
228 smc91cxx_attach(sc, NULL);
230 /* Establish the interrupt handler. */
231 isc->sc_ih = obio_intr_establish(device_private(parent),
232 oba->oba_intr, IPL_NET, smintr, sc);
234 if (isc->sc_ih == NULL)
235 aprint_normal_dev(self, "couldn't establish interrupt handler\n");