Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
| 4 | * (C) Copyright 2001-2015 |
| 5 | * DENX Software Engineering -- wd@denx.de |
| 6 | * Compulab Ltd - http://compulab.co.il/ |
| 7 | * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <dm.h> |
| 12 | #include <video.h> |
| 13 | #include <video_console.h> |
| 14 | #include <video_font.h> /* Get font data, width and height */ |
| 15 | |
| 16 | static int console_normal_set_row(struct udevice *dev, uint row, int clr) |
| 17 | { |
| 18 | struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); |
Simon Glass | 68f3fc7 | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 19 | void *line, *end; |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 20 | int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize; |
Simon Glass | 68f3fc7 | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 21 | int ret; |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 22 | int i; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 23 | |
| 24 | line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length; |
| 25 | switch (vid_priv->bpix) { |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 26 | case VIDEO_BPP8: |
| 27 | if (IS_ENABLED(CONFIG_VIDEO_BPP8)) { |
| 28 | uint8_t *dst = line; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 29 | |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 30 | for (i = 0; i < pixels; i++) |
| 31 | *dst++ = clr; |
Simon Glass | 68f3fc7 | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 32 | end = dst; |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 33 | break; |
| 34 | } |
| 35 | case VIDEO_BPP16: |
| 36 | if (IS_ENABLED(CONFIG_VIDEO_BPP16)) { |
| 37 | uint16_t *dst = line; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 38 | |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 39 | for (i = 0; i < pixels; i++) |
| 40 | *dst++ = clr; |
Simon Glass | 68f3fc7 | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 41 | end = dst; |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 42 | break; |
| 43 | } |
| 44 | case VIDEO_BPP32: |
| 45 | if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { |
| 46 | uint32_t *dst = line; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 47 | |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 48 | for (i = 0; i < pixels; i++) |
| 49 | *dst++ = clr; |
Simon Glass | 68f3fc7 | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 50 | end = dst; |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 51 | break; |
| 52 | } |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 53 | default: |
| 54 | return -ENOSYS; |
| 55 | } |
Simon Glass | 68f3fc7 | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 56 | ret = vidconsole_sync_copy(dev, line, end); |
| 57 | if (ret) |
| 58 | return ret; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | static int console_normal_move_rows(struct udevice *dev, uint rowdst, |
| 64 | uint rowsrc, uint count) |
| 65 | { |
| 66 | struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); |
| 67 | void *dst; |
| 68 | void *src; |
Simon Glass | 68f3fc7 | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 69 | int size; |
| 70 | int ret; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 71 | |
| 72 | dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length; |
| 73 | src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length; |
Simon Glass | 68f3fc7 | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 74 | size = VIDEO_FONT_HEIGHT * vid_priv->line_length * count; |
| 75 | ret = vidconsole_memmove(dev, dst, src, size); |
| 76 | if (ret) |
| 77 | return ret; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 82 | static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y, |
| 83 | char ch) |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 84 | { |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 85 | struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 86 | struct udevice *vid = dev->parent; |
| 87 | struct video_priv *vid_priv = dev_get_uclass_priv(vid); |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 88 | int i, row; |
Simon Glass | 68f3fc7 | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 89 | void *start; |
| 90 | void *line; |
| 91 | int ret; |
| 92 | |
| 93 | start = vid_priv->fb + y * vid_priv->line_length + |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 94 | VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix); |
Simon Glass | 68f3fc7 | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 95 | line = start; |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 96 | |
| 97 | if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) |
| 98 | return -EAGAIN; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 99 | |
| 100 | for (row = 0; row < VIDEO_FONT_HEIGHT; row++) { |
Andre Przywara | 96c9bf7 | 2019-03-23 01:29:55 +0000 | [diff] [blame] | 101 | unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row; |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 102 | uchar bits = video_fontdata[idx]; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 103 | |
| 104 | switch (vid_priv->bpix) { |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 105 | case VIDEO_BPP8: |
| 106 | if (IS_ENABLED(CONFIG_VIDEO_BPP8)) { |
| 107 | uint8_t *dst = line; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 108 | |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 109 | for (i = 0; i < VIDEO_FONT_WIDTH; i++) { |
| 110 | *dst++ = (bits & 0x80) ? |
| 111 | vid_priv->colour_fg : |
| 112 | vid_priv->colour_bg; |
| 113 | bits <<= 1; |
| 114 | } |
| 115 | break; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 116 | } |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 117 | case VIDEO_BPP16: |
| 118 | if (IS_ENABLED(CONFIG_VIDEO_BPP16)) { |
| 119 | uint16_t *dst = line; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 120 | |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 121 | for (i = 0; i < VIDEO_FONT_WIDTH; i++) { |
| 122 | *dst++ = (bits & 0x80) ? |
| 123 | vid_priv->colour_fg : |
| 124 | vid_priv->colour_bg; |
| 125 | bits <<= 1; |
| 126 | } |
| 127 | break; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 128 | } |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 129 | case VIDEO_BPP32: |
| 130 | if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { |
| 131 | uint32_t *dst = line; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 132 | |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame] | 133 | for (i = 0; i < VIDEO_FONT_WIDTH; i++) { |
| 134 | *dst++ = (bits & 0x80) ? |
| 135 | vid_priv->colour_fg : |
| 136 | vid_priv->colour_bg; |
| 137 | bits <<= 1; |
| 138 | } |
| 139 | break; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 140 | } |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 141 | default: |
| 142 | return -ENOSYS; |
| 143 | } |
| 144 | line += vid_priv->line_length; |
| 145 | } |
Simon Glass | 68f3fc7 | 2020-07-02 21:12:24 -0600 | [diff] [blame] | 146 | ret = vidconsole_sync_copy(dev, start, line); |
| 147 | if (ret) |
| 148 | return ret; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 149 | |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 150 | return VID_TO_POS(VIDEO_FONT_WIDTH); |
| 151 | } |
| 152 | |
| 153 | static int console_normal_probe(struct udevice *dev) |
| 154 | { |
| 155 | struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); |
| 156 | struct udevice *vid_dev = dev->parent; |
| 157 | struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev); |
| 158 | |
| 159 | vc_priv->x_charsize = VIDEO_FONT_WIDTH; |
| 160 | vc_priv->y_charsize = VIDEO_FONT_HEIGHT; |
| 161 | vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH; |
| 162 | vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT; |
| 163 | |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | struct vidconsole_ops console_normal_ops = { |
| 168 | .putc_xy = console_normal_putc_xy, |
| 169 | .move_rows = console_normal_move_rows, |
| 170 | .set_row = console_normal_set_row, |
| 171 | }; |
| 172 | |
| 173 | U_BOOT_DRIVER(vidconsole_normal) = { |
| 174 | .name = "vidconsole0", |
| 175 | .id = UCLASS_VIDEO_CONSOLE, |
| 176 | .ops = &console_normal_ops, |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 177 | .probe = console_normal_probe, |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 178 | }; |