1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2015 Google, Inc
6 #ifndef __video_console_h
7 #define __video_console_h
13 #define VID_FRAC_DIV 256
15 #define VID_TO_PIXEL(x) ((x) / VID_FRAC_DIV)
16 #define VID_TO_POS(x) ((x) * VID_FRAC_DIV)
19 * struct vidconsole_priv - uclass-private data about a console device
21 * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe()
22 * method. Drivers may set up @xstart_frac if desired.
24 * @sdev: stdio device, acting as an output sink
25 * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x))
26 * @ycur: Current Y position in pixels (0=top)
27 * @rows: Number of text rows
28 * @cols: Number of text columns
29 * @x_charsize: Character width in pixels
30 * @y_charsize: Character height in pixels
31 * @tab_width_frac: Tab width in fractional units
32 * @xsize_frac: Width of the display in fractional units
33 * @xstart_frac: Left margin for the text console in fractional units
34 * @last_ch: Last character written to the text console on this line
35 * @escape: TRUE if currently accumulating an ANSI escape sequence
36 * @escape_len: Length of accumulated escape sequence so far
37 * @col_saved: Saved X position, in fractional units (VID_TO_POS(x))
38 * @row_saved: Saved Y position in pixels (0=top)
39 * @escape_buf: Buffer to accumulate escape sequence
41 struct vidconsole_priv {
42 struct stdio_dev sdev;
54 * ANSI escape sequences are accumulated character by character,
55 * starting after the ESC char (0x1b) until the entire sequence
56 * is consumed at which point it is acted upon.
66 * struct vidconsole_ops - Video console operations
68 * These operations work on either an absolute console position (measured
69 * in pixels) or a text row number (measured in rows, where each row consists
70 * of an entire line of text - typically 16 pixels).
72 struct vidconsole_ops {
74 * putc_xy() - write a single character to a position
76 * @dev: Device to write to
77 * @x_frac: Fractional pixel X position (0=left-most pixel) which
78 * is the X position multipled by VID_FRAC_DIV.
79 * @y: Pixel Y position (0=top-most pixel)
80 * @ch: Character to write
81 * @return number of fractional pixels that the cursor should move,
82 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
85 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
88 * move_rows() - Move text rows from one place to another
90 * @dev: Device to adjust
91 * @rowdst: Destination text row (0=top)
92 * @rowsrc: Source start text row
93 * @count: Number of text rows to move
94 * @return 0 if OK, -ve on error
96 int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
100 * set_row() - Set the colour of a text row
102 * Every pixel contained within the text row is adjusted
104 * @dev: Device to adjust
105 * @row: Text row to adjust (0=top)
106 * @clr: Raw colour (pixel value) to write to each pixel
107 * @return 0 if OK, -ve on error
109 int (*set_row)(struct udevice *dev, uint row, int clr);
112 * entry_start() - Indicate that text entry is starting afresh
114 * Consoles which use proportional fonts need to track the position of
115 * each character output so that backspace will return to the correct
116 * place. This method signals to the console driver that a new entry
117 * line is being start (e.g. the user pressed return to start a new
118 * command). The driver can use this signal to empty its list of
121 int (*entry_start)(struct udevice *dev);
124 * backspace() - Handle erasing the last character
126 * With proportional fonts the vidconsole uclass cannot itself erase
127 * the previous character. This optional method will be called when
128 * a backspace is needed. The driver should erase the previous
129 * character and update the cursor position (xcur_frac, ycur) to the
130 * start of the previous character.
132 * If not implement, default behaviour will work for fixed-width
135 int (*backspace)(struct udevice *dev);
138 /* Get a pointer to the driver operations for a video console device */
139 #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops)
142 * vidconsole_putc_xy() - write a single character to a position
144 * @dev: Device to write to
145 * @x_frac: Fractional pixel X position (0=left-most pixel) which
146 * is the X position multipled by VID_FRAC_DIV.
147 * @y: Pixel Y position (0=top-most pixel)
148 * @ch: Character to write
149 * Return: number of fractional pixels that the cursor should move,
150 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
153 int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
156 * vidconsole_move_rows() - Move text rows from one place to another
158 * @dev: Device to adjust
159 * @rowdst: Destination text row (0=top)
160 * @rowsrc: Source start text row
161 * @count: Number of text rows to move
162 * Return: 0 if OK, -ve on error
164 int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
168 * vidconsole_set_row() - Set the colour of a text row
170 * Every pixel contained within the text row is adjusted
172 * @dev: Device to adjust
173 * @row: Text row to adjust (0=top)
174 * @clr: Raw colour (pixel value) to write to each pixel
175 * Return: 0 if OK, -ve on error
177 int vidconsole_set_row(struct udevice *dev, uint row, int clr);
180 * vidconsole_put_char() - Output a character to the current console position
182 * Outputs a character to the console and advances the cursor. This function
183 * handles wrapping to new lines and scrolling the console. Special
184 * characters are handled also: \n, \r, \b and \t.
186 * The device always starts with the cursor at position 0,0 (top left). It
187 * can be adjusted manually using vidconsole_position_cursor().
189 * @dev: Device to adjust
190 * @ch: Character to write
191 * Return: 0 if OK, -ve on error
193 int vidconsole_put_char(struct udevice *dev, char ch);
196 * vidconsole_put_string() - Output a string to the current console position
198 * Outputs a string to the console and advances the cursor. This function
199 * handles wrapping to new lines and scrolling the console. Special
200 * characters are handled also: \n, \r, \b and \t.
202 * The device always starts with the cursor at position 0,0 (top left). It
203 * can be adjusted manually using vidconsole_position_cursor().
205 * @dev: Device to adjust
206 * @str: String to write
207 * Return: 0 if OK, -ve on error
209 int vidconsole_put_string(struct udevice *dev, const char *str);
212 * vidconsole_position_cursor() - Move the text cursor
214 * @dev: Device to adjust
215 * @col: New cursor text column
216 * @row: New cursor text row
217 * Return: 0 if OK, -ve on error
219 void vidconsole_position_cursor(struct udevice *dev, unsigned col,
223 * vidconsole_set_cursor_pos() - set cursor position
225 * The cursor is set to the new position and the start-of-line information is
226 * updated to the same position, so that a newline will return to @x
228 * @dev: video console device to update
229 * @x: x position from left in pixels
230 * @y: y position from top in pixels
232 void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y);
235 * vidconsole_list_fonts() - List the available fonts
237 * This shows a list on the console
239 void vidconsole_list_fonts(void);
242 * vidconsole_select_font() - Select a font to use
244 * @dev: vidconsole device
246 * @size: Size of the font (norminal pixel height) or 0 for default
248 int vidconsole_select_font(struct udevice *dev, const char *name, uint size);
251 * vidconsole_get_font() - get the current font name and size
253 * @dev: vidconsole device
254 * @sizep: Place to put the font size (nominal height in pixels)
255 * Returns: Current font name
257 const char *vidconsole_get_font(struct udevice *dev, uint *sizep);
259 #ifdef CONFIG_VIDEO_COPY
261 * vidconsole_sync_copy() - Sync back to the copy framebuffer
263 * This ensures that the copy framebuffer has the same data as the framebuffer
264 * for a particular region. It should be called after the framebuffer is updated
266 * @from and @to can be in either order. The region between them is synced.
268 * @dev: Vidconsole device being updated
269 * @from: Start/end address within the framebuffer (->fb)
270 * @to: Other address within the frame buffer
271 * Return: 0 if OK, -EFAULT if the start address is before the start of the
274 int vidconsole_sync_copy(struct udevice *dev, void *from, void *to);
277 * vidconsole_memmove() - Perform a memmove() within the frame buffer
279 * This handles a memmove(), e.g. for scrolling. It also updates the copy
282 * @dev: Vidconsole device being updated
283 * @dst: Destination address within the framebuffer (->fb)
284 * @src: Source address within the framebuffer (->fb)
285 * @size: Number of bytes to transfer
286 * Return: 0 if OK, -EFAULT if the start address is before the start of the
289 int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
292 static inline int vidconsole_sync_copy(struct udevice *dev, void *from,
298 static inline int vidconsole_memmove(struct udevice *dev, void *dst,
299 const void *src, int size)
301 memmove(dst, src, size);