blob: c8fc187061de5fbd9fc8545f602a62baaa45b8cc [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
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
Dave Airlief453ba02008-11-07 14:05:41 -080036#include <linux/spinlock.h>
37#include <linux/types.h>
38#include <linux/idr.h>
39
40#include <linux/fb.h>
41
Thierry Reding6d11a2f2014-12-17 16:41:42 +010042#include <drm/drm_crtc.h>
43
Jason Wessel21c74a82010-10-13 14:09:44 -050044enum mode_set_atomic {
45 LEAVE_ATOMIC_MODE_SET,
46 ENTER_ATOMIC_MODE_SET,
47};
48
Laurent Pinchart3b02ab82012-05-17 13:27:20 +020049/**
Thierry Reding7552e7d2014-12-17 16:41:43 +010050 * struct drm_crtc_helper_funcs - helper operations for CRTCs
51 * @dpms: set power state
52 * @prepare: prepare the CRTC, called before @mode_set
53 * @commit: commit changes to CRTC, called after @mode_set
54 * @mode_fixup: try to fixup proposed mode for this CRTC
Laurent Pinchart3b02ab82012-05-17 13:27:20 +020055 * @mode_set: set this mode
Thierry Reding7552e7d2014-12-17 16:41:43 +010056 * @mode_set_nofb: set mode only (no scanout buffer attached)
57 * @mode_set_base: update the scanout buffer
58 * @mode_set_base_atomic: non-blocking mode set (used for kgdb support)
59 * @load_lut: load color palette
60 * @disable: disable CRTC when no longer in use
Daniel Vetteree0a89c2015-01-22 16:36:24 +010061 * @enable: enable CRTC
Thierry Reding7552e7d2014-12-17 16:41:43 +010062 * @atomic_check: check for validity of an atomic state
63 * @atomic_begin: begin atomic update
64 * @atomic_flush: flush atomic update
Laurent Pinchart3b02ab82012-05-17 13:27:20 +020065 *
66 * The helper operations are called by the mid-layer CRTC helper.
Daniel Vetteree0a89c2015-01-22 16:36:24 +010067 *
68 * Note that with atomic helpers @dpms, @prepare and @commit hooks are
69 * deprecated. Used @enable and @disable instead exclusively.
70 *
71 * With legacy crtc helpers there's a big semantic difference between @disable
72 * and the other hooks: @disable also needs to release any resources acquired in
73 * @mode_set (like shared PLLs).
Laurent Pinchart3b02ab82012-05-17 13:27:20 +020074 */
Dave Airlief453ba02008-11-07 14:05:41 -080075struct drm_crtc_helper_funcs {
76 /*
77 * Control power levels on the CRTC. If the mode passed in is
78 * unsupported, the provider must use the next lowest power level.
79 */
80 void (*dpms)(struct drm_crtc *crtc, int mode);
81 void (*prepare)(struct drm_crtc *crtc);
82 void (*commit)(struct drm_crtc *crtc);
83
84 /* Provider can fixup or change mode timings before modeset occurs */
85 bool (*mode_fixup)(struct drm_crtc *crtc,
Laurent Pincharte811f5a2012-07-17 17:56:50 +020086 const struct drm_display_mode *mode,
Dave Airlief453ba02008-11-07 14:05:41 -080087 struct drm_display_mode *adjusted_mode);
88 /* Actually set the mode */
Chris Wilson5c3b82e2009-02-11 13:25:09 +000089 int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
90 struct drm_display_mode *adjusted_mode, int x, int y,
91 struct drm_framebuffer *old_fb);
Daniel Vetterc982bd92015-02-22 12:24:20 +010092 /* Actually set the mode for atomic helpers, optional */
Daniel Vetter2f324b42014-10-29 11:13:47 +010093 void (*mode_set_nofb)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -080094
95 /* Move the crtc on the current fb to the given position *optional* */
Chris Wilson5c3b82e2009-02-11 13:25:09 +000096 int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
97 struct drm_framebuffer *old_fb);
Jesse Barnes1a7aba72010-08-05 09:22:31 -050098 int (*mode_set_base_atomic)(struct drm_crtc *crtc,
Jason Wessel413d45d2010-09-26 06:47:25 -050099 struct drm_framebuffer *fb, int x, int y,
Jason Wessel21c74a82010-10-13 14:09:44 -0500100 enum mode_set_atomic);
Dave Airlie068143d2009-10-05 09:58:02 +1000101
102 /* reload the current crtc LUT */
103 void (*load_lut)(struct drm_crtc *crtc);
Alex Deucher5c8d7172010-06-11 17:04:35 -0400104
Alex Deucher5c8d7172010-06-11 17:04:35 -0400105 void (*disable)(struct drm_crtc *crtc);
Daniel Vetteree0a89c2015-01-22 16:36:24 +0100106 void (*enable)(struct drm_crtc *crtc);
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100107
108 /* atomic helpers */
109 int (*atomic_check)(struct drm_crtc *crtc,
110 struct drm_crtc_state *state);
111 void (*atomic_begin)(struct drm_crtc *crtc);
112 void (*atomic_flush)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800113};
114
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200115/**
Thierry Reding7552e7d2014-12-17 16:41:43 +0100116 * struct drm_encoder_helper_funcs - helper operations for encoders
117 * @dpms: set power state
118 * @save: save connector state
119 * @restore: restore connector state
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200120 * @mode_fixup: try to fixup proposed mode for this connector
Thierry Reding7552e7d2014-12-17 16:41:43 +0100121 * @prepare: part of the disable sequence, called before the CRTC modeset
122 * @commit: called after the CRTC modeset
Daniel Vetterc982bd92015-02-22 12:24:20 +0100123 * @mode_set: set this mode, optional for atomic helpers
Thierry Reding7552e7d2014-12-17 16:41:43 +0100124 * @get_crtc: return CRTC that the encoder is currently attached to
125 * @detect: connection status detection
126 * @disable: disable encoder when not in use (overrides DPMS off)
Daniel Vetteree0a89c2015-01-22 16:36:24 +0100127 * @enable: enable encoder
Thierry Reding4cd4df82014-12-03 16:44:34 +0100128 * @atomic_check: check for validity of an atomic update
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200129 *
130 * The helper operations are called by the mid-layer CRTC helper.
Daniel Vetteree0a89c2015-01-22 16:36:24 +0100131 *
132 * Note that with atomic helpers @dpms, @prepare and @commit hooks are
133 * deprecated. Used @enable and @disable instead exclusively.
134 *
135 * With legacy crtc helpers there's a big semantic difference between @disable
136 * and the other hooks: @disable also needs to release any resources acquired in
137 * @mode_set (like shared PLLs).
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200138 */
Dave Airlief453ba02008-11-07 14:05:41 -0800139struct drm_encoder_helper_funcs {
140 void (*dpms)(struct drm_encoder *encoder, int mode);
141 void (*save)(struct drm_encoder *encoder);
142 void (*restore)(struct drm_encoder *encoder);
143
144 bool (*mode_fixup)(struct drm_encoder *encoder,
Laurent Pincharte811f5a2012-07-17 17:56:50 +0200145 const struct drm_display_mode *mode,
Dave Airlief453ba02008-11-07 14:05:41 -0800146 struct drm_display_mode *adjusted_mode);
147 void (*prepare)(struct drm_encoder *encoder);
148 void (*commit)(struct drm_encoder *encoder);
149 void (*mode_set)(struct drm_encoder *encoder,
150 struct drm_display_mode *mode,
151 struct drm_display_mode *adjusted_mode);
Jesse Barnes7bec7562009-02-23 16:09:34 -0800152 struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -0800153 /* detect for DAC style encoders */
154 enum drm_connector_status (*detect)(struct drm_encoder *encoder,
155 struct drm_connector *connector);
Dave Airliea3a05442009-08-31 15:16:30 +1000156 void (*disable)(struct drm_encoder *encoder);
Thierry Reding4cd4df82014-12-03 16:44:34 +0100157
Daniel Vetteree0a89c2015-01-22 16:36:24 +0100158 void (*enable)(struct drm_encoder *encoder);
Dave Airlie21773f12015-01-28 09:34:27 +1000159
Thierry Reding4cd4df82014-12-03 16:44:34 +0100160 /* atomic helpers */
161 int (*atomic_check)(struct drm_encoder *encoder,
162 struct drm_crtc_state *crtc_state,
163 struct drm_connector_state *conn_state);
Dave Airlief453ba02008-11-07 14:05:41 -0800164};
165
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200166/**
Thierry Reding7552e7d2014-12-17 16:41:43 +0100167 * struct drm_connector_helper_funcs - helper operations for connectors
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200168 * @get_modes: get mode list for this connector
Thierry Reding7552e7d2014-12-17 16:41:43 +0100169 * @mode_valid: is this mode valid on the given connector? (optional)
170 * @best_encoder: return the preferred encoder for this connector
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200171 *
172 * The helper operations are called by the mid-layer CRTC helper.
173 */
Dave Airlief453ba02008-11-07 14:05:41 -0800174struct drm_connector_helper_funcs {
175 int (*get_modes)(struct drm_connector *connector);
Damien Lespiau0993f1d2013-11-28 15:29:17 +0000176 enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
177 struct drm_display_mode *mode);
Dave Airlief453ba02008-11-07 14:05:41 -0800178 struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
179};
180
Dave Airlief453ba02008-11-07 14:05:41 -0800181extern void drm_helper_disable_unused_functions(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -0800182extern int drm_crtc_helper_set_config(struct drm_mode_set *set);
183extern bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
184 struct drm_display_mode *mode,
Kristian Høgsberg3c4fdcf2008-12-17 22:14:46 -0500185 int x, int y,
186 struct drm_framebuffer *old_fb);
Dave Airlief453ba02008-11-07 14:05:41 -0800187extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc);
Maarten Maathuisf380ef82009-08-19 00:56:44 +0200188extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -0800189
Keith Packardc9fb15f2009-05-30 20:42:28 -0700190extern void drm_helper_connector_dpms(struct drm_connector *connector, int mode);
191
Daniel Vettercfc1a062012-10-27 15:52:04 +0200192extern void drm_helper_move_panel_connectors_to_head(struct drm_device *);
193
Daniel Vetter9fd93782014-01-23 22:16:24 +0100194extern void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
195 struct drm_mode_fb_cmd2 *mode_cmd);
Dave Airlief453ba02008-11-07 14:05:41 -0800196
197static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
198 const struct drm_crtc_helper_funcs *funcs)
199{
Jani Nikula9a436ee2015-04-13 11:21:42 +0300200 crtc->helper_private = funcs;
Dave Airlief453ba02008-11-07 14:05:41 -0800201}
202
203static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
204 const struct drm_encoder_helper_funcs *funcs)
205{
Jani Nikula9a436ee2015-04-13 11:21:42 +0300206 encoder->helper_private = funcs;
Dave Airlief453ba02008-11-07 14:05:41 -0800207}
208
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000209static inline void drm_connector_helper_add(struct drm_connector *connector,
Dave Airlief453ba02008-11-07 14:05:41 -0800210 const struct drm_connector_helper_funcs *funcs)
211{
Jani Nikula9a436ee2015-04-13 11:21:42 +0300212 connector->helper_private = funcs;
Dave Airlief453ba02008-11-07 14:05:41 -0800213}
214
Daniel Vetter00d762c2014-01-23 22:28:30 +0100215extern void drm_helper_resume_force_mode(struct drm_device *dev);
Daniel Vetter8d754542014-04-10 10:51:11 +0200216
Daniel Vetter2f324b42014-10-29 11:13:47 +0100217int drm_helper_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode,
218 struct drm_display_mode *adjusted_mode, int x, int y,
219 struct drm_framebuffer *old_fb);
220int drm_helper_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
221 struct drm_framebuffer *old_fb);
222
Daniel Vetter8d754542014-04-10 10:51:11 +0200223/* drm_probe_helper.c */
224extern int drm_helper_probe_single_connector_modes(struct drm_connector
225 *connector, uint32_t maxX,
226 uint32_t maxY);
Dave Airlieb87577b2014-05-01 09:26:53 +1000227extern int drm_helper_probe_single_connector_modes_nomerge(struct drm_connector
228 *connector,
229 uint32_t maxX,
230 uint32_t maxY);
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000231extern void drm_kms_helper_poll_init(struct drm_device *dev);
232extern void drm_kms_helper_poll_fini(struct drm_device *dev);
Marc-André Lureaub8206d32013-10-18 16:11:28 +0200233extern bool drm_helper_hpd_irq_event(struct drm_device *dev);
Daniel Vetter3d3683f2012-10-23 18:23:32 +0000234extern void drm_kms_helper_hotplug_event(struct drm_device *dev);
Dave Airliefbf81762010-06-01 09:09:06 +1000235
236extern void drm_kms_helper_poll_disable(struct drm_device *dev);
237extern void drm_kms_helper_poll_enable(struct drm_device *dev);
Ville Syrjäläd0d110e2011-12-20 00:33:24 +0200238
Dave Airlief453ba02008-11-07 14:05:41 -0800239#endif