blob: 3fed7985fcd63410e76b58d2162cdaf8b1c3909f [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
Masahiro Yamada0ae28652019-06-29 02:38:01 +090019#define SG_REVISION_TYPE_SHIFT 16
20#define SG_REVISION_TYPE_MASK (0xff << SG_REVISION_TYPE_SHIFT)
Masahiro Yamadac7432492015-09-22 00:27:37 +090021#define BAUDRATE 115200
22#define DIV_ROUND(x, d) (((x) + ((d) / 2)) / (d))
23
Masahiro Yamada3cac7f72019-06-29 02:38:06 +090024.macro sg_set_pinsel, pin, muxval, mux_bits, reg_stride, ra, rd
Masahiro Yamada76b31242019-07-10 20:07:40 +090025 ldr \ra, =(SG_BASE + SG_PINCTRL_BASE + \pin * \mux_bits / 32 * \reg_stride)
Masahiro Yamada3cac7f72019-06-29 02:38:06 +090026 ldr \rd, [\ra]
27 and \rd, \rd, #~(((1 << \mux_bits) - 1) << (\pin * \mux_bits % 32))
28 orr \rd, \rd, #(\muxval << (\pin * \mux_bits % 32))
29 str \rd, [\ra]
30.endm
31
Masahiro Yamadac7432492015-09-22 00:27:37 +090032ENTRY(debug_ll_init)
Masahiro Yamada76b31242019-07-10 20:07:40 +090033 ldr r0, =(SG_BASE + SG_REVISION)
Masahiro Yamadac7432492015-09-22 00:27:37 +090034 ldr r1, [r0]
35 and r1, r1, #SG_REVISION_TYPE_MASK
36 mov r1, r1, lsr #SG_REVISION_TYPE_SHIFT
37
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090038#if defined(CONFIG_ARCH_UNIPHIER_LD4)
39#define UNIPHIER_LD4_UART_CLK 36864000
Masahiro Yamadac7432492015-09-22 00:27:37 +090040 cmp r1, #0x26
Masahiro Yamada98905692016-03-30 20:17:02 +090041 bne ld4_end
Masahiro Yamadac7432492015-09-22 00:27:37 +090042
Masahiro Yamada76b31242019-07-10 20:07:40 +090043 ldr r0, =(SG_BASE + SG_IECTRL)
Masahiro Yamadac7432492015-09-22 00:27:37 +090044 ldr r1, [r0]
45 orr r1, r1, #1
46 str r1, [r0]
47
48 sg_set_pinsel 88, 1, 8, 4, r0, r1 @ HSDOUT6 -> TXD0
49
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090050 ldr r3, =DIV_ROUND(UNIPHIER_LD4_UART_CLK, 16 * BAUDRATE)
Masahiro Yamadac7432492015-09-22 00:27:37 +090051
52 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +090053ld4_end:
Masahiro Yamadac7432492015-09-22 00:27:37 +090054#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090055#if defined(CONFIG_ARCH_UNIPHIER_PRO4)
56#define UNIPHIER_PRO4_UART_CLK 73728000
Masahiro Yamadac7432492015-09-22 00:27:37 +090057 cmp r1, #0x28
Masahiro Yamada98905692016-03-30 20:17:02 +090058 bne pro4_end
Masahiro Yamadac7432492015-09-22 00:27:37 +090059
60 sg_set_pinsel 128, 0, 4, 8, r0, r1 @ TXD0 -> TXD0
61
Masahiro Yamada76b31242019-07-10 20:07:40 +090062 ldr r0, =(SG_BASE + SG_LOADPINCTRL)
Masahiro Yamadac7432492015-09-22 00:27:37 +090063 mov r1, #1
64 str r1, [r0]
65
Masahiro Yamadac84024c2019-07-10 20:07:41 +090066 ldr r0, =(SC_BASE + SC_CLKCTRL)
Masahiro Yamadac7432492015-09-22 00:27:37 +090067 ldr r1, [r0]
68 orr r1, r1, #SC_CLKCTRL_CEN_PERI
69 str r1, [r0]
70
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090071 ldr r3, =DIV_ROUND(UNIPHIER_PRO4_UART_CLK, 16 * BAUDRATE)
Masahiro Yamadac7432492015-09-22 00:27:37 +090072
73 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +090074pro4_end:
Masahiro Yamadac7432492015-09-22 00:27:37 +090075#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090076#if defined(CONFIG_ARCH_UNIPHIER_SLD8)
77#define UNIPHIER_SLD8_UART_CLK 80000000
Masahiro Yamadac7432492015-09-22 00:27:37 +090078 cmp r1, #0x29
Masahiro Yamada98905692016-03-30 20:17:02 +090079 bne sld8_end
Masahiro Yamadac7432492015-09-22 00:27:37 +090080
Masahiro Yamada76b31242019-07-10 20:07:40 +090081 ldr r0, =(SG_BASE + SG_IECTRL)
Masahiro Yamadac7432492015-09-22 00:27:37 +090082 ldr r1, [r0]
83 orr r1, r1, #1
84 str r1, [r0]
85
86 sg_set_pinsel 70, 3, 8, 4, r0, r1 @ HSDOUT0 -> TXD0
87
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090088 ldr r3, =DIV_ROUND(UNIPHIER_SLD8_UART_CLK, 16 * BAUDRATE)
Masahiro Yamadac7432492015-09-22 00:27:37 +090089
90 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +090091sld8_end:
Masahiro Yamadac7432492015-09-22 00:27:37 +090092#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +090093#if defined(CONFIG_ARCH_UNIPHIER_PRO5)
94#define UNIPHIER_PRO5_UART_CLK 73728000
Masahiro Yamadad5167d52015-09-22 00:27:40 +090095 cmp r1, #0x2A
Masahiro Yamada98905692016-03-30 20:17:02 +090096 bne pro5_end
Masahiro Yamadad5167d52015-09-22 00:27:40 +090097
98 sg_set_pinsel 47, 0, 4, 8, r0, r1 @ TXD0 -> TXD0
99 sg_set_pinsel 49, 0, 4, 8, r0, r1 @ TXD1 -> TXD1
100 sg_set_pinsel 51, 0, 4, 8, r0, r1 @ TXD2 -> TXD2
101 sg_set_pinsel 53, 0, 4, 8, r0, r1 @ TXD3 -> TXD3
102
Masahiro Yamada76b31242019-07-10 20:07:40 +0900103 ldr r0, =(SG_BASE + SG_LOADPINCTRL)
Masahiro Yamadad5167d52015-09-22 00:27:40 +0900104 mov r1, #1
105 str r1, [r0]
106
Masahiro Yamadac84024c2019-07-10 20:07:41 +0900107 ldr r0, =(SC_BASE + SC_CLKCTRL)
Masahiro Yamadad5167d52015-09-22 00:27:40 +0900108 ldr r1, [r0]
109 orr r1, r1, #SC_CLKCTRL_CEN_PERI
110 str r1, [r0]
111
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900112 ldr r3, =DIV_ROUND(UNIPHIER_PRO5_UART_CLK, 16 * BAUDRATE)
Masahiro Yamadad5167d52015-09-22 00:27:40 +0900113
114 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +0900115pro5_end:
Masahiro Yamadad5167d52015-09-22 00:27:40 +0900116#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900117#if defined(CONFIG_ARCH_UNIPHIER_PXS2)
118#define UNIPHIER_PXS2_UART_CLK 88900000
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900119 cmp r1, #0x2E
Masahiro Yamada98905692016-03-30 20:17:02 +0900120 bne pxs2_end
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900121
Masahiro Yamada76b31242019-07-10 20:07:40 +0900122 ldr r0, =(SG_BASE + SG_IECTRL)
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900123 ldr r1, [r0]
124 orr r1, r1, #1
125 str r1, [r0]
126
127 sg_set_pinsel 217, 8, 8, 4, r0, r1 @ TXD0 -> TXD0
128 sg_set_pinsel 115, 8, 8, 4, r0, r1 @ TXD1 -> TXD1
129 sg_set_pinsel 113, 8, 8, 4, r0, r1 @ TXD2 -> TXD2
130 sg_set_pinsel 219, 8, 8, 4, r0, r1 @ TXD3 -> TXD3
131
Masahiro Yamadac84024c2019-07-10 20:07:41 +0900132 ldr r0, =(SC_BASE + SC_CLKCTRL)
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900133 ldr r1, [r0]
134 orr r1, r1, #SC_CLKCTRL_CEN_PERI
135 str r1, [r0]
136
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900137 ldr r3, =DIV_ROUND(UNIPHIER_PXS2_UART_CLK, 16 * BAUDRATE)
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900138
139 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +0900140pxs2_end:
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900141#endif
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900142#if defined(CONFIG_ARCH_UNIPHIER_LD6B)
143#define UNIPHIER_LD6B_UART_CLK 88900000
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900144 cmp r1, #0x2F
Masahiro Yamada98905692016-03-30 20:17:02 +0900145 bne ld6b_end
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900146
Masahiro Yamada76b31242019-07-10 20:07:40 +0900147 ldr r0, =(SG_BASE + SG_IECTRL)
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900148 ldr r1, [r0]
149 orr r1, r1, #1
150 str r1, [r0]
151
152 sg_set_pinsel 135, 3, 8, 4, r0, r1 @ PORT10 -> TXD0
153 sg_set_pinsel 115, 0, 8, 4, r0, r1 @ TXD1 -> TXD1
154 sg_set_pinsel 113, 2, 8, 4, r0, r1 @ SBO0 -> TXD2
155
Masahiro Yamadac84024c2019-07-10 20:07:41 +0900156 ldr r0, =(SC_BASE + SC_CLKCTRL)
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900157 ldr r1, [r0]
158 orr r1, r1, #SC_CLKCTRL_CEN_PERI
159 str r1, [r0]
160
Masahiro Yamada53c59ae2016-03-18 16:41:43 +0900161 ldr r3, =DIV_ROUND(UNIPHIER_LD6B_UART_CLK, 16 * BAUDRATE)
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900162
163 b init_uart
Masahiro Yamada98905692016-03-30 20:17:02 +0900164ld6b_end:
Masahiro Yamada1fe65d32015-09-22 00:27:41 +0900165#endif
Masahiro Yamadaa8ea60d2016-03-07 20:29:41 +0900166 mov pc, lr
Masahiro Yamadac7432492015-09-22 00:27:37 +0900167
168init_uart:
169 addruart r0, r1, r2
170 mov r1, #UART_LCR_WLEN8 << 8
171 str r1, [r0, #0x10]
172 str r3, [r0, #0x24]
173
174 mov pc, lr
175ENDPROC(debug_ll_init)