if_sm_obio.c revision 1.1
1/*	$NetBSD: if_sm_obio.c,v 1.1 2003/06/18 10:51:15 bsh Exp $ */
2
3/*
4 * Copyright (c) 2002, 2003  Genetec Corporation.  All rights reserved.
5 * Written by Hiroyuki Bessho for Genetec Corporation.
6 *
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.
18 *
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.
30 *
31 * attach sm driver to Lubbock on-board bus
32 * based on sys/dev/isa/if_sm_isa.c
33 *
34 */
35
36/*-
37 * Copyright (c) 1997 The NetBSD Foundation, Inc.
38 * All rights reserved.
39 *
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.
43 *
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.
52 * 3. All advertising materials mentioning features or use of this software
53 *    must display the following acknowledgement:
54 *	This product includes software developed by the NetBSD
55 *	Foundation, Inc. and its contributors.
56 * 4. Neither the name of The NetBSD Foundation nor the names of its
57 *    contributors may be used to endorse or promote products derived
58 *    from this software without specific prior written permission.
59 *
60 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
61 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
62 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
63 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
64 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
65 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
66 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
67 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
68 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
69 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
70 * POSSIBILITY OF SUCH DAMAGE.
71 */
72
73#include <sys/cdefs.h>
74__KERNEL_RCSID(0, "$NetBSD: if_sm_obio.c,v 1.1 2003/06/18 10:51:15 bsh Exp $");
75
76#include <sys/param.h>
77#include <sys/systm.h>
78#include <sys/mbuf.h>
79#include <sys/socket.h>
80#include <sys/ioctl.h>
81#include <sys/errno.h>
82#include <sys/syslog.h>
83#include <sys/select.h>
84#include <sys/device.h>
85
86#include <net/if.h>
87#include <net/if_dl.h>
88#include <net/if_ether.h>
89#include <net/if_media.h>
90
91#include <machine/intr.h>
92#include <machine/bus.h>
93
94#include <dev/mii/mii.h>
95#include <dev/mii/miivar.h>
96
97#include <dev/ic/smc91cxxreg.h>
98#include <dev/ic/smc91cxxvar.h>
99
100#include <evbarm/lubbock/lubbock_var.h>
101
102#include "opt_lubbock.h"	/* LUBBOCK_SMC91C96_16BIT */
103
104int	sm_obio_match(struct device *, struct cfdata *, void *);
105void	sm_obio_attach(struct device *, struct device *, void *);
106
107struct sm_obio_softc {
108	struct	smc91cxx_softc sc_smc;		/* real "smc" softc */
109
110	/* OBIO-specific goo. */
111	void	*sc_ih;				/* interrupt handler */
112};
113
114CFATTACH_DECL(sm_obio, sizeof(struct sm_obio_softc), sm_obio_match,
115    sm_obio_attach, NULL, NULL);
116
117extern struct bus_space  smobio8_bs_tag;
118
119#ifndef SM_OBIO_INTR_PARANOIA
120# define smintr	smc91cxx_intr
121#else
122# define smintr smc_obio_intr
123
124static int
125smc_obio_intr(void *arg)
126{
127	while (smc91cxx_intr(arg))
128		;
129	return 1;
130}
131#endif /* SM_OBIO_INTR_PARANOIA */
132
133int
134sm_obio_match(struct device *parent, struct cfdata *match, void *aux)
135{
136	struct obio_attach_args *oba = aux;
137	bus_space_tag_t iot = &smobio8_bs_tag;
138	bus_space_handle_t ioh;
139	u_int16_t tmp;
140	int rv = 0;
141	extern const char *smc91cxx_idstrs[];
142
143
144	/* Map i/o space. */
145	if (bus_space_map(iot, oba->oba_addr, SMC_IOSIZE, 0, &ioh))
146		return (0);
147
148
149	/* Check that high byte of BANK_SELECT is what we expect. */
150	tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
151	if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
152		goto out;
153
154	/*
155	 * Switch to bank 0 and perform the test again.
156	 * XXX INVASIVE!
157	 */
158	bus_space_write_1(iot, ioh, BANK_SELECT_REG_W, 0);
159	tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
160	if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
161		goto out;
162
163	/*
164	 * Check for a recognized chip id.
165	 * XXX INVASIVE!
166	 */
167	bus_space_write_1(iot, ioh, BANK_SELECT_REG_W, 3);
168	tmp = bus_space_read_2(iot, ioh, REVISION_REG_W);
169	if (smc91cxx_idstrs[RR_ID(tmp)] == NULL)
170		goto out;
171
172	/*
173	 * Assume we have an SMC91Cxx.
174	 */
175
176	rv = 1;
177
178 out:
179	bus_space_unmap(iot, ioh, SMC_IOSIZE);
180	if (!rv) {
181		printf("on-board SMC probe failed\n");
182	}
183	return (rv);
184}
185
186void
187sm_obio_attach(struct device *parent, struct device *self, void *aux)
188{
189	struct sm_obio_softc *isc = (struct sm_obio_softc *)self;
190	struct smc91cxx_softc *sc = &isc->sc_smc;
191	struct obio_attach_args *oba = aux;
192	bus_space_handle_t ioh;
193#ifdef LUBBOCK_SMC91C96_16BIT
194	bus_space_tag_t iot = &pxa2x0_a4x_bs_tag;
195#else
196	bus_space_tag_t iot = &smobio8_bs_tag;
197#endif
198
199
200	printf("\n");
201
202	/* Map i/o space. */
203	if (bus_space_map(iot, oba->oba_addr, SMC_IOSIZE, 0, &ioh))
204		panic("sm_obio_attach: can't map i/o space");
205
206#ifdef LUBBOCK_SMC91C96_16BIT
207	/* RedBoot initializes on-board SMSC91C96 in 8-bit mode.
208	   we take it back to 16-bit by clearing ECSR.IOIs8 */
209	{
210		int tmp;
211
212		bus_space_write_1(&smobio8_bs_tag, ioh, BANK_SELECT_REG_W, 4);
213		tmp = bus_space_read_1(&smobio8_bs_tag, ioh, ECSR_REG_B);
214		bus_space_write_1(&smobio8_bs_tag, ioh,
215		    ECSR_REG_B, tmp & ~ECSR_IOIS8);
216	}
217
218	obio16_write(LUBBOCK_MISCWR,
219	    obio16_read(LUBBOCK_MISCWR) & ~MISCWR_ENETEN16 );
220
221#else
222	/* Force 8bit mode */
223	obio16_write(LUBBOCK_MISCWR,
224	    obio16_read(LUBBOCK_MISCWR) | MISCWR_ENETEN16);
225
226#endif /* LUBBOCK_SMC91C96_16BIT */
227
228	sc->sc_bst = iot;
229	sc->sc_bsh = ioh;
230
231	/* should always be enabled */
232	sc->sc_flags |= SMC_FLAGS_ENABLED;
233
234	/* Perform generic intialization. */
235	smc91cxx_attach(sc, NULL);
236
237	/* Establish the interrupt handler. */
238	isc->sc_ih = obio_intr_establish((struct obio_softc *)parent,
239					 oba->oba_intr, IPL_NET, smintr, sc);
240
241	if (isc->sc_ih == NULL)
242		printf("%s: couldn't establish interrupt handler\n",
243		    sc->sc_dev.dv_xname);
244}
245