1 /* $Id: sportster.c,v 1.16.2.4 2004/01/13 23:48:39 keil Exp $
3 * low level stuff for USR Sportster internal TA
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.
11 * Thanks to Christian "naddy" Weisgerber (3Com, US Robotics) for documentation
15 #include <linux/init.h>
21 static const char *sportster_revision
= "$Revision: 1.16.2.4 $";
23 #define byteout(addr, val) outb(val, addr)
24 #define bytein(addr) inb(addr)
26 #define SPORTSTER_ISAC 0xC000
27 #define SPORTSTER_HSCXA 0x0000
28 #define SPORTSTER_HSCXB 0x4000
29 #define SPORTSTER_RES_IRQ 0x8000
30 #define SPORTSTER_RESET 0x80
31 #define SPORTSTER_INTE 0x40
34 calc_off(unsigned int base
, unsigned int off
)
36 return (base
+ ((off
& 0xfc) << 8) + ((off
& 3) << 1));
40 read_fifo(unsigned int adr
, u_char
*data
, int size
)
42 insb(adr
, data
, size
);
46 write_fifo(unsigned int adr
, u_char
*data
, int size
)
48 outsb(adr
, data
, size
);
51 /* Interface functions */
54 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
56 return (bytein(calc_off(cs
->hw
.spt
.isac
, offset
)));
60 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
62 byteout(calc_off(cs
->hw
.spt
.isac
, offset
), value
);
66 ReadISACfifo(struct IsdnCardState
*cs
, u_char
*data
, int size
)
68 read_fifo(cs
->hw
.spt
.isac
, data
, size
);
72 WriteISACfifo(struct IsdnCardState
*cs
, u_char
*data
, int size
)
74 write_fifo(cs
->hw
.spt
.isac
, data
, size
);
78 ReadHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
80 return (bytein(calc_off(cs
->hw
.spt
.hscx
[hscx
], offset
)));
84 WriteHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
, u_char value
)
86 byteout(calc_off(cs
->hw
.spt
.hscx
[hscx
], offset
), value
);
90 * fast interrupt HSCX stuff goes here
93 #define READHSCX(cs, nr, reg) bytein(calc_off(cs->hw.spt.hscx[nr], reg))
94 #define WRITEHSCX(cs, nr, reg, data) byteout(calc_off(cs->hw.spt.hscx[nr], reg), data)
95 #define READHSCXFIFO(cs, nr, ptr, cnt) read_fifo(cs->hw.spt.hscx[nr], ptr, cnt)
96 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) write_fifo(cs->hw.spt.hscx[nr], ptr, cnt)
101 sportster_interrupt(int intno
, void *dev_id
)
103 struct IsdnCardState
*cs
= dev_id
;
107 spin_lock_irqsave(&cs
->lock
, flags
);
108 val
= READHSCX(cs
, 1, HSCX_ISTA
);
111 hscx_int_main(cs
, val
);
112 val
= ReadISAC(cs
, ISAC_ISTA
);
115 isac_interrupt(cs
, val
);
116 val
= READHSCX(cs
, 1, HSCX_ISTA
);
118 if (cs
->debug
& L1_DEB_HSCX
)
119 debugl1(cs
, "HSCX IntStat after IntRoutine");
122 val
= ReadISAC(cs
, ISAC_ISTA
);
124 if (cs
->debug
& L1_DEB_ISAC
)
125 debugl1(cs
, "ISAC IntStat after IntRoutine");
128 /* get a new irq impulse if there any pending */
129 bytein(cs
->hw
.spt
.cfg_reg
+ SPORTSTER_RES_IRQ
+ 1);
130 spin_unlock_irqrestore(&cs
->lock
, flags
);
135 release_io_sportster(struct IsdnCardState
*cs
)
139 byteout(cs
->hw
.spt
.cfg_reg
+ SPORTSTER_RES_IRQ
, 0);
140 for (i
= 0; i
< 64; i
++) {
141 adr
= cs
->hw
.spt
.cfg_reg
+ i
* 1024;
142 release_region(adr
, 8);
147 reset_sportster(struct IsdnCardState
*cs
)
149 cs
->hw
.spt
.res_irq
|= SPORTSTER_RESET
; /* Reset On */
150 byteout(cs
->hw
.spt
.cfg_reg
+ SPORTSTER_RES_IRQ
, cs
->hw
.spt
.res_irq
);
152 cs
->hw
.spt
.res_irq
&= ~SPORTSTER_RESET
; /* Reset Off */
153 byteout(cs
->hw
.spt
.cfg_reg
+ SPORTSTER_RES_IRQ
, cs
->hw
.spt
.res_irq
);
158 Sportster_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
164 spin_lock_irqsave(&cs
->lock
, flags
);
166 spin_unlock_irqrestore(&cs
->lock
, flags
);
169 release_io_sportster(cs
);
172 spin_lock_irqsave(&cs
->lock
, flags
);
175 cs
->hw
.spt
.res_irq
|= SPORTSTER_INTE
; /* IRQ On */
176 byteout(cs
->hw
.spt
.cfg_reg
+ SPORTSTER_RES_IRQ
, cs
->hw
.spt
.res_irq
);
178 spin_unlock_irqrestore(&cs
->lock
, flags
);
186 static int get_io_range(struct IsdnCardState
*cs
)
190 for (i
= 0; i
< 64; i
++) {
191 adr
= cs
->hw
.spt
.cfg_reg
+ i
* 1024;
192 if (!request_region(adr
, 8, "sportster")) {
193 printk(KERN_WARNING
"HiSax: USR Sportster config port "
194 "%x-%x already in use\n",
202 for (j
= 0; j
< i
; j
++) {
203 adr
= cs
->hw
.spt
.cfg_reg
+ j
* 1024;
204 release_region(adr
, 8);
210 int setup_sportster(struct IsdnCard
*card
)
212 struct IsdnCardState
*cs
= card
->cs
;
215 strcpy(tmp
, sportster_revision
);
216 printk(KERN_INFO
"HiSax: USR Sportster driver Rev. %s\n", HiSax_getrev(tmp
));
217 if (cs
->typ
!= ISDN_CTYPE_SPORTSTER
)
220 cs
->hw
.spt
.cfg_reg
= card
->para
[1];
221 cs
->irq
= card
->para
[0];
222 if (!get_io_range(cs
))
224 cs
->hw
.spt
.isac
= cs
->hw
.spt
.cfg_reg
+ SPORTSTER_ISAC
;
225 cs
->hw
.spt
.hscx
[0] = cs
->hw
.spt
.cfg_reg
+ SPORTSTER_HSCXA
;
226 cs
->hw
.spt
.hscx
[1] = cs
->hw
.spt
.cfg_reg
+ SPORTSTER_HSCXB
;
229 case 5: cs
->hw
.spt
.res_irq
= 1;
231 case 7: cs
->hw
.spt
.res_irq
= 2;
233 case 10:cs
->hw
.spt
.res_irq
= 3;
235 case 11:cs
->hw
.spt
.res_irq
= 4;
237 case 12:cs
->hw
.spt
.res_irq
= 5;
239 case 14:cs
->hw
.spt
.res_irq
= 6;
241 case 15:cs
->hw
.spt
.res_irq
= 7;
243 default:release_io_sportster(cs
);
244 printk(KERN_WARNING
"Sportster: wrong IRQ\n");
247 printk(KERN_INFO
"HiSax: USR Sportster config irq:%d cfg:0x%X\n",
248 cs
->irq
, cs
->hw
.spt
.cfg_reg
);
250 cs
->readisac
= &ReadISAC
;
251 cs
->writeisac
= &WriteISAC
;
252 cs
->readisacfifo
= &ReadISACfifo
;
253 cs
->writeisacfifo
= &WriteISACfifo
;
254 cs
->BC_Read_Reg
= &ReadHSCX
;
255 cs
->BC_Write_Reg
= &WriteHSCX
;
256 cs
->BC_Send_Data
= &hscx_fill_fifo
;
257 cs
->cardmsg
= &Sportster_card_msg
;
258 cs
->irq_func
= &sportster_interrupt
;
259 ISACVersion(cs
, "Sportster:");
260 if (HscxVersion(cs
, "Sportster:")) {
262 "Sportster: wrong HSCX versions check IO address\n");
263 release_io_sportster(cs
);