if_sm_gxio.c revision 1.1.2.2 1 1.1.2.2 yamt /* $NetBSD: if_sm_gxio.c,v 1.1.2.2 2006/10/22 06:04:38 yamt Exp $ */
2 1.1.2.2 yamt /*
3 1.1.2.2 yamt * Copyright (C) 2005, 2006 WIDE Project and SOUM Corporation.
4 1.1.2.2 yamt * All rights reserved.
5 1.1.2.2 yamt *
6 1.1.2.2 yamt * Written by Takashi Kiyohara and Susumu Miki for WIDE Project and SOUM
7 1.1.2.2 yamt * Corporation.
8 1.1.2.2 yamt *
9 1.1.2.2 yamt * Redistribution and use in source and binary forms, with or without
10 1.1.2.2 yamt * modification, are permitted provided that the following conditions
11 1.1.2.2 yamt * are met:
12 1.1.2.2 yamt * 1. Redistributions of source code must retain the above copyright
13 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer.
14 1.1.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer in the
16 1.1.2.2 yamt * documentation and/or other materials provided with the distribution.
17 1.1.2.2 yamt * 3. Neither the name of the project nor the name of SOUM Corporation
18 1.1.2.2 yamt * may be used to endorse or promote products derived from this software
19 1.1.2.2 yamt * without specific prior written permission.
20 1.1.2.2 yamt *
21 1.1.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE PROJECT and SOUM CORPORATION ``AS IS''
22 1.1.2.2 yamt * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 1.1.2.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.1.2.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT AND SOUM CORPORATION
25 1.1.2.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 1.1.2.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 1.1.2.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.1.2.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1.2.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.1.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
32 1.1.2.2 yamt */
33 1.1.2.2 yamt /*-
34 1.1.2.2 yamt * Copyright (c) 1997 The NetBSD Foundation, Inc.
35 1.1.2.2 yamt * All rights reserved.
36 1.1.2.2 yamt *
37 1.1.2.2 yamt * This code is derived from software contributed to The NetBSD Foundation
38 1.1.2.2 yamt * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
39 1.1.2.2 yamt * NASA Ames Research Center.
40 1.1.2.2 yamt *
41 1.1.2.2 yamt * Redistribution and use in source and binary forms, with or without
42 1.1.2.2 yamt * modification, are permitted provided that the following conditions
43 1.1.2.2 yamt * are met:
44 1.1.2.2 yamt * 1. Redistributions of source code must retain the above copyright
45 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer.
46 1.1.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
47 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer in the
48 1.1.2.2 yamt * documentation and/or other materials provided with the distribution.
49 1.1.2.2 yamt * 3. All advertising materials mentioning features or use of this software
50 1.1.2.2 yamt * must display the following acknowledgement:
51 1.1.2.2 yamt * This product includes software developed by the NetBSD
52 1.1.2.2 yamt * Foundation, Inc. and its contributors.
53 1.1.2.2 yamt * 4. Neither the name of The NetBSD Foundation nor the names of its
54 1.1.2.2 yamt * contributors may be used to endorse or promote products derived
55 1.1.2.2 yamt * from this software without specific prior written permission.
56 1.1.2.2 yamt *
57 1.1.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
58 1.1.2.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
59 1.1.2.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
60 1.1.2.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
61 1.1.2.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
62 1.1.2.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
63 1.1.2.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
64 1.1.2.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
65 1.1.2.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
66 1.1.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
67 1.1.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
68 1.1.2.2 yamt */
69 1.1.2.2 yamt
70 1.1.2.2 yamt #include <sys/cdefs.h>
71 1.1.2.2 yamt __KERNEL_RCSID(0, "$NetBSD: if_sm_gxio.c,v 1.1.2.2 2006/10/22 06:04:38 yamt Exp $");
72 1.1.2.2 yamt
73 1.1.2.2 yamt #include <sys/param.h>
74 1.1.2.2 yamt #include <sys/device.h>
75 1.1.2.2 yamt #include <sys/errno.h>
76 1.1.2.2 yamt
77 1.1.2.2 yamt #include <sys/systm.h>
78 1.1.2.2 yamt #include <sys/mbuf.h>
79 1.1.2.2 yamt #include <sys/socket.h>
80 1.1.2.2 yamt #include <sys/ioctl.h>
81 1.1.2.2 yamt #include <sys/syslog.h>
82 1.1.2.2 yamt #include <sys/select.h>
83 1.1.2.2 yamt
84 1.1.2.2 yamt #include <net/if.h>
85 1.1.2.2 yamt #include <net/if_dl.h>
86 1.1.2.2 yamt #include <net/if_ether.h>
87 1.1.2.2 yamt #include <net/if_media.h>
88 1.1.2.2 yamt
89 1.1.2.2 yamt #include <machine/intr.h>
90 1.1.2.2 yamt #include <machine/bus.h>
91 1.1.2.2 yamt
92 1.1.2.2 yamt #include <dev/mii/mii.h>
93 1.1.2.2 yamt #include <dev/mii/miivar.h>
94 1.1.2.2 yamt
95 1.1.2.2 yamt #include <dev/ic/smc91cxxreg.h>
96 1.1.2.2 yamt #include <dev/ic/smc91cxxvar.h>
97 1.1.2.2 yamt
98 1.1.2.2 yamt #include <evbarm/gumstix/gumstixvar.h>
99 1.1.2.2 yamt
100 1.1.2.2 yamt #include "locators.h"
101 1.1.2.2 yamt
102 1.1.2.2 yamt
103 1.1.2.2 yamt static int sm_gxio_match(struct device *, struct cfdata *, void *);
104 1.1.2.2 yamt static void sm_gxio_attach(struct device *, struct device *, void *);
105 1.1.2.2 yamt
106 1.1.2.2 yamt static int ether_serial_digit = 1;
107 1.1.2.2 yamt
108 1.1.2.2 yamt struct sm_gxio_softc {
109 1.1.2.2 yamt struct smc91cxx_softc sc_smc;
110 1.1.2.2 yamt void *sc_ih;
111 1.1.2.2 yamt };
112 1.1.2.2 yamt
113 1.1.2.2 yamt CFATTACH_DECL(sm_gxio, sizeof(struct sm_gxio_softc),
114 1.1.2.2 yamt sm_gxio_match, sm_gxio_attach, NULL, NULL);
115 1.1.2.2 yamt
116 1.1.2.2 yamt
117 1.1.2.2 yamt static int
118 1.1.2.2 yamt sm_gxio_match(struct device *parent, struct cfdata *match, void *aux)
119 1.1.2.2 yamt {
120 1.1.2.2 yamt struct gxio_attach_args *gxa = aux;
121 1.1.2.2 yamt bus_space_tag_t iot = gxa->gxa_iot;
122 1.1.2.2 yamt bus_space_handle_t ioh;
123 1.1.2.2 yamt u_int16_t tmp;
124 1.1.2.2 yamt int rv = 0;
125 1.1.2.2 yamt extern const char *smc91cxx_idstrs[];
126 1.1.2.2 yamt
127 1.1.2.2 yamt /* Disallow wildcarded values. */
128 1.1.2.2 yamt if (gxa->gxa_addr == GXIOCF_ADDR_DEFAULT)
129 1.1.2.2 yamt return (0);
130 1.1.2.2 yamt if (gxa->gxa_gpirq == GXIOCF_GPIRQ_DEFAULT)
131 1.1.2.2 yamt return (0);
132 1.1.2.2 yamt
133 1.1.2.2 yamt if (bus_space_map(iot, gxa->gxa_addr, SMC_IOSIZE, 0, &ioh) != 0)
134 1.1.2.2 yamt return (0);
135 1.1.2.2 yamt
136 1.1.2.2 yamt /* Check that high byte of BANK_SELECT is what we expect. */
137 1.1.2.2 yamt tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
138 1.1.2.2 yamt if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
139 1.1.2.2 yamt goto out;
140 1.1.2.2 yamt
141 1.1.2.2 yamt /*
142 1.1.2.2 yamt * Switch to bank 0 and perform the test again.
143 1.1.2.2 yamt * XXX INVASIVE!
144 1.1.2.2 yamt */
145 1.1.2.2 yamt bus_space_write_1(iot, ioh, BANK_SELECT_REG_W, 0);
146 1.1.2.2 yamt tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
147 1.1.2.2 yamt if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
148 1.1.2.2 yamt goto out;
149 1.1.2.2 yamt
150 1.1.2.2 yamt /*
151 1.1.2.2 yamt * Check for a recognized chip id.
152 1.1.2.2 yamt * XXX INVASIVE!
153 1.1.2.2 yamt */
154 1.1.2.2 yamt bus_space_write_1(iot, ioh, BANK_SELECT_REG_W, 3);
155 1.1.2.2 yamt tmp = bus_space_read_2(iot, ioh, REVISION_REG_W);
156 1.1.2.2 yamt if (smc91cxx_idstrs[RR_ID(tmp)] == NULL)
157 1.1.2.2 yamt goto out;
158 1.1.2.2 yamt
159 1.1.2.2 yamt if (ether_serial_digit > 15)
160 1.1.2.2 yamt goto out;
161 1.1.2.2 yamt /*
162 1.1.2.2 yamt * Assume we have an SMC91Cxx.
163 1.1.2.2 yamt */
164 1.1.2.2 yamt
165 1.1.2.2 yamt rv = 1;
166 1.1.2.2 yamt
167 1.1.2.2 yamt out:
168 1.1.2.2 yamt bus_space_unmap(iot, ioh, SMC_IOSIZE);
169 1.1.2.2 yamt return (rv);
170 1.1.2.2 yamt }
171 1.1.2.2 yamt
172 1.1.2.2 yamt void
173 1.1.2.2 yamt sm_gxio_attach(struct device *parent, struct device *self, void *aux)
174 1.1.2.2 yamt {
175 1.1.2.2 yamt struct sm_gxio_softc *gsc = (struct sm_gxio_softc *)self;
176 1.1.2.2 yamt struct smc91cxx_softc *sc = &gsc->sc_smc;
177 1.1.2.2 yamt struct gxio_attach_args *gxa = aux;
178 1.1.2.2 yamt bus_space_handle_t ioh;
179 1.1.2.2 yamt u_int8_t myea[ETHER_ADDR_LEN];
180 1.1.2.2 yamt
181 1.1.2.2 yamt printf("\n");
182 1.1.2.2 yamt
183 1.1.2.2 yamt /* Map i/o space. */
184 1.1.2.2 yamt if (bus_space_map(gxa->gxa_iot, gxa->gxa_addr, SMC_IOSIZE, 0, &ioh))
185 1.1.2.2 yamt panic("sm_gxio_attach: can't map i/o space");
186 1.1.2.2 yamt
187 1.1.2.2 yamt sc->sc_bst = gxa->gxa_iot;
188 1.1.2.2 yamt sc->sc_bsh = ioh;
189 1.1.2.2 yamt
190 1.1.2.2 yamt /* should always be enabled */
191 1.1.2.2 yamt sc->sc_flags |= SMC_FLAGS_ENABLED;
192 1.1.2.2 yamt
193 1.1.2.2 yamt if (system_serial_high != 0 || system_serial_low != 0) {
194 1.1.2.2 yamt myea[0] = ((system_serial_high >> 8) & 0xfe) | 0x02;
195 1.1.2.2 yamt myea[1] = system_serial_high;
196 1.1.2.2 yamt myea[2] = system_serial_low >> 24;
197 1.1.2.2 yamt myea[3] = system_serial_low >> 16;
198 1.1.2.2 yamt myea[4] = system_serial_low >> 8;
199 1.1.2.2 yamt myea[5] = (system_serial_low & 0xc0) |
200 1.1.2.2 yamt (1 << 4) | ((ether_serial_digit++) & 0x0f);
201 1.1.2.2 yamt smc91cxx_attach(sc, myea);
202 1.1.2.2 yamt } else
203 1.1.2.2 yamt smc91cxx_attach(sc, NULL);
204 1.1.2.2 yamt
205 1.1.2.2 yamt /* Establish the interrupt handler. */
206 1.1.2.2 yamt gsc->sc_ih = gxio_intr_establish(gxa->gxa_sc,
207 1.1.2.2 yamt gxa->gxa_gpirq, IST_EDGE_RISING, IPL_NET, smc91cxx_intr, sc);
208 1.1.2.2 yamt
209 1.1.2.2 yamt if (gsc->sc_ih == NULL)
210 1.1.2.2 yamt printf("%s: couldn't establish interrupt handler\n",
211 1.1.2.2 yamt sc->sc_dev.dv_xname);
212 1.1.2.2 yamt }
213