1 // SPDX-License-Identifier: GPL-2.0+
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
11 #include "sandbox_osd.h"
13 struct sandbox_osd_priv {
19 static const struct udevice_id sandbox_osd_ids[] = {
20 { .compatible = "sandbox,sandbox_osd" },
24 inline u16 make_memval(u8 chr, u8 color)
26 return chr * 0x100 + color;
29 int sandbox_osd_get_info(struct udevice *dev, struct video_osd_info *info)
31 struct sandbox_osd_priv *priv = dev_get_priv(dev);
33 info->width = priv->width;
34 info->height = priv->height;
35 info->major_version = 1;
36 info->minor_version = 0;
41 int sandbox_osd_set_mem(struct udevice *dev, uint col, uint row, u8 *buf,
42 size_t buflen, uint count)
44 struct sandbox_osd_priv *priv = dev_get_priv(dev);
46 u8 *mem = (u8 *)priv->buf;
49 pos = 2 * (row * priv->width + col);
51 if (pos >= 2 * (priv->width * priv->height))
54 for (i = 0; i < count; i++)
55 memcpy(mem + pos + (i * buflen), buf, buflen);
60 int _sandbox_osd_set_size(struct udevice *dev, uint col, uint row)
62 struct sandbox_osd_priv *priv = dev_get_priv(dev);
68 size = priv->width * priv->height;
70 priv->buf = calloc(size, sizeof(u16));
72 priv->buf = realloc(priv->buf, size * sizeof(u16));
77 /* Fill OSD with black spaces */
78 for (i = 0; i < size; i++)
79 priv->buf[i] = make_memval(' ', 'k');
84 int sandbox_osd_set_size(struct udevice *dev, uint col, uint row)
86 return _sandbox_osd_set_size(dev, col, row);
89 int sandbox_osd_print(struct udevice *dev, uint col, uint row, ulong color,
92 struct sandbox_osd_priv *priv = dev_get_priv(dev);
97 if (col >= priv->width || row >= priv->height)
121 pos = row * priv->width + col;
124 priv->buf[pos++] = make_memval(*(p++), cval);
129 int sandbox_osd_get_mem(struct udevice *dev, u8 *buf, size_t buflen)
131 struct sandbox_osd_priv *priv = dev_get_priv(dev);
132 uint memsize = 2 * (priv->width * priv->height);
134 if (buflen < memsize)
137 memcpy(buf, priv->buf, memsize);
142 static const struct video_osd_ops sandbox_osd_ops = {
143 .get_info = sandbox_osd_get_info,
144 .set_mem = sandbox_osd_set_mem,
145 .set_size = sandbox_osd_set_size,
146 .print = sandbox_osd_print,
149 int sandbox_osd_probe(struct udevice *dev)
151 return _sandbox_osd_set_size(dev, 10, 10);
154 U_BOOT_DRIVER(sandbox_osd_drv) = {
155 .name = "sandbox_osd_drv",
156 .id = UCLASS_VIDEO_OSD,
157 .ops = &sandbox_osd_ops,
158 .of_match = sandbox_osd_ids,
159 .probe = sandbox_osd_probe,
160 .priv_auto_alloc_size = sizeof(struct sandbox_osd_priv),