console_normal.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2015 Google, Inc
  4. * (C) Copyright 2015
  5. * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
  6. * (C) Copyright 2023 Dzmitry Sankouski <dsankouski@gmail.com>
  7. */
  8. #include <common.h>
  9. #include <dm.h>
  10. #include <video.h>
  11. #include <video_console.h>
  12. #include <video_font.h> /* Get font data, width and height */
  13. #include "vidconsole_internal.h"
  14. static int console_set_row(struct udevice *dev, uint row, int clr)
  15. {
  16. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  17. struct console_simple_priv *priv = dev_get_priv(dev);
  18. struct video_fontdata *fontdata = priv->fontdata;
  19. void *line, *dst, *end;
  20. int pixels = fontdata->height * vid_priv->xsize;
  21. int ret;
  22. int i;
  23. int pbytes;
  24. ret = check_bpix_support(vid_priv->bpix);
  25. if (ret)
  26. return ret;
  27. line = vid_priv->fb + row * fontdata->height * vid_priv->line_length;
  28. dst = line;
  29. pbytes = VNBYTES(vid_priv->bpix);
  30. for (i = 0; i < pixels; i++)
  31. fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
  32. end = dst;
  33. ret = vidconsole_sync_copy(dev, line, end);
  34. if (ret)
  35. return ret;
  36. return 0;
  37. }
  38. static int console_move_rows(struct udevice *dev, uint rowdst,
  39. uint rowsrc, uint count)
  40. {
  41. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  42. struct console_simple_priv *priv = dev_get_priv(dev);
  43. struct video_fontdata *fontdata = priv->fontdata;
  44. void *dst;
  45. void *src;
  46. int size;
  47. int ret;
  48. dst = vid_priv->fb + rowdst * fontdata->height * vid_priv->line_length;
  49. src = vid_priv->fb + rowsrc * fontdata->height * vid_priv->line_length;
  50. size = fontdata->height * vid_priv->line_length * count;
  51. ret = vidconsole_memmove(dev, dst, src, size);
  52. if (ret)
  53. return ret;
  54. return 0;
  55. }
  56. static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch)
  57. {
  58. struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
  59. struct udevice *vid = dev->parent;
  60. struct video_priv *vid_priv = dev_get_uclass_priv(vid);
  61. struct console_simple_priv *priv = dev_get_priv(dev);
  62. struct video_fontdata *fontdata = priv->fontdata;
  63. int pbytes = VNBYTES(vid_priv->bpix);
  64. int x, linenum, ret;
  65. void *start, *line;
  66. uchar *pfont = fontdata->video_fontdata +
  67. (u8)ch * fontdata->char_pixel_bytes;
  68. if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
  69. return -EAGAIN;
  70. linenum = y;
  71. x = VID_TO_PIXEL(x_frac);
  72. start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes;
  73. line = start;
  74. if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
  75. return -EAGAIN;
  76. ret = fill_char_vertically(pfont, &line, vid_priv, fontdata, NORMAL_DIRECTION);
  77. if (ret)
  78. return ret;
  79. ret = vidconsole_sync_copy(dev, start, line);
  80. if (ret)
  81. return ret;
  82. return VID_TO_POS(fontdata->width);
  83. }
  84. struct vidconsole_ops console_ops = {
  85. .putc_xy = console_putc_xy,
  86. .move_rows = console_move_rows,
  87. .set_row = console_set_row,
  88. .get_font_size = console_simple_get_font_size,
  89. .get_font = console_simple_get_font,
  90. .select_font = console_simple_select_font,
  91. };
  92. U_BOOT_DRIVER(vidconsole_normal) = {
  93. .name = "vidconsole0",
  94. .id = UCLASS_VIDEO_CONSOLE,
  95. .ops = &console_ops,
  96. .probe = console_probe,
  97. .priv_auto = sizeof(struct console_simple_priv),
  98. };