forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/gpu/drm/sun4i/sun4i_layer.c
....@@ -1,18 +1,14 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2015 Free Electrons
34 * Copyright (C) 2015 NextThing Co
45 *
56 * Maxime Ripard <maxime.ripard@free-electrons.com>
6
- *
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License as
9
- * published by the Free Software Foundation; either version 2 of
10
- * the License, or (at your option) any later version.
117 */
128
139 #include <drm/drm_atomic_helper.h>
10
+#include <drm/drm_gem_framebuffer_helper.h>
1411 #include <drm/drm_plane_helper.h>
15
-#include <drm/drmP.h>
1612
1713 #include "sun4i_backend.h"
1814 #include "sun4i_frontend.h"
....@@ -35,9 +31,7 @@
3531
3632 state = kzalloc(sizeof(*state), GFP_KERNEL);
3733 if (state) {
38
- plane->state = &state->state;
39
- plane->state->plane = plane;
40
- plane->state->alpha = DRM_BLEND_ALPHA_OPAQUE;
34
+ __drm_atomic_helper_plane_reset(plane, &state->state);
4135 plane->state->zpos = layer->id;
4236 }
4337 }
....@@ -94,14 +88,16 @@
9488 struct sun4i_backend *backend = layer->backend;
9589 struct sun4i_frontend *frontend = backend->frontend;
9690
91
+ sun4i_backend_cleanup_layer(backend, layer->id);
92
+
9793 if (layer_state->uses_frontend) {
9894 sun4i_frontend_init(frontend);
9995 sun4i_frontend_update_coord(frontend, plane);
10096 sun4i_frontend_update_buffer(frontend, plane);
10197 sun4i_frontend_update_formats(frontend, plane,
102
- DRM_FORMAT_ARGB8888);
98
+ DRM_FORMAT_XRGB8888);
10399 sun4i_backend_update_layer_frontend(backend, layer->id,
104
- DRM_FORMAT_ARGB8888);
100
+ DRM_FORMAT_XRGB8888);
105101 sun4i_frontend_enable(frontend);
106102 } else {
107103 sun4i_backend_update_layer_formats(backend, layer->id, plane);
....@@ -113,7 +109,20 @@
113109 sun4i_backend_layer_enable(backend, layer->id, true);
114110 }
115111
112
+static bool sun4i_layer_format_mod_supported(struct drm_plane *plane,
113
+ uint32_t format, uint64_t modifier)
114
+{
115
+ struct sun4i_layer *layer = plane_to_sun4i_layer(plane);
116
+
117
+ if (IS_ERR_OR_NULL(layer->backend->frontend))
118
+ sun4i_backend_format_is_supported(format, modifier);
119
+
120
+ return sun4i_backend_format_is_supported(format, modifier) ||
121
+ sun4i_frontend_format_is_supported(format, modifier);
122
+}
123
+
116124 static const struct drm_plane_helper_funcs sun4i_backend_layer_helper_funcs = {
125
+ .prepare_fb = drm_gem_fb_prepare_fb,
117126 .atomic_disable = sun4i_backend_layer_atomic_disable,
118127 .atomic_update = sun4i_backend_layer_atomic_update,
119128 };
....@@ -125,6 +134,35 @@
125134 .disable_plane = drm_atomic_helper_disable_plane,
126135 .reset = sun4i_backend_layer_reset,
127136 .update_plane = drm_atomic_helper_update_plane,
137
+ .format_mod_supported = sun4i_layer_format_mod_supported,
138
+};
139
+
140
+static const uint32_t sun4i_layer_formats[] = {
141
+ DRM_FORMAT_ARGB8888,
142
+ DRM_FORMAT_ARGB4444,
143
+ DRM_FORMAT_ARGB1555,
144
+ DRM_FORMAT_BGRX8888,
145
+ DRM_FORMAT_RGBA5551,
146
+ DRM_FORMAT_RGBA4444,
147
+ DRM_FORMAT_RGB888,
148
+ DRM_FORMAT_RGB565,
149
+ DRM_FORMAT_NV12,
150
+ DRM_FORMAT_NV16,
151
+ DRM_FORMAT_NV21,
152
+ DRM_FORMAT_NV61,
153
+ DRM_FORMAT_UYVY,
154
+ DRM_FORMAT_VYUY,
155
+ DRM_FORMAT_XRGB8888,
156
+ DRM_FORMAT_YUV411,
157
+ DRM_FORMAT_YUV420,
158
+ DRM_FORMAT_YUV422,
159
+ DRM_FORMAT_YUV444,
160
+ DRM_FORMAT_YUYV,
161
+ DRM_FORMAT_YVU411,
162
+ DRM_FORMAT_YVU420,
163
+ DRM_FORMAT_YVU422,
164
+ DRM_FORMAT_YVU444,
165
+ DRM_FORMAT_YVYU,
128166 };
129167
130168 static const uint32_t sun4i_backend_layer_formats[] = {
....@@ -142,10 +180,19 @@
142180 DRM_FORMAT_YVYU,
143181 };
144182
183
+static const uint64_t sun4i_layer_modifiers[] = {
184
+ DRM_FORMAT_MOD_LINEAR,
185
+ DRM_FORMAT_MOD_ALLWINNER_TILED,
186
+ DRM_FORMAT_MOD_INVALID
187
+};
188
+
145189 static struct sun4i_layer *sun4i_layer_init_one(struct drm_device *drm,
146190 struct sun4i_backend *backend,
147191 enum drm_plane_type type)
148192 {
193
+ const uint64_t *modifiers = sun4i_layer_modifiers;
194
+ const uint32_t *formats = sun4i_layer_formats;
195
+ unsigned int formats_len = ARRAY_SIZE(sun4i_layer_formats);
149196 struct sun4i_layer *layer;
150197 int ret;
151198
....@@ -153,12 +200,19 @@
153200 if (!layer)
154201 return ERR_PTR(-ENOMEM);
155202
203
+ layer->backend = backend;
204
+
205
+ if (IS_ERR_OR_NULL(backend->frontend)) {
206
+ formats = sun4i_backend_layer_formats;
207
+ formats_len = ARRAY_SIZE(sun4i_backend_layer_formats);
208
+ modifiers = NULL;
209
+ }
210
+
156211 /* possible crtcs are set later */
157212 ret = drm_universal_plane_init(drm, &layer->plane, 0,
158213 &sun4i_backend_layer_funcs,
159
- sun4i_backend_layer_formats,
160
- ARRAY_SIZE(sun4i_backend_layer_formats),
161
- NULL, type, NULL);
214
+ formats, formats_len,
215
+ modifiers, type, NULL);
162216 if (ret) {
163217 dev_err(drm->dev, "Couldn't initialize layer\n");
164218 return ERR_PTR(ret);
....@@ -166,7 +220,6 @@
166220
167221 drm_plane_helper_add(&layer->plane,
168222 &sun4i_backend_layer_helper_funcs);
169
- layer->backend = backend;
170223
171224 drm_plane_create_alpha_property(&layer->plane);
172225 drm_plane_create_zpos_property(&layer->plane, 0, 0,
....@@ -197,11 +250,11 @@
197250 dev_err(drm->dev, "Couldn't initialize %s plane\n",
198251 i ? "overlay" : "primary");
199252 return ERR_CAST(layer);
200
- };
253
+ }
201254
202255 layer->id = i;
203256 planes[i] = &layer->plane;
204
- };
257
+ }
205258
206259 return planes;
207260 }