1 /* $Id: isurf.c,v 1.12.2.4 2004/01/13 21:46:03 keil Exp $
3 * low level stuff for Siemens I-Surf/I-Talk cards
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.
13 #include <linux/init.h>
18 #include <linux/isapnp.h>
20 static const char *ISurf_revision
= "$Revision: 1.12.2.4 $";
22 #define byteout(addr, val) outb(val, addr)
23 #define bytein(addr) inb(addr)
25 #define ISURF_ISAR_RESET 1
26 #define ISURF_ISAC_RESET 2
27 #define ISURF_ISAR_EA 4
28 #define ISURF_ARCOFI_RESET 8
29 #define ISURF_RESET (ISURF_ISAR_RESET | ISURF_ISAC_RESET | ISURF_ARCOFI_RESET)
31 #define ISURF_ISAR_OFFSET 0
32 #define ISURF_ISAC_OFFSET 0x100
33 #define ISURF_IOMEM_SIZE 0x400
34 /* Interface functions */
37 ReadISAC(struct IsdnCardState
*cs
, u_char offset
)
39 return (readb(cs
->hw
.isurf
.isac
+ offset
));
43 WriteISAC(struct IsdnCardState
*cs
, u_char offset
, u_char value
)
45 writeb(value
, cs
->hw
.isurf
.isac
+ offset
); mb();
49 ReadISACfifo(struct IsdnCardState
*cs
, u_char
*data
, int size
)
52 for (i
= 0; i
< size
; i
++)
53 data
[i
] = readb(cs
->hw
.isurf
.isac
);
57 WriteISACfifo(struct IsdnCardState
*cs
, u_char
*data
, int size
)
60 for (i
= 0; i
< size
; i
++) {
61 writeb(data
[i
], cs
->hw
.isurf
.isac
); mb();
65 /* ISAR access routines
66 * mode = 0 access with IRQ on
67 * mode = 1 access with IRQ off
68 * mode = 2 access with IRQ off and using last offset
72 ReadISAR(struct IsdnCardState
*cs
, int mode
, u_char offset
)
74 return (readb(cs
->hw
.isurf
.isar
+ offset
));
78 WriteISAR(struct IsdnCardState
*cs
, int mode
, u_char offset
, u_char value
)
80 writeb(value
, cs
->hw
.isurf
.isar
+ offset
); mb();
84 isurf_interrupt(int intno
, void *dev_id
)
86 struct IsdnCardState
*cs
= dev_id
;
91 spin_lock_irqsave(&cs
->lock
, flags
);
92 val
= readb(cs
->hw
.isurf
.isar
+ ISAR_IRQBIT
);
94 if (val
& ISAR_IRQSTA
)
96 val
= readb(cs
->hw
.isurf
.isac
+ ISAC_ISTA
);
99 isac_interrupt(cs
, val
);
100 val
= readb(cs
->hw
.isurf
.isar
+ ISAR_IRQBIT
);
101 if ((val
& ISAR_IRQSTA
) && --cnt
) {
102 if (cs
->debug
& L1_DEB_HSCX
)
103 debugl1(cs
, "ISAR IntStat after IntRoutine");
106 val
= readb(cs
->hw
.isurf
.isac
+ ISAC_ISTA
);
108 if (cs
->debug
& L1_DEB_ISAC
)
109 debugl1(cs
, "ISAC IntStat after IntRoutine");
113 printk(KERN_WARNING
"ISurf IRQ LOOP\n");
115 writeb(0, cs
->hw
.isurf
.isar
+ ISAR_IRQBIT
); mb();
116 writeb(0xFF, cs
->hw
.isurf
.isac
+ ISAC_MASK
); mb();
117 writeb(0, cs
->hw
.isurf
.isac
+ ISAC_MASK
); mb();
118 writeb(ISAR_IRQMSK
, cs
->hw
.isurf
.isar
+ ISAR_IRQBIT
); mb();
119 spin_unlock_irqrestore(&cs
->lock
, flags
);
124 release_io_isurf(struct IsdnCardState
*cs
)
126 release_region(cs
->hw
.isurf
.reset
, 1);
127 iounmap(cs
->hw
.isurf
.isar
);
128 release_mem_region(cs
->hw
.isurf
.phymem
, ISURF_IOMEM_SIZE
);
132 reset_isurf(struct IsdnCardState
*cs
, u_char chips
)
134 printk(KERN_INFO
"ISurf: resetting card\n");
136 byteout(cs
->hw
.isurf
.reset
, chips
); /* Reset On */
138 byteout(cs
->hw
.isurf
.reset
, ISURF_ISAR_EA
); /* Reset Off */
143 ISurf_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
149 spin_lock_irqsave(&cs
->lock
, flags
);
150 reset_isurf(cs
, ISURF_RESET
);
151 spin_unlock_irqrestore(&cs
->lock
, flags
);
154 release_io_isurf(cs
);
157 spin_lock_irqsave(&cs
->lock
, flags
);
158 reset_isurf(cs
, ISURF_RESET
);
159 clear_pending_isac_ints(cs
);
160 writeb(0, cs
->hw
.isurf
.isar
+ ISAR_IRQBIT
); mb();
163 /* Reenable ISAC IRQ */
164 cs
->writeisac(cs
, ISAC_MASK
, 0);
165 /* RESET Receiver and Transmitter */
166 cs
->writeisac(cs
, ISAC_CMDR
, 0x41);
167 spin_unlock_irqrestore(&cs
->lock
, flags
);
176 isurf_auxcmd(struct IsdnCardState
*cs
, isdn_ctrl
*ic
) {
180 if ((ic
->command
== ISDN_CMD_IOCTL
) && (ic
->arg
== 9)) {
181 ret
= isar_auxcmd(cs
, ic
);
182 spin_lock_irqsave(&cs
->lock
, flags
);
184 reset_isurf(cs
, ISURF_ISAR_EA
| ISURF_ISAC_RESET
|
187 cs
->writeisac(cs
, ISAC_MASK
, 0);
188 cs
->writeisac(cs
, ISAC_CMDR
, 0x41);
190 spin_unlock_irqrestore(&cs
->lock
, flags
);
193 return (isar_auxcmd(cs
, ic
));
197 static struct pnp_card
*pnp_c
= NULL
;
200 int setup_isurf(struct IsdnCard
*card
)
203 struct IsdnCardState
*cs
= card
->cs
;
206 strcpy(tmp
, ISurf_revision
);
207 printk(KERN_INFO
"HiSax: ISurf driver Rev. %s\n", HiSax_getrev(tmp
));
209 if (cs
->typ
!= ISDN_CTYPE_ISURF
)
211 if (card
->para
[1] && card
->para
[2]) {
212 cs
->hw
.isurf
.reset
= card
->para
[1];
213 cs
->hw
.isurf
.phymem
= card
->para
[2];
214 cs
->irq
= card
->para
[0];
217 if (isapnp_present()) {
218 struct pnp_dev
*pnp_d
= NULL
;
222 if ((pnp_c
= pnp_find_card(
223 ISAPNP_VENDOR('S', 'I', 'E'),
224 ISAPNP_FUNCTION(0x0010), pnp_c
))) {
225 if (!(pnp_d
= pnp_find_dev(pnp_c
,
226 ISAPNP_VENDOR('S', 'I', 'E'),
227 ISAPNP_FUNCTION(0x0010), pnp_d
))) {
228 printk(KERN_ERR
"ISurfPnP: PnP error card found, no device\n");
231 pnp_disable_dev(pnp_d
);
232 err
= pnp_activate_dev(pnp_d
);
234 pr_warn("%s: pnp_activate_dev ret=%d\n",
238 cs
->hw
.isurf
.reset
= pnp_port_start(pnp_d
, 0);
239 cs
->hw
.isurf
.phymem
= pnp_mem_start(pnp_d
, 1);
240 cs
->irq
= pnp_irq(pnp_d
, 0);
241 if (!cs
->irq
|| !cs
->hw
.isurf
.reset
|| !cs
->hw
.isurf
.phymem
) {
242 printk(KERN_ERR
"ISurfPnP:some resources are missing %d/%x/%lx\n",
243 cs
->irq
, cs
->hw
.isurf
.reset
, cs
->hw
.isurf
.phymem
);
244 pnp_disable_dev(pnp_d
);
248 printk(KERN_INFO
"ISurfPnP: no ISAPnP card found\n");
252 printk(KERN_INFO
"ISurfPnP: no ISAPnP bus found\n");
256 printk(KERN_WARNING
"HiSax: Siemens I-Surf port/mem not set\n");
260 if (!request_region(cs
->hw
.isurf
.reset
, 1, "isurf isdn")) {
262 "HiSax: Siemens I-Surf config port %x already in use\n",
266 if (!request_region(cs
->hw
.isurf
.phymem
, ISURF_IOMEM_SIZE
, "isurf iomem")) {
267 printk(KERN_WARNING
"HiSax: Siemens I-Surf memory region "
268 "%lx-%lx already in use\n",
270 cs
->hw
.isurf
.phymem
+ ISURF_IOMEM_SIZE
);
271 release_region(cs
->hw
.isurf
.reset
, 1);
274 cs
->hw
.isurf
.isar
= ioremap(cs
->hw
.isurf
.phymem
, ISURF_IOMEM_SIZE
);
275 cs
->hw
.isurf
.isac
= cs
->hw
.isurf
.isar
+ ISURF_ISAC_OFFSET
;
277 "ISurf: defined at 0x%x 0x%lx IRQ %d\n",
283 cs
->cardmsg
= &ISurf_card_msg
;
284 cs
->irq_func
= &isurf_interrupt
;
285 cs
->auxcmd
= &isurf_auxcmd
;
286 cs
->readisac
= &ReadISAC
;
287 cs
->writeisac
= &WriteISAC
;
288 cs
->readisacfifo
= &ReadISACfifo
;
289 cs
->writeisacfifo
= &WriteISACfifo
;
290 cs
->bcs
[0].hw
.isar
.reg
= &cs
->hw
.isurf
.isar_r
;
291 cs
->bcs
[1].hw
.isar
.reg
= &cs
->hw
.isurf
.isar_r
;
292 test_and_set_bit(HW_ISAR
, &cs
->HW_Flags
);
293 ISACVersion(cs
, "ISurf:");
294 cs
->BC_Read_Reg
= &ReadISAR
;
295 cs
->BC_Write_Reg
= &WriteISAR
;
296 cs
->BC_Send_Data
= &isar_fill_fifo
;
297 ver
= ISARVersion(cs
, "ISurf:");
300 "ISurf: wrong ISAR version (ret = %d)\n", ver
);
301 release_io_isurf(cs
);