2 * Copyright (c) 2015 Google, Inc
4 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
6 * SPDX-License-Identifier: GPL-2.0+
12 #include <video_console.h>
13 #include <video_font.h> /* Get font data, width and height */
15 static int console_set_row_1(struct udevice *dev, uint row, int clr)
17 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
18 int pbytes = VNBYTES(vid_priv->bpix);
22 line = vid_priv->fb + vid_priv->line_length -
23 (row + 1) * VIDEO_FONT_HEIGHT * pbytes;
24 for (j = 0; j < vid_priv->ysize; j++) {
25 switch (vid_priv->bpix) {
26 #ifdef CONFIG_VIDEO_BPP8
30 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
35 #ifdef CONFIG_VIDEO_BPP16
39 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
44 #ifdef CONFIG_VIDEO_BPP32
48 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
56 line += vid_priv->line_length;
62 static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
65 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
68 int pbytes = VNBYTES(vid_priv->bpix);
71 dst = vid_priv->fb + vid_priv->line_length -
72 (rowdst + count) * VIDEO_FONT_HEIGHT * pbytes;
73 src = vid_priv->fb + vid_priv->line_length -
74 (rowsrc + count) * VIDEO_FONT_HEIGHT * pbytes;
76 for (j = 0; j < vid_priv->ysize; j++) {
77 memmove(dst, src, VIDEO_FONT_HEIGHT * pbytes * count);
78 src += vid_priv->line_length;
79 dst += vid_priv->line_length;
85 static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
87 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
88 struct udevice *vid = dev->parent;
89 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
90 int pbytes = VNBYTES(vid_priv->bpix);
94 uchar *pfont = video_fontdata + ch * VIDEO_FONT_HEIGHT;
96 line = vid_priv->fb + (VID_TO_PIXEL(x_frac) + 1) *
97 vid_priv->line_length - (y + 1) * pbytes;
98 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
101 for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
102 switch (vid_priv->bpix) {
103 #ifdef CONFIG_VIDEO_BPP8
107 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
108 *dst-- = (pfont[i] & mask) ? vid_priv->colour_fg
109 : vid_priv->colour_bg;
114 #ifdef CONFIG_VIDEO_BPP16
116 uint16_t *dst = line;
118 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
119 *dst-- = (pfont[i] & mask) ? vid_priv->colour_fg
120 : vid_priv->colour_bg;
125 #ifdef CONFIG_VIDEO_BPP32
127 uint32_t *dst = line;
129 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
130 *dst-- = (pfont[i] & mask) ? vid_priv->colour_fg
131 : vid_priv->colour_bg;
139 line += vid_priv->line_length;
143 return VID_TO_POS(VIDEO_FONT_WIDTH);
147 static int console_set_row_2(struct udevice *dev, uint row, int clr)
149 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
151 int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
154 line = vid_priv->fb + vid_priv->ysize * vid_priv->line_length -
155 (row + 1) * VIDEO_FONT_HEIGHT * vid_priv->line_length;
156 switch (vid_priv->bpix) {
157 #ifdef CONFIG_VIDEO_BPP8
161 for (i = 0; i < pixels; i++)
166 #ifdef CONFIG_VIDEO_BPP16
168 uint16_t *dst = line;
170 for (i = 0; i < pixels; i++)
175 #ifdef CONFIG_VIDEO_BPP32
177 uint32_t *dst = line;
179 for (i = 0; i < pixels; i++)
191 static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
194 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
199 end = vid_priv->fb + vid_priv->ysize * vid_priv->line_length;
200 dst = end - (rowdst + count) * VIDEO_FONT_HEIGHT *
201 vid_priv->line_length;
202 src = end - (rowsrc + count) * VIDEO_FONT_HEIGHT *
203 vid_priv->line_length;
204 memmove(dst, src, VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
209 static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
211 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
212 struct udevice *vid = dev->parent;
213 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
217 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
220 line = vid_priv->fb + (vid_priv->ysize - y - 1) *
221 vid_priv->line_length +
222 (vid_priv->xsize - VID_TO_PIXEL(x_frac) -
223 VIDEO_FONT_WIDTH - 1) * VNBYTES(vid_priv->bpix);
225 for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
226 uchar bits = video_fontdata[ch * VIDEO_FONT_HEIGHT + row];
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 + 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,