Line data Source code
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 :
26 : /*
27 : * The DRM mode setting helper functions are common code for drivers to use if
28 : * they wish. Drivers are not forced to use this code in their
29 : * implementations but it would be useful if they code they do use at least
30 : * provides a consistent interface and operation to userspace
31 : */
32 :
33 : #ifndef __DRM_CRTC_HELPER_H__
34 : #define __DRM_CRTC_HELPER_H__
35 :
36 : #ifdef __linux__
37 : #include <linux/spinlock.h>
38 : #include <linux/types.h>
39 : #include <linux/idr.h>
40 :
41 : #include <linux/fb.h>
42 : #endif
43 :
44 : #include <dev/pci/drm/drm_crtc.h>
45 :
46 : enum mode_set_atomic {
47 : LEAVE_ATOMIC_MODE_SET,
48 : ENTER_ATOMIC_MODE_SET,
49 : };
50 :
51 : /**
52 : * struct drm_crtc_helper_funcs - helper operations for CRTCs
53 : * @dpms: set power state
54 : * @prepare: prepare the CRTC, called before @mode_set
55 : * @commit: commit changes to CRTC, called after @mode_set
56 : * @mode_fixup: try to fixup proposed mode for this CRTC
57 : * @mode_set: set this mode
58 : * @mode_set_nofb: set mode only (no scanout buffer attached)
59 : * @mode_set_base: update the scanout buffer
60 : * @mode_set_base_atomic: non-blocking mode set (used for kgdb support)
61 : * @load_lut: load color palette
62 : * @disable: disable CRTC when no longer in use
63 : * @enable: enable CRTC
64 : * @atomic_check: check for validity of an atomic state
65 : * @atomic_begin: begin atomic update
66 : * @atomic_flush: flush atomic update
67 : *
68 : * The helper operations are called by the mid-layer CRTC helper.
69 : *
70 : * Note that with atomic helpers @dpms, @prepare and @commit hooks are
71 : * deprecated. Used @enable and @disable instead exclusively.
72 : *
73 : * With legacy crtc helpers there's a big semantic difference between @disable
74 : * and the other hooks: @disable also needs to release any resources acquired in
75 : * @mode_set (like shared PLLs).
76 : */
77 : struct drm_crtc_helper_funcs {
78 : /*
79 : * Control power levels on the CRTC. If the mode passed in is
80 : * unsupported, the provider must use the next lowest power level.
81 : */
82 : void (*dpms)(struct drm_crtc *crtc, int mode);
83 : void (*prepare)(struct drm_crtc *crtc);
84 : void (*commit)(struct drm_crtc *crtc);
85 :
86 : /* Provider can fixup or change mode timings before modeset occurs */
87 : bool (*mode_fixup)(struct drm_crtc *crtc,
88 : const struct drm_display_mode *mode,
89 : struct drm_display_mode *adjusted_mode);
90 : /* Actually set the mode */
91 : int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
92 : struct drm_display_mode *adjusted_mode, int x, int y,
93 : struct drm_framebuffer *old_fb);
94 : /* Actually set the mode for atomic helpers, optional */
95 : void (*mode_set_nofb)(struct drm_crtc *crtc);
96 :
97 : /* Move the crtc on the current fb to the given position *optional* */
98 : int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
99 : struct drm_framebuffer *old_fb);
100 : int (*mode_set_base_atomic)(struct drm_crtc *crtc,
101 : struct drm_framebuffer *fb, int x, int y,
102 : enum mode_set_atomic);
103 :
104 : /* reload the current crtc LUT */
105 : void (*load_lut)(struct drm_crtc *crtc);
106 :
107 : void (*disable)(struct drm_crtc *crtc);
108 : void (*enable)(struct drm_crtc *crtc);
109 :
110 : /* atomic helpers */
111 : int (*atomic_check)(struct drm_crtc *crtc,
112 : struct drm_crtc_state *state);
113 : void (*atomic_begin)(struct drm_crtc *crtc,
114 : struct drm_crtc_state *old_crtc_state);
115 : void (*atomic_flush)(struct drm_crtc *crtc,
116 : struct drm_crtc_state *old_crtc_state);
117 : };
118 :
119 : /**
120 : * struct drm_encoder_helper_funcs - helper operations for encoders
121 : * @dpms: set power state
122 : * @save: save connector state
123 : * @restore: restore connector state
124 : * @mode_fixup: try to fixup proposed mode for this connector
125 : * @prepare: part of the disable sequence, called before the CRTC modeset
126 : * @commit: called after the CRTC modeset
127 : * @mode_set: set this mode, optional for atomic helpers
128 : * @get_crtc: return CRTC that the encoder is currently attached to
129 : * @detect: connection status detection
130 : * @disable: disable encoder when not in use (overrides DPMS off)
131 : * @enable: enable encoder
132 : * @atomic_check: check for validity of an atomic update
133 : *
134 : * The helper operations are called by the mid-layer CRTC helper.
135 : *
136 : * Note that with atomic helpers @dpms, @prepare and @commit hooks are
137 : * deprecated. Used @enable and @disable instead exclusively.
138 : *
139 : * With legacy crtc helpers there's a big semantic difference between @disable
140 : * and the other hooks: @disable also needs to release any resources acquired in
141 : * @mode_set (like shared PLLs).
142 : */
143 : struct drm_encoder_helper_funcs {
144 : void (*dpms)(struct drm_encoder *encoder, int mode);
145 : void (*save)(struct drm_encoder *encoder);
146 : void (*restore)(struct drm_encoder *encoder);
147 :
148 : bool (*mode_fixup)(struct drm_encoder *encoder,
149 : const struct drm_display_mode *mode,
150 : struct drm_display_mode *adjusted_mode);
151 : void (*prepare)(struct drm_encoder *encoder);
152 : void (*commit)(struct drm_encoder *encoder);
153 : void (*mode_set)(struct drm_encoder *encoder,
154 : struct drm_display_mode *mode,
155 : struct drm_display_mode *adjusted_mode);
156 : struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
157 : /* detect for DAC style encoders */
158 : enum drm_connector_status (*detect)(struct drm_encoder *encoder,
159 : struct drm_connector *connector);
160 : void (*disable)(struct drm_encoder *encoder);
161 :
162 : void (*enable)(struct drm_encoder *encoder);
163 :
164 : /* atomic helpers */
165 : int (*atomic_check)(struct drm_encoder *encoder,
166 : struct drm_crtc_state *crtc_state,
167 : struct drm_connector_state *conn_state);
168 : };
169 :
170 : /**
171 : * struct drm_connector_helper_funcs - helper operations for connectors
172 : * @get_modes: get mode list for this connector
173 : * @mode_valid: is this mode valid on the given connector? (optional)
174 : * @best_encoder: return the preferred encoder for this connector
175 : * @atomic_best_encoder: atomic version of @best_encoder
176 : *
177 : * The helper operations are called by the mid-layer CRTC helper.
178 : */
179 : struct drm_connector_helper_funcs {
180 : int (*get_modes)(struct drm_connector *connector);
181 : enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
182 : struct drm_display_mode *mode);
183 : struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
184 : struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
185 : struct drm_connector_state *connector_state);
186 : };
187 :
188 : extern void drm_helper_disable_unused_functions(struct drm_device *dev);
189 : extern int drm_crtc_helper_set_config(struct drm_mode_set *set);
190 : extern bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
191 : struct drm_display_mode *mode,
192 : int x, int y,
193 : struct drm_framebuffer *old_fb);
194 : extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc);
195 : extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder);
196 :
197 : extern int drm_helper_connector_dpms(struct drm_connector *connector, int mode);
198 :
199 : extern void drm_helper_move_panel_connectors_to_head(struct drm_device *);
200 :
201 : extern void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
202 : struct drm_mode_fb_cmd2 *mode_cmd);
203 :
204 0 : static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
205 : const struct drm_crtc_helper_funcs *funcs)
206 : {
207 0 : crtc->helper_private = funcs;
208 0 : }
209 :
210 0 : static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
211 : const struct drm_encoder_helper_funcs *funcs)
212 : {
213 0 : encoder->helper_private = funcs;
214 0 : }
215 :
216 0 : static inline void drm_connector_helper_add(struct drm_connector *connector,
217 : const struct drm_connector_helper_funcs *funcs)
218 : {
219 0 : connector->helper_private = funcs;
220 0 : }
221 :
222 : extern void drm_helper_resume_force_mode(struct drm_device *dev);
223 :
224 : int drm_helper_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode,
225 : struct drm_display_mode *adjusted_mode, int x, int y,
226 : struct drm_framebuffer *old_fb);
227 : int drm_helper_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
228 : struct drm_framebuffer *old_fb);
229 :
230 : /* drm_probe_helper.c */
231 : extern int drm_helper_probe_single_connector_modes(struct drm_connector
232 : *connector, uint32_t maxX,
233 : uint32_t maxY);
234 : extern int drm_helper_probe_single_connector_modes_nomerge(struct drm_connector
235 : *connector,
236 : uint32_t maxX,
237 : uint32_t maxY);
238 : extern void drm_kms_helper_poll_init(struct drm_device *dev);
239 : extern void drm_kms_helper_poll_fini(struct drm_device *dev);
240 : extern bool drm_helper_hpd_irq_event(struct drm_device *dev);
241 : extern void drm_kms_helper_hotplug_event(struct drm_device *dev);
242 :
243 : extern void drm_kms_helper_poll_disable(struct drm_device *dev);
244 : extern void drm_kms_helper_poll_enable(struct drm_device *dev);
245 : extern void drm_kms_helper_poll_enable_locked(struct drm_device *dev);
246 :
247 : #endif
|