1
2
3
4
5
6#include <common.h>
7#include <spl.h>
8#include <asm/io.h>
9#include <asm/arch/cpu.h>
10#include <asm/arch/soc.h>
11
12#include "seq_exec.h"
13#include "sys_env_lib.h"
14
15#ifdef CONFIG_ARMADA_38X
16enum unit_id sys_env_soc_unit_nums[MAX_UNITS_ID][MAX_DEV_ID_NUM] = {
17
18 { 4, 3, 3, 4},
19 { 3, 2, 3, 3},
20 { 2, 2, 2, 2},
21 { 1, 1, 1, 1},
22 { 2, 2, 2, 4},
23 { 1, 0, 0, 1},
24 { 0, 0, 0, 0},
25 { 0, 0, 0, 0}
26};
27#else
28enum unit_id sys_env_soc_unit_nums[MAX_UNITS_ID][MAX_DEV_ID_NUM] = {
29
30 { 4, 4},
31 { 3, 4},
32 { 1, 2},
33 { 0, 1},
34 { 0, 4},
35 { 0, 1},
36 { 1, 1},
37 { 1, 1}
38};
39#endif
40
41u32 g_dev_id = -1;
42
43u32 mv_board_id_get(void)
44{
45#if defined(CONFIG_TARGET_DB_88F6820_GP)
46 return DB_GP_68XX_ID;
47#else
48
49
50
51
52 return 0;
53#endif
54}
55
56u32 mv_board_tclk_get(void)
57{
58 u32 value;
59
60 value = (reg_read(DEVICE_SAMPLE_AT_RESET1_REG) >> 15) & 0x1;
61
62 switch (value) {
63 case (0x0):
64 return 250000000;
65 case (0x1):
66 return 200000000;
67 default:
68 return 0xffffffff;
69 }
70}
71
72u32 mv_board_id_index_get(u32 board_id)
73{
74
75
76
77
78 return board_id & (MARVELL_BOARD_ID_MASK - 1);
79}
80
81
82
83
84
85
86
87
88
89
90
91enum suspend_wakeup_status sys_env_suspend_wakeup_check(void)
92{
93 u32 reg, board_id_index, gpio;
94 struct board_wakeup_gpio board_gpio[] = MV_BOARD_WAKEUP_GPIO_INFO;
95
96 board_id_index = mv_board_id_index_get(mv_board_id_get());
97 if (!(sizeof(board_gpio) / sizeof(struct board_wakeup_gpio) >
98 board_id_index)) {
99 printf("\n_failed loading Suspend-Wakeup information (invalid board ID)\n");
100 return SUSPEND_WAKEUP_DISABLED;
101 }
102
103
104
105
106
107 if (board_gpio[board_id_index].gpio_num == -1) {
108
109 return SUSPEND_WAKEUP_DISABLED;
110 } else if (board_gpio[board_id_index].gpio_num == -2) {
111
112
113
114
115 return SUSPEND_WAKEUP_ENABLED;
116 } else {
117 gpio = board_gpio[board_id_index].gpio_num;
118 }
119
120
121 reg = reg_read(MPP_CONTROL_REG(MPP_REG_NUM(gpio)));
122
123 reg &= ~MPP_MASK(gpio);
124 reg_write(MPP_CONTROL_REG(MPP_REG_NUM(gpio)), reg);
125
126
127 reg = reg_read(GPP_DATA_OUT_EN_REG(GPP_REG_NUM(gpio)));
128 reg |= GPP_MASK(gpio);
129 reg_write(GPP_DATA_OUT_EN_REG(GPP_REG_NUM(gpio)), reg);
130
131
132
133
134
135 reg = reg_read(GPP_DATA_IN_REG(GPP_REG_NUM(gpio)));
136
137
138 return (reg & GPP_MASK(gpio)) ? SUSPEND_WAKEUP_ENABLED_GPIO_DETECTED :
139 SUSPEND_WAKEUP_DISABLED;
140}
141
142
143
144
145
146
147
148
149
150
151u32 sys_env_id_index_get(u32 ctrl_model)
152{
153 switch (ctrl_model) {
154 case MV_6820_DEV_ID:
155 return MV_6820_INDEX;
156 case MV_6810_DEV_ID:
157 return MV_6810_INDEX;
158 case MV_6811_DEV_ID:
159 return MV_6811_INDEX;
160 case MV_6828_DEV_ID:
161 return MV_6828_INDEX;
162 case MV_6920_DEV_ID:
163 return MV_6920_INDEX;
164 case MV_6928_DEV_ID:
165 return MV_6928_INDEX;
166 default:
167 return MV_6820_INDEX;
168 }
169}
170
171u32 sys_env_unit_max_num_get(enum unit_id unit)
172{
173 u32 dev_id_index;
174
175 if (unit >= MAX_UNITS_ID) {
176 printf("%s: Error: Wrong unit type (%u)\n", __func__, unit);
177 return 0;
178 }
179
180 dev_id_index = sys_env_id_index_get(sys_env_model_get());
181 return sys_env_soc_unit_nums[unit][dev_id_index];
182}
183
184
185
186
187
188
189u16 sys_env_model_get(void)
190{
191 u32 default_ctrl_id, ctrl_id = reg_read(DEV_ID_REG);
192 ctrl_id = (ctrl_id & (DEV_ID_REG_DEVICE_ID_MASK)) >>
193 DEV_ID_REG_DEVICE_ID_OFFS;
194
195 switch (ctrl_id) {
196 case MV_6820_DEV_ID:
197 case MV_6810_DEV_ID:
198 case MV_6811_DEV_ID:
199 case MV_6828_DEV_ID:
200 case MV_6920_DEV_ID:
201 case MV_6928_DEV_ID:
202 return ctrl_id;
203 default:
204
205 #ifdef CONFIG_ARMADA_38X
206 default_ctrl_id = MV_6820_DEV_ID;
207 #else
208 default_ctrl_id = MV_6920_DEV_ID;
209 #endif
210 printf("%s: Error retrieving device ID (%x), using default ID = %x\n",
211 __func__, ctrl_id, default_ctrl_id);
212 return default_ctrl_id;
213 }
214}
215
216
217
218
219
220u32 sys_env_device_id_get(void)
221{
222 char *device_id_str[7] = {
223 "6810", "6820", "6811", "6828", "NONE", "6920", "6928"
224 };
225
226 if (g_dev_id != -1)
227 return g_dev_id;
228
229 g_dev_id = reg_read(DEVICE_SAMPLE_AT_RESET1_REG);
230 g_dev_id = g_dev_id >> SAR_DEV_ID_OFFS & SAR_DEV_ID_MASK;
231 printf("Detected Device ID %s\n", device_id_str[g_dev_id]);
232
233 return g_dev_id;
234}
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252u8 sys_env_device_rev_get(void)
253{
254 u32 value;
255
256 value = reg_read(DEV_VERSION_ID_REG);
257 return (value & (REVISON_ID_MASK)) >> REVISON_ID_OFFS;
258}
259