exynos_drm_plane.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics Co.Ltd
  3. * Authors: Joonyoung Shim <jy0922.shim@samsung.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. */
  11. #include "drmP.h"
  12. #include "exynos_drm.h"
  13. #include "exynos_drm_crtc.h"
  14. #include "exynos_drm_drv.h"
  15. #include "exynos_drm_encoder.h"
  16. struct exynos_plane {
  17. struct drm_plane base;
  18. struct exynos_drm_overlay overlay;
  19. bool enabled;
  20. };
  21. static const uint32_t formats[] = {
  22. DRM_FORMAT_XRGB8888,
  23. DRM_FORMAT_ARGB8888,
  24. DRM_FORMAT_NV12,
  25. DRM_FORMAT_NV12M,
  26. DRM_FORMAT_NV12MT,
  27. };
  28. static int
  29. exynos_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
  30. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  31. unsigned int crtc_w, unsigned int crtc_h,
  32. uint32_t src_x, uint32_t src_y,
  33. uint32_t src_w, uint32_t src_h)
  34. {
  35. struct exynos_plane *exynos_plane =
  36. container_of(plane, struct exynos_plane, base);
  37. struct exynos_drm_overlay *overlay = &exynos_plane->overlay;
  38. struct exynos_drm_crtc_pos pos;
  39. int ret;
  40. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  41. memset(&pos, 0, sizeof(struct exynos_drm_crtc_pos));
  42. pos.crtc_x = crtc_x;
  43. pos.crtc_y = crtc_y;
  44. pos.crtc_w = crtc_w;
  45. pos.crtc_h = crtc_h;
  46. /* considering 16.16 fixed point of source values */
  47. pos.fb_x = src_x >> 16;
  48. pos.fb_y = src_y >> 16;
  49. pos.src_w = src_w >> 16;
  50. pos.src_h = src_h >> 16;
  51. ret = exynos_drm_overlay_update(overlay, fb, &crtc->mode, &pos);
  52. if (ret < 0)
  53. return ret;
  54. exynos_drm_fn_encoder(crtc, overlay,
  55. exynos_drm_encoder_crtc_mode_set);
  56. exynos_drm_fn_encoder(crtc, &overlay->zpos,
  57. exynos_drm_encoder_crtc_plane_commit);
  58. exynos_plane->enabled = true;
  59. return 0;
  60. }
  61. static int exynos_disable_plane(struct drm_plane *plane)
  62. {
  63. struct exynos_plane *exynos_plane =
  64. container_of(plane, struct exynos_plane, base);
  65. struct exynos_drm_overlay *overlay = &exynos_plane->overlay;
  66. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  67. if (!exynos_plane->enabled)
  68. return 0;
  69. exynos_drm_fn_encoder(plane->crtc, &overlay->zpos,
  70. exynos_drm_encoder_crtc_disable);
  71. exynos_plane->enabled = false;
  72. exynos_plane->overlay.zpos = DEFAULT_ZPOS;
  73. return 0;
  74. }
  75. static void exynos_plane_destroy(struct drm_plane *plane)
  76. {
  77. struct exynos_plane *exynos_plane =
  78. container_of(plane, struct exynos_plane, base);
  79. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  80. exynos_disable_plane(plane);
  81. drm_plane_cleanup(plane);
  82. kfree(exynos_plane);
  83. }
  84. static struct drm_plane_funcs exynos_plane_funcs = {
  85. .update_plane = exynos_update_plane,
  86. .disable_plane = exynos_disable_plane,
  87. .destroy = exynos_plane_destroy,
  88. };
  89. int exynos_plane_init(struct drm_device *dev, unsigned int nr)
  90. {
  91. struct exynos_plane *exynos_plane;
  92. uint32_t possible_crtcs;
  93. exynos_plane = kzalloc(sizeof(struct exynos_plane), GFP_KERNEL);
  94. if (!exynos_plane)
  95. return -ENOMEM;
  96. /* all CRTCs are available */
  97. possible_crtcs = (1 << MAX_CRTC) - 1;
  98. exynos_plane->overlay.zpos = DEFAULT_ZPOS;
  99. return drm_plane_init(dev, &exynos_plane->base, possible_crtcs,
  100. &exynos_plane_funcs, formats, ARRAY_SIZE(formats),
  101. false);
  102. }
  103. int exynos_plane_set_zpos_ioctl(struct drm_device *dev, void *data,
  104. struct drm_file *file_priv)
  105. {
  106. struct drm_exynos_plane_set_zpos *zpos_req = data;
  107. struct drm_mode_object *obj;
  108. struct drm_plane *plane;
  109. struct exynos_plane *exynos_plane;
  110. int ret = 0;
  111. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  112. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  113. return -EINVAL;
  114. if (zpos_req->zpos < 0 || zpos_req->zpos >= MAX_PLANE) {
  115. if (zpos_req->zpos != DEFAULT_ZPOS) {
  116. DRM_ERROR("zpos not within limits\n");
  117. return -EINVAL;
  118. }
  119. }
  120. mutex_lock(&dev->mode_config.mutex);
  121. obj = drm_mode_object_find(dev, zpos_req->plane_id,
  122. DRM_MODE_OBJECT_PLANE);
  123. if (!obj) {
  124. DRM_DEBUG_KMS("Unknown plane ID %d\n",
  125. zpos_req->plane_id);
  126. ret = -EINVAL;
  127. goto out;
  128. }
  129. plane = obj_to_plane(obj);
  130. exynos_plane = container_of(plane, struct exynos_plane, base);
  131. exynos_plane->overlay.zpos = zpos_req->zpos;
  132. out:
  133. mutex_unlock(&dev->mode_config.mutex);
  134. return ret;
  135. }