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