blob: 65358a1c6e7436b07f2bbb998aad071a4069fd34 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass87aae882016-01-18 19:52:19 -07002/*
3 * Copyright (c) 2015 Google, Inc
4 * (C) Copyright 2015
5 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +03006 * (C) Copyright 2023 Dzmitry Sankouski <dsankouski@gmail.com>
Simon Glass87aae882016-01-18 19:52:19 -07007 */
8
9#include <common.h>
10#include <dm.h>
11#include <video.h>
12#include <video_console.h>
13#include <video_font.h> /* Get font data, width and height */
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030014#include "vidconsole_internal.h"
Simon Glass87aae882016-01-18 19:52:19 -070015
16static int console_set_row_1(struct udevice *dev, uint row, int clr)
17{
18 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030019 struct console_simple_priv *priv = dev_get_priv(dev);
20 struct video_fontdata *fontdata = priv->fontdata;
Simon Glass87aae882016-01-18 19:52:19 -070021 int pbytes = VNBYTES(vid_priv->bpix);
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030022 void *start, *dst, *line;
Simon Glass87aae882016-01-18 19:52:19 -070023 int i, j;
Simon Glass42301da2020-07-02 21:12:26 -060024 int ret;
Simon Glass87aae882016-01-18 19:52:19 -070025
Simon Glass42301da2020-07-02 21:12:26 -060026 start = vid_priv->fb + vid_priv->line_length -
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030027 (row + 1) * fontdata->height * pbytes;
Simon Glass42301da2020-07-02 21:12:26 -060028 line = start;
Simon Glass87aae882016-01-18 19:52:19 -070029 for (j = 0; j < vid_priv->ysize; j++) {
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030030 dst = line;
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030031 for (i = 0; i < fontdata->height; i++)
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030032 fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
Simon Glass87aae882016-01-18 19:52:19 -070033 line += vid_priv->line_length;
34 }
Simon Glass42301da2020-07-02 21:12:26 -060035 ret = vidconsole_sync_copy(dev, start, line);
36 if (ret)
37 return ret;
Simon Glass87aae882016-01-18 19:52:19 -070038
39 return 0;
40}
41
42static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030043 uint count)
Simon Glass87aae882016-01-18 19:52:19 -070044{
45 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030046 struct console_simple_priv *priv = dev_get_priv(dev);
47 struct video_fontdata *fontdata = priv->fontdata;
Simon Glass80daa3f2020-07-02 21:12:16 -060048 int pbytes = VNBYTES(vid_priv->bpix);
Simon Glass87aae882016-01-18 19:52:19 -070049 void *dst;
50 void *src;
Simon Glass42301da2020-07-02 21:12:26 -060051 int j, ret;
Simon Glass87aae882016-01-18 19:52:19 -070052
53 dst = vid_priv->fb + vid_priv->line_length -
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030054 (rowdst + count) * fontdata->height * pbytes;
Simon Glass87aae882016-01-18 19:52:19 -070055 src = vid_priv->fb + vid_priv->line_length -
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030056 (rowsrc + count) * fontdata->height * pbytes;
Simon Glass87aae882016-01-18 19:52:19 -070057
58 for (j = 0; j < vid_priv->ysize; j++) {
Simon Glass42301da2020-07-02 21:12:26 -060059 ret = vidconsole_memmove(dev, dst, src,
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030060 fontdata->height * pbytes * count);
Simon Glass42301da2020-07-02 21:12:26 -060061 if (ret)
62 return ret;
Simon Glass87aae882016-01-18 19:52:19 -070063 src += vid_priv->line_length;
64 dst += vid_priv->line_length;
65 }
66
67 return 0;
68}
69
Simon Glass52c10c52016-01-14 18:10:37 -070070static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
Simon Glass87aae882016-01-18 19:52:19 -070071{
Simon Glass52c10c52016-01-14 18:10:37 -070072 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
Simon Glass87aae882016-01-18 19:52:19 -070073 struct udevice *vid = dev->parent;
74 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030075 struct console_simple_priv *priv = dev_get_priv(dev);
76 struct video_fontdata *fontdata = priv->fontdata;
Simon Glass87aae882016-01-18 19:52:19 -070077 int pbytes = VNBYTES(vid_priv->bpix);
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030078 int x, linenum, ret;
Simon Glass42301da2020-07-02 21:12:26 -060079 void *start, *line;
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030080 uchar *pfont = fontdata->video_fontdata +
81 (u8)ch * fontdata->char_pixel_bytes;
Simon Glass87aae882016-01-18 19:52:19 -070082
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030083 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
84 return -EAGAIN;
Simon Glass80daa3f2020-07-02 21:12:16 -060085 linenum = VID_TO_PIXEL(x_frac) + 1;
86 x = y + 1;
Simon Glass42301da2020-07-02 21:12:26 -060087 start = vid_priv->fb + linenum * vid_priv->line_length - x * pbytes;
88 line = start;
Simon Glass87aae882016-01-18 19:52:19 -070089
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030090 ret = fill_char_horizontally(pfont, &line, vid_priv, fontdata, FLIPPED_DIRECTION);
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030091 if (ret)
92 return ret;
Simon Glass87aae882016-01-18 19:52:19 -070093
Simon Glass42301da2020-07-02 21:12:26 -060094 /* We draw backwards from 'start, so account for the first line */
95 ret = vidconsole_sync_copy(dev, start - vid_priv->line_length, line);
96 if (ret)
97 return ret;
Simon Glass87aae882016-01-18 19:52:19 -070098
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030099 return VID_TO_POS(fontdata->width);
Simon Glass87aae882016-01-18 19:52:19 -0700100}
101
102
103static int console_set_row_2(struct udevice *dev, uint row, int clr)
104{
105 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300106 struct console_simple_priv *priv = dev_get_priv(dev);
107 struct video_fontdata *fontdata = priv->fontdata;
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300108 void *start, *line, *dst, *end;
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300109 int pixels = fontdata->height * vid_priv->xsize;
Simon Glass42301da2020-07-02 21:12:26 -0600110 int i, ret;
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300111 int pbytes = VNBYTES(vid_priv->bpix);
Simon Glass87aae882016-01-18 19:52:19 -0700112
Simon Glass42301da2020-07-02 21:12:26 -0600113 start = vid_priv->fb + vid_priv->ysize * vid_priv->line_length -
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300114 (row + 1) * fontdata->height * vid_priv->line_length;
Simon Glass42301da2020-07-02 21:12:26 -0600115 line = start;
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300116 dst = line;
117 for (i = 0; i < pixels; i++)
118 fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
119 end = dst;
Simon Glass42301da2020-07-02 21:12:26 -0600120 ret = vidconsole_sync_copy(dev, start, end);
121 if (ret)
122 return ret;
Simon Glass87aae882016-01-18 19:52:19 -0700123
124 return 0;
125}
126
127static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
128 uint count)
129{
130 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300131 struct console_simple_priv *priv = dev_get_priv(dev);
132 struct video_fontdata *fontdata = priv->fontdata;
Simon Glass87aae882016-01-18 19:52:19 -0700133 void *dst;
134 void *src;
135 void *end;
136
137 end = vid_priv->fb + vid_priv->ysize * vid_priv->line_length;
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300138 dst = end - (rowdst + count) * fontdata->height *
Simon Glass87aae882016-01-18 19:52:19 -0700139 vid_priv->line_length;
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300140 src = end - (rowsrc + count) * fontdata->height *
Simon Glass87aae882016-01-18 19:52:19 -0700141 vid_priv->line_length;
Simon Glass42301da2020-07-02 21:12:26 -0600142 vidconsole_memmove(dev, dst, src,
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300143 fontdata->height * vid_priv->line_length * count);
Simon Glass87aae882016-01-18 19:52:19 -0700144
145 return 0;
146}
147
Simon Glass52c10c52016-01-14 18:10:37 -0700148static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
Simon Glass87aae882016-01-18 19:52:19 -0700149{
Simon Glass52c10c52016-01-14 18:10:37 -0700150 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
Simon Glass87aae882016-01-18 19:52:19 -0700151 struct udevice *vid = dev->parent;
152 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300153 struct console_simple_priv *priv = dev_get_priv(dev);
154 struct video_fontdata *fontdata = priv->fontdata;
Simon Glass80daa3f2020-07-02 21:12:16 -0600155 int pbytes = VNBYTES(vid_priv->bpix);
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300156 int linenum, x, ret;
Simon Glass42301da2020-07-02 21:12:26 -0600157 void *start, *line;
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300158 uchar *pfont = fontdata->video_fontdata +
159 (u8)ch * fontdata->char_pixel_bytes;
Simon Glass87aae882016-01-18 19:52:19 -0700160
Simon Glass52c10c52016-01-14 18:10:37 -0700161 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
162 return -EAGAIN;
Simon Glass80daa3f2020-07-02 21:12:16 -0600163 linenum = vid_priv->ysize - y - 1;
Simon Glassf50a6b92020-07-02 21:12:17 -0600164 x = vid_priv->xsize - VID_TO_PIXEL(x_frac) - 1;
Simon Glass42301da2020-07-02 21:12:26 -0600165 start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes;
166 line = start;
Simon Glass87aae882016-01-18 19:52:19 -0700167
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300168 ret = fill_char_vertically(pfont, &line, vid_priv, fontdata, FLIPPED_DIRECTION);
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300169 if (ret)
170 return ret;
Simon Glass87aae882016-01-18 19:52:19 -0700171
Simon Glass42301da2020-07-02 21:12:26 -0600172 /* Add 4 bytes to allow for the first pixel writen */
173 ret = vidconsole_sync_copy(dev, start + 4, line);
174 if (ret)
175 return ret;
Simon Glass87aae882016-01-18 19:52:19 -0700176
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300177 return VID_TO_POS(fontdata->width);
Simon Glass87aae882016-01-18 19:52:19 -0700178}
179
180static int console_set_row_3(struct udevice *dev, uint row, int clr)
181{
182 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300183 struct console_simple_priv *priv = dev_get_priv(dev);
184 struct video_fontdata *fontdata = priv->fontdata;
Simon Glass87aae882016-01-18 19:52:19 -0700185 int pbytes = VNBYTES(vid_priv->bpix);
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300186 void *start, *dst, *line;
Simon Glass42301da2020-07-02 21:12:26 -0600187 int i, j, ret;
Simon Glass87aae882016-01-18 19:52:19 -0700188
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300189 start = vid_priv->fb + row * fontdata->height * pbytes;
Simon Glass42301da2020-07-02 21:12:26 -0600190 line = start;
Simon Glass87aae882016-01-18 19:52:19 -0700191 for (j = 0; j < vid_priv->ysize; j++) {
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300192 dst = line;
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300193 for (i = 0; i < fontdata->height; i++)
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300194 fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
Simon Glass87aae882016-01-18 19:52:19 -0700195 line += vid_priv->line_length;
196 }
Simon Glass42301da2020-07-02 21:12:26 -0600197 ret = vidconsole_sync_copy(dev, start, line);
198 if (ret)
199 return ret;
Simon Glass87aae882016-01-18 19:52:19 -0700200
201 return 0;
202}
203
204static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
205 uint count)
206{
207 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300208 struct console_simple_priv *priv = dev_get_priv(dev);
209 struct video_fontdata *fontdata = priv->fontdata;
Simon Glass80daa3f2020-07-02 21:12:16 -0600210 int pbytes = VNBYTES(vid_priv->bpix);
Simon Glass87aae882016-01-18 19:52:19 -0700211 void *dst;
212 void *src;
Simon Glass42301da2020-07-02 21:12:26 -0600213 int j, ret;
Simon Glass87aae882016-01-18 19:52:19 -0700214
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300215 dst = vid_priv->fb + rowdst * fontdata->height * pbytes;
216 src = vid_priv->fb + rowsrc * fontdata->height * pbytes;
Simon Glass87aae882016-01-18 19:52:19 -0700217
218 for (j = 0; j < vid_priv->ysize; j++) {
Simon Glass42301da2020-07-02 21:12:26 -0600219 ret = vidconsole_memmove(dev, dst, src,
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300220 fontdata->height * pbytes * count);
Simon Glass42301da2020-07-02 21:12:26 -0600221 if (ret)
222 return ret;
Simon Glass87aae882016-01-18 19:52:19 -0700223 src += vid_priv->line_length;
224 dst += vid_priv->line_length;
225 }
226
227 return 0;
228}
229
Simon Glass52c10c52016-01-14 18:10:37 -0700230static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
Simon Glass87aae882016-01-18 19:52:19 -0700231{
Simon Glass52c10c52016-01-14 18:10:37 -0700232 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
Simon Glass87aae882016-01-18 19:52:19 -0700233 struct udevice *vid = dev->parent;
234 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300235 struct console_simple_priv *priv = dev_get_priv(dev);
236 struct video_fontdata *fontdata = priv->fontdata;
Simon Glass87aae882016-01-18 19:52:19 -0700237 int pbytes = VNBYTES(vid_priv->bpix);
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300238 int linenum, x, ret;
Simon Glass42301da2020-07-02 21:12:26 -0600239 void *start, *line;
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300240 uchar *pfont = fontdata->video_fontdata +
241 (u8)ch * fontdata->char_pixel_bytes;
Simon Glass87aae882016-01-18 19:52:19 -0700242
Simon Glass52c10c52016-01-14 18:10:37 -0700243 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
244 return -EAGAIN;
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300245 x = y;
246 linenum = vid_priv->ysize - VID_TO_PIXEL(x_frac) - 1;
247 start = vid_priv->fb + linenum * vid_priv->line_length + y * pbytes;
Simon Glass42301da2020-07-02 21:12:26 -0600248 line = start;
Simon Glass87aae882016-01-18 19:52:19 -0700249
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300250 ret = fill_char_horizontally(pfont, &line, vid_priv, fontdata, NORMAL_DIRECTION);
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300251 if (ret)
252 return ret;
Simon Glass42301da2020-07-02 21:12:26 -0600253 /* Add a line to allow for the first pixels writen */
254 ret = vidconsole_sync_copy(dev, start + vid_priv->line_length, line);
255 if (ret)
256 return ret;
Simon Glass87aae882016-01-18 19:52:19 -0700257
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300258 return VID_TO_POS(fontdata->width);
Simon Glass87aae882016-01-18 19:52:19 -0700259}
260
Simon Glass87aae882016-01-18 19:52:19 -0700261struct vidconsole_ops console_ops_1 = {
262 .putc_xy = console_putc_xy_1,
263 .move_rows = console_move_rows_1,
264 .set_row = console_set_row_1,
Dzmitry Sankouskibb165e42023-03-07 13:21:16 +0300265 .get_font_size = console_simple_get_font_size,
266 .get_font = console_simple_get_font,
267 .select_font = console_simple_select_font,
Simon Glass87aae882016-01-18 19:52:19 -0700268};
269
270struct vidconsole_ops console_ops_2 = {
271 .putc_xy = console_putc_xy_2,
272 .move_rows = console_move_rows_2,
273 .set_row = console_set_row_2,
Dzmitry Sankouskibb165e42023-03-07 13:21:16 +0300274 .get_font_size = console_simple_get_font_size,
275 .get_font = console_simple_get_font,
276 .select_font = console_simple_select_font,
Simon Glass87aae882016-01-18 19:52:19 -0700277};
278
279struct vidconsole_ops console_ops_3 = {
280 .putc_xy = console_putc_xy_3,
281 .move_rows = console_move_rows_3,
282 .set_row = console_set_row_3,
Dzmitry Sankouskibb165e42023-03-07 13:21:16 +0300283 .get_font_size = console_simple_get_font_size,
284 .get_font = console_simple_get_font,
285 .select_font = console_simple_select_font,
Simon Glass87aae882016-01-18 19:52:19 -0700286};
287
288U_BOOT_DRIVER(vidconsole_1) = {
289 .name = "vidconsole1",
290 .id = UCLASS_VIDEO_CONSOLE,
291 .ops = &console_ops_1,
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300292 .probe = console_probe,
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300293 .priv_auto = sizeof(struct console_simple_priv),
Simon Glass87aae882016-01-18 19:52:19 -0700294};
295
296U_BOOT_DRIVER(vidconsole_2) = {
297 .name = "vidconsole2",
298 .id = UCLASS_VIDEO_CONSOLE,
299 .ops = &console_ops_2,
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300300 .probe = console_probe,
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300301 .priv_auto = sizeof(struct console_simple_priv),
Simon Glass87aae882016-01-18 19:52:19 -0700302};
303
304U_BOOT_DRIVER(vidconsole_3) = {
305 .name = "vidconsole3",
306 .id = UCLASS_VIDEO_CONSOLE,
307 .ops = &console_ops_3,
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300308 .probe = console_probe,
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300309 .priv_auto = sizeof(struct console_simple_priv),
Simon Glass87aae882016-01-18 19:52:19 -0700310};