blob: 39e64f5f2eb343edf6aba3fab2fa88a137b419c3 [file] [log] [blame]
Mario Sixf8395902018-09-27 09:19:34 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2017
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
5 *
6 * based on the gdsys osd driver, which is
7 *
8 * (C) Copyright 2010
9 * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
10 */
11
Simon Glassed38aef2020-05-10 11:40:03 -060012#include <command.h>
Mario Sixf8395902018-09-27 09:19:34 +020013#include <dm.h>
14#include <hexdump.h>
15#include <video_osd.h>
16#include <malloc.h>
17
Simon Glassed38aef2020-05-10 11:40:03 -060018static int do_osd_write(struct cmd_tbl *cmdtp, int flag, int argc,
19 char *const argv[])
Mario Sixf8395902018-09-27 09:19:34 +020020{
21 struct udevice *dev;
22 uint x, y;
23 uint count;
24 char *hexstr;
25 u8 *buffer;
26 size_t buflen;
27 int res;
28
29 if (argc < 4 || (strlen(argv[3])) % 2)
30 return CMD_RET_USAGE;
31
Simon Glass3ff49ec2021-07-24 09:03:29 -060032 x = hextoul(argv[1], NULL);
33 y = hextoul(argv[2], NULL);
Mario Sixf8395902018-09-27 09:19:34 +020034 hexstr = argv[3];
Simon Glass3ff49ec2021-07-24 09:03:29 -060035 count = (argc > 4) ? hextoul(argv[4], NULL) : 1;
Mario Sixf8395902018-09-27 09:19:34 +020036
37 buflen = strlen(hexstr) / 2;
38
39 buffer = malloc(buflen);
40 if (!buffer) {
41 puts("Memory allocation failure\n");
42 return CMD_RET_FAILURE;
43 }
44
45 res = hex2bin(buffer, hexstr, buflen);
46 if (res) {
47 free(buffer);
48 puts("Hexadecimal input contained invalid characters\n");
49 return CMD_RET_FAILURE;
50 }
51
52 for (uclass_first_device(UCLASS_VIDEO_OSD, &dev);
53 dev;
54 uclass_next_device(&dev)) {
55 int res;
56
57 res = video_osd_set_mem(dev, x, y, buffer, buflen, count);
58 if (res) {
59 free(buffer);
60 printf("Could not write to video mem on osd %s\n",
61 dev->name);
62 return CMD_RET_FAILURE;
63 }
64 }
65
66 free(buffer);
67
68 return CMD_RET_SUCCESS;
69}
70
Simon Glassed38aef2020-05-10 11:40:03 -060071static int do_osd_print(struct cmd_tbl *cmdtp, int flag, int argc,
72 char *const argv[])
Mario Sixf8395902018-09-27 09:19:34 +020073{
74 struct udevice *dev;
75 uint x, y;
76 u8 color;
77 char *text;
78
79 if (argc < 5)
80 return CMD_RET_USAGE;
81
Simon Glass3ff49ec2021-07-24 09:03:29 -060082 x = hextoul(argv[1], NULL);
83 y = hextoul(argv[2], NULL);
84 color = hextoul(argv[3], NULL);
Mario Sixf8395902018-09-27 09:19:34 +020085 text = argv[4];
86
87 for (uclass_first_device(UCLASS_VIDEO_OSD, &dev);
88 dev;
89 uclass_next_device(&dev)) {
90 int res;
91
92 res = video_osd_print(dev, x, y, color, text);
93 if (res) {
94 printf("Could not print string to osd %s\n", dev->name);
95 return CMD_RET_FAILURE;
96 }
97 }
98
99 return CMD_RET_SUCCESS;
100}
101
Simon Glassed38aef2020-05-10 11:40:03 -0600102static int do_osd_size(struct cmd_tbl *cmdtp, int flag, int argc,
103 char *const argv[])
Mario Sixf8395902018-09-27 09:19:34 +0200104{
105 struct udevice *dev;
106 uint x, y;
107
108 if (argc < 3)
109 return CMD_RET_USAGE;
110
Simon Glass3ff49ec2021-07-24 09:03:29 -0600111 x = hextoul(argv[1], NULL);
112 y = hextoul(argv[2], NULL);
Mario Sixf8395902018-09-27 09:19:34 +0200113
114 for (uclass_first_device(UCLASS_VIDEO_OSD, &dev);
115 dev;
116 uclass_next_device(&dev)) {
117 int res;
118
119 res = video_osd_set_size(dev, x, y);
120
121 if (res) {
122 printf("Could not set size on osd %s\n", dev->name);
123 return CMD_RET_FAILURE;
124 }
125 }
126
127 return CMD_RET_SUCCESS;
128}
129
130U_BOOT_CMD(
131 osdw, 5, 0, do_osd_write,
132 "write 16-bit hex encoded buffer to osd memory",
133 "osdw [pos_x] [pos_y] [buffer] [count] - write 8-bit hex encoded buffer to osd memory\n"
134);
135
136U_BOOT_CMD(
137 osdp, 5, 0, do_osd_print,
138 "write ASCII buffer to osd memory",
139 "osdp [pos_x] [pos_y] [color] [text] - write ASCII buffer to osd memory\n"
140);
141
142U_BOOT_CMD(
143 osdsize, 3, 0, do_osd_size,
144 "set OSD XY size in characters",
145 "osdsize [size_x] [size_y] - set OSD XY size in characters\n"
146);