console_normal.c 3.8 KB

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