1 /* $NetBSD: if_sm_isa.c,v 1.21 2009/05/12 08:44:19 cegger Exp $ */
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
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
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>
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>
47 #include <net/if_dl.h>
48 #include <net/if_ether.h>
49 #include <net/if_media.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 *);
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
);
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
;
83 extern const char *smc91cxx_idstrs
[];
90 if (ISA_DIRECT_CONFIG(ia
))
93 /* Disallow wildcarded values. */
94 if (ia
->ia_io
[0].ir_addr
== ISA_UNKNOWN_PORT
)
96 if (ia
->ia_irq
[0].ir_irq
== ISA_UNKNOWN_IRQ
)
100 if (bus_space_map(iot
, ia
->ia_io
[0].ir_addr
, SMC_IOSIZE
, 0, &ioh
))
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
)
109 * Switch to bank 0 and perform the test again.
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
)
118 * Switch to bank 1 and check the base address register.
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))
127 * Check for a recognized chip id.
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
)
136 * Assume we have an SMC91Cxx.
139 ia
->ia_io
[0].ir_size
= SMC_IOSIZE
;
149 bus_space_unmap(iot
, ioh
, SMC_IOSIZE
);
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
;
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");
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");