blob: 77b99eecbc49cd9d0a81472f19f3932d0a6bc122 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 *
3 * A driver for Nokia Connectivity Card DTL-1 devices
4 *
5 * Copyright (C) 2001-2002 Marcel Holtmann <marcel@holtmann.org>
6 *
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation;
11 *
12 * Software distributed under the License is distributed on an "AS
13 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * rights and limitations under the License.
16 *
17 * The initial developer of the original code is David A. Hinds
18 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
19 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
20 *
21 */
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/module.h>
24
25#include <linux/kernel.h>
26#include <linux/init.h>
27#include <linux/slab.h>
28#include <linux/types.h>
29#include <linux/sched.h>
30#include <linux/delay.h>
31#include <linux/errno.h>
32#include <linux/ptrace.h>
33#include <linux/ioport.h>
34#include <linux/spinlock.h>
35#include <linux/moduleparam.h>
36
37#include <linux/skbuff.h>
38#include <linux/string.h>
39#include <linux/serial.h>
40#include <linux/serial_reg.h>
41#include <linux/bitops.h>
42#include <asm/system.h>
43#include <asm/io.h>
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <pcmcia/cs_types.h>
46#include <pcmcia/cs.h>
47#include <pcmcia/cistpl.h>
48#include <pcmcia/ciscode.h>
49#include <pcmcia/ds.h>
50#include <pcmcia/cisreg.h>
51
52#include <net/bluetooth/bluetooth.h>
53#include <net/bluetooth/hci_core.h>
54
55
56
57/* ======================== Module parameters ======================== */
58
59
60MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
61MODULE_DESCRIPTION("Bluetooth driver for Nokia Connectivity Card DTL-1");
62MODULE_LICENSE("GPL");
63
64
65
66/* ======================== Local structures ======================== */
67
68
69typedef struct dtl1_info_t {
Dominik Brodowskifd238232006-03-05 10:45:09 +010070 struct pcmcia_device *p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 dev_node_t node;
72
73 struct hci_dev *hdev;
74
75 spinlock_t lock; /* For serializing operations */
76
77 unsigned long flowmask; /* HCI flow mask */
78 int ri_latch;
79
80 struct sk_buff_head txq;
81 unsigned long tx_state;
82
83 unsigned long rx_state;
84 unsigned long rx_count;
85 struct sk_buff *rx_skb;
86} dtl1_info_t;
87
88
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020089static int dtl1_config(struct pcmcia_device *link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020090static void dtl1_release(struct pcmcia_device *link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010092static void dtl1_detach(struct pcmcia_device *p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95/* Transmit states */
96#define XMIT_SENDING 1
97#define XMIT_WAKEUP 2
98#define XMIT_WAITING 8
99
100/* Receiver States */
101#define RECV_WAIT_NSH 0
102#define RECV_WAIT_DATA 1
103
104
105typedef struct {
106 u8 type;
107 u8 zero;
108 u16 len;
109} __attribute__ ((packed)) nsh_t; /* Nokia Specific Header */
110
111#define NSHL 4 /* Nokia Specific Header Length */
112
113
114
115/* ======================== Interrupt handling ======================== */
116
117
118static int dtl1_write(unsigned int iobase, int fifo_size, __u8 *buf, int len)
119{
120 int actual = 0;
121
122 /* Tx FIFO should be empty */
123 if (!(inb(iobase + UART_LSR) & UART_LSR_THRE))
124 return 0;
125
126 /* Fill FIFO with current frame */
127 while ((fifo_size-- > 0) && (actual < len)) {
128 /* Transmit next byte */
129 outb(buf[actual], iobase + UART_TX);
130 actual++;
131 }
132
133 return actual;
134}
135
136
137static void dtl1_write_wakeup(dtl1_info_t *info)
138{
139 if (!info) {
140 BT_ERR("Unknown device");
141 return;
142 }
143
144 if (test_bit(XMIT_WAITING, &(info->tx_state))) {
145 set_bit(XMIT_WAKEUP, &(info->tx_state));
146 return;
147 }
148
149 if (test_and_set_bit(XMIT_SENDING, &(info->tx_state))) {
150 set_bit(XMIT_WAKEUP, &(info->tx_state));
151 return;
152 }
153
154 do {
Dominik Brodowskifd238232006-03-05 10:45:09 +0100155 register unsigned int iobase = info->p_dev->io.BasePort1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 register struct sk_buff *skb;
157 register int len;
158
159 clear_bit(XMIT_WAKEUP, &(info->tx_state));
160
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100161 if (!pcmcia_dev_present(info->p_dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 return;
163
164 if (!(skb = skb_dequeue(&(info->txq))))
165 break;
166
167 /* Send frame */
168 len = dtl1_write(iobase, 32, skb->data, skb->len);
169
170 if (len == skb->len) {
171 set_bit(XMIT_WAITING, &(info->tx_state));
172 kfree_skb(skb);
173 } else {
174 skb_pull(skb, len);
175 skb_queue_head(&(info->txq), skb);
176 }
177
178 info->hdev->stat.byte_tx += len;
179
180 } while (test_bit(XMIT_WAKEUP, &(info->tx_state)));
181
182 clear_bit(XMIT_SENDING, &(info->tx_state));
183}
184
185
186static void dtl1_control(dtl1_info_t *info, struct sk_buff *skb)
187{
188 u8 flowmask = *(u8 *)skb->data;
189 int i;
190
191 printk(KERN_INFO "Bluetooth: Nokia control data =");
192 for (i = 0; i < skb->len; i++) {
193 printk(" %02x", skb->data[i]);
194 }
195 printk("\n");
196
197 /* transition to active state */
198 if (((info->flowmask & 0x07) == 0) && ((flowmask & 0x07) != 0)) {
199 clear_bit(XMIT_WAITING, &(info->tx_state));
200 dtl1_write_wakeup(info);
201 }
202
203 info->flowmask = flowmask;
204
205 kfree_skb(skb);
206}
207
208
209static void dtl1_receive(dtl1_info_t *info)
210{
211 unsigned int iobase;
212 nsh_t *nsh;
213 int boguscount = 0;
214
215 if (!info) {
216 BT_ERR("Unknown device");
217 return;
218 }
219
Dominik Brodowskifd238232006-03-05 10:45:09 +0100220 iobase = info->p_dev->io.BasePort1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 do {
223 info->hdev->stat.byte_rx++;
224
225 /* Allocate packet */
226 if (info->rx_skb == NULL)
227 if (!(info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
228 BT_ERR("Can't allocate mem for new packet");
229 info->rx_state = RECV_WAIT_NSH;
230 info->rx_count = NSHL;
231 return;
232 }
233
234 *skb_put(info->rx_skb, 1) = inb(iobase + UART_RX);
235 nsh = (nsh_t *)info->rx_skb->data;
236
237 info->rx_count--;
238
239 if (info->rx_count == 0) {
240
241 switch (info->rx_state) {
242 case RECV_WAIT_NSH:
243 info->rx_state = RECV_WAIT_DATA;
244 info->rx_count = nsh->len + (nsh->len & 0x0001);
245 break;
246 case RECV_WAIT_DATA:
Marcel Holtmann0d48d932005-08-09 20:30:28 -0700247 bt_cb(info->rx_skb)->pkt_type = nsh->type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 /* remove PAD byte if it exists */
250 if (nsh->len & 0x0001) {
251 info->rx_skb->tail--;
252 info->rx_skb->len--;
253 }
254
255 /* remove NSH */
256 skb_pull(info->rx_skb, NSHL);
257
Marcel Holtmann0d48d932005-08-09 20:30:28 -0700258 switch (bt_cb(info->rx_skb)->pkt_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 case 0x80:
260 /* control data for the Nokia Card */
261 dtl1_control(info, info->rx_skb);
262 break;
263 case 0x82:
264 case 0x83:
265 case 0x84:
266 /* send frame to the HCI layer */
267 info->rx_skb->dev = (void *) info->hdev;
Marcel Holtmann0d48d932005-08-09 20:30:28 -0700268 bt_cb(info->rx_skb)->pkt_type &= 0x0f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 hci_recv_frame(info->rx_skb);
270 break;
271 default:
272 /* unknown packet */
Marcel Holtmann0d48d932005-08-09 20:30:28 -0700273 BT_ERR("Unknown HCI packet with type 0x%02x received", bt_cb(info->rx_skb)->pkt_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 kfree_skb(info->rx_skb);
275 break;
276 }
277
278 info->rx_state = RECV_WAIT_NSH;
279 info->rx_count = NSHL;
280 info->rx_skb = NULL;
281 break;
282 }
283
284 }
285
286 /* Make sure we don't stay here too long */
287 if (boguscount++ > 32)
288 break;
289
290 } while (inb(iobase + UART_LSR) & UART_LSR_DR);
291}
292
293
David Howells7d12e782006-10-05 14:55:46 +0100294static irqreturn_t dtl1_interrupt(int irq, void *dev_inst)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
296 dtl1_info_t *info = dev_inst;
297 unsigned int iobase;
298 unsigned char msr;
299 int boguscount = 0;
300 int iir, lsr;
301
302 if (!info || !info->hdev) {
303 BT_ERR("Call of irq %d for unknown device", irq);
304 return IRQ_NONE;
305 }
306
Dominik Brodowskifd238232006-03-05 10:45:09 +0100307 iobase = info->p_dev->io.BasePort1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309 spin_lock(&(info->lock));
310
311 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
312 while (iir) {
313
314 /* Clear interrupt */
315 lsr = inb(iobase + UART_LSR);
316
317 switch (iir) {
318 case UART_IIR_RLSI:
319 BT_ERR("RLSI");
320 break;
321 case UART_IIR_RDI:
322 /* Receive interrupt */
323 dtl1_receive(info);
324 break;
325 case UART_IIR_THRI:
326 if (lsr & UART_LSR_THRE) {
327 /* Transmitter ready for data */
328 dtl1_write_wakeup(info);
329 }
330 break;
331 default:
332 BT_ERR("Unhandled IIR=%#x", iir);
333 break;
334 }
335
336 /* Make sure we don't stay here too long */
337 if (boguscount++ > 100)
338 break;
339
340 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
341
342 }
343
344 msr = inb(iobase + UART_MSR);
345
346 if (info->ri_latch ^ (msr & UART_MSR_RI)) {
347 info->ri_latch = msr & UART_MSR_RI;
348 clear_bit(XMIT_WAITING, &(info->tx_state));
349 dtl1_write_wakeup(info);
350 }
351
352 spin_unlock(&(info->lock));
353
354 return IRQ_HANDLED;
355}
356
357
358
359/* ======================== HCI interface ======================== */
360
361
362static int dtl1_hci_open(struct hci_dev *hdev)
363{
364 set_bit(HCI_RUNNING, &(hdev->flags));
365
366 return 0;
367}
368
369
370static int dtl1_hci_flush(struct hci_dev *hdev)
371{
372 dtl1_info_t *info = (dtl1_info_t *)(hdev->driver_data);
373
374 /* Drop TX queue */
375 skb_queue_purge(&(info->txq));
376
377 return 0;
378}
379
380
381static int dtl1_hci_close(struct hci_dev *hdev)
382{
383 if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
384 return 0;
385
386 dtl1_hci_flush(hdev);
387
388 return 0;
389}
390
391
392static int dtl1_hci_send_frame(struct sk_buff *skb)
393{
394 dtl1_info_t *info;
395 struct hci_dev *hdev = (struct hci_dev *)(skb->dev);
396 struct sk_buff *s;
397 nsh_t nsh;
398
399 if (!hdev) {
400 BT_ERR("Frame for unknown HCI device (hdev=NULL)");
401 return -ENODEV;
402 }
403
404 info = (dtl1_info_t *)(hdev->driver_data);
405
Marcel Holtmann0d48d932005-08-09 20:30:28 -0700406 switch (bt_cb(skb)->pkt_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 case HCI_COMMAND_PKT:
408 hdev->stat.cmd_tx++;
409 nsh.type = 0x81;
410 break;
411 case HCI_ACLDATA_PKT:
412 hdev->stat.acl_tx++;
413 nsh.type = 0x82;
414 break;
415 case HCI_SCODATA_PKT:
416 hdev->stat.sco_tx++;
417 nsh.type = 0x83;
418 break;
419 };
420
421 nsh.zero = 0;
422 nsh.len = skb->len;
423
424 s = bt_skb_alloc(NSHL + skb->len + 1, GFP_ATOMIC);
Jesper Juhl57136ca2006-06-26 00:24:33 -0700425 if (!s)
426 return -ENOMEM;
427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 skb_reserve(s, NSHL);
429 memcpy(skb_put(s, skb->len), skb->data, skb->len);
430 if (skb->len & 0x0001)
431 *skb_put(s, 1) = 0; /* PAD */
432
433 /* Prepend skb with Nokia frame header and queue */
434 memcpy(skb_push(s, NSHL), &nsh, NSHL);
435 skb_queue_tail(&(info->txq), s);
436
437 dtl1_write_wakeup(info);
438
439 kfree_skb(skb);
440
441 return 0;
442}
443
444
445static void dtl1_hci_destruct(struct hci_dev *hdev)
446{
447}
448
449
450static int dtl1_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
451{
452 return -ENOIOCTLCMD;
453}
454
455
456
457/* ======================== Card services HCI interaction ======================== */
458
459
460static int dtl1_open(dtl1_info_t *info)
461{
462 unsigned long flags;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100463 unsigned int iobase = info->p_dev->io.BasePort1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 struct hci_dev *hdev;
465
466 spin_lock_init(&(info->lock));
467
468 skb_queue_head_init(&(info->txq));
469
470 info->rx_state = RECV_WAIT_NSH;
471 info->rx_count = NSHL;
472 info->rx_skb = NULL;
473
474 set_bit(XMIT_WAITING, &(info->tx_state));
475
476 /* Initialize HCI device */
477 hdev = hci_alloc_dev();
478 if (!hdev) {
479 BT_ERR("Can't allocate HCI device");
480 return -ENOMEM;
481 }
482
483 info->hdev = hdev;
484
485 hdev->type = HCI_PCCARD;
486 hdev->driver_data = info;
Marcel Holtmann27d35282006-07-03 10:02:37 +0200487 SET_HCIDEV_DEV(hdev, &info->p_dev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489 hdev->open = dtl1_hci_open;
490 hdev->close = dtl1_hci_close;
491 hdev->flush = dtl1_hci_flush;
492 hdev->send = dtl1_hci_send_frame;
493 hdev->destruct = dtl1_hci_destruct;
494 hdev->ioctl = dtl1_hci_ioctl;
495
496 hdev->owner = THIS_MODULE;
497
498 spin_lock_irqsave(&(info->lock), flags);
499
500 /* Reset UART */
501 outb(0, iobase + UART_MCR);
502
503 /* Turn off interrupts */
504 outb(0, iobase + UART_IER);
505
506 /* Initialize UART */
507 outb(UART_LCR_WLEN8, iobase + UART_LCR); /* Reset DLAB */
508 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), iobase + UART_MCR);
509
Dominik Brodowskifd238232006-03-05 10:45:09 +0100510 info->ri_latch = inb(info->p_dev->io.BasePort1 + UART_MSR) & UART_MSR_RI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 /* Turn on interrupts */
513 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
514
515 spin_unlock_irqrestore(&(info->lock), flags);
516
517 /* Timeout before it is safe to send the first HCI packet */
518 msleep(2000);
519
520 /* Register HCI device */
521 if (hci_register_dev(hdev) < 0) {
522 BT_ERR("Can't register HCI device");
523 info->hdev = NULL;
524 hci_free_dev(hdev);
525 return -ENODEV;
526 }
527
528 return 0;
529}
530
531
532static int dtl1_close(dtl1_info_t *info)
533{
534 unsigned long flags;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100535 unsigned int iobase = info->p_dev->io.BasePort1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 struct hci_dev *hdev = info->hdev;
537
538 if (!hdev)
539 return -ENODEV;
540
541 dtl1_hci_close(hdev);
542
543 spin_lock_irqsave(&(info->lock), flags);
544
545 /* Reset UART */
546 outb(0, iobase + UART_MCR);
547
548 /* Turn off interrupts */
549 outb(0, iobase + UART_IER);
550
551 spin_unlock_irqrestore(&(info->lock), flags);
552
553 if (hci_unregister_dev(hdev) < 0)
554 BT_ERR("Can't unregister HCI device %s", hdev->name);
555
556 hci_free_dev(hdev);
557
558 return 0;
559}
560
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200561static int dtl1_probe(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562{
563 dtl1_info_t *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 /* Create new info device */
Deepak Saxena089b1db2005-11-07 01:01:26 -0800566 info = kzalloc(sizeof(*info), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 if (!info)
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100568 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200570 info->p_dev = link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 link->priv = info;
572
573 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
574 link->io.NumPorts1 = 8;
575 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
576 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
577
578 link->irq.Handler = dtl1_interrupt;
579 link->irq.Instance = info;
580
581 link->conf.Attributes = CONF_ENABLE_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 link->conf.IntType = INT_MEMORY_AND_IO;
583
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200584 return dtl1_config(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585}
586
587
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200588static void dtl1_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589{
590 dtl1_info_t *info = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100592 dtl1_release(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 kfree(info);
595}
596
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200597static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
599 int i;
600
601 i = pcmcia_get_tuple_data(handle, tuple);
602 if (i != CS_SUCCESS)
603 return i;
604
605 return pcmcia_parse_tuple(handle, tuple, parse);
606}
607
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200608static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609{
610 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
611 return CS_NO_MORE_ITEMS;
612 return get_tuple(handle, tuple, parse);
613}
614
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200615static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616{
617 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
618 return CS_NO_MORE_ITEMS;
619 return get_tuple(handle, tuple, parse);
620}
621
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200622static int dtl1_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 dtl1_info_t *info = link->priv;
625 tuple_t tuple;
626 u_short buf[256];
627 cisparse_t parse;
628 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
Dominik Brodowskiaf2b3b52006-10-25 21:49:27 -0400629 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 tuple.TupleData = (cisdata_t *)buf;
632 tuple.TupleOffset = 0;
633 tuple.TupleDataMax = 255;
634 tuple.Attributes = 0;
635 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
636
637 /* Look for a generic full-sized window */
638 link->io.NumPorts1 = 8;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200639 i = first_tuple(link, &tuple, &parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 while (i != CS_NO_MORE_ITEMS) {
641 if ((i == CS_SUCCESS) && (cf->io.nwin == 1) && (cf->io.win[0].len > 8)) {
642 link->conf.ConfigIndex = cf->index;
643 link->io.BasePort1 = cf->io.win[0].base;
644 link->io.NumPorts1 = cf->io.win[0].len; /*yo */
645 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200646 i = pcmcia_request_io(link, &link->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 if (i == CS_SUCCESS)
648 break;
649 }
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200650 i = next_tuple(link, &tuple, &parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 }
652
653 if (i != CS_SUCCESS) {
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200654 cs_error(link, RequestIO, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 goto failed;
656 }
657
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200658 i = pcmcia_request_irq(link, &link->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 if (i != CS_SUCCESS) {
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200660 cs_error(link, RequestIRQ, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 link->irq.AssignedIRQ = 0;
662 }
663
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200664 i = pcmcia_request_configuration(link, &link->conf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 if (i != CS_SUCCESS) {
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200666 cs_error(link, RequestConfiguration, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 goto failed;
668 }
669
670 if (dtl1_open(info) != 0)
671 goto failed;
672
673 strcpy(info->node.dev_name, info->hdev->name);
Dominik Brodowskifd238232006-03-05 10:45:09 +0100674 link->dev_node = &info->node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200676 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678failed:
679 dtl1_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200680 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
683
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200684static void dtl1_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685{
686 dtl1_info_t *info = link->priv;
687
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100688 dtl1_close(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200690 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691}
692
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
Dominik Brodowski88eca2e2005-06-27 16:28:39 -0700694static struct pcmcia_device_id dtl1_ids[] = {
695 PCMCIA_DEVICE_PROD_ID12("Nokia Mobile Phones", "DTL-1", 0xe1bfdd64, 0xe168480d),
Marcel Holtmann8602b4f2006-10-20 08:55:34 +0200696 PCMCIA_DEVICE_PROD_ID12("Nokia Mobile Phones", "DTL-4", 0xe1bfdd64, 0x9102bc82),
Dominik Brodowski88eca2e2005-06-27 16:28:39 -0700697 PCMCIA_DEVICE_PROD_ID12("Socket", "CF", 0xb38bcc2e, 0x44ebf863),
Richard Purdie725a6ab2006-01-05 09:56:03 +0000698 PCMCIA_DEVICE_PROD_ID12("Socket", "CF+ Personal Network Card", 0xb38bcc2e, 0xe732bae3),
Dominik Brodowski88eca2e2005-06-27 16:28:39 -0700699 PCMCIA_DEVICE_NULL
700};
701MODULE_DEVICE_TABLE(pcmcia, dtl1_ids);
702
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703static struct pcmcia_driver dtl1_driver = {
704 .owner = THIS_MODULE,
705 .drv = {
706 .name = "dtl1_cs",
707 },
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200708 .probe = dtl1_probe,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100709 .remove = dtl1_detach,
Dominik Brodowski88eca2e2005-06-27 16:28:39 -0700710 .id_table = dtl1_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711};
712
713static int __init init_dtl1_cs(void)
714{
715 return pcmcia_register_driver(&dtl1_driver);
716}
717
718
719static void __exit exit_dtl1_cs(void)
720{
721 pcmcia_unregister_driver(&dtl1_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722}
723
724module_init(init_dtl1_cs);
725module_exit(exit_dtl1_cs);