1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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>
28#include <asm/system.h>
29
30#include <pcmcia/cistpl.h>
31#include <pcmcia/cisreg.h>
32#include <pcmcia/ds.h>
33#include "hisax_cfg.h"
34
35MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for Teles PCMCIA cards");
36MODULE_AUTHOR("Christof Petig, christof.petig@wtal.de, Karsten Keil, kkeil@suse.de");
37MODULE_LICENSE("GPL");
38
39
40
41
42
43
44static int protocol = 2;
45module_param(protocol, int, 0);
46
47static int teles_cs_config(struct pcmcia_device *link) __devinit ;
48static void teles_cs_release(struct pcmcia_device *link);
49static void teles_detach(struct pcmcia_device *p_dev) __devexit ;
50
51typedef struct local_info_t {
52 struct pcmcia_device *p_dev;
53 int busy;
54 int cardnr;
55} local_info_t;
56
57static int __devinit teles_probe(struct pcmcia_device *link)
58{
59 local_info_t *local;
60
61 dev_dbg(&link->dev, "teles_attach()\n");
62
63
64 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
65 if (!local) return -ENOMEM;
66 local->cardnr = -1;
67
68 local->p_dev = link;
69 link->priv = local;
70
71 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
72
73 return teles_cs_config(link);
74}
75
76static void __devexit teles_detach(struct pcmcia_device *link)
77{
78 local_info_t *info = link->priv;
79
80 dev_dbg(&link->dev, "teles_detach(0x%p)\n", link);
81
82 info->busy = 1;
83 teles_cs_release(link);
84
85 kfree(info);
86}
87
88static int teles_cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
89{
90 int j;
91
92 p_dev->io_lines = 5;
93 p_dev->resource[0]->end = 96;
94 p_dev->resource[0]->flags &= IO_DATA_PATH_WIDTH;
95 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
96
97 if ((p_dev->resource[0]->end) && p_dev->resource[0]->start) {
98 printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
99 if (!pcmcia_request_io(p_dev))
100 return 0;
101 } else {
102 printk(KERN_INFO "(teles_cs: looks like the 97 model)\n");
103 for (j = 0x2f0; j > 0x100; j -= 0x10) {
104 p_dev->resource[0]->start = j;
105 if (!pcmcia_request_io(p_dev))
106 return 0;
107 }
108 }
109 return -ENODEV;
110}
111
112static int __devinit teles_cs_config(struct pcmcia_device *link)
113{
114 local_info_t *dev;
115 int i;
116 IsdnCard_t icard;
117
118 dev_dbg(&link->dev, "teles_config(0x%p)\n", link);
119 dev = link->priv;
120
121 i = pcmcia_loop_config(link, teles_cs_configcheck, NULL);
122 if (i != 0)
123 goto cs_failed;
124
125 if (!link->irq)
126 goto cs_failed;
127
128 i = pcmcia_enable_device(link);
129 if (i != 0)
130 goto cs_failed;
131
132 icard.para[0] = link->irq;
133 icard.para[1] = link->resource[0]->start;
134 icard.protocol = protocol;
135 icard.typ = ISDN_CTYPE_TELESPCMCIA;
136
137 i = hisax_init_pcmcia(link, &(((local_info_t*)link->priv)->busy), &icard);
138 if (i < 0) {
139 printk(KERN_ERR "teles_cs: failed to initialize Teles PCMCIA %d at i/o %#x\n",
140 i, (unsigned int) link->resource[0]->start);
141 teles_cs_release(link);
142 return -ENODEV;
143 }
144
145 ((local_info_t*)link->priv)->cardnr = i;
146 return 0;
147
148cs_failed:
149 teles_cs_release(link);
150 return -ENODEV;
151}
152
153static void teles_cs_release(struct pcmcia_device *link)
154{
155 local_info_t *local = link->priv;
156
157 dev_dbg(&link->dev, "teles_cs_release(0x%p)\n", link);
158
159 if (local) {
160 if (local->cardnr >= 0) {
161
162 HiSax_closecard(local->cardnr);
163 }
164 }
165
166 pcmcia_disable_device(link);
167}
168
169static int teles_suspend(struct pcmcia_device *link)
170{
171 local_info_t *dev = link->priv;
172
173 dev->busy = 1;
174
175 return 0;
176}
177
178static int teles_resume(struct pcmcia_device *link)
179{
180 local_info_t *dev = link->priv;
181
182 dev->busy = 0;
183
184 return 0;
185}
186
187
188static struct pcmcia_device_id teles_ids[] = {
189 PCMCIA_DEVICE_PROD_ID12("TELES", "S0/PC", 0x67b50eae, 0xe9e70119),
190 PCMCIA_DEVICE_NULL,
191};
192MODULE_DEVICE_TABLE(pcmcia, teles_ids);
193
194static struct pcmcia_driver teles_cs_driver = {
195 .owner = THIS_MODULE,
196 .name = "teles_cs",
197 .probe = teles_probe,
198 .remove = __devexit_p(teles_detach),
199 .id_table = teles_ids,
200 .suspend = teles_suspend,
201 .resume = teles_resume,
202};
203
204static int __init init_teles_cs(void)
205{
206 return pcmcia_register_driver(&teles_cs_driver);
207}
208
209static void __exit exit_teles_cs(void)
210{
211 pcmcia_unregister_driver(&teles_cs_driver);
212}
213
214module_init(init_teles_cs);
215module_exit(exit_teles_cs);
216