0001
0002
0003
0004
0005
0006
0007 #include <drm/drm_atomic.h>
0008 #include <drm/drm_plane_helper.h>
0009 #include <drm/drm_atomic_helper.h>
0010 #include <drm/drm_fourcc.h>
0011 #include <drm/drm_framebuffer.h>
0012
0013 #include "tilcdc_drv.h"
0014
0015 static const struct drm_plane_funcs tilcdc_plane_funcs = {
0016 .update_plane = drm_atomic_helper_update_plane,
0017 .disable_plane = drm_atomic_helper_disable_plane,
0018 .destroy = drm_plane_cleanup,
0019 .reset = drm_atomic_helper_plane_reset,
0020 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
0021 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
0022 };
0023
0024 static int tilcdc_plane_atomic_check(struct drm_plane *plane,
0025 struct drm_atomic_state *state)
0026 {
0027 struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
0028 plane);
0029 struct drm_crtc_state *crtc_state;
0030 struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,
0031 plane);
0032 unsigned int pitch;
0033
0034 if (!new_state->crtc)
0035 return 0;
0036
0037 if (WARN_ON(!new_state->fb))
0038 return -EINVAL;
0039
0040 if (new_state->crtc_x || new_state->crtc_y) {
0041 dev_err(plane->dev->dev, "%s: crtc position must be zero.",
0042 __func__);
0043 return -EINVAL;
0044 }
0045
0046 crtc_state = drm_atomic_get_existing_crtc_state(state,
0047 new_state->crtc);
0048
0049 if (WARN_ON(!crtc_state))
0050 return 0;
0051
0052 if (crtc_state->mode.hdisplay != new_state->crtc_w ||
0053 crtc_state->mode.vdisplay != new_state->crtc_h) {
0054 dev_err(plane->dev->dev,
0055 "%s: Size must match mode (%dx%d == %dx%d)", __func__,
0056 crtc_state->mode.hdisplay, crtc_state->mode.vdisplay,
0057 new_state->crtc_w, new_state->crtc_h);
0058 return -EINVAL;
0059 }
0060
0061 pitch = crtc_state->mode.hdisplay *
0062 new_state->fb->format->cpp[0];
0063 if (new_state->fb->pitches[0] != pitch) {
0064 dev_err(plane->dev->dev,
0065 "Invalid pitch: fb and crtc widths must be the same");
0066 return -EINVAL;
0067 }
0068
0069 if (old_state->fb && new_state->fb->format != old_state->fb->format) {
0070 dev_dbg(plane->dev->dev,
0071 "%s(): pixel format change requires mode_change\n",
0072 __func__);
0073 crtc_state->mode_changed = true;
0074 }
0075
0076 return 0;
0077 }
0078
0079 static void tilcdc_plane_atomic_update(struct drm_plane *plane,
0080 struct drm_atomic_state *state)
0081 {
0082 struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
0083 plane);
0084
0085 if (!new_state->crtc)
0086 return;
0087
0088 if (WARN_ON(!new_state->fb || !new_state->crtc->state))
0089 return;
0090
0091 if (tilcdc_crtc_update_fb(new_state->crtc,
0092 new_state->fb,
0093 new_state->crtc->state->event) == 0) {
0094 new_state->crtc->state->event = NULL;
0095 }
0096 }
0097
0098 static const struct drm_plane_helper_funcs plane_helper_funcs = {
0099 .atomic_check = tilcdc_plane_atomic_check,
0100 .atomic_update = tilcdc_plane_atomic_update,
0101 };
0102
0103 int tilcdc_plane_init(struct drm_device *dev,
0104 struct drm_plane *plane)
0105 {
0106 struct tilcdc_drm_private *priv = dev->dev_private;
0107 int ret;
0108
0109 ret = drm_plane_init(dev, plane, 1,
0110 &tilcdc_plane_funcs,
0111 priv->pixelformats,
0112 priv->num_pixelformats,
0113 true);
0114 if (ret) {
0115 dev_err(dev->dev, "Failed to initialize plane: %d\n", ret);
0116 return ret;
0117 }
0118
0119 drm_plane_helper_add(plane, &plane_helper_funcs);
0120
0121 return 0;
0122 }