1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2013 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
12 #include <asm/global_data.h>
13 #include <linux/delay.h>
14 #include <samsung/misc.h>
19 #include <linux/sizes.h>
20 #include <asm/arch/cpu.h>
22 #include <linux/input.h>
25 * Use #ifdef to work around conflicting headers while we wait for this to be
26 * converted to driver model.
28 #ifdef CONFIG_DM_PMIC_MAX77686
29 #include <power/max77686_pmic.h>
31 #ifdef CONFIG_DM_PMIC_MAX8998
32 #include <power/max8998_pmic.h>
34 #ifdef CONFIG_PMIC_MAX8997
35 #include <power/max8997_pmic.h>
37 #include <power/pmic.h>
40 DECLARE_GLOBAL_DATA_PTR;
42 #ifdef CONFIG_SET_DFU_ALT_INFO
43 void set_dfu_alt_info(char *interface, char *devstr)
45 size_t buf_size = CONFIG_SET_DFU_ALT_BUF_LEN;
46 ALLOC_CACHE_ALIGN_BUFFER(char, buf, buf_size);
47 char *alt_info = "Settings not found!";
48 char *status = "error!\n";
53 puts("DFU alt info setting: ");
55 alt_setting = get_dfu_alt_boot(interface, devstr);
57 env_set("dfu_alt_boot", alt_setting);
58 offset = snprintf(buf, buf_size, "%s", alt_setting);
61 alt_setting = get_dfu_alt_system(interface, devstr);
68 offset += snprintf(buf + offset, buf_size - offset,
69 "%s%s", alt_sep, alt_setting);
77 env_set("dfu_alt_info", alt_info);
82 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
83 void set_board_info(void)
87 snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev & 0xf0) >> 4,
89 env_set("soc_rev", info);
91 snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id);
92 env_set("soc_id", info);
94 #ifdef CONFIG_REVISION_TAG
95 snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev());
96 env_set("board_rev", info);
98 #ifdef CONFIG_OF_LIBFDT
99 const char *bdtype = "";
100 const char *bdname = CONFIG_SYS_BOARD;
102 #ifdef CONFIG_BOARD_TYPES
103 bdtype = get_board_type();
107 sprintf(info, "%s%s", bdname, bdtype);
108 env_set("board_name", info);
110 snprintf(info, ARRAY_SIZE(info), "%s%x-%s%s.dtb",
111 CONFIG_SYS_SOC, s5p_cpu_id, bdname, bdtype);
112 env_set("fdtfile", info);
115 #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
117 #ifdef CONFIG_LCD_MENU
118 static int power_key_pressed(u32 reg)
125 if (IS_ENABLED(CONFIG_TARGET_TRATS))
126 ret = pmic_get("max8997-pmic", &dev);
127 else if (IS_ENABLED(CONFIG_TARGET_TRATS2))
128 ret = pmic_get("max77686-pmic", &dev);
129 else if (IS_ENABLED(CONFIG_TARGET_S5PC210_UNIVERSAL))
130 ret = pmic_get("max8998-pmic", &dev);
137 if (reg == KEY_PWR_STATUS_REG)
138 mask = KEY_PWR_STATUS_MASK;
140 mask = KEY_PWR_INTERRUPT_MASK;
142 status = pmic_reg_read(dev, reg);
146 return !!(status & mask);
149 static int key_pressed(int key)
155 value = power_key_pressed(KEY_PWR_INTERRUPT_REG);
158 value = !gpio_get_value(KEY_VOL_UP_GPIO);
161 value = !gpio_get_value(KEY_VOL_DOWN_GPIO);
172 static int check_keys(void)
176 if (key_pressed(KEY_POWER))
178 if (key_pressed(KEY_VOLUMEUP))
179 keys += KEY_VOLUMEUP;
180 if (key_pressed(KEY_VOLUMEDOWN))
181 keys += KEY_VOLUMEDOWN;
194 mode_name[BOOT_MODE_EXIT + 1][2] = {
205 mode_info[BOOT_MODE_EXIT + 1] = {
212 "and run normal boot"
216 mode_cmd[BOOT_MODE_EXIT + 1] = {
221 "gpt write mmc 0 $partitions",
222 "env default -a; saveenv",
226 static void display_board_info(void)
229 struct mmc *mmc = find_mmc_device(0);
231 vidinfo_t *vid = &panel_info;
233 lcd_position_cursor(4, 4);
235 lcd_printf("%s\n\t", U_BOOT_VERSION);
236 lcd_puts("\n\t\tBoard Info:\n");
237 #ifdef CONFIG_SYS_BOARD
238 lcd_printf("\tBoard name: %s\n", CONFIG_SYS_BOARD);
240 #ifdef CONFIG_REVISION_TAG
241 lcd_printf("\tBoard rev: %u\n", get_board_rev());
243 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS);
244 lcd_printf("\tDRAM size: %u MB\n", gd->ram_size / SZ_1M);
251 lcd_printf("\teMMC size: %llu MB\n", mmc->capacity / SZ_1M);
255 lcd_printf("\tDisplay resolution: %u x % u\n",
256 vid->vl_col, vid->vl_row);
258 lcd_printf("\tDisplay BPP: %u\n", 1 << vid->vl_bpix);
262 static int mode_leave_menu(int mode)
266 char *exit_reset = "reset";
267 char *exit_back = "back";
278 display_board_info();
279 exit_option = exit_back;
283 cmd = find_cmd(mode_name[mode][1]);
285 printf("Enter: %s %s\n", mode_name[mode][0],
287 lcd_printf("\n\n\t%s %s\n", mode_name[mode][0],
289 lcd_puts("\n\tDo not turn off device before finish!\n");
291 cmd_result = run_command(mode_cmd[mode], 0);
293 if (cmd_result == CMD_RET_SUCCESS) {
294 printf("Command finished\n");
296 lcd_printf("\n\n\t%s finished\n",
299 exit_option = exit_reset;
302 printf("Command error\n");
304 lcd_printf("\n\n\t%s command error\n",
307 exit_option = exit_back;
311 lcd_puts("\n\n\tThis mode is not supported.\n");
312 exit_option = exit_back;
317 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option);
319 /* Clear PWR button Rising edge interrupt status flag */
320 power_key_pressed(KEY_PWR_INTERRUPT_REG);
322 /* Wait for PWR key */
323 while (!key_pressed(KEY_POWER))
334 static void display_download_menu(int mode)
336 char *selection[BOOT_MODE_EXIT + 1];
339 for (i = 0; i <= BOOT_MODE_EXIT; i++)
340 selection[i] = "[ ]";
342 selection[mode] = "[=>]";
345 lcd_printf("\n\n\t\tDownload Mode Menu\n\n");
347 for (i = 0; i <= BOOT_MODE_EXIT; i++)
348 lcd_printf("\t%s %s - %s\n\n", selection[i],
349 mode_name[i][0], mode_info[i]);
353 static void download_menu(void)
360 int timeout = 15; /* sec */
363 display_download_menu(mode);
367 /* Start count if no key is pressed */
372 lcd_printf("\r\tNormal boot will start in: %2.d seconds.",
375 /* about 1000 ms in for loop */
376 for (i = 0; i < 10; i++) {
394 if (mode != last_mode)
395 display_download_menu(mode);
410 if (mode < BOOT_MODE_EXIT)
418 if (mode_leave_menu(mode))
419 run_command("reset", 0);
421 display_download_menu(mode);
429 void check_boot_mode(void)
433 pwr_key = power_key_pressed(KEY_PWR_STATUS_REG);
437 /* Clear PWR button Rising edge interrupt status flag */
438 power_key_pressed(KEY_PWR_INTERRUPT_REG);
440 if (key_pressed(KEY_VOLUMEUP))
442 else if (key_pressed(KEY_VOLUMEDOWN))
443 mode_leave_menu(BOOT_MODE_THOR);
448 /* Set direction to input */
449 gpio_request(KEY_VOL_UP_GPIO, "volume-up");
450 gpio_request(KEY_VOL_DOWN_GPIO, "volume-down");
451 gpio_direction_input(KEY_VOL_UP_GPIO);
452 gpio_direction_input(KEY_VOL_DOWN_GPIO);
454 #endif /* CONFIG_LCD_MENU */
456 #ifdef CONFIG_CMD_BMP
462 addr = panel_info.logo_addr;
464 pr_err("There is no logo data.\n");
468 if (panel_info.vl_width >= panel_info.logo_width) {
469 x = ((panel_info.vl_width - panel_info.logo_width) >> 1);
470 x += panel_info.logo_x_offset; /* For X center align */
473 printf("Warning: image width is bigger than display width\n");
476 if (panel_info.vl_height >= panel_info.logo_height) {
477 y = ((panel_info.vl_height - panel_info.logo_height) >> 1);
478 y += panel_info.logo_y_offset; /* For Y center align */
481 printf("Warning: image height is bigger than display height\n");
484 bmp_display(addr, x, y);
486 #endif /* CONFIG_CMD_BMP */