3 #include <linux/module.h>
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>
12 #include <pcmcia/cs_types.h>
13 #include <pcmcia/cs.h>
14 #include <pcmcia/cistpl.h>
15 #include <pcmcia/ds.h>
20 * PCMCIA service support for Quicknet cards
24 static int pc_debug
= PCMCIA_DEBUG
;
25 module_param(pc_debug
, int, 0644);
26 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
28 #define DEBUG(n, args...)
31 typedef struct ixj_info_t
{
37 static void ixj_detach(struct pcmcia_device
*p_dev
);
38 static int ixj_config(struct pcmcia_device
* link
);
39 static void ixj_cs_release(struct pcmcia_device
* link
);
41 static int ixj_probe(struct pcmcia_device
*p_dev
)
43 DEBUG(0, "ixj_attach()\n");
44 /* Create new ixj device */
45 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
);
53 memset(p_dev
->priv
, 0, sizeof(struct ixj_info_t
));
55 p_dev
->state
|= DEV_PRESENT
| DEV_CONFIG_PENDING
;
56 return ixj_config(p_dev
);
59 static void ixj_detach(struct pcmcia_device
*link
)
61 DEBUG(0, "ixj_detach(0x%p)\n", link
);
63 link
->state
&= ~DEV_RELEASE_PENDING
;
64 if (link
->state
& DEV_CONFIG
)
70 #define CS_CHECK(fn, ret) \
71 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
73 static void ixj_get_serial(struct pcmcia_device
* link
, IXJ
* j
)
78 int last_ret
, last_fn
, i
, place
;
79 DEBUG(0, "ixj_get_serial(0x%p)\n", link
);
80 tuple
.TupleData
= (cisdata_t
*) buf
;
81 tuple
.TupleOffset
= 0;
82 tuple
.TupleDataMax
= 80;
84 tuple
.DesiredTuple
= CISTPL_VERS_1
;
85 CS_CHECK(GetFirstTuple
, pcmcia_get_first_tuple(link
, &tuple
));
86 CS_CHECK(GetTupleData
, pcmcia_get_tuple_data(link
, &tuple
));
88 printk("PCMCIA Version %d.%d\n", str
[0], str
[1]);
91 str
= str
+ strlen(str
) + 1;
93 str
= str
+ strlen(str
) + 1;
95 for (i
= strlen(str
) - 1; i
>= 0; i
--) {
107 j
->serial
+= (str
[i
] - 48) * place
;
115 j
->serial
+= (str
[i
] - 55) * place
;
123 j
->serial
+= (str
[i
] - 87) * place
;
126 place
= place
* 0x10;
128 str
= str
+ strlen(str
) + 1;
129 printk(" version %s\n", str
);
134 static int ixj_config(struct pcmcia_device
* link
)
141 cistpl_cftable_entry_t
*cfg
= &parse
.cftable_entry
;
142 cistpl_cftable_entry_t dflt
=
146 int last_ret
, last_fn
;
148 DEBUG(0, "ixj_config(0x%p)\n", link
);
149 tuple
.TupleData
= (cisdata_t
*) buf
;
150 tuple
.TupleOffset
= 0;
151 tuple
.TupleDataMax
= 255;
152 tuple
.Attributes
= 0;
153 tuple
.DesiredTuple
= CISTPL_CONFIG
;
154 CS_CHECK(GetFirstTuple
, pcmcia_get_first_tuple(link
, &tuple
));
155 CS_CHECK(GetTupleData
, pcmcia_get_tuple_data(link
, &tuple
));
156 CS_CHECK(ParseTuple
, pcmcia_parse_tuple(link
, &tuple
, &parse
));
157 link
->conf
.ConfigBase
= parse
.config
.base
;
158 link
->conf
.Present
= parse
.config
.rmask
[0];
159 link
->state
|= DEV_CONFIG
;
160 tuple
.DesiredTuple
= CISTPL_CFTABLE_ENTRY
;
161 tuple
.Attributes
= 0;
162 CS_CHECK(GetFirstTuple
, pcmcia_get_first_tuple(link
, &tuple
));
164 if (pcmcia_get_tuple_data(link
, &tuple
) != 0 ||
165 pcmcia_parse_tuple(link
, &tuple
, &parse
) != 0)
167 if ((cfg
->io
.nwin
> 0) || (dflt
.io
.nwin
> 0)) {
168 cistpl_io_t
*io
= (cfg
->io
.nwin
) ? &cfg
->io
: &dflt
.io
;
169 link
->conf
.ConfigIndex
= cfg
->index
;
170 link
->io
.BasePort1
= io
->win
[0].base
;
171 link
->io
.NumPorts1
= io
->win
[0].len
;
173 link
->io
.BasePort2
= io
->win
[1].base
;
174 link
->io
.NumPorts2
= io
->win
[1].len
;
176 if (pcmcia_request_io(link
, &link
->io
) != 0)
178 /* If we've got this far, we're done */
182 if (cfg
->flags
& CISTPL_CFTABLE_DEFAULT
)
184 CS_CHECK(GetNextTuple
, pcmcia_get_next_tuple(link
, &tuple
));
187 CS_CHECK(RequestConfiguration
, pcmcia_request_configuration(link
, &link
->conf
));
190 * Register the card with the core.
192 j
=ixj_pcmcia_probe(link
->io
.BasePort1
,link
->io
.BasePort1
+ 0x10);
195 info
->node
.major
= PHONE_MAJOR
;
196 link
->dev_node
= &info
->node
;
197 ixj_get_serial(link
, j
);
198 link
->state
&= ~DEV_CONFIG_PENDING
;
201 cs_error(link
, last_fn
, last_ret
);
202 ixj_cs_release(link
);
206 static void ixj_cs_release(struct pcmcia_device
*link
)
208 ixj_info_t
*info
= link
->priv
;
209 DEBUG(0, "ixj_cs_release(0x%p)\n", link
);
211 pcmcia_disable_device(link
);
214 static struct pcmcia_device_id ixj_ids
[] = {
215 PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
218 MODULE_DEVICE_TABLE(pcmcia
, ixj_ids
);
220 static struct pcmcia_driver ixj_driver
= {
221 .owner
= THIS_MODULE
,
226 .remove
= ixj_detach
,
230 static int __init
ixj_pcmcia_init(void)
232 return pcmcia_register_driver(&ixj_driver
);
235 static void ixj_pcmcia_exit(void)
237 pcmcia_unregister_driver(&ixj_driver
);
240 module_init(ixj_pcmcia_init
);
241 module_exit(ixj_pcmcia_exit
);
243 MODULE_LICENSE("GPL");