blob: 05243fc8965989e8ad55fb8700865288ff959278 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Przemyslaw Marczak679549d2014-01-22 11:24:12 +01002/*
3 * Copyright (C) 2013 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
Przemyslaw Marczak679549d2014-01-22 11:24:12 +01005 */
6
7#include <common.h>
8#include <lcd.h>
9#include <libtizen.h>
10#include <samsung/misc.h>
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010011#include <errno.h>
12#include <version.h>
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020013#include <malloc.h>
Simon Glasscf92e052015-09-02 17:24:58 -060014#include <memalign.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>
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010017#include <asm/gpio.h>
18#include <linux/input.h>
Przemyslaw Marczakca2b9332015-05-13 13:38:25 +020019#include <dm.h>
Simon Glassf6e76202017-05-18 20:09:31 -060020/*
21 * Use #ifdef to work around conflicting headers while we wait for this to be
22 * converted to driver model.
23 */
24#ifdef CONFIG_DM_PMIC_MAX77686
25#include <power/max77686_pmic.h>
26#endif
27#ifdef CONFIG_DM_PMIC_MAX8998
28#include <power/max8998_pmic.h>
29#endif
30#ifdef CONFIG_PMIC_MAX8997
31#include <power/max8997_pmic.h>
32#endif
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010033#include <power/pmic.h>
34#include <mmc.h>
35
36DECLARE_GLOBAL_DATA_PTR;
37
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020038#ifdef CONFIG_SET_DFU_ALT_INFO
Przemyslaw Marczak899a5282015-02-17 12:24:11 +010039void set_dfu_alt_info(char *interface, char *devstr)
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020040{
41 size_t buf_size = CONFIG_SET_DFU_ALT_BUF_LEN;
42 ALLOC_CACHE_ALIGN_BUFFER(char, buf, buf_size);
43 char *alt_info = "Settings not found!";
44 char *status = "error!\n";
45 char *alt_setting;
46 char *alt_sep;
47 int offset = 0;
48
49 puts("DFU alt info setting: ");
50
Przemyslaw Marczak899a5282015-02-17 12:24:11 +010051 alt_setting = get_dfu_alt_boot(interface, devstr);
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020052 if (alt_setting) {
Simon Glass382bee52017-08-03 12:22:09 -060053 env_set("dfu_alt_boot", alt_setting);
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020054 offset = snprintf(buf, buf_size, "%s", alt_setting);
55 }
56
Przemyslaw Marczak899a5282015-02-17 12:24:11 +010057 alt_setting = get_dfu_alt_system(interface, devstr);
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020058 if (alt_setting) {
59 if (offset)
60 alt_sep = ";";
61 else
62 alt_sep = "";
63
64 offset += snprintf(buf + offset, buf_size - offset,
65 "%s%s", alt_sep, alt_setting);
66 }
67
68 if (offset) {
69 alt_info = buf;
70 status = "done\n";
71 }
72
Simon Glass382bee52017-08-03 12:22:09 -060073 env_set("dfu_alt_info", alt_info);
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020074 puts(status);
75}
76#endif
77
Piotr Wilczekeee2fab2014-01-22 15:54:32 +010078#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
79void set_board_info(void)
80{
81 char info[64];
82
Przemyslaw Marczak0dc579f2014-09-01 13:50:42 +020083 snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev & 0xf0) >> 4,
84 s5p_cpu_rev & 0xf);
Simon Glass382bee52017-08-03 12:22:09 -060085 env_set("soc_rev", info);
Piotr Wilczekeee2fab2014-01-22 15:54:32 +010086
87 snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id);
Simon Glass382bee52017-08-03 12:22:09 -060088 env_set("soc_id", info);
Piotr Wilczekeee2fab2014-01-22 15:54:32 +010089
90#ifdef CONFIG_REVISION_TAG
91 snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev());
Simon Glass382bee52017-08-03 12:22:09 -060092 env_set("board_rev", info);
Piotr Wilczekeee2fab2014-01-22 15:54:32 +010093#endif
94#ifdef CONFIG_OF_LIBFDT
Przemyslaw Marczakc9c36bf2014-09-01 13:50:50 +020095 const char *bdtype = "";
96 const char *bdname = CONFIG_SYS_BOARD;
97
98#ifdef CONFIG_BOARD_TYPES
99 bdtype = get_board_type();
Przemyslaw Marczakbc3f39e2015-10-27 13:07:54 +0100100 if (!bdtype)
101 bdtype = "";
102
Przemyslaw Marczakc9c36bf2014-09-01 13:50:50 +0200103 sprintf(info, "%s%s", bdname, bdtype);
Simon Glass382bee52017-08-03 12:22:09 -0600104 env_set("boardname", info);
Przemyslaw Marczakc9c36bf2014-09-01 13:50:50 +0200105#endif
106 snprintf(info, ARRAY_SIZE(info), "%s%x-%s%s.dtb",
107 CONFIG_SYS_SOC, s5p_cpu_id, bdname, bdtype);
Simon Glass382bee52017-08-03 12:22:09 -0600108 env_set("fdtfile", info);
Piotr Wilczekeee2fab2014-01-22 15:54:32 +0100109#endif
110}
111#endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
112
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100113#ifdef CONFIG_LCD_MENU
114static int power_key_pressed(u32 reg)
115{
Simon Glassfc47cf92016-11-23 06:34:40 -0700116#ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100117 struct pmic *pmic;
118 u32 status;
119 u32 mask;
120
121 pmic = pmic_get(KEY_PWR_PMIC_NAME);
122 if (!pmic) {
123 printf("%s: Not found\n", KEY_PWR_PMIC_NAME);
124 return 0;
125 }
126
127 if (pmic_probe(pmic))
128 return 0;
129
130 if (reg == KEY_PWR_STATUS_REG)
131 mask = KEY_PWR_STATUS_MASK;
132 else
133 mask = KEY_PWR_INTERRUPT_MASK;
134
135 if (pmic_reg_read(pmic, reg, &status))
136 return 0;
137
138 return !!(status & mask);
Simon Glassfc47cf92016-11-23 06:34:40 -0700139#else
140 return 0;
141#endif
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100142}
143
144static int key_pressed(int key)
145{
146 int value;
147
148 switch (key) {
149 case KEY_POWER:
150 value = power_key_pressed(KEY_PWR_INTERRUPT_REG);
151 break;
152 case KEY_VOLUMEUP:
153 value = !gpio_get_value(KEY_VOL_UP_GPIO);
154 break;
155 case KEY_VOLUMEDOWN:
156 value = !gpio_get_value(KEY_VOL_DOWN_GPIO);
157 break;
158 default:
159 value = 0;
160 break;
161 }
162
163 return value;
164}
165
Simon Glass531a4a62016-02-21 21:08:53 -0700166#ifdef CONFIG_LCD
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100167static int check_keys(void)
168{
169 int keys = 0;
170
171 if (key_pressed(KEY_POWER))
172 keys += KEY_POWER;
173 if (key_pressed(KEY_VOLUMEUP))
174 keys += KEY_VOLUMEUP;
175 if (key_pressed(KEY_VOLUMEDOWN))
176 keys += KEY_VOLUMEDOWN;
177
178 return keys;
179}
180
181/*
182 * 0 BOOT_MODE_INFO
183 * 1 BOOT_MODE_THOR
184 * 2 BOOT_MODE_UMS
185 * 3 BOOT_MODE_DFU
186 * 4 BOOT_MODE_EXIT
187 */
188static char *
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200189mode_name[BOOT_MODE_EXIT + 1][2] = {
190 {"DEVICE", ""},
191 {"THOR", "thor"},
192 {"UMS", "ums"},
193 {"DFU", "dfu"},
Przemyslaw Marczak5c7b8a32014-04-30 13:28:07 +0200194 {"GPT", "gpt"},
Inha Song0954dd62014-04-30 13:28:08 +0200195 {"ENV", "env"},
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200196 {"EXIT", ""},
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100197};
198
199static char *
200mode_info[BOOT_MODE_EXIT + 1] = {
201 "info",
202 "downloader",
203 "mass storage",
204 "firmware update",
Przemyslaw Marczak5c7b8a32014-04-30 13:28:07 +0200205 "restore",
Inha Song0954dd62014-04-30 13:28:08 +0200206 "default",
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100207 "and run normal boot"
208};
209
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100210static char *
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200211mode_cmd[BOOT_MODE_EXIT + 1] = {
212 "",
213 "thor 0 mmc 0",
214 "ums 0 mmc 0",
215 "dfu 0 mmc 0",
Przemyslaw Marczak5c7b8a32014-04-30 13:28:07 +0200216 "gpt write mmc 0 $partitions",
Inha Song0954dd62014-04-30 13:28:08 +0200217 "env default -a; saveenv",
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200218 "",
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100219};
220
221static void display_board_info(void)
222{
Masahiro Yamada4aa2ba32017-05-09 20:31:39 +0900223#ifdef CONFIG_MMC
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100224 struct mmc *mmc = find_mmc_device(0);
225#endif
226 vidinfo_t *vid = &panel_info;
227
228 lcd_position_cursor(4, 4);
229
230 lcd_printf("%s\n\t", U_BOOT_VERSION);
231 lcd_puts("\n\t\tBoard Info:\n");
232#ifdef CONFIG_SYS_BOARD
233 lcd_printf("\tBoard name: %s\n", CONFIG_SYS_BOARD);
234#endif
235#ifdef CONFIG_REVISION_TAG
236 lcd_printf("\tBoard rev: %u\n", get_board_rev());
237#endif
238 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS);
239 lcd_printf("\tDRAM size: %u MB\n", gd->ram_size / SZ_1M);
240
Masahiro Yamada4aa2ba32017-05-09 20:31:39 +0900241#ifdef CONFIG_MMC
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100242 if (mmc) {
243 if (!mmc->capacity)
244 mmc_init(mmc);
245
246 lcd_printf("\teMMC size: %llu MB\n", mmc->capacity / SZ_1M);
247 }
248#endif
249 if (vid)
250 lcd_printf("\tDisplay resolution: %u x % u\n",
251 vid->vl_col, vid->vl_row);
252
253 lcd_printf("\tDisplay BPP: %u\n", 1 << vid->vl_bpix);
254}
Simon Glass531a4a62016-02-21 21:08:53 -0700255#endif
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100256
257static int mode_leave_menu(int mode)
258{
Simon Glass531a4a62016-02-21 21:08:53 -0700259#ifdef CONFIG_LCD
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100260 char *exit_option;
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200261 char *exit_reset = "reset";
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100262 char *exit_back = "back";
263 cmd_tbl_t *cmd;
264 int cmd_result;
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100265 int leave;
266
267 lcd_clear();
268
269 switch (mode) {
270 case BOOT_MODE_EXIT:
271 return 1;
272 case BOOT_MODE_INFO:
273 display_board_info();
274 exit_option = exit_back;
275 leave = 0;
276 break;
277 default:
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200278 cmd = find_cmd(mode_name[mode][1]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100279 if (cmd) {
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200280 printf("Enter: %s %s\n", mode_name[mode][0],
Minkyu Kangde5f9732015-10-23 16:21:20 +0900281 mode_info[mode]);
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200282 lcd_printf("\n\n\t%s %s\n", mode_name[mode][0],
Minkyu Kangde5f9732015-10-23 16:21:20 +0900283 mode_info[mode]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100284 lcd_puts("\n\tDo not turn off device before finish!\n");
285
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200286 cmd_result = run_command(mode_cmd[mode], 0);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100287
288 if (cmd_result == CMD_RET_SUCCESS) {
289 printf("Command finished\n");
290 lcd_clear();
291 lcd_printf("\n\n\t%s finished\n",
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200292 mode_name[mode][0]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100293
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200294 exit_option = exit_reset;
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100295 leave = 1;
296 } else {
297 printf("Command error\n");
298 lcd_clear();
299 lcd_printf("\n\n\t%s command error\n",
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200300 mode_name[mode][0]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100301
302 exit_option = exit_back;
303 leave = 0;
304 }
305 } else {
306 lcd_puts("\n\n\tThis mode is not supported.\n");
307 exit_option = exit_back;
308 leave = 0;
309 }
310 }
311
312 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option);
313
314 /* Clear PWR button Rising edge interrupt status flag */
315 power_key_pressed(KEY_PWR_INTERRUPT_REG);
316
317 /* Wait for PWR key */
318 while (!key_pressed(KEY_POWER))
319 mdelay(1);
320
321 lcd_clear();
322 return leave;
Simon Glass531a4a62016-02-21 21:08:53 -0700323#else
324 return 0;
325#endif
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100326}
327
Simon Glass531a4a62016-02-21 21:08:53 -0700328#ifdef CONFIG_LCD
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100329static void display_download_menu(int mode)
330{
331 char *selection[BOOT_MODE_EXIT + 1];
332 int i;
333
334 for (i = 0; i <= BOOT_MODE_EXIT; i++)
335 selection[i] = "[ ]";
336
337 selection[mode] = "[=>]";
338
339 lcd_clear();
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200340 lcd_printf("\n\n\t\tDownload Mode Menu\n\n");
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100341
342 for (i = 0; i <= BOOT_MODE_EXIT; i++)
343 lcd_printf("\t%s %s - %s\n\n", selection[i],
Minkyu Kangde5f9732015-10-23 16:21:20 +0900344 mode_name[i][0], mode_info[i]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100345}
Simon Glass531a4a62016-02-21 21:08:53 -0700346#endif
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100347
348static void download_menu(void)
349{
Simon Glass531a4a62016-02-21 21:08:53 -0700350#ifdef CONFIG_LCD
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100351 int mode = 0;
352 int last_mode = 0;
353 int run;
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200354 int key = 0;
355 int timeout = 15; /* sec */
356 int i;
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100357
358 display_download_menu(mode);
359
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200360 lcd_puts("\n");
361
362 /* Start count if no key is pressed */
363 while (check_keys())
364 continue;
365
366 while (timeout--) {
367 lcd_printf("\r\tNormal boot will start in: %2.d seconds.",
368 timeout);
369
370 /* about 1000 ms in for loop */
371 for (i = 0; i < 10; i++) {
372 mdelay(100);
373 key = check_keys();
374 if (key)
375 break;
376 }
377 if (key)
378 break;
379 }
380
381 if (!key) {
382 lcd_clear();
383 return;
384 }
385
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100386 while (1) {
387 run = 0;
388
389 if (mode != last_mode)
390 display_download_menu(mode);
391
392 last_mode = mode;
Przemyslaw Marczakf418a1c2014-04-30 13:28:09 +0200393 mdelay(200);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100394
395 key = check_keys();
396 switch (key) {
397 case KEY_POWER:
398 run = 1;
399 break;
400 case KEY_VOLUMEUP:
401 if (mode > 0)
402 mode--;
403 break;
404 case KEY_VOLUMEDOWN:
405 if (mode < BOOT_MODE_EXIT)
406 mode++;
407 break;
408 default:
409 break;
410 }
411
412 if (run) {
413 if (mode_leave_menu(mode))
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200414 run_command("reset", 0);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100415
416 display_download_menu(mode);
417 }
418 }
419
420 lcd_clear();
Simon Glass531a4a62016-02-21 21:08:53 -0700421#endif
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100422}
423
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100424void check_boot_mode(void)
425{
426 int pwr_key;
427
428 pwr_key = power_key_pressed(KEY_PWR_STATUS_REG);
429 if (!pwr_key)
430 return;
431
432 /* Clear PWR button Rising edge interrupt status flag */
433 power_key_pressed(KEY_PWR_INTERRUPT_REG);
434
435 if (key_pressed(KEY_VOLUMEUP))
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200436 download_menu();
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100437 else if (key_pressed(KEY_VOLUMEDOWN))
438 mode_leave_menu(BOOT_MODE_THOR);
439}
440
441void keys_init(void)
442{
443 /* Set direction to input */
Simon Glass7f196102014-10-20 19:48:39 -0600444 gpio_request(KEY_VOL_UP_GPIO, "volume-up");
445 gpio_request(KEY_VOL_DOWN_GPIO, "volume-down");
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100446 gpio_direction_input(KEY_VOL_UP_GPIO);
447 gpio_direction_input(KEY_VOL_DOWN_GPIO);
448}
449#endif /* CONFIG_LCD_MENU */
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100450
451#ifdef CONFIG_CMD_BMP
452void draw_logo(void)
453{
454 int x, y;
455 ulong addr;
456
457 addr = panel_info.logo_addr;
458 if (!addr) {
Seung-Woo Kim5c890b12018-06-04 16:03:05 +0900459 pr_err("There is no logo data.\n");
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100460 return;
461 }
462
463 if (panel_info.vl_width >= panel_info.logo_width) {
464 x = ((panel_info.vl_width - panel_info.logo_width) >> 1);
Przemyslaw Marczak903afe12013-11-29 18:30:43 +0100465 x += panel_info.logo_x_offset; /* For X center align */
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100466 } else {
467 x = 0;
468 printf("Warning: image width is bigger than display width\n");
469 }
470
471 if (panel_info.vl_height >= panel_info.logo_height) {
472 y = ((panel_info.vl_height - panel_info.logo_height) >> 1);
Przemyslaw Marczak903afe12013-11-29 18:30:43 +0100473 y += panel_info.logo_y_offset; /* For Y center align */
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100474 } else {
475 y = 0;
476 printf("Warning: image height is bigger than display height\n");
477 }
478
479 bmp_display(addr, x, y);
480}
481#endif /* CONFIG_CMD_BMP */