forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/gpu/drm/mediatek/mtk_drm_plane.c
....@@ -1,32 +1,31 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2015 MediaTek Inc.
34 * Author: CK Hu <ck.hu@mediatek.com>
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
135 */
146
15
-#include <drm/drmP.h>
167 #include <drm/drm_atomic.h>
178 #include <drm/drm_atomic_helper.h>
9
+#include <drm/drm_fourcc.h>
10
+#include <drm/drm_atomic_uapi.h>
1811 #include <drm/drm_plane_helper.h>
12
+#include <drm/drm_gem_framebuffer_helper.h>
1913
2014 #include "mtk_drm_crtc.h"
2115 #include "mtk_drm_ddp_comp.h"
2216 #include "mtk_drm_drv.h"
23
-#include "mtk_drm_fb.h"
2417 #include "mtk_drm_gem.h"
2518 #include "mtk_drm_plane.h"
2619
2720 static const u32 formats[] = {
2821 DRM_FORMAT_XRGB8888,
2922 DRM_FORMAT_ARGB8888,
23
+ DRM_FORMAT_BGRX8888,
24
+ DRM_FORMAT_BGRA8888,
25
+ DRM_FORMAT_ABGR8888,
26
+ DRM_FORMAT_XBGR8888,
27
+ DRM_FORMAT_RGB888,
28
+ DRM_FORMAT_BGR888,
3029 DRM_FORMAT_RGB565,
3130 DRM_FORMAT_UYVY,
3231 DRM_FORMAT_YUYV,
....@@ -77,6 +76,57 @@
7776 kfree(to_mtk_plane_state(state));
7877 }
7978
79
+static int mtk_plane_atomic_async_check(struct drm_plane *plane,
80
+ struct drm_plane_state *state)
81
+{
82
+ struct drm_crtc_state *crtc_state;
83
+ int ret;
84
+
85
+ if (plane != state->crtc->cursor)
86
+ return -EINVAL;
87
+
88
+ if (!plane->state)
89
+ return -EINVAL;
90
+
91
+ if (!plane->state->fb)
92
+ return -EINVAL;
93
+
94
+ ret = mtk_drm_crtc_plane_check(state->crtc, plane,
95
+ to_mtk_plane_state(state));
96
+ if (ret)
97
+ return ret;
98
+
99
+ if (state->state)
100
+ crtc_state = drm_atomic_get_existing_crtc_state(state->state,
101
+ state->crtc);
102
+ else /* Special case for asynchronous cursor updates. */
103
+ crtc_state = state->crtc->state;
104
+
105
+ return drm_atomic_helper_check_plane_state(plane->state, crtc_state,
106
+ DRM_PLANE_HELPER_NO_SCALING,
107
+ DRM_PLANE_HELPER_NO_SCALING,
108
+ true, true);
109
+}
110
+
111
+static void mtk_plane_atomic_async_update(struct drm_plane *plane,
112
+ struct drm_plane_state *new_state)
113
+{
114
+ struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
115
+
116
+ plane->state->crtc_x = new_state->crtc_x;
117
+ plane->state->crtc_y = new_state->crtc_y;
118
+ plane->state->crtc_h = new_state->crtc_h;
119
+ plane->state->crtc_w = new_state->crtc_w;
120
+ plane->state->src_x = new_state->src_x;
121
+ plane->state->src_y = new_state->src_y;
122
+ plane->state->src_h = new_state->src_h;
123
+ plane->state->src_w = new_state->src_w;
124
+ swap(plane->state->fb, new_state->fb);
125
+ state->pending.async_dirty = true;
126
+
127
+ mtk_drm_crtc_async_update(new_state->crtc, plane, new_state);
128
+}
129
+
80130 static const struct drm_plane_funcs mtk_plane_funcs = {
81131 .update_plane = drm_atomic_helper_update_plane,
82132 .disable_plane = drm_atomic_helper_disable_plane,
....@@ -91,12 +141,18 @@
91141 {
92142 struct drm_framebuffer *fb = state->fb;
93143 struct drm_crtc_state *crtc_state;
144
+ int ret;
94145
95146 if (!fb)
96147 return 0;
97148
98
- if (!state->crtc)
149
+ if (WARN_ON(!state->crtc))
99150 return 0;
151
+
152
+ ret = mtk_drm_crtc_plane_check(state->crtc, plane,
153
+ to_mtk_plane_state(state));
154
+ if (ret)
155
+ return ret;
100156
101157 crtc_state = drm_atomic_get_crtc_state(state->state, state->crtc);
102158 if (IS_ERR(crtc_state))
....@@ -154,18 +210,23 @@
154210 state->pending.y = plane->state->dst.y1;
155211 state->pending.width = drm_rect_width(&plane->state->dst);
156212 state->pending.height = drm_rect_height(&plane->state->dst);
213
+ state->pending.rotation = plane->state->rotation;
157214 wmb(); /* Make sure the above parameters are set before update */
158215 state->pending.dirty = true;
159216 }
160217
161218 static const struct drm_plane_helper_funcs mtk_plane_helper_funcs = {
219
+ .prepare_fb = drm_gem_fb_prepare_fb,
162220 .atomic_check = mtk_plane_atomic_check,
163221 .atomic_update = mtk_plane_atomic_update,
164222 .atomic_disable = mtk_plane_atomic_disable,
223
+ .atomic_async_update = mtk_plane_atomic_async_update,
224
+ .atomic_async_check = mtk_plane_atomic_async_check,
165225 };
166226
167227 int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane,
168
- unsigned long possible_crtcs, enum drm_plane_type type)
228
+ unsigned long possible_crtcs, enum drm_plane_type type,
229
+ unsigned int supported_rotations)
169230 {
170231 int err;
171232
....@@ -177,6 +238,14 @@
177238 return err;
178239 }
179240
241
+ if (supported_rotations & ~DRM_MODE_ROTATE_0) {
242
+ err = drm_plane_create_rotation_property(plane,
243
+ DRM_MODE_ROTATE_0,
244
+ supported_rotations);
245
+ if (err)
246
+ DRM_INFO("Create rotation property failed\n");
247
+ }
248
+
180249 drm_plane_helper_add(plane, &mtk_plane_helper_funcs);
181250
182251 return 0;