lib/string_helpers.c: make arrays static
[deliverable/linux.git] / arch / mips / ath79 / early_printk.c
CommitLineData
d4a67d9d 1/*
0bd3acdf 2 * Atheros AR7XXX/AR9XXX SoC early printk support
d4a67d9d 3 *
0bd3acdf 4 * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
d4a67d9d
GJ
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/io.h>
0bd3acdf 13#include <linux/errno.h>
d4a67d9d
GJ
14#include <linux/serial_reg.h>
15#include <asm/addrspace.h>
16
0bd3acdf 17#include <asm/mach-ath79/ath79.h>
d4a67d9d 18#include <asm/mach-ath79/ar71xx_regs.h>
0bd3acdf 19#include <asm/mach-ath79/ar933x_uart.h>
d4a67d9d 20
0bd3acdf
GJ
21static void (*_prom_putchar) (unsigned char);
22
23static inline void prom_putchar_wait(void __iomem *reg, u32 mask, u32 val)
d4a67d9d 24{
0bd3acdf 25 u32 t;
d4a67d9d
GJ
26
27 do {
0bd3acdf
GJ
28 t = __raw_readl(reg);
29 if ((t & mask) == val)
d4a67d9d
GJ
30 break;
31 } while (1);
32}
33
0bd3acdf 34static void prom_putchar_ar71xx(unsigned char ch)
d4a67d9d
GJ
35{
36 void __iomem *base = (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE));
37
0bd3acdf 38 prom_putchar_wait(base + UART_LSR * 4, UART_LSR_THRE, UART_LSR_THRE);
d4a67d9d 39 __raw_writel(ch, base + UART_TX * 4);
0bd3acdf
GJ
40 prom_putchar_wait(base + UART_LSR * 4, UART_LSR_THRE, UART_LSR_THRE);
41}
42
43static void prom_putchar_ar933x(unsigned char ch)
44{
45 void __iomem *base = (void __iomem *)(KSEG1ADDR(AR933X_UART_BASE));
46
47 prom_putchar_wait(base + AR933X_UART_DATA_REG, AR933X_UART_DATA_TX_CSR,
48 AR933X_UART_DATA_TX_CSR);
49 __raw_writel(AR933X_UART_DATA_TX_CSR | ch, base + AR933X_UART_DATA_REG);
50 prom_putchar_wait(base + AR933X_UART_DATA_REG, AR933X_UART_DATA_TX_CSR,
51 AR933X_UART_DATA_TX_CSR);
52}
53
54static void prom_putchar_dummy(unsigned char ch)
55{
56 /* nothing to do */
57}
58
59static void prom_putchar_init(void)
60{
61 void __iomem *base;
62 u32 id;
63
64 base = (void __iomem *)(KSEG1ADDR(AR71XX_RESET_BASE));
65 id = __raw_readl(base + AR71XX_RESET_REG_REV_ID);
66 id &= REV_ID_MAJOR_MASK;
67
68 switch (id) {
69 case REV_ID_MAJOR_AR71XX:
70 case REV_ID_MAJOR_AR7240:
71 case REV_ID_MAJOR_AR7241:
72 case REV_ID_MAJOR_AR7242:
73 case REV_ID_MAJOR_AR913X:
74 _prom_putchar = prom_putchar_ar71xx;
75 break;
76
77 case REV_ID_MAJOR_AR9330:
78 case REV_ID_MAJOR_AR9331:
79 _prom_putchar = prom_putchar_ar933x;
80 break;
81
82 default:
83 _prom_putchar = prom_putchar_dummy;
84 break;
85 }
86}
87
88void prom_putchar(unsigned char ch)
89{
90 if (!_prom_putchar)
91 prom_putchar_init();
92
93 _prom_putchar(ch);
d4a67d9d 94}
This page took 0.125645 seconds and 5 git commands to generate.