Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / net / i4b / layer1 / isic / i4b_dynalink.c
1 /*
2  *   Copyright (c) 1998 Martijn Plak. 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  *      isdn4bsd layer1 driver for Dynalink IS64PH isdn TA
34  *      ==================================================
35  *
36  * $FreeBSD: src/sys/i4b/layer1/isic/i4b_dynalink.c,v 1.5.2.1 2001/08/10 14:08:38 obrien Exp $
37  *
38  *      last edit-date: [Wed Jan 24 09:08:03 2001]
39  *
40  *---------------------------------------------------------------------------*/
41
42 /*      NOTES:
43         
44         This driver was written for the Dynalink IS64PH ISDN TA, based on two 
45         Siemens chips (HSCX 21525 and ISAC 2186). It is sold in the Netherlands.
46         
47         model numbers found on (my) card:
48                 IS64PH, TAS100H-N, P/N:89590555, TA200S100045521
49         
50         chips:  
51                 Siemens PSB 21525N, HSCX TE V2.1
52                 Siemens PSB 2186N, ISAC-S TE V1.1
53                 95MS14, PNP
54         
55         plug-and-play info: 
56                 device id       "ASU1688" 
57                 vendor id       0x88167506 
58                 serial          0x00000044
59                 i/o port        4 byte alignment, 4 bytes requested, 
60                                 10 bit i/o decoding, 0x100-0x3f8 (?)
61                 irq             3,4,5,9,10,11,12,15, high true, edge sensitive
62                         
63         At the moment I'm writing this Dynalink is replacing this card with 
64         one based on a single Siemens chip (IPAC). It will apparently be sold 
65         under the same model name.
66
67         This driver might also work for Asuscom cards.
68 */
69
70 #include "isic.h"
71 #include "opt_i4b.h"
72
73 #if (NISIC > 0) && defined(DYNALINK)
74
75 #include <sys/param.h>
76 #include <sys/systm.h>
77 #include <sys/socket.h>
78 #include <net/if.h>
79
80 #include <machine/i4b_ioctl.h>
81 #include <machine/i4b_trace.h>
82
83 #include <i4b/layer1/i4b_l1.h>
84 #include <i4b/layer1/isic/i4b_isic.h>
85 #include <i4b/layer1/isic/i4b_hscx.h>
86
87 /* io address mapping */
88 #define ISAC            0
89 #define HSCX            1
90 #define ADDR            2
91
92 /* ADDR bits */
93 #define ADDRMASK        0x7F
94 #define RESET           0x80
95
96 /* HSCX register offsets */
97 #define HSCXA           0x00
98 #define HSCXB           0x40
99
100 /*      LOW-LEVEL DEVICE ACCESS
101 */
102
103 static void             
104 dynalink_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
105 {
106         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[0]);
107         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
108
109         switch (what) {
110                 case ISIC_WHAT_ISAC:
111                         bus_space_write_1(t, h, ADDR, 0);
112                         bus_space_read_multi_1(t, h, ISAC, buf, size);
113                         break;
114                 case ISIC_WHAT_HSCXA:
115                         bus_space_write_1(t, h, ADDR, HSCXA);
116                         bus_space_read_multi_1(t, h, HSCX, buf, size);
117                         break;
118                 case ISIC_WHAT_HSCXB:
119                         bus_space_write_1(t, h, ADDR, HSCXB);
120                         bus_space_read_multi_1(t, h, HSCX, buf, size);
121                         break;
122         }
123 }
124
125 static void
126 dynalink_write_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
127 {
128         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[0]);
129         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
130
131         switch (what) {
132                 case ISIC_WHAT_ISAC:
133                         bus_space_write_1(t, h, ADDR, 0);
134                         bus_space_write_multi_1(t, h, ISAC, (u_int8_t*)buf, size);
135                         break;
136                 case ISIC_WHAT_HSCXA:
137                         bus_space_write_1(t, h, ADDR, HSCXA);
138                         bus_space_write_multi_1(t, h, HSCX, (u_int8_t*)buf, size);
139                         break;
140                 case ISIC_WHAT_HSCXB:
141                         bus_space_write_1(t, h, ADDR, HSCXB);
142                         bus_space_write_multi_1(t, h, HSCX, (u_int8_t*)buf, size);
143                         break;
144         }
145 }
146
147 static void
148 dynalink_write_reg(struct l1_softc *sc, int what, bus_size_t reg, u_int8_t data)
149 {
150         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[0]);
151         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
152
153         switch (what) {
154                 case ISIC_WHAT_ISAC:
155                         bus_space_write_1(t, h, ADDR, reg);
156                         bus_space_write_1(t, h, ISAC, data);
157                         break;
158                 case ISIC_WHAT_HSCXA:
159                         bus_space_write_1(t, h, ADDR, HSCXA+reg);
160                         bus_space_write_1(t, h, HSCX, data);
161                         break;
162                 case ISIC_WHAT_HSCXB:
163                         bus_space_write_1(t, h, ADDR, HSCXB+reg);
164                         bus_space_write_1(t, h, HSCX, data);
165                         break;
166         }
167 }
168
169 static u_int8_t
170 dynalink_read_reg(struct l1_softc *sc, int what, bus_size_t reg)
171 {
172         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[0]);
173         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
174
175         switch (what) {
176                 case ISIC_WHAT_ISAC:
177                         bus_space_write_1(t, h, ADDR, reg);
178                         return bus_space_read_1(t, h, ISAC);
179                 case ISIC_WHAT_HSCXA:
180                         bus_space_write_1(t, h, ADDR, HSCXA+reg);
181                         return bus_space_read_1(t, h, HSCX);
182                 case ISIC_WHAT_HSCXB:
183                         bus_space_write_1(t, h, ADDR, HSCXB+reg);
184                         return bus_space_read_1(t, h, HSCX);
185         }
186         return 0;
187 }
188
189 /* attach callback routine */
190 int
191 isic_attach_Dyn(device_t dev)
192 {
193         int unit = device_get_unit(dev);        /* get unit */
194         struct l1_softc *sc = &l1_sc[unit];             /* pointer to softc */
195
196         struct i4b_info *  info = &(sc->sc_resources);
197         bus_space_tag_t    t = rman_get_bustag(info->io_base[0]);
198         bus_space_handle_t h = rman_get_bushandle(info->io_base[0]);
199
200         /* fill in l1_softc structure */
201         sc->readreg     = dynalink_read_reg;
202         sc->writereg    = dynalink_write_reg;
203         sc->readfifo    = dynalink_read_fifo;
204         sc->writefifo   = dynalink_write_fifo;
205         sc->clearirq    = NULL;
206         sc->sc_cardtyp = CARD_TYPEP_DYNALINK;
207         sc->sc_bustyp = BUS_TYPE_IOM2;
208         sc->sc_ipac = 0;
209         sc->sc_bfifolen = HSCX_FIFO_LEN;
210
211         /* Read HSCX A/B VSTR.  Expected value is 0x05 (V2.1). */
212         if( ((HSCX_READ(0, H_VSTR) & 0xf) != 0x5) || 
213             ((HSCX_READ(1, H_VSTR) & 0xf) != 0x5) )
214         {
215                 printf("isic%d: HSCX VSTR test failed for Dynalink\n",
216                         sc->sc_unit);
217                 printf("isic%d: HSC0: VSTR: %#x\n",
218                         sc->sc_unit, HSCX_READ(0, H_VSTR));
219                 printf("isic%d: HSC1: VSTR: %#x\n",
220                         sc->sc_unit, HSCX_READ(1, H_VSTR));
221                 return ENXIO;
222         }
223
224         /* reset card */
225         bus_space_write_1(t,h,ADDR,RESET);
226         DELAY(SEC_DELAY / 10);
227         bus_space_write_1(t,h,ADDR,0);
228         DELAY(SEC_DELAY / 10);
229
230         return 0;                
231 }
232
233 #endif /* (NISIC > 0) && defined(DYNALINK) */