From de246ff1f1f6b22cdf79f9b0b6ad798f435c06f8 Mon Sep 17 00:00:00 2001 From: luowei Date: Fri, 24 Sep 2010 21:43:37 +0800 Subject: [PATCH] improve something for fpga --- arch/arm/mach-rk2818/include/mach/spi_fpga.h | 2 +- drivers/fpga/spi_fpga_init.c | 13 +++++++------ drivers/fpga/spi_i2c.c | 4 ++-- drivers/fpga/spi_uart.c | 19 +++++++++---------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/arch/arm/mach-rk2818/include/mach/spi_fpga.h b/arch/arm/mach-rk2818/include/mach/spi_fpga.h index 63ead95f6534..4fa616ebcc8e 100755 --- a/arch/arm/mach-rk2818/include/mach/spi_fpga.h +++ b/arch/arm/mach-rk2818/include/mach/spi_fpga.h @@ -528,7 +528,7 @@ typedef enum eSpiGpioPinIntIsr extern struct spi_fpga_port *pFpgaPort; #if SPI_FPGA_TRANS_WORK -extern int spi_write_work(struct spi_device *spi, const u8 *buf, size_t len); +extern int spi_write_work(struct spi_device *spi, u8 *buf, size_t len); #endif extern unsigned int spi_in(struct spi_fpga_port *port, int reg, int type); extern void spi_out(struct spi_fpga_port *port, int reg, int value, int type); diff --git a/drivers/fpga/spi_fpga_init.c b/drivers/fpga/spi_fpga_init.c index 623e3b6ddb4b..1bad3d6c15b2 100755 --- a/drivers/fpga/spi_fpga_init.c +++ b/drivers/fpga/spi_fpga_init.c @@ -59,7 +59,7 @@ struct spi_fpga_port *pFpgaPort; #define ID_SPI_FPGA_READ 2 struct spi_fpga_transfer { - const u8 *txbuf; + u8 *txbuf; unsigned n_tx; u8 *rxbuf; unsigned n_rx; @@ -72,9 +72,10 @@ static void spi_fpga_trans_work_handler(struct work_struct *work) struct spi_fpga_port *port = container_of(work, struct spi_fpga_port, fpga_trans_work); unsigned long flags; - + spin_lock_irqsave(&port->work_lock, flags); while (!list_empty(&port->trans_queue)) { + spin_unlock_irqrestore(&port->work_lock, flags); struct spi_fpga_transfer *t = NULL, *tmp; list_for_each_entry_safe(t, tmp, &port->trans_queue, queue) { @@ -96,13 +97,13 @@ static void spi_fpga_trans_work_handler(struct work_struct *work) } spin_lock_irqsave(&port->work_lock, flags); list_del_init(&port->trans_queue); - spin_unlock_irqrestore(&port->work_lock, flags); - } + } + spin_unlock_irqrestore(&port->work_lock, flags); } -int spi_write_work(struct spi_device *spi, const u8 *buf, size_t len) +int spi_write_work(struct spi_device *spi, u8 *buf, size_t len) { struct spi_fpga_port *port = spi_get_drvdata(spi); struct spi_fpga_transfer *t; @@ -325,7 +326,7 @@ void spi_out(struct spi_fpga_port *port, int reg, int value, int type) tx_buf[1] = (value>>8) & 0xff; tx_buf[2] = value & 0xff; if(reg_temp == UART_IER) - spi_write_work(port->spi, (const u8 *)&tx_buf, sizeof(tx_buf)); + spi_write_work(port->spi, tx_buf, sizeof(tx_buf)); else spi_write(port->spi, (const u8 *)&tx_buf, sizeof(tx_buf)); DBG("%s,SEL_UART reg=0x%x,value=0x%x\n",__FUNCTION__,reg&0xff,value&0xffff); diff --git a/drivers/fpga/spi_i2c.c b/drivers/fpga/spi_i2c.c index 2d753ab5e3a7..7c1653f7755c 100755 --- a/drivers/fpga/spi_i2c.c +++ b/drivers/fpga/spi_i2c.c @@ -153,7 +153,7 @@ int spi_i2c_readbuf(struct spi_fpga_port *port ,struct i2c_msg *pmsg,int ch) spi_out(port,reg,len,SEL_I2C); #if SPI_FPGA_I2C_EVENT - ret = wait_event_timeout(port->i2c.wait_r, port->i2c.interrupt == INT_I2C_READ_ACK, msecs_to_jiffies(60)); + ret = wait_event_timeout(port->i2c.wait_r, ((port->i2c.interrupt == INT_I2C_READ_ACK) || (port->i2c.interrupt == INT_I2C_READ_NACK)), msecs_to_jiffies(60)); if(ret == 0) { printk("%s:60ms time out!\n",__FUNCTION__); @@ -243,7 +243,7 @@ int spi_i2c_writebuf(struct spi_fpga_port *port ,struct i2c_msg *pmsg,int ch) reg = channel|ICE_SEL_I2C_STOP; spi_out(port,reg,pmsg->buf[i],SEL_I2C); #if SPI_FPGA_I2C_EVENT - ret = wait_event_timeout(port->i2c.wait_w, port->i2c.interrupt == INT_I2C_WRITE_ACK, msecs_to_jiffies(60)); + ret = wait_event_timeout(port->i2c.wait_w, ((port->i2c.interrupt == INT_I2C_WRITE_ACK) || (port->i2c.interrupt == INT_I2C_WRITE_NACK)), msecs_to_jiffies(60)); if(ret == 0) { printk("%s:60ms time out!\n",__FUNCTION__); diff --git a/drivers/fpga/spi_uart.c b/drivers/fpga/spi_uart.c index 28eba8290cf5..4d44e0f8f043 100755 --- a/drivers/fpga/spi_uart.c +++ b/drivers/fpga/spi_uart.c @@ -400,16 +400,15 @@ static void spi_uart_receive_chars(struct spi_uart *uart, unsigned int *status) { struct tty_struct *tty = uart->tty; struct spi_fpga_port *port = container_of(uart, struct spi_fpga_port, uart); - unsigned int ch, flag; + unsigned char ch, flag; int max_count = 1024; DBG("rx:"); #if SPI_UART_TXRX_BUF - int ret,count,stat = 0; + int ret,count,stat = *status; int i = 0; unsigned char buf[SPI_UART_FIFO_LEN]; - while (max_count >0 ) + while (max_count >0) { - stat = spi_in(port, UART_LSR, SEL_UART); if((((stat >> 8) & 0x3f) != 0) && (!(stat & UART_LSR_DR))) printk("%s:warning:no receive data but count =%d \n",__FUNCTION__,((stat >> 8) & 0x3f)); if(!(stat & UART_LSR_DR)) @@ -427,18 +426,18 @@ static void spi_uart_receive_chars(struct spi_uart *uart, unsigned int *status) printk("err:%s:stat=%d,fail to read uart data because of spi bus error!\n",__FUNCTION__,stat); } max_count -= count; + flag = TTY_NORMAL; + uart->icount.rx += count; for(i=0;iicount.rx++; ch = buf[i]; tty_insert_flip_char(tty, ch, flag); DBG("0x%x,",ch); } + tty_flip_buffer_push(tty); DBG("\n"); } - tty_flip_buffer_push(tty); DBG("\n"); #else @@ -912,7 +911,7 @@ static int spi_uart_open (struct tty_struct *tty, struct file * filp) static void spi_uart_close(struct tty_struct *tty, struct file * filp) { struct spi_uart *uart = tty->driver_data; - printk("%s:LINE=%d,tty->hw_stopped=%d\n",__FUNCTION__,__LINE__,tty->hw_stopped); + DBG("%s:LINE=%d,tty->hw_stopped=%d\n",__FUNCTION__,__LINE__,tty->hw_stopped); if (!uart) return; @@ -1001,7 +1000,7 @@ static int spi_uart_write_room(struct tty_struct *tty) static int spi_uart_chars_in_buffer(struct tty_struct *tty) { struct spi_uart *uart = tty->driver_data; - printk("%s:LINE=%d,circ=%ld\n",__FUNCTION__,__LINE__,circ_chars_pending(&uart->xmit)); + DBG("%s:LINE=%d,circ=%ld\n",__FUNCTION__,__LINE__,circ_chars_pending(&uart->xmit)); return uart ? circ_chars_pending(&uart->xmit) : 0; } @@ -1009,7 +1008,7 @@ static void spi_uart_send_xchar(struct tty_struct *tty, char ch) { struct spi_uart *uart = tty->driver_data; struct spi_fpga_port *port = container_of(uart, struct spi_fpga_port, uart); - printk("%s:LINE=%d\n",__FUNCTION__,__LINE__); + DBG("%s:LINE=%d\n",__FUNCTION__,__LINE__); uart->x_char = ch; if (ch && !(uart->ier & UART_IER_THRI)) { mutex_lock(&port->spi_lock); -- 2.34.1