1/* SPDX-License-Identifier: GPL-2.0+ */ 2/* 3 * Copyright (c) 2015 Google, Inc 4 * (C) Copyright 2015 5 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com 6 * (C) Copyright 2023 Dzmitry Sankouski <dsankouski@gmail.com> 7 */ 8 9#include <charset.h> 10#include <config.h> 11 12#define FLIPPED_DIRECTION 1 13#define NORMAL_DIRECTION 0 14 15/** 16 * struct console_simple_priv - Private data for this driver 17 * 18 * @video_fontdata font graphical representation data 19 */ 20struct console_simple_priv { 21 struct video_fontdata *fontdata; 22}; 23 24/** 25 * Checks if bits per pixel supported. 26 * 27 * @param bpix framebuffer bits per pixel. 28 * 29 * @returns 0, if supported, or else -ENOSYS. 30 */ 31int check_bpix_support(int bpix); 32 33/** 34 * Fill 1 pixel in framebuffer, and go to next one. 35 * 36 * @param dstp a pointer to pointer to framebuffer. 37 * @param value value to write to framebuffer. 38 * @param pbytes framebuffer bytes per pixel. 39 * @param step framebuffer pointer increment. Usually is equal to pbytes, 40 * and may be negative to control filling direction. 41 */ 42void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes, int step); 43 44/** 45 * Fills 1 character in framebuffer vertically. Vertically means we're filling char font data rows 46 * across the lines. 47 * 48 * @param pfont a pointer to character font data. 49 * @param line a pointer to pointer to framebuffer. It's a point for upper left char corner 50 * @param vid_priv driver private data. 51 * @fontdata font graphical representation data 52 * @param direction controls character orientation. Can be normal or flipped. 53 * When normal: When flipped: 54 *|-----------------------------------------------| 55 *| line stepping | | 56 *| | | stepping -> | 57 *| * | | * * * | 58 *| * * v | * | 59 *| * | * | 60 *| * | * * ^ | 61 *| * * * | * | | 62 *| | | | 63 *| stepping -> | line stepping | 64 *|---!!we're starting from upper left char corner| 65 *|-----------------------------------------------| 66 * 67 * @returns 0, if success, or else error code. 68 */ 69int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vid_priv, 70 struct video_fontdata *fontdata, bool direction); 71 72/** 73 * Fills 1 character in framebuffer horizontally. 74 * Horizontally means we're filling char font data columns across the lines. 75 * 76 * @param pfont a pointer to character font data. 77 * @param line a pointer to pointer to framebuffer. It's a point for upper left char corner 78 * @param vid_priv driver private data. 79 * @fontdata font graphical representation data 80 * @param direction controls character orientation. Can be normal or flipped. 81 * When normal: When flipped: 82 *|-----------------------------------------------| 83 *| * | line stepping | 84 *| ^ * * * * * | | | 85 *| | * * | v * * | 86 *| | | * * * * * | 87 *| line stepping | * | 88 *| | | 89 *| stepping -> | <- stepping | 90 *|---!!we're starting from upper left char corner| 91 *|-----------------------------------------------| 92 * 93 * @returns 0, if success, or else error code. 94 */ 95int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *vid_priv, 96 struct video_fontdata *fontdata, bool direction); 97 98/** 99 * draw_cursor_vertically() - Draw a simple vertical cursor 100 * 101 * @line: pointer to framebuffer buffer: upper left cursor corner 102 * @vid_priv: driver private data 103 * @height: height of the cursor in pixels 104 * @param direction controls cursor orientation. Can be normal or flipped. 105 * When normal: When flipped: 106 *|-----------------------------------------------| 107 *| * | line stepping | 108 *| ^ * * * * * | | | 109 *| | * * | v * * | 110 *| | | * * * * * | 111 *| line stepping | * | 112 *| | | 113 *| stepping -> | <<- stepping | 114 *|---!!we're starting from upper left char corner| 115 *|-----------------------------------------------| 116 * 117 * Return: 0, if success, or else error code. 118 */ 119int draw_cursor_vertically(void **line, struct video_priv *vid_priv, 120 uint height, bool direction); 121 122/** 123 * console probe function. 124 * 125 * @param dev a pointer to device. 126 * 127 * @returns 0, if success, or else error code. 128 */ 129int console_probe(struct udevice *dev); 130 131/** 132 * Internal function to be used in as ops. 133 * See details in video_console.h get_font_size function 134 **/ 135const char *console_simple_get_font_size(struct udevice *dev, uint *sizep); 136 137/** 138 * Internal function to be used in as ops. 139 * See details in video_console.h get_font function 140 **/ 141int console_simple_get_font(struct udevice *dev, int seq, struct vidfont_info *info); 142 143/** 144 * Internal function to be used in as ops. 145 * See details in video_console.h select_font function 146 **/ 147int console_simple_select_font(struct udevice *dev, const char *name, uint size); 148 149/** 150 * Internal function to convert Unicode code points to code page 437. 151 * Used by video consoles using bitmap fonts. 152 * 153 * @param codepoint Unicode code point 154 * @returns code page 437 character. 155 */ 156static inline u8 console_utf_to_cp437(int codepoint) 157{ 158 if (CONFIG_IS_ENABLED(CHARSET)) { 159 utf_to_cp(&codepoint, codepage_437); 160 return codepoint; 161 } 162 return codepoint; 163} 164