1 /* $Id: avm_a1.c,v 2.15.2.4 2004/01/13 21:46:03 keil Exp $
3 * low level stuff for AVM A1 (Fritz) isdn cards
6 * Copyright by Karsten Keil <keil@isdn4linux.de>
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
13 #include <linux/init.h>
19 static const char *avm_revision = "$Revision: 2.15.2.4 $";
21 #define AVM_A1_STAT_ISAC 0x01
22 #define AVM_A1_STAT_HSCX 0x02
23 #define AVM_A1_STAT_TIMER 0x04
25 #define byteout(addr,val) outb(val,addr)
26 #define bytein(addr) inb(addr)
29 readreg(unsigned int adr, u_char off)
31 return (bytein(adr + off));
35 writereg(unsigned int adr, u_char off, u_char data)
37 byteout(adr + off, data);
42 read_fifo(unsigned int adr, u_char * data, int size)
44 insb(adr, data, size);
48 write_fifo(unsigned int adr, u_char * data, int size)
50 outsb(adr, data, size);
53 /* Interface functions */
56 ReadISAC(struct IsdnCardState *cs, u_char offset)
58 return (readreg(cs->hw.avm.isac, offset));
62 WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
64 writereg(cs->hw.avm.isac, offset, value);
68 ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
70 read_fifo(cs->hw.avm.isacfifo, data, size);
74 WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
76 write_fifo(cs->hw.avm.isacfifo, data, size);
80 ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
82 return (readreg(cs->hw.avm.hscx[hscx], offset));
86 WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
88 writereg(cs->hw.avm.hscx[hscx], offset, value);
92 * fast interrupt HSCX stuff goes here
95 #define READHSCX(cs, nr, reg) readreg(cs->hw.avm.hscx[nr], reg)
96 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.avm.hscx[nr], reg, data)
97 #define READHSCXFIFO(cs, nr, ptr, cnt) read_fifo(cs->hw.avm.hscxfifo[nr], ptr, cnt)
98 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) write_fifo(cs->hw.avm.hscxfifo[nr], ptr, cnt)
100 #include "hscx_irq.c"
103 avm_a1_interrupt(int intno, void *dev_id)
105 struct IsdnCardState *cs = dev_id;
109 spin_lock_irqsave(&cs->lock, flags);
110 while (((sval = bytein(cs->hw.avm.cfg_reg)) & 0xf) != 0x7) {
111 if (!(sval & AVM_A1_STAT_TIMER)) {
112 byteout(cs->hw.avm.cfg_reg, 0x1E);
113 sval = bytein(cs->hw.avm.cfg_reg);
114 } else if (cs->debug & L1_DEB_INTSTAT)
115 debugl1(cs, "avm IntStatus %x", sval);
116 if (!(sval & AVM_A1_STAT_HSCX)) {
117 val = readreg(cs->hw.avm.hscx[1], HSCX_ISTA);
119 hscx_int_main(cs, val);
121 if (!(sval & AVM_A1_STAT_ISAC)) {
122 val = readreg(cs->hw.avm.isac, ISAC_ISTA);
124 isac_interrupt(cs, val);
127 writereg(cs->hw.avm.hscx[0], HSCX_MASK, 0xFF);
128 writereg(cs->hw.avm.hscx[1], HSCX_MASK, 0xFF);
129 writereg(cs->hw.avm.isac, ISAC_MASK, 0xFF);
130 writereg(cs->hw.avm.isac, ISAC_MASK, 0x0);
131 writereg(cs->hw.avm.hscx[0], HSCX_MASK, 0x0);
132 writereg(cs->hw.avm.hscx[1], HSCX_MASK, 0x0);
133 spin_unlock_irqrestore(&cs->lock, flags);
138 release_ioregs(struct IsdnCardState *cs, int mask)
140 release_region(cs->hw.avm.cfg_reg, 8);
142 release_region(cs->hw.avm.isac + 32, 32);
144 release_region(cs->hw.avm.isacfifo, 1);
146 release_region(cs->hw.avm.hscx[0] + 32, 32);
148 release_region(cs->hw.avm.hscxfifo[0], 1);
150 release_region(cs->hw.avm.hscx[1] + 32, 32);
152 release_region(cs->hw.avm.hscxfifo[1], 1);
156 AVM_card_msg(struct IsdnCardState *cs, int mt, void *arg)
164 release_ioregs(cs, 0x3f);
167 spin_lock_irqsave(&cs->lock, flags);
169 byteout(cs->hw.avm.cfg_reg, 0x16);
170 byteout(cs->hw.avm.cfg_reg, 0x1E);
172 spin_unlock_irqrestore(&cs->lock, flags);
181 setup_avm_a1(struct IsdnCard *card)
184 struct IsdnCardState *cs = card->cs;
187 strcpy(tmp, avm_revision);
188 printk(KERN_INFO "HiSax: AVM driver Rev. %s\n", HiSax_getrev(tmp));
189 if (cs->typ != ISDN_CTYPE_A1)
192 cs->hw.avm.cfg_reg = card->para[1] + 0x1800;
193 cs->hw.avm.isac = card->para[1] + 0x1400 - 0x20;
194 cs->hw.avm.hscx[0] = card->para[1] + 0x400 - 0x20;
195 cs->hw.avm.hscx[1] = card->para[1] + 0xc00 - 0x20;
196 cs->hw.avm.isacfifo = card->para[1] + 0x1000;
197 cs->hw.avm.hscxfifo[0] = card->para[1];
198 cs->hw.avm.hscxfifo[1] = card->para[1] + 0x800;
199 cs->irq = card->para[0];
200 if (!request_region(cs->hw.avm.cfg_reg, 8, "avm cfg")) {
202 "HiSax: AVM A1 config port %x-%x already in use\n",
204 cs->hw.avm.cfg_reg + 8);
207 if (!request_region(cs->hw.avm.isac + 32, 32, "HiSax isac")) {
209 "HiSax: AVM A1 isac ports %x-%x already in use\n",
210 cs->hw.avm.isac + 32,
211 cs->hw.avm.isac + 64);
212 release_ioregs(cs, 0);
215 if (!request_region(cs->hw.avm.isacfifo, 1, "HiSax isac fifo")) {
217 "HiSax: AVM A1 isac fifo port %x already in use\n",
218 cs->hw.avm.isacfifo);
219 release_ioregs(cs, 1);
222 if (!request_region(cs->hw.avm.hscx[0] + 32, 32, "HiSax hscx A")) {
224 "HiSax: AVM A1 hscx A ports %x-%x already in use\n",
225 cs->hw.avm.hscx[0] + 32,
226 cs->hw.avm.hscx[0] + 64);
227 release_ioregs(cs, 3);
230 if (!request_region(cs->hw.avm.hscxfifo[0], 1, "HiSax hscx A fifo")) {
232 "HiSax: AVM A1 hscx A fifo port %x already in use\n",
233 cs->hw.avm.hscxfifo[0]);
234 release_ioregs(cs, 7);
237 if (!request_region(cs->hw.avm.hscx[1] + 32, 32, "HiSax hscx B")) {
239 "HiSax: AVM A1 hscx B ports %x-%x already in use\n",
240 cs->hw.avm.hscx[1] + 32,
241 cs->hw.avm.hscx[1] + 64);
242 release_ioregs(cs, 0xf);
245 if (!request_region(cs->hw.avm.hscxfifo[1], 1, "HiSax hscx B fifo")) {
247 "HiSax: AVM A1 hscx B fifo port %x already in use\n",
248 cs->hw.avm.hscxfifo[1]);
249 release_ioregs(cs, 0x1f);
252 byteout(cs->hw.avm.cfg_reg, 0x0);
254 byteout(cs->hw.avm.cfg_reg, 0x1);
256 byteout(cs->hw.avm.cfg_reg, 0x0);
261 byteout(cs->hw.avm.cfg_reg + 1, val);
263 byteout(cs->hw.avm.cfg_reg, 0x0);
266 val = bytein(cs->hw.avm.cfg_reg);
267 printk(KERN_INFO "AVM A1: Byte at %x is %x\n",
268 cs->hw.avm.cfg_reg, val);
269 val = bytein(cs->hw.avm.cfg_reg + 3);
270 printk(KERN_INFO "AVM A1: Byte at %x is %x\n",
271 cs->hw.avm.cfg_reg + 3, val);
272 val = bytein(cs->hw.avm.cfg_reg + 2);
273 printk(KERN_INFO "AVM A1: Byte at %x is %x\n",
274 cs->hw.avm.cfg_reg + 2, val);
275 val = bytein(cs->hw.avm.cfg_reg);
276 printk(KERN_INFO "AVM A1: Byte at %x is %x\n",
277 cs->hw.avm.cfg_reg, val);
279 printk(KERN_INFO "HiSax: AVM A1 config irq:%d cfg:0x%X\n",
283 "HiSax: isac:0x%X/0x%X\n",
284 cs->hw.avm.isac + 32, cs->hw.avm.isacfifo);
286 "HiSax: hscx A:0x%X/0x%X hscx B:0x%X/0x%X\n",
287 cs->hw.avm.hscx[0] + 32, cs->hw.avm.hscxfifo[0],
288 cs->hw.avm.hscx[1] + 32, cs->hw.avm.hscxfifo[1]);
290 cs->readisac = &ReadISAC;
291 cs->writeisac = &WriteISAC;
292 cs->readisacfifo = &ReadISACfifo;
293 cs->writeisacfifo = &WriteISACfifo;
294 cs->BC_Read_Reg = &ReadHSCX;
295 cs->BC_Write_Reg = &WriteHSCX;
296 cs->BC_Send_Data = &hscx_fill_fifo;
298 cs->cardmsg = &AVM_card_msg;
299 cs->irq_func = &avm_a1_interrupt;
300 ISACVersion(cs, "AVM A1:");
301 if (HscxVersion(cs, "AVM A1:")) {
303 "AVM A1: wrong HSCX versions check IO address\n");
304 release_ioregs(cs, 0x3f);