1 // SPDX-License-Identifier: GPL-2.0+
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
10 #include <video_osd.h>
12 #include "sandbox_osd.h"
14 struct sandbox_osd_priv {
20 static const struct udevice_id sandbox_osd_ids[] = {
21 { .compatible = "sandbox,sandbox_osd" },
25 inline u16 make_memval(u8 chr, u8 color)
27 return chr * 0x100 + color;
30 int sandbox_osd_get_info(struct udevice *dev, struct video_osd_info *info)
32 struct sandbox_osd_priv *priv = dev_get_priv(dev);
34 info->width = priv->width;
35 info->height = priv->height;
36 info->major_version = 1;
37 info->minor_version = 0;
42 int sandbox_osd_set_mem(struct udevice *dev, uint col, uint row, u8 *buf,
43 size_t buflen, uint count)
45 struct sandbox_osd_priv *priv = dev_get_priv(dev);
47 u8 *mem = (u8 *)priv->buf;
50 pos = 2 * (row * priv->width + col);
52 if (pos >= 2 * (priv->width * priv->height))
55 for (i = 0; i < count; i++)
56 memcpy(mem + pos + (i * buflen), buf, buflen);
61 int _sandbox_osd_set_size(struct udevice *dev, uint col, uint row)
63 struct sandbox_osd_priv *priv = dev_get_priv(dev);
69 size = priv->width * priv->height;
71 priv->buf = calloc(size, sizeof(u16));
73 priv->buf = realloc(priv->buf, size * sizeof(u16));
78 /* Fill OSD with black spaces */
79 for (i = 0; i < size; i++)
80 priv->buf[i] = make_memval(' ', 'k');
85 int sandbox_osd_set_size(struct udevice *dev, uint col, uint row)
87 return _sandbox_osd_set_size(dev, col, row);
90 int sandbox_osd_print(struct udevice *dev, uint col, uint row, ulong color,
93 struct sandbox_osd_priv *priv = dev_get_priv(dev);
98 if (col >= priv->width || row >= priv->height)
122 pos = row * priv->width + col;
125 priv->buf[pos++] = make_memval(*(p++), cval);
130 int sandbox_osd_get_mem(struct udevice *dev, u8 *buf, size_t buflen)
132 struct sandbox_osd_priv *priv = dev_get_priv(dev);
133 uint memsize = 2 * (priv->width * priv->height);
135 if (buflen < memsize)
138 memcpy(buf, priv->buf, memsize);
143 static const struct video_osd_ops sandbox_osd_ops = {
144 .get_info = sandbox_osd_get_info,
145 .set_mem = sandbox_osd_set_mem,
146 .set_size = sandbox_osd_set_size,
147 .print = sandbox_osd_print,
150 int sandbox_osd_probe(struct udevice *dev)
152 return _sandbox_osd_set_size(dev, 10, 10);
155 U_BOOT_DRIVER(sandbox_osd_drv) = {
156 .name = "sandbox_osd_drv",
157 .id = UCLASS_VIDEO_OSD,
158 .ops = &sandbox_osd_ops,
159 .of_match = sandbox_osd_ids,
160 .probe = sandbox_osd_probe,
161 .priv_auto = sizeof(struct sandbox_osd_priv),