Initial commit
[wrt350n-kernel.git] / drivers / isdn / hisax / saphir.c
blobc99b16690fb32e6ed986ac5d0902e969177bde97
1 /* $Id: saphir.c,v 1.10.2.4 2004/01/13 23:48:39 keil Exp $
3 * low level stuff for HST Saphir 1
5 * Author Karsten Keil
6 * Copyright by Karsten Keil <keil@isdn4linux.de>
7 *
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 HST High Soft Tech GmbH
15 #include <linux/init.h>
16 #include "hisax.h"
17 #include "isac.h"
18 #include "hscx.h"
19 #include "isdnl1.h"
21 extern const char *CardType[];
22 static char *saphir_rev = "$Revision: 1.10.2.4 $";
24 #define byteout(addr,val) outb(val,addr)
25 #define bytein(addr) inb(addr)
27 #define ISAC_DATA 0
28 #define HSCX_DATA 1
29 #define ADDRESS_REG 2
30 #define IRQ_REG 3
31 #define SPARE_REG 4
32 #define RESET_REG 5
34 static inline u_char
35 readreg(unsigned int ale, unsigned int adr, u_char off)
37 register u_char ret;
39 byteout(ale, off);
40 ret = bytein(adr);
41 return (ret);
44 static inline void
45 readfifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
47 byteout(ale, off);
48 insb(adr, data, size);
52 static inline void
53 writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
55 byteout(ale, off);
56 byteout(adr, data);
59 static inline void
60 writefifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
62 byteout(ale, off);
63 outsb(adr, data, size);
66 /* Interface functions */
68 static u_char
69 ReadISAC(struct IsdnCardState *cs, u_char offset)
71 return (readreg(cs->hw.saphir.ale, cs->hw.saphir.isac, offset));
74 static void
75 WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
77 writereg(cs->hw.saphir.ale, cs->hw.saphir.isac, offset, value);
80 static void
81 ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
83 readfifo(cs->hw.saphir.ale, cs->hw.saphir.isac, 0, data, size);
86 static void
87 WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
89 writefifo(cs->hw.saphir.ale, cs->hw.saphir.isac, 0, data, size);
92 static u_char
93 ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
95 return (readreg(cs->hw.saphir.ale, cs->hw.saphir.hscx,
96 offset + (hscx ? 0x40 : 0)));
99 static void
100 WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
102 writereg(cs->hw.saphir.ale, cs->hw.saphir.hscx,
103 offset + (hscx ? 0x40 : 0), value);
106 #define READHSCX(cs, nr, reg) readreg(cs->hw.saphir.ale, \
107 cs->hw.saphir.hscx, reg + (nr ? 0x40 : 0))
108 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.saphir.ale, \
109 cs->hw.saphir.hscx, reg + (nr ? 0x40 : 0), data)
111 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.saphir.ale, \
112 cs->hw.saphir.hscx, (nr ? 0x40 : 0), ptr, cnt)
114 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.saphir.ale, \
115 cs->hw.saphir.hscx, (nr ? 0x40 : 0), ptr, cnt)
117 #include "hscx_irq.c"
119 static irqreturn_t
120 saphir_interrupt(int intno, void *dev_id)
122 struct IsdnCardState *cs = dev_id;
123 u_char val;
124 u_long flags;
126 spin_lock_irqsave(&cs->lock, flags);
127 val = readreg(cs->hw.saphir.ale, cs->hw.saphir.hscx, HSCX_ISTA + 0x40);
128 Start_HSCX:
129 if (val)
130 hscx_int_main(cs, val);
131 val = readreg(cs->hw.saphir.ale, cs->hw.saphir.isac, ISAC_ISTA);
132 Start_ISAC:
133 if (val)
134 isac_interrupt(cs, val);
135 val = readreg(cs->hw.saphir.ale, cs->hw.saphir.hscx, HSCX_ISTA + 0x40);
136 if (val) {
137 if (cs->debug & L1_DEB_HSCX)
138 debugl1(cs, "HSCX IntStat after IntRoutine");
139 goto Start_HSCX;
141 val = readreg(cs->hw.saphir.ale, cs->hw.saphir.isac, ISAC_ISTA);
142 if (val) {
143 if (cs->debug & L1_DEB_ISAC)
144 debugl1(cs, "ISAC IntStat after IntRoutine");
145 goto Start_ISAC;
147 /* Watchdog */
148 if (cs->hw.saphir.timer.function)
149 mod_timer(&cs->hw.saphir.timer, jiffies+1*HZ);
150 else
151 printk(KERN_WARNING "saphir: Spurious timer!\n");
152 writereg(cs->hw.saphir.ale, cs->hw.saphir.hscx, HSCX_MASK, 0xFF);
153 writereg(cs->hw.saphir.ale, cs->hw.saphir.hscx, HSCX_MASK + 0x40, 0xFF);
154 writereg(cs->hw.saphir.ale, cs->hw.saphir.isac, ISAC_MASK, 0xFF);
155 writereg(cs->hw.saphir.ale, cs->hw.saphir.isac, ISAC_MASK, 0);
156 writereg(cs->hw.saphir.ale, cs->hw.saphir.hscx, HSCX_MASK, 0);
157 writereg(cs->hw.saphir.ale, cs->hw.saphir.hscx, HSCX_MASK + 0x40, 0);
158 spin_unlock_irqrestore(&cs->lock, flags);
159 return IRQ_HANDLED;
162 static void
163 SaphirWatchDog(struct IsdnCardState *cs)
165 u_long flags;
167 spin_lock_irqsave(&cs->lock, flags);
168 /* 5 sec WatchDog, so read at least every 4 sec */
169 cs->readisac(cs, ISAC_RBCH);
170 spin_unlock_irqrestore(&cs->lock, flags);
171 mod_timer(&cs->hw.saphir.timer, jiffies+1*HZ);
174 static void
175 release_io_saphir(struct IsdnCardState *cs)
177 byteout(cs->hw.saphir.cfg_reg + IRQ_REG, 0xff);
178 del_timer(&cs->hw.saphir.timer);
179 cs->hw.saphir.timer.function = NULL;
180 if (cs->hw.saphir.cfg_reg)
181 release_region(cs->hw.saphir.cfg_reg, 6);
184 static int
185 saphir_reset(struct IsdnCardState *cs)
187 u_char irq_val;
189 switch(cs->irq) {
190 case 5: irq_val = 0;
191 break;
192 case 3: irq_val = 1;
193 break;
194 case 11:
195 irq_val = 2;
196 break;
197 case 12:
198 irq_val = 3;
199 break;
200 case 15:
201 irq_val = 4;
202 break;
203 default:
204 printk(KERN_WARNING "HiSax: saphir wrong IRQ %d\n",
205 cs->irq);
206 return (1);
208 byteout(cs->hw.saphir.cfg_reg + IRQ_REG, irq_val);
209 byteout(cs->hw.saphir.cfg_reg + RESET_REG, 1);
210 mdelay(10);
211 byteout(cs->hw.saphir.cfg_reg + RESET_REG, 0);
212 mdelay(10);
213 byteout(cs->hw.saphir.cfg_reg + IRQ_REG, irq_val);
214 byteout(cs->hw.saphir.cfg_reg + SPARE_REG, 0x02);
215 return (0);
218 static int
219 saphir_card_msg(struct IsdnCardState *cs, int mt, void *arg)
221 u_long flags;
223 switch (mt) {
224 case CARD_RESET:
225 spin_lock_irqsave(&cs->lock, flags);
226 saphir_reset(cs);
227 spin_unlock_irqrestore(&cs->lock, flags);
228 return(0);
229 case CARD_RELEASE:
230 release_io_saphir(cs);
231 return(0);
232 case CARD_INIT:
233 spin_lock_irqsave(&cs->lock, flags);
234 inithscxisac(cs, 3);
235 spin_unlock_irqrestore(&cs->lock, flags);
236 return(0);
237 case CARD_TEST:
238 return(0);
240 return(0);
244 int __devinit
245 setup_saphir(struct IsdnCard *card)
247 struct IsdnCardState *cs = card->cs;
248 char tmp[64];
250 strcpy(tmp, saphir_rev);
251 printk(KERN_INFO "HiSax: HST Saphir driver Rev. %s\n", HiSax_getrev(tmp));
252 if (cs->typ != ISDN_CTYPE_HSTSAPHIR)
253 return (0);
255 /* IO-Ports */
256 cs->hw.saphir.cfg_reg = card->para[1];
257 cs->hw.saphir.isac = card->para[1] + ISAC_DATA;
258 cs->hw.saphir.hscx = card->para[1] + HSCX_DATA;
259 cs->hw.saphir.ale = card->para[1] + ADDRESS_REG;
260 cs->irq = card->para[0];
261 if (!request_region(cs->hw.saphir.cfg_reg, 6, "saphir")) {
262 printk(KERN_WARNING
263 "HiSax: %s config port %x-%x already in use\n",
264 CardType[card->typ],
265 cs->hw.saphir.cfg_reg,
266 cs->hw.saphir.cfg_reg + 5);
267 return (0);
270 printk(KERN_INFO "HiSax: %s config irq:%d io:0x%X\n",
271 CardType[cs->typ], cs->irq, cs->hw.saphir.cfg_reg);
273 setup_isac(cs);
274 cs->hw.saphir.timer.function = (void *) SaphirWatchDog;
275 cs->hw.saphir.timer.data = (long) cs;
276 init_timer(&cs->hw.saphir.timer);
277 cs->hw.saphir.timer.expires = jiffies + 4*HZ;
278 add_timer(&cs->hw.saphir.timer);
279 if (saphir_reset(cs)) {
280 release_io_saphir(cs);
281 return (0);
283 cs->readisac = &ReadISAC;
284 cs->writeisac = &WriteISAC;
285 cs->readisacfifo = &ReadISACfifo;
286 cs->writeisacfifo = &WriteISACfifo;
287 cs->BC_Read_Reg = &ReadHSCX;
288 cs->BC_Write_Reg = &WriteHSCX;
289 cs->BC_Send_Data = &hscx_fill_fifo;
290 cs->cardmsg = &saphir_card_msg;
291 cs->irq_func = &saphir_interrupt;
292 ISACVersion(cs, "saphir:");
293 if (HscxVersion(cs, "saphir:")) {
294 printk(KERN_WARNING
295 "saphir: wrong HSCX versions check IO address\n");
296 release_io_saphir(cs);
297 return (0);
299 return (1);