Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 4 | * (C) Copyright 2015 |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 5 | * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 6 | * (C) Copyright 2023 Dzmitry Sankouski <dsankouski@gmail.com> |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <dm.h> |
| 11 | #include <video.h> |
| 12 | #include <video_console.h> |
| 13 | #include <video_font.h> /* Get font data, width and height */ |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 14 | #include "vidconsole_internal.h" |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 15 | |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 16 | static int console_set_row(struct udevice *dev, uint row, int clr) |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 17 | { |
| 18 | struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); |
Dzmitry Sankouski | 7fa964a | 2023-03-07 13:21:14 +0300 | [diff] [blame] | 19 | struct console_simple_priv *priv = dev_get_priv(dev); |
| 20 | struct video_fontdata *fontdata = priv->fontdata; |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 21 | void *line, *dst, *end; |
Dzmitry Sankouski | 7fa964a | 2023-03-07 13:21:14 +0300 | [diff] [blame] | 22 | int pixels = fontdata->height * vid_priv->xsize; |
Simon Glass | 03a96ae | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 23 | int ret; |
Simon Glass | 6c1ca6b | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 24 | int i; |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 25 | int pbytes; |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 26 | |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 27 | ret = check_bpix_support(vid_priv->bpix); |
| 28 | if (ret) |
| 29 | return ret; |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 30 | |
Dzmitry Sankouski | 7fa964a | 2023-03-07 13:21:14 +0300 | [diff] [blame] | 31 | line = vid_priv->fb + row * fontdata->height * vid_priv->line_length; |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 32 | dst = line; |
| 33 | pbytes = VNBYTES(vid_priv->bpix); |
| 34 | for (i = 0; i < pixels; i++) |
| 35 | fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes); |
| 36 | end = dst; |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 37 | |
Simon Glass | 03a96ae | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 38 | ret = vidconsole_sync_copy(dev, line, end); |
| 39 | if (ret) |
| 40 | return ret; |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 45 | static int console_move_rows(struct udevice *dev, uint rowdst, |
| 46 | uint rowsrc, uint count) |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 47 | { |
| 48 | struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); |
Dzmitry Sankouski | 7fa964a | 2023-03-07 13:21:14 +0300 | [diff] [blame] | 49 | struct console_simple_priv *priv = dev_get_priv(dev); |
| 50 | struct video_fontdata *fontdata = priv->fontdata; |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 51 | void *dst; |
| 52 | void *src; |
Simon Glass | 03a96ae | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 53 | int size; |
| 54 | int ret; |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 55 | |
Dzmitry Sankouski | 7fa964a | 2023-03-07 13:21:14 +0300 | [diff] [blame] | 56 | dst = vid_priv->fb + rowdst * fontdata->height * vid_priv->line_length; |
| 57 | src = vid_priv->fb + rowsrc * fontdata->height * vid_priv->line_length; |
| 58 | size = fontdata->height * vid_priv->line_length * count; |
Simon Glass | 03a96ae | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 59 | ret = vidconsole_memmove(dev, dst, src, size); |
| 60 | if (ret) |
| 61 | return ret; |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 66 | static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch) |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 67 | { |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 68 | struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 69 | struct udevice *vid = dev->parent; |
| 70 | struct video_priv *vid_priv = dev_get_uclass_priv(vid); |
Dzmitry Sankouski | 7fa964a | 2023-03-07 13:21:14 +0300 | [diff] [blame] | 71 | struct console_simple_priv *priv = dev_get_priv(dev); |
| 72 | struct video_fontdata *fontdata = priv->fontdata; |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 73 | int pbytes = VNBYTES(vid_priv->bpix); |
| 74 | int x, linenum, ret; |
| 75 | void *start, *line; |
Dzmitry Sankouski | 7fa964a | 2023-03-07 13:21:14 +0300 | [diff] [blame] | 76 | uchar *pfont = fontdata->video_fontdata + |
| 77 | (u8)ch * fontdata->char_pixel_bytes; |
Simon Glass | 03a96ae | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 78 | |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 79 | if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) |
| 80 | return -EAGAIN; |
| 81 | linenum = y; |
| 82 | x = VID_TO_PIXEL(x_frac); |
| 83 | start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes; |
Simon Glass | 03a96ae | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 84 | line = start; |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 85 | |
| 86 | if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) |
| 87 | return -EAGAIN; |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 88 | |
Dzmitry Sankouski | 7fa964a | 2023-03-07 13:21:14 +0300 | [diff] [blame] | 89 | ret = fill_char_vertically(pfont, &line, vid_priv, fontdata, NORMAL_DIRECTION); |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 90 | if (ret) |
| 91 | return ret; |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 92 | |
Simon Glass | 03a96ae | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 93 | ret = vidconsole_sync_copy(dev, start, line); |
| 94 | if (ret) |
| 95 | return ret; |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 96 | |
Dzmitry Sankouski | 7fa964a | 2023-03-07 13:21:14 +0300 | [diff] [blame] | 97 | return VID_TO_POS(fontdata->width); |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 100 | struct vidconsole_ops console_ops = { |
| 101 | .putc_xy = console_putc_xy, |
| 102 | .move_rows = console_move_rows, |
| 103 | .set_row = console_set_row, |
Dzmitry Sankouski | bb165e4 | 2023-03-07 13:21:16 +0300 | [diff] [blame] | 104 | .get_font_size = console_simple_get_font_size, |
| 105 | .get_font = console_simple_get_font, |
| 106 | .select_font = console_simple_select_font, |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | U_BOOT_DRIVER(vidconsole_normal) = { |
Dzmitry Sankouski | 7fa964a | 2023-03-07 13:21:14 +0300 | [diff] [blame] | 110 | .name = "vidconsole0", |
| 111 | .id = UCLASS_VIDEO_CONSOLE, |
| 112 | .ops = &console_ops, |
| 113 | .probe = console_probe, |
| 114 | .priv_auto = sizeof(struct console_simple_priv), |
Simon Glass | 23825a9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 115 | }; |