Merge branch '2022-08-10-assorted-updates'
[pandora-u-boot.git] / common / splash.c
1 /*
2  * Copyright (C) 2013, Boundary Devices <info@boundarydevices.com>
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., http://www.fsf.org/about/contact/
20  *
21  */
22
23 #include <common.h>
24 #include <display_options.h>
25 #include <env.h>
26 #include <splash.h>
27 #include <lcd.h>
28
29 static struct splash_location default_splash_locations[] = {
30         {
31                 .name = "sf",
32                 .storage = SPLASH_STORAGE_SF,
33                 .flags = SPLASH_STORAGE_RAW,
34                 .offset = 0x0,
35         },
36         {
37                 .name = "mmc_fs",
38                 .storage = SPLASH_STORAGE_MMC,
39                 .flags = SPLASH_STORAGE_FS,
40                 .devpart = "0:1",
41         },
42         {
43                 .name = "usb_fs",
44                 .storage = SPLASH_STORAGE_USB,
45                 .flags = SPLASH_STORAGE_FS,
46                 .devpart = "0:1",
47         },
48         {
49                 .name = "sata_fs",
50                 .storage = SPLASH_STORAGE_SATA,
51                 .flags = SPLASH_STORAGE_FS,
52                 .devpart = "0:1",
53         },
54 };
55
56 #ifdef CONFIG_VIDEO_LOGO
57
58 #include <bmp_logo_data.h>
59
60 static int splash_video_logo_load(void)
61 {
62         char *splashimage;
63         ulong bmp_load_addr;
64
65         splashimage = env_get("splashimage");
66         if (!splashimage)
67                 return -ENOENT;
68
69         bmp_load_addr = hextoul(splashimage, 0);
70         if (!bmp_load_addr) {
71                 printf("Error: bad 'splashimage' address\n");
72                 return -EFAULT;
73         }
74
75         memcpy((void *)bmp_load_addr, bmp_logo_bitmap,
76                ARRAY_SIZE(bmp_logo_bitmap));
77
78         return 0;
79 }
80 #else
81 static inline int splash_video_logo_load(void) { return -ENOSYS; }
82 #endif
83
84 __weak int splash_screen_prepare(void)
85 {
86         if (CONFIG_IS_ENABLED(SPLASH_SOURCE))
87                 return splash_source_load(default_splash_locations,
88                                           ARRAY_SIZE(default_splash_locations));
89
90         return splash_video_logo_load();
91 }
92
93 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
94 void splash_get_pos(int *x, int *y)
95 {
96         char *s = env_get("splashpos");
97
98         if (!s)
99                 return;
100
101         if (s[0] == 'm')
102                 *x = BMP_ALIGN_CENTER;
103         else
104                 *x = simple_strtol(s, NULL, 0);
105
106         s = strchr(s + 1, ',');
107         if (s != NULL) {
108                 if (s[1] == 'm')
109                         *y = BMP_ALIGN_CENTER;
110                 else
111                         *y = simple_strtol(s + 1, NULL, 0);
112         }
113 }
114 #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
115
116 #if defined(CONFIG_DM_VIDEO) && !defined(CONFIG_HIDE_LOGO_VERSION)
117
118 #ifdef CONFIG_VIDEO_LOGO
119 #include <bmp_logo.h>
120 #endif
121 #include <dm.h>
122 #include <video_console.h>
123 #include <video_font.h>
124
125 void splash_display_banner(void)
126 {
127         struct udevice *dev;
128         char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
129         int col, row, ret;
130
131         ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &dev);
132         if (ret)
133                 return;
134
135 #ifdef CONFIG_VIDEO_LOGO
136         col = BMP_LOGO_WIDTH / VIDEO_FONT_WIDTH + 1;
137         row = BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT + 1;
138 #else
139         col = 0;
140         row = 0;
141 #endif
142
143         display_options_get_banner(false, buf, sizeof(buf));
144         vidconsole_position_cursor(dev, col, 1);
145         vidconsole_put_string(dev, buf);
146         vidconsole_position_cursor(dev, 0, row);
147 }
148 #endif /* CONFIG_DM_VIDEO && !CONFIG_HIDE_LOGO_VERSION */
149
150 /*
151  * Common function to show a splash image if env("splashimage") is set.
152  * Is used for both dm_video and lcd video stacks. For additional
153  * details please refer to doc/README.splashprepare.
154  */
155 #if defined(CONFIG_SPLASH_SCREEN) && defined(CONFIG_CMD_BMP)
156 int splash_display(void)
157 {
158         ulong addr;
159         char *s;
160         int x = 0, y = 0, ret;
161
162         s = env_get("splashimage");
163         if (!s)
164                 return -EINVAL;
165
166         addr = hextoul(s, NULL);
167         ret = splash_screen_prepare();
168         if (ret)
169                 return ret;
170
171         splash_get_pos(&x, &y);
172
173         ret = bmp_display(addr, x, y);
174
175         /* Skip banner output on video console if the logo is not at 0,0 */
176         if (x || y)
177                 goto end;
178
179 #if defined(CONFIG_DM_VIDEO) && !defined(CONFIG_HIDE_LOGO_VERSION)
180         splash_display_banner();
181 #endif
182 end:
183         return ret;
184 }
185 #endif