ar71xx: flush DDR writeback buffers for WMAC and PCIe on AR934X
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / early_printk.c
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
12 #include <linux/errno.h>
13 #include <linux/io.h>
14 #include <linux/serial_reg.h>
15 #include <asm/addrspace.h>
16
17 #include <asm/mach-ar71xx/ar71xx.h>
18 #include <asm/mach-ar71xx/ar933x_uart.h>
19
20 static void (*_prom_putchar) (unsigned char);
21
22 static inline void prom_putchar_wait(void __iomem *reg, u32 mask, u32 val)
23 {
24         u32 t;
25
26         do {
27                 t = __raw_readl(reg);
28                 if ((t & mask) == val)
29                         break;
30         } while (1);
31 }
32
33 static void prom_putchar_ar71xx(unsigned char ch)
34 {
35         void __iomem *base = (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE));
36
37         prom_putchar_wait(base + UART_LSR * 4, UART_LSR_THRE, UART_LSR_THRE);
38         __raw_writel(ch, base + UART_TX * 4);
39         prom_putchar_wait(base + UART_LSR * 4, UART_LSR_THRE, UART_LSR_THRE);
40 }
41
42 static void prom_putchar_ar933x(unsigned char ch)
43 {
44         void __iomem *base = (void __iomem *)(KSEG1ADDR(AR933X_UART_BASE));
45
46         prom_putchar_wait(base + AR933X_UART_DATA_REG, AR933X_UART_DATA_TX_CSR,
47                           AR933X_UART_DATA_TX_CSR);
48         __raw_writel(AR933X_UART_DATA_TX_CSR | ch, base + AR933X_UART_DATA_REG);
49         prom_putchar_wait(base + AR933X_UART_DATA_REG, AR933X_UART_DATA_TX_CSR,
50                           AR933X_UART_DATA_TX_CSR);
51 }
52
53 static void prom_putchar_dummy(unsigned char ch)
54 {
55         /* nothing to do */
56 }
57
58 static void prom_putchar_init(void)
59 {
60         void __iomem *base;
61         u32 id;
62
63         base = (void __iomem *)(KSEG1ADDR(AR71XX_RESET_BASE));
64         id = __raw_readl(base + AR71XX_RESET_REG_REV_ID);
65         id &= REV_ID_MAJOR_MASK;
66
67         switch (id) {
68         case REV_ID_MAJOR_AR71XX:
69         case REV_ID_MAJOR_AR7240:
70         case REV_ID_MAJOR_AR7241:
71         case REV_ID_MAJOR_AR7242:
72         case REV_ID_MAJOR_AR913X:
73         case REV_ID_MAJOR_AR9341:
74         case REV_ID_MAJOR_AR9342:
75         case REV_ID_MAJOR_AR9344:
76                 _prom_putchar = prom_putchar_ar71xx;
77                 break;
78
79         case REV_ID_MAJOR_AR9330:
80         case REV_ID_MAJOR_AR9331:
81                 _prom_putchar = prom_putchar_ar933x;
82                 break;
83
84         default:
85                 _prom_putchar = prom_putchar_dummy;
86                 break;
87         }
88 }
89
90 void prom_putchar(unsigned char ch)
91 {
92         if (!_prom_putchar)
93                 prom_putchar_init();
94
95         _prom_putchar(ch);
96 }