On 23/11/2023 11.38, Lukas Wunner wrote: > On Thu, Nov 23, 2023 at 11:07:16AM +0100, Rasmus Villemoes wrote: >> On 22/11/2023 15.53, Lukas Wunner wrote: >>> But if that patch gets accepted, we'd have *three* different modes: >>> RS-232, RS-485, RS-422. A single GPIO seems insufficient to handle that. >>> You'd need at least two GPIOs. >> >> I don't see Crescent introducing any new gpio that needs to be handled. >> In fact, I can't even see why from the perspective of the software that >> rs422 isn't just rs232; there's no transmit enable pin that needs to be >> handled. But maybe the uart driver does something different in rs422 >> mode; I assume he must have some update of some driver, since otherwise >> the new rs422 bit should be rejected by the core. So I can't really see >> the whole picture of that rs422 story. > > The question is, could we conceivably have the need to support > switching between the three modes RS-232, RS-485, RS-422. > If yes, then the GPIO mux interface should probably allow for that. > > As a case in point, the Siemens IOT 2040 has two serial ports > which can be set to either of those three modes. The signals > are routed to the same D-sub socket, but the pins used are > different. See page 46 and 47 of this document: > > https://cache.industry.siemens.com/dl/files/658/109741658/att_899623/v1/iot2000_operating_instructions_enUS_en-US.pdf > > The driver for this product is 8250_exar.c. It's an Intel-based > product, so no devicetree, but it shows that such use cases exist. OK. I did look at the mux-controller/mux-consumer bindings, but couldn't really make heads or tails of it, and there aren't a whole lot of examples in-tree. Also, the C API seems ... not quite what is needed here. I realize that's not really anything to do with the best way to describe the hardware, but that, plus the fact that the serial core already handles a number of gpios controlling circuitry related to rs485, was what made me go for one extra gpio. How would a mux-consumer description look? mux-states = <&mux 0>, <&mux 1>; mux-state-names = "rs485", "rs232"; or should that be mux-controls? Would that be enough so that we're sure that if and when a rs422 state is needed that could easily be represented here? Now implementation-wise, there's the complication that switching the mux to/from rs485 mode must be done after/before the driver's ->rs485_config is called, to avoid the transceiver temporarily being activated (thus blocking/disturbing other traffic). That plus the need to mux_*_deselect the old mode means the consumer (serial core in this case) ends up with quite a lot of bookkeeping, and even more so taking error path into consideration. Rasmus