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, uint y, char ch)
87 struct udevice *vid = dev->parent;
88 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
89 int pbytes = VNBYTES(vid_priv->bpix);
92 void *line = vid_priv->fb + (x + 1) * vid_priv->line_length -
94 uchar *pfont = video_fontdata + ch * VIDEO_FONT_HEIGHT;
96 for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
97 switch (vid_priv->bpix) {
98 #ifdef CONFIG_VIDEO_BPP8
102 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
103 *dst-- = (pfont[i] & mask) ? vid_priv->colour_fg
104 : vid_priv->colour_bg;
109 #ifdef CONFIG_VIDEO_BPP16
111 uint16_t *dst = line;
113 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
114 *dst-- = (pfont[i] & mask) ? vid_priv->colour_fg
115 : vid_priv->colour_bg;
120 #ifdef CONFIG_VIDEO_BPP32
122 uint32_t *dst = line;
124 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
125 *dst-- = (pfont[i] & mask) ? vid_priv->colour_fg
126 : vid_priv->colour_bg;
134 line += vid_priv->line_length;
142 static int console_set_row_2(struct udevice *dev, uint row, int clr)
144 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
146 int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
149 line = vid_priv->fb + vid_priv->ysize * vid_priv->line_length -
150 (row + 1) * VIDEO_FONT_HEIGHT * vid_priv->line_length;
151 switch (vid_priv->bpix) {
152 #ifdef CONFIG_VIDEO_BPP8
156 for (i = 0; i < pixels; i++)
161 #ifdef CONFIG_VIDEO_BPP16
163 uint16_t *dst = line;
165 for (i = 0; i < pixels; i++)
170 #ifdef CONFIG_VIDEO_BPP32
172 uint32_t *dst = line;
174 for (i = 0; i < pixels; i++)
186 static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
189 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
194 end = vid_priv->fb + vid_priv->ysize * vid_priv->line_length;
195 dst = end - (rowdst + count) * VIDEO_FONT_HEIGHT *
196 vid_priv->line_length;
197 src = end - (rowsrc + count) * VIDEO_FONT_HEIGHT *
198 vid_priv->line_length;
199 memmove(dst, src, VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
204 static int console_putc_xy_2(struct udevice *dev, uint x, uint y, char ch)
206 struct udevice *vid = dev->parent;
207 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
211 line = vid_priv->fb + (vid_priv->ysize - y - 1) *
212 vid_priv->line_length +
213 (vid_priv->xsize - x - VIDEO_FONT_WIDTH - 1) *
214 VNBYTES(vid_priv->bpix);
216 for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
217 uchar bits = video_fontdata[ch * VIDEO_FONT_HEIGHT + row];
219 switch (vid_priv->bpix) {
220 #ifdef CONFIG_VIDEO_BPP8
224 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
225 *dst-- = (bits & 0x80) ? vid_priv->colour_fg
226 : vid_priv->colour_bg;
232 #ifdef CONFIG_VIDEO_BPP16
234 uint16_t *dst = line;
236 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
237 *dst-- = (bits & 0x80) ? vid_priv->colour_fg
238 : vid_priv->colour_bg;
244 #ifdef CONFIG_VIDEO_BPP32
246 uint32_t *dst = line;
248 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
249 *dst-- = (bits & 0x80) ? vid_priv->colour_fg
250 : vid_priv->colour_bg;
259 line -= vid_priv->line_length;
265 static int console_set_row_3(struct udevice *dev, uint row, int clr)
267 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
268 int pbytes = VNBYTES(vid_priv->bpix);
272 line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * pbytes;
273 for (j = 0; j < vid_priv->ysize; j++) {
274 switch (vid_priv->bpix) {
275 #ifdef CONFIG_VIDEO_BPP8
279 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
284 #ifdef CONFIG_VIDEO_BPP16
286 uint16_t *dst = line;
288 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
293 #ifdef CONFIG_VIDEO_BPP32
295 uint32_t *dst = line;
297 for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
305 line += vid_priv->line_length;
311 static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
314 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
317 int pbytes = VNBYTES(vid_priv->bpix);
320 dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * pbytes;
321 src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * pbytes;
323 for (j = 0; j < vid_priv->ysize; j++) {
324 memmove(dst, src, VIDEO_FONT_HEIGHT * pbytes * count);
325 src += vid_priv->line_length;
326 dst += vid_priv->line_length;
332 static int console_putc_xy_3(struct udevice *dev, uint x, uint y, char ch)
334 struct udevice *vid = dev->parent;
335 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
336 int pbytes = VNBYTES(vid_priv->bpix);
339 void *line = vid_priv->fb + (vid_priv->ysize - x - 1) *
340 vid_priv->line_length + y * pbytes;
341 uchar *pfont = video_fontdata + ch * VIDEO_FONT_HEIGHT;
343 for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
344 switch (vid_priv->bpix) {
345 #ifdef CONFIG_VIDEO_BPP8
349 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
350 *dst++ = (pfont[i] & mask) ? vid_priv->colour_fg
351 : vid_priv->colour_bg;
356 #ifdef CONFIG_VIDEO_BPP16
358 uint16_t *dst = line;
360 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
361 *dst++ = (pfont[i] & mask) ? vid_priv->colour_fg
362 : vid_priv->colour_bg;
367 #ifdef CONFIG_VIDEO_BPP32
369 uint32_t *dst = line;
371 for (i = 0; i < VIDEO_FONT_HEIGHT; i++) {
372 *dst++ = (pfont[i] & mask) ? vid_priv->colour_fg
373 : vid_priv->colour_bg;
381 line -= vid_priv->line_length;
389 static int console_probe_1_3(struct udevice *dev)
391 struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
392 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
394 priv->cols = vid_priv->ysize / VIDEO_FONT_WIDTH;
395 priv->rows = vid_priv->xsize / VIDEO_FONT_HEIGHT;
400 struct vidconsole_ops console_ops_1 = {
401 .putc_xy = console_putc_xy_1,
402 .move_rows = console_move_rows_1,
403 .set_row = console_set_row_1,
406 struct vidconsole_ops console_ops_2 = {
407 .putc_xy = console_putc_xy_2,
408 .move_rows = console_move_rows_2,
409 .set_row = console_set_row_2,
412 struct vidconsole_ops console_ops_3 = {
413 .putc_xy = console_putc_xy_3,
414 .move_rows = console_move_rows_3,
415 .set_row = console_set_row_3,
418 U_BOOT_DRIVER(vidconsole_1) = {
419 .name = "vidconsole1",
420 .id = UCLASS_VIDEO_CONSOLE,
421 .ops = &console_ops_1,
422 .probe = console_probe_1_3,
425 U_BOOT_DRIVER(vidconsole_2) = {
426 .name = "vidconsole2",
427 .id = UCLASS_VIDEO_CONSOLE,
428 .ops = &console_ops_2,
431 U_BOOT_DRIVER(vidconsole_3) = {
432 .name = "vidconsole3",
433 .id = UCLASS_VIDEO_CONSOLE,
434 .ops = &console_ops_3,
435 .probe = console_probe_1_3,