Merge branch 'drm-next-4.7' of git://people.freedesktop.org/~agd5f/linux into drm...
[deliverable/linux.git] / drivers / gpu / drm / sti / sti_plane.c
CommitLineData
9bbf86fe
BG
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
de4b00b0 9#include <drm/drmP.h>
871bcdfe 10#include <drm/drm_fb_cma_helper.h>
29d1dc62 11#include <drm/drm_gem_cma_helper.h>
de4b00b0 12
9bbf86fe 13#include "sti_compositor.h"
9e1f05b2
VA
14#include "sti_drv.h"
15#include "sti_plane.h"
9bbf86fe 16
871bcdfe
VA
17/* (Background) < GDP0 < GDP1 < HQVDP0 < GDP2 < GDP3 < (ForeGround) */
18enum sti_plane_desc sti_plane_default_zorder[] = {
9bbf86fe 19 STI_GDP_0,
9bbf86fe 20 STI_GDP_1,
871bcdfe 21 STI_HQVDP_0,
9bbf86fe
BG
22 STI_GDP_2,
23 STI_GDP_3,
24};
25
871bcdfe 26const char *sti_plane_to_str(struct sti_plane *plane)
9bbf86fe 27{
871bcdfe
VA
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}
871bcdfe 45
bf8f9e4a
VA
46#define STI_FPS_INTERVAL_MS 3000
47
48static int sti_plane_timespec_ms_diff(struct timespec lhs, struct timespec rhs)
49{
50 struct timespec tmp_ts = timespec_sub(lhs, rhs);
51 u64 tmp_ns = (u64)timespec_to_ns(&tmp_ts);
52
53 do_div(tmp_ns, NSEC_PER_MSEC);
54
55 return (u32)tmp_ns;
56}
57
58void sti_plane_update_fps(struct sti_plane *plane,
59 bool new_frame,
60 bool new_field)
61{
62 struct timespec now;
63 struct sti_fps_info *fps;
64 int fpks, fipks, ms_since_last, num_frames, num_fields;
65
66 getrawmonotonic(&now);
67
68 /* Compute number of frame updates */
69 fps = &plane->fps_info;
70
71 if (new_field)
72 fps->curr_field_counter++;
73
74 /* do not perform fps calcul if new_frame is false */
75 if (!new_frame)
76 return;
77
78 fps->curr_frame_counter++;
79 ms_since_last = sti_plane_timespec_ms_diff(now, fps->last_timestamp);
80 num_frames = fps->curr_frame_counter - fps->last_frame_counter;
81
82 if (num_frames <= 0 || ms_since_last < STI_FPS_INTERVAL_MS)
83 return;
84
85 fps->last_timestamp = now;
86 fps->last_frame_counter = fps->curr_frame_counter;
87 fpks = (num_frames * 1000000) / ms_since_last;
88 snprintf(plane->fps_info.fps_str, FPS_LENGTH, "%-6s @ %d.%.3d fps",
89 sti_plane_to_str(plane), fpks / 1000, fpks % 1000);
90
91 if (fps->curr_field_counter) {
92 /* Compute number of field updates */
93 num_fields = fps->curr_field_counter - fps->last_field_counter;
94 fps->last_field_counter = fps->curr_field_counter;
95 fipks = (num_fields * 1000000) / ms_since_last;
96 snprintf(plane->fps_info.fips_str,
97 FPS_LENGTH, " - %d.%.3d field/sec",
98 fipks / 1000, fipks % 1000);
99 } else {
100 plane->fps_info.fips_str[0] = '\0';
101 }
102
103 if (fps->output)
104 DRM_INFO("%s%s\n",
105 plane->fps_info.fps_str,
106 plane->fps_info.fips_str);
107}
108
9e1f05b2 109static void sti_plane_destroy(struct drm_plane *drm_plane)
9bbf86fe
BG
110{
111 DRM_DEBUG_DRIVER("\n");
112
871bcdfe
VA
113 drm_plane_helper_disable(drm_plane);
114 drm_plane_cleanup(drm_plane);
9bbf86fe
BG
115}
116
9e1f05b2
VA
117static int sti_plane_set_property(struct drm_plane *drm_plane,
118 struct drm_property *property,
119 uint64_t val)
9bbf86fe 120{
871bcdfe 121 struct drm_device *dev = drm_plane->dev;
9e1f05b2 122 struct sti_private *private = dev->dev_private;
871bcdfe 123 struct sti_plane *plane = to_sti_plane(drm_plane);
9bbf86fe
BG
124
125 DRM_DEBUG_DRIVER("\n");
126
127 if (property == private->plane_zorder_property) {
871bcdfe 128 plane->zorder = val;
9bbf86fe
BG
129 return 0;
130 }
131
132 return -EINVAL;
133}
134
9e1f05b2 135static void sti_plane_attach_zorder_property(struct drm_plane *drm_plane)
9bbf86fe 136{
871bcdfe 137 struct drm_device *dev = drm_plane->dev;
9e1f05b2 138 struct sti_private *private = dev->dev_private;
871bcdfe 139 struct sti_plane *plane = to_sti_plane(drm_plane);
9bbf86fe 140 struct drm_property *prop;
9bbf86fe
BG
141
142 prop = private->plane_zorder_property;
143 if (!prop) {
bf60b29f
VA
144 prop = drm_property_create_range(dev, 0, "zpos", 1,
145 GAM_MIXER_NB_DEPTH_LEVEL);
9bbf86fe
BG
146 if (!prop)
147 return;
148
149 private->plane_zorder_property = prop;
150 }
151
871bcdfe 152 drm_object_attach_property(&drm_plane->base, prop, plane->zorder);
9bbf86fe
BG
153}
154
29d1dc62
VA
155void sti_plane_init_property(struct sti_plane *plane,
156 enum drm_plane_type type)
9bbf86fe 157{
29d1dc62 158 unsigned int i;
de4b00b0 159
871bcdfe
VA
160 for (i = 0; i < ARRAY_SIZE(sti_plane_default_zorder); i++)
161 if (sti_plane_default_zorder[i] == plane->desc)
9bbf86fe
BG
162 break;
163
871bcdfe 164 plane->zorder = i + 1;
9bbf86fe
BG
165
166 if (type == DRM_PLANE_TYPE_OVERLAY)
9e1f05b2 167 sti_plane_attach_zorder_property(&plane->drm_plane);
9bbf86fe 168
871bcdfe
VA
169 DRM_DEBUG_DRIVER("drm plane:%d mapped to %s with zorder:%d\n",
170 plane->drm_plane.base.id,
171 sti_plane_to_str(plane), plane->zorder);
9bbf86fe 172}
29d1dc62
VA
173
174struct drm_plane_funcs sti_plane_helpers_funcs = {
175 .update_plane = drm_atomic_helper_update_plane,
176 .disable_plane = drm_atomic_helper_disable_plane,
177 .destroy = sti_plane_destroy,
178 .set_property = sti_plane_set_property,
179 .reset = drm_atomic_helper_plane_reset,
180 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
181 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
182};
This page took 0.219249 seconds and 5 git commands to generate.