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 | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame^] | 19 | void *line; |
| 20 | int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize; |
| 21 | int i; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 22 | |
| 23 | line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length; |
| 24 | switch (vid_priv->bpix) { |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame^] | 25 | case VIDEO_BPP8: |
| 26 | if (IS_ENABLED(CONFIG_VIDEO_BPP8)) { |
| 27 | uint8_t *dst = line; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 28 | |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame^] | 29 | for (i = 0; i < pixels; i++) |
| 30 | *dst++ = clr; |
| 31 | break; |
| 32 | } |
| 33 | case VIDEO_BPP16: |
| 34 | if (IS_ENABLED(CONFIG_VIDEO_BPP16)) { |
| 35 | uint16_t *dst = line; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 36 | |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame^] | 37 | for (i = 0; i < pixels; i++) |
| 38 | *dst++ = clr; |
| 39 | break; |
| 40 | } |
| 41 | case VIDEO_BPP32: |
| 42 | if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { |
| 43 | uint32_t *dst = line; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 44 | |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame^] | 45 | for (i = 0; i < pixels; i++) |
| 46 | *dst++ = clr; |
| 47 | break; |
| 48 | } |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 49 | default: |
| 50 | return -ENOSYS; |
| 51 | } |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static int console_normal_move_rows(struct udevice *dev, uint rowdst, |
| 57 | uint rowsrc, uint count) |
| 58 | { |
| 59 | struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); |
| 60 | void *dst; |
| 61 | void *src; |
| 62 | |
| 63 | dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length; |
| 64 | src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length; |
| 65 | memmove(dst, src, VIDEO_FONT_HEIGHT * vid_priv->line_length * count); |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 70 | static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y, |
| 71 | char ch) |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 72 | { |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 73 | struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 74 | struct udevice *vid = dev->parent; |
| 75 | struct video_priv *vid_priv = dev_get_uclass_priv(vid); |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame^] | 76 | int i, row; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 77 | void *line = vid_priv->fb + y * vid_priv->line_length + |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 78 | VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix); |
| 79 | |
| 80 | if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) |
| 81 | return -EAGAIN; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 82 | |
| 83 | for (row = 0; row < VIDEO_FONT_HEIGHT; row++) { |
Andre Przywara | 96c9bf7 | 2019-03-23 01:29:55 +0000 | [diff] [blame] | 84 | unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row; |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame^] | 85 | uchar bits = video_fontdata[idx]; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 86 | |
| 87 | switch (vid_priv->bpix) { |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame^] | 88 | case VIDEO_BPP8: |
| 89 | if (IS_ENABLED(CONFIG_VIDEO_BPP8)) { |
| 90 | uint8_t *dst = line; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 91 | |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame^] | 92 | for (i = 0; i < VIDEO_FONT_WIDTH; i++) { |
| 93 | *dst++ = (bits & 0x80) ? |
| 94 | vid_priv->colour_fg : |
| 95 | vid_priv->colour_bg; |
| 96 | bits <<= 1; |
| 97 | } |
| 98 | break; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 99 | } |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame^] | 100 | case VIDEO_BPP16: |
| 101 | if (IS_ENABLED(CONFIG_VIDEO_BPP16)) { |
| 102 | uint16_t *dst = line; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 103 | |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame^] | 104 | for (i = 0; i < VIDEO_FONT_WIDTH; i++) { |
| 105 | *dst++ = (bits & 0x80) ? |
| 106 | vid_priv->colour_fg : |
| 107 | vid_priv->colour_bg; |
| 108 | bits <<= 1; |
| 109 | } |
| 110 | break; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 111 | } |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame^] | 112 | case VIDEO_BPP32: |
| 113 | if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { |
| 114 | uint32_t *dst = line; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 115 | |
Simon Glass | 4642119 | 2019-12-20 18:10:34 -0700 | [diff] [blame^] | 116 | for (i = 0; i < VIDEO_FONT_WIDTH; i++) { |
| 117 | *dst++ = (bits & 0x80) ? |
| 118 | vid_priv->colour_fg : |
| 119 | vid_priv->colour_bg; |
| 120 | bits <<= 1; |
| 121 | } |
| 122 | break; |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 123 | } |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 124 | default: |
| 125 | return -ENOSYS; |
| 126 | } |
| 127 | line += vid_priv->line_length; |
| 128 | } |
| 129 | |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 130 | return VID_TO_POS(VIDEO_FONT_WIDTH); |
| 131 | } |
| 132 | |
| 133 | static int console_normal_probe(struct udevice *dev) |
| 134 | { |
| 135 | struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); |
| 136 | struct udevice *vid_dev = dev->parent; |
| 137 | struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev); |
| 138 | |
| 139 | vc_priv->x_charsize = VIDEO_FONT_WIDTH; |
| 140 | vc_priv->y_charsize = VIDEO_FONT_HEIGHT; |
| 141 | vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH; |
| 142 | vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT; |
| 143 | |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | struct vidconsole_ops console_normal_ops = { |
| 148 | .putc_xy = console_normal_putc_xy, |
| 149 | .move_rows = console_normal_move_rows, |
| 150 | .set_row = console_normal_set_row, |
| 151 | }; |
| 152 | |
| 153 | U_BOOT_DRIVER(vidconsole_normal) = { |
| 154 | .name = "vidconsole0", |
| 155 | .id = UCLASS_VIDEO_CONSOLE, |
| 156 | .ops = &console_normal_ops, |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 157 | .probe = console_normal_probe, |
Simon Glass | 72cded9 | 2016-01-18 19:52:18 -0700 | [diff] [blame] | 158 | }; |