summaryrefslogtreecommitdiff
path: root/drivers/usb/serial/xr_serial.c
AgeCommit message (Collapse)AuthorFilesLines
2024-08-26USB: serial: drop driver owner initializationKrzysztof Kozlowski1-1/+0
Core in usb_serial_register_drivers() already sets the .owner, so driver does not need to. Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Signed-off-by: Johan Hovold <johan@kernel.org>
2023-07-20USB: serial: xr: add TIOCGRS485 and TIOCSRS485 ioctlsJarkko Sonninen1-1/+88
Exar devices like XR21B1411 can control an RS485 transceiver by automatically asserting the RTS#/RS485 pin before sending data and deasserting it when the last stop bit has been transmitted. The polarity of the RST#/RS485 signal is configurable and the hardware also supports half-duplex turn-around delay and address matching mode. Add support for enabling and disabling RS-485 mode and configuring the RST#/RS485 signal polarity using the TIOCGRS485 and TIOCSRS485 ioctls. Support for half-duplex turn-around delay and address matching mode are left unimplemented for now. User enables RS-485 mode by setting SER_RS485_ENABLED flag in struct serial_rs485 flags. User should also set either SER_RS485_RTS_ON_SEND or SER_RS485_RTS_AFTER_SEND to select the behaviour of the RTS#/RS485 pin. Setting SER_RS485_RTS_ON_SEND will drive RTS#/RS485 low during transmission. Signed-off-by: Jarkko Sonninen <kasper@iki.fi> [ johan: let SER_RS485_RTS_ON_SEND determine SER_RS485_RTS_AFTER_SEND ] Signed-off-by: Johan Hovold <johan@kernel.org>
2023-06-07USB: serial: return errors from break handlingJohan Hovold1-2/+2
Start propagating errors to user space when setting the break state fails. This will be used by follow-on changes to also report when a driver or device does not support break control. Tested-by: Corey Minyard <cminyard@mvista.com> Signed-off-by: Johan Hovold <johan@kernel.org>
2022-11-30USB: serial: xr: avoid requesting zero DTE rateJohan Hovold1-2/+0
When the requested line speed is B0 (hangup) there is no need to use the current speed in the line-coding request. This specifically avoids requesting a zero DTE rate when the current speed is B0, which could potentially confuse buggy firmware. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org>
2022-08-30usb: serial: Make ->set_termios() old ktermios constIlpo Järvinen1-8/+12
There should be no reason to adjust old ktermios which is going to get discarded anyway. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Link: https://lore.kernel.org/r/20220816115739.10928-8-ilpo.jarvinen@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-04-13USB: serial: xr: add copyright noticeJohan Hovold1-0/+1
Add another copyright notice for the work done in 2021. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-04-13USB: serial: xr: reset FIFOs on openJohan Hovold1-0/+51
Reset the transmit and receive FIFOs before enabling the UARTs as part of open() in order to flush any stale data. Note that the XR21V141X needs a type-specific implementation due to its UART Manager registers. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-04-13USB: serial: xr: add support for XR22801, XR22802, XR22804Johan Hovold1-0/+23
The XR22801, XR22802 and XR22804 are compound devices with an embedded hub and up to seven downstream USB devices including one, two or four UARTs respectively. The UART function is similar to XR21B142X but most registers are offset by 0x40, the register requests are different and are directed at the device rather than interface, and 5 and 6-bit words are not supported. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-04-13USB: serial: xr: add support for XR21B1411Johan Hovold1-16/+48
The single-port XR21B1411 is similar to the XR21B142X type but uses 12-bit registers and 16-bit register addresses, the register requests are different and are directed at the device rather than interface, and 5 and 6-bit words are not supported. The register layout is very similar to XR21B142X except that most registers are offset by 0xc00 (corresponding to a channel index of 12 in the MSB of wIndex). As the device is single-port so that the derived channel index is 0, the current register accessors can be reused after simply changing the address width. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-04-13USB: serial: xr: add support for XR21B1421, XR21B1422 and XR21B1424Johan Hovold1-76/+262
The XR21B1421, XR21B1422 and XR21B1424 are the one-, two- and four-port models of a second XR21B142X type of the Maxlinear/Exar USB UARTs. The XR21B142X type differs from XR21V141X in several ways, including: - register layout - register width (16-bit instead of 8-bit) - vendor register requests - UART enable/disable sequence - custom-driver mode flag - three additional GPIOs (9 instead of 6) As for XR21V141X, the XR21B142X vendor requests encode the channel index in the MSB of wIndex, but it lacks the UART Manager registers which have been replaced by regular UART registers. The new type also uses the interface number of the control interface (0, 2, 4, 6) as channel index instead of the channel number (0, 1, 2, 3). The XR21B142X lacks the divisor and format registers used by XR21V141X and instead uses the CDC SET_LINE_CONTROL request to configure the line settings. Note that the currently supported XR21V141X type lacks the custom-driver mode flag that prevents the device from entering CDC-ACM mode when a CDC requests is received. This specifically means that the SET_LINE_CONTROL request cannot be used with XR21V141X even though it is otherwise supported. The UART enable sequence for XR21B142X does not involve explicitly enabling the FIFOs, but according to datasheet the UART must be disabled when writing any register but GPIO_SET, GPIO_CLEAR, TX_BREAK and ERROR_STATUS. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-04-13USB: serial: xr: add type abstractionJohan Hovold1-43/+85
There are at least four types of Maxlinear/Exar USB UARTs which differ in various ways such as in their register layouts: XR21V141X XR21B142X XR21B1411 XR22804 It is not clear whether the device type can be inferred from the descriptors so encode it in the device-id table for now. Add a type structure that can be used to abstract the register layout and other features, and use it when accessing the XR21V141X UART registers that are shared by all types. Note that the currently supported XR21V141X type is the only type that has a set of UART Manager registers and that these will need to be handled specifically. Similarly, XR21V141X is the only type which has the divisor registers and that needs to use the format register when configuring the line settings. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-04-13USB: serial: xr: drop type prefix from shared definesJohan Hovold1-61/+61
In preparation for adding support for further types, drop the type prefix from defines that are not specific to XR21V141X. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-04-13USB: serial: xr: move pin configuration to probeJohan Hovold1-8/+37
There's no need to configure the pins on every open and judging from the vendor driver and datasheet it can be done before enabling the UART. Move pin configuration from open() to port probe and make sure to deassert DTR and RTS after configuring all pins as GPIO. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-04-13USB: serial: xr: rename GPIO-pin definesJohan Hovold1-17/+17
Rename the GPIO-pin defines so that they reflect how they are used. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-04-13USB: serial: xr: rename GPIO-mode definesJohan Hovold1-7/+7
Rename the GPIO mode defines so that they reflect the datasheet and how they are used. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-04-13USB: serial: xr: add support for XR21V1412 and XR21V1414Johan Hovold1-4/+51
Add support for the two- and four-port variants of XR21V1410. Use the interface number of each control interface (e.g. 0, 2, 4, 6) to derive the zero-based channel index: XR21V1410 0 XR21V1412 0, 1 XR21V1414 0, 1, 2, 3 Note that the UART registers reside in separate blocks per channel, while the UART Manager functionality is implemented using per-channel registers. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-04-01USB: serial: xr: claim both interfacesJohan Hovold1-3/+23
Use the new multi-interface support in USB serial core to properly claim also the control interface during probe. This prevents having another driver claim the control interface and makes core allocate resources also for the interrupt endpoint (currently unused). Switch to probing only Communication Class interfaces and use the Union functional descriptor to determine the corresponding data interface. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org>
2021-04-01USB: serial: xr: fix CSIZE handlingJohan Hovold1-0/+5
The XR21V141X does not have a 5- or 6-bit mode, but the current implementation failed to properly restore the old setting when CS5 or CS6 was requested. Instead an invalid request would be sent to the device. Fixes: c2d405aa86b4 ("USB: serial: add MaxLinear/Exar USB to Serial driver") Reviewed-by: Manivannan Sadhasivam <mani@kernel.org> Cc: stable@vger.kernel.org # 5.12 Signed-off-by: Johan Hovold <johan@kernel.org>
2021-03-09USB: serial: xr: fix NULL-deref on disconnectJohan Hovold1-25/+0
Claiming the sibling control interface is a bit more involved and specifically requires adding support to USB-serial core for managing either interface being unbound first, something which could otherwise lead to a NULL-pointer dereference. Similarly, additional infrastructure is also needed to handle suspend properly. Since the driver currently isn't actually using the control interface, we can defer this for now by simply not claiming the control interface. Fixes: c2d405aa86b4 ("USB: serial: add MaxLinear/Exar USB to Serial driver") Reported-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Tested-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Manivannan Sadhasivam <mani@kernel.org> Signed-off-by: Johan Hovold <johan@kernel.org>
2021-01-26USB: serial: xr: fix B0 handlingJohan Hovold1-9/+14
Fix up B0 handling which should leave the baud rate unchanged and specifically not report back a non-B0 rate when B0 is requested; must temporarily disable hardware flow control so that RTS can be deasserted; and should reassert DTR/RTS when moving from B0. Fixes: c2d405aa86b4 ("USB: serial: add MaxLinear/Exar USB to Serial driver") Signed-off-by: Johan Hovold <johan@kernel.org>
2021-01-26USB: serial: xr: fix pin configurationJohan Hovold1-0/+8
Make sure that the modem pins are set up correctly when opening the port to avoid leaving, for example, DTR and RTS configured as inputs, which is the device default. This is specifically needed to be able to control DTR and RTS when hardware flow control is disabled. Fixes: c2d405aa86b4 ("USB: serial: add MaxLinear/Exar USB to Serial driver") Signed-off-by: Johan Hovold <johan@kernel.org>
2021-01-26USB: serial: xr: fix gpio-mode handlingJohan Hovold1-6/+3
Fix the gpio-mode handling so that all the pins are under driver control (i.e. in gpio mode) when hardware flow control is disabled. This is specifically needed to be able to control RTS. Fixes: c2d405aa86b4 ("USB: serial: add MaxLinear/Exar USB to Serial driver") Signed-off-by: Johan Hovold <johan@kernel.org>
2021-01-26USB: serial: xr: simplify line-speed logicJohan Hovold1-2/+1
Simplify the changed-line-speed conditional expression. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-01-26USB: serial: xr: clean up line-settings handlingJohan Hovold1-19/+15
Shift the line-setting values when defining them rather than in set_termios() for consistency and improved readability. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-01-26USB: serial: xr: document vendor-request recipientJohan Hovold1-4/+4
Add the missing device-recipient define to the vendor control requests for completeness. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-01-26USB: serial: xr: use termios flag helpersJohan Hovold1-2/+1
Use the termios flag helpers consistently, including for CRTSCTS. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-01-26USB: serial: xr: use subsystem usb_device at probeJohan Hovold1-2/+1
Use the subsystem struct usb_device pointer at probe instead of deriving it from the interface pointer. Signed-off-by: Johan Hovold <johan@kernel.org>
2021-01-26USB: serial: xr: fix interface leak at disconnectJohan Hovold1-0/+10
Make sure to release the control interface at disconnect so that the driver can be unbound without leaking resources (and later rebound). Fixes: c2d405aa86b4 ("USB: serial: add MaxLinear/Exar USB to Serial driver") Signed-off-by: Johan Hovold <johan@kernel.org>
2021-01-26USB: serial: xr: fix NULL-deref at probeJohan Hovold1-0/+3
Make sure that the probed device has an interface 0 to avoid dereferencing a NULL pointer in case of a malicious device or during USB-descriptor fuzzing. Fixes: c2d405aa86b4 ("USB: serial: add MaxLinear/Exar USB to Serial driver") Signed-off-by: Johan Hovold <johan@kernel.org>
2021-01-21USB: serial: add MaxLinear/Exar USB to Serial driverManivannan Sadhasivam1-0/+595
Add support for MaxLinear/Exar USB to Serial converters. This driver only supports XR21V141X series but it can be extended to other series from Exar as well in future. This driver is inspired from the initial one submitted by Patong Yang: https://lore.kernel.org/r/20180404070634.nhspvmxcjwfgjkcv@advantechmxl-desktop While the initial driver was a custom tty USB driver exposing whole new serial interface ttyXRUSBn, this version is completely based on USB serial core thus exposing the interfaces as ttyUSBn. This will avoid the overhead of exposing a new USB serial interface which the userspace tools are unaware of. The Exar XR21V141X can be used in either ACM mode using the cdc-acm driver or in "custom driver" mode in which further features such as hardware and software flow control, GPIO control and in-band line-status reporting are available. In ACM mode the device always enables RTS/CTS flow control, something which could prevent transmission in case the CTS input isn't wired up corrently. A follow-on patch will prevent cdc_acm from binding whenever this driver is enabled. Signed-off-by: Manivannan Sadhasivam <mani@kernel.org> Link: https://lore.kernel.org/r/20201122170822.21715-2-mani@kernel.org [ johan: fix some style nits, group related functions, drop unused callbacks, and amend commit message; a few remaining non-trivial issues will be fixed separately ] Signed-off-by: Johan Hovold <johan@kernel.org>