tilcdc_plane.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2015 Texas Instruments
  4. * Author: Jyri Sarha <[email protected]>
  5. */
  6. #include <drm/drm_atomic.h>
  7. #include <drm/drm_atomic_helper.h>
  8. #include <drm/drm_fourcc.h>
  9. #include <drm/drm_framebuffer.h>
  10. #include "tilcdc_drv.h"
  11. static const struct drm_plane_funcs tilcdc_plane_funcs = {
  12. .update_plane = drm_atomic_helper_update_plane,
  13. .disable_plane = drm_atomic_helper_disable_plane,
  14. .destroy = drm_plane_cleanup,
  15. .reset = drm_atomic_helper_plane_reset,
  16. .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
  17. .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
  18. };
  19. static int tilcdc_plane_atomic_check(struct drm_plane *plane,
  20. struct drm_atomic_state *state)
  21. {
  22. struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
  23. plane);
  24. struct drm_crtc_state *crtc_state;
  25. struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,
  26. plane);
  27. unsigned int pitch;
  28. if (!new_state->crtc)
  29. return 0;
  30. if (WARN_ON(!new_state->fb))
  31. return -EINVAL;
  32. if (new_state->crtc_x || new_state->crtc_y) {
  33. dev_err(plane->dev->dev, "%s: crtc position must be zero.",
  34. __func__);
  35. return -EINVAL;
  36. }
  37. crtc_state = drm_atomic_get_existing_crtc_state(state,
  38. new_state->crtc);
  39. /* we should have a crtc state if the plane is attached to a crtc */
  40. if (WARN_ON(!crtc_state))
  41. return 0;
  42. if (crtc_state->mode.hdisplay != new_state->crtc_w ||
  43. crtc_state->mode.vdisplay != new_state->crtc_h) {
  44. dev_err(plane->dev->dev,
  45. "%s: Size must match mode (%dx%d == %dx%d)", __func__,
  46. crtc_state->mode.hdisplay, crtc_state->mode.vdisplay,
  47. new_state->crtc_w, new_state->crtc_h);
  48. return -EINVAL;
  49. }
  50. pitch = crtc_state->mode.hdisplay *
  51. new_state->fb->format->cpp[0];
  52. if (new_state->fb->pitches[0] != pitch) {
  53. dev_err(plane->dev->dev,
  54. "Invalid pitch: fb and crtc widths must be the same");
  55. return -EINVAL;
  56. }
  57. if (old_state->fb && new_state->fb->format != old_state->fb->format) {
  58. dev_dbg(plane->dev->dev,
  59. "%s(): pixel format change requires mode_change\n",
  60. __func__);
  61. crtc_state->mode_changed = true;
  62. }
  63. return 0;
  64. }
  65. static void tilcdc_plane_atomic_update(struct drm_plane *plane,
  66. struct drm_atomic_state *state)
  67. {
  68. struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
  69. plane);
  70. if (!new_state->crtc)
  71. return;
  72. if (WARN_ON(!new_state->fb || !new_state->crtc->state))
  73. return;
  74. if (tilcdc_crtc_update_fb(new_state->crtc,
  75. new_state->fb,
  76. new_state->crtc->state->event) == 0) {
  77. new_state->crtc->state->event = NULL;
  78. }
  79. }
  80. static const struct drm_plane_helper_funcs plane_helper_funcs = {
  81. .atomic_check = tilcdc_plane_atomic_check,
  82. .atomic_update = tilcdc_plane_atomic_update,
  83. };
  84. int tilcdc_plane_init(struct drm_device *dev,
  85. struct drm_plane *plane)
  86. {
  87. struct tilcdc_drm_private *priv = dev->dev_private;
  88. int ret;
  89. ret = drm_universal_plane_init(dev, plane, 1, &tilcdc_plane_funcs,
  90. priv->pixelformats,
  91. priv->num_pixelformats,
  92. NULL, DRM_PLANE_TYPE_PRIMARY, NULL);
  93. if (ret) {
  94. dev_err(dev->dev, "Failed to initialize plane: %d\n", ret);
  95. return ret;
  96. }
  97. drm_plane_helper_add(plane, &plane_helper_funcs);
  98. return 0;
  99. }