/arch/mips/ath79/early_printk.c

http://github.com/mirrors/linux · C · 146 lines · 111 code · 26 blank · 9 comment · 6 complexity · f0c3f43bc7a10c8b663c93decd377a37 MD5 · raw file

  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Atheros AR7XXX/AR9XXX SoC early printk support
  4. *
  5. * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  6. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7. */
  8. #include <linux/io.h>
  9. #include <linux/errno.h>
  10. #include <linux/serial_reg.h>
  11. #include <asm/addrspace.h>
  12. #include <asm/setup.h>
  13. #include <asm/mach-ath79/ath79.h>
  14. #include <asm/mach-ath79/ar71xx_regs.h>
  15. #include <asm/mach-ath79/ar933x_uart.h>
  16. static void (*_prom_putchar)(char);
  17. static inline void prom_putchar_wait(void __iomem *reg, u32 mask, u32 val)
  18. {
  19. u32 t;
  20. do {
  21. t = __raw_readl(reg);
  22. if ((t & mask) == val)
  23. break;
  24. } while (1);
  25. }
  26. #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
  27. static void prom_putchar_ar71xx(char ch)
  28. {
  29. void __iomem *base = (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE));
  30. prom_putchar_wait(base + UART_LSR * 4, BOTH_EMPTY, BOTH_EMPTY);
  31. __raw_writel((unsigned char)ch, base + UART_TX * 4);
  32. prom_putchar_wait(base + UART_LSR * 4, BOTH_EMPTY, BOTH_EMPTY);
  33. }
  34. static void prom_putchar_ar933x(char ch)
  35. {
  36. void __iomem *base = (void __iomem *)(KSEG1ADDR(AR933X_UART_BASE));
  37. prom_putchar_wait(base + AR933X_UART_DATA_REG, AR933X_UART_DATA_TX_CSR,
  38. AR933X_UART_DATA_TX_CSR);
  39. __raw_writel(AR933X_UART_DATA_TX_CSR | (unsigned char)ch,
  40. base + AR933X_UART_DATA_REG);
  41. prom_putchar_wait(base + AR933X_UART_DATA_REG, AR933X_UART_DATA_TX_CSR,
  42. AR933X_UART_DATA_TX_CSR);
  43. }
  44. static void prom_putchar_dummy(char ch)
  45. {
  46. /* nothing to do */
  47. }
  48. static void prom_enable_uart(u32 id)
  49. {
  50. void __iomem *gpio_base;
  51. u32 uart_en;
  52. u32 t;
  53. switch (id) {
  54. case REV_ID_MAJOR_AR71XX:
  55. uart_en = AR71XX_GPIO_FUNC_UART_EN;
  56. break;
  57. case REV_ID_MAJOR_AR7240:
  58. case REV_ID_MAJOR_AR7241:
  59. case REV_ID_MAJOR_AR7242:
  60. uart_en = AR724X_GPIO_FUNC_UART_EN;
  61. break;
  62. case REV_ID_MAJOR_AR913X:
  63. uart_en = AR913X_GPIO_FUNC_UART_EN;
  64. break;
  65. case REV_ID_MAJOR_AR9330:
  66. case REV_ID_MAJOR_AR9331:
  67. uart_en = AR933X_GPIO_FUNC_UART_EN;
  68. break;
  69. case REV_ID_MAJOR_AR9341:
  70. case REV_ID_MAJOR_AR9342:
  71. case REV_ID_MAJOR_AR9344:
  72. /* TODO */
  73. default:
  74. return;
  75. }
  76. gpio_base = (void __iomem *)KSEG1ADDR(AR71XX_GPIO_BASE);
  77. t = __raw_readl(gpio_base + AR71XX_GPIO_REG_FUNC);
  78. t |= uart_en;
  79. __raw_writel(t, gpio_base + AR71XX_GPIO_REG_FUNC);
  80. }
  81. static void prom_putchar_init(void)
  82. {
  83. void __iomem *base;
  84. u32 id;
  85. base = (void __iomem *)(KSEG1ADDR(AR71XX_RESET_BASE));
  86. id = __raw_readl(base + AR71XX_RESET_REG_REV_ID);
  87. id &= REV_ID_MAJOR_MASK;
  88. switch (id) {
  89. case REV_ID_MAJOR_AR71XX:
  90. case REV_ID_MAJOR_AR7240:
  91. case REV_ID_MAJOR_AR7241:
  92. case REV_ID_MAJOR_AR7242:
  93. case REV_ID_MAJOR_AR913X:
  94. case REV_ID_MAJOR_AR9341:
  95. case REV_ID_MAJOR_AR9342:
  96. case REV_ID_MAJOR_AR9344:
  97. case REV_ID_MAJOR_QCA9533:
  98. case REV_ID_MAJOR_QCA9533_V2:
  99. case REV_ID_MAJOR_QCA9556:
  100. case REV_ID_MAJOR_QCA9558:
  101. case REV_ID_MAJOR_TP9343:
  102. case REV_ID_MAJOR_QCA956X:
  103. _prom_putchar = prom_putchar_ar71xx;
  104. break;
  105. case REV_ID_MAJOR_AR9330:
  106. case REV_ID_MAJOR_AR9331:
  107. _prom_putchar = prom_putchar_ar933x;
  108. break;
  109. default:
  110. _prom_putchar = prom_putchar_dummy;
  111. return;
  112. }
  113. prom_enable_uart(id);
  114. }
  115. void prom_putchar(char ch)
  116. {
  117. if (!_prom_putchar)
  118. prom_putchar_init();
  119. _prom_putchar(ch);
  120. }