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>
21 #include <power/pmic.h>
24 DECLARE_GLOBAL_DATA_PTR
;
26 #ifdef CONFIG_SET_DFU_ALT_INFO
27 void set_dfu_alt_info(char *interface
, char *devstr
)
29 size_t buf_size
= CONFIG_SET_DFU_ALT_BUF_LEN
;
30 ALLOC_CACHE_ALIGN_BUFFER(char, buf
, buf_size
);
31 char *alt_info
= "Settings not found!";
32 char *status
= "error!\n";
37 puts("DFU alt info setting: ");
39 alt_setting
= get_dfu_alt_boot(interface
, devstr
);
41 setenv("dfu_alt_boot", alt_setting
);
42 offset
= snprintf(buf
, buf_size
, "%s", alt_setting
);
45 alt_setting
= get_dfu_alt_system(interface
, devstr
);
52 offset
+= snprintf(buf
+ offset
, buf_size
- offset
,
53 "%s%s", alt_sep
, alt_setting
);
61 setenv("dfu_alt_info", alt_info
);
66 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
67 void set_board_info(void)
71 snprintf(info
, ARRAY_SIZE(info
), "%u.%u", (s5p_cpu_rev
& 0xf0) >> 4,
73 setenv("soc_rev", info
);
75 snprintf(info
, ARRAY_SIZE(info
), "%x", s5p_cpu_id
);
76 setenv("soc_id", info
);
78 #ifdef CONFIG_REVISION_TAG
79 snprintf(info
, ARRAY_SIZE(info
), "%x", get_board_rev());
80 setenv("board_rev", info
);
82 #ifdef CONFIG_OF_LIBFDT
83 const char *bdtype
= "";
84 const char *bdname
= CONFIG_SYS_BOARD
;
86 #ifdef CONFIG_BOARD_TYPES
87 bdtype
= get_board_type();
88 sprintf(info
, "%s%s", bdname
, bdtype
);
89 setenv("boardname", info
);
91 snprintf(info
, ARRAY_SIZE(info
), "%s%x-%s%s.dtb",
92 CONFIG_SYS_SOC
, s5p_cpu_id
, bdname
, bdtype
);
93 setenv("fdtfile", info
);
96 #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
98 #ifdef CONFIG_LCD_MENU
99 static int power_key_pressed(u32 reg
)
105 pmic
= pmic_get(KEY_PWR_PMIC_NAME
);
107 printf("%s: Not found\n", KEY_PWR_PMIC_NAME
);
111 if (pmic_probe(pmic
))
114 if (reg
== KEY_PWR_STATUS_REG
)
115 mask
= KEY_PWR_STATUS_MASK
;
117 mask
= KEY_PWR_INTERRUPT_MASK
;
119 if (pmic_reg_read(pmic
, reg
, &status
))
122 return !!(status
& mask
);
125 static int key_pressed(int key
)
131 value
= power_key_pressed(KEY_PWR_INTERRUPT_REG
);
134 value
= !gpio_get_value(KEY_VOL_UP_GPIO
);
137 value
= !gpio_get_value(KEY_VOL_DOWN_GPIO
);
147 static int check_keys(void)
151 if (key_pressed(KEY_POWER
))
153 if (key_pressed(KEY_VOLUMEUP
))
154 keys
+= KEY_VOLUMEUP
;
155 if (key_pressed(KEY_VOLUMEDOWN
))
156 keys
+= KEY_VOLUMEDOWN
;
169 mode_name
[BOOT_MODE_EXIT
+ 1][2] = {
180 mode_info
[BOOT_MODE_EXIT
+ 1] = {
187 "and run normal boot"
191 mode_cmd
[BOOT_MODE_EXIT
+ 1] = {
196 "gpt write mmc 0 $partitions",
197 "env default -a; saveenv",
201 static void display_board_info(void)
203 #ifdef CONFIG_GENERIC_MMC
204 struct mmc
*mmc
= find_mmc_device(0);
206 vidinfo_t
*vid
= &panel_info
;
208 lcd_position_cursor(4, 4);
210 lcd_printf("%s\n\t", U_BOOT_VERSION
);
211 lcd_puts("\n\t\tBoard Info:\n");
212 #ifdef CONFIG_SYS_BOARD
213 lcd_printf("\tBoard name: %s\n", CONFIG_SYS_BOARD
);
215 #ifdef CONFIG_REVISION_TAG
216 lcd_printf("\tBoard rev: %u\n", get_board_rev());
218 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS
);
219 lcd_printf("\tDRAM size: %u MB\n", gd
->ram_size
/ SZ_1M
);
221 #ifdef CONFIG_GENERIC_MMC
226 lcd_printf("\teMMC size: %llu MB\n", mmc
->capacity
/ SZ_1M
);
230 lcd_printf("\tDisplay resolution: %u x % u\n",
231 vid
->vl_col
, vid
->vl_row
);
233 lcd_printf("\tDisplay BPP: %u\n", 1 << vid
->vl_bpix
);
236 static int mode_leave_menu(int mode
)
239 char *exit_reset
= "reset";
240 char *exit_back
= "back";
251 display_board_info();
252 exit_option
= exit_back
;
256 cmd
= find_cmd(mode_name
[mode
][1]);
258 printf("Enter: %s %s\n", mode_name
[mode
][0],
260 lcd_printf("\n\n\t%s %s\n", mode_name
[mode
][0],
262 lcd_puts("\n\tDo not turn off device before finish!\n");
264 cmd_result
= run_command(mode_cmd
[mode
], 0);
266 if (cmd_result
== CMD_RET_SUCCESS
) {
267 printf("Command finished\n");
269 lcd_printf("\n\n\t%s finished\n",
272 exit_option
= exit_reset
;
275 printf("Command error\n");
277 lcd_printf("\n\n\t%s command error\n",
280 exit_option
= exit_back
;
284 lcd_puts("\n\n\tThis mode is not supported.\n");
285 exit_option
= exit_back
;
290 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option
);
292 /* Clear PWR button Rising edge interrupt status flag */
293 power_key_pressed(KEY_PWR_INTERRUPT_REG
);
295 /* Wait for PWR key */
296 while (!key_pressed(KEY_POWER
))
303 static void display_download_menu(int mode
)
305 char *selection
[BOOT_MODE_EXIT
+ 1];
308 for (i
= 0; i
<= BOOT_MODE_EXIT
; i
++)
309 selection
[i
] = "[ ]";
311 selection
[mode
] = "[=>]";
314 lcd_printf("\n\n\t\tDownload Mode Menu\n\n");
316 for (i
= 0; i
<= BOOT_MODE_EXIT
; i
++)
317 lcd_printf("\t%s %s - %s\n\n", selection
[i
],
322 static void download_menu(void)
328 int timeout
= 15; /* sec */
331 display_download_menu(mode
);
335 /* Start count if no key is pressed */
340 lcd_printf("\r\tNormal boot will start in: %2.d seconds.",
343 /* about 1000 ms in for loop */
344 for (i
= 0; i
< 10; i
++) {
362 if (mode
!= last_mode
)
363 display_download_menu(mode
);
378 if (mode
< BOOT_MODE_EXIT
)
386 if (mode_leave_menu(mode
))
387 run_command("reset", 0);
389 display_download_menu(mode
);
396 void check_boot_mode(void)
400 pwr_key
= power_key_pressed(KEY_PWR_STATUS_REG
);
404 /* Clear PWR button Rising edge interrupt status flag */
405 power_key_pressed(KEY_PWR_INTERRUPT_REG
);
407 if (key_pressed(KEY_VOLUMEUP
))
409 else if (key_pressed(KEY_VOLUMEDOWN
))
410 mode_leave_menu(BOOT_MODE_THOR
);
415 /* Set direction to input */
416 gpio_request(KEY_VOL_UP_GPIO
, "volume-up");
417 gpio_request(KEY_VOL_DOWN_GPIO
, "volume-down");
418 gpio_direction_input(KEY_VOL_UP_GPIO
);
419 gpio_direction_input(KEY_VOL_DOWN_GPIO
);
421 #endif /* CONFIG_LCD_MENU */
423 #ifdef CONFIG_CMD_BMP
429 addr
= panel_info
.logo_addr
;
431 error("There is no logo data.");
435 if (panel_info
.vl_width
>= panel_info
.logo_width
) {
436 x
= ((panel_info
.vl_width
- panel_info
.logo_width
) >> 1);
437 x
+= panel_info
.logo_x_offset
; /* For X center align */
440 printf("Warning: image width is bigger than display width\n");
443 if (panel_info
.vl_height
>= panel_info
.logo_height
) {
444 y
= ((panel_info
.vl_height
- panel_info
.logo_height
) >> 1);
445 y
+= panel_info
.logo_y_offset
; /* For Y center align */
448 printf("Warning: image height is bigger than display height\n");
451 bmp_display(addr
, x
, y
);
453 #endif /* CONFIG_CMD_BMP */