early_printk.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Atheros AR7XXX/AR9XXX SoC early printk support
  3. *
  4. * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  5. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published
  9. * by the Free Software Foundation.
  10. */
  11. #include <linux/io.h>
  12. #include <linux/errno.h>
  13. #include <linux/serial_reg.h>
  14. #include <asm/addrspace.h>
  15. #include <asm/mach-ath79/ath79.h>
  16. #include <asm/mach-ath79/ar71xx_regs.h>
  17. #include <asm/mach-ath79/ar933x_uart.h>
  18. static void (*_prom_putchar) (unsigned char);
  19. static inline void prom_putchar_wait(void __iomem *reg, u32 mask, u32 val)
  20. {
  21. u32 t;
  22. do {
  23. t = __raw_readl(reg);
  24. if ((t & mask) == val)
  25. break;
  26. } while (1);
  27. }
  28. #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
  29. static void prom_putchar_ar71xx(unsigned char ch)
  30. {
  31. void __iomem *base = (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE));
  32. prom_putchar_wait(base + UART_LSR * 4, BOTH_EMPTY, BOTH_EMPTY);
  33. __raw_writel(ch, base + UART_TX * 4);
  34. prom_putchar_wait(base + UART_LSR * 4, BOTH_EMPTY, BOTH_EMPTY);
  35. }
  36. static void prom_putchar_ar933x(unsigned char ch)
  37. {
  38. void __iomem *base = (void __iomem *)(KSEG1ADDR(AR933X_UART_BASE));
  39. prom_putchar_wait(base + AR933X_UART_DATA_REG, AR933X_UART_DATA_TX_CSR,
  40. AR933X_UART_DATA_TX_CSR);
  41. __raw_writel(AR933X_UART_DATA_TX_CSR | ch, base + AR933X_UART_DATA_REG);
  42. prom_putchar_wait(base + AR933X_UART_DATA_REG, AR933X_UART_DATA_TX_CSR,
  43. AR933X_UART_DATA_TX_CSR);
  44. }
  45. static void prom_putchar_dummy(unsigned char ch)
  46. {
  47. /* nothing to do */
  48. }
  49. static void prom_putchar_init(void)
  50. {
  51. void __iomem *base;
  52. u32 id;
  53. base = (void __iomem *)(KSEG1ADDR(AR71XX_RESET_BASE));
  54. id = __raw_readl(base + AR71XX_RESET_REG_REV_ID);
  55. id &= REV_ID_MAJOR_MASK;
  56. switch (id) {
  57. case REV_ID_MAJOR_AR71XX:
  58. case REV_ID_MAJOR_AR7240:
  59. case REV_ID_MAJOR_AR7241:
  60. case REV_ID_MAJOR_AR7242:
  61. case REV_ID_MAJOR_AR913X:
  62. case REV_ID_MAJOR_AR9341:
  63. case REV_ID_MAJOR_AR9342:
  64. case REV_ID_MAJOR_AR9344:
  65. case REV_ID_MAJOR_QCA9556:
  66. case REV_ID_MAJOR_QCA9558:
  67. _prom_putchar = prom_putchar_ar71xx;
  68. break;
  69. case REV_ID_MAJOR_AR9330:
  70. case REV_ID_MAJOR_AR9331:
  71. _prom_putchar = prom_putchar_ar933x;
  72. break;
  73. default:
  74. _prom_putchar = prom_putchar_dummy;
  75. break;
  76. }
  77. }
  78. void prom_putchar(unsigned char ch)
  79. {
  80. if (!_prom_putchar)
  81. prom_putchar_init();
  82. _prom_putchar(ch);
  83. }