Re: [PATCH V4 1/1] usb:serial:f81534 add F81532/534 driver

2015-07-15 Thread Johan Hovold
On Wed, Jul 15, 2015 at 04:55:19PM +0800, Peter Hung wrote:
> Hi Paul & Johan
> 
> Paul Bolle 於 2015/7/15 下午 04:36 寫道:
> > Just a few nits, I'm afraid.
> >> +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.

No problem, I'll wait for v5.

Thanks,
Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V4 1/1] usb:serial:f81534 add F81532/534 driver

2015-07-15 Thread Peter Hung

Hi Paul & Johan

Paul Bolle 於 2015/7/15 下午 04:36 寫道:

Just a few nits, I'm afraid.

+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.
--
With Best Regards,
Peter Hung
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V4 1/1] usb:serial:f81534 add F81532/534 driver

2015-07-15 Thread Paul Bolle
Just a few nits, I'm afraid.

On di, 2015-07-14 at 11:13 +0800, Peter Hung wrote:
> --- /dev/null
> +++ b/drivers/usb/serial/f81534.c

> +int f81534_gpio_request(struct gpio_chip *chip, unsigned offset)
> +{
> + [...]
> +}

static?

> +void f81534_gpio_free(struct gpio_chip *chip, unsigned offset)
> +{
> + [...]
> +}

Ditto.

> +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.

> +static int f81534_ioctl(struct tty_struct *tty, unsigned int cmd,
> + unsigned long arg)
> +{
> + [...]
> + case TIOCSRS485:
> + return f81534_ioctl_set_rs485(port,
> +   (struct serial_rs485 __user *)
> +   arg);
> + [...]
> +}

> +int f81534_prepare_write_buffer(struct usb_serial_port *port,
> + void *dest, size_t size)
> +{
> + [...]
> +}

Ditto.

> +static struct usb_serial_driver f81534_device = {
> + [...]
> + .prepare_write_buffer = f81534_prepare_write_buffer,
> + .[...]
> +};
> +
> +static struct usb_serial_driver *const serial_drivers[] = {
> + _device, NULL
> +};
> +

If you drop this empty line ...

> +module_usb_serial_driver(serial_drivers, id_table);

and add an empty line here, things look neater.

> +MODULE_DESCRIPTION(DRIVER_DESC);
> +MODULE_AUTHOR("Peter Hong ");
> +MODULE_AUTHOR("Tom Tsai ");
> +MODULE_LICENSE("GPL");

Thanks,


Paul Bolle
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V4 1/1] usb:serial:f81534 add F81532/534 driver

2015-07-15 Thread Paul Bolle
Just a few nits, I'm afraid.

On di, 2015-07-14 at 11:13 +0800, Peter Hung wrote:
 --- /dev/null
 +++ b/drivers/usb/serial/f81534.c

 +int f81534_gpio_request(struct gpio_chip *chip, unsigned offset)
 +{
 + [...]
 +}

static?

 +void f81534_gpio_free(struct gpio_chip *chip, unsigned offset)
 +{
 + [...]
 +}

Ditto.

 +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.

 +static int f81534_ioctl(struct tty_struct *tty, unsigned int cmd,
 + unsigned long arg)
 +{
 + [...]
 + case TIOCSRS485:
 + return f81534_ioctl_set_rs485(port,
 +   (struct serial_rs485 __user *)
 +   arg);
 + [...]
 +}

 +int f81534_prepare_write_buffer(struct usb_serial_port *port,
 + void *dest, size_t size)
 +{
 + [...]
 +}

Ditto.

 +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 ...

 +module_usb_serial_driver(serial_drivers, id_table);

and add an empty line here, things look neater.

 +MODULE_DESCRIPTION(DRIVER_DESC);
 +MODULE_AUTHOR(Peter Hong peter_h...@fintek.com.tw);
 +MODULE_AUTHOR(Tom Tsai tom_t...@fintek.com.tw);
 +MODULE_LICENSE(GPL);

Thanks,


Paul Bolle
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V4 1/1] usb:serial:f81534 add F81532/534 driver

2015-07-15 Thread Peter Hung

Hi Paul  Johan

Paul Bolle 於 2015/7/15 下午 04:36 寫道:

Just a few nits, I'm afraid.

+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.
--
With Best Regards,
Peter Hung
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V4 1/1] usb:serial:f81534 add F81532/534 driver

2015-07-15 Thread Johan Hovold
On Wed, Jul 15, 2015 at 04:55:19PM +0800, Peter Hung wrote:
 Hi Paul  Johan
 
 Paul Bolle 於 2015/7/15 下午 04:36 寫道:
  Just a few nits, I'm afraid.
  +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.

No problem, I'll wait for v5.

Thanks,
Johan
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V4 1/1] usb:serial:f81534 add F81532/534 driver

2015-07-13 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 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]/value
   which 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

Signed-off-by: Peter Hung 
---
 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

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 as a module, choose M here: the
+ module will be called f81534.
+
+
 config USB_SERIAL_GARMIN
tristate "USB Garmin GPS driver"
help
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index 349d9df..9e43b7b 100644
--- 

[PATCH V4 1/1] usb:serial:f81534 add F81532/534 driver

2015-07-13 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 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]/value
   which 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

Signed-off-by: Peter Hung hpeter+linux_ker...@gmail.com
---
 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

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 as a module, choose M here: the
+ module will be called f81534.
+
+
 config USB_SERIAL_GARMIN
tristate USB Garmin GPS driver
help
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index 349d9df..9e43b7b 100644
---