]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/samsung/common/misc.c
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>
14 #include <linux/sizes.h>
15 #include <asm/arch/cpu.h>
16 #include <asm/arch/gpio.h>
18 #include <linux/input.h>
19 #include <power/pmic.h>
22 DECLARE_GLOBAL_DATA_PTR
;
24 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
25 void set_board_info(void)
29 snprintf(info
, ARRAY_SIZE(info
), "%d.%d", s5p_cpu_rev
& 0x0f,
30 (s5p_cpu_rev
& 0xf0) >> 0x04);
31 setenv("soc_rev", info
);
33 snprintf(info
, ARRAY_SIZE(info
), "%x", s5p_cpu_id
);
34 setenv("soc_id", info
);
36 #ifdef CONFIG_REVISION_TAG
37 snprintf(info
, ARRAY_SIZE(info
), "%x", get_board_rev());
38 setenv("board_rev", info
);
40 #ifdef CONFIG_OF_LIBFDT
41 snprintf(info
, ARRAY_SIZE(info
), "%s%x-%s.dtb",
42 CONFIG_SYS_SOC
, s5p_cpu_id
, CONFIG_SYS_BOARD
);
43 setenv("fdtfile", info
);
46 #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
48 #ifdef CONFIG_LCD_MENU
49 static int power_key_pressed(u32 reg
)
55 pmic
= pmic_get(KEY_PWR_PMIC_NAME
);
57 printf("%s: Not found\n", KEY_PWR_PMIC_NAME
);
64 if (reg
== KEY_PWR_STATUS_REG
)
65 mask
= KEY_PWR_STATUS_MASK
;
67 mask
= KEY_PWR_INTERRUPT_MASK
;
69 if (pmic_reg_read(pmic
, reg
, &status
))
72 return !!(status
& mask
);
75 static int key_pressed(int key
)
81 value
= power_key_pressed(KEY_PWR_INTERRUPT_REG
);
84 value
= !gpio_get_value(KEY_VOL_UP_GPIO
);
87 value
= !gpio_get_value(KEY_VOL_DOWN_GPIO
);
97 static int check_keys(void)
101 if (key_pressed(KEY_POWER
))
103 if (key_pressed(KEY_VOLUMEUP
))
104 keys
+= KEY_VOLUMEUP
;
105 if (key_pressed(KEY_VOLUMEDOWN
))
106 keys
+= KEY_VOLUMEDOWN
;
119 mode_name
[BOOT_MODE_EXIT
+ 1][2] = {
130 mode_info
[BOOT_MODE_EXIT
+ 1] = {
137 "and run normal boot"
141 mode_cmd
[BOOT_MODE_EXIT
+ 1] = {
146 "gpt write mmc 0 $partitions",
147 "env default -a; saveenv",
151 static void display_board_info(void)
153 #ifdef CONFIG_GENERIC_MMC
154 struct mmc
*mmc
= find_mmc_device(0);
156 vidinfo_t
*vid
= &panel_info
;
158 lcd_position_cursor(4, 4);
160 lcd_printf("%s\n\t", U_BOOT_VERSION
);
161 lcd_puts("\n\t\tBoard Info:\n");
162 #ifdef CONFIG_SYS_BOARD
163 lcd_printf("\tBoard name: %s\n", CONFIG_SYS_BOARD
);
165 #ifdef CONFIG_REVISION_TAG
166 lcd_printf("\tBoard rev: %u\n", get_board_rev());
168 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS
);
169 lcd_printf("\tDRAM size: %u MB\n", gd
->ram_size
/ SZ_1M
);
171 #ifdef CONFIG_GENERIC_MMC
176 lcd_printf("\teMMC size: %llu MB\n", mmc
->capacity
/ SZ_1M
);
180 lcd_printf("\tDisplay resolution: %u x % u\n",
181 vid
->vl_col
, vid
->vl_row
);
183 lcd_printf("\tDisplay BPP: %u\n", 1 << vid
->vl_bpix
);
186 static int mode_leave_menu(int mode
)
189 char *exit_reset
= "reset";
190 char *exit_back
= "back";
201 display_board_info();
202 exit_option
= exit_back
;
206 cmd
= find_cmd(mode_name
[mode
][1]);
208 printf("Enter: %s %s\n", mode_name
[mode
][0],
210 lcd_printf("\n\n\t%s %s\n", mode_name
[mode
][0],
212 lcd_puts("\n\tDo not turn off device before finish!\n");
214 cmd_result
= run_command(mode_cmd
[mode
], 0);
216 if (cmd_result
== CMD_RET_SUCCESS
) {
217 printf("Command finished\n");
219 lcd_printf("\n\n\t%s finished\n",
222 exit_option
= exit_reset
;
225 printf("Command error\n");
227 lcd_printf("\n\n\t%s command error\n",
230 exit_option
= exit_back
;
234 lcd_puts("\n\n\tThis mode is not supported.\n");
235 exit_option
= exit_back
;
240 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option
);
242 /* Clear PWR button Rising edge interrupt status flag */
243 power_key_pressed(KEY_PWR_INTERRUPT_REG
);
245 /* Wait for PWR key */
246 while (!key_pressed(KEY_POWER
))
253 static void display_download_menu(int mode
)
255 char *selection
[BOOT_MODE_EXIT
+ 1];
258 for (i
= 0; i
<= BOOT_MODE_EXIT
; i
++)
259 selection
[i
] = "[ ]";
261 selection
[mode
] = "[=>]";
264 lcd_printf("\n\n\t\tDownload Mode Menu\n\n");
266 for (i
= 0; i
<= BOOT_MODE_EXIT
; i
++)
267 lcd_printf("\t%s %s - %s\n\n", selection
[i
],
272 static void download_menu(void)
278 int timeout
= 15; /* sec */
281 display_download_menu(mode
);
285 /* Start count if no key is pressed */
290 lcd_printf("\r\tNormal boot will start in: %2.d seconds.",
293 /* about 1000 ms in for loop */
294 for (i
= 0; i
< 10; i
++) {
312 if (mode
!= last_mode
)
313 display_download_menu(mode
);
328 if (mode
< BOOT_MODE_EXIT
)
336 if (mode_leave_menu(mode
))
337 run_command("reset", 0);
339 display_download_menu(mode
);
346 void check_boot_mode(void)
350 pwr_key
= power_key_pressed(KEY_PWR_STATUS_REG
);
354 /* Clear PWR button Rising edge interrupt status flag */
355 power_key_pressed(KEY_PWR_INTERRUPT_REG
);
357 if (key_pressed(KEY_VOLUMEUP
))
359 else if (key_pressed(KEY_VOLUMEDOWN
))
360 mode_leave_menu(BOOT_MODE_THOR
);
365 /* Set direction to input */
366 gpio_direction_input(KEY_VOL_UP_GPIO
);
367 gpio_direction_input(KEY_VOL_DOWN_GPIO
);
369 #endif /* CONFIG_LCD_MENU */
371 #ifdef CONFIG_CMD_BMP
377 addr
= panel_info
.logo_addr
;
379 error("There is no logo data.");
383 if (panel_info
.vl_width
>= panel_info
.logo_width
) {
384 x
= ((panel_info
.vl_width
- panel_info
.logo_width
) >> 1);
385 x
+= panel_info
.logo_x_offset
; /* For X center align */
388 printf("Warning: image width is bigger than display width\n");
391 if (panel_info
.vl_height
>= panel_info
.logo_height
) {
392 y
= ((panel_info
.vl_height
- panel_info
.logo_height
) >> 1);
393 y
+= panel_info
.logo_y_offset
; /* For Y center align */
396 printf("Warning: image height is bigger than display height\n");
399 bmp_display(addr
, x
, y
);
401 #endif /* CONFIG_CMD_BMP */