3 #include <linux/module.h>
5 #include <linux/init.h>
6 #include <linux/kernel.h> /* printk() */
7 #include <linux/fs.h> /* everything... */
8 #include <linux/errno.h> /* error codes */
9 #include <linux/slab.h>
11 #include <pcmcia/cs_types.h>
12 #include <pcmcia/cs.h>
13 #include <pcmcia/cistpl.h>
14 #include <pcmcia/ds.h>
19 * PCMCIA service support for Quicknet cards
23 static int pc_debug
= PCMCIA_DEBUG
;
24 module_param(pc_debug
, int, 0644);
25 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
27 #define DEBUG(n, args...)
30 typedef struct ixj_info_t
{
36 static void ixj_detach(struct pcmcia_device
*p_dev
);
37 static int ixj_config(struct pcmcia_device
* link
);
38 static void ixj_cs_release(struct pcmcia_device
* link
);
40 static int ixj_probe(struct pcmcia_device
*p_dev
)
42 DEBUG(0, "ixj_attach()\n");
43 /* Create new ixj device */
44 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
= kzalloc(sizeof(struct ixj_info_t
), GFP_KERNEL
);
53 return ixj_config(p_dev
);
56 static void ixj_detach(struct pcmcia_device
*link
)
58 DEBUG(0, "ixj_detach(0x%p)\n", link
);
65 #define CS_CHECK(fn, ret) \
66 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
68 static void ixj_get_serial(struct pcmcia_device
* link
, IXJ
* j
)
72 DEBUG(0, "ixj_get_serial(0x%p)\n", link
);
74 str
= link
->prod_id
[0];
78 str
= link
->prod_id
[1];
82 str
= link
->prod_id
[2];
86 for (i
= strlen(str
) - 1; i
>= 0; i
--) {
98 j
->serial
+= (str
[i
] - 48) * place
;
106 j
->serial
+= (str
[i
] - 55) * place
;
114 j
->serial
+= (str
[i
] - 87) * place
;
117 place
= place
* 0x10;
119 str
= link
->prod_id
[3];
122 printk(" version %s\n", str
);
127 static int ixj_config(struct pcmcia_device
* link
)
134 cistpl_cftable_entry_t
*cfg
= &parse
.cftable_entry
;
135 cistpl_cftable_entry_t dflt
=
139 int last_ret
, last_fn
;
141 DEBUG(0, "ixj_config(0x%p)\n", link
);
142 tuple
.TupleData
= (cisdata_t
*) buf
;
143 tuple
.TupleOffset
= 0;
144 tuple
.TupleDataMax
= 255;
145 tuple
.DesiredTuple
= CISTPL_CFTABLE_ENTRY
;
146 tuple
.Attributes
= 0;
147 CS_CHECK(GetFirstTuple
, pcmcia_get_first_tuple(link
, &tuple
));
149 if (pcmcia_get_tuple_data(link
, &tuple
) != 0 ||
150 pcmcia_parse_tuple(link
, &tuple
, &parse
) != 0)
152 if ((cfg
->io
.nwin
> 0) || (dflt
.io
.nwin
> 0)) {
153 cistpl_io_t
*io
= (cfg
->io
.nwin
) ? &cfg
->io
: &dflt
.io
;
154 link
->conf
.ConfigIndex
= cfg
->index
;
155 link
->io
.BasePort1
= io
->win
[0].base
;
156 link
->io
.NumPorts1
= io
->win
[0].len
;
158 link
->io
.BasePort2
= io
->win
[1].base
;
159 link
->io
.NumPorts2
= io
->win
[1].len
;
161 if (pcmcia_request_io(link
, &link
->io
) != 0)
163 /* If we've got this far, we're done */
167 if (cfg
->flags
& CISTPL_CFTABLE_DEFAULT
)
169 CS_CHECK(GetNextTuple
, pcmcia_get_next_tuple(link
, &tuple
));
172 CS_CHECK(RequestConfiguration
, pcmcia_request_configuration(link
, &link
->conf
));
175 * Register the card with the core.
177 j
=ixj_pcmcia_probe(link
->io
.BasePort1
,link
->io
.BasePort1
+ 0x10);
180 info
->node
.major
= PHONE_MAJOR
;
181 link
->dev_node
= &info
->node
;
182 ixj_get_serial(link
, j
);
185 cs_error(link
, last_fn
, last_ret
);
186 ixj_cs_release(link
);
190 static void ixj_cs_release(struct pcmcia_device
*link
)
192 ixj_info_t
*info
= link
->priv
;
193 DEBUG(0, "ixj_cs_release(0x%p)\n", link
);
195 pcmcia_disable_device(link
);
198 static struct pcmcia_device_id ixj_ids
[] = {
199 PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
202 MODULE_DEVICE_TABLE(pcmcia
, ixj_ids
);
204 static struct pcmcia_driver ixj_driver
= {
205 .owner
= THIS_MODULE
,
210 .remove
= ixj_detach
,
214 static int __init
ixj_pcmcia_init(void)
216 return pcmcia_register_driver(&ixj_driver
);
219 static void ixj_pcmcia_exit(void)
221 pcmcia_unregister_driver(&ixj_driver
);
224 module_init(ixj_pcmcia_init
);
225 module_exit(ixj_pcmcia_exit
);
227 MODULE_LICENSE("GPL");