1 /*********************************************************************
5 * Description: Driver for the NSC PC'108 and PC'338 IrDA chipsets
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Sat Nov 7 21:43:15 1998
9 * Modified at: Wed Mar 1 11:29:34 2000
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
12 * Copyright (c) 1998-2000 Dag Brattli <dagb@cs.uit.no>
13 * Copyright (c) 1998 Lichen Wang, <lwang@actisys.com>
14 * Copyright (c) 1998 Actisys Corp., www.actisys.com
15 * Copyright (c) 2000-2004 Jean Tourrilhes <jt@hpl.hp.com>
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License as
20 * published by the Free Software Foundation; either version 2 of
21 * the License, or (at your option) any later version.
23 * Neither Dag Brattli nor University of Tromsø admit liability nor
24 * provide warranty for any of this software. This material is
25 * provided "AS-IS" and at no charge.
27 * Notice that all functions that needs to access the chip in _any_
28 * way, must save BSR register on entry, and restore it on exit.
29 * It is _very_ important to follow this policy!
33 * bank = inb(iobase+BSR);
35 * do_your_stuff_here();
37 * outb(bank, iobase+BSR);
39 * If you find bugs in this file, its very likely that the same bug
40 * will also be in w83977af_ir.c since the implementations are quite
43 ********************************************************************/
45 #include <linux/module.h>
47 #include <linux/kernel.h>
48 #include <linux/types.h>
49 #include <linux/skbuff.h>
50 #include <linux/netdevice.h>
51 #include <linux/ioport.h>
52 #include <linux/delay.h>
53 #include <linux/slab.h>
54 #include <linux/init.h>
55 #include <linux/rtnetlink.h>
56 #include <linux/dma-mapping.h>
57 #include <linux/pnp.h>
58 #include <linux/platform_device.h>
62 #include <asm/byteorder.h>
64 #include <net/irda/wrapper.h>
65 #include <net/irda/irda.h>
66 #include <net/irda/irda_device.h>
70 #define CHIP_IO_EXTENT 8
71 #define BROKEN_DONGLE_ID
73 static char *driver_name
= "nsc-ircc";
75 /* Power Management */
76 #define NSC_IRCC_DRIVER_NAME "nsc-ircc"
77 static int nsc_ircc_suspend(struct platform_device
*dev
, pm_message_t state
);
78 static int nsc_ircc_resume(struct platform_device
*dev
);
80 static struct platform_driver nsc_ircc_driver
= {
81 .suspend
= nsc_ircc_suspend
,
82 .resume
= nsc_ircc_resume
,
84 .name
= NSC_IRCC_DRIVER_NAME
,
88 /* Module parameters */
89 static int qos_mtt_bits
= 0x07; /* 1 ms or more */
92 /* Use BIOS settions by default, but user may supply module parameters */
93 static unsigned int io
[] = { ~0, ~0, ~0, ~0, ~0 };
94 static unsigned int irq
[] = { 0, 0, 0, 0, 0 };
95 static unsigned int dma
[] = { 0, 0, 0, 0, 0 };
97 static int nsc_ircc_probe_108(nsc_chip_t
*chip
, chipio_t
*info
);
98 static int nsc_ircc_probe_338(nsc_chip_t
*chip
, chipio_t
*info
);
99 static int nsc_ircc_probe_39x(nsc_chip_t
*chip
, chipio_t
*info
);
100 static int nsc_ircc_init_108(nsc_chip_t
*chip
, chipio_t
*info
);
101 static int nsc_ircc_init_338(nsc_chip_t
*chip
, chipio_t
*info
);
102 static int nsc_ircc_init_39x(nsc_chip_t
*chip
, chipio_t
*info
);
104 static int nsc_ircc_pnp_probe(struct pnp_dev
*dev
, const struct pnp_device_id
*id
);
107 /* These are the known NSC chips */
108 static nsc_chip_t chips
[] = {
109 /* Name, {cfg registers}, chip id index reg, chip id expected value, revision mask */
110 { "PC87108", { 0x150, 0x398, 0xea }, 0x05, 0x10, 0xf0,
111 nsc_ircc_probe_108
, nsc_ircc_init_108
},
112 { "PC87338", { 0x398, 0x15c, 0x2e }, 0x08, 0xb0, 0xf8,
113 nsc_ircc_probe_338
, nsc_ircc_init_338
},
114 /* Contributed by Steffen Pingel - IBM X40 */
115 { "PC8738x", { 0x164e, 0x4e, 0x2e }, 0x20, 0xf4, 0xff,
116 nsc_ircc_probe_39x
, nsc_ircc_init_39x
},
117 /* Contributed by Jan Frey - IBM A30/A31 */
118 { "PC8739x", { 0x2e, 0x4e, 0x0 }, 0x20, 0xea, 0xff,
119 nsc_ircc_probe_39x
, nsc_ircc_init_39x
},
120 /* IBM ThinkPads using PC8738x (T60/X60/Z60) */
121 { "IBM-PC8738x", { 0x2e, 0x4e, 0x0 }, 0x20, 0xf4, 0xff,
122 nsc_ircc_probe_39x
, nsc_ircc_init_39x
},
123 /* IBM ThinkPads using PC8394T (T43/R52/?) */
124 { "IBM-PC8394T", { 0x2e, 0x4e, 0x0 }, 0x20, 0xf9, 0xff,
125 nsc_ircc_probe_39x
, nsc_ircc_init_39x
},
129 static struct nsc_ircc_cb
*dev_self
[] = { NULL
, NULL
, NULL
, NULL
, NULL
};
131 static char *dongle_types
[] = {
132 "Differential serial interface",
133 "Differential serial interface",
138 "Single-ended serial interface",
140 "HP HSDL-2300, HP HSDL-3600/HSDL-3610",
141 "IBM31T1100 or Temic TFDS6000/TFDS6500",
144 "HP HSDL-1100/HSDL-2100",
145 "HP HSDL-1100/HSDL-2100",
146 "Supports SIR Mode only",
147 "No dongle connected",
151 static chipio_t pnp_info
;
152 static const struct pnp_device_id nsc_ircc_pnp_table
[] = {
153 { .id
= "NSC6001", .driver_data
= 0 },
154 { .id
= "IBM0071", .driver_data
= 0 },
158 MODULE_DEVICE_TABLE(pnp
, nsc_ircc_pnp_table
);
160 static struct pnp_driver nsc_ircc_pnp_driver
= {
163 .id_table
= nsc_ircc_pnp_table
,
164 .probe
= nsc_ircc_pnp_probe
,
168 /* Some prototypes */
169 static int nsc_ircc_open(chipio_t
*info
);
170 static int nsc_ircc_close(struct nsc_ircc_cb
*self
);
171 static int nsc_ircc_setup(chipio_t
*info
);
172 static void nsc_ircc_pio_receive(struct nsc_ircc_cb
*self
);
173 static int nsc_ircc_dma_receive(struct nsc_ircc_cb
*self
);
174 static int nsc_ircc_dma_receive_complete(struct nsc_ircc_cb
*self
, int iobase
);
175 static int nsc_ircc_hard_xmit_sir(struct sk_buff
*skb
, struct net_device
*dev
);
176 static int nsc_ircc_hard_xmit_fir(struct sk_buff
*skb
, struct net_device
*dev
);
177 static int nsc_ircc_pio_write(int iobase
, __u8
*buf
, int len
, int fifo_size
);
178 static void nsc_ircc_dma_xmit(struct nsc_ircc_cb
*self
, int iobase
);
179 static __u8
nsc_ircc_change_speed(struct nsc_ircc_cb
*self
, __u32 baud
);
180 static int nsc_ircc_is_receiving(struct nsc_ircc_cb
*self
);
181 static int nsc_ircc_read_dongle_id (int iobase
);
182 static void nsc_ircc_init_dongle_interface (int iobase
, int dongle_id
);
184 static int nsc_ircc_net_open(struct net_device
*dev
);
185 static int nsc_ircc_net_close(struct net_device
*dev
);
186 static int nsc_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
187 static struct net_device_stats
*nsc_ircc_net_get_stats(struct net_device
*dev
);
190 static int pnp_registered
;
191 static int pnp_succeeded
;
194 * Function nsc_ircc_init ()
196 * Initialize chip. Just try to find out how many chips we are dealing with
199 static int __init
nsc_ircc_init(void)
209 ret
= platform_driver_register(&nsc_ircc_driver
);
211 IRDA_ERROR("%s, Can't register driver!\n", driver_name
);
215 /* Register with PnP subsystem to detect disable ports */
216 ret
= pnp_register_driver(&nsc_ircc_pnp_driver
);
223 /* Probe for all the NSC chipsets we know about */
224 for (chip
= chips
; chip
->name
; chip
++) {
225 IRDA_DEBUG(2, "%s(), Probing for %s ...\n", __FUNCTION__
,
228 /* Try all config registers for this chip */
229 for (cfg
= 0; cfg
< ARRAY_SIZE(chip
->cfg
); cfg
++) {
230 cfg_base
= chip
->cfg
[cfg
];
234 /* Read index register */
237 IRDA_DEBUG(2, "%s() no chip at 0x%03x\n", __FUNCTION__
, cfg_base
);
241 /* Read chip identification register */
242 outb(chip
->cid_index
, cfg_base
);
243 id
= inb(cfg_base
+1);
244 if ((id
& chip
->cid_mask
) == chip
->cid_value
) {
245 IRDA_DEBUG(2, "%s() Found %s chip, revision=%d\n",
246 __FUNCTION__
, chip
->name
, id
& ~chip
->cid_mask
);
249 * If we found a correct PnP setting,
253 memset(&info
, 0, sizeof(chipio_t
));
254 info
.cfg_base
= cfg_base
;
255 info
.fir_base
= pnp_info
.fir_base
;
256 info
.dma
= pnp_info
.dma
;
257 info
.irq
= pnp_info
.irq
;
259 if (info
.fir_base
< 0x2000) {
260 IRDA_MESSAGE("%s, chip->init\n", driver_name
);
261 chip
->init(chip
, &info
);
263 chip
->probe(chip
, &info
);
265 if (nsc_ircc_open(&info
) >= 0)
270 * Opening based on PnP values failed.
271 * Let's fallback to user values, or probe
275 IRDA_DEBUG(2, "%s, PnP init failed\n", driver_name
);
276 memset(&info
, 0, sizeof(chipio_t
));
277 info
.cfg_base
= cfg_base
;
278 info
.fir_base
= io
[i
];
283 * If the user supplies the base address, then
284 * we init the chip, if not we probe the values
287 if (io
[i
] < 0x2000) {
288 chip
->init(chip
, &info
);
290 chip
->probe(chip
, &info
);
292 if (nsc_ircc_open(&info
) >= 0)
297 IRDA_DEBUG(2, "%s(), Wrong chip id=0x%02x\n", __FUNCTION__
, id
);
303 platform_driver_unregister(&nsc_ircc_driver
);
304 pnp_unregister_driver(&nsc_ircc_pnp_driver
);
312 * Function nsc_ircc_cleanup ()
314 * Close all configured chips
317 static void __exit
nsc_ircc_cleanup(void)
321 for (i
= 0; i
< ARRAY_SIZE(dev_self
); i
++) {
323 nsc_ircc_close(dev_self
[i
]);
326 platform_driver_unregister(&nsc_ircc_driver
);
329 pnp_unregister_driver(&nsc_ircc_pnp_driver
);
335 * Function nsc_ircc_open (iobase, irq)
337 * Open driver instance
340 static int __init
nsc_ircc_open(chipio_t
*info
)
342 struct net_device
*dev
;
343 struct nsc_ircc_cb
*self
;
347 IRDA_DEBUG(2, "%s()\n", __FUNCTION__
);
350 for (chip_index
= 0; chip_index
< ARRAY_SIZE(dev_self
); chip_index
++) {
351 if (!dev_self
[chip_index
])
355 if (chip_index
== ARRAY_SIZE(dev_self
)) {
356 IRDA_ERROR("%s(), maximum number of supported chips reached!\n", __FUNCTION__
);
360 IRDA_MESSAGE("%s, Found chip at base=0x%03x\n", driver_name
,
363 if ((nsc_ircc_setup(info
)) == -1)
366 IRDA_MESSAGE("%s, driver loaded (Dag Brattli)\n", driver_name
);
368 dev
= alloc_irdadev(sizeof(struct nsc_ircc_cb
));
370 IRDA_ERROR("%s(), can't allocate memory for "
371 "control block!\n", __FUNCTION__
);
377 spin_lock_init(&self
->lock
);
379 /* Need to store self somewhere */
380 dev_self
[chip_index
] = self
;
381 self
->index
= chip_index
;
384 self
->io
.cfg_base
= info
->cfg_base
;
385 self
->io
.fir_base
= info
->fir_base
;
386 self
->io
.irq
= info
->irq
;
387 self
->io
.fir_ext
= CHIP_IO_EXTENT
;
388 self
->io
.dma
= info
->dma
;
389 self
->io
.fifo_size
= 32;
391 /* Reserve the ioports that we need */
392 ret
= request_region(self
->io
.fir_base
, self
->io
.fir_ext
, driver_name
);
394 IRDA_WARNING("%s(), can't get iobase of 0x%03x\n",
395 __FUNCTION__
, self
->io
.fir_base
);
400 /* Initialize QoS for this device */
401 irda_init_max_qos_capabilies(&self
->qos
);
403 /* The only value we must override it the baudrate */
404 self
->qos
.baud_rate
.bits
= IR_9600
|IR_19200
|IR_38400
|IR_57600
|
405 IR_115200
|IR_576000
|IR_1152000
|(IR_4000000
<< 8);
407 self
->qos
.min_turn_time
.bits
= qos_mtt_bits
;
408 irda_qos_bits_to_value(&self
->qos
);
410 /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
411 self
->rx_buff
.truesize
= 14384;
412 self
->tx_buff
.truesize
= 14384;
414 /* Allocate memory if needed */
416 dma_alloc_coherent(NULL
, self
->rx_buff
.truesize
,
417 &self
->rx_buff_dma
, GFP_KERNEL
);
418 if (self
->rx_buff
.head
== NULL
) {
423 memset(self
->rx_buff
.head
, 0, self
->rx_buff
.truesize
);
426 dma_alloc_coherent(NULL
, self
->tx_buff
.truesize
,
427 &self
->tx_buff_dma
, GFP_KERNEL
);
428 if (self
->tx_buff
.head
== NULL
) {
432 memset(self
->tx_buff
.head
, 0, self
->tx_buff
.truesize
);
434 self
->rx_buff
.in_frame
= FALSE
;
435 self
->rx_buff
.state
= OUTSIDE_FRAME
;
436 self
->tx_buff
.data
= self
->tx_buff
.head
;
437 self
->rx_buff
.data
= self
->rx_buff
.head
;
439 /* Reset Tx queue info */
440 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
441 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
443 /* Override the network functions we need to use */
444 dev
->hard_start_xmit
= nsc_ircc_hard_xmit_sir
;
445 dev
->open
= nsc_ircc_net_open
;
446 dev
->stop
= nsc_ircc_net_close
;
447 dev
->do_ioctl
= nsc_ircc_net_ioctl
;
448 dev
->get_stats
= nsc_ircc_net_get_stats
;
450 err
= register_netdev(dev
);
452 IRDA_ERROR("%s(), register_netdev() failed!\n", __FUNCTION__
);
455 IRDA_MESSAGE("IrDA: Registered device %s\n", dev
->name
);
457 /* Check if user has supplied a valid dongle id or not */
458 if ((dongle_id
<= 0) ||
459 (dongle_id
>= ARRAY_SIZE(dongle_types
))) {
460 dongle_id
= nsc_ircc_read_dongle_id(self
->io
.fir_base
);
462 IRDA_MESSAGE("%s, Found dongle: %s\n", driver_name
,
463 dongle_types
[dongle_id
]);
465 IRDA_MESSAGE("%s, Using dongle: %s\n", driver_name
,
466 dongle_types
[dongle_id
]);
469 self
->io
.dongle_id
= dongle_id
;
470 nsc_ircc_init_dongle_interface(self
->io
.fir_base
, dongle_id
);
472 self
->pldev
= platform_device_register_simple(NSC_IRCC_DRIVER_NAME
,
473 self
->index
, NULL
, 0);
474 if (IS_ERR(self
->pldev
)) {
475 err
= PTR_ERR(self
->pldev
);
478 platform_set_drvdata(self
->pldev
, self
);
483 unregister_netdev(dev
);
485 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
486 self
->tx_buff
.head
, self
->tx_buff_dma
);
488 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
489 self
->rx_buff
.head
, self
->rx_buff_dma
);
491 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
494 dev_self
[chip_index
] = NULL
;
499 * Function nsc_ircc_close (self)
501 * Close driver instance
504 static int __exit
nsc_ircc_close(struct nsc_ircc_cb
*self
)
508 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
510 IRDA_ASSERT(self
!= NULL
, return -1;);
512 iobase
= self
->io
.fir_base
;
514 platform_device_unregister(self
->pldev
);
516 /* Remove netdevice */
517 unregister_netdev(self
->netdev
);
519 /* Release the PORT that this driver is using */
520 IRDA_DEBUG(4, "%s(), Releasing Region %03x\n",
521 __FUNCTION__
, self
->io
.fir_base
);
522 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
524 if (self
->tx_buff
.head
)
525 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
526 self
->tx_buff
.head
, self
->tx_buff_dma
);
528 if (self
->rx_buff
.head
)
529 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
530 self
->rx_buff
.head
, self
->rx_buff_dma
);
532 dev_self
[self
->index
] = NULL
;
533 free_netdev(self
->netdev
);
539 * Function nsc_ircc_init_108 (iobase, cfg_base, irq, dma)
541 * Initialize the NSC '108 chip
544 static int nsc_ircc_init_108(nsc_chip_t
*chip
, chipio_t
*info
)
546 int cfg_base
= info
->cfg_base
;
549 outb(2, cfg_base
); /* Mode Control Register (MCTL) */
550 outb(0x00, cfg_base
+1); /* Disable device */
552 /* Base Address and Interrupt Control Register (BAIC) */
553 outb(CFG_108_BAIC
, cfg_base
);
554 switch (info
->fir_base
) {
555 case 0x3e8: outb(0x14, cfg_base
+1); break;
556 case 0x2e8: outb(0x15, cfg_base
+1); break;
557 case 0x3f8: outb(0x16, cfg_base
+1); break;
558 case 0x2f8: outb(0x17, cfg_base
+1); break;
559 default: IRDA_ERROR("%s(), invalid base_address", __FUNCTION__
);
562 /* Control Signal Routing Register (CSRT) */
564 case 3: temp
= 0x01; break;
565 case 4: temp
= 0x02; break;
566 case 5: temp
= 0x03; break;
567 case 7: temp
= 0x04; break;
568 case 9: temp
= 0x05; break;
569 case 11: temp
= 0x06; break;
570 case 15: temp
= 0x07; break;
571 default: IRDA_ERROR("%s(), invalid irq", __FUNCTION__
);
573 outb(CFG_108_CSRT
, cfg_base
);
576 case 0: outb(0x08+temp
, cfg_base
+1); break;
577 case 1: outb(0x10+temp
, cfg_base
+1); break;
578 case 3: outb(0x18+temp
, cfg_base
+1); break;
579 default: IRDA_ERROR("%s(), invalid dma", __FUNCTION__
);
582 outb(CFG_108_MCTL
, cfg_base
); /* Mode Control Register (MCTL) */
583 outb(0x03, cfg_base
+1); /* Enable device */
589 * Function nsc_ircc_probe_108 (chip, info)
594 static int nsc_ircc_probe_108(nsc_chip_t
*chip
, chipio_t
*info
)
596 int cfg_base
= info
->cfg_base
;
599 /* Read address and interrupt control register (BAIC) */
600 outb(CFG_108_BAIC
, cfg_base
);
601 reg
= inb(cfg_base
+1);
603 switch (reg
& 0x03) {
605 info
->fir_base
= 0x3e8;
608 info
->fir_base
= 0x2e8;
611 info
->fir_base
= 0x3f8;
614 info
->fir_base
= 0x2f8;
617 info
->sir_base
= info
->fir_base
;
618 IRDA_DEBUG(2, "%s(), probing fir_base=0x%03x\n", __FUNCTION__
,
621 /* Read control signals routing register (CSRT) */
622 outb(CFG_108_CSRT
, cfg_base
);
623 reg
= inb(cfg_base
+1);
625 switch (reg
& 0x07) {
651 IRDA_DEBUG(2, "%s(), probing irq=%d\n", __FUNCTION__
, info
->irq
);
653 /* Currently we only read Rx DMA but it will also be used for Tx */
654 switch ((reg
>> 3) & 0x03) {
668 IRDA_DEBUG(2, "%s(), probing dma=%d\n", __FUNCTION__
, info
->dma
);
670 /* Read mode control register (MCTL) */
671 outb(CFG_108_MCTL
, cfg_base
);
672 reg
= inb(cfg_base
+1);
674 info
->enabled
= reg
& 0x01;
675 info
->suspended
= !((reg
>> 1) & 0x01);
681 * Function nsc_ircc_init_338 (chip, info)
683 * Initialize the NSC '338 chip. Remember that the 87338 needs two
684 * consecutive writes to the data registers while CPU interrupts are
685 * disabled. The 97338 does not require this, but shouldn't be any
686 * harm if we do it anyway.
688 static int nsc_ircc_init_338(nsc_chip_t
*chip
, chipio_t
*info
)
696 * Function nsc_ircc_probe_338 (chip, info)
701 static int nsc_ircc_probe_338(nsc_chip_t
*chip
, chipio_t
*info
)
703 int cfg_base
= info
->cfg_base
;
707 /* Read funtion enable register (FER) */
708 outb(CFG_338_FER
, cfg_base
);
709 reg
= inb(cfg_base
+1);
711 info
->enabled
= (reg
>> 2) & 0x01;
713 /* Check if we are in Legacy or PnP mode */
714 outb(CFG_338_PNP0
, cfg_base
);
715 reg
= inb(cfg_base
+1);
717 pnp
= (reg
>> 3) & 0x01;
719 IRDA_DEBUG(2, "(), Chip is in PnP mode\n");
720 outb(0x46, cfg_base
);
721 reg
= (inb(cfg_base
+1) & 0xfe) << 2;
723 outb(0x47, cfg_base
);
724 reg
|= ((inb(cfg_base
+1) & 0xfc) << 8);
726 info
->fir_base
= reg
;
728 /* Read function address register (FAR) */
729 outb(CFG_338_FAR
, cfg_base
);
730 reg
= inb(cfg_base
+1);
732 switch ((reg
>> 4) & 0x03) {
734 info
->fir_base
= 0x3f8;
737 info
->fir_base
= 0x2f8;
748 switch ((reg
>> 6) & 0x03) {
751 info
->fir_base
= 0x3e8;
753 info
->fir_base
= 0x2e8;
757 info
->fir_base
= 0x338;
759 info
->fir_base
= 0x238;
763 info
->fir_base
= 0x2e8;
765 info
->fir_base
= 0x2e0;
769 info
->fir_base
= 0x220;
771 info
->fir_base
= 0x228;
776 info
->sir_base
= info
->fir_base
;
778 /* Read PnP register 1 (PNP1) */
779 outb(CFG_338_PNP1
, cfg_base
);
780 reg
= inb(cfg_base
+1);
782 info
->irq
= reg
>> 4;
784 /* Read PnP register 3 (PNP3) */
785 outb(CFG_338_PNP3
, cfg_base
);
786 reg
= inb(cfg_base
+1);
788 info
->dma
= (reg
& 0x07) - 1;
790 /* Read power and test register (PTR) */
791 outb(CFG_338_PTR
, cfg_base
);
792 reg
= inb(cfg_base
+1);
794 info
->suspended
= reg
& 0x01;
801 * Function nsc_ircc_init_39x (chip, info)
803 * Now that we know it's a '39x (see probe below), we need to
804 * configure it so we can use it.
806 * The NSC '338 chip is a Super I/O chip with a "bank" architecture,
807 * the configuration of the different functionality (serial, parallel,
808 * floppy...) are each in a different bank (Logical Device Number).
809 * The base address, irq and dma configuration registers are common
810 * to all functionalities (index 0x30 to 0x7F).
811 * There is only one configuration register specific to the
812 * serial port, CFG_39X_SPC.
815 * Note : this code was written by Jan Frey <janfrey@web.de>
817 static int nsc_ircc_init_39x(nsc_chip_t
*chip
, chipio_t
*info
)
819 int cfg_base
= info
->cfg_base
;
822 /* User is sure about his config... accept it. */
823 IRDA_DEBUG(2, "%s(): nsc_ircc_init_39x (user settings): "
824 "io=0x%04x, irq=%d, dma=%d\n",
825 __FUNCTION__
, info
->fir_base
, info
->irq
, info
->dma
);
827 /* Access bank for SP2 */
828 outb(CFG_39X_LDN
, cfg_base
);
829 outb(0x02, cfg_base
+1);
833 /* We want to enable the device if not enabled */
834 outb(CFG_39X_ACT
, cfg_base
);
835 enabled
= inb(cfg_base
+1) & 0x01;
838 /* Enable the device */
839 outb(CFG_39X_SIOCF1
, cfg_base
);
840 outb(0x01, cfg_base
+1);
841 /* May want to update info->enabled. Jean II */
844 /* Enable UART bank switching (bit 7) ; Sets the chip to normal
845 * power mode (wake up from sleep mode) (bit 1) */
846 outb(CFG_39X_SPC
, cfg_base
);
847 outb(0x82, cfg_base
+1);
853 * Function nsc_ircc_probe_39x (chip, info)
855 * Test if we really have a '39x chip at the given address
857 * Note : this code was written by Jan Frey <janfrey@web.de>
859 static int nsc_ircc_probe_39x(nsc_chip_t
*chip
, chipio_t
*info
)
861 int cfg_base
= info
->cfg_base
;
862 int reg1
, reg2
, irq
, irqt
, dma1
, dma2
;
865 IRDA_DEBUG(2, "%s(), nsc_ircc_probe_39x, base=%d\n",
866 __FUNCTION__
, cfg_base
);
868 /* This function should be executed with irq off to avoid
869 * another driver messing with the Super I/O bank - Jean II */
871 /* Access bank for SP2 */
872 outb(CFG_39X_LDN
, cfg_base
);
873 outb(0x02, cfg_base
+1);
875 /* Read infos about SP2 ; store in info struct */
876 outb(CFG_39X_BASEH
, cfg_base
);
877 reg1
= inb(cfg_base
+1);
878 outb(CFG_39X_BASEL
, cfg_base
);
879 reg2
= inb(cfg_base
+1);
880 info
->fir_base
= (reg1
<< 8) | reg2
;
882 outb(CFG_39X_IRQNUM
, cfg_base
);
883 irq
= inb(cfg_base
+1);
884 outb(CFG_39X_IRQSEL
, cfg_base
);
885 irqt
= inb(cfg_base
+1);
888 outb(CFG_39X_DMA0
, cfg_base
);
889 dma1
= inb(cfg_base
+1);
890 outb(CFG_39X_DMA1
, cfg_base
);
891 dma2
= inb(cfg_base
+1);
894 outb(CFG_39X_ACT
, cfg_base
);
895 info
->enabled
= enabled
= inb(cfg_base
+1) & 0x01;
897 outb(CFG_39X_SPC
, cfg_base
);
898 susp
= 1 - ((inb(cfg_base
+1) & 0x02) >> 1);
900 IRDA_DEBUG(2, "%s(): io=0x%02x%02x, irq=%d (type %d), rxdma=%d, txdma=%d, enabled=%d (suspended=%d)\n", __FUNCTION__
, reg1
,reg2
,irq
,irqt
,dma1
,dma2
,enabled
,susp
);
904 /* We want to enable the device if not enabled */
905 outb(CFG_39X_ACT
, cfg_base
);
906 enabled
= inb(cfg_base
+1) & 0x01;
909 /* Enable the device */
910 outb(CFG_39X_SIOCF1
, cfg_base
);
911 outb(0x01, cfg_base
+1);
912 /* May want to update info->enabled. Jean II */
915 /* Enable UART bank switching (bit 7) ; Sets the chip to normal
916 * power mode (wake up from sleep mode) (bit 1) */
917 outb(CFG_39X_SPC
, cfg_base
);
918 outb(0x82, cfg_base
+1);
925 static int nsc_ircc_pnp_probe(struct pnp_dev
*dev
, const struct pnp_device_id
*id
)
927 memset(&pnp_info
, 0, sizeof(chipio_t
));
932 /* There don't seem to be any way to get the cfg_base.
933 * On my box, cfg_base is in the PnP descriptor of the
934 * motherboard. Oh well... Jean II */
936 if (pnp_port_valid(dev
, 0) &&
937 !(pnp_port_flags(dev
, 0) & IORESOURCE_DISABLED
))
938 pnp_info
.fir_base
= pnp_port_start(dev
, 0);
940 if (pnp_irq_valid(dev
, 0) &&
941 !(pnp_irq_flags(dev
, 0) & IORESOURCE_DISABLED
))
942 pnp_info
.irq
= pnp_irq(dev
, 0);
944 if (pnp_dma_valid(dev
, 0) &&
945 !(pnp_dma_flags(dev
, 0) & IORESOURCE_DISABLED
))
946 pnp_info
.dma
= pnp_dma(dev
, 0);
948 IRDA_DEBUG(0, "%s() : From PnP, found firbase 0x%03X ; irq %d ; dma %d.\n",
949 __FUNCTION__
, pnp_info
.fir_base
, pnp_info
.irq
, pnp_info
.dma
);
951 if((pnp_info
.fir_base
== 0) ||
952 (pnp_info
.irq
== -1) || (pnp_info
.dma
== -1)) {
953 /* Returning an error will disable the device. Yuck ! */
963 * Function nsc_ircc_setup (info)
965 * Returns non-negative on success.
968 static int nsc_ircc_setup(chipio_t
*info
)
971 int iobase
= info
->fir_base
;
973 /* Read the Module ID */
974 switch_bank(iobase
, BANK3
);
975 version
= inb(iobase
+MID
);
977 IRDA_DEBUG(2, "%s() Driver %s Found chip version %02x\n",
978 __FUNCTION__
, driver_name
, version
);
981 if (0x20 != (version
& 0xf0)) {
982 IRDA_ERROR("%s, Wrong chip version %02x\n",
983 driver_name
, version
);
987 /* Switch to advanced mode */
988 switch_bank(iobase
, BANK2
);
989 outb(ECR1_EXT_SL
, iobase
+ECR1
);
990 switch_bank(iobase
, BANK0
);
992 /* Set FIFO threshold to TX17, RX16, reset and enable FIFO's */
993 switch_bank(iobase
, BANK0
);
994 outb(FCR_RXTH
|FCR_TXTH
|FCR_TXSR
|FCR_RXSR
|FCR_FIFO_EN
, iobase
+FCR
);
996 outb(0x03, iobase
+LCR
); /* 8 bit word length */
997 outb(MCR_SIR
, iobase
+MCR
); /* Start at SIR-mode, also clears LSR*/
999 /* Set FIFO size to 32 */
1000 switch_bank(iobase
, BANK2
);
1001 outb(EXCR2_RFSIZ
|EXCR2_TFSIZ
, iobase
+EXCR2
);
1003 /* IRCR2: FEND_MD is not set */
1004 switch_bank(iobase
, BANK5
);
1005 outb(0x02, iobase
+4);
1007 /* Make sure that some defaults are OK */
1008 switch_bank(iobase
, BANK6
);
1009 outb(0x20, iobase
+0); /* Set 32 bits FIR CRC */
1010 outb(0x0a, iobase
+1); /* Set MIR pulse width */
1011 outb(0x0d, iobase
+2); /* Set SIR pulse width to 1.6us */
1012 outb(0x2a, iobase
+4); /* Set beginning frag, and preamble length */
1014 /* Enable receive interrupts */
1015 switch_bank(iobase
, BANK0
);
1016 outb(IER_RXHDL_IE
, iobase
+IER
);
1022 * Function nsc_ircc_read_dongle_id (void)
1024 * Try to read dongle indentification. This procedure needs to be executed
1025 * once after power-on/reset. It also needs to be used whenever you suspect
1026 * that the user may have plugged/unplugged the IrDA Dongle.
1028 static int nsc_ircc_read_dongle_id (int iobase
)
1033 bank
= inb(iobase
+BSR
);
1036 switch_bank(iobase
, BANK7
);
1038 /* IRCFG4: IRSL0_DS and IRSL21_DS are cleared */
1039 outb(0x00, iobase
+7);
1041 /* ID0, 1, and 2 are pulled up/down very slowly */
1044 /* IRCFG1: read the ID bits */
1045 dongle_id
= inb(iobase
+4) & 0x0f;
1047 #ifdef BROKEN_DONGLE_ID
1048 if (dongle_id
== 0x0a)
1051 /* Go back to bank 0 before returning */
1052 switch_bank(iobase
, BANK0
);
1054 outb(bank
, iobase
+BSR
);
1060 * Function nsc_ircc_init_dongle_interface (iobase, dongle_id)
1062 * This function initializes the dongle for the transceiver that is
1063 * used. This procedure needs to be executed once after
1064 * power-on/reset. It also needs to be used whenever you suspect that
1065 * the dongle is changed.
1067 static void nsc_ircc_init_dongle_interface (int iobase
, int dongle_id
)
1071 /* Save current bank */
1072 bank
= inb(iobase
+BSR
);
1075 switch_bank(iobase
, BANK7
);
1077 /* IRCFG4: set according to dongle_id */
1078 switch (dongle_id
) {
1079 case 0x00: /* same as */
1080 case 0x01: /* Differential serial interface */
1081 IRDA_DEBUG(0, "%s(), %s not defined by irda yet\n",
1082 __FUNCTION__
, dongle_types
[dongle_id
]);
1084 case 0x02: /* same as */
1085 case 0x03: /* Reserved */
1086 IRDA_DEBUG(0, "%s(), %s not defined by irda yet\n",
1087 __FUNCTION__
, dongle_types
[dongle_id
]);
1089 case 0x04: /* Sharp RY5HD01 */
1091 case 0x05: /* Reserved, but this is what the Thinkpad reports */
1092 IRDA_DEBUG(0, "%s(), %s not defined by irda yet\n",
1093 __FUNCTION__
, dongle_types
[dongle_id
]);
1095 case 0x06: /* Single-ended serial interface */
1096 IRDA_DEBUG(0, "%s(), %s not defined by irda yet\n",
1097 __FUNCTION__
, dongle_types
[dongle_id
]);
1099 case 0x07: /* Consumer-IR only */
1100 IRDA_DEBUG(0, "%s(), %s is not for IrDA mode\n",
1101 __FUNCTION__
, dongle_types
[dongle_id
]);
1103 case 0x08: /* HP HSDL-2300, HP HSDL-3600/HSDL-3610 */
1104 IRDA_DEBUG(0, "%s(), %s\n",
1105 __FUNCTION__
, dongle_types
[dongle_id
]);
1107 case 0x09: /* IBM31T1100 or Temic TFDS6000/TFDS6500 */
1108 outb(0x28, iobase
+7); /* Set irsl[0-2] as output */
1110 case 0x0A: /* same as */
1111 case 0x0B: /* Reserved */
1112 IRDA_DEBUG(0, "%s(), %s not defined by irda yet\n",
1113 __FUNCTION__
, dongle_types
[dongle_id
]);
1115 case 0x0C: /* same as */
1116 case 0x0D: /* HP HSDL-1100/HSDL-2100 */
1118 * Set irsl0 as input, irsl[1-2] as output, and separate
1119 * inputs are used for SIR and MIR/FIR
1121 outb(0x48, iobase
+7);
1123 case 0x0E: /* Supports SIR Mode only */
1124 outb(0x28, iobase
+7); /* Set irsl[0-2] as output */
1126 case 0x0F: /* No dongle connected */
1127 IRDA_DEBUG(0, "%s(), %s\n",
1128 __FUNCTION__
, dongle_types
[dongle_id
]);
1130 switch_bank(iobase
, BANK0
);
1131 outb(0x62, iobase
+MCR
);
1134 IRDA_DEBUG(0, "%s(), invalid dongle_id %#x",
1135 __FUNCTION__
, dongle_id
);
1138 /* IRCFG1: IRSL1 and 2 are set to IrDA mode */
1139 outb(0x00, iobase
+4);
1141 /* Restore bank register */
1142 outb(bank
, iobase
+BSR
);
1144 } /* set_up_dongle_interface */
1147 * Function nsc_ircc_change_dongle_speed (iobase, speed, dongle_id)
1149 * Change speed of the attach dongle
1152 static void nsc_ircc_change_dongle_speed(int iobase
, int speed
, int dongle_id
)
1156 /* Save current bank */
1157 bank
= inb(iobase
+BSR
);
1160 switch_bank(iobase
, BANK7
);
1162 /* IRCFG1: set according to dongle_id */
1163 switch (dongle_id
) {
1164 case 0x00: /* same as */
1165 case 0x01: /* Differential serial interface */
1166 IRDA_DEBUG(0, "%s(), %s not defined by irda yet\n",
1167 __FUNCTION__
, dongle_types
[dongle_id
]);
1169 case 0x02: /* same as */
1170 case 0x03: /* Reserved */
1171 IRDA_DEBUG(0, "%s(), %s not defined by irda yet\n",
1172 __FUNCTION__
, dongle_types
[dongle_id
]);
1174 case 0x04: /* Sharp RY5HD01 */
1176 case 0x05: /* Reserved */
1177 IRDA_DEBUG(0, "%s(), %s not defined by irda yet\n",
1178 __FUNCTION__
, dongle_types
[dongle_id
]);
1180 case 0x06: /* Single-ended serial interface */
1181 IRDA_DEBUG(0, "%s(), %s not defined by irda yet\n",
1182 __FUNCTION__
, dongle_types
[dongle_id
]);
1184 case 0x07: /* Consumer-IR only */
1185 IRDA_DEBUG(0, "%s(), %s is not for IrDA mode\n",
1186 __FUNCTION__
, dongle_types
[dongle_id
]);
1188 case 0x08: /* HP HSDL-2300, HP HSDL-3600/HSDL-3610 */
1189 IRDA_DEBUG(0, "%s(), %s\n",
1190 __FUNCTION__
, dongle_types
[dongle_id
]);
1191 outb(0x00, iobase
+4);
1193 outb(0x01, iobase
+4);
1195 case 0x09: /* IBM31T1100 or Temic TFDS6000/TFDS6500 */
1196 outb(0x01, iobase
+4);
1198 if (speed
== 4000000) {
1199 /* There was a cli() there, but we now are already
1200 * under spin_lock_irqsave() - JeanII */
1201 outb(0x81, iobase
+4);
1202 outb(0x80, iobase
+4);
1204 outb(0x00, iobase
+4);
1206 case 0x0A: /* same as */
1207 case 0x0B: /* Reserved */
1208 IRDA_DEBUG(0, "%s(), %s not defined by irda yet\n",
1209 __FUNCTION__
, dongle_types
[dongle_id
]);
1211 case 0x0C: /* same as */
1212 case 0x0D: /* HP HSDL-1100/HSDL-2100 */
1214 case 0x0E: /* Supports SIR Mode only */
1216 case 0x0F: /* No dongle connected */
1217 IRDA_DEBUG(0, "%s(), %s is not for IrDA mode\n",
1218 __FUNCTION__
, dongle_types
[dongle_id
]);
1220 switch_bank(iobase
, BANK0
);
1221 outb(0x62, iobase
+MCR
);
1224 IRDA_DEBUG(0, "%s(), invalid data_rate\n", __FUNCTION__
);
1226 /* Restore bank register */
1227 outb(bank
, iobase
+BSR
);
1231 * Function nsc_ircc_change_speed (self, baud)
1233 * Change the speed of the device
1235 * This function *must* be called with irq off and spin-lock.
1237 static __u8
nsc_ircc_change_speed(struct nsc_ircc_cb
*self
, __u32 speed
)
1239 struct net_device
*dev
= self
->netdev
;
1243 __u8 ier
; /* Interrupt enable register */
1245 IRDA_DEBUG(2, "%s(), speed=%d\n", __FUNCTION__
, speed
);
1247 IRDA_ASSERT(self
!= NULL
, return 0;);
1249 iobase
= self
->io
.fir_base
;
1251 /* Update accounting for new speed */
1252 self
->io
.speed
= speed
;
1254 /* Save current bank */
1255 bank
= inb(iobase
+BSR
);
1257 /* Disable interrupts */
1258 switch_bank(iobase
, BANK0
);
1259 outb(0, iobase
+IER
);
1262 switch_bank(iobase
, BANK2
);
1264 outb(0x00, iobase
+BGDH
);
1266 case 9600: outb(0x0c, iobase
+BGDL
); break;
1267 case 19200: outb(0x06, iobase
+BGDL
); break;
1268 case 38400: outb(0x03, iobase
+BGDL
); break;
1269 case 57600: outb(0x02, iobase
+BGDL
); break;
1270 case 115200: outb(0x01, iobase
+BGDL
); break;
1272 switch_bank(iobase
, BANK5
);
1274 /* IRCR2: MDRS is set */
1275 outb(inb(iobase
+4) | 0x04, iobase
+4);
1278 IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __FUNCTION__
);
1282 IRDA_DEBUG(0, "%s(), handling baud of 1152000\n", __FUNCTION__
);
1286 IRDA_DEBUG(0, "%s(), handling baud of 4000000\n", __FUNCTION__
);
1290 IRDA_DEBUG(0, "%s(), unknown baud rate of %d\n",
1291 __FUNCTION__
, speed
);
1295 /* Set appropriate speed mode */
1296 switch_bank(iobase
, BANK0
);
1297 outb(mcr
| MCR_TX_DFR
, iobase
+MCR
);
1299 /* Give some hits to the transceiver */
1300 nsc_ircc_change_dongle_speed(iobase
, speed
, self
->io
.dongle_id
);
1302 /* Set FIFO threshold to TX17, RX16 */
1303 switch_bank(iobase
, BANK0
);
1304 outb(0x00, iobase
+FCR
);
1305 outb(FCR_FIFO_EN
, iobase
+FCR
);
1306 outb(FCR_RXTH
| /* Set Rx FIFO threshold */
1307 FCR_TXTH
| /* Set Tx FIFO threshold */
1308 FCR_TXSR
| /* Reset Tx FIFO */
1309 FCR_RXSR
| /* Reset Rx FIFO */
1310 FCR_FIFO_EN
, /* Enable FIFOs */
1313 /* Set FIFO size to 32 */
1314 switch_bank(iobase
, BANK2
);
1315 outb(EXCR2_RFSIZ
|EXCR2_TFSIZ
, iobase
+EXCR2
);
1317 /* Enable some interrupts so we can receive frames */
1318 switch_bank(iobase
, BANK0
);
1319 if (speed
> 115200) {
1320 /* Install FIR xmit handler */
1321 dev
->hard_start_xmit
= nsc_ircc_hard_xmit_fir
;
1323 nsc_ircc_dma_receive(self
);
1325 /* Install SIR xmit handler */
1326 dev
->hard_start_xmit
= nsc_ircc_hard_xmit_sir
;
1329 /* Set our current interrupt mask */
1330 outb(ier
, iobase
+IER
);
1333 outb(bank
, iobase
+BSR
);
1335 /* Make sure interrupt handlers keep the proper interrupt mask */
1340 * Function nsc_ircc_hard_xmit (skb, dev)
1342 * Transmit the frame!
1345 static int nsc_ircc_hard_xmit_sir(struct sk_buff
*skb
, struct net_device
*dev
)
1347 struct nsc_ircc_cb
*self
;
1348 unsigned long flags
;
1353 self
= (struct nsc_ircc_cb
*) dev
->priv
;
1355 IRDA_ASSERT(self
!= NULL
, return 0;);
1357 iobase
= self
->io
.fir_base
;
1359 netif_stop_queue(dev
);
1361 /* Make sure tests *& speed change are atomic */
1362 spin_lock_irqsave(&self
->lock
, flags
);
1364 /* Check if we need to change the speed */
1365 speed
= irda_get_next_speed(skb
);
1366 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
1367 /* Check for empty frame. */
1369 /* If we just sent a frame, we get called before
1370 * the last bytes get out (because of the SIR FIFO).
1371 * If this is the case, let interrupt handler change
1372 * the speed itself... Jean II */
1373 if (self
->io
.direction
== IO_RECV
) {
1374 nsc_ircc_change_speed(self
, speed
);
1375 /* TODO : For SIR->SIR, the next packet
1376 * may get corrupted - Jean II */
1377 netif_wake_queue(dev
);
1379 self
->new_speed
= speed
;
1380 /* Queue will be restarted after speed change
1381 * to make sure packets gets through the
1382 * proper xmit handler - Jean II */
1384 dev
->trans_start
= jiffies
;
1385 spin_unlock_irqrestore(&self
->lock
, flags
);
1389 self
->new_speed
= speed
;
1392 /* Save current bank */
1393 bank
= inb(iobase
+BSR
);
1395 self
->tx_buff
.data
= self
->tx_buff
.head
;
1397 self
->tx_buff
.len
= async_wrap_skb(skb
, self
->tx_buff
.data
,
1398 self
->tx_buff
.truesize
);
1400 self
->stats
.tx_bytes
+= self
->tx_buff
.len
;
1402 /* Add interrupt on tx low level (will fire immediately) */
1403 switch_bank(iobase
, BANK0
);
1404 outb(IER_TXLDL_IE
, iobase
+IER
);
1406 /* Restore bank register */
1407 outb(bank
, iobase
+BSR
);
1409 dev
->trans_start
= jiffies
;
1410 spin_unlock_irqrestore(&self
->lock
, flags
);
1417 static int nsc_ircc_hard_xmit_fir(struct sk_buff
*skb
, struct net_device
*dev
)
1419 struct nsc_ircc_cb
*self
;
1420 unsigned long flags
;
1426 self
= (struct nsc_ircc_cb
*) dev
->priv
;
1427 iobase
= self
->io
.fir_base
;
1429 netif_stop_queue(dev
);
1431 /* Make sure tests *& speed change are atomic */
1432 spin_lock_irqsave(&self
->lock
, flags
);
1434 /* Check if we need to change the speed */
1435 speed
= irda_get_next_speed(skb
);
1436 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
1437 /* Check for empty frame. */
1439 /* If we are currently transmitting, defer to
1440 * interrupt handler. - Jean II */
1441 if(self
->tx_fifo
.len
== 0) {
1442 nsc_ircc_change_speed(self
, speed
);
1443 netif_wake_queue(dev
);
1445 self
->new_speed
= speed
;
1446 /* Keep queue stopped :
1447 * the speed change operation may change the
1448 * xmit handler, and we want to make sure
1449 * the next packet get through the proper
1450 * Tx path, so block the Tx queue until
1451 * the speed change has been done.
1454 dev
->trans_start
= jiffies
;
1455 spin_unlock_irqrestore(&self
->lock
, flags
);
1459 /* Change speed after current frame */
1460 self
->new_speed
= speed
;
1464 /* Save current bank */
1465 bank
= inb(iobase
+BSR
);
1467 /* Register and copy this frame to DMA memory */
1468 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
= self
->tx_fifo
.tail
;
1469 self
->tx_fifo
.queue
[self
->tx_fifo
.free
].len
= skb
->len
;
1470 self
->tx_fifo
.tail
+= skb
->len
;
1472 self
->stats
.tx_bytes
+= skb
->len
;
1474 skb_copy_from_linear_data(skb
, self
->tx_fifo
.queue
[self
->tx_fifo
.free
].start
,
1476 self
->tx_fifo
.len
++;
1477 self
->tx_fifo
.free
++;
1479 /* Start transmit only if there is currently no transmit going on */
1480 if (self
->tx_fifo
.len
== 1) {
1481 /* Check if we must wait the min turn time or not */
1482 mtt
= irda_get_mtt(skb
);
1484 /* Check how much time we have used already */
1485 do_gettimeofday(&self
->now
);
1486 diff
= self
->now
.tv_usec
- self
->stamp
.tv_usec
;
1490 /* Check if the mtt is larger than the time we have
1491 * already used by all the protocol processing
1497 * Use timer if delay larger than 125 us, and
1498 * use udelay for smaller values which should
1502 /* Adjust for timer resolution */
1506 switch_bank(iobase
, BANK4
);
1507 outb(mtt
& 0xff, iobase
+TMRL
);
1508 outb((mtt
>> 8) & 0x0f, iobase
+TMRH
);
1511 outb(IRCR1_TMR_EN
, iobase
+IRCR1
);
1512 self
->io
.direction
= IO_XMIT
;
1514 /* Enable timer interrupt */
1515 switch_bank(iobase
, BANK0
);
1516 outb(IER_TMR_IE
, iobase
+IER
);
1518 /* Timer will take care of the rest */
1524 /* Enable DMA interrupt */
1525 switch_bank(iobase
, BANK0
);
1526 outb(IER_DMA_IE
, iobase
+IER
);
1528 /* Transmit frame */
1529 nsc_ircc_dma_xmit(self
, iobase
);
1532 /* Not busy transmitting anymore if window is not full,
1533 * and if we don't need to change speed */
1534 if ((self
->tx_fifo
.free
< MAX_TX_WINDOW
) && (self
->new_speed
== 0))
1535 netif_wake_queue(self
->netdev
);
1537 /* Restore bank register */
1538 outb(bank
, iobase
+BSR
);
1540 dev
->trans_start
= jiffies
;
1541 spin_unlock_irqrestore(&self
->lock
, flags
);
1548 * Function nsc_ircc_dma_xmit (self, iobase)
1550 * Transmit data using DMA
1553 static void nsc_ircc_dma_xmit(struct nsc_ircc_cb
*self
, int iobase
)
1557 /* Save current bank */
1558 bsr
= inb(iobase
+BSR
);
1561 switch_bank(iobase
, BANK0
);
1562 outb(inb(iobase
+MCR
) & ~MCR_DMA_EN
, iobase
+MCR
);
1564 self
->io
.direction
= IO_XMIT
;
1566 /* Choose transmit DMA channel */
1567 switch_bank(iobase
, BANK2
);
1568 outb(ECR1_DMASWP
|ECR1_DMANF
|ECR1_EXT_SL
, iobase
+ECR1
);
1570 irda_setup_dma(self
->io
.dma
,
1571 ((u8
*)self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].start
-
1572 self
->tx_buff
.head
) + self
->tx_buff_dma
,
1573 self
->tx_fifo
.queue
[self
->tx_fifo
.ptr
].len
,
1576 /* Enable DMA and SIR interaction pulse */
1577 switch_bank(iobase
, BANK0
);
1578 outb(inb(iobase
+MCR
)|MCR_TX_DFR
|MCR_DMA_EN
|MCR_IR_PLS
, iobase
+MCR
);
1580 /* Restore bank register */
1581 outb(bsr
, iobase
+BSR
);
1585 * Function nsc_ircc_pio_xmit (self, iobase)
1587 * Transmit data using PIO. Returns the number of bytes that actually
1591 static int nsc_ircc_pio_write(int iobase
, __u8
*buf
, int len
, int fifo_size
)
1596 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
1598 /* Save current bank */
1599 bank
= inb(iobase
+BSR
);
1601 switch_bank(iobase
, BANK0
);
1602 if (!(inb_p(iobase
+LSR
) & LSR_TXEMP
)) {
1603 IRDA_DEBUG(4, "%s(), warning, FIFO not empty yet!\n",
1606 /* FIFO may still be filled to the Tx interrupt threshold */
1610 /* Fill FIFO with current frame */
1611 while ((fifo_size
-- > 0) && (actual
< len
)) {
1612 /* Transmit next byte */
1613 outb(buf
[actual
++], iobase
+TXD
);
1616 IRDA_DEBUG(4, "%s(), fifo_size %d ; %d sent of %d\n",
1617 __FUNCTION__
, fifo_size
, actual
, len
);
1620 outb(bank
, iobase
+BSR
);
1626 * Function nsc_ircc_dma_xmit_complete (self)
1628 * The transfer of a frame in finished. This function will only be called
1629 * by the interrupt handler
1632 static int nsc_ircc_dma_xmit_complete(struct nsc_ircc_cb
*self
)
1638 IRDA_DEBUG(2, "%s()\n", __FUNCTION__
);
1640 iobase
= self
->io
.fir_base
;
1642 /* Save current bank */
1643 bank
= inb(iobase
+BSR
);
1646 switch_bank(iobase
, BANK0
);
1647 outb(inb(iobase
+MCR
) & ~MCR_DMA_EN
, iobase
+MCR
);
1649 /* Check for underrrun! */
1650 if (inb(iobase
+ASCR
) & ASCR_TXUR
) {
1651 self
->stats
.tx_errors
++;
1652 self
->stats
.tx_fifo_errors
++;
1654 /* Clear bit, by writing 1 into it */
1655 outb(ASCR_TXUR
, iobase
+ASCR
);
1657 self
->stats
.tx_packets
++;
1660 /* Finished with this frame, so prepare for next */
1661 self
->tx_fifo
.ptr
++;
1662 self
->tx_fifo
.len
--;
1664 /* Any frames to be sent back-to-back? */
1665 if (self
->tx_fifo
.len
) {
1666 nsc_ircc_dma_xmit(self
, iobase
);
1668 /* Not finished yet! */
1671 /* Reset Tx FIFO info */
1672 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
1673 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
1676 /* Make sure we have room for more frames and
1677 * that we don't need to change speed */
1678 if ((self
->tx_fifo
.free
< MAX_TX_WINDOW
) && (self
->new_speed
== 0)) {
1679 /* Not busy transmitting anymore */
1680 /* Tell the network layer, that we can accept more frames */
1681 netif_wake_queue(self
->netdev
);
1685 outb(bank
, iobase
+BSR
);
1691 * Function nsc_ircc_dma_receive (self)
1693 * Get ready for receiving a frame. The device will initiate a DMA
1694 * if it starts to receive a frame.
1697 static int nsc_ircc_dma_receive(struct nsc_ircc_cb
*self
)
1702 iobase
= self
->io
.fir_base
;
1704 /* Reset Tx FIFO info */
1705 self
->tx_fifo
.len
= self
->tx_fifo
.ptr
= self
->tx_fifo
.free
= 0;
1706 self
->tx_fifo
.tail
= self
->tx_buff
.head
;
1708 /* Save current bank */
1709 bsr
= inb(iobase
+BSR
);
1712 switch_bank(iobase
, BANK0
);
1713 outb(inb(iobase
+MCR
) & ~MCR_DMA_EN
, iobase
+MCR
);
1715 /* Choose DMA Rx, DMA Fairness, and Advanced mode */
1716 switch_bank(iobase
, BANK2
);
1717 outb(ECR1_DMANF
|ECR1_EXT_SL
, iobase
+ECR1
);
1719 self
->io
.direction
= IO_RECV
;
1720 self
->rx_buff
.data
= self
->rx_buff
.head
;
1722 /* Reset Rx FIFO. This will also flush the ST_FIFO */
1723 switch_bank(iobase
, BANK0
);
1724 outb(FCR_RXSR
|FCR_FIFO_EN
, iobase
+FCR
);
1726 self
->st_fifo
.len
= self
->st_fifo
.pending_bytes
= 0;
1727 self
->st_fifo
.tail
= self
->st_fifo
.head
= 0;
1729 irda_setup_dma(self
->io
.dma
, self
->rx_buff_dma
, self
->rx_buff
.truesize
,
1733 switch_bank(iobase
, BANK0
);
1734 outb(inb(iobase
+MCR
)|MCR_DMA_EN
, iobase
+MCR
);
1736 /* Restore bank register */
1737 outb(bsr
, iobase
+BSR
);
1743 * Function nsc_ircc_dma_receive_complete (self)
1745 * Finished with receiving frames
1749 static int nsc_ircc_dma_receive_complete(struct nsc_ircc_cb
*self
, int iobase
)
1751 struct st_fifo
*st_fifo
;
1752 struct sk_buff
*skb
;
1757 st_fifo
= &self
->st_fifo
;
1759 /* Save current bank */
1760 bank
= inb(iobase
+BSR
);
1762 /* Read all entries in status FIFO */
1763 switch_bank(iobase
, BANK5
);
1764 while ((status
= inb(iobase
+FRM_ST
)) & FRM_ST_VLD
) {
1765 /* We must empty the status FIFO no matter what */
1766 len
= inb(iobase
+RFLFL
) | ((inb(iobase
+RFLFH
) & 0x1f) << 8);
1768 if (st_fifo
->tail
>= MAX_RX_WINDOW
) {
1769 IRDA_DEBUG(0, "%s(), window is full!\n", __FUNCTION__
);
1773 st_fifo
->entries
[st_fifo
->tail
].status
= status
;
1774 st_fifo
->entries
[st_fifo
->tail
].len
= len
;
1775 st_fifo
->pending_bytes
+= len
;
1779 /* Try to process all entries in status FIFO */
1780 while (st_fifo
->len
> 0) {
1781 /* Get first entry */
1782 status
= st_fifo
->entries
[st_fifo
->head
].status
;
1783 len
= st_fifo
->entries
[st_fifo
->head
].len
;
1784 st_fifo
->pending_bytes
-= len
;
1788 /* Check for errors */
1789 if (status
& FRM_ST_ERR_MSK
) {
1790 if (status
& FRM_ST_LOST_FR
) {
1791 /* Add number of lost frames to stats */
1792 self
->stats
.rx_errors
+= len
;
1795 self
->stats
.rx_errors
++;
1797 self
->rx_buff
.data
+= len
;
1799 if (status
& FRM_ST_MAX_LEN
)
1800 self
->stats
.rx_length_errors
++;
1802 if (status
& FRM_ST_PHY_ERR
)
1803 self
->stats
.rx_frame_errors
++;
1805 if (status
& FRM_ST_BAD_CRC
)
1806 self
->stats
.rx_crc_errors
++;
1808 /* The errors below can be reported in both cases */
1809 if (status
& FRM_ST_OVR1
)
1810 self
->stats
.rx_fifo_errors
++;
1812 if (status
& FRM_ST_OVR2
)
1813 self
->stats
.rx_fifo_errors
++;
1816 * First we must make sure that the frame we
1817 * want to deliver is all in main memory. If we
1818 * cannot tell, then we check if the Rx FIFO is
1819 * empty. If not then we will have to take a nap
1820 * and try again later.
1822 if (st_fifo
->pending_bytes
< self
->io
.fifo_size
) {
1823 switch_bank(iobase
, BANK0
);
1824 if (inb(iobase
+LSR
) & LSR_RXDA
) {
1825 /* Put this entry back in fifo */
1828 st_fifo
->pending_bytes
+= len
;
1829 st_fifo
->entries
[st_fifo
->head
].status
= status
;
1830 st_fifo
->entries
[st_fifo
->head
].len
= len
;
1832 * DMA not finished yet, so try again
1833 * later, set timer value, resolution
1836 switch_bank(iobase
, BANK4
);
1837 outb(0x02, iobase
+TMRL
); /* x 125 us */
1838 outb(0x00, iobase
+TMRH
);
1841 outb(IRCR1_TMR_EN
, iobase
+IRCR1
);
1843 /* Restore bank register */
1844 outb(bank
, iobase
+BSR
);
1846 return FALSE
; /* I'll be back! */
1851 * Remember the time we received this frame, so we can
1852 * reduce the min turn time a bit since we will know
1853 * how much time we have used for protocol processing
1855 do_gettimeofday(&self
->stamp
);
1857 skb
= dev_alloc_skb(len
+1);
1859 IRDA_WARNING("%s(), memory squeeze, "
1860 "dropping frame.\n",
1862 self
->stats
.rx_dropped
++;
1864 /* Restore bank register */
1865 outb(bank
, iobase
+BSR
);
1870 /* Make sure IP header gets aligned */
1871 skb_reserve(skb
, 1);
1873 /* Copy frame without CRC */
1874 if (self
->io
.speed
< 4000000) {
1875 skb_put(skb
, len
-2);
1876 skb_copy_to_linear_data(skb
,
1880 skb_put(skb
, len
-4);
1881 skb_copy_to_linear_data(skb
,
1886 /* Move to next frame */
1887 self
->rx_buff
.data
+= len
;
1888 self
->stats
.rx_bytes
+= len
;
1889 self
->stats
.rx_packets
++;
1891 skb
->dev
= self
->netdev
;
1892 skb_reset_mac_header(skb
);
1893 skb
->protocol
= htons(ETH_P_IRDA
);
1895 self
->netdev
->last_rx
= jiffies
;
1898 /* Restore bank register */
1899 outb(bank
, iobase
+BSR
);
1905 * Function nsc_ircc_pio_receive (self)
1907 * Receive all data in receiver FIFO
1910 static void nsc_ircc_pio_receive(struct nsc_ircc_cb
*self
)
1915 iobase
= self
->io
.fir_base
;
1917 /* Receive all characters in Rx FIFO */
1919 byte
= inb(iobase
+RXD
);
1920 async_unwrap_char(self
->netdev
, &self
->stats
, &self
->rx_buff
,
1922 } while (inb(iobase
+LSR
) & LSR_RXDA
); /* Data available */
1926 * Function nsc_ircc_sir_interrupt (self, eir)
1928 * Handle SIR interrupt
1931 static void nsc_ircc_sir_interrupt(struct nsc_ircc_cb
*self
, int eir
)
1935 /* Check if transmit FIFO is low on data */
1936 if (eir
& EIR_TXLDL_EV
) {
1937 /* Write data left in transmit buffer */
1938 actual
= nsc_ircc_pio_write(self
->io
.fir_base
,
1941 self
->io
.fifo_size
);
1942 self
->tx_buff
.data
+= actual
;
1943 self
->tx_buff
.len
-= actual
;
1945 self
->io
.direction
= IO_XMIT
;
1947 /* Check if finished */
1948 if (self
->tx_buff
.len
> 0)
1949 self
->ier
= IER_TXLDL_IE
;
1952 self
->stats
.tx_packets
++;
1953 netif_wake_queue(self
->netdev
);
1954 self
->ier
= IER_TXEMP_IE
;
1958 /* Check if transmission has completed */
1959 if (eir
& EIR_TXEMP_EV
) {
1960 /* Turn around and get ready to receive some data */
1961 self
->io
.direction
= IO_RECV
;
1962 self
->ier
= IER_RXHDL_IE
;
1963 /* Check if we need to change the speed?
1964 * Need to be after self->io.direction to avoid race with
1965 * nsc_ircc_hard_xmit_sir() - Jean II */
1966 if (self
->new_speed
) {
1967 IRDA_DEBUG(2, "%s(), Changing speed!\n", __FUNCTION__
);
1968 self
->ier
= nsc_ircc_change_speed(self
,
1970 self
->new_speed
= 0;
1971 netif_wake_queue(self
->netdev
);
1973 /* Check if we are going to FIR */
1974 if (self
->io
.speed
> 115200) {
1975 /* No need to do anymore SIR stuff */
1981 /* Rx FIFO threshold or timeout */
1982 if (eir
& EIR_RXHDL_EV
) {
1983 nsc_ircc_pio_receive(self
);
1985 /* Keep receiving */
1986 self
->ier
= IER_RXHDL_IE
;
1991 * Function nsc_ircc_fir_interrupt (self, eir)
1993 * Handle MIR/FIR interrupt
1996 static void nsc_ircc_fir_interrupt(struct nsc_ircc_cb
*self
, int iobase
,
2001 bank
= inb(iobase
+BSR
);
2003 /* Status FIFO event*/
2004 if (eir
& EIR_SFIF_EV
) {
2005 /* Check if DMA has finished */
2006 if (nsc_ircc_dma_receive_complete(self
, iobase
)) {
2007 /* Wait for next status FIFO interrupt */
2008 self
->ier
= IER_SFIF_IE
;
2010 self
->ier
= IER_SFIF_IE
| IER_TMR_IE
;
2012 } else if (eir
& EIR_TMR_EV
) { /* Timer finished */
2014 switch_bank(iobase
, BANK4
);
2015 outb(0, iobase
+IRCR1
);
2017 /* Clear timer event */
2018 switch_bank(iobase
, BANK0
);
2019 outb(ASCR_CTE
, iobase
+ASCR
);
2021 /* Check if this is a Tx timer interrupt */
2022 if (self
->io
.direction
== IO_XMIT
) {
2023 nsc_ircc_dma_xmit(self
, iobase
);
2025 /* Interrupt on DMA */
2026 self
->ier
= IER_DMA_IE
;
2028 /* Check (again) if DMA has finished */
2029 if (nsc_ircc_dma_receive_complete(self
, iobase
)) {
2030 self
->ier
= IER_SFIF_IE
;
2032 self
->ier
= IER_SFIF_IE
| IER_TMR_IE
;
2035 } else if (eir
& EIR_DMA_EV
) {
2036 /* Finished with all transmissions? */
2037 if (nsc_ircc_dma_xmit_complete(self
)) {
2038 if(self
->new_speed
!= 0) {
2039 /* As we stop the Tx queue, the speed change
2040 * need to be done when the Tx fifo is
2041 * empty. Ask for a Tx done interrupt */
2042 self
->ier
= IER_TXEMP_IE
;
2044 /* Check if there are more frames to be
2046 if (irda_device_txqueue_empty(self
->netdev
)) {
2047 /* Prepare for receive */
2048 nsc_ircc_dma_receive(self
);
2049 self
->ier
= IER_SFIF_IE
;
2051 IRDA_WARNING("%s(), potential "
2052 "Tx queue lockup !\n",
2056 /* Not finished yet, so interrupt on DMA again */
2057 self
->ier
= IER_DMA_IE
;
2059 } else if (eir
& EIR_TXEMP_EV
) {
2060 /* The Tx FIFO has totally drained out, so now we can change
2061 * the speed... - Jean II */
2062 self
->ier
= nsc_ircc_change_speed(self
, self
->new_speed
);
2063 self
->new_speed
= 0;
2064 netif_wake_queue(self
->netdev
);
2065 /* Note : nsc_ircc_change_speed() restarted Rx fifo */
2068 outb(bank
, iobase
+BSR
);
2072 * Function nsc_ircc_interrupt (irq, dev_id, regs)
2074 * An interrupt from the chip has arrived. Time to do some work
2077 static irqreturn_t
nsc_ircc_interrupt(int irq
, void *dev_id
)
2079 struct net_device
*dev
= dev_id
;
2080 struct nsc_ircc_cb
*self
;
2086 spin_lock(&self
->lock
);
2088 iobase
= self
->io
.fir_base
;
2090 bsr
= inb(iobase
+BSR
); /* Save current bank */
2092 switch_bank(iobase
, BANK0
);
2093 self
->ier
= inb(iobase
+IER
);
2094 eir
= inb(iobase
+EIR
) & self
->ier
; /* Mask out the interesting ones */
2096 outb(0, iobase
+IER
); /* Disable interrupts */
2099 /* Dispatch interrupt handler for the current speed */
2100 if (self
->io
.speed
> 115200)
2101 nsc_ircc_fir_interrupt(self
, iobase
, eir
);
2103 nsc_ircc_sir_interrupt(self
, eir
);
2106 outb(self
->ier
, iobase
+IER
); /* Restore interrupts */
2107 outb(bsr
, iobase
+BSR
); /* Restore bank register */
2109 spin_unlock(&self
->lock
);
2110 return IRQ_RETVAL(eir
);
2114 * Function nsc_ircc_is_receiving (self)
2116 * Return TRUE is we are currently receiving a frame
2119 static int nsc_ircc_is_receiving(struct nsc_ircc_cb
*self
)
2121 unsigned long flags
;
2126 IRDA_ASSERT(self
!= NULL
, return FALSE
;);
2128 spin_lock_irqsave(&self
->lock
, flags
);
2130 if (self
->io
.speed
> 115200) {
2131 iobase
= self
->io
.fir_base
;
2133 /* Check if rx FIFO is not empty */
2134 bank
= inb(iobase
+BSR
);
2135 switch_bank(iobase
, BANK2
);
2136 if ((inb(iobase
+RXFLV
) & 0x3f) != 0) {
2137 /* We are receiving something */
2140 outb(bank
, iobase
+BSR
);
2142 status
= (self
->rx_buff
.state
!= OUTSIDE_FRAME
);
2144 spin_unlock_irqrestore(&self
->lock
, flags
);
2150 * Function nsc_ircc_net_open (dev)
2155 static int nsc_ircc_net_open(struct net_device
*dev
)
2157 struct nsc_ircc_cb
*self
;
2162 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
2164 IRDA_ASSERT(dev
!= NULL
, return -1;);
2165 self
= (struct nsc_ircc_cb
*) dev
->priv
;
2167 IRDA_ASSERT(self
!= NULL
, return 0;);
2169 iobase
= self
->io
.fir_base
;
2171 if (request_irq(self
->io
.irq
, nsc_ircc_interrupt
, 0, dev
->name
, dev
)) {
2172 IRDA_WARNING("%s, unable to allocate irq=%d\n",
2173 driver_name
, self
->io
.irq
);
2177 * Always allocate the DMA channel after the IRQ, and clean up on
2180 if (request_dma(self
->io
.dma
, dev
->name
)) {
2181 IRDA_WARNING("%s, unable to allocate dma=%d\n",
2182 driver_name
, self
->io
.dma
);
2183 free_irq(self
->io
.irq
, dev
);
2187 /* Save current bank */
2188 bank
= inb(iobase
+BSR
);
2190 /* turn on interrupts */
2191 switch_bank(iobase
, BANK0
);
2192 outb(IER_LS_IE
| IER_RXHDL_IE
, iobase
+IER
);
2194 /* Restore bank register */
2195 outb(bank
, iobase
+BSR
);
2197 /* Ready to play! */
2198 netif_start_queue(dev
);
2200 /* Give self a hardware name */
2201 sprintf(hwname
, "NSC-FIR @ 0x%03x", self
->io
.fir_base
);
2204 * Open new IrLAP layer instance, now that everything should be
2205 * initialized properly
2207 self
->irlap
= irlap_open(dev
, &self
->qos
, hwname
);
2213 * Function nsc_ircc_net_close (dev)
2218 static int nsc_ircc_net_close(struct net_device
*dev
)
2220 struct nsc_ircc_cb
*self
;
2224 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
2226 IRDA_ASSERT(dev
!= NULL
, return -1;);
2228 self
= (struct nsc_ircc_cb
*) dev
->priv
;
2229 IRDA_ASSERT(self
!= NULL
, return 0;);
2232 netif_stop_queue(dev
);
2234 /* Stop and remove instance of IrLAP */
2236 irlap_close(self
->irlap
);
2239 iobase
= self
->io
.fir_base
;
2241 disable_dma(self
->io
.dma
);
2243 /* Save current bank */
2244 bank
= inb(iobase
+BSR
);
2246 /* Disable interrupts */
2247 switch_bank(iobase
, BANK0
);
2248 outb(0, iobase
+IER
);
2250 free_irq(self
->io
.irq
, dev
);
2251 free_dma(self
->io
.dma
);
2253 /* Restore bank register */
2254 outb(bank
, iobase
+BSR
);
2260 * Function nsc_ircc_net_ioctl (dev, rq, cmd)
2262 * Process IOCTL commands for this device
2265 static int nsc_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2267 struct if_irda_req
*irq
= (struct if_irda_req
*) rq
;
2268 struct nsc_ircc_cb
*self
;
2269 unsigned long flags
;
2272 IRDA_ASSERT(dev
!= NULL
, return -1;);
2276 IRDA_ASSERT(self
!= NULL
, return -1;);
2278 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__
, dev
->name
, cmd
);
2281 case SIOCSBANDWIDTH
: /* Set bandwidth */
2282 if (!capable(CAP_NET_ADMIN
)) {
2286 spin_lock_irqsave(&self
->lock
, flags
);
2287 nsc_ircc_change_speed(self
, irq
->ifr_baudrate
);
2288 spin_unlock_irqrestore(&self
->lock
, flags
);
2290 case SIOCSMEDIABUSY
: /* Set media busy */
2291 if (!capable(CAP_NET_ADMIN
)) {
2295 irda_device_set_media_busy(self
->netdev
, TRUE
);
2297 case SIOCGRECEIVING
: /* Check if we are receiving right now */
2298 /* This is already protected */
2299 irq
->ifr_receiving
= nsc_ircc_is_receiving(self
);
2307 static struct net_device_stats
*nsc_ircc_net_get_stats(struct net_device
*dev
)
2309 struct nsc_ircc_cb
*self
= (struct nsc_ircc_cb
*) dev
->priv
;
2311 return &self
->stats
;
2314 static int nsc_ircc_suspend(struct platform_device
*dev
, pm_message_t state
)
2316 struct nsc_ircc_cb
*self
= platform_get_drvdata(dev
);
2318 unsigned long flags
;
2319 int iobase
= self
->io
.fir_base
;
2321 if (self
->io
.suspended
)
2324 IRDA_DEBUG(1, "%s, Suspending\n", driver_name
);
2327 if (netif_running(self
->netdev
)) {
2328 netif_device_detach(self
->netdev
);
2329 spin_lock_irqsave(&self
->lock
, flags
);
2330 /* Save current bank */
2331 bank
= inb(iobase
+BSR
);
2333 /* Disable interrupts */
2334 switch_bank(iobase
, BANK0
);
2335 outb(0, iobase
+IER
);
2337 /* Restore bank register */
2338 outb(bank
, iobase
+BSR
);
2340 spin_unlock_irqrestore(&self
->lock
, flags
);
2341 free_irq(self
->io
.irq
, self
->netdev
);
2342 disable_dma(self
->io
.dma
);
2344 self
->io
.suspended
= 1;
2350 static int nsc_ircc_resume(struct platform_device
*dev
)
2352 struct nsc_ircc_cb
*self
= platform_get_drvdata(dev
);
2353 unsigned long flags
;
2355 if (!self
->io
.suspended
)
2358 IRDA_DEBUG(1, "%s, Waking up\n", driver_name
);
2361 nsc_ircc_setup(&self
->io
);
2362 nsc_ircc_init_dongle_interface(self
->io
.fir_base
, self
->io
.dongle_id
);
2364 if (netif_running(self
->netdev
)) {
2365 if (request_irq(self
->io
.irq
, nsc_ircc_interrupt
, 0,
2366 self
->netdev
->name
, self
->netdev
)) {
2367 IRDA_WARNING("%s, unable to allocate irq=%d\n",
2368 driver_name
, self
->io
.irq
);
2371 * Don't fail resume process, just kill this
2374 unregister_netdevice(self
->netdev
);
2376 spin_lock_irqsave(&self
->lock
, flags
);
2377 nsc_ircc_change_speed(self
, self
->io
.speed
);
2378 spin_unlock_irqrestore(&self
->lock
, flags
);
2379 netif_device_attach(self
->netdev
);
2383 spin_lock_irqsave(&self
->lock
, flags
);
2384 nsc_ircc_change_speed(self
, 9600);
2385 spin_unlock_irqrestore(&self
->lock
, flags
);
2387 self
->io
.suspended
= 0;
2393 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
2394 MODULE_DESCRIPTION("NSC IrDA Device Driver");
2395 MODULE_LICENSE("GPL");
2398 module_param(qos_mtt_bits
, int, 0);
2399 MODULE_PARM_DESC(qos_mtt_bits
, "Minimum Turn Time");
2400 module_param_array(io
, int, NULL
, 0);
2401 MODULE_PARM_DESC(io
, "Base I/O addresses");
2402 module_param_array(irq
, int, NULL
, 0);
2403 MODULE_PARM_DESC(irq
, "IRQ lines");
2404 module_param_array(dma
, int, NULL
, 0);
2405 MODULE_PARM_DESC(dma
, "DMA channels");
2406 module_param(dongle_id
, int, 0);
2407 MODULE_PARM_DESC(dongle_id
, "Type-id of used dongle");
2409 module_init(nsc_ircc_init
);
2410 module_exit(nsc_ircc_cleanup
);