[PATCH] pcmcia: remove prod_id indirection
[safe/jmp/linux-2.6] / 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 int ixj_config(struct pcmcia_device * link);
39 static void ixj_cs_release(struct pcmcia_device * link);
40
41 static int ixj_probe(struct pcmcia_device *p_dev)
42 {
43         DEBUG(0, "ixj_attach()\n");
44         /* Create new ixj device */
45         p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
46         p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
47         p_dev->io.IOAddrLines = 3;
48         p_dev->conf.IntType = INT_MEMORY_AND_IO;
49         p_dev->priv = kmalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
50         if (!p_dev->priv) {
51                 return -ENOMEM;
52         }
53         memset(p_dev->priv, 0, sizeof(struct ixj_info_t));
54
55         return ixj_config(p_dev);
56 }
57
58 static void ixj_detach(struct pcmcia_device *link)
59 {
60         DEBUG(0, "ixj_detach(0x%p)\n", link);
61
62         ixj_cs_release(link);
63
64         kfree(link->priv);
65 }
66
67 #define CS_CHECK(fn, ret) \
68 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
69
70 static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
71 {
72         char *str;
73         int i, place;
74         DEBUG(0, "ixj_get_serial(0x%p)\n", link);
75
76         str = link->prod_id[0];
77         if (!str)
78                 goto cs_failed;
79         printk("%s", str);
80         str = link->prod_id[1];
81         if (!str)
82                 goto cs_failed;
83         printk(" %s", str);
84         str = link->prod_id[2];
85         if (!str)
86                 goto cs_failed;
87         place = 1;
88         for (i = strlen(str) - 1; i >= 0; i--) {
89                 switch (str[i]) {
90                 case '0':
91                 case '1':
92                 case '2':
93                 case '3':
94                 case '4':
95                 case '5':
96                 case '6':
97                 case '7':
98                 case '8':
99                 case '9':
100                         j->serial += (str[i] - 48) * place;
101                         break;
102                 case 'A':
103                 case 'B':
104                 case 'C':
105                 case 'D':
106                 case 'E':
107                 case 'F':
108                         j->serial += (str[i] - 55) * place;
109                         break;
110                 case 'a':
111                 case 'b':
112                 case 'c':
113                 case 'd':
114                 case 'e':
115                 case 'f':
116                         j->serial += (str[i] - 87) * place;
117                         break;
118                 }
119                 place = place * 0x10;
120         }
121         str = link->prod_id[3];
122         if (!str)
123                 goto cs_failed;
124         printk(" version %s\n", str);
125       cs_failed:
126         return;
127 }
128
129 static int ixj_config(struct pcmcia_device * link)
130 {
131         IXJ *j;
132         ixj_info_t *info;
133         tuple_t tuple;
134         u_short buf[128];
135         cisparse_t parse;
136         cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
137         cistpl_cftable_entry_t dflt =
138         {
139                 0
140         };
141         int last_ret, last_fn;
142         info = link->priv;
143         DEBUG(0, "ixj_config(0x%p)\n", link);
144         tuple.TupleData = (cisdata_t *) buf;
145         tuple.TupleOffset = 0;
146         tuple.TupleDataMax = 255;
147         tuple.Attributes = 0;
148         tuple.DesiredTuple = CISTPL_CONFIG;
149         CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
150         CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
151         CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
152         link->conf.ConfigBase = parse.config.base;
153         link->conf.Present = parse.config.rmask[0];
154         tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
155         tuple.Attributes = 0;
156         CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
157         while (1) {
158                 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
159                                 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
160                         goto next_entry;
161                 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
162                         cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
163                         link->conf.ConfigIndex = cfg->index;
164                         link->io.BasePort1 = io->win[0].base;
165                         link->io.NumPorts1 = io->win[0].len;
166                         if (io->nwin == 2) {
167                                 link->io.BasePort2 = io->win[1].base;
168                                 link->io.NumPorts2 = io->win[1].len;
169                         }
170                         if (pcmcia_request_io(link, &link->io) != 0)
171                                 goto next_entry;
172                         /* If we've got this far, we're done */
173                         break;
174                 }
175               next_entry:
176                 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
177                         dflt = *cfg;
178                 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
179         }
180
181         CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
182
183         /*
184          *      Register the card with the core.
185          */     
186         j=ixj_pcmcia_probe(link->io.BasePort1,link->io.BasePort1 + 0x10);
187
188         info->ndev = 1;
189         info->node.major = PHONE_MAJOR;
190         link->dev_node = &info->node;
191         ixj_get_serial(link, j);
192         return 0;
193       cs_failed:
194         cs_error(link, last_fn, last_ret);
195         ixj_cs_release(link);
196         return -ENODEV;
197 }
198
199 static void ixj_cs_release(struct pcmcia_device *link)
200 {
201         ixj_info_t *info = link->priv;
202         DEBUG(0, "ixj_cs_release(0x%p)\n", link);
203         info->ndev = 0;
204         pcmcia_disable_device(link);
205 }
206
207 static struct pcmcia_device_id ixj_ids[] = {
208         PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
209         PCMCIA_DEVICE_NULL
210 };
211 MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
212
213 static struct pcmcia_driver ixj_driver = {
214         .owner          = THIS_MODULE,
215         .drv            = {
216                 .name   = "ixj_cs",
217         },
218         .probe          = ixj_probe,
219         .remove         = ixj_detach,
220         .id_table       = ixj_ids,
221 };
222
223 static int __init ixj_pcmcia_init(void)
224 {
225         return pcmcia_register_driver(&ixj_driver);
226 }
227
228 static void ixj_pcmcia_exit(void)
229 {
230         pcmcia_unregister_driver(&ixj_driver);
231 }
232
233 module_init(ixj_pcmcia_init);
234 module_exit(ixj_pcmcia_exit);
235
236 MODULE_LICENSE("GPL");