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/dma-mapping.h>
16 #include <linux/interrupt.h>
17 #include <linux/module.h>
18 #include <linux/netdevice.h>
19 #include <linux/etherdevice.h>
20 #include <linux/platform_device.h>
21 #include <linux/clk.h>
22 #include <linux/gpio.h>
23 #include <linux/slab.h>
25 #include <net/irda/irda.h>
26 #include <net/irda/irmod.h>
27 #include <net/irda/wrapper.h>
28 #include <net/irda/irda_device.h>
31 #include <mach/irda.h>
32 #include <mach/regs-uart.h>
33 #include <mach/regs-ost.h>
35 #define FICP __REG(0x40800000) /* Start of FICP area */
36 #define ICCR0 __REG(0x40800000) /* ICP Control Register 0 */
37 #define ICCR1 __REG(0x40800004) /* ICP Control Register 1 */
38 #define ICCR2 __REG(0x40800008) /* ICP Control Register 2 */
39 #define ICDR __REG(0x4080000c) /* ICP Data Register */
40 #define ICSR0 __REG(0x40800014) /* ICP Status Register 0 */
41 #define ICSR1 __REG(0x40800018) /* ICP Status Register 1 */
43 #define ICCR0_AME (1 << 7) /* Address match enable */
44 #define ICCR0_TIE (1 << 6) /* Transmit FIFO interrupt enable */
45 #define ICCR0_RIE (1 << 5) /* Receive FIFO interrupt enable */
46 #define ICCR0_RXE (1 << 4) /* Receive enable */
47 #define ICCR0_TXE (1 << 3) /* Transmit enable */
48 #define ICCR0_TUS (1 << 2) /* Transmit FIFO underrun select */
49 #define ICCR0_LBM (1 << 1) /* Loopback mode */
50 #define ICCR0_ITR (1 << 0) /* IrDA transmission */
52 #define ICCR2_RXP (1 << 3) /* Receive Pin Polarity select */
53 #define ICCR2_TXP (1 << 2) /* Transmit Pin Polarity select */
54 #define ICCR2_TRIG (3 << 0) /* Receive FIFO Trigger threshold */
55 #define ICCR2_TRIG_8 (0 << 0) /* >= 8 bytes */
56 #define ICCR2_TRIG_16 (1 << 0) /* >= 16 bytes */
57 #define ICCR2_TRIG_32 (2 << 0) /* >= 32 bytes */
60 #define ICSR0_EOC (1 << 6) /* DMA End of Descriptor Chain */
62 #define ICSR0_FRE (1 << 5) /* Framing error */
63 #define ICSR0_RFS (1 << 4) /* Receive FIFO service request */
64 #define ICSR0_TFS (1 << 3) /* Transnit FIFO service request */
65 #define ICSR0_RAB (1 << 2) /* Receiver abort */
66 #define ICSR0_TUR (1 << 1) /* Trunsmit FIFO underun */
67 #define ICSR0_EIF (1 << 0) /* End/Error in FIFO */
69 #define ICSR1_ROR (1 << 6) /* Receiver FIFO underrun */
70 #define ICSR1_CRE (1 << 5) /* CRC error */
71 #define ICSR1_EOF (1 << 4) /* End of frame */
72 #define ICSR1_TNF (1 << 3) /* Transmit FIFO not full */
73 #define ICSR1_RNE (1 << 2) /* Receive FIFO not empty */
74 #define ICSR1_TBY (1 << 1) /* Tramsmiter busy flag */
75 #define ICSR1_RSY (1 << 0) /* Recevier synchronized flag */
77 #define IrSR_RXPL_NEG_IS_ZERO (1<<4)
78 #define IrSR_RXPL_POS_IS_ZERO 0x0
79 #define IrSR_TXPL_NEG_IS_ZERO (1<<3)
80 #define IrSR_TXPL_POS_IS_ZERO 0x0
81 #define IrSR_XMODE_PULSE_1_6 (1<<2)
82 #define IrSR_XMODE_PULSE_3_16 0x0
83 #define IrSR_RCVEIR_IR_MODE (1<<1)
84 #define IrSR_RCVEIR_UART_MODE 0x0
85 #define IrSR_XMITIR_IR_MODE (1<<0)
86 #define IrSR_XMITIR_UART_MODE 0x0
88 #define IrSR_IR_RECEIVE_ON (\
89 IrSR_RXPL_NEG_IS_ZERO | \
90 IrSR_TXPL_POS_IS_ZERO | \
91 IrSR_XMODE_PULSE_3_16 | \
92 IrSR_RCVEIR_IR_MODE | \
93 IrSR_XMITIR_UART_MODE)
95 #define IrSR_IR_TRANSMIT_ON (\
96 IrSR_RXPL_NEG_IS_ZERO | \
97 IrSR_TXPL_POS_IS_ZERO | \
98 IrSR_XMODE_PULSE_3_16 | \
99 IrSR_RCVEIR_UART_MODE | \
105 unsigned long last_oscr
;
107 unsigned char *dma_rx_buff
;
108 unsigned char *dma_tx_buff
;
109 dma_addr_t dma_rx_buff_phy
;
110 dma_addr_t dma_tx_buff_phy
;
111 unsigned int dma_tx_buff_len
;
115 struct irlap_cb
*irlap
;
122 struct pxaficp_platform_data
*pdata
;
128 static inline void pxa_irda_disable_clk(struct pxa_irda
*si
)
131 clk_disable(si
->cur_clk
);
135 static inline void pxa_irda_enable_firclk(struct pxa_irda
*si
)
137 si
->cur_clk
= si
->fir_clk
;
138 clk_enable(si
->fir_clk
);
141 static inline void pxa_irda_enable_sirclk(struct pxa_irda
*si
)
143 si
->cur_clk
= si
->sir_clk
;
144 clk_enable(si
->sir_clk
);
148 #define IS_FIR(si) ((si)->speed >= 4000000)
149 #define IRDA_FRAME_SIZE_LIMIT 2047
151 inline static void pxa_irda_fir_dma_rx_start(struct pxa_irda
*si
)
153 DCSR(si
->rxdma
) = DCSR_NODESC
;
154 DSADR(si
->rxdma
) = __PREG(ICDR
);
155 DTADR(si
->rxdma
) = si
->dma_rx_buff_phy
;
156 DCMD(si
->rxdma
) = DCMD_INCTRGADDR
| DCMD_FLOWSRC
| DCMD_WIDTH1
| DCMD_BURST32
| IRDA_FRAME_SIZE_LIMIT
;
157 DCSR(si
->rxdma
) |= DCSR_RUN
;
160 inline static void pxa_irda_fir_dma_tx_start(struct pxa_irda
*si
)
162 DCSR(si
->txdma
) = DCSR_NODESC
;
163 DSADR(si
->txdma
) = si
->dma_tx_buff_phy
;
164 DTADR(si
->txdma
) = __PREG(ICDR
);
165 DCMD(si
->txdma
) = DCMD_INCSRCADDR
| DCMD_FLOWTRG
| DCMD_ENDIRQEN
| DCMD_WIDTH1
| DCMD_BURST32
| si
->dma_tx_buff_len
;
166 DCSR(si
->txdma
) |= DCSR_RUN
;
170 * Set the IrDA communications mode.
172 static void pxa_irda_set_mode(struct pxa_irda
*si
, int mode
)
174 if (si
->pdata
->transceiver_mode
)
175 si
->pdata
->transceiver_mode(si
->dev
, mode
);
177 if (gpio_is_valid(si
->pdata
->gpio_pwdown
))
178 gpio_set_value(si
->pdata
->gpio_pwdown
,
180 !si
->pdata
->gpio_pwdown_inverted
);
181 pxa2xx_transceiver_mode(si
->dev
, mode
);
186 * Set the IrDA communications speed.
188 static int pxa_irda_set_speed(struct pxa_irda
*si
, int speed
)
191 unsigned int divisor
;
194 case 9600: case 19200: case 38400:
195 case 57600: case 115200:
197 /* refer to PXA250/210 Developer's Manual 10-7 */
198 /* BaudRate = 14.7456 MHz / (16*Divisor) */
199 divisor
= 14745600 / (16 * speed
);
201 local_irq_save(flags
);
205 DCSR(si
->rxdma
) &= ~DCSR_RUN
;
208 pxa_irda_disable_clk(si
);
210 /* set board transceiver to SIR mode */
211 pxa_irda_set_mode(si
, IR_SIRMODE
);
213 /* enable the STUART clock */
214 pxa_irda_enable_sirclk(si
);
217 /* disable STUART first */
220 /* access DLL & DLH */
222 STDLL
= divisor
& 0xff;
223 STDLH
= divisor
>> 8;
227 STISR
= IrSR_IR_RECEIVE_ON
| IrSR_XMODE_PULSE_1_6
;
228 STIER
= IER_UUE
| IER_RLSE
| IER_RAVIE
| IER_RTIOE
;
230 local_irq_restore(flags
);
234 local_irq_save(flags
);
239 pxa_irda_disable_clk(si
);
241 /* disable FICP first */
244 /* set board transceiver to FIR mode */
245 pxa_irda_set_mode(si
, IR_FIRMODE
);
247 /* enable the FICP clock */
248 pxa_irda_enable_firclk(si
);
251 pxa_irda_fir_dma_rx_start(si
);
252 ICCR0
= ICCR0_ITR
| ICCR0_RXE
;
254 local_irq_restore(flags
);
264 /* SIR interrupt service routine. */
265 static irqreturn_t
pxa_irda_sir_irq(int irq
, void *dev_id
)
267 struct net_device
*dev
= dev_id
;
268 struct pxa_irda
*si
= netdev_priv(dev
);
273 switch (iir
& 0x0F) {
274 case 0x06: /* Receiver Line Status */
276 while (lsr
& LSR_FIFOE
) {
278 if (lsr
& (LSR_OE
| LSR_PE
| LSR_FE
| LSR_BI
)) {
279 printk(KERN_DEBUG
"pxa_ir: sir receiving error\n");
280 dev
->stats
.rx_errors
++;
282 dev
->stats
.rx_frame_errors
++;
284 dev
->stats
.rx_fifo_errors
++;
286 dev
->stats
.rx_bytes
++;
287 async_unwrap_char(dev
, &dev
->stats
,
292 si
->last_oscr
= OSCR
;
295 case 0x04: /* Received Data Available */
298 case 0x0C: /* Character Timeout Indication */
300 dev
->stats
.rx_bytes
++;
301 async_unwrap_char(dev
, &dev
->stats
, &si
->rx_buff
, STRBR
);
302 } while (STLSR
& LSR_DR
);
303 si
->last_oscr
= OSCR
;
306 case 0x02: /* Transmit FIFO Data Request */
307 while ((si
->tx_buff
.len
) && (STLSR
& LSR_TDRQ
)) {
308 STTHR
= *si
->tx_buff
.data
++;
309 si
->tx_buff
.len
-= 1;
312 if (si
->tx_buff
.len
== 0) {
313 dev
->stats
.tx_packets
++;
314 dev
->stats
.tx_bytes
+= si
->tx_buff
.data
- si
->tx_buff
.head
;
316 /* We need to ensure that the transmitter has finished. */
317 while ((STLSR
& LSR_TEMT
) == 0)
319 si
->last_oscr
= OSCR
;
322 * Ok, we've finished transmitting. Now enable
323 * the receiver. Sometimes we get a receive IRQ
324 * immediately after a transmit...
327 pxa_irda_set_speed(si
, si
->newspeed
);
330 /* enable IR Receiver, disable IR Transmitter */
331 STISR
= IrSR_IR_RECEIVE_ON
| IrSR_XMODE_PULSE_1_6
;
332 /* enable STUART and receive interrupts */
333 STIER
= IER_UUE
| IER_RLSE
| IER_RAVIE
| IER_RTIOE
;
336 netif_wake_queue(dev
);
344 /* FIR Receive DMA interrupt handler */
345 static void pxa_irda_fir_dma_rx_irq(int channel
, void *data
)
347 int dcsr
= DCSR(channel
);
349 DCSR(channel
) = dcsr
& ~DCSR_RUN
;
351 printk(KERN_DEBUG
"pxa_ir: fir rx dma bus error %#x\n", dcsr
);
354 /* FIR Transmit DMA interrupt handler */
355 static void pxa_irda_fir_dma_tx_irq(int channel
, void *data
)
357 struct net_device
*dev
= data
;
358 struct pxa_irda
*si
= netdev_priv(dev
);
361 dcsr
= DCSR(channel
);
362 DCSR(channel
) = dcsr
& ~DCSR_RUN
;
364 if (dcsr
& DCSR_ENDINTR
) {
365 dev
->stats
.tx_packets
++;
366 dev
->stats
.tx_bytes
+= si
->dma_tx_buff_len
;
368 dev
->stats
.tx_errors
++;
371 while (ICSR1
& ICSR1_TBY
)
373 si
->last_oscr
= OSCR
;
376 * HACK: It looks like the TBY bit is dropped too soon.
377 * Without this delay things break.
382 pxa_irda_set_speed(si
, si
->newspeed
);
388 pxa_irda_fir_dma_rx_start(si
);
389 while ((ICSR1
& ICSR1_RNE
) && i
--)
391 ICCR0
= ICCR0_ITR
| ICCR0_RXE
;
394 printk(KERN_ERR
"pxa_ir: cannot clear Rx FIFO!\n");
396 netif_wake_queue(dev
);
399 /* EIF(Error in FIFO/End in Frame) handler for FIR */
400 static void pxa_irda_fir_irq_eif(struct pxa_irda
*si
, struct net_device
*dev
, int icsr0
)
402 unsigned int len
, stat
, data
;
404 /* Get the current data position. */
405 len
= DTADR(si
->rxdma
) - si
->dma_rx_buff_phy
;
408 /* Read Status, and then Data. */
413 if (stat
& (ICSR1_CRE
| ICSR1_ROR
)) {
414 dev
->stats
.rx_errors
++;
415 if (stat
& ICSR1_CRE
) {
416 printk(KERN_DEBUG
"pxa_ir: fir receive CRC error\n");
417 dev
->stats
.rx_crc_errors
++;
419 if (stat
& ICSR1_ROR
) {
420 printk(KERN_DEBUG
"pxa_ir: fir receive overrun\n");
421 dev
->stats
.rx_over_errors
++;
424 si
->dma_rx_buff
[len
++] = data
;
426 /* If we hit the end of frame, there's no point in continuing. */
427 if (stat
& ICSR1_EOF
)
429 } while (ICSR0
& ICSR0_EIF
);
431 if (stat
& ICSR1_EOF
) {
435 if (icsr0
& ICSR0_FRE
) {
436 printk(KERN_ERR
"pxa_ir: dropping erroneous frame\n");
437 dev
->stats
.rx_dropped
++;
441 skb
= alloc_skb(len
+1,GFP_ATOMIC
);
443 printk(KERN_ERR
"pxa_ir: fir out of memory for receive skb\n");
444 dev
->stats
.rx_dropped
++;
448 /* Align IP header to 20 bytes */
450 skb_copy_to_linear_data(skb
, si
->dma_rx_buff
, len
);
453 /* Feed it to IrLAP */
455 skb_reset_mac_header(skb
);
456 skb
->protocol
= htons(ETH_P_IRDA
);
459 dev
->stats
.rx_packets
++;
460 dev
->stats
.rx_bytes
+= len
;
464 /* FIR interrupt handler */
465 static irqreturn_t
pxa_irda_fir_irq(int irq
, void *dev_id
)
467 struct net_device
*dev
= dev_id
;
468 struct pxa_irda
*si
= netdev_priv(dev
);
472 DCSR(si
->rxdma
) &= ~DCSR_RUN
;
473 si
->last_oscr
= OSCR
;
476 if (icsr0
& (ICSR0_FRE
| ICSR0_RAB
)) {
477 if (icsr0
& ICSR0_FRE
) {
478 printk(KERN_DEBUG
"pxa_ir: fir receive frame error\n");
479 dev
->stats
.rx_frame_errors
++;
481 printk(KERN_DEBUG
"pxa_ir: fir receive abort\n");
482 dev
->stats
.rx_errors
++;
484 ICSR0
= icsr0
& (ICSR0_FRE
| ICSR0_RAB
);
487 if (icsr0
& ICSR0_EIF
) {
488 /* An error in FIFO occurred, or there is a end of frame */
489 pxa_irda_fir_irq_eif(si
, dev
, icsr0
);
493 pxa_irda_fir_dma_rx_start(si
);
494 while ((ICSR1
& ICSR1_RNE
) && i
--)
496 ICCR0
= ICCR0_ITR
| ICCR0_RXE
;
499 printk(KERN_ERR
"pxa_ir: cannot clear Rx FIFO!\n");
504 /* hard_xmit interface of irda device */
505 static int pxa_irda_hard_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
507 struct pxa_irda
*si
= netdev_priv(dev
);
508 int speed
= irda_get_next_speed(skb
);
511 * Does this packet contain a request to change the interface
512 * speed? If so, remember it until we complete the transmission
515 if (speed
!= si
->speed
&& speed
!= -1)
516 si
->newspeed
= speed
;
519 * If this is an empty frame, we can bypass a lot.
524 pxa_irda_set_speed(si
, speed
);
530 netif_stop_queue(dev
);
533 si
->tx_buff
.data
= si
->tx_buff
.head
;
534 si
->tx_buff
.len
= async_wrap_skb(skb
, si
->tx_buff
.data
, si
->tx_buff
.truesize
);
536 /* Disable STUART interrupts and switch to transmit mode. */
538 STISR
= IrSR_IR_TRANSMIT_ON
| IrSR_XMODE_PULSE_1_6
;
540 /* enable STUART and transmit interrupts */
541 STIER
= IER_UUE
| IER_TIE
;
543 unsigned long mtt
= irda_get_mtt(skb
);
545 si
->dma_tx_buff_len
= skb
->len
;
546 skb_copy_from_linear_data(skb
, si
->dma_tx_buff
, skb
->len
);
549 while ((unsigned)(OSCR
- si
->last_oscr
)/4 < mtt
)
552 /* stop RX DMA, disable FICP */
553 DCSR(si
->rxdma
) &= ~DCSR_RUN
;
556 pxa_irda_fir_dma_tx_start(si
);
557 ICCR0
= ICCR0_ITR
| ICCR0_TXE
;
564 static int pxa_irda_ioctl(struct net_device
*dev
, struct ifreq
*ifreq
, int cmd
)
566 struct if_irda_req
*rq
= (struct if_irda_req
*)ifreq
;
567 struct pxa_irda
*si
= netdev_priv(dev
);
573 if (capable(CAP_NET_ADMIN
)) {
575 * We are unable to set the speed if the
576 * device is not running.
578 if (netif_running(dev
)) {
579 ret
= pxa_irda_set_speed(si
,
582 printk(KERN_INFO
"pxa_ir: SIOCSBANDWIDTH: !netif_running\n");
590 if (capable(CAP_NET_ADMIN
)) {
591 irda_device_set_media_busy(dev
, TRUE
);
598 rq
->ifr_receiving
= IS_FIR(si
) ? 0
599 : si
->rx_buff
.state
!= OUTSIDE_FRAME
;
610 static void pxa_irda_startup(struct pxa_irda
*si
)
612 /* Disable STUART interrupts */
614 /* enable STUART interrupt to the processor */
616 /* configure SIR frame format: StartBit - Data 7 ... Data 0 - Stop Bit */
617 STLCR
= LCR_WLS0
| LCR_WLS1
;
618 /* enable FIFO, we use FIFO to improve performance */
619 STFCR
= FCR_TRFIFOE
| FCR_ITL_32
;
623 /* configure FICP ICCR2 */
624 ICCR2
= ICCR2_TXP
| ICCR2_TRIG_32
;
627 DRCMR(17) = si
->rxdma
| DRCMR_MAPVLD
;
628 DRCMR(18) = si
->txdma
| DRCMR_MAPVLD
;
630 /* force SIR reinitialization */
632 pxa_irda_set_speed(si
, 9600);
634 printk(KERN_DEBUG
"pxa_ir: irda startup\n");
637 static void pxa_irda_shutdown(struct pxa_irda
*si
)
641 local_irq_save(flags
);
643 /* disable STUART and interrupt */
645 /* disable STUART SIR mode */
649 DCSR(si
->txdma
) &= ~DCSR_RUN
;
650 DCSR(si
->rxdma
) &= ~DCSR_RUN
;
654 /* disable the STUART or FICP clocks */
655 pxa_irda_disable_clk(si
);
660 local_irq_restore(flags
);
662 /* power off board transceiver */
663 pxa_irda_set_mode(si
, IR_OFF
);
665 printk(KERN_DEBUG
"pxa_ir: irda shutdown\n");
668 static int pxa_irda_start(struct net_device
*dev
)
670 struct pxa_irda
*si
= netdev_priv(dev
);
675 err
= request_irq(IRQ_STUART
, pxa_irda_sir_irq
, 0, dev
->name
, dev
);
679 err
= request_irq(IRQ_ICP
, pxa_irda_fir_irq
, 0, dev
->name
, dev
);
684 * The interrupt must remain disabled for now.
686 disable_irq(IRQ_STUART
);
687 disable_irq(IRQ_ICP
);
690 si
->rxdma
= pxa_request_dma("FICP_RX",DMA_PRIO_LOW
, pxa_irda_fir_dma_rx_irq
, dev
);
694 si
->txdma
= pxa_request_dma("FICP_TX",DMA_PRIO_LOW
, pxa_irda_fir_dma_tx_irq
, dev
);
699 si
->dma_rx_buff
= dma_alloc_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
,
700 &si
->dma_rx_buff_phy
, GFP_KERNEL
);
701 if (!si
->dma_rx_buff
)
702 goto err_dma_rx_buff
;
704 si
->dma_tx_buff
= dma_alloc_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
,
705 &si
->dma_tx_buff_phy
, GFP_KERNEL
);
706 if (!si
->dma_tx_buff
)
707 goto err_dma_tx_buff
;
709 /* Setup the serial port for the initial speed. */
710 pxa_irda_startup(si
);
713 * Open a new IrLAP layer instance.
715 si
->irlap
= irlap_open(dev
, &si
->qos
, "pxa");
721 * Now enable the interrupt and start the queue
723 enable_irq(IRQ_STUART
);
725 netif_start_queue(dev
);
727 printk(KERN_DEBUG
"pxa_ir: irda driver opened\n");
732 pxa_irda_shutdown(si
);
733 dma_free_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
, si
->dma_tx_buff
, si
->dma_tx_buff_phy
);
735 dma_free_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
, si
->dma_rx_buff
, si
->dma_rx_buff_phy
);
737 pxa_free_dma(si
->txdma
);
739 pxa_free_dma(si
->rxdma
);
741 free_irq(IRQ_ICP
, dev
);
743 free_irq(IRQ_STUART
, dev
);
749 static int pxa_irda_stop(struct net_device
*dev
)
751 struct pxa_irda
*si
= netdev_priv(dev
);
753 netif_stop_queue(dev
);
755 pxa_irda_shutdown(si
);
759 irlap_close(si
->irlap
);
763 free_irq(IRQ_STUART
, dev
);
764 free_irq(IRQ_ICP
, dev
);
766 pxa_free_dma(si
->rxdma
);
767 pxa_free_dma(si
->txdma
);
770 dma_free_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
, si
->dma_tx_buff
, si
->dma_tx_buff_phy
);
772 dma_free_coherent(si
->dev
, IRDA_FRAME_SIZE_LIMIT
, si
->dma_rx_buff
, si
->dma_rx_buff_phy
);
774 printk(KERN_DEBUG
"pxa_ir: irda driver closed\n");
778 static int pxa_irda_suspend(struct platform_device
*_dev
, pm_message_t state
)
780 struct net_device
*dev
= platform_get_drvdata(_dev
);
783 if (dev
&& netif_running(dev
)) {
784 si
= netdev_priv(dev
);
785 netif_device_detach(dev
);
786 pxa_irda_shutdown(si
);
792 static int pxa_irda_resume(struct platform_device
*_dev
)
794 struct net_device
*dev
= platform_get_drvdata(_dev
);
797 if (dev
&& netif_running(dev
)) {
798 si
= netdev_priv(dev
);
799 pxa_irda_startup(si
);
800 netif_device_attach(dev
);
801 netif_wake_queue(dev
);
808 static int pxa_irda_init_iobuf(iobuff_t
*io
, int size
)
810 io
->head
= kmalloc(size
, GFP_KERNEL
| GFP_DMA
);
811 if (io
->head
!= NULL
) {
813 io
->in_frame
= FALSE
;
814 io
->state
= OUTSIDE_FRAME
;
817 return io
->head
? 0 : -ENOMEM
;
820 static const struct net_device_ops pxa_irda_netdev_ops
= {
821 .ndo_open
= pxa_irda_start
,
822 .ndo_stop
= pxa_irda_stop
,
823 .ndo_start_xmit
= pxa_irda_hard_xmit
,
824 .ndo_do_ioctl
= pxa_irda_ioctl
,
827 static int pxa_irda_probe(struct platform_device
*pdev
)
829 struct net_device
*dev
;
831 unsigned int baudrate_mask
;
834 if (!pdev
->dev
.platform_data
)
837 err
= request_mem_region(__PREG(STUART
), 0x24, "IrDA") ? 0 : -EBUSY
;
841 err
= request_mem_region(__PREG(FICP
), 0x1c, "IrDA") ? 0 : -EBUSY
;
845 dev
= alloc_irdadev(sizeof(struct pxa_irda
));
849 SET_NETDEV_DEV(dev
, &pdev
->dev
);
850 si
= netdev_priv(dev
);
851 si
->dev
= &pdev
->dev
;
852 si
->pdata
= pdev
->dev
.platform_data
;
854 si
->sir_clk
= clk_get(&pdev
->dev
, "UARTCLK");
855 si
->fir_clk
= clk_get(&pdev
->dev
, "FICPCLK");
856 if (IS_ERR(si
->sir_clk
) || IS_ERR(si
->fir_clk
)) {
857 err
= PTR_ERR(IS_ERR(si
->sir_clk
) ? si
->sir_clk
: si
->fir_clk
);
862 * Initialise the SIR buffers
864 err
= pxa_irda_init_iobuf(&si
->rx_buff
, 14384);
867 err
= pxa_irda_init_iobuf(&si
->tx_buff
, 4000);
871 if (gpio_is_valid(si
->pdata
->gpio_pwdown
)) {
872 err
= gpio_request(si
->pdata
->gpio_pwdown
, "IrDA switch");
875 err
= gpio_direction_output(si
->pdata
->gpio_pwdown
,
876 !si
->pdata
->gpio_pwdown_inverted
);
878 gpio_free(si
->pdata
->gpio_pwdown
);
883 if (si
->pdata
->startup
) {
884 err
= si
->pdata
->startup(si
->dev
);
889 if (gpio_is_valid(si
->pdata
->gpio_pwdown
) && si
->pdata
->startup
)
890 dev_warn(si
->dev
, "gpio_pwdown and startup() both defined!\n");
892 dev
->netdev_ops
= &pxa_irda_netdev_ops
;
894 irda_init_max_qos_capabilies(&si
->qos
);
897 if (si
->pdata
->transceiver_cap
& IR_SIRMODE
)
898 baudrate_mask
|= IR_9600
|IR_19200
|IR_38400
|IR_57600
|IR_115200
;
899 if (si
->pdata
->transceiver_cap
& IR_FIRMODE
)
900 baudrate_mask
|= IR_4000000
<< 8;
902 si
->qos
.baud_rate
.bits
&= baudrate_mask
;
903 si
->qos
.min_turn_time
.bits
= 7; /* 1ms or more */
905 irda_qos_bits_to_value(&si
->qos
);
907 err
= register_netdev(dev
);
910 dev_set_drvdata(&pdev
->dev
, dev
);
913 if (si
->pdata
->shutdown
)
914 si
->pdata
->shutdown(si
->dev
);
916 kfree(si
->tx_buff
.head
);
918 kfree(si
->rx_buff
.head
);
920 if (si
->sir_clk
&& !IS_ERR(si
->sir_clk
))
921 clk_put(si
->sir_clk
);
922 if (si
->fir_clk
&& !IS_ERR(si
->fir_clk
))
923 clk_put(si
->fir_clk
);
926 release_mem_region(__PREG(FICP
), 0x1c);
928 release_mem_region(__PREG(STUART
), 0x24);
934 static int pxa_irda_remove(struct platform_device
*_dev
)
936 struct net_device
*dev
= platform_get_drvdata(_dev
);
939 struct pxa_irda
*si
= netdev_priv(dev
);
940 unregister_netdev(dev
);
941 if (gpio_is_valid(si
->pdata
->gpio_pwdown
))
942 gpio_free(si
->pdata
->gpio_pwdown
);
943 if (si
->pdata
->shutdown
)
944 si
->pdata
->shutdown(si
->dev
);
945 kfree(si
->tx_buff
.head
);
946 kfree(si
->rx_buff
.head
);
947 clk_put(si
->fir_clk
);
948 clk_put(si
->sir_clk
);
952 release_mem_region(__PREG(STUART
), 0x24);
953 release_mem_region(__PREG(FICP
), 0x1c);
958 static struct platform_driver pxa_ir_driver
= {
961 .owner
= THIS_MODULE
,
963 .probe
= pxa_irda_probe
,
964 .remove
= pxa_irda_remove
,
965 .suspend
= pxa_irda_suspend
,
966 .resume
= pxa_irda_resume
,
969 static int __init
pxa_irda_init(void)
971 return platform_driver_register(&pxa_ir_driver
);
974 static void __exit
pxa_irda_exit(void)
976 platform_driver_unregister(&pxa_ir_driver
);
979 module_init(pxa_irda_init
);
980 module_exit(pxa_irda_exit
);
982 MODULE_LICENSE("GPL");
983 MODULE_ALIAS("platform:pxa2xx-ir");