RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / telephony / ixj_pcmcia.c
bloba1900e5025184521e0fe1c6f0c39b233e43026fe
1 #include "ixj-ver.h"
3 #include <linux/module.h>
5 #include <linux/init.h>
6 #include <linux/kernel.h> /* printk() */
7 #include <linux/fs.h> /* everything... */
8 #include <linux/errno.h> /* error codes */
9 #include <linux/slab.h>
11 #include <pcmcia/cs.h>
12 #include <pcmcia/cistpl.h>
13 #include <pcmcia/ds.h>
15 #include "ixj.h"
18 * PCMCIA service support for Quicknet cards
22 typedef struct ixj_info_t {
23 int ndev;
24 struct ixj *port;
25 } ixj_info_t;
27 static void ixj_detach(struct pcmcia_device *p_dev);
28 static int ixj_config(struct pcmcia_device * link);
29 static void ixj_cs_release(struct pcmcia_device * link);
31 static int ixj_probe(struct pcmcia_device *p_dev)
33 dev_dbg(&p_dev->dev, "ixj_attach()\n");
34 /* Create new ixj device */
35 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
36 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
37 p_dev->conf.IntType = INT_MEMORY_AND_IO;
38 p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
39 if (!p_dev->priv) {
40 return -ENOMEM;
43 return ixj_config(p_dev);
46 static void ixj_detach(struct pcmcia_device *link)
48 dev_dbg(&link->dev, "ixj_detach\n");
50 ixj_cs_release(link);
52 kfree(link->priv);
55 static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
57 char *str;
58 int i, place;
59 dev_dbg(&link->dev, "ixj_get_serial\n");
61 str = link->prod_id[0];
62 if (!str)
63 goto failed;
64 printk("%s", str);
65 str = link->prod_id[1];
66 if (!str)
67 goto failed;
68 printk(" %s", str);
69 str = link->prod_id[2];
70 if (!str)
71 goto failed;
72 place = 1;
73 for (i = strlen(str) - 1; i >= 0; i--) {
74 switch (str[i]) {
75 case '0':
76 case '1':
77 case '2':
78 case '3':
79 case '4':
80 case '5':
81 case '6':
82 case '7':
83 case '8':
84 case '9':
85 j->serial += (str[i] - 48) * place;
86 break;
87 case 'A':
88 case 'B':
89 case 'C':
90 case 'D':
91 case 'E':
92 case 'F':
93 j->serial += (str[i] - 55) * place;
94 break;
95 case 'a':
96 case 'b':
97 case 'c':
98 case 'd':
99 case 'e':
100 case 'f':
101 j->serial += (str[i] - 87) * place;
102 break;
104 place = place * 0x10;
106 str = link->prod_id[3];
107 if (!str)
108 goto failed;
109 printk(" version %s\n", str);
110 failed:
111 return;
114 static int ixj_config_check(struct pcmcia_device *p_dev,
115 cistpl_cftable_entry_t *cfg,
116 cistpl_cftable_entry_t *dflt,
117 unsigned int vcc,
118 void *priv_data)
120 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
121 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
122 p_dev->resource[0]->start = io->win[0].base;
123 p_dev->resource[0]->end = io->win[0].len;
124 p_dev->io_lines = 3;
125 if (io->nwin == 2) {
126 p_dev->resource[1]->start = io->win[1].base;
127 p_dev->resource[1]->end = io->win[1].len;
129 if (!pcmcia_request_io(p_dev))
130 return 0;
132 return -ENODEV;
135 static int ixj_config(struct pcmcia_device * link)
137 IXJ *j;
138 ixj_info_t *info;
139 cistpl_cftable_entry_t dflt = { 0 };
141 info = link->priv;
142 dev_dbg(&link->dev, "ixj_config\n");
144 if (pcmcia_loop_config(link, ixj_config_check, &dflt))
145 goto failed;
147 if (pcmcia_request_configuration(link, &link->conf))
148 goto failed;
151 * Register the card with the core.
153 j = ixj_pcmcia_probe(link->resource[0]->start,
154 link->resource[0]->start + 0x10);
156 info->ndev = 1;
157 ixj_get_serial(link, j);
158 return 0;
160 failed:
161 ixj_cs_release(link);
162 return -ENODEV;
165 static void ixj_cs_release(struct pcmcia_device *link)
167 ixj_info_t *info = link->priv;
168 dev_dbg(&link->dev, "ixj_cs_release\n");
169 info->ndev = 0;
170 pcmcia_disable_device(link);
173 static struct pcmcia_device_id ixj_ids[] = {
174 PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
175 PCMCIA_DEVICE_NULL
177 MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
179 static struct pcmcia_driver ixj_driver = {
180 .owner = THIS_MODULE,
181 .drv = {
182 .name = "ixj_cs",
184 .probe = ixj_probe,
185 .remove = ixj_detach,
186 .id_table = ixj_ids,
189 static int __init ixj_pcmcia_init(void)
191 return pcmcia_register_driver(&ixj_driver);
194 static void ixj_pcmcia_exit(void)
196 pcmcia_unregister_driver(&ixj_driver);
199 module_init(ixj_pcmcia_init);
200 module_exit(ixj_pcmcia_exit);
202 MODULE_LICENSE("GPL");