1 /* $NetBSD: if_sm_gxio.c,v 1.6 2008/05/11 08:23:17 kiyohara Exp $ */
3 * Copyright (C) 2005, 2006 WIDE Project and SOUM Corporation.
6 * Written by Takashi Kiyohara and Susumu Miki for WIDE Project and SOUM
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the project nor the name of SOUM Corporation
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT and SOUM CORPORATION ``AS IS''
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT AND SOUM CORPORATION
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1997 The NetBSD Foundation, Inc.
35 * All rights reserved.
37 * This code is derived from software contributed to The NetBSD Foundation
38 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
39 * NASA Ames Research Center.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
50 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
51 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
52 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
54 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
55 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
56 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
57 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
58 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
59 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
60 * POSSIBILITY OF SUCH DAMAGE.
63 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: if_sm_gxio.c,v 1.6 2008/05/11 08:23:17 kiyohara Exp $");
66 #include <sys/param.h>
67 #include <sys/device.h>
68 #include <sys/errno.h>
70 #include <sys/systm.h>
72 #include <sys/socket.h>
73 #include <sys/ioctl.h>
74 #include <sys/syslog.h>
75 #include <sys/select.h>
78 #include <net/if_dl.h>
79 #include <net/if_ether.h>
80 #include <net/if_media.h>
82 #include <machine/intr.h>
83 #include <machine/bus.h>
85 #include <dev/mii/mii.h>
86 #include <dev/mii/miivar.h>
88 #include <dev/ic/smc91cxxreg.h>
89 #include <dev/ic/smc91cxxvar.h>
91 #include <evbarm/gumstix/gumstixvar.h>
96 static int sm_gxio_match(device_t
, struct cfdata
*, void *);
97 static void sm_gxio_attach(device_t
, device_t
, void *);
99 static int ether_serial_digit
= 1;
101 struct sm_gxio_softc
{
102 struct smc91cxx_softc sc_smc
;
106 CFATTACH_DECL(sm_gxio
, sizeof(struct sm_gxio_softc
),
107 sm_gxio_match
, sm_gxio_attach
, NULL
, NULL
);
112 sm_gxio_match(device_t parent
, struct cfdata
*match
, void *aux
)
114 struct gxio_attach_args
*gxa
= aux
;
115 bus_space_tag_t iot
= gxa
->gxa_iot
;
116 bus_space_handle_t ioh
;
119 extern const char *smc91cxx_idstrs
[];
121 /* Disallow wildcarded values. */
122 if (gxa
->gxa_addr
== GXIOCF_ADDR_DEFAULT
)
124 if (gxa
->gxa_gpirq
== GXIOCF_GPIRQ_DEFAULT
)
127 if (bus_space_map(iot
, gxa
->gxa_addr
, SMC_IOSIZE
, 0, &ioh
) != 0)
130 /* Check that high byte of BANK_SELECT is what we expect. */
131 tmp
= bus_space_read_2(iot
, ioh
, BANK_SELECT_REG_W
);
132 if ((tmp
& BSR_DETECT_MASK
) != BSR_DETECT_VALUE
)
136 * Switch to bank 0 and perform the test again.
139 bus_space_write_1(iot
, ioh
, BANK_SELECT_REG_W
, 0);
140 tmp
= bus_space_read_2(iot
, ioh
, BANK_SELECT_REG_W
);
141 if ((tmp
& BSR_DETECT_MASK
) != BSR_DETECT_VALUE
)
145 * Check for a recognized chip id.
148 bus_space_write_1(iot
, ioh
, BANK_SELECT_REG_W
, 3);
149 tmp
= bus_space_read_2(iot
, ioh
, REVISION_REG_W
);
150 if (smc91cxx_idstrs
[RR_ID(tmp
)] == NULL
)
153 if (ether_serial_digit
> 15)
156 * Assume we have an SMC91Cxx.
162 bus_space_unmap(iot
, ioh
, SMC_IOSIZE
);
168 sm_gxio_attach(device_t parent
, device_t self
, void *aux
)
170 struct sm_gxio_softc
*gsc
= device_private(self
);
171 struct smc91cxx_softc
*sc
= &gsc
->sc_smc
;
172 struct gxio_attach_args
*gxa
= aux
;
173 bus_space_handle_t ioh
;
174 uint8_t myea
[ETHER_ADDR_LEN
];
179 KASSERT(system_serial_high
!= 0 || system_serial_low
!= 0);
182 if (bus_space_map(gxa
->gxa_iot
, gxa
->gxa_addr
, SMC_IOSIZE
, 0, &ioh
))
183 panic("sm_gxio_attach: can't map i/o space");
185 sc
->sc_bst
= gxa
->gxa_iot
;
188 /* should always be enabled */
189 sc
->sc_flags
|= SMC_FLAGS_ENABLED
;
191 myea
[0] = ((system_serial_high
>> 8) & 0xfe) | 0x02;
192 myea
[1] = system_serial_high
;
193 myea
[2] = system_serial_low
>> 24;
194 myea
[3] = system_serial_low
>> 16;
195 myea
[4] = system_serial_low
>> 8;
196 myea
[5] = (system_serial_low
& 0xc0) |
197 (1 << 4) | ((ether_serial_digit
++) & 0x0f);
198 smc91cxx_attach(sc
, myea
);
200 /* Establish the interrupt handler. */
201 gsc
->sc_ih
= gxio_intr_establish(gxa
->gxa_sc
,
202 gxa
->gxa_gpirq
, IST_EDGE_RISING
, IPL_NET
, smc91cxx_intr
, sc
);
204 if (gsc
->sc_ih
== NULL
)
205 aprint_error_dev(self
,
206 "couldn't establish interrupt handler\n");