]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i4b/layer1/i4b_ctx_s0P.c
This commit was generated by cvs2svn to compensate for changes in r63516,
[FreeBSD/FreeBSD.git] / sys / i4b / layer1 / i4b_ctx_s0P.c
1 /*
2  * Copyright (c) 1997, 1999 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  *      $Id: i4b_ctx_s0P.c,v 1.4 1999/12/13 21:25:26 hm Exp $ 
31  *
32  * $FreeBSD$
33  *
34  *      last edit-date: [Mon Dec 13 21:59:23 1999]
35  *
36  *      Note: this driver works for the Creatix ISDN S0-16 P+P and
37  *            for the Teles S0/16.3 PnP card. Although they are not
38  *            the same hardware and don't share the same PnP config
39  *            information, once the base addresses are set, the
40  *            offsets are same and therefore they can use the same
41  *            driver.
42  *
43  *---------------------------------------------------------------------------*/
44
45 #include "isic.h"
46 #include "opt_i4b.h"
47
48 #if (NISIC > 0) && (defined(CRTX_S0_P) || defined(TEL_S0_16_3_P))
49
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/mbuf.h>
53 #include <sys/socket.h>
54
55 #include <machine/clock.h>
56
57 #include <net/if.h>
58
59 #include <machine/i4b_debug.h>
60 #include <machine/i4b_ioctl.h>
61
62 #include <i4b/include/i4b_global.h>
63
64 #include <i4b/layer1/i4b_l1.h>
65 #include <i4b/layer1/i4b_isac.h>
66 #include <i4b/layer1/i4b_hscx.h>
67
68 #include <i4b/include/i4b_l1l2.h>
69 #include <i4b/include/i4b_mbuf.h>
70
71 /*---------------------------------------------------------------------------*
72  *      Creatix / Teles PnP ISAC get fifo routine
73  *---------------------------------------------------------------------------*/
74 static void
75 ctxs0P_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
76 {
77         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[what+2]);
78         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+2]);
79         bus_space_read_multi_1(t,h,0x3e,buf,size);
80 }
81
82 /*---------------------------------------------------------------------------*
83  *      Creatix / Teles PnP ISAC put fifo routine
84  *---------------------------------------------------------------------------*/
85 static void
86 ctxs0P_write_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
87 {
88         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[what+2]);
89         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+2]);
90         bus_space_write_multi_1(t,h,0x3e,buf,size);
91 }
92
93 /*---------------------------------------------------------------------------*
94  *      Creatix / Teles PnP ISAC put register routine
95  *---------------------------------------------------------------------------*/
96 static void
97 ctxs0P_write_reg(struct l1_softc *sc, int what, bus_size_t offs, u_int8_t data)
98 {
99         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[what+2]);
100         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+2]);
101         bus_space_write_1(t,h,offs,data);
102 }
103
104 /*---------------------------------------------------------------------------*
105  *      Creatix / Teles PnP ISAC get register routine
106  *---------------------------------------------------------------------------*/
107 static u_int8_t
108 ctxs0P_read_reg(struct l1_softc *sc, int what, bus_size_t offs)
109 {
110         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[what+2]);
111         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+2]);
112         return bus_space_read_1(t,h,offs);
113 }
114
115 /*---------------------------------------------------------------------------*
116  *      isic_attach_Cs0P - attach Creatix / Teles PnP
117  *---------------------------------------------------------------------------*/
118 int
119 isic_attach_Cs0P(device_t dev)
120 {
121         u_int32_t iobase1;
122         u_int32_t iobase2;
123         int unit = device_get_unit(dev);
124         struct l1_softc *sc = &l1_sc[unit];     
125         bus_space_tag_t t;
126         bus_space_handle_t h;
127
128         /*
129          * this card needs a second io_base,
130          * free resources if we don't get it
131          */
132
133         sc->sc_resources.io_rid[1] = 1;
134         
135         if(!(sc->sc_resources.io_base[1] =
136                         bus_alloc_resource(dev, SYS_RES_IOPORT,
137                                         &sc->sc_resources.io_rid[1],
138                                         0UL, ~0UL, 1, RF_ACTIVE)))
139         {
140                 printf("isic%d: Could not get io area 1 for Creatix / Teles PnP!\n", unit);
141                 isic_detach_common(dev);
142                 return ENXIO;
143         }
144
145         /* remember the io base addresses */
146         
147         iobase1 = rman_get_start(sc->sc_resources.io_base[0]);
148         iobase2 = rman_get_start(sc->sc_resources.io_base[1]);
149         
150         /*
151          * because overlapping resources are invalid,
152          * release the first io port resource
153          */
154         
155         bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_resources.io_rid[0],
156                         sc->sc_resources.io_base[0]);
157         
158         /* set and allocate a base io address for the ISAC chip */
159         
160         sc->sc_resources.io_rid[2] = 2;
161         
162         bus_set_resource(dev, SYS_RES_IOPORT, 2, iobase1-0x20, 0x40);
163         
164         if(!(sc->sc_resources.io_base[2] =
165                 bus_alloc_resource(dev, SYS_RES_IOPORT,
166                                    &sc->sc_resources.io_rid[2],
167                                    0ul, ~0ul, 1, RF_ACTIVE)))
168         {
169                 printf("isic%d: Could not get io area 2 for Creatix / Teles PnP!\n", unit);
170                 isic_detach_common(dev);
171                 return ENXIO;
172         }
173
174         /*
175          * because overlapping resources are invalid,
176          * release the second io port resource
177          */
178
179         bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_resources.io_rid[1],
180                         sc->sc_resources.io_base[1]);
181
182         /* set and allocate a resource for the HSCX channel A */
183         
184         sc->sc_resources.io_rid[3] = 3;
185
186 /*XXX*/ /* FIXME !!!!
187          * the width of the resource is too small, there are accesses
188          * to it with an offset of 0x3e into the next resource. anyway,
189          * it seems to work and i have no idea how to do 2 resources
190          * overlapping each other.
191          */
192
193         bus_set_resource(dev, SYS_RES_IOPORT, 3, iobase2-0x20, 0x20);
194
195         if(!(sc->sc_resources.io_base[3] =
196                 bus_alloc_resource(dev,SYS_RES_IOPORT,
197                                    &sc->sc_resources.io_rid[3],
198                                    0ul,~0ul, 1, RF_ACTIVE)))
199         {
200                 printf("isic%d: Could not get io area 3 for Creatix / Teles PnP!\n", unit);
201                 isic_detach_common(dev);
202                 return ENXIO;
203         }
204
205         /* set and allocate a resources for the HSCX channel B */
206         
207         sc->sc_resources.io_rid[4] = 4;
208         
209         bus_set_resource(dev, SYS_RES_IOPORT, 4, iobase2, 0x40);
210                                         
211         if(!(sc->sc_resources.io_base[4] =
212                 bus_alloc_resource(dev,SYS_RES_IOPORT,
213                                    &sc->sc_resources.io_rid[4],
214                                    0ul, ~0ul, 1, RF_ACTIVE)))
215         {
216                 printf("isic%d: Could not get io area 4 for Creatix / Teles PnP!\n", unit);
217                 isic_detach_common(dev);
218                 return ENXIO;
219         }
220         
221         /* setup access routines */
222
223         sc->clearirq = NULL;
224         sc->readreg = ctxs0P_read_reg;
225         sc->writereg = ctxs0P_write_reg;
226
227         sc->readfifo = ctxs0P_read_fifo;
228         sc->writefifo = ctxs0P_write_fifo;
229
230         /* setup card type */
231         
232         sc->sc_cardtyp = CARD_TYPEP_CS0P;
233
234         /* setup IOM bus type */
235         
236         sc->sc_bustyp = BUS_TYPE_IOM2;
237
238         sc->sc_ipac = 0;
239         sc->sc_bfifolen = HSCX_FIFO_LEN;
240
241         /* enable the card */
242         
243         t = rman_get_bustag(sc->sc_resources.io_base[2]);
244         h = rman_get_bushandle(sc->sc_resources.io_base[2]);
245         
246         bus_space_write_1(t, h, 0x3c, 0);
247         DELAY(SEC_DELAY / 10);
248
249         bus_space_write_1(t, h, 0x3c, 1);
250         DELAY(SEC_DELAY / 10);
251
252         return 0;
253 }
254
255 #endif /* (NISIC > 0) && (defined(CRTX_S0_P) || defined(TEL_S0_16_3_P)) */
256