ar71xx: add AR933x specific early_printk support
[openwrt/svn-archive/archive.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
19 static void __iomem *prom_uart_base;
20 static void (*_putchar)(unsigned char);
21
22 #define UART_READ(r) \
23 __raw_readl(prom_uart_base + 4 * (r))
24
25 #define UART_WRITE(r, v) \
26 __raw_writel((v), prom_uart_base + 4 * (r))
27
28 static void prom_putchar_ar71xx(unsigned char ch)
29 {
30 while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0)
31 ;
32 UART_WRITE(UART_TX, ch);
33 while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0)
34 ;
35 }
36
37 static void prom_putchar_ar933x(unsigned char ch)
38 {
39 while (((UART_READ(0)) & 0x200) == 0)
40 ;
41 UART_WRITE(0, 0x200 | ch);
42 while (((UART_READ(0)) & 0x200) == 0)
43 ;
44 }
45
46 static int prom_putchar_init(void)
47 {
48 if (_putchar)
49 return 0;
50
51 switch(ar71xx_soc) {
52 case AR71XX_SOC_AR7130:
53 case AR71XX_SOC_AR7141:
54 case AR71XX_SOC_AR7161:
55 case AR71XX_SOC_AR7240:
56 case AR71XX_SOC_AR7241:
57 case AR71XX_SOC_AR7242:
58 case AR71XX_SOC_AR9130:
59 case AR71XX_SOC_AR9132:
60 case AR71XX_SOC_AR9341:
61 case AR71XX_SOC_AR9342:
62 case AR71XX_SOC_AR9344:
63 prom_uart_base = (void __iomem *) KSEG1ADDR(AR71XX_UART_BASE);
64 _putchar = prom_putchar_ar71xx;
65 break;
66
67 case AR71XX_SOC_AR9330:
68 case AR71XX_SOC_AR9331:
69 prom_uart_base = (void __iomem *) KSEG1ADDR(AR933X_UART_BASE);
70 _putchar = prom_putchar_ar933x;
71 break;
72
73 default:
74 return -ENODEV;
75 }
76
77 return 0;
78 }
79
80 void prom_putchar(unsigned char ch)
81 {
82 if (prom_putchar_init())
83 return;
84
85 _putchar(ch);
86 }