exynos_drm_plane.c 4.0 KB

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