blob: 93330b05c76588f2110194dd1132e52fda9d446b [file] [log] [blame]
Masahiro Yamada84ccd792015-02-05 14:42:54 +09001/*
Masahiro Yamadab2916712016-09-14 01:06:08 +09002 * Copyright (C) 2012-2015 Panasonic Corporation
3 * Copyright (C) 2015-2016 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada84ccd792015-02-05 14:42:54 +09005 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
Masahiro Yamadae64a6b12016-06-29 19:39:03 +09009#include <common.h>
10#include <libfdt.h>
11#include <linux/io.h>
12
Masahiro Yamada107b3fb2016-01-09 01:51:13 +090013#include "init.h"
14#include "micro-support-card.h"
Masahiro Yamadab78ffc52016-09-17 03:33:07 +090015#include "sg-regs.h"
Masahiro Yamada107b3fb2016-01-09 01:51:13 +090016#include "soc-info.h"
Masahiro Yamada84ccd792015-02-05 14:42:54 +090017
Masahiro Yamadae64a6b12016-06-29 19:39:03 +090018DECLARE_GLOBAL_DATA_PTR;
19
20static void uniphier_setup_xirq(void)
21{
22 const void *fdt = gd->fdt_blob;
23 int soc_node, aidet_node;
24 const u32 *val;
25 unsigned long aidet_base;
26 u32 tmp;
27
28 soc_node = fdt_path_offset(fdt, "/soc");
29 if (soc_node < 0)
30 return;
31
32 aidet_node = fdt_subnode_offset_namelen(fdt, soc_node, "aidet", 5);
33 if (aidet_node < 0)
34 return;
35
36 val = fdt_getprop(fdt, aidet_node, "reg", NULL);
37 if (!val)
38 return;
39
40 aidet_base = fdt32_to_cpu(*val);
41
42 tmp = readl(aidet_base + 8); /* AIDET DETCONFR2 */
43 tmp |= 0x00ff0000; /* Set XIRQ0-7 low active */
44 writel(tmp, aidet_base + 8);
45
46 tmp = readl(0x55000090); /* IRQCTL */
47 tmp |= 0x000000ff;
48 writel(tmp, 0x55000090);
49}
50
Masahiro Yamadab61664e2017-01-15 14:59:08 +090051#ifdef CONFIG_ARCH_UNIPHIER_LD11
52static void uniphier_ld11_misc_init(void)
Masahiro Yamada5ac9dfb2016-09-17 03:33:04 +090053{
Masahiro Yamadab61664e2017-01-15 14:59:08 +090054 sg_set_pinsel(149, 14, 8, 4); /* XIRQ0 -> XIRQ0 */
55 sg_set_iectrl(149);
56 sg_set_pinsel(153, 14, 8, 4); /* XIRQ4 -> XIRQ4 */
57 sg_set_iectrl(153);
58}
Masahiro Yamada5ac9dfb2016-09-17 03:33:04 +090059#endif
Masahiro Yamadab61664e2017-01-15 14:59:08 +090060
61#ifdef CONFIG_ARCH_UNIPHIER_LD20
62static void uniphier_ld20_misc_init(void)
63{
64 sg_set_pinsel(149, 14, 8, 4); /* XIRQ0 -> XIRQ0 */
65 sg_set_iectrl(149);
66 sg_set_pinsel(153, 14, 8, 4); /* XIRQ4 -> XIRQ4 */
67 sg_set_iectrl(153);
68
69 /* ES1 errata: increase VDD09 supply to suppress VBO noise */
70 if (uniphier_get_soc_revision() == 1) {
71 writel(0x00000003, 0x6184e004);
72 writel(0x00000100, 0x6184e040);
73 writel(0x0000b500, 0x6184e024);
74 writel(0x00000001, 0x6184e000);
75 }
76
77 cci500_init(2);
78}
79#endif
80
81struct uniphier_initdata {
82 enum uniphier_soc_id soc_id;
83 bool nand_2cs;
Masahiro Yamada26b09c02017-01-15 14:59:10 +090084 void (*sbc_init)(void);
Masahiro Yamadab61664e2017-01-15 14:59:08 +090085 void (*pll_init)(void);
86 void (*clk_init)(void);
87 void (*misc_init)(void);
88};
89
90struct uniphier_initdata uniphier_initdata[] = {
91#if defined(CONFIG_ARCH_UNIPHIER_SLD3)
92 {
93 .soc_id = SOC_UNIPHIER_SLD3,
94 .nand_2cs = true,
Masahiro Yamada26b09c02017-01-15 14:59:10 +090095 .sbc_init = uniphier_sbc_init_admulti,
Masahiro Yamadab61664e2017-01-15 14:59:08 +090096 .pll_init = uniphier_sld3_pll_init,
97 .clk_init = uniphier_ld4_clk_init,
98 },
99#endif
100#if defined(CONFIG_ARCH_UNIPHIER_LD4)
101 {
102 .soc_id = SOC_UNIPHIER_LD4,
103 .nand_2cs = true,
Masahiro Yamada26b09c02017-01-15 14:59:10 +0900104 .sbc_init = uniphier_ld4_sbc_init,
Masahiro Yamadab61664e2017-01-15 14:59:08 +0900105 .pll_init = uniphier_ld4_pll_init,
106 .clk_init = uniphier_ld4_clk_init,
107 },
108#endif
109#if defined(CONFIG_ARCH_UNIPHIER_PRO4)
110 {
111 .soc_id = SOC_UNIPHIER_PRO4,
112 .nand_2cs = false,
Masahiro Yamada26b09c02017-01-15 14:59:10 +0900113 .sbc_init = uniphier_sbc_init_savepin,
Masahiro Yamadab61664e2017-01-15 14:59:08 +0900114 .pll_init = uniphier_pro4_pll_init,
115 .clk_init = uniphier_pro4_clk_init,
116 },
117#endif
118#if defined(CONFIG_ARCH_UNIPHIER_SLD8)
119 {
120 .soc_id = SOC_UNIPHIER_SLD8,
121 .nand_2cs = true,
Masahiro Yamada26b09c02017-01-15 14:59:10 +0900122 .sbc_init = uniphier_ld4_sbc_init,
Masahiro Yamadab61664e2017-01-15 14:59:08 +0900123 .pll_init = uniphier_ld4_pll_init,
124 .clk_init = uniphier_ld4_clk_init,
125 },
126#endif
127#if defined(CONFIG_ARCH_UNIPHIER_PRO5)
128 {
129 .soc_id = SOC_UNIPHIER_PRO5,
130 .nand_2cs = true,
Masahiro Yamada26b09c02017-01-15 14:59:10 +0900131 .sbc_init = uniphier_sbc_init_savepin,
Masahiro Yamadab61664e2017-01-15 14:59:08 +0900132 .clk_init = uniphier_pro5_clk_init,
133 },
134#endif
135#if defined(CONFIG_ARCH_UNIPHIER_PXS2)
136 {
137 .soc_id = SOC_UNIPHIER_PXS2,
138 .nand_2cs = true,
Masahiro Yamada26b09c02017-01-15 14:59:10 +0900139 .sbc_init = uniphier_pxs2_sbc_init,
Masahiro Yamadab61664e2017-01-15 14:59:08 +0900140 .clk_init = uniphier_pxs2_clk_init,
141 },
142#endif
143#if defined(CONFIG_ARCH_UNIPHIER_LD6B)
144 {
145 .soc_id = SOC_UNIPHIER_LD6B,
146 .nand_2cs = true,
Masahiro Yamada26b09c02017-01-15 14:59:10 +0900147 .sbc_init = uniphier_pxs2_sbc_init,
Masahiro Yamadab61664e2017-01-15 14:59:08 +0900148 .clk_init = uniphier_pxs2_clk_init,
149 },
150#endif
151#if defined(CONFIG_ARCH_UNIPHIER_LD11)
152 {
153 .soc_id = SOC_UNIPHIER_LD11,
154 .nand_2cs = false,
Masahiro Yamada26b09c02017-01-15 14:59:10 +0900155 .sbc_init = uniphier_ld11_sbc_init,
Masahiro Yamadab61664e2017-01-15 14:59:08 +0900156 .pll_init = uniphier_ld11_pll_init,
157 .clk_init = uniphier_ld11_clk_init,
158 .misc_init = uniphier_ld11_misc_init,
159 },
160#endif
161#if defined(CONFIG_ARCH_UNIPHIER_LD20)
162 {
163 .soc_id = SOC_UNIPHIER_LD20,
164 .nand_2cs = false,
Masahiro Yamada26b09c02017-01-15 14:59:10 +0900165 .sbc_init = uniphier_ld11_sbc_init,
Masahiro Yamadab61664e2017-01-15 14:59:08 +0900166 .pll_init = uniphier_ld20_pll_init,
167 .misc_init = uniphier_ld20_misc_init,
168 },
169#endif
170};
171
172static struct uniphier_initdata *uniphier_get_initdata(
173 enum uniphier_soc_id soc_id)
174{
175 int i;
176
177 for (i = 0; i < ARRAY_SIZE(uniphier_initdata); i++) {
178 if (uniphier_initdata[i].soc_id == soc_id)
179 return &uniphier_initdata[i];
180 }
181
182 return NULL;
Masahiro Yamada5ac9dfb2016-09-17 03:33:04 +0900183}
184
Masahiro Yamadab2916712016-09-14 01:06:08 +0900185int board_init(void)
Masahiro Yamada84ccd792015-02-05 14:42:54 +0900186{
Masahiro Yamadab61664e2017-01-15 14:59:08 +0900187 struct uniphier_initdata *initdata;
188 enum uniphier_soc_id soc_id;
189 int ret;
190
Masahiro Yamada84697002015-09-22 00:27:31 +0900191 led_puts("U0");
Masahiro Yamada84ccd792015-02-05 14:42:54 +0900192
Masahiro Yamadab61664e2017-01-15 14:59:08 +0900193 soc_id = uniphier_get_soc_type();
194 initdata = uniphier_get_initdata(soc_id);
195 if (!initdata) {
196 pr_err("unsupported board\n");
197 return -EINVAL;
Masahiro Yamada323d1f92015-09-22 00:27:39 +0900198 }
Masahiro Yamada198a97a2015-02-27 02:26:51 +0900199
Masahiro Yamada26b09c02017-01-15 14:59:10 +0900200 initdata->sbc_init();
201
202 support_card_init();
203
204 led_puts("U0");
205
Masahiro Yamadab61664e2017-01-15 14:59:08 +0900206 if (IS_ENABLED(CONFIG_NAND_DENALI)) {
207 ret = uniphier_pin_init(initdata->nand_2cs ?
208 "nand2cs_grp" : "nand_grp");
209 if (ret)
210 pr_err("failed to init NAND pins\n");
211 }
212
213 led_puts("U1");
214
215 if (initdata->pll_init)
216 initdata->pll_init();
Masahiro Yamadae64a6b12016-06-29 19:39:03 +0900217
Masahiro Yamada84697002015-09-22 00:27:31 +0900218 led_puts("U2");
Masahiro Yamada198a97a2015-02-27 02:26:51 +0900219
Masahiro Yamadab61664e2017-01-15 14:59:08 +0900220 if (initdata->clk_init)
221 initdata->clk_init();
Masahiro Yamadab2916712016-09-14 01:06:08 +0900222
223 led_puts("U3");
224
Masahiro Yamadab61664e2017-01-15 14:59:08 +0900225 if (initdata->misc_init)
226 initdata->misc_init();
227
228 led_puts("U4");
229
230 uniphier_setup_xirq();
231
232 led_puts("U5");
233
234 support_card_late_init();
235
236 led_puts("U6");
237
Masahiro Yamadab2916712016-09-14 01:06:08 +0900238#ifdef CONFIG_ARM64
239 uniphier_smp_kick_all_cpus();
240#endif
241
242 led_puts("Uboo");
243
Masahiro Yamada84ccd792015-02-05 14:42:54 +0900244 return 0;
245}