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 <asm/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_LCD_MENU
25 static int power_key_pressed(u32 reg)
31 pmic = pmic_get(KEY_PWR_PMIC_NAME);
33 printf("%s: Not found\n", KEY_PWR_PMIC_NAME);
40 if (reg == KEY_PWR_STATUS_REG)
41 mask = KEY_PWR_STATUS_MASK;
43 mask = KEY_PWR_INTERRUPT_MASK;
45 if (pmic_reg_read(pmic, reg, &status))
48 return !!(status & mask);
51 static int key_pressed(int key)
57 value = power_key_pressed(KEY_PWR_INTERRUPT_REG);
60 value = !gpio_get_value(KEY_VOL_UP_GPIO);
63 value = !gpio_get_value(KEY_VOL_DOWN_GPIO);
73 static int check_keys(void)
77 if (key_pressed(KEY_POWER))
79 if (key_pressed(KEY_VOLUMEUP))
81 if (key_pressed(KEY_VOLUMEDOWN))
82 keys += KEY_VOLUMEDOWN;
95 mode_name[BOOT_MODE_EXIT + 1] = {
104 mode_info[BOOT_MODE_EXIT + 1] = {
109 "and run normal boot"
112 #define MODE_CMD_ARGC 4
115 mode_cmd[BOOT_MODE_EXIT + 1][MODE_CMD_ARGC] = {
117 {"thor", "0", "mmc", "0"},
118 {"ums", "0", "mmc", "0"},
119 {"dfu", "0", "mmc", "0"},
123 static void display_board_info(void)
125 #ifdef CONFIG_GENERIC_MMC
126 struct mmc *mmc = find_mmc_device(0);
128 vidinfo_t *vid = &panel_info;
130 lcd_position_cursor(4, 4);
132 lcd_printf("%s\n\t", U_BOOT_VERSION);
133 lcd_puts("\n\t\tBoard Info:\n");
134 #ifdef CONFIG_SYS_BOARD
135 lcd_printf("\tBoard name: %s\n", CONFIG_SYS_BOARD);
137 #ifdef CONFIG_REVISION_TAG
138 lcd_printf("\tBoard rev: %u\n", get_board_rev());
140 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS);
141 lcd_printf("\tDRAM size: %u MB\n", gd->ram_size / SZ_1M);
143 #ifdef CONFIG_GENERIC_MMC
148 lcd_printf("\teMMC size: %llu MB\n", mmc->capacity / SZ_1M);
152 lcd_printf("\tDisplay resolution: %u x % u\n",
153 vid->vl_col, vid->vl_row);
155 lcd_printf("\tDisplay BPP: %u\n", 1 << vid->vl_bpix);
158 static int mode_leave_menu(int mode)
161 char *exit_boot = "boot";
162 char *exit_back = "back";
174 display_board_info();
175 exit_option = exit_back;
179 cmd = find_cmd(mode_cmd[mode][0]);
181 printf("Enter: %s %s\n", mode_name[mode],
183 lcd_printf("\n\n\t%s %s\n", mode_name[mode],
185 lcd_puts("\n\tDo not turn off device before finish!\n");
187 cmd_result = cmd_process(0, MODE_CMD_ARGC,
189 &cmd_repeatable, NULL);
191 if (cmd_result == CMD_RET_SUCCESS) {
192 printf("Command finished\n");
194 lcd_printf("\n\n\t%s finished\n",
197 exit_option = exit_boot;
200 printf("Command error\n");
202 lcd_printf("\n\n\t%s command error\n",
205 exit_option = exit_back;
209 lcd_puts("\n\n\tThis mode is not supported.\n");
210 exit_option = exit_back;
215 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option);
217 /* Clear PWR button Rising edge interrupt status flag */
218 power_key_pressed(KEY_PWR_INTERRUPT_REG);
220 /* Wait for PWR key */
221 while (!key_pressed(KEY_POWER))
228 static void display_download_menu(int mode)
230 char *selection[BOOT_MODE_EXIT + 1];
233 for (i = 0; i <= BOOT_MODE_EXIT; i++)
234 selection[i] = "[ ]";
236 selection[mode] = "[=>]";
239 lcd_printf("\n\t\tDownload Mode Menu\n");
241 for (i = 0; i <= BOOT_MODE_EXIT; i++)
242 lcd_printf("\t%s %s - %s\n\n", selection[i],
247 static void download_menu(void)
254 display_download_menu(mode);
259 if (mode != last_mode)
260 display_download_menu(mode);
275 if (mode < BOOT_MODE_EXIT)
283 if (mode_leave_menu(mode))
286 display_download_menu(mode);
293 static void display_mode_info(void)
295 lcd_position_cursor(4, 4);
296 lcd_printf("%s\n", U_BOOT_VERSION);
297 lcd_puts("\nDownload Mode Menu\n");
298 #ifdef CONFIG_SYS_BOARD
299 lcd_printf("Board name: %s\n", CONFIG_SYS_BOARD);
301 lcd_printf("Press POWER KEY to display MENU options.");
304 static int boot_menu(void)
312 lcd_printf("\rNormal boot will start in: %d seconds.", timeout);
315 key = key_pressed(KEY_POWER);
322 /* If PWR pressed - show download menu */
324 printf("Power pressed - go to download menu\n");
326 printf("Download mode exit.\n");
332 void check_boot_mode(void)
336 pwr_key = power_key_pressed(KEY_PWR_STATUS_REG);
340 /* Clear PWR button Rising edge interrupt status flag */
341 power_key_pressed(KEY_PWR_INTERRUPT_REG);
343 if (key_pressed(KEY_VOLUMEUP))
345 else if (key_pressed(KEY_VOLUMEDOWN))
346 mode_leave_menu(BOOT_MODE_THOR);
351 /* Set direction to input */
352 gpio_direction_input(KEY_VOL_UP_GPIO);
353 gpio_direction_input(KEY_VOL_DOWN_GPIO);
355 #endif /* CONFIG_LCD_MENU */
357 #ifdef CONFIG_CMD_BMP
363 addr = panel_info.logo_addr;
365 error("There is no logo data.");
369 if (panel_info.vl_width >= panel_info.logo_width) {
370 x = ((panel_info.vl_width - panel_info.logo_width) >> 1);
371 x += panel_info.logo_x_offset; /* For X center align */
374 printf("Warning: image width is bigger than display width\n");
377 if (panel_info.vl_height >= panel_info.logo_height) {
378 y = ((panel_info.vl_height - panel_info.logo_height) >> 1);
379 y += panel_info.logo_y_offset; /* For Y center align */
382 printf("Warning: image height is bigger than display height\n");
385 bmp_display(addr, x, y);
387 #endif /* CONFIG_CMD_BMP */