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
15 #include <video_osd.h>
18 /* Container for selected OSD device */
19 static struct udevice *osd_cur;
22 * cmd_osd_set_osd_num() - Set the OSD selected for operation
24 * Set the OSD device, which will be used by all subsequent OSD commands.
26 * Devices are identified by their uclass sequence number (as listed by 'osd
29 * @osdnum: The OSD device to be selected, identified by its sequence number.
30 * Return: 0 if OK, -ve on error
32 static int cmd_osd_set_osd_num(unsigned int osdnum)
37 res = uclass_get_device_by_seq(UCLASS_VIDEO_OSD, osdnum, &osd);
39 printf("%s: No OSD %u (err = %d)\n", __func__, osdnum, res);
48 * osd_get_osd_cur() - Get the selected OSD device
50 * Get the OSD device that is used by all OSD commands.
52 * @osdp: Pointer to structure that will receive the currently selected OSD
54 * Return: 0 if OK, -ve on error
56 static int osd_get_osd_cur(struct udevice **osdp)
59 puts("No osd selected\n");
68 * show_osd() - Display information about a OSD device
70 * Display a device's ID (sequence number), and whether it is active (i.e.
73 * @osd: OSD device to print information for
75 static void show_osd(struct udevice *osd)
77 printf("OSD %d:\t%s", osd->req_seq, osd->name);
78 if (device_active(osd))
79 printf(" (active %d)", osd->seq);
83 static int do_osd_write(cmd_tbl_t *cmdtp, int flag, int argc,
93 if (argc < 4 || (strlen(argv[3]) % 2))
97 puts("No osd selected\n");
98 return CMD_RET_FAILURE;
101 x = simple_strtoul(argv[1], NULL, 16);
102 y = simple_strtoul(argv[2], NULL, 16);
104 count = (argc > 4) ? simple_strtoul(argv[4], NULL, 16) : 1;
106 buflen = strlen(hexstr) / 2;
108 buffer = malloc(buflen);
110 puts("Memory allocation failure\n");
111 return CMD_RET_FAILURE;
114 res = hex2bin(buffer, hexstr, buflen);
117 puts("Hexadecimal input contained invalid characters\n");
118 return CMD_RET_FAILURE;
121 res = video_osd_set_mem(osd_cur, x, y, buffer, buflen, count);
124 printf("%s: Could not write to video mem\n",
126 return CMD_RET_FAILURE;
131 return CMD_RET_SUCCESS;
134 static int do_osd_print(cmd_tbl_t *cmdtp, int flag, int argc,
143 return CMD_RET_USAGE;
146 puts("No osd selected\n");
147 return CMD_RET_FAILURE;
150 x = simple_strtoul(argv[1], NULL, 16);
151 y = simple_strtoul(argv[2], NULL, 16);
152 color = simple_strtoul(argv[3], NULL, 16);
155 res = video_osd_print(osd_cur, x, y, color, text);
157 printf("Could not print string to osd %s\n", osd_cur->name);
158 return CMD_RET_FAILURE;
161 return CMD_RET_SUCCESS;
164 static int do_osd_size(cmd_tbl_t *cmdtp, int flag, int argc,
171 return CMD_RET_USAGE;
174 puts("No osd selected\n");
175 return CMD_RET_FAILURE;
178 x = simple_strtoul(argv[1], NULL, 16);
179 y = simple_strtoul(argv[2], NULL, 16);
181 res = video_osd_set_size(osd_cur, x, y);
183 printf("Could not set size on osd %s\n", osd_cur->name);
184 return CMD_RET_FAILURE;
187 return CMD_RET_SUCCESS;
190 static int do_show_osd(cmd_tbl_t *cmdtp, int flag, int argc,
200 res = uclass_get(UCLASS_VIDEO_OSD, &uc);
202 printf("Error while getting OSD uclass (err=%d)\n",
204 return CMD_RET_FAILURE;
207 uclass_foreach_dev(osd, uc)
212 /* show specific OSD */
213 i = simple_strtoul(argv[1], NULL, 10);
215 res = uclass_get_device_by_seq(UCLASS_VIDEO_OSD, i, &osd);
217 printf("Invalid osd %d: err=%d\n", i, res);
218 return CMD_RET_FAILURE;
223 return CMD_RET_SUCCESS;
226 static int do_osd_num(cmd_tbl_t *cmdtp, int flag, int argc,
233 /* querying current setting */
236 if (!osd_get_osd_cur(&osd))
240 printf("Current osd is %d\n", osd_no);
242 osd_no = simple_strtoul(argv[1], NULL, 10);
243 printf("Setting osd to %d\n", osd_no);
245 res = cmd_osd_set_osd_num(osd_no);
247 printf("Failure changing osd number (err = %d)\n", res);
250 return res ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
253 static cmd_tbl_t cmd_osd_sub[] = {
254 U_BOOT_CMD_MKENT(show, 1, 1, do_show_osd, "", ""),
255 U_BOOT_CMD_MKENT(dev, 1, 1, do_osd_num, "", ""),
256 U_BOOT_CMD_MKENT(write, 4, 1, do_osd_write, "", ""),
257 U_BOOT_CMD_MKENT(print, 4, 1, do_osd_print, "", ""),
258 U_BOOT_CMD_MKENT(size, 2, 1, do_osd_size, "", ""),
261 static int do_osd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
266 return CMD_RET_USAGE;
268 /* Strip off leading 'osd' command argument */
272 c = find_cmd_tbl(argv[0], &cmd_osd_sub[0], ARRAY_SIZE(cmd_osd_sub));
275 return c->cmd(cmdtp, flag, argc, argv);
277 return CMD_RET_USAGE;
280 static char osd_help_text[] =
281 "show - show OSD info\n"
282 "osd dev [dev] - show or set current OSD\n"
283 "write [pos_x] [pos_y] [buffer] [count] - write 8-bit hex encoded buffer to osd memory at a given position\n"
284 "print [pos_x] [pos_y] [color] [text] - write ASCII buffer (given by text data and driver-specific color information) to osd memory\n"
285 "size [size_x] [size_y] - set OSD XY size in characters\n";