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