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