2 * Copyright (C) 2011 Samsung Electronics Co.Ltd
3 * Authors: Joonyoung Shim <jy0922.shim@samsung.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
14 #include "exynos_drm.h"
15 #include "exynos_drm_drv.h"
16 #include "exynos_drm_crtc.h"
17 #include "exynos_drm_encoder.h"
19 #define to_exynos_plane(x) container_of(x, struct exynos_plane, base)
22 struct drm_plane base;
23 struct exynos_drm_overlay overlay;
27 static const uint32_t formats[] = {
36 exynos_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
37 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
38 unsigned int crtc_w, unsigned int crtc_h,
39 uint32_t src_x, uint32_t src_y,
40 uint32_t src_w, uint32_t src_h)
42 struct exynos_plane *exynos_plane = to_exynos_plane(plane);
43 struct exynos_drm_overlay *overlay = &exynos_plane->overlay;
44 struct exynos_drm_crtc_pos pos;
47 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
49 memset(&pos, 0, sizeof(struct exynos_drm_crtc_pos));
55 /* considering 16.16 fixed point of source values */
56 pos.fb_x = src_x >> 16;
57 pos.fb_y = src_y >> 16;
58 pos.src_w = src_w >> 16;
59 pos.src_h = src_h >> 16;
61 ret = exynos_drm_overlay_update(overlay, fb, &crtc->mode, &pos);
65 exynos_drm_fn_encoder(crtc, overlay,
66 exynos_drm_encoder_crtc_mode_set);
67 exynos_drm_fn_encoder(crtc, &overlay->zpos,
68 exynos_drm_encoder_crtc_plane_commit);
70 exynos_plane->enabled = true;
75 static int exynos_disable_plane(struct drm_plane *plane)
77 struct exynos_plane *exynos_plane = to_exynos_plane(plane);
78 struct exynos_drm_overlay *overlay = &exynos_plane->overlay;
80 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
82 if (!exynos_plane->enabled)
85 exynos_drm_fn_encoder(plane->crtc, &overlay->zpos,
86 exynos_drm_encoder_crtc_disable);
88 exynos_plane->enabled = false;
89 exynos_plane->overlay.zpos = DEFAULT_ZPOS;
94 static void exynos_plane_destroy(struct drm_plane *plane)
96 struct exynos_plane *exynos_plane = to_exynos_plane(plane);
98 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
100 exynos_disable_plane(plane);
101 drm_plane_cleanup(plane);
105 static struct drm_plane_funcs exynos_plane_funcs = {
106 .update_plane = exynos_update_plane,
107 .disable_plane = exynos_disable_plane,
108 .destroy = exynos_plane_destroy,
111 struct drm_plane *exynos_plane_init(struct drm_device *dev,
112 unsigned int possible_crtcs, bool priv)
114 struct exynos_plane *exynos_plane;
117 exynos_plane = kzalloc(sizeof(struct exynos_plane), GFP_KERNEL);
119 DRM_ERROR("failed to allocate plane\n");
123 exynos_plane->overlay.zpos = DEFAULT_ZPOS;
125 err = drm_plane_init(dev, &exynos_plane->base, possible_crtcs,
126 &exynos_plane_funcs, formats, ARRAY_SIZE(formats),
129 DRM_ERROR("failed to initialize plane\n");
134 return &exynos_plane->base;
137 int exynos_plane_set_zpos_ioctl(struct drm_device *dev, void *data,
138 struct drm_file *file_priv)
140 struct drm_exynos_plane_set_zpos *zpos_req = data;
141 struct drm_mode_object *obj;
142 struct drm_plane *plane;
143 struct exynos_plane *exynos_plane;
146 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
148 if (!drm_core_check_feature(dev, DRIVER_MODESET))
151 if (zpos_req->zpos < 0 || zpos_req->zpos >= MAX_PLANE) {
152 if (zpos_req->zpos != DEFAULT_ZPOS) {
153 DRM_ERROR("zpos not within limits\n");
158 mutex_lock(&dev->mode_config.mutex);
160 obj = drm_mode_object_find(dev, zpos_req->plane_id,
161 DRM_MODE_OBJECT_PLANE);
163 DRM_DEBUG_KMS("Unknown plane ID %d\n",
169 plane = obj_to_plane(obj);
170 exynos_plane = to_exynos_plane(plane);
172 exynos_plane->overlay.zpos = zpos_req->zpos;
175 mutex_unlock(&dev->mode_config.mutex);
179 struct exynos_drm_overlay *get_exynos_drm_overlay(struct drm_plane *plane)
181 struct exynos_plane *exynos_plane = to_exynos_plane(plane);
183 return &exynos_plane->overlay;