blob: 36c8d0609d8734682d870ce683a987d02e370856 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassb5146b22016-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
Simon Glassb5146b22016-01-18 19:52:19 -07006 */
7
8#include <common.h>
9#include <dm.h>
10#include <video.h>
11#include <video_console.h>
12#include <video_font.h> /* Get font data, width and height */
13
14static int console_set_row_1(struct udevice *dev, uint row, int clr)
15{
16 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
17 int pbytes = VNBYTES(vid_priv->bpix);
Simon Glassc30c5f22020-07-02 21:12:26 -060018 void *start, *line;
Simon Glassb5146b22016-01-18 19:52:19 -070019 int i, j;
Simon Glassc30c5f22020-07-02 21:12:26 -060020 int ret;
Simon Glassb5146b22016-01-18 19:52:19 -070021
Simon Glassc30c5f22020-07-02 21:12:26 -060022 start = vid_priv->fb + vid_priv->line_length -
Simon Glassb5146b22016-01-18 19:52:19 -070023 (row + 1) * VIDEO_FONT_HEIGHT * pbytes;
Simon Glassc30c5f22020-07-02 21:12:26 -060024 line = start;
Simon Glassb5146b22016-01-18 19:52:19 -070025 for (j = 0; j < vid_priv->ysize; j++) {
26 switch (vid_priv->bpix) {
Simon Glassc6567312019-12-20 18:10:35 -070027 case VIDEO_BPP8:
28 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
29 uint8_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -070030
Simon Glassc6567312019-12-20 18:10:35 -070031 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
32 *dst++ = clr;
33 break;
34 }
35 case VIDEO_BPP16:
36 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
37 uint16_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -070038
Simon Glassc6567312019-12-20 18:10:35 -070039 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
40 *dst++ = clr;
41 break;
42 }
43 case VIDEO_BPP32:
44 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
45 uint32_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -070046
Simon Glassc6567312019-12-20 18:10:35 -070047 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
48 *dst++ = clr;
49 break;
50 }
Simon Glassb5146b22016-01-18 19:52:19 -070051 default:
52 return -ENOSYS;
53 }
54 line += vid_priv->line_length;
55 }
Simon Glassc30c5f22020-07-02 21:12:26 -060056 ret = vidconsole_sync_copy(dev, start, line);
57 if (ret)
58 return ret;
Simon Glassb5146b22016-01-18 19:52:19 -070059
60 return 0;
61}
62
63static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
64 uint count)
65{
66 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
Simon Glassa254d112020-07-02 21:12:16 -060067 int pbytes = VNBYTES(vid_priv->bpix);
Simon Glassb5146b22016-01-18 19:52:19 -070068 void *dst;
69 void *src;
Simon Glassc30c5f22020-07-02 21:12:26 -060070 int j, ret;
Simon Glassb5146b22016-01-18 19:52:19 -070071
72 dst = vid_priv->fb + vid_priv->line_length -
73 (rowdst + count) * VIDEO_FONT_HEIGHT * pbytes;
74 src = vid_priv->fb + vid_priv->line_length -
75 (rowsrc + count) * VIDEO_FONT_HEIGHT * pbytes;
76
77 for (j = 0; j < vid_priv->ysize; j++) {
Simon Glassc30c5f22020-07-02 21:12:26 -060078 ret = vidconsole_memmove(dev, dst, src,
79 VIDEO_FONT_HEIGHT * pbytes * count);
80 if (ret)
81 return ret;
Simon Glassb5146b22016-01-18 19:52:19 -070082 src += vid_priv->line_length;
83 dst += vid_priv->line_length;
84 }
85
86 return 0;
87}
88
Simon Glassf2661782016-01-14 18:10:37 -070089static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
Simon Glassb5146b22016-01-18 19:52:19 -070090{
Simon Glassf2661782016-01-14 18:10:37 -070091 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
Simon Glassb5146b22016-01-18 19:52:19 -070092 struct udevice *vid = dev->parent;
93 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
Simon Glassa254d112020-07-02 21:12:16 -060094 uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
Simon Glassb5146b22016-01-18 19:52:19 -070095 int pbytes = VNBYTES(vid_priv->bpix);
Simon Glassc30c5f22020-07-02 21:12:26 -060096 int i, col, x, linenum, ret;
Simon Glassb5146b22016-01-18 19:52:19 -070097 int mask = 0x80;
Simon Glassc30c5f22020-07-02 21:12:26 -060098 void *start, *line;
Simon Glassb5146b22016-01-18 19:52:19 -070099
Simon Glassa254d112020-07-02 21:12:16 -0600100 linenum = VID_TO_PIXEL(x_frac) + 1;
101 x = y + 1;
Simon Glassc30c5f22020-07-02 21:12:26 -0600102 start = vid_priv->fb + linenum * vid_priv->line_length - x * pbytes;
103 line = start;
Simon Glassf2661782016-01-14 18:10:37 -0700104 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
105 return -EAGAIN;
106
Simon Glassb5146b22016-01-18 19:52:19 -0700107 for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
108 switch (vid_priv->bpix) {
Simon Glassc6567312019-12-20 18:10:35 -0700109 case VIDEO_BPP8:
110 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
111 uint8_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -0700112
Simon Glassc6567312019-12-20 18:10:35 -0700113 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
114 *dst-- = (pfont[i] & mask) ?
115 vid_priv->colour_fg :
116 vid_priv->colour_bg;
117 }
118 break;
Simon Glassb5146b22016-01-18 19:52:19 -0700119 }
Simon Glassc6567312019-12-20 18:10:35 -0700120 case VIDEO_BPP16:
121 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
122 uint16_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -0700123
Simon Glassc6567312019-12-20 18:10:35 -0700124 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
125 *dst-- = (pfont[i] & mask) ?
126 vid_priv->colour_fg :
127 vid_priv->colour_bg;
128 }
129 break;
Simon Glassb5146b22016-01-18 19:52:19 -0700130 }
Simon Glassc6567312019-12-20 18:10:35 -0700131 case VIDEO_BPP32:
132 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
133 uint32_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -0700134
Simon Glassc6567312019-12-20 18:10:35 -0700135 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
136 *dst-- = (pfont[i] & mask) ?
137 vid_priv->colour_fg :
138 vid_priv->colour_bg;
139 }
140 break;
Simon Glassb5146b22016-01-18 19:52:19 -0700141 }
Simon Glassb5146b22016-01-18 19:52:19 -0700142 default:
143 return -ENOSYS;
144 }
145 line += vid_priv->line_length;
146 mask >>= 1;
147 }
Simon Glassc30c5f22020-07-02 21:12:26 -0600148 /* We draw backwards from 'start, so account for the first line */
149 ret = vidconsole_sync_copy(dev, start - vid_priv->line_length, line);
150 if (ret)
151 return ret;
Simon Glassb5146b22016-01-18 19:52:19 -0700152
Simon Glassf2661782016-01-14 18:10:37 -0700153 return VID_TO_POS(VIDEO_FONT_WIDTH);
Simon Glassb5146b22016-01-18 19:52:19 -0700154}
155
156
157static int console_set_row_2(struct udevice *dev, uint row, int clr)
158{
159 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
Simon Glassc30c5f22020-07-02 21:12:26 -0600160 void *start, *line, *end;
Simon Glassb5146b22016-01-18 19:52:19 -0700161 int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
Simon Glassc30c5f22020-07-02 21:12:26 -0600162 int i, ret;
Simon Glassb5146b22016-01-18 19:52:19 -0700163
Simon Glassc30c5f22020-07-02 21:12:26 -0600164 start = vid_priv->fb + vid_priv->ysize * vid_priv->line_length -
Simon Glassb5146b22016-01-18 19:52:19 -0700165 (row + 1) * VIDEO_FONT_HEIGHT * vid_priv->line_length;
Simon Glassc30c5f22020-07-02 21:12:26 -0600166 line = start;
Simon Glassb5146b22016-01-18 19:52:19 -0700167 switch (vid_priv->bpix) {
Simon Glassc6567312019-12-20 18:10:35 -0700168 case VIDEO_BPP8:
169 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
170 uint8_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -0700171
Simon Glassc6567312019-12-20 18:10:35 -0700172 for (i = 0; i < pixels; i++)
173 *dst++ = clr;
Simon Glassc30c5f22020-07-02 21:12:26 -0600174 end = dst;
Simon Glassc6567312019-12-20 18:10:35 -0700175 break;
176 }
177 case VIDEO_BPP16:
178 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
179 uint16_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -0700180
Simon Glassc6567312019-12-20 18:10:35 -0700181 for (i = 0; i < pixels; i++)
182 *dst++ = clr;
Simon Glassc30c5f22020-07-02 21:12:26 -0600183 end = dst;
Simon Glassc6567312019-12-20 18:10:35 -0700184 break;
185 }
186 case VIDEO_BPP32:
187 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
188 uint32_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -0700189
Simon Glassc6567312019-12-20 18:10:35 -0700190 for (i = 0; i < pixels; i++)
191 *dst++ = clr;
Simon Glassc30c5f22020-07-02 21:12:26 -0600192 end = dst;
Simon Glassc6567312019-12-20 18:10:35 -0700193 break;
194 }
Simon Glassb5146b22016-01-18 19:52:19 -0700195 default:
196 return -ENOSYS;
197 }
Simon Glassc30c5f22020-07-02 21:12:26 -0600198 ret = vidconsole_sync_copy(dev, start, end);
199 if (ret)
200 return ret;
Simon Glassb5146b22016-01-18 19:52:19 -0700201
202 return 0;
203}
204
205static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
206 uint count)
207{
208 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
209 void *dst;
210 void *src;
211 void *end;
212
213 end = vid_priv->fb + vid_priv->ysize * vid_priv->line_length;
214 dst = end - (rowdst + count) * VIDEO_FONT_HEIGHT *
215 vid_priv->line_length;
216 src = end - (rowsrc + count) * VIDEO_FONT_HEIGHT *
217 vid_priv->line_length;
Simon Glassc30c5f22020-07-02 21:12:26 -0600218 vidconsole_memmove(dev, dst, src,
219 VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
Simon Glassb5146b22016-01-18 19:52:19 -0700220
221 return 0;
222}
223
Simon Glassf2661782016-01-14 18:10:37 -0700224static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
Simon Glassb5146b22016-01-18 19:52:19 -0700225{
Simon Glassf2661782016-01-14 18:10:37 -0700226 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
Simon Glassb5146b22016-01-18 19:52:19 -0700227 struct udevice *vid = dev->parent;
228 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
Simon Glassa254d112020-07-02 21:12:16 -0600229 int pbytes = VNBYTES(vid_priv->bpix);
Simon Glassc30c5f22020-07-02 21:12:26 -0600230 int i, row, x, linenum, ret;
231 void *start, *line;
Simon Glassb5146b22016-01-18 19:52:19 -0700232
Simon Glassf2661782016-01-14 18:10:37 -0700233 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
234 return -EAGAIN;
Simon Glassa254d112020-07-02 21:12:16 -0600235 linenum = vid_priv->ysize - y - 1;
Simon Glass9beb3642020-07-02 21:12:17 -0600236 x = vid_priv->xsize - VID_TO_PIXEL(x_frac) - 1;
Simon Glassc30c5f22020-07-02 21:12:26 -0600237 start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes;
238 line = start;
Simon Glassb5146b22016-01-18 19:52:19 -0700239
240 for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
Andre Przywara96c9bf72019-03-23 01:29:55 +0000241 unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row;
242 uchar bits = video_fontdata[idx];
Simon Glassb5146b22016-01-18 19:52:19 -0700243
244 switch (vid_priv->bpix) {
Simon Glassc6567312019-12-20 18:10:35 -0700245 case VIDEO_BPP8:
246 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
247 uint8_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -0700248
Simon Glassc6567312019-12-20 18:10:35 -0700249 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
250 *dst-- = (bits & 0x80) ?
251 vid_priv->colour_fg :
252 vid_priv->colour_bg;
253 bits <<= 1;
254 }
255 break;
Simon Glassb5146b22016-01-18 19:52:19 -0700256 }
Simon Glassc6567312019-12-20 18:10:35 -0700257 case VIDEO_BPP16:
258 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
259 uint16_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -0700260
Simon Glassc6567312019-12-20 18:10:35 -0700261 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
262 *dst-- = (bits & 0x80) ?
263 vid_priv->colour_fg :
264 vid_priv->colour_bg;
265 bits <<= 1;
266 }
267 break;
Simon Glassb5146b22016-01-18 19:52:19 -0700268 }
Simon Glassc6567312019-12-20 18:10:35 -0700269 case VIDEO_BPP32:
270 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
271 uint32_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -0700272
Simon Glassc6567312019-12-20 18:10:35 -0700273 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
274 *dst-- = (bits & 0x80) ?
275 vid_priv->colour_fg :
276 vid_priv->colour_bg;
277 bits <<= 1;
278 }
279 break;
Simon Glassb5146b22016-01-18 19:52:19 -0700280 }
Simon Glassb5146b22016-01-18 19:52:19 -0700281 default:
282 return -ENOSYS;
283 }
284 line -= vid_priv->line_length;
285 }
Simon Glassc30c5f22020-07-02 21:12:26 -0600286 /* Add 4 bytes to allow for the first pixel writen */
287 ret = vidconsole_sync_copy(dev, start + 4, line);
288 if (ret)
289 return ret;
Simon Glassb5146b22016-01-18 19:52:19 -0700290
Simon Glassf2661782016-01-14 18:10:37 -0700291 return VID_TO_POS(VIDEO_FONT_WIDTH);
Simon Glassb5146b22016-01-18 19:52:19 -0700292}
293
294static int console_set_row_3(struct udevice *dev, uint row, int clr)
295{
296 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
297 int pbytes = VNBYTES(vid_priv->bpix);
Simon Glassc30c5f22020-07-02 21:12:26 -0600298 void *start, *line;
299 int i, j, ret;
Simon Glassb5146b22016-01-18 19:52:19 -0700300
Simon Glassc30c5f22020-07-02 21:12:26 -0600301 start = vid_priv->fb + row * VIDEO_FONT_HEIGHT * pbytes;
302 line = start;
Simon Glassb5146b22016-01-18 19:52:19 -0700303 for (j = 0; j < vid_priv->ysize; j++) {
304 switch (vid_priv->bpix) {
Simon Glassc6567312019-12-20 18:10:35 -0700305 case VIDEO_BPP8:
306 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
307 uint8_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -0700308
Simon Glassc6567312019-12-20 18:10:35 -0700309 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
310 *dst++ = clr;
311 break;
312 }
313 case VIDEO_BPP16:
314 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
315 uint16_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -0700316
Simon Glassc6567312019-12-20 18:10:35 -0700317 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
318 *dst++ = clr;
319 break;
320 }
321 case VIDEO_BPP32:
322 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
323 uint32_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -0700324
Simon Glassc6567312019-12-20 18:10:35 -0700325 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
326 *dst++ = clr;
327 break;
328 }
Simon Glassb5146b22016-01-18 19:52:19 -0700329 default:
330 return -ENOSYS;
331 }
332 line += vid_priv->line_length;
333 }
Simon Glassc30c5f22020-07-02 21:12:26 -0600334 ret = vidconsole_sync_copy(dev, start, line);
335 if (ret)
336 return ret;
Simon Glassb5146b22016-01-18 19:52:19 -0700337
338 return 0;
339}
340
341static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
342 uint count)
343{
344 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
Simon Glassa254d112020-07-02 21:12:16 -0600345 int pbytes = VNBYTES(vid_priv->bpix);
Simon Glassb5146b22016-01-18 19:52:19 -0700346 void *dst;
347 void *src;
Simon Glassc30c5f22020-07-02 21:12:26 -0600348 int j, ret;
Simon Glassb5146b22016-01-18 19:52:19 -0700349
350 dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * pbytes;
351 src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * pbytes;
352
353 for (j = 0; j < vid_priv->ysize; j++) {
Simon Glassc30c5f22020-07-02 21:12:26 -0600354 ret = vidconsole_memmove(dev, dst, src,
355 VIDEO_FONT_HEIGHT * pbytes * count);
356 if (ret)
357 return ret;
Simon Glassb5146b22016-01-18 19:52:19 -0700358 src += vid_priv->line_length;
359 dst += vid_priv->line_length;
360 }
361
362 return 0;
363}
364
Simon Glassf2661782016-01-14 18:10:37 -0700365static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
Simon Glassb5146b22016-01-18 19:52:19 -0700366{
Simon Glassf2661782016-01-14 18:10:37 -0700367 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
Simon Glassb5146b22016-01-18 19:52:19 -0700368 struct udevice *vid = dev->parent;
369 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
Andre Przywara96c9bf72019-03-23 01:29:55 +0000370 uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
Simon Glassa254d112020-07-02 21:12:16 -0600371 int pbytes = VNBYTES(vid_priv->bpix);
Simon Glassc30c5f22020-07-02 21:12:26 -0600372 int i, col, x, ret;
Simon Glassa254d112020-07-02 21:12:16 -0600373 int mask = 0x80;
Simon Glassc30c5f22020-07-02 21:12:26 -0600374 void *start, *line;
Simon Glassb5146b22016-01-18 19:52:19 -0700375
Simon Glassf2661782016-01-14 18:10:37 -0700376 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
377 return -EAGAIN;
Simon Glassa254d112020-07-02 21:12:16 -0600378 x = vid_priv->ysize - VID_TO_PIXEL(x_frac) - 1;
Simon Glassc30c5f22020-07-02 21:12:26 -0600379 start = vid_priv->fb + x * vid_priv->line_length + y * pbytes;
380 line = start;
Simon Glassb5146b22016-01-18 19:52:19 -0700381 for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
382 switch (vid_priv->bpix) {
Simon Glassc6567312019-12-20 18:10:35 -0700383 case VIDEO_BPP8:
384 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
385 uint8_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -0700386
Simon Glassc6567312019-12-20 18:10:35 -0700387 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
388 *dst++ = (pfont[i] & mask) ?
389 vid_priv->colour_fg :
390 vid_priv->colour_bg;
391 }
392 break;
Simon Glassb5146b22016-01-18 19:52:19 -0700393 }
Simon Glassc6567312019-12-20 18:10:35 -0700394 case VIDEO_BPP16:
395 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
396 uint16_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -0700397
Simon Glassc6567312019-12-20 18:10:35 -0700398 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
399 *dst++ = (pfont[i] & mask) ?
400 vid_priv->colour_fg :
401 vid_priv->colour_bg;
402 }
403 break;
Simon Glassb5146b22016-01-18 19:52:19 -0700404 }
Simon Glassc6567312019-12-20 18:10:35 -0700405 case VIDEO_BPP32:
406 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
407 uint32_t *dst = line;
Simon Glassb5146b22016-01-18 19:52:19 -0700408
Simon Glassc6567312019-12-20 18:10:35 -0700409 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
410 *dst++ = (pfont[i] & mask) ?
411 vid_priv->colour_fg :
412 vid_priv->colour_bg;
413 }
414 break;
Simon Glassb5146b22016-01-18 19:52:19 -0700415 }
Simon Glassb5146b22016-01-18 19:52:19 -0700416 default:
417 return -ENOSYS;
418 }
419 line -= vid_priv->line_length;
420 mask >>= 1;
421 }
Simon Glassc30c5f22020-07-02 21:12:26 -0600422 /* Add a line to allow for the first pixels writen */
423 ret = vidconsole_sync_copy(dev, start + vid_priv->line_length, line);
424 if (ret)
425 return ret;
Simon Glassb5146b22016-01-18 19:52:19 -0700426
Simon Glassf2661782016-01-14 18:10:37 -0700427 return VID_TO_POS(VIDEO_FONT_WIDTH);
Simon Glassb5146b22016-01-18 19:52:19 -0700428}
429
430
Simon Glassf2661782016-01-14 18:10:37 -0700431static int console_probe_2(struct udevice *dev)
432{
433 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
434 struct udevice *vid_dev = dev->parent;
435 struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
436
437 vc_priv->x_charsize = VIDEO_FONT_WIDTH;
438 vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
439 vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
440 vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
441
442 return 0;
443}
444
Simon Glassb5146b22016-01-18 19:52:19 -0700445static int console_probe_1_3(struct udevice *dev)
446{
Simon Glassf2661782016-01-14 18:10:37 -0700447 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
448 struct udevice *vid_dev = dev->parent;
449 struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
Simon Glassb5146b22016-01-18 19:52:19 -0700450
Simon Glassf2661782016-01-14 18:10:37 -0700451 vc_priv->x_charsize = VIDEO_FONT_WIDTH;
452 vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
453 vc_priv->cols = vid_priv->ysize / VIDEO_FONT_WIDTH;
454 vc_priv->rows = vid_priv->xsize / VIDEO_FONT_HEIGHT;
455 vc_priv->xsize_frac = VID_TO_POS(vid_priv->ysize);
Simon Glassb5146b22016-01-18 19:52:19 -0700456
457 return 0;
458}
459
460struct vidconsole_ops console_ops_1 = {
461 .putc_xy = console_putc_xy_1,
462 .move_rows = console_move_rows_1,
463 .set_row = console_set_row_1,
464};
465
466struct vidconsole_ops console_ops_2 = {
467 .putc_xy = console_putc_xy_2,
468 .move_rows = console_move_rows_2,
469 .set_row = console_set_row_2,
470};
471
472struct vidconsole_ops console_ops_3 = {
473 .putc_xy = console_putc_xy_3,
474 .move_rows = console_move_rows_3,
475 .set_row = console_set_row_3,
476};
477
478U_BOOT_DRIVER(vidconsole_1) = {
479 .name = "vidconsole1",
480 .id = UCLASS_VIDEO_CONSOLE,
481 .ops = &console_ops_1,
482 .probe = console_probe_1_3,
483};
484
485U_BOOT_DRIVER(vidconsole_2) = {
486 .name = "vidconsole2",
487 .id = UCLASS_VIDEO_CONSOLE,
488 .ops = &console_ops_2,
Simon Glassf2661782016-01-14 18:10:37 -0700489 .probe = console_probe_2,
Simon Glassb5146b22016-01-18 19:52:19 -0700490};
491
492U_BOOT_DRIVER(vidconsole_3) = {
493 .name = "vidconsole3",
494 .id = UCLASS_VIDEO_CONSOLE,
495 .ops = &console_ops_3,
496 .probe = console_probe_1_3,
497};