sti_plane.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (C) STMicroelectronics SA 2014
  3. * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
  4. * Fabien Dessenne <fabien.dessenne@st.com>
  5. * for STMicroelectronics.
  6. * License terms: GNU General Public License (GPL), version 2
  7. */
  8. #include <drm/drmP.h>
  9. #include <drm/drm_fb_cma_helper.h>
  10. #include <drm/drm_gem_cma_helper.h>
  11. #include "sti_compositor.h"
  12. #include "sti_drv.h"
  13. #include "sti_plane.h"
  14. /* (Background) < GDP0 < GDP1 < HQVDP0 < GDP2 < GDP3 < (ForeGround) */
  15. enum sti_plane_desc sti_plane_default_zorder[] = {
  16. STI_GDP_0,
  17. STI_GDP_1,
  18. STI_HQVDP_0,
  19. STI_GDP_2,
  20. STI_GDP_3,
  21. };
  22. const char *sti_plane_to_str(struct sti_plane *plane)
  23. {
  24. switch (plane->desc) {
  25. case STI_GDP_0:
  26. return "GDP0";
  27. case STI_GDP_1:
  28. return "GDP1";
  29. case STI_GDP_2:
  30. return "GDP2";
  31. case STI_GDP_3:
  32. return "GDP3";
  33. case STI_HQVDP_0:
  34. return "HQVDP0";
  35. case STI_CURSOR:
  36. return "CURSOR";
  37. default:
  38. return "<UNKNOWN PLANE>";
  39. }
  40. }
  41. static void sti_plane_destroy(struct drm_plane *drm_plane)
  42. {
  43. DRM_DEBUG_DRIVER("\n");
  44. drm_plane_helper_disable(drm_plane);
  45. drm_plane_cleanup(drm_plane);
  46. }
  47. static int sti_plane_set_property(struct drm_plane *drm_plane,
  48. struct drm_property *property,
  49. uint64_t val)
  50. {
  51. struct drm_device *dev = drm_plane->dev;
  52. struct sti_private *private = dev->dev_private;
  53. struct sti_plane *plane = to_sti_plane(drm_plane);
  54. DRM_DEBUG_DRIVER("\n");
  55. if (property == private->plane_zorder_property) {
  56. plane->zorder = val;
  57. return 0;
  58. }
  59. return -EINVAL;
  60. }
  61. static void sti_plane_attach_zorder_property(struct drm_plane *drm_plane)
  62. {
  63. struct drm_device *dev = drm_plane->dev;
  64. struct sti_private *private = dev->dev_private;
  65. struct sti_plane *plane = to_sti_plane(drm_plane);
  66. struct drm_property *prop;
  67. prop = private->plane_zorder_property;
  68. if (!prop) {
  69. prop = drm_property_create_range(dev, 0, "zpos", 1,
  70. GAM_MIXER_NB_DEPTH_LEVEL);
  71. if (!prop)
  72. return;
  73. private->plane_zorder_property = prop;
  74. }
  75. drm_object_attach_property(&drm_plane->base, prop, plane->zorder);
  76. }
  77. void sti_plane_init_property(struct sti_plane *plane,
  78. enum drm_plane_type type)
  79. {
  80. unsigned int i;
  81. for (i = 0; i < ARRAY_SIZE(sti_plane_default_zorder); i++)
  82. if (sti_plane_default_zorder[i] == plane->desc)
  83. break;
  84. plane->zorder = i + 1;
  85. if (type == DRM_PLANE_TYPE_OVERLAY)
  86. sti_plane_attach_zorder_property(&plane->drm_plane);
  87. DRM_DEBUG_DRIVER("drm plane:%d mapped to %s with zorder:%d\n",
  88. plane->drm_plane.base.id,
  89. sti_plane_to_str(plane), plane->zorder);
  90. }
  91. struct drm_plane_funcs sti_plane_helpers_funcs = {
  92. .update_plane = drm_atomic_helper_update_plane,
  93. .disable_plane = drm_atomic_helper_disable_plane,
  94. .destroy = sti_plane_destroy,
  95. .set_property = sti_plane_set_property,
  96. .reset = drm_atomic_helper_plane_reset,
  97. .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
  98. .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
  99. };