1 // SPDX-License-Identifier: GPL-2.0+
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
6 * based on the gdsys osd driver, which is
9 * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
16 #include <video_osd.h>
19 /* Container for selected OSD device */
20 static struct udevice *osd_cur;
23 * cmd_osd_set_osd_num() - Set the OSD selected for operation
25 * Set the OSD device, which will be used by all subsequent OSD commands.
27 * Devices are identified by their uclass sequence number (as listed by 'osd
30 * @osdnum: The OSD device to be selected, identified by its sequence number.
31 * Return: 0 if OK, -ve on error
33 static int cmd_osd_set_osd_num(unsigned int osdnum)
38 res = uclass_get_device_by_seq(UCLASS_VIDEO_OSD, osdnum, &osd);
40 printf("%s: No OSD %u (err = %d)\n", __func__, osdnum, res);
49 * osd_get_osd_cur() - Get the selected OSD device
51 * Get the OSD device that is used by all OSD commands.
53 * @osdp: Pointer to structure that will receive the currently selected OSD
55 * Return: 0 if OK, -ve on error
57 static int osd_get_osd_cur(struct udevice **osdp)
60 puts("No osd selected\n");
69 * show_osd() - Display information about a OSD device
71 * Display a device's ID (sequence number), and whether it is active (i.e.
74 * @osd: OSD device to print information for
76 static void show_osd(struct udevice *osd)
78 printf("OSD %d:\t%s", dev_seq(osd), osd->name);
79 if (device_active(osd))
84 static int do_osd_write(struct cmd_tbl *cmdtp, int flag, int argc,
94 if (argc < 4 || (strlen(argv[3]) % 2))
98 puts("No osd selected\n");
99 return CMD_RET_FAILURE;
102 x = hextoul(argv[1], NULL);
103 y = hextoul(argv[2], NULL);
105 count = (argc > 4) ? hextoul(argv[4], NULL) : 1;
107 buflen = strlen(hexstr) / 2;
109 buffer = malloc(buflen);
111 puts("Memory allocation failure\n");
112 return CMD_RET_FAILURE;
115 res = hex2bin(buffer, hexstr, buflen);
118 puts("Hexadecimal input contained invalid characters\n");
119 return CMD_RET_FAILURE;
122 res = video_osd_set_mem(osd_cur, x, y, buffer, buflen, count);
125 printf("%s: Could not write to video mem\n",
127 return CMD_RET_FAILURE;
132 return CMD_RET_SUCCESS;
135 static int do_osd_print(struct cmd_tbl *cmdtp, int flag, int argc,
144 return CMD_RET_USAGE;
147 puts("No osd selected\n");
148 return CMD_RET_FAILURE;
151 x = hextoul(argv[1], NULL);
152 y = hextoul(argv[2], NULL);
153 color = hextoul(argv[3], NULL);
156 res = video_osd_print(osd_cur, x, y, color, text);
158 printf("Could not print string to osd %s\n", osd_cur->name);
159 return CMD_RET_FAILURE;
162 return CMD_RET_SUCCESS;
165 static int do_osd_size(struct cmd_tbl *cmdtp, int flag, int argc,
172 return CMD_RET_USAGE;
175 puts("No osd selected\n");
176 return CMD_RET_FAILURE;
179 x = hextoul(argv[1], NULL);
180 y = hextoul(argv[2], NULL);
182 res = video_osd_set_size(osd_cur, x, y);
184 printf("Could not set size on osd %s\n", osd_cur->name);
185 return CMD_RET_FAILURE;
188 return CMD_RET_SUCCESS;
191 static int do_show_osd(struct cmd_tbl *cmdtp, int flag, int argc,
201 res = uclass_get(UCLASS_VIDEO_OSD, &uc);
203 printf("Error while getting OSD uclass (err=%d)\n",
205 return CMD_RET_FAILURE;
208 uclass_foreach_dev(osd, uc)
213 /* show specific OSD */
214 i = dectoul(argv[1], NULL);
216 res = uclass_get_device_by_seq(UCLASS_VIDEO_OSD, i, &osd);
218 printf("Invalid osd %d: err=%d\n", i, res);
219 return CMD_RET_FAILURE;
224 return CMD_RET_SUCCESS;
227 static int do_osd_num(struct cmd_tbl *cmdtp, int flag, int argc,
234 /* querying current setting */
237 if (!osd_get_osd_cur(&osd))
238 osd_no = dev_seq(osd);
241 printf("Current osd is %d\n", osd_no);
243 osd_no = dectoul(argv[1], NULL);
244 printf("Setting osd to %d\n", osd_no);
246 res = cmd_osd_set_osd_num(osd_no);
248 printf("Failure changing osd number (err = %d)\n", res);
251 return res ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
254 static struct cmd_tbl cmd_osd_sub[] = {
255 U_BOOT_CMD_MKENT(show, 1, 1, do_show_osd, "", ""),
256 U_BOOT_CMD_MKENT(dev, 1, 1, do_osd_num, "", ""),
257 U_BOOT_CMD_MKENT(write, 4, 1, do_osd_write, "", ""),
258 U_BOOT_CMD_MKENT(print, 4, 1, do_osd_print, "", ""),
259 U_BOOT_CMD_MKENT(size, 2, 1, do_osd_size, "", ""),
262 static int do_osd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
267 return CMD_RET_USAGE;
269 /* Strip off leading 'osd' command argument */
273 c = find_cmd_tbl(argv[0], &cmd_osd_sub[0], ARRAY_SIZE(cmd_osd_sub));
276 return c->cmd(cmdtp, flag, argc, argv);
278 return CMD_RET_USAGE;
281 static char osd_help_text[] =
282 "show - show OSD info\n"
283 "osd dev [dev] - show or set current OSD\n"
284 "write [pos_x] [pos_y] [buffer] [count] - write 8-bit hex encoded buffer to osd memory at a given position\n"
285 "print [pos_x] [pos_y] [color] [text] - write ASCII buffer (given by text data and driver-specific color information) to osd memory\n"
286 "size [size_x] [size_y] - set OSD XY size in characters\n";