sti_plane.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. EXPORT_SYMBOL(sti_plane_to_str);
  42. static void sti_plane_destroy(struct drm_plane *drm_plane)
  43. {
  44. DRM_DEBUG_DRIVER("\n");
  45. drm_plane_helper_disable(drm_plane);
  46. drm_plane_cleanup(drm_plane);
  47. }
  48. static int sti_plane_set_property(struct drm_plane *drm_plane,
  49. struct drm_property *property,
  50. uint64_t val)
  51. {
  52. struct drm_device *dev = drm_plane->dev;
  53. struct sti_private *private = dev->dev_private;
  54. struct sti_plane *plane = to_sti_plane(drm_plane);
  55. DRM_DEBUG_DRIVER("\n");
  56. if (property == private->plane_zorder_property) {
  57. plane->zorder = val;
  58. return 0;
  59. }
  60. return -EINVAL;
  61. }
  62. static void sti_plane_attach_zorder_property(struct drm_plane *drm_plane)
  63. {
  64. struct drm_device *dev = drm_plane->dev;
  65. struct sti_private *private = dev->dev_private;
  66. struct sti_plane *plane = to_sti_plane(drm_plane);
  67. struct drm_property *prop;
  68. prop = private->plane_zorder_property;
  69. if (!prop) {
  70. prop = drm_property_create_range(dev, 0, "zpos", 1,
  71. GAM_MIXER_NB_DEPTH_LEVEL);
  72. if (!prop)
  73. return;
  74. private->plane_zorder_property = prop;
  75. }
  76. drm_object_attach_property(&drm_plane->base, prop, plane->zorder);
  77. }
  78. void sti_plane_init_property(struct sti_plane *plane,
  79. enum drm_plane_type type)
  80. {
  81. unsigned int i;
  82. for (i = 0; i < ARRAY_SIZE(sti_plane_default_zorder); i++)
  83. if (sti_plane_default_zorder[i] == plane->desc)
  84. break;
  85. plane->zorder = i + 1;
  86. if (type == DRM_PLANE_TYPE_OVERLAY)
  87. sti_plane_attach_zorder_property(&plane->drm_plane);
  88. DRM_DEBUG_DRIVER("drm plane:%d mapped to %s with zorder:%d\n",
  89. plane->drm_plane.base.id,
  90. sti_plane_to_str(plane), plane->zorder);
  91. }
  92. EXPORT_SYMBOL(sti_plane_init_property);
  93. struct drm_plane_funcs sti_plane_helpers_funcs = {
  94. .update_plane = drm_atomic_helper_update_plane,
  95. .disable_plane = drm_atomic_helper_disable_plane,
  96. .destroy = sti_plane_destroy,
  97. .set_property = sti_plane_set_property,
  98. .reset = drm_atomic_helper_plane_reset,
  99. .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
  100. .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
  101. };
  102. EXPORT_SYMBOL(sti_plane_helpers_funcs);