Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 1 | /* |
| 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 Dudau | b9c3315 | 2016-11-25 14:28:54 +0000 | [diff] [blame] | 14 | #include <drm/drm_atomic.h> |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 15 | #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 Atanassov | 88d4d90 | 2017-01-23 15:12:02 +0000 | [diff] [blame] | 19 | #include <drm/drm_print.h> |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 20 | |
| 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 Atanassov | 28ce675 | 2017-02-13 15:14:05 +0000 | [diff] [blame] | 28 | #define LAYER_FLOWCFG_MASK 7 |
| 29 | #define LAYER_FLOWCFG(x) (((x) & LAYER_FLOWCFG_MASK) << 1) |
| 30 | #define LAYER_FLOWCFG_SCALE_SE 3 |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 31 | #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 Starkey | c57eb71 | 2016-10-11 15:26:08 +0100 | [diff] [blame] | 35 | #define LAYER_COMP_MASK (0x3 << 12) |
| 36 | #define LAYER_COMP_PIXEL (0x3 << 12) |
| 37 | #define LAYER_COMP_PLANE (0x2 << 12) |
Ayan Halder | f043781 | 2018-01-23 16:49:29 +0000 | [diff] [blame^] | 38 | #define LAYER_ALPHA_OFFSET (16) |
| 39 | #define LAYER_ALPHA_MASK (0xff) |
| 40 | #define LAYER_ALPHA(x) (((x) & LAYER_ALPHA_MASK) << LAYER_ALPHA_OFFSET) |
Brian Starkey | c57eb71 | 2016-10-11 15:26:08 +0100 | [diff] [blame] | 41 | #define MALIDP_LAYER_COMPOSE 0x008 |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 42 | #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 Atanassov | d1479f6 | 2017-02-09 11:32:00 +0000 | [diff] [blame] | 47 | #define MALIDP550_LS_ENABLE 0x01c |
| 48 | #define MALIDP550_LS_R1_IN_SIZE 0x020 |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 49 | |
Brian Starkey | c57eb71 | 2016-10-11 15:26:08 +0100 | [diff] [blame] | 50 | /* |
| 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 Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 58 | static 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 Akturk | c2cc215 | 2017-08-11 15:32:48 +0300 | [diff] [blame] | 63 | drm_framebuffer_put(mp->base.fb); |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 64 | |
| 65 | drm_plane_helper_disable(plane); |
| 66 | drm_plane_cleanup(plane); |
| 67 | devm_kfree(plane->dev->dev, mp); |
| 68 | } |
| 69 | |
Mihail Atanassov | fe10cd6 | 2016-12-01 12:19:58 +0000 | [diff] [blame] | 70 | /* |
| 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 | */ |
| 75 | static 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 Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 86 | state->base.rotation = DRM_MODE_ROTATE_0; |
Mihail Atanassov | fe10cd6 | 2016-12-01 12:19:58 +0000 | [diff] [blame] | 87 | plane->state = &state->base; |
| 88 | } |
| 89 | } |
| 90 | |
Baoyou Xie | ed8b0c0 | 2016-10-22 17:13:01 +0800 | [diff] [blame] | 91 | static struct |
| 92 | drm_plane_state *malidp_duplicate_plane_state(struct drm_plane *plane) |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 93 | { |
| 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 Verma | 94d8b9b | 2016-11-11 13:35:00 +0000 | [diff] [blame] | 100 | 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 Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 108 | |
| 109 | return &state->base; |
| 110 | } |
| 111 | |
Baoyou Xie | ed8b0c0 | 2016-10-22 17:13:01 +0800 | [diff] [blame] | 112 | static void malidp_destroy_plane_state(struct drm_plane *plane, |
| 113 | struct drm_plane_state *state) |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 114 | { |
| 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 Atanassov | 88d4d90 | 2017-01-23 15:12:02 +0000 | [diff] [blame] | 121 | static 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 Atanassov | 88d4d90 | 2017-01-23 15:12:02 +0000 | [diff] [blame] | 125 | |
| 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 Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 131 | static 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 Atanassov | fe10cd6 | 2016-12-01 12:19:58 +0000 | [diff] [blame] | 135 | .reset = malidp_plane_reset, |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 136 | .atomic_duplicate_state = malidp_duplicate_plane_state, |
| 137 | .atomic_destroy_state = malidp_destroy_plane_state, |
Mihail Atanassov | 88d4d90 | 2017-01-23 15:12:02 +0000 | [diff] [blame] | 138 | .atomic_print_state = malidp_plane_atomic_print_state, |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
Mihail Atanassov | 28ce675 | 2017-02-13 15:14:05 +0000 | [diff] [blame] | 141 | static 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 Atanassov | 28ce675 | 2017-02-13 15:14:05 +0000 | [diff] [blame] | 147 | u32 src_w, src_h; |
| 148 | int ret; |
| 149 | |
| 150 | if (!crtc_state) |
| 151 | return -EINVAL; |
| 152 | |
Dan Carpenter | f2f2c85 | 2017-12-09 14:46:13 +0300 | [diff] [blame] | 153 | mc = to_malidp_crtc_state(crtc_state); |
| 154 | |
Ville Syrjälä | 81af63a | 2018-01-23 19:08:57 +0200 | [diff] [blame] | 155 | ret = drm_atomic_helper_check_plane_state(state, crtc_state, |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 156 | 0, INT_MAX, true, true); |
Mihail Atanassov | 28ce675 | 2017-02-13 15:14:05 +0000 | [diff] [blame] | 157 | if (ret) |
| 158 | return ret; |
| 159 | |
Liviu Dudau | e0521c0 | 2017-12-15 16:42:19 +0000 | [diff] [blame] | 160 | 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 Atanassov | 28ce675 | 2017-02-13 15:14:05 +0000 | [diff] [blame] | 168 | 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 Atanassov | 28ce675 | 2017-02-13 15:14:05 +0000 | [diff] [blame] | 177 | mc->scaled_planes_mask |= mp->layer->id; |
| 178 | /* Defer scaling requirements calculation to the crtc check. */ |
| 179 | return 0; |
| 180 | } |
| 181 | |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 182 | static 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 Dudau | fcad73b | 2017-12-05 16:51:03 +0000 | [diff] [blame] | 187 | bool rotated = state->rotation & MALIDP_ROTATED_MASK; |
Brian Starkey | a46a096 | 2016-10-11 15:26:05 +0100 | [diff] [blame] | 188 | struct drm_framebuffer *fb; |
Liviu Dudau | b9c3315 | 2016-11-25 14:28:54 +0000 | [diff] [blame] | 189 | int i, ret; |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 190 | |
| 191 | if (!state->crtc || !state->fb) |
| 192 | return 0; |
| 193 | |
Brian Starkey | a46a096 | 2016-10-11 15:26:05 +0100 | [diff] [blame] | 194 | fb = state->fb; |
| 195 | |
Liviu Dudau | a6993b2 | 2017-08-31 15:48:43 +0100 | [diff] [blame] | 196 | ms->format = malidp_hw_get_format_id(&mp->hwdev->hw->map, |
| 197 | mp->layer->id, |
| 198 | fb->format->format); |
Brian Starkey | 70c94a3 | 2016-10-11 15:26:09 +0100 | [diff] [blame] | 199 | if (ms->format == MALIDP_INVALID_FORMAT_ID) |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 200 | return -EINVAL; |
| 201 | |
Ville Syrjälä | bcb0b46 | 2016-12-14 23:30:22 +0200 | [diff] [blame] | 202 | ms->n_planes = fb->format->num_planes; |
Brian Starkey | 70c94a3 | 2016-10-11 15:26:09 +0100 | [diff] [blame] | 203 | for (i = 0; i < ms->n_planes; i++) { |
Liviu Dudau | fcad73b | 2017-12-05 16:51:03 +0000 | [diff] [blame] | 204 | u8 alignment = malidp_hw_get_pitch_align(mp->hwdev, rotated); |
| 205 | if (fb->pitches[i] & (alignment - 1)) { |
Brian Starkey | a46a096 | 2016-10-11 15:26:05 +0100 | [diff] [blame] | 206 | DRM_DEBUG_KMS("Invalid pitch %u for plane %d\n", |
| 207 | fb->pitches[i], i); |
| 208 | return -EINVAL; |
| 209 | } |
| 210 | } |
| 211 | |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 212 | 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 Starkey | b2a2ddb | 2016-12-07 13:14:51 +0000 | [diff] [blame] | 215 | (state->crtc_h < mp->hwdev->min_line_size)) |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 216 | return -EINVAL; |
| 217 | |
Mihail Atanassov | 83d642e | 2017-01-23 15:24:35 +0000 | [diff] [blame] | 218 | /* |
| 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 Dudau | a6993b2 | 2017-08-31 15:48:43 +0100 | [diff] [blame] | 224 | !(mp->hwdev->hw->features & MALIDP_DEVICE_LV_HAS_3_STRIDES) && |
Mihail Atanassov | 83d642e | 2017-01-23 15:24:35 +0000 | [diff] [blame] | 225 | (state->fb->pitches[1] != state->fb->pitches[2])) |
| 226 | return -EINVAL; |
| 227 | |
Mihail Atanassov | 28ce675 | 2017-02-13 15:14:05 +0000 | [diff] [blame] | 228 | ret = malidp_se_check_scaling(mp, state); |
| 229 | if (ret) |
| 230 | return ret; |
| 231 | |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 232 | /* packed RGB888 / BGR888 can't be rotated or flipped */ |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 233 | if (state->rotation != DRM_MODE_ROTATE_0 && |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 234 | (fb->format->format == DRM_FORMAT_RGB888 || |
| 235 | fb->format->format == DRM_FORMAT_BGR888)) |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 236 | return -EINVAL; |
| 237 | |
| 238 | ms->rotmem_size = 0; |
| 239 | if (state->rotation & MALIDP_ROTATED_MASK) { |
| 240 | int val; |
| 241 | |
Liviu Dudau | a6993b2 | 2017-08-31 15:48:43 +0100 | [diff] [blame] | 242 | val = mp->hwdev->hw->rotmem_required(mp->hwdev, state->crtc_h, |
| 243 | state->crtc_w, |
| 244 | fb->format->format); |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 245 | if (val < 0) |
| 246 | return val; |
| 247 | |
| 248 | ms->rotmem_size = val; |
| 249 | } |
| 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
Mihail Atanassov | 83d642e | 2017-01-23 15:24:35 +0000 | [diff] [blame] | 254 | static 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 Dudau | a6993b2 | 2017-08-31 15:48:43 +0100 | [diff] [blame] | 264 | num_strides = (mp->hwdev->hw->features & |
Mihail Atanassov | 83d642e | 2017-01-23 15:24:35 +0000 | [diff] [blame] | 265 | 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 Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 273 | static void malidp_de_plane_update(struct drm_plane *plane, |
| 274 | struct drm_plane_state *old_state) |
| 275 | { |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 276 | struct malidp_plane *mp; |
Brian Starkey | 70c94a3 | 2016-10-11 15:26:09 +0100 | [diff] [blame] | 277 | struct malidp_plane_state *ms = to_malidp_plane_state(plane->state); |
Brian Starkey | 70c94a3 | 2016-10-11 15:26:09 +0100 | [diff] [blame] | 278 | u32 src_w, src_h, dest_w, dest_h, val; |
| 279 | int i; |
Ayan Halder | f043781 | 2018-01-23 16:49:29 +0000 | [diff] [blame^] | 280 | bool format_has_alpha = plane->state->fb->format->has_alpha; |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 281 | |
| 282 | mp = to_malidp_plane(plane); |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 283 | |
| 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 Starkey | edabb3c | 2016-12-07 13:17:21 +0000 | [diff] [blame] | 287 | dest_w = plane->state->crtc_w; |
| 288 | dest_h = plane->state->crtc_h; |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 289 | |
Brian Starkey | 70c94a3 | 2016-10-11 15:26:09 +0100 | [diff] [blame] | 290 | malidp_hw_write(mp->hwdev, ms->format, mp->layer->base); |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 291 | |
Brian Starkey | 70c94a3 | 2016-10-11 15:26:09 +0100 | [diff] [blame] | 292 | for (i = 0; i < ms->n_planes; i++) { |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 293 | /* calculate the offset for the layer's plane registers */ |
Liviu Dudau | e40eda3 | 2017-06-13 12:20:39 +0100 | [diff] [blame] | 294 | 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 Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 297 | |
Liviu Dudau | e40eda3 | 2017-06-13 12:20:39 +0100 | [diff] [blame] | 298 | 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 Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 300 | } |
Mihail Atanassov | 83d642e | 2017-01-23 15:24:35 +0000 | [diff] [blame] | 301 | malidp_de_set_plane_pitches(mp, ms->n_planes, |
| 302 | plane->state->fb->pitches); |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 303 | |
| 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 Atanassov | d1479f6 | 2017-02-09 11:32:00 +0000 | [diff] [blame] | 314 | 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 Starkey | c57eb71 | 2016-10-11 15:26:08 +0100 | [diff] [blame] | 319 | /* first clear the rotation bits */ |
| 320 | val = malidp_hw_read(mp->hwdev, mp->layer->base + MALIDP_LAYER_CONTROL); |
| 321 | val &= ~LAYER_ROT_MASK; |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 322 | |
| 323 | /* setup the rotation and axis flip bits */ |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 324 | if (plane->state->rotation & DRM_MODE_ROTATE_MASK) |
| 325 | val |= ilog2(plane->state->rotation & DRM_MODE_ROTATE_MASK) << |
Mihail Atanassov | c7ffa59 | 2016-12-23 09:57:20 +0000 | [diff] [blame] | 326 | LAYER_ROT_OFFSET; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 327 | if (plane->state->rotation & DRM_MODE_REFLECT_X) |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 328 | val |= LAYER_H_FLIP; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 329 | if (plane->state->rotation & DRM_MODE_REFLECT_Y) |
Brian Starkey | 7916efe | 2016-12-07 13:20:28 +0000 | [diff] [blame] | 330 | val |= LAYER_V_FLIP; |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 331 | |
Brian Starkey | c57eb71 | 2016-10-11 15:26:08 +0100 | [diff] [blame] | 332 | val &= ~LAYER_COMP_MASK; |
Ayan Halder | f043781 | 2018-01-23 16:49:29 +0000 | [diff] [blame^] | 333 | 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 Starkey | c57eb71 | 2016-10-11 15:26:08 +0100 | [diff] [blame] | 351 | |
Mihail Atanassov | 28ce675 | 2017-02-13 15:14:05 +0000 | [diff] [blame] | 352 | 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 Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 362 | /* set the 'enable layer' bit */ |
| 363 | val |= LAYER_ENABLE; |
| 364 | |
Brian Starkey | c57eb71 | 2016-10-11 15:26:08 +0100 | [diff] [blame] | 365 | malidp_hw_write(mp->hwdev, val, |
| 366 | mp->layer->base + MALIDP_LAYER_CONTROL); |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | static 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 Atanassov | 28ce675 | 2017-02-13 15:14:05 +0000 | [diff] [blame] | 374 | malidp_hw_clearbits(mp->hwdev, |
| 375 | LAYER_ENABLE | LAYER_FLOWCFG(LAYER_FLOWCFG_MASK), |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 376 | mp->layer->base + MALIDP_LAYER_CONTROL); |
| 377 | } |
| 378 | |
| 379 | static 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 | |
| 385 | int malidp_de_planes_init(struct drm_device *drm) |
| 386 | { |
| 387 | struct malidp_drm *malidp = drm->dev_private; |
Liviu Dudau | a6993b2 | 2017-08-31 15:48:43 +0100 | [diff] [blame] | 388 | const struct malidp_hw_regmap *map = &malidp->dev->hw->map; |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 389 | struct malidp_plane *plane = NULL; |
| 390 | enum drm_plane_type plane_type; |
| 391 | unsigned long crtcs = 1 << drm->mode_config.num_crtc; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 392 | 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 Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 394 | u32 *formats; |
| 395 | int ret, i, j, n; |
| 396 | |
Brian Starkey | 6211b48 | 2016-10-03 15:08:12 +0100 | [diff] [blame] | 397 | formats = kcalloc(map->n_pixel_formats, sizeof(*formats), GFP_KERNEL); |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 398 | 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 Starkey | 6211b48 | 2016-10-03 15:08:12 +0100 | [diff] [blame] | 413 | 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 Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 416 | } |
| 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 Widawsky | e6fc3b6 | 2017-07-23 20:46:38 -0700 | [diff] [blame] | 422 | n, NULL, plane_type, NULL); |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 423 | if (ret < 0) |
| 424 | goto cleanup; |
| 425 | |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 426 | drm_plane_helper_add(&plane->base, |
| 427 | &malidp_de_plane_helper_funcs); |
| 428 | plane->hwdev = malidp->dev; |
| 429 | plane->layer = &map->layers[i]; |
Brian Starkey | 1580778 | 2016-10-11 15:26:07 +0100 | [diff] [blame] | 430 | |
Mihail Atanassov | d1479f6 | 2017-02-09 11:32:00 +0000 | [diff] [blame] | 431 | 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 Starkey | 1580778 | 2016-10-11 15:26:07 +0100 | [diff] [blame] | 439 | continue; |
Mihail Atanassov | d1479f6 | 2017-02-09 11:32:00 +0000 | [diff] [blame] | 440 | } |
Brian Starkey | 1580778 | 2016-10-11 15:26:07 +0100 | [diff] [blame] | 441 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 442 | drm_plane_create_rotation_property(&plane->base, DRM_MODE_ROTATE_0, flags); |
Brian Starkey | c57eb71 | 2016-10-11 15:26:08 +0100 | [diff] [blame] | 443 | malidp_hw_write(malidp->dev, MALIDP_ALPHA_LUT, |
| 444 | plane->layer->base + MALIDP_LAYER_COMPOSE); |
Liviu Dudau | ad49f86 | 2016-03-07 10:00:53 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | kfree(formats); |
| 448 | |
| 449 | return 0; |
| 450 | |
| 451 | cleanup: |
| 452 | malidp_de_planes_destroy(drm); |
| 453 | kfree(formats); |
| 454 | |
| 455 | return ret; |
| 456 | } |
| 457 | |
| 458 | void 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 | } |