Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / net / i4b / layer1 / isic / i4b_ctx_s0P.c
1 /*
2  * Copyright (c) 1997, 2001 Hellmuth Michaelis. 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  * 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.
12  *
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
23  * SUCH DAMAGE.
24  *
25  *---------------------------------------------------------------------------
26  *
27  *      isic - I4B Siemens ISDN Chipset Driver for Creatix/Teles PnP
28  *      ============================================================
29  *
30  * $FreeBSD: src/sys/i4b/layer1/isic/i4b_ctx_s0P.c,v 1.5.2.2 2001/12/10 12:18:11 hm Exp $
31  * $DragonFly: src/sys/net/i4b/layer1/isic/i4b_ctx_s0P.c,v 1.2 2003/06/17 04:28:40 dillon Exp $
32  *
33  *      last edit-date: [Wed Jan 24 09:07:22 2001]
34  *
35  *      Note: this driver works for the Creatix ISDN S0-16 P+P and
36  *            for the Teles S0/16.3 PnP card. Although they are not
37  *            the same hardware and don't share the same PnP config
38  *            information, once the base addresses are set, the
39  *            offsets are same and therefore they can use the same
40  *            driver.
41  *
42  *---------------------------------------------------------------------------*/
43
44 #include "isic.h"
45 #include "opt_i4b.h"
46
47 #if (NISIC > 0) && (defined(CRTX_S0_P) || defined(TEL_S0_16_3_P) || defined(COMPAQ_M610))
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/socket.h>
52 #include <net/if.h>
53
54 #include <machine/i4b_ioctl.h>
55 #include <machine/i4b_trace.h>
56
57 #include <i4b/layer1/i4b_l1.h>
58 #include <i4b/layer1/isic/i4b_isic.h>
59 #include <i4b/layer1/isic/i4b_hscx.h>
60
61 /*---------------------------------------------------------------------------*
62  *      Creatix / Teles PnP ISAC get fifo routine
63  *---------------------------------------------------------------------------*/
64 static void
65 ctxs0P_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
66 {
67         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[what+2]);
68         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+2]);
69         bus_space_read_multi_1(t,h,0x3e,buf,size);
70 }
71
72 /*---------------------------------------------------------------------------*
73  *      Creatix / Teles PnP ISAC put fifo routine
74  *---------------------------------------------------------------------------*/
75 static void
76 ctxs0P_write_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
77 {
78         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[what+2]);
79         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+2]);
80         bus_space_write_multi_1(t,h,0x3e,buf,size);
81 }
82
83 /*---------------------------------------------------------------------------*
84  *      Creatix / Teles PnP ISAC put register routine
85  *---------------------------------------------------------------------------*/
86 static void
87 ctxs0P_write_reg(struct l1_softc *sc, int what, bus_size_t offs, u_int8_t data)
88 {
89         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[what+2]);
90         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+2]);
91         bus_space_write_1(t,h,offs,data);
92 }
93
94 /*---------------------------------------------------------------------------*
95  *      Creatix / Teles PnP ISAC get register routine
96  *---------------------------------------------------------------------------*/
97 static u_int8_t
98 ctxs0P_read_reg(struct l1_softc *sc, int what, bus_size_t offs)
99 {
100         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[what+2]);
101         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+2]);
102         return bus_space_read_1(t,h,offs);
103 }
104
105 /*---------------------------------------------------------------------------*
106  *      isic_attach_Cs0P - attach Creatix / Teles PnP
107  *---------------------------------------------------------------------------*/
108 int
109 isic_attach_Cs0P(device_t dev)
110 {
111         u_int32_t iobase1;
112         u_int32_t iobase2;
113         u_int32_t iocfg;
114         int unit = device_get_unit(dev);
115         struct l1_softc *sc = &l1_sc[unit];     
116         bus_space_tag_t t;
117         bus_space_handle_t h;
118
119         /*
120          * this card needs a second io_base,
121          * free resources if we don't get it
122          */
123
124         sc->sc_resources.io_rid[1] = 1;
125         
126         if(!(sc->sc_resources.io_base[1] =
127                         bus_alloc_resource(dev, SYS_RES_IOPORT,
128                                         &sc->sc_resources.io_rid[1],
129                                         0UL, ~0UL, 1, RF_ACTIVE)))
130         {
131                 printf("isic%d: Could not get io area 1 for Creatix / Teles PnP!\n", unit);
132                 isic_detach_common(dev);
133                 return ENXIO;
134         }
135
136         /*
137          * Compaq M610 has a cfg io area,
138          * we need it
139          */
140
141         if (sc->sc_cardtyp == CARD_TYPEP_COMPAQ_M610)
142         {
143                 sc->sc_resources.io_rid[2] = 2;
144         
145                 if(!(sc->sc_resources.io_base[2] =
146                                 bus_alloc_resource(dev, SYS_RES_IOPORT,
147                                                 &sc->sc_resources.io_rid[2],
148                                                 0UL, ~0UL, 1, RF_ACTIVE)))
149                 {
150                         printf("isic%d: Could not get cfg io area for Compaq Microcom 610\n", unit);
151                         isic_detach_common(dev);
152                         return ENXIO;
153                 }
154
155                 iocfg = rman_get_start(sc->sc_resources.io_base[2]);
156
157                 bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_resources.io_rid[2],
158                                 sc->sc_resources.io_base[2]);
159         }
160
161         /* remember the io base addresses */
162         
163         if (sc->sc_cardtyp != CARD_TYPEP_COMPAQ_M610)
164         {
165                 iobase1 = rman_get_start(sc->sc_resources.io_base[0]);
166                 iobase2 = rman_get_start(sc->sc_resources.io_base[1]);
167         }
168         else
169         {
170                 iobase1 = rman_get_start(sc->sc_resources.io_base[1]);
171                 iobase2 = rman_get_start(sc->sc_resources.io_base[0]);
172         }
173
174         /*
175          * because overlapping resources are invalid,
176          * release the first and second io port resource
177          */
178         
179         bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_resources.io_rid[0],
180                         sc->sc_resources.io_base[0]);
181         
182         bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_resources.io_rid[1],
183                         sc->sc_resources.io_base[1]);
184
185         /* set and allocate a base io address for the ISAC chip */
186         
187         sc->sc_resources.io_rid[2] = 2;
188         
189         bus_set_resource(dev, SYS_RES_IOPORT, 2, iobase1-0x20, 0x40);
190
191         if(!(sc->sc_resources.io_base[2] =
192                 bus_alloc_resource(dev, SYS_RES_IOPORT,
193                                    &sc->sc_resources.io_rid[2],
194                                    0ul, ~0ul, 1, RF_ACTIVE)))
195         {
196                 printf("isic%d: Could not get io area 2 for Creatix / Teles PnP!\n", unit);
197                 isic_detach_common(dev);
198                 return ENXIO;
199         }
200
201
202         /* set and allocate a resource for the HSCX channel A */
203         
204         sc->sc_resources.io_rid[3] = 3;
205
206 /*XXX*/ /* FIXME !!!!
207          * the width of the resource is too small, there are accesses
208          * to it with an offset of 0x3e into the next resource. anyway,
209          * it seems to work and i have no idea how to do 2 resources
210          * overlapping each other.
211          */
212
213 #if 0
214         bus_set_resource(dev, SYS_RES_IOPORT, 3, iobase2-0x20, 0x20);
215 #else
216         bus_set_resource(dev, SYS_RES_IOPORT, 3, iobase2-0x20, 0x10);
217 #endif
218
219         if(!(sc->sc_resources.io_base[3] =
220                 bus_alloc_resource(dev,SYS_RES_IOPORT,
221                                    &sc->sc_resources.io_rid[3],
222                                    0ul,~0ul, 1, RF_ACTIVE)))
223         {
224                 printf("isic%d: Could not get io area 3 for Creatix / Teles PnP!\n", unit);
225                 isic_detach_common(dev);
226                 return ENXIO;
227         }
228
229         /* set and allocate a resources for the HSCX channel B */
230         
231         sc->sc_resources.io_rid[4] = 4;
232         
233         bus_set_resource(dev, SYS_RES_IOPORT, 4, iobase2, 0x40);
234
235         if(!(sc->sc_resources.io_base[4] =
236                 bus_alloc_resource(dev,SYS_RES_IOPORT,
237                                    &sc->sc_resources.io_rid[4],
238                                    0ul, ~0ul, 1, RF_ACTIVE)))
239         {
240                 printf("isic%d: Could not get io area 4 for Creatix / Teles PnP!\n", unit);
241                 isic_detach_common(dev);
242                 return ENXIO;
243         }
244
245         /*
246          * set and allocate a resource for the cfg io
247          * for compaq m610
248          */
249
250         if (sc->sc_cardtyp == CARD_TYPEP_COMPAQ_M610)
251         {
252                 sc->sc_resources.io_rid[5] = 5;
253
254                 bus_set_resource(dev, SYS_RES_IOPORT, 5, iocfg, 0x01);
255
256                 if(!(sc->sc_resources.io_base[5] =
257                         bus_alloc_resource(dev,SYS_RES_IOPORT,
258                                            &sc->sc_resources.io_rid[5],
259                                            0ul, ~0ul, 1, RF_ACTIVE)))
260                 {
261                         printf("isic%d: Could not get cfg io area for Compaq Microcom 610!\n", unit);
262                         isic_detach_common(dev);
263                         return ENXIO;
264                 }
265         }
266
267         /* setup access routines */
268
269         sc->clearirq = NULL;
270         sc->readreg = ctxs0P_read_reg;
271         sc->writereg = ctxs0P_write_reg;
272
273         sc->readfifo = ctxs0P_read_fifo;
274         sc->writefifo = ctxs0P_write_fifo;
275
276         /* setup card type */
277
278         if (sc->sc_cardtyp != CARD_TYPEP_COMPAQ_M610)
279                 sc->sc_cardtyp = CARD_TYPEP_CS0P;
280
281         /* setup IOM bus type */
282         
283         sc->sc_bustyp = BUS_TYPE_IOM2;
284
285         sc->sc_ipac = 0;
286         sc->sc_bfifolen = HSCX_FIFO_LEN;
287
288         /* enable the card */
289         
290         if (sc->sc_cardtyp != CARD_TYPEP_COMPAQ_M610)
291         {
292                 t = rman_get_bustag(sc->sc_resources.io_base[2]);
293                 h = rman_get_bushandle(sc->sc_resources.io_base[2]);
294         
295                 bus_space_write_1(t, h, 0x3c, 0);
296                 DELAY(SEC_DELAY / 10);
297
298                 bus_space_write_1(t, h, 0x3c, 1);
299                 DELAY(SEC_DELAY / 10);
300         }
301         else
302         {
303                 t = rman_get_bustag(sc->sc_resources.io_base[5]);
304                 h = rman_get_bushandle(sc->sc_resources.io_base[5]);
305
306                 bus_space_write_1(t, h, 0xff, 0);
307                 DELAY(SEC_DELAY / 10);
308
309                 bus_space_write_1(t, h, 0x00, 1);
310                 DELAY(SEC_DELAY / 10);
311         }
312
313         return 0;
314 }
315
316 #endif /* (NISIC > 0) && (defined(CRTX_S0_P) || defined(TEL_S0_16_3_P) || defined(COMPAQ_M610)) */
317