2 * Copyright (c) 2015 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
7 #ifndef __video_console_h
8 #define __video_console_h
10 #define VID_FRAC_DIV 256
12 #define VID_TO_PIXEL(x) ((x) / VID_FRAC_DIV)
13 #define VID_TO_POS(x) ((x) * VID_FRAC_DIV)
16 * struct vidconsole_priv - uclass-private data about a console device
18 * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe()
19 * method. Drivers may set up @xstart_frac if desired.
21 * @sdev: stdio device, acting as an output sink
22 * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x))
23 * @curr_row: Current Y position in pixels (0=top)
24 * @rows: Number of text rows
25 * @cols: Number of text columns
26 * @x_charsize: Character width in pixels
27 * @y_charsize: Character height in pixels
28 * @tab_width_frac: Tab width in fractional units
29 * @xsize_frac: Width of the display in fractional units
30 * @xstart_frac: Left margin for the text console in fractional units
31 * @last_ch: Last character written to the text console on this line
33 struct vidconsole_priv {
34 struct stdio_dev sdev;
48 * struct vidconsole_ops - Video console operations
50 * These operations work on either an absolute console position (measured
51 * in pixels) or a text row number (measured in rows, where each row consists
52 * of an entire line of text - typically 16 pixels).
54 struct vidconsole_ops {
56 * putc_xy() - write a single character to a position
58 * @dev: Device to write to
59 * @x_frac: Fractional pixel X position (0=left-most pixel) which
60 * is the X position multipled by VID_FRAC_DIV.
61 * @y: Pixel Y position (0=top-most pixel)
62 * @ch: Character to write
63 * @return number of fractional pixels that the cursor should move,
64 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
67 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
70 * move_rows() - Move text rows from one place to another
72 * @dev: Device to adjust
73 * @rowdst: Destination text row (0=top)
74 * @rowsrc: Source start text row
75 * @count: Number of text rows to move
76 * @return 0 if OK, -ve on error
78 int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
82 * set_row() - Set the colour of a text row
84 * Every pixel contained within the text row is adjusted
86 * @dev: Device to adjust
87 * @row: Text row to adjust (0=top)
88 * @clr: Raw colour (pixel value) to write to each pixel
89 * @return 0 if OK, -ve on error
91 int (*set_row)(struct udevice *dev, uint row, int clr);
94 * entry_start() - Indicate that text entry is starting afresh
96 * Consoles which use proportional fonts need to track the position of
97 * each character output so that backspace will return to the correct
98 * place. This method signals to the console driver that a new entry
99 * line is being start (e.g. the user pressed return to start a new
100 * command). The driver can use this signal to empty its list of
103 int (*entry_start)(struct udevice *dev);
106 * backspace() - Handle erasing the last character
108 * With proportional fonts the vidconsole uclass cannot itself erase
109 * the previous character. This optional method will be called when
110 * a backspace is needed. The driver should erase the previous
111 * character and update the cursor position (xcur_frac, ycur) to the
112 * start of the previous character.
114 * If not implement, default behaviour will work for fixed-width
117 int (*backspace)(struct udevice *dev);
120 /* Get a pointer to the driver operations for a video console device */
121 #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops)
124 * vidconsole_putc_xy() - write a single character to a position
126 * @dev: Device to write to
127 * @x_frac: Fractional pixel X position (0=left-most pixel) which
128 * is the X position multipled by VID_FRAC_DIV.
129 * @y: Pixel Y position (0=top-most pixel)
130 * @ch: Character to write
131 * @return number of fractional pixels that the cursor should move,
132 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
135 int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
138 * vidconsole_move_rows() - Move text rows from one place to another
140 * @dev: Device to adjust
141 * @rowdst: Destination text row (0=top)
142 * @rowsrc: Source start text row
143 * @count: Number of text rows to move
144 * @return 0 if OK, -ve on error
146 int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
150 * vidconsole_set_row() - Set the colour of a text row
152 * Every pixel contained within the text row is adjusted
154 * @dev: Device to adjust
155 * @row: Text row to adjust (0=top)
156 * @clr: Raw colour (pixel value) to write to each pixel
157 * @return 0 if OK, -ve on error
159 int vidconsole_set_row(struct udevice *dev, uint row, int clr);
162 * vidconsole_put_char() - Output a character to the current console position
164 * Outputs a character to the console and advances the cursor. This function
165 * handles wrapping to new lines and scrolling the console. Special
166 * characters are handled also: \n, \r, \b and \t.
168 * The device always starts with the cursor at position 0,0 (top left). It
169 * can be adjusted manually using vidconsole_position_cursor().
171 * @dev: Device to adjust
172 * @ch: Character to write
173 * @return 0 if OK, -ve on error
175 int vidconsole_put_char(struct udevice *dev, char ch);
178 * vidconsole_position_cursor() - Move the text cursor
180 * @dev: Device to adjust
181 * @col: New cursor text column
182 * @row: New cursor text row
183 * @return 0 if OK, -ve on error
185 void vidconsole_position_cursor(struct udevice *dev, unsigned col,