0015-MIPS-ralink-cleanup-early_printk.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. From e410b0069ee7c318a5b556f39b8b16814330a208 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Fri, 24 Jan 2014 17:01:17 +0100
  4. Subject: [PATCH 15/57] MIPS: ralink: cleanup early_printk
  5. Add support for the new MT7621/8 SoC and kill ifdefs.
  6. Cleanup some whitespace error while we are at it.
  7. Signed-off-by: John Crispin <blogic@openwrt.org>
  8. ---
  9. arch/mips/ralink/early_printk.c | 45 ++++++++++++++++++++++++++-------------
  10. 1 file changed, 30 insertions(+), 15 deletions(-)
  11. --- a/arch/mips/ralink/early_printk.c
  12. +++ b/arch/mips/ralink/early_printk.c
  13. @@ -12,21 +12,26 @@
  14. #include <asm/addrspace.h>
  15. #ifdef CONFIG_SOC_RT288X
  16. -#define EARLY_UART_BASE 0x300c00
  17. +#define EARLY_UART_BASE 0x300c00
  18. +#define CHIPID_BASE 0x300004
  19. +#elif defined(CONFIG_SOC_MT7621)
  20. +#define EARLY_UART_BASE 0x1E000c00
  21. +#define CHIPID_BASE 0x1E000004
  22. #else
  23. -#define EARLY_UART_BASE 0x10000c00
  24. +#define EARLY_UART_BASE 0x10000c00
  25. +#define CHIPID_BASE 0x10000004
  26. #endif
  27. -#define UART_REG_RX 0x00
  28. -#define UART_REG_TX 0x04
  29. -#define UART_REG_IER 0x08
  30. -#define UART_REG_IIR 0x0c
  31. -#define UART_REG_FCR 0x10
  32. -#define UART_REG_LCR 0x14
  33. -#define UART_REG_MCR 0x18
  34. -#define UART_REG_LSR 0x1c
  35. +#define MT7628_CHIP_NAME1 0x20203832
  36. +
  37. +#define UART_REG_TX 0x04
  38. +#define UART_REG_LCR 0x0c
  39. +#define UART_REG_LSR 0x14
  40. +#define UART_REG_LSR_RT2880 0x1c
  41. static __iomem void *uart_membase = (__iomem void *) KSEG1ADDR(EARLY_UART_BASE);
  42. +static __iomem void *chipid_membase = (__iomem void *) KSEG1ADDR(CHIPID_BASE);
  43. +static int init_complete;
  44. static inline void uart_w32(u32 val, unsigned reg)
  45. {
  46. @@ -38,11 +43,46 @@ static inline u32 uart_r32(unsigned reg)
  47. return __raw_readl(uart_membase + reg);
  48. }
  49. +static inline int soc_is_mt7628(void)
  50. +{
  51. + return IS_ENABLED(CONFIG_SOC_MT7620) &&
  52. + (__raw_readl(chipid_membase) == MT7628_CHIP_NAME1);
  53. +}
  54. +
  55. +static inline void find_uart_base(void)
  56. +{
  57. + int i;
  58. +
  59. + if (!soc_is_mt7628())
  60. + return;
  61. +
  62. + for (i = 0; i < 3; i++) {
  63. + u32 reg = uart_r32(UART_REG_LCR + (0x100 * i));
  64. +
  65. + if (!reg)
  66. + continue;
  67. +
  68. + uart_membase = (__iomem void *) KSEG1ADDR(EARLY_UART_BASE + (0x100 * i));
  69. + break;
  70. + }
  71. +}
  72. +
  73. void prom_putchar(unsigned char ch)
  74. {
  75. - while ((uart_r32(UART_REG_LSR) & UART_LSR_THRE) == 0)
  76. - ;
  77. - uart_w32(ch, UART_REG_TX);
  78. - while ((uart_r32(UART_REG_LSR) & UART_LSR_THRE) == 0)
  79. - ;
  80. + if (!init_complete) {
  81. + find_uart_base();
  82. + init_complete = 1;
  83. + }
  84. +
  85. + if (IS_ENABLED(CONFIG_SOC_MT7621) || soc_is_mt7628()) {
  86. + uart_w32(ch, UART_TX);
  87. + while ((uart_r32(UART_REG_LSR) & UART_LSR_THRE) == 0)
  88. + ;
  89. + } else {
  90. + while ((uart_r32(UART_REG_LSR_RT2880) & UART_LSR_THRE) == 0)
  91. + ;
  92. + uart_w32(ch, UART_REG_TX);
  93. + while ((uart_r32(UART_REG_LSR_RT2880) & UART_LSR_THRE) == 0)
  94. + ;
  95. + }
  96. }