2 * Copyright (C) 2013 Samsung Electronics
3 * Przemyslaw Marczak <p.marczak@samsung.com>
5 * SPDX-License-Identifier: GPL-2.0+
11 #include <samsung/misc.h>
15 #include <linux/sizes.h>
16 #include <asm/arch/cpu.h>
17 #include <asm/arch/gpio.h>
19 #include <linux/input.h>
20 #include <power/pmic.h>
23 DECLARE_GLOBAL_DATA_PTR;
25 #ifdef CONFIG_SET_DFU_ALT_INFO
26 void set_dfu_alt_info(void)
28 size_t buf_size = CONFIG_SET_DFU_ALT_BUF_LEN;
29 ALLOC_CACHE_ALIGN_BUFFER(char, buf, buf_size);
30 char *alt_info = "Settings not found!";
31 char *status = "error!\n";
36 puts("DFU alt info setting: ");
38 alt_setting = get_dfu_alt_boot();
40 setenv("dfu_alt_boot", alt_setting);
41 offset = snprintf(buf, buf_size, "%s", alt_setting);
44 alt_setting = get_dfu_alt_system();
51 offset += snprintf(buf + offset, buf_size - offset,
52 "%s%s", alt_sep, alt_setting);
60 setenv("dfu_alt_info", alt_info);
65 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
66 void set_board_info(void)
70 snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev & 0xf0) >> 4,
72 setenv("soc_rev", info);
74 snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id);
75 setenv("soc_id", info);
77 #ifdef CONFIG_REVISION_TAG
78 snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev());
79 setenv("board_rev", info);
81 #ifdef CONFIG_OF_LIBFDT
82 snprintf(info, ARRAY_SIZE(info), "%s%x-%s.dtb",
83 CONFIG_SYS_SOC, s5p_cpu_id, CONFIG_SYS_BOARD);
84 setenv("fdtfile", info);
87 #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
89 #ifdef CONFIG_LCD_MENU
90 static int power_key_pressed(u32 reg)
96 pmic = pmic_get(KEY_PWR_PMIC_NAME);
98 printf("%s: Not found\n", KEY_PWR_PMIC_NAME);
102 if (pmic_probe(pmic))
105 if (reg == KEY_PWR_STATUS_REG)
106 mask = KEY_PWR_STATUS_MASK;
108 mask = KEY_PWR_INTERRUPT_MASK;
110 if (pmic_reg_read(pmic, reg, &status))
113 return !!(status & mask);
116 static int key_pressed(int key)
122 value = power_key_pressed(KEY_PWR_INTERRUPT_REG);
125 value = !gpio_get_value(KEY_VOL_UP_GPIO);
128 value = !gpio_get_value(KEY_VOL_DOWN_GPIO);
138 static int check_keys(void)
142 if (key_pressed(KEY_POWER))
144 if (key_pressed(KEY_VOLUMEUP))
145 keys += KEY_VOLUMEUP;
146 if (key_pressed(KEY_VOLUMEDOWN))
147 keys += KEY_VOLUMEDOWN;
160 mode_name[BOOT_MODE_EXIT + 1][2] = {
171 mode_info[BOOT_MODE_EXIT + 1] = {
178 "and run normal boot"
182 mode_cmd[BOOT_MODE_EXIT + 1] = {
187 "gpt write mmc 0 $partitions",
188 "env default -a; saveenv",
192 static void display_board_info(void)
194 #ifdef CONFIG_GENERIC_MMC
195 struct mmc *mmc = find_mmc_device(0);
197 vidinfo_t *vid = &panel_info;
199 lcd_position_cursor(4, 4);
201 lcd_printf("%s\n\t", U_BOOT_VERSION);
202 lcd_puts("\n\t\tBoard Info:\n");
203 #ifdef CONFIG_SYS_BOARD
204 lcd_printf("\tBoard name: %s\n", CONFIG_SYS_BOARD);
206 #ifdef CONFIG_REVISION_TAG
207 lcd_printf("\tBoard rev: %u\n", get_board_rev());
209 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS);
210 lcd_printf("\tDRAM size: %u MB\n", gd->ram_size / SZ_1M);
212 #ifdef CONFIG_GENERIC_MMC
217 lcd_printf("\teMMC size: %llu MB\n", mmc->capacity / SZ_1M);
221 lcd_printf("\tDisplay resolution: %u x % u\n",
222 vid->vl_col, vid->vl_row);
224 lcd_printf("\tDisplay BPP: %u\n", 1 << vid->vl_bpix);
227 static int mode_leave_menu(int mode)
230 char *exit_reset = "reset";
231 char *exit_back = "back";
242 display_board_info();
243 exit_option = exit_back;
247 cmd = find_cmd(mode_name[mode][1]);
249 printf("Enter: %s %s\n", mode_name[mode][0],
251 lcd_printf("\n\n\t%s %s\n", mode_name[mode][0],
253 lcd_puts("\n\tDo not turn off device before finish!\n");
255 cmd_result = run_command(mode_cmd[mode], 0);
257 if (cmd_result == CMD_RET_SUCCESS) {
258 printf("Command finished\n");
260 lcd_printf("\n\n\t%s finished\n",
263 exit_option = exit_reset;
266 printf("Command error\n");
268 lcd_printf("\n\n\t%s command error\n",
271 exit_option = exit_back;
275 lcd_puts("\n\n\tThis mode is not supported.\n");
276 exit_option = exit_back;
281 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option);
283 /* Clear PWR button Rising edge interrupt status flag */
284 power_key_pressed(KEY_PWR_INTERRUPT_REG);
286 /* Wait for PWR key */
287 while (!key_pressed(KEY_POWER))
294 static void display_download_menu(int mode)
296 char *selection[BOOT_MODE_EXIT + 1];
299 for (i = 0; i <= BOOT_MODE_EXIT; i++)
300 selection[i] = "[ ]";
302 selection[mode] = "[=>]";
305 lcd_printf("\n\n\t\tDownload Mode Menu\n\n");
307 for (i = 0; i <= BOOT_MODE_EXIT; i++)
308 lcd_printf("\t%s %s - %s\n\n", selection[i],
313 static void download_menu(void)
319 int timeout = 15; /* sec */
322 display_download_menu(mode);
326 /* Start count if no key is pressed */
331 lcd_printf("\r\tNormal boot will start in: %2.d seconds.",
334 /* about 1000 ms in for loop */
335 for (i = 0; i < 10; i++) {
353 if (mode != last_mode)
354 display_download_menu(mode);
369 if (mode < BOOT_MODE_EXIT)
377 if (mode_leave_menu(mode))
378 run_command("reset", 0);
380 display_download_menu(mode);
387 void check_boot_mode(void)
391 pwr_key = power_key_pressed(KEY_PWR_STATUS_REG);
395 /* Clear PWR button Rising edge interrupt status flag */
396 power_key_pressed(KEY_PWR_INTERRUPT_REG);
398 if (key_pressed(KEY_VOLUMEUP))
400 else if (key_pressed(KEY_VOLUMEDOWN))
401 mode_leave_menu(BOOT_MODE_THOR);
406 /* Set direction to input */
407 gpio_direction_input(KEY_VOL_UP_GPIO);
408 gpio_direction_input(KEY_VOL_DOWN_GPIO);
410 #endif /* CONFIG_LCD_MENU */
412 #ifdef CONFIG_CMD_BMP
418 addr = panel_info.logo_addr;
420 error("There is no logo data.");
424 if (panel_info.vl_width >= panel_info.logo_width) {
425 x = ((panel_info.vl_width - panel_info.logo_width) >> 1);
426 x += panel_info.logo_x_offset; /* For X center align */
429 printf("Warning: image width is bigger than display width\n");
432 if (panel_info.vl_height >= panel_info.logo_height) {
433 y = ((panel_info.vl_height - panel_info.logo_height) >> 1);
434 y += panel_info.logo_y_offset; /* For Y center align */
437 printf("Warning: image height is bigger than display height\n");
440 bmp_display(addr, x, y);
442 #endif /* CONFIG_CMD_BMP */