Sync usage with man page.
[netbsd-mini2440.git] / sys / dev / pcmcia / isic_pcmcia_elsa_isdnmc.c
blob267b406bd28416ad739746d8de0f0c5aec63c186
1 /*-
2 * Copyright (c) 2002 The NetBSD Foundation, Inc.
3 * All rights reserved.
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Martin Husemann <martin@NetBSD.org>.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: isic_pcmcia_elsa_isdnmc.c,v 1.12 2007/10/19 12:01:05 ad Exp $");
33 #include "opt_isicpcmcia.h"
34 #ifdef ISICPCMCIA_ELSA_ISDNMC
36 #include <sys/param.h>
37 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
38 #include <sys/ioccom.h>
39 #else
40 #include <sys/ioctl.h>
41 #endif
42 #include <sys/kernel.h>
43 #include <sys/systm.h>
44 #include <sys/mbuf.h>
46 #ifdef __FreeBSD__
47 #include <machine/clock.h>
48 #include <i386/isa/isa_device.h>
49 #else
50 #include <sys/bus.h>
51 #include <sys/device.h>
52 #endif
54 #include <sys/socket.h>
55 #include <net/if.h>
57 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
58 #include <sys/callout.h>
59 #endif
61 #ifdef __FreeBSD__
62 #include <machine/i4b_debug.h>
63 #include <machine/i4b_ioctl.h>
64 #else
65 #include <netisdn/i4b_debug.h>
66 #include <netisdn/i4b_ioctl.h>
68 #include <dev/pcmcia/pcmciareg.h>
69 #include <dev/pcmcia/pcmciavar.h>
70 #endif
72 #include <netisdn/i4b_l2.h>
73 #include <netisdn/i4b_l1l2.h>
74 #include <dev/ic/isic_l1.h>
75 #include <dev/ic/isac.h>
76 #include <dev/ic/hscx.h>
78 #include <dev/pcmcia/isic_pcmcia.h>
80 #ifndef __FreeBSD__
81 /* PCMCIA support routines */
82 static u_int8_t elsa_isdnmc_read_reg(struct isic_softc *sc, int what, bus_size_t offs);
83 static void elsa_isdnmc_write_reg(struct isic_softc *sc, int what, bus_size_t offs, u_int8_t data);
84 static void elsa_isdnmc_read_fifo(struct isic_softc *sc, int what, void *buf, size_t size);
85 static void elsa_isdnmc_write_fifo(struct isic_softc *sc, int what, const void *data, size_t size);
86 static void elsa_isdnmc_clrirq(struct isic_softc *sc);
87 #endif
90 * The ELSA MicroLink ISDN/MC uses one contigous IO region,
91 * mapped by the pcmcia code.
92 * The chip access is via three ports:
94 #define ISAC_DATA 1 /* ISAC dataport at offset 1 */
95 #define HSCX_DATA 2 /* HSCX dataport at offset 2 */
96 #define ADDR_LATCH 4 /* address latch at offset 4 */
98 /* This is very similar to the ELSA QuickStep 1000 (ISA) card */
100 #ifdef __FreeBSD__
101 static void
102 elsa_isdnmc_clrirq(void *base)
105 #else
106 static void
107 elsa_isdnmc_clrirq(struct isic_softc *sc)
109 ISAC_WRITE(I_MASK, 0xff);
110 HSCX_WRITE(0, H_MASK, 0xff);
111 HSCX_WRITE(1, H_MASK, 0xff);
112 ISAC_WRITE(I_MASK, ISAC_IMASK);
113 HSCX_WRITE(0, H_MASK, HSCX_A_IMASK);
114 HSCX_WRITE(1, H_MASK, HSCX_B_IMASK);
116 #endif
118 /*---------------------------------------------------------------------------*
119 * read fifo routines
120 *---------------------------------------------------------------------------*/
121 #ifdef __FreeBSD__
122 static void
123 elsa_isdnmc_read_fifo(void *buf, const void *base, size_t len)
126 #else
127 static void
128 elsa_isdnmc_read_fifo(struct isic_softc *sc, int what, void *buf, size_t size)
130 bus_space_tag_t t = sc->sc_maps[0].t;
131 bus_space_handle_t h = sc->sc_maps[0].h;
132 switch (what) {
133 case ISIC_WHAT_ISAC:
134 bus_space_write_1(t, h, ADDR_LATCH, 0);
135 bus_space_read_multi_1(t, h, ISAC_DATA, buf, size);
136 break;
137 case ISIC_WHAT_HSCXA:
138 bus_space_write_1(t, h, ADDR_LATCH, 0);
139 bus_space_read_multi_1(t, h, HSCX_DATA, buf, size);
140 break;
141 case ISIC_WHAT_HSCXB:
142 bus_space_write_1(t, h, ADDR_LATCH, 0x40);
143 bus_space_read_multi_1(t, h, HSCX_DATA, buf, size);
144 break;
147 #endif
149 /*---------------------------------------------------------------------------*
150 * write fifo routines
151 *---------------------------------------------------------------------------*/
152 #ifdef __FreeBSD__
153 static void
154 elsa_isdnmc_write_fifo(void *base, const void *buf, size_t len)
157 #else
158 static void
159 elsa_isdnmc_write_fifo(struct isic_softc *sc, int what, const void *buf, size_t size)
161 bus_space_tag_t t = sc->sc_maps[0].t;
162 bus_space_handle_t h = sc->sc_maps[0].h;
163 switch (what) {
164 case ISIC_WHAT_ISAC:
165 bus_space_write_1(t, h, ADDR_LATCH, 0);
166 bus_space_write_multi_1(t, h, ISAC_DATA, buf, size);
167 break;
168 case ISIC_WHAT_HSCXA:
169 bus_space_write_1(t, h, ADDR_LATCH, 0);
170 bus_space_write_multi_1(t, h, HSCX_DATA, buf, size);
171 break;
172 case ISIC_WHAT_HSCXB:
173 bus_space_write_1(t, h, ADDR_LATCH, 0x40);
174 bus_space_write_multi_1(t, h, HSCX_DATA, buf, size);
175 break;
178 #endif
180 /*---------------------------------------------------------------------------*
181 * write register routines
182 *---------------------------------------------------------------------------*/
183 #ifdef __FreeBSD__
184 static void
185 elsa_isdnmc_write_reg(u_char *base, u_int offset, u_int v)
188 #else
189 static void
190 elsa_isdnmc_write_reg(struct isic_softc *sc, int what, bus_size_t offs, u_int8_t data)
192 bus_space_tag_t t = sc->sc_maps[0].t;
193 bus_space_handle_t h = sc->sc_maps[0].h;
194 switch (what) {
195 case ISIC_WHAT_ISAC:
196 bus_space_write_1(t, h, ADDR_LATCH, offs);
197 bus_space_write_1(t, h, ISAC_DATA, data);
198 break;
199 case ISIC_WHAT_HSCXA:
200 bus_space_write_1(t, h, ADDR_LATCH, offs);
201 bus_space_write_1(t, h, HSCX_DATA, data);
202 break;
203 case ISIC_WHAT_HSCXB:
204 bus_space_write_1(t, h, ADDR_LATCH, 0x40+offs);
205 bus_space_write_1(t, h, HSCX_DATA, data);
206 break;
209 #endif
211 /*---------------------------------------------------------------------------*
212 * read register routines
213 *---------------------------------------------------------------------------*/
214 #ifdef __FreeBSD__
215 static u_char
216 elsa_isdnmc_read_reg(u_char *base, u_int offset)
218 return 0;
220 #else
221 static u_int8_t
222 elsa_isdnmc_read_reg(struct isic_softc *sc, int what, bus_size_t offs)
224 bus_space_tag_t t = sc->sc_maps[0].t;
225 bus_space_handle_t h = sc->sc_maps[0].h;
226 switch (what) {
227 case ISIC_WHAT_ISAC:
228 bus_space_write_1(t, h, ADDR_LATCH, offs);
229 return bus_space_read_1(t, h, ISAC_DATA);
230 case ISIC_WHAT_HSCXA:
231 bus_space_write_1(t, h, ADDR_LATCH, offs);
232 return bus_space_read_1(t, h, HSCX_DATA);
233 case ISIC_WHAT_HSCXB:
234 bus_space_write_1(t, h, ADDR_LATCH, 0x40+offs);
235 return bus_space_read_1(t, h, HSCX_DATA);
237 return 0;
239 #endif
241 #ifdef __FreeBSD__
242 #else
245 * XXX - one time only! Some of this has to go into an enable
246 * function, with apropriate counterpart in disable, so a card
247 * could be removed an inserted again.
250 isic_attach_elsaisdnmc(struct pcmcia_isic_softc *psc, struct pcmcia_config_entry *cfe, struct pcmcia_attach_args *pa)
252 struct isic_softc *sc = &psc->sc_isic;
253 bus_space_tag_t t;
254 bus_space_handle_t h;
256 /* Validate config info */
257 if (cfe->num_memspace != 0)
258 printf(": unexpected number of memory spaces %d should be 0\n",
259 cfe->num_memspace);
260 if (cfe->num_iospace != 1)
261 printf(": unexpected number of memory spaces %d should be 1\n",
262 cfe->num_iospace);
264 /* Allocate pcmcia space */
265 if (pcmcia_io_alloc(pa->pf, 0, cfe->iospace[0].length,
266 cfe->iospace[0].length, &psc->sc_pcioh))
267 printf(": can't allocate i/o space\n");
269 /* map them */
270 if (pcmcia_io_map(pa->pf, ((cfe->flags & PCMCIA_CFE_IO16) ?
271 PCMCIA_WIDTH_IO16 : PCMCIA_WIDTH_IO8), &psc->sc_pcioh,
272 &psc->sc_io_window)) {
273 printf(": can't map i/o space\n");
274 return 0;
277 /* Setup bus space maps */
278 sc->sc_num_mappings = 1;
279 MALLOC_MAPS(sc);
281 /* Copy our handles/tags to the MI maps */
282 sc->sc_maps[0].t = psc->sc_pcioh.iot;
283 sc->sc_maps[0].h = psc->sc_pcioh.ioh;
284 sc->sc_maps[0].offset = 0;
285 sc->sc_maps[0].size = 0; /* not our mapping */
287 t = sc->sc_maps[0].t;
288 h = sc->sc_maps[0].h;
290 sc->clearirq = elsa_isdnmc_clrirq;
292 sc->readreg = elsa_isdnmc_read_reg;
293 sc->writereg = elsa_isdnmc_write_reg;
295 sc->readfifo = elsa_isdnmc_read_fifo;
296 sc->writefifo = elsa_isdnmc_write_fifo;
298 /* setup IOM bus type */
300 sc->sc_bustyp = BUS_TYPE_IOM2;
302 sc->sc_ipac = 0;
303 sc->sc_bfifolen = HSCX_FIFO_LEN;
305 return 1;
307 #endif
309 #endif /* ISICPCMCIA_ELSA_ISDNMC */