1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2013 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
10 #include <samsung/misc.h>
15 #include <linux/sizes.h>
16 #include <asm/arch/cpu.h>
18 #include <linux/input.h>
21 * Use #ifdef to work around conflicting headers while we wait for this to be
22 * converted to driver model.
24 #ifdef CONFIG_DM_PMIC_MAX77686
25 #include <power/max77686_pmic.h>
27 #ifdef CONFIG_DM_PMIC_MAX8998
28 #include <power/max8998_pmic.h>
30 #ifdef CONFIG_PMIC_MAX8997
31 #include <power/max8997_pmic.h>
33 #include <power/pmic.h>
36 DECLARE_GLOBAL_DATA_PTR;
38 #ifdef CONFIG_SET_DFU_ALT_INFO
39 void set_dfu_alt_info(char *interface, char *devstr)
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";
49 puts("DFU alt info setting: ");
51 alt_setting = get_dfu_alt_boot(interface, devstr);
53 env_set("dfu_alt_boot", alt_setting);
54 offset = snprintf(buf, buf_size, "%s", alt_setting);
57 alt_setting = get_dfu_alt_system(interface, devstr);
64 offset += snprintf(buf + offset, buf_size - offset,
65 "%s%s", alt_sep, alt_setting);
73 env_set("dfu_alt_info", alt_info);
78 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
79 void set_board_info(void)
83 snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev & 0xf0) >> 4,
85 env_set("soc_rev", info);
87 snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id);
88 env_set("soc_id", info);
90 #ifdef CONFIG_REVISION_TAG
91 snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev());
92 env_set("board_rev", info);
94 #ifdef CONFIG_OF_LIBFDT
95 const char *bdtype = "";
96 const char *bdname = CONFIG_SYS_BOARD;
98 #ifdef CONFIG_BOARD_TYPES
99 bdtype = get_board_type();
103 sprintf(info, "%s%s", bdname, bdtype);
104 env_set("board_name", info);
106 snprintf(info, ARRAY_SIZE(info), "%s%x-%s%s.dtb",
107 CONFIG_SYS_SOC, s5p_cpu_id, bdname, bdtype);
108 env_set("fdtfile", info);
111 #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
113 #ifdef CONFIG_LCD_MENU
114 static int power_key_pressed(u32 reg)
116 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
121 pmic = pmic_get(KEY_PWR_PMIC_NAME);
123 printf("%s: Not found\n", KEY_PWR_PMIC_NAME);
127 if (pmic_probe(pmic))
130 if (reg == KEY_PWR_STATUS_REG)
131 mask = KEY_PWR_STATUS_MASK;
133 mask = KEY_PWR_INTERRUPT_MASK;
135 if (pmic_reg_read(pmic, reg, &status))
138 return !!(status & mask);
144 static int key_pressed(int key)
150 value = power_key_pressed(KEY_PWR_INTERRUPT_REG);
153 value = !gpio_get_value(KEY_VOL_UP_GPIO);
156 value = !gpio_get_value(KEY_VOL_DOWN_GPIO);
167 static int check_keys(void)
171 if (key_pressed(KEY_POWER))
173 if (key_pressed(KEY_VOLUMEUP))
174 keys += KEY_VOLUMEUP;
175 if (key_pressed(KEY_VOLUMEDOWN))
176 keys += KEY_VOLUMEDOWN;
189 mode_name[BOOT_MODE_EXIT + 1][2] = {
200 mode_info[BOOT_MODE_EXIT + 1] = {
207 "and run normal boot"
211 mode_cmd[BOOT_MODE_EXIT + 1] = {
216 "gpt write mmc 0 $partitions",
217 "env default -a; saveenv",
221 static void display_board_info(void)
224 struct mmc *mmc = find_mmc_device(0);
226 vidinfo_t *vid = &panel_info;
228 lcd_position_cursor(4, 4);
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);
235 #ifdef CONFIG_REVISION_TAG
236 lcd_printf("\tBoard rev: %u\n", get_board_rev());
238 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS);
239 lcd_printf("\tDRAM size: %u MB\n", gd->ram_size / SZ_1M);
246 lcd_printf("\teMMC size: %llu MB\n", mmc->capacity / SZ_1M);
250 lcd_printf("\tDisplay resolution: %u x % u\n",
251 vid->vl_col, vid->vl_row);
253 lcd_printf("\tDisplay BPP: %u\n", 1 << vid->vl_bpix);
257 static int mode_leave_menu(int mode)
261 char *exit_reset = "reset";
262 char *exit_back = "back";
273 display_board_info();
274 exit_option = exit_back;
278 cmd = find_cmd(mode_name[mode][1]);
280 printf("Enter: %s %s\n", mode_name[mode][0],
282 lcd_printf("\n\n\t%s %s\n", mode_name[mode][0],
284 lcd_puts("\n\tDo not turn off device before finish!\n");
286 cmd_result = run_command(mode_cmd[mode], 0);
288 if (cmd_result == CMD_RET_SUCCESS) {
289 printf("Command finished\n");
291 lcd_printf("\n\n\t%s finished\n",
294 exit_option = exit_reset;
297 printf("Command error\n");
299 lcd_printf("\n\n\t%s command error\n",
302 exit_option = exit_back;
306 lcd_puts("\n\n\tThis mode is not supported.\n");
307 exit_option = exit_back;
312 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option);
314 /* Clear PWR button Rising edge interrupt status flag */
315 power_key_pressed(KEY_PWR_INTERRUPT_REG);
317 /* Wait for PWR key */
318 while (!key_pressed(KEY_POWER))
329 static void display_download_menu(int mode)
331 char *selection[BOOT_MODE_EXIT + 1];
334 for (i = 0; i <= BOOT_MODE_EXIT; i++)
335 selection[i] = "[ ]";
337 selection[mode] = "[=>]";
340 lcd_printf("\n\n\t\tDownload Mode Menu\n\n");
342 for (i = 0; i <= BOOT_MODE_EXIT; i++)
343 lcd_printf("\t%s %s - %s\n\n", selection[i],
344 mode_name[i][0], mode_info[i]);
348 static void download_menu(void)
355 int timeout = 15; /* sec */
358 display_download_menu(mode);
362 /* Start count if no key is pressed */
367 lcd_printf("\r\tNormal boot will start in: %2.d seconds.",
370 /* about 1000 ms in for loop */
371 for (i = 0; i < 10; i++) {
389 if (mode != last_mode)
390 display_download_menu(mode);
405 if (mode < BOOT_MODE_EXIT)
413 if (mode_leave_menu(mode))
414 run_command("reset", 0);
416 display_download_menu(mode);
424 void check_boot_mode(void)
428 pwr_key = power_key_pressed(KEY_PWR_STATUS_REG);
432 /* Clear PWR button Rising edge interrupt status flag */
433 power_key_pressed(KEY_PWR_INTERRUPT_REG);
435 if (key_pressed(KEY_VOLUMEUP))
437 else if (key_pressed(KEY_VOLUMEDOWN))
438 mode_leave_menu(BOOT_MODE_THOR);
443 /* Set direction to input */
444 gpio_request(KEY_VOL_UP_GPIO, "volume-up");
445 gpio_request(KEY_VOL_DOWN_GPIO, "volume-down");
446 gpio_direction_input(KEY_VOL_UP_GPIO);
447 gpio_direction_input(KEY_VOL_DOWN_GPIO);
449 #endif /* CONFIG_LCD_MENU */
451 #ifdef CONFIG_CMD_BMP
457 addr = panel_info.logo_addr;
459 pr_err("There is no logo data.\n");
463 if (panel_info.vl_width >= panel_info.logo_width) {
464 x = ((panel_info.vl_width - panel_info.logo_width) >> 1);
465 x += panel_info.logo_x_offset; /* For X center align */
468 printf("Warning: image width is bigger than display width\n");
471 if (panel_info.vl_height >= panel_info.logo_height) {
472 y = ((panel_info.vl_height - panel_info.logo_height) >> 1);
473 y += panel_info.logo_y_offset; /* For Y center align */
476 printf("Warning: image height is bigger than display height\n");
479 bmp_display(addr, x, y);
481 #endif /* CONFIG_CMD_BMP */