1 /*********************************************************************
5 * Description: Driver for the SMC Infrared Communications Controller
6 * Status: Experimental.
7 * Author: Thomas Davis (tadavis@jps.net)
9 * Modified at: Tue Feb 22 10:05:06 2000
10 * Modified by: Dag Brattli <dag@brattli.net>
12 * Copyright (c) 1999-2000 Dag Brattli
13 * Copyright (c) 1998-1999 Thomas Davis,
14 * All Rights Reserved.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 * SIO's: SMC FDC37N869, FDC37C669, FDC37N958
32 * Applicable Models : Fujitsu Lifebook 635t, Sony PCG-505TX
34 ********************************************************************/
36 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/types.h>
39 #include <linux/skbuff.h>
40 #include <linux/netdevice.h>
41 #include <linux/ioport.h>
42 #include <linux/delay.h>
43 #include <linux/malloc.h>
44 #include <linux/init.h>
45 #include <linux/rtnetlink.h>
46 #include <linux/serial_reg.h>
50 #include <asm/byteorder.h>
54 #include <net/irda/wrapper.h>
55 #include <net/irda/irda.h>
56 #include <net/irda/irmod.h>
57 #include <net/irda/irlap_frame.h>
58 #include <net/irda/irda_device.h>
60 #include <net/irda/smc-ircc.h>
61 #include <net/irda/irport.h>
63 static char *driver_name
= "smc-ircc";
65 #define CHIP_IO_EXTENT 8
67 static unsigned int io
[] = { ~0, ~0 };
68 static unsigned int io2
[] = { 0, 0 };
70 static struct ircc_cb
*dev_self
[] = { NULL
, NULL
};
73 static int ircc_open(int i
, unsigned int iobase
, unsigned int board_addr
);
75 static int ircc_close(struct ircc_cb
*self
);
77 static int ircc_probe(int iobase
, int board_addr
);
78 static int ircc_probe_58(smc_chip_t
*chip
, chipio_t
*info
);
79 static int ircc_probe_69(smc_chip_t
*chip
, chipio_t
*info
);
80 static int ircc_dma_receive(struct ircc_cb
*self
, int iobase
);
81 static void ircc_dma_receive_complete(struct ircc_cb
*self
, int iobase
);
82 static int ircc_hard_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
83 static void ircc_dma_xmit(struct ircc_cb
*self
, int iobase
, int bofs
);
84 static void ircc_change_speed(void *priv
, __u32 speed
);
85 static void ircc_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
87 static int ircc_is_receiving(struct ircc_cb
*self
);
90 static int ircc_net_open(struct net_device
*dev
);
91 static int ircc_net_close(struct net_device
*dev
);
92 static int ircc_pmproc(struct pm_dev
*dev
, pm_request_t rqst
, void *data
);
94 /* These are the currently known SMC chipsets */
95 static smc_chip_t chips
[] =
97 { "FDC37C669", 0x55, 0x55, 0x0d, 0x04, ircc_probe_69
},
98 { "FDC37N769", 0x55, 0x55, 0x0d, 0x28, ircc_probe_69
},
99 { "FDC37N869", 0x55, 0x00, 0x0d, 0x29, ircc_probe_69
},
100 { "FDC37N958", 0x55, 0x55, 0x20, 0x09, ircc_probe_58
},
104 static int ircc_irq
=255;
105 static int ircc_dma
=255;
107 static inline void register_bank(int iobase
, int bank
)
109 outb(((inb(iobase
+IRCC_MASTER
) & 0xf0) | (bank
& 0x07)),
114 * Function ircc_init ()
116 * Initialize chip. Just try to find out how many chips we are dealing with
119 int __init
ircc_init(void)
121 static int smcreg
[] = { 0x3f0, 0x370 };
127 IRDA_DEBUG(0, __FUNCTION__
"\n");
129 /* Probe for all the NSC chipsets we know about */
130 for (chip
=chips
; chip
->name
; chip
++,i
++) {
131 for (i
=0; i
<2; i
++) {
132 info
.cfg_base
= smcreg
[i
];
135 * First we check if the user has supplied any
136 * parameters which we should use instead of probed
140 info
.fir_base
= io
[i
];
141 info
.sir_base
= io2
[i
];
142 } else if (chip
->probe(chip
, &info
) < 0)
144 if (check_region(info
.fir_base
, CHIP_IO_EXTENT
) < 0)
146 if (check_region(info
.sir_base
, CHIP_IO_EXTENT
) < 0)
148 if (ircc_open(i
, info
.fir_base
, info
.sir_base
) == 0)
156 * Function ircc_cleanup ()
158 * Close all configured chips
162 static void ircc_cleanup(void)
166 IRDA_DEBUG(0, __FUNCTION__
"\n");
168 for (i
=0; i
< 2; i
++) {
170 ircc_close(dev_self
[i
]);
176 * Function ircc_open (iobase, irq)
178 * Open driver instance
181 static int ircc_open(int i
, unsigned int fir_base
, unsigned int sir_base
)
183 struct ircc_cb
*self
;
184 struct irport_cb
*irport
;
188 IRDA_DEBUG(0, __FUNCTION__
"\n");
190 if ((config
= ircc_probe(fir_base
, sir_base
)) == -1) {
191 IRDA_DEBUG(0, __FUNCTION__
192 "(), addr 0x%04x - no device found!\n", fir_base
);
197 * Allocate new instance of the driver
199 self
= kmalloc(sizeof(struct ircc_cb
), GFP_KERNEL
);
201 ERROR("%s, Can't allocate memory for control block!\n",
205 memset(self
, 0, sizeof(struct ircc_cb
));
206 spin_lock_init(&self
->lock
);
208 /* Need to store self somewhere */
211 irport
= irport_open(i
, sir_base
, config
>> 4 & 0x0f);
215 /* Steal the network device from irport */
216 self
->netdev
= irport
->netdev
;
217 self
->irport
= irport
;
221 self
->io
.fir_base
= fir_base
;
222 self
->io
.sir_base
= sir_base
; /* Used by irport */
223 self
->io
.irq
= config
>> 4 & 0x0f;
224 if (ircc_irq
< 255) {
225 MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
226 driver_name
, self
->io
.irq
, ircc_irq
);
227 self
->io
.irq
= ircc_irq
;
229 self
->io
.fir_ext
= CHIP_IO_EXTENT
;
230 self
->io
.sir_ext
= 8; /* Used by irport */
231 self
->io
.dma
= config
& 0x0f;
232 if (ircc_dma
< 255) {
233 MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
234 driver_name
, self
->io
.dma
, ircc_dma
);
235 self
->io
.dma
= ircc_dma
;
238 /* Lock the port that we need */
239 ret
= check_region(self
->io
.fir_base
, self
->io
.fir_ext
);
241 IRDA_DEBUG(0, __FUNCTION__
": can't get fir_base of 0x%03x\n",
246 request_region(self
->io
.fir_base
, self
->io
.fir_ext
, driver_name
);
248 /* Initialize QoS for this device */
249 irda_init_max_qos_capabilies(&irport
->qos
);
251 /* The only value we must override it the baudrate */
252 irport
->qos
.baud_rate
.bits
= IR_9600
|IR_19200
|IR_38400
|IR_57600
|
253 IR_115200
|IR_576000
|IR_1152000
|(IR_4000000
<< 8);
255 irport
->qos
.min_turn_time
.bits
= 0x07;
256 irport
->qos
.window_size
.bits
= 0x01;
257 irda_qos_bits_to_value(&irport
->qos
);
259 irport
->flags
= IFF_FIR
|IFF_MIR
|IFF_SIR
|IFF_DMA
|IFF_PIO
;
261 /* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
262 self
->rx_buff
.truesize
= 4000;
263 self
->tx_buff
.truesize
= 4000;
265 self
->rx_buff
.head
= (__u8
*) kmalloc(self
->rx_buff
.truesize
,
267 if (self
->rx_buff
.head
== NULL
)
269 memset(self
->rx_buff
.head
, 0, self
->rx_buff
.truesize
);
271 self
->tx_buff
.head
= (__u8
*) kmalloc(self
->tx_buff
.truesize
,
273 if (self
->tx_buff
.head
== NULL
) {
274 kfree(self
->rx_buff
.head
);
277 memset(self
->tx_buff
.head
, 0, self
->tx_buff
.truesize
);
279 self
->rx_buff
.in_frame
= FALSE
;
280 self
->rx_buff
.state
= OUTSIDE_FRAME
;
281 self
->tx_buff
.data
= self
->tx_buff
.head
;
282 self
->rx_buff
.data
= self
->rx_buff
.head
;
284 /* Override the speed change function, since we must control it now */
285 irport
->change_speed
= &ircc_change_speed
;
286 irport
->interrupt
= &ircc_interrupt
;
287 self
->netdev
->open
= &ircc_net_open
;
288 self
->netdev
->stop
= &ircc_net_close
;
290 irport_start(self
->irport
);
292 self
->pmdev
= pm_register(PM_SYS_DEV
, PM_SYS_IRDA
, ircc_pmproc
);
294 self
->pmdev
->data
= self
;
300 * Function ircc_close (self)
302 * Close driver instance
306 static int ircc_close(struct ircc_cb
*self
)
310 IRDA_DEBUG(0, __FUNCTION__
"\n");
312 ASSERT(self
!= NULL
, return -1;);
314 iobase
= self
->io
.fir_base
;
316 irport_close(self
->irport
);
318 /* Stop interrupts */
319 register_bank(iobase
, 0);
320 outb(0, iobase
+IRCC_IER
);
321 outb(IRCC_MASTER_RESET
, iobase
+IRCC_MASTER
);
322 outb(0x00, iobase
+IRCC_MASTER
);
324 /* Reset to SIR mode */
325 register_bank(iobase
, 1);
326 outb(IRCC_CFGA_IRDA_SIR_A
|IRCC_CFGA_TX_POLARITY
, iobase
+IRCC_SCE_CFGA
);
327 outb(IRCC_CFGB_IR
, iobase
+IRCC_SCE_CFGB
);
329 /* Release the PORT that this driver is using */
330 IRDA_DEBUG(0, __FUNCTION__
"(), releasing 0x%03x\n",
333 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
335 if (self
->tx_buff
.head
)
336 kfree(self
->tx_buff
.head
);
338 if (self
->rx_buff
.head
)
339 kfree(self
->rx_buff
.head
);
348 * Function ircc_probe_69 (chip, info)
350 * Probes for the SMC FDC37C669 and FDC37N869
353 static int ircc_probe_69(smc_chip_t
*chip
, chipio_t
*info
)
355 int cfg_base
= info
->cfg_base
;
360 IRDA_DEBUG(0, __FUNCTION__
"()\n");
362 /* Enter configuration */
363 outb(chip
->entr1
, cfg_base
);
364 outb(chip
->entr2
, cfg_base
);
366 outb(chip
->cid_index
, cfg_base
);
367 devid
= inb(cfg_base
+1);
368 IRDA_DEBUG(0, __FUNCTION__
"(), devid=0x%02x\n",devid
);
370 /* Check for expected device ID; are there others? */
371 if (devid
== chip
->cid_value
) {
372 outb(0x0c, cfg_base
);
373 mode
= inb(cfg_base
+1);
374 mode
= (mode
& 0x38) >> 3;
376 /* Value for IR port */
377 if (mode
&& mode
< 4) {
379 outb(0x25, cfg_base
);
380 info
->sir_base
= inb(cfg_base
+1) << 2;
383 outb(0x2b, cfg_base
);
384 fir_io
= inb(cfg_base
+1) << 3;
387 info
->fir_base
= fir_io
;
392 /* Exit configuration */
393 outb(0xaa, cfg_base
);
399 * Function ircc_probe_58 (chip, info)
401 * Probes for the SMC FDC37N958
404 static int ircc_probe_58(smc_chip_t
*chip
, chipio_t
*info
)
406 int cfg_base
= info
->cfg_base
;
411 IRDA_DEBUG(0, __FUNCTION__
"()\n");
413 /* Enter configuration */
414 outb(chip
->entr1
, cfg_base
);
415 outb(chip
->entr2
, cfg_base
);
417 outb(chip
->cid_index
, cfg_base
);
418 devid
= inb(cfg_base
+1);
419 IRDA_DEBUG(0, __FUNCTION__
"(), devid=0x%02x\n",devid
);
421 /* Check for expected device ID; are there others? */
422 if (devid
== chip
->cid_value
) {
423 /* Select logical device (UART2) */
424 outb(0x07, cfg_base
);
425 outb(0x05, cfg_base
+ 1);
428 outb(0x60, cfg_base
);
429 info
->sir_base
= inb(cfg_base
+ 1) << 8;
430 outb(0x61, cfg_base
);
431 info
->sir_base
|= inb(cfg_base
+ 1);
434 outb(0x62, cfg_base
);
435 fir_io
= inb(cfg_base
+ 1) << 8;
436 outb(0x63, cfg_base
);
437 fir_io
|= inb(cfg_base
+ 1);
438 outb(0x2b, cfg_base
);
441 info
->fir_base
= fir_io
;
445 /* Exit configuration */
446 outb(0xaa, cfg_base
);
452 * Function ircc_probe (iobase, board_addr, irq, dma)
454 * Returns non-negative on success.
457 static int ircc_probe(int fir_base
, int sir_base
)
459 int low
, high
, chip
, config
, dma
, irq
;
460 int iobase
= fir_base
;
463 IRDA_DEBUG(0, __FUNCTION__
"\n");
465 register_bank(iobase
, 3);
466 high
= inb(iobase
+IRCC_ID_HIGH
);
467 low
= inb(iobase
+IRCC_ID_LOW
);
468 chip
= inb(iobase
+IRCC_CHIP_ID
);
469 version
= inb(iobase
+IRCC_VERSION
);
470 config
= inb(iobase
+IRCC_INTERFACE
);
471 irq
= config
>> 4 & 0x0f;
474 if (high
== 0x10 && low
== 0xb8 && (chip
== 0xf1 || chip
== 0xf2)) {
475 MESSAGE("SMC IrDA Controller found; IrCC version %d.%d, "
476 "port 0x%03x, dma=%d, irq=%d\n",
477 chip
& 0x0f, version
, iobase
, dma
, irq
);
481 /* Power on device */
482 outb(0x00, iobase
+IRCC_MASTER
);
488 * Function ircc_change_speed (self, baud)
490 * Change the speed of the device
493 static void ircc_change_speed(void *priv
, __u32 speed
)
495 int iobase
, ir_mode
, ctrl
, fast
;
496 struct ircc_cb
*self
= (struct ircc_cb
*) priv
;
497 struct net_device
*dev
;
499 IRDA_DEBUG(0, __FUNCTION__
"\n");
501 ASSERT(self
!= NULL
, return;);
504 iobase
= self
->io
.fir_base
;
506 /* Update accounting for new speed */
507 self
->io
.speed
= speed
;
509 outb(IRCC_MASTER_RESET
, iobase
+IRCC_MASTER
);
510 outb(0x00, iobase
+IRCC_MASTER
);
514 IRDA_DEBUG(0, __FUNCTION__
"(), unknown baud rate of %d\n",
522 ir_mode
= IRCC_CFGA_IRDA_SIR_A
;
527 ir_mode
= IRCC_CFGA_IRDA_HDLC
;
530 IRDA_DEBUG(0, __FUNCTION__
"(), handling baud of 576000\n");
533 ir_mode
= IRCC_CFGA_IRDA_HDLC
;
534 ctrl
= IRCC_1152
| IRCC_CRC
;
536 IRDA_DEBUG(0, __FUNCTION__
"(), handling baud of 1152000\n");
539 ir_mode
= IRCC_CFGA_IRDA_4PPM
;
541 fast
= IRCC_LCR_A_FAST
;
542 IRDA_DEBUG(0, __FUNCTION__
"(), handling baud of 4000000\n");
546 register_bank(iobase
, 0);
547 outb(0, iobase
+IRCC_IER
);
548 outb(IRCC_MASTER_INT_EN
, iobase
+IRCC_MASTER
);
550 /* Make special FIR init if necessary */
551 if (speed
> 115200) {
552 irport_stop(self
->irport
);
554 /* Install FIR transmit handler */
555 dev
->hard_start_xmit
= &ircc_hard_xmit
;
558 * Don't know why we have to do this, but FIR interrupts
559 * stops working if we remove it.
561 /* outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR); */
563 /* Be ready for incomming frames */
564 ircc_dma_receive(self
, iobase
);
566 /* Install SIR transmit handler */
567 dev
->hard_start_xmit
= &irport_hard_xmit
;
568 irport_start(self
->irport
);
570 IRDA_DEBUG(0, __FUNCTION__
571 "(), using irport to change speed to %d\n", speed
);
572 irport_change_speed(self
->irport
, speed
);
575 register_bank(iobase
, 1);
576 outb(((inb(iobase
+IRCC_SCE_CFGA
) & 0x87) | ir_mode
),
577 iobase
+IRCC_SCE_CFGA
);
579 #ifdef SMC_669 /* Uses pin 88/89 for Rx/Tx */
580 outb(((inb(iobase
+IRCC_SCE_CFGB
) & 0x3f) | IRCC_CFGB_MUX_COM
),
581 iobase
+IRCC_SCE_CFGB
);
583 outb(((inb(iobase
+IRCC_SCE_CFGB
) & 0x3f) | IRCC_CFGB_MUX_IR
),
584 iobase
+IRCC_SCE_CFGB
);
586 (void) inb(iobase
+IRCC_FIFO_THRESHOLD
);
587 outb(64, iobase
+IRCC_FIFO_THRESHOLD
);
589 register_bank(iobase
, 4);
590 outb((inb(iobase
+IRCC_CONTROL
) & 0x30) | ctrl
, iobase
+IRCC_CONTROL
);
592 register_bank(iobase
, 0);
593 outb(fast
, iobase
+IRCC_LCR_A
);
595 netif_start_queue(dev
);
599 * Function ircc_hard_xmit (skb, dev)
601 * Transmit the frame!
604 static int ircc_hard_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
606 struct irport_cb
*irport
;
607 struct ircc_cb
*self
;
613 irport
= (struct irport_cb
*) dev
->priv
;
614 self
= (struct ircc_cb
*) irport
->priv
;
615 ASSERT(self
!= NULL
, return 0;);
617 iobase
= self
->io
.fir_base
;
619 netif_stop_queue(dev
);
621 /* Check if we need to change the speed after this frame */
622 if ((speed
= irda_get_speed(skb
)) != self
->io
.speed
) {
623 /* Check for empty frame */
625 ircc_change_speed(self
, speed
);
628 self
->new_speed
= speed
;
631 spin_lock_irqsave(&self
->lock
, flags
);
633 memcpy(self
->tx_buff
.head
, skb
->data
, skb
->len
);
635 self
->tx_buff
.len
= skb
->len
;
636 self
->tx_buff
.data
= self
->tx_buff
.head
;
638 mtt
= irda_get_mtt(skb
);
643 * Compute how many BOFs (STA or PA's) we need to waste the
644 * min turn time given the speed of the link.
646 bofs
= mtt
* (self
->io
.speed
/ 1000) / 8000;
650 ircc_dma_xmit(self
, iobase
, bofs
);
653 ircc_dma_xmit(self
, iobase
, 0);
655 spin_unlock_irqrestore(&self
->lock
, flags
);
662 * Function ircc_dma_xmit (self, iobase)
664 * Transmit data using DMA
667 static void ircc_dma_xmit(struct ircc_cb
*self
, int iobase
, int bofs
)
671 IRDA_DEBUG(2, __FUNCTION__
"\n");
674 register_bank(iobase
, 0);
675 outb(0x00, iobase
+IRCC_LCR_B
);
677 register_bank(iobase
, 1);
678 outb(inb(iobase
+IRCC_SCE_CFGB
) & ~IRCC_CFGB_DMA_ENABLE
,
679 iobase
+IRCC_SCE_CFGB
);
681 self
->io
.direction
= IO_XMIT
;
683 /* Set BOF additional count for generating the min turn time */
684 register_bank(iobase
, 4);
685 outb(bofs
& 0xff, iobase
+IRCC_BOF_COUNT_LO
);
686 ctrl
= inb(iobase
+IRCC_CONTROL
) & 0xf0;
687 outb(ctrl
| ((bofs
>> 8) & 0x0f), iobase
+IRCC_BOF_COUNT_HI
);
689 /* Set max Tx frame size */
690 outb(self
->tx_buff
.len
>> 8, iobase
+IRCC_TX_SIZE_HI
);
691 outb(self
->tx_buff
.len
& 0xff, iobase
+IRCC_TX_SIZE_LO
);
693 /* Setup DMA controller (must be done after enabling chip DMA) */
694 setup_dma(self
->io
.dma
, self
->tx_buff
.data
, self
->tx_buff
.len
,
697 outb(UART_MCR_OUT2
, self
->io
.sir_base
+ UART_MCR
);
698 /* Enable burst mode chip Tx DMA */
699 register_bank(iobase
, 1);
700 outb(inb(iobase
+IRCC_SCE_CFGB
) | IRCC_CFGB_DMA_ENABLE
|
701 IRCC_CFGB_DMA_BURST
, iobase
+IRCC_SCE_CFGB
);
703 /* Enable interrupt */
704 outb(IRCC_MASTER_INT_EN
, iobase
+IRCC_MASTER
);
705 register_bank(iobase
, 0);
706 outb(IRCC_IER_ACTIVE_FRAME
| IRCC_IER_EOM
, iobase
+IRCC_IER
);
708 /* Enable transmit */
709 outb(IRCC_LCR_B_SCE_TRANSMIT
|IRCC_LCR_B_SIP_ENABLE
, iobase
+IRCC_LCR_B
);
713 * Function ircc_dma_xmit_complete (self)
715 * The transfer of a frame in finished. This function will only be called
716 * by the interrupt handler
719 static void ircc_dma_xmit_complete(struct ircc_cb
*self
, int iobase
)
721 IRDA_DEBUG(2, __FUNCTION__
"\n");
724 register_bank(iobase
, 0);
725 outb(0x00, iobase
+IRCC_LCR_B
);
727 register_bank(self
->io
.fir_base
, 1);
728 outb(inb(self
->io
.fir_base
+IRCC_SCE_CFGB
) & ~IRCC_CFGB_DMA_ENABLE
,
729 self
->io
.fir_base
+IRCC_SCE_CFGB
);
731 /* Check for underrrun! */
732 register_bank(iobase
, 0);
733 if (inb(iobase
+IRCC_LSR
) & IRCC_LSR_UNDERRUN
) {
734 self
->irport
->stats
.tx_errors
++;
735 self
->irport
->stats
.tx_fifo_errors
++;
737 /* Reset error condition */
738 register_bank(iobase
, 0);
739 outb(IRCC_MASTER_ERROR_RESET
, iobase
+IRCC_MASTER
);
740 outb(0x00, iobase
+IRCC_MASTER
);
742 self
->irport
->stats
.tx_packets
++;
743 self
->irport
->stats
.tx_bytes
+= self
->tx_buff
.len
;
746 /* Check if it's time to change the speed */
747 if (self
->new_speed
) {
748 ircc_change_speed(self
, self
->new_speed
);
752 netif_wake_queue(self
->netdev
);
756 * Function ircc_dma_receive (self)
758 * Get ready for receiving a frame. The device will initiate a DMA
759 * if it starts to receive a frame.
762 static int ircc_dma_receive(struct ircc_cb
*self
, int iobase
)
764 /* Turn off chip DMA */
765 //register_bank(iobase, 1);
766 //outb(inb(iobase+IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
767 // iobase+IRCC_SCE_CFGB);
769 setup_dma(self
->io
.dma
, self
->rx_buff
.data
, self
->rx_buff
.truesize
,
772 /* Set max Rx frame size */
773 register_bank(iobase
, 4);
774 outb((2050 >> 8) & 0x0f, iobase
+IRCC_RX_SIZE_HI
);
775 outb(2050 & 0xff, iobase
+IRCC_RX_SIZE_LO
);
777 self
->io
.direction
= IO_RECV
;
778 self
->rx_buff
.data
= self
->rx_buff
.head
;
780 /* Setup DMA controller */
782 /* Enable receiver */
783 register_bank(iobase
, 0);
784 outb(IRCC_LCR_B_SCE_RECEIVE
| IRCC_LCR_B_SIP_ENABLE
,
787 /* Enable burst mode chip Rx DMA */
788 register_bank(iobase
, 1);
789 outb(inb(iobase
+IRCC_SCE_CFGB
) | IRCC_CFGB_DMA_ENABLE
|
790 IRCC_CFGB_DMA_BURST
, iobase
+IRCC_SCE_CFGB
);
796 * Function ircc_dma_receive_complete (self)
798 * Finished with receiving frames
801 static void ircc_dma_receive_complete(struct ircc_cb
*self
, int iobase
)
806 IRDA_DEBUG(2, __FUNCTION__
"\n");
809 register_bank(iobase
, 0);
810 outb(0x00, iobase
+IRCC_LCR_B
);
812 register_bank(iobase
, 0);
813 msgcnt
= inb(iobase
+IRCC_LCR_B
) & 0x08;
815 IRDA_DEBUG(2, __FUNCTION__
": dma count = %d\n",
816 get_dma_residue(self
->io
.dma
));
818 len
= self
->rx_buff
.truesize
- get_dma_residue(self
->io
.dma
);
821 if (self
->io
.speed
< 4000000)
826 if ((len
< 2) || (len
> 2050)) {
827 WARNING(__FUNCTION__
"(), bogus len=%d\n", len
);
830 IRDA_DEBUG(2, __FUNCTION__
": msgcnt = %d, len=%d\n", msgcnt
, len
);
832 skb
= dev_alloc_skb(len
+1);
834 WARNING(__FUNCTION__
"(), memory squeeze, dropping frame.\n");
837 /* Make sure IP header gets aligned */
840 memcpy(skb_put(skb
, len
), self
->rx_buff
.data
, len
);
841 self
->irport
->stats
.rx_packets
++;
842 self
->irport
->stats
.rx_bytes
+= len
;
844 skb
->dev
= self
->netdev
;
845 skb
->mac
.raw
= skb
->data
;
846 skb
->protocol
= htons(ETH_P_IRDA
);
851 * Function ircc_interrupt (irq, dev_id, regs)
853 * An interrupt from the chip has arrived. Time to do some work
856 static void ircc_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
858 struct net_device
*dev
= (struct net_device
*) dev_id
;
859 struct irport_cb
*irport
;
860 struct ircc_cb
*self
;
864 printk(KERN_WARNING
"%s: irq %d for unknown device.\n",
868 irport
= (struct irport_cb
*) dev
->priv
;
869 ASSERT(irport
!= NULL
, return;);
870 self
= (struct ircc_cb
*) irport
->priv
;
871 ASSERT(self
!= NULL
, return;);
873 /* Check if we should use the SIR interrupt handler */
874 if (self
->io
.speed
< 576000) {
875 irport_interrupt(irq
, dev_id
, regs
);
878 iobase
= self
->io
.fir_base
;
880 spin_lock(&self
->lock
);
882 register_bank(iobase
, 0);
883 iir
= inb(iobase
+IRCC_IIR
);
885 /* Disable interrupts */
886 outb(0, iobase
+IRCC_IER
);
888 IRDA_DEBUG(2, __FUNCTION__
"(), iir = 0x%02x\n", iir
);
890 if (iir
& IRCC_IIR_EOM
) {
891 if (self
->io
.direction
== IO_RECV
)
892 ircc_dma_receive_complete(self
, iobase
);
894 ircc_dma_xmit_complete(self
, iobase
);
896 ircc_dma_receive(self
, iobase
);
899 /* Enable interrupts again */
900 register_bank(iobase
, 0);
901 outb(IRCC_IER_ACTIVE_FRAME
|IRCC_IER_EOM
, iobase
+IRCC_IER
);
903 spin_unlock(&self
->lock
);
908 * Function ircc_is_receiving (self)
910 * Return TRUE is we are currently receiving a frame
913 static int ircc_is_receiving(struct ircc_cb
*self
)
918 IRDA_DEBUG(0, __FUNCTION__
"\n");
920 ASSERT(self
!= NULL
, return FALSE
;);
922 IRDA_DEBUG(0, __FUNCTION__
": dma count = %d\n",
923 get_dma_residue(self
->io
.dma
));
925 status
= (self
->rx_buff
.state
!= OUTSIDE_FRAME
);
932 * Function ircc_net_open (dev)
937 static int ircc_net_open(struct net_device
*dev
)
939 struct irport_cb
*irport
;
940 struct ircc_cb
*self
;
943 IRDA_DEBUG(0, __FUNCTION__
"\n");
945 ASSERT(dev
!= NULL
, return -1;);
946 irport
= (struct irport_cb
*) dev
->priv
;
947 self
= (struct ircc_cb
*) irport
->priv
;
949 ASSERT(self
!= NULL
, return 0;);
951 iobase
= self
->io
.fir_base
;
953 irport_net_open(dev
); /* irport allocates the irq */
956 * Always allocate the DMA channel after the IRQ,
957 * and clean up on failure.
959 if (request_dma(self
->io
.dma
, dev
->name
)) {
960 irport_net_close(dev
);
971 * Function ircc_net_close (dev)
976 static int ircc_net_close(struct net_device
*dev
)
978 struct irport_cb
*irport
;
979 struct ircc_cb
*self
;
982 IRDA_DEBUG(0, __FUNCTION__
"\n");
984 ASSERT(dev
!= NULL
, return -1;);
985 irport
= (struct irport_cb
*) dev
->priv
;
986 self
= (struct ircc_cb
*) irport
->priv
;
988 ASSERT(self
!= NULL
, return 0;);
990 iobase
= self
->io
.fir_base
;
992 irport_net_close(dev
);
994 disable_dma(self
->io
.dma
);
996 free_dma(self
->io
.dma
);
1003 static void ircc_suspend(struct ircc_cb
*self
)
1005 MESSAGE("%s, Suspending\n", driver_name
);
1007 if (self
->io
.suspended
)
1010 ircc_net_close(self
->netdev
);
1012 self
->io
.suspended
= 1;
1015 static void ircc_wakeup(struct ircc_cb
*self
)
1017 unsigned long flags
;
1019 if (!self
->io
.suspended
)
1025 ircc_net_open(self
->netdev
);
1027 restore_flags(flags
);
1028 MESSAGE("%s, Waking up\n", driver_name
);
1031 static int ircc_pmproc(struct pm_dev
*dev
, pm_request_t rqst
, void *data
)
1033 struct ircc_cb
*self
= (struct ircc_cb
*) dev
->data
;
1048 MODULE_AUTHOR("Thomas Davis <tadavis@jps.net>");
1049 MODULE_DESCRIPTION("SMC IrCC controller driver");
1050 MODULE_PARM(ircc_dma
, "1i");
1051 MODULE_PARM_DESC(ircc_dma
, "DMA channel");
1052 MODULE_PARM(ircc_irq
, "1i");
1053 MODULE_PARM_DESC(ircc_irq
, "IRQ line");
1055 int init_module(void)
1060 void cleanup_module(void)