blob: 76631f2faa222a0ef485f56c43a3ea9d481673a7 [file] [log] [blame]
Masahiro Yamadac7432492015-09-22 00:27:37 +09001/*
2 * On-chip UART initializaion for low-level debugging
3 *
4 * Copyright (C) 2014-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <linux/serial_reg.h>
10#include <linux/linkage.h>
Masahiro Yamadaefdf3402016-01-09 01:51:13 +090011
Masahiro Yamada3119eb42016-02-26 18:59:44 +090012#include "../bcu/bcu-regs.h"
13#include "../sc-regs.h"
14#include "../sg-regs.h"
Masahiro Yamadac7432492015-09-22 00:27:37 +090015
16#if !defined(CONFIG_DEBUG_SEMIHOSTING)
17#include CONFIG_DEBUG_LL_INCLUDE
18#endif
19
20#define BAUDRATE 115200
21#define DIV_ROUND(x, d) (((x) + ((d) / 2)) / (d))
22
23ENTRY(debug_ll_init)
24 ldr r0, =SG_REVISION
25 ldr r1, [r0]
26 and r1, r1, #SG_REVISION_TYPE_MASK
27 mov r1, r1, lsr #SG_REVISION_TYPE_SHIFT
28
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090029#if defined(CONFIG_ARCH_UNIPHIER_SLD3)
30#define UNIPHIER_SLD3_UART_CLK 36864000
Masahiro Yamadac7432492015-09-22 00:27:37 +090031 cmp r1, #0x25
Masahiro Yamada98905692016-03-30 20:17:02 +090032 bne sld3_end
Masahiro Yamadac7432492015-09-22 00:27:37 +090033
34 sg_set_pinsel 64, 1, 4, 4, r0, r1 @ TXD0 -> TXD0
35
36 ldr r0, =BCSCR5
37 ldr r1, =0x24440000
38 str r1, [r0]
39
40 ldr r0, =SC_CLKCTRL
41 ldr r1, [r0]
42 orr r1, r1, #SC_CLKCTRL_CEN_PERI
43 str r1, [r0]
44
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090045 ldr r3, =DIV_ROUND(UNIPHIER_SLD3_UART_CLK, 16 * BAUDRATE)
Masahiro Yamadac7432492015-09-22 00:27:37 +090046
47 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +090048sld3_end:
Masahiro Yamadac7432492015-09-22 00:27:37 +090049#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090050#if defined(CONFIG_ARCH_UNIPHIER_LD4)
51#define UNIPHIER_LD4_UART_CLK 36864000
Masahiro Yamadac7432492015-09-22 00:27:37 +090052 cmp r1, #0x26
Masahiro Yamada98905692016-03-30 20:17:02 +090053 bne ld4_end
Masahiro Yamadac7432492015-09-22 00:27:37 +090054
55 ldr r0, =SG_IECTRL
56 ldr r1, [r0]
57 orr r1, r1, #1
58 str r1, [r0]
59
60 sg_set_pinsel 88, 1, 8, 4, r0, r1 @ HSDOUT6 -> TXD0
61
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090062 ldr r3, =DIV_ROUND(UNIPHIER_LD4_UART_CLK, 16 * BAUDRATE)
Masahiro Yamadac7432492015-09-22 00:27:37 +090063
64 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +090065ld4_end:
Masahiro Yamadac7432492015-09-22 00:27:37 +090066#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090067#if defined(CONFIG_ARCH_UNIPHIER_PRO4)
68#define UNIPHIER_PRO4_UART_CLK 73728000
Masahiro Yamadac7432492015-09-22 00:27:37 +090069 cmp r1, #0x28
Masahiro Yamada98905692016-03-30 20:17:02 +090070 bne pro4_end
Masahiro Yamadac7432492015-09-22 00:27:37 +090071
72 sg_set_pinsel 128, 0, 4, 8, r0, r1 @ TXD0 -> TXD0
73
74 ldr r0, =SG_LOADPINCTRL
75 mov r1, #1
76 str r1, [r0]
77
78 ldr r0, =SC_CLKCTRL
79 ldr r1, [r0]
80 orr r1, r1, #SC_CLKCTRL_CEN_PERI
81 str r1, [r0]
82
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090083 ldr r3, =DIV_ROUND(UNIPHIER_PRO4_UART_CLK, 16 * BAUDRATE)
Masahiro Yamadac7432492015-09-22 00:27:37 +090084
85 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +090086pro4_end:
Masahiro Yamadac7432492015-09-22 00:27:37 +090087#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090088#if defined(CONFIG_ARCH_UNIPHIER_SLD8)
89#define UNIPHIER_SLD8_UART_CLK 80000000
Masahiro Yamadac7432492015-09-22 00:27:37 +090090 cmp r1, #0x29
Masahiro Yamada98905692016-03-30 20:17:02 +090091 bne sld8_end
Masahiro Yamadac7432492015-09-22 00:27:37 +090092
93 ldr r0, =SG_IECTRL
94 ldr r1, [r0]
95 orr r1, r1, #1
96 str r1, [r0]
97
98 sg_set_pinsel 70, 3, 8, 4, r0, r1 @ HSDOUT0 -> TXD0
99
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900100 ldr r3, =DIV_ROUND(UNIPHIER_SLD8_UART_CLK, 16 * BAUDRATE)
Masahiro Yamadac7432492015-09-22 00:27:37 +0900101
102 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +0900103sld8_end:
Masahiro Yamadac7432492015-09-22 00:27:37 +0900104#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900105#if defined(CONFIG_ARCH_UNIPHIER_PRO5)
106#define UNIPHIER_PRO5_UART_CLK 73728000
Masahiro Yamadad5167d52015-09-22 00:27:40 +0900107 cmp r1, #0x2A
Masahiro Yamada98905692016-03-30 20:17:02 +0900108 bne pro5_end
Masahiro Yamadad5167d52015-09-22 00:27:40 +0900109
110 sg_set_pinsel 47, 0, 4, 8, r0, r1 @ TXD0 -> TXD0
111 sg_set_pinsel 49, 0, 4, 8, r0, r1 @ TXD1 -> TXD1
112 sg_set_pinsel 51, 0, 4, 8, r0, r1 @ TXD2 -> TXD2
113 sg_set_pinsel 53, 0, 4, 8, r0, r1 @ TXD3 -> TXD3
114
115 ldr r0, =SG_LOADPINCTRL
116 mov r1, #1
117 str r1, [r0]
118
119 ldr r0, =SC_CLKCTRL
120 ldr r1, [r0]
121 orr r1, r1, #SC_CLKCTRL_CEN_PERI
122 str r1, [r0]
123
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900124 ldr r3, =DIV_ROUND(UNIPHIER_PRO5_UART_CLK, 16 * BAUDRATE)
Masahiro Yamadad5167d52015-09-22 00:27:40 +0900125
126 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +0900127pro5_end:
Masahiro Yamadad5167d52015-09-22 00:27:40 +0900128#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900129#if defined(CONFIG_ARCH_UNIPHIER_PXS2)
130#define UNIPHIER_PXS2_UART_CLK 88900000
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900131 cmp r1, #0x2E
Masahiro Yamada98905692016-03-30 20:17:02 +0900132 bne pxs2_end
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900133
134 ldr r0, =SG_IECTRL
135 ldr r1, [r0]
136 orr r1, r1, #1
137 str r1, [r0]
138
139 sg_set_pinsel 217, 8, 8, 4, r0, r1 @ TXD0 -> TXD0
140 sg_set_pinsel 115, 8, 8, 4, r0, r1 @ TXD1 -> TXD1
141 sg_set_pinsel 113, 8, 8, 4, r0, r1 @ TXD2 -> TXD2
142 sg_set_pinsel 219, 8, 8, 4, r0, r1 @ TXD3 -> TXD3
143
144 ldr r0, =SC_CLKCTRL
145 ldr r1, [r0]
146 orr r1, r1, #SC_CLKCTRL_CEN_PERI
147 str r1, [r0]
148
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900149 ldr r3, =DIV_ROUND(UNIPHIER_PXS2_UART_CLK, 16 * BAUDRATE)
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900150
151 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +0900152pxs2_end:
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900153#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900154#if defined(CONFIG_ARCH_UNIPHIER_LD6B)
155#define UNIPHIER_LD6B_UART_CLK 88900000
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900156 cmp r1, #0x2F
Masahiro Yamada98905692016-03-30 20:17:02 +0900157 bne ld6b_end
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900158
159 ldr r0, =SG_IECTRL
160 ldr r1, [r0]
161 orr r1, r1, #1
162 str r1, [r0]
163
164 sg_set_pinsel 135, 3, 8, 4, r0, r1 @ PORT10 -> TXD0
165 sg_set_pinsel 115, 0, 8, 4, r0, r1 @ TXD1 -> TXD1
166 sg_set_pinsel 113, 2, 8, 4, r0, r1 @ SBO0 -> TXD2
167
168 ldr r0, =SC_CLKCTRL
169 ldr r1, [r0]
170 orr r1, r1, #SC_CLKCTRL_CEN_PERI
171 str r1, [r0]
172
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900173 ldr r3, =DIV_ROUND(UNIPHIER_LD6B_UART_CLK, 16 * BAUDRATE)
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900174
175 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +0900176ld6b_end:
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900177#endif
Masahiro Yamadaa8ea60d2016-03-07 20:29:41 +0900178 mov pc, lr
Masahiro Yamadac7432492015-09-22 00:27:37 +0900179
180init_uart:
181 addruart r0, r1, r2
182 mov r1, #UART_LCR_WLEN8 << 8
183 str r1, [r0, #0x10]
184 str r3, [r0, #0x24]
185
186 mov pc, lr
187ENDPROC(debug_ll_init)