/src/u-boot/drivers/video/console_normal.c
Line | Count | Source |
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 | | |
16 | | static int console_set_row(struct udevice *dev, uint row, int clr) |
17 | 0 | { |
18 | 0 | struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); |
19 | 0 | struct console_simple_priv *priv = dev_get_priv(dev); |
20 | 0 | struct video_fontdata *fontdata = priv->fontdata; |
21 | 0 | void *line, *dst, *end; |
22 | 0 | int pixels = fontdata->height * vid_priv->xsize; |
23 | 0 | int ret; |
24 | 0 | int i; |
25 | 0 | int pbytes; |
26 | |
|
27 | 0 | ret = check_bpix_support(vid_priv->bpix); |
28 | 0 | if (ret) |
29 | 0 | return ret; |
30 | | |
31 | 0 | line = vid_priv->fb + row * fontdata->height * vid_priv->line_length; |
32 | 0 | dst = line; |
33 | 0 | pbytes = VNBYTES(vid_priv->bpix); |
34 | 0 | for (i = 0; i < pixels; i++) |
35 | 0 | fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes); |
36 | 0 | end = dst; |
37 | |
|
38 | 0 | video_damage(dev->parent, |
39 | 0 | 0, |
40 | 0 | fontdata->height * row, |
41 | 0 | vid_priv->xsize, |
42 | 0 | fontdata->height); |
43 | |
|
44 | 0 | return 0; |
45 | 0 | } |
46 | | |
47 | | static int console_move_rows(struct udevice *dev, uint rowdst, |
48 | | uint rowsrc, uint count) |
49 | 0 | { |
50 | 0 | struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); |
51 | 0 | struct console_simple_priv *priv = dev_get_priv(dev); |
52 | 0 | struct video_fontdata *fontdata = priv->fontdata; |
53 | 0 | void *dst; |
54 | 0 | void *src; |
55 | 0 | int size; |
56 | |
|
57 | 0 | dst = vid_priv->fb + rowdst * fontdata->height * vid_priv->line_length; |
58 | 0 | src = vid_priv->fb + rowsrc * fontdata->height * vid_priv->line_length; |
59 | 0 | size = fontdata->height * vid_priv->line_length * count; |
60 | 0 | memmove(dst, src, size); |
61 | |
|
62 | 0 | video_damage(dev->parent, |
63 | 0 | 0, |
64 | 0 | fontdata->height * rowdst, |
65 | 0 | vid_priv->xsize, |
66 | 0 | fontdata->height * count); |
67 | |
|
68 | 0 | return 0; |
69 | 0 | } |
70 | | |
71 | | static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp) |
72 | 0 | { |
73 | 0 | struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); |
74 | 0 | struct udevice *vid = dev->parent; |
75 | 0 | struct video_priv *vid_priv = dev_get_uclass_priv(vid); |
76 | 0 | struct console_simple_priv *priv = dev_get_priv(dev); |
77 | 0 | struct video_fontdata *fontdata = priv->fontdata; |
78 | 0 | int pbytes = VNBYTES(vid_priv->bpix); |
79 | 0 | int x, linenum, ret; |
80 | 0 | void *start, *line; |
81 | 0 | u8 ch = console_utf_to_cp437(cp); |
82 | 0 | uchar *pfont = fontdata->video_fontdata + |
83 | 0 | ch * fontdata->char_pixel_bytes; |
84 | |
|
85 | 0 | if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) |
86 | 0 | return -EAGAIN; |
87 | 0 | linenum = y; |
88 | 0 | x = VID_TO_PIXEL(x_frac); |
89 | 0 | start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes; |
90 | 0 | line = start; |
91 | |
|
92 | 0 | if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) |
93 | 0 | return -EAGAIN; |
94 | | |
95 | 0 | ret = fill_char_vertically(pfont, &line, vid_priv, fontdata, NORMAL_DIRECTION); |
96 | 0 | if (ret) |
97 | 0 | return ret; |
98 | | |
99 | 0 | video_damage(dev->parent, |
100 | 0 | x, |
101 | 0 | y, |
102 | 0 | fontdata->width, |
103 | 0 | fontdata->height); |
104 | |
|
105 | 0 | return VID_TO_POS(fontdata->width); |
106 | 0 | } |
107 | | |
108 | | static int console_set_cursor_visible(struct udevice *dev, bool visible, |
109 | | uint x, uint y, uint index) |
110 | 0 | { |
111 | 0 | struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); |
112 | 0 | struct udevice *vid = dev->parent; |
113 | 0 | struct video_priv *vid_priv = dev_get_uclass_priv(vid); |
114 | 0 | struct console_simple_priv *priv = dev_get_priv(dev); |
115 | 0 | struct video_fontdata *fontdata = priv->fontdata; |
116 | 0 | int pbytes = VNBYTES(vid_priv->bpix); |
117 | 0 | void *start, *line; |
118 | | |
119 | | /* for now, this is not used outside expo */ |
120 | 0 | if (!IS_ENABLED(CONFIG_EXPO)) |
121 | 0 | return -ENOSYS; |
122 | | |
123 | 0 | x += index * fontdata->width; |
124 | 0 | start = vid_priv->fb + y * vid_priv->line_length + x * pbytes; |
125 | | |
126 | | /* place the cursor 1 pixel before the start of the next char */ |
127 | 0 | x -= 1; |
128 | |
|
129 | 0 | line = start; |
130 | 0 | draw_cursor_vertically(&line, vid_priv, vc_priv->y_charsize, |
131 | 0 | NORMAL_DIRECTION); |
132 | |
|
133 | 0 | return 0; |
134 | 0 | } |
135 | | |
136 | | struct vidconsole_ops console_ops = { |
137 | | .putc_xy = console_putc_xy, |
138 | | .move_rows = console_move_rows, |
139 | | .set_row = console_set_row, |
140 | | .get_font_size = console_simple_get_font_size, |
141 | | .get_font = console_simple_get_font, |
142 | | .select_font = console_simple_select_font, |
143 | | .set_cursor_visible = console_set_cursor_visible, |
144 | | }; |
145 | | |
146 | | U_BOOT_DRIVER(vidconsole_normal) = { |
147 | | .name = "vidconsole0", |
148 | | .id = UCLASS_VIDEO_CONSOLE, |
149 | | .ops = &console_ops, |
150 | | .probe = console_probe, |
151 | | .priv_auto = sizeof(struct console_simple_priv), |
152 | | }; |