2 * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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
25 *---------------------------------------------------------------------------
27 * isic - I4B Siemens ISDN Chipset Driver for Creatix PnP cards
28 * ============================================================
30 * $Id: isic_isapnp_ctx_s0P.c,v 1.11 2007/10/19 12:00:32 ad Exp $
32 * last edit-date: [Fri Jan 5 11:38:29 2001]
34 *---------------------------------------------------------------------------*/
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: isic_isapnp_ctx_s0P.c,v 1.10 2007/03/04 06:02:13 christos Exp $");
39 #include "opt_isicpnp.h"
42 #include <sys/param.h>
44 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
45 #include <sys/ioccom.h>
47 #include <sys/ioctl.h>
50 #include <sys/kernel.h>
51 #include <sys/systm.h>
54 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
55 #include <sys/callout.h>
59 #include <machine/clock.h>
60 #include <i386/isa/isa_device.h>
63 #include <sys/device.h>
66 #include <sys/socket.h>
70 #include <machine/i4b_debug.h>
71 #include <machine/i4b_ioctl.h>
73 #include <netisdn/i4b_debug.h>
74 #include <netisdn/i4b_ioctl.h>
77 #include <netisdn/i4b_global.h>
78 #include <netisdn/i4b_l2.h>
79 #include <netisdn/i4b_l1l2.h>
81 #include <dev/ic/isic_l1.h>
82 #include <dev/ic/isac.h>
83 #include <dev/ic/hscx.h>
85 #include <netisdn/i4b_mbuf.h>
88 static u_int8_t
ctxs0P_read_reg(struct isic_softc
*sc
, int what
, bus_size_t offs
);
89 static void ctxs0P_write_reg(struct isic_softc
*sc
, int what
, bus_size_t offs
, u_int8_t data
);
90 static void ctxs0P_read_fifo(struct isic_softc
*sc
, int what
, void *buf
, size_t size
);
91 static void ctxs0P_write_fifo(struct isic_softc
*sc
, int what
, const void *data
, size_t size
);
92 void isic_attach_Cs0P(struct isic_softc
*sc
);
96 #include <i386/isa/pnp.h>
97 extern void isicintr ( int unit
);
100 /*---------------------------------------------------------------------------*
101 * Creatix ISDN-S0 P&P ISAC get fifo routine
102 *---------------------------------------------------------------------------*/
106 ctxs0P_read_fifo(void *buf
, const void *base
, size_t len
)
108 insb((int)base
+ 0x3e, (u_char
*)buf
, (u_int
)len
);
114 ctxs0P_read_fifo(struct isic_softc
*sc
, int what
, void *buf
, size_t size
)
116 bus_space_tag_t t
= sc
->sc_maps
[what
+1].t
;
117 bus_space_handle_t h
= sc
->sc_maps
[what
+1].h
;
118 bus_size_t o
= sc
->sc_maps
[what
+1].offset
;
119 bus_space_read_multi_1(t
, h
, o
+ 0x3e, buf
, size
);
124 /*---------------------------------------------------------------------------*
125 * Creatix ISDN-S0 P&P ISAC put fifo routine
126 *---------------------------------------------------------------------------*/
130 ctxs0P_write_fifo(void *base
, const void *buf
, size_t len
)
132 outsb((int)base
+ 0x3e, (u_char
*)buf
, (u_int
)len
);
138 ctxs0P_write_fifo(struct isic_softc
*sc
, int what
, const void *buf
, size_t size
)
140 bus_space_tag_t t
= sc
->sc_maps
[what
+1].t
;
141 bus_space_handle_t h
= sc
->sc_maps
[what
+1].h
;
142 bus_size_t o
= sc
->sc_maps
[what
+1].offset
;
143 bus_space_write_multi_1(t
, h
, o
+ 0x3e, buf
, size
);
147 /*---------------------------------------------------------------------------*
148 * Creatix ISDN-S0 P&P ISAC put register routine
149 *---------------------------------------------------------------------------*/
153 ctxs0P_write_reg(u_char
*base
, u_int offset
, u_int v
)
155 outb((int)base
+ offset
, (u_char
)v
);
161 ctxs0P_write_reg(struct isic_softc
*sc
, int what
, bus_size_t offs
, u_int8_t data
)
163 bus_space_tag_t t
= sc
->sc_maps
[what
+1].t
;
164 bus_space_handle_t h
= sc
->sc_maps
[what
+1].h
;
165 bus_size_t o
= sc
->sc_maps
[what
+1].offset
;
166 bus_space_write_1(t
, h
, o
+ offs
, data
);
170 /*---------------------------------------------------------------------------*
171 * Creatix ISDN-S0 P&P ISAC get register routine
172 *---------------------------------------------------------------------------*/
176 ctxs0P_read_reg(u_char
*base
, u_int offset
)
178 return (inb((int)base
+ offset
));
184 ctxs0P_read_reg(struct isic_softc
*sc
, int what
, bus_size_t offs
)
186 bus_space_tag_t t
= sc
->sc_maps
[what
+1].t
;
187 bus_space_handle_t h
= sc
->sc_maps
[what
+1].h
;
188 bus_size_t o
= sc
->sc_maps
[what
+1].offset
;
189 return bus_space_read_1(t
, h
, o
+ offs
);
196 /*---------------------------------------------------------------------------*
197 * isic_probe_Cs0P - probe for Creatix ISDN-S0 P&P and compatibles
198 *---------------------------------------------------------------------------*/
200 isic_probe_Cs0P(struct isa_device
*dev
, unsigned int iobase2
)
202 struct isic_softc
*sc
= &l1_sc
[dev
->id_unit
];
204 /* check max unit range */
206 if(dev
->id_unit
>= ISIC_MAXUNIT
)
208 printf("isic%d: Error, unit %d >= ISIC_MAXUNIT for Creatix ISDN-S0 P&P!\n",
209 dev
->id_unit
, dev
->id_unit
);
212 sc
->sc_unit
= dev
->id_unit
;
214 /* check IRQ validity */
216 switch(ffs(dev
->id_irq
) - 1)
227 printf("isic%d: Error, invalid IRQ [%d] specified for Creatix ISDN-S0 P&P!\n",
228 dev
->id_unit
, ffs(dev
->id_irq
)-1);
232 sc
->sc_irq
= dev
->id_irq
;
234 /* check if memory addr specified */
238 printf("isic%d: Error, mem addr 0x%lx specified for Creatix ISDN-S0 P&P!\n",
239 dev
->id_unit
, (u_long
)dev
->id_maddr
);
246 printf("isic%d: Error, iobase2 is 0 for Creatix ISDN-S0 P&P!\n",
251 /* check if we got an iobase */
253 switch(dev
->id_iobase
)
260 printf("isic%d: Error, invalid iobase 0x%x specified for Creatix ISDN-S0 P&P!\n",
261 dev
->id_unit
, dev
->id_iobase
);
265 sc
->sc_port
= dev
->id_iobase
;
267 /* setup access routines */
270 sc
->readreg
= ctxs0P_read_reg
;
271 sc
->writereg
= ctxs0P_write_reg
;
273 sc
->readfifo
= ctxs0P_read_fifo
;
274 sc
->writefifo
= ctxs0P_write_fifo
;
276 /* setup card type */
278 sc
->sc_cardtyp
= CARD_TYPEP_CS0P
;
280 /* setup IOM bus type */
282 sc
->sc_bustyp
= BUS_TYPE_IOM2
;
285 sc
->sc_bfifolen
= HSCX_FIFO_LEN
;
287 /* setup ISAC and HSCX base addr */
289 ISAC_BASE
= (void *) dev
->id_iobase
- 0x20;
290 HSCX_A_BASE
= (void *) iobase2
- 0x20;
291 HSCX_B_BASE
= (void *) iobase2
;
294 * Read HSCX A/B VSTR. Expected value for the Creatix PnP card is
295 * 0x05 ( = version 2.1 ) in the least significant bits.
298 if( ((HSCX_READ(0, H_VSTR
) & 0xf) != 0x5) ||
299 ((HSCX_READ(1, H_VSTR
) & 0xf) != 0x5) )
301 printf("isic%d: HSCX VSTR test failed for Creatix PnP\n",
303 printf("isic%d: HSC0: VSTR: %#x\n",
304 dev
->id_unit
, HSCX_READ(0, H_VSTR
));
305 printf("isic%d: HSC1: VSTR: %#x\n",
306 dev
->id_unit
, HSCX_READ(1, H_VSTR
));
313 /*---------------------------------------------------------------------------*
314 * isic_attach_s0163P - attach Creatix ISDN-S0 P&P
315 *---------------------------------------------------------------------------*/
317 isic_attach_Cs0P(struct isa_device
*dev
, unsigned int iobase2
)
319 outb((dev
->id_iobase
) + 0x1c, 0);
320 DELAY(SEC_DELAY
/ 10);
321 outb((dev
->id_iobase
) + 0x1c, 1);
322 DELAY(SEC_DELAY
/ 10);
326 #else /* !__FreeBSD__ */
329 isic_attach_Cs0P(struct isic_softc
*sc
)
332 bus_space_tag_t t
= sc
->sc_maps
[0].t
;
333 bus_space_handle_t h
= sc
->sc_maps
[0].h
;
334 bus_space_write_1(t
, h
, 0x1c, 0);
335 DELAY(SEC_DELAY
/ 10);
336 bus_space_write_1(t
, h
, 0x1c, 1);
337 DELAY(SEC_DELAY
/ 10);
339 /* setup access routines */
342 sc
->readreg
= ctxs0P_read_reg
;
343 sc
->writereg
= ctxs0P_write_reg
;
345 sc
->readfifo
= ctxs0P_read_fifo
;
346 sc
->writefifo
= ctxs0P_write_fifo
;
348 /* setup card type */
350 sc
->sc_cardtyp
= CARD_TYPEP_CS0P
;
352 /* setup IOM bus type */
354 sc
->sc_bustyp
= BUS_TYPE_IOM2
;
357 sc
->sc_bfifolen
= HSCX_FIFO_LEN
;
361 #endif /* ISICPNP_CRTX_S0_P */