1 /* $NetBSD: if_cs_smdk24x0.c,v 1.8 2019/04/25 05:42:43 msaitoh 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.8 2019/04/25 05:42:43 msaitoh 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 <net/if.h>
83 #include <net/if_ether.h>
84 #include <net/if_media.h>
85
86 #include <sys/bus.h>
87 #include <machine/intr.h>
88
89 #include <arch/arm/s3c2xx0/s3c2410reg.h>
90 #include <arch/arm/s3c2xx0/s3c2410var.h>
91
92 #include <dev/ic/cs89x0reg.h>
93 #include <dev/ic/cs89x0var.h>
94
95 #include "locators.h"
96 #include "opt_smdk2xx0.h" /* SMDK24X0_ETHER_ADDR_FIXED */
97
98 int cs_ssextio_probe(device_t, cfdata_t, void *);
99 void cs_ssextio_attach(device_t, device_t, void *);
100
101 /*
102 * I/O access is done when A24==1.
103 * default value for I/O base address is 0x300
104 */
105 #define IOADDR(base) (base + (1<<24) + 0x0300)
106
107 CFATTACH_DECL_NEW(cs_ssextio, sizeof(struct cs_softc),
108 cs_ssextio_probe, cs_ssextio_attach, NULL, NULL);
109
110 int
cs_ssextio_probe(device_t parent,cfdata_t cf,void * aux)111 cs_ssextio_probe(device_t parent, cfdata_t cf, void *aux)
112 {
113 struct s3c2xx0_attach_args *sa = aux;
114 bus_space_tag_t iot = sa->sa_iot;
115 bus_space_handle_t ioh;
116 struct cs_softc sc;
117 int rv = 0, have_io = 0;
118 vaddr_t ioaddr;
119
120 if (sa->sa_intr == SSEXTIOCF_INTR_DEFAULT)
121 sa->sa_intr = 9;
122 if (sa->sa_addr == SSEXTIOCF_ADDR_DEFAULT)
123 sa->sa_addr = S3C2410_BANK_START(3);
124
125 /* Map the I/O space. */
126 ioaddr = IOADDR(sa->sa_addr);
127 if (bus_space_map(iot, ioaddr, CS8900_IOSIZE, 0, &ioh))
128 goto out;
129 have_io = 1;
130
131 memset(&sc, 0, sizeof sc);
132 sc.sc_iot = iot;
133 sc.sc_ioh = ioh;
134
135 if (0) {
136 int i;
137
138 for (i = 0; i <= PKTPG_IND_ADDR; i += 2) {
139 if (i % 16 == 0)
140 printf( "\n%04x: ", i);
141 printf("%04x ", CS_READ_PACKET_PAGE_IO(&sc, i));
142 }
143
144 }
145
146 /* Verify that it's a Crystal product. */
147 if (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_EISA_NUM) != EISA_NUM_CRYSTAL)
148 goto out;
149
150 /* Verify that it's a supported chip. */
151 switch (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_PRODUCT_ID) & PROD_ID_MASK) {
152 case PROD_ID_CS8900:
153 #ifdef notyet
154 case PROD_ID_CS8920:
155 case PROD_ID_CS8920M:
156 #endif
157 rv = 1;
158 }
159
160 out:
161 if (have_io)
162 bus_space_unmap(iot, ioh, CS8900_IOSIZE);
163
164 return rv;
165 }
166
167 /* media selection: UTP only */
168 static int cs_media[] = {
169 IFM_ETHER | IFM_10_T,
170 #if 0
171 IFM_ETHER | IFM_10_T | IFM_FDX,
172 #endif
173 };
174
175 void
cs_ssextio_attach(device_t parent,device_t self,void * aux)176 cs_ssextio_attach(device_t parent, device_t self, void *aux)
177 {
178 struct cs_softc *sc = device_private(self);
179 struct s3c2xx0_attach_args *sa = aux;
180 vaddr_t ioaddr;
181 #ifdef SMDK24X0_ETHER_ADDR_FIXED
182 static uint8_t enaddr[ETHER_ADDR_LEN] = {SMDK24X0_ETHER_ADDR_FIXED};
183 #else
184 #define enaddr NULL
185 #endif
186
187 sc->sc_dev = self;
188 sc->sc_iot = sc->sc_memt = sa->sa_iot;
189 /*
190 * sc_irq is an IRQ number in ISA world. Set 10 for INTRQ0 of CS8900A.
191 */
192 sc->sc_irq = 10;
193
194 /* Map the device. */
195 ioaddr = IOADDR(sa->sa_addr);
196 if (bus_space_map(sc->sc_iot, ioaddr, CS8900_IOSIZE, 0, &sc->sc_ioh)) {
197 aprint_error(": unable to map i/o space\n");
198 return;
199 }
200
201 if (bus_space_map(sc->sc_iot, sa->sa_addr, CS8900_MEMSIZE,
202 0, &sc->sc_memh))
203 aprint_error(": unable to map memory space");
204 else {
205 sc->sc_cfgflags |= CFGFLG_MEM_MODE;
206 sc->sc_pktpgaddr = sa->sa_addr;
207 }
208
209 /*
210 * CS8900A is very slow. (nOE->Data valid: 135ns max.)
211 * We need to use IOCHRDY signal.
212 */
213 sc->sc_cfgflags |= CFGFLG_IOCHRDY;
214
215 sc->sc_ih = s3c2410_extint_establish(sa->sa_intr, IPL_NET,
216 IST_EDGE_RISING, cs_intr, sc);
217 if (sc->sc_ih == NULL) {
218 aprint_error(": unable to establish interrupt\n");
219 return;
220 }
221
222 aprint_normal("\n");
223
224 /* SMDK24X0 doesn't have EEPRMO hooked to CS8900A */
225 sc->sc_cfgflags |= CFGFLG_NOT_EEPROM;
226
227 cs_attach(sc, enaddr, cs_media, __arraycount(cs_media),
228 IFM_ETHER | IFM_10_T);
229 }
230