blob: 416433b4a34822ebdc8a517b09ec01c7bf2790b0 [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
23#include <linux/config.h>
24#include <linux/module.h>
25
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/slab.h>
29#include <linux/types.h>
30#include <linux/sched.h>
31#include <linux/delay.h>
32#include <linux/errno.h>
33#include <linux/ptrace.h>
34#include <linux/ioport.h>
35#include <linux/spinlock.h>
36#include <linux/moduleparam.h>
37
38#include <linux/skbuff.h>
39#include <linux/string.h>
40#include <linux/serial.h>
41#include <linux/serial_reg.h>
42#include <linux/bitops.h>
43#include <asm/system.h>
44#include <asm/io.h>
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <pcmcia/cs_types.h>
47#include <pcmcia/cs.h>
48#include <pcmcia/cistpl.h>
49#include <pcmcia/ciscode.h>
50#include <pcmcia/ds.h>
51#include <pcmcia/cisreg.h>
52
53#include <net/bluetooth/bluetooth.h>
54#include <net/bluetooth/hci_core.h>
55
56
57
58/* ======================== Module parameters ======================== */
59
60
61MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
62MODULE_DESCRIPTION("Bluetooth driver for Nokia Connectivity Card DTL-1");
63MODULE_LICENSE("GPL");
64
65
66
67/* ======================== Local structures ======================== */
68
69
70typedef struct dtl1_info_t {
Dominik Brodowskifd238232006-03-05 10:45:09 +010071 struct pcmcia_device *p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 dev_node_t node;
73
74 struct hci_dev *hdev;
75
76 spinlock_t lock; /* For serializing operations */
77
78 unsigned long flowmask; /* HCI flow mask */
79 int ri_latch;
80
81 struct sk_buff_head txq;
82 unsigned long tx_state;
83
84 unsigned long rx_state;
85 unsigned long rx_count;
86 struct sk_buff *rx_skb;
87} dtl1_info_t;
88
89
Dominik Brodowskifba395e2006-03-31 17:21:06 +020090static void dtl1_config(struct pcmcia_device *link);
91static void dtl1_release(struct pcmcia_device *link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010093static void dtl1_detach(struct pcmcia_device *p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96/* Transmit states */
97#define XMIT_SENDING 1
98#define XMIT_WAKEUP 2
99#define XMIT_WAITING 8
100
101/* Receiver States */
102#define RECV_WAIT_NSH 0
103#define RECV_WAIT_DATA 1
104
105
106typedef struct {
107 u8 type;
108 u8 zero;
109 u16 len;
110} __attribute__ ((packed)) nsh_t; /* Nokia Specific Header */
111
112#define NSHL 4 /* Nokia Specific Header Length */
113
114
115
116/* ======================== Interrupt handling ======================== */
117
118
119static int dtl1_write(unsigned int iobase, int fifo_size, __u8 *buf, int len)
120{
121 int actual = 0;
122
123 /* Tx FIFO should be empty */
124 if (!(inb(iobase + UART_LSR) & UART_LSR_THRE))
125 return 0;
126
127 /* Fill FIFO with current frame */
128 while ((fifo_size-- > 0) && (actual < len)) {
129 /* Transmit next byte */
130 outb(buf[actual], iobase + UART_TX);
131 actual++;
132 }
133
134 return actual;
135}
136
137
138static void dtl1_write_wakeup(dtl1_info_t *info)
139{
140 if (!info) {
141 BT_ERR("Unknown device");
142 return;
143 }
144
145 if (test_bit(XMIT_WAITING, &(info->tx_state))) {
146 set_bit(XMIT_WAKEUP, &(info->tx_state));
147 return;
148 }
149
150 if (test_and_set_bit(XMIT_SENDING, &(info->tx_state))) {
151 set_bit(XMIT_WAKEUP, &(info->tx_state));
152 return;
153 }
154
155 do {
Dominik Brodowskifd238232006-03-05 10:45:09 +0100156 register unsigned int iobase = info->p_dev->io.BasePort1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 register struct sk_buff *skb;
158 register int len;
159
160 clear_bit(XMIT_WAKEUP, &(info->tx_state));
161
Dominik Brodowskifd238232006-03-05 10:45:09 +0100162 if (!(info->p_dev->state & DEV_PRESENT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 return;
164
165 if (!(skb = skb_dequeue(&(info->txq))))
166 break;
167
168 /* Send frame */
169 len = dtl1_write(iobase, 32, skb->data, skb->len);
170
171 if (len == skb->len) {
172 set_bit(XMIT_WAITING, &(info->tx_state));
173 kfree_skb(skb);
174 } else {
175 skb_pull(skb, len);
176 skb_queue_head(&(info->txq), skb);
177 }
178
179 info->hdev->stat.byte_tx += len;
180
181 } while (test_bit(XMIT_WAKEUP, &(info->tx_state)));
182
183 clear_bit(XMIT_SENDING, &(info->tx_state));
184}
185
186
187static void dtl1_control(dtl1_info_t *info, struct sk_buff *skb)
188{
189 u8 flowmask = *(u8 *)skb->data;
190 int i;
191
192 printk(KERN_INFO "Bluetooth: Nokia control data =");
193 for (i = 0; i < skb->len; i++) {
194 printk(" %02x", skb->data[i]);
195 }
196 printk("\n");
197
198 /* transition to active state */
199 if (((info->flowmask & 0x07) == 0) && ((flowmask & 0x07) != 0)) {
200 clear_bit(XMIT_WAITING, &(info->tx_state));
201 dtl1_write_wakeup(info);
202 }
203
204 info->flowmask = flowmask;
205
206 kfree_skb(skb);
207}
208
209
210static void dtl1_receive(dtl1_info_t *info)
211{
212 unsigned int iobase;
213 nsh_t *nsh;
214 int boguscount = 0;
215
216 if (!info) {
217 BT_ERR("Unknown device");
218 return;
219 }
220
Dominik Brodowskifd238232006-03-05 10:45:09 +0100221 iobase = info->p_dev->io.BasePort1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 do {
224 info->hdev->stat.byte_rx++;
225
226 /* Allocate packet */
227 if (info->rx_skb == NULL)
228 if (!(info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
229 BT_ERR("Can't allocate mem for new packet");
230 info->rx_state = RECV_WAIT_NSH;
231 info->rx_count = NSHL;
232 return;
233 }
234
235 *skb_put(info->rx_skb, 1) = inb(iobase + UART_RX);
236 nsh = (nsh_t *)info->rx_skb->data;
237
238 info->rx_count--;
239
240 if (info->rx_count == 0) {
241
242 switch (info->rx_state) {
243 case RECV_WAIT_NSH:
244 info->rx_state = RECV_WAIT_DATA;
245 info->rx_count = nsh->len + (nsh->len & 0x0001);
246 break;
247 case RECV_WAIT_DATA:
Marcel Holtmann0d48d932005-08-09 20:30:28 -0700248 bt_cb(info->rx_skb)->pkt_type = nsh->type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250 /* remove PAD byte if it exists */
251 if (nsh->len & 0x0001) {
252 info->rx_skb->tail--;
253 info->rx_skb->len--;
254 }
255
256 /* remove NSH */
257 skb_pull(info->rx_skb, NSHL);
258
Marcel Holtmann0d48d932005-08-09 20:30:28 -0700259 switch (bt_cb(info->rx_skb)->pkt_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 case 0x80:
261 /* control data for the Nokia Card */
262 dtl1_control(info, info->rx_skb);
263 break;
264 case 0x82:
265 case 0x83:
266 case 0x84:
267 /* send frame to the HCI layer */
268 info->rx_skb->dev = (void *) info->hdev;
Marcel Holtmann0d48d932005-08-09 20:30:28 -0700269 bt_cb(info->rx_skb)->pkt_type &= 0x0f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 hci_recv_frame(info->rx_skb);
271 break;
272 default:
273 /* unknown packet */
Marcel Holtmann0d48d932005-08-09 20:30:28 -0700274 BT_ERR("Unknown HCI packet with type 0x%02x received", bt_cb(info->rx_skb)->pkt_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 kfree_skb(info->rx_skb);
276 break;
277 }
278
279 info->rx_state = RECV_WAIT_NSH;
280 info->rx_count = NSHL;
281 info->rx_skb = NULL;
282 break;
283 }
284
285 }
286
287 /* Make sure we don't stay here too long */
288 if (boguscount++ > 32)
289 break;
290
291 } while (inb(iobase + UART_LSR) & UART_LSR_DR);
292}
293
294
295static irqreturn_t dtl1_interrupt(int irq, void *dev_inst, struct pt_regs *regs)
296{
297 dtl1_info_t *info = dev_inst;
298 unsigned int iobase;
299 unsigned char msr;
300 int boguscount = 0;
301 int iir, lsr;
302
303 if (!info || !info->hdev) {
304 BT_ERR("Call of irq %d for unknown device", irq);
305 return IRQ_NONE;
306 }
307
Dominik Brodowskifd238232006-03-05 10:45:09 +0100308 iobase = info->p_dev->io.BasePort1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310 spin_lock(&(info->lock));
311
312 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
313 while (iir) {
314
315 /* Clear interrupt */
316 lsr = inb(iobase + UART_LSR);
317
318 switch (iir) {
319 case UART_IIR_RLSI:
320 BT_ERR("RLSI");
321 break;
322 case UART_IIR_RDI:
323 /* Receive interrupt */
324 dtl1_receive(info);
325 break;
326 case UART_IIR_THRI:
327 if (lsr & UART_LSR_THRE) {
328 /* Transmitter ready for data */
329 dtl1_write_wakeup(info);
330 }
331 break;
332 default:
333 BT_ERR("Unhandled IIR=%#x", iir);
334 break;
335 }
336
337 /* Make sure we don't stay here too long */
338 if (boguscount++ > 100)
339 break;
340
341 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
342
343 }
344
345 msr = inb(iobase + UART_MSR);
346
347 if (info->ri_latch ^ (msr & UART_MSR_RI)) {
348 info->ri_latch = msr & UART_MSR_RI;
349 clear_bit(XMIT_WAITING, &(info->tx_state));
350 dtl1_write_wakeup(info);
351 }
352
353 spin_unlock(&(info->lock));
354
355 return IRQ_HANDLED;
356}
357
358
359
360/* ======================== HCI interface ======================== */
361
362
363static int dtl1_hci_open(struct hci_dev *hdev)
364{
365 set_bit(HCI_RUNNING, &(hdev->flags));
366
367 return 0;
368}
369
370
371static int dtl1_hci_flush(struct hci_dev *hdev)
372{
373 dtl1_info_t *info = (dtl1_info_t *)(hdev->driver_data);
374
375 /* Drop TX queue */
376 skb_queue_purge(&(info->txq));
377
378 return 0;
379}
380
381
382static int dtl1_hci_close(struct hci_dev *hdev)
383{
384 if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
385 return 0;
386
387 dtl1_hci_flush(hdev);
388
389 return 0;
390}
391
392
393static int dtl1_hci_send_frame(struct sk_buff *skb)
394{
395 dtl1_info_t *info;
396 struct hci_dev *hdev = (struct hci_dev *)(skb->dev);
397 struct sk_buff *s;
398 nsh_t nsh;
399
400 if (!hdev) {
401 BT_ERR("Frame for unknown HCI device (hdev=NULL)");
402 return -ENODEV;
403 }
404
405 info = (dtl1_info_t *)(hdev->driver_data);
406
Marcel Holtmann0d48d932005-08-09 20:30:28 -0700407 switch (bt_cb(skb)->pkt_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 case HCI_COMMAND_PKT:
409 hdev->stat.cmd_tx++;
410 nsh.type = 0x81;
411 break;
412 case HCI_ACLDATA_PKT:
413 hdev->stat.acl_tx++;
414 nsh.type = 0x82;
415 break;
416 case HCI_SCODATA_PKT:
417 hdev->stat.sco_tx++;
418 nsh.type = 0x83;
419 break;
420 };
421
422 nsh.zero = 0;
423 nsh.len = skb->len;
424
425 s = bt_skb_alloc(NSHL + skb->len + 1, GFP_ATOMIC);
426 skb_reserve(s, NSHL);
427 memcpy(skb_put(s, skb->len), skb->data, skb->len);
428 if (skb->len & 0x0001)
429 *skb_put(s, 1) = 0; /* PAD */
430
431 /* Prepend skb with Nokia frame header and queue */
432 memcpy(skb_push(s, NSHL), &nsh, NSHL);
433 skb_queue_tail(&(info->txq), s);
434
435 dtl1_write_wakeup(info);
436
437 kfree_skb(skb);
438
439 return 0;
440}
441
442
443static void dtl1_hci_destruct(struct hci_dev *hdev)
444{
445}
446
447
448static int dtl1_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
449{
450 return -ENOIOCTLCMD;
451}
452
453
454
455/* ======================== Card services HCI interaction ======================== */
456
457
458static int dtl1_open(dtl1_info_t *info)
459{
460 unsigned long flags;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100461 unsigned int iobase = info->p_dev->io.BasePort1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 struct hci_dev *hdev;
463
464 spin_lock_init(&(info->lock));
465
466 skb_queue_head_init(&(info->txq));
467
468 info->rx_state = RECV_WAIT_NSH;
469 info->rx_count = NSHL;
470 info->rx_skb = NULL;
471
472 set_bit(XMIT_WAITING, &(info->tx_state));
473
474 /* Initialize HCI device */
475 hdev = hci_alloc_dev();
476 if (!hdev) {
477 BT_ERR("Can't allocate HCI device");
478 return -ENOMEM;
479 }
480
481 info->hdev = hdev;
482
483 hdev->type = HCI_PCCARD;
484 hdev->driver_data = info;
485
486 hdev->open = dtl1_hci_open;
487 hdev->close = dtl1_hci_close;
488 hdev->flush = dtl1_hci_flush;
489 hdev->send = dtl1_hci_send_frame;
490 hdev->destruct = dtl1_hci_destruct;
491 hdev->ioctl = dtl1_hci_ioctl;
492
493 hdev->owner = THIS_MODULE;
494
495 spin_lock_irqsave(&(info->lock), flags);
496
497 /* Reset UART */
498 outb(0, iobase + UART_MCR);
499
500 /* Turn off interrupts */
501 outb(0, iobase + UART_IER);
502
503 /* Initialize UART */
504 outb(UART_LCR_WLEN8, iobase + UART_LCR); /* Reset DLAB */
505 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), iobase + UART_MCR);
506
Dominik Brodowskifd238232006-03-05 10:45:09 +0100507 info->ri_latch = inb(info->p_dev->io.BasePort1 + UART_MSR) & UART_MSR_RI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
509 /* Turn on interrupts */
510 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
511
512 spin_unlock_irqrestore(&(info->lock), flags);
513
514 /* Timeout before it is safe to send the first HCI packet */
515 msleep(2000);
516
517 /* Register HCI device */
518 if (hci_register_dev(hdev) < 0) {
519 BT_ERR("Can't register HCI device");
520 info->hdev = NULL;
521 hci_free_dev(hdev);
522 return -ENODEV;
523 }
524
525 return 0;
526}
527
528
529static int dtl1_close(dtl1_info_t *info)
530{
531 unsigned long flags;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100532 unsigned int iobase = info->p_dev->io.BasePort1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 struct hci_dev *hdev = info->hdev;
534
535 if (!hdev)
536 return -ENODEV;
537
538 dtl1_hci_close(hdev);
539
540 spin_lock_irqsave(&(info->lock), flags);
541
542 /* Reset UART */
543 outb(0, iobase + UART_MCR);
544
545 /* Turn off interrupts */
546 outb(0, iobase + UART_IER);
547
548 spin_unlock_irqrestore(&(info->lock), flags);
549
550 if (hci_unregister_dev(hdev) < 0)
551 BT_ERR("Can't unregister HCI device %s", hdev->name);
552
553 hci_free_dev(hdev);
554
555 return 0;
556}
557
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200558static int dtl1_attach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559{
560 dtl1_info_t *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
562 /* Create new info device */
Deepak Saxena089b1db2005-11-07 01:01:26 -0800563 info = kzalloc(sizeof(*info), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 if (!info)
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100565 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200567 info->p_dev = link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 link->priv = info;
569
570 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
571 link->io.NumPorts1 = 8;
572 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
573 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
574
575 link->irq.Handler = dtl1_interrupt;
576 link->irq.Instance = info;
577
578 link->conf.Attributes = CONF_ENABLE_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 link->conf.IntType = INT_MEMORY_AND_IO;
580
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100581 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
582 dtl1_config(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100584 return 0;
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
592 if (link->state & DEV_CONFIG)
593 dtl1_release(link);
594
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 kfree(info);
596}
597
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200598static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
600 int i;
601
602 i = pcmcia_get_tuple_data(handle, tuple);
603 if (i != CS_SUCCESS)
604 return i;
605
606 return pcmcia_parse_tuple(handle, tuple, parse);
607}
608
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200609static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
611 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
612 return CS_NO_MORE_ITEMS;
613 return get_tuple(handle, tuple, parse);
614}
615
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200616static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617{
618 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
619 return CS_NO_MORE_ITEMS;
620 return get_tuple(handle, tuple, parse);
621}
622
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200623static void dtl1_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 dtl1_info_t *info = link->priv;
626 tuple_t tuple;
627 u_short buf[256];
628 cisparse_t parse;
629 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 int i, last_ret, last_fn;
631
632 tuple.TupleData = (cisdata_t *)buf;
633 tuple.TupleOffset = 0;
634 tuple.TupleDataMax = 255;
635 tuple.Attributes = 0;
636
637 /* Get configuration register information */
638 tuple.DesiredTuple = CISTPL_CONFIG;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200639 last_ret = first_tuple(link, &tuple, &parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 if (last_ret != CS_SUCCESS) {
641 last_fn = ParseTuple;
642 goto cs_failed;
643 }
644 link->conf.ConfigBase = parse.config.base;
645 link->conf.Present = parse.config.rmask[0];
646
647 /* Configure card */
648 link->state |= DEV_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
650 tuple.TupleData = (cisdata_t *)buf;
651 tuple.TupleOffset = 0;
652 tuple.TupleDataMax = 255;
653 tuple.Attributes = 0;
654 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
655
656 /* Look for a generic full-sized window */
657 link->io.NumPorts1 = 8;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200658 i = first_tuple(link, &tuple, &parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 while (i != CS_NO_MORE_ITEMS) {
660 if ((i == CS_SUCCESS) && (cf->io.nwin == 1) && (cf->io.win[0].len > 8)) {
661 link->conf.ConfigIndex = cf->index;
662 link->io.BasePort1 = cf->io.win[0].base;
663 link->io.NumPorts1 = cf->io.win[0].len; /*yo */
664 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200665 i = pcmcia_request_io(link, &link->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 if (i == CS_SUCCESS)
667 break;
668 }
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200669 i = next_tuple(link, &tuple, &parse);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 }
671
672 if (i != CS_SUCCESS) {
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200673 cs_error(link, RequestIO, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 goto failed;
675 }
676
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200677 i = pcmcia_request_irq(link, &link->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 if (i != CS_SUCCESS) {
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200679 cs_error(link, RequestIRQ, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 link->irq.AssignedIRQ = 0;
681 }
682
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200683 i = pcmcia_request_configuration(link, &link->conf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 if (i != CS_SUCCESS) {
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200685 cs_error(link, RequestConfiguration, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 goto failed;
687 }
688
689 if (dtl1_open(info) != 0)
690 goto failed;
691
692 strcpy(info->node.dev_name, info->hdev->name);
Dominik Brodowskifd238232006-03-05 10:45:09 +0100693 link->dev_node = &info->node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 link->state &= ~DEV_CONFIG_PENDING;
695
696 return;
697
698cs_failed:
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200699 cs_error(link, last_fn, last_ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
701failed:
702 dtl1_release(link);
703}
704
705
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200706static void dtl1_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
708 dtl1_info_t *info = link->priv;
709
710 if (link->state & DEV_PRESENT)
711 dtl1_close(info);
712
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200713 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714}
715
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Dominik Brodowski88eca2e2005-06-27 16:28:39 -0700717static struct pcmcia_device_id dtl1_ids[] = {
718 PCMCIA_DEVICE_PROD_ID12("Nokia Mobile Phones", "DTL-1", 0xe1bfdd64, 0xe168480d),
719 PCMCIA_DEVICE_PROD_ID12("Socket", "CF", 0xb38bcc2e, 0x44ebf863),
Richard Purdie725a6ab2006-01-05 09:56:03 +0000720 PCMCIA_DEVICE_PROD_ID12("Socket", "CF+ Personal Network Card", 0xb38bcc2e, 0xe732bae3),
Dominik Brodowski88eca2e2005-06-27 16:28:39 -0700721 PCMCIA_DEVICE_NULL
722};
723MODULE_DEVICE_TABLE(pcmcia, dtl1_ids);
724
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725static struct pcmcia_driver dtl1_driver = {
726 .owner = THIS_MODULE,
727 .drv = {
728 .name = "dtl1_cs",
729 },
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100730 .probe = dtl1_attach,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100731 .remove = dtl1_detach,
Dominik Brodowski88eca2e2005-06-27 16:28:39 -0700732 .id_table = dtl1_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733};
734
735static int __init init_dtl1_cs(void)
736{
737 return pcmcia_register_driver(&dtl1_driver);
738}
739
740
741static void __exit exit_dtl1_cs(void)
742{
743 pcmcia_unregister_driver(&dtl1_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744}
745
746module_init(init_dtl1_cs);
747module_exit(exit_dtl1_cs);