YoungSoo Shin | 1eac492 | 2025-02-06 16:59:13 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2025 Hardkernel Co,. Ltd |
| 3 | * Dongjin Kim <tobetter@gmail.com> |
| 4 | * |
| 5 | * This driver has been modified to support ODROID-C5. |
| 6 | * Modified by Bob Shin <bob.shin@hardkernel.com> |
| 7 | * |
| 8 | * SPDX-License-Identifier: GPL-2.0+ |
| 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <command.h> |
Dongjin Kim | 922e044 | 2025-02-27 18:03:38 +0900 | [diff] [blame] | 13 | #include <fs.h> |
| 14 | #include <mmc.h> |
YoungSoo Shin | 1eac492 | 2025-02-06 16:59:13 +0900 | [diff] [blame] | 15 | #include <vsprintf.h> |
| 16 | |
YoungSoo Shin | 1eac492 | 2025-02-06 16:59:13 +0900 | [diff] [blame] | 17 | static int init_hdmi(const char* mode, bool bestmode) { |
| 18 | /* |
| 19 | * TODO reboot mode |
| 20 | * run_command("get_rebootmode", 0); |
| 21 | * rbm = env_get("reboot_mode"); |
| 22 | * if rbm in {quiescent, recovery_quiescent} then pass hdmi init |
| 23 | */ |
| 24 | int ret; |
| 25 | env_set("hdmimode", mode); |
| 26 | |
| 27 | if (bestmode == false) { |
| 28 | env_set("is.bestmode", "false"); |
| 29 | } |
| 30 | |
| 31 | /* hdmi config */ |
| 32 | ret = run_command("hdmitx hpd", 0); |
YoungSoo Shin | 4e3b3a8 | 2025-03-04 15:44:19 +0900 | [diff] [blame] | 33 | if (ret == 0) { |
YoungSoo Shin | 1eac492 | 2025-02-06 16:59:13 +0900 | [diff] [blame] | 34 | printf("hdmi not connected!\n"); |
| 35 | return -1; |
| 36 | } |
| 37 | |
| 38 | ret = run_command("hdmitx get_parse_edid", 0); |
| 39 | if (ret < 0) { |
| 40 | printf("edid parse fail!\n"); |
| 41 | return -1; |
| 42 | } |
| 43 | return 0; |
| 44 | } |
| 45 | |
Dongjin Kim | 922e044 | 2025-02-27 18:03:38 +0900 | [diff] [blame] | 46 | static int load_boot_logo(void) |
| 47 | { |
| 48 | const char *logofiles[] = { |
| 49 | #ifdef CONFIG_VIDEO_BMP_GZIP |
| 50 | "boot-logo.bmp.gz", |
| 51 | #endif |
| 52 | "boot-logo.bmp" |
| 53 | }; |
| 54 | |
| 55 | char *dev_type = "mmc"; |
| 56 | char dev_part[16]; |
| 57 | int bootdev = mmc_get_env_dev(); |
| 58 | int i, j; |
| 59 | int ret; |
| 60 | loff_t len; |
| 61 | ulong addr; |
| 62 | |
| 63 | addr = simple_strtoull(env_get("bootlogo_addr"), NULL, 0); |
| 64 | if (!addr) |
| 65 | return 0; |
| 66 | |
| 67 | /* check boot device */ |
| 68 | |
| 69 | for (i = 1; i <= 3; i++) { |
| 70 | sprintf(dev_part, "%d:%d", bootdev, i); |
| 71 | |
| 72 | for (j = 0; j < ARRAY_SIZE(logofiles); j++) { |
| 73 | if (file_exists(dev_type, dev_part, logofiles[j], FS_TYPE_ANY)) { |
| 74 | fs_set_blk_dev(dev_type, dev_part, FS_TYPE_ANY); |
| 75 | ret = fs_read(logofiles[j], addr, 0, 0, &len); |
| 76 | if (ret < 0) { |
| 77 | return 0; |
| 78 | } |
| 79 | return 1; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
YoungSoo Shin | 1eac492 | 2025-02-06 16:59:13 +0900 | [diff] [blame] | 87 | static int display_logo(const char* mode, const char* bmp_width, const char* bmp_height) |
| 88 | { |
| 89 | int ret = 0; |
YoungSoo Shin | 1eac492 | 2025-02-06 16:59:13 +0900 | [diff] [blame] | 90 | int bmp_load = false; |
| 91 | |
| 92 | // TODO bestmode |
| 93 | ret = init_hdmi(mode, true); |
| 94 | if (ret) { |
| 95 | printf("init hdmi fail!\n"); |
| 96 | return -1; |
| 97 | } |
| 98 | |
YoungSoo Shin | 1eac492 | 2025-02-06 16:59:13 +0900 | [diff] [blame] | 99 | env_set("bootlogo_addr", env_get("loadaddr")); |
YoungSoo Shin | 1eac492 | 2025-02-06 16:59:13 +0900 | [diff] [blame] | 100 | |
Dongjin Kim | 922e044 | 2025-02-27 18:03:38 +0900 | [diff] [blame] | 101 | bmp_load = load_boot_logo(); |
YoungSoo Shin | 1eac492 | 2025-02-06 16:59:13 +0900 | [diff] [blame] | 102 | |
| 103 | if (bmp_load) { |
| 104 | /* color */ |
| 105 | env_set("display_bpp", "24"); |
| 106 | env_set("display_color_index", "24"); |
YoungSoo Shin | 1eac492 | 2025-02-06 16:59:13 +0900 | [diff] [blame] | 107 | |
| 108 | /* frame buffer */ |
| 109 | |
| 110 | // option. fb size from disp size |
| 111 | // env_set("fb_width", env_get("display_width")); |
| 112 | // env_set("fb_height", env_get("display_height")); |
| 113 | |
Dongjin Kim | 922e044 | 2025-02-27 18:03:38 +0900 | [diff] [blame] | 114 | // else. fb size from bmp size |
YoungSoo Shin | 1eac492 | 2025-02-06 16:59:13 +0900 | [diff] [blame] | 115 | env_set("fb_width", bmp_width); |
| 116 | env_set("fb_height", bmp_height); |
| 117 | |
| 118 | /* osd, bmp */ |
| 119 | run_command("osd open; osd clear", 0); |
| 120 | run_command("bmp display ${bootlogo_addr}", 0); |
| 121 | run_command("bmp scale", 0); |
| 122 | } |
| 123 | |
| 124 | run_command("vout output $outputmode", 0); |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | static int do_showlogo(cmd_tbl_t *cmdtp, int flag, int argc, |
| 129 | char *const argv[]) |
| 130 | { |
| 131 | char *mode; |
| 132 | |
| 133 | if (argc <= 1) { |
| 134 | mode = env_get("hdmimode"); |
| 135 | /* ODROID default logo size 1280x720 */ |
| 136 | display_logo((NULL == mode ? "none" : mode), "1280", "720"); |
| 137 | } else if (argc == 4) { |
| 138 | display_logo(argv[1], argv[2], argv[3]); |
| 139 | } else { |
| 140 | display_logo(argv[1], "1280", "720"); |
| 141 | } |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | U_BOOT_CMD( |
| 147 | showlogo, 4, 0, do_showlogo, |
| 148 | "Displaying BMP logo file to HDMI screen with the specified resolution", |
| 149 | "<resolution> [<bmp_width> <bmp_height>]\n" |
| 150 | " resolution - screen resoltuion on HDMI screen\n" |
| 151 | " '1080p60hz' will be used by default if missing\n" |
| 152 | " bmp_width (optional) - width of logo bmp file\n" |
| 153 | " '1280' will be used by default if missing\n" |
| 154 | " bmp_height (optional) - height of logo bmp file\n" |
| 155 | " '720' will be used by default if missing" |
| 156 | ); |