No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / evbarm / smdk2xx0 / if_cs_smdk24x0.c
blob8bf52d12f6085f0b79f104d5acb157d60d157c01
1 /* $NetBSD: if_cs_smdk24x0.c,v 1.2 2005/12/11 12:17:09 christos Exp $ */
3 /*
4 * Copyright (c) 2003 Genetec corporation. All rights reserved.
5 * Written by Hiroyuki Bessho for Genetec corporation.
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.
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.
32 /* derived from sys/dev/isa/if_cs_isa.c */
34 * Copyright 1997
35 * Digital Equipment Corporation. All rights reserved.
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.
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.
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.
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.
67 * driver for SMDK24[10]0's on-board CS8900A Ethernet
69 * CS8900A is located at CS3 area.
70 * A24=1: I/O access
71 * A24=0: Memory access
74 #include <sys/cdefs.h>
75 __KERNEL_RCSID(0, "$NetBSD: if_cs_smdk24x0.c,v 1.2 2005/12/11 12:17:09 christos Exp $");
77 #include <sys/param.h>
78 #include <sys/systm.h>
79 #include <sys/socket.h>
80 #include <sys/device.h>
82 #include "rnd.h"
83 #if NRND > 0
84 #include <sys/rnd.h>
85 #endif
87 #include <net/if.h>
88 #include <net/if_ether.h>
89 #include <net/if_media.h>
91 #include <machine/bus.h>
92 #include <machine/intr.h>
94 #include <arch/arm/s3c2xx0/s3c2410reg.h>
95 #include <arch/arm/s3c2xx0/s3c2410var.h>
97 #include <dev/ic/cs89x0reg.h>
98 #include <dev/ic/cs89x0var.h>
100 #include "locators.h"
101 #include "opt_smdk2xx0.h" /* SMDK24X0_ETHER_ADDR_FIXED */
103 int cs_ssextio_probe(device_t, cfdata_t, void *);
104 void cs_ssextio_attach(device_t, device_t, void *);
107 * I/O access is done when A24==1.
108 * default value for I/O base address is 0x300
110 #define IOADDR(base) (base + (1<<24) + 0x0300)
112 CFATTACH_DECL_NEW(cs_ssextio, sizeof(struct cs_softc),
113 cs_ssextio_probe, cs_ssextio_attach, NULL, NULL);
115 int
116 cs_ssextio_probe(device_t parent, cfdata_t cf, void *aux)
118 struct s3c2xx0_attach_args *sa = aux;
119 bus_space_tag_t iot = sa->sa_iot;
120 bus_space_handle_t ioh;
121 struct cs_softc sc;
122 int rv = 0, have_io = 0;
123 vaddr_t ioaddr;
125 if (sa->sa_intr == SSEXTIOCF_INTR_DEFAULT)
126 sa->sa_intr = 9;
127 if (sa->sa_addr == SSEXTIOCF_ADDR_DEFAULT)
128 sa->sa_addr = S3C2410_BANK_START(3);
131 * Map the I/O space.
133 ioaddr = IOADDR(sa->sa_addr);
134 if (bus_space_map(iot, ioaddr, CS8900_IOSIZE, 0, &ioh))
135 goto out;
136 have_io = 1;
138 memset(&sc, 0, sizeof sc);
139 sc.sc_iot = iot;
140 sc.sc_ioh = ioh;
142 if (0) {
143 int i;
145 for (i=0; i <=PKTPG_IND_ADDR; i += 2) {
146 if (i % 16 == 0)
147 printf( "\n%04x: ", i);
148 printf("%04x ", CS_READ_PACKET_PAGE_IO(&sc, i));
153 /* Verify that it's a Crystal product. */
154 if (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_EISA_NUM) != EISA_NUM_CRYSTAL)
155 goto out;
158 * Verify that it's a supported chip.
160 switch (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_PRODUCT_ID) & PROD_ID_MASK) {
161 case PROD_ID_CS8900:
162 #ifdef notyet
163 case PROD_ID_CS8920:
164 case PROD_ID_CS8920M:
165 #endif
166 rv = 1;
169 out:
170 if (have_io)
171 bus_space_unmap(iot, ioh, CS8900_IOSIZE);
173 return (rv);
176 /* media selection: UTP only */
177 static int cs_media[] = {
178 IFM_ETHER|IFM_10_T,
179 #if 0
180 IFM_ETHER|IFM_10_T|IFM_FDX,
181 #endif
184 void
185 cs_ssextio_attach(device_t parent, device_t self, void *aux)
187 struct cs_softc *sc = device_private(self);
188 struct s3c2xx0_attach_args *sa = aux;
189 vaddr_t ioaddr;
190 #ifdef SMDK24X0_ETHER_ADDR_FIXED
191 static u_int8_t enaddr[ETHER_ADDR_LEN] = {SMDK24X0_ETHER_ADDR_FIXED};
192 #else
193 #define enaddr NULL
194 #endif
196 sc->sc_dev = self;
197 sc->sc_iot = sc->sc_memt = sa->sa_iot;
198 /* sc_irq is an IRQ number in ISA world. set 10 for INTRQ0 of CS8900A */
199 sc->sc_irq = 10;
202 * Map the device.
204 ioaddr = IOADDR(sa->sa_addr);
205 if (bus_space_map(sc->sc_iot, ioaddr, CS8900_IOSIZE, 0, &sc->sc_ioh)) {
206 aprint_error(": unable to map i/o space\n");
207 return;
210 if (bus_space_map(sc->sc_iot, sa->sa_addr, CS8900_MEMSIZE,
211 0, &sc->sc_memh))
212 aprint_error(": unable to map memory space");
213 else {
214 sc->sc_cfgflags |= CFGFLG_MEM_MODE;
215 sc->sc_pktpgaddr = sa->sa_addr;
218 /* CS8900A is very slow. (nOE->Data valid: 135ns max.)
219 We need to use IOCHRDY signal */
220 sc->sc_cfgflags |= CFGFLG_IOCHRDY;
222 sc->sc_ih = s3c2410_extint_establish(sa->sa_intr, IPL_NET, IST_EDGE_RISING,
223 cs_intr, sc);
224 if (sc->sc_ih == NULL) {
225 aprint_error(": unable to establish interrupt\n");
226 return;
229 aprint_normal("\n");
231 /* SMDK24X0 doesn't have EEPRMO hooked to CS8900A */
232 sc->sc_cfgflags |= CFGFLG_NOT_EEPROM;
234 cs_attach(sc, enaddr, cs_media,
235 sizeof(cs_media) / sizeof(cs_media[0]), IFM_ETHER|IFM_10_T);