1 /* $NetBSD: isic_supio.c,v 1.16 2005/12/11 12:16:28 christos Exp $ */
4 * Copyright (c) 1998,2001 Ignatios Souvatzis. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the author nor the names of any co-contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 * 4. Altered versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software and/or documentation.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 *---------------------------------------------------------------------------
35 * isic_supio.c - Amiga supio pseudo bus frontend for i4b_isic driver
37 * - VMC ISDN Blaster 5001/1
38 * - ITH ISDN MasterII 5000/1
39 * - BSC ISDN Master 2092/64
40 * - Individual ISDN Surfer 4626/5
41 * - Zeus ISDN Link 2189/3
43 * But we attach to the supio, so just see "isicxx"
45 * -is original implementation [Sun Feb 14 10:29:19 1999]
47 *---------------------------------------------------------------------------*/
49 #include <sys/cdefs.h>
50 __KERNEL_RCSID(0, "$NetBSD: isic_supio.c,v 1.16 2005/12/11 12:16:28 christos Exp $");
52 #include <sys/types.h>
53 #include <sys/param.h>
54 #include <sys/errno.h>
55 #include <sys/syslog.h>
56 #include <sys/device.h>
57 #include <sys/socket.h>
59 #include <sys/systm.h>
60 #include <sys/malloc.h>
62 #include <machine/cpu.h>
63 #include <machine/intr.h>
64 #include <machine/bus.h>
66 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
67 #include <sys/callout.h>
70 #include <amiga/dev/supio.h>
72 #include <netisdn/i4b_ioctl.h>
73 #include <netisdn/i4b_trace.h>
74 #include <netisdn/i4b_global.h>
75 #include <netisdn/i4b_debug.h>
76 #include <netisdn/i4b_l2.h>
77 #include <netisdn/i4b_l1l2.h>
78 #include <dev/ic/isic_l1.h>
79 #include <dev/ic/hscx.h>
80 #include <dev/ic/isac.h>
82 /* XXX I think the following line should be elsewhere ... -is */
83 extern const struct isdn_layer1_isdnif_driver isic_std_driver
;
85 /*static*/ int isic_supio_match(struct device
*, struct cfdata
*, void *);
86 /*static*/ void isic_supio_attach(struct device
*, struct device
*, void *);
88 /*static*/ u_int8_t
aster_read_reg(struct isic_softc
*sc
, int what
,
90 /*static*/ void aster_write_reg(struct isic_softc
*sc
, int what
,
91 bus_size_t offs
, u_int8_t data
);
92 /*static*/ void aster_read_fifo(struct isic_softc
*sc
, int what
,
93 void *buf
, size_t size
);
94 /*static*/ void aster_write_fifo(struct isic_softc
*sc
, int what
,
95 const void *data
, size_t size
);
97 static int supio_isicattach(struct isic_softc
*sc
, const char *);
99 struct isic_supio_softc
{
100 struct isic_softc sc_isic
;
102 struct bus_space_tag sc_bst
;
105 CFATTACH_DECL(isic_supio
, sizeof(struct isic_supio_softc
),
106 isic_supio_match
, isic_supio_attach
, NULL
, NULL
);
112 isic_supio_match(struct device
*parent
, struct cfdata
*cf
, void *aux
)
114 struct supio_attach_args
*sap
= aux
;
117 return (!strncmp("isic", sap
->supio_name
, 4));
120 int isic_supio_ipl
= 2;
125 isic_supio_attach(struct device
*parent
, struct device
*self
, void *aux
)
127 struct isic_supio_softc
*ssc
= (void *)self
;
128 struct isic_softc
*sc
= &ssc
->sc_isic
;
129 struct supio_attach_args
*sap
= aux
;
132 bus_space_handle_t h
;
136 /* setup parameters */
137 sc
->sc_cardtyp
= CARD_TYPEP_BLMASTER
;
138 sc
->sc_num_mappings
= 3;
140 /* create io mappings */
143 o1
= (sap
->supio_name
[4]-'0') << 7;
144 o2
= (sap
->supio_name
[5]-'0') << 7;
146 bst
= sap
->supio_iot
;
147 bus_space_map(bst
, sap
->supio_iobase
, 0x1000, 0, &h
);
150 sc
->sc_maps
[0].t
= bst
;
151 sc
->sc_maps
[0].h
= h
;
152 sc
->sc_maps
[0].offset
= o1
;
153 sc
->sc_maps
[0].size
= 0; /* foreign mapping, leave it alone */
156 sc
->sc_maps
[1].t
= bst
;
157 sc
->sc_maps
[1].h
= h
;
158 sc
->sc_maps
[1].offset
= o2
;
159 sc
->sc_maps
[1].size
= 0; /* foreign mapping, leave it alone */
162 sc
->sc_maps
[2].t
= bst
;
163 sc
->sc_maps
[2].h
= h
;
164 sc
->sc_maps
[2].offset
= o2
+ 0x40;
165 sc
->sc_maps
[2].size
= 0; /* foreign mapping, leave it alone */
168 sc
->readreg
= aster_read_reg
;
169 sc
->writereg
= aster_write_reg
;
170 sc
->readfifo
= aster_read_fifo
;
171 sc
->writefifo
= aster_write_fifo
;
173 /* setup card type */
174 sc
->sc_cardtyp
= CARD_TYPEP_BLMASTER
;
175 sc
->sc_bustyp
= BUS_TYPE_IOM2
;
178 sc
->sc_bfifolen
= HSCX_FIFO_LEN
;
180 /* enable RTS on HSCX A */
181 aster_write_reg(sc
, ISIC_WHAT_HSCXA
, H_MODE
, HSCX_MODE_RTS
);
183 /* MI initialization of card */
186 supio_isicattach(sc
, sap
->supio_name
+6);
188 ssc
->sc_isr
.isr_intr
= isicintr
;
189 ssc
->sc_isr
.isr_arg
= sc
;
190 ssc
->sc_isr
.isr_ipl
= isic_supio_ipl
; /* XXX */
191 add_isr(&ssc
->sc_isr
);
195 aster_read_fifo(struct isic_softc
*sc
, int what
, void *buf
, size_t size
)
197 bus_space_tag_t t
= sc
->sc_maps
[what
].t
;
198 bus_space_handle_t h
= sc
->sc_maps
[what
].h
;
199 bus_size_t o
= sc
->sc_maps
[what
].offset
;
201 bus_space_read_multi_1(t
, h
, o
, buf
, size
);
205 aster_write_fifo(struct isic_softc
*sc
, int what
, const void *buf
, size_t size
)
207 bus_space_tag_t t
= sc
->sc_maps
[what
].t
;
208 bus_space_handle_t h
= sc
->sc_maps
[what
].h
;
209 bus_size_t o
= sc
->sc_maps
[what
].offset
;
211 bus_space_write_multi_1(t
, h
, o
, (const u_int8_t
*)buf
, size
);
215 aster_read_reg(struct isic_softc
*sc
, int what
, bus_size_t offs
)
217 bus_space_tag_t t
= sc
->sc_maps
[what
].t
;
218 bus_space_handle_t h
= sc
->sc_maps
[what
].h
;
219 bus_size_t o
= sc
->sc_maps
[what
].offset
;
221 return bus_space_read_1(t
, h
, o
+ offs
);
225 aster_write_reg(struct isic_softc
*sc
, int what
, bus_size_t offs
, u_int8_t data
)
227 bus_space_tag_t t
= sc
->sc_maps
[what
].t
;
228 bus_space_handle_t h
= sc
->sc_maps
[what
].h
;
229 bus_size_t o
= sc
->sc_maps
[what
].offset
;
231 bus_space_write_1(t
, h
, o
+ offs
, data
);
234 /*---------------------------------------------------------------------------*
235 * card independend attach for pcmcia^Wsupio cards
236 * XXX this should be centralized!
237 *---------------------------------------------------------------------------*/
240 * parameter and format for message producing e.g. "isic0: "
241 * there is no FreeBSD/Amiga, so just:
244 #define ISIC_FMT "%s: "
245 #define ISIC_PARM sc->sc_dev.dv_xname
249 supio_isicattach(struct isic_softc
*sc
, const char *cardname
)
251 static const char *ISACversion
[] = {
252 "2085 Version A1/A2 or 2086/2186 Version 1.1",
255 "2085 Version V2.3 (B3)",
259 static const char *HSCXversion
[] = {
265 "82525 or 21525 Version 2.1",
269 sc
->sc_isac_version
= 0;
270 sc
->sc_isac_version
= ((ISAC_READ(I_RBCH
)) >> 5) & 0x03;
272 switch(sc
->sc_isac_version
)
281 printf(ISIC_FMT
"Error, ISAC version %d unknown!\n",
282 ISIC_PARM
, sc
->sc_isac_version
);
287 sc
->sc_hscx_version
= HSCX_READ(0, H_VSTR
) & 0xf;
289 switch(sc
->sc_hscx_version
)
298 printf(ISIC_FMT
"Error, HSCX version %d unknown!\n",
299 ISIC_PARM
, sc
->sc_hscx_version
);
310 isic_bchannel_setup(sc
, HSCX_CH_A
, BPROT_NONE
, 0);
311 isic_bchannel_setup(sc
, HSCX_CH_B
, BPROT_NONE
, 0);
315 isic_init_linktab(sc
);
317 /* set trace level */
319 sc
->sc_trace
= TRACE_OFF
;
321 sc
->sc_state
= ISAC_IDLE
;
333 sc
->sc_freeflag2
= 0;
335 #if defined(__FreeBSD__) && __FreeBSD__ >=3
336 callout_handle_init(&sc
->sc_T3_callout
);
337 callout_handle_init(&sc
->sc_T4_callout
);
340 /* init higher protocol layers */
342 /* MPH_Status_Ind(sc->sc_unit, STI_ATTACH, sc->sc_cardtyp); */
343 isic_attach_bri(sc
, cardname
, &isic_std_driver
);
345 /* announce chip versions */
347 if(sc
->sc_isac_version
>= ISAC_UNKN
)
349 printf(ISIC_FMT
"ISAC Version UNKNOWN (VN=0x%x)" TERMFMT
,
351 sc
->sc_isac_version
);
352 sc
->sc_isac_version
= ISAC_UNKN
;
356 printf(ISIC_FMT
"ISAC %s (IOM-%c)" TERMFMT
,
358 ISACversion
[sc
->sc_isac_version
],
359 sc
->sc_bustyp
== BUS_TYPE_IOM1
? '1' : '2');
362 if(sc
->sc_hscx_version
>= HSCX_UNKN
)
364 printf(ISIC_FMT
"HSCX Version UNKNOWN (VN=0x%x)" TERMFMT
,
366 sc
->sc_hscx_version
);
367 sc
->sc_hscx_version
= HSCX_UNKN
;
371 printf(ISIC_FMT
"HSCX %s" TERMFMT
,
373 HSCXversion
[sc
->sc_hscx_version
]);