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