newton: improve irda driver
authorlyx <lyx@rock-chips.com>
Wed, 14 Sep 2011 01:40:48 +0000 (18:40 -0700)
committerlyx <lyx@rock-chips.com>
Wed, 14 Sep 2011 04:12:49 +0000 (21:12 -0700)
1.去掉一些关键地方的打印信息,解决FIR大数据量快速传输时的丢包问题

drivers/net/irda/ir_serial.c

index e5ae48cea4b90ee0e9e5ce3197ded4bf06661515..36fefebb0ffd3eae4efc978a2207e538f051501c 100755 (executable)
@@ -60,6 +60,7 @@ struct bu92747_port {
 \r
        int rx_enabled;         /* if we should rx chars */\r
 \r
+       int irq_pin;\r
        int irq;                /* irq assigned to the bu92747 */\r
 \r
        int minor;              /* minor number */\r
@@ -68,6 +69,7 @@ struct bu92747_port {
        struct work_struct work;\r
        /* set to 1 to make the workhandler exit as soon as possible */\r
        int  force_end_work;\r
+       \r
        int open_flag;\r
        /* need to know we are suspending to avoid deadlock on workqueue */\r
        int suspending;\r
@@ -85,11 +87,22 @@ static int max_rate = 4000000;
 static u8 g_receive_buf[BU92725GUW_FIFO_SIZE];\r
 \r
 #if 0\r
-#define BU92747_IRDA_DBG(x...) printk(x)\r
+#define IRDA_DBG_FUNC(x...) printk(x)\r
+#else\r
+#define IRDA_DBG_FUNC(x...)\r
+#endif\r
+\r
+#if 0\r
+#define IRDA_DBG_RECV(x...) printk(x)\r
 #else\r
-#define BU92747_IRDA_DBG(x...)\r
+#define IRDA_DBG_RECV(x...)\r
 #endif\r
 \r
+#if 1\r
+#define IRDA_DBG_SENT(x...) printk(x)\r
+#else\r
+#define IRDA_DBG_SENT(x...)\r
+#endif\r
 \r
 /* race on startup&shutdown, mutex lock with CIR driver */\r
 static DEFINE_MUTEX(irda_cir_lock);\r
@@ -112,12 +125,8 @@ static int add_frame_length(struct rev_frame_length *f, unsigned long length)
                return -1;\r
 \r
        f->frame_length[f->iWrite] = length;\r
-       //printk("add one frame, length=%ld\n", f->frame_length[f->iWrite]);\r
        f->iCount++;\r
-       //printk("now frame iCount=%d\n", f->iCount);\r
-       f->iWrite = (f->iWrite+1) % MAX_FRAME_NUM;\r
-       //printk("now frame iWrite=%d\n", f->iWrite);\r
-       \r
+       f->iWrite = (f->iWrite+1) % MAX_FRAME_NUM;      \r
        \r
        return 0;\r
 }\r
@@ -128,11 +137,8 @@ static int get_frame_length(struct rev_frame_length *f, unsigned long *length)
                return -1;\r
 \r
        *length = f->frame_length[f->iRead];\r
-       //printk("read one frame, length=%ld\n", *length);\r
        f->iCount--;\r
-       //printk("now frame iCount=%d\n", f->iCount);\r
        f->iRead = (f->iRead+1) % MAX_FRAME_NUM;\r
-       //printk("now frame iRead=%d\n", f->iRead);\r
        \r
        return 0;\r
 }\r
@@ -143,7 +149,7 @@ static int bu92747_irda_do_rx(struct bu92747_port *s)
        //unsigned int ch, flag;\r
        int len;\r
        struct tty_struct *tty = s->port.state->port.tty;\r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
 \r
        if (s->rx_enabled == 0) {\r
                BU92725GUW_clr_fifo();\r
@@ -164,6 +170,7 @@ static int bu92747_irda_do_rx(struct bu92747_port *s)
        //printk("\n");\r
        #else\r
        if (len > 0) {\r
+               IRDA_DBG_RECV("line %d, enter %s, receive %d data........\n", __LINE__, __func__, len);\r
                tty_insert_flip_string(tty, g_receive_buf, len);\r
                s->port.icount.rx += len;\r
        }\r
@@ -176,22 +183,14 @@ static int bu92747_irda_do_tx(struct bu92747_port *s)
        //int i;\r
        struct circ_buf *xmit = &s->port.state->xmit;\r
        int len = uart_circ_chars_pending(xmit);\r
-       printk("line %d, enter %s, sending %d data\n", __LINE__, __FUNCTION__, len);\r
+       IRDA_DBG_SENT("line %d, enter %s, sending %d data\n", __LINE__, __FUNCTION__, len);\r
        \r
        if (IS_FIR(s)) {\r
-               //printk("fir sending.....\n");\r
                irda_hw_tx_enable_irq(BU92725GUW_FIR);\r
        }\r
        else {          \r
-               //printk("sir sending.....\n");\r
                irda_hw_tx_enable_irq(BU92725GUW_SIR);\r
        }\r
-\r
-       //BU92747_IRDA_DBG("data:\n");\r
-       //for (i=0; i<len; i++) {\r
-               //BU92747_IRDA_DBG("%d ", xmit->buf[xmit->tail+i]);\r
-       //}\r
-       //BU92747_IRDA_DBG("\n");\r
        \r
        if (len>0) {            \r
                s->tx_empty = 0;\r
@@ -220,11 +219,9 @@ static void bu92747_irda_work(struct work_struct *w)
        struct bu92747_port *s = container_of(w, struct bu92747_port, work);\r
        struct circ_buf *xmit = &s->port.state->xmit;\r
 \r
-       printk("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_SENT("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
 \r
        if (!s->force_end_work && !freezing(current)) {\r
-               //BU92725GUW_dump_register();\r
-\r
                if (!uart_circ_empty(xmit) && !uart_tx_stopped(&s->port)) {\r
                        if (s->tx_empty)\r
                                bu92747_irda_do_tx(s);\r
@@ -242,13 +239,12 @@ static irqreturn_t bu92747_irda_irq(int irqno, void *dev_id)
        struct rev_frame_length *f = &(s->rev_frames);\r
 \r
        irq_src = irda_hw_get_irqsrc();\r
-       printk("[%s][%d], 0x%x\n",__FUNCTION__,__LINE__, irq_src);\r
+       IRDA_DBG_RECV("[%s][%d], 0x%x\n",__FUNCTION__,__LINE__, irq_src);\r
 \r
        /* error */\r
        if (irq_src & (REG_INT_CRC | REG_INT_OE | REG_INT_FE\r
                | REG_INT_AC | REG_INT_DECE | REG_INT_RDOE | REG_INT_DEX)) {\r
-               printk("[%s][%d]: do err\n", __FUNCTION__, __LINE__);\r
-               //BU92725GUW_dump_register();\r
+               printk("[%s][%d]: do err, REG_EIR = 0x%x\n", __FUNCTION__, __LINE__, irq_src);\r
                BU92725GUW_clr_fifo();\r
                BU92725GUW_reset();\r
                if ((BU92725GUW_SEND==irda_hw_get_mode())\r
@@ -274,11 +270,9 @@ static irqreturn_t bu92747_irda_irq(int irqno, void *dev_id)
                        spin_lock(&s->data_lock);\r
                        if (add_frame_length(f, s->cur_frame_length) == 0) {\r
                                s->cur_frame_length = 0;\r
-                               //atomic_set(&(s->data_ready), 1);\r
-                               //wake_up(&(s->data_ready_wq) );\r
                        }\r
                        else {\r
-                               printk("line %d: FIR frame length buf full......\n", __LINE__);                         \r
+                               printk("func %s,line %d: FIR frame length buf full......\n", __FUNCTION__, __LINE__);                           \r
                        }\r
                        spin_unlock(&s->data_lock);\r
                }\r
@@ -291,8 +285,7 @@ static irqreturn_t bu92747_irda_irq(int irqno, void *dev_id)
 \r
        /* error */\r
        if (irq_src & REG_INT_TO) {\r
-               BU92747_IRDA_DBG("[%s][%d]: do timeout err\n", __FUNCTION__, __LINE__);\r
-               //BU92725GUW_dump_register();\r
+               printk("[%s][%d]: do timeout err\n", __FUNCTION__, __LINE__);\r
                BU92725GUW_clr_fifo();\r
                BU92725GUW_reset();\r
                if ((BU92725GUW_SEND==irda_hw_get_mode())\r
@@ -300,14 +293,14 @@ static irqreturn_t bu92747_irda_irq(int irqno, void *dev_id)
                        s->tx_empty = 1;\r
                }\r
        }\r
-\r
+       \r
        return IRQ_HANDLED;\r
 }\r
 \r
 \r
 static void bu92747_irda_stop_tx(struct uart_port *port)\r
 {\r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
 }\r
 \r
 static void bu92747_irda_start_tx(struct uart_port *port)\r
@@ -315,7 +308,7 @@ static void bu92747_irda_start_tx(struct uart_port *port)
        struct bu92747_port *s = container_of(port,\r
                                                  struct bu92747_port,\r
                                                  port);\r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
 \r
        //wait for start cmd\r
        if (IS_FIR(s))\r
@@ -330,11 +323,9 @@ static void bu92747_irda_stop_rx(struct uart_port *port)
                                                  struct bu92747_port,\r
                                                  port);\r
 \r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
 \r
        s->rx_enabled = 0;\r
-\r
-       bu92747_irda_dowork(s);\r
 }\r
 \r
 static unsigned int bu92747_irda_tx_empty(struct uart_port *port)\r
@@ -343,10 +334,9 @@ static unsigned int bu92747_irda_tx_empty(struct uart_port *port)
                                                  struct bu92747_port,\r
                                                  port);\r
 \r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
 \r
        /* may not be truly up-to-date */\r
-       //bu92747_irda_dowork(s);\r
        return s->tx_empty;\r
 }\r
 \r
@@ -356,14 +346,14 @@ static const char *bu92747_irda_type(struct uart_port *port)
                                                  struct bu92747_port,\r
                                                  port);\r
 \r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
 \r
        return s->port.type == PORT_IRDA ? "BU92747" : NULL;\r
 }\r
 \r
 static void bu92747_irda_release_port(struct uart_port *port)\r
 {\r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
 }\r
 \r
 static void bu92747_irda_config_port(struct uart_port *port, int flags)\r
@@ -372,7 +362,7 @@ static void bu92747_irda_config_port(struct uart_port *port, int flags)
                                                  struct bu92747_port,\r
                                                  port);\r
 \r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
 \r
        if (flags & UART_CONFIG_TYPE)\r
                s->port.type = PORT_IRDA;\r
@@ -383,7 +373,7 @@ static int bu92747_irda_verify_port(struct uart_port *port,
 {\r
        int ret = -EINVAL;\r
 \r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
 \r
        if (ser->type == PORT_UNKNOWN || ser->type == PORT_IRDA)\r
                ret = 0;\r
@@ -398,7 +388,7 @@ static void bu92747_irda_shutdown(struct uart_port *port)
                                                  port);\r
        struct rev_frame_length *f = &(s->rev_frames);\r
 \r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       printk("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
 \r
        if (s->suspending)\r
                return;\r
@@ -413,7 +403,6 @@ static void bu92747_irda_shutdown(struct uart_port *port)
        }\r
 \r
        spin_lock(&s->data_lock);\r
-       //atomic_set(&(s->data_ready), 0);\r
        frame_length_buf_clear(f);\r
        s->cur_frame_length = 0;\r
        spin_unlock(&s->data_lock);\r
@@ -436,7 +425,7 @@ static int bu92747_irda_startup(struct uart_port *port)
        char b[32];\r
        struct rev_frame_length *f = &(s->rev_frames);\r
 \r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       printk("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
 \r
        s->rx_enabled = 1;\r
        \r
@@ -459,7 +448,7 @@ static int bu92747_irda_startup(struct uart_port *port)
        s->force_end_work = 0;\r
 \r
        sprintf(b, "bu92747_irda-%d", s->minor);\r
-       s->workqueue = create_freezeable_workqueue(b);\r
+       s->workqueue = create_rt_workqueue(b);\r
        if (!s->workqueue) {\r
                dev_warn(s->dev, "cannot create workqueue\n");\r
                bu92747_unlock();\r
@@ -467,10 +456,8 @@ static int bu92747_irda_startup(struct uart_port *port)
        }\r
        INIT_WORK(&s->work, bu92747_irda_work);\r
 \r
-       //atomic_set(&(s->data_ready), 0);\r
-\r
        if (request_irq(s->irq, bu92747_irda_irq,\r
-                       IRQ_TYPE_LEVEL_LOW, "bu92747_irda", s) < 0) {\r
+                       IRQF_TRIGGER_LOW, "bu92747_irda", s) < 0) {\r
                dev_warn(s->dev, "cannot allocate irq %d\n", s->irq);\r
                s->irq = 0;\r
                destroy_workqueue(s->workqueue);\r
@@ -496,13 +483,13 @@ static int bu92747_irda_startup(struct uart_port *port)
 \r
 static int bu92747_irda_request_port(struct uart_port *port)\r
 {\r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
        return 0;\r
 }\r
 \r
 static void bu92747_irda_break_ctl(struct uart_port *port, int break_state)\r
 {\r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
 }\r
 \r
 static unsigned int bu92747_irda_get_mctrl(struct uart_port *port)\r
@@ -512,7 +499,7 @@ static unsigned int bu92747_irda_get_mctrl(struct uart_port *port)
 \r
 static void bu92747_irda_set_mctrl(struct uart_port *port, unsigned int mctrl)\r
 {\r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
 }\r
 \r
 static void\r
@@ -526,7 +513,7 @@ bu92747_irda_set_termios(struct uart_port *port, struct ktermios *termios,
        unsigned cflag;\r
        struct tty_struct *tty = s->port.state->port.tty;\r
 \r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
        if (!tty)\r
                return;\r
 \r
@@ -541,8 +528,10 @@ bu92747_irda_set_termios(struct uart_port *port, struct ktermios *termios,
        case 115200:\r
        case 4000000:\r
                if (s->baud!=baud) {\r
+                       //printk("func %s:irda set baudrate %d........\n", __FUNCTION__, baud);\r
                        irda_hw_set_speed(baud);\r
                        s->baud = baud;\r
+                       s->tx_empty = 1;\r
                }\r
                break;\r
 \r
@@ -558,20 +547,11 @@ static int bu92747_get_frame_length(struct bu92747_port *s)
 {\r
        struct rev_frame_length *f = &(s->rev_frames);\r
        unsigned long len = 0;\r
-#if 0\r
-       wait_event_interruptible_timeout(s->data_ready_wq, \r
-                                                                        atomic_read(&(s->data_ready) ),\r
-                                                                        msecs_to_jiffies(1000) );\r
-       if ( 0 == atomic_read(&(s->data_ready)) ) {\r
-               printk("waiting 'data_ready_wq' timed out.");\r
-               return -1;\r
-       }\r
-#endif\r
+\r
        spin_lock(&s->data_lock);\r
        if (get_frame_length(f, &len) != 0) {\r
-               printk("line %d: FIR data not ready......\n", __LINE__);\r
+               IRDA_DBG_RECV("func %s, line %d: FIR data not ready......\n", __FUNCTION__, __LINE__);\r
                len = 0;\r
-               //atomic_set(&(s->data_ready), 0);\r
        }\r
        spin_unlock(&s->data_lock);\r
        \r
@@ -586,7 +566,7 @@ static int bu92747_irda_ioctl(struct uart_port *port, unsigned int cmd, unsigned
        void __user *argp = (void __user *)arg;\r
        unsigned long len = 0;\r
        int ret = 0;\r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
 \r
        switch (cmd) {\r
        case TTYIR_GETLENGTH:\r
@@ -645,7 +625,7 @@ static int __devinit bu92747_irda_probe(struct platform_device *pdev)
        int i, retval;\r
     struct irda_info *platdata = pdev->dev.platform_data;\r
 \r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
        if (!platdata) {\r
                dev_warn(&pdev->dev, "no platform data info\n");\r
                return -1;\r
@@ -680,6 +660,7 @@ static int __devinit bu92747_irda_probe(struct platform_device *pdev)
                return -ENOMEM;\r
        }\r
        bu92747s[i]->dev = &pdev->dev;\r
+       bu92747s[i]->irq_pin = platdata->intr_pin;\r
        bu92747s[i]->irq = gpio_to_irq(platdata->intr_pin);\r
        if (platdata->iomux_init)\r
                platdata->iomux_init();\r
@@ -706,8 +687,6 @@ static int __devinit bu92747_irda_probe(struct platform_device *pdev)
        if (bu92747s[i]->pdata->irda_pwr_ctl)\r
                bu92747s[i]->pdata->irda_pwr_ctl(0);\r
        \r
-       //init_waitqueue_head(&(bu92747s[i]->data_ready_wq));\r
-\r
        spin_lock_init(&(bu92747s[i]->data_lock));\r
 \r
        mutex_unlock(&bu92747s_lock);\r
@@ -720,7 +699,7 @@ static int __devexit bu92747_irda_remove(struct platform_device *pdev)
        struct bu92747_port *s = dev_get_drvdata(&pdev->dev);\r
        int i;\r
 \r
-       BU92747_IRDA_DBG("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
+       IRDA_DBG_FUNC("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
        mutex_lock(&bu92747s_lock);\r
 \r
        /* find out the index for the chip we are removing */\r
@@ -755,7 +734,7 @@ static int bu92747_irda_suspend(struct platform_device *pdev, pm_message_t state
        if (s->open_flag) {\r
                printk("line %d, enter %s \n", __LINE__, __FUNCTION__);\r
                disable_irq(s->irq);\r
-\r
+               cancel_work_sync(&s->work);\r
                s->suspending = 1;\r
                uart_suspend_port(&bu92747_irda_uart_driver, &s->port);\r
 \r
@@ -783,11 +762,9 @@ static int bu92747_irda_resume(struct platform_device *pdev)
                uart_resume_port(&bu92747_irda_uart_driver, &s->port);\r
                s->suspending = 0;\r
 \r
-               enable_irq(s->irq);\r
-\r
                if (!s->tx_empty)\r
                        s->tx_empty = 1;\r
-               \r
+               enable_irq(s->irq);\r
                if (s->workqueue && !IS_FIR(s))\r
                        bu92747_irda_dowork(s);\r
        }\r