23 #include <linux/module.h>
24 #include <linux/netdevice.h>
27 #include <linux/slab.h>
28 #include <linux/time.h>
29 #include <linux/types.h>
38 #define IR_RING_PTR_STATUS 0x00
39 #define IR_RING_BASE_ADDR_H 0x04
40 #define IR_RING_BASE_ADDR_L 0x08
41 #define IR_RING_SIZE 0x0C
42 #define IR_RING_PROMPT 0x10
43 #define IR_RING_ADDR_CMPR 0x14
44 #define IR_INT_CLEAR 0x18
45 #define IR_CONFIG_1 0x20
46 #define IR_SIR_FLAGS 0x24
47 #define IR_STATUS 0x28
48 #define IR_READ_PHY_CONFIG 0x2C
49 #define IR_WRITE_PHY_CONFIG 0x30
50 #define IR_MAX_PKT_LEN 0x34
51 #define IR_RX_BYTE_CNT 0x38
52 #define IR_CONFIG_2 0x3C
53 #define IR_ENABLE 0x40
56 #define IR_RX_INVERT_LED (1 << 0)
57 #define IR_TX_INVERT_LED (1 << 1)
58 #define IR_ST (1 << 2)
59 #define IR_SF (1 << 3)
60 #define IR_SIR (1 << 4)
61 #define IR_MIR (1 << 5)
62 #define IR_FIR (1 << 6)
63 #define IR_16CRC (1 << 7)
64 #define IR_TD (1 << 8)
65 #define IR_RX_ALL (1 << 9)
66 #define IR_DMA_ENABLE (1 << 10)
67 #define IR_RX_ENABLE (1 << 11)
68 #define IR_TX_ENABLE (1 << 12)
69 #define IR_LOOPBACK (1 << 14)
70 #define IR_SIR_MODE (IR_SIR | IR_DMA_ENABLE | \
71 IR_RX_ALL | IR_RX_ENABLE | IR_SF | \
75 #define IR_RX_STATUS (1 << 9)
76 #define IR_TX_STATUS (1 << 10)
77 #define IR_PHYEN (1 << 15)
80 #define IR_BR(x) (((x) & 0x3f) << 10)
81 #define IR_PW(x) (((x) & 0x1f) << 5)
82 #define IR_P(x) ((x) & 0x1f)
85 #define IR_MODE_INV (1 << 0)
86 #define IR_ONE_PIN (1 << 1)
87 #define IR_PHYCLK_40MHZ (0 << 2)
88 #define IR_PHYCLK_48MHZ (1 << 2)
89 #define IR_PHYCLK_56MHZ (2 << 2)
90 #define IR_PHYCLK_64MHZ (3 << 2)
91 #define IR_DP (1 << 4)
92 #define IR_DA (1 << 5)
93 #define IR_FLT_HIGH (0 << 6)
94 #define IR_FLT_MEDHI (1 << 6)
95 #define IR_FLT_MEDLO (2 << 6)
96 #define IR_FLT_LO (3 << 6)
97 #define IR_IEN (1 << 8)
100 #define IR_HC (1 << 3)
101 #define IR_CE (1 << 2)
102 #define IR_C (1 << 1)
103 #define IR_BE (1 << 0)
105 #define NUM_IR_DESC 64
106 #define RING_SIZE_4 0x0
107 #define RING_SIZE_16 0x3
108 #define RING_SIZE_64 0xF
109 #define MAX_NUM_IR_DESC 64
110 #define MAX_BUF_SIZE 2048
113 #define AU_OWN (1 << 7)
114 #define IR_DIS_CRC (1 << 6)
115 #define IR_BAD_CRC (1 << 5)
116 #define IR_NEED_PULSE (1 << 4)
117 #define IR_FORCE_UNDER (1 << 3)
118 #define IR_DISABLE_TX (1 << 2)
119 #define IR_HW_UNDER (1 << 0)
120 #define IR_TX_ERROR (IR_DIS_CRC | IR_BAD_CRC | IR_HW_UNDER)
122 #define IR_PHY_ERROR (1 << 6)
123 #define IR_CRC_ERROR (1 << 5)
124 #define IR_MAX_LEN (1 << 4)
125 #define IR_FIFO_OVER (1 << 3)
126 #define IR_SIR_ERROR (1 << 2)
127 #define IR_RX_ERROR (IR_PHY_ERROR | IR_CRC_ERROR | \
128 IR_MAX_LEN | IR_FIFO_OVER | IR_SIR_ERROR)
181 static int qos_mtt_bits = 0x07;
183 #define RUN_AT(x) (jiffies + (x))
191 static inline unsigned long irda_read(
struct au1k_private *
p,
202 static inline void irda_write(
struct au1k_private *p,
unsigned long ofs,
244 static void dma_free(
void *
vaddr,
size_t size)
264 static int au1k_irda_init_iobuf(
iobuff_t *
io,
int size)
279 static int au1k_irda_set_speed(
struct net_device *
dev,
int speed)
286 if (speed == aup->
speed)
327 if (speed == 4000000)
370 if (control & (1 << 14)) {
373 if (control & (1 << 11))
375 if (control & (1 << 12))
377 if (control & (1 << 13))
379 if (control & (1 << 10))
381 if (control & (1 << 9))
419 static void au1k_tx_ack(
struct net_device *dev)
426 update_tx_stats(dev, ptxd->
flags,
436 netif_wake_queue(dev);
442 au1k_irda_set_speed(dev, aup->
newspeed);
454 static int au1k_irda_rx(
struct net_device *dev)
465 while (!(flags &
AU_OWN)) {
468 if (!(flags & IR_RX_ERROR)) {
470 update_rx_stats(dev, flags, count);
473 dev->
stats.rx_dropped++;
477 if (aup->
speed == 4000000)
481 skb_copy_to_linear_data(skb, (
void *)pDB->
vaddr,
484 skb_reset_mac_header(skb);
522 #ifndef CONFIG_CPU_LITTLE_ENDIAN
530 aup->
rx_ring[i]->flags = AU_OWN;
552 au1k_irda_set_speed(dev, 9600);
556 static int au1k_irda_start(
struct net_device *dev)
562 retval = au1k_init(dev);
585 sprintf(hwname,
"Au1000 SIR/FIR");
587 netif_start_queue(dev);
600 static int au1k_irda_stop(
struct net_device *dev)
616 netif_stop_queue(dev);
632 int speed = irda_get_next_speed(skb);
637 if (speed != aup->
speed && speed != -1)
642 au1k_irda_set_speed(dev, speed);
652 if (flags & AU_OWN) {
654 netif_stop_queue(dev);
657 }
else if (((aup->
tx_head + 1) & (NUM_IR_DESC - 1)) == aup->
tx_tail) {
659 netif_stop_queue(dev);
673 if (aup->
speed == 4000000) {
675 skb_copy_from_linear_data(skb, (
void *)pDB->
vaddr, skb->
len);
682 ptxd->
count_1 = (len >> 8) & 0xff;
701 static void au1k_tx_timeout(
struct net_device *dev)
709 au1k_irda_set_speed(dev, speed);
711 netif_wake_queue(dev);
728 ret = au1k_irda_set_speed(dev,
747 rq->ifr_receiving = 0;
756 .ndo_open = au1k_irda_start,
757 .ndo_stop = au1k_irda_stop,
758 .ndo_start_xmit = au1k_irda_hard_xmit,
759 .ndo_tx_timeout = au1k_tx_timeout,
760 .ndo_do_ioctl = au1k_irda_ioctl,
767 int i,
err, retval = 0;
770 err = au1k_irda_init_iobuf(&aup->
rx_buff, 14384);
782 aup->
qos.min_turn_time.bits = qos_mtt_bits;
798 if (!aup->
db[0].vaddr)
806 pDB->
pnext = pDBfree;
817 pDB = GetFreeDB(aup);
827 pDB = GetFreeDB(aup);
843 dma_free((
void *)aup->
rx_ring[0],
848 printk(
KERN_ERR "au1k_irda_net_init() failed. Returns %d\n", retval);
863 aup = netdev_priv(dev);
896 err = au1k_irda_net_init(dev);
903 platform_set_drvdata(pdev, dev);
909 dma_free((
void *)aup->
db[0].vaddr,
911 dma_free((
void *)aup->
rx_ring[0],
926 struct net_device *dev = platform_get_drvdata(pdev);
931 dma_free((
void *)aup->
db[0].vaddr,
933 dma_free((
void *)aup->
rx_ring[0],
948 .name =
"au1000-irda",
951 .probe = au1k_irda_probe,
955 static int __init au1k_irda_load(
void)
960 static void __exit au1k_irda_unload(
void)