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