1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2015 Texas Instruments
7 #include <drm/drm_atomic.h>
8 #include <drm/drm_atomic_helper.h>
9 #include <drm/drm_fourcc.h>
10 #include <drm/drm_framebuffer.h>
12 #include "tilcdc_drv.h"
14 static const struct drm_plane_funcs tilcdc_plane_funcs = {
15 .update_plane = drm_atomic_helper_update_plane,
16 .disable_plane = drm_atomic_helper_disable_plane,
17 .destroy = drm_plane_cleanup,
18 .reset = drm_atomic_helper_plane_reset,
19 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
20 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
23 static int tilcdc_plane_atomic_check(struct drm_plane *plane,
24 struct drm_atomic_state *state)
26 struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
28 struct drm_crtc_state *crtc_state;
29 struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,
36 if (WARN_ON(!new_state->fb))
39 if (new_state->crtc_x || new_state->crtc_y) {
40 dev_err(plane->dev->dev, "%s: crtc position must be zero.",
45 crtc_state = drm_atomic_get_existing_crtc_state(state,
47 /* we should have a crtc state if the plane is attached to a crtc */
48 if (WARN_ON(!crtc_state))
51 if (crtc_state->mode.hdisplay != new_state->crtc_w ||
52 crtc_state->mode.vdisplay != new_state->crtc_h) {
53 dev_err(plane->dev->dev,
54 "%s: Size must match mode (%dx%d == %dx%d)", __func__,
55 crtc_state->mode.hdisplay, crtc_state->mode.vdisplay,
56 new_state->crtc_w, new_state->crtc_h);
60 pitch = crtc_state->mode.hdisplay *
61 new_state->fb->format->cpp[0];
62 if (new_state->fb->pitches[0] != pitch) {
63 dev_err(plane->dev->dev,
64 "Invalid pitch: fb and crtc widths must be the same");
68 if (old_state->fb && new_state->fb->format != old_state->fb->format) {
69 dev_dbg(plane->dev->dev,
70 "%s(): pixel format change requires mode_change\n",
72 crtc_state->mode_changed = true;
78 static void tilcdc_plane_atomic_update(struct drm_plane *plane,
79 struct drm_atomic_state *state)
81 struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
87 if (WARN_ON(!new_state->fb || !new_state->crtc->state))
90 if (tilcdc_crtc_update_fb(new_state->crtc,
92 new_state->crtc->state->event) == 0) {
93 new_state->crtc->state->event = NULL;
97 static const struct drm_plane_helper_funcs plane_helper_funcs = {
98 .atomic_check = tilcdc_plane_atomic_check,
99 .atomic_update = tilcdc_plane_atomic_update,
102 int tilcdc_plane_init(struct drm_device *dev,
103 struct drm_plane *plane)
105 struct tilcdc_drm_private *priv = dev->dev_private;
108 ret = drm_universal_plane_init(dev, plane, 1, &tilcdc_plane_funcs,
110 priv->num_pixelformats,
111 NULL, DRM_PLANE_TYPE_PRIMARY, NULL);
113 dev_err(dev->dev, "Failed to initialize plane: %d\n", ret);
117 drm_plane_helper_add(plane, &plane_helper_funcs);