blob: c3f7ef8addcb8489db5c434de533782186fa0db1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass72cded92016-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 Glass72cded92016-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 Glass46421192019-12-20 18:10:34 -070019 void *line;
20 int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
21 int i;
Simon Glass72cded92016-01-18 19:52:18 -070022
23 line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
24 switch (vid_priv->bpix) {
Simon Glass46421192019-12-20 18:10:34 -070025 case VIDEO_BPP8:
26 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
27 uint8_t *dst = line;
Simon Glass72cded92016-01-18 19:52:18 -070028
Simon Glass46421192019-12-20 18:10:34 -070029 for (i = 0; i < pixels; i++)
30 *dst++ = clr;
31 break;
32 }
33 case VIDEO_BPP16:
34 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
35 uint16_t *dst = line;
Simon Glass72cded92016-01-18 19:52:18 -070036
Simon Glass46421192019-12-20 18:10:34 -070037 for (i = 0; i < pixels; i++)
38 *dst++ = clr;
39 break;
40 }
41 case VIDEO_BPP32:
42 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
43 uint32_t *dst = line;
Simon Glass72cded92016-01-18 19:52:18 -070044
Simon Glass46421192019-12-20 18:10:34 -070045 for (i = 0; i < pixels; i++)
46 *dst++ = clr;
47 break;
48 }
Simon Glass72cded92016-01-18 19:52:18 -070049 default:
50 return -ENOSYS;
51 }
52
53 return 0;
54}
55
56static int console_normal_move_rows(struct udevice *dev, uint rowdst,
57 uint rowsrc, uint count)
58{
59 struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
60 void *dst;
61 void *src;
62
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);
66
67 return 0;
68}
69
Simon Glassf2661782016-01-14 18:10:37 -070070static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
71 char ch)
Simon Glass72cded92016-01-18 19:52:18 -070072{
Simon Glassf2661782016-01-14 18:10:37 -070073 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
Simon Glass72cded92016-01-18 19:52:18 -070074 struct udevice *vid = dev->parent;
75 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
Simon Glass46421192019-12-20 18:10:34 -070076 int i, row;
Simon Glass72cded92016-01-18 19:52:18 -070077 void *line = vid_priv->fb + y * vid_priv->line_length +
Simon Glassf2661782016-01-14 18:10:37 -070078 VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix);
79
80 if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
81 return -EAGAIN;
Simon Glass72cded92016-01-18 19:52:18 -070082
83 for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
Andre Przywara96c9bf72019-03-23 01:29:55 +000084 unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row;
Simon Glass46421192019-12-20 18:10:34 -070085 uchar bits = video_fontdata[idx];
Simon Glass72cded92016-01-18 19:52:18 -070086
87 switch (vid_priv->bpix) {
Simon Glass46421192019-12-20 18:10:34 -070088 case VIDEO_BPP8:
89 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
90 uint8_t *dst = line;
Simon Glass72cded92016-01-18 19:52:18 -070091
Simon Glass46421192019-12-20 18:10:34 -070092 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
93 *dst++ = (bits & 0x80) ?
94 vid_priv->colour_fg :
95 vid_priv->colour_bg;
96 bits <<= 1;
97 }
98 break;
Simon Glass72cded92016-01-18 19:52:18 -070099 }
Simon Glass46421192019-12-20 18:10:34 -0700100 case VIDEO_BPP16:
101 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
102 uint16_t *dst = line;
Simon Glass72cded92016-01-18 19:52:18 -0700103
Simon Glass46421192019-12-20 18:10:34 -0700104 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
105 *dst++ = (bits & 0x80) ?
106 vid_priv->colour_fg :
107 vid_priv->colour_bg;
108 bits <<= 1;
109 }
110 break;
Simon Glass72cded92016-01-18 19:52:18 -0700111 }
Simon Glass46421192019-12-20 18:10:34 -0700112 case VIDEO_BPP32:
113 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
114 uint32_t *dst = line;
Simon Glass72cded92016-01-18 19:52:18 -0700115
Simon Glass46421192019-12-20 18:10:34 -0700116 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
117 *dst++ = (bits & 0x80) ?
118 vid_priv->colour_fg :
119 vid_priv->colour_bg;
120 bits <<= 1;
121 }
122 break;
Simon Glass72cded92016-01-18 19:52:18 -0700123 }
Simon Glass72cded92016-01-18 19:52:18 -0700124 default:
125 return -ENOSYS;
126 }
127 line += vid_priv->line_length;
128 }
129
Simon Glassf2661782016-01-14 18:10:37 -0700130 return VID_TO_POS(VIDEO_FONT_WIDTH);
131}
132
133static int console_normal_probe(struct udevice *dev)
134{
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);
138
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;
143
Simon Glass72cded92016-01-18 19:52:18 -0700144 return 0;
145}
146
147struct 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,
151};
152
153U_BOOT_DRIVER(vidconsole_normal) = {
154 .name = "vidconsole0",
155 .id = UCLASS_VIDEO_CONSOLE,
156 .ops = &console_normal_ops,
Simon Glassf2661782016-01-14 18:10:37 -0700157 .probe = console_normal_probe,
Simon Glass72cded92016-01-18 19:52:18 -0700158};