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 dev_link_t
*ixj_attach(void);
38 static void ixj_detach(struct pcmcia_device
*p_dev
);
39 static void ixj_config(dev_link_t
* link
);
40 static void ixj_cs_release(dev_link_t
* link
);
41 static int ixj_event(event_t event
, int priority
, event_callback_args_t
* args
);
42 static dev_info_t dev_info
= "ixj_cs";
43 static dev_link_t
*dev_list
= NULL
;
45 static dev_link_t
*ixj_attach(void)
47 client_reg_t client_reg
;
50 DEBUG(0, "ixj_attach()\n");
51 /* Create new ixj device */
52 link
= kmalloc(sizeof(struct dev_link_t
), GFP_KERNEL
);
55 memset(link
, 0, sizeof(struct dev_link_t
));
56 link
->io
.Attributes1
= IO_DATA_PATH_WIDTH_8
;
57 link
->io
.Attributes2
= IO_DATA_PATH_WIDTH_8
;
58 link
->io
.IOAddrLines
= 3;
60 link
->conf
.IntType
= INT_MEMORY_AND_IO
;
61 link
->priv
= kmalloc(sizeof(struct ixj_info_t
), GFP_KERNEL
);
66 memset(link
->priv
, 0, sizeof(struct ixj_info_t
));
67 /* Register with Card Services */
68 link
->next
= dev_list
;
70 client_reg
.dev_info
= &dev_info
;
71 client_reg
.Version
= 0x0210;
72 client_reg
.event_callback_args
.client_data
= link
;
73 ret
= pcmcia_register_client(&link
->handle
, &client_reg
);
74 if (ret
!= CS_SUCCESS
) {
75 cs_error(link
->handle
, RegisterClient
, ret
);
76 ixj_detach(link
->handle
);
82 static void ixj_detach(struct pcmcia_device
*p_dev
)
84 dev_link_t
*link
= dev_to_instance(p_dev
);
87 DEBUG(0, "ixj_detach(0x%p)\n", link
);
88 for (linkp
= &dev_list
; *linkp
; linkp
= &(*linkp
)->next
)
93 link
->state
&= ~DEV_RELEASE_PENDING
;
94 if (link
->state
& DEV_CONFIG
)
97 /* Unlink device structure, free bits */
103 #define CS_CHECK(fn, ret) \
104 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
106 static void ixj_get_serial(dev_link_t
* link
, IXJ
* j
)
108 client_handle_t handle
;
112 int last_ret
, last_fn
, i
, place
;
113 handle
= link
->handle
;
114 DEBUG(0, "ixj_get_serial(0x%p)\n", link
);
115 tuple
.TupleData
= (cisdata_t
*) buf
;
116 tuple
.TupleOffset
= 0;
117 tuple
.TupleDataMax
= 80;
118 tuple
.Attributes
= 0;
119 tuple
.DesiredTuple
= CISTPL_VERS_1
;
120 CS_CHECK(GetFirstTuple
, pcmcia_get_first_tuple(handle
, &tuple
));
121 CS_CHECK(GetTupleData
, pcmcia_get_tuple_data(handle
, &tuple
));
123 printk("PCMCIA Version %d.%d\n", str
[0], str
[1]);
126 str
= str
+ strlen(str
) + 1;
128 str
= str
+ strlen(str
) + 1;
130 for (i
= strlen(str
) - 1; i
>= 0; i
--) {
142 j
->serial
+= (str
[i
] - 48) * place
;
150 j
->serial
+= (str
[i
] - 55) * place
;
158 j
->serial
+= (str
[i
] - 87) * place
;
161 place
= place
* 0x10;
163 str
= str
+ strlen(str
) + 1;
164 printk(" version %s\n", str
);
169 static void ixj_config(dev_link_t
* link
)
172 client_handle_t handle
;
178 cistpl_cftable_entry_t
*cfg
= &parse
.cftable_entry
;
179 cistpl_cftable_entry_t dflt
=
183 int last_ret
, last_fn
;
184 handle
= link
->handle
;
186 DEBUG(0, "ixj_config(0x%p)\n", link
);
187 tuple
.TupleData
= (cisdata_t
*) buf
;
188 tuple
.TupleOffset
= 0;
189 tuple
.TupleDataMax
= 255;
190 tuple
.Attributes
= 0;
191 tuple
.DesiredTuple
= CISTPL_CONFIG
;
192 CS_CHECK(GetFirstTuple
, pcmcia_get_first_tuple(handle
, &tuple
));
193 CS_CHECK(GetTupleData
, pcmcia_get_tuple_data(handle
, &tuple
));
194 CS_CHECK(ParseTuple
, pcmcia_parse_tuple(handle
, &tuple
, &parse
));
195 link
->conf
.ConfigBase
= parse
.config
.base
;
196 link
->conf
.Present
= parse
.config
.rmask
[0];
197 link
->state
|= DEV_CONFIG
;
198 CS_CHECK(GetConfigurationInfo
, pcmcia_get_configuration_info(handle
, &conf
));
199 tuple
.DesiredTuple
= CISTPL_CFTABLE_ENTRY
;
200 tuple
.Attributes
= 0;
201 CS_CHECK(GetFirstTuple
, pcmcia_get_first_tuple(handle
, &tuple
));
203 if (pcmcia_get_tuple_data(handle
, &tuple
) != 0 ||
204 pcmcia_parse_tuple(handle
, &tuple
, &parse
) != 0)
206 if ((cfg
->io
.nwin
> 0) || (dflt
.io
.nwin
> 0)) {
207 cistpl_io_t
*io
= (cfg
->io
.nwin
) ? &cfg
->io
: &dflt
.io
;
208 link
->conf
.ConfigIndex
= cfg
->index
;
209 link
->io
.BasePort1
= io
->win
[0].base
;
210 link
->io
.NumPorts1
= io
->win
[0].len
;
212 link
->io
.BasePort2
= io
->win
[1].base
;
213 link
->io
.NumPorts2
= io
->win
[1].len
;
215 if (pcmcia_request_io(link
->handle
, &link
->io
) != 0)
217 /* If we've got this far, we're done */
221 if (cfg
->flags
& CISTPL_CFTABLE_DEFAULT
)
223 CS_CHECK(GetNextTuple
, pcmcia_get_next_tuple(handle
, &tuple
));
226 CS_CHECK(RequestConfiguration
, pcmcia_request_configuration(handle
, &link
->conf
));
229 * Register the card with the core.
231 j
=ixj_pcmcia_probe(link
->io
.BasePort1
,link
->io
.BasePort1
+ 0x10);
234 info
->node
.major
= PHONE_MAJOR
;
235 link
->dev
= &info
->node
;
236 ixj_get_serial(link
, j
);
237 link
->state
&= ~DEV_CONFIG_PENDING
;
240 cs_error(link
->handle
, last_fn
, last_ret
);
241 ixj_cs_release(link
);
244 static void ixj_cs_release(dev_link_t
*link
)
246 ixj_info_t
*info
= link
->priv
;
247 DEBUG(0, "ixj_cs_release(0x%p)\n", link
);
250 pcmcia_release_configuration(link
->handle
);
251 pcmcia_release_io(link
->handle
, &link
->io
);
252 link
->state
&= ~DEV_CONFIG
;
255 static int ixj_suspend(struct pcmcia_device
*dev
)
257 dev_link_t
*link
= dev_to_instance(dev
);
259 link
->state
|= DEV_SUSPEND
;
260 if (link
->state
& DEV_CONFIG
)
261 pcmcia_release_configuration(link
->handle
);
266 static int ixj_resume(struct pcmcia_device
*dev
)
268 dev_link_t
*link
= dev_to_instance(dev
);
270 link
->state
&= ~DEV_SUSPEND
;
272 pcmcia_request_configuration(link
->handle
, &link
->conf
);
277 static int ixj_event(event_t event
, int priority
, event_callback_args_t
* args
)
279 dev_link_t
*link
= args
->client_data
;
280 DEBUG(1, "ixj_event(0x%06x)\n", event
);
282 case CS_EVENT_CARD_INSERTION
:
283 link
->state
|= DEV_PRESENT
| DEV_CONFIG_PENDING
;
290 static struct pcmcia_device_id ixj_ids
[] = {
291 PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
294 MODULE_DEVICE_TABLE(pcmcia
, ixj_ids
);
296 static struct pcmcia_driver ixj_driver
= {
297 .owner
= THIS_MODULE
,
301 .attach
= ixj_attach
,
303 .remove
= ixj_detach
,
305 .suspend
= ixj_suspend
,
306 .resume
= ixj_resume
,
309 static int __init
ixj_pcmcia_init(void)
311 return pcmcia_register_driver(&ixj_driver
);
314 static void ixj_pcmcia_exit(void)
316 pcmcia_unregister_driver(&ixj_driver
);
317 BUG_ON(dev_list
!= NULL
);
320 module_init(ixj_pcmcia_init
);
321 module_exit(ixj_pcmcia_exit
);
323 MODULE_LICENSE("GPL");