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