1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2015 Google, Inc
4 * (C) Copyright 2001-2015
5 * DENX Software Engineering -- wd@denx.de
6 * Compulab Ltd - http://compulab.co.il/
7 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
13 #include <video_console.h>
14 #include <video_font.h> /* Get font data, width and height */
16 static int console_normal_set_row(struct udevice *dev, uint row, int clr)
18 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
20 int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
24 line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
25 switch (vid_priv->bpix) {
27 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
30 for (i = 0; i < pixels; i++)
36 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
39 for (i = 0; i < pixels; i++)
45 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
48 for (i = 0; i < pixels; i++)
56 ret = vidconsole_sync_copy(dev, line, end);
63 static int console_normal_move_rows(struct udevice *dev, uint rowdst,
64 uint rowsrc, uint count)
66 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
72 dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length;
73 src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length;
74 size = VIDEO_FONT_HEIGHT * vid_priv->line_length * count;
75 ret = vidconsole_memmove(dev, dst, src, size);
82 static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
85 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
86 struct udevice *vid = dev->parent;
87 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
93 start = vid_priv->fb + y * vid_priv->line_length +
94 VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix);
97 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
100 for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
101 unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row;
102 uchar bits = video_fontdata[idx];
104 switch (vid_priv->bpix) {
106 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
109 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
110 *dst++ = (bits & 0x80) ?
111 vid_priv->colour_fg :
118 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
119 uint16_t *dst = line;
121 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
122 *dst++ = (bits & 0x80) ?
123 vid_priv->colour_fg :
130 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
131 uint32_t *dst = line;
133 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
134 *dst++ = (bits & 0x80) ?
135 vid_priv->colour_fg :
144 line += vid_priv->line_length;
146 ret = vidconsole_sync_copy(dev, start, line);
150 return VID_TO_POS(VIDEO_FONT_WIDTH);
153 static int console_normal_probe(struct udevice *dev)
155 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
156 struct udevice *vid_dev = dev->parent;
157 struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
159 vc_priv->x_charsize = VIDEO_FONT_WIDTH;
160 vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
161 vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
162 vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
167 struct vidconsole_ops console_normal_ops = {
168 .putc_xy = console_normal_putc_xy,
169 .move_rows = console_normal_move_rows,
170 .set_row = console_normal_set_row,
173 U_BOOT_DRIVER(vidconsole_normal) = {
174 .name = "vidconsole0",
175 .id = UCLASS_VIDEO_CONSOLE,
176 .ops = &console_normal_ops,
177 .probe = console_normal_probe,