blob: 39347198d6430068cd85a77d4efcf00e915dd1b8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: avm_a1p.c,v 2.9.2.5 2004/01/24 20:47:19 keil Exp $
2 *
3 * low level stuff for the following AVM cards:
4 * A1 PCMCIA
5 * FRITZ!Card PCMCIA
6 * FRITZ!Card PCMCIA 2.0
7 *
8 * Author Carsten Paeth
9 * Copyright by Carsten Paeth <calle@calle.de>
10 *
11 * This software may be used and distributed according to the terms
12 * of the GNU General Public License, incorporated herein by reference.
13 *
14 */
15
16#include <linux/init.h>
17#include "hisax.h"
18#include "isac.h"
19#include "hscx.h"
20#include "isdnl1.h"
21
22/* register offsets */
23#define ADDRREG_OFFSET 0x02
24#define DATAREG_OFFSET 0x03
25#define ASL0_OFFSET 0x04
26#define ASL1_OFFSET 0x05
27#define MODREG_OFFSET 0x06
28#define VERREG_OFFSET 0x07
29
30/* address offsets */
31#define ISAC_FIFO_OFFSET 0x00
32#define ISAC_REG_OFFSET 0x20
33#define HSCX_CH_DIFF 0x40
34#define HSCX_FIFO_OFFSET 0x80
35#define HSCX_REG_OFFSET 0xa0
36
37/* read bits ASL0 */
38#define ASL0_R_TIMER 0x10 /* active low */
39#define ASL0_R_ISAC 0x20 /* active low */
40#define ASL0_R_HSCX 0x40 /* active low */
41#define ASL0_R_TESTBIT 0x80
Joe Perches475be4d2012-02-19 19:52:38 -080042#define ASL0_R_IRQPENDING (ASL0_R_ISAC | ASL0_R_HSCX | ASL0_R_TIMER)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44/* write bits ASL0 */
45#define ASL0_W_RESET 0x01
46#define ASL0_W_TDISABLE 0x02
47#define ASL0_W_TRESET 0x04
48#define ASL0_W_IRQENABLE 0x08
49#define ASL0_W_TESTBIT 0x80
50
51/* write bits ASL1 */
52#define ASL1_W_LED0 0x10
53#define ASL1_W_LED1 0x20
54#define ASL1_W_ENABLE_S0 0xC0
Joe Perches475be4d2012-02-19 19:52:38 -080055
56#define byteout(addr, val) outb(val, addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define bytein(addr) inb(addr)
58
59static const char *avm_revision = "$Revision: 2.9.2.5 $";
60
61static inline u_char
62ReadISAC(struct IsdnCardState *cs, u_char offset)
63{
Joe Perches475be4d2012-02-19 19:52:38 -080064 u_char ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Joe Perches475be4d2012-02-19 19:52:38 -080066 offset -= 0x20;
67 byteout(cs->hw.avm.cfg_reg + ADDRREG_OFFSET, ISAC_REG_OFFSET + offset);
68 ret = bytein(cs->hw.avm.cfg_reg + DATAREG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 return ret;
70}
71
72static inline void
73WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
74{
Joe Perches475be4d2012-02-19 19:52:38 -080075 offset -= 0x20;
76 byteout(cs->hw.avm.cfg_reg + ADDRREG_OFFSET, ISAC_REG_OFFSET + offset);
77 byteout(cs->hw.avm.cfg_reg + DATAREG_OFFSET, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
79
80static inline void
Joe Perches475be4d2012-02-19 19:52:38 -080081ReadISACfifo(struct IsdnCardState *cs, u_char *data, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Joe Perches475be4d2012-02-19 19:52:38 -080083 byteout(cs->hw.avm.cfg_reg + ADDRREG_OFFSET, ISAC_FIFO_OFFSET);
84 insb(cs->hw.avm.cfg_reg + DATAREG_OFFSET, data, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
87static inline void
Joe Perches475be4d2012-02-19 19:52:38 -080088WriteISACfifo(struct IsdnCardState *cs, u_char *data, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
Joe Perches475be4d2012-02-19 19:52:38 -080090 byteout(cs->hw.avm.cfg_reg + ADDRREG_OFFSET, ISAC_FIFO_OFFSET);
91 outsb(cs->hw.avm.cfg_reg + DATAREG_OFFSET, data, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
94static inline u_char
95ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
96{
97 u_char ret;
98
Joe Perches475be4d2012-02-19 19:52:38 -080099 offset -= 0x20;
100 byteout(cs->hw.avm.cfg_reg + ADDRREG_OFFSET,
101 HSCX_REG_OFFSET + hscx * HSCX_CH_DIFF + offset);
102 ret = bytein(cs->hw.avm.cfg_reg + DATAREG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 return ret;
104}
105
106static inline void
107WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
108{
Joe Perches475be4d2012-02-19 19:52:38 -0800109 offset -= 0x20;
110 byteout(cs->hw.avm.cfg_reg + ADDRREG_OFFSET,
111 HSCX_REG_OFFSET + hscx * HSCX_CH_DIFF + offset);
112 byteout(cs->hw.avm.cfg_reg + DATAREG_OFFSET, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
114
115static inline void
Joe Perches475be4d2012-02-19 19:52:38 -0800116ReadHSCXfifo(struct IsdnCardState *cs, int hscx, u_char *data, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
Joe Perches475be4d2012-02-19 19:52:38 -0800118 byteout(cs->hw.avm.cfg_reg + ADDRREG_OFFSET,
119 HSCX_FIFO_OFFSET + hscx * HSCX_CH_DIFF);
120 insb(cs->hw.avm.cfg_reg + DATAREG_OFFSET, data, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}
122
123static inline void
Joe Perches475be4d2012-02-19 19:52:38 -0800124WriteHSCXfifo(struct IsdnCardState *cs, int hscx, u_char *data, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
Joe Perches475be4d2012-02-19 19:52:38 -0800126 byteout(cs->hw.avm.cfg_reg + ADDRREG_OFFSET,
127 HSCX_FIFO_OFFSET + hscx * HSCX_CH_DIFF);
128 outsb(cs->hw.avm.cfg_reg + DATAREG_OFFSET, data, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
131/*
132 * fast interrupt HSCX stuff goes here
133 */
134
135#define READHSCX(cs, nr, reg) ReadHSCX(cs, nr, reg)
136#define WRITEHSCX(cs, nr, reg, data) WriteHSCX(cs, nr, reg, data)
Joe Perches475be4d2012-02-19 19:52:38 -0800137#define READHSCXFIFO(cs, nr, ptr, cnt) ReadHSCXfifo(cs, nr, ptr, cnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#define WRITEHSCXFIFO(cs, nr, ptr, cnt) WriteHSCXfifo(cs, nr, ptr, cnt)
139
140#include "hscx_irq.c"
141
142static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100143avm_a1p_interrupt(int intno, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
145 struct IsdnCardState *cs = dev_id;
146 u_char val, sval;
147 u_long flags;
148
149 spin_lock_irqsave(&cs->lock, flags);
Joe Perches475be4d2012-02-19 19:52:38 -0800150 while ((sval = (~bytein(cs->hw.avm.cfg_reg + ASL0_OFFSET) & ASL0_R_IRQPENDING))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 if (cs->debug & L1_DEB_INTSTAT)
152 debugl1(cs, "avm IntStatus %x", sval);
153 if (sval & ASL0_R_HSCX) {
Joe Perches475be4d2012-02-19 19:52:38 -0800154 val = ReadHSCX(cs, 1, HSCX_ISTA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 if (val)
156 hscx_int_main(cs, val);
157 }
158 if (sval & ASL0_R_ISAC) {
159 val = ReadISAC(cs, ISAC_ISTA);
160 if (val)
161 isac_interrupt(cs, val);
162 }
163 }
164 WriteHSCX(cs, 0, HSCX_MASK, 0xff);
165 WriteHSCX(cs, 1, HSCX_MASK, 0xff);
166 WriteISAC(cs, ISAC_MASK, 0xff);
167 WriteISAC(cs, ISAC_MASK, 0x00);
168 WriteHSCX(cs, 0, HSCX_MASK, 0x00);
169 WriteHSCX(cs, 1, HSCX_MASK, 0x00);
170 spin_unlock_irqrestore(&cs->lock, flags);
171 return IRQ_HANDLED;
172}
173
174static int
175AVM_card_msg(struct IsdnCardState *cs, int mt, void *arg)
176{
177 u_long flags;
178
179 switch (mt) {
Joe Perches475be4d2012-02-19 19:52:38 -0800180 case CARD_RESET:
181 spin_lock_irqsave(&cs->lock, flags);
182 byteout(cs->hw.avm.cfg_reg + ASL0_OFFSET, 0x00);
183 HZDELAY(HZ / 5 + 1);
184 byteout(cs->hw.avm.cfg_reg + ASL0_OFFSET, ASL0_W_RESET);
185 HZDELAY(HZ / 5 + 1);
186 byteout(cs->hw.avm.cfg_reg + ASL0_OFFSET, 0x00);
187 spin_unlock_irqrestore(&cs->lock, flags);
188 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Joe Perches475be4d2012-02-19 19:52:38 -0800190 case CARD_RELEASE:
191 /* free_irq is done in HiSax_closecard(). */
192 /* free_irq(cs->irq, cs); */
193 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Joe Perches475be4d2012-02-19 19:52:38 -0800195 case CARD_INIT:
196 spin_lock_irqsave(&cs->lock, flags);
197 byteout(cs->hw.avm.cfg_reg + ASL0_OFFSET, ASL0_W_TDISABLE | ASL0_W_TRESET | ASL0_W_IRQENABLE);
198 clear_pending_isac_ints(cs);
199 clear_pending_hscx_ints(cs);
200 inithscxisac(cs, 1);
201 inithscxisac(cs, 2);
202 spin_unlock_irqrestore(&cs->lock, flags);
203 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Joe Perches475be4d2012-02-19 19:52:38 -0800205 case CARD_TEST:
206 /* we really don't need it for the PCMCIA Version */
207 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Joe Perches475be4d2012-02-19 19:52:38 -0800209 default:
210 /* all card drivers ignore others, so we do the same */
211 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 }
213 return 0;
214}
215
Sam Ravnborgf4e64332008-02-09 23:29:28 -0800216int __devinit setup_avm_a1_pcmcia(struct IsdnCard *card)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
218 u_char model, vers;
219 struct IsdnCardState *cs = card->cs;
220 char tmp[64];
221
222
223 strcpy(tmp, avm_revision);
224 printk(KERN_INFO "HiSax: AVM A1 PCMCIA driver Rev. %s\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800225 HiSax_getrev(tmp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 if (cs->typ != ISDN_CTYPE_A1_PCMCIA)
227 return (0);
228
229 cs->hw.avm.cfg_reg = card->para[1];
230 cs->irq = card->para[0];
231
232
Joe Perches475be4d2012-02-19 19:52:38 -0800233 byteout(cs->hw.avm.cfg_reg + ASL1_OFFSET, ASL1_W_ENABLE_S0);
234 byteout(cs->hw.avm.cfg_reg + ASL0_OFFSET, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 HZDELAY(HZ / 5 + 1);
Joe Perches475be4d2012-02-19 19:52:38 -0800236 byteout(cs->hw.avm.cfg_reg + ASL0_OFFSET, ASL0_W_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 HZDELAY(HZ / 5 + 1);
Joe Perches475be4d2012-02-19 19:52:38 -0800238 byteout(cs->hw.avm.cfg_reg + ASL0_OFFSET, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Joe Perches475be4d2012-02-19 19:52:38 -0800240 byteout(cs->hw.avm.cfg_reg + ASL0_OFFSET, ASL0_W_TDISABLE | ASL0_W_TRESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Joe Perches475be4d2012-02-19 19:52:38 -0800242 model = bytein(cs->hw.avm.cfg_reg + MODREG_OFFSET);
243 vers = bytein(cs->hw.avm.cfg_reg + VERREG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245 printk(KERN_INFO "AVM A1 PCMCIA: io 0x%x irq %d model %d version %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800246 cs->hw.avm.cfg_reg, cs->irq, model, vers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
248 setup_isac(cs);
249 cs->readisac = &ReadISAC;
250 cs->writeisac = &WriteISAC;
251 cs->readisacfifo = &ReadISACfifo;
252 cs->writeisacfifo = &WriteISACfifo;
253 cs->BC_Read_Reg = &ReadHSCX;
254 cs->BC_Write_Reg = &WriteHSCX;
255 cs->BC_Send_Data = &hscx_fill_fifo;
256 cs->cardmsg = &AVM_card_msg;
Thomas Gleixner9ba02be2006-07-01 19:29:36 -0700257 cs->irq_flags = IRQF_SHARED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 cs->irq_func = &avm_a1p_interrupt;
259
260 ISACVersion(cs, "AVM A1 PCMCIA:");
261 if (HscxVersion(cs, "AVM A1 PCMCIA:")) {
262 printk(KERN_WARNING
263 "AVM A1 PCMCIA: wrong HSCX versions check IO address\n");
264 return (0);
265 }
266 return (1);
267}