42 #include <linux/module.h>
43 #include <linux/kernel.h>
44 #include <linux/types.h>
46 #include <linux/netdevice.h>
51 #include <linux/rtnetlink.h>
57 #include <asm/byteorder.h>
65 #ifdef CONFIG_ARCH_NETWINDER
66 #undef CONFIG_NETWINDER_TX_DMA_PROBLEMS
67 #define CONFIG_NETWINDER_RX_DMA_PROBLEMS
69 #define CONFIG_USE_W977_PNP
70 #define PIO_MAX_SPEED 115200
73 static int qos_mtt_bits = 0x07;
75 #define CHIP_IO_EXTENT 8
77 static unsigned int io[] = { 0x180, ~0, ~0, ~0 };
78 #ifdef CONFIG_ARCH_NETWINDER
79 static unsigned int irq[] = { 6, 0, 0, 0 };
81 static unsigned int irq[] = { 11, 0, 0, 0 };
83 static unsigned int dma[] = { 1, 0, 0, 0 };
90 static int w83977af_open(
int i,
unsigned int iobase,
unsigned int irq,
92 static int w83977af_close(
struct w83977af_ir *
self);
93 static int w83977af_probe(
int iobase,
int irq,
int dma);
94 static int w83977af_dma_receive(
struct w83977af_ir *
self);
95 static int w83977af_dma_receive_complete(
struct w83977af_ir *
self);
101 static int w83977af_is_receiving(
struct w83977af_ir *
self);
113 static int __init w83977af_init(
void)
120 if (w83977af_open(i, io[i], irq[i],
dma[i]) == 0)
132 static void __exit w83977af_cleanup(
void)
140 w83977af_close(dev_self[i]);
145 .ndo_open = w83977af_net_open,
146 .ndo_stop = w83977af_net_close,
147 .ndo_start_xmit = w83977af_hard_xmit,
148 .ndo_do_ioctl = w83977af_net_ioctl,
157 static int w83977af_open(
int i,
unsigned int iobase,
unsigned int irq,
168 IRDA_DEBUG(0,
"%s(), can't get iobase of 0x%03x\n",
173 if (w83977af_probe(iobase, irq, dma) == -1) {
183 "IrDA control block!\n");
188 self = netdev_priv(dev);
193 self->io.fir_base =
iobase;
197 self->io.fifo_size = 32;
209 self->qos.min_turn_time.bits = qos_mtt_bits;
213 self->rx_buff.truesize = 14384;
214 self->tx_buff.truesize = 4000;
220 if (self->rx_buff.head ==
NULL) {
225 memset(self->rx_buff.head, 0, self->rx_buff.truesize);
230 if (self->tx_buff.head ==
NULL) {
234 memset(self->tx_buff.head, 0, self->tx_buff.truesize);
236 self->rx_buff.in_frame =
FALSE;
238 self->tx_buff.data =
self->tx_buff.head;
239 self->rx_buff.data =
self->rx_buff.head;
246 IRDA_ERROR(
"%s(), register_netdevice() failed!\n", __func__);
257 self->tx_buff.head, self->tx_buff_dma);
260 self->rx_buff.head, self->rx_buff_dma);
274 static int w83977af_close(
struct w83977af_ir *
self)
280 iobase =
self->io.fir_base;
282 #ifdef CONFIG_USE_W977_PNP
284 w977_efm_enter(efio);
289 w977_write_reg(0x30, 0x00, efio);
298 IRDA_DEBUG(0 ,
"%s(), Releasing Region %03x\n",
299 __func__ , self->io.fir_base);
302 if (self->tx_buff.head)
304 self->tx_buff.head, self->tx_buff_dma);
306 if (self->rx_buff.head)
308 self->rx_buff.head, self->rx_buff_dma);
315 static int w83977af_probe(
int iobase,
int irq,
int dma)
320 for (i=0; i < 2; i++) {
322 #ifdef CONFIG_USE_W977_PNP
324 w977_efm_enter(efbase[i]);
329 w977_write_reg(0x60, (iobase >> 8) & 0xff, efbase[i]);
330 w977_write_reg(0x61, (iobase) & 0xff, efbase[i]);
332 w977_write_reg(0x70, irq, efbase[i]);
333 #ifdef CONFIG_ARCH_NETWINDER
335 w977_write_reg(0x74, dma+1, efbase[i]);
337 w977_write_reg(0x74, dma, efbase[i]);
339 w977_write_reg(0x75, 0x04, efbase[i]);
345 w977_write_reg(0x30, 0x01, efbase[i]);
347 w977_efm_exit(efbase[i]);
350 switch_bank(iobase,
SET2);
351 outb(iobase+2, 0x00);
354 switch_bank(iobase,
SET0);
358 switch_bank(iobase,
SET2);
362 switch_bank(iobase,
SET0);
366 switch_bank(iobase,
SET3);
370 if (0x10 == (version & 0xf0)) {
374 switch_bank(iobase,
SET2);
378 switch_bank(iobase,
SET0);
383 switch_bank(iobase,
SET4);
384 outb(2048 & 0xff, iobase+6);
385 outb((2048 >> 8) & 0x1f, iobase+7);
399 switch_bank(iobase,
SET7);
400 outb(0x40, iobase+7);
403 "Version: 0x%02x\n", version);
408 IRDA_DEBUG( 0,
"%s(), Wrong chip version", __func__ );
420 iobase =
self->io.fir_base;
423 self->io.speed = speed;
429 switch_bank(iobase,
SET0);
433 switch_bank(iobase,
SET2);
437 case 9600:
outb(0x0c, iobase+
ABLL);
break;
438 case 19200:
outb(0x06, iobase+
ABLL);
break;
439 case 38400:
outb(0x03, iobase+
ABLL);
break;
440 case 57600:
outb(0x02, iobase+
ABLL);
break;
441 case 115200:
outb(0x01, iobase+
ABLL);
break;
444 IRDA_DEBUG(0,
"%s(), handling baud of 576000\n", __func__ );
448 IRDA_DEBUG(0,
"%s(), handling baud of 1152000\n", __func__ );
452 IRDA_DEBUG(0,
"%s(), handling baud of 4000000\n", __func__ );
456 IRDA_DEBUG(0,
"%s(), unknown baud rate of %d\n", __func__ , speed);
461 switch_bank(iobase,
SET0);
465 switch_bank(iobase,
SET2);
469 switch_bank(iobase,
SET0);
474 netif_wake_queue(self->netdev);
477 switch_bank(iobase,
SET0);
480 w83977af_dma_receive(
self);
503 self = netdev_priv(dev);
505 iobase =
self->io.fir_base;
507 IRDA_DEBUG(4,
"%s(%ld), skb->len=%d\n", __func__ , jiffies,
511 netif_stop_queue(dev);
514 speed = irda_get_next_speed(skb);
515 if ((speed != self->io.speed) && (speed != -1)) {
518 w83977af_change_speed(
self, speed);
522 self->new_speed = speed;
530 self->tx_buff.data =
self->tx_buff.head;
531 skb_copy_from_linear_data(skb, self->tx_buff.
data, skb->
len);
532 self->tx_buff.len = skb->
len;
534 mtt = irda_get_mtt(skb);
535 IRDA_DEBUG(4,
"%s(%ld), mtt=%d\n", __func__ , jiffies, mtt);
540 switch_bank(iobase,
SET0);
542 w83977af_dma_write(
self, iobase);
544 self->tx_buff.data =
self->tx_buff.head;
546 self->tx_buff.truesize);
549 switch_bank(iobase,
SET0);
566 static void w83977af_dma_write(
struct w83977af_ir *
self,
int iobase)
569 #ifdef CONFIG_NETWINDER_TX_DMA_PROBLEMS
573 IRDA_DEBUG(4,
"%s(), len=%d\n", __func__ , self->tx_buff.len);
579 switch_bank(iobase,
SET0);
583 switch_bank(iobase,
SET2);
585 #ifdef CONFIG_NETWINDER_TX_DMA_PROBLEMS
589 clear_dma_ff(self->io.dma);
591 set_dma_addr(self->io.dma, self->tx_buff_dma);
594 irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
600 switch_bank(iobase,
SET0);
601 #ifdef CONFIG_NETWINDER_TX_DMA_PROBLEMS
605 spin_unlock_irqrestore(&self->lock, flags);
620 static int w83977af_pio_write(
int iobase,
__u8 *
buf,
int len,
int fifo_size)
630 switch_bank(iobase,
SET0);
633 "%s(), warning, FIFO not empty yet!\n", __func__ );
636 IRDA_DEBUG(4,
"%s(), %d bytes left in tx fifo\n",
637 __func__ , fifo_size);
641 while ((fifo_size-- > 0) && (actual < len)) {
643 outb(buf[actual++], iobase+TBR);
646 IRDA_DEBUG(4,
"%s(), fifo_size %d ; %d sent of %d\n",
647 __func__ , fifo_size, actual, len);
662 static void w83977af_dma_xmit_complete(
struct w83977af_ir *
self)
667 IRDA_DEBUG(4,
"%s(%ld)\n", __func__ , jiffies);
671 iobase =
self->io.fir_base;
677 switch_bank(iobase,
SET0);
682 IRDA_DEBUG(0,
"%s(), Transmit underrun!\n", __func__ );
684 self->netdev->stats.tx_errors++;
685 self->netdev->stats.tx_fifo_errors++;
690 self->netdev->stats.tx_packets++;
693 if (self->new_speed) {
694 w83977af_change_speed(
self, self->new_speed);
700 netif_wake_queue(self->netdev);
713 static int w83977af_dma_receive(
struct w83977af_ir *
self)
717 #ifdef CONFIG_NETWINDER_RX_DMA_PROBLEMS
725 iobase=
self->io.fir_base;
731 switch_bank(iobase,
SET0);
735 switch_bank(iobase,
SET2);
740 self->rx_buff.data =
self->rx_buff.head;
742 #ifdef CONFIG_NETWINDER_RX_DMA_PROBLEMS
746 clear_dma_ff(self->io.dma);
748 set_dma_addr(self->io.dma, self->rx_buff_dma);
751 irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
759 switch_bank(iobase,
SET0);
761 self->st_fifo.len =
self->st_fifo.tail =
self->st_fifo.head = 0;
764 switch_bank(iobase,
SET0);
765 #ifdef CONFIG_NETWINDER_RX_DMA_PROBLEMS
769 spin_unlock_irqrestore(&self->lock, flags);
785 static int w83977af_dma_receive_complete(
struct w83977af_ir *
self)
796 st_fifo = &
self->st_fifo;
798 iobase =
self->io.fir_base;
803 iobase =
self->io.fir_base;
806 switch_bank(iobase,
SET5);
817 while (st_fifo->
len) {
828 self->netdev->stats.rx_errors +=
len;
831 self->netdev->stats.rx_errors++;
833 self->rx_buff.data +=
len;
836 self->netdev->stats.rx_length_errors++;
839 self->netdev->stats.rx_frame_errors++;
842 self->netdev->stats.rx_crc_errors++;
846 self->netdev->stats.rx_fifo_errors++;
849 self->netdev->stats.rx_fifo_errors++;
853 switch_bank(iobase,
SET0);
858 skb = dev_alloc_skb(len+1);
861 "%s(), memory squeeze, dropping frame.\n", __func__);
872 if (self->io.speed < 4000000) {
874 skb_copy_to_linear_data(skb,
879 skb_copy_to_linear_data(skb,
885 self->rx_buff.data +=
len;
886 self->netdev->stats.rx_packets++;
888 skb->
dev =
self->netdev;
889 skb_reset_mac_header(skb);
906 static void w83977af_pio_receive(
struct w83977af_ir *
self)
915 iobase =
self->io.fir_base;
938 IRDA_DEBUG(4,
"%s(), isr=%#x\n", __func__ , isr);
940 iobase =
self->io.fir_base;
944 actual = w83977af_pio_write(self->io.fir_base,
949 self->tx_buff.data += actual;
950 self->tx_buff.len -= actual;
955 if (self->tx_buff.len > 0) {
959 switch_bank(iobase,
SET0);
963 self->netdev->stats.tx_packets++;
966 netif_wake_queue(self->netdev);
973 if (self->new_speed) {
975 "%s(), Changing speed!\n", __func__ );
976 w83977af_change_speed(
self, self->new_speed);
987 w83977af_pio_receive(
self);
1007 iobase =
self->io.fir_base;
1012 if (w83977af_dma_receive_complete(
self)) {
1020 switch_bank(iobase,
SET4);
1033 switch_bank(iobase,
SET4);
1041 if (self->io.direction ==
IO_XMIT) {
1042 w83977af_dma_write(
self, iobase);
1047 w83977af_dma_receive_complete(
self);
1054 w83977af_dma_xmit_complete(
self);
1063 w83977af_dma_receive(
self);
1087 self = netdev_priv(dev);
1089 iobase =
self->io.fir_base;
1093 switch_bank(iobase,
SET0);
1096 isr =
inb(iobase+
ISR) & icr;
1103 icr = w83977af_fir_interrupt(
self, isr);
1105 icr = w83977af_sir_interrupt(
self, isr);
1119 static int w83977af_is_receiving(
struct w83977af_ir *
self)
1127 if (self->io.speed > 115200) {
1128 iobase =
self->io.fir_base;
1132 switch_bank(iobase,
SET2);
1150 static int w83977af_net_open(
struct net_device *dev)
1160 self = netdev_priv(dev);
1164 iobase =
self->io.fir_base;
1183 switch_bank(iobase,
SET0);
1184 if (self->io.speed > 115200) {
1186 w83977af_dma_receive(
self);
1194 netif_start_queue(dev);
1197 sprintf(hwname,
"w83977af @ 0x%03x", self->io.fir_base);
1203 self->irlap =
irlap_open(dev, &self->qos, hwname);
1214 static int w83977af_net_close(
struct net_device *dev)
1224 self = netdev_priv(dev);
1228 iobase =
self->io.fir_base;
1231 netif_stop_queue(dev);
1244 switch_bank(iobase,
SET0);
1266 unsigned long flags;
1271 self = netdev_priv(dev);
1275 IRDA_DEBUG(2,
"%s(), %s, (cmd=0x%X)\n", __func__ , dev->
name, cmd);
1285 w83977af_change_speed(
self, irq->ifr_baudrate);
1295 irq->ifr_receiving = w83977af_is_receiving(
self);
1301 spin_unlock_irqrestore(&self->lock, flags);