1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2013 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
12 #include <linux/delay.h>
13 #include <samsung/misc.h>
18 #include <linux/sizes.h>
19 #include <asm/arch/cpu.h>
21 #include <linux/input.h>
24 * Use #ifdef to work around conflicting headers while we wait for this to be
25 * converted to driver model.
27 #ifdef CONFIG_DM_PMIC_MAX77686
28 #include <power/max77686_pmic.h>
30 #ifdef CONFIG_DM_PMIC_MAX8998
31 #include <power/max8998_pmic.h>
33 #ifdef CONFIG_PMIC_MAX8997
34 #include <power/max8997_pmic.h>
36 #include <power/pmic.h>
39 DECLARE_GLOBAL_DATA_PTR;
41 #ifdef CONFIG_SET_DFU_ALT_INFO
42 void set_dfu_alt_info(char *interface, char *devstr)
44 size_t buf_size = CONFIG_SET_DFU_ALT_BUF_LEN;
45 ALLOC_CACHE_ALIGN_BUFFER(char, buf, buf_size);
46 char *alt_info = "Settings not found!";
47 char *status = "error!\n";
52 puts("DFU alt info setting: ");
54 alt_setting = get_dfu_alt_boot(interface, devstr);
56 env_set("dfu_alt_boot", alt_setting);
57 offset = snprintf(buf, buf_size, "%s", alt_setting);
60 alt_setting = get_dfu_alt_system(interface, devstr);
67 offset += snprintf(buf + offset, buf_size - offset,
68 "%s%s", alt_sep, alt_setting);
76 env_set("dfu_alt_info", alt_info);
81 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
82 void set_board_info(void)
86 snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev & 0xf0) >> 4,
88 env_set("soc_rev", info);
90 snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id);
91 env_set("soc_id", info);
93 #ifdef CONFIG_REVISION_TAG
94 snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev());
95 env_set("board_rev", info);
97 #ifdef CONFIG_OF_LIBFDT
98 const char *bdtype = "";
99 const char *bdname = CONFIG_SYS_BOARD;
101 #ifdef CONFIG_BOARD_TYPES
102 bdtype = get_board_type();
106 sprintf(info, "%s%s", bdname, bdtype);
107 env_set("board_name", info);
109 snprintf(info, ARRAY_SIZE(info), "%s%x-%s%s.dtb",
110 CONFIG_SYS_SOC, s5p_cpu_id, bdname, bdtype);
111 env_set("fdtfile", info);
114 #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
116 #ifdef CONFIG_LCD_MENU
117 static int power_key_pressed(u32 reg)
119 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
124 pmic = pmic_get(KEY_PWR_PMIC_NAME);
126 printf("%s: Not found\n", KEY_PWR_PMIC_NAME);
130 if (pmic_probe(pmic))
133 if (reg == KEY_PWR_STATUS_REG)
134 mask = KEY_PWR_STATUS_MASK;
136 mask = KEY_PWR_INTERRUPT_MASK;
138 if (pmic_reg_read(pmic, reg, &status))
141 return !!(status & mask);
147 static int key_pressed(int key)
153 value = power_key_pressed(KEY_PWR_INTERRUPT_REG);
156 value = !gpio_get_value(KEY_VOL_UP_GPIO);
159 value = !gpio_get_value(KEY_VOL_DOWN_GPIO);
170 static int check_keys(void)
174 if (key_pressed(KEY_POWER))
176 if (key_pressed(KEY_VOLUMEUP))
177 keys += KEY_VOLUMEUP;
178 if (key_pressed(KEY_VOLUMEDOWN))
179 keys += KEY_VOLUMEDOWN;
192 mode_name[BOOT_MODE_EXIT + 1][2] = {
203 mode_info[BOOT_MODE_EXIT + 1] = {
210 "and run normal boot"
214 mode_cmd[BOOT_MODE_EXIT + 1] = {
219 "gpt write mmc 0 $partitions",
220 "env default -a; saveenv",
224 static void display_board_info(void)
227 struct mmc *mmc = find_mmc_device(0);
229 vidinfo_t *vid = &panel_info;
231 lcd_position_cursor(4, 4);
233 lcd_printf("%s\n\t", U_BOOT_VERSION);
234 lcd_puts("\n\t\tBoard Info:\n");
235 #ifdef CONFIG_SYS_BOARD
236 lcd_printf("\tBoard name: %s\n", CONFIG_SYS_BOARD);
238 #ifdef CONFIG_REVISION_TAG
239 lcd_printf("\tBoard rev: %u\n", get_board_rev());
241 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS);
242 lcd_printf("\tDRAM size: %u MB\n", gd->ram_size / SZ_1M);
249 lcd_printf("\teMMC size: %llu MB\n", mmc->capacity / SZ_1M);
253 lcd_printf("\tDisplay resolution: %u x % u\n",
254 vid->vl_col, vid->vl_row);
256 lcd_printf("\tDisplay BPP: %u\n", 1 << vid->vl_bpix);
260 static int mode_leave_menu(int mode)
264 char *exit_reset = "reset";
265 char *exit_back = "back";
276 display_board_info();
277 exit_option = exit_back;
281 cmd = find_cmd(mode_name[mode][1]);
283 printf("Enter: %s %s\n", mode_name[mode][0],
285 lcd_printf("\n\n\t%s %s\n", mode_name[mode][0],
287 lcd_puts("\n\tDo not turn off device before finish!\n");
289 cmd_result = run_command(mode_cmd[mode], 0);
291 if (cmd_result == CMD_RET_SUCCESS) {
292 printf("Command finished\n");
294 lcd_printf("\n\n\t%s finished\n",
297 exit_option = exit_reset;
300 printf("Command error\n");
302 lcd_printf("\n\n\t%s command error\n",
305 exit_option = exit_back;
309 lcd_puts("\n\n\tThis mode is not supported.\n");
310 exit_option = exit_back;
315 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option);
317 /* Clear PWR button Rising edge interrupt status flag */
318 power_key_pressed(KEY_PWR_INTERRUPT_REG);
320 /* Wait for PWR key */
321 while (!key_pressed(KEY_POWER))
332 static void display_download_menu(int mode)
334 char *selection[BOOT_MODE_EXIT + 1];
337 for (i = 0; i <= BOOT_MODE_EXIT; i++)
338 selection[i] = "[ ]";
340 selection[mode] = "[=>]";
343 lcd_printf("\n\n\t\tDownload Mode Menu\n\n");
345 for (i = 0; i <= BOOT_MODE_EXIT; i++)
346 lcd_printf("\t%s %s - %s\n\n", selection[i],
347 mode_name[i][0], mode_info[i]);
351 static void download_menu(void)
358 int timeout = 15; /* sec */
361 display_download_menu(mode);
365 /* Start count if no key is pressed */
370 lcd_printf("\r\tNormal boot will start in: %2.d seconds.",
373 /* about 1000 ms in for loop */
374 for (i = 0; i < 10; i++) {
392 if (mode != last_mode)
393 display_download_menu(mode);
408 if (mode < BOOT_MODE_EXIT)
416 if (mode_leave_menu(mode))
417 run_command("reset", 0);
419 display_download_menu(mode);
427 void check_boot_mode(void)
431 pwr_key = power_key_pressed(KEY_PWR_STATUS_REG);
435 /* Clear PWR button Rising edge interrupt status flag */
436 power_key_pressed(KEY_PWR_INTERRUPT_REG);
438 if (key_pressed(KEY_VOLUMEUP))
440 else if (key_pressed(KEY_VOLUMEDOWN))
441 mode_leave_menu(BOOT_MODE_THOR);
446 /* Set direction to input */
447 gpio_request(KEY_VOL_UP_GPIO, "volume-up");
448 gpio_request(KEY_VOL_DOWN_GPIO, "volume-down");
449 gpio_direction_input(KEY_VOL_UP_GPIO);
450 gpio_direction_input(KEY_VOL_DOWN_GPIO);
452 #endif /* CONFIG_LCD_MENU */
454 #ifdef CONFIG_CMD_BMP
460 addr = panel_info.logo_addr;
462 pr_err("There is no logo data.\n");
466 if (panel_info.vl_width >= panel_info.logo_width) {
467 x = ((panel_info.vl_width - panel_info.logo_width) >> 1);
468 x += panel_info.logo_x_offset; /* For X center align */
471 printf("Warning: image width is bigger than display width\n");
474 if (panel_info.vl_height >= panel_info.logo_height) {
475 y = ((panel_info.vl_height - panel_info.logo_height) >> 1);
476 y += panel_info.logo_y_offset; /* For Y center align */
479 printf("Warning: image height is bigger than display height\n");
482 bmp_display(addr, x, y);
484 #endif /* CONFIG_CMD_BMP */