2 * Copyright (c) 2001 Cubical Solutions Ltd. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * capi/iavc/iavc_card.c
26 * The AVM ISDN controllers' card specific support routines.
28 * $FreeBSD: src/sys/i4b/capi/iavc/iavc_card.c,v 1.1.2.1 2001/08/10 14:08:34 obrien Exp $
29 * $DragonFly: src/sys/net/i4b/capi/iavc/iavc_card.c,v 1.5 2004/04/16 15:40:21 joerg Exp $
32 #include <sys/param.h>
33 #include <sys/kernel.h>
34 #include <sys/systm.h>
36 #include <sys/socket.h>
39 #include <machine/clock.h>
41 #include <machine/bus.h>
42 #include <machine/resource.h>
46 #include <net/i4b/include/machine/i4b_debug.h>
47 #include <net/i4b/include/machine/i4b_ioctl.h>
48 #include <net/i4b/include/machine/i4b_trace.h>
50 #include "../../include/i4b_global.h"
51 #include "../../include/i4b_l3l4.h"
52 #include "../../include/i4b_mbuf.h"
58 // AVM B1 (active BRI, PIO mode)
61 int b1_detect(iavc_softc_t *sc)
63 if ((iavc_read_port(sc, B1_INSTAT) & 0xfc) ||
64 (iavc_read_port(sc, B1_OUTSTAT) & 0xfc))
67 b1io_outp(sc, B1_INSTAT, 0x02);
68 b1io_outp(sc, B1_OUTSTAT, 0x02);
69 if ((iavc_read_port(sc, B1_INSTAT) & 0xfe) != 2 ||
70 (iavc_read_port(sc, B1_OUTSTAT) & 0xfe) != 2)
73 b1io_outp(sc, B1_INSTAT, 0x00);
74 b1io_outp(sc, B1_OUTSTAT, 0x00);
75 if ((iavc_read_port(sc, B1_INSTAT) & 0xfe) ||
76 (iavc_read_port(sc, B1_OUTSTAT) & 0xfe))
79 return (0); /* found */
82 void b1_disable_irq(iavc_softc_t *sc)
84 b1io_outp(sc, B1_INSTAT, 0x00);
87 void b1_reset(iavc_softc_t *sc)
89 b1io_outp(sc, B1_RESET, 0);
92 b1io_outp(sc, B1_RESET, 1);
95 b1io_outp(sc, B1_RESET, 0);
100 // Newer PCI-based B1's, and T1's, supports DMA
103 int b1dma_detect(iavc_softc_t *sc)
105 AMCC_WRITE(sc, AMCC_MCSR, 0);
107 AMCC_WRITE(sc, AMCC_MCSR, 0x0f000000);
109 AMCC_WRITE(sc, AMCC_MCSR, 0);
112 AMCC_WRITE(sc, AMCC_RXLEN, 0);
113 AMCC_WRITE(sc, AMCC_TXLEN, 0);
115 AMCC_WRITE(sc, AMCC_INTCSR, sc->sc_csr);
117 if (AMCC_READ(sc, AMCC_INTCSR) != 0)
120 AMCC_WRITE(sc, AMCC_RXPTR, 0xffffffff);
121 AMCC_WRITE(sc, AMCC_TXPTR, 0xffffffff);
122 if ((AMCC_READ(sc, AMCC_RXPTR) != 0xfffffffc) ||
123 (AMCC_READ(sc, AMCC_TXPTR) != 0xfffffffc))
126 AMCC_WRITE(sc, AMCC_RXPTR, 0);
127 AMCC_WRITE(sc, AMCC_TXPTR, 0);
128 if ((AMCC_READ(sc, AMCC_RXPTR) != 0) ||
129 (AMCC_READ(sc, AMCC_TXPTR) != 0))
132 iavc_write_port(sc, 0x10, 0x00);
133 iavc_write_port(sc, 0x07, 0x00);
135 iavc_write_port(sc, 0x02, 0x02);
136 iavc_write_port(sc, 0x03, 0x02);
138 if (((iavc_read_port(sc, 0x02) & 0xfe) != 0x02) ||
139 (iavc_read_port(sc, 0x03) != 0x03))
142 iavc_write_port(sc, 0x02, 0x00);
143 iavc_write_port(sc, 0x03, 0x00);
145 if (((iavc_read_port(sc, 0x02) & 0xfe) != 0x00) ||
146 (iavc_read_port(sc, 0x03) != 0x01))
149 return (0); /* found */
152 void b1dma_reset(iavc_softc_t *sc)
157 AMCC_WRITE(sc, AMCC_INTCSR, sc->sc_csr);
158 AMCC_WRITE(sc, AMCC_MCSR, 0);
159 AMCC_WRITE(sc, AMCC_RXLEN, 0);
160 AMCC_WRITE(sc, AMCC_TXLEN, 0);
162 iavc_write_port(sc, 0x10, 0x00); /* XXX magic numbers from */
163 iavc_write_port(sc, 0x07, 0x00); /* XXX the linux driver */
167 AMCC_WRITE(sc, AMCC_MCSR, 0);
169 AMCC_WRITE(sc, AMCC_MCSR, 0x0f000000);
171 AMCC_WRITE(sc, AMCC_MCSR, 0);
176 // AVM T1 (active PRI)
179 /* XXX how do these differ from b1io_{read,write}_reg()? XXX */
181 static int b1dma_tx_empty(int iobase)
182 { return inb(iobase + 3) & 1; }
184 static int b1dma_rx_full(int iobase)
185 { return inb(iobase + 2) & 1; }
187 static int b1dma_tolink(iavc_softc_t *sc, void *buf, int len)
190 char *s = (char*) buf;
193 while (!b1dma_tx_empty(sc->sc_iobase) && spin < 100000)
195 if (!b1dma_tx_empty(sc->sc_iobase))
197 t1io_outp(sc, 1, *s++);
202 static int b1dma_fromlink(iavc_softc_t *sc, void *buf, int len)
205 char *s = (char*) buf;
208 while (!b1dma_rx_full(sc->sc_iobase) && spin < 100000)
210 if (!b1dma_rx_full(sc->sc_iobase))
212 *s++ = t1io_inp(sc, 0);
217 static int WriteReg(iavc_softc_t *sc, u_int32_t reg, u_int8_t val)
220 if (b1dma_tolink(sc, &cmd, 1) == 0 &&
221 b1dma_tolink(sc, ®, 4) == 0) {
223 return b1dma_tolink(sc, &tmp, 4);
228 static u_int8_t ReadReg(iavc_softc_t *sc, u_int32_t reg)
231 if (b1dma_tolink(sc, &cmd, 1) == 0 &&
232 b1dma_tolink(sc, ®, 4) == 0) {
234 if (b1dma_fromlink(sc, &tmp, 4) == 0)
235 return (u_int8_t) tmp;
240 int t1_detect(iavc_softc_t *sc)
242 int ret = b1dma_detect(sc);
245 if ((WriteReg(sc, 0x80001000, 0x11) != 0) ||
246 (WriteReg(sc, 0x80101000, 0x22) != 0) ||
247 (WriteReg(sc, 0x80201000, 0x33) != 0) ||
248 (WriteReg(sc, 0x80301000, 0x44) != 0))
251 if ((ReadReg(sc, 0x80001000) != 0x11) ||
252 (ReadReg(sc, 0x80101000) != 0x22) ||
253 (ReadReg(sc, 0x80201000) != 0x33) ||
254 (ReadReg(sc, 0x80301000) != 0x44))
257 if ((WriteReg(sc, 0x80001000, 0x55) != 0) ||
258 (WriteReg(sc, 0x80101000, 0x66) != 0) ||
259 (WriteReg(sc, 0x80201000, 0x77) != 0) ||
260 (WriteReg(sc, 0x80301000, 0x88) != 0))
263 if ((ReadReg(sc, 0x80001000) != 0x55) ||
264 (ReadReg(sc, 0x80101000) != 0x66) ||
265 (ReadReg(sc, 0x80201000) != 0x77) ||
266 (ReadReg(sc, 0x80301000) != 0x88))
269 return 0; /* found */
272 void t1_disable_irq(iavc_softc_t *sc)
274 iavc_write_port(sc, T1_IRQMASTER, 0x00);
277 void t1_reset(iavc_softc_t *sc)
280 iavc_write_port(sc, B1_INSTAT, 0x00);
281 iavc_write_port(sc, B1_OUTSTAT, 0x00);
282 iavc_write_port(sc, T1_IRQMASTER, 0x00);
283 iavc_write_port(sc, T1_RESETBOARD, 0x0f);