blob: db2904b553b17b75aad61067fef8e46527c5c889 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamada52f0c512016-03-18 16:41:52 +09002/*
3 * Copyright (C) 2016 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada52f0c512016-03-18 16:41:52 +09004 */
5
6#include <common.h>
7#include <debug_uart.h>
8#include <linux/io.h>
9#include <linux/serial_reg.h>
10
11#include "../soc-info.h"
12#include "debug-uart.h"
13
14#define UNIPHIER_UART_TX 0x00
15#define UNIPHIER_UART_LCR_MCR 0x10
16#define UNIPHIER_UART_LSR 0x14
17#define UNIPHIER_UART_LDR 0x24
18
19static void _debug_uart_putc(int c)
20{
21 void __iomem *base = (void __iomem *)CONFIG_DEBUG_UART_BASE;
22
23 while (!(readl(base + UNIPHIER_UART_LSR) & UART_LSR_THRE))
24 ;
25
26 writel(c, base + UNIPHIER_UART_TX);
27}
28
29void _debug_uart_init(void)
30{
Masahiro Yamada1950f122019-06-29 02:38:05 +090031#ifdef CONFIG_SPL_BUILD
Masahiro Yamada52f0c512016-03-18 16:41:52 +090032 void __iomem *base = (void __iomem *)CONFIG_DEBUG_UART_BASE;
33 unsigned int divisor;
34
Masahiro Yamada31649052017-01-21 18:05:26 +090035 switch (uniphier_get_soc_id()) {
Masahiro Yamada52f0c512016-03-18 16:41:52 +090036#if defined(CONFIG_ARCH_UNIPHIER_LD4)
Masahiro Yamada31649052017-01-21 18:05:26 +090037 case UNIPHIER_LD4_ID:
Masahiro Yamada52f0c512016-03-18 16:41:52 +090038 divisor = uniphier_ld4_debug_uart_init();
39 break;
40#endif
41#if defined(CONFIG_ARCH_UNIPHIER_PRO4)
Masahiro Yamada31649052017-01-21 18:05:26 +090042 case UNIPHIER_PRO4_ID:
Masahiro Yamada52f0c512016-03-18 16:41:52 +090043 divisor = uniphier_pro4_debug_uart_init();
44 break;
45#endif
46#if defined(CONFIG_ARCH_UNIPHIER_SLD8)
Masahiro Yamada31649052017-01-21 18:05:26 +090047 case UNIPHIER_SLD8_ID:
Masahiro Yamada52f0c512016-03-18 16:41:52 +090048 divisor = uniphier_sld8_debug_uart_init();
49 break;
50#endif
51#if defined(CONFIG_ARCH_UNIPHIER_PRO5)
Masahiro Yamada31649052017-01-21 18:05:26 +090052 case UNIPHIER_PRO5_ID:
Masahiro Yamada52f0c512016-03-18 16:41:52 +090053 divisor = uniphier_pro5_debug_uart_init();
54 break;
55#endif
56#if defined(CONFIG_ARCH_UNIPHIER_PXS2)
Masahiro Yamada31649052017-01-21 18:05:26 +090057 case UNIPHIER_PXS2_ID:
Masahiro Yamada52f0c512016-03-18 16:41:52 +090058 divisor = uniphier_pxs2_debug_uart_init();
59 break;
60#endif
61#if defined(CONFIG_ARCH_UNIPHIER_LD6B)
Masahiro Yamada31649052017-01-21 18:05:26 +090062 case UNIPHIER_LD6B_ID:
Masahiro Yamada52f0c512016-03-18 16:41:52 +090063 divisor = uniphier_ld6b_debug_uart_init();
64 break;
65#endif
Masahiro Yamada52f0c512016-03-18 16:41:52 +090066 default:
67 return;
68 }
69
70 writel(UART_LCR_WLEN8 << 8, base + UNIPHIER_UART_LCR_MCR);
71
72 writel(divisor, base + UNIPHIER_UART_LDR);
Masahiro Yamada1950f122019-06-29 02:38:05 +090073#endif
Masahiro Yamada52f0c512016-03-18 16:41:52 +090074}
75DEBUG_UART_FUNCS