if_cs_smdk24x0.c revision 1.5
1/*	$NetBSD: if_cs_smdk24x0.c,v 1.5 2012/02/02 19:42:59 tls Exp $ */
2
3/*
4 * Copyright (c) 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
16 *    or promote products derived from this software without specific prior
17 *    written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY GENETEC CORP. ``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 CORP.
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
32/* derived from sys/dev/isa/if_cs_isa.c */
33/*
34 * Copyright 1997
35 * Digital Equipment Corporation. All rights reserved.
36 *
37 * This software is furnished under license and may be used and
38 * copied only in accordance with the following terms and conditions.
39 * Subject to these conditions, you may download, copy, install,
40 * use, modify and distribute this software in source and/or binary
41 * form. No title or ownership is transferred hereby.
42 *
43 * 1) Any source code used, modified or distributed must reproduce
44 *    and retain this copyright notice and list of conditions as
45 *    they appear in the source file.
46 *
47 * 2) No right is granted to use any trade name, trademark, or logo of
48 *    Digital Equipment Corporation. Neither the "Digital Equipment
49 *    Corporation" name nor any trademark or logo of Digital Equipment
50 *    Corporation may be used to endorse or promote products derived
51 *    from this software without the prior written permission of
52 *    Digital Equipment Corporation.
53 *
54 * 3) This software is provided "AS-IS" and any express or implied
55 *    warranties, including but not limited to, any implied warranties
56 *    of merchantability, fitness for a particular purpose, or
57 *    non-infringement are disclaimed. In no event shall DIGITAL be
58 *    liable for any damages whatsoever, and in particular, DIGITAL
59 *    shall not be liable for special, indirect, consequential, or
60 *    incidental damages or damages for lost profits, loss of
61 *    revenue or loss of use, whether such damages arise in contract,
62 *    negligence, tort, under statute, in equity, at law or otherwise,
63 *    even if advised of the possibility of such damage.
64 */
65
66/*
67 * driver for SMDK24[10]0's on-board CS8900A Ethernet
68 *
69 * CS8900A is located at CS3 area.
70 *    A24=1: I/O access
71 *    A24=0: Memory access
72 */
73
74#include <sys/cdefs.h>
75__KERNEL_RCSID(0, "$NetBSD: if_cs_smdk24x0.c,v 1.5 2012/02/02 19:42:59 tls Exp $");
76
77#include <sys/param.h>
78#include <sys/systm.h>
79#include <sys/socket.h>
80#include <sys/device.h>
81
82#include <sys/rnd.h>
83
84#include <net/if.h>
85#include <net/if_ether.h>
86#include <net/if_media.h>
87
88#include <sys/bus.h>
89#include <machine/intr.h>
90
91#include <arch/arm/s3c2xx0/s3c2410reg.h>
92#include <arch/arm/s3c2xx0/s3c2410var.h>
93
94#include <dev/ic/cs89x0reg.h>
95#include <dev/ic/cs89x0var.h>
96
97#include "locators.h"
98#include "opt_smdk2xx0.h"		/* SMDK24X0_ETHER_ADDR_FIXED */
99
100int	cs_ssextio_probe(device_t, cfdata_t, void *);
101void	cs_ssextio_attach(device_t, device_t, void *);
102
103/*
104 * I/O access is done when A24==1.
105 * default value for I/O base address is 0x300
106 */
107#define IOADDR(base)	(base + (1<<24) + 0x0300)
108
109CFATTACH_DECL_NEW(cs_ssextio, sizeof(struct cs_softc),
110    cs_ssextio_probe, cs_ssextio_attach, NULL, NULL);
111
112int
113cs_ssextio_probe(device_t parent, cfdata_t cf, void *aux)
114{
115	struct s3c2xx0_attach_args *sa = aux;
116	bus_space_tag_t iot = sa->sa_iot;
117	bus_space_handle_t ioh;
118	struct cs_softc sc;
119	int rv = 0, have_io = 0;
120	vaddr_t ioaddr;
121
122	if (sa->sa_intr == SSEXTIOCF_INTR_DEFAULT)
123		sa->sa_intr = 9;
124	if (sa->sa_addr == SSEXTIOCF_ADDR_DEFAULT)
125		sa->sa_addr = S3C2410_BANK_START(3);
126
127	/*
128	 * Map the I/O space.
129	 */
130	ioaddr = IOADDR(sa->sa_addr);
131	if (bus_space_map(iot, ioaddr, CS8900_IOSIZE, 0, &ioh))
132		goto out;
133	have_io = 1;
134
135	memset(&sc, 0, sizeof sc);
136	sc.sc_iot = iot;
137	sc.sc_ioh = ioh;
138
139	if (0) {
140		int i;
141
142		for (i=0; i <=PKTPG_IND_ADDR; i += 2) {
143			if (i % 16 == 0)
144				printf( "\n%04x: ", i);
145			printf("%04x ", CS_READ_PACKET_PAGE_IO(&sc, i));
146		}
147
148	}
149
150	/* Verify that it's a Crystal product. */
151	if (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_EISA_NUM) != EISA_NUM_CRYSTAL)
152		goto out;
153
154	/*
155	 * Verify that it's a supported chip.
156	 */
157	switch (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_PRODUCT_ID) & PROD_ID_MASK) {
158	case PROD_ID_CS8900:
159#ifdef notyet
160	case PROD_ID_CS8920:
161	case PROD_ID_CS8920M:
162#endif
163		rv = 1;
164	}
165
166 out:
167	if (have_io)
168		bus_space_unmap(iot, ioh, CS8900_IOSIZE);
169
170	return (rv);
171}
172
173/* media selection: UTP only */
174static int cs_media[] = {
175	IFM_ETHER|IFM_10_T,
176#if 0
177	IFM_ETHER|IFM_10_T|IFM_FDX,
178#endif
179};
180
181void
182cs_ssextio_attach(device_t parent, device_t self, void *aux)
183{
184	struct cs_softc *sc = device_private(self);
185	struct s3c2xx0_attach_args *sa = aux;
186	vaddr_t ioaddr;
187#ifdef	SMDK24X0_ETHER_ADDR_FIXED
188	static u_int8_t enaddr[ETHER_ADDR_LEN] = {SMDK24X0_ETHER_ADDR_FIXED};
189#else
190#define enaddr NULL
191#endif
192
193	sc->sc_dev = self;
194	sc->sc_iot = sc->sc_memt = sa->sa_iot;
195	/* sc_irq is an IRQ number in ISA world. set 10 for INTRQ0 of CS8900A */
196	sc->sc_irq = 10;
197
198	/*
199	 * Map the device.
200	 */
201	ioaddr = IOADDR(sa->sa_addr);
202	if (bus_space_map(sc->sc_iot, ioaddr, CS8900_IOSIZE, 0, &sc->sc_ioh)) {
203		aprint_error(": unable to map i/o space\n");
204		return;
205	}
206
207	if (bus_space_map(sc->sc_iot, sa->sa_addr, CS8900_MEMSIZE,
208			  0, &sc->sc_memh))
209		aprint_error(": unable to map memory space");
210	else {
211		sc->sc_cfgflags |= CFGFLG_MEM_MODE;
212		sc->sc_pktpgaddr = sa->sa_addr;
213	}
214
215	/* CS8900A is very slow. (nOE->Data valid: 135ns max.)
216	   We need to use IOCHRDY signal */
217	sc->sc_cfgflags |= CFGFLG_IOCHRDY;
218
219	sc->sc_ih = s3c2410_extint_establish(sa->sa_intr, IPL_NET, IST_EDGE_RISING,
220	    cs_intr, sc);
221	if (sc->sc_ih == NULL) {
222		aprint_error(": unable to establish interrupt\n");
223		return;
224	}
225
226	aprint_normal("\n");
227
228	/* SMDK24X0 doesn't have EEPRMO hooked to CS8900A */
229	sc->sc_cfgflags |= CFGFLG_NOT_EEPROM;
230
231	cs_attach(sc, enaddr, cs_media,
232	    sizeof(cs_media) / sizeof(cs_media[0]), IFM_ETHER|IFM_10_T);
233}
234