Re: [PATCH v3] USB: Add uPD78F0730 USB to Serial Adaptor Driver

2017-01-19 Thread Maksim Salau
Hi Johan,

> And keep the current modem-control-signal polarity. What are the levels
> of these signals when coming out of reset (i.e. after having connected
> the device, but not opened it yet)?

Thanks.
RTS is low (0V) after plugging the device in.

Regards,
Maksim.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] USB: Add uPD78F0730 USB to Serial Adaptor Driver

2017-01-17 Thread Johan Hovold
On Tue, Jan 17, 2017 at 04:25:18PM +0300, Maksim Salau wrote:
> Hi Johan,
> 
> > I think it's right to keep them as in the current version of the patch
> > (i.e. active high) which is accordance with the datasheet, but if
> > possible you should verify the levels when using hardware flow control
> > to be certain that the polarity is not inverted when enabling hardware
> > flow control.
> 
> It seems to me that CTSRTS flow control is not implemented
> in the device I have. I tried to send lots of data to cause level change
> of the RTS signal with no success. Also I tried to:
> 1. open port;
> 2. disable CTSRTS flow control;
> 3. set RTS to a specific level;
> 4. enable CTSRTS flow control;
> 5. send some data.
>
> I tried the sequence above with RTS set and reset, and I can conclude that
> step 4 doesn't affect RTS signal at all.

Ok, thanks for testing. Better leave CRTSCTS unimplemented for now then.

And keep the current modem-control-signal polarity. What are the levels
of these signals when coming out of reset (i.e. after having connected
the device, but not opened it yet)?

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


Re: [PATCH v3] USB: Add uPD78F0730 USB to Serial Adaptor Driver

2017-01-17 Thread Maksim Salau
Hi Johan,

> I think it's right to keep them as in the current version of the patch
> (i.e. active high) which is accordance with the datasheet, but if
> possible you should verify the levels when using hardware flow control
> to be certain that the polarity is not inverted when enabling hardware
> flow control.

It seems to me that CTSRTS flow control is not implemented
in the device I have. I tried to send lots of data to cause level change
of the RTS signal with no success. Also I tried to:
1. open port;
2. disable CTSRTS flow control;
3. set RTS to a specific level;
4. enable CTSRTS flow control;
5. send some data.

I tried the sequence above with RTS set and reset, and I can conclude that
step 4 doesn't affect RTS signal at all.

Best regards,
Maksim.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] USB: Add uPD78F0730 USB to Serial Adaptor Driver

2017-01-11 Thread Johan Hovold
On Wed, Jan 11, 2017 at 10:49:22AM +0300, Maksim Salau wrote:
> Hi Johan,
> 
> Thanks for feedback.
> 
> > > * Dropped inversion of DTR and RTS signals
> > 
> > Did you figure out whether this was needed or not, for example by
> > comparing to the hardware flow control levels?
> 
> The current version matches the Windows driver.
> 
> I don't have any other adapters at the moment, but
> here is what I get from the adaptor with the current version of the driver:
>   mcr = TIOCM_RTS;
>   ioctl(fd, TIOCMBIC, ); /* results in low level (0V) */
>   ioctl(fd, TIOCMBIS, ); /* results in high level (5V) */
> 
> As far as I know, this is not the way other adaptors work.
> Please, correct me if I'm wrong.

Yes, the control lines are typically active low for TTL-level logic, but
I don't think it's standardised (e.g. as it is for RS-232).

I think it's right to keep them as in the current version of the patch
(i.e. active high) which is accordance with the datasheet, but if
possible you should verify the levels when using hardware flow control
to be certain that the polarity is not inverted when enabling hardware
flow control.

> > > The device I have have only one output signal that is toggled by
> > > tiocmset(fd, TIOCM_DTR, 0) and tiocmset(fd, TIOCM_RTS, 0).
> > 
> > What do you mean by the above? Does your device only have one of DTR and
> > RTS wired? I'd still expect you to only use one of the TIOCM defines to
> > set and clear it.
> 
> Sorry, I was wrong in the way I interpret behavior of my test program.
> The board I have has only RTS wired. I've just verified with a logic analyzer
> that everything is fine with signals (RTS is controlled like mentioned above,
> DTR is not wired or disabled in firmware). Sorry for the mess.

No, worries. Thanks for clarifying.

Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] USB: Add uPD78F0730 USB to Serial Adaptor Driver

2017-01-10 Thread Maksim Salau
Hi Johan,

Thanks for feedback.

> > * Dropped inversion of DTR and RTS signals
> 
> Did you figure out whether this was needed or not, for example by
> comparing to the hardware flow control levels?

The current version matches the Windows driver.

I don't have any other adapters at the moment, but
here is what I get from the adaptor with the current version of the driver:
  mcr = TIOCM_RTS;
  ioctl(fd, TIOCMBIC, ); /* results in low level (0V) */
  ioctl(fd, TIOCMBIS, ); /* results in high level (5V) */

As far as I know, this is not the way other adaptors work.
Please, correct me if I'm wrong.

> > The device I have have only one output signal that is toggled by
> > tiocmset(fd, TIOCM_DTR, 0) and tiocmset(fd, TIOCM_RTS, 0).
> 
> What do you mean by the above? Does your device only have one of DTR and
> RTS wired? I'd still expect you to only use one of the TIOCM defines to
> set and clear it.

Sorry, I was wrong in the way I interpret behavior of my test program.
The board I have has only RTS wired. I've just verified with a logic analyzer
that everything is fine with signals (RTS is controlled like mentioned above,
DTR is not wired or disabled in firmware). Sorry for the mess.

Thanks,
Maksim.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] USB: Add uPD78F0730 USB to Serial Adaptor Driver

2017-01-09 Thread Johan Hovold
On Thu, Dec 08, 2016 at 10:13:37PM +0300, Maksim Salau wrote:
> The adaptor can be found on development boards for 78k, RL78 and V850
> microcontrollers produced by Renesas Electronics Corporation.
> 
> This is not a full-featured USB to serial converter, however it allows
> basic communication and simple control which is enough for programming of
> on-board flash and debugging through a debug monitor.
> 
> uPD78F0730 is a USB-enabled microcontroller with USB-to-UART conversion
> implemented in firmware.
> 
> This chip is also present in some debugging adaptors which use it for
> USB-to-SPI conversion as well. The present driver doesn't cover SPI,
> only USB-to-UART conversion is supported.
> 
> Signed-off-by: Maksim Salau 
> ---
> 
> PATCH v2 can be found here:
> http://thread.gmane.org/gmane.linux.usb.general/137999
> 
> Changes from v2:
> * Addressed all comments
> * Dropped inversion of DTR and RTS signals

Did you figure out whether this was needed or not, for example by
comparing to the hardware flow control levels?

> * Removed support of software flow control and
>   added hardware flow control (Both are untested)
> 
> The device I have have only one output signal that is toggled by
> tiocmset(fd, TIOCM_DTR, 0) and tiocmset(fd, TIOCM_RTS, 0).

What do you mean by the above? Does your device only have one of DTR and
RTS wired? I'd still expect you to only use one of the TIOCM defines to
set and clear it.
 
>  drivers/usb/serial/Kconfig  |   9 +
>  drivers/usb/serial/Makefile |   1 +
>  drivers/usb/serial/upd78f0730.c | 445 
> 
>  3 files changed, 455 insertions(+)
>  create mode 100644 drivers/usb/serial/upd78f0730.c
> 
> diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
> index 56ecb8b..311d1cf 100644
> --- a/drivers/usb/serial/Kconfig
> +++ b/drivers/usb/serial/Kconfig
> @@ -703,6 +703,15 @@ config USB_SERIAL_QT2
> To compile this driver as a module, choose M here: the
> module will be called quatech-serial.
>  
> +config USB_SERIAL_UPD78F0730
> + tristate "USB Renesas uPD78F0730 Single Port Serial Driver"
> + help
> +   Say Y here if you want to use the Renesas uPD78F0730
> +   serial driver.
> +
> +   To compile this driver as a module, choose M here: the
> +   module will be called upd78f0730.
> +
>  config USB_SERIAL_DEBUG
>   tristate "USB Debugging Device"
>   help
> diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
> index 349d9df..93fc707 100644
> --- a/drivers/usb/serial/Makefile
> +++ b/drivers/usb/serial/Makefile
> @@ -60,3 +60,4 @@ obj-$(CONFIG_USB_SERIAL_WISHBONE)   += 
> wishbone-serial.o
>  obj-$(CONFIG_USB_SERIAL_WHITEHEAT)   += whiteheat.o
>  obj-$(CONFIG_USB_SERIAL_XIRCOM)  += keyspan_pda.o
>  obj-$(CONFIG_USB_SERIAL_XSENS_MT)+= xsens_mt.o
> +obj-$(CONFIG_USB_SERIAL_UPD78F0730)  += upd78f0730.o

Please keep the entries sorted by config-symbol name (i.e. put it after
CONFIG_USB_SERIAL_TI).

> diff --git a/drivers/usb/serial/upd78f0730.c b/drivers/usb/serial/upd78f0730.c
> new file mode 100644
> index 000..e2bed13
> --- /dev/null
> +++ b/drivers/usb/serial/upd78f0730.c
> @@ -0,0 +1,445 @@
> +/*
> + * Renesas Electronics uPD78F0730 USB to serial converter driver
> + *
> + * Copyright (C) 2014,2016 Maksim Salau 
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * as published by the Free Software Foundation.

As I mentioned in my comments to v2, this should match the
MODULE_LICENSE below which is currently "GPL" (GNU Public License v2 or
later).

Either use "GPL v2" as MODULE_LICENSE or update the text here.

> + *
> + * Protocol of the adaptor is described in the application note 
> U19660EJ1V0AN00
> + * μPD78F0730 8-bit Single-Chip Microcontroller
> + * USB-to-Serial Conversion Software
> + * 
> + *
> + * The adaptor functionality is limited to the following:
> + * - data bits: 7 or 8
> + * - stop bits: 1 or 2
> + * - parity: even, odd or none
> + * - flow control: hardware or none
> + * - baud rates: 2400, 4800, 9600, 19200, 38400, 57600, 115200
> + * - signals: DTS, RTS and BREAK

DTR?

> + * - there is an option to enable parity error character substitution,
> + *   but is not supported by the driver
> + * - XON/XOFF flow control is described in the document,
> + *   but is not supported by the driver
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define DRIVER_DESC "Renesas uPD78F0730 USB to serial converter driver"
> +
> +#define DRIVER_AUTHOR "Maksim Salau "
> +
> +static const struct usb_device_id id_table[] = {
> + { USB_DEVICE(0x045B, 0x0212) }, /* 

[PATCH v3] USB: Add uPD78F0730 USB to Serial Adaptor Driver

2016-12-08 Thread Maksim Salau
The adaptor can be found on development boards for 78k, RL78 and V850
microcontrollers produced by Renesas Electronics Corporation.

This is not a full-featured USB to serial converter, however it allows
basic communication and simple control which is enough for programming of
on-board flash and debugging through a debug monitor.

uPD78F0730 is a USB-enabled microcontroller with USB-to-UART conversion
implemented in firmware.

This chip is also present in some debugging adaptors which use it for
USB-to-SPI conversion as well. The present driver doesn't cover SPI,
only USB-to-UART conversion is supported.

Signed-off-by: Maksim Salau 
---

PATCH v2 can be found here:
http://thread.gmane.org/gmane.linux.usb.general/137999

Changes from v2:
* Addressed all comments
* Dropped inversion of DTR and RTS signals
* Removed support of software flow control and
  added hardware flow control (Both are untested)

The device I have have only one output signal that is toggled by
tiocmset(fd, TIOCM_DTR, 0) and tiocmset(fd, TIOCM_RTS, 0).

Thanks,
Maksim.

 drivers/usb/serial/Kconfig  |   9 +
 drivers/usb/serial/Makefile |   1 +
 drivers/usb/serial/upd78f0730.c | 445 
 3 files changed, 455 insertions(+)
 create mode 100644 drivers/usb/serial/upd78f0730.c

diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index 56ecb8b..311d1cf 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -703,6 +703,15 @@ config USB_SERIAL_QT2
  To compile this driver as a module, choose M here: the
  module will be called quatech-serial.
 
+config USB_SERIAL_UPD78F0730
+   tristate "USB Renesas uPD78F0730 Single Port Serial Driver"
+   help
+ Say Y here if you want to use the Renesas uPD78F0730
+ serial driver.
+
+ To compile this driver as a module, choose M here: the
+ module will be called upd78f0730.
+
 config USB_SERIAL_DEBUG
tristate "USB Debugging Device"
help
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index 349d9df..93fc707 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -60,3 +60,4 @@ obj-$(CONFIG_USB_SERIAL_WISHBONE) += 
wishbone-serial.o
 obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o
 obj-$(CONFIG_USB_SERIAL_XIRCOM)+= keyspan_pda.o
 obj-$(CONFIG_USB_SERIAL_XSENS_MT)  += xsens_mt.o
+obj-$(CONFIG_USB_SERIAL_UPD78F0730)+= upd78f0730.o
diff --git a/drivers/usb/serial/upd78f0730.c b/drivers/usb/serial/upd78f0730.c
new file mode 100644
index 000..e2bed13
--- /dev/null
+++ b/drivers/usb/serial/upd78f0730.c
@@ -0,0 +1,445 @@
+/*
+ * Renesas Electronics uPD78F0730 USB to serial converter driver
+ *
+ * Copyright (C) 2014,2016 Maksim Salau 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * Protocol of the adaptor is described in the application note U19660EJ1V0AN00
+ * μPD78F0730 8-bit Single-Chip Microcontroller
+ * USB-to-Serial Conversion Software
+ * 
+ *
+ * The adaptor functionality is limited to the following:
+ * - data bits: 7 or 8
+ * - stop bits: 1 or 2
+ * - parity: even, odd or none
+ * - flow control: hardware or none
+ * - baud rates: 2400, 4800, 9600, 19200, 38400, 57600, 115200
+ * - signals: DTS, RTS and BREAK
+ * - there is an option to enable parity error character substitution,
+ *   but is not supported by the driver
+ * - XON/XOFF flow control is described in the document,
+ *   but is not supported by the driver
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRIVER_DESC "Renesas uPD78F0730 USB to serial converter driver"
+
+#define DRIVER_AUTHOR "Maksim Salau "
+
+static const struct usb_device_id id_table[] = {
+   { USB_DEVICE(0x045B, 0x0212) }, /* YRPBRL78G13, YRPBRL78G14 */
+   { USB_DEVICE(0x0409, 0x0063) }, /* V850ESJX3-STICK */
+   {}
+};
+
+MODULE_DEVICE_TABLE(usb, id_table);
+
+/*
+ * Private data structure type declaration.
+ * Each adaptor is associated with a private structure, that holds the current
+ * state of control signals (DTR, RTS and BREAK).
+ */
+struct upd78f0730_serial_private {
+   struct mutexlock;   /* mutex to protect line_signals */
+   u8  line_signals;
+};
+
+/* Op-codes of control commands */
+#define UPD78F0730_CMD_LINE_CONTROL0x00
+#define UPD78F0730_CMD_SET_DTR_RTS 0x01
+#define UPD78F0730_CMD_SET_XON_XOFF_CHR0x02
+#define UPD78F0730_CMD_OPEN_CLOSE  0x03
+#define UPD78F0730_CMD_SET_ERR_CHR 0x04
+
+/* Data sizes in UPD78F0730_CMD_LINE_CONTROL command */
+#define