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

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