183510766SSimon Glass /* 283510766SSimon Glass * Copyright (c) 2015 Google, Inc 383510766SSimon Glass * 483510766SSimon Glass * SPDX-License-Identifier: GPL-2.0+ 583510766SSimon Glass */ 683510766SSimon Glass 783510766SSimon Glass #ifndef __video_console_h 883510766SSimon Glass #define __video_console_h 983510766SSimon Glass 10f2661786SSimon Glass #define VID_FRAC_DIV 256 11f2661786SSimon Glass 12f2661786SSimon Glass #define VID_TO_PIXEL(x) ((x) / VID_FRAC_DIV) 13f2661786SSimon Glass #define VID_TO_POS(x) ((x) * VID_FRAC_DIV) 14f2661786SSimon Glass 1583510766SSimon Glass /** 1683510766SSimon Glass * struct vidconsole_priv - uclass-private data about a console device 1783510766SSimon Glass * 18f2661786SSimon Glass * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe() 19f2661786SSimon Glass * method. Drivers may set up @xstart_frac if desired. 20f2661786SSimon Glass * 2183510766SSimon Glass * @sdev: stdio device, acting as an output sink 22f2661786SSimon Glass * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x)) 23f2661786SSimon Glass * @curr_row: Current Y position in pixels (0=top) 2483510766SSimon Glass * @rows: Number of text rows 2583510766SSimon Glass * @cols: Number of text columns 26f2661786SSimon Glass * @x_charsize: Character width in pixels 27f2661786SSimon Glass * @y_charsize: Character height in pixels 28f2661786SSimon Glass * @tab_width_frac: Tab width in fractional units 29f2661786SSimon Glass * @xsize_frac: Width of the display in fractional units 30*c5b77d01SSimon Glass * @xstart_frac: Left margin for the text console in fractional units 3183510766SSimon Glass */ 3283510766SSimon Glass struct vidconsole_priv { 3383510766SSimon Glass struct stdio_dev sdev; 34f2661786SSimon Glass int xcur_frac; 35f2661786SSimon Glass int ycur; 3683510766SSimon Glass int rows; 3783510766SSimon Glass int cols; 38f2661786SSimon Glass int x_charsize; 39f2661786SSimon Glass int y_charsize; 40f2661786SSimon Glass int tab_width_frac; 41f2661786SSimon Glass int xsize_frac; 42*c5b77d01SSimon Glass int xstart_frac; 4383510766SSimon Glass }; 4483510766SSimon Glass 4583510766SSimon Glass /** 4683510766SSimon Glass * struct vidconsole_ops - Video console operations 4783510766SSimon Glass * 4883510766SSimon Glass * These operations work on either an absolute console position (measured 4983510766SSimon Glass * in pixels) or a text row number (measured in rows, where each row consists 5083510766SSimon Glass * of an entire line of text - typically 16 pixels). 5183510766SSimon Glass */ 5283510766SSimon Glass struct vidconsole_ops { 5383510766SSimon Glass /** 5483510766SSimon Glass * putc_xy() - write a single character to a position 5583510766SSimon Glass * 5683510766SSimon Glass * @dev: Device to write to 57f2661786SSimon Glass * @x_frac: Fractional pixel X position (0=left-most pixel) which 58f2661786SSimon Glass * is the X position multipled by VID_FRAC_DIV. 5983510766SSimon Glass * @y: Pixel Y position (0=top-most pixel) 6083510766SSimon Glass * @ch: Character to write 61f2661786SSimon Glass * @return number of fractional pixels that the cursor should move, 62f2661786SSimon Glass * if all is OK, -EAGAIN if we ran out of space on this line, other -ve 63f2661786SSimon Glass * on error 6483510766SSimon Glass */ 65f2661786SSimon Glass int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch); 6683510766SSimon Glass 6783510766SSimon Glass /** 6883510766SSimon Glass * move_rows() - Move text rows from one place to another 6983510766SSimon Glass * 7083510766SSimon Glass * @dev: Device to adjust 7183510766SSimon Glass * @rowdst: Destination text row (0=top) 7283510766SSimon Glass * @rowsrc: Source start text row 7383510766SSimon Glass * @count: Number of text rows to move 7483510766SSimon Glass * @return 0 if OK, -ve on error 7583510766SSimon Glass */ 7683510766SSimon Glass int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc, 7783510766SSimon Glass uint count); 7883510766SSimon Glass 7983510766SSimon Glass /** 8083510766SSimon Glass * set_row() - Set the colour of a text row 8183510766SSimon Glass * 8283510766SSimon Glass * Every pixel contained within the text row is adjusted 8383510766SSimon Glass * 8483510766SSimon Glass * @dev: Device to adjust 8583510766SSimon Glass * @row: Text row to adjust (0=top) 8683510766SSimon Glass * @clr: Raw colour (pixel value) to write to each pixel 8783510766SSimon Glass * @return 0 if OK, -ve on error 8883510766SSimon Glass */ 8983510766SSimon Glass int (*set_row)(struct udevice *dev, uint row, int clr); 9083510766SSimon Glass }; 9183510766SSimon Glass 9283510766SSimon Glass /* Get a pointer to the driver operations for a video console device */ 9383510766SSimon Glass #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops) 9483510766SSimon Glass 9583510766SSimon Glass /** 9683510766SSimon Glass * vidconsole_putc_xy() - write a single character to a position 9783510766SSimon Glass * 9883510766SSimon Glass * @dev: Device to write to 99f2661786SSimon Glass * @x_frac: Fractional pixel X position (0=left-most pixel) which 100f2661786SSimon Glass * is the X position multipled by VID_FRAC_DIV. 10183510766SSimon Glass * @y: Pixel Y position (0=top-most pixel) 10283510766SSimon Glass * @ch: Character to write 103f2661786SSimon Glass * @return number of fractional pixels that the cursor should move, 104f2661786SSimon Glass * if all is OK, -EAGAIN if we ran out of space on this line, other -ve 105f2661786SSimon Glass * on error 10683510766SSimon Glass */ 10783510766SSimon Glass int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch); 10883510766SSimon Glass 10983510766SSimon Glass /** 11083510766SSimon Glass * vidconsole_move_rows() - Move text rows from one place to another 11183510766SSimon Glass * 11283510766SSimon Glass * @dev: Device to adjust 11383510766SSimon Glass * @rowdst: Destination text row (0=top) 11483510766SSimon Glass * @rowsrc: Source start text row 11583510766SSimon Glass * @count: Number of text rows to move 11683510766SSimon Glass * @return 0 if OK, -ve on error 11783510766SSimon Glass */ 11883510766SSimon Glass int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc, 11983510766SSimon Glass uint count); 12083510766SSimon Glass 12183510766SSimon Glass /** 12283510766SSimon Glass * vidconsole_set_row() - Set the colour of a text row 12383510766SSimon Glass * 12483510766SSimon Glass * Every pixel contained within the text row is adjusted 12583510766SSimon Glass * 12683510766SSimon Glass * @dev: Device to adjust 12783510766SSimon Glass * @row: Text row to adjust (0=top) 12883510766SSimon Glass * @clr: Raw colour (pixel value) to write to each pixel 12983510766SSimon Glass * @return 0 if OK, -ve on error 13083510766SSimon Glass */ 13183510766SSimon Glass int vidconsole_set_row(struct udevice *dev, uint row, int clr); 13283510766SSimon Glass 13383510766SSimon Glass /** 13483510766SSimon Glass * vidconsole_put_char() - Output a character to the current console position 13583510766SSimon Glass * 13683510766SSimon Glass * Outputs a character to the console and advances the cursor. This function 13783510766SSimon Glass * handles wrapping to new lines and scrolling the console. Special 13883510766SSimon Glass * characters are handled also: \n, \r, \b and \t. 13983510766SSimon Glass * 14083510766SSimon Glass * The device always starts with the cursor at position 0,0 (top left). It 14183510766SSimon Glass * can be adjusted manually using vidconsole_position_cursor(). 14283510766SSimon Glass * 14383510766SSimon Glass * @dev: Device to adjust 14483510766SSimon Glass * @ch: Character to write 14583510766SSimon Glass * @return 0 if OK, -ve on error 14683510766SSimon Glass */ 14783510766SSimon Glass int vidconsole_put_char(struct udevice *dev, char ch); 14883510766SSimon Glass 14983510766SSimon Glass /** 15083510766SSimon Glass * vidconsole_position_cursor() - Move the text cursor 15183510766SSimon Glass * 15283510766SSimon Glass * @dev: Device to adjust 15383510766SSimon Glass * @col: New cursor text column 15483510766SSimon Glass * @row: New cursor text row 15583510766SSimon Glass * @return 0 if OK, -ve on error 15683510766SSimon Glass */ 15783510766SSimon Glass void vidconsole_position_cursor(struct udevice *dev, unsigned col, 15883510766SSimon Glass unsigned row); 15983510766SSimon Glass 16083510766SSimon Glass #endif 161