1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
7 #include <drm/drm_atomic.h>
8 #include <drm/drm_atomic_helper.h>
9 #include <drm/drm_blend.h>
10 #include <drm/drm_crtc.h>
11 #include <drm/drm_fourcc.h>
12 #include <drm/drm_framebuffer.h>
13 #include <drm/drm_gem_atomic_helper.h>
15 #include "tidss_crtc.h"
16 #include "tidss_dispc.h"
17 #include "tidss_drv.h"
18 #include "tidss_plane.h"
20 /* drm_plane_helper_funcs */
22 static int tidss_plane_atomic_check(struct drm_plane *plane,
23 struct drm_atomic_state *state)
25 struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
27 struct drm_device *ddev = plane->dev;
28 struct tidss_device *tidss = to_tidss(ddev);
29 struct tidss_plane *tplane = to_tidss_plane(plane);
30 const struct drm_format_info *finfo;
31 struct drm_crtc_state *crtc_state;
32 u32 hw_plane = tplane->hw_plane_id;
36 dev_dbg(ddev->dev, "%s\n", __func__);
38 if (!new_plane_state->crtc) {
40 * The visible field is not reset by the DRM core but only
41 * updated by drm_atomic_helper_check_plane_state(), set it
44 new_plane_state->visible = false;
48 crtc_state = drm_atomic_get_crtc_state(state,
49 new_plane_state->crtc);
50 if (IS_ERR(crtc_state))
51 return PTR_ERR(crtc_state);
53 ret = drm_atomic_helper_check_plane_state(new_plane_state, crtc_state,
60 * The HW is only able to start drawing at subpixel boundary
61 * (the two first checks bellow). At the end of a row the HW
62 * can only jump integer number of subpixels forward to the
63 * beginning of the next row. So we can only show picture with
64 * integer subpixel width (the third check). However, after
65 * reaching the end of the drawn picture the drawing starts
66 * again at the absolute memory address where top left corner
67 * position of the drawn picture is (so there is no need to
68 * check for odd height).
71 finfo = drm_format_info(new_plane_state->fb->format->format);
73 if ((new_plane_state->src_x >> 16) % finfo->hsub != 0) {
75 "%s: x-position %u not divisible subpixel size %u\n",
76 __func__, (new_plane_state->src_x >> 16), finfo->hsub);
80 if ((new_plane_state->src_y >> 16) % finfo->vsub != 0) {
82 "%s: y-position %u not divisible subpixel size %u\n",
83 __func__, (new_plane_state->src_y >> 16), finfo->vsub);
87 if ((new_plane_state->src_w >> 16) % finfo->hsub != 0) {
89 "%s: src width %u not divisible by subpixel size %u\n",
90 __func__, (new_plane_state->src_w >> 16),
95 if (!new_plane_state->visible)
98 hw_videoport = to_tidss_crtc(new_plane_state->crtc)->hw_videoport;
100 ret = dispc_plane_check(tidss->dispc, hw_plane, new_plane_state,
108 static void tidss_plane_atomic_update(struct drm_plane *plane,
109 struct drm_atomic_state *state)
111 struct drm_device *ddev = plane->dev;
112 struct tidss_device *tidss = to_tidss(ddev);
113 struct tidss_plane *tplane = to_tidss_plane(plane);
114 struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
118 dev_dbg(ddev->dev, "%s\n", __func__);
120 if (!new_state->visible) {
121 dispc_plane_enable(tidss->dispc, tplane->hw_plane_id, false);
125 hw_videoport = to_tidss_crtc(new_state->crtc)->hw_videoport;
127 dispc_plane_setup(tidss->dispc, tplane->hw_plane_id, new_state, hw_videoport);
130 static void tidss_plane_atomic_enable(struct drm_plane *plane,
131 struct drm_atomic_state *state)
133 struct drm_device *ddev = plane->dev;
134 struct tidss_device *tidss = to_tidss(ddev);
135 struct tidss_plane *tplane = to_tidss_plane(plane);
137 dev_dbg(ddev->dev, "%s\n", __func__);
139 dispc_plane_enable(tidss->dispc, tplane->hw_plane_id, true);
142 static void tidss_plane_atomic_disable(struct drm_plane *plane,
143 struct drm_atomic_state *state)
145 struct drm_device *ddev = plane->dev;
146 struct tidss_device *tidss = to_tidss(ddev);
147 struct tidss_plane *tplane = to_tidss_plane(plane);
149 dev_dbg(ddev->dev, "%s\n", __func__);
151 dispc_plane_enable(tidss->dispc, tplane->hw_plane_id, false);
154 static void drm_plane_destroy(struct drm_plane *plane)
156 struct tidss_plane *tplane = to_tidss_plane(plane);
158 drm_plane_cleanup(plane);
162 static const struct drm_plane_helper_funcs tidss_plane_helper_funcs = {
163 .atomic_check = tidss_plane_atomic_check,
164 .atomic_update = tidss_plane_atomic_update,
165 .atomic_enable = tidss_plane_atomic_enable,
166 .atomic_disable = tidss_plane_atomic_disable,
169 static const struct drm_plane_funcs tidss_plane_funcs = {
170 .update_plane = drm_atomic_helper_update_plane,
171 .disable_plane = drm_atomic_helper_disable_plane,
172 .reset = drm_atomic_helper_plane_reset,
173 .destroy = drm_plane_destroy,
174 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
175 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
178 struct tidss_plane *tidss_plane_create(struct tidss_device *tidss,
179 u32 hw_plane_id, u32 plane_type,
180 u32 crtc_mask, const u32 *formats,
183 struct tidss_plane *tplane;
184 enum drm_plane_type type;
186 u32 num_planes = tidss->feat->num_planes;
187 u32 color_encodings = (BIT(DRM_COLOR_YCBCR_BT601) |
188 BIT(DRM_COLOR_YCBCR_BT709));
189 u32 color_ranges = (BIT(DRM_COLOR_YCBCR_FULL_RANGE) |
190 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE));
191 u32 default_encoding = DRM_COLOR_YCBCR_BT601;
192 u32 default_range = DRM_COLOR_YCBCR_FULL_RANGE;
193 u32 blend_modes = (BIT(DRM_MODE_BLEND_PREMULTI) |
194 BIT(DRM_MODE_BLEND_COVERAGE));
197 tplane = kzalloc(sizeof(*tplane), GFP_KERNEL);
199 return ERR_PTR(-ENOMEM);
201 tplane->hw_plane_id = hw_plane_id;
203 possible_crtcs = crtc_mask;
206 ret = drm_universal_plane_init(&tidss->ddev, &tplane->plane,
209 formats, num_formats,
214 drm_plane_helper_add(&tplane->plane, &tidss_plane_helper_funcs);
216 drm_plane_create_zpos_property(&tplane->plane, tidss->num_planes, 0,
219 ret = drm_plane_create_color_properties(&tplane->plane,
227 ret = drm_plane_create_alpha_property(&tplane->plane);
231 ret = drm_plane_create_blend_mode_property(&tplane->plane, blend_modes);