PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / isdn / hisax / teles_cs.c
blobb8dd14958757b47698a166973862710bbb722066
1 /* $Id: teles_cs.c,v 1.1.2.2 2004/01/25 15:07:06 keil Exp $ */
2 /*======================================================================
4 A teles S0 PCMCIA client driver
6 Based on skeleton by David Hinds, dhinds@allegro.stanford.edu
7 Written by Christof Petig, christof.petig@wtal.de
9 Also inspired by ELSA PCMCIA driver
10 by Klaus Lichtenwalder <Lichtenwalder@ACM.org>
12 Extensions to new hisax_pcmcia by Karsten Keil
14 minor changes to be compatible with kernel 2.4.x
15 by Jan.Schubert@GMX.li
17 ======================================================================*/
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/ptrace.h>
23 #include <linux/slab.h>
24 #include <linux/string.h>
25 #include <linux/timer.h>
26 #include <linux/ioport.h>
27 #include <asm/io.h>
29 #include <pcmcia/cistpl.h>
30 #include <pcmcia/cisreg.h>
31 #include <pcmcia/ds.h>
32 #include "hisax_cfg.h"
34 MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for Teles PCMCIA cards");
35 MODULE_AUTHOR("Christof Petig, christof.petig@wtal.de, Karsten Keil, kkeil@suse.de");
36 MODULE_LICENSE("GPL");
39 /*====================================================================*/
41 /* Parameters that can be set with 'insmod' */
43 static int protocol = 2; /* EURO-ISDN Default */
44 module_param(protocol, int, 0);
46 static int teles_cs_config(struct pcmcia_device *link);
47 static void teles_cs_release(struct pcmcia_device *link);
48 static void teles_detach(struct pcmcia_device *p_dev);
50 typedef struct local_info_t {
51 struct pcmcia_device *p_dev;
52 int busy;
53 int cardnr;
54 } local_info_t;
56 static int teles_probe(struct pcmcia_device *link)
58 local_info_t *local;
60 dev_dbg(&link->dev, "teles_attach()\n");
62 /* Allocate space for private device-specific data */
63 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
64 if (!local) return -ENOMEM;
65 local->cardnr = -1;
67 local->p_dev = link;
68 link->priv = local;
70 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
72 return teles_cs_config(link);
73 } /* teles_attach */
75 static void teles_detach(struct pcmcia_device *link)
77 local_info_t *info = link->priv;
79 dev_dbg(&link->dev, "teles_detach(0x%p)\n", link);
81 info->busy = 1;
82 teles_cs_release(link);
84 kfree(info);
85 } /* teles_detach */
87 static int teles_cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
89 int j;
91 p_dev->io_lines = 5;
92 p_dev->resource[0]->end = 96;
93 p_dev->resource[0]->flags &= IO_DATA_PATH_WIDTH;
94 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
96 if ((p_dev->resource[0]->end) && p_dev->resource[0]->start) {
97 printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
98 if (!pcmcia_request_io(p_dev))
99 return 0;
100 } else {
101 printk(KERN_INFO "(teles_cs: looks like the 97 model)\n");
102 for (j = 0x2f0; j > 0x100; j -= 0x10) {
103 p_dev->resource[0]->start = j;
104 if (!pcmcia_request_io(p_dev))
105 return 0;
108 return -ENODEV;
111 static int teles_cs_config(struct pcmcia_device *link)
113 int i;
114 IsdnCard_t icard;
116 dev_dbg(&link->dev, "teles_config(0x%p)\n", link);
118 i = pcmcia_loop_config(link, teles_cs_configcheck, NULL);
119 if (i != 0)
120 goto cs_failed;
122 if (!link->irq)
123 goto cs_failed;
125 i = pcmcia_enable_device(link);
126 if (i != 0)
127 goto cs_failed;
129 icard.para[0] = link->irq;
130 icard.para[1] = link->resource[0]->start;
131 icard.protocol = protocol;
132 icard.typ = ISDN_CTYPE_TELESPCMCIA;
134 i = hisax_init_pcmcia(link, &(((local_info_t *)link->priv)->busy), &icard);
135 if (i < 0) {
136 printk(KERN_ERR "teles_cs: failed to initialize Teles PCMCIA %d at i/o %#x\n",
137 i, (unsigned int) link->resource[0]->start);
138 teles_cs_release(link);
139 return -ENODEV;
142 ((local_info_t *)link->priv)->cardnr = i;
143 return 0;
145 cs_failed:
146 teles_cs_release(link);
147 return -ENODEV;
148 } /* teles_cs_config */
150 static void teles_cs_release(struct pcmcia_device *link)
152 local_info_t *local = link->priv;
154 dev_dbg(&link->dev, "teles_cs_release(0x%p)\n", link);
156 if (local) {
157 if (local->cardnr >= 0) {
158 /* no unregister function with hisax */
159 HiSax_closecard(local->cardnr);
163 pcmcia_disable_device(link);
164 } /* teles_cs_release */
166 static int teles_suspend(struct pcmcia_device *link)
168 local_info_t *dev = link->priv;
170 dev->busy = 1;
172 return 0;
175 static int teles_resume(struct pcmcia_device *link)
177 local_info_t *dev = link->priv;
179 dev->busy = 0;
181 return 0;
185 static const struct pcmcia_device_id teles_ids[] = {
186 PCMCIA_DEVICE_PROD_ID12("TELES", "S0/PC", 0x67b50eae, 0xe9e70119),
187 PCMCIA_DEVICE_NULL,
189 MODULE_DEVICE_TABLE(pcmcia, teles_ids);
191 static struct pcmcia_driver teles_cs_driver = {
192 .owner = THIS_MODULE,
193 .name = "teles_cs",
194 .probe = teles_probe,
195 .remove = teles_detach,
196 .id_table = teles_ids,
197 .suspend = teles_suspend,
198 .resume = teles_resume,
200 module_pcmcia_driver(teles_cs_driver);