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