Re: [PATCH V7 1/1] usb:serial: Add Fintek F81532/534 driver

2016-01-03 Thread Johan Hovold
On Wed, Dec 02, 2015 at 03:18:59PM +0800, Peter Hung wrote:
> This driver is for Fintek F81532/F81534 USB to Serial Ports IC.

Do you have a pointer to datasheets and/or information about these
devices? Can't seem to find anything on Fintek's homepage.

> Features:
> 1. F81534 is 1-to-4 & F81532 is 1-to-2 serial ports IC
> 2. Support Baudrate from B50 to B150 (excluding B100).
> 3. The RTS signal can be transformed their behavior with
>configuration by ioctl TIOCGRS485/TIOCSRS485
> 
>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. The 4x3 output-only open-drain pins for F81532/534 is designed for
>control outer devices (with our EVB for examples, the 4 sets of pins
>are designed to control transceiver mode). So it implements as
>gpiolib interface with output-only function.
> 5. It'll save the configuration in internal storage when uart/pins mode
>changed.
> 
>Please reference https://bitbucket.org/hpeter/fintek-general/src/
>with f81534/tools to get set_gpio.c & set_mode.c to change F81532/534
>setting. Please use it carefully.
> 
> Signed-off-by: Peter Hung 
> ---
> Changelog:
> v7
> 1. Make all gpiolib function with #ifdef CONFIG_GPIOLIB marco block.
>Due to F81532/534 could run without gpiolib, we implements
>f81534_prepare_gpio()/f81534_release_gpio() always success without
>CONFIG_GPIOLIB.
> 2. Fix crash when receiving MSR change on driver load/unload. It's cause
>by f81534_process_read_urb() get read URB callback data, but port
>private data is not init complete or released. We solve with 2
>modifications.
> 
>1. add null pointer check with f81534_process_read_urb(). We'll skip
>   this report when port_priv = NULL.
>2. when "one" port f81534_port_remove() is called, kill the port-0
>   read URB before kfree port_priv.
> 
> v6
> 1. Re-implement the write()/resume() function. Due to this device cant be
>suitable with generic write(), we'll do the submit write URB when
>write()/received tx empty/set_termios()/resume()
> 2. Logic/Phy Port mapping rewrite in f81534_port_probe() &
>f81534_phy_to_logic_port().
> 3. Introduced "Port Hide" function. Some customer use F81532 reference
>design for HW layout, but really use F81534 IC. We'll check
>F81534_PORT_CONF_DISABLE_PORT flag with in uart mode field to do
>port hide with port not used. It can be avoid end-user to use not
>layouted port.
> 4. The 4x3 output-only open-drain pins for F81532/534 is designed for
>control outer devices (with our EVB for examples, the 4 sets of pins
>are designed to control transceiver mode). So we decide to implement
>with gpiolib interface.
> 5. Add device vendor id with 0x2c42

Thanks for the update.

I noticed that you have not considered all my comments on earlier
revisions of this driver. Please make sure to address all issues raised.

Also note that a review comment generally applies to all instances of
a particular issue throughout the driver even when it is not
specifically mentioned.

In order to get this driver merged, I think you should consider starting
with a subset of the functionality.

We may need to come up with a generic interface for switching tranceiver
modes as there are more drivers that could benefit from this. I think we
should prevent mode switching for a port that is open as does not seem
to make much sense.

How about you drop mode-switching support completely for now (e.g.
gpiolib and rs485-ioctl) and focus on getting the basic functionality
right first?

You could also consider extending you user-space tool and use that to
switch modes (e.g. reprogram the device eeprom) through libudev, at
least until a generic interface is in place.

As for the basic design, you should use per-interface read and write
urbs. Submit the read urb(s) when the first port is opened, and kill
them when the last device is closed. Similarly for the write urbs,
submit one when there's at least one port with data in its fifo that it
non-busy (TX_EMPTY is set).

> +#define F81534_CUSTOM_ADDRESS_START  0x2f00
> +#define F81534_CUSTOM_TOTAL_SIZE 0x10
> +#define F81534_CUSTOM_DATA_SIZE  0x10
> +#define F81534_CUSTOM_MAX_IDX\
> + (F81534_CUSTOM_TOTAL_SIZE/F81534_CUSTOM_DATA_SIZE)

Do you really expect F81534_CUSTOM_MAX_IDX to be 1?

> +#ifndef C_CMSPAR
> +#define C_CMSPAR(tty)   _C_FLAG((tty), CMSPAR)
> +#endif

Drop this.

> +/*
> + * The following magic numbers is F81532/534 output pin
> + * register maps
> + */
> +static const struct io_map_value f81534_rs232_control = {
> + FINTEK_DEVICE_ID, F81534_NUM_PORT, uart_mode_rs232,
> + 

Re: [PATCH V7 1/1] usb:serial: Add Fintek F81532/534 driver

2016-01-03 Thread Johan Hovold
On Wed, Dec 02, 2015 at 03:18:59PM +0800, Peter Hung wrote:
> This driver is for Fintek F81532/F81534 USB to Serial Ports IC.

Do you have a pointer to datasheets and/or information about these
devices? Can't seem to find anything on Fintek's homepage.

> Features:
> 1. F81534 is 1-to-4 & F81532 is 1-to-2 serial ports IC
> 2. Support Baudrate from B50 to B150 (excluding B100).
> 3. The RTS signal can be transformed their behavior with
>configuration by ioctl TIOCGRS485/TIOCSRS485
> 
>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. The 4x3 output-only open-drain pins for F81532/534 is designed for
>control outer devices (with our EVB for examples, the 4 sets of pins
>are designed to control transceiver mode). So it implements as
>gpiolib interface with output-only function.
> 5. It'll save the configuration in internal storage when uart/pins mode
>changed.
> 
>Please reference https://bitbucket.org/hpeter/fintek-general/src/
>with f81534/tools to get set_gpio.c & set_mode.c to change F81532/534
>setting. Please use it carefully.
> 
> Signed-off-by: Peter Hung 
> ---
> Changelog:
> v7
> 1. Make all gpiolib function with #ifdef CONFIG_GPIOLIB marco block.
>Due to F81532/534 could run without gpiolib, we implements
>f81534_prepare_gpio()/f81534_release_gpio() always success without
>CONFIG_GPIOLIB.
> 2. Fix crash when receiving MSR change on driver load/unload. It's cause
>by f81534_process_read_urb() get read URB callback data, but port
>private data is not init complete or released. We solve with 2
>modifications.
> 
>1. add null pointer check with f81534_process_read_urb(). We'll skip
>   this report when port_priv = NULL.
>2. when "one" port f81534_port_remove() is called, kill the port-0
>   read URB before kfree port_priv.
> 
> v6
> 1. Re-implement the write()/resume() function. Due to this device cant be
>suitable with generic write(), we'll do the submit write URB when
>write()/received tx empty/set_termios()/resume()
> 2. Logic/Phy Port mapping rewrite in f81534_port_probe() &
>f81534_phy_to_logic_port().
> 3. Introduced "Port Hide" function. Some customer use F81532 reference
>design for HW layout, but really use F81534 IC. We'll check
>F81534_PORT_CONF_DISABLE_PORT flag with in uart mode field to do
>port hide with port not used. It can be avoid end-user to use not
>layouted port.
> 4. The 4x3 output-only open-drain pins for F81532/534 is designed for
>control outer devices (with our EVB for examples, the 4 sets of pins
>are designed to control transceiver mode). So we decide to implement
>with gpiolib interface.
> 5. Add device vendor id with 0x2c42

Thanks for the update.

I noticed that you have not considered all my comments on earlier
revisions of this driver. Please make sure to address all issues raised.

Also note that a review comment generally applies to all instances of
a particular issue throughout the driver even when it is not
specifically mentioned.

In order to get this driver merged, I think you should consider starting
with a subset of the functionality.

We may need to come up with a generic interface for switching tranceiver
modes as there are more drivers that could benefit from this. I think we
should prevent mode switching for a port that is open as does not seem
to make much sense.

How about you drop mode-switching support completely for now (e.g.
gpiolib and rs485-ioctl) and focus on getting the basic functionality
right first?

You could also consider extending you user-space tool and use that to
switch modes (e.g. reprogram the device eeprom) through libudev, at
least until a generic interface is in place.

As for the basic design, you should use per-interface read and write
urbs. Submit the read urb(s) when the first port is opened, and kill
them when the last device is closed. Similarly for the write urbs,
submit one when there's at least one port with data in its fifo that it
non-busy (TX_EMPTY is set).

> +#define F81534_CUSTOM_ADDRESS_START  0x2f00
> +#define F81534_CUSTOM_TOTAL_SIZE 0x10
> +#define F81534_CUSTOM_DATA_SIZE  0x10
> +#define F81534_CUSTOM_MAX_IDX\
> + (F81534_CUSTOM_TOTAL_SIZE/F81534_CUSTOM_DATA_SIZE)

Do you really expect F81534_CUSTOM_MAX_IDX to be 1?

> +#ifndef C_CMSPAR
> +#define C_CMSPAR(tty)   _C_FLAG((tty), CMSPAR)
> +#endif

Drop this.

> +/*
> + * The following magic numbers is F81532/534 output pin
> + * register maps
> + */
> +static const struct io_map_value f81534_rs232_control = {
> + FINTEK_DEVICE_ID, 

Re: [PATCH V7 1/1] usb:serial: Add Fintek F81532/534 driver

2015-12-05 Thread kbuild test robot
Hi Peter,

[auto build test ERROR on usb/usb-testing]
[also build test ERROR on v4.4-rc3 next-20151203]

url:
https://github.com/0day-ci/linux/commits/Peter-Hung/usb-serial-Add-Fintek-F81532-534-driver/20151202-152239
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git 
usb-testing
config: mips-allmodconfig (attached as .config)
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=mips 

All errors (new ones prefixed by >>):

   drivers/usb/serial/f81534.c:514:1: warning: data definition has no type or 
storage class
MODULE_DEVICE_TABLE(usb, id_table);
^
>> drivers/usb/serial/f81534.c:514:1: error: type defaults to 'int' in 
>> declaration of 'MODULE_DEVICE_TABLE' [-Werror=implicit-int]
   drivers/usb/serial/f81534.c:514:1: warning: parameter names (without types) 
in function declaration
   In file included from drivers/usb/serial/f81534.c:103:0:
   include/linux/usb/serial.h:403:1: warning: data definition has no type or 
storage class
module_init(usb_serial_module_init); \
^
   include/linux/usb/serial.h:411:2: note: in expansion of macro 
'usb_serial_module_driver'
 usb_serial_module_driver(KBUILD_MODNAME, __serial_drivers, __ids)
 ^
   drivers/usb/serial/f81534.c:2940:1: note: in expansion of macro 
'module_usb_serial_driver'
module_usb_serial_driver(serial_drivers, id_table);
^
>> include/linux/usb/serial.h:403:1: error: type defaults to 'int' in 
>> declaration of 'module_init' [-Werror=implicit-int]
module_init(usb_serial_module_init); \
^
   include/linux/usb/serial.h:411:2: note: in expansion of macro 
'usb_serial_module_driver'
 usb_serial_module_driver(KBUILD_MODNAME, __serial_drivers, __ids)
 ^
   drivers/usb/serial/f81534.c:2940:1: note: in expansion of macro 
'module_usb_serial_driver'
module_usb_serial_driver(serial_drivers, id_table);
^
   drivers/usb/serial/f81534.c:2940:1: warning: parameter names (without types) 
in function declaration
   In file included from drivers/usb/serial/f81534.c:103:0:
   include/linux/usb/serial.h:408:1: warning: data definition has no type or 
storage class
module_exit(usb_serial_module_exit);
^
   include/linux/usb/serial.h:411:2: note: in expansion of macro 
'usb_serial_module_driver'
 usb_serial_module_driver(KBUILD_MODNAME, __serial_drivers, __ids)
 ^
   drivers/usb/serial/f81534.c:2940:1: note: in expansion of macro 
'module_usb_serial_driver'
module_usb_serial_driver(serial_drivers, id_table);
^
>> include/linux/usb/serial.h:408:1: error: type defaults to 'int' in 
>> declaration of 'module_exit' [-Werror=implicit-int]
module_exit(usb_serial_module_exit);
^
   include/linux/usb/serial.h:411:2: note: in expansion of macro 
'usb_serial_module_driver'
 usb_serial_module_driver(KBUILD_MODNAME, __serial_drivers, __ids)
 ^
   drivers/usb/serial/f81534.c:2940:1: note: in expansion of macro 
'module_usb_serial_driver'
module_usb_serial_driver(serial_drivers, id_table);
^
   drivers/usb/serial/f81534.c:2940:1: warning: parameter names (without types) 
in function declaration
>> drivers/usb/serial/f81534.c:154:2: error: expected declaration specifiers or 
>> '...' before string constant
 "Fintek USB to Serial Ports Driver (F81532/F81534-Evaluation Board)"
 ^
   drivers/usb/serial/f81534.c:2942:20: note: in expansion of macro 
'DRIVER_DESC'
MODULE_DESCRIPTION(DRIVER_DESC);
   ^
   drivers/usb/serial/f81534.c:2943:15: error: expected declaration specifiers 
or '...' before string constant
MODULE_AUTHOR("Peter Hong ");
  ^
   drivers/usb/serial/f81534.c:2944:15: error: expected declaration specifiers 
or '...' before string constant
MODULE_AUTHOR("Tom Tsai ");
  ^
   drivers/usb/serial/f81534.c:2945:16: error: expected declaration specifiers 
or '...' before string constant
MODULE_LICENSE("GPL");
   ^
   In file included from drivers/usb/serial/f81534.c:103:0:
   include/linux/usb/serial.h:398:19: warning: 'usb_serial_module_init' defined 
but not used [-Wunused-function]
static int __init usb_serial_module_init(void)\
  ^
   include/linux/usb/serial.h:411:2: note: in expansion of macro 
'usb_serial_module_driver'
 usb_serial_module_driver(KBUILD_MODNAME, __serial_drivers, __ids)
 ^
   drivers/usb/serial/f81534.c:2940:1: note: in expansion of macro 
'module_usb_serial_driver'
module_usb_serial_driver(serial_drivers, id_table);
^
   include/linux/usb/serial.h:404:20: warning: 'usb_serial_module_exit' defined 
but not used [-Wunused-function]
static void __exit usb_serial_module_exit(void)\
   ^
   include/linux/usb/serial.h:411:2: note: in expansion of macro 

Re: [PATCH V7 1/1] usb:serial: Add Fintek F81532/534 driver

2015-12-05 Thread kbuild test robot
Hi Peter,

[auto build test ERROR on usb/usb-testing]
[also build test ERROR on v4.4-rc3 next-20151203]

url:
https://github.com/0day-ci/linux/commits/Peter-Hung/usb-serial-Add-Fintek-F81532-534-driver/20151202-152239
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git 
usb-testing
config: mips-allmodconfig (attached as .config)
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=mips 

All errors (new ones prefixed by >>):

   drivers/usb/serial/f81534.c:514:1: warning: data definition has no type or 
storage class
MODULE_DEVICE_TABLE(usb, id_table);
^
>> drivers/usb/serial/f81534.c:514:1: error: type defaults to 'int' in 
>> declaration of 'MODULE_DEVICE_TABLE' [-Werror=implicit-int]
   drivers/usb/serial/f81534.c:514:1: warning: parameter names (without types) 
in function declaration
   In file included from drivers/usb/serial/f81534.c:103:0:
   include/linux/usb/serial.h:403:1: warning: data definition has no type or 
storage class
module_init(usb_serial_module_init); \
^
   include/linux/usb/serial.h:411:2: note: in expansion of macro 
'usb_serial_module_driver'
 usb_serial_module_driver(KBUILD_MODNAME, __serial_drivers, __ids)
 ^
   drivers/usb/serial/f81534.c:2940:1: note: in expansion of macro 
'module_usb_serial_driver'
module_usb_serial_driver(serial_drivers, id_table);
^
>> include/linux/usb/serial.h:403:1: error: type defaults to 'int' in 
>> declaration of 'module_init' [-Werror=implicit-int]
module_init(usb_serial_module_init); \
^
   include/linux/usb/serial.h:411:2: note: in expansion of macro 
'usb_serial_module_driver'
 usb_serial_module_driver(KBUILD_MODNAME, __serial_drivers, __ids)
 ^
   drivers/usb/serial/f81534.c:2940:1: note: in expansion of macro 
'module_usb_serial_driver'
module_usb_serial_driver(serial_drivers, id_table);
^
   drivers/usb/serial/f81534.c:2940:1: warning: parameter names (without types) 
in function declaration
   In file included from drivers/usb/serial/f81534.c:103:0:
   include/linux/usb/serial.h:408:1: warning: data definition has no type or 
storage class
module_exit(usb_serial_module_exit);
^
   include/linux/usb/serial.h:411:2: note: in expansion of macro 
'usb_serial_module_driver'
 usb_serial_module_driver(KBUILD_MODNAME, __serial_drivers, __ids)
 ^
   drivers/usb/serial/f81534.c:2940:1: note: in expansion of macro 
'module_usb_serial_driver'
module_usb_serial_driver(serial_drivers, id_table);
^
>> include/linux/usb/serial.h:408:1: error: type defaults to 'int' in 
>> declaration of 'module_exit' [-Werror=implicit-int]
module_exit(usb_serial_module_exit);
^
   include/linux/usb/serial.h:411:2: note: in expansion of macro 
'usb_serial_module_driver'
 usb_serial_module_driver(KBUILD_MODNAME, __serial_drivers, __ids)
 ^
   drivers/usb/serial/f81534.c:2940:1: note: in expansion of macro 
'module_usb_serial_driver'
module_usb_serial_driver(serial_drivers, id_table);
^
   drivers/usb/serial/f81534.c:2940:1: warning: parameter names (without types) 
in function declaration
>> drivers/usb/serial/f81534.c:154:2: error: expected declaration specifiers or 
>> '...' before string constant
 "Fintek USB to Serial Ports Driver (F81532/F81534-Evaluation Board)"
 ^
   drivers/usb/serial/f81534.c:2942:20: note: in expansion of macro 
'DRIVER_DESC'
MODULE_DESCRIPTION(DRIVER_DESC);
   ^
   drivers/usb/serial/f81534.c:2943:15: error: expected declaration specifiers 
or '...' before string constant
MODULE_AUTHOR("Peter Hong ");
  ^
   drivers/usb/serial/f81534.c:2944:15: error: expected declaration specifiers 
or '...' before string constant
MODULE_AUTHOR("Tom Tsai ");
  ^
   drivers/usb/serial/f81534.c:2945:16: error: expected declaration specifiers 
or '...' before string constant
MODULE_LICENSE("GPL");
   ^
   In file included from drivers/usb/serial/f81534.c:103:0:
   include/linux/usb/serial.h:398:19: warning: 'usb_serial_module_init' defined 
but not used [-Wunused-function]
static int __init usb_serial_module_init(void)\
  ^
   include/linux/usb/serial.h:411:2: note: in expansion of macro 
'usb_serial_module_driver'
 usb_serial_module_driver(KBUILD_MODNAME, __serial_drivers, __ids)
 ^
   drivers/usb/serial/f81534.c:2940:1: note: in expansion of macro 
'module_usb_serial_driver'
module_usb_serial_driver(serial_drivers, id_table);
^
   include/linux/usb/serial.h:404:20: warning: 'usb_serial_module_exit' defined 
but not used [-Wunused-function]
static void __exit usb_serial_module_exit(void)\
   ^
   include/linux/usb/serial.h:411:2: 

[PATCH V7 1/1] usb:serial: Add Fintek F81532/534 driver

2015-12-01 Thread Peter Hung
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 B150 (excluding B100).
3. The RTS signal can be transformed their behavior with
   configuration by ioctl TIOCGRS485/TIOCSRS485

   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. The 4x3 output-only open-drain pins for F81532/534 is designed for
   control outer devices (with our EVB for examples, the 4 sets of pins
   are designed to control transceiver mode). So it implements as
   gpiolib interface with output-only function.
5. It'll save the configuration in internal storage when uart/pins mode
   changed.

   Please reference https://bitbucket.org/hpeter/fintek-general/src/
   with f81534/tools to get set_gpio.c & set_mode.c to change F81532/534
   setting. Please use it carefully.

Signed-off-by: Peter Hung 
---
Changelog:
v7
1. Make all gpiolib function with #ifdef CONFIG_GPIOLIB marco block.
   Due to F81532/534 could run without gpiolib, we implements
   f81534_prepare_gpio()/f81534_release_gpio() always success without
   CONFIG_GPIOLIB.
2. Fix crash when receiving MSR change on driver load/unload. It's cause
   by f81534_process_read_urb() get read URB callback data, but port
   private data is not init complete or released. We solve with 2
   modifications.

   1. add null pointer check with f81534_process_read_urb(). We'll skip
  this report when port_priv = NULL.
   2. when "one" port f81534_port_remove() is called, kill the port-0
  read URB before kfree port_priv.

v6
1. Re-implement the write()/resume() function. Due to this device cant be
   suitable with generic write(), we'll do the submit write URB when
   write()/received tx empty/set_termios()/resume()
2. Logic/Phy Port mapping rewrite in f81534_port_probe() &
   f81534_phy_to_logic_port().
3. Introduced "Port Hide" function. Some customer use F81532 reference
   design for HW layout, but really use F81534 IC. We'll check
   F81534_PORT_CONF_DISABLE_PORT flag with in uart mode field to do
   port hide with port not used. It can be avoid end-user to use not
   layouted port.
4. The 4x3 output-only open-drain pins for F81532/534 is designed for
   control outer devices (with our EVB for examples, the 4 sets of pins
   are designed to control transceiver mode). So we decide to implement
   with gpiolib interface.
5. Add device vendor id with 0x2c42

v5
1. Change f81534_port_disable/enable() from H/W mode to S/W mode
   It'll skip all rx data when port is not opened.
2. Some function modifier add with static (Thanks for Paul Bolle)
3. It's will direct return when count=0 in f81534_write() to
   reduce spin_lock usage.

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 | 2945 +++
 3 files changed, 2956 insertions(+)
 create mode 100644 drivers/usb/serial/f81534.c

diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index 56ecb8b..0642864 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -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 

[PATCH V7 1/1] usb:serial: Add Fintek F81532/534 driver

2015-12-01 Thread Peter Hung
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 B150 (excluding B100).
3. The RTS signal can be transformed their behavior with
   configuration by ioctl TIOCGRS485/TIOCSRS485

   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. The 4x3 output-only open-drain pins for F81532/534 is designed for
   control outer devices (with our EVB for examples, the 4 sets of pins
   are designed to control transceiver mode). So it implements as
   gpiolib interface with output-only function.
5. It'll save the configuration in internal storage when uart/pins mode
   changed.

   Please reference https://bitbucket.org/hpeter/fintek-general/src/
   with f81534/tools to get set_gpio.c & set_mode.c to change F81532/534
   setting. Please use it carefully.

Signed-off-by: Peter Hung 
---
Changelog:
v7
1. Make all gpiolib function with #ifdef CONFIG_GPIOLIB marco block.
   Due to F81532/534 could run without gpiolib, we implements
   f81534_prepare_gpio()/f81534_release_gpio() always success without
   CONFIG_GPIOLIB.
2. Fix crash when receiving MSR change on driver load/unload. It's cause
   by f81534_process_read_urb() get read URB callback data, but port
   private data is not init complete or released. We solve with 2
   modifications.

   1. add null pointer check with f81534_process_read_urb(). We'll skip
  this report when port_priv = NULL.
   2. when "one" port f81534_port_remove() is called, kill the port-0
  read URB before kfree port_priv.

v6
1. Re-implement the write()/resume() function. Due to this device cant be
   suitable with generic write(), we'll do the submit write URB when
   write()/received tx empty/set_termios()/resume()
2. Logic/Phy Port mapping rewrite in f81534_port_probe() &
   f81534_phy_to_logic_port().
3. Introduced "Port Hide" function. Some customer use F81532 reference
   design for HW layout, but really use F81534 IC. We'll check
   F81534_PORT_CONF_DISABLE_PORT flag with in uart mode field to do
   port hide with port not used. It can be avoid end-user to use not
   layouted port.
4. The 4x3 output-only open-drain pins for F81532/534 is designed for
   control outer devices (with our EVB for examples, the 4 sets of pins
   are designed to control transceiver mode). So we decide to implement
   with gpiolib interface.
5. Add device vendor id with 0x2c42

v5
1. Change f81534_port_disable/enable() from H/W mode to S/W mode
   It'll skip all rx data when port is not opened.
2. Some function modifier add with static (Thanks for Paul Bolle)
3. It's will direct return when count=0 in f81534_write() to
   reduce spin_lock usage.

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 | 2945 +++
 3 files changed, 2956 insertions(+)
 create mode 100644 drivers/usb/serial/f81534.c

diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index 56ecb8b..0642864 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -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.
+
+