These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / gpu / drm / sti / sti_plane.c
1 /*
2  * Copyright (C) STMicroelectronics SA 2014
3  * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
4  *          Fabien Dessenne <fabien.dessenne@st.com>
5  *          for STMicroelectronics.
6  * License terms:  GNU General Public License (GPL), version 2
7  */
8
9 #include <drm/drmP.h>
10 #include <drm/drm_fb_cma_helper.h>
11 #include <drm/drm_gem_cma_helper.h>
12
13 #include "sti_compositor.h"
14 #include "sti_drv.h"
15 #include "sti_plane.h"
16
17 /* (Background) < GDP0 < GDP1 < HQVDP0 < GDP2 < GDP3 < (ForeGround) */
18 enum sti_plane_desc sti_plane_default_zorder[] = {
19         STI_GDP_0,
20         STI_GDP_1,
21         STI_HQVDP_0,
22         STI_GDP_2,
23         STI_GDP_3,
24 };
25
26 const char *sti_plane_to_str(struct sti_plane *plane)
27 {
28         switch (plane->desc) {
29         case STI_GDP_0:
30                 return "GDP0";
31         case STI_GDP_1:
32                 return "GDP1";
33         case STI_GDP_2:
34                 return "GDP2";
35         case STI_GDP_3:
36                 return "GDP3";
37         case STI_HQVDP_0:
38                 return "HQVDP0";
39         case STI_CURSOR:
40                 return "CURSOR";
41         default:
42                 return "<UNKNOWN PLANE>";
43         }
44 }
45
46 static void sti_plane_destroy(struct drm_plane *drm_plane)
47 {
48         DRM_DEBUG_DRIVER("\n");
49
50         drm_plane_helper_disable(drm_plane);
51         drm_plane_cleanup(drm_plane);
52 }
53
54 static int sti_plane_set_property(struct drm_plane *drm_plane,
55                                   struct drm_property *property,
56                                   uint64_t val)
57 {
58         struct drm_device *dev = drm_plane->dev;
59         struct sti_private *private = dev->dev_private;
60         struct sti_plane *plane = to_sti_plane(drm_plane);
61
62         DRM_DEBUG_DRIVER("\n");
63
64         if (property == private->plane_zorder_property) {
65                 plane->zorder = val;
66                 return 0;
67         }
68
69         return -EINVAL;
70 }
71
72 static void sti_plane_attach_zorder_property(struct drm_plane *drm_plane)
73 {
74         struct drm_device *dev = drm_plane->dev;
75         struct sti_private *private = dev->dev_private;
76         struct sti_plane *plane = to_sti_plane(drm_plane);
77         struct drm_property *prop;
78
79         prop = private->plane_zorder_property;
80         if (!prop) {
81                 prop = drm_property_create_range(dev, 0, "zpos", 1,
82                                                  GAM_MIXER_NB_DEPTH_LEVEL);
83                 if (!prop)
84                         return;
85
86                 private->plane_zorder_property = prop;
87         }
88
89         drm_object_attach_property(&drm_plane->base, prop, plane->zorder);
90 }
91
92 void sti_plane_init_property(struct sti_plane *plane,
93                              enum drm_plane_type type)
94 {
95         unsigned int i;
96
97         for (i = 0; i < ARRAY_SIZE(sti_plane_default_zorder); i++)
98                 if (sti_plane_default_zorder[i] == plane->desc)
99                         break;
100
101         plane->zorder = i + 1;
102
103         if (type == DRM_PLANE_TYPE_OVERLAY)
104                 sti_plane_attach_zorder_property(&plane->drm_plane);
105
106         DRM_DEBUG_DRIVER("drm plane:%d mapped to %s with zorder:%d\n",
107                          plane->drm_plane.base.id,
108                          sti_plane_to_str(plane), plane->zorder);
109 }
110
111 struct drm_plane_funcs sti_plane_helpers_funcs = {
112         .update_plane = drm_atomic_helper_update_plane,
113         .disable_plane = drm_atomic_helper_disable_plane,
114         .destroy = sti_plane_destroy,
115         .set_property = sti_plane_set_property,
116         .reset = drm_atomic_helper_plane_reset,
117         .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
118         .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
119 };