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