Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Copyright (C) STMicroelectronics SA 2014
  4 * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
  5 *          Fabien Dessenne <fabien.dessenne@st.com>
  6 *          for STMicroelectronics.
  7 */
  8
  9#include <linux/types.h>
 10
 11#include <drm/drm_blend.h>
 12#include <drm/drm_fourcc.h>
 13#include <drm/drm_framebuffer.h>
 14#include <drm/drm_gem_dma_helper.h>
 15
 16#include "sti_compositor.h"
 17#include "sti_drv.h"
 18#include "sti_plane.h"
 19
 20const char *sti_plane_to_str(struct sti_plane *plane)
 21{
 22	switch (plane->desc) {
 23	case STI_GDP_0:
 24		return "GDP0";
 25	case STI_GDP_1:
 26		return "GDP1";
 27	case STI_GDP_2:
 28		return "GDP2";
 29	case STI_GDP_3:
 30		return "GDP3";
 31	case STI_HQVDP_0:
 32		return "HQVDP0";
 33	case STI_CURSOR:
 34		return "CURSOR";
 35	default:
 36		return "<UNKNOWN PLANE>";
 37	}
 38}
 39
 40#define STI_FPS_INTERVAL_MS     3000
 41
 42void sti_plane_update_fps(struct sti_plane *plane,
 43			  bool new_frame,
 44			  bool new_field)
 45{
 46	struct drm_plane_state *state = plane->drm_plane.state;
 47	ktime_t now;
 48	struct sti_fps_info *fps;
 49	int fpks, fipks, ms_since_last, num_frames, num_fields;
 50
 51	now = ktime_get();
 52
 53	/* Compute number of frame updates */
 54	fps = &plane->fps_info;
 55
 56	if (new_field)
 57		fps->curr_field_counter++;
 58
 59	/* do not perform fps calcul if new_frame is false */
 60	if (!new_frame)
 61		return;
 62
 63	fps->curr_frame_counter++;
 64	ms_since_last = ktime_to_ms(ktime_sub(now, fps->last_timestamp));
 65	num_frames = fps->curr_frame_counter - fps->last_frame_counter;
 66
 67	if (num_frames <= 0  || ms_since_last < STI_FPS_INTERVAL_MS)
 68		return;
 69
 70	fps->last_timestamp = now;
 71	fps->last_frame_counter = fps->curr_frame_counter;
 72
 73	if (state->fb) {
 74		fpks = (num_frames * 1000000) / ms_since_last;
 75		snprintf(plane->fps_info.fps_str, FPS_LENGTH,
 76			 "%-8s %4dx%-4d %.4s @ %3d.%-3.3d fps (%s)",
 77			 plane->drm_plane.name,
 78			 state->fb->width,
 79			 state->fb->height,
 80			 (char *)&state->fb->format->format,
 81			 fpks / 1000, fpks % 1000,
 82			 sti_plane_to_str(plane));
 83	}
 84
 85	if (fps->curr_field_counter) {
 86		/* Compute number of field updates */
 87		num_fields = fps->curr_field_counter - fps->last_field_counter;
 88		fps->last_field_counter = fps->curr_field_counter;
 89		fipks = (num_fields * 1000000) / ms_since_last;
 90		snprintf(plane->fps_info.fips_str,
 91			 FPS_LENGTH, " - %3d.%-3.3d field/sec",
 92			 fipks / 1000, fipks % 1000);
 93	} else {
 94		plane->fps_info.fips_str[0] = '\0';
 95	}
 96
 97	if (fps->output)
 98		DRM_INFO("%s%s\n",
 99			 plane->fps_info.fps_str,
100			 plane->fps_info.fips_str);
101}
102
103static int sti_plane_get_default_zpos(enum drm_plane_type type)
104{
105	switch (type) {
106	case DRM_PLANE_TYPE_PRIMARY:
107		return 0;
108	case DRM_PLANE_TYPE_OVERLAY:
109		return 1;
110	case DRM_PLANE_TYPE_CURSOR:
111		return 7;
112	}
113	return 0;
 
 
 
 
 
 
114}
115
116static void sti_plane_attach_zorder_property(struct drm_plane *drm_plane,
117					     enum drm_plane_type type)
118{
119	int zpos = sti_plane_get_default_zpos(type);
120
121	switch (type) {
122	case DRM_PLANE_TYPE_PRIMARY:
123	case DRM_PLANE_TYPE_OVERLAY:
124		drm_plane_create_zpos_property(drm_plane, zpos, 0, 6);
125		break;
126	case DRM_PLANE_TYPE_CURSOR:
127		drm_plane_create_zpos_immutable_property(drm_plane, zpos);
128		break;
129	}
130}
131
132void sti_plane_init_property(struct sti_plane *plane,
133			     enum drm_plane_type type)
134{
135	sti_plane_attach_zorder_property(&plane->drm_plane, type);
136
137	DRM_DEBUG_DRIVER("drm plane:%d mapped to %s\n",
138			 plane->drm_plane.base.id, sti_plane_to_str(plane));
139}
v4.17
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Copyright (C) STMicroelectronics SA 2014
  4 * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
  5 *          Fabien Dessenne <fabien.dessenne@st.com>
  6 *          for STMicroelectronics.
  7 */
  8
  9#include <drm/drmP.h>
 10#include <drm/drm_fb_cma_helper.h>
 11#include <drm/drm_gem_cma_helper.h>
 
 
 
 12
 13#include "sti_compositor.h"
 14#include "sti_drv.h"
 15#include "sti_plane.h"
 16
 17const char *sti_plane_to_str(struct sti_plane *plane)
 18{
 19	switch (plane->desc) {
 20	case STI_GDP_0:
 21		return "GDP0";
 22	case STI_GDP_1:
 23		return "GDP1";
 24	case STI_GDP_2:
 25		return "GDP2";
 26	case STI_GDP_3:
 27		return "GDP3";
 28	case STI_HQVDP_0:
 29		return "HQVDP0";
 30	case STI_CURSOR:
 31		return "CURSOR";
 32	default:
 33		return "<UNKNOWN PLANE>";
 34	}
 35}
 36
 37#define STI_FPS_INTERVAL_MS     3000
 38
 39void sti_plane_update_fps(struct sti_plane *plane,
 40			  bool new_frame,
 41			  bool new_field)
 42{
 
 43	ktime_t now;
 44	struct sti_fps_info *fps;
 45	int fpks, fipks, ms_since_last, num_frames, num_fields;
 46
 47	now = ktime_get();
 48
 49	/* Compute number of frame updates */
 50	fps = &plane->fps_info;
 51
 52	if (new_field)
 53		fps->curr_field_counter++;
 54
 55	/* do not perform fps calcul if new_frame is false */
 56	if (!new_frame)
 57		return;
 58
 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;
 62
 63	if (num_frames <= 0  || ms_since_last < STI_FPS_INTERVAL_MS)
 64		return;
 65
 66	fps->last_timestamp = now;
 67	fps->last_frame_counter = fps->curr_frame_counter;
 68
 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));
 79	}
 80
 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);
 89	} else {
 90		plane->fps_info.fips_str[0] = '\0';
 91	}
 92
 93	if (fps->output)
 94		DRM_INFO("%s%s\n",
 95			 plane->fps_info.fps_str,
 96			 plane->fps_info.fips_str);
 97}
 98
 99static int sti_plane_get_default_zpos(enum drm_plane_type type)
100{
101	switch (type) {
102	case DRM_PLANE_TYPE_PRIMARY:
103		return 0;
104	case DRM_PLANE_TYPE_OVERLAY:
105		return 1;
106	case DRM_PLANE_TYPE_CURSOR:
107		return 7;
108	}
109	return 0;
110}
111
112void sti_plane_reset(struct drm_plane *plane)
113{
114	drm_atomic_helper_plane_reset(plane);
115	plane->state->zpos = sti_plane_get_default_zpos(plane->type);
116}
117
118static void sti_plane_attach_zorder_property(struct drm_plane *drm_plane,
119					     enum drm_plane_type type)
120{
121	int zpos = sti_plane_get_default_zpos(type);
122
123	switch (type) {
124	case DRM_PLANE_TYPE_PRIMARY:
125	case DRM_PLANE_TYPE_OVERLAY:
126		drm_plane_create_zpos_property(drm_plane, zpos, 0, 6);
127		break;
128	case DRM_PLANE_TYPE_CURSOR:
129		drm_plane_create_zpos_immutable_property(drm_plane, zpos);
130		break;
131	}
132}
133
134void sti_plane_init_property(struct sti_plane *plane,
135			     enum drm_plane_type type)
136{
137	sti_plane_attach_zorder_property(&plane->drm_plane, type);
138
139	DRM_DEBUG_DRIVER("drm plane:%d mapped to %s\n",
140			 plane->drm_plane.base.id, sti_plane_to_str(plane));
141}