]> Git Repo - J-u-boot.git/blame - drivers/video/console_normal.c
video: Show an error when a vidconsole function fails
[J-u-boot.git] / drivers / video / console_normal.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
72cded9e
SG
2/*
3 * Copyright (c) 2015 Google, Inc
4 * (C) Copyright 2001-2015
5 * DENX Software Engineering -- [email protected]
6 * Compulab Ltd - http://compulab.co.il/
7 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
72cded9e
SG
8 */
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);
46421197
SG
19 void *line;
20 int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
21 int i;
72cded9e
SG
22
23 line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
24 switch (vid_priv->bpix) {
46421197
SG
25 case VIDEO_BPP8:
26 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
27 uint8_t *dst = line;
72cded9e 28
46421197
SG
29 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;
36
37 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;
44
45 for (i = 0; i < pixels; i++)
46 *dst++ = clr;
47 break;
48 }
72cded9e
SG
49 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
f2661786
SG
70static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
71 char ch)
72cded9e 72{
f2661786 73 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
72cded9e
SG
74 struct udevice *vid = dev->parent;
75 struct video_priv *vid_priv = dev_get_uclass_priv(vid);
46421197 76 int i, row;
72cded9e 77 void *line = vid_priv->fb + y * vid_priv->line_length +
f2661786
SG
78 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;
72cded9e
SG
82
83 for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
96c9bf7e 84 unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row;
46421197 85 uchar bits = video_fontdata[idx];
72cded9e
SG
86
87 switch (vid_priv->bpix) {
46421197
SG
88 case VIDEO_BPP8:
89 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
90 uint8_t *dst = line;
91
92 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;
72cded9e 99 }
46421197
SG
100 case VIDEO_BPP16:
101 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
102 uint16_t *dst = line;
103
104 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;
72cded9e 111 }
46421197
SG
112 case VIDEO_BPP32:
113 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
114 uint32_t *dst = line;
115
116 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;
72cded9e 123 }
72cded9e
SG
124 default:
125 return -ENOSYS;
126 }
127 line += vid_priv->line_length;
128 }
129
f2661786
SG
130 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
72cded9e
SG
144 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,
f2661786 157 .probe = console_normal_probe,
72cded9e 158};
This page took 0.261062 seconds and 4 git commands to generate.