2 * BRIEF MODULE DESCRIPTION
4 * Infra-red driver for the OMAP1610-H2 and OMAP1710-H3 Platforms
6 * (based on omap-sir.c)
8 * Copyright 2003 MontaVista Software Inc.
9 * Author: MontaVista Software, Inc.
12 * Copyright 2004 Texas Instruments.
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
22 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * You should have received a copy of the GNU General Public License along
31 * with this program; if not, write to the Free Software Foundation, Inc.,
32 * 675 Mass Ave, Cambridge, MA 02139, USA.
35 Feb 2004, Texas Instruments
36 - Ported to 2.6 kernel (Feb 2004).
38 Apr 2004, Texas Instruments
39 - Added support for H3 (Apr 2004).
40 Nov 2004, Texas Instruments
41 - Added support for Power Management.
45 #include <linux/config.h>
46 #include <linux/module.h>
47 #include <linux/types.h>
48 #include <linux/init.h>
49 #include <linux/errno.h>
50 #include <linux/netdevice.h>
51 #include <linux/slab.h>
52 #include <linux/rtnetlink.h>
53 #include <linux/interrupt.h>
54 #include <linux/delay.h>
55 #include <linux/ioport.h>
56 #include <linux/dma-mapping.h>
57 #include <linux/platform_device.h>
58 #include <linux/i2c.h>
60 #include <net/irda/irda.h>
61 #include <net/irda/irmod.h>
62 #include <net/irda/wrapper.h>
63 #include <net/irda/irda_device.h>
67 #include <asm/hardware.h>
68 #include <asm/serial.h>
69 #include <asm/mach-types.h>
71 #include <asm/arch/mux.h>
72 #include <asm/arch/gpio.h>
73 #include <asm/arch/irda.h>
75 #define UART3_EFR_EN (1 << 4)
76 #define UART3_MCR_EN_TCR_TLR (1 << 6)
78 #define UART3_LCR_WL_8 (3 << 0)
79 #define UART3_LCR_SP2 (1 << 2)
80 #define UART3_LCR_DIVEN (1 << 7)
82 #define UART3_FCR_FIFO_EN (1 << 0)
83 #define UART3_FCR_FIFO_RX (1 << 1)
84 #define UART3_FCR_FIFO_TX (1 << 2)
85 #define UART3_FCR_FIFO_DMA1 (1 << 3)
86 #define UART3_FCR_FIFO_TX_TRIG16 (1 << 4)
87 #define UART3_FCR_FIFO_RX_TRIG16 (1 << 6)
88 #define UART3_FCR_CONFIG UART3_FCR_FIFO_EN | UART3_FCR_FIFO_RX | \
89 UART3_FCR_FIFO_TX | UART3_FCR_FIFO_DMA1 | \
90 UART3_FCR_FIFO_TX_TRIG16 | \
91 UART3_FCR_FIFO_RX_TRIG16
93 #define UART3_SCR_TX_TRIG1 (1 << 6)
94 #define UART3_SCR_RX_TRIG1 (1 << 7)
96 #define UART3_MDR1_RESET (0x07)
97 #define UART3_MDR1_SIR (1 << 0)
98 #define UART3_MDR1_MIR (4 << 0)
99 #define UART3_MDR1_FIR (5 << 0)
100 #define UART3_MDR1_SIP_AUTO (1 << 6)
102 #define UART3_MDR2_TRIG1 (0 << 1)
103 #define UART3_MDR2_IRTX_UNDERRUN (1 << 0)
105 #define UART3_ACERG_TX_UNDERRUN_DIS (1 << 4)
106 #define UART3_ACERG_SD_MODE_LOW (1 << 6)
107 #define UART3_ACERG_DIS_IR_RX (1 << 5)
109 #define UART3_IER_EOF (1 << 5)
110 #define UART3_IER_CTS (1 << 7)
112 #define UART3_IIR_TX_STATUS (1 << 5)
113 #define UART3_IIR_EOF (0x80)
115 #define IS_FIR(si) ((si)->speed >= 4000000)
116 #define IRDA_FRAME_SIZE_LIMIT 4096
118 static int rx_state = 0; /* RX state for IOCTL */
122 int speed; /* Current IrDA speed */
125 struct net_device_stats stats;
126 struct irlap_cb *irlap;
132 dma_addr_t rx_buf_dma_phys; /* Physical adress of RX DMA buffer */
133 dma_addr_t tx_buf_dma_phys; /* Physical adress of TX DMA buffer */
135 void *rx_buf_dma_virt; /* Virtual adress of RX DMA buffer */
136 void *tx_buf_dma_virt; /* Virtual adress of TX DMA buffer */
139 struct omap_irda_config *pdata;
142 #define OMAP_IRDA_DEBUG 0
144 #if (OMAP_IRDA_DEBUG > 0)
145 #define DBG(format, args...) printk(KERN_ERR "%s(): " format, __FUNCTION__, ## args);
146 #define DBG_IRQ(format, args...) printk(KERN_ERR "%s(): " format, __FUNCTION__, ## args);
148 #define DBG(format, args...)
149 #define DBG_IRQ(format, args...)
152 #if (OMAP_IRDA_DEBUG > 1)
153 #define __ECHO_IN printk(KERN_ERR "%s: enter\n",__FUNCTION__);
154 #define __ECHO_OUT printk(KERN_ERR "%s: exit\n",__FUNCTION__);
160 #ifdef OMAP1610_IR_HARDWARE_DEBUG_ENABLE
161 #define HDBG_DELAY 200
163 void hard_debug1(u16 i)
167 OMAP1610_GPIO1_BASE + OMAP1610_GPIO_CLEAR_DATAOUT);
171 OMAP1610_GPIO1_BASE + OMAP1610_GPIO_SET_DATAOUT);
176 void hard_debug2(u16 i)
180 OMAP1610_GPIO1_BASE + OMAP1610_GPIO_CLEAR_DATAOUT);
184 OMAP1610_GPIO1_BASE + OMAP1610_GPIO_SET_DATAOUT);
189 #define HDBG1(i) hard_debug1(i)
190 #define HDBG2(i) hard_debug2(i)
196 static void inline uart_reg_out(int idx, u8 val)
198 omap_writeb(val, idx);
201 static u8 inline uart_reg_in(int idx)
203 u8 b = omap_readb(idx);
207 /* forward declarations */
208 extern void irda_device_setup(struct net_device *dev);
209 extern void omap_stop_dma(int lch);
210 static int omap_irda_set_speed(struct net_device *dev, int speed);
212 static void omap_irda_start_rx_dma(struct omap_irda *si)
214 /* default for h2/h3 */
215 unsigned long src_start = 0xfffb9800;
216 unsigned int trigger = 0;
218 if (machine_is_omap_h2() || machine_is_omap_h3()) {
219 src_start = UART3_RHR;
222 if (machine_is_omap_h4()) {
223 src_start = OMAP_UART3_BASE;
224 trigger = OMAP24XX_DMA_UART3_RX;
228 omap_set_dma_src_params(si->rx_dma_channel, 0x3, 0x0, src_start,
231 omap_enable_dma_irq(si->rx_dma_channel, 0x01);
233 omap_set_dma_dest_params(si->rx_dma_channel, 0x0, 0x1,
237 omap_set_dma_transfer_params(si->rx_dma_channel, 0x0,
238 IRDA_FRAME_SIZE_LIMIT, 0x1,
241 omap_start_dma(si->rx_dma_channel);
244 static void omap_start_tx_dma(struct omap_irda *si, int size)
246 /* default for h2/h3 */
247 unsigned long dest_start = 0xfffb9800;
248 unsigned int trigger = 0;
250 if (machine_is_omap_h2() || machine_is_omap_h3()) {
251 dest_start = UART3_THR;
254 if (machine_is_omap_h4()) {
255 dest_start = OMAP_UART3_BASE;
256 trigger = OMAP24XX_DMA_UART3_TX;
261 omap_set_dma_dest_params(si->tx_dma_channel, 0x03, 0x0,
263 omap_enable_dma_irq(si->tx_dma_channel, 0x01);
265 omap_set_dma_src_params(si->tx_dma_channel, 0x0, 0x1,
269 omap_set_dma_transfer_params(si->tx_dma_channel, 0x0, size, 0x1,
275 omap_start_dma(si->tx_dma_channel);
282 /* DMA RX callback - normally, we should not go here,
283 it calls only if something is going wrong
285 static void omap_irda_rx_dma_callback(int lch, u16 ch_status, void *data)
287 struct net_device *dev = data;
288 struct omap_irda *si = dev->priv;
290 printk(KERN_ERR "RX Transfer error or very big frame\n");
292 /* Clear interrupts */
293 uart_reg_in(UART3_IIR);
295 si->stats.rx_frame_errors++;
297 uart_reg_in(UART3_RESUME);
300 omap_irda_start_rx_dma(si);
304 /* DMA TX callback - calling when frame transfer has been finished */
306 static void omap_irda_tx_dma_callback(int lch, u16 ch_status, void *data)
308 struct net_device *dev = data;
309 struct omap_irda *si = dev->priv;
313 /*Stop DMA controller */
314 omap_stop_dma(si->tx_dma_channel);
321 * Set the IrDA communications speed.
322 * Interrupt have to be disabled here.
325 static int omap_irda_startup(struct net_device *dev)
327 struct omap_irda *si = dev->priv;
331 /* FIXME: use clk_* apis for UART3 clock*/
332 /* Enable UART3 clock and set UART3 to IrDA mode */
333 if (machine_is_omap_h2() || machine_is_omap_h3())
334 omap_writel(omap_readl(MOD_CONF_CTRL_0) | (1 << 31) | (1 << 15),
339 if (si->pdata->transceiver_mode && machine_is_omap_h2()) {
340 /* Is it select_irda on H2 ? */
341 omap_writel(omap_readl(FUNC_MUX_CTRL_A) | 7,
343 si->pdata->transceiver_mode(si->dev, IR_SIRMODE);
346 uart_reg_out(UART3_MDR1, UART3_MDR1_RESET); /* Reset mode */
348 /* Clear DLH and DLL */
349 uart_reg_out(UART3_LCR, UART3_LCR_DIVEN);
351 uart_reg_out(UART3_DLL, 0);
352 uart_reg_out(UART3_DLH, 0);
353 uart_reg_out(UART3_LCR, 0xbf); /* FIXME: Add #define */
355 uart_reg_out(UART3_EFR, UART3_EFR_EN);
356 uart_reg_out(UART3_LCR, UART3_LCR_DIVEN);
358 /* Enable access to UART3_TLR and UART3_TCR registers */
359 uart_reg_out(UART3_MCR, UART3_MCR_EN_TCR_TLR);
361 uart_reg_out(UART3_SCR, 0);
362 /* Set Rx trigger to 1 and Tx trigger to 1 */
363 uart_reg_out(UART3_TLR, 0);
365 /* Set LCR to 8 bits and 1 stop bit */
366 uart_reg_out(UART3_LCR, 0x03);
368 /* Clear RX and TX FIFO and enable FIFO */
369 /* Use DMA Req for transfers */
370 uart_reg_out(UART3_FCR, UART3_FCR_CONFIG);
372 uart_reg_out(UART3_MCR, 0);
374 uart_reg_out(UART3_SCR, UART3_SCR_TX_TRIG1 |
377 /* Enable UART3 SIR Mode,(Frame-length method to end frames) */
378 uart_reg_out(UART3_MDR1, UART3_MDR1_SIR);
380 /* Set Status FIFO trig to 1 */
381 uart_reg_out(UART3_MDR2, 0);
383 /* Enables RXIR input */
384 /* and disable TX underrun */
386 uart_reg_out(UART3_ACREG, UART3_ACERG_SD_MODE_LOW |
387 UART3_ACERG_TX_UNDERRUN_DIS);
389 /* Enable EOF Interrupt only */
390 uart_reg_out(UART3_IER, UART3_IER_CTS | UART3_IER_EOF);
392 /* Set Maximum Received Frame size to 2048 bytes */
393 uart_reg_out(UART3_RXFLL, 0x00);
394 uart_reg_out(UART3_RXFLH, 0x08);
396 uart_reg_in(UART3_RESUME);
404 static int omap_irda_shutdown(struct omap_irda *si)
408 local_irq_save(flags);
410 /* Disable all UART3 Interrupts */
411 uart_reg_out(UART3_IER, 0);
413 /* Disable UART3 and disable baud rate generator */
414 uart_reg_out(UART3_MDR1, UART3_MDR1_RESET);
416 /* set SD_MODE pin to high and Disable RX IR */
417 uart_reg_out(UART3_ACREG, (UART3_ACERG_DIS_IR_RX |
418 ~(UART3_ACERG_SD_MODE_LOW)));
420 /* Clear DLH and DLL */
421 uart_reg_out(UART3_LCR, UART3_LCR_DIVEN);
422 uart_reg_out(UART3_DLL, 0);
423 uart_reg_out(UART3_DLH, 0);
425 local_irq_restore(flags);
431 omap_irda_irq(int irq, void *dev_id, struct pt_regs *hw_regs)
433 struct net_device *dev = dev_id;
434 struct omap_irda *si = dev->priv;
442 /* Clear EOF interrupt */
443 status = uart_reg_in(UART3_IIR);
445 if (status & UART3_IIR_TX_STATUS) {
446 u8 mdr2 = uart_reg_in(UART3_MDR2);
448 if (mdr2 & UART3_MDR2_IRTX_UNDERRUN)
449 printk(KERN_ERR "IrDA Buffer underrun error\n");
451 si->stats.tx_packets++;
454 omap_irda_set_speed(dev, si->newspeed);
458 netif_wake_queue(dev);
459 if (!(status & UART3_IIR_EOF))
463 /* Stop DMA and if there are no errors, send frame to upper layer */
464 omap_stop_dma(si->rx_dma_channel);
466 status = uart_reg_in(UART3_SFLSR); /* Take a frame status */
468 if (status != 0) { /* Bad frame? */
469 si->stats.rx_frame_errors++;
470 uart_reg_in(UART3_RESUME);
472 /* We got a frame! */
473 skb = alloc_skb(IRDA_FRAME_SIZE_LIMIT, GFP_ATOMIC);
476 printk(KERN_ERR "omap_sir: out of memory for RX SKB\n");
480 * Align any IP headers that may be contained
486 w = OMAP_DMA_CDAC_REG(si->rx_dma_channel);
488 if (cpu_is_omap16xx())
489 w -= OMAP1_DMA_CDSA_L_REG(si->rx_dma_channel);
490 if (cpu_is_omap24xx())
491 w -= OMAP2_DMA_CDSA_REG(si->rx_dma_channel);
494 /* Copy DMA buffer to skb */
495 memcpy(skb_put(skb, w - 2), si->rx_buf_dma_virt, w - 2);
497 /* Copy DMA buffer to skb */
498 memcpy(skb_put(skb, w - 4), si->rx_buf_dma_virt, w - 4);
502 skb->mac.raw = skb->data;
503 skb->protocol = htons(ETH_P_IRDA);
504 si->stats.rx_packets++;
505 si->stats.rx_bytes += skb->len;
506 netif_receive_skb(skb); /* Send data to upper level */
510 omap_irda_start_rx_dma(si);
512 dev->last_rx = jiffies;
519 static int omap_irda_hard_xmit(struct sk_buff *skb, struct net_device *dev)
521 struct omap_irda *si = dev->priv;
522 int speed = irda_get_next_speed(skb);
523 int mtt = irda_get_mtt(skb);
524 int xbofs = irda_get_next_xbofs(skb);
529 * Does this packet contain a request to change the interface
530 * speed? If so, remember it until we complete the transmission
533 if (speed != si->speed && speed != -1)
534 si->newspeed = speed;
537 /* Set number of addtional BOFS */
538 uart_reg_out(UART3_EBLR, xbofs + 1);
542 * If this is an empty frame, we can bypass a lot.
547 omap_irda_set_speed(dev, speed);
553 netif_stop_queue(dev);
555 /* Copy skb data to DMA buffer */
556 memcpy(si->tx_buf_dma_virt, skb->data, skb->len);
558 /* Copy skb data to DMA buffer */
559 si->stats.tx_bytes += skb->len;
561 /* Set frame length */
562 uart_reg_out(UART3_TXFLL, (skb->len & 0xff));
563 uart_reg_out(UART3_TXFLH, (skb->len >> 8));
570 /* Start TX DMA transfer */
571 omap_start_tx_dma(si, skb->len);
573 /* We can free skb now because it's already in DMA buffer */
576 dev->trans_start = jiffies;
584 omap_irda_ioctl(struct net_device *dev, struct ifreq *ifreq, int cmd)
586 struct if_irda_req *rq = (struct if_irda_req *)ifreq;
587 struct omap_irda *si = dev->priv;
588 int ret = -EOPNOTSUPP;
594 if (capable(CAP_NET_ADMIN)) {
596 * We are unable to set the speed if the
597 * device is not running.
601 omap_irda_set_speed(dev, rq->ifr_baudrate);
603 printk(KERN_ERR "omap_irda_ioctl: SIOCSBANDWIDTH: !netif_running\n");
611 if (capable(CAP_NET_ADMIN)) {
612 irda_device_set_media_busy(dev, TRUE);
618 rq->ifr_receiving = rx_state;
630 static struct net_device_stats *omap_irda_stats(struct net_device *dev)
632 struct omap_irda *si = dev->priv;
636 static int omap_irda_start(struct net_device *dev)
638 struct omap_irda *si = dev->priv;
640 int rx_channel = OMAP_DMA_NO_DEVICE;
641 int tx_channel = OMAP_DMA_NO_DEVICE;
646 err = request_irq(dev->irq, omap_irda_irq, 0, dev->name, dev);
651 * The interrupt must remain disabled for now.
653 disable_irq(dev->irq);
655 /* FIXME: These info can come from board-* files, if no one
658 if (machine_is_omap_h2() || machine_is_omap_h3()) {
659 rx_channel = OMAP_DMA_UART3_RX;
660 tx_channel = OMAP_DMA_UART3_TX;
662 if (machine_is_omap_h4()) {
663 rx_channel = OMAP24XX_DMA_UART3_RX;
664 tx_channel = OMAP24XX_DMA_UART3_TX;
667 /* Request DMA channels for IrDA hardware */
668 if (omap_request_dma(rx_channel, "IrDA Rx DMA",
669 (void *)omap_irda_rx_dma_callback,
670 dev, &(si->rx_dma_channel))) {
671 printk(KERN_ERR "Failed to request IrDA Rx DMA\n");
675 if (omap_request_dma(tx_channel, "IrDA Tx DMA",
676 (void *)omap_irda_tx_dma_callback,
677 dev, &(si->tx_dma_channel))) {
678 printk(KERN_ERR "Failed to request IrDA Tx DMA\n");
682 /* Allocate TX and RX buffers for DMA channels */
683 si->rx_buf_dma_virt =
684 dma_alloc_coherent(NULL, IRDA_FRAME_SIZE_LIMIT, &(si->rx_buf_dma_phys),
687 si->tx_buf_dma_virt =
688 dma_alloc_coherent(NULL, IRDA_FRAME_SIZE_LIMIT, &(si->tx_buf_dma_phys),
692 * Setup the serial port for the specified config.
694 if (si->pdata->select_irda)
695 si->pdata->select_irda(si->dev, IR_SEL);
697 err = omap_irda_startup(dev);
702 omap_irda_set_speed(dev, si->speed = 9600);
705 * Open a new IrLAP layer instance.
707 si->irlap = irlap_open(dev, &si->qos, "omap_sir");
713 /* Now enable the interrupt and start the queue */
717 omap_irda_start_rx_dma(si);
719 enable_irq(dev->irq);
720 netif_start_queue(dev);
728 omap_irda_shutdown(si);
731 free_irq(dev->irq, dev);
735 static int omap_irda_stop(struct net_device *dev)
737 struct omap_irda *si = dev->priv;
741 disable_irq(dev->irq);
743 netif_stop_queue(dev);
745 omap_free_dma(si->rx_dma_channel);
746 omap_free_dma(si->tx_dma_channel);
748 if (si->rx_buf_dma_virt)
749 dma_free_coherent(NULL, IRDA_FRAME_SIZE_LIMIT,
750 si->rx_buf_dma_virt, si->rx_buf_dma_phys);
751 if (si->tx_buf_dma_virt)
752 dma_free_coherent(NULL, IRDA_FRAME_SIZE_LIMIT,
753 si->tx_buf_dma_virt, si->tx_buf_dma_phys);
755 omap_irda_shutdown(si);
759 irlap_close(si->irlap);
768 free_irq(dev->irq, dev);
775 static int omap_irda_set_speed(struct net_device *dev, int speed)
777 struct omap_irda *si = dev->priv;
784 if (speed <= 115200) {
786 local_irq_save(flags);
789 if (si->pdata->transceiver_mode)
790 si->pdata->transceiver_mode(si->dev, IR_SIRMODE);
793 uart_reg_out(UART3_MDR1, 1);
794 uart_reg_out(UART3_EBLR, 1);
796 divisor = 48000000 / (16 * speed); /* Base clock 48 MHz */
800 uart_reg_out(UART3_LCR, UART3_LCR_DIVEN);
801 uart_reg_out(UART3_DLL, (divisor & 0xff));
802 uart_reg_out(UART3_DLH, (divisor >> 8));
803 uart_reg_out(UART3_LCR, 0x03);
805 uart_reg_out(UART3_MCR, 0);
809 local_irq_restore(flags);
811 } else if (speed <= 1152000) {
813 local_irq_save(flags);
815 /* Set MIR mode, auto SIP */
816 uart_reg_out(UART3_MDR1, UART3_MDR1_MIR |
817 UART3_MDR1_SIP_AUTO);
819 uart_reg_out(UART3_EBLR, 2);
821 divisor = 48000000 / (41 * speed); /* Base clock 48 MHz */
823 uart_reg_out(UART3_LCR, UART3_LCR_DIVEN);
824 uart_reg_out(UART3_DLL, (divisor & 0xff));
825 uart_reg_out(UART3_DLH, (divisor >> 8));
826 uart_reg_out(UART3_LCR, 0x03);
828 if (si->pdata->transceiver_mode)
829 si->pdata->transceiver_mode(si->dev, IR_MIRMODE);
831 local_irq_restore(flags);
834 local_irq_save(flags);
837 uart_reg_out(UART3_MDR1, UART3_MDR1_FIR |
838 UART3_MDR1_SIP_AUTO);
840 if (si->pdata->transceiver_mode)
841 si->pdata->transceiver_mode(si->dev, IR_FIRMODE);
843 local_irq_restore(flags);
856 * Suspend the IrDA interface.
858 static int omap_irda_suspend(struct platform_device *pdev, pm_message_t state)
860 struct net_device *dev = platform_get_drvdata(pdev);
861 struct omap_irda *si = dev->priv;
868 * Stop the transmit queue
870 netif_device_detach(dev);
871 disable_irq(dev->irq);
872 omap_irda_shutdown(si);
878 * Resume the IrDA interface.
880 static int omap_irda_resume(struct platform_device *pdev)
882 struct net_device *dev = platform_get_drvdata(pdev);
883 struct omap_irda *si= dev->priv;
890 * If we missed a speed change, initialise at the new speed
891 * directly. It is debatable whether this is actually
892 * required, but in the interests of continuing from where
893 * we left off it is desireable. The converse argument is
894 * that we should re-negotiate at 9600 baud again.
897 si->speed = si->newspeed;
901 omap_irda_startup(dev);
902 omap_irda_set_speed(dev, si->speed);
903 enable_irq(dev->irq);
906 * This automatically wakes up the queue
908 netif_device_attach(dev);
914 #define omap_irda_suspend NULL
915 #define omap_irda_resume NULL
918 static int omap_irda_probe(struct platform_device *pdev)
920 struct net_device *dev;
921 struct omap_irda *si;
922 unsigned int baudrate_mask;
926 if (!pdev->dev.platform_data) {
927 printk(KERN_ERR "IrDA Platform data not supplied\n");
931 dev = alloc_irdadev(sizeof(struct omap_irda));
935 irq = platform_get_irq(pdev, 0);
937 printk(KERN_WARNING "no irq for IrDA\n");
942 si->dev = &pdev->dev;
943 si->pdata = pdev->dev.platform_data;
945 dev->hard_start_xmit = omap_irda_hard_xmit;
946 dev->open = omap_irda_start;
947 dev->stop = omap_irda_stop;
948 dev->do_ioctl = omap_irda_ioctl;
949 dev->get_stats = omap_irda_stats;
952 irda_init_max_qos_capabilies(&si->qos);
955 if (si->pdata->transceiver_cap & IR_SIRMODE)
956 baudrate_mask |= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
957 if (si->pdata->transceiver_cap & IR_MIRMODE)
958 baudrate_mask |= IR_57600 | IR_1152000;
959 if (si->pdata->transceiver_cap & IR_FIRMODE)
960 baudrate_mask |= IR_4000000 << 8;
962 si->qos.baud_rate.bits &= baudrate_mask;
963 si->qos.min_turn_time.bits = 7;
965 irda_qos_bits_to_value(&si->qos);
967 /* Any better way to avoid this? No. */
968 if (machine_is_omap_h3() || machine_is_omap_h4()) {
969 INIT_WORK(&si->pdata->gpio_expa, NULL, NULL);
972 err = register_netdev(dev);
974 platform_set_drvdata(pdev, dev);
982 static int omap_irda_remove(struct platform_device *pdev)
984 struct net_device *dev = platform_get_drvdata(pdev);
987 unregister_netdev(dev);
993 static struct platform_driver omapir_driver = {
994 .probe = omap_irda_probe,
995 .remove = omap_irda_remove,
996 .suspend = omap_irda_suspend,
997 .resume = omap_irda_resume,
1003 static char __initdata banner[] = "OMAP IrDA driver\n";
1005 static int __init omap_irda_init(void)
1008 return platform_driver_register(&omapir_driver);
1011 static void __exit omap_irda_exit(void)
1013 platform_driver_unregister(&omapir_driver);
1016 module_init(omap_irda_init);
1017 module_exit(omap_irda_exit);
1019 MODULE_AUTHOR("MontaVista");
1020 MODULE_DESCRIPTION("OMAP IrDA Driver");
1021 MODULE_LICENSE("GPL");