]> Git Repo - J-u-boot.git/blame - arch/arm/mach-uniphier/boot-device/boot-device.c
command: Remove the cmd_tbl_t typedef
[J-u-boot.git] / arch / arm / mach-uniphier / boot-device / boot-device.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
784548ef
MY
2/*
3 * Copyright (C) 2015-2017 Socionext Inc.
4 * Author: Masahiro Yamada <[email protected]>
784548ef
MY
5 */
6
7#include <common.h>
09140113 8#include <command.h>
784548ef 9#include <spl.h>
dd74b945 10#include <stdio.h>
b521ea39 11#include <linux/io.h>
784548ef
MY
12#include <linux/log2.h>
13
14#include "../init.h"
15#include "../sbc/sbc-regs.h"
16#include "../sg-regs.h"
17#include "../soc-info.h"
18#include "boot-device.h"
19
20struct uniphier_boot_device_info {
21 unsigned int soc_id;
22 unsigned int boot_device_sel_shift;
23 const struct uniphier_boot_device *boot_device_table;
24 const unsigned int *boot_device_count;
c3d8f1e8 25 int (*boot_device_is_sd)(u32 pinmon);
784548ef
MY
26 int (*boot_device_is_usb)(u32 pinmon);
27 unsigned int (*boot_device_fixup)(unsigned int mode);
539d6e0d 28 int (*boot_is_swapped)(void);
ef866f6f 29 bool have_internal_stm;
784548ef
MY
30};
31
32static const struct uniphier_boot_device_info uniphier_boot_device_info[] = {
784548ef
MY
33#if defined(CONFIG_ARCH_UNIPHIER_LD4)
34 {
35 .soc_id = UNIPHIER_LD4_ID,
36 .boot_device_sel_shift = 1,
37 .boot_device_table = uniphier_ld4_boot_device_table,
38 .boot_device_count = &uniphier_ld4_boot_device_count,
539d6e0d 39 .boot_is_swapped = uniphier_sbc_boot_is_swapped,
ef866f6f 40 .have_internal_stm = true,
784548ef
MY
41 },
42#endif
43#if defined(CONFIG_ARCH_UNIPHIER_PRO4)
44 {
45 .soc_id = UNIPHIER_PRO4_ID,
46 .boot_device_sel_shift = 1,
47 .boot_device_table = uniphier_ld4_boot_device_table,
48 .boot_device_count = &uniphier_ld4_boot_device_count,
539d6e0d 49 .boot_is_swapped = uniphier_sbc_boot_is_swapped,
ef866f6f 50 .have_internal_stm = false,
784548ef
MY
51 },
52#endif
53#if defined(CONFIG_ARCH_UNIPHIER_SLD8)
54 {
55 .soc_id = UNIPHIER_SLD8_ID,
56 .boot_device_sel_shift = 1,
57 .boot_device_table = uniphier_ld4_boot_device_table,
58 .boot_device_count = &uniphier_ld4_boot_device_count,
539d6e0d 59 .boot_is_swapped = uniphier_sbc_boot_is_swapped,
ef866f6f 60 .have_internal_stm = true,
784548ef
MY
61 },
62#endif
63#if defined(CONFIG_ARCH_UNIPHIER_PRO5)
64 {
65 .soc_id = UNIPHIER_PRO5_ID,
66 .boot_device_sel_shift = 1,
67 .boot_device_table = uniphier_pro5_boot_device_table,
68 .boot_device_count = &uniphier_pro5_boot_device_count,
539d6e0d 69 .boot_is_swapped = uniphier_sbc_boot_is_swapped,
ef866f6f 70 .have_internal_stm = false,
784548ef
MY
71 },
72#endif
73#if defined(CONFIG_ARCH_UNIPHIER_PXS2)
74 {
75 .soc_id = UNIPHIER_PXS2_ID,
76 .boot_device_sel_shift = 1,
77 .boot_device_table = uniphier_pxs2_boot_device_table,
78 .boot_device_count = &uniphier_pxs2_boot_device_count,
79 .boot_device_is_usb = uniphier_pxs2_boot_device_is_usb,
80 .boot_device_fixup = uniphier_pxs2_boot_device_fixup,
539d6e0d 81 .boot_is_swapped = uniphier_sbc_boot_is_swapped,
ef866f6f 82 .have_internal_stm = false,
784548ef
MY
83 },
84#endif
85#if defined(CONFIG_ARCH_UNIPHIER_LD6B)
86 {
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,
539d6e0d 93 .boot_is_swapped = uniphier_sbc_boot_is_swapped,
ef866f6f 94 .have_internal_stm = true, /* STM on A-chip */
784548ef
MY
95 },
96#endif
97#if defined(CONFIG_ARCH_UNIPHIER_LD11)
98 {
99 .soc_id = UNIPHIER_LD11_ID,
100 .boot_device_sel_shift = 1,
101 .boot_device_table = uniphier_ld11_boot_device_table,
102 .boot_device_count = &uniphier_ld11_boot_device_count,
103 .boot_device_is_usb = uniphier_ld11_boot_device_is_usb,
539d6e0d 104 .boot_is_swapped = uniphier_sbc_boot_is_swapped,
ef866f6f 105 .have_internal_stm = true,
784548ef
MY
106 },
107#endif
108#if defined(CONFIG_ARCH_UNIPHIER_LD20)
109 {
110 .soc_id = UNIPHIER_LD20_ID,
111 .boot_device_sel_shift = 1,
112 .boot_device_table = uniphier_ld11_boot_device_table,
113 .boot_device_count = &uniphier_ld11_boot_device_count,
114 .boot_device_is_usb = uniphier_ld20_boot_device_is_usb,
539d6e0d 115 .boot_is_swapped = uniphier_sbc_boot_is_swapped,
ef866f6f 116 .have_internal_stm = true,
784548ef
MY
117 },
118#endif
81afa9c9
MY
119#if defined(CONFIG_ARCH_UNIPHIER_PXS3)
120 {
121 .soc_id = UNIPHIER_PXS3_ID,
122 .boot_device_sel_shift = 1,
123 .boot_device_table = uniphier_pxs3_boot_device_table,
124 .boot_device_count = &uniphier_pxs3_boot_device_count,
125 .boot_device_is_usb = uniphier_pxs3_boot_device_is_usb,
539d6e0d 126 .boot_is_swapped = uniphier_sbc_boot_is_swapped,
ef866f6f 127 .have_internal_stm = false,
81afa9c9
MY
128 },
129#endif
784548ef
MY
130};
131UNIPHIER_DEFINE_SOCDATA_FUNC(uniphier_get_boot_device_info,
132 uniphier_boot_device_info)
133
134static unsigned int __uniphier_boot_device_raw(
135 const struct uniphier_boot_device_info *info)
136{
137 u32 pinmon;
138 unsigned int boot_sel;
139
539d6e0d 140 if (info->boot_is_swapped && info->boot_is_swapped())
784548ef
MY
141 return BOOT_DEVICE_NOR;
142
d41b358f 143 pinmon = readl(sg_base + SG_PINMON0);
784548ef 144
c3d8f1e8
MY
145 if (info->boot_device_is_sd && info->boot_device_is_sd(pinmon))
146 return BOOT_DEVICE_MMC2;
147
784548ef
MY
148 if (info->boot_device_is_usb && info->boot_device_is_usb(pinmon))
149 return BOOT_DEVICE_USB;
150
151 boot_sel = pinmon >> info->boot_device_sel_shift;
152
153 BUG_ON(!is_power_of_2(*info->boot_device_count));
154 boot_sel &= *info->boot_device_count - 1;
155
156 return info->boot_device_table[boot_sel].boot_device;
157}
158
159unsigned int uniphier_boot_device_raw(void)
160{
161 const struct uniphier_boot_device_info *info;
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 return __uniphier_boot_device_raw(info);
170}
171
172u32 spl_boot_device(void)
173{
174 const struct uniphier_boot_device_info *info;
175 u32 raw_mode;
176
177 info = uniphier_get_boot_device_info();
178 if (!info) {
179 pr_err("unsupported SoC\n");
180 return BOOT_DEVICE_NONE;
181 }
182
183 raw_mode = __uniphier_boot_device_raw(info);
184
185 return info->boot_device_fixup ?
186 info->boot_device_fixup(raw_mode) : raw_mode;
187}
188
63754842
MY
189int uniphier_have_internal_stm(void)
190{
191 const struct uniphier_boot_device_info *info;
192
193 info = uniphier_get_boot_device_info();
194 if (!info) {
195 pr_err("unsupported SoC\n");
196 return -ENOTSUPP;
197 }
198
199 return info->have_internal_stm;
200}
201
202int uniphier_boot_from_backend(void)
203{
d41b358f 204 return !!(readl(sg_base + SG_PINMON0) & BIT(27));
63754842
MY
205}
206
784548ef
MY
207#ifndef CONFIG_SPL_BUILD
208
09140113
SG
209static int do_pinmon(struct cmd_tbl *cmdtp, int flag, int argc,
210 char *const argv[])
784548ef
MY
211{
212 const struct uniphier_boot_device_info *info;
213 u32 pinmon;
214 unsigned int boot_device_count, boot_sel;
215 int i;
216
217 info = uniphier_get_boot_device_info();
218 if (!info) {
219 pr_err("unsupported SoC\n");
220 return CMD_RET_FAILURE;
221 }
222
63754842
MY
223 if (uniphier_have_internal_stm())
224 printf("STB Micon: %s\n",
225 uniphier_boot_from_backend() ? "OFF" : "ON");
226
539d6e0d
MY
227 if (info->boot_is_swapped)
228 printf("Boot Swap: %s\n",
229 info->boot_is_swapped() ? "ON" : "OFF");
784548ef 230
d41b358f 231 pinmon = readl(sg_base + SG_PINMON0);
784548ef 232
c3d8f1e8
MY
233 if (info->boot_device_is_sd)
234 printf("SD Boot: %s\n",
235 info->boot_device_is_sd(pinmon) ? "ON" : "OFF");
236
784548ef 237 if (info->boot_device_is_usb)
63754842 238 printf("USB Boot: %s\n",
784548ef
MY
239 info->boot_device_is_usb(pinmon) ? "ON" : "OFF");
240
241 boot_device_count = *info->boot_device_count;
242
243 boot_sel = pinmon >> info->boot_device_sel_shift;
244 boot_sel &= boot_device_count - 1;
245
63754842 246 printf("\nBoot Mode Sel:\n");
784548ef
MY
247 for (i = 0; i < boot_device_count; i++)
248 printf(" %c %02x %s\n", i == boot_sel ? '*' : ' ', i,
249 info->boot_device_table[i].desc);
250
251 return CMD_RET_SUCCESS;
252}
253
254U_BOOT_CMD(
255 pinmon, 1, 1, do_pinmon,
256 "pin monitor",
257 ""
258);
259
260#endif /* !CONFIG_SPL_BUILD */
This page took 0.218828 seconds and 4 git commands to generate.