Annotation of src/sys/dev/isa/isic_isa_tel_s08.c, Revision 1.3
1.1 martin 1: /*
2: * Copyright (c) 1996 Arne Helme. All rights reserved.
3: *
4: * Copyright (c) 1996 Gary Jennejohn. All rights reserved.
5: *
6: * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: *
12: * 1. Redistributions of source code must retain the above copyright
13: * notice, this list of conditions and the following disclaimer.
14: * 2. Redistributions in binary form must reproduce the above copyright
15: * notice, this list of conditions and the following disclaimer in the
16: * documentation and/or other materials provided with the distribution.
17: * 3. Neither the name of the author nor the names of any co-contributors
18: * may be used to endorse or promote products derived from this software
19: * without specific prior written permission.
20: * 4. Altered versions must be plainly marked as such, and must not be
21: * misrepresented as being the original software and/or documentation.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: *
35: *---------------------------------------------------------------------------
36: *
37: * isic - I4B Siemens ISDN Chipset Driver for Teles S0/8 and clones
38: * ================================================================
39: *
1.3 ! lukem 40: * $Id: isic_isa_tel_s08.c,v 1.2 2001/02/20 22:24:38 martin Exp $
1.1 martin 41: *
42: * last edit-date: [Fri Jan 5 11:37:22 2001]
43: *
44: * -hm clean up
45: * -hm more cleanup
46: * -hm NetBSD patches from Martin
47: * -hm making it finally work (checked with board revision 1.2)
48: * -hm converting asm -> C
49: *
50: *---------------------------------------------------------------------------*/
1.3 ! lukem 51:
! 52: #include <sys/cdefs.h>
! 53: __KERNEL_RCSID(0, "$NetBSD$");
1.1 martin 54:
55: #include "opt_isicisa.h"
56: #ifdef ISICISA_TEL_S0_8
57:
58: #include <sys/param.h>
59: #if defined(__FreeBSD__) && __FreeBSD__ >= 3
60: #include <sys/ioccom.h>
61: #else
62: #include <sys/ioctl.h>
63: #endif
64: #include <sys/kernel.h>
65: #include <sys/systm.h>
66: #include <sys/mbuf.h>
67:
68: #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
69: #include <sys/callout.h>
70: #endif
71:
72: #ifdef __FreeBSD__
73: #include <machine/clock.h>
74: #include <machine/md_var.h>
75: #include <i386/isa/isa_device.h>
76: #else
77: #include <machine/bus.h>
78: #include <sys/device.h>
79: #endif
80:
81: #include <sys/socket.h>
82: #include <net/if.h>
83:
84: #ifdef __FreeBSD__
85: #include <machine/i4b_debug.h>
86: #include <machine/i4b_ioctl.h>
87: #else
88: #include <netisdn/i4b_debug.h>
89: #include <netisdn/i4b_ioctl.h>
90: #endif
91:
1.2 martin 92: #include <dev/ic/isic_l1.h>
93: #include <dev/ic/isac.h>
94: #include <dev/ic/hscx.h>
1.1 martin 95:
96: #include <netisdn/i4b_global.h>
97: #include <netisdn/i4b_l1l2.h>
98: #include <netisdn/i4b_mbuf.h>
99:
100: #ifndef __FreeBSD__
101: static u_int8_t tels08_read_reg __P((struct l1_softc *sc, int what, bus_size_t offs));
102: static void tels08_write_reg __P((struct l1_softc *sc, int what, bus_size_t offs, u_int8_t data));
103: static void tels08_write_fifo __P((struct l1_softc *sc, int what, const void *data, size_t size));
104: static void tels08_read_fifo __P((struct l1_softc *sc, int what, void *buf, size_t size));
105: #endif
106:
107: /*---------------------------------------------------------------------------*
108: * Teles S0/8 write register routine
109: *---------------------------------------------------------------------------*/
110: #ifdef __FreeBSD__
111:
112: static void
113: tels08_write_reg(u_char *base, u_int i, u_int v)
114: {
115: if(i & 0x01)
116: i |= 0x200;
117: base[i] = v;
118: }
119:
120: #else
121:
122: static const bus_size_t offset[] = { 0x100, 0x180, 0x1c0 };
123:
124: static void
125: tels08_write_reg(struct l1_softc *sc, int what, bus_size_t offs, u_int8_t data)
126: {
127: bus_space_tag_t t = sc->sc_maps[0].t;
128: bus_space_handle_t h = sc->sc_maps[0].h;
129:
130: offs += offset[what];
131:
132: if (offs & 0x01)
133: offs |= 0x200;
134:
135: bus_space_write_1(t, h, offs, data);
136: }
137: #endif
138:
139: /*---------------------------------------------------------------------------*
140: * Teles S0/8 read register routine
141: *---------------------------------------------------------------------------*/
142: #ifdef __FreeBSD__
143:
144: static u_char
145: tels08_read_reg(u_char *base, u_int i)
146: {
147: if(i & 0x1)
148: i |= 0x200;
149: return(base[i]);
150: }
151:
152: #else
153:
154: static u_int8_t
155: tels08_read_reg(struct l1_softc *sc, int what, bus_size_t offs)
156: {
157: bus_space_tag_t t = sc->sc_maps[0].t;
158: bus_space_handle_t h = sc->sc_maps[0].h;
159:
160: offs += offset[what];
161:
162: if (offs & 0x01)
163: offs |= 0x200;
164:
165: return bus_space_read_1(t, h, offs);
166: }
167: #endif
168:
169: /*---------------------------------------------------------------------------*
170: * Teles S0/8 fifo read/write access
171: *---------------------------------------------------------------------------*/
172: #ifdef __FreeBSD__
173:
174: static void
175: tels08_memcpyb(void *to, const void *from, size_t len)
176: {
177: for(;len > 0; len--)
178: *((unsigned char *)to)++ = *((unsigned char *)from)++;
179: }
180:
181: #else
182:
183: static void
184: tels08_write_fifo(struct l1_softc *sc, int what, const void *data, size_t size)
185: {
186: bus_space_tag_t t = sc->sc_maps[0].t;
187: bus_space_handle_t h = sc->sc_maps[0].h;
188: bus_space_write_region_1(t, h, offset[what], data, size);
189: }
190:
191: static void
192: tels08_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
193: {
194: bus_space_tag_t t = sc->sc_maps[0].t;
195: bus_space_handle_t h = sc->sc_maps[0].h;
196: bus_space_read_region_1(t, h, offset[what], buf, size);
197: }
198: #endif
199:
200: /*---------------------------------------------------------------------------*
201: * isic_probe_s08 - probe for Teles S0/8 and compatibles
202: *---------------------------------------------------------------------------*/
203: #ifdef __FreeBSD__
204:
205: int
206: isic_probe_s08(struct isa_device *dev)
207: {
208: struct l1_softc *sc = &l1_sc[dev->id_unit];
209:
210: /* check max unit range */
211:
212: if(dev->id_unit >= ISIC_MAXUNIT)
213: {
214: printf("isic%d: Error, unit %d >= ISIC_MAXUNIT for Teles S0/8!\n",
215: dev->id_unit, dev->id_unit);
216: return(0);
217: }
218: sc->sc_unit = dev->id_unit;
219:
220: /* check IRQ validity */
221:
222: switch(ffs(dev->id_irq)-1)
223: {
224: case 2:
225: case 9: /* XXX */
226: case 3:
227: case 4:
228: case 5:
229: case 6:
230: case 7:
231: break;
232:
233: default:
234: printf("isic%d: Error, invalid IRQ [%d] specified for Teles S0/8!\n",
235: dev->id_unit, ffs(dev->id_irq)-1);
236: return(0);
237: break;
238: }
239: sc->sc_irq = dev->id_irq;
240:
241: /* check if we got an iobase */
242:
243: if(dev->id_iobase > 0)
244: {
245: printf("isic%d: Error, iobase specified for Teles S0/8!\n",
246: dev->id_unit);
247: return(0);
248: }
249:
250: /* check if inside memory range of 0xA0000 .. 0xDF000 */
251:
252: if( (kvtop(dev->id_maddr) < 0xa0000) ||
253: (kvtop(dev->id_maddr) > 0xdf000) )
254: {
255: printf("isic%d: Error, mem addr 0x%lx outside 0xA0000-0xDF000 for Teles S0/8!\n",
256: dev->id_unit, kvtop(dev->id_maddr));
257: return(0);
258: }
259:
260: sc->sc_vmem_addr = (caddr_t) dev->id_maddr;
261: dev->id_msize = 0x1000;
262:
263: /* setup ISAC access routines */
264:
265: sc->clearirq = NULL;
266: sc->readreg = tels08_read_reg;
267: sc->writereg = tels08_write_reg;
268:
269: sc->readfifo = tels08_memcpyb;
270: sc->writefifo = tels08_memcpyb;
271:
272: /* setup card type */
273:
274: sc->sc_cardtyp = CARD_TYPEP_8;
275:
276: /* setup IOM bus type */
277:
278: sc->sc_bustyp = BUS_TYPE_IOM1;
279:
280: sc->sc_ipac = 0;
281: sc->sc_bfifolen = HSCX_FIFO_LEN;
282:
283: /* setup ISAC base addr */
284:
285: ISAC_BASE = (caddr_t)((dev->id_maddr) + 0x100);
286:
287: /* setup HSCX base addr */
288:
289: HSCX_A_BASE = (caddr_t)((dev->id_maddr) + 0x180);
290: HSCX_B_BASE = (caddr_t)((dev->id_maddr) + 0x1c0);
291:
292: return (1);
293: }
294:
295: #else
296:
297: int
298: isic_probe_s08(struct isic_attach_args *ia)
299: {
300: /* no real sensible probe is easy - write to fifo memory
301: and read back to verify there is memory doesn't work,
302: because you talk to tx fifo and rcv fifo. So, just check
303: HSCX version, which at least fails if no card present
304: at the given location. */
305: bus_space_tag_t t = ia->ia_maps[0].t;
306: bus_space_handle_t h = ia->ia_maps[0].h;
307: u_int8_t v1, v2;
308:
309: /* HSCX A VSTR */
310: v1 = bus_space_read_1(t, h, offset[1] + H_VSTR) & 0x0f;
311: if (v1 != HSCX_VA1 && v1 != HSCX_VA2 && v1 != HSCX_VA3 && v1 != HSCX_V21)
312: return 0;
313:
314: /* HSCX B VSTR */
315: v2 = bus_space_read_1(t, h, offset[2] + H_VSTR) & 0x0f;
316: if (v2 != HSCX_VA1 && v2 != HSCX_VA2 && v2 != HSCX_VA3 && v2 != HSCX_V21)
317: return 0;
318:
319: /* both HSCX channels should have the same version... */
320: if (v1 != v2)
321: return 0;
322:
323: return 1;
324: }
325: #endif
326:
327: /*---------------------------------------------------------------------------*
328: * isic_attach_s08 - attach Teles S0/8 and compatibles
329: *---------------------------------------------------------------------------*/
330: int
331: #ifdef __FreeBSD__
332: isic_attach_s08(struct isa_device *dev)
333: #else
334: isic_attach_s08(struct l1_softc *sc)
335: #endif
336: {
337: #ifdef __FreeBSD__
338: struct l1_softc *sc = &l1_sc[dev->id_unit];
339: #else
340: bus_space_tag_t t = sc->sc_maps[0].t;
341: bus_space_handle_t h = sc->sc_maps[0].h;
342: #endif
343:
344: /* set card off */
345:
346: #ifdef __FreeBSD__
347: sc->sc_vmem_addr[0x80] = 0;
348: #else
349: bus_space_write_1(t, h, 0x80, 0);
350: #endif
351:
352: DELAY(SEC_DELAY / 5);
353:
354: /* set card on */
355:
356: #ifdef __FreeBSD__
357: sc->sc_vmem_addr[0x80] = 1;
358: #else
359: bus_space_write_1(t, h, 0x80, 1);
360: #endif
361:
362: DELAY(SEC_DELAY / 5);
363:
364: #ifndef __FreeBSD__
365:
366: /* setup ISAC access routines */
367:
368: sc->clearirq = NULL;
369: sc->readreg = tels08_read_reg;
370: sc->writereg = tels08_write_reg;
371: sc->readfifo = tels08_read_fifo;
372: sc->writefifo = tels08_write_fifo;
373:
374: /* setup card type */
375:
376: sc->sc_cardtyp = CARD_TYPEP_8;
377:
378: /* setup IOM bus type */
379:
380: sc->sc_bustyp = BUS_TYPE_IOM1;
381:
382: sc->sc_ipac = 0;
383: sc->sc_bfifolen = HSCX_FIFO_LEN;
384:
385: #endif
386:
387: return (1);
388: }
389:
390: #endif /* ISICISA_TEL_S0_8 */
391:
CVSweb <webmaster@jp.NetBSD.org>