blob: 9fe3eaadf1d95adfd6a1884d89dd60274e978c0e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Masahiro Yamadac7432492015-09-22 00:27:37 +09002/*
3 * On-chip UART initializaion for low-level debugging
4 *
5 * Copyright (C) 2014-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadac7432492015-09-22 00:27:37 +09006 */
7
8#include <linux/serial_reg.h>
9#include <linux/linkage.h>
Masahiro Yamadaefdf3402016-01-09 01:51:13 +090010
Masahiro Yamada3119eb42016-02-26 18:59:44 +090011#include "../bcu/bcu-regs.h"
12#include "../sc-regs.h"
13#include "../sg-regs.h"
Masahiro Yamadac7432492015-09-22 00:27:37 +090014
15#if !defined(CONFIG_DEBUG_SEMIHOSTING)
16#include CONFIG_DEBUG_LL_INCLUDE
17#endif
18
19#define BAUDRATE 115200
20#define DIV_ROUND(x, d) (((x) + ((d) / 2)) / (d))
21
22ENTRY(debug_ll_init)
23 ldr r0, =SG_REVISION
24 ldr r1, [r0]
25 and r1, r1, #SG_REVISION_TYPE_MASK
26 mov r1, r1, lsr #SG_REVISION_TYPE_SHIFT
27
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090028#if defined(CONFIG_ARCH_UNIPHIER_LD4)
29#define UNIPHIER_LD4_UART_CLK 36864000
Masahiro Yamadac7432492015-09-22 00:27:37 +090030 cmp r1, #0x26
Masahiro Yamada98905692016-03-30 20:17:02 +090031 bne ld4_end
Masahiro Yamadac7432492015-09-22 00:27:37 +090032
33 ldr r0, =SG_IECTRL
34 ldr r1, [r0]
35 orr r1, r1, #1
36 str r1, [r0]
37
38 sg_set_pinsel 88, 1, 8, 4, r0, r1 @ HSDOUT6 -> TXD0
39
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090040 ldr r3, =DIV_ROUND(UNIPHIER_LD4_UART_CLK, 16 * BAUDRATE)
Masahiro Yamadac7432492015-09-22 00:27:37 +090041
42 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +090043ld4_end:
Masahiro Yamadac7432492015-09-22 00:27:37 +090044#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090045#if defined(CONFIG_ARCH_UNIPHIER_PRO4)
46#define UNIPHIER_PRO4_UART_CLK 73728000
Masahiro Yamadac7432492015-09-22 00:27:37 +090047 cmp r1, #0x28
Masahiro Yamada98905692016-03-30 20:17:02 +090048 bne pro4_end
Masahiro Yamadac7432492015-09-22 00:27:37 +090049
50 sg_set_pinsel 128, 0, 4, 8, r0, r1 @ TXD0 -> TXD0
51
52 ldr r0, =SG_LOADPINCTRL
53 mov r1, #1
54 str r1, [r0]
55
56 ldr r0, =SC_CLKCTRL
57 ldr r1, [r0]
58 orr r1, r1, #SC_CLKCTRL_CEN_PERI
59 str r1, [r0]
60
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090061 ldr r3, =DIV_ROUND(UNIPHIER_PRO4_UART_CLK, 16 * BAUDRATE)
Masahiro Yamadac7432492015-09-22 00:27:37 +090062
63 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +090064pro4_end:
Masahiro Yamadac7432492015-09-22 00:27:37 +090065#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090066#if defined(CONFIG_ARCH_UNIPHIER_SLD8)
67#define UNIPHIER_SLD8_UART_CLK 80000000
Masahiro Yamadac7432492015-09-22 00:27:37 +090068 cmp r1, #0x29
Masahiro Yamada98905692016-03-30 20:17:02 +090069 bne sld8_end
Masahiro Yamadac7432492015-09-22 00:27:37 +090070
71 ldr r0, =SG_IECTRL
72 ldr r1, [r0]
73 orr r1, r1, #1
74 str r1, [r0]
75
76 sg_set_pinsel 70, 3, 8, 4, r0, r1 @ HSDOUT0 -> TXD0
77
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090078 ldr r3, =DIV_ROUND(UNIPHIER_SLD8_UART_CLK, 16 * BAUDRATE)
Masahiro Yamadac7432492015-09-22 00:27:37 +090079
80 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +090081sld8_end:
Masahiro Yamadac7432492015-09-22 00:27:37 +090082#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090083#if defined(CONFIG_ARCH_UNIPHIER_PRO5)
84#define UNIPHIER_PRO5_UART_CLK 73728000
Masahiro Yamadad5167d52015-09-22 00:27:40 +090085 cmp r1, #0x2A
Masahiro Yamada98905692016-03-30 20:17:02 +090086 bne pro5_end
Masahiro Yamadad5167d52015-09-22 00:27:40 +090087
88 sg_set_pinsel 47, 0, 4, 8, r0, r1 @ TXD0 -> TXD0
89 sg_set_pinsel 49, 0, 4, 8, r0, r1 @ TXD1 -> TXD1
90 sg_set_pinsel 51, 0, 4, 8, r0, r1 @ TXD2 -> TXD2
91 sg_set_pinsel 53, 0, 4, 8, r0, r1 @ TXD3 -> TXD3
92
93 ldr r0, =SG_LOADPINCTRL
94 mov r1, #1
95 str r1, [r0]
96
97 ldr r0, =SC_CLKCTRL
98 ldr r1, [r0]
99 orr r1, r1, #SC_CLKCTRL_CEN_PERI
100 str r1, [r0]
101
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900102 ldr r3, =DIV_ROUND(UNIPHIER_PRO5_UART_CLK, 16 * BAUDRATE)
Masahiro Yamadad5167d52015-09-22 00:27:40 +0900103
104 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +0900105pro5_end:
Masahiro Yamadad5167d52015-09-22 00:27:40 +0900106#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900107#if defined(CONFIG_ARCH_UNIPHIER_PXS2)
108#define UNIPHIER_PXS2_UART_CLK 88900000
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900109 cmp r1, #0x2E
Masahiro Yamada98905692016-03-30 20:17:02 +0900110 bne pxs2_end
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900111
112 ldr r0, =SG_IECTRL
113 ldr r1, [r0]
114 orr r1, r1, #1
115 str r1, [r0]
116
117 sg_set_pinsel 217, 8, 8, 4, r0, r1 @ TXD0 -> TXD0
118 sg_set_pinsel 115, 8, 8, 4, r0, r1 @ TXD1 -> TXD1
119 sg_set_pinsel 113, 8, 8, 4, r0, r1 @ TXD2 -> TXD2
120 sg_set_pinsel 219, 8, 8, 4, r0, r1 @ TXD3 -> TXD3
121
122 ldr r0, =SC_CLKCTRL
123 ldr r1, [r0]
124 orr r1, r1, #SC_CLKCTRL_CEN_PERI
125 str r1, [r0]
126
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900127 ldr r3, =DIV_ROUND(UNIPHIER_PXS2_UART_CLK, 16 * BAUDRATE)
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900128
129 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +0900130pxs2_end:
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900131#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900132#if defined(CONFIG_ARCH_UNIPHIER_LD6B)
133#define UNIPHIER_LD6B_UART_CLK 88900000
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900134 cmp r1, #0x2F
Masahiro Yamada98905692016-03-30 20:17:02 +0900135 bne ld6b_end
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900136
137 ldr r0, =SG_IECTRL
138 ldr r1, [r0]
139 orr r1, r1, #1
140 str r1, [r0]
141
142 sg_set_pinsel 135, 3, 8, 4, r0, r1 @ PORT10 -> TXD0
143 sg_set_pinsel 115, 0, 8, 4, r0, r1 @ TXD1 -> TXD1
144 sg_set_pinsel 113, 2, 8, 4, r0, r1 @ SBO0 -> TXD2
145
146 ldr r0, =SC_CLKCTRL
147 ldr r1, [r0]
148 orr r1, r1, #SC_CLKCTRL_CEN_PERI
149 str r1, [r0]
150
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900151 ldr r3, =DIV_ROUND(UNIPHIER_LD6B_UART_CLK, 16 * BAUDRATE)
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900152
153 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +0900154ld6b_end:
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900155#endif
Masahiro Yamadaa8ea60d2016-03-07 20:29:41 +0900156 mov pc, lr
Masahiro Yamadac7432492015-09-22 00:27:37 +0900157
158init_uart:
159 addruart r0, r1, r2
160 mov r1, #UART_LCR_WLEN8 << 8
161 str r1, [r0, #0x10]
162 str r3, [r0, #0x24]
163
164 mov pc, lr
165ENDPROC(debug_ll_init)