2 * linux/drivers/net/irda/pxaficp_ir.c
4 * Based on sa1100_ir.c by Russell King
6 * Changes copyright (C) 2003-2005 MontaVista Software, Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * Infra-red driver (SIR/FIR) for the PXA2xx embedded microprocessor
15 #include <linux/module.h>
16 #include <linux/netdevice.h>
17 #include <linux/platform_device.h>
18 #include <linux/clk.h>
20 #include <net/irda/irda.h>
21 #include <net/irda/irmod.h>
22 #include <net/irda/wrapper.h>
23 #include <net/irda/irda_device.h>
26 #include <mach/irda.h>
27 #include <mach/regs-uart.h>
28 #include <mach/regs-ost.h>
30 #define FICP __REG(0x40800000) /* Start of FICP area */
31 #define ICCR0 __REG(0x40800000) /* ICP Control Register 0 */
32 #define ICCR1 __REG(0x40800004) /* ICP Control Register 1 */
33 #define ICCR2 __REG(0x40800008) /* ICP Control Register 2 */
34 #define ICDR __REG(0x4080000c) /* ICP Data Register */
35 #define ICSR0 __REG(0x40800014) /* ICP Status Register 0 */
36 #define ICSR1 __REG(0x40800018) /* ICP Status Register 1 */
38 #define ICCR0_AME (1 << 7) /* Address match enable */
39 #define ICCR0_TIE (1 << 6) /* Transmit FIFO interrupt enable */
40 #define ICCR0_RIE (1 << 5) /* Recieve FIFO interrupt enable */
41 #define ICCR0_RXE (1 << 4) /* Receive enable */
42 #define ICCR0_TXE (1 << 3) /* Transmit enable */
43 #define ICCR0_TUS (1 << 2) /* Transmit FIFO underrun select */
44 #define ICCR0_LBM (1 << 1) /* Loopback mode */
45 #define ICCR0_ITR (1 << 0) /* IrDA transmission */
47 #define ICCR2_RXP (1 << 3) /* Receive Pin Polarity select */
48 #define ICCR2_TXP (1 << 2) /* Transmit Pin Polarity select */
49 #define ICCR2_TRIG (3 << 0) /* Receive FIFO Trigger threshold */
50 #define ICCR2_TRIG_8 (0 << 0) /* >= 8 bytes */
51 #define ICCR2_TRIG_16 (1 << 0) /* >= 16 bytes */
52 #define ICCR2_TRIG_32 (2 << 0) /* >= 32 bytes */
55 #define ICSR0_EOC (1 << 6) /* DMA End of Descriptor Chain */
57 #define ICSR0_FRE (1 << 5) /* Framing error */
58 #define ICSR0_RFS (1 << 4) /* Receive FIFO service request */
59 #define ICSR0_TFS (1 << 3) /* Transnit FIFO service request */
60 #define ICSR0_RAB (1 << 2) /* Receiver abort */
61 #define ICSR0_TUR (1 << 1) /* Trunsmit FIFO underun */
62 #define ICSR0_EIF (1 << 0) /* End/Error in FIFO */
64 #define ICSR1_ROR (1 << 6) /* Receiver FIFO underrun */
65 #define ICSR1_CRE (1 << 5) /* CRC error */
66 #define ICSR1_EOF (1 << 4) /* End of frame */
67 #define ICSR1_TNF (1 << 3) /* Transmit FIFO not full */
68 #define ICSR1_RNE (1 << 2) /* Receive FIFO not empty */
69 #define ICSR1_TBY (1 << 1) /* Tramsmiter busy flag */
70 #define ICSR1_RSY (1 << 0) /* Recevier synchronized flag */
72 #define IrSR_RXPL_NEG_IS_ZERO (1<<4)
73 #define IrSR_RXPL_POS_IS_ZERO 0x0
74 #define IrSR_TXPL_NEG_IS_ZERO (1<<3)
75 #define IrSR_TXPL_POS_IS_ZERO 0x0
76 #define IrSR_XMODE_PULSE_1_6 (1<<2)
77 #define IrSR_XMODE_PULSE_3_16 0x0
78 #define IrSR_RCVEIR_IR_MODE (1<<1)
79 #define IrSR_RCVEIR_UART_MODE 0x0
80 #define IrSR_XMITIR_IR_MODE (1<<0)
81 #define IrSR_XMITIR_UART_MODE 0x0
83 #define IrSR_IR_RECEIVE_ON (\
84 IrSR_RXPL_NEG_IS_ZERO | \
85 IrSR_TXPL_POS_IS_ZERO | \
86 IrSR_XMODE_PULSE_3_16 | \
87 IrSR_RCVEIR_IR_MODE | \
88 IrSR_XMITIR_UART_MODE)
90 #define IrSR_IR_TRANSMIT_ON (\
91 IrSR_RXPL_NEG_IS_ZERO | \
92 IrSR_TXPL_POS_IS_ZERO | \
93 IrSR_XMODE_PULSE_3_16 | \
94 IrSR_RCVEIR_UART_MODE | \
100 unsigned long last_oscr
;
102 unsigned char *dma_rx_buff
;
103 unsigned char *dma_tx_buff
;
104 dma_addr_t dma_rx_buff_phy
;
105 dma_addr_t dma_tx_buff_phy
;
106 unsigned int dma_tx_buff_len
;
110 struct irlap_cb
*irlap
;
117 struct pxaficp_platform_data
*pdata
;
123 static inline void pxa_irda_disable_clk(struct pxa_irda
*si
)
126 clk_disable(si
->cur_clk
);
130 static inline void pxa_irda_enable_firclk(struct pxa_irda
*si
)
132 si
->cur_clk
= si
->fir_clk
;
133 clk_enable(si
->fir_clk
);
136 static inline void pxa_irda_enable_sirclk(struct pxa_irda
*si
)
138 si
->cur_clk
= si
->sir_clk
;
139 clk_enable(si
->sir_clk
);
143 #define IS_FIR(si) ((si)->speed >= 4000000)
144 #define IRDA_FRAME_SIZE_LIMIT 2047
146 inline static void pxa_irda_fir_dma_rx_start(struct pxa_irda
*si
)
148 DCSR(si
->rxdma
) = DCSR_NODESC
;
149 DSADR(si
->rxdma
) = __PREG(ICDR
);
150 DTADR(si
->rxdma
) = si
->dma_rx_buff_phy
;
151 DCMD(si
->rxdma
) = DCMD_INCTRGADDR
| DCMD_FLOWSRC
| DCMD_WIDTH1
| DCMD_BURST32
| IRDA_FRAME_SIZE_LIMIT
;
152 DCSR(si
->rxdma
) |= DCSR_RUN
;
155 inline static void pxa_irda_fir_dma_tx_start(struct pxa_irda
*si
)
157 DCSR(si
->txdma
) = DCSR_NODESC
;
158 DSADR(si
->txdma
) = si
->dma_tx_buff_phy
;
159 DTADR(si
->txdma
) = __PREG(ICDR
);
160 DCMD(si
->txdma
) = DCMD_INCSRCADDR
| DCMD_FLOWTRG
| DCMD_ENDIRQEN
| DCMD_WIDTH1
| DCMD_BURST32
| si
->dma_tx_buff_len
;
161 DCSR(si
->txdma
) |= DCSR_RUN
;
165 * Set the IrDA communications speed.
167 static int pxa_irda_set_speed(struct pxa_irda
*si
, int speed
)
170 unsigned int divisor
;
173 case 9600: case 19200: case 38400:
174 case 57600: case 115200:
176 /* refer to PXA250/210 Developer's Manual 10-7 */
177 /* BaudRate = 14.7456 MHz / (16*Divisor) */
178 divisor
= 14745600 / (16 * speed
);
180 local_irq_save(flags
);
184 DCSR(si
->rxdma
) &= ~DCSR_RUN
;
187 pxa_irda_disable_clk(si
);
189 /* set board transceiver to SIR mode */
190 si
->pdata
->transceiver_mode(si
->dev
, IR_SIRMODE
);
192 /* enable the STUART clock */
193 pxa_irda_enable_sirclk(si
);
196 /* disable STUART first */
199 /* access DLL & DLH */
201 STDLL
= divisor
& 0xff;
202 STDLH
= divisor
>> 8;
206 STISR
= IrSR_IR_RECEIVE_ON
| IrSR_XMODE_PULSE_1_6
;
207 STIER
= IER_UUE
| IER_RLSE
| IER_RAVIE
| IER_RTIOE
;
209 local_irq_restore(flags
);
213 local_irq_save(flags
);
218 pxa_irda_disable_clk(si
);
220 /* disable FICP first */
223 /* set board transceiver to FIR mode */
224 si
->pdata
->transceiver_mode(si
->dev
, IR_FIRMODE
);
226 /* enable the FICP clock */
227 pxa_irda_enable_firclk(si
);
230 pxa_irda_fir_dma_rx_start(si
);
231 ICCR0
= ICCR0_ITR
| ICCR0_RXE
;
233 local_irq_restore(flags
);
243 /* SIR interrupt service routine. */
244 static irqreturn_t
pxa_irda_sir_irq(int irq
, void *dev_id
)
246 struct net_device
*dev
= dev_id
;
247 struct pxa_irda
*si
= netdev_priv(dev
);
252 switch (iir
& 0x0F) {
253 case 0x06: /* Receiver Line Status */
255 while (lsr
& LSR_FIFOE
) {
257 if (lsr
& (LSR_OE
| LSR_PE
| LSR_FE
| LSR_BI
)) {
258 printk(KERN_DEBUG
"pxa_ir: sir receiving error\n");
259 dev
->stats
.rx_errors
++;
261 dev
->stats
.rx_frame_errors
++;
263 dev
->stats
.rx_fifo_errors
++;
265 dev
->stats
.rx_bytes
++;
266 async_unwrap_char(dev
, &dev
->stats
,
271 si
->last_oscr
= OSCR
;
274 case 0x04: /* Received Data Available */
277 case 0x0C: /* Character Timeout Indication */
279 dev
->stats
.rx_bytes
++;
280 async_unwrap_char(dev
, &dev
->stats
, &si
->rx_buff
, STRBR
);
281 } while (STLSR
& LSR_DR
);
282 si
->last_oscr
= OSCR
;
285 case 0x02: /* Transmit FIFO Data Request */
286 while ((si
->tx_buff
.len
) && (STLSR
& LSR_TDRQ
)) {
287 STTHR
= *si
->tx_buff
.data
++;
288 si
->tx_buff
.len
-= 1;
291 if (si
->tx_buff
.len
== 0) {
292 dev
->stats
.tx_packets
++;
293 dev
->stats
.tx_bytes
+= si
->tx_buff
.data
- si
->tx_buff
.head
;
295 /* We need to ensure that the transmitter has finished. */
296 while ((STLSR
& LSR_TEMT
) == 0)
298 si
->last_oscr
= OSCR
;
301 * Ok, we've finished transmitting. Now enable
302 * the receiver. Sometimes we get a receive IRQ
303 * immediately after a transmit...
306 pxa_irda_set_speed(si
, si
->newspeed
);
309 /* enable IR Receiver, disable IR Transmitter */
310 STISR
= IrSR_IR_RECEIVE_ON
| IrSR_XMODE_PULSE_1_6
;
311 /* enable STUART and receive interrupts */
312 STIER
= IER_UUE
| IER_RLSE
| IER_RAVIE
| IER_RTIOE
;
315 netif_wake_queue(dev
);
323 /* FIR Receive DMA interrupt handler */
324 static void pxa_irda_fir_dma_rx_irq(int channel
, void *data
)
326 int dcsr
= DCSR(channel
);
328 DCSR(channel
) = dcsr
& ~DCSR_RUN
;
330 printk(KERN_DEBUG
"pxa_ir: fir rx dma bus error %#x\n", dcsr
);
333 /* FIR Transmit DMA interrupt handler */
334 static void pxa_irda_fir_dma_tx_irq(int channel
, void *data
)
336 struct net_device
*dev
= data
;
337 struct pxa_irda
*si
= netdev_priv(dev
);
340 dcsr
= DCSR(channel
);
341 DCSR(channel
) = dcsr
& ~DCSR_RUN
;
343 if (dcsr
& DCSR_ENDINTR
) {
344 dev
->stats
.tx_packets
++;
345 dev
->stats
.tx_bytes
+= si
->dma_tx_buff_len
;
347 dev
->stats
.tx_errors
++;
350 while (ICSR1
& ICSR1_TBY
)
352 si
->last_oscr
= OSCR
;
355 * HACK: It looks like the TBY bit is dropped too soon.
356 * Without this delay things break.
361 pxa_irda_set_speed(si
, si
->newspeed
);
367 pxa_irda_fir_dma_rx_start(si
);
368 while ((ICSR1
& ICSR1_RNE
) && i
--)
370 ICCR0
= ICCR0_ITR
| ICCR0_RXE
;
373 printk(KERN_ERR
"pxa_ir: cannot clear Rx FIFO!\n");
375 netif_wake_queue(dev
);
378 /* EIF(Error in FIFO/End in Frame) handler for FIR */
379 static void pxa_irda_fir_irq_eif(struct pxa_irda
*si
, struct net_device
*dev
, int icsr0
)
381 unsigned int len
, stat
, data
;
383 /* Get the current data position. */
384 len
= DTADR(si
->rxdma
) - si
->dma_rx_buff_phy
;
387 /* Read Status, and then Data. */
392 if (stat
& (ICSR1_CRE
| ICSR1_ROR
)) {
393 dev
->stats
.rx_errors
++;
394 if (stat
& ICSR1_CRE
) {
395 printk(KERN_DEBUG
"pxa_ir: fir receive CRC error\n");
396 dev
->stats
.rx_crc_errors
++;
398 if (stat
& ICSR1_ROR
) {
399 printk(KERN_DEBUG
"pxa_ir: fir receive overrun\n");
400 dev
->stats
.rx_over_errors
++;
403 si
->dma_rx_buff
[len
++] = data
;
405 /* If we hit the end of frame, there's no point in continuing. */
406 if (stat
& ICSR1_EOF
)
408 } while (ICSR0
& ICSR0_EIF
);
410 if (stat
& ICSR1_EOF
) {
414 if (icsr0
& ICSR0_FRE
) {
415 printk(KERN_ERR
"pxa_ir: dropping erroneous frame\n");
416 dev
->stats
.rx_dropped
++;
420 skb
= alloc_skb(len
+1,GFP_ATOMIC
);
422 printk(KERN_ERR
"pxa_ir: fir out of memory for receive skb\n");
423 dev
->stats
.rx_dropped
++;
427 /* Align IP header to 20 bytes */
429 skb_copy_to_linear_data(skb
, si
->dma_rx_buff
, len
);
432 /* Feed it to IrLAP */
434 skb_reset_mac_header(skb
);
435 skb
->protocol
= htons(ETH_P_IRDA
);
438 dev
->stats
.rx_packets
++;
439 dev
->stats
.rx_bytes
+= len
;
443 /* FIR interrupt handler */
444 static irqreturn_t
pxa_irda_fir_irq(int irq
, void *dev_id
)
446 struct net_device
*dev
= dev_id
;
447 struct pxa_irda
*si
= netdev_priv(dev
);
451 DCSR(si
->rxdma
) &= ~DCSR_RUN
;
452 si
->last_oscr
= OSCR
;
455 if (icsr0
& (ICSR0_FRE
| ICSR0_RAB
)) {
456 if (icsr0
& ICSR0_FRE
) {
457 printk(KERN_DEBUG
"pxa_ir: fir receive frame error\n");
458 dev
->stats
.rx_frame_errors
++;
460 printk(KERN_DEBUG
"pxa_ir: fir receive abort\n");
461 dev
->stats
.rx_errors
++;
463 ICSR0
= icsr0
& (ICSR0_FRE
| ICSR0_RAB
);
466 if (icsr0
& ICSR0_EIF
) {
467 /* An error in FIFO occured, or there is a end of frame */
468 pxa_irda_fir_irq_eif(si
, dev
, icsr0
);
472 pxa_irda_fir_dma_rx_start(si
);
473 while ((ICSR1
& ICSR1_RNE
) && i
--)
475 ICCR0
= ICCR0_ITR
| ICCR0_RXE
;
478 printk(KERN_ERR
"pxa_ir: cannot clear Rx FIFO!\n");
483 /* hard_xmit interface of irda device */
484 static int pxa_irda_hard_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
486 struct pxa_irda
*si
= netdev_priv(dev
);
487 int speed
= irda_get_next_speed(skb
);
490 * Does this packet contain a request to change the interface
491 * speed? If so, remember it until we complete the transmission
494 if (speed
!= si
->speed
&& speed
!= -1)
495 si
->newspeed
= speed
;
498 * If this is an empty frame, we can bypass a lot.
503 pxa_irda_set_speed(si
, speed
);
509 netif_stop_queue(dev
);
512 si
->tx_buff
.data
= si
->tx_buff
.head
;
513 si
->tx_buff
.len
= async_wrap_skb(skb
, si
->tx_buff
.data
, si
->tx_buff
.truesize
);
515 /* Disable STUART interrupts and switch to transmit mode. */
517 STISR
= IrSR_IR_TRANSMIT_ON
| IrSR_XMODE_PULSE_1_6
;
519 /* enable STUART and transmit interrupts */
520 STIER
= IER_UUE
| IER_TIE
;
522 unsigned long mtt
= irda_get_mtt(skb
);
524 si
->dma_tx_buff_len
= skb
->len
;
525 skb_copy_from_linear_data(skb
, si
->dma_tx_buff
, skb
->len
);
528 while ((unsigned)(OSCR
- si
->last_oscr
)/4 < mtt
)
531 /* stop RX DMA, disable FICP */
532 DCSR(si
->rxdma
) &= ~DCSR_RUN
;
535 pxa_irda_fir_dma_tx_start(si
);
536 ICCR0
= ICCR0_ITR
| ICCR0_TXE
;
540 dev
->trans_start
= jiffies
;
544 static int pxa_irda_ioctl(struct net_device
*dev
, struct ifreq
*ifreq
, int cmd
)
546 struct if_irda_req
*rq
= (struct if_irda_req
*)ifreq
;
547 struct pxa_irda
*si
= netdev_priv(dev
);
553 if (capable(CAP_NET_ADMIN
)) {
555 * We are unable to set the speed if the
556 * device is not running.
558 if (netif_running(dev
)) {
559 ret
= pxa_irda_set_speed(si
,
562 printk(KERN_INFO
"pxa_ir: SIOCSBANDWIDTH: !netif_running\n");
570 if (capable(CAP_NET_ADMIN
)) {
571 irda_device_set_media_busy(dev
, TRUE
);
578 rq
->ifr_receiving
= IS_FIR(si
) ? 0
579 : si
->rx_buff
.state
!= OUTSIDE_FRAME
;
590 static void pxa_irda_startup(struct pxa_irda
*si
)
592 /* Disable STUART interrupts */
594 /* enable STUART interrupt to the processor */
596 /* configure SIR frame format: StartBit - Data 7 ... Data 0 - Stop Bit */
597 STLCR
= LCR_WLS0
| LCR_WLS1
;
598 /* enable FIFO, we use FIFO to improve performance */
599 STFCR
= FCR_TRFIFOE
| FCR_ITL_32
;
603 /* configure FICP ICCR2 */
604 ICCR2
= ICCR2_TXP
| ICCR2_TRIG_32
;
607 DRCMR(17) = si
->rxdma
| DRCMR_MAPVLD
;
608 DRCMR(18) = si
->txdma
| DRCMR_MAPVLD
;
610 /* force SIR reinitialization */
612 pxa_irda_set_speed(si
, 9600);
614 printk(KERN_DEBUG
"pxa_ir: irda startup\n");
617 static void pxa_irda_shutdown(struct pxa_irda
*si
)
621 local_irq_save(flags
);
623 /* disable STUART and interrupt */
625 /* disable STUART SIR mode */
629 DCSR(si
->txdma
) &= ~DCSR_RUN
;
630 DCSR(si
->rxdma
) &= ~DCSR_RUN
;
634 /* disable the STUART or FICP clocks */
635 pxa_irda_disable_clk(si
);
640 local_irq_restore(flags
);
642 /* power off board transceiver */
643 si
->pdata
->transceiver_mode(si
->dev
, IR_OFF
);
645 printk(KERN_DEBUG
"pxa_ir: irda shutdown\n");
648 static int pxa_irda_start(struct net_device
*dev
)
650 struct pxa_irda
*si
= netdev_priv(dev
);
655 err
= request_irq(IRQ_STUART
, pxa_irda_sir_irq
, 0, dev
->name
, dev
);
659 err
= request_irq(IRQ_ICP
, pxa_irda_fir_irq
, 0, dev
->name
, dev
);
664 * The interrupt must remain disabled for now.
666 disable_irq(IRQ_STUART
);
667 disable_irq(IRQ_ICP
);
670 si
->rxdma
= pxa_request_dma("FICP_RX",DMA_PRIO_LOW
, pxa_irda_fir_dma_rx_irq
, dev
);
674 si
->txdma
= pxa_request_dma("FICP_TX",DMA_PRIO_LOW
, pxa_irda_fir_dma_tx_irq
, dev
);
679 si
->dma_rx_buff
= dma_alloc_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
,
680 &si
->dma_rx_buff_phy
, GFP_KERNEL
);
681 if (!si
->dma_rx_buff
)
682 goto err_dma_rx_buff
;
684 si
->dma_tx_buff
= dma_alloc_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
,
685 &si
->dma_tx_buff_phy
, GFP_KERNEL
);
686 if (!si
->dma_tx_buff
)
687 goto err_dma_tx_buff
;
689 /* Setup the serial port for the initial speed. */
690 pxa_irda_startup(si
);
693 * Open a new IrLAP layer instance.
695 si
->irlap
= irlap_open(dev
, &si
->qos
, "pxa");
701 * Now enable the interrupt and start the queue
703 enable_irq(IRQ_STUART
);
705 netif_start_queue(dev
);
707 printk(KERN_DEBUG
"pxa_ir: irda driver opened\n");
712 pxa_irda_shutdown(si
);
713 dma_free_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
, si
->dma_tx_buff
, si
->dma_tx_buff_phy
);
715 dma_free_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
, si
->dma_rx_buff
, si
->dma_rx_buff_phy
);
717 pxa_free_dma(si
->txdma
);
719 pxa_free_dma(si
->rxdma
);
721 free_irq(IRQ_ICP
, dev
);
723 free_irq(IRQ_STUART
, dev
);
729 static int pxa_irda_stop(struct net_device
*dev
)
731 struct pxa_irda
*si
= netdev_priv(dev
);
733 netif_stop_queue(dev
);
735 pxa_irda_shutdown(si
);
739 irlap_close(si
->irlap
);
743 free_irq(IRQ_STUART
, dev
);
744 free_irq(IRQ_ICP
, dev
);
746 pxa_free_dma(si
->rxdma
);
747 pxa_free_dma(si
->txdma
);
750 dma_free_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
, si
->dma_tx_buff
, si
->dma_tx_buff_phy
);
752 dma_free_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
, si
->dma_rx_buff
, si
->dma_rx_buff_phy
);
754 printk(KERN_DEBUG
"pxa_ir: irda driver closed\n");
758 static int pxa_irda_suspend(struct platform_device
*_dev
, pm_message_t state
)
760 struct net_device
*dev
= platform_get_drvdata(_dev
);
763 if (dev
&& netif_running(dev
)) {
764 si
= netdev_priv(dev
);
765 netif_device_detach(dev
);
766 pxa_irda_shutdown(si
);
772 static int pxa_irda_resume(struct platform_device
*_dev
)
774 struct net_device
*dev
= platform_get_drvdata(_dev
);
777 if (dev
&& netif_running(dev
)) {
778 si
= netdev_priv(dev
);
779 pxa_irda_startup(si
);
780 netif_device_attach(dev
);
781 netif_wake_queue(dev
);
788 static int pxa_irda_init_iobuf(iobuff_t
*io
, int size
)
790 io
->head
= kmalloc(size
, GFP_KERNEL
| GFP_DMA
);
791 if (io
->head
!= NULL
) {
793 io
->in_frame
= FALSE
;
794 io
->state
= OUTSIDE_FRAME
;
797 return io
->head
? 0 : -ENOMEM
;
800 static int pxa_irda_probe(struct platform_device
*pdev
)
802 struct net_device
*dev
;
804 unsigned int baudrate_mask
;
807 if (!pdev
->dev
.platform_data
)
810 err
= request_mem_region(__PREG(STUART
), 0x24, "IrDA") ? 0 : -EBUSY
;
814 err
= request_mem_region(__PREG(FICP
), 0x1c, "IrDA") ? 0 : -EBUSY
;
818 dev
= alloc_irdadev(sizeof(struct pxa_irda
));
822 si
= netdev_priv(dev
);
823 si
->dev
= &pdev
->dev
;
824 si
->pdata
= pdev
->dev
.platform_data
;
826 si
->sir_clk
= clk_get(&pdev
->dev
, "UARTCLK");
827 si
->fir_clk
= clk_get(&pdev
->dev
, "FICPCLK");
828 if (IS_ERR(si
->sir_clk
) || IS_ERR(si
->fir_clk
)) {
829 err
= PTR_ERR(IS_ERR(si
->sir_clk
) ? si
->sir_clk
: si
->fir_clk
);
834 * Initialise the SIR buffers
836 err
= pxa_irda_init_iobuf(&si
->rx_buff
, 14384);
839 err
= pxa_irda_init_iobuf(&si
->tx_buff
, 4000);
843 if (si
->pdata
->startup
)
844 err
= si
->pdata
->startup(si
->dev
);
848 dev
->hard_start_xmit
= pxa_irda_hard_xmit
;
849 dev
->open
= pxa_irda_start
;
850 dev
->stop
= pxa_irda_stop
;
851 dev
->do_ioctl
= pxa_irda_ioctl
;
853 irda_init_max_qos_capabilies(&si
->qos
);
856 if (si
->pdata
->transceiver_cap
& IR_SIRMODE
)
857 baudrate_mask
|= IR_9600
|IR_19200
|IR_38400
|IR_57600
|IR_115200
;
858 if (si
->pdata
->transceiver_cap
& IR_FIRMODE
)
859 baudrate_mask
|= IR_4000000
<< 8;
861 si
->qos
.baud_rate
.bits
&= baudrate_mask
;
862 si
->qos
.min_turn_time
.bits
= 7; /* 1ms or more */
864 irda_qos_bits_to_value(&si
->qos
);
866 err
= register_netdev(dev
);
869 dev_set_drvdata(&pdev
->dev
, dev
);
872 if (si
->pdata
->shutdown
)
873 si
->pdata
->shutdown(si
->dev
);
875 kfree(si
->tx_buff
.head
);
877 kfree(si
->rx_buff
.head
);
879 if (si
->sir_clk
&& !IS_ERR(si
->sir_clk
))
880 clk_put(si
->sir_clk
);
881 if (si
->fir_clk
&& !IS_ERR(si
->fir_clk
))
882 clk_put(si
->fir_clk
);
885 release_mem_region(__PREG(FICP
), 0x1c);
887 release_mem_region(__PREG(STUART
), 0x24);
893 static int pxa_irda_remove(struct platform_device
*_dev
)
895 struct net_device
*dev
= platform_get_drvdata(_dev
);
898 struct pxa_irda
*si
= netdev_priv(dev
);
899 unregister_netdev(dev
);
900 if (si
->pdata
->shutdown
)
901 si
->pdata
->shutdown(si
->dev
);
902 kfree(si
->tx_buff
.head
);
903 kfree(si
->rx_buff
.head
);
904 clk_put(si
->fir_clk
);
905 clk_put(si
->sir_clk
);
909 release_mem_region(__PREG(STUART
), 0x24);
910 release_mem_region(__PREG(FICP
), 0x1c);
915 static struct platform_driver pxa_ir_driver
= {
918 .owner
= THIS_MODULE
,
920 .probe
= pxa_irda_probe
,
921 .remove
= pxa_irda_remove
,
922 .suspend
= pxa_irda_suspend
,
923 .resume
= pxa_irda_resume
,
926 static int __init
pxa_irda_init(void)
928 return platform_driver_register(&pxa_ir_driver
);
931 static void __exit
pxa_irda_exit(void)
933 platform_driver_unregister(&pxa_ir_driver
);
936 module_init(pxa_irda_init
);
937 module_exit(pxa_irda_exit
);
939 MODULE_LICENSE("GPL");
940 MODULE_ALIAS("platform:pxa2xx-ir");