2 * Copyright (C) 2015-2017 Socionext Inc.
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <linux/log2.h>
13 #include "../sbc/sbc-regs.h"
14 #include "../sg-regs.h"
15 #include "../soc-info.h"
16 #include "boot-device.h"
18 struct uniphier_boot_device_info {
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);
25 int have_internal_stm;
28 static const struct uniphier_boot_device_info uniphier_boot_device_info[] = {
29 #if defined(CONFIG_ARCH_UNIPHIER_SLD3)
31 .soc_id = UNIPHIER_SLD3_ID,
32 .boot_device_sel_shift = 0,
33 .boot_device_table = uniphier_sld3_boot_device_table,
34 .boot_device_count = &uniphier_sld3_boot_device_count,
35 .have_internal_stm = 0,
38 #if defined(CONFIG_ARCH_UNIPHIER_LD4)
40 .soc_id = UNIPHIER_LD4_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,
44 .have_internal_stm = 1,
47 #if defined(CONFIG_ARCH_UNIPHIER_PRO4)
49 .soc_id = UNIPHIER_PRO4_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,
53 .have_internal_stm = 0,
56 #if defined(CONFIG_ARCH_UNIPHIER_SLD8)
58 .soc_id = UNIPHIER_SLD8_ID,
59 .boot_device_sel_shift = 1,
60 .boot_device_table = uniphier_ld4_boot_device_table,
61 .boot_device_count = &uniphier_ld4_boot_device_count,
62 .have_internal_stm = 1,
65 #if defined(CONFIG_ARCH_UNIPHIER_PRO5)
67 .soc_id = UNIPHIER_PRO5_ID,
68 .boot_device_sel_shift = 1,
69 .boot_device_table = uniphier_pro5_boot_device_table,
70 .boot_device_count = &uniphier_pro5_boot_device_count,
71 .have_internal_stm = 0,
74 #if defined(CONFIG_ARCH_UNIPHIER_PXS2)
76 .soc_id = UNIPHIER_PXS2_ID,
77 .boot_device_sel_shift = 1,
78 .boot_device_table = uniphier_pxs2_boot_device_table,
79 .boot_device_count = &uniphier_pxs2_boot_device_count,
80 .boot_device_is_usb = uniphier_pxs2_boot_device_is_usb,
81 .boot_device_fixup = uniphier_pxs2_boot_device_fixup,
82 .have_internal_stm = 0,
85 #if defined(CONFIG_ARCH_UNIPHIER_LD6B)
87 .soc_id = UNIPHIER_LD6B_ID,
88 .boot_device_sel_shift = 1,
89 .boot_device_table = uniphier_pxs2_boot_device_table,
90 .boot_device_count = &uniphier_pxs2_boot_device_count,
91 .boot_device_is_usb = uniphier_pxs2_boot_device_is_usb,
92 .boot_device_fixup = uniphier_pxs2_boot_device_fixup,
93 .have_internal_stm = 1, /* STM on A-chip */
96 #if defined(CONFIG_ARCH_UNIPHIER_LD11)
98 .soc_id = UNIPHIER_LD11_ID,
99 .boot_device_sel_shift = 1,
100 .boot_device_table = uniphier_ld11_boot_device_table,
101 .boot_device_count = &uniphier_ld11_boot_device_count,
102 .boot_device_is_usb = uniphier_ld11_boot_device_is_usb,
103 .boot_device_fixup = uniphier_ld11_boot_device_fixup,
104 .have_internal_stm = 1,
107 #if defined(CONFIG_ARCH_UNIPHIER_LD20)
109 .soc_id = UNIPHIER_LD20_ID,
110 .boot_device_sel_shift = 1,
111 .boot_device_table = uniphier_ld11_boot_device_table,
112 .boot_device_count = &uniphier_ld11_boot_device_count,
113 .boot_device_is_usb = uniphier_ld20_boot_device_is_usb,
114 .boot_device_fixup = uniphier_ld11_boot_device_fixup,
115 .have_internal_stm = 1,
118 #if defined(CONFIG_ARCH_UNIPHIER_PXS3)
120 .soc_id = UNIPHIER_PXS3_ID,
121 .boot_device_sel_shift = 1,
122 .boot_device_table = uniphier_pxs3_boot_device_table,
123 .boot_device_count = &uniphier_pxs3_boot_device_count,
124 .boot_device_is_usb = uniphier_pxs3_boot_device_is_usb,
125 .have_internal_stm = 0,
129 UNIPHIER_DEFINE_SOCDATA_FUNC(uniphier_get_boot_device_info,
130 uniphier_boot_device_info)
132 static unsigned int __uniphier_boot_device_raw(
133 const struct uniphier_boot_device_info *info)
136 unsigned int boot_sel;
138 if (boot_is_swapped())
139 return BOOT_DEVICE_NOR;
141 pinmon = readl(SG_PINMON0);
143 if (info->boot_device_is_usb && info->boot_device_is_usb(pinmon))
144 return BOOT_DEVICE_USB;
146 boot_sel = pinmon >> info->boot_device_sel_shift;
148 BUG_ON(!is_power_of_2(*info->boot_device_count));
149 boot_sel &= *info->boot_device_count - 1;
151 return info->boot_device_table[boot_sel].boot_device;
154 unsigned int uniphier_boot_device_raw(void)
156 const struct uniphier_boot_device_info *info;
158 info = uniphier_get_boot_device_info();
160 pr_err("unsupported SoC\n");
161 return BOOT_DEVICE_NONE;
164 return __uniphier_boot_device_raw(info);
167 u32 spl_boot_device(void)
169 const struct uniphier_boot_device_info *info;
172 info = uniphier_get_boot_device_info();
174 pr_err("unsupported SoC\n");
175 return BOOT_DEVICE_NONE;
178 raw_mode = __uniphier_boot_device_raw(info);
180 return info->boot_device_fixup ?
181 info->boot_device_fixup(raw_mode) : raw_mode;
184 int uniphier_have_internal_stm(void)
186 const struct uniphier_boot_device_info *info;
188 info = uniphier_get_boot_device_info();
190 pr_err("unsupported SoC\n");
194 return info->have_internal_stm;
197 int uniphier_boot_from_backend(void)
199 return !!(readl(SG_PINMON0) & BIT(27));
202 #ifndef CONFIG_SPL_BUILD
204 static int do_pinmon(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
206 const struct uniphier_boot_device_info *info;
208 unsigned int boot_device_count, boot_sel;
211 info = uniphier_get_boot_device_info();
213 pr_err("unsupported SoC\n");
214 return CMD_RET_FAILURE;
217 if (uniphier_have_internal_stm())
218 printf("STB Micon: %s\n",
219 uniphier_boot_from_backend() ? "OFF" : "ON");
221 printf("Boot Swap: %s\n", boot_is_swapped() ? "ON" : "OFF");
223 pinmon = readl(SG_PINMON0);
225 if (info->boot_device_is_usb)
226 printf("USB Boot: %s\n",
227 info->boot_device_is_usb(pinmon) ? "ON" : "OFF");
229 boot_device_count = *info->boot_device_count;
231 boot_sel = pinmon >> info->boot_device_sel_shift;
232 boot_sel &= boot_device_count - 1;
234 printf("\nBoot Mode Sel:\n");
235 for (i = 0; i < boot_device_count; i++)
236 printf(" %c %02x %s\n", i == boot_sel ? '*' : ' ', i,
237 info->boot_device_table[i].desc);
239 return CMD_RET_SUCCESS;
243 pinmon, 1, 1, do_pinmon,
248 #endif /* !CONFIG_SPL_BUILD */