blob: 466dc9b03bf7867e0914567f668637668f102b07 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Masahiro Yamadae8a92932016-08-10 16:08:49 +09002/*
3 * Copyright (C) 2016 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadae8a92932016-08-10 16:08:49 +09005 */
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
22static 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
32static 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
42static 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
54static inline void debug_putc(int c)
55{
56}
57
58static inline void debug_puts(const char *s)
59{
60}
61
62static inline void debug_puth(unsigned long val)
63{
64}
65#endif
66
67#endif /* __DEBUG_H__ */