]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* $Id: hfcscard.c,v 1.10.2.4 2004/01/14 16:04:48 keil Exp $ |
2 | * | |
3 | * low level stuff for hfcs based cards (Teles3c, ACER P10) | |
4 | * | |
5 | * Author Karsten Keil | |
6 | * Copyright by Karsten Keil <[email protected]> | |
475be4d8 | 7 | * |
1da177e4 LT |
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 | */ | |
12 | ||
13 | #include <linux/init.h> | |
14 | #include <linux/isapnp.h> | |
15 | #include "hisax.h" | |
16 | #include "hfc_2bds0.h" | |
17 | #include "isdnl1.h" | |
18 | ||
1da177e4 LT |
19 | static const char *hfcs_revision = "$Revision: 1.10.2.4 $"; |
20 | ||
21 | static irqreturn_t | |
7d12e780 | 22 | hfcs_interrupt(int intno, void *dev_id) |
1da177e4 LT |
23 | { |
24 | struct IsdnCardState *cs = dev_id; | |
25 | u_char val, stat; | |
26 | u_long flags; | |
27 | ||
28 | spin_lock_irqsave(&cs->lock, flags); | |
475be4d8 JP |
29 | if ((HFCD_ANYINT | HFCD_BUSY_NBUSY) & |
30 | (stat = cs->BC_Read_Reg(cs, HFCD_DATA, HFCD_STAT))) { | |
1da177e4 LT |
31 | val = cs->BC_Read_Reg(cs, HFCD_DATA, HFCD_INT_S1); |
32 | if (cs->debug & L1_DEB_ISAC) | |
33 | debugl1(cs, "HFCS: stat(%02x) s1(%02x)", stat, val); | |
34 | hfc2bds0_interrupt(cs, val); | |
35 | } else { | |
36 | if (cs->debug & L1_DEB_ISAC) | |
37 | debugl1(cs, "HFCS: irq_no_irq stat(%02x)", stat); | |
38 | } | |
39 | spin_unlock_irqrestore(&cs->lock, flags); | |
40 | return IRQ_HANDLED; | |
41 | } | |
42 | ||
43 | static void | |
5e8b824d | 44 | hfcs_Timer(struct timer_list *t) |
1da177e4 | 45 | { |
5e8b824d | 46 | struct IsdnCardState *cs = from_timer(cs, t, hw.hfcD.timer); |
1da177e4 LT |
47 | cs->hw.hfcD.timer.expires = jiffies + 75; |
48 | /* WD RESET */ | |
49 | /* WriteReg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcD.ctmt | 0x80); | |
50 | add_timer(&cs->hw.hfcD.timer); | |
51 | */ | |
52 | } | |
53 | ||
672c3fd9 | 54 | static void |
1da177e4 LT |
55 | release_io_hfcs(struct IsdnCardState *cs) |
56 | { | |
57 | release2bds0(cs); | |
58 | del_timer(&cs->hw.hfcD.timer); | |
59 | if (cs->hw.hfcD.addr) | |
60 | release_region(cs->hw.hfcD.addr, 2); | |
61 | } | |
62 | ||
63 | static void | |
64 | reset_hfcs(struct IsdnCardState *cs) | |
65 | { | |
66 | printk(KERN_INFO "HFCS: resetting card\n"); | |
67 | cs->hw.hfcD.cirm = HFCD_RESET; | |
68 | if (cs->typ == ISDN_CTYPE_TELES3C) | |
69 | cs->hw.hfcD.cirm |= HFCD_MEM8K; | |
70 | cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_CIRM, cs->hw.hfcD.cirm); /* Reset On */ | |
71 | mdelay(10); | |
72 | cs->hw.hfcD.cirm = 0; | |
73 | if (cs->typ == ISDN_CTYPE_TELES3C) | |
74 | cs->hw.hfcD.cirm |= HFCD_MEM8K; | |
75 | cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_CIRM, cs->hw.hfcD.cirm); /* Reset Off */ | |
76 | mdelay(10); | |
77 | if (cs->typ == ISDN_CTYPE_TELES3C) | |
78 | cs->hw.hfcD.cirm |= HFCD_INTB; | |
79 | else if (cs->typ == ISDN_CTYPE_ACERP10) | |
80 | cs->hw.hfcD.cirm |= HFCD_INTA; | |
81 | cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_CIRM, cs->hw.hfcD.cirm); | |
82 | cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_CLKDEL, 0x0e); | |
83 | cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_TEST, HFCD_AUTO_AWAKE); /* S/T Auto awake */ | |
84 | cs->hw.hfcD.ctmt = HFCD_TIM25 | HFCD_AUTO_TIMER; | |
85 | cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcD.ctmt); | |
86 | cs->hw.hfcD.int_m2 = HFCD_IRQ_ENABLE; | |
87 | cs->hw.hfcD.int_m1 = HFCD_INTS_B1TRANS | HFCD_INTS_B2TRANS | | |
88 | HFCD_INTS_DTRANS | HFCD_INTS_B1REC | HFCD_INTS_B2REC | | |
89 | HFCD_INTS_DREC | HFCD_INTS_L1STATE; | |
90 | cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_INT_M1, cs->hw.hfcD.int_m1); | |
91 | cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_INT_M2, cs->hw.hfcD.int_m2); | |
92 | cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_STATES, HFCD_LOAD_STATE | 2); /* HFC ST 2 */ | |
93 | udelay(10); | |
94 | cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_STATES, 2); /* HFC ST 2 */ | |
95 | cs->hw.hfcD.mst_m = HFCD_MASTER; | |
96 | cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_MST_MODE, cs->hw.hfcD.mst_m); /* HFC Master */ | |
97 | cs->hw.hfcD.sctrl = 0; | |
98 | cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_SCTRL, cs->hw.hfcD.sctrl); | |
99 | } | |
100 | ||
101 | static int | |
102 | hfcs_card_msg(struct IsdnCardState *cs, int mt, void *arg) | |
103 | { | |
104 | u_long flags; | |
105 | int delay; | |
106 | ||
107 | if (cs->debug & L1_DEB_ISAC) | |
108 | debugl1(cs, "HFCS: card_msg %x", mt); | |
109 | switch (mt) { | |
475be4d8 JP |
110 | case CARD_RESET: |
111 | spin_lock_irqsave(&cs->lock, flags); | |
112 | reset_hfcs(cs); | |
113 | spin_unlock_irqrestore(&cs->lock, flags); | |
114 | return (0); | |
115 | case CARD_RELEASE: | |
116 | release_io_hfcs(cs); | |
117 | return (0); | |
118 | case CARD_INIT: | |
119 | delay = (75 * HZ) / 100 + 1; | |
120 | mod_timer(&cs->hw.hfcD.timer, jiffies + delay); | |
121 | spin_lock_irqsave(&cs->lock, flags); | |
122 | reset_hfcs(cs); | |
123 | init2bds0(cs); | |
124 | spin_unlock_irqrestore(&cs->lock, flags); | |
125 | delay = (80 * HZ) / 1000 + 1; | |
126 | msleep(80); | |
127 | spin_lock_irqsave(&cs->lock, flags); | |
128 | cs->hw.hfcD.ctmt |= HFCD_TIM800; | |
129 | cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcD.ctmt); | |
130 | cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_MST_MODE, cs->hw.hfcD.mst_m); | |
131 | spin_unlock_irqrestore(&cs->lock, flags); | |
132 | return (0); | |
133 | case CARD_TEST: | |
134 | return (0); | |
1da177e4 | 135 | } |
475be4d8 | 136 | return (0); |
1da177e4 LT |
137 | } |
138 | ||
139 | #ifdef __ISAPNP__ | |
ed5a84cd | 140 | static struct isapnp_device_id hfc_ids[] = { |
1da177e4 | 141 | { ISAPNP_VENDOR('A', 'N', 'X'), ISAPNP_FUNCTION(0x1114), |
475be4d8 | 142 | ISAPNP_VENDOR('A', 'N', 'X'), ISAPNP_FUNCTION(0x1114), |
1da177e4 LT |
143 | (unsigned long) "Acer P10" }, |
144 | { ISAPNP_VENDOR('B', 'I', 'L'), ISAPNP_FUNCTION(0x0002), | |
475be4d8 | 145 | ISAPNP_VENDOR('B', 'I', 'L'), ISAPNP_FUNCTION(0x0002), |
1da177e4 LT |
146 | (unsigned long) "Billion 2" }, |
147 | { ISAPNP_VENDOR('B', 'I', 'L'), ISAPNP_FUNCTION(0x0001), | |
475be4d8 | 148 | ISAPNP_VENDOR('B', 'I', 'L'), ISAPNP_FUNCTION(0x0001), |
1da177e4 LT |
149 | (unsigned long) "Billion 1" }, |
150 | { ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x7410), | |
475be4d8 | 151 | ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x7410), |
1da177e4 LT |
152 | (unsigned long) "IStar PnP" }, |
153 | { ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2610), | |
475be4d8 | 154 | ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2610), |
1da177e4 LT |
155 | (unsigned long) "Teles 16.3c" }, |
156 | { ISAPNP_VENDOR('S', 'F', 'M'), ISAPNP_FUNCTION(0x0001), | |
475be4d8 | 157 | ISAPNP_VENDOR('S', 'F', 'M'), ISAPNP_FUNCTION(0x0001), |
1da177e4 LT |
158 | (unsigned long) "Tornado Tipa C" }, |
159 | { ISAPNP_VENDOR('K', 'Y', 'E'), ISAPNP_FUNCTION(0x0001), | |
475be4d8 | 160 | ISAPNP_VENDOR('K', 'Y', 'E'), ISAPNP_FUNCTION(0x0001), |
1da177e4 LT |
161 | (unsigned long) "Genius Speed Surfer" }, |
162 | { 0, } | |
163 | }; | |
164 | ||
ed5a84cd GKH |
165 | static struct isapnp_device_id *ipid = &hfc_ids[0]; |
166 | static struct pnp_card *pnp_c = NULL; | |
1da177e4 LT |
167 | #endif |
168 | ||
ed5a84cd | 169 | int setup_hfcs(struct IsdnCard *card) |
1da177e4 LT |
170 | { |
171 | struct IsdnCardState *cs = card->cs; | |
172 | char tmp[64]; | |
173 | ||
174 | strcpy(tmp, hfcs_revision); | |
175 | printk(KERN_INFO "HiSax: HFC-S driver Rev. %s\n", HiSax_getrev(tmp)); | |
176 | ||
177 | #ifdef __ISAPNP__ | |
178 | if (!card->para[1] && isapnp_present()) { | |
179 | struct pnp_dev *pnp_d; | |
475be4d8 | 180 | while (ipid->card_vendor) { |
1da177e4 | 181 | if ((pnp_c = pnp_find_card(ipid->card_vendor, |
475be4d8 | 182 | ipid->card_device, pnp_c))) { |
1da177e4 LT |
183 | pnp_d = NULL; |
184 | if ((pnp_d = pnp_find_dev(pnp_c, | |
475be4d8 | 185 | ipid->vendor, ipid->function, pnp_d))) { |
1da177e4 LT |
186 | int err; |
187 | ||
188 | printk(KERN_INFO "HiSax: %s detected\n", | |
475be4d8 | 189 | (char *)ipid->driver_data); |
1da177e4 LT |
190 | pnp_disable_dev(pnp_d); |
191 | err = pnp_activate_dev(pnp_d); | |
475be4d8 | 192 | if (err < 0) { |
1da177e4 | 193 | printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n", |
475be4d8 JP |
194 | __func__, err); |
195 | return (0); | |
1da177e4 LT |
196 | } |
197 | card->para[1] = pnp_port_start(pnp_d, 0); | |
198 | card->para[0] = pnp_irq(pnp_d, 0); | |
faa2efff | 199 | if (card->para[0] == -1 || !card->para[1]) { |
1da177e4 | 200 | printk(KERN_ERR "HFC PnP:some resources are missing %ld/%lx\n", |
475be4d8 | 201 | card->para[0], card->para[1]); |
1da177e4 | 202 | pnp_disable_dev(pnp_d); |
475be4d8 | 203 | return (0); |
1da177e4 LT |
204 | } |
205 | break; | |
206 | } else { | |
207 | printk(KERN_ERR "HFC PnP: PnP error card found, no device\n"); | |
208 | } | |
209 | } | |
210 | ipid++; | |
211 | pnp_c = NULL; | |
475be4d8 | 212 | } |
1da177e4 LT |
213 | if (!ipid->card_vendor) { |
214 | printk(KERN_INFO "HFC PnP: no ISAPnP card found\n"); | |
475be4d8 | 215 | return (0); |
1da177e4 LT |
216 | } |
217 | } | |
218 | #endif | |
219 | cs->hw.hfcD.addr = card->para[1] & 0xfffe; | |
220 | cs->irq = card->para[0]; | |
221 | cs->hw.hfcD.cip = 0; | |
222 | cs->hw.hfcD.int_s1 = 0; | |
223 | cs->hw.hfcD.send = NULL; | |
224 | cs->bcs[0].hw.hfc.send = NULL; | |
225 | cs->bcs[1].hw.hfc.send = NULL; | |
226 | cs->hw.hfcD.dfifosize = 512; | |
227 | cs->dc.hfcd.ph_state = 0; | |
228 | cs->hw.hfcD.fifo = 255; | |
229 | if (cs->typ == ISDN_CTYPE_TELES3C) { | |
230 | cs->hw.hfcD.bfifosize = 1024 + 512; | |
231 | } else if (cs->typ == ISDN_CTYPE_ACERP10) { | |
475be4d8 | 232 | cs->hw.hfcD.bfifosize = 7 * 1024 + 512; |
1da177e4 LT |
233 | } else |
234 | return (0); | |
235 | if (!request_region(cs->hw.hfcD.addr, 2, "HFCS isdn")) { | |
236 | printk(KERN_WARNING | |
237 | "HiSax: %s config port %x-%x already in use\n", | |
238 | CardType[card->typ], | |
239 | cs->hw.hfcD.addr, | |
240 | cs->hw.hfcD.addr + 2); | |
241 | return (0); | |
242 | } | |
243 | printk(KERN_INFO | |
244 | "HFCS: defined at 0x%x IRQ %d HZ %d\n", | |
245 | cs->hw.hfcD.addr, | |
246 | cs->irq, HZ); | |
247 | if (cs->typ == ISDN_CTYPE_TELES3C) { | |
248 | /* Teles 16.3c IO ADR is 0x200 | YY0U (YY Bit 15/14 address) */ | |
249 | outb(0x00, cs->hw.hfcD.addr); | |
250 | outb(0x56, cs->hw.hfcD.addr | 1); | |
251 | } else if (cs->typ == ISDN_CTYPE_ACERP10) { | |
252 | /* Acer P10 IO ADR is 0x300 */ | |
253 | outb(0x00, cs->hw.hfcD.addr); | |
254 | outb(0x57, cs->hw.hfcD.addr | 1); | |
255 | } | |
256 | set_cs_func(cs); | |
5e8b824d | 257 | timer_setup(&cs->hw.hfcD.timer, hfcs_Timer, 0); |
1da177e4 LT |
258 | cs->cardmsg = &hfcs_card_msg; |
259 | cs->irq_func = &hfcs_interrupt; | |
260 | return (1); | |
261 | } |