proc: use seq_puts()/seq_putc() where possible
[linux-2.6/next.git] / drivers / telephony / ixj_pcmcia.c
blobd005b9eeebbcc1f751763c7ab039c9dea13333ca
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/cistpl.h>
12 #include <pcmcia/ds.h>
14 #include "ixj.h"
17 * PCMCIA service support for Quicknet cards
21 typedef struct ixj_info_t {
22 int ndev;
23 struct ixj *port;
24 } ixj_info_t;
26 static void ixj_detach(struct pcmcia_device *p_dev);
27 static int ixj_config(struct pcmcia_device * link);
28 static void ixj_cs_release(struct pcmcia_device * link);
30 static int ixj_probe(struct pcmcia_device *p_dev)
32 dev_dbg(&p_dev->dev, "ixj_attach()\n");
33 /* Create new ixj device */
34 p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
35 if (!p_dev->priv) {
36 return -ENOMEM;
39 return ixj_config(p_dev);
42 static void ixj_detach(struct pcmcia_device *link)
44 dev_dbg(&link->dev, "ixj_detach\n");
46 ixj_cs_release(link);
48 kfree(link->priv);
51 static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
53 char *str;
54 int i, place;
55 dev_dbg(&link->dev, "ixj_get_serial\n");
57 str = link->prod_id[0];
58 if (!str)
59 goto failed;
60 printk("%s", str);
61 str = link->prod_id[1];
62 if (!str)
63 goto failed;
64 printk(" %s", str);
65 str = link->prod_id[2];
66 if (!str)
67 goto failed;
68 place = 1;
69 for (i = strlen(str) - 1; i >= 0; i--) {
70 switch (str[i]) {
71 case '0':
72 case '1':
73 case '2':
74 case '3':
75 case '4':
76 case '5':
77 case '6':
78 case '7':
79 case '8':
80 case '9':
81 j->serial += (str[i] - 48) * place;
82 break;
83 case 'A':
84 case 'B':
85 case 'C':
86 case 'D':
87 case 'E':
88 case 'F':
89 j->serial += (str[i] - 55) * place;
90 break;
91 case 'a':
92 case 'b':
93 case 'c':
94 case 'd':
95 case 'e':
96 case 'f':
97 j->serial += (str[i] - 87) * place;
98 break;
100 place = place * 0x10;
102 str = link->prod_id[3];
103 if (!str)
104 goto failed;
105 printk(" version %s\n", str);
106 failed:
107 return;
110 static int ixj_config_check(struct pcmcia_device *p_dev, void *priv_data)
112 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
113 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
114 p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
115 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
116 p_dev->io_lines = 3;
118 return pcmcia_request_io(p_dev);
121 static int ixj_config(struct pcmcia_device * link)
123 IXJ *j;
124 ixj_info_t *info;
126 info = link->priv;
127 dev_dbg(&link->dev, "ixj_config\n");
129 link->config_flags = CONF_AUTO_SET_IO;
131 if (pcmcia_loop_config(link, ixj_config_check, NULL))
132 goto failed;
134 if (pcmcia_enable_device(link))
135 goto failed;
138 * Register the card with the core.
140 j = ixj_pcmcia_probe(link->resource[0]->start,
141 link->resource[0]->start + 0x10);
143 info->ndev = 1;
144 ixj_get_serial(link, j);
145 return 0;
147 failed:
148 ixj_cs_release(link);
149 return -ENODEV;
152 static void ixj_cs_release(struct pcmcia_device *link)
154 ixj_info_t *info = link->priv;
155 dev_dbg(&link->dev, "ixj_cs_release\n");
156 info->ndev = 0;
157 pcmcia_disable_device(link);
160 static struct pcmcia_device_id ixj_ids[] = {
161 PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
162 PCMCIA_DEVICE_NULL
164 MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
166 static struct pcmcia_driver ixj_driver = {
167 .owner = THIS_MODULE,
168 .name = "ixj_cs",
169 .probe = ixj_probe,
170 .remove = ixj_detach,
171 .id_table = ixj_ids,
174 static int __init ixj_pcmcia_init(void)
176 return pcmcia_register_driver(&ixj_driver);
179 static void ixj_pcmcia_exit(void)
181 pcmcia_unregister_driver(&ixj_driver);
184 module_init(ixj_pcmcia_init);
185 module_exit(ixj_pcmcia_exit);
187 MODULE_LICENSE("GPL");