]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/irda/pxaficp_ir.c
net drivers: fix platform driver hotplug/coldplug
[linux-2.6-omap-h63xx.git] / drivers / net / irda / pxaficp_ir.c
index 9137e239fac2e55120fed2520db2dccbe5bfcbe9..60b94bb4d25e060fe33ff2cbeedb4e8b0f6f9fc8 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
+#include <linux/clk.h>
 
 #include <net/irda/irda.h>
 #include <net/irda/irmod.h>
@@ -87,8 +88,30 @@ struct pxa_irda {
 
        struct device           *dev;
        struct pxaficp_platform_data *pdata;
+       struct clk              *fir_clk;
+       struct clk              *sir_clk;
+       struct clk              *cur_clk;
 };
 
+static inline void pxa_irda_disable_clk(struct pxa_irda *si)
+{
+       if (si->cur_clk)
+               clk_disable(si->cur_clk);
+       si->cur_clk = NULL;
+}
+
+static inline void pxa_irda_enable_firclk(struct pxa_irda *si)
+{
+       si->cur_clk = si->fir_clk;
+       clk_enable(si->fir_clk);
+}
+
+static inline void pxa_irda_enable_sirclk(struct pxa_irda *si)
+{
+       si->cur_clk = si->sir_clk;
+       clk_enable(si->sir_clk);
+}
+
 
 #define IS_FIR(si)             ((si)->speed >= 4000000)
 #define IRDA_FRAME_SIZE_LIMIT  2047
@@ -134,7 +157,7 @@ static int pxa_irda_set_speed(struct pxa_irda *si, int speed)
                        DCSR(si->rxdma) &= ~DCSR_RUN;
                        /* disable FICP */
                        ICCR0 = 0;
-                       pxa_set_cken(CKEN13_FICP, 0);
+                       pxa_irda_disable_clk(si);
 
                        /* set board transceiver to SIR mode */
                        si->pdata->transceiver_mode(si->dev, IR_SIRMODE);
@@ -144,7 +167,7 @@ static int pxa_irda_set_speed(struct pxa_irda *si, int speed)
                        pxa_gpio_mode(GPIO47_STTXD_MD);
 
                        /* enable the STUART clock */
-                       pxa_set_cken(CKEN5_STUART, 1);
+                       pxa_irda_enable_sirclk(si);
                }
 
                /* disable STUART first */
@@ -169,7 +192,7 @@ static int pxa_irda_set_speed(struct pxa_irda *si, int speed)
                /* disable STUART */
                STIER = 0;
                STISR = 0;
-               pxa_set_cken(CKEN5_STUART, 0);
+               pxa_irda_disable_clk(si);
 
                /* disable FICP first */
                ICCR0 = 0;
@@ -182,7 +205,7 @@ static int pxa_irda_set_speed(struct pxa_irda *si, int speed)
                pxa_gpio_mode(GPIO47_ICPTXD_MD);
 
                /* enable the FICP clock */
-               pxa_set_cken(CKEN13_FICP, 1);
+               pxa_irda_enable_firclk(si);
 
                si->speed = speed;
                pxa_irda_fir_dma_rx_start(si);
@@ -321,15 +344,22 @@ static void pxa_irda_fir_dma_tx_irq(int channel, void *data)
                pxa_irda_set_speed(si, si->newspeed);
                si->newspeed = 0;
        } else {
+               int i = 64;
+
                ICCR0 = 0;
                pxa_irda_fir_dma_rx_start(si);
+               while ((ICSR1 & ICSR1_RNE) && i--)
+                       (void)ICDR;
                ICCR0 = ICCR0_ITR | ICCR0_RXE;
+
+               if (i < 0)
+                       printk(KERN_ERR "pxa_ir: cannot clear Rx FIFO!\n");
        }
        netif_wake_queue(dev);
 }
 
 /* EIF(Error in FIFO/End in Frame) handler for FIR */
-static void pxa_irda_fir_irq_eif(struct pxa_irda *si, struct net_device *dev)
+static void pxa_irda_fir_irq_eif(struct pxa_irda *si, struct net_device *dev, int icsr0)
 {
        unsigned int len, stat, data;
 
@@ -350,7 +380,7 @@ static void pxa_irda_fir_irq_eif(struct pxa_irda *si, struct net_device *dev)
                        }
                        if (stat & ICSR1_ROR) {
                                printk(KERN_DEBUG "pxa_ir: fir receive overrun\n");
-                               si->stats.rx_frame_errors++;
+                               si->stats.rx_over_errors++;
                        }
                } else  {
                        si->dma_rx_buff[len++] = data;
@@ -362,7 +392,15 @@ static void pxa_irda_fir_irq_eif(struct pxa_irda *si, struct net_device *dev)
 
        if (stat & ICSR1_EOF) {
                /* end of frame. */
-               struct sk_buff *skb = alloc_skb(len+1,GFP_ATOMIC);
+               struct sk_buff *skb;
+
+               if (icsr0 & ICSR0_FRE) {
+                       printk(KERN_ERR "pxa_ir: dropping erroneous frame\n");
+                       si->stats.rx_dropped++;
+                       return;
+               }
+
+               skb = alloc_skb(len+1,GFP_ATOMIC);
                if (!skb)  {
                        printk(KERN_ERR "pxa_ir: fir out of memory for receive skb\n");
                        si->stats.rx_dropped++;
@@ -371,12 +409,12 @@ static void pxa_irda_fir_irq_eif(struct pxa_irda *si, struct net_device *dev)
 
                /* Align IP header to 20 bytes  */
                skb_reserve(skb, 1);
-               memcpy(skb->data, si->dma_rx_buff, len);
+               skb_copy_to_linear_data(skb, si->dma_rx_buff, len);
                skb_put(skb, len);
 
                /* Feed it to IrLAP  */
                skb->dev = dev;
-               skb->mac.raw  = skb->data;
+               skb_reset_mac_header(skb);
                skb->protocol = htons(ETH_P_IRDA);
                netif_rx(skb);
 
@@ -392,7 +430,7 @@ static irqreturn_t pxa_irda_fir_irq(int irq, void *dev_id)
 {
        struct net_device *dev = dev_id;
        struct pxa_irda *si = netdev_priv(dev);
-       int icsr0;
+       int icsr0, i = 64;
 
        /* stop RX DMA */
        DCSR(si->rxdma) &= ~DCSR_RUN;
@@ -412,13 +450,18 @@ static irqreturn_t pxa_irda_fir_irq(int irq, void *dev_id)
 
        if (icsr0 & ICSR0_EIF) {
                /* An error in FIFO occured, or there is a end of frame */
-               pxa_irda_fir_irq_eif(si, dev);
+               pxa_irda_fir_irq_eif(si, dev, icsr0);
        }
 
        ICCR0 = 0;
        pxa_irda_fir_dma_rx_start(si);
+       while ((ICSR1 & ICSR1_RNE) && i--)
+               (void)ICDR;
        ICCR0 = ICCR0_ITR | ICCR0_RXE;
 
+       if (i < 0)
+               printk(KERN_ERR "pxa_ir: cannot clear Rx FIFO!\n");
+
        return IRQ_HANDLED;
 }
 
@@ -464,7 +507,7 @@ static int pxa_irda_hard_xmit(struct sk_buff *skb, struct net_device *dev)
                unsigned long mtt = irda_get_mtt(skb);
 
                si->dma_tx_buff_len = skb->len;
-               memcpy(si->dma_tx_buff, skb->data, skb->len);
+               skb_copy_from_linear_data(skb, si->dma_tx_buff, skb->len);
 
                if (mtt)
                        while ((unsigned)(OSCR - si->last_oscr)/4 < mtt)
@@ -572,16 +615,15 @@ static void pxa_irda_shutdown(struct pxa_irda *si)
        STIER = 0;
        /* disable STUART SIR mode */
        STISR = 0;
-       /* disable the STUART clock */
-       pxa_set_cken(CKEN5_STUART, 0);
 
        /* disable DMA */
        DCSR(si->txdma) &= ~DCSR_RUN;
        DCSR(si->rxdma) &= ~DCSR_RUN;
        /* disable FICP */
        ICCR0 = 0;
-       /* disable the FICP clock */
-       pxa_set_cken(CKEN13_FICP, 0);
+
+       /* disable the STUART or FICP clocks */
+       pxa_irda_disable_clk(si);
 
        DRCMR17 = 0;
        DRCMR18 = 0;
@@ -772,6 +814,13 @@ static int pxa_irda_probe(struct platform_device *pdev)
        si->dev = &pdev->dev;
        si->pdata = pdev->dev.platform_data;
 
+       si->sir_clk = clk_get(&pdev->dev, "UARTCLK");
+       si->fir_clk = clk_get(&pdev->dev, "FICPCLK");
+       if (IS_ERR(si->sir_clk) || IS_ERR(si->fir_clk)) {
+               err = PTR_ERR(IS_ERR(si->sir_clk) ? si->sir_clk : si->fir_clk);
+               goto err_mem_4;
+       }
+
        /*
         * Initialise the SIR buffers
         */
@@ -811,6 +860,10 @@ static int pxa_irda_probe(struct platform_device *pdev)
 err_mem_5:
                kfree(si->rx_buff.head);
 err_mem_4:
+               if (si->sir_clk && !IS_ERR(si->sir_clk))
+                       clk_put(si->sir_clk);
+               if (si->fir_clk && !IS_ERR(si->fir_clk))
+                       clk_put(si->fir_clk);
                free_netdev(dev);
 err_mem_3:
                release_mem_region(__PREG(FICP), 0x1c);
@@ -830,6 +883,8 @@ static int pxa_irda_remove(struct platform_device *_dev)
                unregister_netdev(dev);
                kfree(si->tx_buff.head);
                kfree(si->rx_buff.head);
+               clk_put(si->fir_clk);
+               clk_put(si->sir_clk);
                free_netdev(dev);
        }
 
@@ -842,6 +897,7 @@ static int pxa_irda_remove(struct platform_device *_dev)
 static struct platform_driver pxa_ir_driver = {
        .driver         = {
                .name   = "pxa2xx-ir",
+               .owner  = THIS_MODULE,
        },
        .probe          = pxa_irda_probe,
        .remove         = pxa_irda_remove,
@@ -863,3 +919,4 @@ module_init(pxa_irda_init);
 module_exit(pxa_irda_exit);
 
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pxa2xx-ir");