blob: a0231293f311d830f279bcc0bd7653001cdff639 [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
9#include <common.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 */
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
Simon Glass03a96ae2020-07-02 21:12:24 -060038 ret = vidconsole_sync_copy(dev, line, end);
39 if (ret)
40 return ret;
Simon Glass23825a92016-01-18 19:52:18 -070041
42 return 0;
43}
44
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030045static int console_move_rows(struct udevice *dev, uint rowdst,
46 uint rowsrc, uint count)
Simon Glass23825a92016-01-18 19:52:18 -070047{
48 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030049 struct console_simple_priv *priv = dev_get_priv(dev);
50 struct video_fontdata *fontdata = priv->fontdata;
Simon Glass23825a92016-01-18 19:52:18 -070051 void *dst;
52 void *src;
Simon Glass03a96ae2020-07-02 21:12:24 -060053 int size;
54 int ret;
Simon Glass23825a92016-01-18 19:52:18 -070055
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030056 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;
Simon Glass03a96ae2020-07-02 21:12:24 -060059 ret = vidconsole_memmove(dev, dst, src, size);
60 if (ret)
61 return ret;
Simon Glass23825a92016-01-18 19:52:18 -070062
63 return 0;
64}
65
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030066static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch)
Simon Glass23825a92016-01-18 19:52:18 -070067{
Simon Glass52c10c52016-01-14 18:10:37 -070068 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
Simon Glass23825a92016-01-18 19:52:18 -070069 struct udevice *vid = dev->parent;
70 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030071 struct console_simple_priv *priv = dev_get_priv(dev);
72 struct video_fontdata *fontdata = priv->fontdata;
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030073 int pbytes = VNBYTES(vid_priv->bpix);
74 int x, linenum, ret;
75 void *start, *line;
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030076 uchar *pfont = fontdata->video_fontdata +
77 (u8)ch * fontdata->char_pixel_bytes;
Simon Glass03a96ae2020-07-02 21:12:24 -060078
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030079 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
80 return -EAGAIN;
81 linenum = y;
82 x = VID_TO_PIXEL(x_frac);
83 start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes;
Simon Glass03a96ae2020-07-02 21:12:24 -060084 line = start;
Simon Glass52c10c52016-01-14 18:10:37 -070085
86 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
87 return -EAGAIN;
Simon Glass23825a92016-01-18 19:52:18 -070088
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030089 ret = fill_char_vertically(pfont, &line, vid_priv, fontdata, NORMAL_DIRECTION);
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +030090 if (ret)
91 return ret;
Simon Glass23825a92016-01-18 19:52:18 -070092
Simon Glass03a96ae2020-07-02 21:12:24 -060093 ret = vidconsole_sync_copy(dev, start, line);
94 if (ret)
95 return ret;
Simon Glass23825a92016-01-18 19:52:18 -070096
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +030097 return VID_TO_POS(fontdata->width);
Simon Glass52c10c52016-01-14 18:10:37 -070098}
99
Simon Glass377f79aa2023-10-01 19:13:21 -0600100static int console_set_cursor_visible(struct udevice *dev, bool visible,
101 uint x, uint y, uint index)
102{
103 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
104 struct udevice *vid = dev->parent;
105 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
106 struct console_simple_priv *priv = dev_get_priv(dev);
107 struct video_fontdata *fontdata = priv->fontdata;
108 int pbytes = VNBYTES(vid_priv->bpix);
109 void *start, *line;
110
111 /* for now, this is not used outside expo */
112 if (!IS_ENABLED(CONFIG_EXPO))
113 return -ENOSYS;
114
115 x += index * fontdata->width;
116 start = vid_priv->fb + y * vid_priv->line_length + x * pbytes;
117
118 /* place the cursor 1 pixel before the start of the next char */
119 x -= 1;
120
121 line = start;
122 draw_cursor_vertically(&line, vid_priv, vc_priv->y_charsize,
123 NORMAL_DIRECTION);
124
125 return 0;
126}
127
Dzmitry Sankouskiaea2d2d2023-03-07 13:21:11 +0300128struct vidconsole_ops console_ops = {
129 .putc_xy = console_putc_xy,
130 .move_rows = console_move_rows,
131 .set_row = console_set_row,
Dzmitry Sankouskibb165e42023-03-07 13:21:16 +0300132 .get_font_size = console_simple_get_font_size,
133 .get_font = console_simple_get_font,
134 .select_font = console_simple_select_font,
Simon Glass377f79aa2023-10-01 19:13:21 -0600135 .set_cursor_visible = console_set_cursor_visible,
Simon Glass23825a92016-01-18 19:52:18 -0700136};
137
138U_BOOT_DRIVER(vidconsole_normal) = {
Dzmitry Sankouski7fa964a2023-03-07 13:21:14 +0300139 .name = "vidconsole0",
140 .id = UCLASS_VIDEO_CONSOLE,
141 .ops = &console_ops,
142 .probe = console_probe,
143 .priv_auto = sizeof(struct console_simple_priv),
Simon Glass23825a92016-01-18 19:52:18 -0700144};