2 * Alchemy Semi Au1000 IrDA driver
4 * Copyright 2001 MontaVista Software Inc.
5 * Author: MontaVista Software, Inc.
6 * ppopov@mvista.com or source@mvista.com
8 * This program is free software; you can distribute it and/or modify it
9 * under the terms of the GNU General Public License (Version 2) as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include <linux/clk.h>
22 #include <linux/module.h>
23 #include <linux/netdevice.h>
24 #include <linux/interrupt.h>
25 #include <linux/platform_device.h>
26 #include <linux/slab.h>
27 #include <linux/types.h>
29 #include <net/irda/irda.h>
30 #include <net/irda/irmod.h>
31 #include <net/irda/wrapper.h>
32 #include <net/irda/irda_device.h>
33 #include <asm/mach-au1x00/au1000.h>
36 #define IR_RING_PTR_STATUS 0x00
37 #define IR_RING_BASE_ADDR_H 0x04
38 #define IR_RING_BASE_ADDR_L 0x08
39 #define IR_RING_SIZE 0x0C
40 #define IR_RING_PROMPT 0x10
41 #define IR_RING_ADDR_CMPR 0x14
42 #define IR_INT_CLEAR 0x18
43 #define IR_CONFIG_1 0x20
44 #define IR_SIR_FLAGS 0x24
45 #define IR_STATUS 0x28
46 #define IR_READ_PHY_CONFIG 0x2C
47 #define IR_WRITE_PHY_CONFIG 0x30
48 #define IR_MAX_PKT_LEN 0x34
49 #define IR_RX_BYTE_CNT 0x38
50 #define IR_CONFIG_2 0x3C
51 #define IR_ENABLE 0x40
54 #define IR_RX_INVERT_LED (1 << 0)
55 #define IR_TX_INVERT_LED (1 << 1)
56 #define IR_ST (1 << 2)
57 #define IR_SF (1 << 3)
58 #define IR_SIR (1 << 4)
59 #define IR_MIR (1 << 5)
60 #define IR_FIR (1 << 6)
61 #define IR_16CRC (1 << 7)
62 #define IR_TD (1 << 8)
63 #define IR_RX_ALL (1 << 9)
64 #define IR_DMA_ENABLE (1 << 10)
65 #define IR_RX_ENABLE (1 << 11)
66 #define IR_TX_ENABLE (1 << 12)
67 #define IR_LOOPBACK (1 << 14)
68 #define IR_SIR_MODE (IR_SIR | IR_DMA_ENABLE | \
69 IR_RX_ALL | IR_RX_ENABLE | IR_SF | \
73 #define IR_RX_STATUS (1 << 9)
74 #define IR_TX_STATUS (1 << 10)
75 #define IR_PHYEN (1 << 15)
77 /* ir_write_phy_config */
78 #define IR_BR(x) (((x) & 0x3f) << 10) /* baud rate */
79 #define IR_PW(x) (((x) & 0x1f) << 5) /* pulse width */
80 #define IR_P(x) ((x) & 0x1f) /* preamble bits */
83 #define IR_MODE_INV (1 << 0)
84 #define IR_ONE_PIN (1 << 1)
85 #define IR_PHYCLK_40MHZ (0 << 2)
86 #define IR_PHYCLK_48MHZ (1 << 2)
87 #define IR_PHYCLK_56MHZ (2 << 2)
88 #define IR_PHYCLK_64MHZ (3 << 2)
89 #define IR_DP (1 << 4)
90 #define IR_DA (1 << 5)
91 #define IR_FLT_HIGH (0 << 6)
92 #define IR_FLT_MEDHI (1 << 6)
93 #define IR_FLT_MEDLO (2 << 6)
94 #define IR_FLT_LO (3 << 6)
95 #define IR_IEN (1 << 8)
98 #define IR_HC (1 << 3) /* divide SBUS clock by 2 */
99 #define IR_CE (1 << 2) /* clock enable */
100 #define IR_C (1 << 1) /* coherency bit */
101 #define IR_BE (1 << 0) /* set in big endian mode */
103 #define NUM_IR_DESC 64
104 #define RING_SIZE_4 0x0
105 #define RING_SIZE_16 0x3
106 #define RING_SIZE_64 0xF
107 #define MAX_NUM_IR_DESC 64
108 #define MAX_BUF_SIZE 2048
110 /* Ring descriptor flags */
111 #define AU_OWN (1 << 7) /* tx,rx */
112 #define IR_DIS_CRC (1 << 6) /* tx */
113 #define IR_BAD_CRC (1 << 5) /* tx */
114 #define IR_NEED_PULSE (1 << 4) /* tx */
115 #define IR_FORCE_UNDER (1 << 3) /* tx */
116 #define IR_DISABLE_TX (1 << 2) /* tx */
117 #define IR_HW_UNDER (1 << 0) /* tx */
118 #define IR_TX_ERROR (IR_DIS_CRC | IR_BAD_CRC | IR_HW_UNDER)
120 #define IR_PHY_ERROR (1 << 6) /* rx */
121 #define IR_CRC_ERROR (1 << 5) /* rx */
122 #define IR_MAX_LEN (1 << 4) /* rx */
123 #define IR_FIFO_OVER (1 << 3) /* rx */
124 #define IR_SIR_ERROR (1 << 2) /* rx */
125 #define IR_RX_ERROR (IR_PHY_ERROR | IR_CRC_ERROR | \
126 IR_MAX_LEN | IR_FIFO_OVER | IR_SIR_ERROR)
129 struct db_dest
*pnext
;
135 u8 count_0
; /* 7:0 */
136 u8 count_1
; /* 12:8 */
140 u8 addr_1
; /* 15:8 */
141 u8 addr_2
; /* 23:16 */
142 u8 addr_3
; /* 31:24 */
145 /* Private data for each instance */
146 struct au1k_private
{
147 void __iomem
*iobase
;
150 struct db_dest
*pDBfree
;
151 struct db_dest db
[2 * NUM_IR_DESC
];
152 volatile struct ring_dest
*rx_ring
[NUM_IR_DESC
];
153 volatile struct ring_dest
*tx_ring
[NUM_IR_DESC
];
154 struct db_dest
*rx_db_inuse
[NUM_IR_DESC
];
155 struct db_dest
*tx_db_inuse
[NUM_IR_DESC
];
163 struct net_device
*netdev
;
165 struct irlap_cb
*irlap
;
171 struct resource
*ioarea
;
172 struct au1k_irda_platform_data
*platdata
;
173 struct clk
*irda_clk
;
176 static int qos_mtt_bits
= 0x07; /* 1 ms or more */
178 static void au1k_irda_plat_set_phy_mode(struct au1k_private
*p
, int mode
)
180 if (p
->platdata
&& p
->platdata
->set_phy_mode
)
181 p
->platdata
->set_phy_mode(mode
);
184 static inline unsigned long irda_read(struct au1k_private
*p
,
188 * IrDA peripheral bug. You have to read the register
189 * twice to get the right value.
191 (void)__raw_readl(p
->iobase
+ ofs
);
192 return __raw_readl(p
->iobase
+ ofs
);
195 static inline void irda_write(struct au1k_private
*p
, unsigned long ofs
,
198 __raw_writel(val
, p
->iobase
+ ofs
);
203 * Buffer allocation/deallocation routines. The buffer descriptor returned
204 * has the virtual and dma address of a buffer suitable for
205 * both, receive and transmit operations.
207 static struct db_dest
*GetFreeDB(struct au1k_private
*aup
)
213 aup
->pDBfree
= db
->pnext
;
218 DMA memory allocation, derived from pci_alloc_consistent.
219 However, the Au1000 data cache is coherent (when programmed
220 so), therefore we return KSEG0 address, not KSEG1.
222 static void *dma_alloc(size_t size
, dma_addr_t
*dma_handle
)
225 int gfp
= GFP_ATOMIC
| GFP_DMA
;
227 ret
= (void *)__get_free_pages(gfp
, get_order(size
));
230 memset(ret
, 0, size
);
231 *dma_handle
= virt_to_bus(ret
);
232 ret
= (void *)KSEG0ADDR(ret
);
237 static void dma_free(void *vaddr
, size_t size
)
239 vaddr
= (void *)KSEG0ADDR(vaddr
);
240 free_pages((unsigned long) vaddr
, get_order(size
));
244 static void setup_hw_rings(struct au1k_private
*aup
, u32 rx_base
, u32 tx_base
)
247 for (i
= 0; i
< NUM_IR_DESC
; i
++) {
248 aup
->rx_ring
[i
] = (volatile struct ring_dest
*)
249 (rx_base
+ sizeof(struct ring_dest
) * i
);
251 for (i
= 0; i
< NUM_IR_DESC
; i
++) {
252 aup
->tx_ring
[i
] = (volatile struct ring_dest
*)
253 (tx_base
+ sizeof(struct ring_dest
) * i
);
257 static int au1k_irda_init_iobuf(iobuff_t
*io
, int size
)
259 io
->head
= kmalloc(size
, GFP_KERNEL
);
260 if (io
->head
!= NULL
) {
262 io
->in_frame
= FALSE
;
263 io
->state
= OUTSIDE_FRAME
;
266 return io
->head
? 0 : -ENOMEM
;
270 * Set the IrDA communications speed.
272 static int au1k_irda_set_speed(struct net_device
*dev
, int speed
)
274 struct au1k_private
*aup
= netdev_priv(dev
);
275 volatile struct ring_dest
*ptxd
;
276 unsigned long control
;
277 int ret
= 0, timeout
= 10, i
;
279 if (speed
== aup
->speed
)
282 /* disable PHY first */
283 au1k_irda_plat_set_phy_mode(aup
, AU1000_IRDA_PHY_MODE_OFF
);
284 irda_write(aup
, IR_STATUS
, irda_read(aup
, IR_STATUS
) & ~IR_PHYEN
);
287 irda_write(aup
, IR_CONFIG_1
,
288 irda_read(aup
, IR_CONFIG_1
) & ~(IR_RX_ENABLE
| IR_TX_ENABLE
));
290 while (irda_read(aup
, IR_STATUS
) & (IR_RX_STATUS
| IR_TX_STATUS
)) {
293 printk(KERN_ERR
"%s: rx/tx disable timeout\n",
300 irda_write(aup
, IR_CONFIG_1
,
301 irda_read(aup
, IR_CONFIG_1
) & ~IR_DMA_ENABLE
);
304 /* After we disable tx/rx. the index pointers go back to zero. */
305 aup
->tx_head
= aup
->tx_tail
= aup
->rx_head
= 0;
306 for (i
= 0; i
< NUM_IR_DESC
; i
++) {
307 ptxd
= aup
->tx_ring
[i
];
313 for (i
= 0; i
< NUM_IR_DESC
; i
++) {
314 ptxd
= aup
->rx_ring
[i
];
317 ptxd
->flags
= AU_OWN
;
320 if (speed
== 4000000)
321 au1k_irda_plat_set_phy_mode(aup
, AU1000_IRDA_PHY_MODE_FIR
);
323 au1k_irda_plat_set_phy_mode(aup
, AU1000_IRDA_PHY_MODE_SIR
);
327 irda_write(aup
, IR_WRITE_PHY_CONFIG
, IR_BR(11) | IR_PW(12));
328 irda_write(aup
, IR_CONFIG_1
, IR_SIR_MODE
);
331 irda_write(aup
, IR_WRITE_PHY_CONFIG
, IR_BR(5) | IR_PW(12));
332 irda_write(aup
, IR_CONFIG_1
, IR_SIR_MODE
);
335 irda_write(aup
, IR_WRITE_PHY_CONFIG
, IR_BR(2) | IR_PW(12));
336 irda_write(aup
, IR_CONFIG_1
, IR_SIR_MODE
);
339 irda_write(aup
, IR_WRITE_PHY_CONFIG
, IR_BR(1) | IR_PW(12));
340 irda_write(aup
, IR_CONFIG_1
, IR_SIR_MODE
);
343 irda_write(aup
, IR_WRITE_PHY_CONFIG
, IR_PW(12));
344 irda_write(aup
, IR_CONFIG_1
, IR_SIR_MODE
);
347 irda_write(aup
, IR_WRITE_PHY_CONFIG
, IR_P(15));
348 irda_write(aup
, IR_CONFIG_1
, IR_FIR
| IR_DMA_ENABLE
|
352 printk(KERN_ERR
"%s unsupported speed %x\n", dev
->name
, speed
);
358 irda_write(aup
, IR_STATUS
, irda_read(aup
, IR_STATUS
) | IR_PHYEN
);
360 control
= irda_read(aup
, IR_STATUS
);
361 irda_write(aup
, IR_RING_PROMPT
, 0);
363 if (control
& (1 << 14)) {
364 printk(KERN_ERR
"%s: configuration error\n", dev
->name
);
366 if (control
& (1 << 11))
367 printk(KERN_DEBUG
"%s Valid SIR config\n", dev
->name
);
368 if (control
& (1 << 12))
369 printk(KERN_DEBUG
"%s Valid MIR config\n", dev
->name
);
370 if (control
& (1 << 13))
371 printk(KERN_DEBUG
"%s Valid FIR config\n", dev
->name
);
372 if (control
& (1 << 10))
373 printk(KERN_DEBUG
"%s TX enabled\n", dev
->name
);
374 if (control
& (1 << 9))
375 printk(KERN_DEBUG
"%s RX enabled\n", dev
->name
);
381 static void update_rx_stats(struct net_device
*dev
, u32 status
, u32 count
)
383 struct net_device_stats
*ps
= &dev
->stats
;
387 if (status
& IR_RX_ERROR
) {
389 if (status
& (IR_PHY_ERROR
| IR_FIFO_OVER
))
390 ps
->rx_missed_errors
++;
391 if (status
& IR_MAX_LEN
)
392 ps
->rx_length_errors
++;
393 if (status
& IR_CRC_ERROR
)
396 ps
->rx_bytes
+= count
;
399 static void update_tx_stats(struct net_device
*dev
, u32 status
, u32 pkt_len
)
401 struct net_device_stats
*ps
= &dev
->stats
;
404 ps
->tx_bytes
+= pkt_len
;
406 if (status
& IR_TX_ERROR
) {
408 ps
->tx_aborted_errors
++;
412 static void au1k_tx_ack(struct net_device
*dev
)
414 struct au1k_private
*aup
= netdev_priv(dev
);
415 volatile struct ring_dest
*ptxd
;
417 ptxd
= aup
->tx_ring
[aup
->tx_tail
];
418 while (!(ptxd
->flags
& AU_OWN
) && (aup
->tx_tail
!= aup
->tx_head
)) {
419 update_tx_stats(dev
, ptxd
->flags
,
420 (ptxd
->count_1
<< 8) | ptxd
->count_0
);
424 aup
->tx_tail
= (aup
->tx_tail
+ 1) & (NUM_IR_DESC
- 1);
425 ptxd
= aup
->tx_ring
[aup
->tx_tail
];
429 netif_wake_queue(dev
);
433 if (aup
->tx_tail
== aup
->tx_head
) {
435 au1k_irda_set_speed(dev
, aup
->newspeed
);
438 irda_write(aup
, IR_CONFIG_1
,
439 irda_read(aup
, IR_CONFIG_1
) & ~IR_TX_ENABLE
);
440 irda_write(aup
, IR_CONFIG_1
,
441 irda_read(aup
, IR_CONFIG_1
) | IR_RX_ENABLE
);
442 irda_write(aup
, IR_RING_PROMPT
, 0);
447 static int au1k_irda_rx(struct net_device
*dev
)
449 struct au1k_private
*aup
= netdev_priv(dev
);
450 volatile struct ring_dest
*prxd
;
455 prxd
= aup
->rx_ring
[aup
->rx_head
];
458 while (!(flags
& AU_OWN
)) {
459 pDB
= aup
->rx_db_inuse
[aup
->rx_head
];
460 count
= (prxd
->count_1
<< 8) | prxd
->count_0
;
461 if (!(flags
& IR_RX_ERROR
)) {
463 update_rx_stats(dev
, flags
, count
);
464 skb
= alloc_skb(count
+ 1, GFP_ATOMIC
);
466 dev
->stats
.rx_dropped
++;
470 if (aup
->speed
== 4000000)
473 skb_put(skb
, count
- 2);
474 skb_copy_to_linear_data(skb
, (void *)pDB
->vaddr
,
477 skb_reset_mac_header(skb
);
478 skb
->protocol
= htons(ETH_P_IRDA
);
483 prxd
->flags
|= AU_OWN
;
484 aup
->rx_head
= (aup
->rx_head
+ 1) & (NUM_IR_DESC
- 1);
485 irda_write(aup
, IR_RING_PROMPT
, 0);
487 /* next descriptor */
488 prxd
= aup
->rx_ring
[aup
->rx_head
];
495 static irqreturn_t
au1k_irda_interrupt(int dummy
, void *dev_id
)
497 struct net_device
*dev
= dev_id
;
498 struct au1k_private
*aup
= netdev_priv(dev
);
500 irda_write(aup
, IR_INT_CLEAR
, 0); /* ack irda interrupts */
508 static int au1k_init(struct net_device
*dev
)
510 struct au1k_private
*aup
= netdev_priv(dev
);
511 u32 enable
, ring_address
, phyck
;
515 c
= clk_get(NULL
, "irda_clk");
518 i
= clk_prepare_enable(c
);
524 switch (clk_get_rate(c
)) {
526 phyck
= IR_PHYCLK_40MHZ
;
529 phyck
= IR_PHYCLK_48MHZ
;
532 phyck
= IR_PHYCLK_56MHZ
;
535 phyck
= IR_PHYCLK_64MHZ
;
538 clk_disable_unprepare(c
);
544 enable
= IR_HC
| IR_CE
| IR_C
;
545 #ifndef CONFIG_CPU_LITTLE_ENDIAN
552 for (i
= 0; i
< NUM_IR_DESC
; i
++)
553 aup
->rx_ring
[i
]->flags
= AU_OWN
;
555 irda_write(aup
, IR_ENABLE
, enable
);
559 au1k_irda_plat_set_phy_mode(aup
, AU1000_IRDA_PHY_MODE_OFF
);
560 irda_write(aup
, IR_STATUS
, irda_read(aup
, IR_STATUS
) & ~IR_PHYEN
);
563 irda_write(aup
, IR_MAX_PKT_LEN
, MAX_BUF_SIZE
);
565 ring_address
= (u32
)virt_to_phys((void *)aup
->rx_ring
[0]);
566 irda_write(aup
, IR_RING_BASE_ADDR_H
, ring_address
>> 26);
567 irda_write(aup
, IR_RING_BASE_ADDR_L
, (ring_address
>> 10) & 0xffff);
569 irda_write(aup
, IR_RING_SIZE
,
570 (RING_SIZE_64
<< 8) | (RING_SIZE_64
<< 12));
572 irda_write(aup
, IR_CONFIG_2
, phyck
| IR_ONE_PIN
);
573 irda_write(aup
, IR_RING_ADDR_CMPR
, 0);
575 au1k_irda_set_speed(dev
, 9600);
579 static int au1k_irda_start(struct net_device
*dev
)
581 struct au1k_private
*aup
= netdev_priv(dev
);
585 retval
= au1k_init(dev
);
587 printk(KERN_ERR
"%s: error in au1k_init\n", dev
->name
);
591 retval
= request_irq(aup
->irq_tx
, &au1k_irda_interrupt
, 0,
594 printk(KERN_ERR
"%s: unable to get IRQ %d\n",
595 dev
->name
, dev
->irq
);
598 retval
= request_irq(aup
->irq_rx
, &au1k_irda_interrupt
, 0,
601 free_irq(aup
->irq_tx
, dev
);
602 printk(KERN_ERR
"%s: unable to get IRQ %d\n",
603 dev
->name
, dev
->irq
);
607 /* Give self a hardware name */
608 sprintf(hwname
, "Au1000 SIR/FIR");
609 aup
->irlap
= irlap_open(dev
, &aup
->qos
, hwname
);
610 netif_start_queue(dev
);
613 irda_write(aup
, IR_CONFIG_2
, irda_read(aup
, IR_CONFIG_2
) | IR_IEN
);
616 au1k_irda_plat_set_phy_mode(aup
, AU1000_IRDA_PHY_MODE_SIR
);
621 static int au1k_irda_stop(struct net_device
*dev
)
623 struct au1k_private
*aup
= netdev_priv(dev
);
625 au1k_irda_plat_set_phy_mode(aup
, AU1000_IRDA_PHY_MODE_OFF
);
627 /* disable interrupts */
628 irda_write(aup
, IR_CONFIG_2
, irda_read(aup
, IR_CONFIG_2
) & ~IR_IEN
);
629 irda_write(aup
, IR_CONFIG_1
, 0);
630 irda_write(aup
, IR_ENABLE
, 0); /* disable clock */
633 irlap_close(aup
->irlap
);
637 netif_stop_queue(dev
);
639 /* disable the interrupt */
640 free_irq(aup
->irq_tx
, dev
);
641 free_irq(aup
->irq_rx
, dev
);
643 clk_disable_unprepare(aup
->irda_clk
);
644 clk_put(aup
->irda_clk
);
650 * Au1000 transmit routine.
652 static int au1k_irda_hard_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
654 struct au1k_private
*aup
= netdev_priv(dev
);
655 int speed
= irda_get_next_speed(skb
);
656 volatile struct ring_dest
*ptxd
;
660 if (speed
!= aup
->speed
&& speed
!= -1)
661 aup
->newspeed
= speed
;
663 if ((skb
->len
== 0) && (aup
->newspeed
)) {
664 if (aup
->tx_tail
== aup
->tx_head
) {
665 au1k_irda_set_speed(dev
, speed
);
672 ptxd
= aup
->tx_ring
[aup
->tx_head
];
675 if (flags
& AU_OWN
) {
676 printk(KERN_DEBUG
"%s: tx_full\n", dev
->name
);
677 netif_stop_queue(dev
);
680 } else if (((aup
->tx_head
+ 1) & (NUM_IR_DESC
- 1)) == aup
->tx_tail
) {
681 printk(KERN_DEBUG
"%s: tx_full\n", dev
->name
);
682 netif_stop_queue(dev
);
687 pDB
= aup
->tx_db_inuse
[aup
->tx_head
];
690 if (irda_read(aup
, IR_RX_BYTE_CNT
) != 0) {
691 printk(KERN_DEBUG
"tx warning: rx byte cnt %x\n",
692 irda_read(aup
, IR_RX_BYTE_CNT
));
696 if (aup
->speed
== 4000000) {
698 skb_copy_from_linear_data(skb
, (void *)pDB
->vaddr
, skb
->len
);
699 ptxd
->count_0
= skb
->len
& 0xff;
700 ptxd
->count_1
= (skb
->len
>> 8) & 0xff;
703 len
= async_wrap_skb(skb
, (u8
*)pDB
->vaddr
, MAX_BUF_SIZE
);
704 ptxd
->count_0
= len
& 0xff;
705 ptxd
->count_1
= (len
>> 8) & 0xff;
706 ptxd
->flags
|= IR_DIS_CRC
;
708 ptxd
->flags
|= AU_OWN
;
711 irda_write(aup
, IR_CONFIG_1
,
712 irda_read(aup
, IR_CONFIG_1
) | IR_TX_ENABLE
);
713 irda_write(aup
, IR_RING_PROMPT
, 0);
716 aup
->tx_head
= (aup
->tx_head
+ 1) & (NUM_IR_DESC
- 1);
721 * The Tx ring has been full longer than the watchdog timeout
722 * value. The transmitter must be hung?
724 static void au1k_tx_timeout(struct net_device
*dev
)
727 struct au1k_private
*aup
= netdev_priv(dev
);
729 printk(KERN_ERR
"%s: tx timeout\n", dev
->name
);
732 au1k_irda_set_speed(dev
, speed
);
734 netif_wake_queue(dev
);
737 static int au1k_irda_ioctl(struct net_device
*dev
, struct ifreq
*ifreq
, int cmd
)
739 struct if_irda_req
*rq
= (struct if_irda_req
*)ifreq
;
740 struct au1k_private
*aup
= netdev_priv(dev
);
741 int ret
= -EOPNOTSUPP
;
745 if (capable(CAP_NET_ADMIN
)) {
747 * We are unable to set the speed if the
748 * device is not running.
751 ret
= au1k_irda_set_speed(dev
,
754 printk(KERN_ERR
"%s ioctl: !netif_running\n",
763 if (capable(CAP_NET_ADMIN
)) {
764 irda_device_set_media_busy(dev
, TRUE
);
770 rq
->ifr_receiving
= 0;
778 static const struct net_device_ops au1k_irda_netdev_ops
= {
779 .ndo_open
= au1k_irda_start
,
780 .ndo_stop
= au1k_irda_stop
,
781 .ndo_start_xmit
= au1k_irda_hard_xmit
,
782 .ndo_tx_timeout
= au1k_tx_timeout
,
783 .ndo_do_ioctl
= au1k_irda_ioctl
,
786 static int au1k_irda_net_init(struct net_device
*dev
)
788 struct au1k_private
*aup
= netdev_priv(dev
);
789 struct db_dest
*pDB
, *pDBfree
;
790 int i
, err
, retval
= 0;
793 err
= au1k_irda_init_iobuf(&aup
->rx_buff
, 14384);
797 dev
->netdev_ops
= &au1k_irda_netdev_ops
;
799 irda_init_max_qos_capabilies(&aup
->qos
);
801 /* The only value we must override it the baudrate */
802 aup
->qos
.baud_rate
.bits
= IR_9600
| IR_19200
| IR_38400
|
803 IR_57600
| IR_115200
| IR_576000
| (IR_4000000
<< 8);
805 aup
->qos
.min_turn_time
.bits
= qos_mtt_bits
;
806 irda_qos_bits_to_value(&aup
->qos
);
810 /* Tx ring follows rx ring + 512 bytes */
811 /* we need a 1k aligned buffer */
812 aup
->rx_ring
[0] = (struct ring_dest
*)
813 dma_alloc(2 * MAX_NUM_IR_DESC
* (sizeof(struct ring_dest
)),
815 if (!aup
->rx_ring
[0])
818 /* allocate the data buffers */
820 dma_alloc(MAX_BUF_SIZE
* 2 * NUM_IR_DESC
, &temp
);
821 if (!aup
->db
[0].vaddr
)
824 setup_hw_rings(aup
, (u32
)aup
->rx_ring
[0], (u32
)aup
->rx_ring
[0] + 512);
828 for (i
= 0; i
< (2 * NUM_IR_DESC
); i
++) {
829 pDB
->pnext
= pDBfree
;
832 (u32
*)((unsigned)aup
->db
[0].vaddr
+ (MAX_BUF_SIZE
* i
));
833 pDB
->dma_addr
= (dma_addr_t
)virt_to_bus(pDB
->vaddr
);
836 aup
->pDBfree
= pDBfree
;
838 /* attach a data buffer to each descriptor */
839 for (i
= 0; i
< NUM_IR_DESC
; i
++) {
840 pDB
= GetFreeDB(aup
);
843 aup
->rx_ring
[i
]->addr_0
= (u8
)(pDB
->dma_addr
& 0xff);
844 aup
->rx_ring
[i
]->addr_1
= (u8
)((pDB
->dma_addr
>> 8) & 0xff);
845 aup
->rx_ring
[i
]->addr_2
= (u8
)((pDB
->dma_addr
>> 16) & 0xff);
846 aup
->rx_ring
[i
]->addr_3
= (u8
)((pDB
->dma_addr
>> 24) & 0xff);
847 aup
->rx_db_inuse
[i
] = pDB
;
849 for (i
= 0; i
< NUM_IR_DESC
; i
++) {
850 pDB
= GetFreeDB(aup
);
853 aup
->tx_ring
[i
]->addr_0
= (u8
)(pDB
->dma_addr
& 0xff);
854 aup
->tx_ring
[i
]->addr_1
= (u8
)((pDB
->dma_addr
>> 8) & 0xff);
855 aup
->tx_ring
[i
]->addr_2
= (u8
)((pDB
->dma_addr
>> 16) & 0xff);
856 aup
->tx_ring
[i
]->addr_3
= (u8
)((pDB
->dma_addr
>> 24) & 0xff);
857 aup
->tx_ring
[i
]->count_0
= 0;
858 aup
->tx_ring
[i
]->count_1
= 0;
859 aup
->tx_ring
[i
]->flags
= 0;
860 aup
->tx_db_inuse
[i
] = pDB
;
866 dma_free((void *)aup
->rx_ring
[0],
867 2 * MAX_NUM_IR_DESC
* (sizeof(struct ring_dest
)));
869 kfree(aup
->rx_buff
.head
);
871 printk(KERN_ERR
"au1k_irda_net_init() failed. Returns %d\n", retval
);
875 static int au1k_irda_probe(struct platform_device
*pdev
)
877 struct au1k_private
*aup
;
878 struct net_device
*dev
;
883 dev
= alloc_irdadev(sizeof(struct au1k_private
));
887 aup
= netdev_priv(dev
);
889 aup
->platdata
= pdev
->dev
.platform_data
;
892 r
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
896 aup
->irq_tx
= r
->start
;
898 r
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 1);
902 aup
->irq_rx
= r
->start
;
904 r
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
909 aup
->ioarea
= request_mem_region(r
->start
, resource_size(r
),
914 /* bail out early if clock doesn't exist */
915 c
= clk_get(NULL
, "irda_clk");
922 aup
->iobase
= ioremap_nocache(r
->start
, resource_size(r
));
926 dev
->irq
= aup
->irq_rx
;
928 err
= au1k_irda_net_init(dev
);
931 err
= register_netdev(dev
);
935 platform_set_drvdata(pdev
, dev
);
937 printk(KERN_INFO
"IrDA: Registered device %s\n", dev
->name
);
941 dma_free((void *)aup
->db
[0].vaddr
,
942 MAX_BUF_SIZE
* 2 * NUM_IR_DESC
);
943 dma_free((void *)aup
->rx_ring
[0],
944 2 * MAX_NUM_IR_DESC
* (sizeof(struct ring_dest
)));
945 kfree(aup
->rx_buff
.head
);
947 iounmap(aup
->iobase
);
949 release_resource(aup
->ioarea
);
956 static int au1k_irda_remove(struct platform_device
*pdev
)
958 struct net_device
*dev
= platform_get_drvdata(pdev
);
959 struct au1k_private
*aup
= netdev_priv(dev
);
961 unregister_netdev(dev
);
963 dma_free((void *)aup
->db
[0].vaddr
,
964 MAX_BUF_SIZE
* 2 * NUM_IR_DESC
);
965 dma_free((void *)aup
->rx_ring
[0],
966 2 * MAX_NUM_IR_DESC
* (sizeof(struct ring_dest
)));
967 kfree(aup
->rx_buff
.head
);
969 iounmap(aup
->iobase
);
970 release_resource(aup
->ioarea
);
978 static struct platform_driver au1k_irda_driver
= {
980 .name
= "au1000-irda",
982 .probe
= au1k_irda_probe
,
983 .remove
= au1k_irda_remove
,
986 module_platform_driver(au1k_irda_driver
);
988 MODULE_AUTHOR("Pete Popov <ppopov@mvista.com>");
989 MODULE_DESCRIPTION("Au1000 IrDA Device Driver");