usb:serial:f81534 add F81532/534 driver
Subsystems (2)
PATCH v4 1/1 usb:serial:f81534 add F81532/534 driver
This driver is for Fintek F81532/F81534 USB to Serial Ports IC.
Features:
1. F81534 is 1-to-4 & F81532 is 1-to-2 serial ports IC
2. Support Baudrate from B50 to B1500000 (excluding B1000000).
3. The RTS signal can be transformed their behavior with configuration by default ioctl TIOCGRS485/TIOCSRS485 (for RS232/RS485/RS422 with transceiver)
If the driver setting with SER_RS485_ENABLED, the RTS signal will high with not in TX and low with in TX.
If the driver setting with SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND, the RTS signal will low with not in TX and high with in TX.
4. There are 4x3 output-only ic pins to control transceiver mode. It's can be controlled via gpiolib. We could found the gpio number from /sys/class/tty/ttyUSB[x]/device/gpiochap[yyy] where x is F81532/534 serial port and yyy is gpiochip number.
After we found chip number, we can export 3 gpios(M2/M1/M0) per serial port by
echo yyy > /sys/class/gpio/export
echo yyy+1 > /sys/class/gpio/export
echo yyy+2 > /sys/class/gpio/export
then we can control it with
echo [M0 value] > /sys/class/gpio/gpio[yyy]/value
echo [M1 value] > /sys/class/gpio/gpio[yyy+1]/value
echo [M2 value] > /sys/class/gpio/gpio[yyy+2]/valuewhich M0/M1/M2 as your desired value, value is only 0 or 1.
When configure complete, It's a must to free all gpio by
echo yyy > /sys/class/gpio/unexport
echo yyy+1 > /sys/class/gpio/unexport
echo yyy+2 > /sys/class/gpio/unexport
The driver will "save" gpio configure after we release all gpio of a serial port.
For examples to change mode & gpio with F81532/534 Evalaution Board.
F81532 EVB
port0: F81437 (RS232 only)
port1: F81439 (RS232/RS485/RS422 ... etc.) F81534 EVB
port0/1: F81437 (RS232 only) port2/3: F81439 (RS232/RS485/RS422 ... etc.)
1. RS232 Mode (Default IC Mode)
1. Set struct serial_rs485 flags "without" SER_RS485_ENABLED (control F81532/534 RTS control)
2. Set M2/M1/M0 as 0/0/1
(control F81532/534 output pin to control transceiver mode)
2. RS485 Mode (RTS Low when TX Mode)
1. Set struct serial_rs485 flags with SER_RS485_ENABLED
2. Set M2/M1/M0 as 0/1/0
3. RS485 Mode (RTS High when TX Mode)
1. Set struct serial_rs485 flags with SER_RS485_ENABLED and SER_RS485_RTS_ON_SEND
2. Set M2/M1/M0 as 0/1/1
4. RS422 Mode
1. The RTS mode is dont care.
2. Set M2/M1/M0 as 0/0/0
Please reference https://bitbucket.org/hpeter/fintek-general/src/
with f81534/tools to get set_gpio.c & set_mode.c. Please use it carefully.
Changelog
v4
1. clearify f81534_process_read_urb() with f81534_process_per_serial_block(). (referenced from mxuport.c)
2. We limited f81534_write() max tx kfifo with 124Bytes. Original subsystem is designed for auto tranmiting fifo data if available. But we must wait for tx_empty for next tx data (H/W design).
With this kfifo size limit, we can use generic subsystem api with f81534_write(). When usb_serial_generic_write_start() called after first write URB complete, the fifo will no data. The generic subsystem of write will go to idle state. Until we received TX_EMPTY and release write spinlock, the fifo will fill max 124Bytes by following f81534_write().
v3
1. Migrate read, write and some routine from custom code to usbserial subsystem callback function.
2. Use more defines to replece magic numbers to make it meaningful
3. Make more comments as document in source code.
v2
1. v1 version submit to staging tree, but Greg KH advised me to cleanup source code & re-submit it to correct subsystem
2. Remove all custom ioctl commands
--- drivers/usb/serial/Kconfig | 10 + drivers/usb/serial/Makefile | 1 + drivers/usb/serial/f81534.c | 3315 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 3326 insertions(+) create mode 100644 drivers/usb/serial/f81534.c
drivers/usb/serial/Kconfig +10 -0
@@ -255,6 +255,16 @@ config USB_SERIAL_F81232 To compile this driver as a module, choose M here: the module will be called f81232. +config USB_SERIAL_F8153X + tristate "USB Fintek F81532/534 Multi-Ports Serial Driver" + help + Say Y here if you want to use the Fintek F81532/534 Multi-Ports + usb to serial adapter. + + To compile this driver as a module, choose M here: the + module will be called f81534. + + config USB_SERIAL_GARMIN tristate "USB Garmin GPS driver" help
drivers/usb/serial/Makefile +1 -0
@@ -23,6 +23,7 @@ obj-$(CONFIG_USB_SERIAL_EDGEPORT) += io_edgeport.o obj-$(CONFIG_USB_SERIAL_EDGEPORT_TI) += io_ti.o obj-$(CONFIG_USB_SERIAL_EMPEG) += empeg.o obj-$(CONFIG_USB_SERIAL_F81232) += f81232.o +obj-$(CONFIG_USB_SERIAL_F8153X) += f81534.o obj-$(CONFIG_USB_SERIAL_FTDI_SIO) += ftdi_sio.o obj-$(CONFIG_USB_SERIAL_GARMIN) += garmin_gps.o obj-$(CONFIG_USB_SERIAL_IPAQ) += ipaq.o
drivers/usb/serial/f81534.c new file +3315 -0
2,977 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.9.1
Part of the diff is not shown here. View the raw message.
Just a few nits, I'm afraid.
drivers/usb/serial/f81534.c line 1232
Quoted 7 lines · Peter Hung
drivers/usb/serial/f81534.c new file +4
-0+int f81534_gpio_request (struct gpio_chip *chip,unsigned offset) +{ + [...] +}
static?
drivers/usb/serial/f81534.c line 1255
Quoted 4 lines
drivers/usb/serial/f81534.c new file +4
-0+void f81534_gpio_free (struct gpio_chip *chip,unsigned offset) +{ + [...] +}
Ditto.
drivers/usb/serial/f81534.c line 1283
Quoted 12 lines
drivers/usb/serial/f81534.c new file +11
-0+static struct gpio_chip f81534_gpio_chip_templete = { + [...] + .request = f81534_gpio_request, + .free = f81534_gpio_free, + [...] +}; +int f81534_ioctl_set_rs485 (struct usb_serial_port *port, +struct serial_rs485 __user *arg) +{ + [...] +}
Ditto.
Quoted 6 lines
drivers/usb/serial/f81534.c new file +6
-0+static int f81534_ioctl (struct tty_struct *tty,unsigned int cmd, +unsigned long arg) +{ + [...] +case TIOCSRS485 : + return f81534_ioctl_set_rs485(port,
drivers/usb/serial/f81534.c line 2381
Quoted 10 lines
drivers/usb/serial/f81534.c new file +9
-0+ (struct serial_rs485 __user *) + arg); + [...] +} +int f81534_prepare_write_buffer (struct usb_serial_port *port, +void *dest,size_t size) +{ + [...] +}
Ditto.
drivers/usb/serial/f81534.c line 3310
Quoted 10 lines
drivers/usb/serial/f81534.c new file +10
-0+static struct usb_serial_driver f81534_device = { + [...] + .prepare_write_buffer = f81534_prepare_write_buffer, + .[...] +}; + +static struct usb_serial_driver *const serial_drivers[] = { + &f81534_device,NULL +}; +
If you drop this empty line ...
Quoted 1 line
+module_usb_serial_driver(serial_drivers,
id_table);
and add an empty line here, things look neater.
drivers/usb/serial/f81534.c line 3315
Quoted 4 lines
drivers/usb/serial/f81534.c new file +4
-0+MODULE_DESCRIPTION (DRIVER_DESC ); +MODULE_AUTHOR ("Peter Hong <[email protected]>" ); +MODULE_AUTHOR ("Tom Tsai <[email protected]>" ); +MODULE_LICENSE ("GPL" );
Thanks,
Paul Bolle
Hi Paul & Johan
Paul Bolle 於 2015/7/15 下午 04:36 寫道:
Quoted 7 lines
Just a few nits, I'm afraid.
drivers/usb/serial/f81534.c line 1232
Quoted 4 lines
drivers/usb/serial/f81534.c new file +4
-0+int f81534_gpio_request (struct gpio_chip *chip,unsigned offset) +{ + [...] +}static?
Thanks Paul for point this out.
And sorry for Johan. It's seems to make a new patch V5. I'll merge some minor fix with newer patch.
Signature · 2 lines
With Best Regards, Peter Hung
Johan Hovold
maintainerQuoted 11 lines · Peter Hung
Hi Paul & Johan
Paul Bolle 於 2015/7/15 下午 04:36 寫道:
Quoted 7 lines
Just a few nits, I'm afraid.
drivers/usb/serial/f81534.c line 1232
Quoted 4 lines
drivers/usb/serial/f81534.c new file +4
-0+int f81534_gpio_request (struct gpio_chip *chip,unsigned offset) +{ + [...] +}static?
Quoted 4 lines
Thanks Paul for point this out.
And sorry for Johan. It's seems to make a new patch V5. I'll merge some minor fix with newer patch.
No problem, I'll wait for v5.
Thanks,
Johan