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;
23 line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
24 switch (vid_priv->bpix) {
25 #ifdef CONFIG_VIDEO_BPP8
29 for (i = 0; i < pixels; i++)
34 #ifdef CONFIG_VIDEO_BPP16
38 for (i = 0; i < pixels; i++)
43 #ifdef CONFIG_VIDEO_BPP32
47 for (i = 0; i < pixels; i++)
59 static int console_normal_move_rows(struct udevice *dev, uint rowdst,
60 uint rowsrc, uint count)
62 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
66 dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length;
67 src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length;
68 memmove(dst, src, VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
73 static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
76 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
77 struct udevice *vid = dev->parent;
78 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
80 void *line = vid_priv->fb + y * vid_priv->line_length +
81 VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix);
83 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
86 for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
87 uchar bits = video_fontdata[ch * VIDEO_FONT_HEIGHT + row];
89 switch (vid_priv->bpix) {
90 #ifdef CONFIG_VIDEO_BPP8
94 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
95 *dst++ = (bits & 0x80) ? vid_priv->colour_fg
96 : vid_priv->colour_bg;
102 #ifdef CONFIG_VIDEO_BPP16
104 uint16_t *dst = line;
106 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
107 *dst++ = (bits & 0x80) ? vid_priv->colour_fg
108 : vid_priv->colour_bg;
114 #ifdef CONFIG_VIDEO_BPP32
116 uint32_t *dst = line;
118 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
119 *dst++ = (bits & 0x80) ? vid_priv->colour_fg
120 : vid_priv->colour_bg;
129 line += vid_priv->line_length;
132 return VID_TO_POS(VIDEO_FONT_WIDTH);
135 static int console_normal_probe(struct udevice *dev)
137 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
138 struct udevice *vid_dev = dev->parent;
139 struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
141 vc_priv->x_charsize = VIDEO_FONT_WIDTH;
142 vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
143 vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
144 vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
149 struct vidconsole_ops console_normal_ops = {
150 .putc_xy = console_normal_putc_xy,
151 .move_rows = console_normal_move_rows,
152 .set_row = console_normal_set_row,
155 U_BOOT_DRIVER(vidconsole_normal) = {
156 .name = "vidconsole0",
157 .id = UCLASS_VIDEO_CONSOLE,
158 .ops = &console_normal_ops,
159 .probe = console_normal_probe,