blob: 04f022491e52db6eb29b2d716670e675fc61294c [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
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
Simon Glass23825a92016-01-18 19:52:18 -07008 */
9
10#include <common.h>
11#include <dm.h>
12#include <video.h>
13#include <video_console.h>
14#include <video_font.h> /* Get font data, width and height */
15
16static int console_normal_set_row(struct udevice *dev, uint row, int clr)
17{
18 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
Simon Glass03a96ae2020-07-02 21:12:24 -060019 void *line, *end;
Simon Glass6c1ca6b2019-12-20 18:10:34 -070020 int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
Simon Glass03a96ae2020-07-02 21:12:24 -060021 int ret;
Simon Glass6c1ca6b2019-12-20 18:10:34 -070022 int i;
Simon Glass23825a92016-01-18 19:52:18 -070023
24 line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
25 switch (vid_priv->bpix) {
Simon Glass6c1ca6b2019-12-20 18:10:34 -070026 case VIDEO_BPP8:
27 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
28 uint8_t *dst = line;
Simon Glass23825a92016-01-18 19:52:18 -070029
Simon Glass6c1ca6b2019-12-20 18:10:34 -070030 for (i = 0; i < pixels; i++)
31 *dst++ = clr;
Simon Glass03a96ae2020-07-02 21:12:24 -060032 end = dst;
Simon Glass6c1ca6b2019-12-20 18:10:34 -070033 break;
34 }
35 case VIDEO_BPP16:
36 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
37 uint16_t *dst = line;
Simon Glass23825a92016-01-18 19:52:18 -070038
Simon Glass6c1ca6b2019-12-20 18:10:34 -070039 for (i = 0; i < pixels; i++)
40 *dst++ = clr;
Simon Glass03a96ae2020-07-02 21:12:24 -060041 end = dst;
Simon Glass6c1ca6b2019-12-20 18:10:34 -070042 break;
43 }
44 case VIDEO_BPP32:
45 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
46 uint32_t *dst = line;
Simon Glass23825a92016-01-18 19:52:18 -070047
Simon Glass6c1ca6b2019-12-20 18:10:34 -070048 for (i = 0; i < pixels; i++)
49 *dst++ = clr;
Simon Glass03a96ae2020-07-02 21:12:24 -060050 end = dst;
Simon Glass6c1ca6b2019-12-20 18:10:34 -070051 break;
52 }
Simon Glass23825a92016-01-18 19:52:18 -070053 default:
54 return -ENOSYS;
55 }
Simon Glass03a96ae2020-07-02 21:12:24 -060056 ret = vidconsole_sync_copy(dev, line, end);
57 if (ret)
58 return ret;
Simon Glass23825a92016-01-18 19:52:18 -070059
60 return 0;
61}
62
63static int console_normal_move_rows(struct udevice *dev, uint rowdst,
64 uint rowsrc, uint count)
65{
66 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
67 void *dst;
68 void *src;
Simon Glass03a96ae2020-07-02 21:12:24 -060069 int size;
70 int ret;
Simon Glass23825a92016-01-18 19:52:18 -070071
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;
Simon Glass03a96ae2020-07-02 21:12:24 -060074 size = VIDEO_FONT_HEIGHT * vid_priv->line_length * count;
75 ret = vidconsole_memmove(dev, dst, src, size);
76 if (ret)
77 return ret;
Simon Glass23825a92016-01-18 19:52:18 -070078
79 return 0;
80}
81
Simon Glass52c10c52016-01-14 18:10:37 -070082static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
83 char ch)
Simon Glass23825a92016-01-18 19:52:18 -070084{
Simon Glass52c10c52016-01-14 18:10:37 -070085 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
Simon Glass23825a92016-01-18 19:52:18 -070086 struct udevice *vid = dev->parent;
87 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
Simon Glass6c1ca6b2019-12-20 18:10:34 -070088 int i, row;
Simon Glass03a96ae2020-07-02 21:12:24 -060089 void *start;
90 void *line;
91 int ret;
92
93 start = vid_priv->fb + y * vid_priv->line_length +
Simon Glass52c10c52016-01-14 18:10:37 -070094 VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix);
Simon Glass03a96ae2020-07-02 21:12:24 -060095 line = start;
Simon Glass52c10c52016-01-14 18:10:37 -070096
97 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
98 return -EAGAIN;
Simon Glass23825a92016-01-18 19:52:18 -070099
100 for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
Andre Przywara22b4f012019-03-23 01:29:55 +0000101 unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row;
Simon Glass6c1ca6b2019-12-20 18:10:34 -0700102 uchar bits = video_fontdata[idx];
Simon Glass23825a92016-01-18 19:52:18 -0700103
104 switch (vid_priv->bpix) {
Simon Glass6c1ca6b2019-12-20 18:10:34 -0700105 case VIDEO_BPP8:
106 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
107 uint8_t *dst = line;
Simon Glass23825a92016-01-18 19:52:18 -0700108
Simon Glass6c1ca6b2019-12-20 18:10:34 -0700109 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
110 *dst++ = (bits & 0x80) ?
111 vid_priv->colour_fg :
112 vid_priv->colour_bg;
113 bits <<= 1;
114 }
115 break;
Simon Glass23825a92016-01-18 19:52:18 -0700116 }
Simon Glass6c1ca6b2019-12-20 18:10:34 -0700117 case VIDEO_BPP16:
118 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
119 uint16_t *dst = line;
Simon Glass23825a92016-01-18 19:52:18 -0700120
Simon Glass6c1ca6b2019-12-20 18:10:34 -0700121 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
122 *dst++ = (bits & 0x80) ?
123 vid_priv->colour_fg :
124 vid_priv->colour_bg;
125 bits <<= 1;
126 }
127 break;
Simon Glass23825a92016-01-18 19:52:18 -0700128 }
Simon Glass6c1ca6b2019-12-20 18:10:34 -0700129 case VIDEO_BPP32:
130 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
131 uint32_t *dst = line;
Simon Glass23825a92016-01-18 19:52:18 -0700132
Simon Glass6c1ca6b2019-12-20 18:10:34 -0700133 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
134 *dst++ = (bits & 0x80) ?
135 vid_priv->colour_fg :
136 vid_priv->colour_bg;
137 bits <<= 1;
138 }
139 break;
Simon Glass23825a92016-01-18 19:52:18 -0700140 }
Simon Glass23825a92016-01-18 19:52:18 -0700141 default:
142 return -ENOSYS;
143 }
144 line += vid_priv->line_length;
145 }
Simon Glass03a96ae2020-07-02 21:12:24 -0600146 ret = vidconsole_sync_copy(dev, start, line);
147 if (ret)
148 return ret;
Simon Glass23825a92016-01-18 19:52:18 -0700149
Simon Glass52c10c52016-01-14 18:10:37 -0700150 return VID_TO_POS(VIDEO_FONT_WIDTH);
151}
152
153static int console_normal_probe(struct udevice *dev)
154{
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);
158
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;
163
Simon Glass23825a92016-01-18 19:52:18 -0700164 return 0;
165}
166
167struct 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,
171};
172
173U_BOOT_DRIVER(vidconsole_normal) = {
174 .name = "vidconsole0",
175 .id = UCLASS_VIDEO_CONSOLE,
176 .ops = &console_normal_ops,
Simon Glass52c10c52016-01-14 18:10:37 -0700177 .probe = console_normal_probe,
Simon Glass23825a92016-01-18 19:52:18 -0700178};