1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2013 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
12 #include <samsung/misc.h>
17 #include <linux/sizes.h>
18 #include <asm/arch/cpu.h>
20 #include <linux/input.h>
23 * Use #ifdef to work around conflicting headers while we wait for this to be
24 * converted to driver model.
26 #ifdef CONFIG_DM_PMIC_MAX77686
27 #include <power/max77686_pmic.h>
29 #ifdef CONFIG_DM_PMIC_MAX8998
30 #include <power/max8998_pmic.h>
32 #ifdef CONFIG_PMIC_MAX8997
33 #include <power/max8997_pmic.h>
35 #include <power/pmic.h>
38 DECLARE_GLOBAL_DATA_PTR;
40 #ifdef CONFIG_SET_DFU_ALT_INFO
41 void set_dfu_alt_info(char *interface, char *devstr)
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";
51 puts("DFU alt info setting: ");
53 alt_setting = get_dfu_alt_boot(interface, devstr);
55 env_set("dfu_alt_boot", alt_setting);
56 offset = snprintf(buf, buf_size, "%s", alt_setting);
59 alt_setting = get_dfu_alt_system(interface, devstr);
66 offset += snprintf(buf + offset, buf_size - offset,
67 "%s%s", alt_sep, alt_setting);
75 env_set("dfu_alt_info", alt_info);
80 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
81 void set_board_info(void)
85 snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev & 0xf0) >> 4,
87 env_set("soc_rev", info);
89 snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id);
90 env_set("soc_id", info);
92 #ifdef CONFIG_REVISION_TAG
93 snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev());
94 env_set("board_rev", info);
96 #ifdef CONFIG_OF_LIBFDT
97 const char *bdtype = "";
98 const char *bdname = CONFIG_SYS_BOARD;
100 #ifdef CONFIG_BOARD_TYPES
101 bdtype = get_board_type();
105 sprintf(info, "%s%s", bdname, bdtype);
106 env_set("board_name", info);
108 snprintf(info, ARRAY_SIZE(info), "%s%x-%s%s.dtb",
109 CONFIG_SYS_SOC, s5p_cpu_id, bdname, bdtype);
110 env_set("fdtfile", info);
113 #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
115 #ifdef CONFIG_LCD_MENU
116 static int power_key_pressed(u32 reg)
118 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
123 pmic = pmic_get(KEY_PWR_PMIC_NAME);
125 printf("%s: Not found\n", KEY_PWR_PMIC_NAME);
129 if (pmic_probe(pmic))
132 if (reg == KEY_PWR_STATUS_REG)
133 mask = KEY_PWR_STATUS_MASK;
135 mask = KEY_PWR_INTERRUPT_MASK;
137 if (pmic_reg_read(pmic, reg, &status))
140 return !!(status & mask);
146 static int key_pressed(int key)
152 value = power_key_pressed(KEY_PWR_INTERRUPT_REG);
155 value = !gpio_get_value(KEY_VOL_UP_GPIO);
158 value = !gpio_get_value(KEY_VOL_DOWN_GPIO);
169 static int check_keys(void)
173 if (key_pressed(KEY_POWER))
175 if (key_pressed(KEY_VOLUMEUP))
176 keys += KEY_VOLUMEUP;
177 if (key_pressed(KEY_VOLUMEDOWN))
178 keys += KEY_VOLUMEDOWN;
191 mode_name[BOOT_MODE_EXIT + 1][2] = {
202 mode_info[BOOT_MODE_EXIT + 1] = {
209 "and run normal boot"
213 mode_cmd[BOOT_MODE_EXIT + 1] = {
218 "gpt write mmc 0 $partitions",
219 "env default -a; saveenv",
223 static void display_board_info(void)
226 struct mmc *mmc = find_mmc_device(0);
228 vidinfo_t *vid = &panel_info;
230 lcd_position_cursor(4, 4);
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);
237 #ifdef CONFIG_REVISION_TAG
238 lcd_printf("\tBoard rev: %u\n", get_board_rev());
240 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS);
241 lcd_printf("\tDRAM size: %u MB\n", gd->ram_size / SZ_1M);
248 lcd_printf("\teMMC size: %llu MB\n", mmc->capacity / SZ_1M);
252 lcd_printf("\tDisplay resolution: %u x % u\n",
253 vid->vl_col, vid->vl_row);
255 lcd_printf("\tDisplay BPP: %u\n", 1 << vid->vl_bpix);
259 static int mode_leave_menu(int mode)
263 char *exit_reset = "reset";
264 char *exit_back = "back";
275 display_board_info();
276 exit_option = exit_back;
280 cmd = find_cmd(mode_name[mode][1]);
282 printf("Enter: %s %s\n", mode_name[mode][0],
284 lcd_printf("\n\n\t%s %s\n", mode_name[mode][0],
286 lcd_puts("\n\tDo not turn off device before finish!\n");
288 cmd_result = run_command(mode_cmd[mode], 0);
290 if (cmd_result == CMD_RET_SUCCESS) {
291 printf("Command finished\n");
293 lcd_printf("\n\n\t%s finished\n",
296 exit_option = exit_reset;
299 printf("Command error\n");
301 lcd_printf("\n\n\t%s command error\n",
304 exit_option = exit_back;
308 lcd_puts("\n\n\tThis mode is not supported.\n");
309 exit_option = exit_back;
314 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option);
316 /* Clear PWR button Rising edge interrupt status flag */
317 power_key_pressed(KEY_PWR_INTERRUPT_REG);
319 /* Wait for PWR key */
320 while (!key_pressed(KEY_POWER))
331 static void display_download_menu(int mode)
333 char *selection[BOOT_MODE_EXIT + 1];
336 for (i = 0; i <= BOOT_MODE_EXIT; i++)
337 selection[i] = "[ ]";
339 selection[mode] = "[=>]";
342 lcd_printf("\n\n\t\tDownload Mode Menu\n\n");
344 for (i = 0; i <= BOOT_MODE_EXIT; i++)
345 lcd_printf("\t%s %s - %s\n\n", selection[i],
346 mode_name[i][0], mode_info[i]);
350 static void download_menu(void)
357 int timeout = 15; /* sec */
360 display_download_menu(mode);
364 /* Start count if no key is pressed */
369 lcd_printf("\r\tNormal boot will start in: %2.d seconds.",
372 /* about 1000 ms in for loop */
373 for (i = 0; i < 10; i++) {
391 if (mode != last_mode)
392 display_download_menu(mode);
407 if (mode < BOOT_MODE_EXIT)
415 if (mode_leave_menu(mode))
416 run_command("reset", 0);
418 display_download_menu(mode);
426 void check_boot_mode(void)
430 pwr_key = power_key_pressed(KEY_PWR_STATUS_REG);
434 /* Clear PWR button Rising edge interrupt status flag */
435 power_key_pressed(KEY_PWR_INTERRUPT_REG);
437 if (key_pressed(KEY_VOLUMEUP))
439 else if (key_pressed(KEY_VOLUMEDOWN))
440 mode_leave_menu(BOOT_MODE_THOR);
445 /* Set direction to input */
446 gpio_request(KEY_VOL_UP_GPIO, "volume-up");
447 gpio_request(KEY_VOL_DOWN_GPIO, "volume-down");
448 gpio_direction_input(KEY_VOL_UP_GPIO);
449 gpio_direction_input(KEY_VOL_DOWN_GPIO);
451 #endif /* CONFIG_LCD_MENU */
453 #ifdef CONFIG_CMD_BMP
459 addr = panel_info.logo_addr;
461 pr_err("There is no logo data.\n");
465 if (panel_info.vl_width >= panel_info.logo_width) {
466 x = ((panel_info.vl_width - panel_info.logo_width) >> 1);
467 x += panel_info.logo_x_offset; /* For X center align */
470 printf("Warning: image width is bigger than display width\n");
473 if (panel_info.vl_height >= panel_info.logo_height) {
474 y = ((panel_info.vl_height - panel_info.logo_height) >> 1);
475 y += panel_info.logo_y_offset; /* For Y center align */
478 printf("Warning: image height is bigger than display height\n");
481 bmp_display(addr, x, y);
483 #endif /* CONFIG_CMD_BMP */