console_normal.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2015 Google, Inc
  4. * (C) Copyright 2001-2015
  5. * DENX Software Engineering -- wd@denx.de
  6. * Compulab Ltd - http://compulab.co.il/
  7. * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
  8. */
  9. #include <common.h>
  10. #include <dm.h>
  11. #include <video.h>
  12. #include <video_console.h>
  13. #include <video_font.h> /* Get font data, width and height */
  14. static int console_normal_set_row(struct udevice *dev, uint row, int clr)
  15. {
  16. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  17. void *line;
  18. int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
  19. int i;
  20. line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
  21. switch (vid_priv->bpix) {
  22. #ifdef CONFIG_VIDEO_BPP8
  23. case VIDEO_BPP8: {
  24. uint8_t *dst = line;
  25. for (i = 0; i < pixels; i++)
  26. *dst++ = clr;
  27. break;
  28. }
  29. #endif
  30. #ifdef CONFIG_VIDEO_BPP16
  31. case VIDEO_BPP16: {
  32. uint16_t *dst = line;
  33. for (i = 0; i < pixels; i++)
  34. *dst++ = clr;
  35. break;
  36. }
  37. #endif
  38. #ifdef CONFIG_VIDEO_BPP32
  39. case VIDEO_BPP32: {
  40. uint32_t *dst = line;
  41. for (i = 0; i < pixels; i++)
  42. *dst++ = clr;
  43. break;
  44. }
  45. #endif
  46. default:
  47. return -ENOSYS;
  48. }
  49. return 0;
  50. }
  51. static int console_normal_move_rows(struct udevice *dev, uint rowdst,
  52. uint rowsrc, uint count)
  53. {
  54. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  55. void *dst;
  56. void *src;
  57. dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length;
  58. src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length;
  59. memmove(dst, src, VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
  60. return 0;
  61. }
  62. static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
  63. char ch)
  64. {
  65. struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
  66. struct udevice *vid = dev->parent;
  67. struct video_priv *vid_priv = dev_get_uclass_priv(vid);
  68. int i, row;
  69. void *line = vid_priv->fb + y * vid_priv->line_length +
  70. VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix);
  71. if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
  72. return -EAGAIN;
  73. for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
  74. uchar bits = video_fontdata[ch * VIDEO_FONT_HEIGHT + row];
  75. switch (vid_priv->bpix) {
  76. #ifdef CONFIG_VIDEO_BPP8
  77. case VIDEO_BPP8: {
  78. uint8_t *dst = line;
  79. for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
  80. *dst++ = (bits & 0x80) ? vid_priv->colour_fg
  81. : vid_priv->colour_bg;
  82. bits <<= 1;
  83. }
  84. break;
  85. }
  86. #endif
  87. #ifdef CONFIG_VIDEO_BPP16
  88. case VIDEO_BPP16: {
  89. uint16_t *dst = line;
  90. for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
  91. *dst++ = (bits & 0x80) ? vid_priv->colour_fg
  92. : vid_priv->colour_bg;
  93. bits <<= 1;
  94. }
  95. break;
  96. }
  97. #endif
  98. #ifdef CONFIG_VIDEO_BPP32
  99. case VIDEO_BPP32: {
  100. uint32_t *dst = line;
  101. for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
  102. *dst++ = (bits & 0x80) ? vid_priv->colour_fg
  103. : vid_priv->colour_bg;
  104. bits <<= 1;
  105. }
  106. break;
  107. }
  108. #endif
  109. default:
  110. return -ENOSYS;
  111. }
  112. line += vid_priv->line_length;
  113. }
  114. return VID_TO_POS(VIDEO_FONT_WIDTH);
  115. }
  116. static int console_normal_probe(struct udevice *dev)
  117. {
  118. struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
  119. struct udevice *vid_dev = dev->parent;
  120. struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
  121. vc_priv->x_charsize = VIDEO_FONT_WIDTH;
  122. vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
  123. vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
  124. vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
  125. return 0;
  126. }
  127. struct vidconsole_ops console_normal_ops = {
  128. .putc_xy = console_normal_putc_xy,
  129. .move_rows = console_normal_move_rows,
  130. .set_row = console_normal_set_row,
  131. };
  132. U_BOOT_DRIVER(vidconsole_normal) = {
  133. .name = "vidconsole0",
  134. .id = UCLASS_VIDEO_CONSOLE,
  135. .ops = &console_normal_ops,
  136. .probe = console_normal_probe,
  137. };