Re: [PATCH] usb: serial: mos7840.c Support RS485 mode in B&B Electronics USOPTL4-4P and USOPTL4-2P

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03/01/2016 08:54 PM, amarburg@xxxxxxxxxxxxxxxxxx wrote:

From: Aaron Marburg <amarburg@xxxxxxxxxxxxxxxxxx>

The USOPTL4-4P and USOPTL4-2P USB-to-quad/dual RS-485/422 hubs use the
Moschip 7840/7820.   For correct operation in RS-485, the chip must be
configured in “RS-485 mode” through the scratchpad register as per the
datasheet. This strobes the DTR line on transmission, enabling the driver
on the RS485 transceiver chip.

Patch enables RS485 mode automatically for the USOPTL4-4P and USOPTL4-2P
based on USB product ID.   It also includes a module command line option
"force_rs485={0|1}" to manually force-enable (for all devices regardless
of USB ID) and force-disable (for no devices, not even USOPTL*) the
functionality.

Signed-off-by: Aaron Marburg <amarburg@xxxxxxxxxxxxxxxxxx>

---
  drivers/usb/serial/mos7840.c | 25 +++++++++++++++++++++++++
  1 file changed, 25 insertions(+)

diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 2c69bfc..2356828 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
[...]

@@ -991,6 +997,22 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
  	status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data);
  	mos7840_port->shadowLCR = Data;

+	if (!(force_rs485 == 0)) {
+		if ((force_rs485 == 1) ||
+			(product == BANDB_DEVICE_ID_USOPTL4_4P) ||
+			(product == BANDB_DEVICE_ID_USOPTL4_2P)) {

Parens not necessary. And please indent the continuation lines either to start at the next character after the first ( or by 2 extra tabs, so it's easier on the eyes, not blending with the following code.

+			/* Enable RS485 mode by setting bytes in
+			 * scratchpad register:
+			 * 0x00  RS485 mode disabled
+			 * 0x80  = RS485 mode enabled, DTR Low on tx
+			 * 0xC0  = RS485 mode enabled, DTR High on tx
+			 */
+			dev_notice(&port->dev, "Detected B&B Electronics USOPTL4_4P, enabling RS485 mode.\n");
+			Data = 0xC0;
+			status = mos7840_set_uart_reg(port, SCRATCH_PAD_REGISTER, Data);

   Just write 0xC0, no need to set 'Data' beforehand.

[...]

MBR, Sergei

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



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux