1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) STMicroelectronics SA 2014
4 * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
5 * Fabien Dessenne <fabien.dessenne@st.com>
6 * for STMicroelectronics.
9 #include <linux/types.h>
11 #include <drm/drm_fb_cma_helper.h>
12 #include <drm/drm_fourcc.h>
13 #include <drm/drm_gem_cma_helper.h>
15 #include "sti_compositor.h"
17 #include "sti_plane.h"
19 const char *sti_plane_to_str(struct sti_plane
*plane
)
21 switch (plane
->desc
) {
35 return "<UNKNOWN PLANE>";
39 #define STI_FPS_INTERVAL_MS 3000
41 void sti_plane_update_fps(struct sti_plane
*plane
,
45 struct drm_plane_state
*state
= plane
->drm_plane
.state
;
47 struct sti_fps_info
*fps
;
48 int fpks
, fipks
, ms_since_last
, num_frames
, num_fields
;
52 /* Compute number of frame updates */
53 fps
= &plane
->fps_info
;
56 fps
->curr_field_counter
++;
58 /* do not perform fps calcul if new_frame is false */
62 fps
->curr_frame_counter
++;
63 ms_since_last
= ktime_to_ms(ktime_sub(now
, fps
->last_timestamp
));
64 num_frames
= fps
->curr_frame_counter
- fps
->last_frame_counter
;
66 if (num_frames
<= 0 || ms_since_last
< STI_FPS_INTERVAL_MS
)
69 fps
->last_timestamp
= now
;
70 fps
->last_frame_counter
= fps
->curr_frame_counter
;
73 fpks
= (num_frames
* 1000000) / ms_since_last
;
74 snprintf(plane
->fps_info
.fps_str
, FPS_LENGTH
,
75 "%-8s %4dx%-4d %.4s @ %3d.%-3.3d fps (%s)",
76 plane
->drm_plane
.name
,
79 (char *)&state
->fb
->format
->format
,
80 fpks
/ 1000, fpks
% 1000,
81 sti_plane_to_str(plane
));
84 if (fps
->curr_field_counter
) {
85 /* Compute number of field updates */
86 num_fields
= fps
->curr_field_counter
- fps
->last_field_counter
;
87 fps
->last_field_counter
= fps
->curr_field_counter
;
88 fipks
= (num_fields
* 1000000) / ms_since_last
;
89 snprintf(plane
->fps_info
.fips_str
,
90 FPS_LENGTH
, " - %3d.%-3.3d field/sec",
91 fipks
/ 1000, fipks
% 1000);
93 plane
->fps_info
.fips_str
[0] = '\0';
98 plane
->fps_info
.fps_str
,
99 plane
->fps_info
.fips_str
);
102 static int sti_plane_get_default_zpos(enum drm_plane_type type
)
105 case DRM_PLANE_TYPE_PRIMARY
:
107 case DRM_PLANE_TYPE_OVERLAY
:
109 case DRM_PLANE_TYPE_CURSOR
:
115 void sti_plane_reset(struct drm_plane
*plane
)
117 drm_atomic_helper_plane_reset(plane
);
118 plane
->state
->zpos
= sti_plane_get_default_zpos(plane
->type
);
121 static void sti_plane_attach_zorder_property(struct drm_plane
*drm_plane
,
122 enum drm_plane_type type
)
124 int zpos
= sti_plane_get_default_zpos(type
);
127 case DRM_PLANE_TYPE_PRIMARY
:
128 case DRM_PLANE_TYPE_OVERLAY
:
129 drm_plane_create_zpos_property(drm_plane
, zpos
, 0, 6);
131 case DRM_PLANE_TYPE_CURSOR
:
132 drm_plane_create_zpos_immutable_property(drm_plane
, zpos
);
137 void sti_plane_init_property(struct sti_plane
*plane
,
138 enum drm_plane_type type
)
140 sti_plane_attach_zorder_property(&plane
->drm_plane
, type
);
142 DRM_DEBUG_DRIVER("drm plane:%d mapped to %s\n",
143 plane
->drm_plane
.base
.id
, sti_plane_to_str(plane
));