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 extern const char *CardType
[];
22 static const char *sportster_revision
= "$Revision: 1.16.2.4 $";
24 #define byteout(addr,val) outb(val,addr)
25 #define bytein(addr) inb(addr)
27 #define SPORTSTER_ISAC 0xC000
28 #define SPORTSTER_HSCXA 0x0000
29 #define SPORTSTER_HSCXB 0x4000
30 #define SPORTSTER_RES_IRQ 0x8000
31 #define SPORTSTER_RESET 0x80
32 #define SPORTSTER_INTE 0x40
35 calc_off(unsigned int base
, unsigned int off
)
37 return(base
+ ((off
& 0xfc)<<8) + ((off
& 3)<<1));
41 read_fifo(unsigned int adr
, u_char
* data
, int size
)
43 insb(adr
, data
, size
);
47 write_fifo(unsigned int adr
, u_char
* data
, int size
)
49 outsb(adr
, data
, size
);
52 /* Interface functions */
55 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
57 return (bytein(calc_off(cs
->hw
.spt
.isac
, offset
)));
61 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
63 byteout(calc_off(cs
->hw
.spt
.isac
, offset
), value
);
67 ReadISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
69 read_fifo(cs
->hw
.spt
.isac
, data
, size
);
73 WriteISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
75 write_fifo(cs
->hw
.spt
.isac
, data
, size
);
79 ReadHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
81 return (bytein(calc_off(cs
->hw
.spt
.hscx
[hscx
], offset
)));
85 WriteHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
, u_char value
)
87 byteout(calc_off(cs
->hw
.spt
.hscx
[hscx
], offset
), value
);
91 * fast interrupt HSCX stuff goes here
94 #define READHSCX(cs, nr, reg) bytein(calc_off(cs->hw.spt.hscx[nr], reg))
95 #define WRITEHSCX(cs, nr, reg, data) byteout(calc_off(cs->hw.spt.hscx[nr], reg), data)
96 #define READHSCXFIFO(cs, nr, ptr, cnt) read_fifo(cs->hw.spt.hscx[nr], ptr, cnt)
97 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) write_fifo(cs->hw.spt.hscx[nr], ptr, cnt)
102 sportster_interrupt(int intno
, void *dev_id
)
104 struct IsdnCardState
*cs
= dev_id
;
108 spin_lock_irqsave(&cs
->lock
, flags
);
109 val
= READHSCX(cs
, 1, HSCX_ISTA
);
112 hscx_int_main(cs
, val
);
113 val
= ReadISAC(cs
, ISAC_ISTA
);
116 isac_interrupt(cs
, val
);
117 val
= READHSCX(cs
, 1, HSCX_ISTA
);
119 if (cs
->debug
& L1_DEB_HSCX
)
120 debugl1(cs
, "HSCX IntStat after IntRoutine");
123 val
= ReadISAC(cs
, ISAC_ISTA
);
125 if (cs
->debug
& L1_DEB_ISAC
)
126 debugl1(cs
, "ISAC IntStat after IntRoutine");
129 /* get a new irq impulse if there any pending */
130 bytein(cs
->hw
.spt
.cfg_reg
+ SPORTSTER_RES_IRQ
+1);
131 spin_unlock_irqrestore(&cs
->lock
, flags
);
136 release_io_sportster(struct IsdnCardState
*cs
)
140 byteout(cs
->hw
.spt
.cfg_reg
+ SPORTSTER_RES_IRQ
, 0);
141 for (i
=0; i
<64; i
++) {
142 adr
= cs
->hw
.spt
.cfg_reg
+ i
*1024;
143 release_region(adr
, 8);
148 reset_sportster(struct IsdnCardState
*cs
)
150 cs
->hw
.spt
.res_irq
|= SPORTSTER_RESET
; /* Reset On */
151 byteout(cs
->hw
.spt
.cfg_reg
+ SPORTSTER_RES_IRQ
, cs
->hw
.spt
.res_irq
);
153 cs
->hw
.spt
.res_irq
&= ~SPORTSTER_RESET
; /* Reset Off */
154 byteout(cs
->hw
.spt
.cfg_reg
+ SPORTSTER_RES_IRQ
, cs
->hw
.spt
.res_irq
);
159 Sportster_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
165 spin_lock_irqsave(&cs
->lock
, flags
);
167 spin_unlock_irqrestore(&cs
->lock
, flags
);
170 release_io_sportster(cs
);
173 spin_lock_irqsave(&cs
->lock
, flags
);
176 cs
->hw
.spt
.res_irq
|= SPORTSTER_INTE
; /* IRQ On */
177 byteout(cs
->hw
.spt
.cfg_reg
+ SPORTSTER_RES_IRQ
, cs
->hw
.spt
.res_irq
);
179 spin_unlock_irqrestore(&cs
->lock
, flags
);
188 get_io_range(struct IsdnCardState
*cs
)
193 adr
= cs
->hw
.spt
.cfg_reg
+ i
*1024;
194 if (!request_region(adr
, 8, "sportster")) {
196 "HiSax: %s config port %x-%x already in use\n",
197 CardType
[cs
->typ
], adr
, adr
+ 8);
204 for (j
=0; j
<i
; j
++) {
205 adr
= cs
->hw
.spt
.cfg_reg
+ j
*1024;
206 release_region(adr
, 8);
213 setup_sportster(struct IsdnCard
*card
)
215 struct IsdnCardState
*cs
= card
->cs
;
218 strcpy(tmp
, sportster_revision
);
219 printk(KERN_INFO
"HiSax: USR Sportster driver Rev. %s\n", HiSax_getrev(tmp
));
220 if (cs
->typ
!= ISDN_CTYPE_SPORTSTER
)
223 cs
->hw
.spt
.cfg_reg
= card
->para
[1];
224 cs
->irq
= card
->para
[0];
225 if (!get_io_range(cs
))
227 cs
->hw
.spt
.isac
= cs
->hw
.spt
.cfg_reg
+ SPORTSTER_ISAC
;
228 cs
->hw
.spt
.hscx
[0] = cs
->hw
.spt
.cfg_reg
+ SPORTSTER_HSCXA
;
229 cs
->hw
.spt
.hscx
[1] = cs
->hw
.spt
.cfg_reg
+ SPORTSTER_HSCXB
;
232 case 5: cs
->hw
.spt
.res_irq
= 1;
234 case 7: cs
->hw
.spt
.res_irq
= 2;
236 case 10:cs
->hw
.spt
.res_irq
= 3;
238 case 11:cs
->hw
.spt
.res_irq
= 4;
240 case 12:cs
->hw
.spt
.res_irq
= 5;
242 case 14:cs
->hw
.spt
.res_irq
= 6;
244 case 15:cs
->hw
.spt
.res_irq
= 7;
246 default:release_io_sportster(cs
);
247 printk(KERN_WARNING
"Sportster: wrong IRQ\n");
250 printk(KERN_INFO
"HiSax: %s config irq:%d cfg:0x%X\n",
251 CardType
[cs
->typ
], cs
->irq
, cs
->hw
.spt
.cfg_reg
);
253 cs
->readisac
= &ReadISAC
;
254 cs
->writeisac
= &WriteISAC
;
255 cs
->readisacfifo
= &ReadISACfifo
;
256 cs
->writeisacfifo
= &WriteISACfifo
;
257 cs
->BC_Read_Reg
= &ReadHSCX
;
258 cs
->BC_Write_Reg
= &WriteHSCX
;
259 cs
->BC_Send_Data
= &hscx_fill_fifo
;
260 cs
->cardmsg
= &Sportster_card_msg
;
261 cs
->irq_func
= &sportster_interrupt
;
262 ISACVersion(cs
, "Sportster:");
263 if (HscxVersion(cs
, "Sportster:")) {
265 "Sportster: wrong HSCX versions check IO address\n");
266 release_io_sportster(cs
);