Hi All,
I am trying to add a support of CP210x serial-usb driver on D-Link DIR-615.
I add a support of CP210x chip in Linux kernel. When I connect a CP210x chip to router using serial cable it detect properly.
But I am not able to read data from CP210x chip.
The setup of my testing is
1. Connect CP210x to router using USB cable.
2. Short the TX and RX pin of CP210x. (using as a loop back)
3. Run the following program on router to TX and RX data.
4. In the output I didn't get data, my program get holted at select() call. select() is not going to recevice any interrupt.
5. Enable a debug parameter for generic and cp210x form sysfs
root@OpenWrt:~# echo 1 > /sys/bus/usb-serial/drivers/generic/module/parameters/debug
root@OpenWrt:~# echo 1 > /sys/bus/usb-serial/drivers/cp210x/module/parameters/debug
root@OpenWrt:~# cat /sys/bus/usb-serial/drivers/generic/module/parameters/debug
Y
root@OpenWrt:~# cat /sys/bus/usb-serial/drivers/cp210x/module/parameters/debug
Y
root@OpenWrt:~#
The code is given below,
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <memory.h>
#include <termios.h>
#include <errno.h>
#include <unistd.h>
int main()
{
int fd_ttl;
int read_len;
fd_set readfds;
int ReturnVal;
char buf[64];
char ReadData1[] = "Hello";
fd_ttl = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
if(fd_ttl < 0) {
perror("Open");
return -1;
}
ReturnVal = write(fd_ttl, ReadData1, strlen(ReadData1));
printf("ReturnVal: %d\n", ReturnVal);
perror("Write");
while(1)
{
FD_ZERO(&readfds);
FD_SET(fd_ttl, &readfds);
printf("line: %d\n", __LINE__);
if(select(fd_ttl + 1, &readfds, NULL, NULL, NULL) < 0)
continue;
printf("line: %d\n", __LINE__);
if(FD_ISSET(fd_ttl, &readfds))
{
bzero(buf, sizeof(buf));
read_len = read(fd_ttl, buf, sizeof(buf));
printf("%s\n", buf);
break;
}
}
close(fd_ttl);
return 0;
}Program output:
root@OpenWrt:~# ./simple
ReturnVal: 5
Write: Success
line: 93 (It get halted here, read() is not get called)
The debug log is,
root@OpenWrt:~# dmesg
usb 1-1: new full speed USB device using ar71xx-ohci and address 11
usb 1-1: configuration #1 chosen from 1 choice
drivers/usb/serial/usb-serial.c: static descriptor matches
drivers/usb/serial/usb-serial.c: found bulk in on endpoint 0
drivers/usb/serial/usb-serial.c: found bulk out on endpoint 1
cp210x 1-1:1.0: cp210x converter detected
drivers/usb/serial/usb-serial.c: usb_serial_probe - setting up 1 port structures for this device
usb 1-1: reset full speed USB device using ar71xx-ohci and address 11
drivers/usb/serial/usb-serial.c: get_free_serial 1
drivers/usb/serial/usb-serial.c: get_free_serial - minor base = 0
drivers/usb/serial/usb-serial.c: usb_serial_probe - registering ttyUSB0
usb 1-1: cp210x converter now attached to ttyUSB0
drivers/usb/serial/usb-serial.c: serial_install
drivers/usb/serial/usb-serial.c: serial_open - port 0
drivers/usb/serial/cp210x.c: cp210x_open - port 0
drivers/usb/serial/cp210x.c: cp210x_get_termios_port - port 0
drivers/usb/serial/cp210x.c: cp210x_get_termios_port - baud rate = 115200
drivers/usb/serial/cp210x.c: cp210x_get_termios_port - data bits = 8
drivers/usb/serial/cp210x.c: cp210x_get_termios_port - parity = NONE
drivers/usb/serial/cp210x.c: cp210x_get_termios_port - stop bits = 1
drivers/usb/serial/cp210x.c: cp210x_get_termios_port - flow control = NONE
drivers/usb/serial/cp210x.c: cp210x_tiocmset_port - port 0
drivers/usb/serial/cp210x.c: cp210x_tiocmset_port - control = 0x0303
drivers/usb/serial/usb-serial.c: serial_write_room - port 0
drivers/usb/serial/generic.c: usb_serial_generic_write_room - port 0
drivers/usb/serial/generic.c: usb_serial_generic_write_room - returns 4096
drivers/usb/serial/usb-serial.c: serial_write - port 0, 5 byte(s)
drivers/usb/serial/generic.c: usb_serial_generic_write - port 0
cp210x ttyUSB0: usb_serial_generic_write_start - length = 5, data = 48 65 6c 6c 6f
drivers/usb/serial/usb-serial.c: serial_chars_in_buffer = port 0
drivers/usb/serial/generic.c: usb_serial_generic_chars_in_buffer - port 0
drivers/usb/serial/generic.c: usb_serial_generic_chars_in_buffer - returns 0
drivers/usb/serial/usb-serial.c: serial_write_room - port 0
drivers/usb/serial/generic.c: usb_serial_generic_write_room - port 0
drivers/usb/serial/generic.c: usb_serial_generic_write_room - returns 4096
drivers/usb/serial/generic.c: usb_serial_generic_write_bulk_callback - port 0
drivers/usb/serial/usb-serial.c: usb_serial_port_work - port 0
Leaving usb_serial_port_work
drivers/usb/serial/generic.c: usb_serial_generic_read_bulk_callback - port 0
drivers/usb/serial/generic.c: usb_serial_generic_read_bulk_callback - nonzero read bulk status received: -71
Router info
Router Name OpenWrt
Router Model D-Link DIR-600 rev. A1
Firmware Version OpenWrt Backfire 10.03.1-RC5 / LuCI Trunk (trunk+svn8384)
Kernel Version 2.6.32.27
I follow these link to port openwrt on my Router,
http://wiki.openwrt.org/toh/d-link/dir-615
http://wiki.openwrt.org/toh/d-link/dir-615/ex-usb
