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 * The 16 colors supported by the console
43 * struct vidconsole_priv - uclass-private data about a console device
45 * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe()
46 * method. Drivers may set up @xstart_frac if desired.
48 * @sdev: stdio device, acting as an output sink
49 * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x))
50 * @ycur: Current Y position in pixels (0=top)
51 * @rows: Number of text rows
52 * @cols: Number of text columns
53 * @x_charsize: Character width in pixels
54 * @y_charsize: Character height in pixels
55 * @tab_width_frac: Tab width in fractional units
56 * @xsize_frac: Width of the display in fractional units
57 * @xstart_frac: Left margin for the text console in fractional units
58 * @last_ch: Last character written to the text console on this line
59 * @escape: TRUE if currently accumulating an ANSI escape sequence
60 * @escape_len: Length of accumulated escape sequence so far
61 * @col_saved: Saved X position, in fractional units (VID_TO_POS(x))
62 * @row_saved: Saved Y position in pixels (0=top)
63 * @escape_buf: Buffer to accumulate escape sequence
65 struct vidconsole_priv {
66 struct stdio_dev sdev;
78 * ANSI escape sequences are accumulated character by character,
79 * starting after the ESC char (0x1b) until the entire sequence
80 * is consumed at which point it is acted upon.
90 * struct vidconsole_ops - Video console operations
92 * These operations work on either an absolute console position (measured
93 * in pixels) or a text row number (measured in rows, where each row consists
94 * of an entire line of text - typically 16 pixels).
96 struct vidconsole_ops {
98 * putc_xy() - write a single character to a position
100 * @dev: Device to write to
101 * @x_frac: Fractional pixel X position (0=left-most pixel) which
102 * is the X position multipled by VID_FRAC_DIV.
103 * @y: Pixel Y position (0=top-most pixel)
104 * @ch: Character to write
105 * @return number of fractional pixels that the cursor should move,
106 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
109 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
112 * move_rows() - Move text rows from one place to another
114 * @dev: Device to adjust
115 * @rowdst: Destination text row (0=top)
116 * @rowsrc: Source start text row
117 * @count: Number of text rows to move
118 * @return 0 if OK, -ve on error
120 int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
124 * set_row() - Set the colour of a text row
126 * Every pixel contained within the text row is adjusted
128 * @dev: Device to adjust
129 * @row: Text row to adjust (0=top)
130 * @clr: Raw colour (pixel value) to write to each pixel
131 * @return 0 if OK, -ve on error
133 int (*set_row)(struct udevice *dev, uint row, int clr);
136 * entry_start() - Indicate that text entry is starting afresh
138 * Consoles which use proportional fonts need to track the position of
139 * each character output so that backspace will return to the correct
140 * place. This method signals to the console driver that a new entry
141 * line is being start (e.g. the user pressed return to start a new
142 * command). The driver can use this signal to empty its list of
145 int (*entry_start)(struct udevice *dev);
148 * backspace() - Handle erasing the last character
150 * With proportional fonts the vidconsole uclass cannot itself erase
151 * the previous character. This optional method will be called when
152 * a backspace is needed. The driver should erase the previous
153 * character and update the cursor position (xcur_frac, ycur) to the
154 * start of the previous character.
156 * If not implement, default behaviour will work for fixed-width
159 int (*backspace)(struct udevice *dev);
162 /* Get a pointer to the driver operations for a video console device */
163 #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops)
166 * vidconsole_putc_xy() - write a single character to a position
168 * @dev: Device to write to
169 * @x_frac: Fractional pixel X position (0=left-most pixel) which
170 * is the X position multipled by VID_FRAC_DIV.
171 * @y: Pixel Y position (0=top-most pixel)
172 * @ch: Character to write
173 * @return number of fractional pixels that the cursor should move,
174 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
177 int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
180 * vidconsole_move_rows() - Move text rows from one place to another
182 * @dev: Device to adjust
183 * @rowdst: Destination text row (0=top)
184 * @rowsrc: Source start text row
185 * @count: Number of text rows to move
186 * @return 0 if OK, -ve on error
188 int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
192 * vidconsole_set_row() - Set the colour of a text row
194 * Every pixel contained within the text row is adjusted
196 * @dev: Device to adjust
197 * @row: Text row to adjust (0=top)
198 * @clr: Raw colour (pixel value) to write to each pixel
199 * @return 0 if OK, -ve on error
201 int vidconsole_set_row(struct udevice *dev, uint row, int clr);
204 * vidconsole_put_char() - Output a character to the current console position
206 * Outputs a character to the console and advances the cursor. This function
207 * handles wrapping to new lines and scrolling the console. Special
208 * characters are handled also: \n, \r, \b and \t.
210 * The device always starts with the cursor at position 0,0 (top left). It
211 * can be adjusted manually using vidconsole_position_cursor().
213 * @dev: Device to adjust
214 * @ch: Character to write
215 * @return 0 if OK, -ve on error
217 int vidconsole_put_char(struct udevice *dev, char ch);
220 * vidconsole_put_string() - Output a string to the current console position
222 * Outputs a string to the console and advances the cursor. This function
223 * handles wrapping to new lines and scrolling the console. Special
224 * characters are handled also: \n, \r, \b and \t.
226 * The device always starts with the cursor at position 0,0 (top left). It
227 * can be adjusted manually using vidconsole_position_cursor().
229 * @dev: Device to adjust
230 * @str: String to write
231 * @return 0 if OK, -ve on error
233 int vidconsole_put_string(struct udevice *dev, const char *str);
236 * vidconsole_position_cursor() - Move the text cursor
238 * @dev: Device to adjust
239 * @col: New cursor text column
240 * @row: New cursor text row
241 * @return 0 if OK, -ve on error
243 void vidconsole_position_cursor(struct udevice *dev, unsigned col,
247 * vid_console_color() - convert a color code to a pixel's internal
250 * The caller has to guarantee that the color index is less than
253 * @priv private data of the console device
255 * @return color value
257 u32 vid_console_color(struct video_priv *priv, unsigned int idx);
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);