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