2 * Copyright (c) 1999, 2001 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 driver for ELSA MicroLink ISDN/PCC-16 and ELSA PCFpro
28 * ================================================================
30 * $FreeBSD: src/sys/i4b/layer1/isic/i4b_elsa_pcc16.c,v 1.5.2.2 2001/10/24 14:17:20 hm Exp $
31 * $DragonFly: src/sys/net/i4b/layer1/isic/i4b_elsa_pcc16.c,v 1.3 2003/08/07 21:17:26 dillon Exp $
33 * last edit-date: [Wed Oct 24 16:15:26 2001]
35 *---------------------------------------------------------------------------*/
40 #if (NISIC > 0) && defined(ELSA_PCC16)
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/socket.h>
47 #include <machine/i4b_ioctl.h>
52 static void i4b_epcc16_clrirq(struct l1_softc *sc);
54 /* masks for register encoded in base addr */
56 #define ELSA_BASE_MASK 0x0ffff
57 #define ELSA_OFF_MASK 0xf0000
59 /* register id's to be encoded in base addr */
61 #define ELSA_IDISAC 0x00000
62 #define ELSA_IDHSCXA 0x10000
63 #define ELSA_IDHSCXB 0x20000
65 /* offsets from base address */
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
75 /* control register (write access) */
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
83 /*---------------------------------------------------------------------------*
84 * ELSA MicroLink ISDN/PCC-16 clear IRQ routine
85 *---------------------------------------------------------------------------*/
87 i4b_epcc16_clrirq(struct l1_softc *sc)
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);
94 /*---------------------------------------------------------------------------*
95 * ELSA MicroLink ISDN/PCC-16 ISAC get fifo routine
96 *---------------------------------------------------------------------------*/
98 epcc16_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
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]);
105 bus_space_write_1(t, h, ELSA_OFF_OFF, 0);
106 bus_space_read_multi_1(t, h, ELSA_OFF_ISAC, buf, size);
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);
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);
119 /*---------------------------------------------------------------------------*
120 * ELSA MicroLink ISDN/PCC-16 ISAC put fifo routine
121 *---------------------------------------------------------------------------*/
123 epcc16_write_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
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]);
130 bus_space_write_1(t, h, ELSA_OFF_OFF, 0);
131 bus_space_write_multi_1(t, h, ELSA_OFF_ISAC, buf, size);
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);
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);
144 /*---------------------------------------------------------------------------*
145 * ELSA MicroLink ISDN/PCC-16 ISAC put register routine
146 *---------------------------------------------------------------------------*/
148 epcc16_write_reg(struct l1_softc *sc, int what, bus_size_t offs, u_int8_t data)
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]);
155 bus_space_write_1(t, h, ELSA_OFF_OFF, offs);
156 bus_space_write_1(t, h, ELSA_OFF_ISAC, data);
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);
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);
169 /*---------------------------------------------------------------------------*
170 * ELSA MicroLink ISDN/PCC-16 ISAC get register routine
171 *---------------------------------------------------------------------------*/
173 epcc16_read_reg(struct l1_softc *sc, int what, bus_size_t offs)
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]);
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);
192 /*---------------------------------------------------------------------------*
193 * isic_detach_Epcc16 - detach for ELSA MicroLink ISDN/PCC-16
194 *---------------------------------------------------------------------------*/
196 isic_detach_Epcc16(device_t dev)
198 struct l1_softc *sc = &l1_sc[device_get_unit(dev)];
200 if ( sc->sc_resources.irq )
202 bus_teardown_intr(dev,sc->sc_resources.irq,
203 (void(*)(void *))isicintr);
204 bus_release_resource(dev,SYS_RES_IRQ,
205 sc->sc_resources.irq_rid,
206 sc->sc_resources.irq);
207 sc->sc_resources.irq = 0;
210 if ( sc->sc_resources.io_base[0] ) {
211 bus_release_resource(dev,SYS_RES_IOPORT,
212 sc->sc_resources.io_rid[0],
213 sc->sc_resources.io_base[0]);
214 sc->sc_resources.io_base[0] = 0;
218 /*---------------------------------------------------------------------------*
219 * isic_probe_Epcc16 - probe for ELSA MicroLink ISDN/PCC-16
220 *---------------------------------------------------------------------------*/
222 isic_probe_Epcc16(device_t dev)
224 size_t unit = device_get_unit(dev); /* get unit */
225 struct l1_softc *sc = 0; /* pointer to softc */
226 void *ih = 0; /* dummy */
228 /* check max unit range */
229 if(unit >= ISIC_MAXUNIT)
231 printf("isic%d: Error, unit %d >= ISIC_MAXUNIT for ELSA PCC-16!\n",
236 sc = &l1_sc[unit]; /* get pointer to softc */
237 sc->sc_unit = unit; /* set unit */
239 /* see if an io base was supplied */
241 if(!(sc->sc_resources.io_base[0] =
242 bus_alloc_resource(dev, SYS_RES_IOPORT,
243 &sc->sc_resources.io_rid[0],
244 0ul, ~0ul, 1, RF_ACTIVE)))
246 printf("isic%d: Could not get iobase for ELSA PCC-16.\n",
251 /* check if we got an iobase */
253 sc->sc_port = rman_get_start(sc->sc_resources.io_base[0]);
263 printf("isic%d: Error, invalid iobase 0x%x specified for ELSA MicroLink ISDN/PCC-16!\n",
265 isic_detach_Epcc16(dev);
270 /* setup access routines */
272 sc->clearirq = i4b_epcc16_clrirq;
273 sc->readreg = epcc16_read_reg;
274 sc->writereg = epcc16_write_reg;
276 sc->readfifo = epcc16_read_fifo;
277 sc->writefifo = epcc16_write_fifo;
279 /* setup card type */
281 sc->sc_cardtyp = CARD_TYPEP_PCC16;
283 /* setup IOM bus type */
285 sc->sc_bustyp = BUS_TYPE_IOM2;
288 sc->sc_bfifolen = HSCX_FIFO_LEN;
291 * Read HSCX A/B VSTR. Expected value for the ELSA PCC-16
292 * is 0x05 ( = version 2.1 ) in the least significant bits.
295 if( ((HSCX_READ(0, H_VSTR) & 0xf) != 0x5) ||
296 ((HSCX_READ(1, H_VSTR) & 0xf) != 0x5) )
298 /* patch from "Doobee R . Tzeck" <drt@ailis.de>:
299 * I own an ELSA PCFpro. To my knowledge, the ELSA PCC16 is
300 * a stripped down Version on the PCFpro. By patching the
301 * card detection routine for the PPC16 I was able to use
302 * the PPC16 driver for the PCFpro.
304 if( ((HSCX_READ(0, H_VSTR) & 0xf) != 0x85) ||
305 ((HSCX_READ(1, H_VSTR) & 0xf) != 0x85) )
307 printf("isic%d: HSCX VSTR test failed for ELSA MicroLink ISDN/PCC-16\n",
309 isic_detach_Epcc16(dev);
310 printf("isic%d: HSC0: VSTR: %#x\n",
311 unit, HSCX_READ(0, H_VSTR));
312 printf("isic%d: HSC1: VSTR: %#x\n",
313 unit, HSCX_READ(1, H_VSTR));
318 printf("isic%d: ELSA MicroLink ISDN/PCFpro found, going to tread it as PCC-16\n",
325 if(!(sc->sc_resources.irq =
326 bus_alloc_resource(dev, SYS_RES_IRQ,
327 &sc->sc_resources.irq_rid,
328 0ul, ~0ul, 1, RF_ACTIVE)))
330 printf("isic%d: Could not get an irq.\n",unit);
331 isic_detach_Epcc16(dev);
335 /* get the irq number */
336 sc->sc_irq = rman_get_start(sc->sc_resources.irq);
338 /* check IRQ validity */
351 printf("isic%d: Error, invalid IRQ [%d] specified for ELSA MicroLink ISDN/PCC-16!\n",
353 isic_detach_Epcc16(dev);
358 /* register interupt routine */
359 bus_setup_intr(dev,sc->sc_resources.irq,INTR_TYPE_NET,
360 (void(*)(void *))(isicintr),
367 /*---------------------------------------------------------------------------*
368 * isic_attach_Epcc16 - attach for ELSA MicroLink ISDN/PCC-16
369 *---------------------------------------------------------------------------*/
371 isic_attach_Epcc16(device_t dev)
373 int unit = device_get_unit(dev);
374 struct l1_softc *sc = &l1_sc[unit];
375 bus_space_tag_t t = rman_get_bustag(sc->sc_resources.io_base[0]);
376 bus_space_handle_t h = rman_get_bushandle(sc->sc_resources.io_base[0]);
378 u_char byte = ELSA_CTRL_SECRET;
380 byte &= ~ELSA_CTRL_RESET;
381 bus_space_write_1(t, h, ELSA_OFF_CTRL, byte);
383 byte |= ELSA_CTRL_RESET;
384 bus_space_write_1(t, h, ELSA_OFF_CTRL, byte);
387 bus_space_write_1(t, h, ELSA_OFF_IRQ, 0xff);
392 #endif /* (NISIC > 0) && defined(ELSA_PCC16) */