2019-06-03 05:44:50 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-01-16 18:51:16 +00:00
|
|
|
/*
|
2017-12-05 20:29:31 +00:00
|
|
|
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
2012-01-16 18:51:16 +00:00
|
|
|
* Author: Rob Clark <rob.clark@linaro.org>
|
|
|
|
*/
|
|
|
|
|
2015-06-16 11:54:51 +00:00
|
|
|
#include <drm/drm_atomic.h>
|
2015-03-05 19:38:16 +00:00
|
|
|
#include <drm/drm_atomic_helper.h>
|
2015-03-05 11:39:56 +00:00
|
|
|
#include <drm/drm_plane_helper.h>
|
2015-03-05 19:38:16 +00:00
|
|
|
|
2012-08-15 20:18:01 +00:00
|
|
|
#include "omap_dmm_tiler.h"
|
2015-03-05 19:31:37 +00:00
|
|
|
#include "omap_drv.h"
|
2012-01-16 18:51:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* plane funcs
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define to_omap_plane(x) container_of(x, struct omap_plane, base)
|
|
|
|
|
|
|
|
struct omap_plane {
|
|
|
|
struct drm_plane base;
|
2017-03-24 14:47:54 +00:00
|
|
|
enum omap_plane_id id;
|
2012-12-04 19:59:12 +00:00
|
|
|
const char *name;
|
2012-03-05 16:48:31 +00:00
|
|
|
};
|
2012-01-16 18:51:16 +00:00
|
|
|
|
2015-05-29 08:05:37 +00:00
|
|
|
static int omap_plane_prepare_fb(struct drm_plane *plane,
|
2016-08-18 18:00:16 +00:00
|
|
|
struct drm_plane_state *new_state)
|
2015-05-29 08:05:37 +00:00
|
|
|
{
|
2015-09-02 08:42:40 +00:00
|
|
|
if (!new_state->fb)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return omap_framebuffer_pin(new_state->fb);
|
2015-05-29 08:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void omap_plane_cleanup_fb(struct drm_plane *plane,
|
2016-08-18 18:00:16 +00:00
|
|
|
struct drm_plane_state *old_state)
|
2015-05-29 08:05:37 +00:00
|
|
|
{
|
2015-09-02 08:42:40 +00:00
|
|
|
if (old_state->fb)
|
|
|
|
omap_framebuffer_unpin(old_state->fb);
|
2015-05-29 08:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void omap_plane_atomic_update(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *old_state)
|
2015-03-06 16:35:16 +00:00
|
|
|
{
|
2015-11-05 16:39:52 +00:00
|
|
|
struct omap_drm_private *priv = plane->dev->dev_private;
|
2015-03-06 17:18:56 +00:00
|
|
|
struct omap_plane *omap_plane = to_omap_plane(plane);
|
|
|
|
struct drm_plane_state *state = plane->state;
|
2015-03-06 17:00:18 +00:00
|
|
|
struct omap_overlay_info info;
|
2012-01-16 18:51:17 +00:00
|
|
|
int ret;
|
2012-01-16 18:51:16 +00:00
|
|
|
|
2015-03-06 17:18:56 +00:00
|
|
|
DBG("%s, crtc=%p fb=%p", omap_plane->name, state->crtc, state->fb);
|
2012-12-04 19:59:12 +00:00
|
|
|
|
2015-03-06 17:00:18 +00:00
|
|
|
memset(&info, 0, sizeof(info));
|
2017-05-03 11:14:27 +00:00
|
|
|
info.rotation_type = OMAP_DSS_ROT_NONE;
|
2017-05-16 08:05:09 +00:00
|
|
|
info.rotation = DRM_MODE_ROTATE_0;
|
2015-03-06 17:00:18 +00:00
|
|
|
info.global_alpha = 0xff;
|
2018-03-21 10:20:29 +00:00
|
|
|
info.zorder = state->normalized_zpos;
|
2015-03-06 17:00:18 +00:00
|
|
|
|
2012-12-04 19:59:12 +00:00
|
|
|
/* update scanout: */
|
2017-05-15 10:40:08 +00:00
|
|
|
omap_framebuffer_update_scanout(state->fb, state, &info);
|
2012-01-16 18:51:16 +00:00
|
|
|
|
2015-03-06 17:00:18 +00:00
|
|
|
DBG("%dx%d -> %dx%d (%d)", info.width, info.height,
|
|
|
|
info.out_width, info.out_height,
|
|
|
|
info.screen_width);
|
|
|
|
DBG("%d,%d %pad %pad", info.pos_x, info.pos_y,
|
|
|
|
&info.paddr, &info.p_uv_addr);
|
2012-12-04 19:59:12 +00:00
|
|
|
|
|
|
|
/* and finally, update omapdss: */
|
2018-02-13 12:00:42 +00:00
|
|
|
ret = priv->dispc_ops->ovl_setup(priv->dispc, omap_plane->id, &info,
|
2017-02-17 10:30:07 +00:00
|
|
|
omap_crtc_timings(state->crtc), false,
|
|
|
|
omap_crtc_channel(state->crtc));
|
2016-06-10 09:44:31 +00:00
|
|
|
if (ret) {
|
|
|
|
dev_err(plane->dev->dev, "Failed to setup plane %s\n",
|
|
|
|
omap_plane->name);
|
2018-02-13 12:00:42 +00:00
|
|
|
priv->dispc_ops->ovl_enable(priv->dispc, omap_plane->id, false);
|
2015-05-29 08:03:15 +00:00
|
|
|
return;
|
2015-05-29 08:06:07 +00:00
|
|
|
}
|
2012-12-04 19:59:12 +00:00
|
|
|
|
2018-02-13 12:00:42 +00:00
|
|
|
priv->dispc_ops->ovl_enable(priv->dispc, omap_plane->id, true);
|
2015-03-05 11:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void omap_plane_atomic_disable(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *old_state)
|
2012-01-16 18:51:16 +00:00
|
|
|
{
|
2015-11-05 16:39:52 +00:00
|
|
|
struct omap_drm_private *priv = plane->dev->dev_private;
|
2012-08-15 20:18:01 +00:00
|
|
|
struct omap_plane *omap_plane = to_omap_plane(plane);
|
2015-01-12 20:38:16 +00:00
|
|
|
|
2017-05-19 20:50:17 +00:00
|
|
|
plane->state->rotation = DRM_MODE_ROTATE_0;
|
2017-05-08 22:27:12 +00:00
|
|
|
plane->state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY
|
2015-03-06 16:35:16 +00:00
|
|
|
? 0 : omap_plane->id;
|
2015-01-12 21:56:57 +00:00
|
|
|
|
2018-02-13 12:00:42 +00:00
|
|
|
priv->dispc_ops->ovl_enable(priv->dispc, omap_plane->id, false);
|
2012-01-16 18:51:16 +00:00
|
|
|
}
|
|
|
|
|
2015-06-16 11:54:51 +00:00
|
|
|
static int omap_plane_atomic_check(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *state)
|
|
|
|
{
|
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
|
2016-06-10 09:50:53 +00:00
|
|
|
if (!state->fb)
|
2015-06-16 11:54:51 +00:00
|
|
|
return 0;
|
|
|
|
|
2016-06-10 09:50:53 +00:00
|
|
|
/* crtc should only be NULL when disabling (i.e., !state->fb) */
|
|
|
|
if (WARN_ON(!state->crtc))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
crtc_state = drm_atomic_get_existing_crtc_state(state->state, state->crtc);
|
|
|
|
/* we should have a crtc state if the plane is attached to a crtc */
|
|
|
|
if (WARN_ON(!crtc_state))
|
|
|
|
return 0;
|
2015-06-16 11:54:51 +00:00
|
|
|
|
2016-06-10 09:50:39 +00:00
|
|
|
if (!crtc_state->enable)
|
|
|
|
return 0;
|
|
|
|
|
2015-06-16 11:54:51 +00:00
|
|
|
if (state->crtc_x < 0 || state->crtc_y < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (state->crtc_x + state->crtc_w > crtc_state->adjusted_mode.hdisplay)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (state->crtc_y + state->crtc_h > crtc_state->adjusted_mode.vdisplay)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2017-05-19 20:50:17 +00:00
|
|
|
if (state->rotation != DRM_MODE_ROTATE_0 &&
|
2016-06-10 09:50:53 +00:00
|
|
|
!omap_framebuffer_supports_rotation(state->fb))
|
|
|
|
return -EINVAL;
|
2015-08-27 10:09:22 +00:00
|
|
|
|
2015-06-16 11:54:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-05 11:39:56 +00:00
|
|
|
static const struct drm_plane_helper_funcs omap_plane_helper_funcs = {
|
|
|
|
.prepare_fb = omap_plane_prepare_fb,
|
|
|
|
.cleanup_fb = omap_plane_cleanup_fb,
|
2015-06-16 11:54:51 +00:00
|
|
|
.atomic_check = omap_plane_atomic_check,
|
2015-03-05 11:39:56 +00:00
|
|
|
.atomic_update = omap_plane_atomic_update,
|
|
|
|
.atomic_disable = omap_plane_atomic_disable,
|
|
|
|
};
|
|
|
|
|
2012-01-16 18:51:16 +00:00
|
|
|
static void omap_plane_destroy(struct drm_plane *plane)
|
|
|
|
{
|
|
|
|
struct omap_plane *omap_plane = to_omap_plane(plane);
|
2012-12-04 19:59:12 +00:00
|
|
|
|
|
|
|
DBG("%s", omap_plane->name);
|
|
|
|
|
2012-01-16 18:51:16 +00:00
|
|
|
drm_plane_cleanup(plane);
|
2012-12-04 19:59:12 +00:00
|
|
|
|
2012-01-16 18:51:16 +00:00
|
|
|
kfree(omap_plane);
|
|
|
|
}
|
|
|
|
|
2012-08-15 20:18:01 +00:00
|
|
|
/* helper to install properties which are common to planes and crtcs */
|
|
|
|
void omap_plane_install_properties(struct drm_plane *plane,
|
|
|
|
struct drm_mode_object *obj)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = plane->dev;
|
|
|
|
struct omap_drm_private *priv = dev->dev_private;
|
|
|
|
|
2012-10-25 22:14:13 +00:00
|
|
|
if (priv->has_dmm) {
|
2016-09-26 16:30:52 +00:00
|
|
|
if (!plane->rotation_property)
|
|
|
|
drm_plane_create_rotation_property(plane,
|
2017-05-19 20:50:17 +00:00
|
|
|
DRM_MODE_ROTATE_0,
|
|
|
|
DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
|
|
|
|
DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270 |
|
|
|
|
DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y);
|
2016-09-26 16:30:52 +00:00
|
|
|
|
|
|
|
/* Attach the rotation property also to the crtc object */
|
|
|
|
if (plane->rotation_property && obj != &plane->base)
|
|
|
|
drm_object_attach_property(obj, plane->rotation_property,
|
2017-05-19 20:50:17 +00:00
|
|
|
DRM_MODE_ROTATE_0);
|
2012-08-15 20:18:01 +00:00
|
|
|
}
|
2012-08-15 20:18:02 +00:00
|
|
|
|
2015-03-06 15:16:43 +00:00
|
|
|
drm_object_attach_property(obj, priv->zorder_prop, 0);
|
2012-08-15 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 09:33:23 +00:00
|
|
|
static void omap_plane_reset(struct drm_plane *plane)
|
|
|
|
{
|
|
|
|
struct omap_plane *omap_plane = to_omap_plane(plane);
|
|
|
|
|
2017-05-08 22:27:13 +00:00
|
|
|
drm_atomic_helper_plane_reset(plane);
|
|
|
|
if (!plane->state)
|
2015-12-15 09:33:23 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
2017-05-08 22:27:12 +00:00
|
|
|
* Set the zpos default depending on whether we are a primary or overlay
|
2015-12-15 09:33:23 +00:00
|
|
|
* plane.
|
|
|
|
*/
|
2017-05-08 22:27:13 +00:00
|
|
|
plane->state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY
|
|
|
|
? 0 : omap_plane->id;
|
2015-12-15 09:33:23 +00:00
|
|
|
}
|
|
|
|
|
2015-03-06 16:35:16 +00:00
|
|
|
static int omap_plane_atomic_set_property(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *state,
|
|
|
|
struct drm_property *property,
|
2018-02-11 13:07:33 +00:00
|
|
|
u64 val)
|
2012-08-15 20:18:01 +00:00
|
|
|
{
|
|
|
|
struct omap_drm_private *priv = plane->dev->dev_private;
|
|
|
|
|
2015-03-06 16:35:16 +00:00
|
|
|
if (property == priv->zorder_prop)
|
2017-05-08 22:27:12 +00:00
|
|
|
state->zpos = val;
|
2015-03-06 16:35:16 +00:00
|
|
|
else
|
2015-01-17 17:09:26 +00:00
|
|
|
return -EINVAL;
|
2012-08-15 20:18:01 +00:00
|
|
|
|
2015-03-06 16:35:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-01-17 17:09:26 +00:00
|
|
|
|
2015-03-06 16:35:16 +00:00
|
|
|
static int omap_plane_atomic_get_property(struct drm_plane *plane,
|
|
|
|
const struct drm_plane_state *state,
|
|
|
|
struct drm_property *property,
|
2018-02-11 13:07:33 +00:00
|
|
|
u64 *val)
|
2015-03-06 16:35:16 +00:00
|
|
|
{
|
|
|
|
struct omap_drm_private *priv = plane->dev->dev_private;
|
|
|
|
|
|
|
|
if (property == priv->zorder_prop)
|
2017-05-08 22:27:12 +00:00
|
|
|
*val = state->zpos;
|
2015-03-06 16:35:16 +00:00
|
|
|
else
|
|
|
|
return -EINVAL;
|
2015-01-17 17:09:26 +00:00
|
|
|
|
2015-03-06 16:35:16 +00:00
|
|
|
return 0;
|
2012-08-15 20:18:01 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 18:51:16 +00:00
|
|
|
static const struct drm_plane_funcs omap_plane_funcs = {
|
2015-03-05 19:50:00 +00:00
|
|
|
.update_plane = drm_atomic_helper_update_plane,
|
|
|
|
.disable_plane = drm_atomic_helper_disable_plane,
|
2015-03-06 16:35:16 +00:00
|
|
|
.reset = omap_plane_reset,
|
2015-01-10 22:02:07 +00:00
|
|
|
.destroy = omap_plane_destroy,
|
2017-05-08 22:27:13 +00:00
|
|
|
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
|
|
|
|
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
|
2015-03-06 16:35:16 +00:00
|
|
|
.atomic_set_property = omap_plane_atomic_set_property,
|
|
|
|
.atomic_get_property = omap_plane_atomic_get_property,
|
2012-01-16 18:51:16 +00:00
|
|
|
};
|
|
|
|
|
2017-03-24 14:47:55 +00:00
|
|
|
static const char *plane_id_to_name[] = {
|
2015-01-10 22:02:07 +00:00
|
|
|
[OMAP_DSS_GFX] = "gfx",
|
|
|
|
[OMAP_DSS_VIDEO1] = "vid1",
|
|
|
|
[OMAP_DSS_VIDEO2] = "vid2",
|
|
|
|
[OMAP_DSS_VIDEO3] = "vid3",
|
2012-12-04 19:59:12 +00:00
|
|
|
};
|
|
|
|
|
2017-03-24 14:47:55 +00:00
|
|
|
static const enum omap_plane_id plane_idx_to_id[] = {
|
|
|
|
OMAP_DSS_GFX,
|
|
|
|
OMAP_DSS_VIDEO1,
|
|
|
|
OMAP_DSS_VIDEO2,
|
|
|
|
OMAP_DSS_VIDEO3,
|
|
|
|
};
|
|
|
|
|
2012-01-16 18:51:16 +00:00
|
|
|
/* initialize plane */
|
|
|
|
struct drm_plane *omap_plane_init(struct drm_device *dev,
|
2017-03-24 14:47:55 +00:00
|
|
|
int idx, enum drm_plane_type type,
|
2016-12-02 14:07:11 +00:00
|
|
|
u32 possible_crtcs)
|
2012-01-16 18:51:16 +00:00
|
|
|
{
|
2015-11-05 16:39:52 +00:00
|
|
|
struct omap_drm_private *priv = dev->dev_private;
|
2018-02-13 12:00:42 +00:00
|
|
|
unsigned int num_planes = priv->dispc_ops->get_num_ovls(priv->dispc);
|
2015-01-10 22:11:18 +00:00
|
|
|
struct drm_plane *plane;
|
2012-01-16 18:51:16 +00:00
|
|
|
struct omap_plane *omap_plane;
|
2017-03-24 14:47:55 +00:00
|
|
|
enum omap_plane_id id;
|
2015-01-10 22:11:18 +00:00
|
|
|
int ret;
|
2017-05-04 08:27:49 +00:00
|
|
|
u32 nformats;
|
|
|
|
const u32 *formats;
|
2012-01-16 18:51:16 +00:00
|
|
|
|
2017-03-24 14:47:55 +00:00
|
|
|
if (WARN_ON(idx >= ARRAY_SIZE(plane_idx_to_id)))
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
id = plane_idx_to_id[idx];
|
|
|
|
|
|
|
|
DBG("%s: type=%d", plane_id_to_name[id], type);
|
2012-03-05 16:48:35 +00:00
|
|
|
|
2012-01-16 18:51:16 +00:00
|
|
|
omap_plane = kzalloc(sizeof(*omap_plane), GFP_KERNEL);
|
2013-02-11 17:41:29 +00:00
|
|
|
if (!omap_plane)
|
2015-01-11 14:30:44 +00:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2012-01-16 18:51:16 +00:00
|
|
|
|
2018-02-13 12:00:42 +00:00
|
|
|
formats = priv->dispc_ops->ovl_get_color_modes(priv->dispc, id);
|
2017-05-04 08:27:49 +00:00
|
|
|
for (nformats = 0; formats[nformats]; ++nformats)
|
|
|
|
;
|
2012-12-04 19:59:12 +00:00
|
|
|
omap_plane->id = id;
|
2017-03-24 14:47:55 +00:00
|
|
|
omap_plane->name = plane_id_to_name[id];
|
2012-12-04 19:59:12 +00:00
|
|
|
|
2012-01-16 18:51:16 +00:00
|
|
|
plane = &omap_plane->base;
|
|
|
|
|
2016-12-02 14:07:11 +00:00
|
|
|
ret = drm_universal_plane_init(dev, plane, possible_crtcs,
|
2017-05-04 08:27:49 +00:00
|
|
|
&omap_plane_funcs, formats,
|
2017-07-24 03:46:38 +00:00
|
|
|
nformats, NULL, type, NULL);
|
2015-01-10 22:11:18 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
2012-01-16 18:51:16 +00:00
|
|
|
|
2015-03-05 11:39:56 +00:00
|
|
|
drm_plane_helper_add(plane, &omap_plane_helper_funcs);
|
|
|
|
|
2012-08-15 20:18:01 +00:00
|
|
|
omap_plane_install_properties(plane, &plane->base);
|
2017-05-08 22:27:14 +00:00
|
|
|
drm_plane_create_zpos_property(plane, 0, 0, num_planes - 1);
|
2012-08-15 20:18:01 +00:00
|
|
|
|
2012-01-16 18:51:16 +00:00
|
|
|
return plane;
|
2015-01-10 22:11:18 +00:00
|
|
|
|
|
|
|
error:
|
2017-03-24 14:47:55 +00:00
|
|
|
dev_err(dev->dev, "%s(): could not create plane: %s\n",
|
|
|
|
__func__, plane_id_to_name[id]);
|
|
|
|
|
2015-01-10 22:11:18 +00:00
|
|
|
kfree(omap_plane);
|
|
|
|
return NULL;
|
2012-01-16 18:51:16 +00:00
|
|
|
}
|