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