"Das U-Boot" Source Tree
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2015 Google, Inc
4 * (C) Copyright 2015
5 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
6 * (C) Copyright 2023 Dzmitry Sankouski <dsankouski@gmail.com>
7 */
8
9#include <charset.h>
10#include <dm.h>
11#include <video.h>
12#include <video_console.h>
13#include <video_font.h> /* Get font data, width and height */
14#include "vidconsole_internal.h"
15
16static int console_set_row(struct udevice *dev, uint row, int clr)
17{
18 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
19 struct console_simple_priv *priv = dev_get_priv(dev);
20 struct video_fontdata *fontdata = priv->fontdata;
21 void *line, *dst, *end;
22 int pixels = fontdata->height * vid_priv->xsize;
23 int ret;
24 int i;
25 int pbytes;
26
27 ret = check_bpix_support(vid_priv->bpix);
28 if (ret)
29 return ret;
30
31 line = vid_priv->fb + row * fontdata->height * vid_priv->line_length;
32 dst = line;
33 pbytes = VNBYTES(vid_priv->bpix);
34 for (i = 0; i < pixels; i++)
35 fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
36 end = dst;
37
38 ret = vidconsole_sync_copy(dev, line, end);
39 if (ret)
40 return ret;
41
42 return 0;
43}
44
45static int console_move_rows(struct udevice *dev, uint rowdst,
46 uint rowsrc, uint count)
47{
48 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
49 struct console_simple_priv *priv = dev_get_priv(dev);
50 struct video_fontdata *fontdata = priv->fontdata;
51 void *dst;
52 void *src;
53 int size;
54 int ret;
55
56 dst = vid_priv->fb + rowdst * fontdata->height * vid_priv->line_length;
57 src = vid_priv->fb + rowsrc * fontdata->height * vid_priv->line_length;
58 size = fontdata->height * vid_priv->line_length * count;
59 ret = vidconsole_memmove(dev, dst, src, size);
60 if (ret)
61 return ret;
62
63 return 0;
64}
65
66static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp)
67{
68 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
69 struct udevice *vid = dev->parent;
70 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
71 struct console_simple_priv *priv = dev_get_priv(dev);
72 struct video_fontdata *fontdata = priv->fontdata;
73 int pbytes = VNBYTES(vid_priv->bpix);
74 int x, linenum, ret;
75 void *start, *line;
76 u8 ch = console_utf_to_cp437(cp);
77 uchar *pfont = fontdata->video_fontdata +
78 ch * fontdata->char_pixel_bytes;
79
80 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
81 return -EAGAIN;
82 linenum = y;
83 x = VID_TO_PIXEL(x_frac);
84 start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes;
85 line = start;
86
87 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
88 return -EAGAIN;
89
90 ret = fill_char_vertically(pfont, &line, vid_priv, fontdata, NORMAL_DIRECTION);
91 if (ret)
92 return ret;
93
94 ret = vidconsole_sync_copy(dev, start, line);
95 if (ret)
96 return ret;
97
98 return VID_TO_POS(fontdata->width);
99}
100
101static int console_set_cursor_visible(struct udevice *dev, bool visible,
102 uint x, uint y, uint index)
103{
104 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
105 struct udevice *vid = dev->parent;
106 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
107 struct console_simple_priv *priv = dev_get_priv(dev);
108 struct video_fontdata *fontdata = priv->fontdata;
109 int pbytes = VNBYTES(vid_priv->bpix);
110 void *start, *line;
111
112 /* for now, this is not used outside expo */
113 if (!IS_ENABLED(CONFIG_EXPO))
114 return -ENOSYS;
115
116 x += index * fontdata->width;
117 start = vid_priv->fb + y * vid_priv->line_length + x * pbytes;
118
119 /* place the cursor 1 pixel before the start of the next char */
120 x -= 1;
121
122 line = start;
123 draw_cursor_vertically(&line, vid_priv, vc_priv->y_charsize,
124 NORMAL_DIRECTION);
125
126 return 0;
127}
128
129struct vidconsole_ops console_ops = {
130 .putc_xy = console_putc_xy,
131 .move_rows = console_move_rows,
132 .set_row = console_set_row,
133 .get_font_size = console_simple_get_font_size,
134 .get_font = console_simple_get_font,
135 .select_font = console_simple_select_font,
136 .set_cursor_visible = console_set_cursor_visible,
137};
138
139U_BOOT_DRIVER(vidconsole_normal) = {
140 .name = "vidconsole0",
141 .id = UCLASS_VIDEO_CONSOLE,
142 .ops = &console_ops,
143 .probe = console_probe,
144 .priv_auto = sizeof(struct console_simple_priv),
145};