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>
16 #include <linux/sizes.h>
17 #include <asm/arch/cpu.h>
19 #include <linux/input.h>
22 * Use #ifdef to work around conflicting headers while we wait for this to be
23 * converted to driver model.
25 #ifdef CONFIG_DM_PMIC_MAX77686
26 #include <power/max77686_pmic.h>
28 #ifdef CONFIG_DM_PMIC_MAX8998
29 #include <power/max8998_pmic.h>
31 #ifdef CONFIG_PMIC_MAX8997
32 #include <power/max8997_pmic.h>
34 #include <power/pmic.h>
37 DECLARE_GLOBAL_DATA_PTR;
39 #ifdef CONFIG_SET_DFU_ALT_INFO
40 void set_dfu_alt_info(char *interface, char *devstr)
42 size_t buf_size = CONFIG_SET_DFU_ALT_BUF_LEN;
43 ALLOC_CACHE_ALIGN_BUFFER(char, buf, buf_size);
44 char *alt_info = "Settings not found!";
45 char *status = "error!\n";
50 puts("DFU alt info setting: ");
52 alt_setting = get_dfu_alt_boot(interface, devstr);
54 env_set("dfu_alt_boot", alt_setting);
55 offset = snprintf(buf, buf_size, "%s", alt_setting);
58 alt_setting = get_dfu_alt_system(interface, devstr);
65 offset += snprintf(buf + offset, buf_size - offset,
66 "%s%s", alt_sep, alt_setting);
74 env_set("dfu_alt_info", alt_info);
79 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
80 void set_board_info(void)
84 snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev & 0xf0) >> 4,
86 env_set("soc_rev", info);
88 snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id);
89 env_set("soc_id", info);
91 #ifdef CONFIG_REVISION_TAG
92 snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev());
93 env_set("board_rev", info);
95 #ifdef CONFIG_OF_LIBFDT
96 const char *bdtype = "";
97 const char *bdname = CONFIG_SYS_BOARD;
99 #ifdef CONFIG_BOARD_TYPES
100 bdtype = get_board_type();
104 sprintf(info, "%s%s", bdname, bdtype);
105 env_set("boardname", info);
107 snprintf(info, ARRAY_SIZE(info), "%s%x-%s%s.dtb",
108 CONFIG_SYS_SOC, s5p_cpu_id, bdname, bdtype);
109 env_set("fdtfile", info);
112 #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
114 #ifdef CONFIG_LCD_MENU
115 static int power_key_pressed(u32 reg)
117 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
122 pmic = pmic_get(KEY_PWR_PMIC_NAME);
124 printf("%s: Not found\n", KEY_PWR_PMIC_NAME);
128 if (pmic_probe(pmic))
131 if (reg == KEY_PWR_STATUS_REG)
132 mask = KEY_PWR_STATUS_MASK;
134 mask = KEY_PWR_INTERRUPT_MASK;
136 if (pmic_reg_read(pmic, reg, &status))
139 return !!(status & mask);
145 static int key_pressed(int key)
151 value = power_key_pressed(KEY_PWR_INTERRUPT_REG);
154 value = !gpio_get_value(KEY_VOL_UP_GPIO);
157 value = !gpio_get_value(KEY_VOL_DOWN_GPIO);
168 static int check_keys(void)
172 if (key_pressed(KEY_POWER))
174 if (key_pressed(KEY_VOLUMEUP))
175 keys += KEY_VOLUMEUP;
176 if (key_pressed(KEY_VOLUMEDOWN))
177 keys += KEY_VOLUMEDOWN;
190 mode_name[BOOT_MODE_EXIT + 1][2] = {
201 mode_info[BOOT_MODE_EXIT + 1] = {
208 "and run normal boot"
212 mode_cmd[BOOT_MODE_EXIT + 1] = {
217 "gpt write mmc 0 $partitions",
218 "env default -a; saveenv",
222 static void display_board_info(void)
225 struct mmc *mmc = find_mmc_device(0);
227 vidinfo_t *vid = &panel_info;
229 lcd_position_cursor(4, 4);
231 lcd_printf("%s\n\t", U_BOOT_VERSION);
232 lcd_puts("\n\t\tBoard Info:\n");
233 #ifdef CONFIG_SYS_BOARD
234 lcd_printf("\tBoard name: %s\n", CONFIG_SYS_BOARD);
236 #ifdef CONFIG_REVISION_TAG
237 lcd_printf("\tBoard rev: %u\n", get_board_rev());
239 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS);
240 lcd_printf("\tDRAM size: %u MB\n", gd->ram_size / SZ_1M);
247 lcd_printf("\teMMC size: %llu MB\n", mmc->capacity / SZ_1M);
251 lcd_printf("\tDisplay resolution: %u x % u\n",
252 vid->vl_col, vid->vl_row);
254 lcd_printf("\tDisplay BPP: %u\n", 1 << vid->vl_bpix);
258 static int mode_leave_menu(int mode)
262 char *exit_reset = "reset";
263 char *exit_back = "back";
274 display_board_info();
275 exit_option = exit_back;
279 cmd = find_cmd(mode_name[mode][1]);
281 printf("Enter: %s %s\n", mode_name[mode][0],
283 lcd_printf("\n\n\t%s %s\n", mode_name[mode][0],
285 lcd_puts("\n\tDo not turn off device before finish!\n");
287 cmd_result = run_command(mode_cmd[mode], 0);
289 if (cmd_result == CMD_RET_SUCCESS) {
290 printf("Command finished\n");
292 lcd_printf("\n\n\t%s finished\n",
295 exit_option = exit_reset;
298 printf("Command error\n");
300 lcd_printf("\n\n\t%s command error\n",
303 exit_option = exit_back;
307 lcd_puts("\n\n\tThis mode is not supported.\n");
308 exit_option = exit_back;
313 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option);
315 /* Clear PWR button Rising edge interrupt status flag */
316 power_key_pressed(KEY_PWR_INTERRUPT_REG);
318 /* Wait for PWR key */
319 while (!key_pressed(KEY_POWER))
330 static void display_download_menu(int mode)
332 char *selection[BOOT_MODE_EXIT + 1];
335 for (i = 0; i <= BOOT_MODE_EXIT; i++)
336 selection[i] = "[ ]";
338 selection[mode] = "[=>]";
341 lcd_printf("\n\n\t\tDownload Mode Menu\n\n");
343 for (i = 0; i <= BOOT_MODE_EXIT; i++)
344 lcd_printf("\t%s %s - %s\n\n", selection[i],
345 mode_name[i][0], mode_info[i]);
349 static void download_menu(void)
356 int timeout = 15; /* sec */
359 display_download_menu(mode);
363 /* Start count if no key is pressed */
368 lcd_printf("\r\tNormal boot will start in: %2.d seconds.",
371 /* about 1000 ms in for loop */
372 for (i = 0; i < 10; i++) {
390 if (mode != last_mode)
391 display_download_menu(mode);
406 if (mode < BOOT_MODE_EXIT)
414 if (mode_leave_menu(mode))
415 run_command("reset", 0);
417 display_download_menu(mode);
425 void check_boot_mode(void)
429 pwr_key = power_key_pressed(KEY_PWR_STATUS_REG);
433 /* Clear PWR button Rising edge interrupt status flag */
434 power_key_pressed(KEY_PWR_INTERRUPT_REG);
436 if (key_pressed(KEY_VOLUMEUP))
438 else if (key_pressed(KEY_VOLUMEDOWN))
439 mode_leave_menu(BOOT_MODE_THOR);
444 /* Set direction to input */
445 gpio_request(KEY_VOL_UP_GPIO, "volume-up");
446 gpio_request(KEY_VOL_DOWN_GPIO, "volume-down");
447 gpio_direction_input(KEY_VOL_UP_GPIO);
448 gpio_direction_input(KEY_VOL_DOWN_GPIO);
450 #endif /* CONFIG_LCD_MENU */
452 #ifdef CONFIG_CMD_BMP
458 addr = panel_info.logo_addr;
460 pr_err("There is no logo data.");
464 if (panel_info.vl_width >= panel_info.logo_width) {
465 x = ((panel_info.vl_width - panel_info.logo_width) >> 1);
466 x += panel_info.logo_x_offset; /* For X center align */
469 printf("Warning: image width is bigger than display width\n");
472 if (panel_info.vl_height >= panel_info.logo_height) {
473 y = ((panel_info.vl_height - panel_info.logo_height) >> 1);
474 y += panel_info.logo_y_offset; /* For Y center align */
477 printf("Warning: image height is bigger than display height\n");
480 bmp_display(addr, x, y);
482 #endif /* CONFIG_CMD_BMP */