Commit | Line | Data |
---|---|---|
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 | |
22 | typedef struct ixj_info_t { | |
23 | int ndev; | |
1da177e4 LT |
24 | struct ixj *port; |
25 | } ixj_info_t; | |
26 | ||
cc3b4866 | 27 | static void ixj_detach(struct pcmcia_device *p_dev); |
15b99ac1 | 28 | static int ixj_config(struct pcmcia_device * link); |
fba395ee | 29 | static void ixj_cs_release(struct pcmcia_device * link); |
1da177e4 | 30 | |
15b99ac1 | 31 | static 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 */ |
90abdc3b DB |
35 | p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; |
36 | p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8; | |
fd238232 | 37 | p_dev->conf.IntType = INT_MEMORY_AND_IO; |
dd00cc48 | 38 | p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL); |
fd238232 | 39 | if (!p_dev->priv) { |
f8cfa618 | 40 | return -ENOMEM; |
1da177e4 | 41 | } |
f8cfa618 | 42 | |
15b99ac1 | 43 | return ixj_config(p_dev); |
1da177e4 LT |
44 | } |
45 | ||
fba395ee | 46 | static void ixj_detach(struct pcmcia_device *link) |
1da177e4 | 47 | { |
9b44de20 | 48 | dev_dbg(&link->dev, "ixj_detach\n"); |
b4635811 | 49 | |
e2d40963 | 50 | ixj_cs_release(link); |
cc3b4866 | 51 | |
1da177e4 | 52 | kfree(link->priv); |
1da177e4 LT |
53 | } |
54 | ||
fba395ee | 55 | static void ixj_get_serial(struct pcmcia_device * link, IXJ * j) |
1da177e4 | 56 | { |
1da177e4 | 57 | char *str; |
a9606fd3 | 58 | int i, place; |
9b44de20 | 59 | dev_dbg(&link->dev, "ixj_get_serial\n"); |
a9606fd3 DB |
60 | |
61 | str = link->prod_id[0]; | |
62 | if (!str) | |
9b44de20 | 63 | goto failed; |
1da177e4 | 64 | printk("%s", str); |
a9606fd3 DB |
65 | str = link->prod_id[1]; |
66 | if (!str) | |
9b44de20 | 67 | goto failed; |
1da177e4 | 68 | printk(" %s", str); |
a9606fd3 DB |
69 | str = link->prod_id[2]; |
70 | if (!str) | |
9b44de20 | 71 | goto failed; |
1da177e4 LT |
72 | place = 1; |
73 | for (i = strlen(str) - 1; i >= 0; i--) { | |
74 | switch (str[i]) { | |
75 | case '0': | |
76 | case '1': | |
77 | case '2': | |
78 | case '3': | |
79 | case '4': | |
80 | case '5': | |
81 | case '6': | |
82 | case '7': | |
83 | case '8': | |
84 | case '9': | |
85 | j->serial += (str[i] - 48) * place; | |
86 | break; | |
87 | case 'A': | |
88 | case 'B': | |
89 | case 'C': | |
90 | case 'D': | |
91 | case 'E': | |
92 | case 'F': | |
93 | j->serial += (str[i] - 55) * place; | |
94 | break; | |
95 | case 'a': | |
96 | case 'b': | |
97 | case 'c': | |
98 | case 'd': | |
99 | case 'e': | |
100 | case 'f': | |
101 | j->serial += (str[i] - 87) * place; | |
102 | break; | |
103 | } | |
104 | place = place * 0x10; | |
105 | } | |
a9606fd3 DB |
106 | str = link->prod_id[3]; |
107 | if (!str) | |
9b44de20 | 108 | goto failed; |
1da177e4 | 109 | printk(" version %s\n", str); |
9b44de20 | 110 | failed: |
1da177e4 LT |
111 | return; |
112 | } | |
113 | ||
84e2d340 DB |
114 | static int ixj_config_check(struct pcmcia_device *p_dev, |
115 | cistpl_cftable_entry_t *cfg, | |
8e2fc39d | 116 | cistpl_cftable_entry_t *dflt, |
ad913c11 | 117 | unsigned int vcc, |
84e2d340 DB |
118 | void *priv_data) |
119 | { | |
84e2d340 DB |
120 | if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) { |
121 | cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io; | |
90abdc3b DB |
122 | p_dev->resource[0]->start = io->win[0].base; |
123 | p_dev->resource[0]->end = io->win[0].len; | |
124 | p_dev->io_lines = 3; | |
84e2d340 | 125 | if (io->nwin == 2) { |
90abdc3b DB |
126 | p_dev->resource[1]->start = io->win[1].base; |
127 | p_dev->resource[1]->end = io->win[1].len; | |
84e2d340 | 128 | } |
90abdc3b | 129 | if (!pcmcia_request_io(p_dev)) |
84e2d340 DB |
130 | return 0; |
131 | } | |
132 | return -ENODEV; | |
133 | } | |
134 | ||
15b99ac1 | 135 | static 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 | 160 | failed: |
1da177e4 | 161 | ixj_cs_release(link); |
15b99ac1 | 162 | return -ENODEV; |
1da177e4 LT |
163 | } |
164 | ||
fba395ee | 165 | static 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 |
173 | static struct pcmcia_device_id ixj_ids[] = { |
174 | PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600), | |
175 | PCMCIA_DEVICE_NULL | |
176 | }; | |
177 | MODULE_DEVICE_TABLE(pcmcia, ixj_ids); | |
178 | ||
1da177e4 LT |
179 | static 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 | ||
189 | static int __init ixj_pcmcia_init(void) | |
190 | { | |
191 | return pcmcia_register_driver(&ixj_driver); | |
192 | } | |
193 | ||
194 | static void ixj_pcmcia_exit(void) | |
195 | { | |
196 | pcmcia_unregister_driver(&ixj_driver); | |
1da177e4 LT |
197 | } |
198 | ||
199 | module_init(ixj_pcmcia_init); | |
200 | module_exit(ixj_pcmcia_exit); | |
201 | ||
202 | MODULE_LICENSE("GPL"); |