]> git.ipfire.org Git - thirdparty/u-boot.git/blame - drivers/video/vidconsole-uclass.c
video: Support showing a cursor
[thirdparty/u-boot.git] / drivers / video / vidconsole-uclass.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
83510766
SG
2/*
3 * Copyright (c) 2015 Google, Inc
4 * (C) Copyright 2001-2015
5 * DENX Software Engineering -- wd@denx.de
6 * Compulab Ltd - http://compulab.co.il/
7 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
83510766
SG
8 */
9
b953ec2b
PD
10#define LOG_CATEGORY UCLASS_VIDEO_CONSOLE
11
83510766 12#include <common.h>
9899eef2 13#include <abuf.h>
09140113 14#include <command.h>
8b763dfd 15#include <console.h>
f7ae49fc 16#include <log.h>
83510766
SG
17#include <dm.h>
18#include <video.h>
19#include <video_console.h>
5fba5329 20#include <video_font.h> /* Bitmap font for code page 437 */
8b763dfd 21#include <linux/ctype.h>
83510766 22
83510766
SG
23int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch)
24{
25 struct vidconsole_ops *ops = vidconsole_get_ops(dev);
26
27 if (!ops->putc_xy)
28 return -ENOSYS;
29 return ops->putc_xy(dev, x, y, ch);
30}
31
32int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
33 uint count)
34{
35 struct vidconsole_ops *ops = vidconsole_get_ops(dev);
36
37 if (!ops->move_rows)
38 return -ENOSYS;
39 return ops->move_rows(dev, rowdst, rowsrc, count);
40}
41
42int vidconsole_set_row(struct udevice *dev, uint row, int clr)
43{
44 struct vidconsole_ops *ops = vidconsole_get_ops(dev);
45
46 if (!ops->set_row)
47 return -ENOSYS;
48 return ops->set_row(dev, row, clr);
49}
50
617d7b54 51int vidconsole_entry_start(struct udevice *dev)
58c733a7
SG
52{
53 struct vidconsole_ops *ops = vidconsole_get_ops(dev);
54
55 if (!ops->entry_start)
56 return -ENOSYS;
57 return ops->entry_start(dev);
58}
59
83510766 60/* Move backwards one space */
7b9f7e44 61static int vidconsole_back(struct udevice *dev)
83510766
SG
62{
63 struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
7b9f7e44
SG
64 struct vidconsole_ops *ops = vidconsole_get_ops(dev);
65 int ret;
66
67 if (ops->backspace) {
68 ret = ops->backspace(dev);
69 if (ret != -ENOSYS)
70 return ret;
71 }
83510766 72
f2661786 73 priv->xcur_frac -= VID_TO_POS(priv->x_charsize);
c5b77d01 74 if (priv->xcur_frac < priv->xstart_frac) {
f2661786
SG
75 priv->xcur_frac = (priv->cols - 1) *
76 VID_TO_POS(priv->x_charsize);
77 priv->ycur -= priv->y_charsize;
78 if (priv->ycur < 0)
79 priv->ycur = 0;
83510766 80 }
9de731f2 81 return video_sync(dev->parent, false);
83510766
SG
82}
83
84/* Move to a newline, scrolling the display if necessary */
85static void vidconsole_newline(struct udevice *dev)
86{
87 struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
88 struct udevice *vid_dev = dev->parent;
89 struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
86fbee60 90 const int rows = CONFIG_VAL(CONSOLE_SCROLL_LINES);
9de731f2 91 int i, ret;
83510766 92
c5b77d01 93 priv->xcur_frac = priv->xstart_frac;
f2661786 94 priv->ycur += priv->y_charsize;
83510766
SG
95
96 /* Check if we need to scroll the terminal */
f2661786 97 if ((priv->ycur + priv->y_charsize) / priv->y_charsize > priv->rows) {
83510766
SG
98 vidconsole_move_rows(dev, 0, rows, priv->rows - rows);
99 for (i = 0; i < rows; i++)
100 vidconsole_set_row(dev, priv->rows - i - 1,
101 vid_priv->colour_bg);
f2661786 102 priv->ycur -= rows * priv->y_charsize;
83510766 103 }
58c733a7
SG
104 priv->last_ch = 0;
105
9de731f2
MS
106 ret = video_sync(dev->parent, false);
107 if (ret) {
108#ifdef DEBUG
109 console_puts_select_stderr(true, "[vc err: video_sync]");
110#endif
111 }
83510766
SG
112}
113
a085aa1f
RC
114static char *parsenum(char *s, int *num)
115{
116 char *end;
117 *num = simple_strtol(s, &end, 10);
118 return end;
119}
120
6b6dc0d2
SG
121void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y)
122{
123 struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
124
125 priv->xcur_frac = VID_TO_POS(x);
126 priv->xstart_frac = priv->xcur_frac;
127 priv->ycur = y;
128}
129
f6546c78
TR
130/**
131 * set_cursor_position() - set cursor position
132 *
133 * @priv: private data of the video console
134 * @row: new row
135 * @col: new column
136 */
137static void set_cursor_position(struct vidconsole_priv *priv, int row, int col)
662f381a 138{
f6546c78
TR
139 /*
140 * Ensure we stay in the bounds of the screen.
141 */
142 if (row >= priv->rows)
143 row = priv->rows - 1;
144 if (col >= priv->cols)
145 col = priv->cols - 1;
146
147 priv->ycur = row * priv->y_charsize;
148 priv->xcur_frac = priv->xstart_frac +
149 VID_TO_POS(col * priv->x_charsize);
662f381a
HS
150}
151
152/**
153 * get_cursor_position() - get cursor position
154 *
155 * @priv: private data of the video console
156 * @row: row
157 * @col: column
158 */
159static void get_cursor_position(struct vidconsole_priv *priv,
160 int *row, int *col)
161{
162 *row = priv->ycur / priv->y_charsize;
163 *col = VID_TO_PIXEL(priv->xcur_frac - priv->xstart_frac) /
164 priv->x_charsize;
165}
166
a085aa1f
RC
167/*
168 * Process a character while accumulating an escape string. Chars are
169 * accumulated into escape_buf until the end of escape sequence is
170 * found, at which point the sequence is parsed and processed.
171 */
172static void vidconsole_escape_char(struct udevice *dev, char ch)
173{
174 struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
175
176 if (!IS_ENABLED(CONFIG_VIDEO_ANSI))
177 goto error;
178
179 /* Sanity checking for bogus ESC sequences: */
180 if (priv->escape_len >= sizeof(priv->escape_buf))
181 goto error;
662f381a
HS
182 if (priv->escape_len == 0) {
183 switch (ch) {
184 case '7':
185 /* Save cursor position */
186 get_cursor_position(priv, &priv->row_saved,
187 &priv->col_saved);
188 priv->escape = 0;
189
190 return;
191 case '8': {
192 /* Restore cursor position */
193 int row = priv->row_saved;
194 int col = priv->col_saved;
195
f6546c78 196 set_cursor_position(priv, row, col);
662f381a
HS
197 priv->escape = 0;
198 return;
199 }
200 case '[':
201 break;
202 default:
203 goto error;
204 }
205 }
a085aa1f
RC
206
207 priv->escape_buf[priv->escape_len++] = ch;
208
209 /*
210 * Escape sequences are terminated by a letter, so keep
211 * accumulating until we get one:
212 */
213 if (!isalpha(ch))
214 return;
215
216 /*
217 * clear escape mode first, otherwise things will get highly
218 * surprising if you hit any debug prints that come back to
219 * this console.
220 */
221 priv->escape = 0;
222
223 switch (ch) {
29c158b9
AP
224 case 'A':
225 case 'B':
226 case 'C':
227 case 'D':
228 case 'E':
229 case 'F': {
230 int row, col, num;
231 char *s = priv->escape_buf;
232
233 /*
234 * Cursor up/down: [%dA, [%dB, [%dE, [%dF
235 * Cursor left/right: [%dD, [%dC
236 */
237 s++; /* [ */
238 s = parsenum(s, &num);
239 if (num == 0) /* No digit in sequence ... */
240 num = 1; /* ... means "move by 1". */
241
242 get_cursor_position(priv, &row, &col);
243 if (ch == 'A' || ch == 'F')
244 row -= num;
245 if (ch == 'C')
246 col += num;
247 if (ch == 'D')
248 col -= num;
249 if (ch == 'B' || ch == 'E')
250 row += num;
251 if (ch == 'E' || ch == 'F')
252 col = 0;
253 if (col < 0)
254 col = 0;
255 if (row < 0)
256 row = 0;
257 /* Right and bottom overflows are handled in the callee. */
f6546c78 258 set_cursor_position(priv, row, col);
29c158b9
AP
259 break;
260 }
a085aa1f
RC
261 case 'H':
262 case 'f': {
263 int row, col;
264 char *s = priv->escape_buf;
265
266 /*
267 * Set cursor position: [%d;%df or [%d;%dH
268 */
269 s++; /* [ */
270 s = parsenum(s, &row);
271 s++; /* ; */
272 s = parsenum(s, &col);
273
118f020d
HS
274 /*
275 * Video origin is [0, 0], terminal origin is [1, 1].
276 */
277 if (row)
278 --row;
279 if (col)
280 --col;
281
f6546c78 282 set_cursor_position(priv, row, col);
a085aa1f
RC
283
284 break;
285 }
286 case 'J': {
287 int mode;
288
289 /*
290 * Clear part/all screen:
291 * [J or [0J - clear screen from cursor down
292 * [1J - clear screen from cursor up
293 * [2J - clear entire screen
294 *
295 * TODO we really only handle entire-screen case, others
296 * probably require some additions to video-uclass (and
297 * are not really needed yet by efi_console)
298 */
299 parsenum(priv->escape_buf + 1, &mode);
300
301 if (mode == 2) {
9de731f2
MS
302 int ret;
303
a085aa1f 304 video_clear(dev->parent);
9de731f2
MS
305 ret = video_sync(dev->parent, false);
306 if (ret) {
307#ifdef DEBUG
308 console_puts_select_stderr(true, "[vc err: video_sync]");
309#endif
310 }
a085aa1f
RC
311 priv->ycur = 0;
312 priv->xcur_frac = priv->xstart_frac;
313 } else {
314 debug("unsupported clear mode: %d\n", mode);
315 }
316 break;
317 }
4422294c
AP
318 case 'K': {
319 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
320 int mode;
321
322 /*
323 * Clear (parts of) current line
324 * [0K - clear line to end
325 * [2K - clear entire line
326 */
327 parsenum(priv->escape_buf + 1, &mode);
328
329 if (mode == 2) {
330 int row, col;
331
332 get_cursor_position(priv, &row, &col);
333 vidconsole_set_row(dev, row, vid_priv->colour_bg);
334 }
335 break;
336 }
703d885c
RC
337 case 'm': {
338 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
339 char *s = priv->escape_buf;
340 char *end = &priv->escape_buf[priv->escape_len];
341
342 /*
343 * Set graphics mode: [%d;...;%dm
344 *
345 * Currently only supports the color attributes:
346 *
347 * Foreground Colors:
348 *
349 * 30 Black
350 * 31 Red
351 * 32 Green
352 * 33 Yellow
353 * 34 Blue
354 * 35 Magenta
355 * 36 Cyan
356 * 37 White
357 *
358 * Background Colors:
359 *
360 * 40 Black
361 * 41 Red
362 * 42 Green
363 * 43 Yellow
364 * 44 Blue
365 * 45 Magenta
366 * 46 Cyan
367 * 47 White
368 */
369
370 s++; /* [ */
371 while (s < end) {
372 int val;
373
374 s = parsenum(s, &val);
375 s++;
376
377 switch (val) {
9ffa4d12
HS
378 case 0:
379 /* all attributes off */
b9f210a3 380 video_set_default_colors(dev->parent, false);
9ffa4d12
HS
381 break;
382 case 1:
383 /* bold */
384 vid_priv->fg_col_idx |= 8;
a032e4b5 385 vid_priv->colour_fg = video_index_to_colour(
9ffa4d12
HS
386 vid_priv, vid_priv->fg_col_idx);
387 break;
eabb0725
AP
388 case 7:
389 /* reverse video */
a032e4b5 390 vid_priv->colour_fg = video_index_to_colour(
eabb0725 391 vid_priv, vid_priv->bg_col_idx);
a032e4b5 392 vid_priv->colour_bg = video_index_to_colour(
eabb0725
AP
393 vid_priv, vid_priv->fg_col_idx);
394 break;
703d885c 395 case 30 ... 37:
5c30fbb8 396 /* foreground color */
9ffa4d12
HS
397 vid_priv->fg_col_idx &= ~7;
398 vid_priv->fg_col_idx |= val - 30;
a032e4b5 399 vid_priv->colour_fg = video_index_to_colour(
9ffa4d12 400 vid_priv, vid_priv->fg_col_idx);
703d885c
RC
401 break;
402 case 40 ... 47:
eabb0725
AP
403 /* background color, also mask the bold bit */
404 vid_priv->bg_col_idx &= ~0xf;
405 vid_priv->bg_col_idx |= val - 40;
a032e4b5 406 vid_priv->colour_bg = video_index_to_colour(
eabb0725 407 vid_priv, vid_priv->bg_col_idx);
703d885c
RC
408 break;
409 default:
5c30fbb8 410 /* ignore unsupported SGR parameter */
703d885c
RC
411 break;
412 }
413 }
414
415 break;
416 }
a085aa1f
RC
417 default:
418 debug("unrecognized escape sequence: %*s\n",
419 priv->escape_len, priv->escape_buf);
420 }
421
422 return;
423
424error:
425 /* something went wrong, just revert to normal mode: */
426 priv->escape = 0;
427}
428
7035ec3c
AP
429/* Put that actual character on the screen (using the CP437 code page). */
430static int vidconsole_output_glyph(struct udevice *dev, char ch)
431{
432 struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
433 int ret;
434
435 /*
436 * Failure of this function normally indicates an unsupported
437 * colour depth. Check this and return an error to help with
438 * diagnosis.
439 */
440 ret = vidconsole_putc_xy(dev, priv->xcur_frac, priv->ycur, ch);
441 if (ret == -EAGAIN) {
442 vidconsole_newline(dev);
443 ret = vidconsole_putc_xy(dev, priv->xcur_frac, priv->ycur, ch);
444 }
445 if (ret < 0)
446 return ret;
447 priv->xcur_frac += ret;
448 priv->last_ch = ch;
449 if (priv->xcur_frac >= priv->xsize_frac)
450 vidconsole_newline(dev);
451
452 return 0;
453}
454
83510766
SG
455int vidconsole_put_char(struct udevice *dev, char ch)
456{
457 struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
458 int ret;
459
a085aa1f
RC
460 if (priv->escape) {
461 vidconsole_escape_char(dev, ch);
462 return 0;
463 }
464
83510766 465 switch (ch) {
a085aa1f
RC
466 case '\x1b':
467 priv->escape_len = 0;
468 priv->escape = 1;
469 break;
5508f10a
SG
470 case '\a':
471 /* beep */
472 break;
83510766 473 case '\r':
c5b77d01 474 priv->xcur_frac = priv->xstart_frac;
83510766
SG
475 break;
476 case '\n':
477 vidconsole_newline(dev);
58c733a7 478 vidconsole_entry_start(dev);
83510766
SG
479 break;
480 case '\t': /* Tab (8 chars alignment) */
f2661786
SG
481 priv->xcur_frac = ((priv->xcur_frac / priv->tab_width_frac)
482 + 1) * priv->tab_width_frac;
83510766 483
f2661786 484 if (priv->xcur_frac >= priv->xsize_frac)
83510766
SG
485 vidconsole_newline(dev);
486 break;
487 case '\b':
488 vidconsole_back(dev);
58c733a7 489 priv->last_ch = 0;
83510766
SG
490 break;
491 default:
7035ec3c 492 ret = vidconsole_output_glyph(dev, ch);
f2661786 493 if (ret < 0)
83510766 494 return ret;
83510766
SG
495 break;
496 }
497
498 return 0;
499}
500
e63168a9
MV
501int vidconsole_put_string(struct udevice *dev, const char *str)
502{
503 const char *s;
504 int ret;
505
506 for (s = str; *s; s++) {
507 ret = vidconsole_put_char(dev, *s);
508 if (ret)
509 return ret;
510 }
511
512 return 0;
513}
514
83510766
SG
515static void vidconsole_putc(struct stdio_dev *sdev, const char ch)
516{
517 struct udevice *dev = sdev->priv;
8b763dfd 518 int ret;
83510766 519
8b763dfd
SG
520 ret = vidconsole_put_char(dev, ch);
521 if (ret) {
522#ifdef DEBUG
523 console_puts_select_stderr(true, "[vc err: putc]");
524#endif
525 }
9de731f2
MS
526 ret = video_sync(dev->parent, false);
527 if (ret) {
528#ifdef DEBUG
529 console_puts_select_stderr(true, "[vc err: video_sync]");
530#endif
531 }
83510766
SG
532}
533
534static void vidconsole_puts(struct stdio_dev *sdev, const char *s)
535{
536 struct udevice *dev = sdev->priv;
8b763dfd
SG
537 int ret;
538
539 ret = vidconsole_put_string(dev, s);
540 if (ret) {
541#ifdef DEBUG
542 char str[30];
83510766 543
8b763dfd
SG
544 snprintf(str, sizeof(str), "[vc err: puts %d]", ret);
545 console_puts_select_stderr(true, str);
546#endif
547 }
9de731f2
MS
548 ret = video_sync(dev->parent, false);
549 if (ret) {
550#ifdef DEBUG
551 console_puts_select_stderr(true, "[vc err: video_sync]");
552#endif
553 }
83510766
SG
554}
555
0e38bd84
SG
556void vidconsole_list_fonts(struct udevice *dev)
557{
558 struct vidfont_info info;
559 int ret, i;
560
561 for (i = 0, ret = 0; !ret; i++) {
562 ret = vidconsole_get_font(dev, i, &info);
563 if (!ret)
564 printf("%s\n", info.name);
565 }
566}
567
568int vidconsole_get_font(struct udevice *dev, int seq,
569 struct vidfont_info *info)
570{
571 struct vidconsole_ops *ops = vidconsole_get_ops(dev);
572
573 if (!ops->get_font)
574 return -ENOSYS;
575
576 return ops->get_font(dev, seq, info);
577}
578
4f6e3481
DS
579int vidconsole_get_font_size(struct udevice *dev, const char **name, uint *sizep)
580{
581 struct vidconsole_ops *ops = vidconsole_get_ops(dev);
582
583 if (!ops->get_font_size)
584 return -ENOSYS;
585
586 *name = ops->get_font_size(dev, sizep);
587 return 0;
588}
589
0e38bd84
SG
590int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
591{
592 struct vidconsole_ops *ops = vidconsole_get_ops(dev);
593
594 if (!ops->select_font)
595 return -ENOSYS;
596
597 return ops->select_font(dev, name, size);
598}
599
b828ed7d
SG
600int vidconsole_measure(struct udevice *dev, const char *name, uint size,
601 const char *text, struct vidconsole_bbox *bbox)
602{
603 struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
604 struct vidconsole_ops *ops = vidconsole_get_ops(dev);
605 int ret;
606
01c76f1a 607 if (ops->measure) {
b828ed7d
SG
608 ret = ops->measure(dev, name, size, text, bbox);
609 if (ret != -ENOSYS)
610 return ret;
611 }
612
613 bbox->valid = true;
614 bbox->x0 = 0;
615 bbox->y0 = 0;
616 bbox->x1 = priv->x_charsize * strlen(text);
617 bbox->y1 = priv->y_charsize;
618
619 return 0;
620}
621
9e55d095
SG
622int vidconsole_nominal(struct udevice *dev, const char *name, uint size,
623 uint num_chars, struct vidconsole_bbox *bbox)
624{
625 struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
626 struct vidconsole_ops *ops = vidconsole_get_ops(dev);
627 int ret;
628
629 if (ops->measure) {
630 ret = ops->nominal(dev, name, size, num_chars, bbox);
631 if (ret != -ENOSYS)
632 return ret;
633 }
634
635 bbox->valid = true;
636 bbox->x0 = 0;
637 bbox->y0 = 0;
638 bbox->x1 = priv->x_charsize * num_chars;
639 bbox->y1 = priv->y_charsize;
640
641 return 0;
642}
643
9899eef2
SG
644int vidconsole_entry_save(struct udevice *dev, struct abuf *buf)
645{
646 struct vidconsole_ops *ops = vidconsole_get_ops(dev);
647 int ret;
648
649 if (ops->measure) {
650 ret = ops->entry_save(dev, buf);
651 if (ret != -ENOSYS)
652 return ret;
653 }
654
655 /* no data so make sure the buffer is empty */
656 abuf_realloc(buf, 0);
657
658 return 0;
659}
660
661int vidconsole_entry_restore(struct udevice *dev, struct abuf *buf)
662{
663 struct vidconsole_ops *ops = vidconsole_get_ops(dev);
664 int ret;
665
666 if (ops->measure) {
667 ret = ops->entry_restore(dev, buf);
668 if (ret != -ENOSYS)
669 return ret;
670 }
671
672 return 0;
673}
674
37db20d0
SG
675int vidconsole_set_cursor_visible(struct udevice *dev, bool visible,
676 uint x, uint y, uint index)
677{
678 struct vidconsole_ops *ops = vidconsole_get_ops(dev);
679 int ret;
680
681 if (ops->set_cursor_visible) {
682 ret = ops->set_cursor_visible(dev, visible, x, y, index);
683 if (ret != -ENOSYS)
684 return ret;
685 }
686
687 return 0;
688}
689
648a4991
SG
690void vidconsole_push_colour(struct udevice *dev, enum colour_idx fg,
691 enum colour_idx bg, struct vidconsole_colour *old)
692{
693 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
694
695 old->colour_fg = vid_priv->colour_fg;
696 old->colour_bg = vid_priv->colour_bg;
697
698 vid_priv->colour_fg = video_index_to_colour(vid_priv, fg);
699 vid_priv->colour_bg = video_index_to_colour(vid_priv, bg);
700}
701
702void vidconsole_pop_colour(struct udevice *dev, struct vidconsole_colour *old)
703{
704 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
705
706 vid_priv->colour_fg = old->colour_fg;
707 vid_priv->colour_bg = old->colour_bg;
708}
709
83510766
SG
710/* Set up the number of rows and colours (rotated drivers override this) */
711static int vidconsole_pre_probe(struct udevice *dev)
712{
713 struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
714 struct udevice *vid = dev->parent;
715 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
716
f2661786 717 priv->xsize_frac = VID_TO_POS(vid_priv->xsize);
83510766
SG
718
719 return 0;
720}
721
722/* Register the device with stdio */
723static int vidconsole_post_probe(struct udevice *dev)
724{
725 struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
726 struct stdio_dev *sdev = &priv->sdev;
83510766 727
f2661786
SG
728 if (!priv->tab_width_frac)
729 priv->tab_width_frac = VID_TO_POS(priv->x_charsize) * 8;
730
8b85dfc6 731 if (dev_seq(dev)) {
f1a1247d 732 snprintf(sdev->name, sizeof(sdev->name), "vidconsole%d",
8b85dfc6 733 dev_seq(dev));
f1a1247d
SG
734 } else {
735 strcpy(sdev->name, "vidconsole");
736 }
f2661786 737
83510766
SG
738 sdev->flags = DEV_FLAGS_OUTPUT;
739 sdev->putc = vidconsole_putc;
740 sdev->puts = vidconsole_puts;
741 sdev->priv = dev;
83510766 742
720873bf 743 return stdio_register(sdev);
83510766
SG
744}
745
746UCLASS_DRIVER(vidconsole) = {
747 .id = UCLASS_VIDEO_CONSOLE,
748 .name = "vidconsole0",
749 .pre_probe = vidconsole_pre_probe,
750 .post_probe = vidconsole_post_probe,
41575d8e 751 .per_device_auto = sizeof(struct vidconsole_priv),
83510766
SG
752};
753
8c0b5d26
SG
754#ifdef CONFIG_VIDEO_COPY
755int vidconsole_sync_copy(struct udevice *dev, void *from, void *to)
756{
757 struct udevice *vid = dev_get_parent(dev);
758
759 return video_sync_copy(vid, from, to);
760}
761
762int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
763 int size)
764{
765 memmove(dst, src, size);
766 return vidconsole_sync_copy(dev, dst, dst + size);
767}
768#endif
a76b60f8
SG
769
770int vidconsole_clear_and_reset(struct udevice *dev)
771{
772 int ret;
773
774 ret = video_clear(dev_get_parent(dev));
775 if (ret)
776 return ret;
777 vidconsole_position_cursor(dev, 0, 0);
778
779 return 0;
780}
f6546c78
TR
781
782void vidconsole_position_cursor(struct udevice *dev, unsigned col, unsigned row)
783{
784 struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
785 struct udevice *vid_dev = dev->parent;
786 struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
787 short x, y;
788
789 x = min_t(short, col * priv->x_charsize, vid_priv->xsize - 1);
790 y = min_t(short, row * priv->y_charsize, vid_priv->ysize - 1);
791 vidconsole_set_cursor_pos(dev, x, y);
792}