blob: 9e5245230a5d37ca549dde860d8fca23fe3d589d [file] [log] [blame]
Przemyslaw Marczak679549d2014-01-22 11:24:12 +01001/*
2 * Copyright (C) 2013 Samsung Electronics
3 * Przemyslaw Marczak <p.marczak@samsung.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <lcd.h>
10#include <libtizen.h>
11#include <samsung/misc.h>
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010012#include <errno.h>
13#include <version.h>
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020014#include <malloc.h>
Alexey Brodkin1ace4022014-02-26 17:47:58 +040015#include <linux/sizes.h>
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010016#include <asm/arch/cpu.h>
17#include <asm/arch/gpio.h>
18#include <asm/gpio.h>
19#include <linux/input.h>
20#include <power/pmic.h>
21#include <mmc.h>
22
23DECLARE_GLOBAL_DATA_PTR;
24
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020025#ifdef CONFIG_SET_DFU_ALT_INFO
26void set_dfu_alt_info(void)
27{
28 size_t buf_size = CONFIG_SET_DFU_ALT_BUF_LEN;
29 ALLOC_CACHE_ALIGN_BUFFER(char, buf, buf_size);
30 char *alt_info = "Settings not found!";
31 char *status = "error!\n";
32 char *alt_setting;
33 char *alt_sep;
34 int offset = 0;
35
36 puts("DFU alt info setting: ");
37
38 alt_setting = get_dfu_alt_boot();
39 if (alt_setting) {
40 setenv("dfu_alt_boot", alt_setting);
41 offset = snprintf(buf, buf_size, "%s", alt_setting);
42 }
43
44 alt_setting = get_dfu_alt_system();
45 if (alt_setting) {
46 if (offset)
47 alt_sep = ";";
48 else
49 alt_sep = "";
50
51 offset += snprintf(buf + offset, buf_size - offset,
52 "%s%s", alt_sep, alt_setting);
53 }
54
55 if (offset) {
56 alt_info = buf;
57 status = "done\n";
58 }
59
60 setenv("dfu_alt_info", alt_info);
61 puts(status);
62}
63#endif
64
Piotr Wilczekeee2fab2014-01-22 15:54:32 +010065#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
66void set_board_info(void)
67{
68 char info[64];
69
Przemyslaw Marczak0dc579f2014-09-01 13:50:42 +020070 snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev & 0xf0) >> 4,
71 s5p_cpu_rev & 0xf);
Piotr Wilczekeee2fab2014-01-22 15:54:32 +010072 setenv("soc_rev", info);
73
74 snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id);
75 setenv("soc_id", info);
76
77#ifdef CONFIG_REVISION_TAG
78 snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev());
79 setenv("board_rev", info);
80#endif
81#ifdef CONFIG_OF_LIBFDT
82 snprintf(info, ARRAY_SIZE(info), "%s%x-%s.dtb",
83 CONFIG_SYS_SOC, s5p_cpu_id, CONFIG_SYS_BOARD);
84 setenv("fdtfile", info);
85#endif
86}
87#endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
88
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010089#ifdef CONFIG_LCD_MENU
90static int power_key_pressed(u32 reg)
91{
92 struct pmic *pmic;
93 u32 status;
94 u32 mask;
95
96 pmic = pmic_get(KEY_PWR_PMIC_NAME);
97 if (!pmic) {
98 printf("%s: Not found\n", KEY_PWR_PMIC_NAME);
99 return 0;
100 }
101
102 if (pmic_probe(pmic))
103 return 0;
104
105 if (reg == KEY_PWR_STATUS_REG)
106 mask = KEY_PWR_STATUS_MASK;
107 else
108 mask = KEY_PWR_INTERRUPT_MASK;
109
110 if (pmic_reg_read(pmic, reg, &status))
111 return 0;
112
113 return !!(status & mask);
114}
115
116static int key_pressed(int key)
117{
118 int value;
119
120 switch (key) {
121 case KEY_POWER:
122 value = power_key_pressed(KEY_PWR_INTERRUPT_REG);
123 break;
124 case KEY_VOLUMEUP:
125 value = !gpio_get_value(KEY_VOL_UP_GPIO);
126 break;
127 case KEY_VOLUMEDOWN:
128 value = !gpio_get_value(KEY_VOL_DOWN_GPIO);
129 break;
130 default:
131 value = 0;
132 break;
133 }
134
135 return value;
136}
137
138static int check_keys(void)
139{
140 int keys = 0;
141
142 if (key_pressed(KEY_POWER))
143 keys += KEY_POWER;
144 if (key_pressed(KEY_VOLUMEUP))
145 keys += KEY_VOLUMEUP;
146 if (key_pressed(KEY_VOLUMEDOWN))
147 keys += KEY_VOLUMEDOWN;
148
149 return keys;
150}
151
152/*
153 * 0 BOOT_MODE_INFO
154 * 1 BOOT_MODE_THOR
155 * 2 BOOT_MODE_UMS
156 * 3 BOOT_MODE_DFU
157 * 4 BOOT_MODE_EXIT
158 */
159static char *
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200160mode_name[BOOT_MODE_EXIT + 1][2] = {
161 {"DEVICE", ""},
162 {"THOR", "thor"},
163 {"UMS", "ums"},
164 {"DFU", "dfu"},
Przemyslaw Marczak5c7b8a32014-04-30 13:28:07 +0200165 {"GPT", "gpt"},
Inha Song0954dd62014-04-30 13:28:08 +0200166 {"ENV", "env"},
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200167 {"EXIT", ""},
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100168};
169
170static char *
171mode_info[BOOT_MODE_EXIT + 1] = {
172 "info",
173 "downloader",
174 "mass storage",
175 "firmware update",
Przemyslaw Marczak5c7b8a32014-04-30 13:28:07 +0200176 "restore",
Inha Song0954dd62014-04-30 13:28:08 +0200177 "default",
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100178 "and run normal boot"
179};
180
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100181static char *
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200182mode_cmd[BOOT_MODE_EXIT + 1] = {
183 "",
184 "thor 0 mmc 0",
185 "ums 0 mmc 0",
186 "dfu 0 mmc 0",
Przemyslaw Marczak5c7b8a32014-04-30 13:28:07 +0200187 "gpt write mmc 0 $partitions",
Inha Song0954dd62014-04-30 13:28:08 +0200188 "env default -a; saveenv",
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200189 "",
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100190};
191
192static void display_board_info(void)
193{
194#ifdef CONFIG_GENERIC_MMC
195 struct mmc *mmc = find_mmc_device(0);
196#endif
197 vidinfo_t *vid = &panel_info;
198
199 lcd_position_cursor(4, 4);
200
201 lcd_printf("%s\n\t", U_BOOT_VERSION);
202 lcd_puts("\n\t\tBoard Info:\n");
203#ifdef CONFIG_SYS_BOARD
204 lcd_printf("\tBoard name: %s\n", CONFIG_SYS_BOARD);
205#endif
206#ifdef CONFIG_REVISION_TAG
207 lcd_printf("\tBoard rev: %u\n", get_board_rev());
208#endif
209 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS);
210 lcd_printf("\tDRAM size: %u MB\n", gd->ram_size / SZ_1M);
211
212#ifdef CONFIG_GENERIC_MMC
213 if (mmc) {
214 if (!mmc->capacity)
215 mmc_init(mmc);
216
217 lcd_printf("\teMMC size: %llu MB\n", mmc->capacity / SZ_1M);
218 }
219#endif
220 if (vid)
221 lcd_printf("\tDisplay resolution: %u x % u\n",
222 vid->vl_col, vid->vl_row);
223
224 lcd_printf("\tDisplay BPP: %u\n", 1 << vid->vl_bpix);
225}
226
227static int mode_leave_menu(int mode)
228{
229 char *exit_option;
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200230 char *exit_reset = "reset";
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100231 char *exit_back = "back";
232 cmd_tbl_t *cmd;
233 int cmd_result;
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100234 int leave;
235
236 lcd_clear();
237
238 switch (mode) {
239 case BOOT_MODE_EXIT:
240 return 1;
241 case BOOT_MODE_INFO:
242 display_board_info();
243 exit_option = exit_back;
244 leave = 0;
245 break;
246 default:
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200247 cmd = find_cmd(mode_name[mode][1]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100248 if (cmd) {
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200249 printf("Enter: %s %s\n", mode_name[mode][0],
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100250 mode_info[mode]);
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200251 lcd_printf("\n\n\t%s %s\n", mode_name[mode][0],
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100252 mode_info[mode]);
253 lcd_puts("\n\tDo not turn off device before finish!\n");
254
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200255 cmd_result = run_command(mode_cmd[mode], 0);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100256
257 if (cmd_result == CMD_RET_SUCCESS) {
258 printf("Command finished\n");
259 lcd_clear();
260 lcd_printf("\n\n\t%s finished\n",
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200261 mode_name[mode][0]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100262
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200263 exit_option = exit_reset;
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100264 leave = 1;
265 } else {
266 printf("Command error\n");
267 lcd_clear();
268 lcd_printf("\n\n\t%s command error\n",
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200269 mode_name[mode][0]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100270
271 exit_option = exit_back;
272 leave = 0;
273 }
274 } else {
275 lcd_puts("\n\n\tThis mode is not supported.\n");
276 exit_option = exit_back;
277 leave = 0;
278 }
279 }
280
281 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option);
282
283 /* Clear PWR button Rising edge interrupt status flag */
284 power_key_pressed(KEY_PWR_INTERRUPT_REG);
285
286 /* Wait for PWR key */
287 while (!key_pressed(KEY_POWER))
288 mdelay(1);
289
290 lcd_clear();
291 return leave;
292}
293
294static void display_download_menu(int mode)
295{
296 char *selection[BOOT_MODE_EXIT + 1];
297 int i;
298
299 for (i = 0; i <= BOOT_MODE_EXIT; i++)
300 selection[i] = "[ ]";
301
302 selection[mode] = "[=>]";
303
304 lcd_clear();
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200305 lcd_printf("\n\n\t\tDownload Mode Menu\n\n");
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100306
307 for (i = 0; i <= BOOT_MODE_EXIT; i++)
308 lcd_printf("\t%s %s - %s\n\n", selection[i],
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200309 mode_name[i][0],
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100310 mode_info[i]);
311}
312
313static void download_menu(void)
314{
315 int mode = 0;
316 int last_mode = 0;
317 int run;
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200318 int key = 0;
319 int timeout = 15; /* sec */
320 int i;
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100321
322 display_download_menu(mode);
323
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200324 lcd_puts("\n");
325
326 /* Start count if no key is pressed */
327 while (check_keys())
328 continue;
329
330 while (timeout--) {
331 lcd_printf("\r\tNormal boot will start in: %2.d seconds.",
332 timeout);
333
334 /* about 1000 ms in for loop */
335 for (i = 0; i < 10; i++) {
336 mdelay(100);
337 key = check_keys();
338 if (key)
339 break;
340 }
341 if (key)
342 break;
343 }
344
345 if (!key) {
346 lcd_clear();
347 return;
348 }
349
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100350 while (1) {
351 run = 0;
352
353 if (mode != last_mode)
354 display_download_menu(mode);
355
356 last_mode = mode;
Przemyslaw Marczakf418a1c2014-04-30 13:28:09 +0200357 mdelay(200);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100358
359 key = check_keys();
360 switch (key) {
361 case KEY_POWER:
362 run = 1;
363 break;
364 case KEY_VOLUMEUP:
365 if (mode > 0)
366 mode--;
367 break;
368 case KEY_VOLUMEDOWN:
369 if (mode < BOOT_MODE_EXIT)
370 mode++;
371 break;
372 default:
373 break;
374 }
375
376 if (run) {
377 if (mode_leave_menu(mode))
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200378 run_command("reset", 0);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100379
380 display_download_menu(mode);
381 }
382 }
383
384 lcd_clear();
385}
386
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100387void check_boot_mode(void)
388{
389 int pwr_key;
390
391 pwr_key = power_key_pressed(KEY_PWR_STATUS_REG);
392 if (!pwr_key)
393 return;
394
395 /* Clear PWR button Rising edge interrupt status flag */
396 power_key_pressed(KEY_PWR_INTERRUPT_REG);
397
398 if (key_pressed(KEY_VOLUMEUP))
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200399 download_menu();
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100400 else if (key_pressed(KEY_VOLUMEDOWN))
401 mode_leave_menu(BOOT_MODE_THOR);
402}
403
404void keys_init(void)
405{
406 /* Set direction to input */
407 gpio_direction_input(KEY_VOL_UP_GPIO);
408 gpio_direction_input(KEY_VOL_DOWN_GPIO);
409}
410#endif /* CONFIG_LCD_MENU */
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100411
412#ifdef CONFIG_CMD_BMP
413void draw_logo(void)
414{
415 int x, y;
416 ulong addr;
417
418 addr = panel_info.logo_addr;
419 if (!addr) {
420 error("There is no logo data.");
421 return;
422 }
423
424 if (panel_info.vl_width >= panel_info.logo_width) {
425 x = ((panel_info.vl_width - panel_info.logo_width) >> 1);
Przemyslaw Marczak903afe12013-11-29 18:30:43 +0100426 x += panel_info.logo_x_offset; /* For X center align */
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100427 } else {
428 x = 0;
429 printf("Warning: image width is bigger than display width\n");
430 }
431
432 if (panel_info.vl_height >= panel_info.logo_height) {
433 y = ((panel_info.vl_height - panel_info.logo_height) >> 1);
Przemyslaw Marczak903afe12013-11-29 18:30:43 +0100434 y += panel_info.logo_y_offset; /* For Y center align */
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100435 } else {
436 y = 0;
437 printf("Warning: image height is bigger than display height\n");
438 }
439
440 bmp_display(addr, x, y);
441}
442#endif /* CONFIG_CMD_BMP */