.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2015 Free Electrons |
---|
3 | 4 | * Copyright (C) 2015 NextThing Co |
---|
4 | 5 | * |
---|
5 | 6 | * 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. |
---|
11 | 7 | */ |
---|
12 | 8 | |
---|
13 | 9 | #include <drm/drm_atomic_helper.h> |
---|
| 10 | +#include <drm/drm_gem_framebuffer_helper.h> |
---|
14 | 11 | #include <drm/drm_plane_helper.h> |
---|
15 | | -#include <drm/drmP.h> |
---|
16 | 12 | |
---|
17 | 13 | #include "sun4i_backend.h" |
---|
18 | 14 | #include "sun4i_frontend.h" |
---|
.. | .. |
---|
35 | 31 | |
---|
36 | 32 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
---|
37 | 33 | 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); |
---|
41 | 35 | plane->state->zpos = layer->id; |
---|
42 | 36 | } |
---|
43 | 37 | } |
---|
.. | .. |
---|
94 | 88 | struct sun4i_backend *backend = layer->backend; |
---|
95 | 89 | struct sun4i_frontend *frontend = backend->frontend; |
---|
96 | 90 | |
---|
| 91 | + sun4i_backend_cleanup_layer(backend, layer->id); |
---|
| 92 | + |
---|
97 | 93 | if (layer_state->uses_frontend) { |
---|
98 | 94 | sun4i_frontend_init(frontend); |
---|
99 | 95 | sun4i_frontend_update_coord(frontend, plane); |
---|
100 | 96 | sun4i_frontend_update_buffer(frontend, plane); |
---|
101 | 97 | sun4i_frontend_update_formats(frontend, plane, |
---|
102 | | - DRM_FORMAT_ARGB8888); |
---|
| 98 | + DRM_FORMAT_XRGB8888); |
---|
103 | 99 | sun4i_backend_update_layer_frontend(backend, layer->id, |
---|
104 | | - DRM_FORMAT_ARGB8888); |
---|
| 100 | + DRM_FORMAT_XRGB8888); |
---|
105 | 101 | sun4i_frontend_enable(frontend); |
---|
106 | 102 | } else { |
---|
107 | 103 | sun4i_backend_update_layer_formats(backend, layer->id, plane); |
---|
.. | .. |
---|
113 | 109 | sun4i_backend_layer_enable(backend, layer->id, true); |
---|
114 | 110 | } |
---|
115 | 111 | |
---|
| 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 | + |
---|
116 | 124 | static const struct drm_plane_helper_funcs sun4i_backend_layer_helper_funcs = { |
---|
| 125 | + .prepare_fb = drm_gem_fb_prepare_fb, |
---|
117 | 126 | .atomic_disable = sun4i_backend_layer_atomic_disable, |
---|
118 | 127 | .atomic_update = sun4i_backend_layer_atomic_update, |
---|
119 | 128 | }; |
---|
.. | .. |
---|
125 | 134 | .disable_plane = drm_atomic_helper_disable_plane, |
---|
126 | 135 | .reset = sun4i_backend_layer_reset, |
---|
127 | 136 | .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, |
---|
128 | 166 | }; |
---|
129 | 167 | |
---|
130 | 168 | static const uint32_t sun4i_backend_layer_formats[] = { |
---|
.. | .. |
---|
142 | 180 | DRM_FORMAT_YVYU, |
---|
143 | 181 | }; |
---|
144 | 182 | |
---|
| 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 | + |
---|
145 | 189 | static struct sun4i_layer *sun4i_layer_init_one(struct drm_device *drm, |
---|
146 | 190 | struct sun4i_backend *backend, |
---|
147 | 191 | enum drm_plane_type type) |
---|
148 | 192 | { |
---|
| 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); |
---|
149 | 196 | struct sun4i_layer *layer; |
---|
150 | 197 | int ret; |
---|
151 | 198 | |
---|
.. | .. |
---|
153 | 200 | if (!layer) |
---|
154 | 201 | return ERR_PTR(-ENOMEM); |
---|
155 | 202 | |
---|
| 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 | + |
---|
156 | 211 | /* possible crtcs are set later */ |
---|
157 | 212 | ret = drm_universal_plane_init(drm, &layer->plane, 0, |
---|
158 | 213 | &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); |
---|
162 | 216 | if (ret) { |
---|
163 | 217 | dev_err(drm->dev, "Couldn't initialize layer\n"); |
---|
164 | 218 | return ERR_PTR(ret); |
---|
.. | .. |
---|
166 | 220 | |
---|
167 | 221 | drm_plane_helper_add(&layer->plane, |
---|
168 | 222 | &sun4i_backend_layer_helper_funcs); |
---|
169 | | - layer->backend = backend; |
---|
170 | 223 | |
---|
171 | 224 | drm_plane_create_alpha_property(&layer->plane); |
---|
172 | 225 | drm_plane_create_zpos_property(&layer->plane, 0, 0, |
---|
.. | .. |
---|
197 | 250 | dev_err(drm->dev, "Couldn't initialize %s plane\n", |
---|
198 | 251 | i ? "overlay" : "primary"); |
---|
199 | 252 | return ERR_CAST(layer); |
---|
200 | | - }; |
---|
| 253 | + } |
---|
201 | 254 | |
---|
202 | 255 | layer->id = i; |
---|
203 | 256 | planes[i] = &layer->plane; |
---|
204 | | - }; |
---|
| 257 | + } |
---|
205 | 258 | |
---|
206 | 259 | return planes; |
---|
207 | 260 | } |
---|