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>
21 #include <net/irda/irda.h>
22 #include <net/irda/irmod.h>
23 #include <net/irda/wrapper.h>
24 #include <net/irda/irda_device.h>
27 #include <mach/irda.h>
28 #include <mach/regs-uart.h>
29 #include <mach/regs-ost.h>
31 #define FICP __REG(0x40800000) /* Start of FICP area */
32 #define ICCR0 __REG(0x40800000) /* ICP Control Register 0 */
33 #define ICCR1 __REG(0x40800004) /* ICP Control Register 1 */
34 #define ICCR2 __REG(0x40800008) /* ICP Control Register 2 */
35 #define ICDR __REG(0x4080000c) /* ICP Data Register */
36 #define ICSR0 __REG(0x40800014) /* ICP Status Register 0 */
37 #define ICSR1 __REG(0x40800018) /* ICP Status Register 1 */
39 #define ICCR0_AME (1 << 7) /* Address match enable */
40 #define ICCR0_TIE (1 << 6) /* Transmit FIFO interrupt enable */
41 #define ICCR0_RIE (1 << 5) /* Recieve FIFO interrupt enable */
42 #define ICCR0_RXE (1 << 4) /* Receive enable */
43 #define ICCR0_TXE (1 << 3) /* Transmit enable */
44 #define ICCR0_TUS (1 << 2) /* Transmit FIFO underrun select */
45 #define ICCR0_LBM (1 << 1) /* Loopback mode */
46 #define ICCR0_ITR (1 << 0) /* IrDA transmission */
48 #define ICCR2_RXP (1 << 3) /* Receive Pin Polarity select */
49 #define ICCR2_TXP (1 << 2) /* Transmit Pin Polarity select */
50 #define ICCR2_TRIG (3 << 0) /* Receive FIFO Trigger threshold */
51 #define ICCR2_TRIG_8 (0 << 0) /* >= 8 bytes */
52 #define ICCR2_TRIG_16 (1 << 0) /* >= 16 bytes */
53 #define ICCR2_TRIG_32 (2 << 0) /* >= 32 bytes */
56 #define ICSR0_EOC (1 << 6) /* DMA End of Descriptor Chain */
58 #define ICSR0_FRE (1 << 5) /* Framing error */
59 #define ICSR0_RFS (1 << 4) /* Receive FIFO service request */
60 #define ICSR0_TFS (1 << 3) /* Transnit FIFO service request */
61 #define ICSR0_RAB (1 << 2) /* Receiver abort */
62 #define ICSR0_TUR (1 << 1) /* Trunsmit FIFO underun */
63 #define ICSR0_EIF (1 << 0) /* End/Error in FIFO */
65 #define ICSR1_ROR (1 << 6) /* Receiver FIFO underrun */
66 #define ICSR1_CRE (1 << 5) /* CRC error */
67 #define ICSR1_EOF (1 << 4) /* End of frame */
68 #define ICSR1_TNF (1 << 3) /* Transmit FIFO not full */
69 #define ICSR1_RNE (1 << 2) /* Receive FIFO not empty */
70 #define ICSR1_TBY (1 << 1) /* Tramsmiter busy flag */
71 #define ICSR1_RSY (1 << 0) /* Recevier synchronized flag */
73 #define IrSR_RXPL_NEG_IS_ZERO (1<<4)
74 #define IrSR_RXPL_POS_IS_ZERO 0x0
75 #define IrSR_TXPL_NEG_IS_ZERO (1<<3)
76 #define IrSR_TXPL_POS_IS_ZERO 0x0
77 #define IrSR_XMODE_PULSE_1_6 (1<<2)
78 #define IrSR_XMODE_PULSE_3_16 0x0
79 #define IrSR_RCVEIR_IR_MODE (1<<1)
80 #define IrSR_RCVEIR_UART_MODE 0x0
81 #define IrSR_XMITIR_IR_MODE (1<<0)
82 #define IrSR_XMITIR_UART_MODE 0x0
84 #define IrSR_IR_RECEIVE_ON (\
85 IrSR_RXPL_NEG_IS_ZERO | \
86 IrSR_TXPL_POS_IS_ZERO | \
87 IrSR_XMODE_PULSE_3_16 | \
88 IrSR_RCVEIR_IR_MODE | \
89 IrSR_XMITIR_UART_MODE)
91 #define IrSR_IR_TRANSMIT_ON (\
92 IrSR_RXPL_NEG_IS_ZERO | \
93 IrSR_TXPL_POS_IS_ZERO | \
94 IrSR_XMODE_PULSE_3_16 | \
95 IrSR_RCVEIR_UART_MODE | \
101 unsigned long last_oscr;
103 unsigned char *dma_rx_buff;
104 unsigned char *dma_tx_buff;
105 dma_addr_t dma_rx_buff_phy;
106 dma_addr_t dma_tx_buff_phy;
107 unsigned int dma_tx_buff_len;
111 struct irlap_cb *irlap;
118 struct pxaficp_platform_data *pdata;
124 static inline void pxa_irda_disable_clk(struct pxa_irda *si)
127 clk_disable(si->cur_clk);
131 static inline void pxa_irda_enable_firclk(struct pxa_irda *si)
133 si->cur_clk = si->fir_clk;
134 clk_enable(si->fir_clk);
137 static inline void pxa_irda_enable_sirclk(struct pxa_irda *si)
139 si->cur_clk = si->sir_clk;
140 clk_enable(si->sir_clk);
144 #define IS_FIR(si) ((si)->speed >= 4000000)
145 #define IRDA_FRAME_SIZE_LIMIT 2047
147 inline static void pxa_irda_fir_dma_rx_start(struct pxa_irda *si)
149 DCSR(si->rxdma) = DCSR_NODESC;
150 DSADR(si->rxdma) = __PREG(ICDR);
151 DTADR(si->rxdma) = si->dma_rx_buff_phy;
152 DCMD(si->rxdma) = DCMD_INCTRGADDR | DCMD_FLOWSRC | DCMD_WIDTH1 | DCMD_BURST32 | IRDA_FRAME_SIZE_LIMIT;
153 DCSR(si->rxdma) |= DCSR_RUN;
156 inline static void pxa_irda_fir_dma_tx_start(struct pxa_irda *si)
158 DCSR(si->txdma) = DCSR_NODESC;
159 DSADR(si->txdma) = si->dma_tx_buff_phy;
160 DTADR(si->txdma) = __PREG(ICDR);
161 DCMD(si->txdma) = DCMD_INCSRCADDR | DCMD_FLOWTRG | DCMD_ENDIRQEN | DCMD_WIDTH1 | DCMD_BURST32 | si->dma_tx_buff_len;
162 DCSR(si->txdma) |= DCSR_RUN;
166 * Set the IrDA communications speed.
168 static int pxa_irda_set_speed(struct pxa_irda *si, int speed)
171 unsigned int divisor;
174 case 9600: case 19200: case 38400:
175 case 57600: case 115200:
177 /* refer to PXA250/210 Developer's Manual 10-7 */
178 /* BaudRate = 14.7456 MHz / (16*Divisor) */
179 divisor = 14745600 / (16 * speed);
181 local_irq_save(flags);
185 DCSR(si->rxdma) &= ~DCSR_RUN;
188 pxa_irda_disable_clk(si);
190 /* set board transceiver to SIR mode */
191 si->pdata->transceiver_mode(si->dev, IR_SIRMODE);
193 /* enable the STUART clock */
194 pxa_irda_enable_sirclk(si);
197 /* disable STUART first */
200 /* access DLL & DLH */
202 STDLL = divisor & 0xff;
203 STDLH = divisor >> 8;
207 STISR = IrSR_IR_RECEIVE_ON | IrSR_XMODE_PULSE_1_6;
208 STIER = IER_UUE | IER_RLSE | IER_RAVIE | IER_RTIOE;
210 local_irq_restore(flags);
214 local_irq_save(flags);
219 pxa_irda_disable_clk(si);
221 /* disable FICP first */
224 /* set board transceiver to FIR mode */
225 si->pdata->transceiver_mode(si->dev, IR_FIRMODE);
227 /* enable the FICP clock */
228 pxa_irda_enable_firclk(si);
231 pxa_irda_fir_dma_rx_start(si);
232 ICCR0 = ICCR0_ITR | ICCR0_RXE;
234 local_irq_restore(flags);
244 /* SIR interrupt service routine. */
245 static irqreturn_t pxa_irda_sir_irq(int irq, void *dev_id)
247 struct net_device *dev = dev_id;
248 struct pxa_irda *si = netdev_priv(dev);
253 switch (iir & 0x0F) {
254 case 0x06: /* Receiver Line Status */
256 while (lsr & LSR_FIFOE) {
258 if (lsr & (LSR_OE | LSR_PE | LSR_FE | LSR_BI)) {
259 printk(KERN_DEBUG "pxa_ir: sir receiving error\n");
260 dev->stats.rx_errors++;
262 dev->stats.rx_frame_errors++;
264 dev->stats.rx_fifo_errors++;
266 dev->stats.rx_bytes++;
267 async_unwrap_char(dev, &dev->stats,
272 si->last_oscr = OSCR;
275 case 0x04: /* Received Data Available */
278 case 0x0C: /* Character Timeout Indication */
280 dev->stats.rx_bytes++;
281 async_unwrap_char(dev, &dev->stats, &si->rx_buff, STRBR);
282 } while (STLSR & LSR_DR);
283 si->last_oscr = OSCR;
286 case 0x02: /* Transmit FIFO Data Request */
287 while ((si->tx_buff.len) && (STLSR & LSR_TDRQ)) {
288 STTHR = *si->tx_buff.data++;
289 si->tx_buff.len -= 1;
292 if (si->tx_buff.len == 0) {
293 dev->stats.tx_packets++;
294 dev->stats.tx_bytes += si->tx_buff.data - si->tx_buff.head;
296 /* We need to ensure that the transmitter has finished. */
297 while ((STLSR & LSR_TEMT) == 0)
299 si->last_oscr = OSCR;
302 * Ok, we've finished transmitting. Now enable
303 * the receiver. Sometimes we get a receive IRQ
304 * immediately after a transmit...
307 pxa_irda_set_speed(si, si->newspeed);
310 /* enable IR Receiver, disable IR Transmitter */
311 STISR = IrSR_IR_RECEIVE_ON | IrSR_XMODE_PULSE_1_6;
312 /* enable STUART and receive interrupts */
313 STIER = IER_UUE | IER_RLSE | IER_RAVIE | IER_RTIOE;
316 netif_wake_queue(dev);
324 /* FIR Receive DMA interrupt handler */
325 static void pxa_irda_fir_dma_rx_irq(int channel, void *data)
327 int dcsr = DCSR(channel);
329 DCSR(channel) = dcsr & ~DCSR_RUN;
331 printk(KERN_DEBUG "pxa_ir: fir rx dma bus error %#x\n", dcsr);
334 /* FIR Transmit DMA interrupt handler */
335 static void pxa_irda_fir_dma_tx_irq(int channel, void *data)
337 struct net_device *dev = data;
338 struct pxa_irda *si = netdev_priv(dev);
341 dcsr = DCSR(channel);
342 DCSR(channel) = dcsr & ~DCSR_RUN;
344 if (dcsr & DCSR_ENDINTR) {
345 dev->stats.tx_packets++;
346 dev->stats.tx_bytes += si->dma_tx_buff_len;
348 dev->stats.tx_errors++;
351 while (ICSR1 & ICSR1_TBY)
353 si->last_oscr = OSCR;
356 * HACK: It looks like the TBY bit is dropped too soon.
357 * Without this delay things break.
362 pxa_irda_set_speed(si, si->newspeed);
368 pxa_irda_fir_dma_rx_start(si);
369 while ((ICSR1 & ICSR1_RNE) && i--)
371 ICCR0 = ICCR0_ITR | ICCR0_RXE;
374 printk(KERN_ERR "pxa_ir: cannot clear Rx FIFO!\n");
376 netif_wake_queue(dev);
379 /* EIF(Error in FIFO/End in Frame) handler for FIR */
380 static void pxa_irda_fir_irq_eif(struct pxa_irda *si, struct net_device *dev, int icsr0)
382 unsigned int len, stat, data;
384 /* Get the current data position. */
385 len = DTADR(si->rxdma) - si->dma_rx_buff_phy;
388 /* Read Status, and then Data. */
393 if (stat & (ICSR1_CRE | ICSR1_ROR)) {
394 dev->stats.rx_errors++;
395 if (stat & ICSR1_CRE) {
396 printk(KERN_DEBUG "pxa_ir: fir receive CRC error\n");
397 dev->stats.rx_crc_errors++;
399 if (stat & ICSR1_ROR) {
400 printk(KERN_DEBUG "pxa_ir: fir receive overrun\n");
401 dev->stats.rx_over_errors++;
404 si->dma_rx_buff[len++] = data;
406 /* If we hit the end of frame, there's no point in continuing. */
407 if (stat & ICSR1_EOF)
409 } while (ICSR0 & ICSR0_EIF);
411 if (stat & ICSR1_EOF) {
415 if (icsr0 & ICSR0_FRE) {
416 printk(KERN_ERR "pxa_ir: dropping erroneous frame\n");
417 dev->stats.rx_dropped++;
421 skb = alloc_skb(len+1,GFP_ATOMIC);
423 printk(KERN_ERR "pxa_ir: fir out of memory for receive skb\n");
424 dev->stats.rx_dropped++;
428 /* Align IP header to 20 bytes */
430 skb_copy_to_linear_data(skb, si->dma_rx_buff, len);
433 /* Feed it to IrLAP */
435 skb_reset_mac_header(skb);
436 skb->protocol = htons(ETH_P_IRDA);
439 dev->stats.rx_packets++;
440 dev->stats.rx_bytes += len;
444 /* FIR interrupt handler */
445 static irqreturn_t pxa_irda_fir_irq(int irq, void *dev_id)
447 struct net_device *dev = dev_id;
448 struct pxa_irda *si = netdev_priv(dev);
452 DCSR(si->rxdma) &= ~DCSR_RUN;
453 si->last_oscr = OSCR;
456 if (icsr0 & (ICSR0_FRE | ICSR0_RAB)) {
457 if (icsr0 & ICSR0_FRE) {
458 printk(KERN_DEBUG "pxa_ir: fir receive frame error\n");
459 dev->stats.rx_frame_errors++;
461 printk(KERN_DEBUG "pxa_ir: fir receive abort\n");
462 dev->stats.rx_errors++;
464 ICSR0 = icsr0 & (ICSR0_FRE | ICSR0_RAB);
467 if (icsr0 & ICSR0_EIF) {
468 /* An error in FIFO occured, or there is a end of frame */
469 pxa_irda_fir_irq_eif(si, dev, icsr0);
473 pxa_irda_fir_dma_rx_start(si);
474 while ((ICSR1 & ICSR1_RNE) && i--)
476 ICCR0 = ICCR0_ITR | ICCR0_RXE;
479 printk(KERN_ERR "pxa_ir: cannot clear Rx FIFO!\n");
484 /* hard_xmit interface of irda device */
485 static int pxa_irda_hard_xmit(struct sk_buff *skb, struct net_device *dev)
487 struct pxa_irda *si = netdev_priv(dev);
488 int speed = irda_get_next_speed(skb);
491 * Does this packet contain a request to change the interface
492 * speed? If so, remember it until we complete the transmission
495 if (speed != si->speed && speed != -1)
496 si->newspeed = speed;
499 * If this is an empty frame, we can bypass a lot.
504 pxa_irda_set_speed(si, speed);
510 netif_stop_queue(dev);
513 si->tx_buff.data = si->tx_buff.head;
514 si->tx_buff.len = async_wrap_skb(skb, si->tx_buff.data, si->tx_buff.truesize);
516 /* Disable STUART interrupts and switch to transmit mode. */
518 STISR = IrSR_IR_TRANSMIT_ON | IrSR_XMODE_PULSE_1_6;
520 /* enable STUART and transmit interrupts */
521 STIER = IER_UUE | IER_TIE;
523 unsigned long mtt = irda_get_mtt(skb);
525 si->dma_tx_buff_len = skb->len;
526 skb_copy_from_linear_data(skb, si->dma_tx_buff, skb->len);
529 while ((unsigned)(OSCR - si->last_oscr)/4 < mtt)
532 /* stop RX DMA, disable FICP */
533 DCSR(si->rxdma) &= ~DCSR_RUN;
536 pxa_irda_fir_dma_tx_start(si);
537 ICCR0 = ICCR0_ITR | ICCR0_TXE;
541 dev->trans_start = jiffies;
545 static int pxa_irda_ioctl(struct net_device *dev, struct ifreq *ifreq, int cmd)
547 struct if_irda_req *rq = (struct if_irda_req *)ifreq;
548 struct pxa_irda *si = netdev_priv(dev);
554 if (capable(CAP_NET_ADMIN)) {
556 * We are unable to set the speed if the
557 * device is not running.
559 if (netif_running(dev)) {
560 ret = pxa_irda_set_speed(si,
563 printk(KERN_INFO "pxa_ir: SIOCSBANDWIDTH: !netif_running\n");
571 if (capable(CAP_NET_ADMIN)) {
572 irda_device_set_media_busy(dev, TRUE);
579 rq->ifr_receiving = IS_FIR(si) ? 0
580 : si->rx_buff.state != OUTSIDE_FRAME;
591 static void pxa_irda_startup(struct pxa_irda *si)
593 /* Disable STUART interrupts */
595 /* enable STUART interrupt to the processor */
597 /* configure SIR frame format: StartBit - Data 7 ... Data 0 - Stop Bit */
598 STLCR = LCR_WLS0 | LCR_WLS1;
599 /* enable FIFO, we use FIFO to improve performance */
600 STFCR = FCR_TRFIFOE | FCR_ITL_32;
604 /* configure FICP ICCR2 */
605 ICCR2 = ICCR2_TXP | ICCR2_TRIG_32;
608 DRCMR(17) = si->rxdma | DRCMR_MAPVLD;
609 DRCMR(18) = si->txdma | DRCMR_MAPVLD;
611 /* force SIR reinitialization */
613 pxa_irda_set_speed(si, 9600);
615 printk(KERN_DEBUG "pxa_ir: irda startup\n");
618 static void pxa_irda_shutdown(struct pxa_irda *si)
622 local_irq_save(flags);
624 /* disable STUART and interrupt */
626 /* disable STUART SIR mode */
630 DCSR(si->txdma) &= ~DCSR_RUN;
631 DCSR(si->rxdma) &= ~DCSR_RUN;
635 /* disable the STUART or FICP clocks */
636 pxa_irda_disable_clk(si);
641 local_irq_restore(flags);
643 /* power off board transceiver */
644 si->pdata->transceiver_mode(si->dev, IR_OFF);
646 printk(KERN_DEBUG "pxa_ir: irda shutdown\n");
649 static int pxa_irda_start(struct net_device *dev)
651 struct pxa_irda *si = netdev_priv(dev);
656 err = request_irq(IRQ_STUART, pxa_irda_sir_irq, 0, dev->name, dev);
660 err = request_irq(IRQ_ICP, pxa_irda_fir_irq, 0, dev->name, dev);
665 * The interrupt must remain disabled for now.
667 disable_irq(IRQ_STUART);
668 disable_irq(IRQ_ICP);
671 si->rxdma = pxa_request_dma("FICP_RX",DMA_PRIO_LOW, pxa_irda_fir_dma_rx_irq, dev);
675 si->txdma = pxa_request_dma("FICP_TX",DMA_PRIO_LOW, pxa_irda_fir_dma_tx_irq, dev);
680 si->dma_rx_buff = dma_alloc_coherent(si->dev, IRDA_FRAME_SIZE_LIMIT,
681 &si->dma_rx_buff_phy, GFP_KERNEL );
682 if (!si->dma_rx_buff)
683 goto err_dma_rx_buff;
685 si->dma_tx_buff = dma_alloc_coherent(si->dev, IRDA_FRAME_SIZE_LIMIT,
686 &si->dma_tx_buff_phy, GFP_KERNEL );
687 if (!si->dma_tx_buff)
688 goto err_dma_tx_buff;
690 /* Setup the serial port for the initial speed. */
691 pxa_irda_startup(si);
694 * Open a new IrLAP layer instance.
696 si->irlap = irlap_open(dev, &si->qos, "pxa");
702 * Now enable the interrupt and start the queue
704 enable_irq(IRQ_STUART);
706 netif_start_queue(dev);
708 printk(KERN_DEBUG "pxa_ir: irda driver opened\n");
713 pxa_irda_shutdown(si);
714 dma_free_coherent(si->dev, IRDA_FRAME_SIZE_LIMIT, si->dma_tx_buff, si->dma_tx_buff_phy);
716 dma_free_coherent(si->dev, IRDA_FRAME_SIZE_LIMIT, si->dma_rx_buff, si->dma_rx_buff_phy);
718 pxa_free_dma(si->txdma);
720 pxa_free_dma(si->rxdma);
722 free_irq(IRQ_ICP, dev);
724 free_irq(IRQ_STUART, dev);
730 static int pxa_irda_stop(struct net_device *dev)
732 struct pxa_irda *si = netdev_priv(dev);
734 netif_stop_queue(dev);
736 pxa_irda_shutdown(si);
740 irlap_close(si->irlap);
744 free_irq(IRQ_STUART, dev);
745 free_irq(IRQ_ICP, dev);
747 pxa_free_dma(si->rxdma);
748 pxa_free_dma(si->txdma);
751 dma_free_coherent(si->dev, IRDA_FRAME_SIZE_LIMIT, si->dma_tx_buff, si->dma_tx_buff_phy);
753 dma_free_coherent(si->dev, IRDA_FRAME_SIZE_LIMIT, si->dma_rx_buff, si->dma_rx_buff_phy);
755 printk(KERN_DEBUG "pxa_ir: irda driver closed\n");
759 static int pxa_irda_suspend(struct platform_device *_dev, pm_message_t state)
761 struct net_device *dev = platform_get_drvdata(_dev);
764 if (dev && netif_running(dev)) {
765 si = netdev_priv(dev);
766 netif_device_detach(dev);
767 pxa_irda_shutdown(si);
773 static int pxa_irda_resume(struct platform_device *_dev)
775 struct net_device *dev = platform_get_drvdata(_dev);
778 if (dev && netif_running(dev)) {
779 si = netdev_priv(dev);
780 pxa_irda_startup(si);
781 netif_device_attach(dev);
782 netif_wake_queue(dev);
789 static int pxa_irda_init_iobuf(iobuff_t *io, int size)
791 io->head = kmalloc(size, GFP_KERNEL | GFP_DMA);
792 if (io->head != NULL) {
794 io->in_frame = FALSE;
795 io->state = OUTSIDE_FRAME;
798 return io->head ? 0 : -ENOMEM;
801 static const struct net_device_ops pxa_irda_netdev_ops = {
802 .ndo_open = pxa_irda_start,
803 .ndo_stop = pxa_irda_stop,
804 .ndo_start_xmit = pxa_irda_hard_xmit,
805 .ndo_do_ioctl = pxa_irda_ioctl,
808 static int pxa_irda_probe(struct platform_device *pdev)
810 struct net_device *dev;
812 unsigned int baudrate_mask;
815 if (!pdev->dev.platform_data)
818 err = request_mem_region(__PREG(STUART), 0x24, "IrDA") ? 0 : -EBUSY;
822 err = request_mem_region(__PREG(FICP), 0x1c, "IrDA") ? 0 : -EBUSY;
826 dev = alloc_irdadev(sizeof(struct pxa_irda));
830 SET_NETDEV_DEV(dev, &pdev->dev);
831 si = netdev_priv(dev);
832 si->dev = &pdev->dev;
833 si->pdata = pdev->dev.platform_data;
835 si->sir_clk = clk_get(&pdev->dev, "UARTCLK");
836 si->fir_clk = clk_get(&pdev->dev, "FICPCLK");
837 if (IS_ERR(si->sir_clk) || IS_ERR(si->fir_clk)) {
838 err = PTR_ERR(IS_ERR(si->sir_clk) ? si->sir_clk : si->fir_clk);
843 * Initialise the SIR buffers
845 err = pxa_irda_init_iobuf(&si->rx_buff, 14384);
848 err = pxa_irda_init_iobuf(&si->tx_buff, 4000);
852 if (si->pdata->startup)
853 err = si->pdata->startup(si->dev);
857 dev->netdev_ops = &pxa_irda_netdev_ops;
859 irda_init_max_qos_capabilies(&si->qos);
862 if (si->pdata->transceiver_cap & IR_SIRMODE)
863 baudrate_mask |= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
864 if (si->pdata->transceiver_cap & IR_FIRMODE)
865 baudrate_mask |= IR_4000000 << 8;
867 si->qos.baud_rate.bits &= baudrate_mask;
868 si->qos.min_turn_time.bits = 7; /* 1ms or more */
870 irda_qos_bits_to_value(&si->qos);
872 err = register_netdev(dev);
875 dev_set_drvdata(&pdev->dev, dev);
878 if (si->pdata->shutdown)
879 si->pdata->shutdown(si->dev);
881 kfree(si->tx_buff.head);
883 kfree(si->rx_buff.head);
885 if (si->sir_clk && !IS_ERR(si->sir_clk))
886 clk_put(si->sir_clk);
887 if (si->fir_clk && !IS_ERR(si->fir_clk))
888 clk_put(si->fir_clk);
891 release_mem_region(__PREG(FICP), 0x1c);
893 release_mem_region(__PREG(STUART), 0x24);
899 static int pxa_irda_remove(struct platform_device *_dev)
901 struct net_device *dev = platform_get_drvdata(_dev);
904 struct pxa_irda *si = netdev_priv(dev);
905 unregister_netdev(dev);
906 if (si->pdata->shutdown)
907 si->pdata->shutdown(si->dev);
908 kfree(si->tx_buff.head);
909 kfree(si->rx_buff.head);
910 clk_put(si->fir_clk);
911 clk_put(si->sir_clk);
915 release_mem_region(__PREG(STUART), 0x24);
916 release_mem_region(__PREG(FICP), 0x1c);
921 static struct platform_driver pxa_ir_driver = {
924 .owner = THIS_MODULE,
926 .probe = pxa_irda_probe,
927 .remove = pxa_irda_remove,
928 .suspend = pxa_irda_suspend,
929 .resume = pxa_irda_resume,
932 static int __init pxa_irda_init(void)
934 return platform_driver_register(&pxa_ir_driver);
937 static void __exit pxa_irda_exit(void)
939 platform_driver_unregister(&pxa_ir_driver);
942 module_init(pxa_irda_init);
943 module_exit(pxa_irda_exit);
945 MODULE_LICENSE("GPL");
946 MODULE_ALIAS("platform:pxa2xx-ir");