summaryrefslogtreecommitdiff
path: root/common/cmd_showlogo.c
blob: ae854cae7d3a6f9682cee4cd3d3620b5229e1e40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 * Copyright (C) 2015 Hardkernel Co,. Ltd
 * Dongjin Kim <tobetter@gmail.com>
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <command.h>
#include <asm/errno.h>
#include <vsprintf.h>
#include <linux/kernel.h>

#ifdef CONFIG_DISPLAY_LOGO
static struct c2_resolution {
	const char *name;
	int display_width;
	int display_height;
} c2_res_list[] = {
	{"480cvbs", 720, 480},
	{"576cvbs", 720, 576},
	{"480p60hz", 720, 480},
	{"576p50hz", 720, 576},
	{"720p60hz", 1280, 720},
	{"720p50hz", 1280, 720},
	{"1080p60hz", 1920, 1080},
	{"1080p50hz", 1920, 1080},
	{"1080p30hz", 1920, 1080},
	{"1080p24hz", 1920, 1080},
	{"1080i60hz", 1920, 1080},
	{"1080i50hz", 1920, 1080},
	{"2160p60hz", 3840, 2160},
	{"2160p50hz", 3840, 2160},
	{"2160p30hz", 3840, 2160},
	{"2160p25hz", 3840, 2160},
	{"2160p24hz", 3840, 2160},
	{"2160p60hz420", 3840, 2160},
	{"2160p50hz420", 3840, 2160},
	{"640x480p60hz", 640, 480},
	{"800x480p60hz", 800, 480},
	{"800x600p60hz", 800, 600},
	{"1024x600p60hz", 1024, 600},
	{"1024x768p60hz", 1024, 768},
	{"1280x800p60hz", 1280, 800},
	{"1280x1024p60hz", 1280, 1024},
	{"1360x768p60hz", 1360, 768},
	{"1440x900p60hz", 1440, 900},
	{"1600x900p60hz", 1600, 900},
	{"1600x1200p60hz", 1600, 1200},
	{"1680x1050p60hz", 1680, 1050},
	{"1920x1200p60hz", 1920, 1200},
	{"2560x1600p60hz", 2560, 1600},
	{"2560x1440p60hz", 2560, 1440},
	{"2560x1080p60hz", 2560, 1080},
	{"3440x1440p60hz", 3440, 1440},
	/* for custombuilt, default size is supported on uboot */
	{"custombuilt", 1920, 1080},
};

static int display_logo(const char* mode, const char* bmp_width, const char* bmp_height)
{
	int ret = 0;
	int i = 0;

	for (i = 0; i < ARRAY_SIZE(c2_res_list); ++i) {
		if (!strcmp(c2_res_list[i].name, mode)) {
			if (!strcmp(mode, "custombuilt")) {
				setenv("display_width", getenv("customwidth"));
				setenv("display_height", getenv("customheight"));
			} else {
				setenv("display_width", simple_itoa(c2_res_list[i].display_width));
				setenv("display_height", simple_itoa(c2_res_list[i].display_height));
			}
			break;
		}
	}

	/* If hdmimode is set by invalid mode, u-boot set the default mode(1080p60hz). */
	if (i == ARRAY_SIZE(c2_res_list)) {
		printf("error: '%s' is invalid resolution.\n", mode);
		printf("Set the default resolution. => 1080p60hz.\n");
		mode = "1080p60hz";
		setenv("display_width", "1920");
		setenv("display_height", "1080");
		setenv("hdmimode", "1080p60hz");
		run_command("save", 0);
	}

	setenv("bootlogo_addr", "0x20000000"); /* initrd load address + 0xD0000000 */
#ifdef CONFIG_VIDEO_BMP_GZIP
	ret = run_command("fatload mmc 0 ${bootlogo_addr} boot-logo.bmp.gz", 1);
	if (!ret)	goto display_logo;
#endif
	ret = run_command("fatload mmc 0 ${bootlogo_addr} boot-logo.bmp", 1);
	if (!ret)	goto display_logo;

	ret = run_command("movi read logo 0 ${bootlogo_addr}", 1);
	if (!ret)
		goto display_logo;

	return 1;

display_logo:
	/* for video_hw_init in osd_fb.c */
	setenv("fb_addr", "0x3f800000");
	setenv("display_bpp", "24");
	setenv("display_color_index", "24");
	setenv("display_layer", "osd1");
	setenv("display_color_fg", "0xffff");
	setenv("display_color_bg", "0");
	setenv("cvbsmode", "576cvbs");
	setenv("hdmimode", mode);
	setenv("outputmode", mode);

	setenv("fb_width", bmp_width);
	setenv("fb_height", bmp_height);

	if (NULL == getenv("vout_mode"))
		setenv("vout_mode", "hdmi");

	run_command("hdmitx hpd; osd open; osd clear", 0);
	run_command("vout output ${outputmode}; hdmitx mode ${vout_mode}; hdmitx output ${outputmode}", 0);
	run_command("bmp display ${bootlogo_addr}", 0);
	run_command("bmp scale", 0);
	run_command("setenv logoopt ${display_layer},loaded,${fb_addr},${hdmimode}", 0);

	return 0;
}

static int do_showlogo(cmd_tbl_t *cmdtp, int flag, int argc,
		char *const argv[])
{
	char *mode;

	if (argc <= 1) {
		mode = getenv("hdmimode");
		display_logo((NULL == mode) ? "1080p60hz" : mode, "1280", "720");
	} else if (argc == 4) {
		display_logo(argv[1], argv[2], argv[3]);
	} else {
		display_logo(argv[1], "1280", "720");
	}

	return 0;
}

U_BOOT_CMD(
		showlogo,		4,		0,	do_showlogo,
		"Displaying BMP logo file to HDMI screen with the specified resolution",
		"<resolution> [<bmp_width> <bmp_height>]\n"
		"	resolution - screen resoltuion on HDMI screen\n"
		"		'1080p60hz' will be used by default if missing\n"
		"	bmp_width (optional) - width of logo bmp file\n"
		"		'1280' will be used by default if missing\n"
		"	bmp_height (optional) - height of logo bmp file\n"
		"		'720' will be used by default if missing"
);
#endif  /* CONFIG_DISPLAY_LOGO */

/* vim: set ts=4 sw=4 tw=80: */