| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2015 MediaTek Inc. |
|---|
| 3 | 4 | * 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. |
|---|
| 13 | 5 | */ |
|---|
| 14 | 6 | |
|---|
| 15 | | -#include <drm/drmP.h> |
|---|
| 16 | 7 | #include <drm/drm_atomic.h> |
|---|
| 17 | 8 | #include <drm/drm_atomic_helper.h> |
|---|
| 9 | +#include <drm/drm_fourcc.h> |
|---|
| 10 | +#include <drm/drm_atomic_uapi.h> |
|---|
| 18 | 11 | #include <drm/drm_plane_helper.h> |
|---|
| 12 | +#include <drm/drm_gem_framebuffer_helper.h> |
|---|
| 19 | 13 | |
|---|
| 20 | 14 | #include "mtk_drm_crtc.h" |
|---|
| 21 | 15 | #include "mtk_drm_ddp_comp.h" |
|---|
| 22 | 16 | #include "mtk_drm_drv.h" |
|---|
| 23 | | -#include "mtk_drm_fb.h" |
|---|
| 24 | 17 | #include "mtk_drm_gem.h" |
|---|
| 25 | 18 | #include "mtk_drm_plane.h" |
|---|
| 26 | 19 | |
|---|
| 27 | 20 | static const u32 formats[] = { |
|---|
| 28 | 21 | DRM_FORMAT_XRGB8888, |
|---|
| 29 | 22 | 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, |
|---|
| 30 | 29 | DRM_FORMAT_RGB565, |
|---|
| 31 | 30 | DRM_FORMAT_UYVY, |
|---|
| 32 | 31 | DRM_FORMAT_YUYV, |
|---|
| .. | .. |
|---|
| 77 | 76 | kfree(to_mtk_plane_state(state)); |
|---|
| 78 | 77 | } |
|---|
| 79 | 78 | |
|---|
| 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 | + |
|---|
| 80 | 130 | static const struct drm_plane_funcs mtk_plane_funcs = { |
|---|
| 81 | 131 | .update_plane = drm_atomic_helper_update_plane, |
|---|
| 82 | 132 | .disable_plane = drm_atomic_helper_disable_plane, |
|---|
| .. | .. |
|---|
| 91 | 141 | { |
|---|
| 92 | 142 | struct drm_framebuffer *fb = state->fb; |
|---|
| 93 | 143 | struct drm_crtc_state *crtc_state; |
|---|
| 144 | + int ret; |
|---|
| 94 | 145 | |
|---|
| 95 | 146 | if (!fb) |
|---|
| 96 | 147 | return 0; |
|---|
| 97 | 148 | |
|---|
| 98 | | - if (!state->crtc) |
|---|
| 149 | + if (WARN_ON(!state->crtc)) |
|---|
| 99 | 150 | 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; |
|---|
| 100 | 156 | |
|---|
| 101 | 157 | crtc_state = drm_atomic_get_crtc_state(state->state, state->crtc); |
|---|
| 102 | 158 | if (IS_ERR(crtc_state)) |
|---|
| .. | .. |
|---|
| 154 | 210 | state->pending.y = plane->state->dst.y1; |
|---|
| 155 | 211 | state->pending.width = drm_rect_width(&plane->state->dst); |
|---|
| 156 | 212 | state->pending.height = drm_rect_height(&plane->state->dst); |
|---|
| 213 | + state->pending.rotation = plane->state->rotation; |
|---|
| 157 | 214 | wmb(); /* Make sure the above parameters are set before update */ |
|---|
| 158 | 215 | state->pending.dirty = true; |
|---|
| 159 | 216 | } |
|---|
| 160 | 217 | |
|---|
| 161 | 218 | static const struct drm_plane_helper_funcs mtk_plane_helper_funcs = { |
|---|
| 219 | + .prepare_fb = drm_gem_fb_prepare_fb, |
|---|
| 162 | 220 | .atomic_check = mtk_plane_atomic_check, |
|---|
| 163 | 221 | .atomic_update = mtk_plane_atomic_update, |
|---|
| 164 | 222 | .atomic_disable = mtk_plane_atomic_disable, |
|---|
| 223 | + .atomic_async_update = mtk_plane_atomic_async_update, |
|---|
| 224 | + .atomic_async_check = mtk_plane_atomic_async_check, |
|---|
| 165 | 225 | }; |
|---|
| 166 | 226 | |
|---|
| 167 | 227 | 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) |
|---|
| 169 | 230 | { |
|---|
| 170 | 231 | int err; |
|---|
| 171 | 232 | |
|---|
| .. | .. |
|---|
| 177 | 238 | return err; |
|---|
| 178 | 239 | } |
|---|
| 179 | 240 | |
|---|
| 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 | + |
|---|
| 180 | 249 | drm_plane_helper_add(plane, &mtk_plane_helper_funcs); |
|---|
| 181 | 250 | |
|---|
| 182 | 251 | return 0; |
|---|