]> Git Repo - J-u-boot.git/blob - arch/arm/mach-uniphier/boot-device/boot-device.c
ARM: uniphier: use bool type for have_internal_stm parameter
[J-u-boot.git] / arch / arm / mach-uniphier / boot-device / boot-device.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2015-2017 Socionext Inc.
4  *   Author: Masahiro Yamada <[email protected]>
5  */
6
7 #include <common.h>
8 #include <spl.h>
9 #include <stdio.h>
10 #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
18 struct 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);
25         bool have_internal_stm;
26 };
27
28 static const struct uniphier_boot_device_info uniphier_boot_device_info[] = {
29 #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,
35                 .have_internal_stm = true,
36         },
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,
44                 .have_internal_stm = false,
45         },
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,
53                 .have_internal_stm = true,
54         },
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,
62                 .have_internal_stm = false,
63         },
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,
73                 .have_internal_stm = false,
74         },
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,
84                 .have_internal_stm = true,      /* STM on A-chip */
85         },
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                 .have_internal_stm = true,
95         },
96 #endif
97 #if defined(CONFIG_ARCH_UNIPHIER_LD20)
98         {
99                 .soc_id = UNIPHIER_LD20_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_ld20_boot_device_is_usb,
104                 .have_internal_stm = true,
105         },
106 #endif
107 #if defined(CONFIG_ARCH_UNIPHIER_PXS3)
108         {
109                 .soc_id = UNIPHIER_PXS3_ID,
110                 .boot_device_sel_shift = 1,
111                 .boot_device_table = uniphier_pxs3_boot_device_table,
112                 .boot_device_count = &uniphier_pxs3_boot_device_count,
113                 .boot_device_is_usb = uniphier_pxs3_boot_device_is_usb,
114                 .have_internal_stm = false,
115         },
116 #endif
117 };
118 UNIPHIER_DEFINE_SOCDATA_FUNC(uniphier_get_boot_device_info,
119                              uniphier_boot_device_info)
120
121 static unsigned int __uniphier_boot_device_raw(
122                                 const struct uniphier_boot_device_info *info)
123 {
124         u32 pinmon;
125         unsigned int boot_sel;
126
127         if (boot_is_swapped())
128                 return BOOT_DEVICE_NOR;
129
130         pinmon = readl(SG_PINMON0);
131
132         if (info->boot_device_is_usb && info->boot_device_is_usb(pinmon))
133                 return BOOT_DEVICE_USB;
134
135         boot_sel = pinmon >> info->boot_device_sel_shift;
136
137         BUG_ON(!is_power_of_2(*info->boot_device_count));
138         boot_sel &= *info->boot_device_count - 1;
139
140         return info->boot_device_table[boot_sel].boot_device;
141 }
142
143 unsigned int uniphier_boot_device_raw(void)
144 {
145         const struct uniphier_boot_device_info *info;
146
147         info = uniphier_get_boot_device_info();
148         if (!info) {
149                 pr_err("unsupported SoC\n");
150                 return BOOT_DEVICE_NONE;
151         }
152
153         return __uniphier_boot_device_raw(info);
154 }
155
156 u32 spl_boot_device(void)
157 {
158         const struct uniphier_boot_device_info *info;
159         u32 raw_mode;
160
161         info = uniphier_get_boot_device_info();
162         if (!info) {
163                 pr_err("unsupported SoC\n");
164                 return BOOT_DEVICE_NONE;
165         }
166
167         raw_mode = __uniphier_boot_device_raw(info);
168
169         return info->boot_device_fixup ?
170                                 info->boot_device_fixup(raw_mode) : raw_mode;
171 }
172
173 int uniphier_have_internal_stm(void)
174 {
175         const struct uniphier_boot_device_info *info;
176
177         info = uniphier_get_boot_device_info();
178         if (!info) {
179                 pr_err("unsupported SoC\n");
180                 return -ENOTSUPP;
181         }
182
183         return info->have_internal_stm;
184 }
185
186 int uniphier_boot_from_backend(void)
187 {
188         return !!(readl(SG_PINMON0) & BIT(27));
189 }
190
191 #ifndef CONFIG_SPL_BUILD
192
193 static int do_pinmon(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
194 {
195         const struct uniphier_boot_device_info *info;
196         u32 pinmon;
197         unsigned int boot_device_count, boot_sel;
198         int i;
199
200         info = uniphier_get_boot_device_info();
201         if (!info) {
202                 pr_err("unsupported SoC\n");
203                 return CMD_RET_FAILURE;
204         }
205
206         if (uniphier_have_internal_stm())
207                 printf("STB Micon: %s\n",
208                        uniphier_boot_from_backend() ? "OFF" : "ON");
209
210         printf("Boot Swap: %s\n", boot_is_swapped() ? "ON" : "OFF");
211
212         pinmon = readl(SG_PINMON0);
213
214         if (info->boot_device_is_usb)
215                 printf("USB Boot:  %s\n",
216                        info->boot_device_is_usb(pinmon) ? "ON" : "OFF");
217
218         boot_device_count = *info->boot_device_count;
219
220         boot_sel = pinmon >> info->boot_device_sel_shift;
221         boot_sel &= boot_device_count - 1;
222
223         printf("\nBoot Mode Sel:\n");
224         for (i = 0; i < boot_device_count; i++)
225                 printf(" %c %02x %s\n", i == boot_sel ? '*' : ' ', i,
226                        info->boot_device_table[i].desc);
227
228         return CMD_RET_SUCCESS;
229 }
230
231 U_BOOT_CMD(
232         pinmon, 1,      1,      do_pinmon,
233         "pin monitor",
234         ""
235 );
236
237 #endif /* !CONFIG_SPL_BUILD */
This page took 0.039566 seconds and 4 git commands to generate.