blob: 9117669f715e70871113792dce7d40964e67535a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Przemyslaw Marczak283a3202014-01-22 11:24:12 +01002/*
3 * Copyright (C) 2013 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
Przemyslaw Marczak283a3202014-01-22 11:24:12 +01005 */
6
7#include <common.h>
Simon Glassadaaa482019-11-14 12:57:43 -07008#include <command.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06009#include <env.h>
Przemyslaw Marczak283a3202014-01-22 11:24:12 +010010#include <lcd.h>
11#include <libtizen.h>
12#include <samsung/misc.h>
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +010013#include <errno.h>
14#include <version.h>
Przemyslaw Marczakfa9566f2014-09-01 13:50:46 +020015#include <malloc.h>
Simon Glass2dd337a2015-09-02 17:24:58 -060016#include <memalign.h>
Alexey Brodkin267d8e22014-02-26 17:47:58 +040017#include <linux/sizes.h>
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +010018#include <asm/arch/cpu.h>
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +010019#include <asm/gpio.h>
20#include <linux/input.h>
Przemyslaw Marczake7781bc2015-05-13 13:38:25 +020021#include <dm.h>
Simon Glass19eb1182017-05-18 20:09:31 -060022/*
23 * Use #ifdef to work around conflicting headers while we wait for this to be
24 * converted to driver model.
25 */
26#ifdef CONFIG_DM_PMIC_MAX77686
27#include <power/max77686_pmic.h>
28#endif
29#ifdef CONFIG_DM_PMIC_MAX8998
30#include <power/max8998_pmic.h>
31#endif
32#ifdef CONFIG_PMIC_MAX8997
33#include <power/max8997_pmic.h>
34#endif
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +010035#include <power/pmic.h>
36#include <mmc.h>
37
38DECLARE_GLOBAL_DATA_PTR;
39
Przemyslaw Marczakfa9566f2014-09-01 13:50:46 +020040#ifdef CONFIG_SET_DFU_ALT_INFO
Przemyslaw Marczakd0dd6092015-02-17 12:24:11 +010041void set_dfu_alt_info(char *interface, char *devstr)
Przemyslaw Marczakfa9566f2014-09-01 13:50:46 +020042{
43 size_t buf_size = CONFIG_SET_DFU_ALT_BUF_LEN;
44 ALLOC_CACHE_ALIGN_BUFFER(char, buf, buf_size);
45 char *alt_info = "Settings not found!";
46 char *status = "error!\n";
47 char *alt_setting;
48 char *alt_sep;
49 int offset = 0;
50
51 puts("DFU alt info setting: ");
52
Przemyslaw Marczakd0dd6092015-02-17 12:24:11 +010053 alt_setting = get_dfu_alt_boot(interface, devstr);
Przemyslaw Marczakfa9566f2014-09-01 13:50:46 +020054 if (alt_setting) {
Simon Glass6a38e412017-08-03 12:22:09 -060055 env_set("dfu_alt_boot", alt_setting);
Przemyslaw Marczakfa9566f2014-09-01 13:50:46 +020056 offset = snprintf(buf, buf_size, "%s", alt_setting);
57 }
58
Przemyslaw Marczakd0dd6092015-02-17 12:24:11 +010059 alt_setting = get_dfu_alt_system(interface, devstr);
Przemyslaw Marczakfa9566f2014-09-01 13:50:46 +020060 if (alt_setting) {
61 if (offset)
62 alt_sep = ";";
63 else
64 alt_sep = "";
65
66 offset += snprintf(buf + offset, buf_size - offset,
67 "%s%s", alt_sep, alt_setting);
68 }
69
70 if (offset) {
71 alt_info = buf;
72 status = "done\n";
73 }
74
Simon Glass6a38e412017-08-03 12:22:09 -060075 env_set("dfu_alt_info", alt_info);
Przemyslaw Marczakfa9566f2014-09-01 13:50:46 +020076 puts(status);
77}
78#endif
79
Piotr Wilczek1b5c7662014-01-22 15:54:32 +010080#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
81void set_board_info(void)
82{
83 char info[64];
84
Przemyslaw Marczakb8b07242014-09-01 13:50:42 +020085 snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev & 0xf0) >> 4,
86 s5p_cpu_rev & 0xf);
Simon Glass6a38e412017-08-03 12:22:09 -060087 env_set("soc_rev", info);
Piotr Wilczek1b5c7662014-01-22 15:54:32 +010088
89 snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id);
Simon Glass6a38e412017-08-03 12:22:09 -060090 env_set("soc_id", info);
Piotr Wilczek1b5c7662014-01-22 15:54:32 +010091
92#ifdef CONFIG_REVISION_TAG
93 snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev());
Simon Glass6a38e412017-08-03 12:22:09 -060094 env_set("board_rev", info);
Piotr Wilczek1b5c7662014-01-22 15:54:32 +010095#endif
96#ifdef CONFIG_OF_LIBFDT
Przemyslaw Marczak2cadc4d2014-09-01 13:50:50 +020097 const char *bdtype = "";
98 const char *bdname = CONFIG_SYS_BOARD;
99
100#ifdef CONFIG_BOARD_TYPES
101 bdtype = get_board_type();
Przemyslaw Marczak5b8bbbf2015-10-27 13:07:54 +0100102 if (!bdtype)
103 bdtype = "";
104
Przemyslaw Marczak2cadc4d2014-09-01 13:50:50 +0200105 sprintf(info, "%s%s", bdname, bdtype);
Krzysztof Kozlowskif4befd42019-02-22 19:36:43 +0100106 env_set("board_name", info);
Przemyslaw Marczak2cadc4d2014-09-01 13:50:50 +0200107#endif
108 snprintf(info, ARRAY_SIZE(info), "%s%x-%s%s.dtb",
109 CONFIG_SYS_SOC, s5p_cpu_id, bdname, bdtype);
Simon Glass6a38e412017-08-03 12:22:09 -0600110 env_set("fdtfile", info);
Piotr Wilczek1b5c7662014-01-22 15:54:32 +0100111#endif
112}
113#endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
114
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100115#ifdef CONFIG_LCD_MENU
116static int power_key_pressed(u32 reg)
117{
Simon Glass7bbb7d92016-11-23 06:34:40 -0700118#ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100119 struct pmic *pmic;
120 u32 status;
121 u32 mask;
122
123 pmic = pmic_get(KEY_PWR_PMIC_NAME);
124 if (!pmic) {
125 printf("%s: Not found\n", KEY_PWR_PMIC_NAME);
126 return 0;
127 }
128
129 if (pmic_probe(pmic))
130 return 0;
131
132 if (reg == KEY_PWR_STATUS_REG)
133 mask = KEY_PWR_STATUS_MASK;
134 else
135 mask = KEY_PWR_INTERRUPT_MASK;
136
137 if (pmic_reg_read(pmic, reg, &status))
138 return 0;
139
140 return !!(status & mask);
Simon Glass7bbb7d92016-11-23 06:34:40 -0700141#else
142 return 0;
143#endif
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100144}
145
146static int key_pressed(int key)
147{
148 int value;
149
150 switch (key) {
151 case KEY_POWER:
152 value = power_key_pressed(KEY_PWR_INTERRUPT_REG);
153 break;
154 case KEY_VOLUMEUP:
155 value = !gpio_get_value(KEY_VOL_UP_GPIO);
156 break;
157 case KEY_VOLUMEDOWN:
158 value = !gpio_get_value(KEY_VOL_DOWN_GPIO);
159 break;
160 default:
161 value = 0;
162 break;
163 }
164
165 return value;
166}
167
Simon Glassa216f722016-02-21 21:08:53 -0700168#ifdef CONFIG_LCD
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100169static int check_keys(void)
170{
171 int keys = 0;
172
173 if (key_pressed(KEY_POWER))
174 keys += KEY_POWER;
175 if (key_pressed(KEY_VOLUMEUP))
176 keys += KEY_VOLUMEUP;
177 if (key_pressed(KEY_VOLUMEDOWN))
178 keys += KEY_VOLUMEDOWN;
179
180 return keys;
181}
182
183/*
184 * 0 BOOT_MODE_INFO
185 * 1 BOOT_MODE_THOR
186 * 2 BOOT_MODE_UMS
187 * 3 BOOT_MODE_DFU
188 * 4 BOOT_MODE_EXIT
189 */
190static char *
Przemyslaw Marczakc099c272014-04-30 13:28:06 +0200191mode_name[BOOT_MODE_EXIT + 1][2] = {
192 {"DEVICE", ""},
193 {"THOR", "thor"},
194 {"UMS", "ums"},
195 {"DFU", "dfu"},
Przemyslaw Marczak713f2232014-04-30 13:28:07 +0200196 {"GPT", "gpt"},
Inha Song88bc5f72014-04-30 13:28:08 +0200197 {"ENV", "env"},
Przemyslaw Marczakc099c272014-04-30 13:28:06 +0200198 {"EXIT", ""},
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100199};
200
201static char *
202mode_info[BOOT_MODE_EXIT + 1] = {
203 "info",
204 "downloader",
205 "mass storage",
206 "firmware update",
Przemyslaw Marczak713f2232014-04-30 13:28:07 +0200207 "restore",
Inha Song88bc5f72014-04-30 13:28:08 +0200208 "default",
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100209 "and run normal boot"
210};
211
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100212static char *
Przemyslaw Marczakc099c272014-04-30 13:28:06 +0200213mode_cmd[BOOT_MODE_EXIT + 1] = {
214 "",
215 "thor 0 mmc 0",
216 "ums 0 mmc 0",
217 "dfu 0 mmc 0",
Przemyslaw Marczak713f2232014-04-30 13:28:07 +0200218 "gpt write mmc 0 $partitions",
Inha Song88bc5f72014-04-30 13:28:08 +0200219 "env default -a; saveenv",
Przemyslaw Marczakc099c272014-04-30 13:28:06 +0200220 "",
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100221};
222
223static void display_board_info(void)
224{
Masahiro Yamada0a780172017-05-09 20:31:39 +0900225#ifdef CONFIG_MMC
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100226 struct mmc *mmc = find_mmc_device(0);
227#endif
228 vidinfo_t *vid = &panel_info;
229
230 lcd_position_cursor(4, 4);
231
232 lcd_printf("%s\n\t", U_BOOT_VERSION);
233 lcd_puts("\n\t\tBoard Info:\n");
234#ifdef CONFIG_SYS_BOARD
235 lcd_printf("\tBoard name: %s\n", CONFIG_SYS_BOARD);
236#endif
237#ifdef CONFIG_REVISION_TAG
238 lcd_printf("\tBoard rev: %u\n", get_board_rev());
239#endif
240 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS);
241 lcd_printf("\tDRAM size: %u MB\n", gd->ram_size / SZ_1M);
242
Masahiro Yamada0a780172017-05-09 20:31:39 +0900243#ifdef CONFIG_MMC
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100244 if (mmc) {
245 if (!mmc->capacity)
246 mmc_init(mmc);
247
248 lcd_printf("\teMMC size: %llu MB\n", mmc->capacity / SZ_1M);
249 }
250#endif
251 if (vid)
252 lcd_printf("\tDisplay resolution: %u x % u\n",
253 vid->vl_col, vid->vl_row);
254
255 lcd_printf("\tDisplay BPP: %u\n", 1 << vid->vl_bpix);
256}
Simon Glassa216f722016-02-21 21:08:53 -0700257#endif
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100258
259static int mode_leave_menu(int mode)
260{
Simon Glassa216f722016-02-21 21:08:53 -0700261#ifdef CONFIG_LCD
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100262 char *exit_option;
Przemyslaw Marczakc099c272014-04-30 13:28:06 +0200263 char *exit_reset = "reset";
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100264 char *exit_back = "back";
265 cmd_tbl_t *cmd;
266 int cmd_result;
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100267 int leave;
268
269 lcd_clear();
270
271 switch (mode) {
272 case BOOT_MODE_EXIT:
273 return 1;
274 case BOOT_MODE_INFO:
275 display_board_info();
276 exit_option = exit_back;
277 leave = 0;
278 break;
279 default:
Przemyslaw Marczakc099c272014-04-30 13:28:06 +0200280 cmd = find_cmd(mode_name[mode][1]);
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100281 if (cmd) {
Przemyslaw Marczakc099c272014-04-30 13:28:06 +0200282 printf("Enter: %s %s\n", mode_name[mode][0],
Minkyu Kang1dcc63d2015-10-23 16:21:20 +0900283 mode_info[mode]);
Przemyslaw Marczakc099c272014-04-30 13:28:06 +0200284 lcd_printf("\n\n\t%s %s\n", mode_name[mode][0],
Minkyu Kang1dcc63d2015-10-23 16:21:20 +0900285 mode_info[mode]);
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100286 lcd_puts("\n\tDo not turn off device before finish!\n");
287
Przemyslaw Marczakc099c272014-04-30 13:28:06 +0200288 cmd_result = run_command(mode_cmd[mode], 0);
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100289
290 if (cmd_result == CMD_RET_SUCCESS) {
291 printf("Command finished\n");
292 lcd_clear();
293 lcd_printf("\n\n\t%s finished\n",
Przemyslaw Marczakc099c272014-04-30 13:28:06 +0200294 mode_name[mode][0]);
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100295
Przemyslaw Marczakc099c272014-04-30 13:28:06 +0200296 exit_option = exit_reset;
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100297 leave = 1;
298 } else {
299 printf("Command error\n");
300 lcd_clear();
301 lcd_printf("\n\n\t%s command error\n",
Przemyslaw Marczakc099c272014-04-30 13:28:06 +0200302 mode_name[mode][0]);
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100303
304 exit_option = exit_back;
305 leave = 0;
306 }
307 } else {
308 lcd_puts("\n\n\tThis mode is not supported.\n");
309 exit_option = exit_back;
310 leave = 0;
311 }
312 }
313
314 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option);
315
316 /* Clear PWR button Rising edge interrupt status flag */
317 power_key_pressed(KEY_PWR_INTERRUPT_REG);
318
319 /* Wait for PWR key */
320 while (!key_pressed(KEY_POWER))
321 mdelay(1);
322
323 lcd_clear();
324 return leave;
Simon Glassa216f722016-02-21 21:08:53 -0700325#else
326 return 0;
327#endif
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100328}
329
Simon Glassa216f722016-02-21 21:08:53 -0700330#ifdef CONFIG_LCD
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100331static void display_download_menu(int mode)
332{
333 char *selection[BOOT_MODE_EXIT + 1];
334 int i;
335
336 for (i = 0; i <= BOOT_MODE_EXIT; i++)
337 selection[i] = "[ ]";
338
339 selection[mode] = "[=>]";
340
341 lcd_clear();
Przemyslaw Marczak6d34c992014-04-30 13:28:10 +0200342 lcd_printf("\n\n\t\tDownload Mode Menu\n\n");
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100343
344 for (i = 0; i <= BOOT_MODE_EXIT; i++)
345 lcd_printf("\t%s %s - %s\n\n", selection[i],
Minkyu Kang1dcc63d2015-10-23 16:21:20 +0900346 mode_name[i][0], mode_info[i]);
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100347}
Simon Glassa216f722016-02-21 21:08:53 -0700348#endif
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100349
350static void download_menu(void)
351{
Simon Glassa216f722016-02-21 21:08:53 -0700352#ifdef CONFIG_LCD
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100353 int mode = 0;
354 int last_mode = 0;
355 int run;
Przemyslaw Marczak6d34c992014-04-30 13:28:10 +0200356 int key = 0;
357 int timeout = 15; /* sec */
358 int i;
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100359
360 display_download_menu(mode);
361
Przemyslaw Marczak6d34c992014-04-30 13:28:10 +0200362 lcd_puts("\n");
363
364 /* Start count if no key is pressed */
365 while (check_keys())
366 continue;
367
368 while (timeout--) {
369 lcd_printf("\r\tNormal boot will start in: %2.d seconds.",
370 timeout);
371
372 /* about 1000 ms in for loop */
373 for (i = 0; i < 10; i++) {
374 mdelay(100);
375 key = check_keys();
376 if (key)
377 break;
378 }
379 if (key)
380 break;
381 }
382
383 if (!key) {
384 lcd_clear();
385 return;
386 }
387
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100388 while (1) {
389 run = 0;
390
391 if (mode != last_mode)
392 display_download_menu(mode);
393
394 last_mode = mode;
Przemyslaw Marczak399e2e92014-04-30 13:28:09 +0200395 mdelay(200);
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100396
397 key = check_keys();
398 switch (key) {
399 case KEY_POWER:
400 run = 1;
401 break;
402 case KEY_VOLUMEUP:
403 if (mode > 0)
404 mode--;
405 break;
406 case KEY_VOLUMEDOWN:
407 if (mode < BOOT_MODE_EXIT)
408 mode++;
409 break;
410 default:
411 break;
412 }
413
414 if (run) {
415 if (mode_leave_menu(mode))
Przemyslaw Marczakc099c272014-04-30 13:28:06 +0200416 run_command("reset", 0);
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100417
418 display_download_menu(mode);
419 }
420 }
421
422 lcd_clear();
Simon Glassa216f722016-02-21 21:08:53 -0700423#endif
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100424}
425
426void check_boot_mode(void)
427{
428 int pwr_key;
429
430 pwr_key = power_key_pressed(KEY_PWR_STATUS_REG);
431 if (!pwr_key)
432 return;
433
434 /* Clear PWR button Rising edge interrupt status flag */
435 power_key_pressed(KEY_PWR_INTERRUPT_REG);
436
437 if (key_pressed(KEY_VOLUMEUP))
Przemyslaw Marczak6d34c992014-04-30 13:28:10 +0200438 download_menu();
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100439 else if (key_pressed(KEY_VOLUMEDOWN))
440 mode_leave_menu(BOOT_MODE_THOR);
441}
442
443void keys_init(void)
444{
445 /* Set direction to input */
Simon Glass4f83d3d2014-10-20 19:48:39 -0600446 gpio_request(KEY_VOL_UP_GPIO, "volume-up");
447 gpio_request(KEY_VOL_DOWN_GPIO, "volume-down");
Przemyslaw Marczaka8da5512014-01-22 11:24:17 +0100448 gpio_direction_input(KEY_VOL_UP_GPIO);
449 gpio_direction_input(KEY_VOL_DOWN_GPIO);
450}
451#endif /* CONFIG_LCD_MENU */
Przemyslaw Marczak283a3202014-01-22 11:24:12 +0100452
453#ifdef CONFIG_CMD_BMP
454void draw_logo(void)
455{
456 int x, y;
457 ulong addr;
458
459 addr = panel_info.logo_addr;
460 if (!addr) {
Seung-Woo Kimca211662018-06-04 16:03:05 +0900461 pr_err("There is no logo data.\n");
Przemyslaw Marczak283a3202014-01-22 11:24:12 +0100462 return;
463 }
464
465 if (panel_info.vl_width >= panel_info.logo_width) {
466 x = ((panel_info.vl_width - panel_info.logo_width) >> 1);
Przemyslaw Marczak02f4a092013-11-29 18:30:43 +0100467 x += panel_info.logo_x_offset; /* For X center align */
Przemyslaw Marczak283a3202014-01-22 11:24:12 +0100468 } else {
469 x = 0;
470 printf("Warning: image width is bigger than display width\n");
471 }
472
473 if (panel_info.vl_height >= panel_info.logo_height) {
474 y = ((panel_info.vl_height - panel_info.logo_height) >> 1);
Przemyslaw Marczak02f4a092013-11-29 18:30:43 +0100475 y += panel_info.logo_y_offset; /* For Y center align */
Przemyslaw Marczak283a3202014-01-22 11:24:12 +0100476 } else {
477 y = 0;
478 printf("Warning: image height is bigger than display height\n");
479 }
480
481 bmp_display(addr, x, y);
482}
483#endif /* CONFIG_CMD_BMP */