1 /* $Id: s0box.c,v 2.1 1998/04/15 16:38:24 keil Exp $
3 * s0box.c low level stuff for Creatix S0BOX
5 * Author S0BOX specific stuff: Enrik Berkhan (enrik@starfleet.inka.de)
15 extern const char *CardType
[];
16 const char *s0box_revision
= "$Revision: 2.1 $";
19 writereg(unsigned int padr
, signed int addr
, u_char off
, u_char val
) {
26 outb_p((addr
+off
)&0x7f,padr
);
35 static u_char nibtab
[] = { 1, 9, 5, 0xd, 3, 0xb, 7, 0xf,
36 0, 0, 0, 0, 0, 0, 0, 0,
37 0, 8, 4, 0xc, 2, 0xa, 6, 0xe } ;
40 readreg(unsigned int padr
, signed int addr
, u_char off
) {
41 register u_char n1
, n2
;
48 outb_p((addr
+off
)|0x80,padr
);
51 n1
= (inb_p(padr
+1) >> 3) & 0x17;
53 n2
= (inb_p(padr
+1) >> 3) & 0x17;
57 return nibtab
[n1
] | (nibtab
[n2
] << 4);
61 read_fifo(unsigned int padr
, signed int adr
, u_char
* data
, int size
)
64 register u_char n1
, n2
;
68 outb_p(adr
|0x80, padr
);
70 for (i
=0; i
<size
; i
++) {
72 n1
= (inb_p(padr
+1) >> 3) & 0x17;
74 n2
= (inb_p(padr
+1) >> 3) & 0x17;
75 *(data
++)=nibtab
[n1
] | (nibtab
[n2
] << 4);
83 write_fifo(unsigned int padr
, signed int adr
, u_char
* data
, int size
)
88 outb_p(adr
&0x7f, padr
);
89 for (i
=0; i
<size
; i
++) {
91 outb_p(*(data
++), padr
);
99 /* Interface functions */
102 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
104 return (readreg(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.isac
, offset
));
108 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
110 writereg(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.isac
, offset
, value
);
114 ReadISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
116 read_fifo(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.isacfifo
, data
, size
);
120 WriteISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
122 write_fifo(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.isacfifo
, data
, size
);
126 ReadHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
128 return (readreg(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.hscx
[hscx
], offset
));
132 WriteHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
, u_char value
)
134 writereg(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.hscx
[hscx
], offset
, value
);
138 * fast interrupt HSCX stuff goes here
141 #define READHSCX(cs, nr, reg) readreg(cs->hw.teles3.cfg_reg, cs->hw.teles3.hscx[nr], reg)
142 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.teles3.cfg_reg, cs->hw.teles3.hscx[nr], reg, data)
143 #define READHSCXFIFO(cs, nr, ptr, cnt) read_fifo(cs->hw.teles3.cfg_reg, cs->hw.teles3.hscxfifo[nr], ptr, cnt)
144 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) write_fifo(cs->hw.teles3.cfg_reg, cs->hw.teles3.hscxfifo[nr], ptr, cnt)
146 #include "hscx_irq.c"
149 s0box_interrupt(int intno
, void *dev_id
, struct pt_regs
*regs
)
152 struct IsdnCardState
*cs
= dev_id
;
153 u_char val
, stat
= 0;
157 printk(KERN_WARNING
"Teles: Spurious interrupt!\n");
160 val
= readreg(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.hscx
[1], HSCX_ISTA
);
163 hscx_int_main(cs
, val
);
166 val
= readreg(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.isac
, ISAC_ISTA
);
169 isac_interrupt(cs
, val
);
173 val
= readreg(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.hscx
[1], HSCX_ISTA
);
174 if (val
&& count
< MAXCOUNT
) {
175 if (cs
->debug
& L1_DEB_HSCX
)
176 debugl1(cs
, "HSCX IntStat after IntRoutine");
179 val
= readreg(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.isac
, ISAC_ISTA
);
180 if (val
&& count
< MAXCOUNT
) {
181 if (cs
->debug
& L1_DEB_ISAC
)
182 debugl1(cs
, "ISAC IntStat after IntRoutine");
185 if (count
>= MAXCOUNT
)
186 printk(KERN_WARNING
"S0Box: more than %d loops in s0box_interrupt\n", count
);
188 writereg(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.hscx
[0], HSCX_MASK
, 0xFF);
189 writereg(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.hscx
[1], HSCX_MASK
, 0xFF);
190 writereg(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.hscx
[0], HSCX_MASK
, 0x0);
191 writereg(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.hscx
[1], HSCX_MASK
, 0x0);
194 writereg(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.isac
, ISAC_MASK
, 0xFF);
195 writereg(cs
->hw
.teles3
.cfg_reg
, cs
->hw
.teles3
.isac
, ISAC_MASK
, 0x0);
200 release_io_s0box(struct IsdnCardState
*cs
)
202 release_region(cs
->hw
.teles3
.cfg_reg
, 8);
206 S0Box_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
212 release_io_s0box(cs
);
215 return(request_irq(cs
->irq
, &s0box_interrupt
,
216 I4L_IRQ_FLAG
, "HiSax", cs
));
227 setup_s0box(struct IsdnCard
*card
))
229 struct IsdnCardState
*cs
= card
->cs
;
232 strcpy(tmp
, s0box_revision
);
233 printk(KERN_INFO
"HiSax: S0Box IO driver Rev. %s\n", HiSax_getrev(tmp
));
234 if (cs
->typ
!= ISDN_CTYPE_S0BOX
)
237 cs
->hw
.teles3
.cfg_reg
= card
->para
[1];
238 cs
->hw
.teles3
.hscx
[0] = -0x20;
239 cs
->hw
.teles3
.hscx
[1] = 0x0;
240 cs
->hw
.teles3
.isac
= 0x20;
241 cs
->hw
.teles3
.isacfifo
= cs
->hw
.teles3
.isac
+ 0x3e;
242 cs
->hw
.teles3
.hscxfifo
[0] = cs
->hw
.teles3
.hscx
[0] + 0x3e;
243 cs
->hw
.teles3
.hscxfifo
[1] = cs
->hw
.teles3
.hscx
[1] + 0x3e;
244 cs
->irq
= card
->para
[0];
245 if (check_region(cs
->hw
.teles3
.cfg_reg
,8)) {
247 "HiSax: %s ports %x-%x already in use\n",
249 cs
->hw
.teles3
.cfg_reg
,
250 cs
->hw
.teles3
.cfg_reg
+ 7);
253 request_region(cs
->hw
.teles3
.cfg_reg
, 8, "S0Box parallel I/O");
255 "HiSax: %s config irq:%d isac:0x%x cfg:0x%x\n",
256 CardType
[cs
->typ
], cs
->irq
,
257 cs
->hw
.teles3
.isac
, cs
->hw
.teles3
.cfg_reg
);
259 "HiSax: hscx A:0x%x hscx B:0x%x\n",
260 cs
->hw
.teles3
.hscx
[0], cs
->hw
.teles3
.hscx
[1]);
261 cs
->readisac
= &ReadISAC
;
262 cs
->writeisac
= &WriteISAC
;
263 cs
->readisacfifo
= &ReadISACfifo
;
264 cs
->writeisacfifo
= &WriteISACfifo
;
265 cs
->BC_Read_Reg
= &ReadHSCX
;
266 cs
->BC_Write_Reg
= &WriteHSCX
;
267 cs
->BC_Send_Data
= &hscx_fill_fifo
;
268 cs
->cardmsg
= &S0Box_card_msg
;
269 ISACVersion(cs
, "S0Box:");
270 if (HscxVersion(cs
, "S0Box:")) {
272 "S0Box: wrong HSCX versions check IO address\n");
273 release_io_s0box(cs
);