Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jlbec...
[deliverable/linux.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/cs_types.h>
12#include <pcmcia/cs.h>
13#include <pcmcia/cistpl.h>
14#include <pcmcia/ds.h>
15
16#include "ixj.h"
17
18/*
19 * PCMCIA service support for Quicknet cards
20 */
21
1da177e4
LT
22
23typedef struct ixj_info_t {
24 int ndev;
25 dev_node_t node;
26 struct ixj *port;
27} ixj_info_t;
28
cc3b4866 29static void ixj_detach(struct pcmcia_device *p_dev);
15b99ac1 30static int ixj_config(struct pcmcia_device * link);
fba395ee 31static void ixj_cs_release(struct pcmcia_device * link);
1da177e4 32
15b99ac1 33static int ixj_probe(struct pcmcia_device *p_dev)
1da177e4 34{
9b44de20 35 dev_dbg(&p_dev->dev, "ixj_attach()\n");
1da177e4 36 /* Create new ixj device */
fd238232
DB
37 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
38 p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
39 p_dev->io.IOAddrLines = 3;
40 p_dev->conf.IntType = INT_MEMORY_AND_IO;
dd00cc48 41 p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
fd238232 42 if (!p_dev->priv) {
f8cfa618 43 return -ENOMEM;
1da177e4 44 }
f8cfa618 45
15b99ac1 46 return ixj_config(p_dev);
1da177e4
LT
47}
48
fba395ee 49static void ixj_detach(struct pcmcia_device *link)
1da177e4 50{
9b44de20 51 dev_dbg(&link->dev, "ixj_detach\n");
b4635811 52
e2d40963 53 ixj_cs_release(link);
cc3b4866 54
1da177e4 55 kfree(link->priv);
1da177e4
LT
56}
57
fba395ee 58static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
1da177e4 59{
1da177e4 60 char *str;
a9606fd3 61 int i, place;
9b44de20 62 dev_dbg(&link->dev, "ixj_get_serial\n");
a9606fd3
DB
63
64 str = link->prod_id[0];
65 if (!str)
9b44de20 66 goto failed;
1da177e4 67 printk("%s", str);
a9606fd3
DB
68 str = link->prod_id[1];
69 if (!str)
9b44de20 70 goto failed;
1da177e4 71 printk(" %s", str);
a9606fd3
DB
72 str = link->prod_id[2];
73 if (!str)
9b44de20 74 goto failed;
1da177e4
LT
75 place = 1;
76 for (i = strlen(str) - 1; i >= 0; i--) {
77 switch (str[i]) {
78 case '0':
79 case '1':
80 case '2':
81 case '3':
82 case '4':
83 case '5':
84 case '6':
85 case '7':
86 case '8':
87 case '9':
88 j->serial += (str[i] - 48) * place;
89 break;
90 case 'A':
91 case 'B':
92 case 'C':
93 case 'D':
94 case 'E':
95 case 'F':
96 j->serial += (str[i] - 55) * place;
97 break;
98 case 'a':
99 case 'b':
100 case 'c':
101 case 'd':
102 case 'e':
103 case 'f':
104 j->serial += (str[i] - 87) * place;
105 break;
106 }
107 place = place * 0x10;
108 }
a9606fd3
DB
109 str = link->prod_id[3];
110 if (!str)
9b44de20 111 goto failed;
1da177e4 112 printk(" version %s\n", str);
9b44de20 113failed:
1da177e4
LT
114 return;
115}
116
84e2d340
DB
117static int ixj_config_check(struct pcmcia_device *p_dev,
118 cistpl_cftable_entry_t *cfg,
8e2fc39d 119 cistpl_cftable_entry_t *dflt,
ad913c11 120 unsigned int vcc,
84e2d340
DB
121 void *priv_data)
122{
84e2d340
DB
123 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
124 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
84e2d340
DB
125 p_dev->io.BasePort1 = io->win[0].base;
126 p_dev->io.NumPorts1 = io->win[0].len;
127 if (io->nwin == 2) {
128 p_dev->io.BasePort2 = io->win[1].base;
129 p_dev->io.NumPorts2 = io->win[1].len;
130 }
8e2fc39d 131 if (!pcmcia_request_io(p_dev, &p_dev->io))
84e2d340
DB
132 return 0;
133 }
134 return -ENODEV;
135}
136
15b99ac1 137static int ixj_config(struct pcmcia_device * link)
1da177e4
LT
138{
139 IXJ *j;
1da177e4 140 ixj_info_t *info;
84e2d340
DB
141 cistpl_cftable_entry_t dflt = { 0 };
142
1da177e4 143 info = link->priv;
9b44de20 144 dev_dbg(&link->dev, "ixj_config\n");
1da177e4 145
84e2d340 146 if (pcmcia_loop_config(link, ixj_config_check, &dflt))
9b44de20 147 goto failed;
84e2d340
DB
148
149 if (pcmcia_request_configuration(link, &link->conf))
9b44de20 150 goto failed;
1da177e4
LT
151
152 /*
153 * Register the card with the core.
84e2d340
DB
154 */
155 j = ixj_pcmcia_probe(link->io.BasePort1, link->io.BasePort1 + 0x10);
1da177e4
LT
156
157 info->ndev = 1;
158 info->node.major = PHONE_MAJOR;
fd238232 159 link->dev_node = &info->node;
1da177e4 160 ixj_get_serial(link, j);
15b99ac1 161 return 0;
84e2d340 162
9b44de20 163failed:
1da177e4 164 ixj_cs_release(link);
15b99ac1 165 return -ENODEV;
1da177e4
LT
166}
167
fba395ee 168static void ixj_cs_release(struct pcmcia_device *link)
1da177e4
LT
169{
170 ixj_info_t *info = link->priv;
9b44de20 171 dev_dbg(&link->dev, "ixj_cs_release\n");
1da177e4 172 info->ndev = 0;
fba395ee 173 pcmcia_disable_device(link);
1da177e4
LT
174}
175
07081273
DB
176static struct pcmcia_device_id ixj_ids[] = {
177 PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
178 PCMCIA_DEVICE_NULL
179};
180MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
181
1da177e4
LT
182static struct pcmcia_driver ixj_driver = {
183 .owner = THIS_MODULE,
184 .drv = {
185 .name = "ixj_cs",
186 },
15b99ac1 187 .probe = ixj_probe,
cc3b4866 188 .remove = ixj_detach,
07081273 189 .id_table = ixj_ids,
1da177e4
LT
190};
191
192static int __init ixj_pcmcia_init(void)
193{
194 return pcmcia_register_driver(&ixj_driver);
195}
196
197static void ixj_pcmcia_exit(void)
198{
199 pcmcia_unregister_driver(&ixj_driver);
1da177e4
LT
200}
201
202module_init(ixj_pcmcia_init);
203module_exit(ixj_pcmcia_exit);
204
205MODULE_LICENSE("GPL");
This page took 0.717427 seconds and 5 git commands to generate.