osd_cmd.c 3.0 KB

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