exynos_drm_plane.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. };
  24. static int
  25. exynos_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
  26. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  27. unsigned int crtc_w, unsigned int crtc_h,
  28. uint32_t src_x, uint32_t src_y,
  29. uint32_t src_w, uint32_t src_h)
  30. {
  31. struct exynos_plane *exynos_plane =
  32. container_of(plane, struct exynos_plane, base);
  33. struct exynos_drm_overlay *overlay = &exynos_plane->overlay;
  34. struct exynos_drm_crtc_pos pos;
  35. unsigned int x = src_x >> 16;
  36. unsigned int y = src_y >> 16;
  37. int ret;
  38. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  39. memset(&pos, 0, sizeof(struct exynos_drm_crtc_pos));
  40. pos.crtc_x = crtc_x;
  41. pos.crtc_y = crtc_y;
  42. pos.crtc_w = crtc_w;
  43. pos.crtc_h = crtc_h;
  44. pos.fb_x = x;
  45. pos.fb_y = y;
  46. /* TODO: scale feature */
  47. ret = exynos_drm_overlay_update(overlay, fb, &crtc->mode, &pos);
  48. if (ret < 0)
  49. return ret;
  50. exynos_drm_fn_encoder(crtc, overlay,
  51. exynos_drm_encoder_crtc_mode_set);
  52. exynos_drm_fn_encoder(crtc, &overlay->zpos,
  53. exynos_drm_encoder_crtc_plane_commit);
  54. exynos_plane->enabled = true;
  55. return 0;
  56. }
  57. static int exynos_disable_plane(struct drm_plane *plane)
  58. {
  59. struct exynos_plane *exynos_plane =
  60. container_of(plane, struct exynos_plane, base);
  61. struct exynos_drm_overlay *overlay = &exynos_plane->overlay;
  62. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  63. if (!exynos_plane->enabled)
  64. return 0;
  65. exynos_drm_fn_encoder(plane->crtc, &overlay->zpos,
  66. exynos_drm_encoder_crtc_disable);
  67. exynos_plane->enabled = false;
  68. exynos_plane->overlay.zpos = DEFAULT_ZPOS;
  69. return 0;
  70. }
  71. static void exynos_plane_destroy(struct drm_plane *plane)
  72. {
  73. struct exynos_plane *exynos_plane =
  74. container_of(plane, struct exynos_plane, base);
  75. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  76. exynos_disable_plane(plane);
  77. drm_plane_cleanup(plane);
  78. kfree(exynos_plane);
  79. }
  80. static struct drm_plane_funcs exynos_plane_funcs = {
  81. .update_plane = exynos_update_plane,
  82. .disable_plane = exynos_disable_plane,
  83. .destroy = exynos_plane_destroy,
  84. };
  85. int exynos_plane_init(struct drm_device *dev, unsigned int nr)
  86. {
  87. struct exynos_plane *exynos_plane;
  88. uint32_t possible_crtcs;
  89. exynos_plane = kzalloc(sizeof(struct exynos_plane), GFP_KERNEL);
  90. if (!exynos_plane)
  91. return -ENOMEM;
  92. /* all CRTCs are available */
  93. possible_crtcs = (1 << MAX_CRTC) - 1;
  94. exynos_plane->overlay.zpos = DEFAULT_ZPOS;
  95. return drm_plane_init(dev, &exynos_plane->base, possible_crtcs,
  96. &exynos_plane_funcs, formats, ARRAY_SIZE(formats),
  97. false);
  98. }
  99. int exynos_plane_set_zpos_ioctl(struct drm_device *dev, void *data,
  100. struct drm_file *file_priv)
  101. {
  102. struct drm_exynos_plane_set_zpos *zpos_req = data;
  103. struct drm_mode_object *obj;
  104. struct drm_plane *plane;
  105. struct exynos_plane *exynos_plane;
  106. int ret = 0;
  107. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  108. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  109. return -EINVAL;
  110. if (zpos_req->zpos < 0 || zpos_req->zpos >= MAX_PLANE) {
  111. if (zpos_req->zpos != DEFAULT_ZPOS) {
  112. DRM_ERROR("zpos not within limits\n");
  113. return -EINVAL;
  114. }
  115. }
  116. mutex_lock(&dev->mode_config.mutex);
  117. obj = drm_mode_object_find(dev, zpos_req->plane_id,
  118. DRM_MODE_OBJECT_PLANE);
  119. if (!obj) {
  120. DRM_DEBUG_KMS("Unknown plane ID %d\n",
  121. zpos_req->plane_id);
  122. ret = -EINVAL;
  123. goto out;
  124. }
  125. plane = obj_to_plane(obj);
  126. exynos_plane = container_of(plane, struct exynos_plane, base);
  127. exynos_plane->overlay.zpos = zpos_req->zpos;
  128. out:
  129. mutex_unlock(&dev->mode_config.mutex);
  130. return ret;
  131. }