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) {
26 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
29 for (i = 0; i < pixels; i++)
34 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
37 for (i = 0; i < pixels; i++)
42 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
45 for (i = 0; i < pixels; i++)
56 static int console_normal_move_rows(struct udevice *dev, uint rowdst,
57 uint rowsrc, uint count)
59 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
63 dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length;
64 src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length;
65 memmove(dst, src, VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
70 static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
73 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
74 struct udevice *vid = dev->parent;
75 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
77 void *line = vid_priv->fb + y * vid_priv->line_length +
78 VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix);
80 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
83 for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
84 unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row;
85 uchar bits = video_fontdata[idx];
87 switch (vid_priv->bpix) {
89 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
92 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
93 *dst++ = (bits & 0x80) ?
101 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
102 uint16_t *dst = line;
104 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
105 *dst++ = (bits & 0x80) ?
106 vid_priv->colour_fg :
113 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
114 uint32_t *dst = line;
116 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
117 *dst++ = (bits & 0x80) ?
118 vid_priv->colour_fg :
127 line += vid_priv->line_length;
130 return VID_TO_POS(VIDEO_FONT_WIDTH);
133 static int console_normal_probe(struct udevice *dev)
135 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
136 struct udevice *vid_dev = dev->parent;
137 struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
139 vc_priv->x_charsize = VIDEO_FONT_WIDTH;
140 vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
141 vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
142 vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
147 struct vidconsole_ops console_normal_ops = {
148 .putc_xy = console_normal_putc_xy,
149 .move_rows = console_normal_move_rows,
150 .set_row = console_normal_set_row,
153 U_BOOT_DRIVER(vidconsole_normal) = {
154 .name = "vidconsole0",
155 .id = UCLASS_VIDEO_CONSOLE,
156 .ops = &console_normal_ops,
157 .probe = console_normal_probe,