]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i4b/layer1/isic_supio.c
This commit was generated by cvs2svn to compensate for changes in r63516,
[FreeBSD/FreeBSD.git] / sys / i4b / layer1 / isic_supio.c
1 /*
2  *   Copyright (c) 1998 Ignatios Souvatzis. All rights reserved.
3  *
4  *   Redistribution and use in source and binary forms, with or without
5  *   modification, are permitted provided that the following conditions
6  *   are met:
7  *
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.
18  *   
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
29  *   SUCH DAMAGE.
30  *
31  *---------------------------------------------------------------------------
32  *
33  *      isic_supio.c - Amiga supio pseudo bus frontend for i4b_isic driver
34  *      supports:
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  *      -----------------------------------------------------------
40  *
41  * $FreeBSD$ 
42  *
43  *      last edit-date: [Mon Mar 22 22:49:20 MET 1999]
44  *
45  *      -is     ISDN Master II support added.
46  *      -is     original implementation [Sun Feb 14 10:29:19 1999]
47  *
48  *---------------------------------------------------------------------------*/
49
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>
56 #include <net/if.h>
57 #include <sys/systm.h>
58 #include <sys/malloc.h>
59
60 #include <machine/cpu.h>
61 #include <machine/intr.h>
62 #include <machine/bus.h>
63
64 #include <amiga/dev/supio.h>
65
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>
73
74 /*static*/ int isic_supio_match __P((struct device *, struct cfdata *, void *));
75 /*static*/ void isic_supio_attach __P((struct device *, struct device *, void *));
76
77 /*static*/ u_int8_t aster_read_reg __P((struct isic_softc *sc, int what,
78         bus_size_t offs));
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));
85
86 static int supio_isicattach __P((struct isic_softc *sc));
87
88 struct isic_supio_softc {
89         struct isic_softc       sc_isic;
90         struct isr              sc_isr;
91         struct bus_space_tag    sc_bst;
92 };
93
94 struct cfattach isic_supio_ca = {
95         sizeof(struct isic_supio_softc), isic_supio_match, isic_supio_attach
96 };
97
98 /*
99  * Probe card
100  */
101 /*static*/ int
102 isic_supio_match(parent, cf, aux)
103         struct device *parent;
104         struct cfdata *cf;
105         void *aux;
106 {
107         struct supio_attach_args *sap = aux;
108
109         /* ARGSUSED */
110         return (!strcmp("isic", sap->supio_name) ||
111                 !strcmp("isicII", sap->supio_name));
112 }
113
114 int isic_supio_ipl = 2;
115 /*
116  * Attach the card
117  */
118 /*static*/ void
119 isic_supio_attach(parent, self, aux)
120         struct device *parent, *self;
121         void *aux;
122 {
123         struct isic_supio_softc *ssc = (void *)self;
124         struct isic_softc *sc = &ssc->sc_isic;
125         struct supio_attach_args *sap = aux;
126
127         bus_space_tag_t bst;
128         bus_space_handle_t h;
129
130         int o1, o2;
131
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 ??? */
136
137         /* create io mappings */
138         MALLOC_MAPS(sc);
139
140         if (!strcmp(sap->supio_name, "isic")) {
141                 o1 = 0x300;
142                 o2 = 0x100;
143         } else /* "isic-II" */ {
144                 o1 = 0x100;
145                 o2 = 0x300;
146         }
147         bst = sap->supio_iot;
148         bus_space_map(bst, sap->supio_iobase, 0x400, 0, &h);
149
150         /* ISAC */
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 */
155
156         /* HSCX A */
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 */
161
162         /* HSCX B */
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 */
167
168         sc->clearirq = NULL;
169         sc->readreg = aster_read_reg;
170         sc->writereg = aster_write_reg;
171         sc->readfifo = aster_read_fifo;
172         sc->writefifo = aster_write_fifo;
173
174         /* setup card type */
175         sc->sc_cardtyp = CARD_TYPEP_BLMASTER;
176         sc->sc_bustyp = BUS_TYPE_IOM2;
177
178         sc->sc_ipac = 0;
179         sc->sc_bfifolen = HSCX_FIFO_LEN;
180
181         /* enable RTS on HSCX A */
182         aster_write_reg(sc, ISIC_WHAT_HSCXA, H_MODE, HSCX_MODE_RTS);
183
184         /* MI initialization of card */
185
186        printf("\n");
187         supio_isicattach(sc);
188
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);
193 }
194
195 #if 0
196 int
197 isic_supiointr(p)
198         void *p;
199 {
200         /* XXX should test whether it is our interupt at all */
201         add_sicallback((sifunc_t)isicintr, p, NULL);
202         return 1;
203 }
204 #endif
205
206 /*static*/ void
207 aster_read_fifo(struct isic_softc *sc, int what, void *buf, size_t size)
208 {
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;
212
213         bus_space_read_multi_1(t, h, o, buf, size);
214 }
215
216 /*static*/ void
217 aster_write_fifo(struct isic_softc *sc, int what, const void *buf, size_t size)
218 {
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;
222
223         bus_space_write_multi_1(t, h, o, (u_int8_t*)buf, size);
224 }
225
226 /*static*/ u_int8_t
227 aster_read_reg(struct isic_softc *sc, int what, bus_size_t offs)
228 {
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;
232
233         return bus_space_read_1(t, h, o + offs);
234 }
235
236 /*static*/ void
237 aster_write_reg(struct isic_softc *sc, int what, bus_size_t offs, u_int8_t data) 
238 {
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;
242
243         bus_space_write_1(t, h, o + offs, data);
244 }
245
246 /*---------------------------------------------------------------------------*
247  *      card independend attach for pcmcia^Wsupio cards
248  *      XXX this should be centralized!
249  *---------------------------------------------------------------------------*/
250
251 /*
252  * parameter and format for message producing e.g. "isic0: "
253  * there is no FreeBSD/Amiga, so just: 
254  */
255
256 #define ISIC_FMT        "%s: "
257 #define ISIC_PARM       sc->sc_dev.dv_xname
258 #define TERMFMT "\n"
259
260 int
261 supio_isicattach(struct isic_softc *sc)
262 {
263         static char *ISACversion[] = {
264                 "2085 Version A1/A2 or 2086/2186 Version 1.1",
265                 "2085 Version B1",
266                 "2085 Version B2",
267                 "2085 Version V2.3 (B3)",
268                 "Unknown Version"
269         };
270
271         static char *HSCXversion[] = {
272                 "82525 Version A1",
273                 "Unknown (0x01)",
274                 "82525 Version A2",
275                 "Unknown (0x03)",
276                 "82525 Version A3",
277                 "82525 or 21525 Version 2.1",
278                 "Unknown Version"
279         };
280
281         isic_sc[sc->sc_unit] = sc;              
282         sc->sc_isac_version = 0;
283         sc->sc_isac_version = ((ISAC_READ(I_RBCH)) >> 5) & 0x03;
284
285         switch(sc->sc_isac_version)
286         {
287                 case ISAC_VA:
288                 case ISAC_VB1:
289                 case ISAC_VB2:
290                 case ISAC_VB3:
291                         break;
292
293                 default:
294                         printf(ISIC_FMT "Error, ISAC version %d unknown!\n",
295                                 ISIC_PARM, sc->sc_isac_version);
296                         return(0);
297                         break;
298         }
299
300         sc->sc_hscx_version = HSCX_READ(0, H_VSTR) & 0xf;
301
302         switch(sc->sc_hscx_version)
303         {
304                 case HSCX_VA1:
305                 case HSCX_VA2:
306                 case HSCX_VA3:
307                 case HSCX_V21:
308                         break;
309                         
310                 default:
311                         printf(ISIC_FMT "Error, HSCX version %d unknown!\n",
312                                 ISIC_PARM, sc->sc_hscx_version);
313                         return(0);
314                         break;
315         };
316
317         /* ISAC setup */
318         
319         isic_isac_init(sc);
320
321         /* HSCX setup */
322
323         isic_bchannel_setup(sc->sc_unit, HSCX_CH_A, BPROT_NONE, 0);
324         
325         isic_bchannel_setup(sc->sc_unit, HSCX_CH_B, BPROT_NONE, 0);
326
327         /* setup linktab */
328
329         isic_init_linktab(sc);
330
331         /* set trace level */
332
333         sc->sc_trace = TRACE_OFF;
334
335         sc->sc_state = ISAC_IDLE;
336
337         sc->sc_ibuf = NULL;
338         sc->sc_ib = NULL;
339         sc->sc_ilen = 0;
340
341         sc->sc_obuf = NULL;
342         sc->sc_op = NULL;
343         sc->sc_ol = 0;
344         sc->sc_freeflag = 0;
345
346         sc->sc_obuf2 = NULL;
347         sc->sc_freeflag2 = 0;
348
349         /* init higher protocol layers */
350         
351         MPH_Status_Ind(sc->sc_unit, STI_ATTACH, sc->sc_cardtyp);        
352
353         /* announce chip versions */
354         
355         if(sc->sc_isac_version >= ISAC_UNKN)
356         {
357                 printf(ISIC_FMT "ISAC Version UNKNOWN (VN=0x%x)" TERMFMT,
358                                 ISIC_PARM,
359                                 sc->sc_isac_version);
360                 sc->sc_isac_version = ISAC_UNKN;
361         }
362         else
363         {
364                 printf(ISIC_FMT "ISAC %s (IOM-%c)" TERMFMT,
365                                 ISIC_PARM,
366                                 ISACversion[sc->sc_isac_version],
367                                 sc->sc_bustyp == BUS_TYPE_IOM1 ? '1' : '2');
368         }
369
370         if(sc->sc_hscx_version >= HSCX_UNKN)
371         {
372                 printf(ISIC_FMT "HSCX Version UNKNOWN (VN=0x%x)" TERMFMT,
373                                 ISIC_PARM,
374                                 sc->sc_hscx_version);
375                 sc->sc_hscx_version = HSCX_UNKN;
376         }
377         else
378         {
379                 printf(ISIC_FMT "HSCX %s" TERMFMT,
380                                 ISIC_PARM,
381                                 HSCXversion[sc->sc_hscx_version]);
382         }
383
384         return(1);
385 }
386