tilcdc_plane.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (C) 2015 Texas Instruments
  3. * Author: Jyri Sarha <jsarha@ti.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 version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <drm/drmP.h>
  18. #include <drm/drm_atomic.h>
  19. #include <drm/drm_plane_helper.h>
  20. #include <drm/drm_atomic_helper.h>
  21. #include <uapi/drm/drm_fourcc.h>
  22. #include "tilcdc_drv.h"
  23. static struct drm_plane_funcs tilcdc_plane_funcs = {
  24. .update_plane = drm_atomic_helper_update_plane,
  25. .disable_plane = drm_atomic_helper_disable_plane,
  26. .destroy = drm_plane_cleanup,
  27. .set_property = drm_atomic_helper_plane_set_property,
  28. .reset = drm_atomic_helper_plane_reset,
  29. .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
  30. .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
  31. };
  32. static int tilcdc_plane_atomic_check(struct drm_plane *plane,
  33. struct drm_plane_state *state)
  34. {
  35. struct drm_crtc_state *crtc_state;
  36. struct drm_plane_state *old_state = plane->state;
  37. unsigned int pitch;
  38. if (!state->crtc)
  39. return 0;
  40. if (WARN_ON(!state->fb))
  41. return -EINVAL;
  42. if (state->crtc_x || state->crtc_y) {
  43. dev_err(plane->dev->dev, "%s: crtc position must be zero.",
  44. __func__);
  45. return -EINVAL;
  46. }
  47. crtc_state = drm_atomic_get_existing_crtc_state(state->state,
  48. state->crtc);
  49. /* we should have a crtc state if the plane is attached to a crtc */
  50. if (WARN_ON(!crtc_state))
  51. return 0;
  52. if (crtc_state->mode.hdisplay != state->crtc_w ||
  53. crtc_state->mode.vdisplay != state->crtc_h) {
  54. dev_err(plane->dev->dev,
  55. "%s: Size must match mode (%dx%d == %dx%d)", __func__,
  56. crtc_state->mode.hdisplay, crtc_state->mode.vdisplay,
  57. state->crtc_w, state->crtc_h);
  58. return -EINVAL;
  59. }
  60. pitch = crtc_state->mode.hdisplay *
  61. state->fb->format->cpp[0];
  62. if (state->fb->pitches[0] != pitch) {
  63. dev_err(plane->dev->dev,
  64. "Invalid pitch: fb and crtc widths must be the same");
  65. return -EINVAL;
  66. }
  67. if (state->fb && old_state->fb &&
  68. state->fb->format != old_state->fb->format) {
  69. dev_dbg(plane->dev->dev,
  70. "%s(): pixel format change requires mode_change\n",
  71. __func__);
  72. crtc_state->mode_changed = true;
  73. }
  74. return 0;
  75. }
  76. static void tilcdc_plane_atomic_update(struct drm_plane *plane,
  77. struct drm_plane_state *old_state)
  78. {
  79. struct drm_plane_state *state = plane->state;
  80. if (!state->crtc)
  81. return;
  82. if (WARN_ON(!state->fb || !state->crtc->state))
  83. return;
  84. tilcdc_crtc_update_fb(state->crtc,
  85. state->fb,
  86. state->crtc->state->event);
  87. }
  88. static const struct drm_plane_helper_funcs plane_helper_funcs = {
  89. .atomic_check = tilcdc_plane_atomic_check,
  90. .atomic_update = tilcdc_plane_atomic_update,
  91. };
  92. int tilcdc_plane_init(struct drm_device *dev,
  93. struct drm_plane *plane)
  94. {
  95. struct tilcdc_drm_private *priv = dev->dev_private;
  96. int ret;
  97. ret = drm_plane_init(dev, plane, 1,
  98. &tilcdc_plane_funcs,
  99. priv->pixelformats,
  100. priv->num_pixelformats,
  101. true);
  102. if (ret) {
  103. dev_err(dev->dev, "Failed to initialize plane: %d\n", ret);
  104. return ret;
  105. }
  106. drm_plane_helper_add(plane, &plane_helper_funcs);
  107. return 0;
  108. }