blob: 3e658dc7c2d8fba9710ae34bc0b251750f640674 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include "ixj-ver.h"
2
3#include <linux/module.h>
4
5#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/kernel.h> /* printk() */
7#include <linux/fs.h> /* everything... */
8#include <linux/errno.h> /* error codes */
9#include <linux/slab.h>
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#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
22#ifdef PCMCIA_DEBUG
23static int pc_debug = PCMCIA_DEBUG;
24module_param(pc_debug, int, 0644);
25#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
26#else
27#define DEBUG(n, args...)
28#endif
29
30typedef struct ixj_info_t {
31 int ndev;
32 dev_node_t node;
33 struct ixj *port;
34} ixj_info_t;
35
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010036static void ixj_detach(struct pcmcia_device *p_dev);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020037static int ixj_config(struct pcmcia_device * link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020038static void ixj_cs_release(struct pcmcia_device * link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020040static int ixj_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 DEBUG(0, "ixj_attach()\n");
43 /* Create new ixj device */
Dominik Brodowskifd238232006-03-05 10:45:09 +010044 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
45 p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
46 p_dev->io.IOAddrLines = 3;
47 p_dev->conf.IntType = INT_MEMORY_AND_IO;
48 p_dev->priv = kmalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
49 if (!p_dev->priv) {
Dominik Brodowskif8cfa612005-11-14 21:25:51 +010050 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 }
Dominik Brodowskifd238232006-03-05 10:45:09 +010052 memset(p_dev->priv, 0, sizeof(struct ixj_info_t));
Dominik Brodowskif8cfa612005-11-14 21:25:51 +010053
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020054 return ixj_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
Dominik Brodowskifba395e2006-03-31 17:21:06 +020057static void ixj_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 DEBUG(0, "ixj_detach(0x%p)\n", link);
Dominik Brodowskib4635812005-11-14 21:25:35 +010060
Dominik Brodowskie2d40962006-03-02 00:09:29 +010061 ixj_cs_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010062
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 kfree(link->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}
65
66#define CS_CHECK(fn, ret) \
67do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
68
Dominik Brodowskifba395e2006-03-31 17:21:06 +020069static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 char *str;
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020072 int i, place;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 DEBUG(0, "ixj_get_serial(0x%p)\n", link);
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020074
75 str = link->prod_id[0];
76 if (!str)
77 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 printk("%s", str);
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020079 str = link->prod_id[1];
80 if (!str)
81 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 printk(" %s", str);
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020083 str = link->prod_id[2];
84 if (!str)
85 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 place = 1;
87 for (i = strlen(str) - 1; i >= 0; i--) {
88 switch (str[i]) {
89 case '0':
90 case '1':
91 case '2':
92 case '3':
93 case '4':
94 case '5':
95 case '6':
96 case '7':
97 case '8':
98 case '9':
99 j->serial += (str[i] - 48) * place;
100 break;
101 case 'A':
102 case 'B':
103 case 'C':
104 case 'D':
105 case 'E':
106 case 'F':
107 j->serial += (str[i] - 55) * place;
108 break;
109 case 'a':
110 case 'b':
111 case 'c':
112 case 'd':
113 case 'e':
114 case 'f':
115 j->serial += (str[i] - 87) * place;
116 break;
117 }
118 place = place * 0x10;
119 }
Dominik Brodowskia9606fd2006-06-04 18:06:13 +0200120 str = link->prod_id[3];
121 if (!str)
122 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 printk(" version %s\n", str);
124 cs_failed:
125 return;
126}
127
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200128static int ixj_config(struct pcmcia_device * link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
130 IXJ *j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 ixj_info_t *info;
132 tuple_t tuple;
133 u_short buf[128];
134 cisparse_t parse;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
136 cistpl_cftable_entry_t dflt =
137 {
138 0
139 };
140 int last_ret, last_fn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 info = link->priv;
142 DEBUG(0, "ixj_config(0x%p)\n", link);
143 tuple.TupleData = (cisdata_t *) buf;
144 tuple.TupleOffset = 0;
145 tuple.TupleDataMax = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
147 tuple.Attributes = 0;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200148 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 while (1) {
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200150 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
151 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 goto next_entry;
153 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
154 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
155 link->conf.ConfigIndex = cfg->index;
156 link->io.BasePort1 = io->win[0].base;
157 link->io.NumPorts1 = io->win[0].len;
158 if (io->nwin == 2) {
159 link->io.BasePort2 = io->win[1].base;
160 link->io.NumPorts2 = io->win[1].len;
161 }
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200162 if (pcmcia_request_io(link, &link->io) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 goto next_entry;
164 /* If we've got this far, we're done */
165 break;
166 }
167 next_entry:
168 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
169 dflt = *cfg;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200170 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 }
172
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200173 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 /*
176 * Register the card with the core.
177 */
178 j=ixj_pcmcia_probe(link->io.BasePort1,link->io.BasePort1 + 0x10);
179
180 info->ndev = 1;
181 info->node.major = PHONE_MAJOR;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100182 link->dev_node = &info->node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 ixj_get_serial(link, j);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200184 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 cs_failed:
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200186 cs_error(link, last_fn, last_ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 ixj_cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200188 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189}
190
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200191static void ixj_cs_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
193 ixj_info_t *info = link->priv;
194 DEBUG(0, "ixj_cs_release(0x%p)\n", link);
195 info->ndev = 0;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200196 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197}
198
Dominik Brodowski07081272005-06-27 16:28:40 -0700199static struct pcmcia_device_id ixj_ids[] = {
200 PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
201 PCMCIA_DEVICE_NULL
202};
203MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205static struct pcmcia_driver ixj_driver = {
206 .owner = THIS_MODULE,
207 .drv = {
208 .name = "ixj_cs",
209 },
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200210 .probe = ixj_probe,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100211 .remove = ixj_detach,
Dominik Brodowski07081272005-06-27 16:28:40 -0700212 .id_table = ixj_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213};
214
215static int __init ixj_pcmcia_init(void)
216{
217 return pcmcia_register_driver(&ixj_driver);
218}
219
220static void ixj_pcmcia_exit(void)
221{
222 pcmcia_unregister_driver(&ixj_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
225module_init(ixj_pcmcia_init);
226module_exit(ixj_pcmcia_exit);
227
228MODULE_LICENSE("GPL");