blob: dda0ca45d904ff6b8323f83fb70d1a714b67f582 [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 tuple_t tuple;
73 u_short buf[128];
74 char *str;
75 int last_ret, last_fn, i, place;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 DEBUG(0, "ixj_get_serial(0x%p)\n", link);
77 tuple.TupleData = (cisdata_t *) buf;
78 tuple.TupleOffset = 0;
79 tuple.TupleDataMax = 80;
80 tuple.Attributes = 0;
81 tuple.DesiredTuple = CISTPL_VERS_1;
Dominik Brodowskifba395e2006-03-31 17:21:06 +020082 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
83 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 str = (char *) buf;
85 printk("PCMCIA Version %d.%d\n", str[0], str[1]);
86 str += 2;
87 printk("%s", str);
88 str = str + strlen(str) + 1;
89 printk(" %s", str);
90 str = str + strlen(str) + 1;
91 place = 1;
92 for (i = strlen(str) - 1; i >= 0; i--) {
93 switch (str[i]) {
94 case '0':
95 case '1':
96 case '2':
97 case '3':
98 case '4':
99 case '5':
100 case '6':
101 case '7':
102 case '8':
103 case '9':
104 j->serial += (str[i] - 48) * place;
105 break;
106 case 'A':
107 case 'B':
108 case 'C':
109 case 'D':
110 case 'E':
111 case 'F':
112 j->serial += (str[i] - 55) * place;
113 break;
114 case 'a':
115 case 'b':
116 case 'c':
117 case 'd':
118 case 'e':
119 case 'f':
120 j->serial += (str[i] - 87) * place;
121 break;
122 }
123 place = place * 0x10;
124 }
125 str = str + strlen(str) + 1;
126 printk(" version %s\n", str);
127 cs_failed:
128 return;
129}
130
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200131static int ixj_config(struct pcmcia_device * link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
133 IXJ *j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 ixj_info_t *info;
135 tuple_t tuple;
136 u_short buf[128];
137 cisparse_t parse;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
139 cistpl_cftable_entry_t dflt =
140 {
141 0
142 };
143 int last_ret, last_fn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 info = link->priv;
145 DEBUG(0, "ixj_config(0x%p)\n", link);
146 tuple.TupleData = (cisdata_t *) buf;
147 tuple.TupleOffset = 0;
148 tuple.TupleDataMax = 255;
149 tuple.Attributes = 0;
150 tuple.DesiredTuple = CISTPL_CONFIG;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200151 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
152 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
153 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 link->conf.ConfigBase = parse.config.base;
155 link->conf.Present = parse.config.rmask[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
157 tuple.Attributes = 0;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200158 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 while (1) {
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200160 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
161 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 goto next_entry;
163 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
164 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
165 link->conf.ConfigIndex = cfg->index;
166 link->io.BasePort1 = io->win[0].base;
167 link->io.NumPorts1 = io->win[0].len;
168 if (io->nwin == 2) {
169 link->io.BasePort2 = io->win[1].base;
170 link->io.NumPorts2 = io->win[1].len;
171 }
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200172 if (pcmcia_request_io(link, &link->io) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 goto next_entry;
174 /* If we've got this far, we're done */
175 break;
176 }
177 next_entry:
178 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
179 dflt = *cfg;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200180 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 }
182
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200183 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 /*
186 * Register the card with the core.
187 */
188 j=ixj_pcmcia_probe(link->io.BasePort1,link->io.BasePort1 + 0x10);
189
190 info->ndev = 1;
191 info->node.major = PHONE_MAJOR;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100192 link->dev_node = &info->node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 ixj_get_serial(link, j);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200194 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 cs_failed:
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200196 cs_error(link, last_fn, last_ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 ixj_cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200198 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199}
200
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200201static void ixj_cs_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
203 ixj_info_t *info = link->priv;
204 DEBUG(0, "ixj_cs_release(0x%p)\n", link);
205 info->ndev = 0;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200206 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
208
Dominik Brodowski07081272005-06-27 16:28:40 -0700209static struct pcmcia_device_id ixj_ids[] = {
210 PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
211 PCMCIA_DEVICE_NULL
212};
213MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215static struct pcmcia_driver ixj_driver = {
216 .owner = THIS_MODULE,
217 .drv = {
218 .name = "ixj_cs",
219 },
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200220 .probe = ixj_probe,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100221 .remove = ixj_detach,
Dominik Brodowski07081272005-06-27 16:28:40 -0700222 .id_table = ixj_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223};
224
225static int __init ixj_pcmcia_init(void)
226{
227 return pcmcia_register_driver(&ixj_driver);
228}
229
230static void ixj_pcmcia_exit(void)
231{
232 pcmcia_unregister_driver(&ixj_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
234
235module_init(ixj_pcmcia_init);
236module_exit(ixj_pcmcia_exit);
237
238MODULE_LICENSE("GPL");