860-serial-8250_mtk-track-busclk-state-to-avoid-bus-error.patch 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. From 629c701fc39f1ada9416e0766a86729e83bde86c Mon Sep 17 00:00:00 2001
  2. Message-ID: <629c701fc39f1ada9416e0766a86729e83bde86c.1694465766.git.daniel@makrotopia.org>
  3. From: Daniel Golle <[email protected]>
  4. Date: Mon, 11 Sep 2023 21:27:44 +0100
  5. Subject: [PATCH] serial: 8250_mtk: track busclk state to avoid bus error
  6. To: Greg Kroah-Hartman <[email protected]>,
  7. Jiri Slaby <[email protected]>,
  8. Matthias Brugger <[email protected]>,
  9. AngeloGioacchino Del Regno <[email protected]>,
  10. Daniel Golle <[email protected]>,
  11. John Ogness <[email protected]>,
  12. Chen-Yu Tsai <[email protected]>,
  13. Changqi Hu <[email protected]>,
  14. [email protected],
  15. [email protected],
  16. [email protected],
  17. [email protected]
  18. Commit e32a83c70cf9 ("serial: 8250-mtk: modify mtk uart power and
  19. clock management") introduced polling a debug register to make sure
  20. the UART is idle before disabling the bus clock. However, at least on
  21. some MediaTek SoCs access to that very debug register requires the bus
  22. clock being enabled. Hence calling the suspend function while already
  23. in suspended state results in that register access triggering a bus
  24. error. In order to avoid that, track the state of the bus clock and
  25. only poll the debug register if not already in suspended state.
  26. Fixes: e32a83c70cf9 ("serial: 8250-mtk: modify mtk uart power and clock management")
  27. Signed-off-by: Daniel Golle <[email protected]>
  28. ---
  29. drivers/tty/serial/8250/8250_mtk.c | 11 ++++++++++-
  30. 1 file changed, 10 insertions(+), 1 deletion(-)
  31. --- a/drivers/tty/serial/8250/8250_mtk.c
  32. +++ b/drivers/tty/serial/8250/8250_mtk.c
  33. @@ -32,7 +32,7 @@
  34. #define MTK_UART_RXTRI_AD 0x14 /* RX Trigger address */
  35. #define MTK_UART_FRACDIV_L 0x15 /* Fractional divider LSB address */
  36. #define MTK_UART_FRACDIV_M 0x16 /* Fractional divider MSB address */
  37. -#define MTK_UART_DEBUG0 0x18
  38. +#define MTK_UART_DEBUG0 0x18
  39. #define MTK_UART_IER_XOFFI 0x20 /* Enable XOFF character interrupt */
  40. #define MTK_UART_IER_RTSI 0x40 /* Enable RTS Modem status interrupt */
  41. #define MTK_UART_IER_CTSI 0x80 /* Enable CTS Modem status interrupt */
  42. @@ -418,13 +418,12 @@ static int __maybe_unused mtk8250_runtim
  43. struct mtk8250_data *data = dev_get_drvdata(dev);
  44. struct uart_8250_port *up = serial8250_get_port(data->line);
  45. - /* wait until UART in idle status */
  46. - while
  47. - (serial_in(up, MTK_UART_DEBUG0));
  48. -
  49. if (data->clk_count == 0U) {
  50. dev_dbg(dev, "%s clock count is 0\n", __func__);
  51. } else {
  52. + /* wait until UART in idle status */
  53. + while
  54. + (serial_in(up, MTK_UART_DEBUG0));
  55. clk_disable_unprepare(data->bus_clk);
  56. data->clk_count--;
  57. }