aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/hisax/saphir.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/isdn/hisax/saphir.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/isdn/hisax/saphir.c')
-rw-r--r--drivers/isdn/hisax/saphir.c300
1 files changed, 300 insertions, 0 deletions
diff --git a/drivers/isdn/hisax/saphir.c b/drivers/isdn/hisax/saphir.c
new file mode 100644
index 000000000000..9e6d3d686cce
--- /dev/null
+++ b/drivers/isdn/hisax/saphir.c
@@ -0,0 +1,300 @@
1/* $Id: saphir.c,v 1.10.2.4 2004/01/13 23:48:39 keil Exp $
2 *
3 * low level stuff for HST Saphir 1
4 *
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.
10 *
11 * Thanks to HST High Soft Tech GmbH
12 *
13 */
14
15#include <linux/init.h>
16#include "hisax.h"
17#include "isac.h"
18#include "hscx.h"
19#include "isdnl1.h"
20
21extern const char *CardType[];
22static char *saphir_rev = "$Revision: 1.10.2.4 $";
23
24#define byteout(addr,val) outb(val,addr)
25#define bytein(addr) inb(addr)
26
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
33
34static inline u_char
35readreg(unsigned int ale, unsigned int adr, u_char off)
36{
37 register u_char ret;
38
39 byteout(ale, off);
40 ret = bytein(adr);
41 return (ret);
42}
43
44static inline void
45readfifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
46{
47 byteout(ale, off);
48 insb(adr, data, size);
49}
50
51
52static inline void
53writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
54{
55 byteout(ale, off);
56 byteout(adr, data);
57}
58
59static inline void
60writefifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
61{
62 byteout(ale, off);
63 outsb(adr, data, size);
64}
65
66/* Interface functions */
67
68static u_char
69ReadISAC(struct IsdnCardState *cs, u_char offset)
70{
71 return (readreg(cs->hw.saphir.ale, cs->hw.saphir.isac, offset));
72}
73
74static void
75WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
76{
77 writereg(cs->hw.saphir.ale, cs->hw.saphir.isac, offset, value);
78}
79
80static void
81ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
82{
83 readfifo(cs->hw.saphir.ale, cs->hw.saphir.isac, 0, data, size);
84}
85
86static void
87WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
88{
89 writefifo(cs->hw.saphir.ale, cs->hw.saphir.isac, 0, data, size);
90}
91
92static u_char
93ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
94{
95 return (readreg(cs->hw.saphir.ale, cs->hw.saphir.hscx,
96 offset + (hscx ? 0x40 : 0)));
97}
98
99static void
100WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
101{
102 writereg(cs->hw.saphir.ale, cs->hw.saphir.hscx,
103 offset + (hscx ? 0x40 : 0), value);
104}
105
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)
110
111#define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.saphir.ale, \
112 cs->hw.saphir.hscx, (nr ? 0x40 : 0), ptr, cnt)
113
114#define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.saphir.ale, \
115 cs->hw.saphir.hscx, (nr ? 0x40 : 0), ptr, cnt)
116
117#include "hscx_irq.c"
118
119static irqreturn_t
120saphir_interrupt(int intno, void *dev_id, struct pt_regs *regs)
121{
122 struct IsdnCardState *cs = dev_id;
123 u_char val;
124 u_long flags;
125
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;
140 }
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;
146 }
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;
160}
161
162static void
163SaphirWatchDog(struct IsdnCardState *cs)
164{
165 u_long flags;
166
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);
172}
173
174void
175release_io_saphir(struct IsdnCardState *cs)
176{
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);
182}
183
184static int
185saphir_reset(struct IsdnCardState *cs)
186{
187 u_char irq_val;
188
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);
207 }
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);
216}
217
218static int
219saphir_card_msg(struct IsdnCardState *cs, int mt, void *arg)
220{
221 u_long flags;
222
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);
239 }
240 return(0);
241}
242
243
244int __init
245setup_saphir(struct IsdnCard *card)
246{
247 struct IsdnCardState *cs = card->cs;
248 char tmp[64];
249
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);
254
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);
268 }
269
270 printk(KERN_INFO "HiSax: %s config irq:%d io:0x%X\n",
271 CardType[cs->typ], cs->irq, cs->hw.saphir.cfg_reg);
272
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);
282 }
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);
298 }
299 return (1);
300}