xref: /gfx-drm/usr/src/uts/common/drm/drm_crtc_helper.h (revision 47dc10d7)
1 /* BEGIN CSTYLED */
2 
3 /*
4  * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
5  */
6 
7 /*
8  * Copyright © 2006 Keith Packard
9  * Copyright © 2007-2008 Dave Airlie
10  * Copyright (c) 2007-2008, 2013, Intel Corporation
11  *   Jesse Barnes <jesse.barnes@intel.com>
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included in
21  * all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
26  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
27  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29  * OTHER DEALINGS IN THE SOFTWARE.
30  */
31 
32 /*
33  * The DRM mode setting helper functions are common code for drivers to use if
34  * they wish.  Drivers are not forced to use this code in their
35  * implementations but it would be useful if they code they do use at least
36  * provides a consistent interface and operation to userspace
37  */
38 
39 #ifndef __DRM_CRTC_HELPER_H__
40 #define __DRM_CRTC_HELPER_H__
41 
42 #include <sys/types.h>
43 #include "drmP.h"
44 #include "drm_sun_idr.h"
45 
46 enum mode_set_atomic {
47 	LEAVE_ATOMIC_MODE_SET,
48 	ENTER_ATOMIC_MODE_SET,
49 };
50 
51 /**
52  * drm_crtc_helper_funcs - helper operations for CRTCs
53  * @mode_fixup: try to fixup proposed mode for this connector
54  * @mode_set: set this mode
55  *
56  * The helper operations are called by the mid-layer CRTC helper.
57  */
58 struct drm_crtc_helper_funcs {
59 	/*
60 	 * Control power levels on the CRTC.  If the mode passed in is
61 	 * unsupported, the provider must use the next lowest power level.
62 	 */
63 	void (*dpms)(struct drm_crtc *crtc, int mode);
64 	void (*prepare)(struct drm_crtc *crtc);
65 	void (*commit)(struct drm_crtc *crtc);
66 
67 	/* Provider can fixup or change mode timings before modeset occurs */
68 	bool (*mode_fixup)(struct drm_crtc *crtc,
69 			   const struct drm_display_mode *mode,
70 			   struct drm_display_mode *adjusted_mode);
71 	/* Actually set the mode */
72 	int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
73 			struct drm_display_mode *adjusted_mode, int x, int y,
74 			struct drm_framebuffer *old_fb);
75 
76 	/* Move the crtc on the current fb to the given position *optional* */
77 	int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
78 			     struct drm_framebuffer *old_fb);
79 	int (*mode_set_base_atomic)(struct drm_crtc *crtc,
80 				    struct drm_framebuffer *fb, int x, int y,
81 				    enum mode_set_atomic);
82 
83 	/* reload the current crtc LUT */
84 	void (*load_lut)(struct drm_crtc *crtc);
85 
86 	/* disable crtc when not in use - more explicit than dpms off */
87 	void (*disable)(struct drm_crtc *crtc);
88 };
89 
90 /**
91  * drm_encoder_helper_funcs - helper operations for encoders
92  * @mode_fixup: try to fixup proposed mode for this connector
93  * @mode_set: set this mode
94  *
95  * The helper operations are called by the mid-layer CRTC helper.
96  */
97 struct drm_encoder_helper_funcs {
98 	void (*dpms)(struct drm_encoder *encoder, int mode);
99 	void (*save)(struct drm_encoder *encoder);
100 	void (*restore)(struct drm_encoder *encoder);
101 
102 	bool (*mode_fixup)(struct drm_encoder *encoder,
103 			   const struct drm_display_mode *mode,
104 			   struct drm_display_mode *adjusted_mode);
105 	void (*prepare)(struct drm_encoder *encoder);
106 	void (*commit)(struct drm_encoder *encoder);
107 	void (*mode_set)(struct drm_encoder *encoder,
108 			 struct drm_display_mode *mode,
109 			 struct drm_display_mode *adjusted_mode);
110 	struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
111 	/* detect for DAC style encoders */
112 	enum drm_connector_status (*detect)(struct drm_encoder *encoder,
113 					    struct drm_connector *connector);
114 	/* disable encoder when not in use - more explicit than dpms off */
115 	void (*disable)(struct drm_encoder *encoder);
116 };
117 
118 /**
119  * drm_connector_helper_funcs - helper operations for connectors
120  * @get_modes: get mode list for this connector
121  * @mode_valid: is this mode valid on the given connector?
122  *
123  * The helper operations are called by the mid-layer CRTC helper.
124  */
125 struct drm_connector_helper_funcs {
126 	int (*get_modes)(struct drm_connector *connector);
127 	int (*mode_valid)(struct drm_connector *connector,
128 			  struct drm_display_mode *mode);
129 	struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
130 };
131 
132 extern int drm_helper_probe_single_connector_modes(struct drm_connector *connector, uint32_t maxX, uint32_t maxY);
133 extern void drm_helper_disable_unused_functions(struct drm_device *dev);
134 extern int drm_crtc_helper_set_config(struct drm_mode_set *set);
135 extern bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
136 				     struct drm_display_mode *mode,
137 				     int x, int y,
138 				     struct drm_framebuffer *old_fb);
139 extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc);
140 extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder);
141 
142 extern void drm_helper_connector_dpms(struct drm_connector *connector, int mode);
143 
144 extern void drm_helper_move_panel_connectors_to_head(struct drm_device *);
145 
146 extern int drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
147 					  struct drm_mode_fb_cmd2 *mode_cmd);
148 
drm_crtc_helper_add(struct drm_crtc * crtc,const struct drm_crtc_helper_funcs * funcs)149 static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
150 				       const struct drm_crtc_helper_funcs *funcs)
151 {
152 	crtc->helper_private = (void *)funcs;
153 }
154 
drm_encoder_helper_add(struct drm_encoder * encoder,const struct drm_encoder_helper_funcs * funcs)155 static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
156 					  const struct drm_encoder_helper_funcs *funcs)
157 {
158 	encoder->helper_private = (void *)funcs;
159 }
160 
drm_connector_helper_add(struct drm_connector * connector,const struct drm_connector_helper_funcs * funcs)161 static inline void drm_connector_helper_add(struct drm_connector *connector,
162 					    const struct drm_connector_helper_funcs *funcs)
163 {
164 	connector->helper_private = (void *)funcs;
165 }
166 
167 extern void drm_helper_resume_force_mode(struct drm_device *dev);
168 extern void drm_kms_helper_poll_init(struct drm_device *dev);
169 extern void drm_kms_helper_poll_fini(struct drm_device *dev);
170 extern void drm_helper_hpd_irq_event(struct drm_device *dev);
171 extern void drm_kms_helper_hotplug_event(struct drm_device *dev);
172 
173 extern void drm_kms_helper_poll_disable(struct drm_device *dev);
174 extern void drm_kms_helper_poll_enable(struct drm_device *dev);
175 
176 #endif /* __DRM_CRTC_HELPER_H__ */
177