osd_cmd.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // 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. #include <common.h>
  12. #include <dm.h>
  13. #include <hexdump.h>
  14. #include <video_osd.h>
  15. #include <malloc.h>
  16. static int do_osd_write(cmd_tbl_t *cmdtp, int flag, int argc,
  17. char * const argv[])
  18. {
  19. struct udevice *dev;
  20. uint x, y;
  21. uint count;
  22. char *hexstr;
  23. u8 *buffer;
  24. size_t buflen;
  25. int res;
  26. if (argc < 4 || (strlen(argv[3])) % 2)
  27. return CMD_RET_USAGE;
  28. x = simple_strtoul(argv[1], NULL, 16);
  29. y = simple_strtoul(argv[2], NULL, 16);
  30. hexstr = argv[3];
  31. count = (argc > 4) ? simple_strtoul(argv[4], NULL, 16) : 1;
  32. buflen = strlen(hexstr) / 2;
  33. buffer = malloc(buflen);
  34. if (!buffer) {
  35. puts("Memory allocation failure\n");
  36. return CMD_RET_FAILURE;
  37. }
  38. res = hex2bin(buffer, hexstr, buflen);
  39. if (res) {
  40. free(buffer);
  41. puts("Hexadecimal input contained invalid characters\n");
  42. return CMD_RET_FAILURE;
  43. }
  44. for (uclass_first_device(UCLASS_VIDEO_OSD, &dev);
  45. dev;
  46. uclass_next_device(&dev)) {
  47. int res;
  48. res = video_osd_set_mem(dev, x, y, buffer, buflen, count);
  49. if (res) {
  50. free(buffer);
  51. printf("Could not write to video mem on osd %s\n",
  52. dev->name);
  53. return CMD_RET_FAILURE;
  54. }
  55. }
  56. free(buffer);
  57. return CMD_RET_SUCCESS;
  58. }
  59. static int do_osd_print(cmd_tbl_t *cmdtp, int flag, int argc,
  60. char * const argv[])
  61. {
  62. struct udevice *dev;
  63. uint x, y;
  64. u8 color;
  65. char *text;
  66. if (argc < 5)
  67. return CMD_RET_USAGE;
  68. x = simple_strtoul(argv[1], NULL, 16);
  69. y = simple_strtoul(argv[2], NULL, 16);
  70. color = simple_strtoul(argv[3], NULL, 16);
  71. text = argv[4];
  72. for (uclass_first_device(UCLASS_VIDEO_OSD, &dev);
  73. dev;
  74. uclass_next_device(&dev)) {
  75. int res;
  76. res = video_osd_print(dev, x, y, color, text);
  77. if (res) {
  78. printf("Could not print string to osd %s\n", dev->name);
  79. return CMD_RET_FAILURE;
  80. }
  81. }
  82. return CMD_RET_SUCCESS;
  83. }
  84. static int do_osd_size(cmd_tbl_t *cmdtp, int flag, int argc,
  85. char * const argv[])
  86. {
  87. struct udevice *dev;
  88. uint x, y;
  89. if (argc < 3)
  90. return CMD_RET_USAGE;
  91. x = simple_strtoul(argv[1], NULL, 16);
  92. y = simple_strtoul(argv[2], NULL, 16);
  93. for (uclass_first_device(UCLASS_VIDEO_OSD, &dev);
  94. dev;
  95. uclass_next_device(&dev)) {
  96. int res;
  97. res = video_osd_set_size(dev, x, y);
  98. if (res) {
  99. printf("Could not set size on osd %s\n", dev->name);
  100. return CMD_RET_FAILURE;
  101. }
  102. }
  103. return CMD_RET_SUCCESS;
  104. }
  105. U_BOOT_CMD(
  106. osdw, 5, 0, do_osd_write,
  107. "write 16-bit hex encoded buffer to osd memory",
  108. "osdw [pos_x] [pos_y] [buffer] [count] - write 8-bit hex encoded buffer to osd memory\n"
  109. );
  110. U_BOOT_CMD(
  111. osdp, 5, 0, do_osd_print,
  112. "write ASCII buffer to osd memory",
  113. "osdp [pos_x] [pos_y] [color] [text] - write ASCII buffer to osd memory\n"
  114. );
  115. U_BOOT_CMD(
  116. osdsize, 3, 0, do_osd_size,
  117. "set OSD XY size in characters",
  118. "osdsize [size_x] [size_y] - set OSD XY size in characters\n"
  119. );