2 * Copyright (c) 1997 Andrew Gordon. All rights reserved.
4 * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
33 *---------------------------------------------------------------------------
35 * isic - I4B Siemens ISDN Chipset Driver for Teles S0 PnP
36 * =======================================================
41 * $Id: isic_isapnp_tel_s0P.c,v 1.11 2007/10/19 12:00:32 ad Exp $
43 * last edit-date: [Fri Jan 5 11:38:29 2001]
45 *---------------------------------------------------------------------------*/
47 #include <sys/cdefs.h>
48 __KERNEL_RCSID(0, "$NetBSD: isic_isapnp_tel_s0P.c,v 1.10 2007/03/04 06:02:14 christos Exp $");
50 #include "opt_isicpnp.h"
51 #ifdef ISICPNP_TEL_S0_16_3_P
53 #include <sys/param.h>
54 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
55 #include <sys/ioccom.h>
57 #include <sys/ioctl.h>
59 #include <sys/kernel.h>
60 #include <sys/systm.h>
63 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
64 #include <sys/callout.h>
68 #include <machine/clock.h>
69 #include <i386/isa/isa_device.h>
72 #include <sys/device.h>
75 #include <sys/socket.h>
79 #include <machine/i4b_debug.h>
80 #include <machine/i4b_ioctl.h>
82 #include <netisdn/i4b_debug.h>
83 #include <netisdn/i4b_ioctl.h>
84 #include <netisdn/i4b_l2.h>
87 #include <dev/ic/isic_l1.h>
88 #include <dev/ic/isac.h>
89 #include <dev/ic/hscx.h>
91 #include <netisdn/i4b_global.h>
92 #include <netisdn/i4b_l1l2.h>
93 #include <netisdn/i4b_mbuf.h>
96 static u_int8_t
tels0163P_read_reg(struct isic_softc
*sc
, int what
, bus_size_t offs
);
97 static void tels0163P_write_reg(struct isic_softc
*sc
, int what
, bus_size_t offs
, u_int8_t data
);
98 static void tels0163P_read_fifo(struct isic_softc
*sc
, int what
, void *buf
, size_t size
);
99 static void tels0163P_write_fifo(struct isic_softc
*sc
, int what
, const void *data
, size_t size
);
100 void isic_attach_s0163P(struct isic_softc
*sc
);
104 /*---------------------------------------------------------------------------*
105 * Teles S0/16.3 PnP read fifo routine
106 *---------------------------------------------------------------------------*/
110 tels0163P_read_fifo(void *buf
, const void *base
, size_t len
)
112 insb((int)base
+ 0x3e, (u_char
*)buf
, (u_int
)len
);
118 tels0163P_read_fifo(struct isic_softc
*sc
, int what
, void *buf
, size_t size
)
120 bus_space_tag_t t
= sc
->sc_maps
[what
+1].t
;
121 bus_space_handle_t h
= sc
->sc_maps
[what
+1].h
;
122 bus_size_t o
= sc
->sc_maps
[what
+1].offset
;
123 bus_space_read_multi_1(t
, h
, o
+ 0x3e, buf
, size
);
128 /*---------------------------------------------------------------------------*
129 * Teles S0/16.3 PnP write fifo routine
130 *---------------------------------------------------------------------------*/
134 tels0163P_write_fifo(void *base
, const void *buf
, size_t len
)
136 outsb((int)base
+ 0x3e, (u_char
*)buf
, (u_int
)len
);
142 tels0163P_write_fifo(struct isic_softc
*sc
, int what
, const void *buf
, size_t size
)
144 bus_space_tag_t t
= sc
->sc_maps
[what
+1].t
;
145 bus_space_handle_t h
= sc
->sc_maps
[what
+1].h
;
146 bus_size_t o
= sc
->sc_maps
[what
+1].offset
;
147 bus_space_write_multi_1(t
, h
, o
+ 0x3e, buf
, size
);
151 /*---------------------------------------------------------------------------*
152 * Teles S0/16.3 PnP write register routine
153 *---------------------------------------------------------------------------*/
157 tels0163P_write_reg(u_char
*base
, u_int offset
, u_int v
)
159 outb((int)base
+ offset
, (u_char
)v
);
165 tels0163P_write_reg(struct isic_softc
*sc
, int what
, bus_size_t offs
, u_int8_t data
)
167 bus_space_tag_t t
= sc
->sc_maps
[what
+1].t
;
168 bus_space_handle_t h
= sc
->sc_maps
[what
+1].h
;
169 bus_size_t o
= sc
->sc_maps
[what
+1].offset
;
170 bus_space_write_1(t
, h
, o
+ offs
, data
);
174 /*---------------------------------------------------------------------------*
175 * Teles S0/16.3 PnP read register routine
176 *---------------------------------------------------------------------------*/
180 tels0163P_read_reg(u_char
*base
, u_int offset
)
182 return (inb((int)base
+ offset
));
188 tels0163P_read_reg(struct isic_softc
*sc
, int what
, bus_size_t offs
)
190 bus_space_tag_t t
= sc
->sc_maps
[what
+1].t
;
191 bus_space_handle_t h
= sc
->sc_maps
[what
+1].h
;
192 bus_size_t o
= sc
->sc_maps
[what
+1].offset
;
193 return bus_space_read_1(t
, h
, o
+ offs
);
197 /*---------------------------------------------------------------------------*
198 * isic_probe_s0163P - probe for Teles S0/16.3 PnP and compatibles
199 *---------------------------------------------------------------------------*/
202 isic_probe_s0163P(struct isa_device
*dev
, unsigned int iobase2
)
204 struct isic_softc
*sc
= &l1_sc
[dev
->id_unit
];
206 /* check max unit range */
208 if(dev
->id_unit
>= ISIC_MAXUNIT
)
210 printf("isic%d: Error, unit %d >= ISIC_MAXUNIT for Teles S0/16.3 PnP!\n",
211 dev
->id_unit
, dev
->id_unit
);
214 sc
->sc_unit
= dev
->id_unit
;
216 /* check IRQ validity */
218 switch(ffs(dev
->id_irq
) - 1)
229 printf("isic%d: Error, invalid IRQ [%d] specified for Teles S0/16.3 PnP!\n",
230 dev
->id_unit
, ffs(dev
->id_irq
)-1);
234 sc
->sc_irq
= dev
->id_irq
;
236 /* check if memory addr specified */
240 printf("isic%d: Error, mem addr 0x%lx specified for Teles S0/16.3 PnP!\n",
241 dev
->id_unit
, (u_long
)dev
->id_maddr
);
246 /* check if we got an iobase */
248 switch(dev
->id_iobase
)
256 printf("isic%d: Error, invalid iobase 0x%x specified for Teles S0/16.3 PnP!\n",
257 dev
->id_unit
, dev
->id_iobase
);
261 sc
->sc_port
= dev
->id_iobase
;
263 /* setup access routines */
266 sc
->readreg
= tels0163P_read_reg
;
267 sc
->writereg
= tels0163P_write_reg
;
269 sc
->readfifo
= tels0163P_read_fifo
;
270 sc
->writefifo
= tels0163P_write_fifo
;
272 /* setup card type */
274 sc
->sc_cardtyp
= CARD_TYPEP_163P
;
276 /* setup IOM bus type */
278 sc
->sc_bustyp
= BUS_TYPE_IOM2
;
281 sc
->sc_bfifolen
= HSCX_FIFO_LEN
;
283 /* setup ISAC and HSCX base addr */
285 switch(dev
->id_iobase
)
288 ISAC_BASE
= (void *) 0x580 - 0x20;
289 HSCX_A_BASE
= (void *) 0x180 - 0x20;
290 HSCX_B_BASE
= (void *) 0x180;
294 ISAC_BASE
= (void *) 0x500 - 0x20;
295 HSCX_A_BASE
= (void *) 0x100 - 0x20;
296 HSCX_B_BASE
= (void *) 0x100;
300 ISAC_BASE
= (void *) 0x680 - 0x20;
301 HSCX_A_BASE
= (void *) 0x280 - 0x20;
302 HSCX_B_BASE
= (void *) 0x280;
307 * Read HSCX A/B VSTR. Expected value for the S0/16.3 PnP card is
308 * 0x05 in the least significant bits.
311 if( ((HSCX_READ(0, H_VSTR
) & 0xf) != 0x5) ||
312 ((HSCX_READ(1, H_VSTR
) & 0xf) != 0x5) )
314 printf("isic%d: HSCX VSTR test failed for Teles S0/16.3 PnP\n",
316 printf("isic%d: HSC0: VSTR: %#x\n",
317 dev
->id_unit
, HSCX_READ(0, H_VSTR
));
318 printf("isic%d: HSC1: VSTR: %#x\n",
319 dev
->id_unit
, HSCX_READ(1, H_VSTR
));
327 /*---------------------------------------------------------------------------*
328 * isic_attach_s0163P - attach Teles S0/16.3 PnP and compatibles
329 *---------------------------------------------------------------------------*/
332 isic_attach_s0163P(struct isa_device
*dev
, unsigned int iobase2
)
334 outb((dev
->id_iobase
) + 0x1c, 0);
335 DELAY(SEC_DELAY
/ 10);
336 outb((dev
->id_iobase
) + 0x1c, 1);
337 DELAY(SEC_DELAY
/ 10);
344 isic_attach_s0163P(struct isic_softc
*sc
)
347 bus_space_tag_t t
= sc
->sc_maps
[0].t
;
348 bus_space_handle_t h
= sc
->sc_maps
[0].h
;
349 bus_space_write_1(t
, h
, 0x1c, 0);
350 DELAY(SEC_DELAY
/ 10);
351 bus_space_write_1(t
, h
, 0x1c, 1);
352 DELAY(SEC_DELAY
/ 10);
354 /* setup access routines */
357 sc
->readreg
= tels0163P_read_reg
;
358 sc
->writereg
= tels0163P_write_reg
;
360 sc
->readfifo
= tels0163P_read_fifo
;
361 sc
->writefifo
= tels0163P_write_fifo
;
363 /* setup card type */
365 sc
->sc_cardtyp
= CARD_TYPEP_163P
;
367 /* setup IOM bus type */
369 sc
->sc_bustyp
= BUS_TYPE_IOM2
;
372 sc
->sc_bfifolen
= HSCX_FIFO_LEN
;
376 #endif /* ISICPNP_TEL_S0_16_3_P */