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 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
;
68 fpks
= (num_frames
* 1000000) / ms_since_last
;
69 snprintf(plane
->fps_info
.fps_str
, FPS_LENGTH
, "%-6s @ %d.%.3d fps",
70 sti_plane_to_str(plane
), fpks
/ 1000, fpks
% 1000);
72 if (fps
->curr_field_counter
) {
73 /* Compute number of field updates */
74 num_fields
= fps
->curr_field_counter
- fps
->last_field_counter
;
75 fps
->last_field_counter
= fps
->curr_field_counter
;
76 fipks
= (num_fields
* 1000000) / ms_since_last
;
77 snprintf(plane
->fps_info
.fips_str
,
78 FPS_LENGTH
, " - %d.%.3d field/sec",
79 fipks
/ 1000, fipks
% 1000);
81 plane
->fps_info
.fips_str
[0] = '\0';
86 plane
->fps_info
.fps_str
,
87 plane
->fps_info
.fips_str
);
90 static int sti_plane_get_default_zpos(enum drm_plane_type type
)
93 case DRM_PLANE_TYPE_PRIMARY
:
95 case DRM_PLANE_TYPE_OVERLAY
:
97 case DRM_PLANE_TYPE_CURSOR
:
103 void sti_plane_reset(struct drm_plane
*plane
)
105 drm_atomic_helper_plane_reset(plane
);
106 plane
->state
->zpos
= sti_plane_get_default_zpos(plane
->type
);
109 static void sti_plane_attach_zorder_property(struct drm_plane
*drm_plane
,
110 enum drm_plane_type type
)
112 int zpos
= sti_plane_get_default_zpos(type
);
115 case DRM_PLANE_TYPE_PRIMARY
:
116 case DRM_PLANE_TYPE_OVERLAY
:
117 drm_plane_create_zpos_property(drm_plane
, zpos
, 0, 6);
119 case DRM_PLANE_TYPE_CURSOR
:
120 drm_plane_create_zpos_immutable_property(drm_plane
, zpos
);
125 void sti_plane_init_property(struct sti_plane
*plane
,
126 enum drm_plane_type type
)
128 sti_plane_attach_zorder_property(&plane
->drm_plane
, type
);
130 DRM_DEBUG_DRIVER("drm plane:%d mapped to %s\n",
131 plane
->drm_plane
.base
.id
, sti_plane_to_str(plane
));