1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2015 Google, Inc
5 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
11 #include <video_console.h>
12 #include <video_font.h> /* Get font data, width and height */
14 static int console_set_row_1(struct udevice *dev, uint row, int clr)
16 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
17 int pbytes = VNBYTES(vid_priv->bpix);
21 line = vid_priv->fb + vid_priv->line_length -
22 (row + 1) * VIDEO_FONT_HEIGHT * pbytes;
23 for (j = 0; j < vid_priv->ysize; j++) {
24 switch (vid_priv->bpix) {
25 #ifdef CONFIG_VIDEO_BPP8
29 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
34 #ifdef CONFIG_VIDEO_BPP16
38 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
43 #ifdef CONFIG_VIDEO_BPP32
47 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
55 line += vid_priv->line_length;
61 static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
64 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
67 int pbytes = VNBYTES(vid_priv->bpix);
70 dst = vid_priv->fb + vid_priv->line_length -
71 (rowdst + count) * VIDEO_FONT_HEIGHT * pbytes;
72 src = vid_priv->fb + vid_priv->line_length -
73 (rowsrc + count) * VIDEO_FONT_HEIGHT * pbytes;
75 for (j = 0; j < vid_priv->ysize; j++) {
76 memmove(dst, src, VIDEO_FONT_HEIGHT * pbytes * count);
77 src += vid_priv->line_length;
78 dst += vid_priv->line_length;
84 static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
86 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
87 struct udevice *vid = dev->parent;
88 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
89 int pbytes = VNBYTES(vid_priv->bpix);
93 uchar *pfont = video_fontdata + ch * VIDEO_FONT_HEIGHT;
95 line = vid_priv->fb + (VID_TO_PIXEL(x_frac) + 1) *
96 vid_priv->line_length - (y + 1) * pbytes;
97 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
100 for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
101 switch (vid_priv->bpix) {
102 #ifdef CONFIG_VIDEO_BPP8
106 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
107 *dst-- = (pfont[i] & mask) ? vid_priv->colour_fg
108 : vid_priv->colour_bg;
113 #ifdef CONFIG_VIDEO_BPP16
115 uint16_t *dst = line;
117 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
118 *dst-- = (pfont[i] & mask) ? vid_priv->colour_fg
119 : vid_priv->colour_bg;
124 #ifdef CONFIG_VIDEO_BPP32
126 uint32_t *dst = line;
128 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
129 *dst-- = (pfont[i] & mask) ? vid_priv->colour_fg
130 : vid_priv->colour_bg;
138 line += vid_priv->line_length;
142 return VID_TO_POS(VIDEO_FONT_WIDTH);
146 static int console_set_row_2(struct udevice *dev, uint row, int clr)
148 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
150 int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
153 line = vid_priv->fb + vid_priv->ysize * vid_priv->line_length -
154 (row + 1) * VIDEO_FONT_HEIGHT * vid_priv->line_length;
155 switch (vid_priv->bpix) {
156 #ifdef CONFIG_VIDEO_BPP8
160 for (i = 0; i < pixels; i++)
165 #ifdef CONFIG_VIDEO_BPP16
167 uint16_t *dst = line;
169 for (i = 0; i < pixels; i++)
174 #ifdef CONFIG_VIDEO_BPP32
176 uint32_t *dst = line;
178 for (i = 0; i < pixels; i++)
190 static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
193 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
198 end = vid_priv->fb + vid_priv->ysize * vid_priv->line_length;
199 dst = end - (rowdst + count) * VIDEO_FONT_HEIGHT *
200 vid_priv->line_length;
201 src = end - (rowsrc + count) * VIDEO_FONT_HEIGHT *
202 vid_priv->line_length;
203 memmove(dst, src, VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
208 static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
210 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
211 struct udevice *vid = dev->parent;
212 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
216 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
219 line = vid_priv->fb + (vid_priv->ysize - y - 1) *
220 vid_priv->line_length +
221 (vid_priv->xsize - VID_TO_PIXEL(x_frac) -
222 VIDEO_FONT_WIDTH - 1) * VNBYTES(vid_priv->bpix);
224 for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
225 uchar bits = video_fontdata[ch * VIDEO_FONT_HEIGHT + row];
227 switch (vid_priv->bpix) {
228 #ifdef CONFIG_VIDEO_BPP8
232 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
233 *dst-- = (bits & 0x80) ? vid_priv->colour_fg
234 : vid_priv->colour_bg;
240 #ifdef CONFIG_VIDEO_BPP16
242 uint16_t *dst = line;
244 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
245 *dst-- = (bits & 0x80) ? vid_priv->colour_fg
246 : vid_priv->colour_bg;
252 #ifdef CONFIG_VIDEO_BPP32
254 uint32_t *dst = line;
256 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
257 *dst-- = (bits & 0x80) ? vid_priv->colour_fg
258 : vid_priv->colour_bg;
267 line -= vid_priv->line_length;
270 return VID_TO_POS(VIDEO_FONT_WIDTH);
273 static int console_set_row_3(struct udevice *dev, uint row, int clr)
275 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
276 int pbytes = VNBYTES(vid_priv->bpix);
280 line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * pbytes;
281 for (j = 0; j < vid_priv->ysize; j++) {
282 switch (vid_priv->bpix) {
283 #ifdef CONFIG_VIDEO_BPP8
287 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
292 #ifdef CONFIG_VIDEO_BPP16
294 uint16_t *dst = line;
296 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
301 #ifdef CONFIG_VIDEO_BPP32
303 uint32_t *dst = line;
305 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
313 line += vid_priv->line_length;
319 static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
322 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
325 int pbytes = VNBYTES(vid_priv->bpix);
328 dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * pbytes;
329 src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * pbytes;
331 for (j = 0; j < vid_priv->ysize; j++) {
332 memmove(dst, src, VIDEO_FONT_HEIGHT * pbytes * count);
333 src += vid_priv->line_length;
334 dst += vid_priv->line_length;
340 static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
342 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
343 struct udevice *vid = dev->parent;
344 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
345 int pbytes = VNBYTES(vid_priv->bpix);
348 void *line = vid_priv->fb +
349 (vid_priv->ysize - VID_TO_PIXEL(x_frac) - 1) *
350 vid_priv->line_length + y * pbytes;
351 uchar *pfont = video_fontdata + ch * VIDEO_FONT_HEIGHT;
353 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
356 for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
357 switch (vid_priv->bpix) {
358 #ifdef CONFIG_VIDEO_BPP8
362 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
363 *dst++ = (pfont[i] & mask) ? vid_priv->colour_fg
364 : vid_priv->colour_bg;
369 #ifdef CONFIG_VIDEO_BPP16
371 uint16_t *dst = line;
373 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
374 *dst++ = (pfont[i] & mask) ? vid_priv->colour_fg
375 : vid_priv->colour_bg;
380 #ifdef CONFIG_VIDEO_BPP32
382 uint32_t *dst = line;
384 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
385 *dst++ = (pfont[i] & mask) ? vid_priv->colour_fg
386 : vid_priv->colour_bg;
394 line -= vid_priv->line_length;
398 return VID_TO_POS(VIDEO_FONT_WIDTH);
402 static int console_probe_2(struct udevice *dev)
404 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
405 struct udevice *vid_dev = dev->parent;
406 struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
408 vc_priv->x_charsize = VIDEO_FONT_WIDTH;
409 vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
410 vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
411 vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
416 static int console_probe_1_3(struct udevice *dev)
418 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
419 struct udevice *vid_dev = dev->parent;
420 struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
422 vc_priv->x_charsize = VIDEO_FONT_WIDTH;
423 vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
424 vc_priv->cols = vid_priv->ysize / VIDEO_FONT_WIDTH;
425 vc_priv->rows = vid_priv->xsize / VIDEO_FONT_HEIGHT;
426 vc_priv->xsize_frac = VID_TO_POS(vid_priv->ysize);
431 struct vidconsole_ops console_ops_1 = {
432 .putc_xy = console_putc_xy_1,
433 .move_rows = console_move_rows_1,
434 .set_row = console_set_row_1,
437 struct vidconsole_ops console_ops_2 = {
438 .putc_xy = console_putc_xy_2,
439 .move_rows = console_move_rows_2,
440 .set_row = console_set_row_2,
443 struct vidconsole_ops console_ops_3 = {
444 .putc_xy = console_putc_xy_3,
445 .move_rows = console_move_rows_3,
446 .set_row = console_set_row_3,
449 U_BOOT_DRIVER(vidconsole_1) = {
450 .name = "vidconsole1",
451 .id = UCLASS_VIDEO_CONSOLE,
452 .ops = &console_ops_1,
453 .probe = console_probe_1_3,
456 U_BOOT_DRIVER(vidconsole_2) = {
457 .name = "vidconsole2",
458 .id = UCLASS_VIDEO_CONSOLE,
459 .ops = &console_ops_2,
460 .probe = console_probe_2,
463 U_BOOT_DRIVER(vidconsole_3) = {
464 .name = "vidconsole3",
465 .id = UCLASS_VIDEO_CONSOLE,
466 .ops = &console_ops_3,
467 .probe = console_probe_1_3,