2 * Copyright (c) 1998 Ignatios Souvatzis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 * 4. Altered versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software and/or documentation.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 *---------------------------------------------------------------------------
33 * isic_supio.c - Amiga supio pseudo bus frontend for i4b_isic driver
35 * - ISDN Blaster 5001/1
36 * - ISDN MasterII 5000/1
37 * - ISDN Master 2092/64
38 * But we attach to the supio, so just see "isic" or "isicII".
39 * -----------------------------------------------------------
43 * last edit-date: [Mon Mar 22 22:49:20 MET 1999]
45 * -is ISDN Master II support added.
46 * -is original implementation [Sun Feb 14 10:29:19 1999]
48 *---------------------------------------------------------------------------*/
50 #include <sys/types.h>
51 #include <sys/param.h>
52 #include <sys/errno.h>
53 #include <sys/syslog.h>
54 #include <sys/device.h>
55 #include <sys/socket.h>
57 #include <sys/systm.h>
58 #include <sys/malloc.h>
60 #include <machine/cpu.h>
61 #include <machine/intr.h>
62 #include <machine/bus.h>
64 #include <amiga/dev/supio.h>
66 #include <i4b/i4b_ioctl.h>
67 #include <i4b/i4b_trace.h>
68 #include <i4b/include/i4b_global.h>
69 #include <i4b/include/i4b_l1l2.h>
70 #include <i4b/layer1/i4b_l1.h>
71 #include <i4b/layer1/i4b_hscx.h>
72 #include <i4b/layer1/i4b_isac.h>
74 /*static*/ int isic_supio_match __P((struct device *, struct cfdata *, void *));
75 /*static*/ void isic_supio_attach __P((struct device *, struct device *, void *));
77 /*static*/ u_int8_t aster_read_reg __P((struct isic_softc *sc, int what,
79 /*static*/ void aster_write_reg __P((struct isic_softc *sc, int what,
80 bus_size_t offs, u_int8_t data));
81 /*static*/ void aster_read_fifo __P((struct isic_softc *sc, int what,
82 void *buf, size_t size));
83 /*static*/ void aster_write_fifo __P((struct isic_softc *sc, int what,
84 const void *data, size_t size));
86 static int supio_isicattach __P((struct isic_softc *sc));
88 struct isic_supio_softc {
89 struct isic_softc sc_isic;
91 struct bus_space_tag sc_bst;
94 struct cfattach isic_supio_ca = {
95 sizeof(struct isic_supio_softc), isic_supio_match, isic_supio_attach
102 isic_supio_match(parent, cf, aux)
103 struct device *parent;
107 struct supio_attach_args *sap = aux;
110 return (!strcmp("isic", sap->supio_name) ||
111 !strcmp("isicII", sap->supio_name));
114 int isic_supio_ipl = 2;
119 isic_supio_attach(parent, self, aux)
120 struct device *parent, *self;
123 struct isic_supio_softc *ssc = (void *)self;
124 struct isic_softc *sc = &ssc->sc_isic;
125 struct supio_attach_args *sap = aux;
128 bus_space_handle_t h;
132 /* setup parameters */
133 sc->sc_cardtyp = CARD_TYPEP_BLMASTER;
134 sc->sc_num_mappings = 3;
135 sc->sc_unit = sc->sc_dev.dv_unit; /* XXX ??? */
137 /* create io mappings */
140 if (!strcmp(sap->supio_name, "isic")) {
143 } else /* "isic-II" */ {
147 bst = sap->supio_iot;
148 bus_space_map(bst, sap->supio_iobase, 0x400, 0, &h);
151 sc->sc_maps[0].t = bst;
152 sc->sc_maps[0].h = h;
153 sc->sc_maps[0].offset = o1/2;
154 sc->sc_maps[0].size = 0; /* foreign mapping, leave it alone */
157 sc->sc_maps[1].t = bst;
158 sc->sc_maps[1].h = h;
159 sc->sc_maps[1].offset = o2/2;
160 sc->sc_maps[1].size = 0; /* foreign mapping, leave it alone */
163 sc->sc_maps[2].t = bst;
164 sc->sc_maps[2].h = h;
165 sc->sc_maps[2].offset = (o2 + 0x80)/2;
166 sc->sc_maps[2].size = 0; /* foreign mapping, leave it alone */
169 sc->readreg = aster_read_reg;
170 sc->writereg = aster_write_reg;
171 sc->readfifo = aster_read_fifo;
172 sc->writefifo = aster_write_fifo;
174 /* setup card type */
175 sc->sc_cardtyp = CARD_TYPEP_BLMASTER;
176 sc->sc_bustyp = BUS_TYPE_IOM2;
179 sc->sc_bfifolen = HSCX_FIFO_LEN;
181 /* enable RTS on HSCX A */
182 aster_write_reg(sc, ISIC_WHAT_HSCXA, H_MODE, HSCX_MODE_RTS);
184 /* MI initialization of card */
187 supio_isicattach(sc);
189 ssc->sc_isr.isr_intr = isicintr;
190 ssc->sc_isr.isr_arg = sc;
191 ssc->sc_isr.isr_ipl = isic_supio_ipl; /* XXX */
192 add_isr(&ssc->sc_isr);
200 /* XXX should test whether it is our interupt at all */
201 add_sicallback((sifunc_t)isicintr, p, NULL);
207 aster_read_fifo(struct isic_softc *sc, int what, void *buf, size_t size)
209 bus_space_tag_t t = sc->sc_maps[what].t;
210 bus_space_handle_t h = sc->sc_maps[what].h;
211 bus_size_t o = sc->sc_maps[what].offset;
213 bus_space_read_multi_1(t, h, o, buf, size);
217 aster_write_fifo(struct isic_softc *sc, int what, const void *buf, size_t size)
219 bus_space_tag_t t = sc->sc_maps[what].t;
220 bus_space_handle_t h = sc->sc_maps[what].h;
221 bus_size_t o = sc->sc_maps[what].offset;
223 bus_space_write_multi_1(t, h, o, (u_int8_t*)buf, size);
227 aster_read_reg(struct isic_softc *sc, int what, bus_size_t offs)
229 bus_space_tag_t t = sc->sc_maps[what].t;
230 bus_space_handle_t h = sc->sc_maps[what].h;
231 bus_size_t o = sc->sc_maps[what].offset;
233 return bus_space_read_1(t, h, o + offs);
237 aster_write_reg(struct isic_softc *sc, int what, bus_size_t offs, u_int8_t data)
239 bus_space_tag_t t = sc->sc_maps[what].t;
240 bus_space_handle_t h = sc->sc_maps[what].h;
241 bus_size_t o = sc->sc_maps[what].offset;
243 bus_space_write_1(t, h, o + offs, data);
246 /*---------------------------------------------------------------------------*
247 * card independend attach for pcmcia^Wsupio cards
248 * XXX this should be centralized!
249 *---------------------------------------------------------------------------*/
252 * parameter and format for message producing e.g. "isic0: "
253 * there is no FreeBSD/Amiga, so just:
256 #define ISIC_FMT "%s: "
257 #define ISIC_PARM sc->sc_dev.dv_xname
261 supio_isicattach(struct isic_softc *sc)
263 static char *ISACversion[] = {
264 "2085 Version A1/A2 or 2086/2186 Version 1.1",
267 "2085 Version V2.3 (B3)",
271 static char *HSCXversion[] = {
277 "82525 or 21525 Version 2.1",
281 isic_sc[sc->sc_unit] = sc;
282 sc->sc_isac_version = 0;
283 sc->sc_isac_version = ((ISAC_READ(I_RBCH)) >> 5) & 0x03;
285 switch(sc->sc_isac_version)
294 printf(ISIC_FMT "Error, ISAC version %d unknown!\n",
295 ISIC_PARM, sc->sc_isac_version);
300 sc->sc_hscx_version = HSCX_READ(0, H_VSTR) & 0xf;
302 switch(sc->sc_hscx_version)
311 printf(ISIC_FMT "Error, HSCX version %d unknown!\n",
312 ISIC_PARM, sc->sc_hscx_version);
323 isic_bchannel_setup(sc->sc_unit, HSCX_CH_A, BPROT_NONE, 0);
325 isic_bchannel_setup(sc->sc_unit, HSCX_CH_B, BPROT_NONE, 0);
329 isic_init_linktab(sc);
331 /* set trace level */
333 sc->sc_trace = TRACE_OFF;
335 sc->sc_state = ISAC_IDLE;
347 sc->sc_freeflag2 = 0;
349 /* init higher protocol layers */
351 MPH_Status_Ind(sc->sc_unit, STI_ATTACH, sc->sc_cardtyp);
353 /* announce chip versions */
355 if(sc->sc_isac_version >= ISAC_UNKN)
357 printf(ISIC_FMT "ISAC Version UNKNOWN (VN=0x%x)" TERMFMT,
359 sc->sc_isac_version);
360 sc->sc_isac_version = ISAC_UNKN;
364 printf(ISIC_FMT "ISAC %s (IOM-%c)" TERMFMT,
366 ISACversion[sc->sc_isac_version],
367 sc->sc_bustyp == BUS_TYPE_IOM1 ? '1' : '2');
370 if(sc->sc_hscx_version >= HSCX_UNKN)
372 printf(ISIC_FMT "HSCX Version UNKNOWN (VN=0x%x)" TERMFMT,
374 sc->sc_hscx_version);
375 sc->sc_hscx_version = HSCX_UNKN;
379 printf(ISIC_FMT "HSCX %s" TERMFMT,
381 HSCXversion[sc->sc_hscx_version]);