1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2012 Samsung Electronics
4 * Donghwa Lee <dh09.lee@samsung.com>
12 #ifdef CONFIG_DM_VIDEO
15 #include <video_console.h>
16 #include <dm/device.h>
17 #include <dm/uclass.h>
20 #include "tizen_logo_16bpp.h"
21 #include "tizen_logo_16bpp_gzip.h"
24 #ifdef CONFIG_VIDEO_BMP_GZIP
25 #include "download_logos_16bpp_gzip.h"
27 #include "download_logos_16bpp.h"
30 #define LOGO_X_OFS ((720 - 480) / 2)
31 #define LOGO_Y_OFS ((1280 - 800) / 2)
32 #define PROGRESS_BAR_WIDTH 4
34 void get_tizen_logo_info(vidinfo_t *vid)
36 switch (vid->vl_bpix) {
38 vid->logo_width = TIZEN_LOGO_16BPP_WIDTH;
39 vid->logo_height = TIZEN_LOGO_16BPP_HEIGHT;
40 vid->logo_x_offset = TIZEN_LOGO_16BPP_X_OFFSET;
41 vid->logo_y_offset = TIZEN_LOGO_16BPP_Y_OFFSET;
42 #if defined(CONFIG_VIDEO_BMP_GZIP)
43 vid->logo_addr = (ulong)tizen_logo_16bpp_gzip;
45 vid->logo_addr = (ulong)tizen_logo_16bpp;
54 void draw_thor_fail_screen(void)
63 bmp_display((unsigned long)download_noti_image, x, y);
68 bmp_display((unsigned long)download_fail_text, x, y);
71 static unsigned int tmp_msg_x, tmp_msg_y;
73 void draw_thor_connected(void)
75 unsigned int prev_console_x, prev_console_y;
77 /* Get curent lcd xy */
78 lcd_get_position_cursor(&prev_console_x, &prev_console_y);
80 /* Set proper lcd xy position for clean unneeded messages */
81 lcd_set_position_cursor(tmp_msg_x, tmp_msg_y);
85 lcd_set_position_cursor(tmp_msg_x, tmp_msg_y);
86 lcd_printf("\n\n\tConnection established.");
88 /* Restore last lcd x y position */
89 lcd_set_position_cursor(prev_console_x, prev_console_y);
92 void draw_thor_screen(void)
97 lcd_printf("\n\n\tTHOR Tizen Downloader");
99 lcd_printf("\n\n\tU-BOOT bootloader info:");
100 lcd_printf("\n\tCompilation date: %s\n\tBinary version: %s\n",
101 U_BOOT_DATE, PLAIN_VERSION);
103 char *pit_compatible = getenv("dfu_alt_pit_compatible");
104 if (pit_compatible) {
105 lcd_printf("\tPlatform compatible with PIT Version: %s\n",
109 lcd_get_position_cursor(&tmp_msg_x, &tmp_msg_y);
111 lcd_printf("\n\n\tPlease connect USB cable.");
112 lcd_printf("\n\n\tFor EXIT press POWERKEY 3 times.\n");
114 x = 199 + LOGO_X_OFS;
115 y = 272 + LOGO_Y_OFS;
117 bmp_display((unsigned long)download_image, x, y);
120 y = 360 + LOGO_Y_OFS;
122 bmp_display((unsigned long)download_text, x, y);
125 y = 445 + LOGO_Y_OFS;
127 bmp_display((unsigned long)prog_base, x, y);
131 void draw_thor_progress(unsigned long long int total_file_size,
132 unsigned long long int downloaded_file_size)
134 static struct bmp_image *progress_bar = NULL;
135 static int last_percent;
138 int current_percent = 0;
142 /* Make shift to prevent int overflow */
143 int divisor = total_file_size >> 7;
144 int divident = 100 * (downloaded_file_size >> 7);
146 if (!divisor || !divident)
149 while (divident > 0) {
155 if (current_percent > 100)
156 current_percent = 100;
158 if (!current_percent)
161 draw_percent = current_percent - last_percent;
166 progress_bar = gunzip_bmp((long unsigned int)prog_middle,
170 progress_bar = (struct bmp_image *)prog_middle;
172 /* set bar position */
174 y = 446 + LOGO_Y_OFS;
176 /* set last bar position */
177 x += last_percent * PROGRESS_BAR_WIDTH;
179 for (i=0; i < draw_percent; i++) {
180 tmp_x = x + i * PROGRESS_BAR_WIDTH;
181 lcd_display_bitmap((unsigned long)progress_bar, tmp_x, y);
184 last_percent = current_percent;
188 #ifdef CONFIG_DM_VIDEO
190 #define PROGRESS_BAR_COLOR 0x0000B3F1
191 #define PROGRESS_FRAME_COLOR 0x00F8FBF9
193 static struct udevice *vidcon_dev;
195 static inline void put_pixel(struct video_priv *vid_priv, int x, int y,
198 u32 *screen = vid_priv->fb;
199 screen[y * vid_priv->xsize + x] = colour;
202 static void draw_progress_bar(unsigned int progress_value)
204 struct udevice *vid_dev = vidcon_dev->parent;
205 struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
206 static int xpos, ypos, bar_width, bar_height;
209 if (bar_width == 0) {
210 xpos = vid_priv->ysize / 8;
211 ypos = vid_priv->ysize * 7 / 8;
212 bar_width = vid_priv->xsize - 2 * xpos;
213 bar_height = vid_priv->ysize * 6 / 256;
216 if (progress_value > 100)
217 progress_value = 100;
219 for (y = ypos; y <= ypos + bar_height; y++) {
220 put_pixel(vid_priv, xpos, y, PROGRESS_FRAME_COLOR);
221 put_pixel(vid_priv, xpos + bar_width, y, PROGRESS_FRAME_COLOR);
224 for (x = xpos; x - xpos < bar_width; x++) {
225 put_pixel(vid_priv, x, ypos, PROGRESS_FRAME_COLOR);
226 put_pixel(vid_priv, x, ypos + bar_height, PROGRESS_FRAME_COLOR);
229 for (y = ypos + 1; y < ypos + bar_height; y++)
230 for (x = 1; x < (bar_width * progress_value / 100); x++)
231 put_pixel(vid_priv, x + xpos, y, PROGRESS_BAR_COLOR);
233 video_sync(vid_dev, false);
236 void thor_status_notify(enum thor_notify_type type, struct thor_notify_data *nd)
238 /* Clear rows 5, 7; output text in rows 5, 7 starting from column 5 */
239 static const char *init_text =
240 "\x1b[5,1f\x1b[2K\x1b[7,1f\x1b[2K\x1b[5,5f\x1b[31mTHOR MODE"
241 "\x1b[7,5f\x1b[31mPlease connect USB cable\33[0m\n";
242 /* Clear row 7, output text starting from column 5 */
243 static const char *conn_text = "\x1b[7,1f\x1b[2K\x1b[7,5f"
244 "\x1b[31mWARNING: Do not power off the device\33[0m\n";
245 /* Clear row 7, output text starting from column 5 */
246 static const char *fail_text = "\x1b[7,1f\x1b[2K\n"
247 "\x1b[7,5f\x1b[31mERROR: Downloading failed!\33[0m\n";
248 unsigned int total_size, current_size;
252 ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &vidcon_dev);
253 if (ret || !vidcon_dev)
258 case THOR_NOTIFY_INIT:
259 vidconsole_put_string(vidcon_dev, init_text);
262 case THOR_NOTIFY_CONNECTED:
263 vidconsole_put_string(vidcon_dev, conn_text);
266 case THOR_NOTIFY_PROGRESS:
269 /* Shift to prevent int overflow */
270 total_size = nd->total_size >> 6;
271 current_size = nd->current_size >> 6;
273 draw_progress_bar(current_size * 100 / total_size);
276 case THOR_NOTIFY_DOWNLOAD_FAILED:
277 vidconsole_put_string(vidcon_dev, fail_text);