]> git.ipfire.org Git - thirdparty/u-boot.git/blame - include/video_console.h
usb: dwc3: add dis_u2_freeclk_exists_quirk
[thirdparty/u-boot.git] / include / video_console.h
CommitLineData
83d290c5 1/* SPDX-License-Identifier: GPL-2.0+ */
83510766
SG
2/*
3 * Copyright (c) 2015 Google, Inc
83510766
SG
4 */
5
6#ifndef __video_console_h
7#define __video_console_h
8
5c30fbb8
HS
9#include <video.h>
10
f2661786
SG
11#define VID_FRAC_DIV 256
12
13#define VID_TO_PIXEL(x) ((x) / VID_FRAC_DIV)
14#define VID_TO_POS(x) ((x) * VID_FRAC_DIV)
15
5c30fbb8 16/*
9ffa4d12 17 * The 16 colors supported by the console
5c30fbb8
HS
18 */
19enum color_idx {
20 VID_BLACK = 0,
21 VID_RED,
22 VID_GREEN,
9ffa4d12 23 VID_BROWN,
5c30fbb8
HS
24 VID_BLUE,
25 VID_MAGENTA,
26 VID_CYAN,
9ffa4d12
HS
27 VID_LIGHT_GRAY,
28 VID_GRAY,
29 VID_LIGHT_RED,
30 VID_LIGTH_GREEN,
31 VID_YELLOW,
32 VID_LIGHT_BLUE,
33 VID_LIGHT_MAGENTA,
34 VID_LIGHT_CYAN,
5c30fbb8
HS
35 VID_WHITE,
36
37 VID_COLOR_COUNT
38};
39
83510766
SG
40/**
41 * struct vidconsole_priv - uclass-private data about a console device
42 *
f2661786
SG
43 * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe()
44 * method. Drivers may set up @xstart_frac if desired.
45 *
662f381a
HS
46 * @sdev: stdio device, acting as an output sink
47 * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x))
48 * @ycur: Current Y position in pixels (0=top)
49 * @rows: Number of text rows
50 * @cols: Number of text columns
51 * @x_charsize: Character width in pixels
52 * @y_charsize: Character height in pixels
f2661786 53 * @tab_width_frac: Tab width in fractional units
662f381a 54 * @xsize_frac: Width of the display in fractional units
c5b77d01 55 * @xstart_frac: Left margin for the text console in fractional units
662f381a
HS
56 * @last_ch: Last character written to the text console on this line
57 * @escape: TRUE if currently accumulating an ANSI escape sequence
58 * @escape_len: Length of accumulated escape sequence so far
59 * @col_saved: Saved X position, in fractional units (VID_TO_POS(x))
60 * @row_saved: Saved Y position in pixels (0=top)
61 * @escape_buf: Buffer to accumulate escape sequence
83510766
SG
62 */
63struct vidconsole_priv {
64 struct stdio_dev sdev;
f2661786
SG
65 int xcur_frac;
66 int ycur;
83510766
SG
67 int rows;
68 int cols;
f2661786
SG
69 int x_charsize;
70 int y_charsize;
71 int tab_width_frac;
72 int xsize_frac;
c5b77d01 73 int xstart_frac;
58c733a7 74 int last_ch;
a085aa1f
RC
75 /*
76 * ANSI escape sequences are accumulated character by character,
77 * starting after the ESC char (0x1b) until the entire sequence
78 * is consumed at which point it is acted upon.
79 */
80 int escape;
81 int escape_len;
662f381a
HS
82 int row_saved;
83 int col_saved;
a085aa1f 84 char escape_buf[32];
83510766
SG
85};
86
87/**
88 * struct vidconsole_ops - Video console operations
89 *
90 * These operations work on either an absolute console position (measured
91 * in pixels) or a text row number (measured in rows, where each row consists
92 * of an entire line of text - typically 16 pixels).
93 */
94struct vidconsole_ops {
95 /**
96 * putc_xy() - write a single character to a position
97 *
98 * @dev: Device to write to
f2661786
SG
99 * @x_frac: Fractional pixel X position (0=left-most pixel) which
100 * is the X position multipled by VID_FRAC_DIV.
83510766
SG
101 * @y: Pixel Y position (0=top-most pixel)
102 * @ch: Character to write
f2661786
SG
103 * @return number of fractional pixels that the cursor should move,
104 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
105 * on error
83510766 106 */
f2661786 107 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
83510766
SG
108
109 /**
110 * move_rows() - Move text rows from one place to another
111 *
112 * @dev: Device to adjust
113 * @rowdst: Destination text row (0=top)
114 * @rowsrc: Source start text row
115 * @count: Number of text rows to move
116 * @return 0 if OK, -ve on error
117 */
118 int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
119 uint count);
120
121 /**
122 * set_row() - Set the colour of a text row
123 *
124 * Every pixel contained within the text row is adjusted
125 *
126 * @dev: Device to adjust
127 * @row: Text row to adjust (0=top)
128 * @clr: Raw colour (pixel value) to write to each pixel
129 * @return 0 if OK, -ve on error
130 */
131 int (*set_row)(struct udevice *dev, uint row, int clr);
58c733a7
SG
132
133 /**
134 * entry_start() - Indicate that text entry is starting afresh
135 *
136 * Consoles which use proportional fonts need to track the position of
137 * each character output so that backspace will return to the correct
138 * place. This method signals to the console driver that a new entry
139 * line is being start (e.g. the user pressed return to start a new
140 * command). The driver can use this signal to empty its list of
141 * positions.
142 */
143 int (*entry_start)(struct udevice *dev);
7b9f7e44
SG
144
145 /**
146 * backspace() - Handle erasing the last character
147 *
148 * With proportional fonts the vidconsole uclass cannot itself erase
149 * the previous character. This optional method will be called when
150 * a backspace is needed. The driver should erase the previous
151 * character and update the cursor position (xcur_frac, ycur) to the
152 * start of the previous character.
153 *
154 * If not implement, default behaviour will work for fixed-width
155 * characters.
156 */
157 int (*backspace)(struct udevice *dev);
83510766
SG
158};
159
160/* Get a pointer to the driver operations for a video console device */
161#define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops)
162
163/**
164 * vidconsole_putc_xy() - write a single character to a position
165 *
166 * @dev: Device to write to
f2661786
SG
167 * @x_frac: Fractional pixel X position (0=left-most pixel) which
168 * is the X position multipled by VID_FRAC_DIV.
83510766
SG
169 * @y: Pixel Y position (0=top-most pixel)
170 * @ch: Character to write
f2661786
SG
171 * @return number of fractional pixels that the cursor should move,
172 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
173 * on error
83510766
SG
174 */
175int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
176
177/**
178 * vidconsole_move_rows() - Move text rows from one place to another
179 *
180 * @dev: Device to adjust
181 * @rowdst: Destination text row (0=top)
182 * @rowsrc: Source start text row
183 * @count: Number of text rows to move
184 * @return 0 if OK, -ve on error
185 */
186int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
187 uint count);
188
189/**
190 * vidconsole_set_row() - Set the colour of a text row
191 *
192 * Every pixel contained within the text row is adjusted
193 *
194 * @dev: Device to adjust
195 * @row: Text row to adjust (0=top)
196 * @clr: Raw colour (pixel value) to write to each pixel
197 * @return 0 if OK, -ve on error
198 */
199int vidconsole_set_row(struct udevice *dev, uint row, int clr);
200
201/**
202 * vidconsole_put_char() - Output a character to the current console position
203 *
204 * Outputs a character to the console and advances the cursor. This function
205 * handles wrapping to new lines and scrolling the console. Special
206 * characters are handled also: \n, \r, \b and \t.
207 *
208 * The device always starts with the cursor at position 0,0 (top left). It
209 * can be adjusted manually using vidconsole_position_cursor().
210 *
211 * @dev: Device to adjust
212 * @ch: Character to write
213 * @return 0 if OK, -ve on error
214 */
215int vidconsole_put_char(struct udevice *dev, char ch);
216
e63168a9
MV
217/**
218 * vidconsole_put_string() - Output a string to the current console position
219 *
220 * Outputs a string to the console and advances the cursor. This function
221 * handles wrapping to new lines and scrolling the console. Special
222 * characters are handled also: \n, \r, \b and \t.
223 *
224 * The device always starts with the cursor at position 0,0 (top left). It
225 * can be adjusted manually using vidconsole_position_cursor().
226 *
227 * @dev: Device to adjust
228 * @str: String to write
229 * @return 0 if OK, -ve on error
230 */
231int vidconsole_put_string(struct udevice *dev, const char *str);
232
83510766
SG
233/**
234 * vidconsole_position_cursor() - Move the text cursor
235 *
236 * @dev: Device to adjust
237 * @col: New cursor text column
238 * @row: New cursor text row
239 * @return 0 if OK, -ve on error
240 */
241void vidconsole_position_cursor(struct udevice *dev, unsigned col,
242 unsigned row);
243
5c30fbb8
HS
244#ifdef CONFIG_DM_VIDEO
245
246/**
247 * vid_console_color() - convert a color code to a pixel's internal
248 * representation
249 *
250 * The caller has to guarantee that the color index is less than
251 * VID_COLOR_COUNT.
252 *
253 * @priv private data of the console device
254 * @idx color index
255 * @return color value
256 */
257u32 vid_console_color(struct video_priv *priv, unsigned int idx);
258
259#endif
260
83510766 261#endif