lib: tizen: fix build error with tizen_defconfig
[platform/kernel/u-boot.git] / lib / tizen / tizen.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2012 Samsung Electronics
4  * Donghwa Lee <dh09.lee@samsung.com>
5  */
6
7 #include <common.h>
8 #include <lcd.h>
9 #include <malloc.h>
10 #include <version.h>
11 #include <libtizen.h>
12 #ifdef CONFIG_DM_VIDEO
13 #include <thor.h>
14 #include <video.h>
15 #include <video_console.h>
16 #include <dm/device.h>
17 #include <dm/uclass.h>
18 #endif
19
20 #include "tizen_logo_16bpp.h"
21 #include "tizen_logo_16bpp_gzip.h"
22
23 #ifdef CONFIG_LCD
24 #ifdef CONFIG_VIDEO_BMP_GZIP
25 #include "download_logos_16bpp_gzip.h"
26 #else
27 #include "download_logos_16bpp.h"
28 #endif
29
30 #define LOGO_X_OFS      ((720 - 480) / 2)
31 #define LOGO_Y_OFS      ((1280 - 800) / 2)
32 #define PROGRESS_BAR_WIDTH      4
33
34 void get_tizen_logo_info(vidinfo_t *vid)
35 {
36         switch (vid->vl_bpix) {
37         case 4:
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;
44 #else
45                 vid->logo_addr = (ulong)tizen_logo_16bpp;
46 #endif
47                 break;
48         default:
49                 vid->logo_addr = 0;
50                 break;
51         }
52 }
53
54 void draw_thor_fail_screen(void)
55 {
56         int x, y;
57
58         lcd_clear();
59
60         x = 196 + LOGO_X_OFS;
61         y = 280 + LOGO_Y_OFS;
62
63         bmp_display((unsigned long)download_noti_image, x, y);
64
65         x = 70 + LOGO_X_OFS;
66         y = 370 + LOGO_Y_OFS;
67
68         bmp_display((unsigned long)download_fail_text, x, y);
69 }
70
71 static unsigned int tmp_msg_x, tmp_msg_y;
72
73 void draw_thor_connected(void)
74 {
75         unsigned int prev_console_x, prev_console_y;
76
77         /* Get curent lcd xy */
78         lcd_get_position_cursor(&prev_console_x, &prev_console_y);
79
80         /* Set proper lcd xy position for clean unneeded messages */
81         lcd_set_position_cursor(tmp_msg_x, tmp_msg_y);
82         lcd_puts("\n\n                                          ");
83         lcd_puts("\n\n                                          ");
84
85         lcd_set_position_cursor(tmp_msg_x, tmp_msg_y);
86         lcd_printf("\n\n\tConnection established.");
87
88         /* Restore last lcd x y position */
89         lcd_set_position_cursor(prev_console_x, prev_console_y);
90 }
91
92 void draw_thor_screen(void)
93 {
94         int x, y;
95
96         lcd_clear();
97         lcd_printf("\n\n\tTHOR Tizen Downloader");
98
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);
102
103         char *pit_compatible = getenv("dfu_alt_pit_compatible");
104         if (pit_compatible) {
105                 lcd_printf("\tPlatform compatible with PIT Version: %s\n",
106                            pit_compatible);
107         };
108
109         lcd_get_position_cursor(&tmp_msg_x, &tmp_msg_y);
110
111         lcd_printf("\n\n\tPlease connect USB cable.");
112         lcd_printf("\n\n\tFor EXIT press POWERKEY 3 times.\n");
113
114         x = 199 + LOGO_X_OFS;
115         y = 272 + LOGO_Y_OFS;
116
117         bmp_display((unsigned long)download_image, x, y);
118
119         x = 90 + LOGO_X_OFS;
120         y = 360 + LOGO_Y_OFS;
121
122         bmp_display((unsigned long)download_text, x, y);
123
124         x = 39 + LOGO_X_OFS;
125         y = 445 + LOGO_Y_OFS;
126
127         bmp_display((unsigned long)prog_base, x, y);
128
129 }
130
131 void draw_thor_progress(unsigned long long int total_file_size,
132                    unsigned long long int downloaded_file_size)
133 {
134         static struct bmp_image *progress_bar = NULL;
135         static int last_percent;
136
137         void *bar_bitmap;
138         int current_percent = 0;
139         int draw_percent;
140         int i, tmp_x, x, y;
141
142         /* Make shift to prevent int overflow */
143         int divisor = total_file_size >> 7;
144         int divident = 100 * (downloaded_file_size >> 7);
145
146         if (!divisor || !divident)
147                 return;
148
149         while (divident > 0) {
150                 divident -= divisor;
151                 if (divident >= 0)
152                         current_percent++;
153         }
154
155         if (current_percent > 100)
156                 current_percent = 100;
157
158         if (!current_percent)
159                 last_percent = 0;
160
161         draw_percent = current_percent - last_percent;
162         if (!draw_percent)
163                 return;
164
165         if (!progress_bar)
166                 progress_bar = gunzip_bmp((long unsigned int)prog_middle,
167                                           NULL, &bar_bitmap);
168
169         if (!progress_bar)
170                 progress_bar = (struct bmp_image *)prog_middle;
171
172         /* set bar position */
173         x = 40 + LOGO_X_OFS;
174         y = 446 + LOGO_Y_OFS;
175
176         /* set last bar position */
177         x += last_percent * PROGRESS_BAR_WIDTH;
178
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);
182         }
183
184         last_percent = current_percent;
185 }
186 #endif
187
188 #ifdef CONFIG_DM_VIDEO
189 /* XRGB */
190 #define PROGRESS_BAR_COLOR      0x0000B3F1
191 #define PROGRESS_FRAME_COLOR    0x00F8FBF9
192
193 static struct udevice *vidcon_dev;
194
195 static inline void put_pixel(struct video_priv *vid_priv, int x, int y,
196                              unsigned int colour)
197 {
198         u32 *screen = vid_priv->fb;
199         screen[y * vid_priv->xsize + x] = colour;
200 }
201
202 static void draw_progress_bar(unsigned int progress_value)
203 {
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;
207         int x, y;
208
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;
214         }
215
216         if (progress_value > 100)
217                 progress_value = 100;
218
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);
222         }
223
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);
227         }
228
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);
232
233         video_sync(vid_dev, false);
234 }
235
236 void thor_status_notify(enum thor_notify_type type, struct thor_notify_data *nd)
237 {
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;
249         int ret;
250
251         if (!vidcon_dev) {
252                 ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &vidcon_dev);
253                 if (ret || !vidcon_dev)
254                         return;
255         }
256
257         switch (type) {
258         case THOR_NOTIFY_INIT:
259                 vidconsole_put_string(vidcon_dev, init_text);
260                 break;
261
262         case THOR_NOTIFY_CONNECTED:
263                 vidconsole_put_string(vidcon_dev, conn_text);
264                 break;
265
266         case THOR_NOTIFY_PROGRESS:
267                 if (!nd)
268                         break;
269                 /* Shift to prevent int overflow */
270                 total_size = nd->total_size >> 6;
271                 current_size = nd->current_size >> 6;
272                 if (total_size)
273                         draw_progress_bar(current_size * 100 / total_size);
274                 break;
275
276         case THOR_NOTIFY_DOWNLOAD_FAILED:
277                 vidconsole_put_string(vidcon_dev, fail_text);
278                 break;
279
280         default:
281                 break;
282         }
283 }
284 #endif