Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
early_printk.c
Go to the documentation of this file.
1 /*
2  * Atheros AR7XXX/AR9XXX SoC early printk support
3  *
4  * Copyright (C) 2008-2011 Gabor Juhos <[email protected]>
5  * Copyright (C) 2008 Imre Kaloz <[email protected]>
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>
13 #include <linux/errno.h>
14 #include <linux/serial_reg.h>
15 #include <asm/addrspace.h>
16 
17 #include <asm/mach-ath79/ath79.h>
20 
21 static void (*_prom_putchar) (unsigned char);
22 
23 static inline void prom_putchar_wait(void __iomem *reg, u32 mask, u32 val)
24 {
25  u32 t;
26 
27  do {
28  t = __raw_readl(reg);
29  if ((t & mask) == val)
30  break;
31  } while (1);
32 }
33 
34 static void prom_putchar_ar71xx(unsigned char ch)
35 {
36  void __iomem *base = (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE));
37 
38  prom_putchar_wait(base + UART_LSR * 4, UART_LSR_THRE, UART_LSR_THRE);
39  __raw_writel(ch, base + UART_TX * 4);
40  prom_putchar_wait(base + UART_LSR * 4, UART_LSR_THRE, UART_LSR_THRE);
41 }
42 
43 static 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,
50  prom_putchar_wait(base + AR933X_UART_DATA_REG, AR933X_UART_DATA_TX_CSR,
52 }
53 
54 static void prom_putchar_dummy(unsigned char ch)
55 {
56  /* nothing to do */
57 }
58 
59 static void prom_putchar_init(void)
60 {
61  void __iomem *base;
62  u32 id;
63 
64  base = (void __iomem *)(KSEG1ADDR(AR71XX_RESET_BASE));
66  id &= REV_ID_MAJOR_MASK;
67 
68  switch (id) {
77  _prom_putchar = prom_putchar_ar71xx;
78  break;
79 
82  _prom_putchar = prom_putchar_ar933x;
83  break;
84 
85  default:
86  _prom_putchar = prom_putchar_dummy;
87  break;
88  }
89 }
90 
91 void prom_putchar(unsigned char ch)
92 {
93  if (!_prom_putchar)
94  prom_putchar_init();
95 
96  _prom_putchar(ch);
97 }