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