ARM: uniphier: refactor board_init()
[oweals/u-boot.git] / arch / arm / mach-uniphier / debug.h
1 /*
2  * Copyright (C) 2016 Socionext Inc.
3  *   Author: Masahiro Yamada <yamada.masahiro@socionext.com>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #ifndef __DEBUG_H__
9 #define __DEBUG_H__
10
11 #include <linux/io.h>
12 #include <linux/serial_reg.h>
13
14 #define DEBUG_UART_BASE         0x54006800
15 #define UART_SHIFT 2
16
17 #define UNIPHIER_UART_TX                0
18 #define UNIPHIER_UART_LSR               (5 * 4)
19
20 /* All functions are inline so that they can be called from .secure section. */
21
22 #ifdef DEBUG
23 static inline void debug_putc(int c)
24 {
25         void __iomem *base = (void __iomem *)DEBUG_UART_BASE;
26
27         while (!(readl(base + UNIPHIER_UART_LSR) & UART_LSR_THRE))
28                 ;
29
30         writel(c, base + UNIPHIER_UART_TX);
31 }
32
33 static inline void debug_puts(const char *s)
34 {
35         while (*s) {
36                 if (*s == '\n')
37                         debug_putc('\r');
38
39                 debug_putc(*s++);
40         }
41 }
42
43 static inline void debug_puth(unsigned long val)
44 {
45         int i;
46         unsigned char c;
47
48         for (i = 8; i--; ) {
49                 c = ((val >> (i * 4)) & 0xf);
50                 c += (c >= 10) ? 'a' - 10 : '0';
51                 debug_putc(c);
52         }
53 }
54 #else
55 static inline void debug_putc(int c)
56 {
57 }
58
59 static inline void debug_puts(const char *s)
60 {
61 }
62
63 static inline void debug_puth(unsigned long val)
64 {
65 }
66 #endif
67
68 #endif /* __DEBUG_H__ */