xref: /linux/include/drm/drm_simple_kms_helper.h (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
25b809074SNoralf Trønnes /*
35b809074SNoralf Trønnes  * Copyright (C) 2016 Noralf Trønnes
45b809074SNoralf Trønnes  */
55b809074SNoralf Trønnes 
65b809074SNoralf Trønnes #ifndef __LINUX_DRM_SIMPLE_KMS_HELPER_H
75b809074SNoralf Trønnes #define __LINUX_DRM_SIMPLE_KMS_HELPER_H
85b809074SNoralf Trønnes 
9a6a9534cSNoralf Trønnes #include <drm/drm_crtc.h>
10a6a9534cSNoralf Trønnes #include <drm/drm_encoder.h>
11a6a9534cSNoralf Trønnes #include <drm/drm_plane.h>
12a6a9534cSNoralf Trønnes 
135b809074SNoralf Trønnes struct drm_simple_display_pipe;
145b809074SNoralf Trønnes 
155b809074SNoralf Trønnes /**
165b809074SNoralf Trønnes  * struct drm_simple_display_pipe_funcs - helper operations for a simple
175b809074SNoralf Trønnes  *                                        display pipeline
185b809074SNoralf Trønnes  */
195b809074SNoralf Trønnes struct drm_simple_display_pipe_funcs {
205b809074SNoralf Trønnes 	/**
2140275dc4SLinus Walleij 	 * @mode_valid:
2240275dc4SLinus Walleij 	 *
23afe09e43SLinus Walleij 	 * This callback is used to check if a specific mode is valid in the
24afe09e43SLinus Walleij 	 * crtc used in this simple display pipe. This should be implemented
25afe09e43SLinus Walleij 	 * if the display pipe has some sort of restriction in the modes
26afe09e43SLinus Walleij 	 * it can display. For example, a given display pipe may be responsible
27afe09e43SLinus Walleij 	 * to set a clock value. If the clock can not produce all the values
28afe09e43SLinus Walleij 	 * for the available modes then this callback can be used to restrict
29afe09e43SLinus Walleij 	 * the number of modes to only the ones that can be displayed. Another
30afe09e43SLinus Walleij 	 * reason can be bandwidth mitigation: the memory port on the display
31afe09e43SLinus Walleij 	 * controller can have bandwidth limitations not allowing pixel data
32afe09e43SLinus Walleij 	 * to be fetched at any rate.
33afe09e43SLinus Walleij 	 *
34afe09e43SLinus Walleij 	 * This hook is used by the probe helpers to filter the mode list in
35afe09e43SLinus Walleij 	 * drm_helper_probe_single_connector_modes(), and it is used by the
36afe09e43SLinus Walleij 	 * atomic helpers to validate modes supplied by userspace in
37afe09e43SLinus Walleij 	 * drm_atomic_helper_check_modeset().
38afe09e43SLinus Walleij 	 *
39afe09e43SLinus Walleij 	 * This function is optional.
40afe09e43SLinus Walleij 	 *
41afe09e43SLinus Walleij 	 * NOTE:
42afe09e43SLinus Walleij 	 *
43afe09e43SLinus Walleij 	 * Since this function is both called from the check phase of an atomic
44afe09e43SLinus Walleij 	 * commit, and the mode validation in the probe paths it is not allowed
45afe09e43SLinus Walleij 	 * to look at anything else but the passed-in mode, and validate it
46afe09e43SLinus Walleij 	 * against configuration-invariant hardware constraints.
4740275dc4SLinus Walleij 	 *
4840275dc4SLinus Walleij 	 * RETURNS:
4940275dc4SLinus Walleij 	 *
5040275dc4SLinus Walleij 	 * drm_mode_status Enum
5140275dc4SLinus Walleij 	 */
5262db7d1eSDaniel Vetter 	enum drm_mode_status (*mode_valid)(struct drm_simple_display_pipe *pipe,
5340275dc4SLinus Walleij 					   const struct drm_display_mode *mode);
5440275dc4SLinus Walleij 
5540275dc4SLinus Walleij 	/**
565b809074SNoralf Trønnes 	 * @enable:
575b809074SNoralf Trønnes 	 *
585b809074SNoralf Trønnes 	 * This function should be used to enable the pipeline.
595b809074SNoralf Trønnes 	 * It is called when the underlying crtc is enabled.
605b809074SNoralf Trønnes 	 * This hook is optional.
615b809074SNoralf Trønnes 	 */
625b809074SNoralf Trønnes 	void (*enable)(struct drm_simple_display_pipe *pipe,
630c9c7fd0SVille Syrjälä 		       struct drm_crtc_state *crtc_state,
640c9c7fd0SVille Syrjälä 		       struct drm_plane_state *plane_state);
655b809074SNoralf Trønnes 	/**
665b809074SNoralf Trønnes 	 * @disable:
675b809074SNoralf Trønnes 	 *
685b809074SNoralf Trønnes 	 * This function should be used to disable the pipeline.
695b809074SNoralf Trønnes 	 * It is called when the underlying crtc is disabled.
705b809074SNoralf Trønnes 	 * This hook is optional.
715b809074SNoralf Trønnes 	 */
725b809074SNoralf Trønnes 	void (*disable)(struct drm_simple_display_pipe *pipe);
735b809074SNoralf Trønnes 
745b809074SNoralf Trønnes 	/**
755b809074SNoralf Trønnes 	 * @check:
765b809074SNoralf Trønnes 	 *
775b809074SNoralf Trønnes 	 * This function is called in the check phase of an atomic update,
785b809074SNoralf Trønnes 	 * specifically when the underlying plane is checked.
795b809074SNoralf Trønnes 	 * The simple display pipeline helpers already check that the plane is
805b809074SNoralf Trønnes 	 * not scaled, fills the entire visible area and is always enabled
815b809074SNoralf Trønnes 	 * when the crtc is also enabled.
825b809074SNoralf Trønnes 	 * This hook is optional.
835b809074SNoralf Trønnes 	 *
845b809074SNoralf Trønnes 	 * RETURNS:
855b809074SNoralf Trønnes 	 *
865b809074SNoralf Trønnes 	 * 0 on success, -EINVAL if the state or the transition can't be
875b809074SNoralf Trønnes 	 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
885b809074SNoralf Trønnes 	 * attempt to obtain another state object ran into a &drm_modeset_lock
895b809074SNoralf Trønnes 	 * deadlock.
905b809074SNoralf Trønnes 	 */
915b809074SNoralf Trønnes 	int (*check)(struct drm_simple_display_pipe *pipe,
925b809074SNoralf Trønnes 		     struct drm_plane_state *plane_state,
935b809074SNoralf Trønnes 		     struct drm_crtc_state *crtc_state);
945b809074SNoralf Trønnes 	/**
955b809074SNoralf Trønnes 	 * @update:
965b809074SNoralf Trønnes 	 *
975b809074SNoralf Trønnes 	 * This function is called when the underlying plane state is updated.
985b809074SNoralf Trønnes 	 * This hook is optional.
996dcf0de7SDaniel Vetter 	 *
1006dcf0de7SDaniel Vetter 	 * This is the function drivers should submit the
1016dcf0de7SDaniel Vetter 	 * &drm_pending_vblank_event from. Using either
1026dcf0de7SDaniel Vetter 	 * drm_crtc_arm_vblank_event(), when the driver supports vblank
1037beb691fSThomas Zimmermann 	 * interrupt handling, or drm_crtc_send_vblank_event() for more
1047beb691fSThomas Zimmermann 	 * complex case. In case the hardware lacks vblank support entirely,
1057beb691fSThomas Zimmermann 	 * drivers can set &struct drm_crtc_state.no_vblank in
1067beb691fSThomas Zimmermann 	 * &struct drm_simple_display_pipe_funcs.check and let DRM's
1077beb691fSThomas Zimmermann 	 * atomic helper fake a vblank event.
1085b809074SNoralf Trønnes 	 */
1095b809074SNoralf Trønnes 	void (*update)(struct drm_simple_display_pipe *pipe,
110bcd2ba02SEric Anholt 		       struct drm_plane_state *old_plane_state);
1117d83a155SMarek Vasut 
1127d83a155SMarek Vasut 	/**
1137d83a155SMarek Vasut 	 * @prepare_fb:
1147d83a155SMarek Vasut 	 *
1156806cdf9SDaniel Vetter 	 * Optional, called by &drm_plane_helper_funcs.prepare_fb.  Please read
1166806cdf9SDaniel Vetter 	 * the documentation for the &drm_plane_helper_funcs.prepare_fb hook for
1176806cdf9SDaniel Vetter 	 * more details.
118ccc3b2b3SDaniel Vetter 	 *
11940cfc7fcSDaniel Vetter 	 * For GEM drivers who neither have a @prepare_fb nor @cleanup_fb hook
120*00b5497dSThomas Zimmermann 	 * set, drm_gem_plane_helper_prepare_fb() is called automatically
12140cfc7fcSDaniel Vetter 	 * to implement this. Other drivers which need additional plane
122*00b5497dSThomas Zimmermann 	 * processing can call drm_gem_plane_helper_prepare_fb() from
12340cfc7fcSDaniel Vetter 	 * their @prepare_fb hook.
1247d83a155SMarek Vasut 	 */
1257d83a155SMarek Vasut 	int (*prepare_fb)(struct drm_simple_display_pipe *pipe,
1267d83a155SMarek Vasut 			  struct drm_plane_state *plane_state);
1277d83a155SMarek Vasut 
1287d83a155SMarek Vasut 	/**
1297d83a155SMarek Vasut 	 * @cleanup_fb:
1307d83a155SMarek Vasut 	 *
1316806cdf9SDaniel Vetter 	 * Optional, called by &drm_plane_helper_funcs.cleanup_fb.  Please read
1326806cdf9SDaniel Vetter 	 * the documentation for the &drm_plane_helper_funcs.cleanup_fb hook for
1336806cdf9SDaniel Vetter 	 * more details.
1347d83a155SMarek Vasut 	 */
1357d83a155SMarek Vasut 	void (*cleanup_fb)(struct drm_simple_display_pipe *pipe,
1367d83a155SMarek Vasut 			   struct drm_plane_state *plane_state);
137ac86cba9SOleksandr Andrushchenko 
138ac86cba9SOleksandr Andrushchenko 	/**
13994d879eaSThomas Zimmermann 	 * @begin_fb_access:
14094d879eaSThomas Zimmermann 	 *
14194d879eaSThomas Zimmermann 	 * Optional, called by &drm_plane_helper_funcs.begin_fb_access. Please read
14294d879eaSThomas Zimmermann 	 * the documentation for the &drm_plane_helper_funcs.begin_fb_access hook for
14394d879eaSThomas Zimmermann 	 * more details.
14494d879eaSThomas Zimmermann 	 */
14594d879eaSThomas Zimmermann 	int (*begin_fb_access)(struct drm_simple_display_pipe *pipe,
14694d879eaSThomas Zimmermann 			       struct drm_plane_state *new_plane_state);
14794d879eaSThomas Zimmermann 
14894d879eaSThomas Zimmermann 	/**
14994d879eaSThomas Zimmermann 	 * @end_fb_access:
15094d879eaSThomas Zimmermann 	 *
15194d879eaSThomas Zimmermann 	 * Optional, called by &drm_plane_helper_funcs.end_fb_access. Please read
15294d879eaSThomas Zimmermann 	 * the documentation for the &drm_plane_helper_funcs.end_fb_access hook for
15394d879eaSThomas Zimmermann 	 * more details.
15494d879eaSThomas Zimmermann 	 */
15594d879eaSThomas Zimmermann 	void (*end_fb_access)(struct drm_simple_display_pipe *pipe,
15694d879eaSThomas Zimmermann 			      struct drm_plane_state *plane_state);
15794d879eaSThomas Zimmermann 
15894d879eaSThomas Zimmermann 	/**
159ac86cba9SOleksandr Andrushchenko 	 * @enable_vblank:
160ac86cba9SOleksandr Andrushchenko 	 *
161ac86cba9SOleksandr Andrushchenko 	 * Optional, called by &drm_crtc_funcs.enable_vblank. Please read
162ac86cba9SOleksandr Andrushchenko 	 * the documentation for the &drm_crtc_funcs.enable_vblank hook for
163ac86cba9SOleksandr Andrushchenko 	 * more details.
164ac86cba9SOleksandr Andrushchenko 	 */
165ac86cba9SOleksandr Andrushchenko 	int (*enable_vblank)(struct drm_simple_display_pipe *pipe);
166ac86cba9SOleksandr Andrushchenko 
167ac86cba9SOleksandr Andrushchenko 	/**
168ac86cba9SOleksandr Andrushchenko 	 * @disable_vblank:
169ac86cba9SOleksandr Andrushchenko 	 *
170ac86cba9SOleksandr Andrushchenko 	 * Optional, called by &drm_crtc_funcs.disable_vblank. Please read
171ac86cba9SOleksandr Andrushchenko 	 * the documentation for the &drm_crtc_funcs.disable_vblank hook for
172ac86cba9SOleksandr Andrushchenko 	 * more details.
173ac86cba9SOleksandr Andrushchenko 	 */
174ac86cba9SOleksandr Andrushchenko 	void (*disable_vblank)(struct drm_simple_display_pipe *pipe);
17540f302adSThomas Zimmermann 
17640f302adSThomas Zimmermann 	/**
17738c5af44SThomas Zimmermann 	 * @reset_crtc:
17838c5af44SThomas Zimmermann 	 *
17938c5af44SThomas Zimmermann 	 * Optional, called by &drm_crtc_funcs.reset. Please read the
18038c5af44SThomas Zimmermann 	 * documentation for the &drm_crtc_funcs.reset hook for more details.
18138c5af44SThomas Zimmermann 	 */
18238c5af44SThomas Zimmermann 	void (*reset_crtc)(struct drm_simple_display_pipe *pipe);
18338c5af44SThomas Zimmermann 
18438c5af44SThomas Zimmermann 	/**
18538c5af44SThomas Zimmermann 	 * @duplicate_crtc_state:
18638c5af44SThomas Zimmermann 	 *
18738c5af44SThomas Zimmermann 	 * Optional, called by &drm_crtc_funcs.atomic_duplicate_state. Please
18838c5af44SThomas Zimmermann 	 * read the documentation for the &drm_crtc_funcs.atomic_duplicate_state
18938c5af44SThomas Zimmermann 	 * hook for more details.
19038c5af44SThomas Zimmermann 	 */
19138c5af44SThomas Zimmermann 	struct drm_crtc_state * (*duplicate_crtc_state)(struct drm_simple_display_pipe *pipe);
19238c5af44SThomas Zimmermann 
19338c5af44SThomas Zimmermann 	/**
19438c5af44SThomas Zimmermann 	 * @destroy_crtc_state:
19538c5af44SThomas Zimmermann 	 *
19638c5af44SThomas Zimmermann 	 * Optional, called by &drm_crtc_funcs.atomic_destroy_state. Please
19738c5af44SThomas Zimmermann 	 * read the documentation for the &drm_crtc_funcs.atomic_destroy_state
19838c5af44SThomas Zimmermann 	 * hook for more details.
19938c5af44SThomas Zimmermann 	 */
20038c5af44SThomas Zimmermann 	void (*destroy_crtc_state)(struct drm_simple_display_pipe *pipe,
20138c5af44SThomas Zimmermann 				   struct drm_crtc_state *crtc_state);
20238c5af44SThomas Zimmermann 
20338c5af44SThomas Zimmermann 	/**
20440f302adSThomas Zimmermann 	 * @reset_plane:
20540f302adSThomas Zimmermann 	 *
20640f302adSThomas Zimmermann 	 * Optional, called by &drm_plane_funcs.reset. Please read the
20740f302adSThomas Zimmermann 	 * documentation for the &drm_plane_funcs.reset hook for more details.
20840f302adSThomas Zimmermann 	 */
20940f302adSThomas Zimmermann 	void (*reset_plane)(struct drm_simple_display_pipe *pipe);
21040f302adSThomas Zimmermann 
21140f302adSThomas Zimmermann 	/**
21240f302adSThomas Zimmermann 	 * @duplicate_plane_state:
21340f302adSThomas Zimmermann 	 *
21440f302adSThomas Zimmermann 	 * Optional, called by &drm_plane_funcs.atomic_duplicate_state.  Please
21540f302adSThomas Zimmermann 	 * read the documentation for the &drm_plane_funcs.atomic_duplicate_state
21640f302adSThomas Zimmermann 	 * hook for more details.
21740f302adSThomas Zimmermann 	 */
21840f302adSThomas Zimmermann 	struct drm_plane_state * (*duplicate_plane_state)(struct drm_simple_display_pipe *pipe);
21940f302adSThomas Zimmermann 
22040f302adSThomas Zimmermann 	/**
22140f302adSThomas Zimmermann 	 * @destroy_plane_state:
22240f302adSThomas Zimmermann 	 *
22340f302adSThomas Zimmermann 	 * Optional, called by &drm_plane_funcs.atomic_destroy_state.  Please
22440f302adSThomas Zimmermann 	 * read the documentation for the &drm_plane_funcs.atomic_destroy_state
22540f302adSThomas Zimmermann 	 * hook for more details.
22640f302adSThomas Zimmermann 	 */
22740f302adSThomas Zimmermann 	void (*destroy_plane_state)(struct drm_simple_display_pipe *pipe,
22840f302adSThomas Zimmermann 				    struct drm_plane_state *plane_state);
2295b809074SNoralf Trønnes };
2305b809074SNoralf Trønnes 
2315b809074SNoralf Trønnes /**
2325b809074SNoralf Trønnes  * struct drm_simple_display_pipe - simple display pipeline
2335b809074SNoralf Trønnes  * @crtc: CRTC control structure
2345b809074SNoralf Trønnes  * @plane: Plane control structure
2355b809074SNoralf Trønnes  * @encoder: Encoder control structure
2365b809074SNoralf Trønnes  * @connector: Connector control structure
2375b809074SNoralf Trønnes  * @funcs: Pipeline control functions (optional)
2385b809074SNoralf Trønnes  *
2395b809074SNoralf Trønnes  * Simple display pipeline with plane, crtc and encoder collapsed into one
2405b809074SNoralf Trønnes  * entity. It should be initialized by calling drm_simple_display_pipe_init().
2415b809074SNoralf Trønnes  */
2425b809074SNoralf Trønnes struct drm_simple_display_pipe {
2435b809074SNoralf Trønnes 	struct drm_crtc crtc;
2445b809074SNoralf Trønnes 	struct drm_plane plane;
2455b809074SNoralf Trønnes 	struct drm_encoder encoder;
2465b809074SNoralf Trønnes 	struct drm_connector *connector;
2475b809074SNoralf Trønnes 
2485b809074SNoralf Trønnes 	const struct drm_simple_display_pipe_funcs *funcs;
2495b809074SNoralf Trønnes };
2505b809074SNoralf Trønnes 
251315486c6SAndrea Merello int drm_simple_display_pipe_attach_bridge(struct drm_simple_display_pipe *pipe,
252315486c6SAndrea Merello 					  struct drm_bridge *bridge);
253315486c6SAndrea Merello 
2545b809074SNoralf Trønnes int drm_simple_display_pipe_init(struct drm_device *dev,
2555b809074SNoralf Trønnes 			struct drm_simple_display_pipe *pipe,
2565b809074SNoralf Trønnes 			const struct drm_simple_display_pipe_funcs *funcs,
2575b809074SNoralf Trønnes 			const uint32_t *formats, unsigned int format_count,
258e6fc3b68SBen Widawsky 			const uint64_t *format_modifiers,
2595b809074SNoralf Trønnes 			struct drm_connector *connector);
2605b809074SNoralf Trønnes 
26163170ac6SThomas Zimmermann int drm_simple_encoder_init(struct drm_device *dev,
26263170ac6SThomas Zimmermann 			    struct drm_encoder *encoder,
26363170ac6SThomas Zimmermann 			    int encoder_type);
26463170ac6SThomas Zimmermann 
26559abba48SPhilipp Zabel void *__drmm_simple_encoder_alloc(struct drm_device *dev, size_t size,
26659abba48SPhilipp Zabel 				  size_t offset, int encoder_type);
26759abba48SPhilipp Zabel 
26859abba48SPhilipp Zabel /**
26959abba48SPhilipp Zabel  * drmm_simple_encoder_alloc - Allocate and initialize an encoder with basic
27059abba48SPhilipp Zabel  *                             functionality.
27159abba48SPhilipp Zabel  * @dev: drm device
27259abba48SPhilipp Zabel  * @type: the type of the struct which contains struct &drm_encoder
27359abba48SPhilipp Zabel  * @member: the name of the &drm_encoder within @type.
27459abba48SPhilipp Zabel  * @encoder_type: user visible type of the encoder
27559abba48SPhilipp Zabel  *
27659abba48SPhilipp Zabel  * Allocates and initializes an encoder that has no further functionality.
27759abba48SPhilipp Zabel  * Settings for possible CRTC and clones are left to their initial values.
27859abba48SPhilipp Zabel  * Cleanup is automatically handled through registering drm_encoder_cleanup()
27959abba48SPhilipp Zabel  * with drmm_add_action().
28059abba48SPhilipp Zabel  *
28159abba48SPhilipp Zabel  * Returns:
28259abba48SPhilipp Zabel  * Pointer to new encoder, or ERR_PTR on failure.
28359abba48SPhilipp Zabel  */
28459abba48SPhilipp Zabel #define drmm_simple_encoder_alloc(dev, type, member, encoder_type) \
28559abba48SPhilipp Zabel 	((type *)__drmm_simple_encoder_alloc(dev, sizeof(type), \
28659abba48SPhilipp Zabel 					     offsetof(type, member), \
28759abba48SPhilipp Zabel 					     encoder_type))
28859abba48SPhilipp Zabel 
2895b809074SNoralf Trønnes #endif /* __LINUX_DRM_SIMPLE_KMS_HELPER_H */
290