blob: 07db613ac53c957cfdfff0c9fb857b4aab4d0f21 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass23825a92016-01-18 19:52:18 -07002/*
3 * Copyright (c) 2015 Google, Inc
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +03004 * (C) Copyright 2015
Simon Glass23825a92016-01-18 19:52:18 -07005 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +03006 * (C) Copyright 2023 Dzmitry Sankouski <dsankouski@gmail.com>
Simon Glass23825a92016-01-18 19:52:18 -07007 */
8
Janne Grunau5548c362024-03-16 22:50:19 +01009#include <charset.h>
Simon Glass23825a92016-01-18 19:52:18 -070010#include <dm.h>
11#include <video.h>
12#include <video_console.h>
13#include <video_font.h> /* Get font data, width and height */
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030014#include "vidconsole_internal.h"
Simon Glass23825a92016-01-18 19:52:18 -070015
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030016static int console_set_row(struct udevice *dev, uint row, int clr)
Simon Glass23825a92016-01-18 19:52:18 -070017{
18 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030019 struct console_simple_priv *priv = dev_get_priv(dev);
20 struct video_fontdata *fontdata = priv->fontdata;
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030021 void *line, *dst, *end;
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030022 int pixels = fontdata->height * vid_priv->xsize;
Simon Glass03a96ae2020-07-02 21:12:24 -060023 int ret;
Simon Glass6c1ca6b2019-12-20 18:10:34 -070024 int i;
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030025 int pbytes;
Simon Glass23825a92016-01-18 19:52:18 -070026
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030027 ret = check_bpix_support(vid_priv->bpix);
28 if (ret)
29 return ret;
Simon Glass23825a92016-01-18 19:52:18 -070030
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030031 line = vid_priv->fb + row * fontdata->height * vid_priv->line_length;
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030032 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;
Simon Glass23825a92016-01-18 19:52:18 -070037
Alexander Graf1b47cf22022-06-10 00:59:17 +020038 video_damage(dev->parent,
39 0,
40 fontdata->height * row,
41 vid_priv->xsize,
42 fontdata->height);
43
Simon Glass23825a92016-01-18 19:52:18 -070044 return 0;
45}
46
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030047static int console_move_rows(struct udevice *dev, uint rowdst,
48 uint rowsrc, uint count)
Simon Glass23825a92016-01-18 19:52:18 -070049{
50 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030051 struct console_simple_priv *priv = dev_get_priv(dev);
52 struct video_fontdata *fontdata = priv->fontdata;
Simon Glass23825a92016-01-18 19:52:18 -070053 void *dst;
54 void *src;
Simon Glass03a96ae2020-07-02 21:12:24 -060055 int size;
Simon Glass23825a92016-01-18 19:52:18 -070056
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030057 dst = vid_priv->fb + rowdst * fontdata->height * vid_priv->line_length;
58 src = vid_priv->fb + rowsrc * fontdata->height * vid_priv->line_length;
59 size = fontdata->height * vid_priv->line_length * count;
Alexander Graff88b6a22022-06-10 00:59:21 +020060 memmove(dst, src, size);
Simon Glass23825a92016-01-18 19:52:18 -070061
Alexander Graf1b47cf22022-06-10 00:59:17 +020062 video_damage(dev->parent,
63 0,
64 fontdata->height * rowdst,
65 vid_priv->xsize,
66 fontdata->height * count);
67
Simon Glass23825a92016-01-18 19:52:18 -070068 return 0;
69}
70
Janne Grunau5548c362024-03-16 22:50:19 +010071static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp)
Simon Glass23825a92016-01-18 19:52:18 -070072{
Simon Glass52c10c52016-01-14 18:10:37 -070073 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
Simon Glass23825a92016-01-18 19:52:18 -070074 struct udevice *vid = dev->parent;
75 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030076 struct console_simple_priv *priv = dev_get_priv(dev);
77 struct video_fontdata *fontdata = priv->fontdata;
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030078 int pbytes = VNBYTES(vid_priv->bpix);
79 int x, linenum, ret;
80 void *start, *line;
Janne Grunau5548c362024-03-16 22:50:19 +010081 u8 ch = console_utf_to_cp437(cp);
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030082 uchar *pfont = fontdata->video_fontdata +
Janne Grunau5548c362024-03-16 22:50:19 +010083 ch * fontdata->char_pixel_bytes;
Simon Glass03a96ae2020-07-02 21:12:24 -060084
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030085 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
86 return -EAGAIN;
87 linenum = y;
88 x = VID_TO_PIXEL(x_frac);
89 start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes;
Simon Glass03a96ae2020-07-02 21:12:24 -060090 line = start;
Simon Glass52c10c52016-01-14 18:10:37 -070091
92 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
93 return -EAGAIN;
Simon Glass23825a92016-01-18 19:52:18 -070094
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030095 ret = fill_char_vertically(pfont, &line, vid_priv, fontdata, NORMAL_DIRECTION);
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030096 if (ret)
97 return ret;
Simon Glass23825a92016-01-18 19:52:18 -070098
Alexander Graf1b47cf22022-06-10 00:59:17 +020099 video_damage(dev->parent,
100 x,
101 y,
102 fontdata->width,
103 fontdata->height);
104
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300105 return VID_TO_POS(fontdata->width);
Simon Glass52c10c52016-01-14 18:10:37 -0700106}
107
Simon Glass377f79aa2023-10-01 19:13:21 -0600108static int console_set_cursor_visible(struct udevice *dev, bool visible,
109 uint x, uint y, uint index)
110{
111 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
112 struct udevice *vid = dev->parent;
113 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
114 struct console_simple_priv *priv = dev_get_priv(dev);
115 struct video_fontdata *fontdata = priv->fontdata;
116 int pbytes = VNBYTES(vid_priv->bpix);
117 void *start, *line;
118
119 /* for now, this is not used outside expo */
120 if (!IS_ENABLED(CONFIG_EXPO))
121 return -ENOSYS;
122
123 x += index * fontdata->width;
124 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 x -= 1;
128
129 line = start;
130 draw_cursor_vertically(&line, vid_priv, vc_priv->y_charsize,
131 NORMAL_DIRECTION);
132
133 return 0;
134}
135
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300136struct vidconsole_ops console_ops = {
137 .putc_xy = console_putc_xy,
138 .move_rows = console_move_rows,
139 .set_row = console_set_row,
Dzmitry Sankouskibb165e42023-03-07 13:21:16 +0300140 .get_font_size = console_simple_get_font_size,
141 .get_font = console_simple_get_font,
142 .select_font = console_simple_select_font,
Simon Glass377f79aa2023-10-01 19:13:21 -0600143 .set_cursor_visible = console_set_cursor_visible,
Simon Glass23825a92016-01-18 19:52:18 -0700144};
145
146U_BOOT_DRIVER(vidconsole_normal) = {
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300147 .name = "vidconsole0",
148 .id = UCLASS_VIDEO_CONSOLE,
149 .ops = &console_ops,
150 .probe = console_probe,
151 .priv_auto = sizeof(struct console_simple_priv),
Simon Glass23825a92016-01-18 19:52:18 -0700152};