11dedbd3bSFrançois Tigeot /*
21dedbd3bSFrançois Tigeot  * Copyright (C) 2016 Noralf Trønnes
31dedbd3bSFrançois Tigeot  *
41dedbd3bSFrançois Tigeot  * This program is free software; you can redistribute it and/or modify
51dedbd3bSFrançois Tigeot  * it under the terms of the GNU General Public License as published by
61dedbd3bSFrançois Tigeot  * the Free Software Foundation; either version 2 of the License, or
71dedbd3bSFrançois Tigeot  * (at your option) any later version.
81dedbd3bSFrançois Tigeot  */
91dedbd3bSFrançois Tigeot 
101dedbd3bSFrançois Tigeot #ifndef __LINUX_DRM_SIMPLE_KMS_HELPER_H
111dedbd3bSFrançois Tigeot #define __LINUX_DRM_SIMPLE_KMS_HELPER_H
121dedbd3bSFrançois Tigeot 
13a85cb24fSFrançois Tigeot #include <drm/drm_crtc.h>
14a85cb24fSFrançois Tigeot #include <drm/drm_encoder.h>
15a85cb24fSFrançois Tigeot #include <drm/drm_plane.h>
16a85cb24fSFrançois Tigeot 
171dedbd3bSFrançois Tigeot struct drm_simple_display_pipe;
181dedbd3bSFrançois Tigeot 
191dedbd3bSFrançois Tigeot /**
201dedbd3bSFrançois Tigeot  * struct drm_simple_display_pipe_funcs - helper operations for a simple
211dedbd3bSFrançois Tigeot  *                                        display pipeline
221dedbd3bSFrançois Tigeot  */
231dedbd3bSFrançois Tigeot struct drm_simple_display_pipe_funcs {
241dedbd3bSFrançois Tigeot 	/**
251dedbd3bSFrançois Tigeot 	 * @enable:
261dedbd3bSFrançois Tigeot 	 *
271dedbd3bSFrançois Tigeot 	 * This function should be used to enable the pipeline.
281dedbd3bSFrançois Tigeot 	 * It is called when the underlying crtc is enabled.
291dedbd3bSFrançois Tigeot 	 * This hook is optional.
301dedbd3bSFrançois Tigeot 	 */
311dedbd3bSFrançois Tigeot 	void (*enable)(struct drm_simple_display_pipe *pipe,
321dedbd3bSFrançois Tigeot 		       struct drm_crtc_state *crtc_state);
331dedbd3bSFrançois Tigeot 	/**
341dedbd3bSFrançois Tigeot 	 * @disable:
351dedbd3bSFrançois Tigeot 	 *
361dedbd3bSFrançois Tigeot 	 * This function should be used to disable the pipeline.
371dedbd3bSFrançois Tigeot 	 * It is called when the underlying crtc is disabled.
381dedbd3bSFrançois Tigeot 	 * This hook is optional.
391dedbd3bSFrançois Tigeot 	 */
401dedbd3bSFrançois Tigeot 	void (*disable)(struct drm_simple_display_pipe *pipe);
411dedbd3bSFrançois Tigeot 
421dedbd3bSFrançois Tigeot 	/**
431dedbd3bSFrançois Tigeot 	 * @check:
441dedbd3bSFrançois Tigeot 	 *
451dedbd3bSFrançois Tigeot 	 * This function is called in the check phase of an atomic update,
461dedbd3bSFrançois Tigeot 	 * specifically when the underlying plane is checked.
471dedbd3bSFrançois Tigeot 	 * The simple display pipeline helpers already check that the plane is
481dedbd3bSFrançois Tigeot 	 * not scaled, fills the entire visible area and is always enabled
491dedbd3bSFrançois Tigeot 	 * when the crtc is also enabled.
501dedbd3bSFrançois Tigeot 	 * This hook is optional.
511dedbd3bSFrançois Tigeot 	 *
521dedbd3bSFrançois Tigeot 	 * RETURNS:
531dedbd3bSFrançois Tigeot 	 *
541dedbd3bSFrançois Tigeot 	 * 0 on success, -EINVAL if the state or the transition can't be
551dedbd3bSFrançois Tigeot 	 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
561dedbd3bSFrançois Tigeot 	 * attempt to obtain another state object ran into a &drm_modeset_lock
571dedbd3bSFrançois Tigeot 	 * deadlock.
581dedbd3bSFrançois Tigeot 	 */
591dedbd3bSFrançois Tigeot 	int (*check)(struct drm_simple_display_pipe *pipe,
601dedbd3bSFrançois Tigeot 		     struct drm_plane_state *plane_state,
611dedbd3bSFrançois Tigeot 		     struct drm_crtc_state *crtc_state);
621dedbd3bSFrançois Tigeot 	/**
631dedbd3bSFrançois Tigeot 	 * @update:
641dedbd3bSFrançois Tigeot 	 *
651dedbd3bSFrançois Tigeot 	 * This function is called when the underlying plane state is updated.
661dedbd3bSFrançois Tigeot 	 * This hook is optional.
671dedbd3bSFrançois Tigeot 	 *
681dedbd3bSFrançois Tigeot 	 * This is the function drivers should submit the
691dedbd3bSFrançois Tigeot 	 * &drm_pending_vblank_event from. Using either
701dedbd3bSFrançois Tigeot 	 * drm_crtc_arm_vblank_event(), when the driver supports vblank
711dedbd3bSFrançois Tigeot 	 * interrupt handling, or drm_crtc_send_vblank_event() directly in case
721dedbd3bSFrançois Tigeot 	 * the hardware lacks vblank support entirely.
731dedbd3bSFrançois Tigeot 	 */
741dedbd3bSFrançois Tigeot 	void (*update)(struct drm_simple_display_pipe *pipe,
75a85cb24fSFrançois Tigeot 		       struct drm_plane_state *old_plane_state);
761dedbd3bSFrançois Tigeot 
771dedbd3bSFrançois Tigeot 	/**
781dedbd3bSFrançois Tigeot 	 * @prepare_fb:
791dedbd3bSFrançois Tigeot 	 *
80*3f2dd94aSFrançois Tigeot 	 * Optional, called by &drm_plane_helper_funcs.prepare_fb.  Please read
81*3f2dd94aSFrançois Tigeot 	 * the documentation for the &drm_plane_helper_funcs.prepare_fb hook for
82*3f2dd94aSFrançois Tigeot 	 * more details.
831dedbd3bSFrançois Tigeot 	 */
841dedbd3bSFrançois Tigeot 	int (*prepare_fb)(struct drm_simple_display_pipe *pipe,
851dedbd3bSFrançois Tigeot 			  struct drm_plane_state *plane_state);
861dedbd3bSFrançois Tigeot 
871dedbd3bSFrançois Tigeot 	/**
881dedbd3bSFrançois Tigeot 	 * @cleanup_fb:
891dedbd3bSFrançois Tigeot 	 *
90*3f2dd94aSFrançois Tigeot 	 * Optional, called by &drm_plane_helper_funcs.cleanup_fb.  Please read
91*3f2dd94aSFrançois Tigeot 	 * the documentation for the &drm_plane_helper_funcs.cleanup_fb hook for
92*3f2dd94aSFrançois Tigeot 	 * more details.
931dedbd3bSFrançois Tigeot 	 */
941dedbd3bSFrançois Tigeot 	void (*cleanup_fb)(struct drm_simple_display_pipe *pipe,
951dedbd3bSFrançois Tigeot 			   struct drm_plane_state *plane_state);
961dedbd3bSFrançois Tigeot };
971dedbd3bSFrançois Tigeot 
981dedbd3bSFrançois Tigeot /**
991dedbd3bSFrançois Tigeot  * struct drm_simple_display_pipe - simple display pipeline
1001dedbd3bSFrançois Tigeot  * @crtc: CRTC control structure
1011dedbd3bSFrançois Tigeot  * @plane: Plane control structure
1021dedbd3bSFrançois Tigeot  * @encoder: Encoder control structure
1031dedbd3bSFrançois Tigeot  * @connector: Connector control structure
1041dedbd3bSFrançois Tigeot  * @funcs: Pipeline control functions (optional)
1051dedbd3bSFrançois Tigeot  *
1061dedbd3bSFrançois Tigeot  * Simple display pipeline with plane, crtc and encoder collapsed into one
1071dedbd3bSFrançois Tigeot  * entity. It should be initialized by calling drm_simple_display_pipe_init().
1081dedbd3bSFrançois Tigeot  */
1091dedbd3bSFrançois Tigeot struct drm_simple_display_pipe {
1101dedbd3bSFrançois Tigeot 	struct drm_crtc crtc;
1111dedbd3bSFrançois Tigeot 	struct drm_plane plane;
1121dedbd3bSFrançois Tigeot 	struct drm_encoder encoder;
1131dedbd3bSFrançois Tigeot 	struct drm_connector *connector;
1141dedbd3bSFrançois Tigeot 
1151dedbd3bSFrançois Tigeot 	const struct drm_simple_display_pipe_funcs *funcs;
1161dedbd3bSFrançois Tigeot };
1171dedbd3bSFrançois Tigeot 
1181dedbd3bSFrançois Tigeot int drm_simple_display_pipe_attach_bridge(struct drm_simple_display_pipe *pipe,
1191dedbd3bSFrançois Tigeot 					  struct drm_bridge *bridge);
1201dedbd3bSFrançois Tigeot 
1211dedbd3bSFrançois Tigeot int drm_simple_display_pipe_init(struct drm_device *dev,
1221dedbd3bSFrançois Tigeot 			struct drm_simple_display_pipe *pipe,
1231dedbd3bSFrançois Tigeot 			const struct drm_simple_display_pipe_funcs *funcs,
1241dedbd3bSFrançois Tigeot 			const uint32_t *formats, unsigned int format_count,
125*3f2dd94aSFrançois Tigeot 			const uint64_t *format_modifiers,
1261dedbd3bSFrançois Tigeot 			struct drm_connector *connector);
1271dedbd3bSFrançois Tigeot 
1281dedbd3bSFrançois Tigeot #endif /* __LINUX_DRM_SIMPLE_KMS_HELPER_H */
129