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
10 #include <drm/drm_fb_cma_helper.h>
11 #include <drm/drm_gem_cma_helper.h>
13 #include "sti_compositor.h"
15 #include "sti_plane.h"
17 /* (Background) < GDP0 < GDP1 < HQVDP0 < GDP2 < GDP3 < (ForeGround) */
18 enum sti_plane_desc sti_plane_default_zorder[] = {
26 const char *sti_plane_to_str(struct sti_plane *plane)
28 switch (plane->desc) {
42 return "<UNKNOWN PLANE>";
46 #define STI_FPS_INTERVAL_MS 3000
48 void sti_plane_update_fps(struct sti_plane *plane,
53 struct sti_fps_info *fps;
54 int fpks, fipks, ms_since_last, num_frames, num_fields;
58 /* Compute number of frame updates */
59 fps = &plane->fps_info;
62 fps->curr_field_counter++;
64 /* do not perform fps calcul if new_frame is false */
68 fps->curr_frame_counter++;
69 ms_since_last = ktime_to_ms(ktime_sub(now, fps->last_timestamp));
70 num_frames = fps->curr_frame_counter - fps->last_frame_counter;
72 if (num_frames <= 0 || ms_since_last < STI_FPS_INTERVAL_MS)
75 fps->last_timestamp = now;
76 fps->last_frame_counter = fps->curr_frame_counter;
77 fpks = (num_frames * 1000000) / ms_since_last;
78 snprintf(plane->fps_info.fps_str, FPS_LENGTH, "%-6s @ %d.%.3d fps",
79 sti_plane_to_str(plane), fpks / 1000, fpks % 1000);
81 if (fps->curr_field_counter) {
82 /* Compute number of field updates */
83 num_fields = fps->curr_field_counter - fps->last_field_counter;
84 fps->last_field_counter = fps->curr_field_counter;
85 fipks = (num_fields * 1000000) / ms_since_last;
86 snprintf(plane->fps_info.fips_str,
87 FPS_LENGTH, " - %d.%.3d field/sec",
88 fipks / 1000, fipks % 1000);
90 plane->fps_info.fips_str[0] = '\0';
95 plane->fps_info.fps_str,
96 plane->fps_info.fips_str);
99 int sti_plane_set_property(struct drm_plane *drm_plane,
100 struct drm_property *property,
103 struct drm_device *dev = drm_plane->dev;
104 struct sti_private *private = dev->dev_private;
105 struct sti_plane *plane = to_sti_plane(drm_plane);
107 DRM_DEBUG_DRIVER("\n");
109 if (property == private->plane_zorder_property) {
117 static void sti_plane_attach_zorder_property(struct drm_plane *drm_plane)
119 struct drm_device *dev = drm_plane->dev;
120 struct sti_private *private = dev->dev_private;
121 struct sti_plane *plane = to_sti_plane(drm_plane);
122 struct drm_property *prop;
124 prop = private->plane_zorder_property;
126 prop = drm_property_create_range(dev, 0, "zpos", 1,
127 GAM_MIXER_NB_DEPTH_LEVEL);
131 private->plane_zorder_property = prop;
134 drm_object_attach_property(&drm_plane->base, prop, plane->zorder);
137 void sti_plane_init_property(struct sti_plane *plane,
138 enum drm_plane_type type)
142 for (i = 0; i < ARRAY_SIZE(sti_plane_default_zorder); i++)
143 if (sti_plane_default_zorder[i] == plane->desc)
146 plane->zorder = i + 1;
148 if (type == DRM_PLANE_TYPE_OVERLAY)
149 sti_plane_attach_zorder_property(&plane->drm_plane);
151 DRM_DEBUG_DRIVER("drm plane:%d mapped to %s with zorder:%d\n",
152 plane->drm_plane.base.id,
153 sti_plane_to_str(plane), plane->zorder);