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 + (u8)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 unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row;
226 uchar bits = video_fontdata[idx];
228 switch (vid_priv->bpix) {
229 #ifdef CONFIG_VIDEO_BPP8
233 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
234 *dst-- = (bits & 0x80) ? vid_priv->colour_fg
235 : vid_priv->colour_bg;
241 #ifdef CONFIG_VIDEO_BPP16
243 uint16_t *dst = line;
245 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
246 *dst-- = (bits & 0x80) ? vid_priv->colour_fg
247 : vid_priv->colour_bg;
253 #ifdef CONFIG_VIDEO_BPP32
255 uint32_t *dst = line;
257 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
258 *dst-- = (bits & 0x80) ? vid_priv->colour_fg
259 : vid_priv->colour_bg;
268 line -= vid_priv->line_length;
271 return VID_TO_POS(VIDEO_FONT_WIDTH);
274 static int console_set_row_3(struct udevice *dev, uint row, int clr)
276 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
277 int pbytes = VNBYTES(vid_priv->bpix);
281 line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * pbytes;
282 for (j = 0; j < vid_priv->ysize; j++) {
283 switch (vid_priv->bpix) {
284 #ifdef CONFIG_VIDEO_BPP8
288 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
293 #ifdef CONFIG_VIDEO_BPP16
295 uint16_t *dst = line;
297 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
302 #ifdef CONFIG_VIDEO_BPP32
304 uint32_t *dst = line;
306 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
314 line += vid_priv->line_length;
320 static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
323 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
326 int pbytes = VNBYTES(vid_priv->bpix);
329 dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * pbytes;
330 src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * pbytes;
332 for (j = 0; j < vid_priv->ysize; j++) {
333 memmove(dst, src, VIDEO_FONT_HEIGHT * pbytes * count);
334 src += vid_priv->line_length;
335 dst += vid_priv->line_length;
341 static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
343 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
344 struct udevice *vid = dev->parent;
345 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
346 int pbytes = VNBYTES(vid_priv->bpix);
349 void *line = vid_priv->fb +
350 (vid_priv->ysize - VID_TO_PIXEL(x_frac) - 1) *
351 vid_priv->line_length + y * pbytes;
352 uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
354 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
357 for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
358 switch (vid_priv->bpix) {
359 #ifdef CONFIG_VIDEO_BPP8
363 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
364 *dst++ = (pfont[i] & mask) ? vid_priv->colour_fg
365 : vid_priv->colour_bg;
370 #ifdef CONFIG_VIDEO_BPP16
372 uint16_t *dst = line;
374 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
375 *dst++ = (pfont[i] & mask) ? vid_priv->colour_fg
376 : vid_priv->colour_bg;
381 #ifdef CONFIG_VIDEO_BPP32
383 uint32_t *dst = line;
385 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
386 *dst++ = (pfont[i] & mask) ? vid_priv->colour_fg
387 : vid_priv->colour_bg;
395 line -= vid_priv->line_length;
399 return VID_TO_POS(VIDEO_FONT_WIDTH);
403 static int console_probe_2(struct udevice *dev)
405 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
406 struct udevice *vid_dev = dev->parent;
407 struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
409 vc_priv->x_charsize = VIDEO_FONT_WIDTH;
410 vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
411 vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
412 vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
417 static int console_probe_1_3(struct udevice *dev)
419 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
420 struct udevice *vid_dev = dev->parent;
421 struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
423 vc_priv->x_charsize = VIDEO_FONT_WIDTH;
424 vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
425 vc_priv->cols = vid_priv->ysize / VIDEO_FONT_WIDTH;
426 vc_priv->rows = vid_priv->xsize / VIDEO_FONT_HEIGHT;
427 vc_priv->xsize_frac = VID_TO_POS(vid_priv->ysize);
432 struct vidconsole_ops console_ops_1 = {
433 .putc_xy = console_putc_xy_1,
434 .move_rows = console_move_rows_1,
435 .set_row = console_set_row_1,
438 struct vidconsole_ops console_ops_2 = {
439 .putc_xy = console_putc_xy_2,
440 .move_rows = console_move_rows_2,
441 .set_row = console_set_row_2,
444 struct vidconsole_ops console_ops_3 = {
445 .putc_xy = console_putc_xy_3,
446 .move_rows = console_move_rows_3,
447 .set_row = console_set_row_3,
450 U_BOOT_DRIVER(vidconsole_1) = {
451 .name = "vidconsole1",
452 .id = UCLASS_VIDEO_CONSOLE,
453 .ops = &console_ops_1,
454 .probe = console_probe_1_3,
457 U_BOOT_DRIVER(vidconsole_2) = {
458 .name = "vidconsole2",
459 .id = UCLASS_VIDEO_CONSOLE,
460 .ops = &console_ops_2,
461 .probe = console_probe_2,
464 U_BOOT_DRIVER(vidconsole_3) = {
465 .name = "vidconsole3",
466 .id = UCLASS_VIDEO_CONSOLE,
467 .ops = &console_ops_3,
468 .probe = console_probe_1_3,