1 /* $Id: teles0.c,v 2.15.2.4 2004/01/13 23:48:39 keil Exp $
3 * low level stuff for Teles Memory IO isdn cards
6 * based on the teles driver from Jan den Ouden
7 * Copyright by Karsten Keil <keil@isdn4linux.de>
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
12 * Thanks to Jan den Ouden
18 #include <linux/init.h>
24 extern const char *CardType[];
26 static const char *teles0_revision = "$Revision: 2.15.2.4 $";
28 #define TELES_IOMEM_SIZE 0x400
29 #define byteout(addr,val) outb(val,addr)
30 #define bytein(addr) inb(addr)
33 readisac(void __iomem *adr, u_char off)
35 return readb(adr + ((off & 1) ? 0x2ff : 0x100) + off);
39 writeisac(void __iomem *adr, u_char off, u_char data)
41 writeb(data, adr + ((off & 1) ? 0x2ff : 0x100) + off); mb();
46 readhscx(void __iomem *adr, int hscx, u_char off)
48 return readb(adr + (hscx ? 0x1c0 : 0x180) +
49 ((off & 1) ? 0x1ff : 0) + off);
53 writehscx(void __iomem *adr, int hscx, u_char off, u_char data)
55 writeb(data, adr + (hscx ? 0x1c0 : 0x180) +
56 ((off & 1) ? 0x1ff : 0) + off); mb();
60 read_fifo_isac(void __iomem *adr, u_char * data, int size)
63 register u_char __iomem *ad = adr + 0x100;
64 for (i = 0; i < size; i++)
69 write_fifo_isac(void __iomem *adr, u_char * data, int size)
72 register u_char __iomem *ad = adr + 0x100;
73 for (i = 0; i < size; i++) {
74 writeb(data[i], ad); mb();
79 read_fifo_hscx(void __iomem *adr, int hscx, u_char * data, int size)
82 register u_char __iomem *ad = adr + (hscx ? 0x1c0 : 0x180);
83 for (i = 0; i < size; i++)
88 write_fifo_hscx(void __iomem *adr, int hscx, u_char * data, int size)
91 register u_char __iomem *ad = adr + (hscx ? 0x1c0 : 0x180);
92 for (i = 0; i < size; i++) {
93 writeb(data[i], ad); mb();
97 /* Interface functions */
100 ReadISAC(struct IsdnCardState *cs, u_char offset)
102 return (readisac(cs->hw.teles0.membase, offset));
106 WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
108 writeisac(cs->hw.teles0.membase, offset, value);
112 ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
114 read_fifo_isac(cs->hw.teles0.membase, data, size);
118 WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
120 write_fifo_isac(cs->hw.teles0.membase, data, size);
124 ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
126 return (readhscx(cs->hw.teles0.membase, hscx, offset));
130 WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
132 writehscx(cs->hw.teles0.membase, hscx, offset, value);
136 * fast interrupt HSCX stuff goes here
139 #define READHSCX(cs, nr, reg) readhscx(cs->hw.teles0.membase, nr, reg)
140 #define WRITEHSCX(cs, nr, reg, data) writehscx(cs->hw.teles0.membase, nr, reg, data)
141 #define READHSCXFIFO(cs, nr, ptr, cnt) read_fifo_hscx(cs->hw.teles0.membase, nr, ptr, cnt)
142 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) write_fifo_hscx(cs->hw.teles0.membase, nr, ptr, cnt)
144 #include "hscx_irq.c"
147 teles0_interrupt(int intno, void *dev_id)
149 struct IsdnCardState *cs = dev_id;
154 spin_lock_irqsave(&cs->lock, flags);
155 val = readhscx(cs->hw.teles0.membase, 1, HSCX_ISTA);
158 hscx_int_main(cs, val);
159 val = readisac(cs->hw.teles0.membase, ISAC_ISTA);
162 isac_interrupt(cs, val);
164 val = readhscx(cs->hw.teles0.membase, 1, HSCX_ISTA);
165 if (val && count < 5) {
166 if (cs->debug & L1_DEB_HSCX)
167 debugl1(cs, "HSCX IntStat after IntRoutine");
170 val = readisac(cs->hw.teles0.membase, ISAC_ISTA);
171 if (val && count < 5) {
172 if (cs->debug & L1_DEB_ISAC)
173 debugl1(cs, "ISAC IntStat after IntRoutine");
176 writehscx(cs->hw.teles0.membase, 0, HSCX_MASK, 0xFF);
177 writehscx(cs->hw.teles0.membase, 1, HSCX_MASK, 0xFF);
178 writeisac(cs->hw.teles0.membase, ISAC_MASK, 0xFF);
179 writeisac(cs->hw.teles0.membase, ISAC_MASK, 0x0);
180 writehscx(cs->hw.teles0.membase, 0, HSCX_MASK, 0x0);
181 writehscx(cs->hw.teles0.membase, 1, HSCX_MASK, 0x0);
182 spin_unlock_irqrestore(&cs->lock, flags);
187 release_io_teles0(struct IsdnCardState *cs)
189 if (cs->hw.teles0.cfg_reg)
190 release_region(cs->hw.teles0.cfg_reg, 8);
191 iounmap(cs->hw.teles0.membase);
192 release_mem_region(cs->hw.teles0.phymem, TELES_IOMEM_SIZE);
196 reset_teles0(struct IsdnCardState *cs)
200 if (cs->hw.teles0.cfg_reg) {
230 cfval |= ((cs->hw.teles0.phymem >> 9) & 0xF0);
231 byteout(cs->hw.teles0.cfg_reg + 4, cfval);
232 HZDELAY(HZ / 10 + 1);
233 byteout(cs->hw.teles0.cfg_reg + 4, cfval | 1);
234 HZDELAY(HZ / 10 + 1);
236 writeb(0, cs->hw.teles0.membase + 0x80); mb();
238 writeb(1, cs->hw.teles0.membase + 0x80); mb();
244 Teles_card_msg(struct IsdnCardState *cs, int mt, void *arg)
250 spin_lock_irqsave(&cs->lock, flags);
252 spin_unlock_irqrestore(&cs->lock, flags);
255 release_io_teles0(cs);
258 spin_lock_irqsave(&cs->lock, flags);
260 spin_unlock_irqrestore(&cs->lock, flags);
269 setup_teles0(struct IsdnCard *card)
272 struct IsdnCardState *cs = card->cs;
275 strcpy(tmp, teles0_revision);
276 printk(KERN_INFO "HiSax: Teles 8.0/16.0 driver Rev. %s\n", HiSax_getrev(tmp));
277 if ((cs->typ != ISDN_CTYPE_16_0) && (cs->typ != ISDN_CTYPE_8_0))
280 if (cs->typ == ISDN_CTYPE_16_0)
281 cs->hw.teles0.cfg_reg = card->para[2];
283 cs->hw.teles0.cfg_reg = 0;
285 if (card->para[1] < 0x10000) {
288 "Teles0: membase configured DOSish, assuming 0x%lx\n",
289 (unsigned long) card->para[1]);
291 cs->irq = card->para[0];
292 if (cs->hw.teles0.cfg_reg) {
293 if (!request_region(cs->hw.teles0.cfg_reg, 8, "teles cfg")) {
295 "HiSax: %s config port %x-%x already in use\n",
297 cs->hw.teles0.cfg_reg,
298 cs->hw.teles0.cfg_reg + 8);
302 if (cs->hw.teles0.cfg_reg) {
303 if ((val = bytein(cs->hw.teles0.cfg_reg + 0)) != 0x51) {
304 printk(KERN_WARNING "Teles0: 16.0 Byte at %x is %x\n",
305 cs->hw.teles0.cfg_reg + 0, val);
306 release_region(cs->hw.teles0.cfg_reg, 8);
309 if ((val = bytein(cs->hw.teles0.cfg_reg + 1)) != 0x93) {
310 printk(KERN_WARNING "Teles0: 16.0 Byte at %x is %x\n",
311 cs->hw.teles0.cfg_reg + 1, val);
312 release_region(cs->hw.teles0.cfg_reg, 8);
315 val = bytein(cs->hw.teles0.cfg_reg + 2); /* 0x1e=without AB
319 if (val != 0x1e && val != 0x1f) {
320 printk(KERN_WARNING "Teles0: 16.0 Byte at %x is %x\n",
321 cs->hw.teles0.cfg_reg + 2, val);
322 release_region(cs->hw.teles0.cfg_reg, 8);
326 /* 16.0 and 8.0 designed for IOM1 */
327 test_and_set_bit(HW_IOM1, &cs->HW_Flags);
328 cs->hw.teles0.phymem = card->para[1];
329 if (!request_mem_region(cs->hw.teles0.phymem, TELES_IOMEM_SIZE, "teles iomem")) {
331 "HiSax: %s memory region %lx-%lx already in use\n",
333 cs->hw.teles0.phymem,
334 cs->hw.teles0.phymem + TELES_IOMEM_SIZE);
335 if (cs->hw.teles0.cfg_reg)
336 release_region(cs->hw.teles0.cfg_reg, 8);
339 cs->hw.teles0.membase = ioremap(cs->hw.teles0.phymem, TELES_IOMEM_SIZE);
341 "HiSax: %s config irq:%d mem:%p cfg:0x%X\n",
342 CardType[cs->typ], cs->irq,
343 cs->hw.teles0.membase, cs->hw.teles0.cfg_reg);
344 if (reset_teles0(cs)) {
345 printk(KERN_WARNING "Teles0: wrong IRQ\n");
346 release_io_teles0(cs);
350 cs->readisac = &ReadISAC;
351 cs->writeisac = &WriteISAC;
352 cs->readisacfifo = &ReadISACfifo;
353 cs->writeisacfifo = &WriteISACfifo;
354 cs->BC_Read_Reg = &ReadHSCX;
355 cs->BC_Write_Reg = &WriteHSCX;
356 cs->BC_Send_Data = &hscx_fill_fifo;
357 cs->cardmsg = &Teles_card_msg;
358 cs->irq_func = &teles0_interrupt;
359 ISACVersion(cs, "Teles0:");
360 if (HscxVersion(cs, "Teles0:")) {
362 "Teles0: wrong HSCX versions check IO/MEM addresses\n");
363 release_io_teles0(cs);