2 * Atheros AR7xxx/AR9xxx SoC early printk support
4 * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
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.
12 #include <linux/errno.h>
14 #include <linux/serial_reg.h>
15 #include <asm/addrspace.h>
17 #include <asm/mach-ar71xx/ar71xx.h>
19 static void __iomem *prom_uart_base;
20 static void (*_putchar)(unsigned char);
22 #define UART_READ(r) \
23 __raw_readl(prom_uart_base + 4 * (r))
25 #define UART_WRITE(r, v) \
26 __raw_writel((v), prom_uart_base + 4 * (r))
28 static void prom_putchar_ar71xx(unsigned char ch)
30 while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0)
32 UART_WRITE(UART_TX, ch);
33 while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0)
37 static void prom_putchar_ar933x(unsigned char ch)
39 while (((UART_READ(0)) & 0x200) == 0)
41 UART_WRITE(0, 0x200 | ch);
42 while (((UART_READ(0)) & 0x200) == 0)
46 static int prom_putchar_init(void)
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;
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;
80 void prom_putchar(unsigned char ch)
82 if (prom_putchar_init())