modify spi_dpram for bp
authorluowei <lw@rock-chips.com>
Fri, 27 Aug 2010 11:10:40 +0000 (19:10 +0800)
committerluowei <lw@rock-chips.com>
Fri, 27 Aug 2010 11:12:08 +0000 (19:12 +0800)
arch/arm/mach-rk2818/include/mach/spi_fpga.h
drivers/fpga/spi_dpram.c
drivers/fpga/spi_uart.c

index 56726d1fa4176183848df858b51aedfb98d1f130..31376de88e863d194e9efeed0297109c24ec826f 100755 (executable)
@@ -13,12 +13,17 @@ defines of FPGA chip ICE65L08's register
 #define SPI_FPGA_STANDBY_PIN RK2818_PIN_PH7\r
 #define SPI_FPGA_RST_PIN RK2818_PIN_PF4\r
 \r
+#define SPI_FPGA_POLL_WAIT     1\r
+#define SPI_FPGA_TRANS_WORK    0\r
 #define SPI_FPGA_TEST_DEBUG    0\r
 #if SPI_FPGA_TEST_DEBUG\r
 #define SPI_FPGA_TEST_DEBUG_PIN RK2818_PIN_PE0\r
 extern int spi_test_wrong_handle(void);\r
 #endif\r
 \r
+#define TRUE           1\r
+#define FALSE          0\r
+\r
 struct uart_icount {\r
        __u32   cts;\r
        __u32   dsr;\r
@@ -108,6 +113,8 @@ struct spi_dpram
        unsigned short int  dpram_addr;\r
        struct semaphore        rec_sem;  \r
        struct semaphore        send_sem; \r
+       struct mutex            rec_lock,send_lock;\r
+       spinlock_t                      spin_rec_lock,spin_send_lock;\r
        wait_queue_head_t       recq, sendq;\r
        struct miscdevice       miscdev;\r
 \r
@@ -130,6 +137,19 @@ struct spi_fpga_port {
        struct workqueue_struct         *fpga_irq_workqueue;\r
        struct work_struct      fpga_irq_work;  \r
        struct timer_list       fpga_timer;\r
+#if SPI_FPGA_TRANS_WORK\r
+       struct workqueue_struct         *fpga_trans_workqueue;\r
+       struct work_struct      fpga_trans_work;        \r
+       int write_en;\r
+       int read_en;\r
+       wait_queue_head_t       wait_wq, wait_rq;\r
+       struct list_head        trans_queue;\r
+#endif\r
+\r
+#if SPI_FPGA_POLL_WAIT\r
+       wait_queue_head_t spi_wait_q;\r
+#endif\r
+\r
        /*spi2uart*/\r
 #ifdef CONFIG_SPI_FPGA_UART\r
        struct spi_uart uart;\r
@@ -490,6 +510,9 @@ typedef enum eSpiGpioPinIntIsr
 }eSpiGpioPinIntIsr_t;\r
 \r
 extern struct spi_fpga_port *pFpgaPort;\r
+#if SPI_FPGA_TRANS_WORK\r
+extern int spi_write_work(struct spi_device *spi, const u8 *buf, size_t len);\r
+#endif\r
 extern unsigned int spi_in(struct spi_fpga_port *port, int reg, int type);\r
 extern void spi_out(struct spi_fpga_port *port, int reg, int value, int type);\r
 \r
index 7d3cddc1e6cdb202a7505f522fa376bc831ad145..2e78c6ce534d5341bd3096e30907e8dccf0c42e2 100755 (executable)
@@ -85,9 +85,8 @@
 #define PIN_BPSEND_ACK RK2818_PIN_PE0\r
 #define PIN_APSEND_ACK RK2818_PIN_PF7\r
 \r
-#define MAX_SPI_LEN    768             //the bytes of spi write or read one time\r
-#define TRUE           1\r
-#define FALSE          0\r
+#define MAX_SPI_LEN    512             //the bytes of spi write or read one time\r
+\r
 \r
 static int spi_dpram_write_buf(struct spi_dpram *dpram, unsigned short int addr, unsigned char *buf, unsigned int len)\r
 {      \r
@@ -292,10 +291,10 @@ static void spi_dpram_irq_work_handler(struct work_struct *work)
                container_of(work, struct spi_fpga_port, dpram.spi_dpram_irq_work);\r
        \r
        unsigned short int mbox = port->dpram.read_irq(&port->dpram);\r
-       unsigned int ptr;\r
-       unsigned int len;\r
-       //int i,ret;\r
-\r
+       unsigned int ptr,len;\r
+       int i;\r
+       char temp,*p;\r
+       printk("Enter::%s,mbox=%d\n",__FUNCTION__,mbox);\r
        //gNumRecInt = mbox & 0x1fff;\r
        //if(gNumRecInt - gNumLastRecInt !=1)\r
        //if(++gNumLastRecInt > (1<<12))\r
@@ -306,17 +305,36 @@ static void spi_dpram_irq_work_handler(struct work_struct *work)
        {               \r
                //RAM0\r
                ptr = port->dpram.read_ptr(&port->dpram,SPI_DPRAM_PTR0_BPWRITE_APREAD);\r
-               len = ptr;\r
+               if(ptr%2)\r
+               len = ptr+1;\r
+               else\r
+               len = ptr;              \r
                port->dpram.read_dpram(&port->dpram, SPI_DPRAM_BPWRITE_START, port->dpram.prx, len);\r
-               port->dpram.rec_len += len;     \r
-               printk("%s:ram0:len=%d\n",__FUNCTION__,len);            \r
+               port->dpram.rec_len += ptr;     \r
+               printk("%s:ram0:ptr=%d,len=%d\n",__FUNCTION__,ptr,len); \r
                //send ack\r
                //if(++gNumSendAck > (1<<12))\r
                //gNumSendAck = 0;\r
                //port->dpram.write_ack(&port->dpram, (MAILBOX_APSEND_ACK | MAILBOX_RAM0 | gNumSendAck));\r
 \r
+               p = port->dpram.prx;\r
+               for(i=0;i<(len>>1);i++)\r
+               {\r
+                       temp = *(p+(i<<1));\r
+                       *(p+(i<<1))= *(p+(i<<1)+1);\r
+                       *(p+(i<<1)+1) = temp;\r
+               }\r
+\r
+               for(i=0;i<ptr;i++)\r
+                       printk("%s:prx[%d]=0x%x\n",__FUNCTION__,i,*p++); \r
+               \r
                //wake up ap to read data\r
                wake_up_interruptible(&port->dpram.recq);\r
+\r
+               mutex_lock(&port->dpram.rec_lock);\r
+\r
+               //allow bp write ram0 again\r
+               port->dpram.write_ack(&port->dpram, (MAILBOX_APSEND_ACK | MAILBOX_RAM0));\r
                \r
                //printk("%s:r_irq=0x%x,s_ack=0x%x\n",__FUNCTION__,mbox, (MAILBOX_APSEND_ACK | MAILBOX_RAM0 | gNumSendAck));\r
        }\r
@@ -324,21 +342,35 @@ static void spi_dpram_irq_work_handler(struct work_struct *work)
        {\r
                //RAM2\r
                ptr = port->dpram.read_ptr(&port->dpram,SPI_DPRAM_PTR2_BPWRITE_APREAD);\r
-               len = ptr;\r
+               if(ptr%2)\r
+               len = ptr+1;\r
+               else\r
+               len = ptr;      \r
                port->dpram.read_dpram(&port->dpram, SPI_DPRAM_LOG_BPWRITE_START, port->dpram.prx, len);\r
-               port->dpram.rec_len += len;     \r
-               printk("%s:ram2:len=%d\n",__FUNCTION__,len);    \r
+               port->dpram.rec_len += ptr;     \r
+               printk("%s:ram2:ptr=%d,len=%d\n",__FUNCTION__,ptr,len); \r
                //if(++gNumSendAck > (1<<12))\r
                //gNumSendAck = 0;\r
                //port->dpram.write_ack(&port->dpram, (MAILBOX_APSEND_ACK | MAILBOX_RAM2 | gNumSendAck));\r
+\r
+               p = port->dpram.prx;\r
+               for(i=0;i<(len>>1);i++)\r
+               {\r
+                       temp = *(p+(i<<1));\r
+                       *(p+(i<<1))= *(p+(i<<1)+1);\r
+                       *(p+(i<<1)+1) = temp;\r
+               }\r
                \r
                //wake up ap to read data\r
                wake_up_interruptible(&port->dpram.recq);\r
+\r
+               mutex_lock(&port->dpram.rec_lock);\r
+\r
+               //allow bp write ram0 again\r
+               port->dpram.write_ack(&port->dpram, (MAILBOX_APSEND_ACK | MAILBOX_RAM2));\r
                \r
                //printk("%s:r_irq=0x%x,s_ack=0x%x\n",__FUNCTION__, mbox, (MAILBOX_APSEND_ACK | MAILBOX_RAM2 | gNumSendAck));\r
        }\r
-\r
-\r
        \r
 }\r
 \r
@@ -465,7 +497,7 @@ static void spi_testdpram_timer(unsigned long data)
 int spi_dpram_handle_ack(struct spi_device *spi)\r
 {\r
        struct spi_fpga_port *port = spi_get_drvdata(spi);\r
-       \r
+       printk("Enter::%s,LINE=%d\n",__FUNCTION__,__LINE__);\r
        //clear ack interrupt\r
        port->dpram.read_ack(&port->dpram);\r
        \r
@@ -507,13 +539,17 @@ static int dpr_close(struct inode *inode, struct file *filp)
        return 0;\r
 }\r
 \r
-\r
+int gRecCount = 0;\r
 static ssize_t dpr_read (struct file *filp, char __user *buffer, size_t count, loff_t *ppos)\r
 {\r
-       //int ret;\r
+       int ret=0; \r
        struct spi_fpga_port *port = filp->private_data;\r
-       printk("%s:line=%d,port=0x%x\n",__FUNCTION__,__LINE__,(int)port);\r
+\r
+       down_interruptible(&port->dpram.rec_sem);\r
        \r
+       printk("%s, port=0x%x , count=%d, port->dpram.rec_len=%d \n",__FUNCTION__, (int)port, count, port->dpram.rec_len); \r
+               \r
+       //printk("%s:CURRENT_TASK=0x%x\n",__FUNCTION__,current);        \r
        while(port->dpram.rec_len == 0)\r
        {\r
                if( filp->f_flags&O_NONBLOCK )\r
@@ -524,22 +560,50 @@ static ssize_t dpr_read (struct file *filp, char __user *buffer, size_t count, l
                        printk("%s:NO data in dpram!\n",__FUNCTION__);\r
                        return -ERESTARTSYS;   \r
                }\r
+\r
+               gRecCount = port->dpram.rec_len;\r
        }\r
 \r
        /*read data from buffer*/\r
-       if(copy_to_user((char*)buffer, (char *)port->dpram.prx, port->dpram.rec_len))\r
-    {\r
-        printk("%s:copy_to_user err!\n",__FUNCTION__);\r
-        return -EFAULT;\r
-    }\r
-\r
-       count = port->dpram.rec_len;\r
-       port->dpram.rec_len = 0;\r
+       if(port->dpram.rec_len >=count){ \r
+               if(copy_to_user((char*)buffer, (char *)(port->dpram.prx + gRecCount - port->dpram.rec_len), count))\r
+       {\r
+                       printk("%s:copy_to_user err!\n",__FUNCTION__);\r
+                       return -EFAULT;\r
+       }\r
+               ret = count; \r
+       }else{ \r
+               if(copy_to_user((char*)buffer, (char *)(port->dpram.prx + gRecCount - port->dpram.rec_len), port->dpram.rec_len))\r
+       {\r
+                       printk("%s:copy_to_user err!\n",__FUNCTION__);\r
+                       return -EFAULT;\r
+       }\r
+               ret = port->dpram.rec_len; \r
+       }\r
        \r
-       //allow bp write ram0 again\r
-       port->dpram.write_ack(&port->dpram, (MAILBOX_APSEND_ACK | MAILBOX_RAM0));\r
+       #if 1\r
+       int i;\r
+       char *p = buffer;\r
+       for(i=0;i<ret;i++)\r
+       {\r
+               printk("dpr_read, prx[%d]=0x%x\n", i, *p++); \r
+       }\r
+       #endif\r
        \r
-       return count;\r
+       if(port->dpram.rec_len >= count){ \r
+               port->dpram.rec_len -= count; \r
+       }else{ \r
+               port->dpram.rec_len = 0; \r
+       }\r
+       \r
+       if(port->dpram.rec_len == 0){ \r
+               printk("port->dpram.rec_len to 0 \n"); \r
+               mutex_unlock(&port->dpram.rec_lock); \r
+       } \r
+       \r
+       up(&port->dpram.rec_sem);\r
+\r
+       return ret;\r
 }\r
 \r
 \r
@@ -585,7 +649,6 @@ static ssize_t dpr_write (struct file *filp, const char __user *buffer, size_t c
                temp = *(p+(i<<1));\r
                *(p+(i<<1))= *(p+(i<<1)+1);\r
                *(p+(i<<1)+1) = temp;\r
-               p=p+2;\r
        }\r
        \r
 #if 1\r
@@ -604,7 +667,7 @@ static ssize_t dpr_write (struct file *filp, const char __user *buffer, size_t c
        gNumSendInt = 0;\r
 \r
        //send irq to bp after ap write data to dpram\r
-       port->dpram.write_irq(&port->dpram, MAILBOX_APSEND_IRQ);        \r
+       port->dpram.write_irq(&port->dpram, MAILBOX_APSEND_IRQ | MAILBOX_RAM1); \r
 \r
        return count;\r
     \r
@@ -618,6 +681,23 @@ unsigned int dpr_poll(struct file *filp, struct poll_table_struct * wait)
        port = filp->private_data;\r
        printk("%s:line=%d\n",__FUNCTION__,__LINE__);\r
 \r
+#if 1\r
+       poll_wait(filp, &port->dpram.recq, wait);\r
+       poll_wait(filp, &port->dpram.sendq, wait);\r
+\r
+       if(port->dpram.rec_len >0)\r
+       {\r
+           mask |= POLLIN|POLLRDNORM;\r
+           DBG("%s:exsram_poll_____1\n",__FUNCTION__);\r
+       }\r
+       \r
+       if(port->dpram.apwrite_en == TRUE)\r
+       {\r
+           mask |= POLLOUT|POLLWRNORM;\r
+               DBG("%s:exsram_poll_____2\n",__FUNCTION__);\r
+       }\r
+#endif\r
+\r
        return mask;\r
 }\r
 \r
@@ -677,6 +757,12 @@ int spi_dpram_register(struct spi_fpga_port *port)
        //init the struct spi_dpram\r
        init_waitqueue_head(&port->dpram.recq);\r
        init_waitqueue_head(&port->dpram.sendq);\r
+       mutex_init(&port->dpram.rec_lock);\r
+       mutex_init(&port->dpram.send_lock);\r
+       init_MUTEX(&port->dpram.rec_sem);\r
+       init_MUTEX(&port->dpram.send_sem);\r
+       spin_lock_init(&port->dpram.spin_rec_lock);\r
+       spin_lock_init(&port->dpram.spin_send_lock);\r
        port->dpram.rec_len = 0;\r
        port->dpram.send_len = 0;\r
        port->dpram.apwrite_en = TRUE;\r
index 15846e9f815d28c63a1a933ba2b3491224b817e6..407d0eec8f5b89c6038962101409e5cbfa30755b 100755 (executable)
@@ -2,6 +2,7 @@
 #include <linux/init.h>\r
 #include <linux/kernel.h>\r
 #include <linux/mutex.h>\r
+#include <linux/seq_file.h>\r
 #include <linux/serial_reg.h>\r
 #include <linux/circ_buf.h>\r
 #include <linux/gfp.h>\r
@@ -45,7 +46,7 @@ static struct tty_driver *spi_uart_tty_driver;
 \r
 #define UART_NR                1       /* Number of UARTs this driver can handle */\r
 \r
-#define UART_XMIT_SIZE (PAGE_SIZE<<1)\r
+#define UART_XMIT_SIZE PAGE_SIZE\r
 #define WAKEUP_CHARS   1024\r
 \r
 #define circ_empty(circ)       ((circ)->head == (circ)->tail)\r
@@ -70,17 +71,17 @@ static int spi_uart_write_buf(struct spi_uart *uart, unsigned char *buf, int len
        int index = port->uart.index;\r
        int reg = 0, stat = 0;\r
        int i;\r
-\r
-       for(i=len+2;i>1;i--)\r
-       buf[i] = buf[i-2];\r
+       unsigned char tx_buf[SPI_UART_FIFO_LEN+2];\r
+       \r
+       memcpy(tx_buf + 2, buf, len);\r
        reg = ((((reg) | ICE_SEL_UART) & ICE_SEL_WRITE) | ICE_SEL_UART_CH(index));\r
-       buf[0] = reg & 0xff;\r
-       buf[1] = 0;\r
+       tx_buf[0] = reg & 0xff;\r
+       tx_buf[1] = 0;\r
 \r
-       stat = spi_write(port->spi, buf, len+2);\r
+       stat = spi_write(port->spi, tx_buf, len+2);\r
        if(stat)\r
        printk("%s:spi_write err!!!\n\n\n",__FUNCTION__);                       \r
-       DBG("%s:reg=0x%x,buf=0x%x,len=0x%x\n",__FUNCTION__,reg&0xff,(int)buf,len);\r
+       DBG("%s:reg=0x%x,buf=0x%x,len=0x%x\n",__FUNCTION__,reg&0xff,(int)tx_buf,len);\r
        return 0;\r
 }\r
 \r
@@ -183,11 +184,11 @@ static void spi_uart_port_remove(struct spi_uart *uart)
         * Beware: the lock ordering is critical.\r
         */\r
        mutex_lock(&uart->open_lock);\r
-       //mutex_lock(&port->spi_lock);\r
+       mutex_lock(&port->spi_lock);\r
        spi = port->spi;\r
 \r
        port->spi = NULL;\r
-       //mutex_unlock(&port->spi_lock);\r
+       mutex_unlock(&port->spi_lock);\r
        if (uart->opened)\r
                tty_hangup(uart->tty);\r
        mutex_unlock(&uart->open_lock);\r
@@ -432,13 +433,16 @@ static void spi_uart_receive_chars(struct spi_uart *uart, unsigned int *status)
                while (count-- >0 )\r
                {\r
                        flag = TTY_NORMAL;\r
+                       uart->icount.rx++;\r
                        ch = buf[num++];\r
                        tty_insert_flip_char(tty, ch, flag);\r
                        //printk("%c,",ch);\r
                }\r
                //printk("\n");\r
-               tty_flip_buffer_push(tty); \r
        }\r
+\r
+       tty_flip_buffer_push(tty); \r
+       \r
 #else  \r
        //printk("rx:");\r
        while (--max_count >0 )\r
@@ -775,7 +779,7 @@ static int spi_uart_startup(struct spi_uart *uart)
        uart->xmit.buf = (unsigned char *)page;\r
        circ_clear(&uart->xmit);\r
 \r
-       //mutex_lock(&port->spi_lock);\r
+       mutex_lock(&port->spi_lock);\r
 \r
        /*\r
         * Clear the FIFO buffers and disable them.\r
@@ -816,7 +820,7 @@ static int spi_uart_startup(struct spi_uart *uart)
        DBG("%s:LINE=%d,uart->ier=0x%x\n",__FUNCTION__,__LINE__,uart->ier);\r
        /* Kick the IRQ handler once while we're still holding the host lock */\r
        //spi_uart_handle_irq(port->spi);\r
-       //mutex_unlock(&port->spi_lock);\r
+       mutex_unlock(&port->spi_lock);\r
        return 0;\r
 \r
 //err1:\r
@@ -829,7 +833,7 @@ static void spi_uart_shutdown(struct spi_uart *uart)
        struct spi_fpga_port *port = container_of(uart, struct spi_fpga_port, uart);\r
        DBG("%s:LINE=%d\n",__FUNCTION__,__LINE__);\r
 \r
-       //mutex_lock(&port->spi_lock);\r
+       mutex_lock(&port->spi_lock);\r
 #if 1\r
        spi_uart_stop_rx(uart);\r
 \r
@@ -854,7 +858,7 @@ static void spi_uart_shutdown(struct spi_uart *uart)
                                 UART_FCR_CLEAR_XMIT, SEL_UART);\r
        spi_out(port, UART_FCR, 0, SEL_UART);\r
 #endif\r
-       //mutex_unlock(&port->spi_lock);\r
+       mutex_unlock(&port->spi_lock);\r
 \r
 //skip:\r
        /* Free the transmit buffer page. */\r
@@ -973,13 +977,13 @@ static int spi_uart_write(struct tty_struct * tty, const unsigned char *buf,
        \r
 #if 1\r
        if ( !(uart->ier & UART_IER_THRI)) {\r
-               //mutex_lock(&port->spi_lock);\r
+               mutex_lock(&port->spi_lock);\r
                        DBG("%s:LINE=%d\n",__FUNCTION__,__LINE__);\r
                        /*Note:ICE65L08 output a 'Transmitter holding register interrupt' after 1us*/\r
                        printk("s,");\r
                        spi_uart_start_tx(uart);\r
-               //      spi_uart_handle_irq(port->spi);\r
-               //mutex_unlock(&port->spi_lock);        \r
+                       //spi_uart_handle_irq(port->spi);\r
+               mutex_unlock(&port->spi_lock);  \r
        }       \r
 #endif \r
 \r
@@ -1008,11 +1012,11 @@ static void spi_uart_send_xchar(struct tty_struct *tty, char ch)
        printk("%s:LINE=%d\n",__FUNCTION__,__LINE__);\r
        uart->x_char = ch;\r
        if (ch && !(uart->ier & UART_IER_THRI)) {\r
-               //mutex_lock(&port->spi_lock);\r
+               mutex_lock(&port->spi_lock);\r
                spi_uart_start_tx(uart);\r
                printk("%s:UART_IER=0x%x\n",__FUNCTION__,uart->ier);\r
                spi_uart_handle_irq(port->spi);\r
-               //mutex_unlock(&port->spi_lock);                \r
+               mutex_unlock(&port->spi_lock);          \r
        }\r
 }\r
 \r
@@ -1024,7 +1028,7 @@ static void spi_uart_throttle(struct tty_struct *tty)
        if (!I_IXOFF(tty) && !(tty->termios->c_cflag & CRTSCTS))\r
                return;\r
        printk("%s:LINE=%d\n",__FUNCTION__,__LINE__);\r
-       //mutex_lock(&port->spi_lock);\r
+       mutex_lock(&port->spi_lock);\r
        if (I_IXOFF(tty)) {\r
                uart->x_char = STOP_CHAR(tty);\r
                spi_uart_start_tx(uart);\r
@@ -1035,7 +1039,7 @@ static void spi_uart_throttle(struct tty_struct *tty)
                spi_uart_clear_mctrl(uart, TIOCM_RTS);\r
 \r
        spi_uart_handle_irq(port->spi);\r
-       //mutex_unlock(&port->spi_lock);\r
+       mutex_unlock(&port->spi_lock);\r
 }\r
 \r
 static void spi_uart_unthrottle(struct tty_struct *tty)\r
@@ -1045,7 +1049,7 @@ static void spi_uart_unthrottle(struct tty_struct *tty)
        printk("%s:LINE=%d\n",__FUNCTION__,__LINE__);\r
        if (!I_IXOFF(tty) && !(tty->termios->c_cflag & CRTSCTS))\r
                return;\r
-       //mutex_lock(&port->spi_lock);\r
+       mutex_lock(&port->spi_lock);\r
        if (I_IXOFF(tty)) {\r
                if (uart->x_char) {\r
                        uart->x_char = 0;\r
@@ -1060,13 +1064,13 @@ static void spi_uart_unthrottle(struct tty_struct *tty)
                spi_uart_set_mctrl(uart, TIOCM_RTS);\r
 \r
        spi_uart_handle_irq(port->spi);\r
-       //mutex_unlock(&port->spi_lock);\r
+       mutex_unlock(&port->spi_lock);\r
 }\r
 \r
 static void spi_uart_set_termios(struct tty_struct *tty, struct ktermios *old_termios)\r
 {\r
        struct spi_uart *uart = tty->driver_data;\r
-       //struct spi_fpga_port *port = container_of(uart, struct spi_fpga_port, uart);\r
+       struct spi_fpga_port *port = container_of(uart, struct spi_fpga_port, uart);\r
        unsigned int cflag = tty->termios->c_cflag;\r
        unsigned int mask = TIOCM_DTR;\r
        DBG("%s:LINE=%d\n",__FUNCTION__,__LINE__);\r
@@ -1077,7 +1081,7 @@ static void spi_uart_set_termios(struct tty_struct *tty, struct ktermios *old_te
            RELEVANT_IFLAG(tty->termios->c_iflag ^ old_termios->c_iflag) == 0)\r
                return;\r
 \r
-       //mutex_lock(&port->spi_lock);\r
+       mutex_lock(&port->spi_lock);\r
        spi_uart_change_speed(uart, tty->termios, old_termios);\r
 \r
        /* Handle transition to B0 status */\r
@@ -1111,7 +1115,7 @@ static void spi_uart_set_termios(struct tty_struct *tty, struct ktermios *old_te
                        spi_uart_stop_tx(uart);\r
                }\r
        }\r
-       //mutex_unlock(&port->spi_lock);\r
+       mutex_unlock(&port->spi_lock);\r
 \r
 }\r
 \r
@@ -1120,25 +1124,25 @@ static int spi_uart_break_ctl(struct tty_struct *tty, int break_state)
        struct spi_uart *uart = tty->driver_data;\r
        struct spi_fpga_port *port = container_of(uart, struct spi_fpga_port, uart); \r
        DBG("%s:LINE=%d\n",__FUNCTION__,__LINE__);\r
-       //mutex_lock(&port->spi_lock);\r
+       mutex_lock(&port->spi_lock);\r
        if (break_state == -1)\r
                uart->lcr |= UART_LCR_SBC;\r
        else\r
                uart->lcr &= ~UART_LCR_SBC;\r
        spi_out(port, UART_LCR, uart->lcr, SEL_UART);\r
-       //mutex_unlock(&port->spi_lock);\r
+       mutex_unlock(&port->spi_lock);\r
        return 0;\r
 }\r
 \r
 static int spi_uart_tiocmget(struct tty_struct *tty, struct file *file)\r
 {\r
        struct spi_uart *uart = tty->driver_data;\r
-       //struct spi_fpga_port *port = container_of(uart, struct spi_fpga_port, uart);\r
+       struct spi_fpga_port *port = container_of(uart, struct spi_fpga_port, uart);\r
        int result;\r
        DBG("%s:LINE=%d\n",__FUNCTION__,__LINE__);\r
-       //mutex_lock(&port->spi_lock);\r
+       mutex_lock(&port->spi_lock);\r
        result = uart->mctrl | spi_uart_get_mctrl(uart);\r
-       //mutex_unlock(&port->spi_lock);\r
+       mutex_unlock(&port->spi_lock);\r
        return result;\r
 }\r
 \r
@@ -1146,77 +1150,72 @@ static int spi_uart_tiocmset(struct tty_struct *tty, struct file *file,
                              unsigned int set, unsigned int clear)\r
 {\r
        struct spi_uart *uart = tty->driver_data;\r
-       //struct spi_fpga_port *port = container_of(uart, struct spi_fpga_port, uart);\r
+       struct spi_fpga_port *port = container_of(uart, struct spi_fpga_port, uart);\r
        DBG("%s:LINE=%d\n",__FUNCTION__,__LINE__);\r
-       //mutex_lock(&port->spi_lock);\r
+       mutex_lock(&port->spi_lock);\r
        spi_uart_update_mctrl(uart, set, clear);\r
-       //mutex_unlock(&port->spi_lock);\r
+       mutex_unlock(&port->spi_lock);\r
 \r
        return 0;\r
 }\r
 \r
-#if 0\r
-static int spi_uart_read_proc(char *page, char **start, off_t off,\r
-                              int count, int *eof, void *data)\r
+static int spi_uart_proc_show(struct seq_file *m, void *v)\r
 {\r
-       int i, len = 0;\r
-       off_t begin = 0;\r
-       DBG("%s:LINE=%d************************\n",__FUNCTION__,__LINE__);\r
-       len += sprintf(page, "serinfo:1.0 driver%s%s revision:%s\n",\r
+       int i;\r
+\r
+       seq_printf(m, "serinfo:1.0 driver%s%s revision:%s\n",\r
                       "", "", "");\r
-       for (i = 0; i < UART_NR && len < PAGE_SIZE - 96; i++) {\r
-               struct spi_uart *uart = spi_uart_port_get(i);\r
-               if (uart) {\r
-                       len += sprintf(page+len, "%d: uart:SPI", i);\r
+       for (i = 0; i < UART_NR; i++) {\r
+               struct spi_uart *port = spi_uart_port_get(i);\r
+               if (port) {\r
+                       seq_printf(m, "%d: uart:SPI", i);\r
                        if(capable(CAP_SYS_ADMIN)) {\r
-                               len += sprintf(page + len, " tx:%d rx:%d",\r
-                                              uart->icount.tx, uart->icount.rx);\r
-                               if (uart->icount.frame)\r
-                                       len += sprintf(page + len, " fe:%d",\r
-                                                      uart->icount.frame);\r
-                               if (uart->icount.parity)\r
-                                       len += sprintf(page + len, " pe:%d",\r
-                                                      uart->icount.parity);\r
-                               if (uart->icount.brk)\r
-                                       len += sprintf(page + len, " brk:%d",\r
-                                                      uart->icount.brk);\r
-                               if (uart->icount.overrun)\r
-                                       len += sprintf(page + len, " oe:%d",\r
-                                                      uart->icount.overrun);\r
-                               if (uart->icount.cts)\r
-                                       len += sprintf(page + len, " cts:%d",\r
-                                                      uart->icount.cts);\r
-                               if (uart->icount.dsr)\r
-                                       len += sprintf(page + len, " dsr:%d",\r
-                                                      uart->icount.dsr);\r
-                               if (uart->icount.rng)\r
-                                       len += sprintf(page + len, " rng:%d",\r
-                                                      uart->icount.rng);\r
-                               if (uart->icount.dcd)\r
-                                       len += sprintf(page + len, " dcd:%d",\r
-                                                      uart->icount.dcd);\r
+                               seq_printf(m, " tx:%d rx:%d",\r
+                                              port->icount.tx, port->icount.rx);\r
+                               if (port->icount.frame)\r
+                                       seq_printf(m, " fe:%d",\r
+                                                      port->icount.frame);\r
+                               if (port->icount.parity)\r
+                                       seq_printf(m, " pe:%d",\r
+                                                      port->icount.parity);\r
+                               if (port->icount.brk)\r
+                                       seq_printf(m, " brk:%d",\r
+                                                      port->icount.brk);\r
+                               if (port->icount.overrun)\r
+                                       seq_printf(m, " oe:%d",\r
+                                                      port->icount.overrun);\r
+                               if (port->icount.cts)\r
+                                       seq_printf(m, " cts:%d",\r
+                                                      port->icount.cts);\r
+                               if (port->icount.dsr)\r
+                                       seq_printf(m, " dsr:%d",\r
+                                                      port->icount.dsr);\r
+                               if (port->icount.rng)\r
+                                       seq_printf(m, " rng:%d",\r
+                                                      port->icount.rng);\r
+                               if (port->icount.dcd)\r
+                                       seq_printf(m, " dcd:%d",\r
+                                                      port->icount.dcd);\r
                        }\r
-                       strcat(page, "\n");\r
-                       len++;\r
-                       spi_uart_port_put(uart);\r
-               }\r
-\r
-               if (len + begin > off + count)\r
-                       goto done;\r
-               if (len + begin < off) {\r
-                       begin += len;\r
-                       len = 0;\r
+                       spi_uart_port_put(port);\r
+                       seq_putc(m, '\n');\r
                }\r
        }\r
-       *eof = 1;\r
+       return 0;\r
+}\r
 \r
-done:\r
-       if (off >= len + begin)\r
-               return 0;\r
-       *start = page + (off - begin);\r
-       return (count < begin + len - off) ? count : (begin + len - off);\r
+static int spi_uart_proc_open(struct inode *inode, struct file *file)\r
+{\r
+       return single_open(file, spi_uart_proc_show, NULL);\r
 }\r
-#endif\r
+\r
+static const struct file_operations spi_uart_proc_fops = {\r
+       .owner          = THIS_MODULE,\r
+       .open           = spi_uart_proc_open,\r
+       .read           = seq_read,\r
+       .llseek         = seq_lseek,\r
+       .release        = single_release,\r
+};\r
 \r
 static const struct tty_operations spi_uart_ops = {\r
        .open                   = spi_uart_open,\r
@@ -1231,7 +1230,7 @@ static const struct tty_operations spi_uart_ops = {
        .break_ctl              = spi_uart_break_ctl,\r
        .tiocmget               = spi_uart_tiocmget,\r
        .tiocmset               = spi_uart_tiocmset,\r
-       //.read_proc            = spi_uart_read_proc,\r
+       .proc_fops              = &spi_uart_proc_fops,\r
 };\r
 \r
 \r