1 /*
2  * Copyright (C) 2016 Noralf Trønnes
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  */
9 
10 #ifndef __LINUX_DRM_SIMPLE_KMS_HELPER_H
11 #define __LINUX_DRM_SIMPLE_KMS_HELPER_H
12 
13 #include <drm/drm_crtc.h>
14 #include <drm/drm_encoder.h>
15 #include <drm/drm_plane.h>
16 
17 struct drm_simple_display_pipe;
18 
19 /**
20  * struct drm_simple_display_pipe_funcs - helper operations for a simple
21  *                                        display pipeline
22  */
23 struct drm_simple_display_pipe_funcs {
24 	/**
25 	 * @enable:
26 	 *
27 	 * This function should be used to enable the pipeline.
28 	 * It is called when the underlying crtc is enabled.
29 	 * This hook is optional.
30 	 */
31 	void (*enable)(struct drm_simple_display_pipe *pipe,
32 		       struct drm_crtc_state *crtc_state);
33 	/**
34 	 * @disable:
35 	 *
36 	 * This function should be used to disable the pipeline.
37 	 * It is called when the underlying crtc is disabled.
38 	 * This hook is optional.
39 	 */
40 	void (*disable)(struct drm_simple_display_pipe *pipe);
41 
42 	/**
43 	 * @check:
44 	 *
45 	 * This function is called in the check phase of an atomic update,
46 	 * specifically when the underlying plane is checked.
47 	 * The simple display pipeline helpers already check that the plane is
48 	 * not scaled, fills the entire visible area and is always enabled
49 	 * when the crtc is also enabled.
50 	 * This hook is optional.
51 	 *
52 	 * RETURNS:
53 	 *
54 	 * 0 on success, -EINVAL if the state or the transition can't be
55 	 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
56 	 * attempt to obtain another state object ran into a &drm_modeset_lock
57 	 * deadlock.
58 	 */
59 	int (*check)(struct drm_simple_display_pipe *pipe,
60 		     struct drm_plane_state *plane_state,
61 		     struct drm_crtc_state *crtc_state);
62 	/**
63 	 * @update:
64 	 *
65 	 * This function is called when the underlying plane state is updated.
66 	 * This hook is optional.
67 	 *
68 	 * This is the function drivers should submit the
69 	 * &drm_pending_vblank_event from. Using either
70 	 * drm_crtc_arm_vblank_event(), when the driver supports vblank
71 	 * interrupt handling, or drm_crtc_send_vblank_event() directly in case
72 	 * the hardware lacks vblank support entirely.
73 	 */
74 	void (*update)(struct drm_simple_display_pipe *pipe,
75 		       struct drm_plane_state *old_plane_state);
76 
77 	/**
78 	 * @prepare_fb:
79 	 *
80 	 * Optional, called by &drm_plane_helper_funcs.prepare_fb.  Please read
81 	 * the documentation for the &drm_plane_helper_funcs.prepare_fb hook for
82 	 * more details.
83 	 */
84 	int (*prepare_fb)(struct drm_simple_display_pipe *pipe,
85 			  struct drm_plane_state *plane_state);
86 
87 	/**
88 	 * @cleanup_fb:
89 	 *
90 	 * Optional, called by &drm_plane_helper_funcs.cleanup_fb.  Please read
91 	 * the documentation for the &drm_plane_helper_funcs.cleanup_fb hook for
92 	 * more details.
93 	 */
94 	void (*cleanup_fb)(struct drm_simple_display_pipe *pipe,
95 			   struct drm_plane_state *plane_state);
96 };
97 
98 /**
99  * struct drm_simple_display_pipe - simple display pipeline
100  * @crtc: CRTC control structure
101  * @plane: Plane control structure
102  * @encoder: Encoder control structure
103  * @connector: Connector control structure
104  * @funcs: Pipeline control functions (optional)
105  *
106  * Simple display pipeline with plane, crtc and encoder collapsed into one
107  * entity. It should be initialized by calling drm_simple_display_pipe_init().
108  */
109 struct drm_simple_display_pipe {
110 	struct drm_crtc crtc;
111 	struct drm_plane plane;
112 	struct drm_encoder encoder;
113 	struct drm_connector *connector;
114 
115 	const struct drm_simple_display_pipe_funcs *funcs;
116 };
117 
118 int drm_simple_display_pipe_attach_bridge(struct drm_simple_display_pipe *pipe,
119 					  struct drm_bridge *bridge);
120 
121 int drm_simple_display_pipe_init(struct drm_device *dev,
122 			struct drm_simple_display_pipe *pipe,
123 			const struct drm_simple_display_pipe_funcs *funcs,
124 			const uint32_t *formats, unsigned int format_count,
125 			const uint64_t *format_modifiers,
126 			struct drm_connector *connector);
127 
128 #endif /* __LINUX_DRM_SIMPLE_KMS_HELPER_H */
129