100-fix-plat-marvell-a3720-uart-fix-UART-clock-rate-valu.patch 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. From 66a7752834382595d26214783ae4698fd1f00bd6 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <[email protected]>
  3. Date: Thu, 13 May 2021 14:53:44 +0200
  4. Subject: [PATCH] fix(plat/marvell/a3720/uart): fix UART clock rate value and
  5. divisor calculation
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. UART parent clock is by default the platform's xtal clock, which is
  10. 25 MHz.
  11. The value defined in the driver, though, is 25.8048 MHz. This is a hack
  12. for the suboptimal divisor calculation
  13. Divisor = UART clock / (16 * baudrate)
  14. which does not use rounding division, resulting in a suboptimal value
  15. for divisor if the correct parent clock rate was used.
  16. Change the code for divisor calculation to
  17. Divisor = Round(UART clock / (16 * baudrate))
  18. and change the parent clock rate value to 25 MHz.
  19. The final UART divisor for default baudrate 115200 is not affected by
  20. this change.
  21. (Note that the parent clock rate should not be defined via a macro,
  22. since the xtal clock can also be 40 MHz. This is outside of the scope of
  23. this fix, though.)
  24. Signed-off-by: Pali Rohár <[email protected]>
  25. Change-Id: Iaa401173df87aec94f2dd1b38a90fb6ed0bf0ec6
  26. ---
  27. drivers/marvell/uart/a3700_console.S | 3 ++-
  28. plat/marvell/armada/a3k/common/include/platform_def.h | 2 +-
  29. 2 files changed, 3 insertions(+), 2 deletions(-)
  30. --- a/drivers/marvell/uart/a3700_console.S
  31. +++ b/drivers/marvell/uart/a3700_console.S
  32. @@ -45,8 +45,9 @@ func console_a3700_core_init
  33. cbz w2, init_fail
  34. /* Program the baudrate */
  35. - /* Divisor = Uart clock / (16 * baudrate) */
  36. + /* Divisor = Round(Uartclock / (16 * baudrate)) */
  37. lsl w2, w2, #4
  38. + add w1, w1, w2, lsr #1
  39. udiv w2, w1, w2
  40. and w2, w2, #0x3ff
  41. --- a/plat/marvell/armada/a3k/common/include/platform_def.h
  42. +++ b/plat/marvell/armada/a3k/common/include/platform_def.h
  43. @@ -164,7 +164,7 @@
  44. * PL011 related constants
  45. */
  46. #define PLAT_MARVELL_BOOT_UART_BASE (MVEBU_REGS_BASE + 0x12000)
  47. -#define PLAT_MARVELL_BOOT_UART_CLK_IN_HZ 25804800
  48. +#define PLAT_MARVELL_BOOT_UART_CLK_IN_HZ 25000000
  49. #define PLAT_MARVELL_CRASH_UART_BASE PLAT_MARVELL_BOOT_UART_BASE
  50. #define PLAT_MARVELL_CRASH_UART_CLK_IN_HZ PLAT_MARVELL_BOOT_UART_CLK_IN_HZ