blob: bc16f77b96171d735fe0284f2bdd9af3e6241a3b [file] [log] [blame]
Masahiro Yamadae8a92932016-08-10 16:08:49 +09001/*
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
23static 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
33static 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
43static 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
55static inline void debug_putc(int c)
56{
57}
58
59static inline void debug_puts(const char *s)
60{
61}
62
63static inline void debug_puth(unsigned long val)
64{
65}
66#endif
67
68#endif /* __DEBUG_H__ */