1 /* 2 * Copyright (c) 2015 Google, Inc 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #ifndef __video_console_h 8 #define __video_console_h 9 10 #define VID_FRAC_DIV 256 11 12 #define VID_TO_PIXEL(x) ((x) / VID_FRAC_DIV) 13 #define VID_TO_POS(x) ((x) * VID_FRAC_DIV) 14 15 /** 16 * struct vidconsole_priv - uclass-private data about a console device 17 * 18 * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe() 19 * method. Drivers may set up @xstart_frac if desired. 20 * 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 */ 32 struct vidconsole_priv { 33 struct stdio_dev sdev; 34 int xcur_frac; 35 int ycur; 36 int rows; 37 int cols; 38 int x_charsize; 39 int y_charsize; 40 int tab_width_frac; 41 int xsize_frac; 42 int xstart_frac; 43 }; 44 45 /** 46 * struct vidconsole_ops - Video console operations 47 * 48 * These operations work on either an absolute console position (measured 49 * in pixels) or a text row number (measured in rows, where each row consists 50 * of an entire line of text - typically 16 pixels). 51 */ 52 struct vidconsole_ops { 53 /** 54 * putc_xy() - write a single character to a position 55 * 56 * @dev: Device to write to 57 * @x_frac: Fractional pixel X position (0=left-most pixel) which 58 * is the X position multipled by VID_FRAC_DIV. 59 * @y: Pixel Y position (0=top-most pixel) 60 * @ch: Character to write 61 * @return number of fractional pixels that the cursor should move, 62 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve 63 * on error 64 */ 65 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch); 66 67 /** 68 * move_rows() - Move text rows from one place to another 69 * 70 * @dev: Device to adjust 71 * @rowdst: Destination text row (0=top) 72 * @rowsrc: Source start text row 73 * @count: Number of text rows to move 74 * @return 0 if OK, -ve on error 75 */ 76 int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc, 77 uint count); 78 79 /** 80 * set_row() - Set the colour of a text row 81 * 82 * Every pixel contained within the text row is adjusted 83 * 84 * @dev: Device to adjust 85 * @row: Text row to adjust (0=top) 86 * @clr: Raw colour (pixel value) to write to each pixel 87 * @return 0 if OK, -ve on error 88 */ 89 int (*set_row)(struct udevice *dev, uint row, int clr); 90 }; 91 92 /* Get a pointer to the driver operations for a video console device */ 93 #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops) 94 95 /** 96 * vidconsole_putc_xy() - write a single character to a position 97 * 98 * @dev: Device to write to 99 * @x_frac: Fractional pixel X position (0=left-most pixel) which 100 * is the X position multipled by VID_FRAC_DIV. 101 * @y: Pixel Y position (0=top-most pixel) 102 * @ch: Character to write 103 * @return number of fractional pixels that the cursor should move, 104 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve 105 * on error 106 */ 107 int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch); 108 109 /** 110 * vidconsole_move_rows() - Move text rows from one place to another 111 * 112 * @dev: Device to adjust 113 * @rowdst: Destination text row (0=top) 114 * @rowsrc: Source start text row 115 * @count: Number of text rows to move 116 * @return 0 if OK, -ve on error 117 */ 118 int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc, 119 uint count); 120 121 /** 122 * vidconsole_set_row() - Set the colour of a text row 123 * 124 * Every pixel contained within the text row is adjusted 125 * 126 * @dev: Device to adjust 127 * @row: Text row to adjust (0=top) 128 * @clr: Raw colour (pixel value) to write to each pixel 129 * @return 0 if OK, -ve on error 130 */ 131 int vidconsole_set_row(struct udevice *dev, uint row, int clr); 132 133 /** 134 * vidconsole_put_char() - Output a character to the current console position 135 * 136 * Outputs a character to the console and advances the cursor. This function 137 * handles wrapping to new lines and scrolling the console. Special 138 * characters are handled also: \n, \r, \b and \t. 139 * 140 * The device always starts with the cursor at position 0,0 (top left). It 141 * can be adjusted manually using vidconsole_position_cursor(). 142 * 143 * @dev: Device to adjust 144 * @ch: Character to write 145 * @return 0 if OK, -ve on error 146 */ 147 int vidconsole_put_char(struct udevice *dev, char ch); 148 149 /** 150 * vidconsole_position_cursor() - Move the text cursor 151 * 152 * @dev: Device to adjust 153 * @col: New cursor text column 154 * @row: New cursor text row 155 * @return 0 if OK, -ve on error 156 */ 157 void vidconsole_position_cursor(struct udevice *dev, unsigned col, 158 unsigned row); 159 160 #endif 161