sti_plane.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) STMicroelectronics SA 2014
  4. * Authors: Benjamin Gaignard <[email protected]>
  5. * Fabien Dessenne <[email protected]>
  6. * for STMicroelectronics.
  7. */
  8. #include <linux/types.h>
  9. #include <drm/drm_blend.h>
  10. #include <drm/drm_fourcc.h>
  11. #include <drm/drm_framebuffer.h>
  12. #include <drm/drm_gem_dma_helper.h>
  13. #include "sti_compositor.h"
  14. #include "sti_drv.h"
  15. #include "sti_plane.h"
  16. const char *sti_plane_to_str(struct sti_plane *plane)
  17. {
  18. switch (plane->desc) {
  19. case STI_GDP_0:
  20. return "GDP0";
  21. case STI_GDP_1:
  22. return "GDP1";
  23. case STI_GDP_2:
  24. return "GDP2";
  25. case STI_GDP_3:
  26. return "GDP3";
  27. case STI_HQVDP_0:
  28. return "HQVDP0";
  29. case STI_CURSOR:
  30. return "CURSOR";
  31. default:
  32. return "<UNKNOWN PLANE>";
  33. }
  34. }
  35. #define STI_FPS_INTERVAL_MS 3000
  36. void sti_plane_update_fps(struct sti_plane *plane,
  37. bool new_frame,
  38. bool new_field)
  39. {
  40. struct drm_plane_state *state = plane->drm_plane.state;
  41. ktime_t now;
  42. struct sti_fps_info *fps;
  43. int fpks, fipks, ms_since_last, num_frames, num_fields;
  44. now = ktime_get();
  45. /* Compute number of frame updates */
  46. fps = &plane->fps_info;
  47. if (new_field)
  48. fps->curr_field_counter++;
  49. /* do not perform fps calcul if new_frame is false */
  50. if (!new_frame)
  51. return;
  52. fps->curr_frame_counter++;
  53. ms_since_last = ktime_to_ms(ktime_sub(now, fps->last_timestamp));
  54. num_frames = fps->curr_frame_counter - fps->last_frame_counter;
  55. if (num_frames <= 0 || ms_since_last < STI_FPS_INTERVAL_MS)
  56. return;
  57. fps->last_timestamp = now;
  58. fps->last_frame_counter = fps->curr_frame_counter;
  59. if (state->fb) {
  60. fpks = (num_frames * 1000000) / ms_since_last;
  61. snprintf(plane->fps_info.fps_str, FPS_LENGTH,
  62. "%-8s %4dx%-4d %.4s @ %3d.%-3.3d fps (%s)",
  63. plane->drm_plane.name,
  64. state->fb->width,
  65. state->fb->height,
  66. (char *)&state->fb->format->format,
  67. fpks / 1000, fpks % 1000,
  68. sti_plane_to_str(plane));
  69. }
  70. if (fps->curr_field_counter) {
  71. /* Compute number of field updates */
  72. num_fields = fps->curr_field_counter - fps->last_field_counter;
  73. fps->last_field_counter = fps->curr_field_counter;
  74. fipks = (num_fields * 1000000) / ms_since_last;
  75. snprintf(plane->fps_info.fips_str,
  76. FPS_LENGTH, " - %3d.%-3.3d field/sec",
  77. fipks / 1000, fipks % 1000);
  78. } else {
  79. plane->fps_info.fips_str[0] = '\0';
  80. }
  81. if (fps->output)
  82. DRM_INFO("%s%s\n",
  83. plane->fps_info.fps_str,
  84. plane->fps_info.fips_str);
  85. }
  86. static int sti_plane_get_default_zpos(enum drm_plane_type type)
  87. {
  88. switch (type) {
  89. case DRM_PLANE_TYPE_PRIMARY:
  90. return 0;
  91. case DRM_PLANE_TYPE_OVERLAY:
  92. return 1;
  93. case DRM_PLANE_TYPE_CURSOR:
  94. return 7;
  95. }
  96. return 0;
  97. }
  98. static void sti_plane_attach_zorder_property(struct drm_plane *drm_plane,
  99. enum drm_plane_type type)
  100. {
  101. int zpos = sti_plane_get_default_zpos(type);
  102. switch (type) {
  103. case DRM_PLANE_TYPE_PRIMARY:
  104. case DRM_PLANE_TYPE_OVERLAY:
  105. drm_plane_create_zpos_property(drm_plane, zpos, 0, 6);
  106. break;
  107. case DRM_PLANE_TYPE_CURSOR:
  108. drm_plane_create_zpos_immutable_property(drm_plane, zpos);
  109. break;
  110. }
  111. }
  112. void sti_plane_init_property(struct sti_plane *plane,
  113. enum drm_plane_type type)
  114. {
  115. sti_plane_attach_zorder_property(&plane->drm_plane, type);
  116. DRM_DEBUG_DRIVER("drm plane:%d mapped to %s\n",
  117. plane->drm_plane.base.id, sti_plane_to_str(plane));
  118. }