No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / isa / if_sm_isa.c
blobf009f9250c1e3b8e8c762488cf097207811ae3d1
1 /* $NetBSD: if_sm_isa.c,v 1.21 2009/05/12 08:44:19 cegger Exp $ */
3 /*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
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.
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.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: if_sm_isa.c,v 1.21 2009/05/12 08:44:19 cegger Exp $");
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/mbuf.h>
39 #include <sys/socket.h>
40 #include <sys/ioctl.h>
41 #include <sys/errno.h>
42 #include <sys/syslog.h>
43 #include <sys/select.h>
44 #include <sys/device.h>
46 #include <net/if.h>
47 #include <net/if_dl.h>
48 #include <net/if_ether.h>
49 #include <net/if_media.h>
51 #include <sys/intr.h>
52 #include <sys/bus.h>
54 #include <dev/mii/mii.h>
55 #include <dev/mii/miivar.h>
57 #include <dev/ic/smc91cxxreg.h>
58 #include <dev/ic/smc91cxxvar.h>
60 #include <dev/isa/isavar.h>
62 int sm_isa_match(device_t, cfdata_t, void *);
63 void sm_isa_attach(device_t, device_t, void *);
65 struct sm_isa_softc {
66 struct smc91cxx_softc sc_smc; /* real "smc" softc */
68 /* ISA-specific goo. */
69 void *sc_ih; /* interrupt cookie */
72 CFATTACH_DECL(sm_isa, sizeof(struct sm_isa_softc),
73 sm_isa_match, sm_isa_attach, NULL, NULL);
75 int
76 sm_isa_match(device_t parent, cfdata_t match, void *aux)
78 struct isa_attach_args *ia = aux;
79 bus_space_tag_t iot = ia->ia_iot;
80 bus_space_handle_t ioh;
81 u_int16_t tmp;
82 int rv = 0;
83 extern const char *smc91cxx_idstrs[];
85 if (ia->ia_nio < 1)
86 return (0);
87 if (ia->ia_nirq < 1)
88 return (0);
90 if (ISA_DIRECT_CONFIG(ia))
91 return (0);
93 /* Disallow wildcarded values. */
94 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
95 return (0);
96 if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
97 return (0);
99 /* Map i/o space. */
100 if (bus_space_map(iot, ia->ia_io[0].ir_addr, SMC_IOSIZE, 0, &ioh))
101 return (0);
103 /* Check that high byte of BANK_SELECT is what we expect. */
104 tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
105 if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
106 goto out;
109 * Switch to bank 0 and perform the test again.
110 * XXX INVASIVE!
112 bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 0);
113 tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
114 if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
115 goto out;
118 * Switch to bank 1 and check the base address register.
119 * XXX INVASIVE!
121 bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 1);
122 tmp = bus_space_read_2(iot, ioh, BASE_ADDR_REG_W);
123 if (ia->ia_io[0].ir_addr != ((tmp >> 3) & 0x3e0))
124 goto out;
127 * Check for a recognized chip id.
128 * XXX INVASIVE!
130 bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 3);
131 tmp = bus_space_read_2(iot, ioh, REVISION_REG_W);
132 if (smc91cxx_idstrs[RR_ID(tmp)] == NULL)
133 goto out;
136 * Assume we have an SMC91Cxx.
138 ia->ia_nio = 1;
139 ia->ia_io[0].ir_size = SMC_IOSIZE;
141 ia->ia_nirq = 1;
143 ia->ia_niomem = 0;
144 ia->ia_ndrq = 0;
146 rv = 1;
148 out:
149 bus_space_unmap(iot, ioh, SMC_IOSIZE);
150 return (rv);
153 void
154 sm_isa_attach(device_t parent, device_t self, void *aux)
156 struct sm_isa_softc *isc = (struct sm_isa_softc *)self;
157 struct smc91cxx_softc *sc = &isc->sc_smc;
158 struct isa_attach_args *ia = aux;
159 bus_space_tag_t iot = ia->ia_iot;
160 bus_space_handle_t ioh;
162 printf("\n");
164 /* Map i/o space. */
165 if (bus_space_map(iot, ia->ia_io[0].ir_addr, SMC_IOSIZE, 0, &ioh))
166 panic("sm_isa_attach: can't map i/o space");
168 sc->sc_bst = iot;
169 sc->sc_bsh = ioh;
171 /* should always be enabled */
172 sc->sc_flags |= SMC_FLAGS_ENABLED;
174 /* XXX Should get Ethernet address from EEPROM!! */
176 /* Perform generic intialization. */
177 smc91cxx_attach(sc, NULL);
179 /* Establish the interrupt handler. */
180 isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
181 IST_EDGE, IPL_NET, smc91cxx_intr, sc);
182 if (isc->sc_ih == NULL)
183 aprint_error_dev(&sc->sc_dev, "couldn't establish interrupt handler\n");