1
2
3
4
5
6
7
8
9
10
11
12#include <linux/io.h>
13#include <linux/errno.h>
14#include <linux/serial_reg.h>
15#include <asm/addrspace.h>
16#include <asm/setup.h>
17
18#include <asm/mach-ath79/ath79.h>
19#include <asm/mach-ath79/ar71xx_regs.h>
20#include <asm/mach-ath79/ar933x_uart.h>
21
22static void (*_prom_putchar)(char);
23
24static inline void prom_putchar_wait(void __iomem *reg, u32 mask, u32 val)
25{
26 u32 t;
27
28 do {
29 t = __raw_readl(reg);
30 if ((t & mask) == val)
31 break;
32 } while (1);
33}
34
35#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
36
37static void prom_putchar_ar71xx(char ch)
38{
39 void __iomem *base = (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE));
40
41 prom_putchar_wait(base + UART_LSR * 4, BOTH_EMPTY, BOTH_EMPTY);
42 __raw_writel((unsigned char)ch, base + UART_TX * 4);
43 prom_putchar_wait(base + UART_LSR * 4, BOTH_EMPTY, BOTH_EMPTY);
44}
45
46static void prom_putchar_ar933x(char ch)
47{
48 void __iomem *base = (void __iomem *)(KSEG1ADDR(AR933X_UART_BASE));
49
50 prom_putchar_wait(base + AR933X_UART_DATA_REG, AR933X_UART_DATA_TX_CSR,
51 AR933X_UART_DATA_TX_CSR);
52 __raw_writel(AR933X_UART_DATA_TX_CSR | (unsigned char)ch,
53 base + AR933X_UART_DATA_REG);
54 prom_putchar_wait(base + AR933X_UART_DATA_REG, AR933X_UART_DATA_TX_CSR,
55 AR933X_UART_DATA_TX_CSR);
56}
57
58static void prom_putchar_dummy(char ch)
59{
60
61}
62
63static void prom_enable_uart(u32 id)
64{
65 void __iomem *gpio_base;
66 u32 uart_en;
67 u32 t;
68
69 switch (id) {
70 case REV_ID_MAJOR_AR71XX:
71 uart_en = AR71XX_GPIO_FUNC_UART_EN;
72 break;
73
74 case REV_ID_MAJOR_AR7240:
75 case REV_ID_MAJOR_AR7241:
76 case REV_ID_MAJOR_AR7242:
77 uart_en = AR724X_GPIO_FUNC_UART_EN;
78 break;
79
80 case REV_ID_MAJOR_AR913X:
81 uart_en = AR913X_GPIO_FUNC_UART_EN;
82 break;
83
84 case REV_ID_MAJOR_AR9330:
85 case REV_ID_MAJOR_AR9331:
86 uart_en = AR933X_GPIO_FUNC_UART_EN;
87 break;
88
89 case REV_ID_MAJOR_AR9341:
90 case REV_ID_MAJOR_AR9342:
91 case REV_ID_MAJOR_AR9344:
92
93 default:
94 return;
95 }
96
97 gpio_base = (void __iomem *)KSEG1ADDR(AR71XX_GPIO_BASE);
98 t = __raw_readl(gpio_base + AR71XX_GPIO_REG_FUNC);
99 t |= uart_en;
100 __raw_writel(t, gpio_base + AR71XX_GPIO_REG_FUNC);
101}
102
103static void prom_putchar_init(void)
104{
105 void __iomem *base;
106 u32 id;
107
108 base = (void __iomem *)(KSEG1ADDR(AR71XX_RESET_BASE));
109 id = __raw_readl(base + AR71XX_RESET_REG_REV_ID);
110 id &= REV_ID_MAJOR_MASK;
111
112 switch (id) {
113 case REV_ID_MAJOR_AR71XX:
114 case REV_ID_MAJOR_AR7240:
115 case REV_ID_MAJOR_AR7241:
116 case REV_ID_MAJOR_AR7242:
117 case REV_ID_MAJOR_AR913X:
118 case REV_ID_MAJOR_AR9341:
119 case REV_ID_MAJOR_AR9342:
120 case REV_ID_MAJOR_AR9344:
121 case REV_ID_MAJOR_QCA9533:
122 case REV_ID_MAJOR_QCA9533_V2:
123 case REV_ID_MAJOR_QCA9556:
124 case REV_ID_MAJOR_QCA9558:
125 case REV_ID_MAJOR_TP9343:
126 case REV_ID_MAJOR_QCA956X:
127 _prom_putchar = prom_putchar_ar71xx;
128 break;
129
130 case REV_ID_MAJOR_AR9330:
131 case REV_ID_MAJOR_AR9331:
132 _prom_putchar = prom_putchar_ar933x;
133 break;
134
135 default:
136 _prom_putchar = prom_putchar_dummy;
137 return;
138 }
139
140 prom_enable_uart(id);
141}
142
143void prom_putchar(char ch)
144{
145 if (!_prom_putchar)
146 prom_putchar_init();
147
148 _prom_putchar(ch);
149}
150