]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/i4b/layer1/isic/i4b_tel_s0163.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / i4b / layer1 / isic / i4b_tel_s0163.c
1 /*-
2  *   Copyright (c) 1996 Arne Helme. All rights reserved.
3  *   Copyright (c) 1996 Gary Jennejohn. All rights reserved. 
4  *   Copyright (c) 1997, 2001 Hellmuth Michaelis. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
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.
20  *   
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
31  *   SUCH DAMAGE.
32  */
33
34 /*---------------------------------------------------------------------------
35  *
36  *      isic - I4B Siemens ISDN Chipset Driver for Teles S0/16.3
37  *      ========================================================
38  *      last edit-date: [Wed Jan 24 09:27:40 2001]
39  *
40  *---------------------------------------------------------------------------*/
41
42 #include <sys/cdefs.h>
43 __FBSDID("$FreeBSD$");
44
45 #include "opt_i4b.h"
46
47 #if defined(TEL_S0_16_3)
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/socket.h>
52 #include <net/if.h>
53
54 #include <i4b/include/i4b_ioctl.h>
55 #include <i4b/include/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 static u_char intr_no[] = { 1, 1, 0, 2, 4, 6, 1, 1, 1, 0, 8, 10, 12, 1, 1, 14 };
62
63 #define ISAC_OFFS       0x400
64 #define HSCXA_OFFS      0xc00
65 #define HSCXB_OFFS      0x800
66
67 /*---------------------------------------------------------------------------*
68  *      Teles S0/16.3 read fifo routine
69  *---------------------------------------------------------------------------*/
70 static void
71 tels0163_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
72 {
73         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
74         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
75         bus_space_read_multi_1(t,h,0x1e,buf,size);
76 }
77
78 /*---------------------------------------------------------------------------*
79  *      Teles S0/16.3 write fifo routine
80  *---------------------------------------------------------------------------*/
81 static void
82 tels0163_write_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
83 {
84         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
85         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
86         bus_space_write_multi_1(t,h,0x1e,buf,size);
87 }
88
89 /*---------------------------------------------------------------------------*
90  *      Teles S0/16.3 ISAC put register routine
91  *---------------------------------------------------------------------------*/
92 static void
93 tels0163_write_reg(struct l1_softc *sc, int what, bus_size_t offs, u_int8_t data)
94 {
95         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
96         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
97         bus_space_write_1(t,h,offs - 0x20,data);
98 }
99
100 /*---------------------------------------------------------------------------*
101  *      Teles S0/16.3 ISAC get register routine
102  *---------------------------------------------------------------------------*/
103 static u_int8_t
104 tels0163_read_reg(struct l1_softc *sc, int what, bus_size_t offs)
105 {
106         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[what+1]);
107         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[what+1]);
108         return bus_space_read_1(t,h,offs - 0x20);
109 }
110
111 /*---------------------------------------------------------------------------*
112  *      isic_probe_s0163 - probe routine for Teles S0/16.3
113  *---------------------------------------------------------------------------*/
114 int
115 isic_probe_s0163(device_t dev)
116 {
117         size_t unit = device_get_unit(dev);     /* get unit */
118         struct l1_softc *sc = 0;        /* pointer to softc */
119         void *ih = 0;                   /* dummy */
120         bus_space_tag_t    t;           /* bus things */
121         bus_space_handle_t h;
122         u_int8_t b0,b1,b2;              /* signature */
123
124         /* check max unit range */
125
126         if(unit >= ISIC_MAXUNIT)
127         {
128                 printf("isic%d: Error, unit %d >= ISIC_MAXUNIT for Teles 16.3!\n",
129                                 unit, unit);
130                 return(ENXIO);  
131         }
132
133         sc = &l1_sc[unit];                      /* get pointer to softc */
134         sc->sc_unit = unit;                     /* set unit */
135
136         /* see if an io base was supplied */
137         
138         if(!(sc->sc_resources.io_base[0] =
139                         bus_alloc_resource_any(dev, SYS_RES_IOPORT,
140                                                &sc->sc_resources.io_rid[0],
141                                                RF_ACTIVE)))
142         {
143                 printf("isic%d: Could not get iobase for Teles S0/16.3.\n",
144                                 unit);
145                 return(ENXIO);
146         }
147
148         /* set io base */
149
150         sc->sc_port = rman_get_start(sc->sc_resources.io_base[0]);
151         /* Release the resource -  re-allocate later with correct size  */
152         bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_resources.io_rid[0],
153                         sc->sc_resources.io_base[0]);
154         
155         switch(sc->sc_port)
156         {
157                 case 0xd80:
158                 case 0xe80:
159                 case 0xf80:
160                         break;
161                         
162                 case 0x180:
163                 case 0x280:
164                 case 0x380:
165                         printf("isic%d: Error, instead of using iobase 0x%x for your Teles S0/16.3,\n",
166                                 unit, sc->sc_port);
167                         printf("isic%d:        please use 0x%x in the kernel configuration file!\n",
168                                 unit, sc->sc_port+0xc00);                       
169                         isic_detach_common(dev);
170                         return(ENXIO);
171                         break;
172         
173                 default:
174                         printf("isic%d: Error, invalid iobase 0x%x specified for Teles S0/16.3!\n",
175                                 unit, sc->sc_port);
176                         isic_detach_common(dev);
177                         return(ENXIO);
178                         break;
179         }
180         
181         /* set io port resources */
182
183         sc->sc_resources.io_rid[0] = 0; 
184         bus_set_resource(dev, SYS_RES_IOPORT, 0, sc->sc_port, 0x20);
185         sc->sc_resources.io_base[0] =
186                 bus_alloc_resource_any(dev, SYS_RES_IOPORT,
187                                        &sc->sc_resources.io_rid[0],
188                                        RF_ACTIVE);
189         if(!sc->sc_resources.io_base[0])
190         {
191                 printf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
192                         unit, sc->sc_port);
193                 isic_detach_common(dev);
194                 return ENXIO;
195         }
196         sc->sc_resources.io_rid[1] = 1; 
197         bus_set_resource(dev, SYS_RES_IOPORT, 1,
198                 sc->sc_port-ISAC_OFFS, 0x20);
199         sc->sc_resources.io_base[1] =
200                 bus_alloc_resource_any(dev, SYS_RES_IOPORT,
201                                        &sc->sc_resources.io_rid[1],
202                                        RF_ACTIVE);
203         if(!sc->sc_resources.io_base[1])
204         {
205                 printf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
206                         unit, sc->sc_port-ISAC_OFFS);
207                 isic_detach_common(dev);
208                 return ENXIO;
209         }
210         
211         sc->sc_resources.io_rid[2] = 2;
212         bus_set_resource(dev, SYS_RES_IOPORT, 2,
213                 sc->sc_port-HSCXA_OFFS, 0x20);
214         sc->sc_resources.io_base[2] =
215                 bus_alloc_resource_any(dev, SYS_RES_IOPORT,
216                                        &sc->sc_resources.io_rid[2],
217                                        RF_ACTIVE);
218         if(!sc->sc_resources.io_base[2])
219         {
220                 printf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
221                         unit, sc->sc_port-HSCXA_OFFS);
222                 isic_detach_common(dev);
223                 return ENXIO;
224         }
225
226         sc->sc_resources.io_rid[3] = 3;
227         bus_set_resource(dev, SYS_RES_IOPORT, 3,
228                 sc->sc_port-HSCXB_OFFS, 0x20);
229         sc->sc_resources.io_base[3] =
230                 bus_alloc_resource_any(dev, SYS_RES_IOPORT,
231                                        &sc->sc_resources.io_rid[3],
232                                        RF_ACTIVE);
233         if(!sc->sc_resources.io_base[3])
234         {
235                 printf("isic%d: Error allocating io at 0x%x for Teles S0/16.3!\n",
236                         unit, sc->sc_port-HSCXB_OFFS);
237                 isic_detach_common(dev);
238                 return ENXIO;
239         }
240
241         /* setup access routines */
242
243         sc->clearirq = NULL;
244         sc->readreg = tels0163_read_reg;
245         sc->writereg = tels0163_write_reg;
246
247         sc->readfifo = tels0163_read_fifo;
248         sc->writefifo = tels0163_write_fifo;
249
250         /* setup card type */
251         
252         sc->sc_cardtyp= CARD_TYPEP_16_3;
253
254         /* setup IOM bus type */
255         
256         sc->sc_bustyp = BUS_TYPE_IOM2;
257
258         sc->sc_ipac = 0;
259         sc->sc_bfifolen = HSCX_FIFO_LEN;
260
261         t = rman_get_bustag(sc->sc_resources.io_base[0]);
262         h = rman_get_bushandle(sc->sc_resources.io_base[0]);
263
264         b0 = bus_space_read_1(t, h, 0);
265         b1 = bus_space_read_1(t, h, 1);
266         b2 = bus_space_read_1(t, h, 2);
267         
268         if ( b0 != 0x51 && b0 != 0x10 ) {
269                 printf("isic%d: Error, signature 1 0x%x != 0x51 or 0x10 for Teles S0/16.3!\n",
270                         unit, b0);
271                 isic_detach_common(dev);
272                 return ENXIO;
273         }
274         
275         if ( b1 != 0x93 ) {
276                 printf("isic%d: Error, signature 2 0x%x != 0x93 for Teles S0/16.3!\n",
277                         unit, b1);
278                 isic_detach_common(dev);
279                 return ENXIO;
280         }
281         if (( b2 != 0x1c ) && ( b2 != 0x1f )) {
282                 printf("isic%d: Error, signature 3 0x%x != (0x1c || 0x1f) for Teles S0/16.3!\n",
283                         unit, b2);
284                 isic_detach_common(dev);
285                 return ENXIO;   
286         }
287         
288         /* 
289          * Read HSCX A/B VSTR.  Expected value for the S0/16.3 card is
290          * 0x05 or 0x04 (for older 16.3's) in the least significant bits.
291          */
292          
293         if( (((HSCX_READ(0, H_VSTR) & 0xf) != 0x5) &&
294              ((HSCX_READ(0, H_VSTR) & 0xf) != 0x4))     ||
295             (((HSCX_READ(1, H_VSTR) & 0xf) != 0x5) &&
296              ((HSCX_READ(1, H_VSTR) & 0xf) != 0x4)) )  
297         {
298                 printf("isic%d: HSCX VSTR test failed for Teles S0/16.3\n",
299                         unit);
300                 printf("isic%d: HSC0: VSTR: %#x\n",
301                         unit, HSCX_READ(0, H_VSTR));
302                 printf("isic%d: HSC1: VSTR: %#x\n",
303                         unit, HSCX_READ(1, H_VSTR));
304                 isic_detach_common(dev);
305                 return (ENXIO);
306         }                   
307
308         /* get our irq */
309
310         if(!(sc->sc_resources.irq =
311                 bus_alloc_resource_any(dev, SYS_RES_IRQ,
312                                        &sc->sc_resources.irq_rid,
313                                        RF_ACTIVE)))
314         {
315                 printf("isic%d: Could not get IRQ for Teles S0/16.3.\n",unit);
316                 isic_detach_common(dev);
317                 return ENXIO;
318         }
319
320         /* get the irq number */
321         sc->sc_irq = rman_get_start(sc->sc_resources.irq);
322
323         switch(sc->sc_irq)
324         {
325                 case 2:
326                 case 9:
327                 case 5:
328                 case 10:
329                 case 12:
330                 case 15:
331                         break;
332
333                 default:
334                         printf("isic%d: Error, invalid IRQ [%d] specified for Teles S0/16.3!\n",
335                                 unit, sc->sc_irq);
336                         isic_detach_common(dev);
337                         return(ENXIO);
338                         break;
339         }
340
341         /* register interrupt routine */
342         if (bus_setup_intr(dev, sc->sc_resources.irq, INTR_TYPE_NET, NULL,
343                         (void(*)(void *))(isicintr), sc, &ih) != 0)
344         {
345                 printf("isic%d: Could not setup IRQ for Teles S0/16.3.\n",unit);
346                 isic_detach_common(dev);
347                 return ENXIO;
348         }
349
350         return (0);
351 }
352
353 /*---------------------------------------------------------------------------*
354  *      isic_attach_s0163 - attach Teles S0/16.3 and compatibles
355  *---------------------------------------------------------------------------*/
356 int
357 isic_attach_s0163(device_t dev)
358 {
359         unsigned int unit = device_get_unit(dev);       /* get unit */
360         struct l1_softc *sc = &l1_sc[unit];
361         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[0]);
362         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
363
364         /* configure IRQ */
365         
366         DELAY(SEC_DELAY / 10);
367         bus_space_write_1(t, h, 4, intr_no[sc->sc_irq]);
368
369         DELAY(SEC_DELAY / 10);
370         bus_space_write_1(t, h, 4, intr_no[sc->sc_irq] | 0x01);
371
372         return (0);
373 }
374
375 #endif /* defined(TEL_S0_16_3) */