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 vidfont_info - information about a font
68 * @name: Font name, e.g. nimbus_sans_l_regular
75 * struct vidconsole_colour - Holds colour information
77 * @colour_fg: Foreground colour (pixel value)
78 * @colour_bg: Background colour (pixel value)
80 struct vidconsole_colour {
86 * struct vidconsole_bbox - Bounding box of text
88 * This describes the bounding box of something, measured in pixels. The x0/y0
89 * pair is inclusive; the x1/y2 pair is exclusive, meaning that it is one pixel
90 * beyond the extent of the object
92 * @valid: Values are valid (bounding box is known)
93 * @x0: left x position, in pixels from left side
94 * @y0: top y position, in pixels from top
95 * @x1: right x position + 1
96 * @y1: botton y position + 1
98 struct vidconsole_bbox {
107 * struct vidconsole_ops - Video console operations
109 * These operations work on either an absolute console position (measured
110 * in pixels) or a text row number (measured in rows, where each row consists
111 * of an entire line of text - typically 16 pixels).
113 struct vidconsole_ops {
115 * putc_xy() - write a single character to a position
117 * @dev: Device to write to
118 * @x_frac: Fractional pixel X position (0=left-most pixel) which
119 * is the X position multipled by VID_FRAC_DIV.
120 * @y: Pixel Y position (0=top-most pixel)
121 * @ch: Character to write
122 * @return number of fractional pixels that the cursor should move,
123 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
126 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
129 * move_rows() - Move text rows from one place to another
131 * @dev: Device to adjust
132 * @rowdst: Destination text row (0=top)
133 * @rowsrc: Source start text row
134 * @count: Number of text rows to move
135 * @return 0 if OK, -ve on error
137 int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
141 * set_row() - Set the colour of a text row
143 * Every pixel contained within the text row is adjusted
145 * @dev: Device to adjust
146 * @row: Text row to adjust (0=top)
147 * @clr: Raw colour (pixel value) to write to each pixel
148 * @return 0 if OK, -ve on error
150 int (*set_row)(struct udevice *dev, uint row, int clr);
153 * entry_start() - Indicate that text entry is starting afresh
155 * @dev: Device to adjust
156 * Returns: 0 on success, -ve on error
158 * Consoles which use proportional fonts need to track the position of
159 * each character output so that backspace will return to the correct
160 * place. This method signals to the console driver that a new entry
161 * line is being start (e.g. the user pressed return to start a new
162 * command). The driver can use this signal to empty its list of
165 int (*entry_start)(struct udevice *dev);
168 * backspace() - Handle erasing the last character
170 * @dev: Device to adjust
171 * Returns: 0 on success, -ve on error
173 * With proportional fonts the vidconsole uclass cannot itself erase
174 * the previous character. This optional method will be called when
175 * a backspace is needed. The driver should erase the previous
176 * character and update the cursor position (xcur_frac, ycur) to the
177 * start of the previous character.
179 * If not implement, default behaviour will work for fixed-width
182 int (*backspace)(struct udevice *dev);
185 * get_font() - Obtain information about a font (optional)
187 * @dev: Device to check
188 * @seq: Font number to query (0=first, 1=second, etc.)
189 * @info: Returns font information on success
190 * Returns: 0 on success, -ENOENT if no such font
192 int (*get_font)(struct udevice *dev, int seq,
193 struct vidfont_info *info);
196 * get_font_size() - get the current font name and size
198 * @dev: vidconsole device
199 * @sizep: Place to put the font size (nominal height in pixels)
200 * Returns: Current font name
202 const char *(*get_font_size)(struct udevice *dev, uint *sizep);
205 * select_font() - Select a particular font by name / size
207 * @dev: Device to adjust
208 * @name: Font name to use (NULL to use default)
209 * @size: Font size to use (0 to use default)
210 * Returns: 0 on success, -ENOENT if no such font
212 int (*select_font)(struct udevice *dev, const char *name, uint size);
215 * measure() - Measure the bounds of some text
217 * @dev: Device to adjust
218 * @name: Font name to use (NULL to use default)
219 * @size: Font size to use (0 to use default)
220 * @text: Text to measure
221 * @bbox: Returns bounding box of text, assuming it is positioned
223 * Returns: 0 on success, -ENOENT if no such font
225 int (*measure)(struct udevice *dev, const char *name, uint size,
226 const char *text, struct vidconsole_bbox *bbox);
229 /* Get a pointer to the driver operations for a video console device */
230 #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops)
233 * vidconsole_get_font() - Obtain information about a font
235 * @dev: Device to check
236 * @seq: Font number to query (0=first, 1=second, etc.)
237 * @info: Returns font information on success
238 * Returns: 0 on success, -ENOENT if no such font, -ENOSYS if there is no such
241 int vidconsole_get_font(struct udevice *dev, int seq,
242 struct vidfont_info *info);
245 * vidconsole_select_font() - Select a particular font by name / size
247 * @dev: Device to adjust
248 * @name: Font name to use (NULL to use default)
249 * @size: Font size to use (0 to use default)
251 int vidconsole_select_font(struct udevice *dev, const char *name, uint size);
254 * vidconsole_measure() - Measuring the bounding box of some text
256 * @dev: Console device to use
257 * @name: Font name, NULL for default
258 * @size: Font size, ignored if @name is NULL
259 * @text: Text to measure
260 * @bbox: Returns nounding box of text
261 * Returns: 0 if OK, -ve on error
263 int vidconsole_measure(struct udevice *dev, const char *name, uint size,
264 const char *text, struct vidconsole_bbox *bbox);
267 * vidconsole_push_colour() - Temporarily change the font colour
269 * @dev: Device to adjust
270 * @fg: Foreground colour to select
271 * @bg: Background colour to select
272 * @old: Place to store the current colour, so it can be restored
274 void vidconsole_push_colour(struct udevice *dev, enum colour_idx fg,
275 enum colour_idx bg, struct vidconsole_colour *old);
278 * vidconsole_pop_colour() - Restore the original colour
280 * @dev: Device to adjust
281 * @old: Old colour to be restored
283 void vidconsole_pop_colour(struct udevice *dev, struct vidconsole_colour *old);
286 * vidconsole_putc_xy() - write a single character to a position
288 * @dev: Device to write to
289 * @x_frac: Fractional pixel X position (0=left-most pixel) which
290 * is the X position multipled by VID_FRAC_DIV.
291 * @y: Pixel Y position (0=top-most pixel)
292 * @ch: Character to write
293 * Return: number of fractional pixels that the cursor should move,
294 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
297 int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
300 * vidconsole_move_rows() - Move text rows from one place to another
302 * @dev: Device to adjust
303 * @rowdst: Destination text row (0=top)
304 * @rowsrc: Source start text row
305 * @count: Number of text rows to move
306 * Return: 0 if OK, -ve on error
308 int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
312 * vidconsole_set_row() - Set the colour of a text row
314 * Every pixel contained within the text row is adjusted
316 * @dev: Device to adjust
317 * @row: Text row to adjust (0=top)
318 * @clr: Raw colour (pixel value) to write to each pixel
319 * Return: 0 if OK, -ve on error
321 int vidconsole_set_row(struct udevice *dev, uint row, int clr);
324 * vidconsole_put_char() - Output a character to the current console position
326 * Outputs a character to the console and advances the cursor. This function
327 * handles wrapping to new lines and scrolling the console. Special
328 * characters are handled also: \n, \r, \b and \t.
330 * The device always starts with the cursor at position 0,0 (top left). It
331 * can be adjusted manually using vidconsole_position_cursor().
333 * @dev: Device to adjust
334 * @ch: Character to write
335 * Return: 0 if OK, -ve on error
337 int vidconsole_put_char(struct udevice *dev, char ch);
340 * vidconsole_put_string() - Output a string to the current console position
342 * Outputs a string to the console and advances the cursor. This function
343 * handles wrapping to new lines and scrolling the console. Special
344 * characters are handled also: \n, \r, \b and \t.
346 * The device always starts with the cursor at position 0,0 (top left). It
347 * can be adjusted manually using vidconsole_position_cursor().
349 * @dev: Device to adjust
350 * @str: String to write
351 * Return: 0 if OK, -ve on error
353 int vidconsole_put_string(struct udevice *dev, const char *str);
356 * vidconsole_position_cursor() - Move the text cursor
358 * @dev: Device to adjust
359 * @col: New cursor text column
360 * @row: New cursor text row
361 * Return: 0 if OK, -ve on error
363 void vidconsole_position_cursor(struct udevice *dev, unsigned col,
367 * vidconsole_clear_and_reset() - Clear the console and reset the cursor
369 * The cursor is placed at the start of the console
371 * @dev: vidconsole device to adjust
373 int vidconsole_clear_and_reset(struct udevice *dev);
376 * vidconsole_set_cursor_pos() - set cursor position
378 * The cursor is set to the new position and the start-of-line information is
379 * updated to the same position, so that a newline will return to @x
381 * @dev: video console device to update
382 * @x: x position from left in pixels
383 * @y: y position from top in pixels
385 void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y);
388 * vidconsole_list_fonts() - List the available fonts
390 * @dev: vidconsole device to check
392 * This shows a list of fonts known by this vidconsole. The list is displayed on
393 * the console (not necessarily @dev but probably)
395 void vidconsole_list_fonts(struct udevice *dev);
398 * vidconsole_get_font_size() - get the current font name and size
400 * @dev: vidconsole device
401 * @sizep: Place to put the font size (nominal height in pixels)
402 * @name: pointer to font name, a placeholder for result
403 * Return: 0 if OK, -ENOSYS if not implemented in driver
405 int vidconsole_get_font_size(struct udevice *dev, const char **name, uint *sizep);
407 #ifdef CONFIG_VIDEO_COPY
409 * vidconsole_sync_copy() - Sync back to the copy framebuffer
411 * This ensures that the copy framebuffer has the same data as the framebuffer
412 * for a particular region. It should be called after the framebuffer is updated
414 * @from and @to can be in either order. The region between them is synced.
416 * @dev: Vidconsole device being updated
417 * @from: Start/end address within the framebuffer (->fb)
418 * @to: Other address within the frame buffer
419 * Return: 0 if OK, -EFAULT if the start address is before the start of the
422 int vidconsole_sync_copy(struct udevice *dev, void *from, void *to);
425 * vidconsole_memmove() - Perform a memmove() within the frame buffer
427 * This handles a memmove(), e.g. for scrolling. It also updates the copy
430 * @dev: Vidconsole device being updated
431 * @dst: Destination address within the framebuffer (->fb)
432 * @src: Source address within the framebuffer (->fb)
433 * @size: Number of bytes to transfer
434 * Return: 0 if OK, -EFAULT if the start address is before the start of the
437 int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
443 static inline int vidconsole_sync_copy(struct udevice *dev, void *from,
449 static inline int vidconsole_memmove(struct udevice *dev, void *dst,
450 const void *src, int size)
452 memmove(dst, src, size);