]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #include "ixj-ver.h" |
2 | ||
3 | #include <linux/module.h> | |
4 | ||
5 | #include <linux/init.h> | |
6 | #include <linux/sched.h> | |
7 | #include <linux/kernel.h> /* printk() */ | |
8 | #include <linux/fs.h> /* everything... */ | |
9 | #include <linux/errno.h> /* error codes */ | |
10 | #include <linux/slab.h> | |
11 | ||
1da177e4 LT |
12 | #include <pcmcia/cs_types.h> |
13 | #include <pcmcia/cs.h> | |
14 | #include <pcmcia/cistpl.h> | |
15 | #include <pcmcia/ds.h> | |
16 | ||
17 | #include "ixj.h" | |
18 | ||
19 | /* | |
20 | * PCMCIA service support for Quicknet cards | |
21 | */ | |
22 | ||
23 | #ifdef PCMCIA_DEBUG | |
24 | static int pc_debug = PCMCIA_DEBUG; | |
25 | module_param(pc_debug, int, 0644); | |
26 | #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args) | |
27 | #else | |
28 | #define DEBUG(n, args...) | |
29 | #endif | |
30 | ||
31 | typedef struct ixj_info_t { | |
32 | int ndev; | |
33 | dev_node_t node; | |
34 | struct ixj *port; | |
35 | } ixj_info_t; | |
36 | ||
cc3b4866 | 37 | static void ixj_detach(struct pcmcia_device *p_dev); |
fba395ee DB |
38 | static void ixj_config(struct pcmcia_device * link); |
39 | static void ixj_cs_release(struct pcmcia_device * link); | |
1da177e4 | 40 | |
f8cfa618 | 41 | static int ixj_attach(struct pcmcia_device *p_dev) |
1da177e4 | 42 | { |
1da177e4 LT |
43 | DEBUG(0, "ixj_attach()\n"); |
44 | /* Create new ixj device */ | |
fd238232 DB |
45 | p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8; |
46 | p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_8; | |
47 | p_dev->io.IOAddrLines = 3; | |
48 | p_dev->conf.IntType = INT_MEMORY_AND_IO; | |
49 | p_dev->priv = kmalloc(sizeof(struct ixj_info_t), GFP_KERNEL); | |
50 | if (!p_dev->priv) { | |
f8cfa618 | 51 | return -ENOMEM; |
1da177e4 | 52 | } |
fd238232 | 53 | memset(p_dev->priv, 0, sizeof(struct ixj_info_t)); |
f8cfa618 | 54 | |
fd238232 DB |
55 | p_dev->state |= DEV_PRESENT | DEV_CONFIG_PENDING; |
56 | ixj_config(p_dev); | |
f8cfa618 DB |
57 | |
58 | return 0; | |
1da177e4 LT |
59 | } |
60 | ||
fba395ee | 61 | static void ixj_detach(struct pcmcia_device *link) |
1da177e4 | 62 | { |
1da177e4 | 63 | DEBUG(0, "ixj_detach(0x%p)\n", link); |
b4635811 | 64 | |
1da177e4 LT |
65 | link->state &= ~DEV_RELEASE_PENDING; |
66 | if (link->state & DEV_CONFIG) | |
67 | ixj_cs_release(link); | |
cc3b4866 | 68 | |
1da177e4 | 69 | kfree(link->priv); |
1da177e4 LT |
70 | } |
71 | ||
72 | #define CS_CHECK(fn, ret) \ | |
73 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) | |
74 | ||
fba395ee | 75 | static void ixj_get_serial(struct pcmcia_device * link, IXJ * j) |
1da177e4 | 76 | { |
1da177e4 LT |
77 | tuple_t tuple; |
78 | u_short buf[128]; | |
79 | char *str; | |
80 | int last_ret, last_fn, i, place; | |
1da177e4 LT |
81 | DEBUG(0, "ixj_get_serial(0x%p)\n", link); |
82 | tuple.TupleData = (cisdata_t *) buf; | |
83 | tuple.TupleOffset = 0; | |
84 | tuple.TupleDataMax = 80; | |
85 | tuple.Attributes = 0; | |
86 | tuple.DesiredTuple = CISTPL_VERS_1; | |
fba395ee DB |
87 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); |
88 | CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple)); | |
1da177e4 LT |
89 | str = (char *) buf; |
90 | printk("PCMCIA Version %d.%d\n", str[0], str[1]); | |
91 | str += 2; | |
92 | printk("%s", str); | |
93 | str = str + strlen(str) + 1; | |
94 | printk(" %s", str); | |
95 | str = str + strlen(str) + 1; | |
96 | place = 1; | |
97 | for (i = strlen(str) - 1; i >= 0; i--) { | |
98 | switch (str[i]) { | |
99 | case '0': | |
100 | case '1': | |
101 | case '2': | |
102 | case '3': | |
103 | case '4': | |
104 | case '5': | |
105 | case '6': | |
106 | case '7': | |
107 | case '8': | |
108 | case '9': | |
109 | j->serial += (str[i] - 48) * place; | |
110 | break; | |
111 | case 'A': | |
112 | case 'B': | |
113 | case 'C': | |
114 | case 'D': | |
115 | case 'E': | |
116 | case 'F': | |
117 | j->serial += (str[i] - 55) * place; | |
118 | break; | |
119 | case 'a': | |
120 | case 'b': | |
121 | case 'c': | |
122 | case 'd': | |
123 | case 'e': | |
124 | case 'f': | |
125 | j->serial += (str[i] - 87) * place; | |
126 | break; | |
127 | } | |
128 | place = place * 0x10; | |
129 | } | |
130 | str = str + strlen(str) + 1; | |
131 | printk(" version %s\n", str); | |
132 | cs_failed: | |
133 | return; | |
134 | } | |
135 | ||
fba395ee | 136 | static void ixj_config(struct pcmcia_device * link) |
1da177e4 LT |
137 | { |
138 | IXJ *j; | |
1da177e4 LT |
139 | ixj_info_t *info; |
140 | tuple_t tuple; | |
141 | u_short buf[128]; | |
142 | cisparse_t parse; | |
1da177e4 LT |
143 | cistpl_cftable_entry_t *cfg = &parse.cftable_entry; |
144 | cistpl_cftable_entry_t dflt = | |
145 | { | |
146 | 0 | |
147 | }; | |
148 | int last_ret, last_fn; | |
1da177e4 LT |
149 | info = link->priv; |
150 | DEBUG(0, "ixj_config(0x%p)\n", link); | |
151 | tuple.TupleData = (cisdata_t *) buf; | |
152 | tuple.TupleOffset = 0; | |
153 | tuple.TupleDataMax = 255; | |
154 | tuple.Attributes = 0; | |
155 | tuple.DesiredTuple = CISTPL_CONFIG; | |
fba395ee DB |
156 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); |
157 | CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple)); | |
158 | CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse)); | |
1da177e4 LT |
159 | link->conf.ConfigBase = parse.config.base; |
160 | link->conf.Present = parse.config.rmask[0]; | |
161 | link->state |= DEV_CONFIG; | |
1da177e4 LT |
162 | tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; |
163 | tuple.Attributes = 0; | |
fba395ee | 164 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); |
1da177e4 | 165 | while (1) { |
fba395ee DB |
166 | if (pcmcia_get_tuple_data(link, &tuple) != 0 || |
167 | pcmcia_parse_tuple(link, &tuple, &parse) != 0) | |
1da177e4 LT |
168 | goto next_entry; |
169 | if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { | |
170 | cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; | |
171 | link->conf.ConfigIndex = cfg->index; | |
172 | link->io.BasePort1 = io->win[0].base; | |
173 | link->io.NumPorts1 = io->win[0].len; | |
174 | if (io->nwin == 2) { | |
175 | link->io.BasePort2 = io->win[1].base; | |
176 | link->io.NumPorts2 = io->win[1].len; | |
177 | } | |
fba395ee | 178 | if (pcmcia_request_io(link, &link->io) != 0) |
1da177e4 LT |
179 | goto next_entry; |
180 | /* If we've got this far, we're done */ | |
181 | break; | |
182 | } | |
183 | next_entry: | |
184 | if (cfg->flags & CISTPL_CFTABLE_DEFAULT) | |
185 | dflt = *cfg; | |
fba395ee | 186 | CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple)); |
1da177e4 LT |
187 | } |
188 | ||
fba395ee | 189 | CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); |
1da177e4 LT |
190 | |
191 | /* | |
192 | * Register the card with the core. | |
193 | */ | |
194 | j=ixj_pcmcia_probe(link->io.BasePort1,link->io.BasePort1 + 0x10); | |
195 | ||
196 | info->ndev = 1; | |
197 | info->node.major = PHONE_MAJOR; | |
fd238232 | 198 | link->dev_node = &info->node; |
1da177e4 LT |
199 | ixj_get_serial(link, j); |
200 | link->state &= ~DEV_CONFIG_PENDING; | |
201 | return; | |
202 | cs_failed: | |
fba395ee | 203 | cs_error(link, last_fn, last_ret); |
1da177e4 LT |
204 | ixj_cs_release(link); |
205 | } | |
206 | ||
fba395ee | 207 | static void ixj_cs_release(struct pcmcia_device *link) |
1da177e4 LT |
208 | { |
209 | ixj_info_t *info = link->priv; | |
210 | DEBUG(0, "ixj_cs_release(0x%p)\n", link); | |
211 | info->ndev = 0; | |
fba395ee | 212 | pcmcia_disable_device(link); |
1da177e4 LT |
213 | } |
214 | ||
07081273 DB |
215 | static struct pcmcia_device_id ixj_ids[] = { |
216 | PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600), | |
217 | PCMCIA_DEVICE_NULL | |
218 | }; | |
219 | MODULE_DEVICE_TABLE(pcmcia, ixj_ids); | |
220 | ||
1da177e4 LT |
221 | static struct pcmcia_driver ixj_driver = { |
222 | .owner = THIS_MODULE, | |
223 | .drv = { | |
224 | .name = "ixj_cs", | |
225 | }, | |
f8cfa618 | 226 | .probe = ixj_attach, |
cc3b4866 | 227 | .remove = ixj_detach, |
07081273 | 228 | .id_table = ixj_ids, |
1da177e4 LT |
229 | }; |
230 | ||
231 | static int __init ixj_pcmcia_init(void) | |
232 | { | |
233 | return pcmcia_register_driver(&ixj_driver); | |
234 | } | |
235 | ||
236 | static void ixj_pcmcia_exit(void) | |
237 | { | |
238 | pcmcia_unregister_driver(&ixj_driver); | |
1da177e4 LT |
239 | } |
240 | ||
241 | module_init(ixj_pcmcia_init); | |
242 | module_exit(ixj_pcmcia_exit); | |
243 | ||
244 | MODULE_LICENSE("GPL"); |