2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-01-19 02:52:19 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Google, Inc
|
|
|
|
* (C) Copyright 2015
|
|
|
|
* Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
|
2023-03-07 10:21:11 +00:00
|
|
|
* (C) Copyright 2023 Dzmitry Sankouski <dsankouski@gmail.com>
|
2016-01-19 02:52:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <video.h>
|
|
|
|
#include <video_console.h>
|
|
|
|
#include <video_font.h> /* Get font data, width and height */
|
2023-03-07 10:21:11 +00:00
|
|
|
#include "vidconsole_internal.h"
|
2016-01-19 02:52:19 +00:00
|
|
|
|
|
|
|
static int console_set_row_1(struct udevice *dev, uint row, int clr)
|
|
|
|
{
|
|
|
|
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
|
2023-03-07 10:21:14 +00:00
|
|
|
struct console_simple_priv *priv = dev_get_priv(dev);
|
|
|
|
struct video_fontdata *fontdata = priv->fontdata;
|
2016-01-19 02:52:19 +00:00
|
|
|
int pbytes = VNBYTES(vid_priv->bpix);
|
2023-03-07 10:21:11 +00:00
|
|
|
void *start, *dst, *line;
|
2016-01-19 02:52:19 +00:00
|
|
|
int i, j;
|
2020-07-03 03:12:26 +00:00
|
|
|
int ret;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
2020-07-03 03:12:26 +00:00
|
|
|
start = vid_priv->fb + vid_priv->line_length -
|
2023-03-07 10:21:14 +00:00
|
|
|
(row + 1) * fontdata->height * pbytes;
|
2020-07-03 03:12:26 +00:00
|
|
|
line = start;
|
2016-01-19 02:52:19 +00:00
|
|
|
for (j = 0; j < vid_priv->ysize; j++) {
|
2023-03-07 10:21:11 +00:00
|
|
|
dst = line;
|
2023-03-07 10:21:14 +00:00
|
|
|
for (i = 0; i < fontdata->height; i++)
|
2023-03-07 10:21:11 +00:00
|
|
|
fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
|
2016-01-19 02:52:19 +00:00
|
|
|
line += vid_priv->line_length;
|
|
|
|
}
|
2020-07-03 03:12:26 +00:00
|
|
|
ret = vidconsole_sync_copy(dev, start, line);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
|
2023-03-07 10:21:11 +00:00
|
|
|
uint count)
|
2016-01-19 02:52:19 +00:00
|
|
|
{
|
|
|
|
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
|
2023-03-07 10:21:14 +00:00
|
|
|
struct console_simple_priv *priv = dev_get_priv(dev);
|
|
|
|
struct video_fontdata *fontdata = priv->fontdata;
|
2020-07-03 03:12:16 +00:00
|
|
|
int pbytes = VNBYTES(vid_priv->bpix);
|
2016-01-19 02:52:19 +00:00
|
|
|
void *dst;
|
|
|
|
void *src;
|
2020-07-03 03:12:26 +00:00
|
|
|
int j, ret;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
|
|
|
dst = vid_priv->fb + vid_priv->line_length -
|
2023-03-07 10:21:14 +00:00
|
|
|
(rowdst + count) * fontdata->height * pbytes;
|
2016-01-19 02:52:19 +00:00
|
|
|
src = vid_priv->fb + vid_priv->line_length -
|
2023-03-07 10:21:14 +00:00
|
|
|
(rowsrc + count) * fontdata->height * pbytes;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
|
|
|
for (j = 0; j < vid_priv->ysize; j++) {
|
2020-07-03 03:12:26 +00:00
|
|
|
ret = vidconsole_memmove(dev, dst, src,
|
2023-03-07 10:21:14 +00:00
|
|
|
fontdata->height * pbytes * count);
|
2020-07-03 03:12:26 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2016-01-19 02:52:19 +00:00
|
|
|
src += vid_priv->line_length;
|
|
|
|
dst += vid_priv->line_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-15 01:10:37 +00:00
|
|
|
static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
|
2016-01-19 02:52:19 +00:00
|
|
|
{
|
2016-01-15 01:10:37 +00:00
|
|
|
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
|
2016-01-19 02:52:19 +00:00
|
|
|
struct udevice *vid = dev->parent;
|
|
|
|
struct video_priv *vid_priv = dev_get_uclass_priv(vid);
|
2023-03-07 10:21:14 +00:00
|
|
|
struct console_simple_priv *priv = dev_get_priv(dev);
|
|
|
|
struct video_fontdata *fontdata = priv->fontdata;
|
2016-01-19 02:52:19 +00:00
|
|
|
int pbytes = VNBYTES(vid_priv->bpix);
|
2023-03-07 10:21:11 +00:00
|
|
|
int x, linenum, ret;
|
2020-07-03 03:12:26 +00:00
|
|
|
void *start, *line;
|
2023-03-07 10:21:14 +00:00
|
|
|
uchar *pfont = fontdata->video_fontdata +
|
|
|
|
(u8)ch * fontdata->char_pixel_bytes;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
2023-03-07 10:21:11 +00:00
|
|
|
if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
|
|
|
|
return -EAGAIN;
|
2020-07-03 03:12:16 +00:00
|
|
|
linenum = VID_TO_PIXEL(x_frac) + 1;
|
|
|
|
x = y + 1;
|
2020-07-03 03:12:26 +00:00
|
|
|
start = vid_priv->fb + linenum * vid_priv->line_length - x * pbytes;
|
|
|
|
line = start;
|
2016-01-15 01:10:37 +00:00
|
|
|
|
2023-03-07 10:21:14 +00:00
|
|
|
ret = fill_char_horizontally(pfont, &line, vid_priv, fontdata, FLIPPED_DIRECTION);
|
2023-03-07 10:21:11 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-07-03 03:12:26 +00:00
|
|
|
/* We draw backwards from 'start, so account for the first line */
|
|
|
|
ret = vidconsole_sync_copy(dev, start - vid_priv->line_length, line);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
2023-03-07 10:21:14 +00:00
|
|
|
return VID_TO_POS(fontdata->width);
|
2016-01-19 02:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int console_set_row_2(struct udevice *dev, uint row, int clr)
|
|
|
|
{
|
|
|
|
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
|
2023-03-07 10:21:14 +00:00
|
|
|
struct console_simple_priv *priv = dev_get_priv(dev);
|
|
|
|
struct video_fontdata *fontdata = priv->fontdata;
|
2023-03-07 10:21:11 +00:00
|
|
|
void *start, *line, *dst, *end;
|
2023-03-07 10:21:14 +00:00
|
|
|
int pixels = fontdata->height * vid_priv->xsize;
|
2020-07-03 03:12:26 +00:00
|
|
|
int i, ret;
|
2023-03-07 10:21:11 +00:00
|
|
|
int pbytes = VNBYTES(vid_priv->bpix);
|
2016-01-19 02:52:19 +00:00
|
|
|
|
2020-07-03 03:12:26 +00:00
|
|
|
start = vid_priv->fb + vid_priv->ysize * vid_priv->line_length -
|
2023-03-07 10:21:14 +00:00
|
|
|
(row + 1) * fontdata->height * vid_priv->line_length;
|
2020-07-03 03:12:26 +00:00
|
|
|
line = start;
|
2023-03-07 10:21:11 +00:00
|
|
|
dst = line;
|
|
|
|
for (i = 0; i < pixels; i++)
|
|
|
|
fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
|
|
|
|
end = dst;
|
2020-07-03 03:12:26 +00:00
|
|
|
ret = vidconsole_sync_copy(dev, start, end);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
|
|
|
|
uint count)
|
|
|
|
{
|
|
|
|
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
|
2023-03-07 10:21:14 +00:00
|
|
|
struct console_simple_priv *priv = dev_get_priv(dev);
|
|
|
|
struct video_fontdata *fontdata = priv->fontdata;
|
2016-01-19 02:52:19 +00:00
|
|
|
void *dst;
|
|
|
|
void *src;
|
|
|
|
void *end;
|
|
|
|
|
|
|
|
end = vid_priv->fb + vid_priv->ysize * vid_priv->line_length;
|
2023-03-07 10:21:14 +00:00
|
|
|
dst = end - (rowdst + count) * fontdata->height *
|
2016-01-19 02:52:19 +00:00
|
|
|
vid_priv->line_length;
|
2023-03-07 10:21:14 +00:00
|
|
|
src = end - (rowsrc + count) * fontdata->height *
|
2016-01-19 02:52:19 +00:00
|
|
|
vid_priv->line_length;
|
2020-07-03 03:12:26 +00:00
|
|
|
vidconsole_memmove(dev, dst, src,
|
2023-03-07 10:21:14 +00:00
|
|
|
fontdata->height * vid_priv->line_length * count);
|
2016-01-19 02:52:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-15 01:10:37 +00:00
|
|
|
static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
|
2016-01-19 02:52:19 +00:00
|
|
|
{
|
2016-01-15 01:10:37 +00:00
|
|
|
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
|
2016-01-19 02:52:19 +00:00
|
|
|
struct udevice *vid = dev->parent;
|
|
|
|
struct video_priv *vid_priv = dev_get_uclass_priv(vid);
|
2023-03-07 10:21:14 +00:00
|
|
|
struct console_simple_priv *priv = dev_get_priv(dev);
|
|
|
|
struct video_fontdata *fontdata = priv->fontdata;
|
2020-07-03 03:12:16 +00:00
|
|
|
int pbytes = VNBYTES(vid_priv->bpix);
|
2023-03-07 10:21:11 +00:00
|
|
|
int linenum, x, ret;
|
2020-07-03 03:12:26 +00:00
|
|
|
void *start, *line;
|
2023-03-07 10:21:14 +00:00
|
|
|
uchar *pfont = fontdata->video_fontdata +
|
|
|
|
(u8)ch * fontdata->char_pixel_bytes;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
2016-01-15 01:10:37 +00:00
|
|
|
if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
|
|
|
|
return -EAGAIN;
|
2020-07-03 03:12:16 +00:00
|
|
|
linenum = vid_priv->ysize - y - 1;
|
2020-07-03 03:12:17 +00:00
|
|
|
x = vid_priv->xsize - VID_TO_PIXEL(x_frac) - 1;
|
2020-07-03 03:12:26 +00:00
|
|
|
start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes;
|
|
|
|
line = start;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
2023-03-07 10:21:14 +00:00
|
|
|
ret = fill_char_vertically(pfont, &line, vid_priv, fontdata, FLIPPED_DIRECTION);
|
2023-03-07 10:21:11 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-07-03 03:12:26 +00:00
|
|
|
/* Add 4 bytes to allow for the first pixel writen */
|
|
|
|
ret = vidconsole_sync_copy(dev, start + 4, line);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
2023-03-07 10:21:14 +00:00
|
|
|
return VID_TO_POS(fontdata->width);
|
2016-01-19 02:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int console_set_row_3(struct udevice *dev, uint row, int clr)
|
|
|
|
{
|
|
|
|
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
|
2023-03-07 10:21:14 +00:00
|
|
|
struct console_simple_priv *priv = dev_get_priv(dev);
|
|
|
|
struct video_fontdata *fontdata = priv->fontdata;
|
2016-01-19 02:52:19 +00:00
|
|
|
int pbytes = VNBYTES(vid_priv->bpix);
|
2023-03-07 10:21:11 +00:00
|
|
|
void *start, *dst, *line;
|
2020-07-03 03:12:26 +00:00
|
|
|
int i, j, ret;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
2023-03-07 10:21:14 +00:00
|
|
|
start = vid_priv->fb + row * fontdata->height * pbytes;
|
2020-07-03 03:12:26 +00:00
|
|
|
line = start;
|
2016-01-19 02:52:19 +00:00
|
|
|
for (j = 0; j < vid_priv->ysize; j++) {
|
2023-03-07 10:21:11 +00:00
|
|
|
dst = line;
|
2023-03-07 10:21:14 +00:00
|
|
|
for (i = 0; i < fontdata->height; i++)
|
2023-03-07 10:21:11 +00:00
|
|
|
fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
|
2016-01-19 02:52:19 +00:00
|
|
|
line += vid_priv->line_length;
|
|
|
|
}
|
2020-07-03 03:12:26 +00:00
|
|
|
ret = vidconsole_sync_copy(dev, start, line);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
|
|
|
|
uint count)
|
|
|
|
{
|
|
|
|
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
|
2023-03-07 10:21:14 +00:00
|
|
|
struct console_simple_priv *priv = dev_get_priv(dev);
|
|
|
|
struct video_fontdata *fontdata = priv->fontdata;
|
2020-07-03 03:12:16 +00:00
|
|
|
int pbytes = VNBYTES(vid_priv->bpix);
|
2016-01-19 02:52:19 +00:00
|
|
|
void *dst;
|
|
|
|
void *src;
|
2020-07-03 03:12:26 +00:00
|
|
|
int j, ret;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
2023-03-07 10:21:14 +00:00
|
|
|
dst = vid_priv->fb + rowdst * fontdata->height * pbytes;
|
|
|
|
src = vid_priv->fb + rowsrc * fontdata->height * pbytes;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
|
|
|
for (j = 0; j < vid_priv->ysize; j++) {
|
2020-07-03 03:12:26 +00:00
|
|
|
ret = vidconsole_memmove(dev, dst, src,
|
2023-03-07 10:21:14 +00:00
|
|
|
fontdata->height * pbytes * count);
|
2020-07-03 03:12:26 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2016-01-19 02:52:19 +00:00
|
|
|
src += vid_priv->line_length;
|
|
|
|
dst += vid_priv->line_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-15 01:10:37 +00:00
|
|
|
static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
|
2016-01-19 02:52:19 +00:00
|
|
|
{
|
2016-01-15 01:10:37 +00:00
|
|
|
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
|
2016-01-19 02:52:19 +00:00
|
|
|
struct udevice *vid = dev->parent;
|
|
|
|
struct video_priv *vid_priv = dev_get_uclass_priv(vid);
|
2023-03-07 10:21:14 +00:00
|
|
|
struct console_simple_priv *priv = dev_get_priv(dev);
|
|
|
|
struct video_fontdata *fontdata = priv->fontdata;
|
2016-01-19 02:52:19 +00:00
|
|
|
int pbytes = VNBYTES(vid_priv->bpix);
|
2023-03-07 10:21:11 +00:00
|
|
|
int linenum, x, ret;
|
2020-07-03 03:12:26 +00:00
|
|
|
void *start, *line;
|
2023-03-07 10:21:14 +00:00
|
|
|
uchar *pfont = fontdata->video_fontdata +
|
|
|
|
(u8)ch * fontdata->char_pixel_bytes;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
2016-01-15 01:10:37 +00:00
|
|
|
if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
|
|
|
|
return -EAGAIN;
|
2023-03-07 10:21:11 +00:00
|
|
|
x = y;
|
|
|
|
linenum = vid_priv->ysize - VID_TO_PIXEL(x_frac) - 1;
|
|
|
|
start = vid_priv->fb + linenum * vid_priv->line_length + y * pbytes;
|
2020-07-03 03:12:26 +00:00
|
|
|
line = start;
|
2023-03-07 10:21:11 +00:00
|
|
|
|
2023-03-07 10:21:14 +00:00
|
|
|
ret = fill_char_horizontally(pfont, &line, vid_priv, fontdata, NORMAL_DIRECTION);
|
2023-03-07 10:21:11 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2020-07-03 03:12:26 +00:00
|
|
|
/* Add a line to allow for the first pixels writen */
|
|
|
|
ret = vidconsole_sync_copy(dev, start + vid_priv->line_length, line);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2016-01-19 02:52:19 +00:00
|
|
|
|
2023-03-07 10:21:14 +00:00
|
|
|
return VID_TO_POS(fontdata->width);
|
2016-01-19 02:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct vidconsole_ops console_ops_1 = {
|
|
|
|
.putc_xy = console_putc_xy_1,
|
|
|
|
.move_rows = console_move_rows_1,
|
|
|
|
.set_row = console_set_row_1,
|
2023-03-07 10:21:16 +00:00
|
|
|
.get_font_size = console_simple_get_font_size,
|
|
|
|
.get_font = console_simple_get_font,
|
|
|
|
.select_font = console_simple_select_font,
|
2016-01-19 02:52:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct vidconsole_ops console_ops_2 = {
|
|
|
|
.putc_xy = console_putc_xy_2,
|
|
|
|
.move_rows = console_move_rows_2,
|
|
|
|
.set_row = console_set_row_2,
|
2023-03-07 10:21:16 +00:00
|
|
|
.get_font_size = console_simple_get_font_size,
|
|
|
|
.get_font = console_simple_get_font,
|
|
|
|
.select_font = console_simple_select_font,
|
2016-01-19 02:52:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct vidconsole_ops console_ops_3 = {
|
|
|
|
.putc_xy = console_putc_xy_3,
|
|
|
|
.move_rows = console_move_rows_3,
|
|
|
|
.set_row = console_set_row_3,
|
2023-03-07 10:21:16 +00:00
|
|
|
.get_font_size = console_simple_get_font_size,
|
|
|
|
.get_font = console_simple_get_font,
|
|
|
|
.select_font = console_simple_select_font,
|
2016-01-19 02:52:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(vidconsole_1) = {
|
|
|
|
.name = "vidconsole1",
|
|
|
|
.id = UCLASS_VIDEO_CONSOLE,
|
|
|
|
.ops = &console_ops_1,
|
2023-03-07 10:21:11 +00:00
|
|
|
.probe = console_probe,
|
2023-03-07 10:21:14 +00:00
|
|
|
.priv_auto = sizeof(struct console_simple_priv),
|
2016-01-19 02:52:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(vidconsole_2) = {
|
|
|
|
.name = "vidconsole2",
|
|
|
|
.id = UCLASS_VIDEO_CONSOLE,
|
|
|
|
.ops = &console_ops_2,
|
2023-03-07 10:21:11 +00:00
|
|
|
.probe = console_probe,
|
2023-03-07 10:21:14 +00:00
|
|
|
.priv_auto = sizeof(struct console_simple_priv),
|
2016-01-19 02:52:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(vidconsole_3) = {
|
|
|
|
.name = "vidconsole3",
|
|
|
|
.id = UCLASS_VIDEO_CONSOLE,
|
|
|
|
.ops = &console_ops_3,
|
2023-03-07 10:21:11 +00:00
|
|
|
.probe = console_probe,
|
2023-03-07 10:21:14 +00:00
|
|
|
.priv_auto = sizeof(struct console_simple_priv),
|
2016-01-19 02:52:19 +00:00
|
|
|
};
|