2 * Copyright (c) 2002 The NetBSD Foundation, Inc.
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
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>
40 #include <sys/ioctl.h>
42 #include <sys/kernel.h>
43 #include <sys/systm.h>
47 #include <machine/clock.h>
48 #include <i386/isa/isa_device.h>
51 #include <sys/device.h>
54 #include <sys/socket.h>
57 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
58 #include <sys/callout.h>
62 #include <machine/i4b_debug.h>
63 #include <machine/i4b_ioctl.h>
65 #include <netisdn/i4b_debug.h>
66 #include <netisdn/i4b_ioctl.h>
68 #include <dev/pcmcia/pcmciareg.h>
69 #include <dev/pcmcia/pcmciavar.h>
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>
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
);
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 */
102 elsa_isdnmc_clrirq(void *base
)
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
);
118 /*---------------------------------------------------------------------------*
120 *---------------------------------------------------------------------------*/
123 elsa_isdnmc_read_fifo(void *buf
, const void *base
, size_t len
)
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
;
134 bus_space_write_1(t
, h
, ADDR_LATCH
, 0);
135 bus_space_read_multi_1(t
, h
, ISAC_DATA
, buf
, size
);
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
);
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
);
149 /*---------------------------------------------------------------------------*
150 * write fifo routines
151 *---------------------------------------------------------------------------*/
154 elsa_isdnmc_write_fifo(void *base
, const void *buf
, size_t len
)
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
;
165 bus_space_write_1(t
, h
, ADDR_LATCH
, 0);
166 bus_space_write_multi_1(t
, h
, ISAC_DATA
, buf
, size
);
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
);
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
);
180 /*---------------------------------------------------------------------------*
181 * write register routines
182 *---------------------------------------------------------------------------*/
185 elsa_isdnmc_write_reg(u_char
*base
, u_int offset
, u_int v
)
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
;
196 bus_space_write_1(t
, h
, ADDR_LATCH
, offs
);
197 bus_space_write_1(t
, h
, ISAC_DATA
, data
);
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
);
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
);
211 /*---------------------------------------------------------------------------*
212 * read register routines
213 *---------------------------------------------------------------------------*/
216 elsa_isdnmc_read_reg(u_char
*base
, u_int offset
)
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
;
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
);
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
;
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",
260 if (cfe
->num_iospace
!= 1)
261 printf(": unexpected number of memory spaces %d should be 1\n",
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");
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");
277 /* Setup bus space maps */
278 sc
->sc_num_mappings
= 1;
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
;
303 sc
->sc_bfifolen
= HSCX_FIFO_LEN
;
309 #endif /* ISICPCMCIA_ELSA_ISDNMC */