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]

 



Good question. The cmd line option is a tri-state:

(no command line option) -> force_rs485=-1 -> auto-detect based on product ID
force_rs485 = 0 -> never set RS485 mode (regardless of product ID)
force_rs485 = 1 -> always set RS485 mode (regardless of product ID)


> On Mar 1, 2016, at 11:38 AM, Sergei Shtylyov <sergei.shtylyov@xxxxxxxxxxxxxxxxxx> wrote:
> 
> Hello.
> 
> 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
>> @@ -182,6 +182,9 @@
>> #define LED_ON_MS	500
>> #define LED_OFF_MS	500
>> 
>> +/* Command-line option to force RS485 mode */
>> +static int force_rs485 = -1;
> 
>   Why not just 0 (and no initializer)?
> 
>> +
>> enum mos7840_flag {
>> 	MOS7840_FLAG_CTRL_BUSY,
>> 	MOS7840_FLAG_LED_BUSY,
> [...]
>> @@ -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)) {
> 
>   Use != please. Or better still, just *if* (force).

Yes, of course this would be simpler.


> 
>> +		if ((force_rs485 == 1) ||
>> +			(product == BANDB_DEVICE_ID_USOPTL4_4P) ||
>> +			(product == BANDB_DEVICE_ID_USOPTL4_2P)) {
>> +			/* 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);
>> +		}
>> +	}
>> +
>>  	/* clearing Bulkin and Bulkout Fifo */
>>  	Data = 0x0;
>>  	status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data);
>> @@ -2403,5 +2425,8 @@ static struct usb_serial_driver * const serial_drivers[] = {
>> 
>> module_usb_serial_driver(serial_drivers, id_table);
>> 
>> +module_param(force_rs485, int, S_IRUGO);
>> +MODULE_PARM_DESC(force_rs845, "Force RS-485 mode (1 = force enable, 0 = force enable).
> 
>   Both 0 and 1 enable? :-)

You are correct, should be 0 = force disable.



> 
>> Otherwise automatically enabled for B&B Elec. USOPTL4-4P and USOPTL4-2P.");
>> +
>> MODULE_DESCRIPTION(DRIVER_DESC);
>> MODULE_LICENSE("GPL");
>> -
> 
> [...]
> 
> MBR, Sergei

Attachment: smime.p7s
Description: S/MIME cryptographic signature


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

  Powered by Linux