console_normal.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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, *end;
  18. int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
  19. int ret;
  20. int i;
  21. line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
  22. switch (vid_priv->bpix) {
  23. case VIDEO_BPP8:
  24. if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
  25. uint8_t *dst = line;
  26. for (i = 0; i < pixels; i++)
  27. *dst++ = clr;
  28. end = dst;
  29. break;
  30. }
  31. case VIDEO_BPP16:
  32. if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
  33. uint16_t *dst = line;
  34. for (i = 0; i < pixels; i++)
  35. *dst++ = clr;
  36. end = dst;
  37. break;
  38. }
  39. case VIDEO_BPP32:
  40. if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
  41. uint32_t *dst = line;
  42. for (i = 0; i < pixels; i++)
  43. *dst++ = clr;
  44. end = dst;
  45. break;
  46. }
  47. default:
  48. return -ENOSYS;
  49. }
  50. ret = vidconsole_sync_copy(dev, line, end);
  51. if (ret)
  52. return ret;
  53. return 0;
  54. }
  55. static int console_normal_move_rows(struct udevice *dev, uint rowdst,
  56. uint rowsrc, uint count)
  57. {
  58. struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
  59. void *dst;
  60. void *src;
  61. int size;
  62. int ret;
  63. dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length;
  64. src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length;
  65. size = VIDEO_FONT_HEIGHT * vid_priv->line_length * count;
  66. ret = vidconsole_memmove(dev, dst, src, size);
  67. if (ret)
  68. return ret;
  69. return 0;
  70. }
  71. static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
  72. char ch)
  73. {
  74. struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
  75. struct udevice *vid = dev->parent;
  76. struct video_priv *vid_priv = dev_get_uclass_priv(vid);
  77. int i, row;
  78. void *start;
  79. void *line;
  80. int ret;
  81. start = vid_priv->fb + y * vid_priv->line_length +
  82. VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix);
  83. line = start;
  84. if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
  85. return -EAGAIN;
  86. for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
  87. unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row;
  88. uchar bits = video_fontdata[idx];
  89. switch (vid_priv->bpix) {
  90. case VIDEO_BPP8:
  91. if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
  92. uint8_t *dst = line;
  93. for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
  94. *dst++ = (bits & 0x80) ?
  95. vid_priv->colour_fg :
  96. vid_priv->colour_bg;
  97. bits <<= 1;
  98. }
  99. break;
  100. }
  101. case VIDEO_BPP16:
  102. if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
  103. uint16_t *dst = line;
  104. for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
  105. *dst++ = (bits & 0x80) ?
  106. vid_priv->colour_fg :
  107. vid_priv->colour_bg;
  108. bits <<= 1;
  109. }
  110. break;
  111. }
  112. case VIDEO_BPP32:
  113. if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
  114. uint32_t *dst = line;
  115. for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
  116. *dst++ = (bits & 0x80) ?
  117. vid_priv->colour_fg :
  118. vid_priv->colour_bg;
  119. bits <<= 1;
  120. }
  121. break;
  122. }
  123. default:
  124. return -ENOSYS;
  125. }
  126. line += vid_priv->line_length;
  127. }
  128. ret = vidconsole_sync_copy(dev, start, line);
  129. if (ret)
  130. return ret;
  131. return VID_TO_POS(VIDEO_FONT_WIDTH);
  132. }
  133. static int console_normal_probe(struct udevice *dev)
  134. {
  135. struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
  136. struct udevice *vid_dev = dev->parent;
  137. struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
  138. vc_priv->x_charsize = VIDEO_FONT_WIDTH;
  139. vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
  140. vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
  141. vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
  142. return 0;
  143. }
  144. struct vidconsole_ops console_normal_ops = {
  145. .putc_xy = console_normal_putc_xy,
  146. .move_rows = console_normal_move_rows,
  147. .set_row = console_normal_set_row,
  148. };
  149. U_BOOT_DRIVER(vidconsole_normal) = {
  150. .name = "vidconsole0",
  151. .id = UCLASS_VIDEO_CONSOLE,
  152. .ops = &console_normal_ops,
  153. .probe = console_normal_probe,
  154. };