1 /* $Id: ix1_micro.c,v 2.12.2.4 2004/01/13 23:48:39 keil Exp $
3 * low level stuff for ITK ix1-micro Rev.2 isdn cards
4 * derived from the original file teles3.c from Karsten Keil
6 * Author Klaus-Peter Nischke
7 * Copyright by Klaus-Peter Nischke, ITK AG
8 * <klaus@nischke.do.eunet.de>
9 * by Karsten Keil <keil@isdn4linux.de>
11 * This software may be used and distributed according to the terms
12 * of the GNU General Public License, incorporated herein by reference.
20 #include <linux/init.h>
21 #include <linux/isapnp.h>
27 extern const char *CardType
[];
28 static const char *ix1_revision
= "$Revision: 2.12.2.4 $";
30 #define byteout(addr,val) outb(val,addr)
31 #define bytein(addr) inb(addr)
33 #define SPECIAL_PORT_OFFSET 3
35 #define ISAC_COMMAND_OFFSET 2
36 #define ISAC_DATA_OFFSET 0
37 #define HSCX_COMMAND_OFFSET 2
38 #define HSCX_DATA_OFFSET 1
43 readreg(unsigned int ale
, unsigned int adr
, u_char off
)
53 readfifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
56 insb(adr
, data
, size
);
61 writereg(unsigned int ale
, unsigned int adr
, u_char off
, u_char data
)
68 writefifo(unsigned int ale
, unsigned int adr
, u_char off
, u_char
* data
, int size
)
71 outsb(adr
, data
, size
);
74 /* Interface functions */
77 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
79 return (readreg(cs
->hw
.ix1
.isac_ale
, cs
->hw
.ix1
.isac
, offset
));
83 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
85 writereg(cs
->hw
.ix1
.isac_ale
, cs
->hw
.ix1
.isac
, offset
, value
);
89 ReadISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
91 readfifo(cs
->hw
.ix1
.isac_ale
, cs
->hw
.ix1
.isac
, 0, data
, size
);
95 WriteISACfifo(struct IsdnCardState
*cs
, u_char
* data
, int size
)
97 writefifo(cs
->hw
.ix1
.isac_ale
, cs
->hw
.ix1
.isac
, 0, data
, size
);
101 ReadHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
)
103 return (readreg(cs
->hw
.ix1
.hscx_ale
,
104 cs
->hw
.ix1
.hscx
, offset
+ (hscx
? 0x40 : 0)));
108 WriteHSCX(struct IsdnCardState
*cs
, int hscx
, u_char offset
, u_char value
)
110 writereg(cs
->hw
.ix1
.hscx_ale
,
111 cs
->hw
.ix1
.hscx
, offset
+ (hscx
? 0x40 : 0), value
);
114 #define READHSCX(cs, nr, reg) readreg(cs->hw.ix1.hscx_ale, \
115 cs->hw.ix1.hscx, reg + (nr ? 0x40 : 0))
116 #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.ix1.hscx_ale, \
117 cs->hw.ix1.hscx, reg + (nr ? 0x40 : 0), data)
119 #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.ix1.hscx_ale, \
120 cs->hw.ix1.hscx, (nr ? 0x40 : 0), ptr, cnt)
122 #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.ix1.hscx_ale, \
123 cs->hw.ix1.hscx, (nr ? 0x40 : 0), ptr, cnt)
125 #include "hscx_irq.c"
128 ix1micro_interrupt(int intno
, void *dev_id
)
130 struct IsdnCardState
*cs
= dev_id
;
134 spin_lock_irqsave(&cs
->lock
, flags
);
135 val
= readreg(cs
->hw
.ix1
.hscx_ale
, cs
->hw
.ix1
.hscx
, HSCX_ISTA
+ 0x40);
138 hscx_int_main(cs
, val
);
139 val
= readreg(cs
->hw
.ix1
.isac_ale
, cs
->hw
.ix1
.isac
, ISAC_ISTA
);
142 isac_interrupt(cs
, val
);
143 val
= readreg(cs
->hw
.ix1
.hscx_ale
, cs
->hw
.ix1
.hscx
, HSCX_ISTA
+ 0x40);
145 if (cs
->debug
& L1_DEB_HSCX
)
146 debugl1(cs
, "HSCX IntStat after IntRoutine");
149 val
= readreg(cs
->hw
.ix1
.isac_ale
, cs
->hw
.ix1
.isac
, ISAC_ISTA
);
151 if (cs
->debug
& L1_DEB_ISAC
)
152 debugl1(cs
, "ISAC IntStat after IntRoutine");
155 writereg(cs
->hw
.ix1
.hscx_ale
, cs
->hw
.ix1
.hscx
, HSCX_MASK
, 0xFF);
156 writereg(cs
->hw
.ix1
.hscx_ale
, cs
->hw
.ix1
.hscx
, HSCX_MASK
+ 0x40, 0xFF);
157 writereg(cs
->hw
.ix1
.isac_ale
, cs
->hw
.ix1
.isac
, ISAC_MASK
, 0xFF);
158 writereg(cs
->hw
.ix1
.isac_ale
, cs
->hw
.ix1
.isac
, ISAC_MASK
, 0);
159 writereg(cs
->hw
.ix1
.hscx_ale
, cs
->hw
.ix1
.hscx
, HSCX_MASK
, 0);
160 writereg(cs
->hw
.ix1
.hscx_ale
, cs
->hw
.ix1
.hscx
, HSCX_MASK
+ 0x40, 0);
161 spin_unlock_irqrestore(&cs
->lock
, flags
);
166 release_io_ix1micro(struct IsdnCardState
*cs
)
168 if (cs
->hw
.ix1
.cfg_reg
)
169 release_region(cs
->hw
.ix1
.cfg_reg
, 4);
173 ix1_reset(struct IsdnCardState
*cs
)
178 cnt
= 3 * (HZ
/ 10) + 1;
180 byteout(cs
->hw
.ix1
.cfg_reg
+ SPECIAL_PORT_OFFSET
, 1);
181 HZDELAY(1); /* wait >=10 ms */
183 byteout(cs
->hw
.ix1
.cfg_reg
+ SPECIAL_PORT_OFFSET
, 0);
187 ix1_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
193 spin_lock_irqsave(&cs
->lock
, flags
);
195 spin_unlock_irqrestore(&cs
->lock
, flags
);
198 release_io_ix1micro(cs
);
201 spin_lock_irqsave(&cs
->lock
, flags
);
204 spin_unlock_irqrestore(&cs
->lock
, flags
);
213 static struct isapnp_device_id itk_ids
[] __devinitdata
= {
214 { ISAPNP_VENDOR('I', 'T', 'K'), ISAPNP_FUNCTION(0x25),
215 ISAPNP_VENDOR('I', 'T', 'K'), ISAPNP_FUNCTION(0x25),
216 (unsigned long) "ITK micro 2" },
217 { ISAPNP_VENDOR('I', 'T', 'K'), ISAPNP_FUNCTION(0x29),
218 ISAPNP_VENDOR('I', 'T', 'K'), ISAPNP_FUNCTION(0x29),
219 (unsigned long) "ITK micro 2." },
223 static struct isapnp_device_id
*ipid __devinitdata
= &itk_ids
[0];
224 static struct pnp_card
*pnp_c __devinitdata
= NULL
;
229 setup_ix1micro(struct IsdnCard
*card
)
231 struct IsdnCardState
*cs
= card
->cs
;
234 strcpy(tmp
, ix1_revision
);
235 printk(KERN_INFO
"HiSax: ITK IX1 driver Rev. %s\n", HiSax_getrev(tmp
));
236 if (cs
->typ
!= ISDN_CTYPE_IX1MICROR2
)
240 if (!card
->para
[1] && isapnp_present()) {
241 struct pnp_dev
*pnp_d
;
242 while(ipid
->card_vendor
) {
243 if ((pnp_c
= pnp_find_card(ipid
->card_vendor
,
244 ipid
->card_device
, pnp_c
))) {
246 if ((pnp_d
= pnp_find_dev(pnp_c
,
247 ipid
->vendor
, ipid
->function
, pnp_d
))) {
250 printk(KERN_INFO
"HiSax: %s detected\n",
251 (char *)ipid
->driver_data
);
252 pnp_disable_dev(pnp_d
);
253 err
= pnp_activate_dev(pnp_d
);
255 printk(KERN_WARNING
"%s: pnp_activate_dev ret(%d)\n",
259 card
->para
[1] = pnp_port_start(pnp_d
, 0);
260 card
->para
[0] = pnp_irq(pnp_d
, 0);
261 if (!card
->para
[0] || !card
->para
[1]) {
262 printk(KERN_ERR
"ITK PnP:some resources are missing %ld/%lx\n",
263 card
->para
[0], card
->para
[1]);
264 pnp_disable_dev(pnp_d
);
269 printk(KERN_ERR
"ITK PnP: PnP error card found, no device\n");
275 if (!ipid
->card_vendor
) {
276 printk(KERN_INFO
"ITK PnP: no ISAPnP card found\n");
282 cs
->hw
.ix1
.isac_ale
= card
->para
[1] + ISAC_COMMAND_OFFSET
;
283 cs
->hw
.ix1
.hscx_ale
= card
->para
[1] + HSCX_COMMAND_OFFSET
;
284 cs
->hw
.ix1
.isac
= card
->para
[1] + ISAC_DATA_OFFSET
;
285 cs
->hw
.ix1
.hscx
= card
->para
[1] + HSCX_DATA_OFFSET
;
286 cs
->hw
.ix1
.cfg_reg
= card
->para
[1];
287 cs
->irq
= card
->para
[0];
288 if (cs
->hw
.ix1
.cfg_reg
) {
289 if (!request_region(cs
->hw
.ix1
.cfg_reg
, 4, "ix1micro cfg")) {
291 "HiSax: %s config port %x-%x already in use\n",
294 cs
->hw
.ix1
.cfg_reg
+ 4);
298 printk(KERN_INFO
"HiSax: %s config irq:%d io:0x%X\n",
299 CardType
[cs
->typ
], cs
->irq
, cs
->hw
.ix1
.cfg_reg
);
301 cs
->readisac
= &ReadISAC
;
302 cs
->writeisac
= &WriteISAC
;
303 cs
->readisacfifo
= &ReadISACfifo
;
304 cs
->writeisacfifo
= &WriteISACfifo
;
305 cs
->BC_Read_Reg
= &ReadHSCX
;
306 cs
->BC_Write_Reg
= &WriteHSCX
;
307 cs
->BC_Send_Data
= &hscx_fill_fifo
;
308 cs
->cardmsg
= &ix1_card_msg
;
309 cs
->irq_func
= &ix1micro_interrupt
;
310 ISACVersion(cs
, "ix1-Micro:");
311 if (HscxVersion(cs
, "ix1-Micro:")) {
313 "ix1-Micro: wrong HSCX versions check IO address\n");
314 release_io_ix1micro(cs
);