blob: 1399ddd4f6cb3b62bdae723b63e0ffe86461a615 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: isurf.c,v 1.12.2.4 2004/01/13 21:46:03 keil Exp $
2 *
3 * low level stuff for Siemens I-Surf/I-Talk cards
4 *
5 * Author Karsten Keil
6 * Copyright by Karsten Keil <keil@isdn4linux.de>
Joe Perches475be4d2012-02-19 19:52:38 -08007 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
10 *
11 */
12
13#include <linux/init.h>
14#include "hisax.h"
15#include "isac.h"
16#include "isar.h"
17#include "isdnl1.h"
18#include <linux/isapnp.h>
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020static const char *ISurf_revision = "$Revision: 1.12.2.4 $";
21
Joe Perches475be4d2012-02-19 19:52:38 -080022#define byteout(addr, val) outb(val, addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#define bytein(addr) inb(addr)
24
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)
30
31#define ISURF_ISAR_OFFSET 0
32#define ISURF_ISAC_OFFSET 0x100
33#define ISURF_IOMEM_SIZE 0x400
34/* Interface functions */
35
36static u_char
37ReadISAC(struct IsdnCardState *cs, u_char offset)
38{
39 return (readb(cs->hw.isurf.isac + offset));
40}
41
42static void
43WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
44{
45 writeb(value, cs->hw.isurf.isac + offset); mb();
46}
47
48static void
Joe Perches475be4d2012-02-19 19:52:38 -080049ReadISACfifo(struct IsdnCardState *cs, u_char *data, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
51 register int i;
52 for (i = 0; i < size; i++)
53 data[i] = readb(cs->hw.isurf.isac);
54}
55
56static void
Joe Perches475be4d2012-02-19 19:52:38 -080057WriteISACfifo(struct IsdnCardState *cs, u_char *data, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
59 register int i;
Joe Perches475be4d2012-02-19 19:52:38 -080060 for (i = 0; i < size; i++) {
61 writeb(data[i], cs->hw.isurf.isac); mb();
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 }
63}
64
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
69 */
Joe Perches475be4d2012-02-19 19:52:38 -080070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071static u_char
72ReadISAR(struct IsdnCardState *cs, int mode, u_char offset)
Joe Perches475be4d2012-02-19 19:52:38 -080073{
74 return (readb(cs->hw.isurf.isar + offset));
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
76
77static void
78WriteISAR(struct IsdnCardState *cs, int mode, u_char offset, u_char value)
79{
Joe Perches475be4d2012-02-19 19:52:38 -080080 writeb(value, cs->hw.isurf.isar + offset); mb();
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
83static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +010084isurf_interrupt(int intno, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
86 struct IsdnCardState *cs = dev_id;
87 u_char val;
88 int cnt = 5;
89 u_long flags;
90
91 spin_lock_irqsave(&cs->lock, flags);
92 val = readb(cs->hw.isurf.isar + ISAR_IRQBIT);
Joe Perches475be4d2012-02-19 19:52:38 -080093Start_ISAR:
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 if (val & ISAR_IRQSTA)
95 isar_int_main(cs);
96 val = readb(cs->hw.isurf.isac + ISAC_ISTA);
Joe Perches475be4d2012-02-19 19:52:38 -080097Start_ISAC:
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 if (val)
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");
104 goto Start_ISAR;
105 }
106 val = readb(cs->hw.isurf.isac + ISAC_ISTA);
107 if (val && --cnt) {
108 if (cs->debug & L1_DEB_ISAC)
109 debugl1(cs, "ISAC IntStat after IntRoutine");
110 goto Start_ISAC;
111 }
112 if (!cnt)
113 printk(KERN_WARNING "ISurf IRQ LOOP\n");
114
115 writeb(0, cs->hw.isurf.isar + ISAR_IRQBIT); mb();
Joe Perches475be4d2012-02-19 19:52:38 -0800116 writeb(0xFF, cs->hw.isurf.isac + ISAC_MASK); mb();
117 writeb(0, cs->hw.isurf.isac + ISAC_MASK); mb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 writeb(ISAR_IRQMSK, cs->hw.isurf.isar + ISAR_IRQBIT); mb();
119 spin_unlock_irqrestore(&cs->lock, flags);
120 return IRQ_HANDLED;
121}
122
Adrian Bunk672c3fd2005-06-25 14:59:18 -0700123static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124release_io_isurf(struct IsdnCardState *cs)
125{
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);
129}
130
131static void
132reset_isurf(struct IsdnCardState *cs, u_char chips)
133{
134 printk(KERN_INFO "ISurf: resetting card\n");
135
136 byteout(cs->hw.isurf.reset, chips); /* Reset On */
137 mdelay(10);
138 byteout(cs->hw.isurf.reset, ISURF_ISAR_EA); /* Reset Off */
139 mdelay(10);
140}
141
142static int
143ISurf_card_msg(struct IsdnCardState *cs, int mt, void *arg)
144{
145 u_long flags;
146
147 switch (mt) {
Joe Perches475be4d2012-02-19 19:52:38 -0800148 case CARD_RESET:
149 spin_lock_irqsave(&cs->lock, flags);
150 reset_isurf(cs, ISURF_RESET);
151 spin_unlock_irqrestore(&cs->lock, flags);
152 return (0);
153 case CARD_RELEASE:
154 release_io_isurf(cs);
155 return (0);
156 case CARD_INIT:
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();
161 initisac(cs);
162 initisar(cs);
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);
168 return (0);
169 case CARD_TEST:
170 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 }
Joe Perches475be4d2012-02-19 19:52:38 -0800172 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173}
174
175static int
176isurf_auxcmd(struct IsdnCardState *cs, isdn_ctrl *ic) {
177 int ret;
178 u_long flags;
179
180 if ((ic->command == ISDN_CMD_IOCTL) && (ic->arg == 9)) {
181 ret = isar_auxcmd(cs, ic);
182 spin_lock_irqsave(&cs->lock, flags);
183 if (!ret) {
184 reset_isurf(cs, ISURF_ISAR_EA | ISURF_ISAC_RESET |
Joe Perches475be4d2012-02-19 19:52:38 -0800185 ISURF_ARCOFI_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 initisac(cs);
187 cs->writeisac(cs, ISAC_MASK, 0);
188 cs->writeisac(cs, ISAC_CMDR, 0x41);
189 }
190 spin_unlock_irqrestore(&cs->lock, flags);
Joe Perches475be4d2012-02-19 19:52:38 -0800191 return (ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 }
Joe Perches475be4d2012-02-19 19:52:38 -0800193 return (isar_auxcmd(cs, ic));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194}
195
196#ifdef __ISAPNP__
Greg Kroah-Hartmaned5a84c2012-12-21 13:13:05 -0800197static struct pnp_card *pnp_c = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#endif
199
Greg Kroah-Hartmaned5a84c2012-12-21 13:13:05 -0800200int setup_isurf(struct IsdnCard *card)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
202 int ver;
203 struct IsdnCardState *cs = card->cs;
204 char tmp[64];
205
206 strcpy(tmp, ISurf_revision);
207 printk(KERN_INFO "HiSax: ISurf driver Rev. %s\n", HiSax_getrev(tmp));
Joe Perches475be4d2012-02-19 19:52:38 -0800208
209 if (cs->typ != ISDN_CTYPE_ISURF)
210 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 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];
215 } else {
216#ifdef __ISAPNP__
217 if (isapnp_present()) {
218 struct pnp_dev *pnp_d = NULL;
219 int err;
220
221 cs->subtyp = 0;
222 if ((pnp_c = pnp_find_card(
Joe Perches475be4d2012-02-19 19:52:38 -0800223 ISAPNP_VENDOR('S', 'I', 'E'),
224 ISAPNP_FUNCTION(0x0010), pnp_c))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 if (!(pnp_d = pnp_find_dev(pnp_c,
Joe Perches475be4d2012-02-19 19:52:38 -0800226 ISAPNP_VENDOR('S', 'I', 'E'),
227 ISAPNP_FUNCTION(0x0010), pnp_d))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 printk(KERN_ERR "ISurfPnP: PnP error card found, no device\n");
229 return (0);
230 }
231 pnp_disable_dev(pnp_d);
232 err = pnp_activate_dev(pnp_d);
Karsten Keil5b999fd2012-07-12 07:01:10 +0000233 if (err < 0) {
234 pr_warn("%s: pnp_activate_dev ret=%d\n",
235 __func__, err);
236 return 0;
237 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 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",
Joe Perches475be4d2012-02-19 19:52:38 -0800243 cs->irq, cs->hw.isurf.reset, cs->hw.isurf.phymem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 pnp_disable_dev(pnp_d);
Joe Perches475be4d2012-02-19 19:52:38 -0800245 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 }
247 } else {
248 printk(KERN_INFO "ISurfPnP: no ISAPnP card found\n");
Joe Perches475be4d2012-02-19 19:52:38 -0800249 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
251 } else {
252 printk(KERN_INFO "ISurfPnP: no ISAPnP bus found\n");
Joe Perches475be4d2012-02-19 19:52:38 -0800253 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 }
255#else
Jeff Garzik83493042007-10-31 03:42:07 -0400256 printk(KERN_WARNING "HiSax: Siemens I-Surf port/mem not set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 return (0);
258#endif
259 }
260 if (!request_region(cs->hw.isurf.reset, 1, "isurf isdn")) {
261 printk(KERN_WARNING
Joe Perches475be4d2012-02-19 19:52:38 -0800262 "HiSax: Siemens I-Surf config port %x already in use\n",
263 cs->hw.isurf.reset);
264 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 }
266 if (!request_region(cs->hw.isurf.phymem, ISURF_IOMEM_SIZE, "isurf iomem")) {
Jeff Garzik83493042007-10-31 03:42:07 -0400267 printk(KERN_WARNING "HiSax: Siemens I-Surf memory region "
Joe Perches475be4d2012-02-19 19:52:38 -0800268 "%lx-%lx already in use\n",
269 cs->hw.isurf.phymem,
270 cs->hw.isurf.phymem + ISURF_IOMEM_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 release_region(cs->hw.isurf.reset, 1);
272 return (0);
273 }
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;
276 printk(KERN_INFO
277 "ISurf: defined at 0x%x 0x%lx IRQ %d\n",
278 cs->hw.isurf.reset,
279 cs->hw.isurf.phymem,
280 cs->irq);
281
282 setup_isac(cs);
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:");
298 if (ver < 0) {
299 printk(KERN_WARNING
Joe Perches475be4d2012-02-19 19:52:38 -0800300 "ISurf: wrong ISAR version (ret = %d)\n", ver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 release_io_isurf(cs);
302 return (0);
303 }
304 return (1);
305}