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>
18 #include <linux/input.h>
19 #include <power/pmic.h>
22 DECLARE_GLOBAL_DATA_PTR
;
24 #ifdef CONFIG_SET_DFU_ALT_INFO
25 void set_dfu_alt_info(void)
27 size_t buf_size
= CONFIG_SET_DFU_ALT_BUF_LEN
;
28 ALLOC_CACHE_ALIGN_BUFFER(char, buf
, buf_size
);
29 char *alt_info
= "Settings not found!";
30 char *status
= "error!\n";
35 puts("DFU alt info setting: ");
37 alt_setting
= get_dfu_alt_boot();
39 setenv("dfu_alt_boot", alt_setting
);
40 offset
= snprintf(buf
, buf_size
, "%s", alt_setting
);
43 alt_setting
= get_dfu_alt_system();
50 offset
+= snprintf(buf
+ offset
, buf_size
- offset
,
51 "%s%s", alt_sep
, alt_setting
);
59 setenv("dfu_alt_info", alt_info
);
64 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
65 void set_board_info(void)
69 snprintf(info
, ARRAY_SIZE(info
), "%u.%u", (s5p_cpu_rev
& 0xf0) >> 4,
71 setenv("soc_rev", info
);
73 snprintf(info
, ARRAY_SIZE(info
), "%x", s5p_cpu_id
);
74 setenv("soc_id", info
);
76 #ifdef CONFIG_REVISION_TAG
77 snprintf(info
, ARRAY_SIZE(info
), "%x", get_board_rev());
78 setenv("board_rev", info
);
80 #ifdef CONFIG_OF_LIBFDT
81 const char *bdtype
= "";
82 const char *bdname
= CONFIG_SYS_BOARD
;
84 #ifdef CONFIG_BOARD_TYPES
85 bdtype
= get_board_type();
86 sprintf(info
, "%s%s", bdname
, bdtype
);
87 setenv("boardname", info
);
89 snprintf(info
, ARRAY_SIZE(info
), "%s%x-%s%s.dtb",
90 CONFIG_SYS_SOC
, s5p_cpu_id
, bdname
, bdtype
);
91 setenv("fdtfile", info
);
94 #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
96 #ifdef CONFIG_LCD_MENU
97 static int power_key_pressed(u32 reg
)
103 pmic
= pmic_get(KEY_PWR_PMIC_NAME
);
105 printf("%s: Not found\n", KEY_PWR_PMIC_NAME
);
109 if (pmic_probe(pmic
))
112 if (reg
== KEY_PWR_STATUS_REG
)
113 mask
= KEY_PWR_STATUS_MASK
;
115 mask
= KEY_PWR_INTERRUPT_MASK
;
117 if (pmic_reg_read(pmic
, reg
, &status
))
120 return !!(status
& mask
);
123 static int key_pressed(int key
)
129 value
= power_key_pressed(KEY_PWR_INTERRUPT_REG
);
132 value
= !gpio_get_value(KEY_VOL_UP_GPIO
);
135 value
= !gpio_get_value(KEY_VOL_DOWN_GPIO
);
145 static int check_keys(void)
149 if (key_pressed(KEY_POWER
))
151 if (key_pressed(KEY_VOLUMEUP
))
152 keys
+= KEY_VOLUMEUP
;
153 if (key_pressed(KEY_VOLUMEDOWN
))
154 keys
+= KEY_VOLUMEDOWN
;
167 mode_name
[BOOT_MODE_EXIT
+ 1][2] = {
178 mode_info
[BOOT_MODE_EXIT
+ 1] = {
185 "and run normal boot"
189 mode_cmd
[BOOT_MODE_EXIT
+ 1] = {
194 "gpt write mmc 0 $partitions",
195 "env default -a; saveenv",
199 static void display_board_info(void)
201 #ifdef CONFIG_GENERIC_MMC
202 struct mmc
*mmc
= find_mmc_device(0);
204 vidinfo_t
*vid
= &panel_info
;
206 lcd_position_cursor(4, 4);
208 lcd_printf("%s\n\t", U_BOOT_VERSION
);
209 lcd_puts("\n\t\tBoard Info:\n");
210 #ifdef CONFIG_SYS_BOARD
211 lcd_printf("\tBoard name: %s\n", CONFIG_SYS_BOARD
);
213 #ifdef CONFIG_REVISION_TAG
214 lcd_printf("\tBoard rev: %u\n", get_board_rev());
216 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS
);
217 lcd_printf("\tDRAM size: %u MB\n", gd
->ram_size
/ SZ_1M
);
219 #ifdef CONFIG_GENERIC_MMC
224 lcd_printf("\teMMC size: %llu MB\n", mmc
->capacity
/ SZ_1M
);
228 lcd_printf("\tDisplay resolution: %u x % u\n",
229 vid
->vl_col
, vid
->vl_row
);
231 lcd_printf("\tDisplay BPP: %u\n", 1 << vid
->vl_bpix
);
234 static int mode_leave_menu(int mode
)
237 char *exit_reset
= "reset";
238 char *exit_back
= "back";
249 display_board_info();
250 exit_option
= exit_back
;
254 cmd
= find_cmd(mode_name
[mode
][1]);
256 printf("Enter: %s %s\n", mode_name
[mode
][0],
258 lcd_printf("\n\n\t%s %s\n", mode_name
[mode
][0],
260 lcd_puts("\n\tDo not turn off device before finish!\n");
262 cmd_result
= run_command(mode_cmd
[mode
], 0);
264 if (cmd_result
== CMD_RET_SUCCESS
) {
265 printf("Command finished\n");
267 lcd_printf("\n\n\t%s finished\n",
270 exit_option
= exit_reset
;
273 printf("Command error\n");
275 lcd_printf("\n\n\t%s command error\n",
278 exit_option
= exit_back
;
282 lcd_puts("\n\n\tThis mode is not supported.\n");
283 exit_option
= exit_back
;
288 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option
);
290 /* Clear PWR button Rising edge interrupt status flag */
291 power_key_pressed(KEY_PWR_INTERRUPT_REG
);
293 /* Wait for PWR key */
294 while (!key_pressed(KEY_POWER
))
301 static void display_download_menu(int mode
)
303 char *selection
[BOOT_MODE_EXIT
+ 1];
306 for (i
= 0; i
<= BOOT_MODE_EXIT
; i
++)
307 selection
[i
] = "[ ]";
309 selection
[mode
] = "[=>]";
312 lcd_printf("\n\n\t\tDownload Mode Menu\n\n");
314 for (i
= 0; i
<= BOOT_MODE_EXIT
; i
++)
315 lcd_printf("\t%s %s - %s\n\n", selection
[i
],
320 static void download_menu(void)
326 int timeout
= 15; /* sec */
329 display_download_menu(mode
);
333 /* Start count if no key is pressed */
338 lcd_printf("\r\tNormal boot will start in: %2.d seconds.",
341 /* about 1000 ms in for loop */
342 for (i
= 0; i
< 10; i
++) {
360 if (mode
!= last_mode
)
361 display_download_menu(mode
);
376 if (mode
< BOOT_MODE_EXIT
)
384 if (mode_leave_menu(mode
))
385 run_command("reset", 0);
387 display_download_menu(mode
);
394 void check_boot_mode(void)
398 pwr_key
= power_key_pressed(KEY_PWR_STATUS_REG
);
402 /* Clear PWR button Rising edge interrupt status flag */
403 power_key_pressed(KEY_PWR_INTERRUPT_REG
);
405 if (key_pressed(KEY_VOLUMEUP
))
407 else if (key_pressed(KEY_VOLUMEDOWN
))
408 mode_leave_menu(BOOT_MODE_THOR
);
413 /* Set direction to input */
414 gpio_request(KEY_VOL_UP_GPIO
, "volume-up");
415 gpio_request(KEY_VOL_DOWN_GPIO
, "volume-down");
416 gpio_direction_input(KEY_VOL_UP_GPIO
);
417 gpio_direction_input(KEY_VOL_DOWN_GPIO
);
419 #endif /* CONFIG_LCD_MENU */
421 #ifdef CONFIG_CMD_BMP
427 addr
= panel_info
.logo_addr
;
429 error("There is no logo data.");
433 if (panel_info
.vl_width
>= panel_info
.logo_width
) {
434 x
= ((panel_info
.vl_width
- panel_info
.logo_width
) >> 1);
435 x
+= panel_info
.logo_x_offset
; /* For X center align */
438 printf("Warning: image width is bigger than display width\n");
441 if (panel_info
.vl_height
>= panel_info
.logo_height
) {
442 y
= ((panel_info
.vl_height
- panel_info
.logo_height
) >> 1);
443 y
+= panel_info
.logo_y_offset
; /* For Y center align */
446 printf("Warning: image height is bigger than display height\n");
449 bmp_display(addr
, x
, y
);
451 #endif /* CONFIG_CMD_BMP */