950-tty-serial-exar-generalize-rs485-setup.patch 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. From 24d5ba8ad40c3ac7903f688580c345aafa764dc7 Mon Sep 17 00:00:00 2001
  2. From: Daniel Golle <daniel@makrotopia.org>
  3. Date: Mon, 4 Jun 2018 14:51:29 +0200
  4. Subject: [PATCH] tty: serial: exar: generalize rs485 setup
  5. To: linux-serial@vger.kernel.org,
  6. Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  7. Cc: Linus Walleij <linus.walleij@linaro.org>,
  8. Jan Kiszka <jan.kiszka@siemens.com>
  9. Move the non-board-specific part of the RS485 initialization
  10. from iot2040_rs485_config function to a new generic function
  11. used also for other boards.
  12. This allows using PCIe boards which are hard-wired to RS485
  13. or have jumpers for their configurations.
  14. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
  15. ---
  16. drivers/tty/serial/8250/8250_exar.c | 38 +++++++++++++++++++----------
  17. 1 file changed, 25 insertions(+), 13 deletions(-)
  18. --- a/drivers/tty/serial/8250/8250_exar.c
  19. +++ b/drivers/tty/serial/8250/8250_exar.c
  20. @@ -275,8 +275,32 @@ static int xr17v35x_register_gpio(struct
  21. return 0;
  22. }
  23. +static int generic_rs485_config(struct uart_port *port,
  24. + struct serial_rs485 *rs485)
  25. +{
  26. + bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED);
  27. + u8 __iomem *p = port->membase;
  28. + u8 value;
  29. +
  30. + value = readb(p + UART_EXAR_FCTR);
  31. + if (is_rs485)
  32. + value |= UART_FCTR_EXAR_485;
  33. + else
  34. + value &= ~UART_FCTR_EXAR_485;
  35. +
  36. + writeb(value, p + UART_EXAR_FCTR);
  37. +
  38. + if (is_rs485)
  39. + writeb(UART_EXAR_RS485_DLY(4), p + UART_MSR);
  40. +
  41. + port->rs485 = *rs485;
  42. +
  43. + return 0;
  44. +}
  45. +
  46. static const struct exar8250_platform exar8250_default_platform = {
  47. .register_gpio = xr17v35x_register_gpio,
  48. + .rs485_config = generic_rs485_config,
  49. };
  50. static int iot2040_rs485_config(struct uart_port *port,
  51. @@ -309,19 +333,7 @@ static int iot2040_rs485_config(struct u
  52. value |= mode;
  53. writeb(value, p + UART_EXAR_MPIOLVL_7_0);
  54. - value = readb(p + UART_EXAR_FCTR);
  55. - if (is_rs485)
  56. - value |= UART_FCTR_EXAR_485;
  57. - else
  58. - value &= ~UART_FCTR_EXAR_485;
  59. - writeb(value, p + UART_EXAR_FCTR);
  60. -
  61. - if (is_rs485)
  62. - writeb(UART_EXAR_RS485_DLY(4), p + UART_MSR);
  63. -
  64. - port->rs485 = *rs485;
  65. -
  66. - return 0;
  67. + return generic_rs485_config(port, rs485);
  68. }
  69. static const struct property_entry iot2040_gpio_properties[] = {