blob: 23be8cfcf00df3213f05f5ab9ff14aa1d6d98dc1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamadafb092032017-02-14 01:24:26 +09002/*
3 * Copyright (C) 2015-2017 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadafb092032017-02-14 01:24:26 +09005 */
6
7#include <common.h>
8#include <spl.h>
Masahiro Yamada609cd532017-10-13 19:21:55 +09009#include <stdio.h>
Masahiro Yamadafb092032017-02-14 01:24:26 +090010#include <linux/log2.h>
11
12#include "../init.h"
13#include "../sbc/sbc-regs.h"
14#include "../sg-regs.h"
15#include "../soc-info.h"
16#include "boot-device.h"
17
18struct uniphier_boot_device_info {
19 unsigned int soc_id;
20 unsigned int boot_device_sel_shift;
21 const struct uniphier_boot_device *boot_device_table;
22 const unsigned int *boot_device_count;
23 int (*boot_device_is_usb)(u32 pinmon);
24 unsigned int (*boot_device_fixup)(unsigned int mode);
Masahiro Yamadaaf198102017-04-20 16:54:43 +090025 int have_internal_stm;
Masahiro Yamadafb092032017-02-14 01:24:26 +090026};
27
28static const struct uniphier_boot_device_info uniphier_boot_device_info[] = {
Masahiro Yamadafb092032017-02-14 01:24:26 +090029#if defined(CONFIG_ARCH_UNIPHIER_LD4)
30 {
31 .soc_id = UNIPHIER_LD4_ID,
32 .boot_device_sel_shift = 1,
33 .boot_device_table = uniphier_ld4_boot_device_table,
34 .boot_device_count = &uniphier_ld4_boot_device_count,
Masahiro Yamadaaf198102017-04-20 16:54:43 +090035 .have_internal_stm = 1,
Masahiro Yamadafb092032017-02-14 01:24:26 +090036 },
37#endif
38#if defined(CONFIG_ARCH_UNIPHIER_PRO4)
39 {
40 .soc_id = UNIPHIER_PRO4_ID,
41 .boot_device_sel_shift = 1,
42 .boot_device_table = uniphier_ld4_boot_device_table,
43 .boot_device_count = &uniphier_ld4_boot_device_count,
Masahiro Yamadaaf198102017-04-20 16:54:43 +090044 .have_internal_stm = 0,
Masahiro Yamadafb092032017-02-14 01:24:26 +090045 },
46#endif
47#if defined(CONFIG_ARCH_UNIPHIER_SLD8)
48 {
49 .soc_id = UNIPHIER_SLD8_ID,
50 .boot_device_sel_shift = 1,
51 .boot_device_table = uniphier_ld4_boot_device_table,
52 .boot_device_count = &uniphier_ld4_boot_device_count,
Masahiro Yamadaaf198102017-04-20 16:54:43 +090053 .have_internal_stm = 1,
Masahiro Yamadafb092032017-02-14 01:24:26 +090054 },
55#endif
56#if defined(CONFIG_ARCH_UNIPHIER_PRO5)
57 {
58 .soc_id = UNIPHIER_PRO5_ID,
59 .boot_device_sel_shift = 1,
60 .boot_device_table = uniphier_pro5_boot_device_table,
61 .boot_device_count = &uniphier_pro5_boot_device_count,
Masahiro Yamadaaf198102017-04-20 16:54:43 +090062 .have_internal_stm = 0,
Masahiro Yamadafb092032017-02-14 01:24:26 +090063 },
64#endif
65#if defined(CONFIG_ARCH_UNIPHIER_PXS2)
66 {
67 .soc_id = UNIPHIER_PXS2_ID,
68 .boot_device_sel_shift = 1,
69 .boot_device_table = uniphier_pxs2_boot_device_table,
70 .boot_device_count = &uniphier_pxs2_boot_device_count,
71 .boot_device_is_usb = uniphier_pxs2_boot_device_is_usb,
72 .boot_device_fixup = uniphier_pxs2_boot_device_fixup,
Masahiro Yamadaaf198102017-04-20 16:54:43 +090073 .have_internal_stm = 0,
Masahiro Yamadafb092032017-02-14 01:24:26 +090074 },
75#endif
76#if defined(CONFIG_ARCH_UNIPHIER_LD6B)
77 {
78 .soc_id = UNIPHIER_LD6B_ID,
79 .boot_device_sel_shift = 1,
80 .boot_device_table = uniphier_pxs2_boot_device_table,
81 .boot_device_count = &uniphier_pxs2_boot_device_count,
82 .boot_device_is_usb = uniphier_pxs2_boot_device_is_usb,
83 .boot_device_fixup = uniphier_pxs2_boot_device_fixup,
Masahiro Yamadaaf198102017-04-20 16:54:43 +090084 .have_internal_stm = 1, /* STM on A-chip */
Masahiro Yamadafb092032017-02-14 01:24:26 +090085 },
86#endif
87#if defined(CONFIG_ARCH_UNIPHIER_LD11)
88 {
89 .soc_id = UNIPHIER_LD11_ID,
90 .boot_device_sel_shift = 1,
91 .boot_device_table = uniphier_ld11_boot_device_table,
92 .boot_device_count = &uniphier_ld11_boot_device_count,
93 .boot_device_is_usb = uniphier_ld11_boot_device_is_usb,
94 .boot_device_fixup = uniphier_ld11_boot_device_fixup,
Masahiro Yamadaaf198102017-04-20 16:54:43 +090095 .have_internal_stm = 1,
Masahiro Yamadafb092032017-02-14 01:24:26 +090096 },
97#endif
98#if defined(CONFIG_ARCH_UNIPHIER_LD20)
99 {
100 .soc_id = UNIPHIER_LD20_ID,
101 .boot_device_sel_shift = 1,
102 .boot_device_table = uniphier_ld11_boot_device_table,
103 .boot_device_count = &uniphier_ld11_boot_device_count,
104 .boot_device_is_usb = uniphier_ld20_boot_device_is_usb,
105 .boot_device_fixup = uniphier_ld11_boot_device_fixup,
Masahiro Yamadaaf198102017-04-20 16:54:43 +0900106 .have_internal_stm = 1,
Masahiro Yamadafb092032017-02-14 01:24:26 +0900107 },
108#endif
Masahiro Yamada8e0a4502017-05-15 14:26:33 +0900109#if defined(CONFIG_ARCH_UNIPHIER_PXS3)
110 {
111 .soc_id = UNIPHIER_PXS3_ID,
112 .boot_device_sel_shift = 1,
113 .boot_device_table = uniphier_pxs3_boot_device_table,
114 .boot_device_count = &uniphier_pxs3_boot_device_count,
115 .boot_device_is_usb = uniphier_pxs3_boot_device_is_usb,
116 .have_internal_stm = 0,
117 },
118#endif
Masahiro Yamadafb092032017-02-14 01:24:26 +0900119};
120UNIPHIER_DEFINE_SOCDATA_FUNC(uniphier_get_boot_device_info,
121 uniphier_boot_device_info)
122
123static unsigned int __uniphier_boot_device_raw(
124 const struct uniphier_boot_device_info *info)
125{
126 u32 pinmon;
127 unsigned int boot_sel;
128
129 if (boot_is_swapped())
130 return BOOT_DEVICE_NOR;
131
132 pinmon = readl(SG_PINMON0);
133
134 if (info->boot_device_is_usb && info->boot_device_is_usb(pinmon))
135 return BOOT_DEVICE_USB;
136
137 boot_sel = pinmon >> info->boot_device_sel_shift;
138
139 BUG_ON(!is_power_of_2(*info->boot_device_count));
140 boot_sel &= *info->boot_device_count - 1;
141
142 return info->boot_device_table[boot_sel].boot_device;
143}
144
145unsigned int uniphier_boot_device_raw(void)
146{
147 const struct uniphier_boot_device_info *info;
148
149 info = uniphier_get_boot_device_info();
150 if (!info) {
151 pr_err("unsupported SoC\n");
152 return BOOT_DEVICE_NONE;
153 }
154
155 return __uniphier_boot_device_raw(info);
156}
157
158u32 spl_boot_device(void)
159{
160 const struct uniphier_boot_device_info *info;
161 u32 raw_mode;
162
163 info = uniphier_get_boot_device_info();
164 if (!info) {
165 pr_err("unsupported SoC\n");
166 return BOOT_DEVICE_NONE;
167 }
168
169 raw_mode = __uniphier_boot_device_raw(info);
170
171 return info->boot_device_fixup ?
172 info->boot_device_fixup(raw_mode) : raw_mode;
173}
174
Masahiro Yamadaaf198102017-04-20 16:54:43 +0900175int uniphier_have_internal_stm(void)
176{
177 const struct uniphier_boot_device_info *info;
178
179 info = uniphier_get_boot_device_info();
180 if (!info) {
181 pr_err("unsupported SoC\n");
182 return -ENOTSUPP;
183 }
184
185 return info->have_internal_stm;
186}
187
188int uniphier_boot_from_backend(void)
189{
190 return !!(readl(SG_PINMON0) & BIT(27));
191}
192
Masahiro Yamadafb092032017-02-14 01:24:26 +0900193#ifndef CONFIG_SPL_BUILD
194
195static int do_pinmon(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
196{
197 const struct uniphier_boot_device_info *info;
198 u32 pinmon;
199 unsigned int boot_device_count, boot_sel;
200 int i;
201
202 info = uniphier_get_boot_device_info();
203 if (!info) {
204 pr_err("unsupported SoC\n");
205 return CMD_RET_FAILURE;
206 }
207
Masahiro Yamadaaf198102017-04-20 16:54:43 +0900208 if (uniphier_have_internal_stm())
209 printf("STB Micon: %s\n",
210 uniphier_boot_from_backend() ? "OFF" : "ON");
211
212 printf("Boot Swap: %s\n", boot_is_swapped() ? "ON" : "OFF");
Masahiro Yamadafb092032017-02-14 01:24:26 +0900213
214 pinmon = readl(SG_PINMON0);
215
216 if (info->boot_device_is_usb)
Masahiro Yamadaaf198102017-04-20 16:54:43 +0900217 printf("USB Boot: %s\n",
Masahiro Yamadafb092032017-02-14 01:24:26 +0900218 info->boot_device_is_usb(pinmon) ? "ON" : "OFF");
219
220 boot_device_count = *info->boot_device_count;
221
222 boot_sel = pinmon >> info->boot_device_sel_shift;
223 boot_sel &= boot_device_count - 1;
224
Masahiro Yamadaaf198102017-04-20 16:54:43 +0900225 printf("\nBoot Mode Sel:\n");
Masahiro Yamadafb092032017-02-14 01:24:26 +0900226 for (i = 0; i < boot_device_count; i++)
227 printf(" %c %02x %s\n", i == boot_sel ? '*' : ' ', i,
228 info->boot_device_table[i].desc);
229
230 return CMD_RET_SUCCESS;
231}
232
233U_BOOT_CMD(
234 pinmon, 1, 1, do_pinmon,
235 "pin monitor",
236 ""
237);
238
239#endif /* !CONFIG_SPL_BUILD */