Przemyslaw Marczak | 283a320 | 2014-01-22 11:24:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Samsung Electronics |
| 3 | * Przemyslaw Marczak <p.marczak@samsung.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <lcd.h> |
| 10 | #include <libtizen.h> |
| 11 | #include <samsung/misc.h> |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 12 | #include <errno.h> |
| 13 | #include <version.h> |
Alexey Brodkin | 267d8e2 | 2014-02-26 17:47:58 +0400 | [diff] [blame] | 14 | #include <linux/sizes.h> |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 15 | #include <asm/arch/cpu.h> |
| 16 | #include <asm/arch/gpio.h> |
| 17 | #include <asm/gpio.h> |
| 18 | #include <linux/input.h> |
| 19 | #include <power/pmic.h> |
| 20 | #include <mmc.h> |
| 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Piotr Wilczek | 1b5c766 | 2014-01-22 15:54:32 +0100 | [diff] [blame] | 24 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 25 | void set_board_info(void) |
| 26 | { |
| 27 | char info[64]; |
| 28 | |
| 29 | snprintf(info, ARRAY_SIZE(info), "%d.%d", s5p_cpu_rev & 0x0f, |
| 30 | (s5p_cpu_rev & 0xf0) >> 0x04); |
| 31 | setenv("soc_rev", info); |
| 32 | |
| 33 | snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id); |
| 34 | setenv("soc_id", info); |
| 35 | |
| 36 | #ifdef CONFIG_REVISION_TAG |
| 37 | snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev()); |
| 38 | setenv("board_rev", info); |
| 39 | #endif |
| 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); |
| 44 | #endif |
| 45 | } |
| 46 | #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */ |
| 47 | |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 48 | #ifdef CONFIG_LCD_MENU |
| 49 | static int power_key_pressed(u32 reg) |
| 50 | { |
| 51 | struct pmic *pmic; |
| 52 | u32 status; |
| 53 | u32 mask; |
| 54 | |
| 55 | pmic = pmic_get(KEY_PWR_PMIC_NAME); |
| 56 | if (!pmic) { |
| 57 | printf("%s: Not found\n", KEY_PWR_PMIC_NAME); |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | if (pmic_probe(pmic)) |
| 62 | return 0; |
| 63 | |
| 64 | if (reg == KEY_PWR_STATUS_REG) |
| 65 | mask = KEY_PWR_STATUS_MASK; |
| 66 | else |
| 67 | mask = KEY_PWR_INTERRUPT_MASK; |
| 68 | |
| 69 | if (pmic_reg_read(pmic, reg, &status)) |
| 70 | return 0; |
| 71 | |
| 72 | return !!(status & mask); |
| 73 | } |
| 74 | |
| 75 | static int key_pressed(int key) |
| 76 | { |
| 77 | int value; |
| 78 | |
| 79 | switch (key) { |
| 80 | case KEY_POWER: |
| 81 | value = power_key_pressed(KEY_PWR_INTERRUPT_REG); |
| 82 | break; |
| 83 | case KEY_VOLUMEUP: |
| 84 | value = !gpio_get_value(KEY_VOL_UP_GPIO); |
| 85 | break; |
| 86 | case KEY_VOLUMEDOWN: |
| 87 | value = !gpio_get_value(KEY_VOL_DOWN_GPIO); |
| 88 | break; |
| 89 | default: |
| 90 | value = 0; |
| 91 | break; |
| 92 | } |
| 93 | |
| 94 | return value; |
| 95 | } |
| 96 | |
| 97 | static int check_keys(void) |
| 98 | { |
| 99 | int keys = 0; |
| 100 | |
| 101 | if (key_pressed(KEY_POWER)) |
| 102 | keys += KEY_POWER; |
| 103 | if (key_pressed(KEY_VOLUMEUP)) |
| 104 | keys += KEY_VOLUMEUP; |
| 105 | if (key_pressed(KEY_VOLUMEDOWN)) |
| 106 | keys += KEY_VOLUMEDOWN; |
| 107 | |
| 108 | return keys; |
| 109 | } |
| 110 | |
| 111 | /* |
| 112 | * 0 BOOT_MODE_INFO |
| 113 | * 1 BOOT_MODE_THOR |
| 114 | * 2 BOOT_MODE_UMS |
| 115 | * 3 BOOT_MODE_DFU |
| 116 | * 4 BOOT_MODE_EXIT |
| 117 | */ |
| 118 | static char * |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 119 | mode_name[BOOT_MODE_EXIT + 1][2] = { |
| 120 | {"DEVICE", ""}, |
| 121 | {"THOR", "thor"}, |
| 122 | {"UMS", "ums"}, |
| 123 | {"DFU", "dfu"}, |
Przemyslaw Marczak | 713f223 | 2014-04-30 13:28:07 +0200 | [diff] [blame] | 124 | {"GPT", "gpt"}, |
Inha Song | 88bc5f7 | 2014-04-30 13:28:08 +0200 | [diff] [blame] | 125 | {"ENV", "env"}, |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 126 | {"EXIT", ""}, |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | static char * |
| 130 | mode_info[BOOT_MODE_EXIT + 1] = { |
| 131 | "info", |
| 132 | "downloader", |
| 133 | "mass storage", |
| 134 | "firmware update", |
Przemyslaw Marczak | 713f223 | 2014-04-30 13:28:07 +0200 | [diff] [blame] | 135 | "restore", |
Inha Song | 88bc5f7 | 2014-04-30 13:28:08 +0200 | [diff] [blame] | 136 | "default", |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 137 | "and run normal boot" |
| 138 | }; |
| 139 | |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 140 | static char * |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 141 | mode_cmd[BOOT_MODE_EXIT + 1] = { |
| 142 | "", |
| 143 | "thor 0 mmc 0", |
| 144 | "ums 0 mmc 0", |
| 145 | "dfu 0 mmc 0", |
Przemyslaw Marczak | 713f223 | 2014-04-30 13:28:07 +0200 | [diff] [blame] | 146 | "gpt write mmc 0 $partitions", |
Inha Song | 88bc5f7 | 2014-04-30 13:28:08 +0200 | [diff] [blame] | 147 | "env default -a; saveenv", |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 148 | "", |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | static void display_board_info(void) |
| 152 | { |
| 153 | #ifdef CONFIG_GENERIC_MMC |
| 154 | struct mmc *mmc = find_mmc_device(0); |
| 155 | #endif |
| 156 | vidinfo_t *vid = &panel_info; |
| 157 | |
| 158 | lcd_position_cursor(4, 4); |
| 159 | |
| 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); |
| 164 | #endif |
| 165 | #ifdef CONFIG_REVISION_TAG |
| 166 | lcd_printf("\tBoard rev: %u\n", get_board_rev()); |
| 167 | #endif |
| 168 | lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS); |
| 169 | lcd_printf("\tDRAM size: %u MB\n", gd->ram_size / SZ_1M); |
| 170 | |
| 171 | #ifdef CONFIG_GENERIC_MMC |
| 172 | if (mmc) { |
| 173 | if (!mmc->capacity) |
| 174 | mmc_init(mmc); |
| 175 | |
| 176 | lcd_printf("\teMMC size: %llu MB\n", mmc->capacity / SZ_1M); |
| 177 | } |
| 178 | #endif |
| 179 | if (vid) |
| 180 | lcd_printf("\tDisplay resolution: %u x % u\n", |
| 181 | vid->vl_col, vid->vl_row); |
| 182 | |
| 183 | lcd_printf("\tDisplay BPP: %u\n", 1 << vid->vl_bpix); |
| 184 | } |
| 185 | |
| 186 | static int mode_leave_menu(int mode) |
| 187 | { |
| 188 | char *exit_option; |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 189 | char *exit_reset = "reset"; |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 190 | char *exit_back = "back"; |
| 191 | cmd_tbl_t *cmd; |
| 192 | int cmd_result; |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 193 | int leave; |
| 194 | |
| 195 | lcd_clear(); |
| 196 | |
| 197 | switch (mode) { |
| 198 | case BOOT_MODE_EXIT: |
| 199 | return 1; |
| 200 | case BOOT_MODE_INFO: |
| 201 | display_board_info(); |
| 202 | exit_option = exit_back; |
| 203 | leave = 0; |
| 204 | break; |
| 205 | default: |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 206 | cmd = find_cmd(mode_name[mode][1]); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 207 | if (cmd) { |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 208 | printf("Enter: %s %s\n", mode_name[mode][0], |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 209 | mode_info[mode]); |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 210 | lcd_printf("\n\n\t%s %s\n", mode_name[mode][0], |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 211 | mode_info[mode]); |
| 212 | lcd_puts("\n\tDo not turn off device before finish!\n"); |
| 213 | |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 214 | cmd_result = run_command(mode_cmd[mode], 0); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 215 | |
| 216 | if (cmd_result == CMD_RET_SUCCESS) { |
| 217 | printf("Command finished\n"); |
| 218 | lcd_clear(); |
| 219 | lcd_printf("\n\n\t%s finished\n", |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 220 | mode_name[mode][0]); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 221 | |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 222 | exit_option = exit_reset; |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 223 | leave = 1; |
| 224 | } else { |
| 225 | printf("Command error\n"); |
| 226 | lcd_clear(); |
| 227 | lcd_printf("\n\n\t%s command error\n", |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 228 | mode_name[mode][0]); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 229 | |
| 230 | exit_option = exit_back; |
| 231 | leave = 0; |
| 232 | } |
| 233 | } else { |
| 234 | lcd_puts("\n\n\tThis mode is not supported.\n"); |
| 235 | exit_option = exit_back; |
| 236 | leave = 0; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option); |
| 241 | |
| 242 | /* Clear PWR button Rising edge interrupt status flag */ |
| 243 | power_key_pressed(KEY_PWR_INTERRUPT_REG); |
| 244 | |
| 245 | /* Wait for PWR key */ |
| 246 | while (!key_pressed(KEY_POWER)) |
| 247 | mdelay(1); |
| 248 | |
| 249 | lcd_clear(); |
| 250 | return leave; |
| 251 | } |
| 252 | |
| 253 | static void display_download_menu(int mode) |
| 254 | { |
| 255 | char *selection[BOOT_MODE_EXIT + 1]; |
| 256 | int i; |
| 257 | |
| 258 | for (i = 0; i <= BOOT_MODE_EXIT; i++) |
| 259 | selection[i] = "[ ]"; |
| 260 | |
| 261 | selection[mode] = "[=>]"; |
| 262 | |
| 263 | lcd_clear(); |
| 264 | lcd_printf("\n\t\tDownload Mode Menu\n"); |
| 265 | |
| 266 | for (i = 0; i <= BOOT_MODE_EXIT; i++) |
| 267 | lcd_printf("\t%s %s - %s\n\n", selection[i], |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 268 | mode_name[i][0], |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 269 | mode_info[i]); |
| 270 | } |
| 271 | |
| 272 | static void download_menu(void) |
| 273 | { |
| 274 | int mode = 0; |
| 275 | int last_mode = 0; |
| 276 | int run; |
| 277 | int key; |
| 278 | |
| 279 | display_download_menu(mode); |
| 280 | |
| 281 | while (1) { |
| 282 | run = 0; |
| 283 | |
| 284 | if (mode != last_mode) |
| 285 | display_download_menu(mode); |
| 286 | |
| 287 | last_mode = mode; |
Przemyslaw Marczak | 399e2e9 | 2014-04-30 13:28:09 +0200 | [diff] [blame^] | 288 | mdelay(200); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 289 | |
| 290 | key = check_keys(); |
| 291 | switch (key) { |
| 292 | case KEY_POWER: |
| 293 | run = 1; |
| 294 | break; |
| 295 | case KEY_VOLUMEUP: |
| 296 | if (mode > 0) |
| 297 | mode--; |
| 298 | break; |
| 299 | case KEY_VOLUMEDOWN: |
| 300 | if (mode < BOOT_MODE_EXIT) |
| 301 | mode++; |
| 302 | break; |
| 303 | default: |
| 304 | break; |
| 305 | } |
| 306 | |
| 307 | if (run) { |
| 308 | if (mode_leave_menu(mode)) |
Przemyslaw Marczak | c099c27 | 2014-04-30 13:28:06 +0200 | [diff] [blame] | 309 | run_command("reset", 0); |
Przemyslaw Marczak | a8da551 | 2014-01-22 11:24:17 +0100 | [diff] [blame] | 310 | |
| 311 | display_download_menu(mode); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | lcd_clear(); |
| 316 | } |
| 317 | |
| 318 | static void display_mode_info(void) |
| 319 | { |
| 320 | lcd_position_cursor(4, 4); |
| 321 | lcd_printf("%s\n", U_BOOT_VERSION); |
| 322 | lcd_puts("\nDownload Mode Menu\n"); |
| 323 | #ifdef CONFIG_SYS_BOARD |
| 324 | lcd_printf("Board name: %s\n", CONFIG_SYS_BOARD); |
| 325 | #endif |
| 326 | lcd_printf("Press POWER KEY to display MENU options."); |
| 327 | } |
| 328 | |
| 329 | static int boot_menu(void) |
| 330 | { |
| 331 | int key = 0; |
| 332 | int timeout = 10; |
| 333 | |
| 334 | display_mode_info(); |
| 335 | |
| 336 | while (timeout--) { |
| 337 | lcd_printf("\rNormal boot will start in: %d seconds.", timeout); |
| 338 | mdelay(1000); |
| 339 | |
| 340 | key = key_pressed(KEY_POWER); |
| 341 | if (key) |
| 342 | break; |
| 343 | } |
| 344 | |
| 345 | lcd_clear(); |
| 346 | |
| 347 | /* If PWR pressed - show download menu */ |
| 348 | if (key) { |
| 349 | printf("Power pressed - go to download menu\n"); |
| 350 | download_menu(); |
| 351 | printf("Download mode exit.\n"); |
| 352 | } |
| 353 | |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | void check_boot_mode(void) |
| 358 | { |
| 359 | int pwr_key; |
| 360 | |
| 361 | pwr_key = power_key_pressed(KEY_PWR_STATUS_REG); |
| 362 | if (!pwr_key) |
| 363 | return; |
| 364 | |
| 365 | /* Clear PWR button Rising edge interrupt status flag */ |
| 366 | power_key_pressed(KEY_PWR_INTERRUPT_REG); |
| 367 | |
| 368 | if (key_pressed(KEY_VOLUMEUP)) |
| 369 | boot_menu(); |
| 370 | else if (key_pressed(KEY_VOLUMEDOWN)) |
| 371 | mode_leave_menu(BOOT_MODE_THOR); |
| 372 | } |
| 373 | |
| 374 | void keys_init(void) |
| 375 | { |
| 376 | /* Set direction to input */ |
| 377 | gpio_direction_input(KEY_VOL_UP_GPIO); |
| 378 | gpio_direction_input(KEY_VOL_DOWN_GPIO); |
| 379 | } |
| 380 | #endif /* CONFIG_LCD_MENU */ |
Przemyslaw Marczak | 283a320 | 2014-01-22 11:24:12 +0100 | [diff] [blame] | 381 | |
| 382 | #ifdef CONFIG_CMD_BMP |
| 383 | void draw_logo(void) |
| 384 | { |
| 385 | int x, y; |
| 386 | ulong addr; |
| 387 | |
| 388 | addr = panel_info.logo_addr; |
| 389 | if (!addr) { |
| 390 | error("There is no logo data."); |
| 391 | return; |
| 392 | } |
| 393 | |
| 394 | if (panel_info.vl_width >= panel_info.logo_width) { |
| 395 | x = ((panel_info.vl_width - panel_info.logo_width) >> 1); |
Przemyslaw Marczak | 02f4a09 | 2013-11-29 18:30:43 +0100 | [diff] [blame] | 396 | x += panel_info.logo_x_offset; /* For X center align */ |
Przemyslaw Marczak | 283a320 | 2014-01-22 11:24:12 +0100 | [diff] [blame] | 397 | } else { |
| 398 | x = 0; |
| 399 | printf("Warning: image width is bigger than display width\n"); |
| 400 | } |
| 401 | |
| 402 | if (panel_info.vl_height >= panel_info.logo_height) { |
| 403 | y = ((panel_info.vl_height - panel_info.logo_height) >> 1); |
Przemyslaw Marczak | 02f4a09 | 2013-11-29 18:30:43 +0100 | [diff] [blame] | 404 | y += panel_info.logo_y_offset; /* For Y center align */ |
Przemyslaw Marczak | 283a320 | 2014-01-22 11:24:12 +0100 | [diff] [blame] | 405 | } else { |
| 406 | y = 0; |
| 407 | printf("Warning: image height is bigger than display height\n"); |
| 408 | } |
| 409 | |
| 410 | bmp_display(addr, x, y); |
| 411 | } |
| 412 | #endif /* CONFIG_CMD_BMP */ |