2 * Copyright (C) STMicroelectronics SA 2014
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 const char *sti_plane_to_str(struct sti_plane *plane)
19 switch (plane->desc) {
33 return "<UNKNOWN PLANE>";
37 #define STI_FPS_INTERVAL_MS 3000
39 void sti_plane_update_fps(struct sti_plane *plane,
44 struct sti_fps_info *fps;
45 int fpks, fipks, ms_since_last, num_frames, num_fields;
49 /* Compute number of frame updates */
50 fps = &plane->fps_info;
53 fps->curr_field_counter++;
55 /* do not perform fps calcul if new_frame is false */
59 fps->curr_frame_counter++;
60 ms_since_last = ktime_to_ms(ktime_sub(now, fps->last_timestamp));
61 num_frames = fps->curr_frame_counter - fps->last_frame_counter;
63 if (num_frames <= 0 || ms_since_last < STI_FPS_INTERVAL_MS)
66 fps->last_timestamp = now;
67 fps->last_frame_counter = fps->curr_frame_counter;
69 if (plane->drm_plane.fb) {
70 fpks = (num_frames * 1000000) / ms_since_last;
71 snprintf(plane->fps_info.fps_str, FPS_LENGTH,
72 "%-8s %4dx%-4d %.4s @ %3d.%-3.3d fps (%s)",
73 plane->drm_plane.name,
74 plane->drm_plane.fb->width,
75 plane->drm_plane.fb->height,
76 (char *)&plane->drm_plane.fb->format->format,
77 fpks / 1000, fpks % 1000,
78 sti_plane_to_str(plane));
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, " - %3d.%-3.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 static int sti_plane_get_default_zpos(enum drm_plane_type type)
102 case DRM_PLANE_TYPE_PRIMARY:
104 case DRM_PLANE_TYPE_OVERLAY:
106 case DRM_PLANE_TYPE_CURSOR:
112 void sti_plane_reset(struct drm_plane *plane)
114 drm_atomic_helper_plane_reset(plane);
115 plane->state->zpos = sti_plane_get_default_zpos(plane->type);
118 static void sti_plane_attach_zorder_property(struct drm_plane *drm_plane,
119 enum drm_plane_type type)
121 int zpos = sti_plane_get_default_zpos(type);
124 case DRM_PLANE_TYPE_PRIMARY:
125 case DRM_PLANE_TYPE_OVERLAY:
126 drm_plane_create_zpos_property(drm_plane, zpos, 0, 6);
128 case DRM_PLANE_TYPE_CURSOR:
129 drm_plane_create_zpos_immutable_property(drm_plane, zpos);
134 void sti_plane_init_property(struct sti_plane *plane,
135 enum drm_plane_type type)
137 sti_plane_attach_zorder_property(&plane->drm_plane, type);
139 DRM_DEBUG_DRIVER("drm plane:%d mapped to %s\n",
140 plane->drm_plane.base.id, sti_plane_to_str(plane));