]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/telephony/ixj_pcmcia.c
Merge branch 'l2x0-pull-rmk' of git://dev.omapzoom.org/pub/scm/santosh/kernel-omap4...
[net-next-2.6.git] / drivers / telephony / ixj_pcmcia.c
CommitLineData
1da177e4
LT
1#include "ixj-ver.h"
2
3#include <linux/module.h>
4
5#include <linux/init.h>
1da177e4
LT
6#include <linux/kernel.h> /* printk() */
7#include <linux/fs.h> /* everything... */
8#include <linux/errno.h> /* error codes */
9#include <linux/slab.h>
10
1da177e4
LT
11#include <pcmcia/cistpl.h>
12#include <pcmcia/ds.h>
13
14#include "ixj.h"
15
16/*
17 * PCMCIA service support for Quicknet cards
18 */
19
1da177e4
LT
20
21typedef struct ixj_info_t {
22 int ndev;
1da177e4
LT
23 struct ixj *port;
24} ixj_info_t;
25
cc3b4866 26static void ixj_detach(struct pcmcia_device *p_dev);
15b99ac1 27static int ixj_config(struct pcmcia_device * link);
fba395ee 28static void ixj_cs_release(struct pcmcia_device * link);
1da177e4 29
15b99ac1 30static int ixj_probe(struct pcmcia_device *p_dev)
1da177e4 31{
9b44de20 32 dev_dbg(&p_dev->dev, "ixj_attach()\n");
1da177e4 33 /* Create new ixj device */
dd00cc48 34 p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
fd238232 35 if (!p_dev->priv) {
f8cfa618 36 return -ENOMEM;
1da177e4 37 }
f8cfa618 38
15b99ac1 39 return ixj_config(p_dev);
1da177e4
LT
40}
41
fba395ee 42static void ixj_detach(struct pcmcia_device *link)
1da177e4 43{
9b44de20 44 dev_dbg(&link->dev, "ixj_detach\n");
b4635811 45
e2d40963 46 ixj_cs_release(link);
cc3b4866 47
1da177e4 48 kfree(link->priv);
1da177e4
LT
49}
50
fba395ee 51static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
1da177e4 52{
1da177e4 53 char *str;
a9606fd3 54 int i, place;
9b44de20 55 dev_dbg(&link->dev, "ixj_get_serial\n");
a9606fd3
DB
56
57 str = link->prod_id[0];
58 if (!str)
9b44de20 59 goto failed;
1da177e4 60 printk("%s", str);
a9606fd3
DB
61 str = link->prod_id[1];
62 if (!str)
9b44de20 63 goto failed;
1da177e4 64 printk(" %s", str);
a9606fd3
DB
65 str = link->prod_id[2];
66 if (!str)
9b44de20 67 goto failed;
1da177e4
LT
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;
99 }
100 place = place * 0x10;
101 }
a9606fd3
DB
102 str = link->prod_id[3];
103 if (!str)
9b44de20 104 goto failed;
1da177e4 105 printk(" version %s\n", str);
9b44de20 106failed:
1da177e4
LT
107 return;
108}
109
00990e7c 110static int ixj_config_check(struct pcmcia_device *p_dev, void *priv_data)
84e2d340 111{
00990e7c
DB
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;
117
118 return pcmcia_request_io(p_dev);
84e2d340
DB
119}
120
15b99ac1 121static int ixj_config(struct pcmcia_device * link)
1da177e4
LT
122{
123 IXJ *j;
1da177e4 124 ixj_info_t *info;
84e2d340 125
1da177e4 126 info = link->priv;
9b44de20 127 dev_dbg(&link->dev, "ixj_config\n");
1da177e4 128
00990e7c
DB
129 link->config_flags = CONF_AUTO_SET_IO;
130
131 if (pcmcia_loop_config(link, ixj_config_check, NULL))
9b44de20 132 goto failed;
84e2d340 133
1ac71e5a 134 if (pcmcia_enable_device(link))
9b44de20 135 goto failed;
1da177e4
LT
136
137 /*
138 * Register the card with the core.
84e2d340 139 */
9a017a91
DB
140 j = ixj_pcmcia_probe(link->resource[0]->start,
141 link->resource[0]->start + 0x10);
1da177e4
LT
142
143 info->ndev = 1;
1da177e4 144 ixj_get_serial(link, j);
15b99ac1 145 return 0;
84e2d340 146
9b44de20 147failed:
1da177e4 148 ixj_cs_release(link);
15b99ac1 149 return -ENODEV;
1da177e4
LT
150}
151
fba395ee 152static void ixj_cs_release(struct pcmcia_device *link)
1da177e4
LT
153{
154 ixj_info_t *info = link->priv;
9b44de20 155 dev_dbg(&link->dev, "ixj_cs_release\n");
1da177e4 156 info->ndev = 0;
fba395ee 157 pcmcia_disable_device(link);
1da177e4
LT
158}
159
07081273
DB
160static struct pcmcia_device_id ixj_ids[] = {
161 PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
162 PCMCIA_DEVICE_NULL
163};
164MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
165
1da177e4
LT
166static struct pcmcia_driver ixj_driver = {
167 .owner = THIS_MODULE,
2e9b981a 168 .name = "ixj_cs",
15b99ac1 169 .probe = ixj_probe,
cc3b4866 170 .remove = ixj_detach,
07081273 171 .id_table = ixj_ids,
1da177e4
LT
172};
173
174static int __init ixj_pcmcia_init(void)
175{
176 return pcmcia_register_driver(&ixj_driver);
177}
178
179static void ixj_pcmcia_exit(void)
180{
181 pcmcia_unregister_driver(&ixj_driver);
1da177e4
LT
182}
183
184module_init(ixj_pcmcia_init);
185module_exit(ixj_pcmcia_exit);
186
187MODULE_LICENSE("GPL");