Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 1 | /* |
Andrew F. Davis | bb5cdf8 | 2017-12-05 14:29:31 -0600 | [diff] [blame] | 2 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 3 | * Author: Rob Clark <rob.clark@linaro.org> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published by |
| 7 | * the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
Tomi Valkeinen | c423bc8 | 2015-06-16 14:54:51 +0300 | [diff] [blame] | 18 | #include <drm/drm_atomic.h> |
Laurent Pinchart | 69a1226 | 2015-03-05 21:38:16 +0200 | [diff] [blame] | 19 | #include <drm/drm_atomic_helper.h> |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 20 | #include <drm/drm_plane_helper.h> |
Laurent Pinchart | 69a1226 | 2015-03-05 21:38:16 +0200 | [diff] [blame] | 21 | |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 22 | #include "omap_dmm_tiler.h" |
Laurent Pinchart | 2d278f5 | 2015-03-05 21:31:37 +0200 | [diff] [blame] | 23 | #include "omap_drv.h" |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 24 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 25 | /* |
| 26 | * plane funcs |
| 27 | */ |
| 28 | |
| 29 | #define to_omap_plane(x) container_of(x, struct omap_plane, base) |
| 30 | |
| 31 | struct omap_plane { |
| 32 | struct drm_plane base; |
Jyri Sarha | 694c99c | 2017-03-24 16:47:54 +0200 | [diff] [blame] | 33 | enum omap_plane_id id; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 34 | const char *name; |
Rob Clark | a890e66 | 2012-03-05 10:48:31 -0600 | [diff] [blame] | 35 | }; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 36 | |
Tomi Valkeinen | 11ffd03 | 2015-05-29 11:05:37 +0300 | [diff] [blame] | 37 | static int omap_plane_prepare_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 38 | struct drm_plane_state *new_state) |
Tomi Valkeinen | 11ffd03 | 2015-05-29 11:05:37 +0300 | [diff] [blame] | 39 | { |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 40 | if (!new_state->fb) |
| 41 | return 0; |
| 42 | |
| 43 | return omap_framebuffer_pin(new_state->fb); |
Tomi Valkeinen | 11ffd03 | 2015-05-29 11:05:37 +0300 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | static void omap_plane_cleanup_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 47 | struct drm_plane_state *old_state) |
Tomi Valkeinen | 11ffd03 | 2015-05-29 11:05:37 +0300 | [diff] [blame] | 48 | { |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 49 | if (old_state->fb) |
| 50 | omap_framebuffer_unpin(old_state->fb); |
Tomi Valkeinen | 11ffd03 | 2015-05-29 11:05:37 +0300 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | static void omap_plane_atomic_update(struct drm_plane *plane, |
| 54 | struct drm_plane_state *old_state) |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 55 | { |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 56 | struct omap_drm_private *priv = plane->dev->dev_private; |
Laurent Pinchart | edc7255 | 2015-03-06 19:18:56 +0200 | [diff] [blame] | 57 | struct omap_plane *omap_plane = to_omap_plane(plane); |
| 58 | struct drm_plane_state *state = plane->state; |
Laurent Pinchart | fb730c9 | 2015-03-06 19:00:18 +0200 | [diff] [blame] | 59 | struct omap_overlay_info info; |
Rob Clark | 9a0774e | 2012-01-16 12:51:17 -0600 | [diff] [blame] | 60 | int ret; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 61 | |
Laurent Pinchart | edc7255 | 2015-03-06 19:18:56 +0200 | [diff] [blame] | 62 | DBG("%s, crtc=%p fb=%p", omap_plane->name, state->crtc, state->fb); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 63 | |
Laurent Pinchart | fb730c9 | 2015-03-06 19:00:18 +0200 | [diff] [blame] | 64 | memset(&info, 0, sizeof(info)); |
Tomi Valkeinen | 517a8a95 | 2017-05-03 14:14:27 +0300 | [diff] [blame] | 65 | info.rotation_type = OMAP_DSS_ROT_NONE; |
Tomi Valkeinen | 0bd97c4 | 2017-05-16 11:05:09 +0300 | [diff] [blame] | 66 | info.rotation = DRM_MODE_ROTATE_0; |
Laurent Pinchart | fb730c9 | 2015-03-06 19:00:18 +0200 | [diff] [blame] | 67 | info.global_alpha = 0xff; |
Laurent Pinchart | ba527c1 | 2017-05-09 01:27:12 +0300 | [diff] [blame] | 68 | info.zorder = state->zpos; |
Laurent Pinchart | fb730c9 | 2015-03-06 19:00:18 +0200 | [diff] [blame] | 69 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 70 | /* update scanout: */ |
Tomi Valkeinen | 218ed53 | 2017-05-15 13:40:08 +0300 | [diff] [blame] | 71 | omap_framebuffer_update_scanout(state->fb, state, &info); |
Rob Clark | 9a0774e | 2012-01-16 12:51:17 -0600 | [diff] [blame] | 72 | |
Laurent Pinchart | fb730c9 | 2015-03-06 19:00:18 +0200 | [diff] [blame] | 73 | DBG("%dx%d -> %dx%d (%d)", info.width, info.height, |
| 74 | info.out_width, info.out_height, |
| 75 | info.screen_width); |
| 76 | DBG("%d,%d %pad %pad", info.pos_x, info.pos_y, |
| 77 | &info.paddr, &info.p_uv_addr); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 78 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 79 | /* and finally, update omapdss: */ |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 80 | ret = priv->dispc_ops->ovl_setup(priv->dispc, omap_plane->id, &info, |
Tomi Valkeinen | 49a3057 | 2017-02-17 12:30:07 +0200 | [diff] [blame] | 81 | omap_crtc_timings(state->crtc), false, |
| 82 | omap_crtc_channel(state->crtc)); |
Tomi Valkeinen | cfb73f2 | 2016-06-10 12:44:31 +0300 | [diff] [blame] | 83 | if (ret) { |
| 84 | dev_err(plane->dev->dev, "Failed to setup plane %s\n", |
| 85 | omap_plane->name); |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 86 | priv->dispc_ops->ovl_enable(priv->dispc, omap_plane->id, false); |
Tomi Valkeinen | d9157df | 2015-05-29 11:03:15 +0300 | [diff] [blame] | 87 | return; |
Tomi Valkeinen | 794a65f | 2015-05-29 11:06:07 +0300 | [diff] [blame] | 88 | } |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 89 | |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 90 | priv->dispc_ops->ovl_enable(priv->dispc, omap_plane->id, true); |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 91 | } |
| 92 | |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 93 | static void omap_plane_atomic_disable(struct drm_plane *plane, |
| 94 | struct drm_plane_state *old_state) |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 95 | { |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 96 | struct omap_drm_private *priv = plane->dev->dev_private; |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 97 | struct omap_plane *omap_plane = to_omap_plane(plane); |
Laurent Pinchart | 2debab9 | 2015-01-12 22:38:16 +0200 | [diff] [blame] | 98 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 99 | plane->state->rotation = DRM_MODE_ROTATE_0; |
Laurent Pinchart | ba527c1 | 2017-05-09 01:27:12 +0300 | [diff] [blame] | 100 | plane->state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 101 | ? 0 : omap_plane->id; |
Laurent Pinchart | 82e58855 | 2015-01-12 23:56:57 +0200 | [diff] [blame] | 102 | |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 103 | priv->dispc_ops->ovl_enable(priv->dispc, omap_plane->id, false); |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 104 | } |
| 105 | |
Tomi Valkeinen | c423bc8 | 2015-06-16 14:54:51 +0300 | [diff] [blame] | 106 | static int omap_plane_atomic_check(struct drm_plane *plane, |
| 107 | struct drm_plane_state *state) |
| 108 | { |
| 109 | struct drm_crtc_state *crtc_state; |
| 110 | |
Tomi Valkeinen | 70dd2a6 | 2016-06-10 12:50:53 +0300 | [diff] [blame] | 111 | if (!state->fb) |
Tomi Valkeinen | c423bc8 | 2015-06-16 14:54:51 +0300 | [diff] [blame] | 112 | return 0; |
| 113 | |
Tomi Valkeinen | 70dd2a6 | 2016-06-10 12:50:53 +0300 | [diff] [blame] | 114 | /* crtc should only be NULL when disabling (i.e., !state->fb) */ |
| 115 | if (WARN_ON(!state->crtc)) |
| 116 | return 0; |
| 117 | |
| 118 | crtc_state = drm_atomic_get_existing_crtc_state(state->state, state->crtc); |
| 119 | /* we should have a crtc state if the plane is attached to a crtc */ |
| 120 | if (WARN_ON(!crtc_state)) |
| 121 | return 0; |
Tomi Valkeinen | c423bc8 | 2015-06-16 14:54:51 +0300 | [diff] [blame] | 122 | |
Tomi Valkeinen | aaf7642 | 2016-06-10 12:50:39 +0300 | [diff] [blame] | 123 | if (!crtc_state->enable) |
| 124 | return 0; |
| 125 | |
Tomi Valkeinen | c423bc8 | 2015-06-16 14:54:51 +0300 | [diff] [blame] | 126 | if (state->crtc_x < 0 || state->crtc_y < 0) |
| 127 | return -EINVAL; |
| 128 | |
| 129 | if (state->crtc_x + state->crtc_w > crtc_state->adjusted_mode.hdisplay) |
| 130 | return -EINVAL; |
| 131 | |
| 132 | if (state->crtc_y + state->crtc_h > crtc_state->adjusted_mode.vdisplay) |
| 133 | return -EINVAL; |
| 134 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 135 | if (state->rotation != DRM_MODE_ROTATE_0 && |
Tomi Valkeinen | 70dd2a6 | 2016-06-10 12:50:53 +0300 | [diff] [blame] | 136 | !omap_framebuffer_supports_rotation(state->fb)) |
| 137 | return -EINVAL; |
Tomi Valkeinen | bfeece5 | 2015-08-27 13:09:22 +0300 | [diff] [blame] | 138 | |
Tomi Valkeinen | c423bc8 | 2015-06-16 14:54:51 +0300 | [diff] [blame] | 139 | return 0; |
| 140 | } |
| 141 | |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 142 | static const struct drm_plane_helper_funcs omap_plane_helper_funcs = { |
| 143 | .prepare_fb = omap_plane_prepare_fb, |
| 144 | .cleanup_fb = omap_plane_cleanup_fb, |
Tomi Valkeinen | c423bc8 | 2015-06-16 14:54:51 +0300 | [diff] [blame] | 145 | .atomic_check = omap_plane_atomic_check, |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 146 | .atomic_update = omap_plane_atomic_update, |
| 147 | .atomic_disable = omap_plane_atomic_disable, |
| 148 | }; |
| 149 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 150 | static void omap_plane_destroy(struct drm_plane *plane) |
| 151 | { |
| 152 | struct omap_plane *omap_plane = to_omap_plane(plane); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 153 | |
| 154 | DBG("%s", omap_plane->name); |
| 155 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 156 | drm_plane_cleanup(plane); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 157 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 158 | kfree(omap_plane); |
| 159 | } |
| 160 | |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 161 | /* helper to install properties which are common to planes and crtcs */ |
| 162 | void omap_plane_install_properties(struct drm_plane *plane, |
| 163 | struct drm_mode_object *obj) |
| 164 | { |
| 165 | struct drm_device *dev = plane->dev; |
| 166 | struct omap_drm_private *priv = dev->dev_private; |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 167 | |
Rob Clark | c2a6a55 | 2012-10-25 17:14:13 -0500 | [diff] [blame] | 168 | if (priv->has_dmm) { |
Ville Syrjälä | 0da88db | 2016-09-26 19:30:52 +0300 | [diff] [blame] | 169 | if (!plane->rotation_property) |
| 170 | drm_plane_create_rotation_property(plane, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 171 | DRM_MODE_ROTATE_0, |
| 172 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 | |
| 173 | DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270 | |
| 174 | DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y); |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 175 | |
Ville Syrjälä | 0da88db | 2016-09-26 19:30:52 +0300 | [diff] [blame] | 176 | /* Attach the rotation property also to the crtc object */ |
| 177 | if (plane->rotation_property && obj != &plane->base) |
| 178 | drm_object_attach_property(obj, plane->rotation_property, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 179 | DRM_MODE_ROTATE_0); |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 180 | } |
Andre Renaud | 8451b5a | 2012-08-15 15:18:02 -0500 | [diff] [blame] | 181 | |
Laurent Pinchart | e2cd09b | 2015-03-06 17:16:43 +0200 | [diff] [blame] | 182 | drm_object_attach_property(obj, priv->zorder_prop, 0); |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 183 | } |
| 184 | |
Tomi Valkeinen | e07323c | 2015-12-15 11:33:23 +0200 | [diff] [blame] | 185 | static void omap_plane_reset(struct drm_plane *plane) |
| 186 | { |
| 187 | struct omap_plane *omap_plane = to_omap_plane(plane); |
Tomi Valkeinen | e07323c | 2015-12-15 11:33:23 +0200 | [diff] [blame] | 188 | |
Laurent Pinchart | d980278 | 2017-05-09 01:27:13 +0300 | [diff] [blame] | 189 | drm_atomic_helper_plane_reset(plane); |
| 190 | if (!plane->state) |
Tomi Valkeinen | e07323c | 2015-12-15 11:33:23 +0200 | [diff] [blame] | 191 | return; |
| 192 | |
| 193 | /* |
Laurent Pinchart | ba527c1 | 2017-05-09 01:27:12 +0300 | [diff] [blame] | 194 | * Set the zpos default depending on whether we are a primary or overlay |
Tomi Valkeinen | e07323c | 2015-12-15 11:33:23 +0200 | [diff] [blame] | 195 | * plane. |
| 196 | */ |
Laurent Pinchart | d980278 | 2017-05-09 01:27:13 +0300 | [diff] [blame] | 197 | plane->state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY |
| 198 | ? 0 : omap_plane->id; |
Tomi Valkeinen | e07323c | 2015-12-15 11:33:23 +0200 | [diff] [blame] | 199 | } |
| 200 | |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 201 | static int omap_plane_atomic_set_property(struct drm_plane *plane, |
| 202 | struct drm_plane_state *state, |
| 203 | struct drm_property *property, |
Laurent Pinchart | dfe9cfc | 2018-02-11 15:07:33 +0200 | [diff] [blame] | 204 | u64 val) |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 205 | { |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 206 | struct omap_drm_private *priv = plane->dev->dev_private; |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 207 | |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 208 | if (property == priv->zorder_prop) |
Laurent Pinchart | ba527c1 | 2017-05-09 01:27:12 +0300 | [diff] [blame] | 209 | state->zpos = val; |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 210 | else |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 211 | return -EINVAL; |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 212 | |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 213 | return 0; |
| 214 | } |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 215 | |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 216 | static int omap_plane_atomic_get_property(struct drm_plane *plane, |
| 217 | const struct drm_plane_state *state, |
| 218 | struct drm_property *property, |
Laurent Pinchart | dfe9cfc | 2018-02-11 15:07:33 +0200 | [diff] [blame] | 219 | u64 *val) |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 220 | { |
| 221 | struct omap_drm_private *priv = plane->dev->dev_private; |
Laurent Pinchart | a42133a | 2015-01-17 19:09:26 +0200 | [diff] [blame] | 222 | |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 223 | if (property == priv->zorder_prop) |
Laurent Pinchart | ba527c1 | 2017-05-09 01:27:12 +0300 | [diff] [blame] | 224 | *val = state->zpos; |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 225 | else |
| 226 | return -EINVAL; |
| 227 | |
| 228 | return 0; |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 229 | } |
| 230 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 231 | static const struct drm_plane_funcs omap_plane_funcs = { |
Laurent Pinchart | cef77d4 | 2015-03-05 21:50:00 +0200 | [diff] [blame] | 232 | .update_plane = drm_atomic_helper_update_plane, |
| 233 | .disable_plane = drm_atomic_helper_disable_plane, |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 234 | .reset = omap_plane_reset, |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 235 | .destroy = omap_plane_destroy, |
Laurent Pinchart | d980278 | 2017-05-09 01:27:13 +0300 | [diff] [blame] | 236 | .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, |
| 237 | .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, |
Laurent Pinchart | afc3493 | 2015-03-06 18:35:16 +0200 | [diff] [blame] | 238 | .atomic_set_property = omap_plane_atomic_set_property, |
| 239 | .atomic_get_property = omap_plane_atomic_get_property, |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 240 | }; |
| 241 | |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 242 | static const char *plane_id_to_name[] = { |
Laurent Pinchart | 222025e | 2015-01-11 00:02:07 +0200 | [diff] [blame] | 243 | [OMAP_DSS_GFX] = "gfx", |
| 244 | [OMAP_DSS_VIDEO1] = "vid1", |
| 245 | [OMAP_DSS_VIDEO2] = "vid2", |
| 246 | [OMAP_DSS_VIDEO3] = "vid3", |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 247 | }; |
| 248 | |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 249 | static const enum omap_plane_id plane_idx_to_id[] = { |
| 250 | OMAP_DSS_GFX, |
| 251 | OMAP_DSS_VIDEO1, |
| 252 | OMAP_DSS_VIDEO2, |
| 253 | OMAP_DSS_VIDEO3, |
| 254 | }; |
| 255 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 256 | /* initialize plane */ |
| 257 | struct drm_plane *omap_plane_init(struct drm_device *dev, |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 258 | int idx, enum drm_plane_type type, |
Tomi Valkeinen | e43f2c3 | 2016-12-02 16:07:11 +0200 | [diff] [blame] | 259 | u32 possible_crtcs) |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 260 | { |
Tomi Valkeinen | 9f75922 | 2015-11-05 18:39:52 +0200 | [diff] [blame] | 261 | struct omap_drm_private *priv = dev->dev_private; |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 262 | unsigned int num_planes = priv->dispc_ops->get_num_ovls(priv->dispc); |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 263 | struct drm_plane *plane; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 264 | struct omap_plane *omap_plane; |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 265 | enum omap_plane_id id; |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 266 | int ret; |
Tomi Valkeinen | eecad43 | 2017-05-04 11:27:49 +0300 | [diff] [blame] | 267 | u32 nformats; |
| 268 | const u32 *formats; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 269 | |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 270 | if (WARN_ON(idx >= ARRAY_SIZE(plane_idx_to_id))) |
| 271 | return ERR_PTR(-EINVAL); |
| 272 | |
| 273 | id = plane_idx_to_id[idx]; |
| 274 | |
| 275 | DBG("%s: type=%d", plane_id_to_name[id], type); |
Rob Clark | b33f34d | 2012-03-05 10:48:35 -0600 | [diff] [blame] | 276 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 277 | omap_plane = kzalloc(sizeof(*omap_plane), GFP_KERNEL); |
Joe Perches | 78110bb | 2013-02-11 09:41:29 -0800 | [diff] [blame] | 278 | if (!omap_plane) |
Laurent Pinchart | fb9a35f | 2015-01-11 16:30:44 +0200 | [diff] [blame] | 279 | return ERR_PTR(-ENOMEM); |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 280 | |
Laurent Pinchart | 50638ae | 2018-02-13 14:00:42 +0200 | [diff] [blame] | 281 | formats = priv->dispc_ops->ovl_get_color_modes(priv->dispc, id); |
Tomi Valkeinen | eecad43 | 2017-05-04 11:27:49 +0300 | [diff] [blame] | 282 | for (nformats = 0; formats[nformats]; ++nformats) |
| 283 | ; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 284 | omap_plane->id = id; |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 285 | omap_plane->name = plane_id_to_name[id]; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 286 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 287 | plane = &omap_plane->base; |
| 288 | |
Tomi Valkeinen | e43f2c3 | 2016-12-02 16:07:11 +0200 | [diff] [blame] | 289 | ret = drm_universal_plane_init(dev, plane, possible_crtcs, |
Tomi Valkeinen | eecad43 | 2017-05-04 11:27:49 +0300 | [diff] [blame] | 290 | &omap_plane_funcs, formats, |
Ben Widawsky | e6fc3b6 | 2017-07-23 20:46:38 -0700 | [diff] [blame] | 291 | nformats, NULL, type, NULL); |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 292 | if (ret < 0) |
| 293 | goto error; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 294 | |
Laurent Pinchart | de8e410 | 2015-03-05 13:39:56 +0200 | [diff] [blame] | 295 | drm_plane_helper_add(plane, &omap_plane_helper_funcs); |
| 296 | |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 297 | omap_plane_install_properties(plane, &plane->base); |
Laurent Pinchart | dff6c24 | 2017-05-09 01:27:14 +0300 | [diff] [blame] | 298 | drm_plane_create_zpos_property(plane, 0, 0, num_planes - 1); |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 299 | |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 300 | return plane; |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 301 | |
| 302 | error: |
Jyri Sarha | e8e13b1 | 2017-03-24 16:47:55 +0200 | [diff] [blame] | 303 | dev_err(dev->dev, "%s(): could not create plane: %s\n", |
| 304 | __func__, plane_id_to_name[id]); |
| 305 | |
Laurent Pinchart | ef6b0e0 | 2015-01-11 00:11:18 +0200 | [diff] [blame] | 306 | kfree(omap_plane); |
| 307 | return NULL; |
Rob Clark | bb5c2d9 | 2012-01-16 12:51:16 -0600 | [diff] [blame] | 308 | } |