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 extern const char *CardType
[];
20 static const char *avm_revision
= "$Revision: 2.15.2.4 $";
22 #define AVM_A1_STAT_ISAC 0x01
23 #define AVM_A1_STAT_HSCX 0x02
24 #define AVM_A1_STAT_TIMER 0x04
26 #define byteout(addr,val) outb(val,addr)
27 #define bytein(addr) inb(addr)
30 readreg(unsigned int adr
, u_char off
)
32 return (bytein(adr
+ off
));
36 writereg(unsigned int adr
, u_char off
, u_char data
)
38 byteout(adr
+ off
, data
);
43 read_fifo(unsigned int adr
, u_char
* data
, int size
)
45 insb(adr
, data
, size
);
49 write_fifo(unsigned int adr
, u_char
* data
, int size
)
51 outsb(adr
, data
, size
);
54 /* Interface functions */
57 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
59 return (readreg(cs
->hw
.avm
.isac
, offset
));
63 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
65 writereg(cs
->hw
.avm
.isac
, offset
, value
);
69 ReadISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
71 read_fifo(cs
->hw
.avm
.isacfifo
, data
, size
);
75 WriteISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
77 write_fifo(cs
->hw
.avm
.isacfifo
, data
, size
);
81 ReadHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
83 return (readreg(cs
->hw
.avm
.hscx
[hscx
], offset
));
87 WriteHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
, u_char value
)
89 writereg(cs
->hw
.avm
.hscx
[hscx
], offset
, value
);
93 * fast interrupt HSCX stuff goes here
96 #define READHSCX(cs, nr, reg) readreg(cs->hw.avm.hscx[nr], reg)
97 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.avm.hscx[nr], reg, data)
98 #define READHSCXFIFO(cs, nr, ptr, cnt) read_fifo(cs->hw.avm.hscxfifo[nr], ptr, cnt)
99 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) write_fifo(cs->hw.avm.hscxfifo[nr], ptr, cnt)
101 #include "hscx_irq.c"
104 avm_a1_interrupt(int intno
, void *dev_id
, struct pt_regs
*regs
)
106 struct IsdnCardState
*cs
= dev_id
;
110 spin_lock_irqsave(&cs
->lock
, flags
);
111 while (((sval
= bytein(cs
->hw
.avm
.cfg_reg
)) & 0xf) != 0x7) {
112 if (!(sval
& AVM_A1_STAT_TIMER
)) {
113 byteout(cs
->hw
.avm
.cfg_reg
, 0x1E);
114 sval
= bytein(cs
->hw
.avm
.cfg_reg
);
115 } else if (cs
->debug
& L1_DEB_INTSTAT
)
116 debugl1(cs
, "avm IntStatus %x", sval
);
117 if (!(sval
& AVM_A1_STAT_HSCX
)) {
118 val
= readreg(cs
->hw
.avm
.hscx
[1], HSCX_ISTA
);
120 hscx_int_main(cs
, val
);
122 if (!(sval
& AVM_A1_STAT_ISAC
)) {
123 val
= readreg(cs
->hw
.avm
.isac
, ISAC_ISTA
);
125 isac_interrupt(cs
, val
);
128 writereg(cs
->hw
.avm
.hscx
[0], HSCX_MASK
, 0xFF);
129 writereg(cs
->hw
.avm
.hscx
[1], HSCX_MASK
, 0xFF);
130 writereg(cs
->hw
.avm
.isac
, ISAC_MASK
, 0xFF);
131 writereg(cs
->hw
.avm
.isac
, ISAC_MASK
, 0x0);
132 writereg(cs
->hw
.avm
.hscx
[0], HSCX_MASK
, 0x0);
133 writereg(cs
->hw
.avm
.hscx
[1], HSCX_MASK
, 0x0);
134 spin_unlock_irqrestore(&cs
->lock
, flags
);
139 release_ioregs(struct IsdnCardState
*cs
, int mask
)
141 release_region(cs
->hw
.avm
.cfg_reg
, 8);
143 release_region(cs
->hw
.avm
.isac
+ 32, 32);
145 release_region(cs
->hw
.avm
.isacfifo
, 1);
147 release_region(cs
->hw
.avm
.hscx
[0] + 32, 32);
149 release_region(cs
->hw
.avm
.hscxfifo
[0], 1);
151 release_region(cs
->hw
.avm
.hscx
[1] + 32, 32);
153 release_region(cs
->hw
.avm
.hscxfifo
[1], 1);
157 AVM_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
165 release_ioregs(cs
, 0x3f);
168 spin_lock_irqsave(&cs
->lock
, flags
);
170 byteout(cs
->hw
.avm
.cfg_reg
, 0x16);
171 byteout(cs
->hw
.avm
.cfg_reg
, 0x1E);
173 spin_unlock_irqrestore(&cs
->lock
, flags
);
182 setup_avm_a1(struct IsdnCard
*card
)
185 struct IsdnCardState
*cs
= card
->cs
;
188 strcpy(tmp
, avm_revision
);
189 printk(KERN_INFO
"HiSax: AVM driver Rev. %s\n", HiSax_getrev(tmp
));
190 if (cs
->typ
!= ISDN_CTYPE_A1
)
193 cs
->hw
.avm
.cfg_reg
= card
->para
[1] + 0x1800;
194 cs
->hw
.avm
.isac
= card
->para
[1] + 0x1400 - 0x20;
195 cs
->hw
.avm
.hscx
[0] = card
->para
[1] + 0x400 - 0x20;
196 cs
->hw
.avm
.hscx
[1] = card
->para
[1] + 0xc00 - 0x20;
197 cs
->hw
.avm
.isacfifo
= card
->para
[1] + 0x1000;
198 cs
->hw
.avm
.hscxfifo
[0] = card
->para
[1];
199 cs
->hw
.avm
.hscxfifo
[1] = card
->para
[1] + 0x800;
200 cs
->irq
= card
->para
[0];
201 if (!request_region(cs
->hw
.avm
.cfg_reg
, 8, "avm cfg")) {
203 "HiSax: %s config port %x-%x already in use\n",
206 cs
->hw
.avm
.cfg_reg
+ 8);
209 if (!request_region(cs
->hw
.avm
.isac
+ 32, 32, "HiSax isac")) {
211 "HiSax: %s isac ports %x-%x already in use\n",
213 cs
->hw
.avm
.isac
+ 32,
214 cs
->hw
.avm
.isac
+ 64);
215 release_ioregs(cs
, 0);
218 if (!request_region(cs
->hw
.avm
.isacfifo
, 1, "HiSax isac fifo")) {
220 "HiSax: %s isac fifo port %x already in use\n",
222 cs
->hw
.avm
.isacfifo
);
223 release_ioregs(cs
, 1);
226 if (!request_region(cs
->hw
.avm
.hscx
[0] + 32, 32, "HiSax hscx A")) {
228 "HiSax: %s hscx A ports %x-%x already in use\n",
230 cs
->hw
.avm
.hscx
[0] + 32,
231 cs
->hw
.avm
.hscx
[0] + 64);
232 release_ioregs(cs
, 3);
235 if (!request_region(cs
->hw
.avm
.hscxfifo
[0], 1, "HiSax hscx A fifo")) {
237 "HiSax: %s hscx A fifo port %x already in use\n",
239 cs
->hw
.avm
.hscxfifo
[0]);
240 release_ioregs(cs
, 7);
243 if (!request_region(cs
->hw
.avm
.hscx
[1] + 32, 32, "HiSax hscx B")) {
245 "HiSax: %s hscx B ports %x-%x already in use\n",
247 cs
->hw
.avm
.hscx
[1] + 32,
248 cs
->hw
.avm
.hscx
[1] + 64);
249 release_ioregs(cs
, 0xf);
252 if (!request_region(cs
->hw
.avm
.hscxfifo
[1], 1, "HiSax hscx B fifo")) {
254 "HiSax: %s hscx B fifo port %x already in use\n",
256 cs
->hw
.avm
.hscxfifo
[1]);
257 release_ioregs(cs
, 0x1f);
260 byteout(cs
->hw
.avm
.cfg_reg
, 0x0);
262 byteout(cs
->hw
.avm
.cfg_reg
, 0x1);
264 byteout(cs
->hw
.avm
.cfg_reg
, 0x0);
269 byteout(cs
->hw
.avm
.cfg_reg
+ 1, val
);
271 byteout(cs
->hw
.avm
.cfg_reg
, 0x0);
274 val
= bytein(cs
->hw
.avm
.cfg_reg
);
275 printk(KERN_INFO
"AVM A1: Byte at %x is %x\n",
276 cs
->hw
.avm
.cfg_reg
, val
);
277 val
= bytein(cs
->hw
.avm
.cfg_reg
+ 3);
278 printk(KERN_INFO
"AVM A1: Byte at %x is %x\n",
279 cs
->hw
.avm
.cfg_reg
+ 3, val
);
280 val
= bytein(cs
->hw
.avm
.cfg_reg
+ 2);
281 printk(KERN_INFO
"AVM A1: Byte at %x is %x\n",
282 cs
->hw
.avm
.cfg_reg
+ 2, val
);
283 val
= bytein(cs
->hw
.avm
.cfg_reg
);
284 printk(KERN_INFO
"AVM A1: Byte at %x is %x\n",
285 cs
->hw
.avm
.cfg_reg
, val
);
288 "HiSax: %s config irq:%d cfg:0x%X\n",
289 CardType
[cs
->typ
], cs
->irq
,
292 "HiSax: isac:0x%X/0x%X\n",
293 cs
->hw
.avm
.isac
+ 32, cs
->hw
.avm
.isacfifo
);
295 "HiSax: hscx A:0x%X/0x%X hscx B:0x%X/0x%X\n",
296 cs
->hw
.avm
.hscx
[0] + 32, cs
->hw
.avm
.hscxfifo
[0],
297 cs
->hw
.avm
.hscx
[1] + 32, cs
->hw
.avm
.hscxfifo
[1]);
299 cs
->readisac
= &ReadISAC
;
300 cs
->writeisac
= &WriteISAC
;
301 cs
->readisacfifo
= &ReadISACfifo
;
302 cs
->writeisacfifo
= &WriteISACfifo
;
303 cs
->BC_Read_Reg
= &ReadHSCX
;
304 cs
->BC_Write_Reg
= &WriteHSCX
;
305 cs
->BC_Send_Data
= &hscx_fill_fifo
;
307 cs
->cardmsg
= &AVM_card_msg
;
308 cs
->irq_func
= &avm_a1_interrupt
;
309 ISACVersion(cs
, "AVM A1:");
310 if (HscxVersion(cs
, "AVM A1:")) {
312 "AVM A1: wrong HSCX versions check IO address\n");
313 release_ioregs(cs
, 0x3f);