kernel tree reorganization stage 1: Major cvs repository work (not logged as
[dragonfly.git] / sys / net / i4b / layer1 / isic / i4b_elsa_qs1i.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 ELSA Quickstep 1000pro ISA
28  *      =====================================================================
29  *
30  * $FreeBSD: src/sys/i4b/layer1/isic/i4b_elsa_qs1i.c,v 1.5.2.1 2001/08/10 14:08:38 obrien Exp $
31  * $DragonFly: src/sys/net/i4b/layer1/isic/i4b_elsa_qs1i.c,v 1.3 2003/08/07 21:17:26 dillon Exp $
32  *
33  *      last edit-date: [Wed Jan 24 09:09:03 2001]
34  *
35  *---------------------------------------------------------------------------*/
36
37 #include "use_isic.h"
38 #include "opt_i4b.h"
39
40 #if (NISIC > 0) && defined(ELSA_QS1ISA)
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/socket.h>
45 #include <net/if.h>
46
47 #include <machine/i4b_ioctl.h>
48
49 #include "i4b_isic.h"
50 #include "i4b_hscx.h"
51
52 static void i4b_eq1i_clrirq(struct l1_softc *sc);
53
54 /* masks for register encoded in base addr */
55
56 #define ELSA_BASE_MASK          0x0ffff
57 #define ELSA_OFF_MASK           0xf0000
58
59 /* register id's to be encoded in base addr */
60
61 #define ELSA_IDISAC             0x00000
62 #define ELSA_IDHSCXA            0x10000
63 #define ELSA_IDHSCXB            0x20000
64
65 /* offsets from base address */
66
67 #define ELSA_OFF_ISAC           0x00
68 #define ELSA_OFF_HSCX           0x02
69 #define ELSA_OFF_OFF            0x03
70 #define ELSA_OFF_CTRL           0x04
71 #define ELSA_OFF_CFG            0x05
72 #define ELSA_OFF_TIMR           0x06
73 #define ELSA_OFF_IRQ            0x07
74
75 /* control register (write access) */
76
77 #define ELSA_CTRL_LED_YELLOW    0x02
78 #define ELSA_CTRL_LED_GREEN     0x08
79 #define ELSA_CTRL_RESET         0x20
80 #define ELSA_CTRL_TIMEREN       0x80
81 #define ELSA_CTRL_SECRET        0x50
82
83 /*---------------------------------------------------------------------------*
84  *      ELSA QuickStep 1000pro/ISA clear IRQ routine
85  *---------------------------------------------------------------------------*/
86 static void
87 i4b_eq1i_clrirq(struct l1_softc *sc)
88 {
89         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[0]);
90         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
91         bus_space_write_1(t, h, ELSA_OFF_IRQ, 0);
92 }
93
94 /*---------------------------------------------------------------------------*
95  *      ELSA QuickStep 1000pro/ISA ISAC get fifo routine
96  *---------------------------------------------------------------------------*/
97 static void
98 eqs1pi_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
99 {
100         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[0]);
101         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
102
103         switch (what) {
104                 case ISIC_WHAT_ISAC:
105                         bus_space_write_1(t, h, ELSA_OFF_OFF, 0);
106                         bus_space_read_multi_1(t, h, ELSA_OFF_ISAC, buf, size);
107                         break;
108                 case ISIC_WHAT_HSCXA:
109                         bus_space_write_1(t, h, ELSA_OFF_OFF, 0);
110                         bus_space_read_multi_1(t, h, ELSA_OFF_HSCX, buf, size);
111                         break;
112                 case ISIC_WHAT_HSCXB:
113                         bus_space_write_1(t, h, ELSA_OFF_OFF, 0x40);
114                         bus_space_read_multi_1(t, h, ELSA_OFF_HSCX, buf, size);
115                         break;
116         }
117 }
118
119 /*---------------------------------------------------------------------------*
120  *      ELSA QuickStep 1000pro/ISA ISAC put fifo routine
121  *---------------------------------------------------------------------------*/
122 static void
123 eqs1pi_write_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
124 {
125         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[0]);
126         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
127
128         switch (what) {
129                 case ISIC_WHAT_ISAC:
130                         bus_space_write_1(t, h, ELSA_OFF_OFF, 0);
131                         bus_space_write_multi_1(t, h, ELSA_OFF_ISAC, buf, size);
132                         break;
133                 case ISIC_WHAT_HSCXA:
134                         bus_space_write_1(t, h, ELSA_OFF_OFF, 0);
135                         bus_space_write_multi_1(t, h, ELSA_OFF_HSCX, buf, size);
136                         break;
137                 case ISIC_WHAT_HSCXB:
138                         bus_space_write_1(t, h, ELSA_OFF_OFF, 0x40);
139                         bus_space_write_multi_1(t, h, ELSA_OFF_HSCX, buf, size);
140                         break;
141         }
142 }
143
144 /*---------------------------------------------------------------------------*
145  *      ELSA QuickStep 1000pro/ISA ISAC put register routine
146  *---------------------------------------------------------------------------*/
147 static void
148 eqs1pi_write_reg(struct l1_softc *sc, int what, bus_size_t offs, 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, ELSA_OFF_OFF, offs);
156                         bus_space_write_1(t, h, ELSA_OFF_ISAC, data);
157                         break;
158                 case ISIC_WHAT_HSCXA:
159                         bus_space_write_1(t, h, ELSA_OFF_OFF, offs);
160                         bus_space_write_1(t, h, ELSA_OFF_HSCX, data);
161                         break;
162                 case ISIC_WHAT_HSCXB:
163                         bus_space_write_1(t, h, ELSA_OFF_OFF, 0x40+offs);
164                         bus_space_write_1(t, h, ELSA_OFF_HSCX, data);
165                         break;
166         }
167 }
168
169 /*---------------------------------------------------------------------------*
170  *      ELSA QuickStep 1000pro/ISA ISAC get register routine
171  *---------------------------------------------------------------------------*/
172 static u_int8_t
173 eqs1pi_read_reg(struct l1_softc *sc, int what, bus_size_t offs)
174 {
175         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[0]);
176         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
177
178         switch (what) {
179                 case ISIC_WHAT_ISAC:
180                         bus_space_write_1(t, h, ELSA_OFF_OFF, offs);
181                         return bus_space_read_1(t, h, ELSA_OFF_ISAC);
182                 case ISIC_WHAT_HSCXA:
183                         bus_space_write_1(t, h, ELSA_OFF_OFF, offs);
184                         return bus_space_read_1(t, h, ELSA_OFF_HSCX);
185                 case ISIC_WHAT_HSCXB:
186                         bus_space_write_1(t, h, ELSA_OFF_OFF, 0x40+offs);
187                         return bus_space_read_1(t, h, ELSA_OFF_HSCX);
188         }
189         return 0;
190 }
191
192 /*---------------------------------------------------------------------------*
193  * isic_attach_Eqs1pi - attach for ELSA QuickStep 1000pro/ISA
194  *---------------------------------------------------------------------------*/
195 int
196 isic_attach_Eqs1pi(device_t dev)
197 {
198         int unit = device_get_unit(dev);
199         struct l1_softc *sc = &l1_sc[unit];     
200         bus_space_tag_t    t = rman_get_bustag(sc->sc_resources.io_base[0]);
201         bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
202
203         u_char byte = ELSA_CTRL_SECRET;
204
205         /* setup access routines */
206
207         sc->clearirq = i4b_eq1i_clrirq;
208         sc->readreg = eqs1pi_read_reg;
209         sc->writereg = eqs1pi_write_reg;
210
211         sc->readfifo = eqs1pi_read_fifo;
212         sc->writefifo = eqs1pi_write_fifo;
213
214         /* setup card type */
215         
216         sc->sc_cardtyp = CARD_TYPEP_ELSAQS1ISA;
217
218         /* setup IOM bus type */
219         
220         sc->sc_bustyp = BUS_TYPE_IOM2;
221
222         sc->sc_ipac = 0;
223         sc->sc_bfifolen = HSCX_FIFO_LEN;        
224
225         /* enable the card */
226         
227         byte &= ~ELSA_CTRL_RESET;
228         bus_space_write_1(t, h, ELSA_OFF_CTRL, byte);
229         DELAY(20);
230         byte |= ELSA_CTRL_RESET;
231         bus_space_write_1(t, h, ELSA_OFF_CTRL, byte);
232
233         DELAY(20);
234         bus_space_write_1(t, h, ELSA_OFF_IRQ, 0xff);
235
236         return 0;
237 }
238 #endif /* (NISIC > 0) && defined(ELSA_QS1ISA) */