blob: 164a5dcf1f1e69a31d01a28348ab393e30100d1d [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>
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#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
24static int pc_debug = PCMCIA_DEBUG;
25module_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
31typedef struct ixj_info_t {
32 int ndev;
33 dev_node_t node;
34 struct ixj *port;
35} ixj_info_t;
36
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010037static void ixj_detach(struct pcmcia_device *p_dev);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020038static int ixj_config(struct pcmcia_device * link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020039static void ixj_cs_release(struct pcmcia_device * link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020041static int ixj_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 DEBUG(0, "ixj_attach()\n");
44 /* Create new ixj device */
Dominik Brodowskifd238232006-03-05 10:45:09 +010045 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) {
Dominik Brodowskif8cfa612005-11-14 21:25:51 +010051 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 }
Dominik Brodowskifd238232006-03-05 10:45:09 +010053 memset(p_dev->priv, 0, sizeof(struct ixj_info_t));
Dominik Brodowskif8cfa612005-11-14 21:25:51 +010054
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020055 return ixj_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056}
57
Dominik Brodowskifba395e2006-03-31 17:21:06 +020058static void ixj_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 DEBUG(0, "ixj_detach(0x%p)\n", link);
Dominik Brodowskib4635812005-11-14 21:25:35 +010061
Dominik Brodowskie2d40962006-03-02 00:09:29 +010062 ixj_cs_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010063
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 kfree(link->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
67#define CS_CHECK(fn, ret) \
68do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
69
Dominik Brodowskifba395e2006-03-31 17:21:06 +020070static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 char *str;
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020073 int i, place;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 DEBUG(0, "ixj_get_serial(0x%p)\n", link);
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020075
76 str = link->prod_id[0];
77 if (!str)
78 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 printk("%s", str);
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020080 str = link->prod_id[1];
81 if (!str)
82 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 printk(" %s", str);
Dominik Brodowskia9606fd2006-06-04 18:06:13 +020084 str = link->prod_id[2];
85 if (!str)
86 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 place = 1;
88 for (i = strlen(str) - 1; i >= 0; i--) {
89 switch (str[i]) {
90 case '0':
91 case '1':
92 case '2':
93 case '3':
94 case '4':
95 case '5':
96 case '6':
97 case '7':
98 case '8':
99 case '9':
100 j->serial += (str[i] - 48) * place;
101 break;
102 case 'A':
103 case 'B':
104 case 'C':
105 case 'D':
106 case 'E':
107 case 'F':
108 j->serial += (str[i] - 55) * place;
109 break;
110 case 'a':
111 case 'b':
112 case 'c':
113 case 'd':
114 case 'e':
115 case 'f':
116 j->serial += (str[i] - 87) * place;
117 break;
118 }
119 place = place * 0x10;
120 }
Dominik Brodowskia9606fd2006-06-04 18:06:13 +0200121 str = link->prod_id[3];
122 if (!str)
123 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 printk(" version %s\n", str);
125 cs_failed:
126 return;
127}
128
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200129static int ixj_config(struct pcmcia_device * link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
131 IXJ *j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 ixj_info_t *info;
133 tuple_t tuple;
134 u_short buf[128];
135 cisparse_t parse;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
137 cistpl_cftable_entry_t dflt =
138 {
139 0
140 };
141 int last_ret, last_fn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 info = link->priv;
143 DEBUG(0, "ixj_config(0x%p)\n", link);
144 tuple.TupleData = (cisdata_t *) buf;
145 tuple.TupleOffset = 0;
146 tuple.TupleDataMax = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
148 tuple.Attributes = 0;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200149 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 while (1) {
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200151 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
152 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 goto next_entry;
154 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
155 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
156 link->conf.ConfigIndex = cfg->index;
157 link->io.BasePort1 = io->win[0].base;
158 link->io.NumPorts1 = io->win[0].len;
159 if (io->nwin == 2) {
160 link->io.BasePort2 = io->win[1].base;
161 link->io.NumPorts2 = io->win[1].len;
162 }
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200163 if (pcmcia_request_io(link, &link->io) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 goto next_entry;
165 /* If we've got this far, we're done */
166 break;
167 }
168 next_entry:
169 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
170 dflt = *cfg;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200171 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 }
173
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200174 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176 /*
177 * Register the card with the core.
178 */
179 j=ixj_pcmcia_probe(link->io.BasePort1,link->io.BasePort1 + 0x10);
180
181 info->ndev = 1;
182 info->node.major = PHONE_MAJOR;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100183 link->dev_node = &info->node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 ixj_get_serial(link, j);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200185 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 cs_failed:
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200187 cs_error(link, last_fn, last_ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 ixj_cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200189 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190}
191
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200192static void ixj_cs_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193{
194 ixj_info_t *info = link->priv;
195 DEBUG(0, "ixj_cs_release(0x%p)\n", link);
196 info->ndev = 0;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200197 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
199
Dominik Brodowski07081272005-06-27 16:28:40 -0700200static struct pcmcia_device_id ixj_ids[] = {
201 PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
202 PCMCIA_DEVICE_NULL
203};
204MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206static struct pcmcia_driver ixj_driver = {
207 .owner = THIS_MODULE,
208 .drv = {
209 .name = "ixj_cs",
210 },
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200211 .probe = ixj_probe,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100212 .remove = ixj_detach,
Dominik Brodowski07081272005-06-27 16:28:40 -0700213 .id_table = ixj_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214};
215
216static int __init ixj_pcmcia_init(void)
217{
218 return pcmcia_register_driver(&ixj_driver);
219}
220
221static void ixj_pcmcia_exit(void)
222{
223 pcmcia_unregister_driver(&ixj_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224}
225
226module_init(ixj_pcmcia_init);
227module_exit(ixj_pcmcia_exit);
228
229MODULE_LICENSE("GPL");