blob: 1a2992f178e51a93536b6a5aa3cd9479004a7f36 [file] [log] [blame]
Liviu Dudauad49f862016-03-07 10:00:53 +00001/*
2 * (C) COPYRIGHT 2016 ARM Limited. All rights reserved.
3 * Author: Liviu Dudau <Liviu.Dudau@arm.com>
4 *
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
8 * of such GNU licence.
9 *
10 * ARM Mali DP plane manipulation routines.
11 */
12
13#include <drm/drmP.h>
Liviu Dudaub9c33152016-11-25 14:28:54 +000014#include <drm/drm_atomic.h>
Liviu Dudauad49f862016-03-07 10:00:53 +000015#include <drm/drm_atomic_helper.h>
16#include <drm/drm_fb_cma_helper.h>
17#include <drm/drm_gem_cma_helper.h>
18#include <drm/drm_plane_helper.h>
Mihail Atanassov88d4d902017-01-23 15:12:02 +000019#include <drm/drm_print.h>
Liviu Dudauad49f862016-03-07 10:00:53 +000020
21#include "malidp_hw.h"
22#include "malidp_drv.h"
23
24/* Layer specific register offsets */
25#define MALIDP_LAYER_FORMAT 0x000
26#define MALIDP_LAYER_CONTROL 0x004
27#define LAYER_ENABLE (1 << 0)
Mihail Atanassov28ce6752017-02-13 15:14:05 +000028#define LAYER_FLOWCFG_MASK 7
29#define LAYER_FLOWCFG(x) (((x) & LAYER_FLOWCFG_MASK) << 1)
30#define LAYER_FLOWCFG_SCALE_SE 3
Liviu Dudauad49f862016-03-07 10:00:53 +000031#define LAYER_ROT_OFFSET 8
32#define LAYER_H_FLIP (1 << 10)
33#define LAYER_V_FLIP (1 << 11)
34#define LAYER_ROT_MASK (0xf << 8)
Brian Starkeyc57eb712016-10-11 15:26:08 +010035#define LAYER_COMP_MASK (0x3 << 12)
36#define LAYER_COMP_PIXEL (0x3 << 12)
37#define LAYER_COMP_PLANE (0x2 << 12)
Ayan Halderf0437812018-01-23 16:49:29 +000038#define LAYER_ALPHA_OFFSET (16)
39#define LAYER_ALPHA_MASK (0xff)
40#define LAYER_ALPHA(x) (((x) & LAYER_ALPHA_MASK) << LAYER_ALPHA_OFFSET)
Brian Starkeyc57eb712016-10-11 15:26:08 +010041#define MALIDP_LAYER_COMPOSE 0x008
Liviu Dudauad49f862016-03-07 10:00:53 +000042#define MALIDP_LAYER_SIZE 0x00c
43#define LAYER_H_VAL(x) (((x) & 0x1fff) << 0)
44#define LAYER_V_VAL(x) (((x) & 0x1fff) << 16)
45#define MALIDP_LAYER_COMP_SIZE 0x010
46#define MALIDP_LAYER_OFFSET 0x014
Mihail Atanassovd1479f62017-02-09 11:32:00 +000047#define MALIDP550_LS_ENABLE 0x01c
48#define MALIDP550_LS_R1_IN_SIZE 0x020
Liviu Dudauad49f862016-03-07 10:00:53 +000049
Brian Starkeyc57eb712016-10-11 15:26:08 +010050/*
51 * This 4-entry look-up-table is used to determine the full 8-bit alpha value
52 * for formats with 1- or 2-bit alpha channels.
53 * We set it to give 100%/0% opacity for 1-bit formats and 100%/66%/33%/0%
54 * opacity for 2-bit formats.
55 */
56#define MALIDP_ALPHA_LUT 0xffaa5500
57
Liviu Dudauad49f862016-03-07 10:00:53 +000058static void malidp_de_plane_destroy(struct drm_plane *plane)
59{
60 struct malidp_plane *mp = to_malidp_plane(plane);
61
62 if (mp->base.fb)
Cihangir Akturkc2cc2152017-08-11 15:32:48 +030063 drm_framebuffer_put(mp->base.fb);
Liviu Dudauad49f862016-03-07 10:00:53 +000064
65 drm_plane_helper_disable(plane);
66 drm_plane_cleanup(plane);
67 devm_kfree(plane->dev->dev, mp);
68}
69
Mihail Atanassovfe10cd62016-12-01 12:19:58 +000070/*
71 * Replicate what the default ->reset hook does: free the state pointer and
72 * allocate a new empty object. We just need enough space to store
73 * a malidp_plane_state instead of a drm_plane_state.
74 */
75static void malidp_plane_reset(struct drm_plane *plane)
76{
77 struct malidp_plane_state *state = to_malidp_plane_state(plane->state);
78
79 if (state)
80 __drm_atomic_helper_plane_destroy_state(&state->base);
81 kfree(state);
82 plane->state = NULL;
83 state = kzalloc(sizeof(*state), GFP_KERNEL);
84 if (state) {
85 state->base.plane = plane;
Robert Fossc2c446a2017-05-19 16:50:17 -040086 state->base.rotation = DRM_MODE_ROTATE_0;
Mihail Atanassovfe10cd62016-12-01 12:19:58 +000087 plane->state = &state->base;
88 }
89}
90
Baoyou Xieed8b0c02016-10-22 17:13:01 +080091static struct
92drm_plane_state *malidp_duplicate_plane_state(struct drm_plane *plane)
Liviu Dudauad49f862016-03-07 10:00:53 +000093{
94 struct malidp_plane_state *state, *m_state;
95
96 if (!plane->state)
97 return NULL;
98
99 state = kmalloc(sizeof(*state), GFP_KERNEL);
Shailendra Verma94d8b9b2016-11-11 13:35:00 +0000100 if (!state)
101 return NULL;
102
103 m_state = to_malidp_plane_state(plane->state);
104 __drm_atomic_helper_plane_duplicate_state(plane, &state->base);
105 state->rotmem_size = m_state->rotmem_size;
106 state->format = m_state->format;
107 state->n_planes = m_state->n_planes;
Liviu Dudauad49f862016-03-07 10:00:53 +0000108
109 return &state->base;
110}
111
Baoyou Xieed8b0c02016-10-22 17:13:01 +0800112static void malidp_destroy_plane_state(struct drm_plane *plane,
113 struct drm_plane_state *state)
Liviu Dudauad49f862016-03-07 10:00:53 +0000114{
115 struct malidp_plane_state *m_state = to_malidp_plane_state(state);
116
117 __drm_atomic_helper_plane_destroy_state(state);
118 kfree(m_state);
119}
120
Mihail Atanassov88d4d902017-01-23 15:12:02 +0000121static void malidp_plane_atomic_print_state(struct drm_printer *p,
122 const struct drm_plane_state *state)
123{
124 struct malidp_plane_state *ms = to_malidp_plane_state(state);
Mihail Atanassov88d4d902017-01-23 15:12:02 +0000125
126 drm_printf(p, "\trotmem_size=%u\n", ms->rotmem_size);
127 drm_printf(p, "\tformat_id=%u\n", ms->format);
128 drm_printf(p, "\tn_planes=%u\n", ms->n_planes);
129}
130
Liviu Dudauad49f862016-03-07 10:00:53 +0000131static const struct drm_plane_funcs malidp_de_plane_funcs = {
132 .update_plane = drm_atomic_helper_update_plane,
133 .disable_plane = drm_atomic_helper_disable_plane,
134 .destroy = malidp_de_plane_destroy,
Mihail Atanassovfe10cd62016-12-01 12:19:58 +0000135 .reset = malidp_plane_reset,
Liviu Dudauad49f862016-03-07 10:00:53 +0000136 .atomic_duplicate_state = malidp_duplicate_plane_state,
137 .atomic_destroy_state = malidp_destroy_plane_state,
Mihail Atanassov88d4d902017-01-23 15:12:02 +0000138 .atomic_print_state = malidp_plane_atomic_print_state,
Liviu Dudauad49f862016-03-07 10:00:53 +0000139};
140
Mihail Atanassov28ce6752017-02-13 15:14:05 +0000141static int malidp_se_check_scaling(struct malidp_plane *mp,
142 struct drm_plane_state *state)
143{
144 struct drm_crtc_state *crtc_state =
145 drm_atomic_get_existing_crtc_state(state->state, state->crtc);
146 struct malidp_crtc_state *mc;
Mihail Atanassov28ce6752017-02-13 15:14:05 +0000147 u32 src_w, src_h;
148 int ret;
149
150 if (!crtc_state)
151 return -EINVAL;
152
Dan Carpenterf2f2c852017-12-09 14:46:13 +0300153 mc = to_malidp_crtc_state(crtc_state);
154
Ville Syrjälä81af63a2018-01-23 19:08:57 +0200155 ret = drm_atomic_helper_check_plane_state(state, crtc_state,
Ville Syrjäläa01cb8b2017-11-01 22:16:19 +0200156 0, INT_MAX, true, true);
Mihail Atanassov28ce6752017-02-13 15:14:05 +0000157 if (ret)
158 return ret;
159
Liviu Dudaue0521c02017-12-15 16:42:19 +0000160 if (state->rotation & MALIDP_ROTATED_MASK) {
161 src_w = state->src_h >> 16;
162 src_h = state->src_w >> 16;
163 } else {
164 src_w = state->src_w >> 16;
165 src_h = state->src_h >> 16;
166 }
167
Mihail Atanassov28ce6752017-02-13 15:14:05 +0000168 if ((state->crtc_w == src_w) && (state->crtc_h == src_h)) {
169 /* Scaling not necessary for this plane. */
170 mc->scaled_planes_mask &= ~(mp->layer->id);
171 return 0;
172 }
173
174 if (mp->layer->id & (DE_SMART | DE_GRAPHICS2))
175 return -EINVAL;
176
Mihail Atanassov28ce6752017-02-13 15:14:05 +0000177 mc->scaled_planes_mask |= mp->layer->id;
178 /* Defer scaling requirements calculation to the crtc check. */
179 return 0;
180}
181
Liviu Dudauad49f862016-03-07 10:00:53 +0000182static int malidp_de_plane_check(struct drm_plane *plane,
183 struct drm_plane_state *state)
184{
185 struct malidp_plane *mp = to_malidp_plane(plane);
186 struct malidp_plane_state *ms = to_malidp_plane_state(state);
Liviu Dudaufcad73b2017-12-05 16:51:03 +0000187 bool rotated = state->rotation & MALIDP_ROTATED_MASK;
Brian Starkeya46a0962016-10-11 15:26:05 +0100188 struct drm_framebuffer *fb;
Liviu Dudaub9c33152016-11-25 14:28:54 +0000189 int i, ret;
Liviu Dudauad49f862016-03-07 10:00:53 +0000190
191 if (!state->crtc || !state->fb)
192 return 0;
193
Brian Starkeya46a0962016-10-11 15:26:05 +0100194 fb = state->fb;
195
Liviu Dudaua6993b22017-08-31 15:48:43 +0100196 ms->format = malidp_hw_get_format_id(&mp->hwdev->hw->map,
197 mp->layer->id,
198 fb->format->format);
Brian Starkey70c94a32016-10-11 15:26:09 +0100199 if (ms->format == MALIDP_INVALID_FORMAT_ID)
Liviu Dudauad49f862016-03-07 10:00:53 +0000200 return -EINVAL;
201
Ville Syrjäläbcb0b462016-12-14 23:30:22 +0200202 ms->n_planes = fb->format->num_planes;
Brian Starkey70c94a32016-10-11 15:26:09 +0100203 for (i = 0; i < ms->n_planes; i++) {
Liviu Dudaufcad73b2017-12-05 16:51:03 +0000204 u8 alignment = malidp_hw_get_pitch_align(mp->hwdev, rotated);
205 if (fb->pitches[i] & (alignment - 1)) {
Brian Starkeya46a0962016-10-11 15:26:05 +0100206 DRM_DEBUG_KMS("Invalid pitch %u for plane %d\n",
207 fb->pitches[i], i);
208 return -EINVAL;
209 }
210 }
211
Liviu Dudauad49f862016-03-07 10:00:53 +0000212 if ((state->crtc_w > mp->hwdev->max_line_size) ||
213 (state->crtc_h > mp->hwdev->max_line_size) ||
214 (state->crtc_w < mp->hwdev->min_line_size) ||
Brian Starkeyb2a2ddb2016-12-07 13:14:51 +0000215 (state->crtc_h < mp->hwdev->min_line_size))
Liviu Dudauad49f862016-03-07 10:00:53 +0000216 return -EINVAL;
217
Mihail Atanassov83d642e2017-01-23 15:24:35 +0000218 /*
219 * DP550/650 video layers can accept 3 plane formats only if
220 * fb->pitches[1] == fb->pitches[2] since they don't have a
221 * third plane stride register.
222 */
223 if (ms->n_planes == 3 &&
Liviu Dudaua6993b22017-08-31 15:48:43 +0100224 !(mp->hwdev->hw->features & MALIDP_DEVICE_LV_HAS_3_STRIDES) &&
Mihail Atanassov83d642e2017-01-23 15:24:35 +0000225 (state->fb->pitches[1] != state->fb->pitches[2]))
226 return -EINVAL;
227
Mihail Atanassov28ce6752017-02-13 15:14:05 +0000228 ret = malidp_se_check_scaling(mp, state);
229 if (ret)
230 return ret;
231
Liviu Dudauad49f862016-03-07 10:00:53 +0000232 /* packed RGB888 / BGR888 can't be rotated or flipped */
Robert Fossc2c446a2017-05-19 16:50:17 -0400233 if (state->rotation != DRM_MODE_ROTATE_0 &&
Ville Syrjälä438b74a2016-12-14 23:32:55 +0200234 (fb->format->format == DRM_FORMAT_RGB888 ||
235 fb->format->format == DRM_FORMAT_BGR888))
Liviu Dudauad49f862016-03-07 10:00:53 +0000236 return -EINVAL;
237
238 ms->rotmem_size = 0;
239 if (state->rotation & MALIDP_ROTATED_MASK) {
240 int val;
241
Liviu Dudaua6993b22017-08-31 15:48:43 +0100242 val = mp->hwdev->hw->rotmem_required(mp->hwdev, state->crtc_h,
243 state->crtc_w,
244 fb->format->format);
Liviu Dudauad49f862016-03-07 10:00:53 +0000245 if (val < 0)
246 return val;
247
248 ms->rotmem_size = val;
249 }
250
251 return 0;
252}
253
Mihail Atanassov83d642e2017-01-23 15:24:35 +0000254static void malidp_de_set_plane_pitches(struct malidp_plane *mp,
255 int num_planes, unsigned int pitches[3])
256{
257 int i;
258 int num_strides = num_planes;
259
260 if (!mp->layer->stride_offset)
261 return;
262
263 if (num_planes == 3)
Liviu Dudaua6993b22017-08-31 15:48:43 +0100264 num_strides = (mp->hwdev->hw->features &
Mihail Atanassov83d642e2017-01-23 15:24:35 +0000265 MALIDP_DEVICE_LV_HAS_3_STRIDES) ? 3 : 2;
266
267 for (i = 0; i < num_strides; ++i)
268 malidp_hw_write(mp->hwdev, pitches[i],
269 mp->layer->base +
270 mp->layer->stride_offset + i * 4);
271}
272
Liviu Dudauad49f862016-03-07 10:00:53 +0000273static void malidp_de_plane_update(struct drm_plane *plane,
274 struct drm_plane_state *old_state)
275{
Liviu Dudauad49f862016-03-07 10:00:53 +0000276 struct malidp_plane *mp;
Brian Starkey70c94a32016-10-11 15:26:09 +0100277 struct malidp_plane_state *ms = to_malidp_plane_state(plane->state);
Brian Starkey70c94a32016-10-11 15:26:09 +0100278 u32 src_w, src_h, dest_w, dest_h, val;
279 int i;
Ayan Halderf0437812018-01-23 16:49:29 +0000280 bool format_has_alpha = plane->state->fb->format->has_alpha;
Liviu Dudauad49f862016-03-07 10:00:53 +0000281
282 mp = to_malidp_plane(plane);
Liviu Dudauad49f862016-03-07 10:00:53 +0000283
284 /* convert src values from Q16 fixed point to integer */
285 src_w = plane->state->src_w >> 16;
286 src_h = plane->state->src_h >> 16;
Brian Starkeyedabb3c2016-12-07 13:17:21 +0000287 dest_w = plane->state->crtc_w;
288 dest_h = plane->state->crtc_h;
Liviu Dudauad49f862016-03-07 10:00:53 +0000289
Brian Starkey70c94a32016-10-11 15:26:09 +0100290 malidp_hw_write(mp->hwdev, ms->format, mp->layer->base);
Liviu Dudauad49f862016-03-07 10:00:53 +0000291
Brian Starkey70c94a32016-10-11 15:26:09 +0100292 for (i = 0; i < ms->n_planes; i++) {
Liviu Dudauad49f862016-03-07 10:00:53 +0000293 /* calculate the offset for the layer's plane registers */
Liviu Dudaue40eda32017-06-13 12:20:39 +0100294 u16 ptr = mp->layer->ptr + (i << 4);
295 dma_addr_t fb_addr = drm_fb_cma_get_gem_addr(plane->state->fb,
296 plane->state, i);
Liviu Dudauad49f862016-03-07 10:00:53 +0000297
Liviu Dudaue40eda32017-06-13 12:20:39 +0100298 malidp_hw_write(mp->hwdev, lower_32_bits(fb_addr), ptr);
299 malidp_hw_write(mp->hwdev, upper_32_bits(fb_addr), ptr + 4);
Liviu Dudauad49f862016-03-07 10:00:53 +0000300 }
Mihail Atanassov83d642e2017-01-23 15:24:35 +0000301 malidp_de_set_plane_pitches(mp, ms->n_planes,
302 plane->state->fb->pitches);
Liviu Dudauad49f862016-03-07 10:00:53 +0000303
304 malidp_hw_write(mp->hwdev, LAYER_H_VAL(src_w) | LAYER_V_VAL(src_h),
305 mp->layer->base + MALIDP_LAYER_SIZE);
306
307 malidp_hw_write(mp->hwdev, LAYER_H_VAL(dest_w) | LAYER_V_VAL(dest_h),
308 mp->layer->base + MALIDP_LAYER_COMP_SIZE);
309
310 malidp_hw_write(mp->hwdev, LAYER_H_VAL(plane->state->crtc_x) |
311 LAYER_V_VAL(plane->state->crtc_y),
312 mp->layer->base + MALIDP_LAYER_OFFSET);
313
Mihail Atanassovd1479f62017-02-09 11:32:00 +0000314 if (mp->layer->id == DE_SMART)
315 malidp_hw_write(mp->hwdev,
316 LAYER_H_VAL(src_w) | LAYER_V_VAL(src_h),
317 mp->layer->base + MALIDP550_LS_R1_IN_SIZE);
318
Brian Starkeyc57eb712016-10-11 15:26:08 +0100319 /* first clear the rotation bits */
320 val = malidp_hw_read(mp->hwdev, mp->layer->base + MALIDP_LAYER_CONTROL);
321 val &= ~LAYER_ROT_MASK;
Liviu Dudauad49f862016-03-07 10:00:53 +0000322
323 /* setup the rotation and axis flip bits */
Robert Fossc2c446a2017-05-19 16:50:17 -0400324 if (plane->state->rotation & DRM_MODE_ROTATE_MASK)
325 val |= ilog2(plane->state->rotation & DRM_MODE_ROTATE_MASK) <<
Mihail Atanassovc7ffa592016-12-23 09:57:20 +0000326 LAYER_ROT_OFFSET;
Robert Fossc2c446a2017-05-19 16:50:17 -0400327 if (plane->state->rotation & DRM_MODE_REFLECT_X)
Liviu Dudauad49f862016-03-07 10:00:53 +0000328 val |= LAYER_H_FLIP;
Robert Fossc2c446a2017-05-19 16:50:17 -0400329 if (plane->state->rotation & DRM_MODE_REFLECT_Y)
Brian Starkey7916efe2016-12-07 13:20:28 +0000330 val |= LAYER_V_FLIP;
Liviu Dudauad49f862016-03-07 10:00:53 +0000331
Brian Starkeyc57eb712016-10-11 15:26:08 +0100332 val &= ~LAYER_COMP_MASK;
Ayan Halderf0437812018-01-23 16:49:29 +0000333 if (format_has_alpha) {
334
335 /*
336 * always enable pixel alpha blending until we have a way
337 * to change blend modes
338 */
339 val |= LAYER_COMP_PIXEL;
340 } else {
341
342 /*
343 * do not enable pixel alpha blending as the color channel
344 * does not have any alpha information
345 */
346 val |= LAYER_COMP_PLANE;
347
348 /* Set layer alpha coefficient to 0xff ie fully opaque */
349 val |= LAYER_ALPHA(0xff);
350 }
Brian Starkeyc57eb712016-10-11 15:26:08 +0100351
Mihail Atanassov28ce6752017-02-13 15:14:05 +0000352 val &= ~LAYER_FLOWCFG(LAYER_FLOWCFG_MASK);
353 if (plane->state->crtc) {
354 struct malidp_crtc_state *m =
355 to_malidp_crtc_state(plane->state->crtc->state);
356
357 if (m->scaler_config.scale_enable &&
358 m->scaler_config.plane_src_id == mp->layer->id)
359 val |= LAYER_FLOWCFG(LAYER_FLOWCFG_SCALE_SE);
360 }
361
Liviu Dudauad49f862016-03-07 10:00:53 +0000362 /* set the 'enable layer' bit */
363 val |= LAYER_ENABLE;
364
Brian Starkeyc57eb712016-10-11 15:26:08 +0100365 malidp_hw_write(mp->hwdev, val,
366 mp->layer->base + MALIDP_LAYER_CONTROL);
Liviu Dudauad49f862016-03-07 10:00:53 +0000367}
368
369static void malidp_de_plane_disable(struct drm_plane *plane,
370 struct drm_plane_state *state)
371{
372 struct malidp_plane *mp = to_malidp_plane(plane);
373
Mihail Atanassov28ce6752017-02-13 15:14:05 +0000374 malidp_hw_clearbits(mp->hwdev,
375 LAYER_ENABLE | LAYER_FLOWCFG(LAYER_FLOWCFG_MASK),
Liviu Dudauad49f862016-03-07 10:00:53 +0000376 mp->layer->base + MALIDP_LAYER_CONTROL);
377}
378
379static const struct drm_plane_helper_funcs malidp_de_plane_helper_funcs = {
380 .atomic_check = malidp_de_plane_check,
381 .atomic_update = malidp_de_plane_update,
382 .atomic_disable = malidp_de_plane_disable,
383};
384
385int malidp_de_planes_init(struct drm_device *drm)
386{
387 struct malidp_drm *malidp = drm->dev_private;
Liviu Dudaua6993b22017-08-31 15:48:43 +0100388 const struct malidp_hw_regmap *map = &malidp->dev->hw->map;
Liviu Dudauad49f862016-03-07 10:00:53 +0000389 struct malidp_plane *plane = NULL;
390 enum drm_plane_type plane_type;
391 unsigned long crtcs = 1 << drm->mode_config.num_crtc;
Robert Fossc2c446a2017-05-19 16:50:17 -0400392 unsigned long flags = DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_180 |
393 DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y;
Liviu Dudauad49f862016-03-07 10:00:53 +0000394 u32 *formats;
395 int ret, i, j, n;
396
Brian Starkey6211b482016-10-03 15:08:12 +0100397 formats = kcalloc(map->n_pixel_formats, sizeof(*formats), GFP_KERNEL);
Liviu Dudauad49f862016-03-07 10:00:53 +0000398 if (!formats) {
399 ret = -ENOMEM;
400 goto cleanup;
401 }
402
403 for (i = 0; i < map->n_layers; i++) {
404 u8 id = map->layers[i].id;
405
406 plane = kzalloc(sizeof(*plane), GFP_KERNEL);
407 if (!plane) {
408 ret = -ENOMEM;
409 goto cleanup;
410 }
411
412 /* build the list of DRM supported formats based on the map */
Brian Starkey6211b482016-10-03 15:08:12 +0100413 for (n = 0, j = 0; j < map->n_pixel_formats; j++) {
414 if ((map->pixel_formats[j].layer & id) == id)
415 formats[n++] = map->pixel_formats[j].format;
Liviu Dudauad49f862016-03-07 10:00:53 +0000416 }
417
418 plane_type = (i == 0) ? DRM_PLANE_TYPE_PRIMARY :
419 DRM_PLANE_TYPE_OVERLAY;
420 ret = drm_universal_plane_init(drm, &plane->base, crtcs,
421 &malidp_de_plane_funcs, formats,
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700422 n, NULL, plane_type, NULL);
Liviu Dudauad49f862016-03-07 10:00:53 +0000423 if (ret < 0)
424 goto cleanup;
425
Liviu Dudauad49f862016-03-07 10:00:53 +0000426 drm_plane_helper_add(&plane->base,
427 &malidp_de_plane_helper_funcs);
428 plane->hwdev = malidp->dev;
429 plane->layer = &map->layers[i];
Brian Starkey15807782016-10-11 15:26:07 +0100430
Mihail Atanassovd1479f62017-02-09 11:32:00 +0000431 if (id == DE_SMART) {
432 /*
433 * Enable the first rectangle in the SMART layer to be
434 * able to use it as a drm plane.
435 */
436 malidp_hw_write(malidp->dev, 1,
437 plane->layer->base + MALIDP550_LS_ENABLE);
438 /* Skip the features which the SMART layer doesn't have. */
Brian Starkey15807782016-10-11 15:26:07 +0100439 continue;
Mihail Atanassovd1479f62017-02-09 11:32:00 +0000440 }
Brian Starkey15807782016-10-11 15:26:07 +0100441
Robert Fossc2c446a2017-05-19 16:50:17 -0400442 drm_plane_create_rotation_property(&plane->base, DRM_MODE_ROTATE_0, flags);
Brian Starkeyc57eb712016-10-11 15:26:08 +0100443 malidp_hw_write(malidp->dev, MALIDP_ALPHA_LUT,
444 plane->layer->base + MALIDP_LAYER_COMPOSE);
Liviu Dudauad49f862016-03-07 10:00:53 +0000445 }
446
447 kfree(formats);
448
449 return 0;
450
451cleanup:
452 malidp_de_planes_destroy(drm);
453 kfree(formats);
454
455 return ret;
456}
457
458void malidp_de_planes_destroy(struct drm_device *drm)
459{
460 struct drm_plane *p, *pt;
461
462 list_for_each_entry_safe(p, pt, &drm->mode_config.plane_list, head) {
463 drm_plane_cleanup(p);
464 kfree(p);
465 }
466}