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/etherdevice.h>
18 #include <linux/platform_device.h>
19 #include <linux/clk.h>
20 #include <linux/gpio.h>
21 #include <linux/slab.h>
23 #include <net/irda/irda.h>
24 #include <net/irda/irmod.h>
25 #include <net/irda/wrapper.h>
26 #include <net/irda/irda_device.h>
29 #include <mach/irda.h>
30 #include <mach/regs-uart.h>
31 #include <mach/regs-ost.h>
33 #define FICP __REG(0x40800000) /* Start of FICP area */
34 #define ICCR0 __REG(0x40800000) /* ICP Control Register 0 */
35 #define ICCR1 __REG(0x40800004) /* ICP Control Register 1 */
36 #define ICCR2 __REG(0x40800008) /* ICP Control Register 2 */
37 #define ICDR __REG(0x4080000c) /* ICP Data Register */
38 #define ICSR0 __REG(0x40800014) /* ICP Status Register 0 */
39 #define ICSR1 __REG(0x40800018) /* ICP Status Register 1 */
41 #define ICCR0_AME (1 << 7) /* Address match enable */
42 #define ICCR0_TIE (1 << 6) /* Transmit FIFO interrupt enable */
43 #define ICCR0_RIE (1 << 5) /* Recieve FIFO interrupt enable */
44 #define ICCR0_RXE (1 << 4) /* Receive enable */
45 #define ICCR0_TXE (1 << 3) /* Transmit enable */
46 #define ICCR0_TUS (1 << 2) /* Transmit FIFO underrun select */
47 #define ICCR0_LBM (1 << 1) /* Loopback mode */
48 #define ICCR0_ITR (1 << 0) /* IrDA transmission */
50 #define ICCR2_RXP (1 << 3) /* Receive Pin Polarity select */
51 #define ICCR2_TXP (1 << 2) /* Transmit Pin Polarity select */
52 #define ICCR2_TRIG (3 << 0) /* Receive FIFO Trigger threshold */
53 #define ICCR2_TRIG_8 (0 << 0) /* >= 8 bytes */
54 #define ICCR2_TRIG_16 (1 << 0) /* >= 16 bytes */
55 #define ICCR2_TRIG_32 (2 << 0) /* >= 32 bytes */
58 #define ICSR0_EOC (1 << 6) /* DMA End of Descriptor Chain */
60 #define ICSR0_FRE (1 << 5) /* Framing error */
61 #define ICSR0_RFS (1 << 4) /* Receive FIFO service request */
62 #define ICSR0_TFS (1 << 3) /* Transnit FIFO service request */
63 #define ICSR0_RAB (1 << 2) /* Receiver abort */
64 #define ICSR0_TUR (1 << 1) /* Trunsmit FIFO underun */
65 #define ICSR0_EIF (1 << 0) /* End/Error in FIFO */
67 #define ICSR1_ROR (1 << 6) /* Receiver FIFO underrun */
68 #define ICSR1_CRE (1 << 5) /* CRC error */
69 #define ICSR1_EOF (1 << 4) /* End of frame */
70 #define ICSR1_TNF (1 << 3) /* Transmit FIFO not full */
71 #define ICSR1_RNE (1 << 2) /* Receive FIFO not empty */
72 #define ICSR1_TBY (1 << 1) /* Tramsmiter busy flag */
73 #define ICSR1_RSY (1 << 0) /* Recevier synchronized flag */
75 #define IrSR_RXPL_NEG_IS_ZERO (1<<4)
76 #define IrSR_RXPL_POS_IS_ZERO 0x0
77 #define IrSR_TXPL_NEG_IS_ZERO (1<<3)
78 #define IrSR_TXPL_POS_IS_ZERO 0x0
79 #define IrSR_XMODE_PULSE_1_6 (1<<2)
80 #define IrSR_XMODE_PULSE_3_16 0x0
81 #define IrSR_RCVEIR_IR_MODE (1<<1)
82 #define IrSR_RCVEIR_UART_MODE 0x0
83 #define IrSR_XMITIR_IR_MODE (1<<0)
84 #define IrSR_XMITIR_UART_MODE 0x0
86 #define IrSR_IR_RECEIVE_ON (\
87 IrSR_RXPL_NEG_IS_ZERO | \
88 IrSR_TXPL_POS_IS_ZERO | \
89 IrSR_XMODE_PULSE_3_16 | \
90 IrSR_RCVEIR_IR_MODE | \
91 IrSR_XMITIR_UART_MODE)
93 #define IrSR_IR_TRANSMIT_ON (\
94 IrSR_RXPL_NEG_IS_ZERO | \
95 IrSR_TXPL_POS_IS_ZERO | \
96 IrSR_XMODE_PULSE_3_16 | \
97 IrSR_RCVEIR_UART_MODE | \
103 unsigned long last_oscr
;
105 unsigned char *dma_rx_buff
;
106 unsigned char *dma_tx_buff
;
107 dma_addr_t dma_rx_buff_phy
;
108 dma_addr_t dma_tx_buff_phy
;
109 unsigned int dma_tx_buff_len
;
113 struct irlap_cb
*irlap
;
120 struct pxaficp_platform_data
*pdata
;
126 static inline void pxa_irda_disable_clk(struct pxa_irda
*si
)
129 clk_disable(si
->cur_clk
);
133 static inline void pxa_irda_enable_firclk(struct pxa_irda
*si
)
135 si
->cur_clk
= si
->fir_clk
;
136 clk_enable(si
->fir_clk
);
139 static inline void pxa_irda_enable_sirclk(struct pxa_irda
*si
)
141 si
->cur_clk
= si
->sir_clk
;
142 clk_enable(si
->sir_clk
);
146 #define IS_FIR(si) ((si)->speed >= 4000000)
147 #define IRDA_FRAME_SIZE_LIMIT 2047
149 inline static void pxa_irda_fir_dma_rx_start(struct pxa_irda
*si
)
151 DCSR(si
->rxdma
) = DCSR_NODESC
;
152 DSADR(si
->rxdma
) = __PREG(ICDR
);
153 DTADR(si
->rxdma
) = si
->dma_rx_buff_phy
;
154 DCMD(si
->rxdma
) = DCMD_INCTRGADDR
| DCMD_FLOWSRC
| DCMD_WIDTH1
| DCMD_BURST32
| IRDA_FRAME_SIZE_LIMIT
;
155 DCSR(si
->rxdma
) |= DCSR_RUN
;
158 inline static void pxa_irda_fir_dma_tx_start(struct pxa_irda
*si
)
160 DCSR(si
->txdma
) = DCSR_NODESC
;
161 DSADR(si
->txdma
) = si
->dma_tx_buff_phy
;
162 DTADR(si
->txdma
) = __PREG(ICDR
);
163 DCMD(si
->txdma
) = DCMD_INCSRCADDR
| DCMD_FLOWTRG
| DCMD_ENDIRQEN
| DCMD_WIDTH1
| DCMD_BURST32
| si
->dma_tx_buff_len
;
164 DCSR(si
->txdma
) |= DCSR_RUN
;
168 * Set the IrDA communications mode.
170 static void pxa_irda_set_mode(struct pxa_irda
*si
, int mode
)
172 if (si
->pdata
->transceiver_mode
)
173 si
->pdata
->transceiver_mode(si
->dev
, mode
);
175 if (gpio_is_valid(si
->pdata
->gpio_pwdown
))
176 gpio_set_value(si
->pdata
->gpio_pwdown
,
178 !si
->pdata
->gpio_pwdown_inverted
);
179 pxa2xx_transceiver_mode(si
->dev
, mode
);
184 * Set the IrDA communications speed.
186 static int pxa_irda_set_speed(struct pxa_irda
*si
, int speed
)
189 unsigned int divisor
;
192 case 9600: case 19200: case 38400:
193 case 57600: case 115200:
195 /* refer to PXA250/210 Developer's Manual 10-7 */
196 /* BaudRate = 14.7456 MHz / (16*Divisor) */
197 divisor
= 14745600 / (16 * speed
);
199 local_irq_save(flags
);
203 DCSR(si
->rxdma
) &= ~DCSR_RUN
;
206 pxa_irda_disable_clk(si
);
208 /* set board transceiver to SIR mode */
209 pxa_irda_set_mode(si
, IR_SIRMODE
);
211 /* enable the STUART clock */
212 pxa_irda_enable_sirclk(si
);
215 /* disable STUART first */
218 /* access DLL & DLH */
220 STDLL
= divisor
& 0xff;
221 STDLH
= divisor
>> 8;
225 STISR
= IrSR_IR_RECEIVE_ON
| IrSR_XMODE_PULSE_1_6
;
226 STIER
= IER_UUE
| IER_RLSE
| IER_RAVIE
| IER_RTIOE
;
228 local_irq_restore(flags
);
232 local_irq_save(flags
);
237 pxa_irda_disable_clk(si
);
239 /* disable FICP first */
242 /* set board transceiver to FIR mode */
243 pxa_irda_set_mode(si
, IR_FIRMODE
);
245 /* enable the FICP clock */
246 pxa_irda_enable_firclk(si
);
249 pxa_irda_fir_dma_rx_start(si
);
250 ICCR0
= ICCR0_ITR
| ICCR0_RXE
;
252 local_irq_restore(flags
);
262 /* SIR interrupt service routine. */
263 static irqreturn_t
pxa_irda_sir_irq(int irq
, void *dev_id
)
265 struct net_device
*dev
= dev_id
;
266 struct pxa_irda
*si
= netdev_priv(dev
);
271 switch (iir
& 0x0F) {
272 case 0x06: /* Receiver Line Status */
274 while (lsr
& LSR_FIFOE
) {
276 if (lsr
& (LSR_OE
| LSR_PE
| LSR_FE
| LSR_BI
)) {
277 printk(KERN_DEBUG
"pxa_ir: sir receiving error\n");
278 dev
->stats
.rx_errors
++;
280 dev
->stats
.rx_frame_errors
++;
282 dev
->stats
.rx_fifo_errors
++;
284 dev
->stats
.rx_bytes
++;
285 async_unwrap_char(dev
, &dev
->stats
,
290 si
->last_oscr
= OSCR
;
293 case 0x04: /* Received Data Available */
296 case 0x0C: /* Character Timeout Indication */
298 dev
->stats
.rx_bytes
++;
299 async_unwrap_char(dev
, &dev
->stats
, &si
->rx_buff
, STRBR
);
300 } while (STLSR
& LSR_DR
);
301 si
->last_oscr
= OSCR
;
304 case 0x02: /* Transmit FIFO Data Request */
305 while ((si
->tx_buff
.len
) && (STLSR
& LSR_TDRQ
)) {
306 STTHR
= *si
->tx_buff
.data
++;
307 si
->tx_buff
.len
-= 1;
310 if (si
->tx_buff
.len
== 0) {
311 dev
->stats
.tx_packets
++;
312 dev
->stats
.tx_bytes
+= si
->tx_buff
.data
- si
->tx_buff
.head
;
314 /* We need to ensure that the transmitter has finished. */
315 while ((STLSR
& LSR_TEMT
) == 0)
317 si
->last_oscr
= OSCR
;
320 * Ok, we've finished transmitting. Now enable
321 * the receiver. Sometimes we get a receive IRQ
322 * immediately after a transmit...
325 pxa_irda_set_speed(si
, si
->newspeed
);
328 /* enable IR Receiver, disable IR Transmitter */
329 STISR
= IrSR_IR_RECEIVE_ON
| IrSR_XMODE_PULSE_1_6
;
330 /* enable STUART and receive interrupts */
331 STIER
= IER_UUE
| IER_RLSE
| IER_RAVIE
| IER_RTIOE
;
334 netif_wake_queue(dev
);
342 /* FIR Receive DMA interrupt handler */
343 static void pxa_irda_fir_dma_rx_irq(int channel
, void *data
)
345 int dcsr
= DCSR(channel
);
347 DCSR(channel
) = dcsr
& ~DCSR_RUN
;
349 printk(KERN_DEBUG
"pxa_ir: fir rx dma bus error %#x\n", dcsr
);
352 /* FIR Transmit DMA interrupt handler */
353 static void pxa_irda_fir_dma_tx_irq(int channel
, void *data
)
355 struct net_device
*dev
= data
;
356 struct pxa_irda
*si
= netdev_priv(dev
);
359 dcsr
= DCSR(channel
);
360 DCSR(channel
) = dcsr
& ~DCSR_RUN
;
362 if (dcsr
& DCSR_ENDINTR
) {
363 dev
->stats
.tx_packets
++;
364 dev
->stats
.tx_bytes
+= si
->dma_tx_buff_len
;
366 dev
->stats
.tx_errors
++;
369 while (ICSR1
& ICSR1_TBY
)
371 si
->last_oscr
= OSCR
;
374 * HACK: It looks like the TBY bit is dropped too soon.
375 * Without this delay things break.
380 pxa_irda_set_speed(si
, si
->newspeed
);
386 pxa_irda_fir_dma_rx_start(si
);
387 while ((ICSR1
& ICSR1_RNE
) && i
--)
389 ICCR0
= ICCR0_ITR
| ICCR0_RXE
;
392 printk(KERN_ERR
"pxa_ir: cannot clear Rx FIFO!\n");
394 netif_wake_queue(dev
);
397 /* EIF(Error in FIFO/End in Frame) handler for FIR */
398 static void pxa_irda_fir_irq_eif(struct pxa_irda
*si
, struct net_device
*dev
, int icsr0
)
400 unsigned int len
, stat
, data
;
402 /* Get the current data position. */
403 len
= DTADR(si
->rxdma
) - si
->dma_rx_buff_phy
;
406 /* Read Status, and then Data. */
411 if (stat
& (ICSR1_CRE
| ICSR1_ROR
)) {
412 dev
->stats
.rx_errors
++;
413 if (stat
& ICSR1_CRE
) {
414 printk(KERN_DEBUG
"pxa_ir: fir receive CRC error\n");
415 dev
->stats
.rx_crc_errors
++;
417 if (stat
& ICSR1_ROR
) {
418 printk(KERN_DEBUG
"pxa_ir: fir receive overrun\n");
419 dev
->stats
.rx_over_errors
++;
422 si
->dma_rx_buff
[len
++] = data
;
424 /* If we hit the end of frame, there's no point in continuing. */
425 if (stat
& ICSR1_EOF
)
427 } while (ICSR0
& ICSR0_EIF
);
429 if (stat
& ICSR1_EOF
) {
433 if (icsr0
& ICSR0_FRE
) {
434 printk(KERN_ERR
"pxa_ir: dropping erroneous frame\n");
435 dev
->stats
.rx_dropped
++;
439 skb
= alloc_skb(len
+1,GFP_ATOMIC
);
441 printk(KERN_ERR
"pxa_ir: fir out of memory for receive skb\n");
442 dev
->stats
.rx_dropped
++;
446 /* Align IP header to 20 bytes */
448 skb_copy_to_linear_data(skb
, si
->dma_rx_buff
, len
);
451 /* Feed it to IrLAP */
453 skb_reset_mac_header(skb
);
454 skb
->protocol
= htons(ETH_P_IRDA
);
457 dev
->stats
.rx_packets
++;
458 dev
->stats
.rx_bytes
+= len
;
462 /* FIR interrupt handler */
463 static irqreturn_t
pxa_irda_fir_irq(int irq
, void *dev_id
)
465 struct net_device
*dev
= dev_id
;
466 struct pxa_irda
*si
= netdev_priv(dev
);
470 DCSR(si
->rxdma
) &= ~DCSR_RUN
;
471 si
->last_oscr
= OSCR
;
474 if (icsr0
& (ICSR0_FRE
| ICSR0_RAB
)) {
475 if (icsr0
& ICSR0_FRE
) {
476 printk(KERN_DEBUG
"pxa_ir: fir receive frame error\n");
477 dev
->stats
.rx_frame_errors
++;
479 printk(KERN_DEBUG
"pxa_ir: fir receive abort\n");
480 dev
->stats
.rx_errors
++;
482 ICSR0
= icsr0
& (ICSR0_FRE
| ICSR0_RAB
);
485 if (icsr0
& ICSR0_EIF
) {
486 /* An error in FIFO occured, or there is a end of frame */
487 pxa_irda_fir_irq_eif(si
, dev
, icsr0
);
491 pxa_irda_fir_dma_rx_start(si
);
492 while ((ICSR1
& ICSR1_RNE
) && i
--)
494 ICCR0
= ICCR0_ITR
| ICCR0_RXE
;
497 printk(KERN_ERR
"pxa_ir: cannot clear Rx FIFO!\n");
502 /* hard_xmit interface of irda device */
503 static int pxa_irda_hard_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
505 struct pxa_irda
*si
= netdev_priv(dev
);
506 int speed
= irda_get_next_speed(skb
);
509 * Does this packet contain a request to change the interface
510 * speed? If so, remember it until we complete the transmission
513 if (speed
!= si
->speed
&& speed
!= -1)
514 si
->newspeed
= speed
;
517 * If this is an empty frame, we can bypass a lot.
522 pxa_irda_set_speed(si
, speed
);
528 netif_stop_queue(dev
);
531 si
->tx_buff
.data
= si
->tx_buff
.head
;
532 si
->tx_buff
.len
= async_wrap_skb(skb
, si
->tx_buff
.data
, si
->tx_buff
.truesize
);
534 /* Disable STUART interrupts and switch to transmit mode. */
536 STISR
= IrSR_IR_TRANSMIT_ON
| IrSR_XMODE_PULSE_1_6
;
538 /* enable STUART and transmit interrupts */
539 STIER
= IER_UUE
| IER_TIE
;
541 unsigned long mtt
= irda_get_mtt(skb
);
543 si
->dma_tx_buff_len
= skb
->len
;
544 skb_copy_from_linear_data(skb
, si
->dma_tx_buff
, skb
->len
);
547 while ((unsigned)(OSCR
- si
->last_oscr
)/4 < mtt
)
550 /* stop RX DMA, disable FICP */
551 DCSR(si
->rxdma
) &= ~DCSR_RUN
;
554 pxa_irda_fir_dma_tx_start(si
);
555 ICCR0
= ICCR0_ITR
| ICCR0_TXE
;
562 static int pxa_irda_ioctl(struct net_device
*dev
, struct ifreq
*ifreq
, int cmd
)
564 struct if_irda_req
*rq
= (struct if_irda_req
*)ifreq
;
565 struct pxa_irda
*si
= netdev_priv(dev
);
571 if (capable(CAP_NET_ADMIN
)) {
573 * We are unable to set the speed if the
574 * device is not running.
576 if (netif_running(dev
)) {
577 ret
= pxa_irda_set_speed(si
,
580 printk(KERN_INFO
"pxa_ir: SIOCSBANDWIDTH: !netif_running\n");
588 if (capable(CAP_NET_ADMIN
)) {
589 irda_device_set_media_busy(dev
, TRUE
);
596 rq
->ifr_receiving
= IS_FIR(si
) ? 0
597 : si
->rx_buff
.state
!= OUTSIDE_FRAME
;
608 static void pxa_irda_startup(struct pxa_irda
*si
)
610 /* Disable STUART interrupts */
612 /* enable STUART interrupt to the processor */
614 /* configure SIR frame format: StartBit - Data 7 ... Data 0 - Stop Bit */
615 STLCR
= LCR_WLS0
| LCR_WLS1
;
616 /* enable FIFO, we use FIFO to improve performance */
617 STFCR
= FCR_TRFIFOE
| FCR_ITL_32
;
621 /* configure FICP ICCR2 */
622 ICCR2
= ICCR2_TXP
| ICCR2_TRIG_32
;
625 DRCMR(17) = si
->rxdma
| DRCMR_MAPVLD
;
626 DRCMR(18) = si
->txdma
| DRCMR_MAPVLD
;
628 /* force SIR reinitialization */
630 pxa_irda_set_speed(si
, 9600);
632 printk(KERN_DEBUG
"pxa_ir: irda startup\n");
635 static void pxa_irda_shutdown(struct pxa_irda
*si
)
639 local_irq_save(flags
);
641 /* disable STUART and interrupt */
643 /* disable STUART SIR mode */
647 DCSR(si
->txdma
) &= ~DCSR_RUN
;
648 DCSR(si
->rxdma
) &= ~DCSR_RUN
;
652 /* disable the STUART or FICP clocks */
653 pxa_irda_disable_clk(si
);
658 local_irq_restore(flags
);
660 /* power off board transceiver */
661 pxa_irda_set_mode(si
, IR_OFF
);
663 printk(KERN_DEBUG
"pxa_ir: irda shutdown\n");
666 static int pxa_irda_start(struct net_device
*dev
)
668 struct pxa_irda
*si
= netdev_priv(dev
);
673 err
= request_irq(IRQ_STUART
, pxa_irda_sir_irq
, 0, dev
->name
, dev
);
677 err
= request_irq(IRQ_ICP
, pxa_irda_fir_irq
, 0, dev
->name
, dev
);
682 * The interrupt must remain disabled for now.
684 disable_irq(IRQ_STUART
);
685 disable_irq(IRQ_ICP
);
688 si
->rxdma
= pxa_request_dma("FICP_RX",DMA_PRIO_LOW
, pxa_irda_fir_dma_rx_irq
, dev
);
692 si
->txdma
= pxa_request_dma("FICP_TX",DMA_PRIO_LOW
, pxa_irda_fir_dma_tx_irq
, dev
);
697 si
->dma_rx_buff
= dma_alloc_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
,
698 &si
->dma_rx_buff_phy
, GFP_KERNEL
);
699 if (!si
->dma_rx_buff
)
700 goto err_dma_rx_buff
;
702 si
->dma_tx_buff
= dma_alloc_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
,
703 &si
->dma_tx_buff_phy
, GFP_KERNEL
);
704 if (!si
->dma_tx_buff
)
705 goto err_dma_tx_buff
;
707 /* Setup the serial port for the initial speed. */
708 pxa_irda_startup(si
);
711 * Open a new IrLAP layer instance.
713 si
->irlap
= irlap_open(dev
, &si
->qos
, "pxa");
719 * Now enable the interrupt and start the queue
721 enable_irq(IRQ_STUART
);
723 netif_start_queue(dev
);
725 printk(KERN_DEBUG
"pxa_ir: irda driver opened\n");
730 pxa_irda_shutdown(si
);
731 dma_free_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
, si
->dma_tx_buff
, si
->dma_tx_buff_phy
);
733 dma_free_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
, si
->dma_rx_buff
, si
->dma_rx_buff_phy
);
735 pxa_free_dma(si
->txdma
);
737 pxa_free_dma(si
->rxdma
);
739 free_irq(IRQ_ICP
, dev
);
741 free_irq(IRQ_STUART
, dev
);
747 static int pxa_irda_stop(struct net_device
*dev
)
749 struct pxa_irda
*si
= netdev_priv(dev
);
751 netif_stop_queue(dev
);
753 pxa_irda_shutdown(si
);
757 irlap_close(si
->irlap
);
761 free_irq(IRQ_STUART
, dev
);
762 free_irq(IRQ_ICP
, dev
);
764 pxa_free_dma(si
->rxdma
);
765 pxa_free_dma(si
->txdma
);
768 dma_free_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
, si
->dma_tx_buff
, si
->dma_tx_buff_phy
);
770 dma_free_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
, si
->dma_rx_buff
, si
->dma_rx_buff_phy
);
772 printk(KERN_DEBUG
"pxa_ir: irda driver closed\n");
776 static int pxa_irda_suspend(struct platform_device
*_dev
, pm_message_t state
)
778 struct net_device
*dev
= platform_get_drvdata(_dev
);
781 if (dev
&& netif_running(dev
)) {
782 si
= netdev_priv(dev
);
783 netif_device_detach(dev
);
784 pxa_irda_shutdown(si
);
790 static int pxa_irda_resume(struct platform_device
*_dev
)
792 struct net_device
*dev
= platform_get_drvdata(_dev
);
795 if (dev
&& netif_running(dev
)) {
796 si
= netdev_priv(dev
);
797 pxa_irda_startup(si
);
798 netif_device_attach(dev
);
799 netif_wake_queue(dev
);
806 static int pxa_irda_init_iobuf(iobuff_t
*io
, int size
)
808 io
->head
= kmalloc(size
, GFP_KERNEL
| GFP_DMA
);
809 if (io
->head
!= NULL
) {
811 io
->in_frame
= FALSE
;
812 io
->state
= OUTSIDE_FRAME
;
815 return io
->head
? 0 : -ENOMEM
;
818 static const struct net_device_ops pxa_irda_netdev_ops
= {
819 .ndo_open
= pxa_irda_start
,
820 .ndo_stop
= pxa_irda_stop
,
821 .ndo_start_xmit
= pxa_irda_hard_xmit
,
822 .ndo_do_ioctl
= pxa_irda_ioctl
,
825 static int pxa_irda_probe(struct platform_device
*pdev
)
827 struct net_device
*dev
;
829 unsigned int baudrate_mask
;
832 if (!pdev
->dev
.platform_data
)
835 err
= request_mem_region(__PREG(STUART
), 0x24, "IrDA") ? 0 : -EBUSY
;
839 err
= request_mem_region(__PREG(FICP
), 0x1c, "IrDA") ? 0 : -EBUSY
;
843 dev
= alloc_irdadev(sizeof(struct pxa_irda
));
847 SET_NETDEV_DEV(dev
, &pdev
->dev
);
848 si
= netdev_priv(dev
);
849 si
->dev
= &pdev
->dev
;
850 si
->pdata
= pdev
->dev
.platform_data
;
852 si
->sir_clk
= clk_get(&pdev
->dev
, "UARTCLK");
853 si
->fir_clk
= clk_get(&pdev
->dev
, "FICPCLK");
854 if (IS_ERR(si
->sir_clk
) || IS_ERR(si
->fir_clk
)) {
855 err
= PTR_ERR(IS_ERR(si
->sir_clk
) ? si
->sir_clk
: si
->fir_clk
);
860 * Initialise the SIR buffers
862 err
= pxa_irda_init_iobuf(&si
->rx_buff
, 14384);
865 err
= pxa_irda_init_iobuf(&si
->tx_buff
, 4000);
869 if (gpio_is_valid(si
->pdata
->gpio_pwdown
)) {
870 err
= gpio_request(si
->pdata
->gpio_pwdown
, "IrDA switch");
873 err
= gpio_direction_output(si
->pdata
->gpio_pwdown
,
874 !si
->pdata
->gpio_pwdown_inverted
);
876 gpio_free(si
->pdata
->gpio_pwdown
);
881 if (si
->pdata
->startup
) {
882 err
= si
->pdata
->startup(si
->dev
);
887 if (gpio_is_valid(si
->pdata
->gpio_pwdown
) && si
->pdata
->startup
)
888 dev_warn(si
->dev
, "gpio_pwdown and startup() both defined!\n");
890 dev
->netdev_ops
= &pxa_irda_netdev_ops
;
892 irda_init_max_qos_capabilies(&si
->qos
);
895 if (si
->pdata
->transceiver_cap
& IR_SIRMODE
)
896 baudrate_mask
|= IR_9600
|IR_19200
|IR_38400
|IR_57600
|IR_115200
;
897 if (si
->pdata
->transceiver_cap
& IR_FIRMODE
)
898 baudrate_mask
|= IR_4000000
<< 8;
900 si
->qos
.baud_rate
.bits
&= baudrate_mask
;
901 si
->qos
.min_turn_time
.bits
= 7; /* 1ms or more */
903 irda_qos_bits_to_value(&si
->qos
);
905 err
= register_netdev(dev
);
908 dev_set_drvdata(&pdev
->dev
, dev
);
911 if (si
->pdata
->shutdown
)
912 si
->pdata
->shutdown(si
->dev
);
914 kfree(si
->tx_buff
.head
);
916 kfree(si
->rx_buff
.head
);
918 if (si
->sir_clk
&& !IS_ERR(si
->sir_clk
))
919 clk_put(si
->sir_clk
);
920 if (si
->fir_clk
&& !IS_ERR(si
->fir_clk
))
921 clk_put(si
->fir_clk
);
924 release_mem_region(__PREG(FICP
), 0x1c);
926 release_mem_region(__PREG(STUART
), 0x24);
932 static int pxa_irda_remove(struct platform_device
*_dev
)
934 struct net_device
*dev
= platform_get_drvdata(_dev
);
937 struct pxa_irda
*si
= netdev_priv(dev
);
938 unregister_netdev(dev
);
939 if (gpio_is_valid(si
->pdata
->gpio_pwdown
))
940 gpio_free(si
->pdata
->gpio_pwdown
);
941 if (si
->pdata
->shutdown
)
942 si
->pdata
->shutdown(si
->dev
);
943 kfree(si
->tx_buff
.head
);
944 kfree(si
->rx_buff
.head
);
945 clk_put(si
->fir_clk
);
946 clk_put(si
->sir_clk
);
950 release_mem_region(__PREG(STUART
), 0x24);
951 release_mem_region(__PREG(FICP
), 0x1c);
956 static struct platform_driver pxa_ir_driver
= {
959 .owner
= THIS_MODULE
,
961 .probe
= pxa_irda_probe
,
962 .remove
= pxa_irda_remove
,
963 .suspend
= pxa_irda_suspend
,
964 .resume
= pxa_irda_resume
,
967 static int __init
pxa_irda_init(void)
969 return platform_driver_register(&pxa_ir_driver
);
972 static void __exit
pxa_irda_exit(void)
974 platform_driver_unregister(&pxa_ir_driver
);
977 module_init(pxa_irda_init
);
978 module_exit(pxa_irda_exit
);
980 MODULE_LICENSE("GPL");
981 MODULE_ALIAS("platform:pxa2xx-ir");