[PATCH] pcmcia: remove unneeded Vcc pseudo setting
[powerpc.git] / drivers / telephony / ixj_pcmcia.c
1 #include "ixj-ver.h"
2
3 #include <linux/module.h>
4
5 #include <linux/init.h>
6 #include <linux/sched.h>
7 #include <linux/kernel.h>       /* printk() */
8 #include <linux/fs.h>           /* everything... */
9 #include <linux/errno.h>        /* error codes */
10 #include <linux/slab.h>
11
12 #include <pcmcia/cs_types.h>
13 #include <pcmcia/cs.h>
14 #include <pcmcia/cistpl.h>
15 #include <pcmcia/ds.h>
16
17 #include "ixj.h"
18
19 /*
20  *      PCMCIA service support for Quicknet cards
21  */
22  
23 #ifdef PCMCIA_DEBUG
24 static int pc_debug = PCMCIA_DEBUG;
25 module_param(pc_debug, int, 0644);
26 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
27 #else
28 #define DEBUG(n, args...)
29 #endif
30
31 typedef struct ixj_info_t {
32         int ndev;
33         dev_node_t node;
34         struct ixj *port;
35 } ixj_info_t;
36
37 static void ixj_detach(struct pcmcia_device *p_dev);
38 static void ixj_config(dev_link_t * link);
39 static void ixj_cs_release(dev_link_t * link);
40
41 static int ixj_attach(struct pcmcia_device *p_dev)
42 {
43         dev_link_t *link;
44
45         DEBUG(0, "ixj_attach()\n");
46         /* Create new ixj device */
47         link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
48         if (!link)
49                 return -ENOMEM;
50         memset(link, 0, sizeof(struct dev_link_t));
51         link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
52         link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
53         link->io.IOAddrLines = 3;
54         link->conf.IntType = INT_MEMORY_AND_IO;
55         link->priv = kmalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
56         if (!link->priv) {
57                 kfree(link);
58                 return -ENOMEM;
59         }
60         memset(link->priv, 0, sizeof(struct ixj_info_t));
61
62         link->handle = p_dev;
63         p_dev->instance = link;
64
65         link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
66         ixj_config(link);
67
68         return 0;
69 }
70
71 static void ixj_detach(struct pcmcia_device *p_dev)
72 {
73         dev_link_t *link = dev_to_instance(p_dev);
74
75         DEBUG(0, "ixj_detach(0x%p)\n", link);
76
77         link->state &= ~DEV_RELEASE_PENDING;
78         if (link->state & DEV_CONFIG)
79                 ixj_cs_release(link);
80
81         kfree(link->priv);
82         kfree(link);
83 }
84
85 #define CS_CHECK(fn, ret) \
86 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
87
88 static void ixj_get_serial(dev_link_t * link, IXJ * j)
89 {
90         client_handle_t handle;
91         tuple_t tuple;
92         u_short buf[128];
93         char *str;
94         int last_ret, last_fn, i, place;
95         handle = link->handle;
96         DEBUG(0, "ixj_get_serial(0x%p)\n", link);
97         tuple.TupleData = (cisdata_t *) buf;
98         tuple.TupleOffset = 0;
99         tuple.TupleDataMax = 80;
100         tuple.Attributes = 0;
101         tuple.DesiredTuple = CISTPL_VERS_1;
102         CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
103         CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
104         str = (char *) buf;
105         printk("PCMCIA Version %d.%d\n", str[0], str[1]);
106         str += 2;
107         printk("%s", str);
108         str = str + strlen(str) + 1;
109         printk(" %s", str);
110         str = str + strlen(str) + 1;
111         place = 1;
112         for (i = strlen(str) - 1; i >= 0; i--) {
113                 switch (str[i]) {
114                 case '0':
115                 case '1':
116                 case '2':
117                 case '3':
118                 case '4':
119                 case '5':
120                 case '6':
121                 case '7':
122                 case '8':
123                 case '9':
124                         j->serial += (str[i] - 48) * place;
125                         break;
126                 case 'A':
127                 case 'B':
128                 case 'C':
129                 case 'D':
130                 case 'E':
131                 case 'F':
132                         j->serial += (str[i] - 55) * place;
133                         break;
134                 case 'a':
135                 case 'b':
136                 case 'c':
137                 case 'd':
138                 case 'e':
139                 case 'f':
140                         j->serial += (str[i] - 87) * place;
141                         break;
142                 }
143                 place = place * 0x10;
144         }
145         str = str + strlen(str) + 1;
146         printk(" version %s\n", str);
147       cs_failed:
148         return;
149 }
150
151 static void ixj_config(dev_link_t * link)
152 {
153         IXJ *j;
154         client_handle_t handle;
155         ixj_info_t *info;
156         tuple_t tuple;
157         u_short buf[128];
158         cisparse_t parse;
159         cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
160         cistpl_cftable_entry_t dflt =
161         {
162                 0
163         };
164         int last_ret, last_fn;
165         handle = link->handle;
166         info = link->priv;
167         DEBUG(0, "ixj_config(0x%p)\n", link);
168         tuple.TupleData = (cisdata_t *) buf;
169         tuple.TupleOffset = 0;
170         tuple.TupleDataMax = 255;
171         tuple.Attributes = 0;
172         tuple.DesiredTuple = CISTPL_CONFIG;
173         CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
174         CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
175         CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
176         link->conf.ConfigBase = parse.config.base;
177         link->conf.Present = parse.config.rmask[0];
178         link->state |= DEV_CONFIG;
179         tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
180         tuple.Attributes = 0;
181         CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
182         while (1) {
183                 if (pcmcia_get_tuple_data(handle, &tuple) != 0 ||
184                                 pcmcia_parse_tuple(handle, &tuple, &parse) != 0)
185                         goto next_entry;
186                 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
187                         cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
188                         link->conf.ConfigIndex = cfg->index;
189                         link->io.BasePort1 = io->win[0].base;
190                         link->io.NumPorts1 = io->win[0].len;
191                         if (io->nwin == 2) {
192                                 link->io.BasePort2 = io->win[1].base;
193                                 link->io.NumPorts2 = io->win[1].len;
194                         }
195                         if (pcmcia_request_io(link->handle, &link->io) != 0)
196                                 goto next_entry;
197                         /* If we've got this far, we're done */
198                         break;
199                 }
200               next_entry:
201                 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
202                         dflt = *cfg;
203                 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple));
204         }
205
206         CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf));
207
208         /*
209          *      Register the card with the core.
210          */     
211         j=ixj_pcmcia_probe(link->io.BasePort1,link->io.BasePort1 + 0x10);
212
213         info->ndev = 1;
214         info->node.major = PHONE_MAJOR;
215         link->dev = &info->node;
216         ixj_get_serial(link, j);
217         link->state &= ~DEV_CONFIG_PENDING;
218         return;
219       cs_failed:
220         cs_error(link->handle, last_fn, last_ret);
221         ixj_cs_release(link);
222 }
223
224 static void ixj_cs_release(dev_link_t *link)
225 {
226         ixj_info_t *info = link->priv;
227         DEBUG(0, "ixj_cs_release(0x%p)\n", link);
228         info->ndev = 0;
229         pcmcia_disable_device(link->handle);
230 }
231
232 static struct pcmcia_device_id ixj_ids[] = {
233         PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
234         PCMCIA_DEVICE_NULL
235 };
236 MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
237
238 static struct pcmcia_driver ixj_driver = {
239         .owner          = THIS_MODULE,
240         .drv            = {
241                 .name   = "ixj_cs",
242         },
243         .probe          = ixj_attach,
244         .remove         = ixj_detach,
245         .id_table       = ixj_ids,
246 };
247
248 static int __init ixj_pcmcia_init(void)
249 {
250         return pcmcia_register_driver(&ixj_driver);
251 }
252
253 static void ixj_pcmcia_exit(void)
254 {
255         pcmcia_unregister_driver(&ixj_driver);
256 }
257
258 module_init(ixj_pcmcia_init);
259 module_exit(ixj_pcmcia_exit);
260
261 MODULE_LICENSE("GPL");