Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Przemyslaw Marczak | 283a320 | 2014-01-22 11:24:12 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013 Samsung Electronics |
| 4 | * Przemyslaw Marczak <p.marczak@samsung.com> |
Przemyslaw Marczak | 283a320 | 2014-01-22 11:24:12 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | adaaa48 | 2019-11-14 12:57:43 -0700 | [diff] [blame] | 8 | #include <command.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 9 | #include <env.h> |
Przemyslaw Marczak | 283a320 | 2014-01-22 11:24:12 +0100 | [diff] [blame] | 10 | #include <lcd.h> |
| 11 | #include <libtizen.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 13 | #include <linux/delay.h> |
Przemyslaw Marczak | 283a320 | 2014-01-22 11:24:12 +0100 | [diff] [blame] | 14 | #include <samsung/misc.h> |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 15 | #include <errno.h> |
| 16 | #include <version.h> |
Przemyslaw Marczak | fa9566f | 2014-09-01 13:50:46 +0200 | [diff] [blame] | 17 | #include <malloc.h> |
Simon Glass | 2dd337a | 2015-09-02 17:24:58 -0600 | [diff] [blame] | 18 | #include <memalign.h> |
Alexey Brodkin | 267d8e2 | 2014-02-26 17:47:58 +0400 | [diff] [blame] | 19 | #include <linux/sizes.h> |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 20 | #include <asm/arch/cpu.h> |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 21 | #include <asm/gpio.h> |
| 22 | #include <linux/input.h> |
Przemyslaw Marczak | e7781bc | 2015-05-13 13:38:25 +0200 | [diff] [blame] | 23 | #include <dm.h> |
Simon Glass | 19eb118 | 2017-05-18 20:09:31 -0600 | [diff] [blame] | 24 | /* |
| 25 | * Use #ifdef to work around conflicting headers while we wait for this to be |
| 26 | * converted to driver model. |
| 27 | */ |
| 28 | #ifdef CONFIG_DM_PMIC_MAX77686 |
| 29 | #include <power/max77686_pmic.h> |
| 30 | #endif |
| 31 | #ifdef CONFIG_DM_PMIC_MAX8998 |
| 32 | #include <power/max8998_pmic.h> |
| 33 | #endif |
| 34 | #ifdef CONFIG_PMIC_MAX8997 |
| 35 | #include <power/max8997_pmic.h> |
| 36 | #endif |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 37 | #include <power/pmic.h> |
| 38 | #include <mmc.h> |
| 39 | |
| 40 | DECLARE_GLOBAL_DATA_PTR; |
| 41 | |
Przemyslaw Marczak | fa9566f | 2014-09-01 13:50:46 +0200 | [diff] [blame] | 42 | #ifdef CONFIG_SET_DFU_ALT_INFO |
Przemyslaw Marczak | d0dd609 | 2015-02-17 12:24:11 +0100 | [diff] [blame] | 43 | void set_dfu_alt_info(char *interface, char *devstr) |
Przemyslaw Marczak | fa9566f | 2014-09-01 13:50:46 +0200 | [diff] [blame] | 44 | { |
| 45 | size_t buf_size = CONFIG_SET_DFU_ALT_BUF_LEN; |
| 46 | ALLOC_CACHE_ALIGN_BUFFER(char, buf, buf_size); |
| 47 | char *alt_info = "Settings not found!"; |
| 48 | char *status = "error!\n"; |
| 49 | char *alt_setting; |
| 50 | char *alt_sep; |
| 51 | int offset = 0; |
| 52 | |
| 53 | puts("DFU alt info setting: "); |
| 54 | |
Przemyslaw Marczak | d0dd609 | 2015-02-17 12:24:11 +0100 | [diff] [blame] | 55 | alt_setting = get_dfu_alt_boot(interface, devstr); |
Przemyslaw Marczak | fa9566f | 2014-09-01 13:50:46 +0200 | [diff] [blame] | 56 | if (alt_setting) { |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 57 | env_set("dfu_alt_boot", alt_setting); |
Przemyslaw Marczak | fa9566f | 2014-09-01 13:50:46 +0200 | [diff] [blame] | 58 | offset = snprintf(buf, buf_size, "%s", alt_setting); |
| 59 | } |
| 60 | |
Przemyslaw Marczak | d0dd609 | 2015-02-17 12:24:11 +0100 | [diff] [blame] | 61 | alt_setting = get_dfu_alt_system(interface, devstr); |
Przemyslaw Marczak | fa9566f | 2014-09-01 13:50:46 +0200 | [diff] [blame] | 62 | if (alt_setting) { |
| 63 | if (offset) |
| 64 | alt_sep = ";"; |
| 65 | else |
| 66 | alt_sep = ""; |
| 67 | |
| 68 | offset += snprintf(buf + offset, buf_size - offset, |
| 69 | "%s%s", alt_sep, alt_setting); |
| 70 | } |
| 71 | |
| 72 | if (offset) { |
| 73 | alt_info = buf; |
| 74 | status = "done\n"; |
| 75 | } |
| 76 | |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 77 | env_set("dfu_alt_info", alt_info); |
Przemyslaw Marczak | fa9566f | 2014-09-01 13:50:46 +0200 | [diff] [blame] | 78 | puts(status); |
| 79 | } |
| 80 | #endif |
| 81 | |
Piotr Wilczek | 1b5c766 | 2014-01-22 15:54:32 +0100 | [diff] [blame] | 82 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 83 | void set_board_info(void) |
| 84 | { |
| 85 | char info[64]; |
| 86 | |
Przemyslaw Marczak | b8b0724 | 2014-09-01 13:50:42 +0200 | [diff] [blame] | 87 | snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev & 0xf0) >> 4, |
| 88 | s5p_cpu_rev & 0xf); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 89 | env_set("soc_rev", info); |
Piotr Wilczek | 1b5c766 | 2014-01-22 15:54:32 +0100 | [diff] [blame] | 90 | |
| 91 | snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 92 | env_set("soc_id", info); |
Piotr Wilczek | 1b5c766 | 2014-01-22 15:54:32 +0100 | [diff] [blame] | 93 | |
| 94 | #ifdef CONFIG_REVISION_TAG |
| 95 | snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev()); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 96 | env_set("board_rev", info); |
Piotr Wilczek | 1b5c766 | 2014-01-22 15:54:32 +0100 | [diff] [blame] | 97 | #endif |
| 98 | #ifdef CONFIG_OF_LIBFDT |
Przemyslaw Marczak | 2cadc4d | 2014-09-01 13:50:50 +0200 | [diff] [blame] | 99 | const char *bdtype = ""; |
| 100 | const char *bdname = CONFIG_SYS_BOARD; |
| 101 | |
| 102 | #ifdef CONFIG_BOARD_TYPES |
| 103 | bdtype = get_board_type(); |
Przemyslaw Marczak | 5b8bbbf | 2015-10-27 13:07:54 +0100 | [diff] [blame] | 104 | if (!bdtype) |
| 105 | bdtype = ""; |
| 106 | |
Przemyslaw Marczak | 2cadc4d | 2014-09-01 13:50:50 +0200 | [diff] [blame] | 107 | sprintf(info, "%s%s", bdname, bdtype); |
Krzysztof Kozlowski | f4befd4 | 2019-02-22 19:36:43 +0100 | [diff] [blame] | 108 | env_set("board_name", info); |
Przemyslaw Marczak | 2cadc4d | 2014-09-01 13:50:50 +0200 | [diff] [blame] | 109 | #endif |
| 110 | snprintf(info, ARRAY_SIZE(info), "%s%x-%s%s.dtb", |
| 111 | CONFIG_SYS_SOC, s5p_cpu_id, bdname, bdtype); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 112 | env_set("fdtfile", info); |
Piotr Wilczek | 1b5c766 | 2014-01-22 15:54:32 +0100 | [diff] [blame] | 113 | #endif |
| 114 | } |
| 115 | #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */ |
| 116 | |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 117 | #ifdef CONFIG_LCD_MENU |
| 118 | static int power_key_pressed(u32 reg) |
| 119 | { |
Jaehoon Chung | 4cc3c8b | 2021-02-23 07:28:22 +0900 | [diff] [blame] | 120 | struct udevice *dev; |
| 121 | int ret; |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 122 | u32 status; |
| 123 | u32 mask; |
| 124 | |
Jaehoon Chung | 4cc3c8b | 2021-02-23 07:28:22 +0900 | [diff] [blame] | 125 | if (IS_ENABLED(CONFIG_TARGET_TRATS)) |
| 126 | ret = pmic_get("max8997-pmic", &dev); |
| 127 | else if (IS_ENABLED(CONFIG_TARGET_TRATS2)) |
| 128 | ret = pmic_get("max77686-pmic", &dev); |
| 129 | else if (IS_ENABLED(CONFIG_TARGET_S5PC210_UNIVERSAL)) |
| 130 | ret = pmic_get("max8998-pmic", &dev); |
| 131 | else |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 132 | return 0; |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 133 | |
Jaehoon Chung | 4cc3c8b | 2021-02-23 07:28:22 +0900 | [diff] [blame] | 134 | if (ret) |
| 135 | return ret; |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 136 | |
| 137 | if (reg == KEY_PWR_STATUS_REG) |
| 138 | mask = KEY_PWR_STATUS_MASK; |
| 139 | else |
| 140 | mask = KEY_PWR_INTERRUPT_MASK; |
| 141 | |
Jaehoon Chung | 4cc3c8b | 2021-02-23 07:28:22 +0900 | [diff] [blame] | 142 | status = pmic_reg_read(dev, reg); |
| 143 | if (status < 0) |
| 144 | return status; |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 145 | |
| 146 | return !!(status & mask); |
| 147 | } |
| 148 | |
| 149 | static int key_pressed(int key) |
| 150 | { |
| 151 | int value; |
| 152 | |
| 153 | switch (key) { |
| 154 | case KEY_POWER: |
| 155 | value = power_key_pressed(KEY_PWR_INTERRUPT_REG); |
| 156 | break; |
| 157 | case KEY_VOLUMEUP: |
| 158 | value = !gpio_get_value(KEY_VOL_UP_GPIO); |
| 159 | break; |
| 160 | case KEY_VOLUMEDOWN: |
| 161 | value = !gpio_get_value(KEY_VOL_DOWN_GPIO); |
| 162 | break; |
| 163 | default: |
| 164 | value = 0; |
| 165 | break; |
| 166 | } |
| 167 | |
| 168 | return value; |
| 169 | } |
| 170 | |
Simon Glass | a216f72 | 2016-02-21 21:08:53 -0700 | [diff] [blame] | 171 | #ifdef CONFIG_LCD |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 172 | static int check_keys(void) |
| 173 | { |
| 174 | int keys = 0; |
| 175 | |
| 176 | if (key_pressed(KEY_POWER)) |
| 177 | keys += KEY_POWER; |
| 178 | if (key_pressed(KEY_VOLUMEUP)) |
| 179 | keys += KEY_VOLUMEUP; |
| 180 | if (key_pressed(KEY_VOLUMEDOWN)) |
| 181 | keys += KEY_VOLUMEDOWN; |
| 182 | |
| 183 | return keys; |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * 0 BOOT_MODE_INFO |
| 188 | * 1 BOOT_MODE_THOR |
| 189 | * 2 BOOT_MODE_UMS |
| 190 | * 3 BOOT_MODE_DFU |
| 191 | * 4 BOOT_MODE_EXIT |
| 192 | */ |
| 193 | static char * |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 194 | mode_name[BOOT_MODE_EXIT + 1][2] = { |
| 195 | {"DEVICE", ""}, |
| 196 | {"THOR", "thor"}, |
| 197 | {"UMS", "ums"}, |
| 198 | {"DFU", "dfu"}, |
Przemyslaw Marczak | 713f223 | 2014-04-30 13:28:07 +0200 | [diff] [blame] | 199 | {"GPT", "gpt"}, |
Inha Song | 88bc5f7 | 2014-04-30 13:28:08 +0200 | [diff] [blame] | 200 | {"ENV", "env"}, |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 201 | {"EXIT", ""}, |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | static char * |
| 205 | mode_info[BOOT_MODE_EXIT + 1] = { |
| 206 | "info", |
| 207 | "downloader", |
| 208 | "mass storage", |
| 209 | "firmware update", |
Przemyslaw Marczak | 713f223 | 2014-04-30 13:28:07 +0200 | [diff] [blame] | 210 | "restore", |
Inha Song | 88bc5f7 | 2014-04-30 13:28:08 +0200 | [diff] [blame] | 211 | "default", |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 212 | "and run normal boot" |
| 213 | }; |
| 214 | |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 215 | static char * |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 216 | mode_cmd[BOOT_MODE_EXIT + 1] = { |
| 217 | "", |
| 218 | "thor 0 mmc 0", |
| 219 | "ums 0 mmc 0", |
| 220 | "dfu 0 mmc 0", |
Przemyslaw Marczak | 713f223 | 2014-04-30 13:28:07 +0200 | [diff] [blame] | 221 | "gpt write mmc 0 $partitions", |
Inha Song | 88bc5f7 | 2014-04-30 13:28:08 +0200 | [diff] [blame] | 222 | "env default -a; saveenv", |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 223 | "", |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 224 | }; |
| 225 | |
| 226 | static void display_board_info(void) |
| 227 | { |
Masahiro Yamada | 0a78017 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 228 | #ifdef CONFIG_MMC |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 229 | struct mmc *mmc = find_mmc_device(0); |
| 230 | #endif |
| 231 | vidinfo_t *vid = &panel_info; |
| 232 | |
| 233 | lcd_position_cursor(4, 4); |
| 234 | |
| 235 | lcd_printf("%s\n\t", U_BOOT_VERSION); |
| 236 | lcd_puts("\n\t\tBoard Info:\n"); |
| 237 | #ifdef CONFIG_SYS_BOARD |
| 238 | lcd_printf("\tBoard name: %s\n", CONFIG_SYS_BOARD); |
| 239 | #endif |
| 240 | #ifdef CONFIG_REVISION_TAG |
| 241 | lcd_printf("\tBoard rev: %u\n", get_board_rev()); |
| 242 | #endif |
| 243 | lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS); |
| 244 | lcd_printf("\tDRAM size: %u MB\n", gd->ram_size / SZ_1M); |
| 245 | |
Masahiro Yamada | 0a78017 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 246 | #ifdef CONFIG_MMC |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 247 | if (mmc) { |
| 248 | if (!mmc->capacity) |
| 249 | mmc_init(mmc); |
| 250 | |
| 251 | lcd_printf("\teMMC size: %llu MB\n", mmc->capacity / SZ_1M); |
| 252 | } |
| 253 | #endif |
| 254 | if (vid) |
| 255 | lcd_printf("\tDisplay resolution: %u x % u\n", |
| 256 | vid->vl_col, vid->vl_row); |
| 257 | |
| 258 | lcd_printf("\tDisplay BPP: %u\n", 1 << vid->vl_bpix); |
| 259 | } |
Simon Glass | a216f72 | 2016-02-21 21:08:53 -0700 | [diff] [blame] | 260 | #endif |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 261 | |
| 262 | static int mode_leave_menu(int mode) |
| 263 | { |
Simon Glass | a216f72 | 2016-02-21 21:08:53 -0700 | [diff] [blame] | 264 | #ifdef CONFIG_LCD |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 265 | char *exit_option; |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 266 | char *exit_reset = "reset"; |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 267 | char *exit_back = "back"; |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 268 | struct cmd_tbl *cmd; |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 269 | int cmd_result; |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 270 | int leave; |
| 271 | |
| 272 | lcd_clear(); |
| 273 | |
| 274 | switch (mode) { |
| 275 | case BOOT_MODE_EXIT: |
| 276 | return 1; |
| 277 | case BOOT_MODE_INFO: |
| 278 | display_board_info(); |
| 279 | exit_option = exit_back; |
| 280 | leave = 0; |
| 281 | break; |
| 282 | default: |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 283 | cmd = find_cmd(mode_name[mode][1]); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 284 | if (cmd) { |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 285 | printf("Enter: %s %s\n", mode_name[mode][0], |
Minkyu Kang | 1dcc63d | 2015-10-23 16:21:20 +0900 | [diff] [blame] | 286 | mode_info[mode]); |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 287 | lcd_printf("\n\n\t%s %s\n", mode_name[mode][0], |
Minkyu Kang | 1dcc63d | 2015-10-23 16:21:20 +0900 | [diff] [blame] | 288 | mode_info[mode]); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 289 | lcd_puts("\n\tDo not turn off device before finish!\n"); |
| 290 | |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 291 | cmd_result = run_command(mode_cmd[mode], 0); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 292 | |
| 293 | if (cmd_result == CMD_RET_SUCCESS) { |
| 294 | printf("Command finished\n"); |
| 295 | lcd_clear(); |
| 296 | lcd_printf("\n\n\t%s finished\n", |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 297 | mode_name[mode][0]); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 298 | |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 299 | exit_option = exit_reset; |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 300 | leave = 1; |
| 301 | } else { |
| 302 | printf("Command error\n"); |
| 303 | lcd_clear(); |
| 304 | lcd_printf("\n\n\t%s command error\n", |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 305 | mode_name[mode][0]); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 306 | |
| 307 | exit_option = exit_back; |
| 308 | leave = 0; |
| 309 | } |
| 310 | } else { |
| 311 | lcd_puts("\n\n\tThis mode is not supported.\n"); |
| 312 | exit_option = exit_back; |
| 313 | leave = 0; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option); |
| 318 | |
| 319 | /* Clear PWR button Rising edge interrupt status flag */ |
| 320 | power_key_pressed(KEY_PWR_INTERRUPT_REG); |
| 321 | |
| 322 | /* Wait for PWR key */ |
| 323 | while (!key_pressed(KEY_POWER)) |
| 324 | mdelay(1); |
| 325 | |
| 326 | lcd_clear(); |
| 327 | return leave; |
Simon Glass | a216f72 | 2016-02-21 21:08:53 -0700 | [diff] [blame] | 328 | #else |
| 329 | return 0; |
| 330 | #endif |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 331 | } |
| 332 | |
Simon Glass | a216f72 | 2016-02-21 21:08:53 -0700 | [diff] [blame] | 333 | #ifdef CONFIG_LCD |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 334 | static void display_download_menu(int mode) |
| 335 | { |
| 336 | char *selection[BOOT_MODE_EXIT + 1]; |
| 337 | int i; |
| 338 | |
| 339 | for (i = 0; i <= BOOT_MODE_EXIT; i++) |
| 340 | selection[i] = "[ ]"; |
| 341 | |
| 342 | selection[mode] = "[=>]"; |
| 343 | |
| 344 | lcd_clear(); |
Przemyslaw Marczak | 6d34c99 | 2014-04-30 13:28:10 +0200 | [diff] [blame] | 345 | lcd_printf("\n\n\t\tDownload Mode Menu\n\n"); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 346 | |
| 347 | for (i = 0; i <= BOOT_MODE_EXIT; i++) |
| 348 | lcd_printf("\t%s %s - %s\n\n", selection[i], |
Minkyu Kang | 1dcc63d | 2015-10-23 16:21:20 +0900 | [diff] [blame] | 349 | mode_name[i][0], mode_info[i]); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 350 | } |
Simon Glass | a216f72 | 2016-02-21 21:08:53 -0700 | [diff] [blame] | 351 | #endif |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 352 | |
| 353 | static void download_menu(void) |
| 354 | { |
Simon Glass | a216f72 | 2016-02-21 21:08:53 -0700 | [diff] [blame] | 355 | #ifdef CONFIG_LCD |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 356 | int mode = 0; |
| 357 | int last_mode = 0; |
| 358 | int run; |
Przemyslaw Marczak | 6d34c99 | 2014-04-30 13:28:10 +0200 | [diff] [blame] | 359 | int key = 0; |
| 360 | int timeout = 15; /* sec */ |
| 361 | int i; |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 362 | |
| 363 | display_download_menu(mode); |
| 364 | |
Przemyslaw Marczak | 6d34c99 | 2014-04-30 13:28:10 +0200 | [diff] [blame] | 365 | lcd_puts("\n"); |
| 366 | |
| 367 | /* Start count if no key is pressed */ |
| 368 | while (check_keys()) |
| 369 | continue; |
| 370 | |
| 371 | while (timeout--) { |
| 372 | lcd_printf("\r\tNormal boot will start in: %2.d seconds.", |
| 373 | timeout); |
| 374 | |
| 375 | /* about 1000 ms in for loop */ |
| 376 | for (i = 0; i < 10; i++) { |
| 377 | mdelay(100); |
| 378 | key = check_keys(); |
| 379 | if (key) |
| 380 | break; |
| 381 | } |
| 382 | if (key) |
| 383 | break; |
| 384 | } |
| 385 | |
| 386 | if (!key) { |
| 387 | lcd_clear(); |
| 388 | return; |
| 389 | } |
| 390 | |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 391 | while (1) { |
| 392 | run = 0; |
| 393 | |
| 394 | if (mode != last_mode) |
| 395 | display_download_menu(mode); |
| 396 | |
| 397 | last_mode = mode; |
Przemyslaw Marczak | 399e2e9 | 2014-04-30 13:28:09 +0200 | [diff] [blame] | 398 | mdelay(200); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 399 | |
| 400 | key = check_keys(); |
| 401 | switch (key) { |
| 402 | case KEY_POWER: |
| 403 | run = 1; |
| 404 | break; |
| 405 | case KEY_VOLUMEUP: |
| 406 | if (mode > 0) |
| 407 | mode--; |
| 408 | break; |
| 409 | case KEY_VOLUMEDOWN: |
| 410 | if (mode < BOOT_MODE_EXIT) |
| 411 | mode++; |
| 412 | break; |
| 413 | default: |
| 414 | break; |
| 415 | } |
| 416 | |
| 417 | if (run) { |
| 418 | if (mode_leave_menu(mode)) |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 419 | run_command("reset", 0); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 420 | |
| 421 | display_download_menu(mode); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | lcd_clear(); |
Simon Glass | a216f72 | 2016-02-21 21:08:53 -0700 | [diff] [blame] | 426 | #endif |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | void check_boot_mode(void) |
| 430 | { |
| 431 | int pwr_key; |
| 432 | |
| 433 | pwr_key = power_key_pressed(KEY_PWR_STATUS_REG); |
| 434 | if (!pwr_key) |
| 435 | return; |
| 436 | |
| 437 | /* Clear PWR button Rising edge interrupt status flag */ |
| 438 | power_key_pressed(KEY_PWR_INTERRUPT_REG); |
| 439 | |
| 440 | if (key_pressed(KEY_VOLUMEUP)) |
Przemyslaw Marczak | 6d34c99 | 2014-04-30 13:28:10 +0200 | [diff] [blame] | 441 | download_menu(); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 442 | else if (key_pressed(KEY_VOLUMEDOWN)) |
| 443 | mode_leave_menu(BOOT_MODE_THOR); |
| 444 | } |
| 445 | |
| 446 | void keys_init(void) |
| 447 | { |
| 448 | /* Set direction to input */ |
Simon Glass | 4f83d3d | 2014-10-20 19:48:39 -0600 | [diff] [blame] | 449 | gpio_request(KEY_VOL_UP_GPIO, "volume-up"); |
| 450 | gpio_request(KEY_VOL_DOWN_GPIO, "volume-down"); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 451 | gpio_direction_input(KEY_VOL_UP_GPIO); |
| 452 | gpio_direction_input(KEY_VOL_DOWN_GPIO); |
| 453 | } |
| 454 | #endif /* CONFIG_LCD_MENU */ |
Przemyslaw Marczak | 283a320 | 2014-01-22 11:24:12 +0100 | [diff] [blame] | 455 | |
| 456 | #ifdef CONFIG_CMD_BMP |
| 457 | void draw_logo(void) |
| 458 | { |
| 459 | int x, y; |
| 460 | ulong addr; |
| 461 | |
| 462 | addr = panel_info.logo_addr; |
| 463 | if (!addr) { |
Seung-Woo Kim | ca21166 | 2018-06-04 16:03:05 +0900 | [diff] [blame] | 464 | pr_err("There is no logo data.\n"); |
Przemyslaw Marczak | 283a320 | 2014-01-22 11:24:12 +0100 | [diff] [blame] | 465 | return; |
| 466 | } |
| 467 | |
| 468 | if (panel_info.vl_width >= panel_info.logo_width) { |
| 469 | x = ((panel_info.vl_width - panel_info.logo_width) >> 1); |
Przemyslaw Marczak | 02f4a09 | 2013-11-29 18:30:43 +0100 | [diff] [blame] | 470 | x += panel_info.logo_x_offset; /* For X center align */ |
Przemyslaw Marczak | 283a320 | 2014-01-22 11:24:12 +0100 | [diff] [blame] | 471 | } else { |
| 472 | x = 0; |
| 473 | printf("Warning: image width is bigger than display width\n"); |
| 474 | } |
| 475 | |
| 476 | if (panel_info.vl_height >= panel_info.logo_height) { |
| 477 | y = ((panel_info.vl_height - panel_info.logo_height) >> 1); |
Przemyslaw Marczak | 02f4a09 | 2013-11-29 18:30:43 +0100 | [diff] [blame] | 478 | y += panel_info.logo_y_offset; /* For Y center align */ |
Przemyslaw Marczak | 283a320 | 2014-01-22 11:24:12 +0100 | [diff] [blame] | 479 | } else { |
| 480 | y = 0; |
| 481 | printf("Warning: image height is bigger than display height\n"); |
| 482 | } |
| 483 | |
| 484 | bmp_display(addr, x, y); |
| 485 | } |
| 486 | #endif /* CONFIG_CMD_BMP */ |