blob: 3febb4b9fce9243793fbaf3e8dbb331fe6adf81d [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);
Maarten Lankhorst613d2b22015-07-21 13:28:58 +0200111 void (*atomic_begin)(struct drm_crtc *crtc,
112 struct drm_crtc_state *old_crtc_state);
113 void (*atomic_flush)(struct drm_crtc *crtc,
114 struct drm_crtc_state *old_crtc_state);
Dave Airlief453ba02008-11-07 14:05:41 -0800115};
116
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200117/**
Thierry Reding7552e7d2014-12-17 16:41:43 +0100118 * struct drm_encoder_helper_funcs - helper operations for encoders
119 * @dpms: set power state
120 * @save: save connector state
121 * @restore: restore connector state
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200122 * @mode_fixup: try to fixup proposed mode for this connector
Thierry Reding7552e7d2014-12-17 16:41:43 +0100123 * @prepare: part of the disable sequence, called before the CRTC modeset
124 * @commit: called after the CRTC modeset
Daniel Vetterc982bd92015-02-22 12:24:20 +0100125 * @mode_set: set this mode, optional for atomic helpers
Thierry Reding7552e7d2014-12-17 16:41:43 +0100126 * @get_crtc: return CRTC that the encoder is currently attached to
127 * @detect: connection status detection
128 * @disable: disable encoder when not in use (overrides DPMS off)
Daniel Vetteree0a89c2015-01-22 16:36:24 +0100129 * @enable: enable encoder
Thierry Reding4cd4df82014-12-03 16:44:34 +0100130 * @atomic_check: check for validity of an atomic update
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200131 *
132 * The helper operations are called by the mid-layer CRTC helper.
Daniel Vetteree0a89c2015-01-22 16:36:24 +0100133 *
134 * Note that with atomic helpers @dpms, @prepare and @commit hooks are
135 * deprecated. Used @enable and @disable instead exclusively.
136 *
137 * With legacy crtc helpers there's a big semantic difference between @disable
138 * and the other hooks: @disable also needs to release any resources acquired in
139 * @mode_set (like shared PLLs).
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200140 */
Dave Airlief453ba02008-11-07 14:05:41 -0800141struct drm_encoder_helper_funcs {
142 void (*dpms)(struct drm_encoder *encoder, int mode);
143 void (*save)(struct drm_encoder *encoder);
144 void (*restore)(struct drm_encoder *encoder);
145
146 bool (*mode_fixup)(struct drm_encoder *encoder,
Laurent Pincharte811f5a2012-07-17 17:56:50 +0200147 const struct drm_display_mode *mode,
Dave Airlief453ba02008-11-07 14:05:41 -0800148 struct drm_display_mode *adjusted_mode);
149 void (*prepare)(struct drm_encoder *encoder);
150 void (*commit)(struct drm_encoder *encoder);
151 void (*mode_set)(struct drm_encoder *encoder,
152 struct drm_display_mode *mode,
153 struct drm_display_mode *adjusted_mode);
Jesse Barnes7bec7562009-02-23 16:09:34 -0800154 struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -0800155 /* detect for DAC style encoders */
156 enum drm_connector_status (*detect)(struct drm_encoder *encoder,
157 struct drm_connector *connector);
Dave Airliea3a05442009-08-31 15:16:30 +1000158 void (*disable)(struct drm_encoder *encoder);
Thierry Reding4cd4df82014-12-03 16:44:34 +0100159
Daniel Vetteree0a89c2015-01-22 16:36:24 +0100160 void (*enable)(struct drm_encoder *encoder);
Dave Airlie21773f12015-01-28 09:34:27 +1000161
Thierry Reding4cd4df82014-12-03 16:44:34 +0100162 /* atomic helpers */
163 int (*atomic_check)(struct drm_encoder *encoder,
164 struct drm_crtc_state *crtc_state,
165 struct drm_connector_state *conn_state);
Dave Airlief453ba02008-11-07 14:05:41 -0800166};
167
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200168/**
Thierry Reding7552e7d2014-12-17 16:41:43 +0100169 * struct drm_connector_helper_funcs - helper operations for connectors
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200170 * @get_modes: get mode list for this connector
Thierry Reding7552e7d2014-12-17 16:41:43 +0100171 * @mode_valid: is this mode valid on the given connector? (optional)
172 * @best_encoder: return the preferred encoder for this connector
Daniel Vetter3b8a684b2015-08-03 17:24:08 +0200173 * @atomic_best_encoder: atomic version of @best_encoder
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200174 *
175 * The helper operations are called by the mid-layer CRTC helper.
176 */
Dave Airlief453ba02008-11-07 14:05:41 -0800177struct drm_connector_helper_funcs {
178 int (*get_modes)(struct drm_connector *connector);
Damien Lespiau0993f1d2013-11-28 15:29:17 +0000179 enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
180 struct drm_display_mode *mode);
Dave Airlief453ba02008-11-07 14:05:41 -0800181 struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
Daniel Vetter3b8a684b2015-08-03 17:24:08 +0200182 struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
183 struct drm_connector_state *connector_state);
Dave Airlief453ba02008-11-07 14:05:41 -0800184};
185
Dave Airlief453ba02008-11-07 14:05:41 -0800186extern void drm_helper_disable_unused_functions(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -0800187extern int drm_crtc_helper_set_config(struct drm_mode_set *set);
188extern bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
189 struct drm_display_mode *mode,
Kristian Høgsberg3c4fdcf2008-12-17 22:14:46 -0500190 int x, int y,
191 struct drm_framebuffer *old_fb);
Dave Airlief453ba02008-11-07 14:05:41 -0800192extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc);
Maarten Maathuisf380ef82009-08-19 00:56:44 +0200193extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -0800194
Maarten Lankhorst9a69a9a2015-07-21 11:34:55 +0200195extern int drm_helper_connector_dpms(struct drm_connector *connector, int mode);
Keith Packardc9fb15f2009-05-30 20:42:28 -0700196
Daniel Vettercfc1a062012-10-27 15:52:04 +0200197extern void drm_helper_move_panel_connectors_to_head(struct drm_device *);
198
Daniel Vetter9fd93782014-01-23 22:16:24 +0100199extern void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
200 struct drm_mode_fb_cmd2 *mode_cmd);
Dave Airlief453ba02008-11-07 14:05:41 -0800201
202static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
203 const struct drm_crtc_helper_funcs *funcs)
204{
Jani Nikula9a436ee2015-04-13 11:21:42 +0300205 crtc->helper_private = funcs;
Dave Airlief453ba02008-11-07 14:05:41 -0800206}
207
208static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
209 const struct drm_encoder_helper_funcs *funcs)
210{
Jani Nikula9a436ee2015-04-13 11:21:42 +0300211 encoder->helper_private = funcs;
Dave Airlief453ba02008-11-07 14:05:41 -0800212}
213
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000214static inline void drm_connector_helper_add(struct drm_connector *connector,
Dave Airlief453ba02008-11-07 14:05:41 -0800215 const struct drm_connector_helper_funcs *funcs)
216{
Jani Nikula9a436ee2015-04-13 11:21:42 +0300217 connector->helper_private = funcs;
Dave Airlief453ba02008-11-07 14:05:41 -0800218}
219
Daniel Vetter00d762c2014-01-23 22:28:30 +0100220extern void drm_helper_resume_force_mode(struct drm_device *dev);
Daniel Vetter8d754542014-04-10 10:51:11 +0200221
Daniel Vetter2f324b42014-10-29 11:13:47 +0100222int drm_helper_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode,
223 struct drm_display_mode *adjusted_mode, int x, int y,
224 struct drm_framebuffer *old_fb);
225int drm_helper_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
226 struct drm_framebuffer *old_fb);
227
Daniel Vetter8d754542014-04-10 10:51:11 +0200228/* drm_probe_helper.c */
229extern int drm_helper_probe_single_connector_modes(struct drm_connector
230 *connector, uint32_t maxX,
231 uint32_t maxY);
Dave Airlieb87577b2014-05-01 09:26:53 +1000232extern int drm_helper_probe_single_connector_modes_nomerge(struct drm_connector
233 *connector,
234 uint32_t maxX,
235 uint32_t maxY);
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000236extern void drm_kms_helper_poll_init(struct drm_device *dev);
237extern void drm_kms_helper_poll_fini(struct drm_device *dev);
Marc-André Lureaub8206d32013-10-18 16:11:28 +0200238extern bool drm_helper_hpd_irq_event(struct drm_device *dev);
Daniel Vetter3d3683f2012-10-23 18:23:32 +0000239extern void drm_kms_helper_hotplug_event(struct drm_device *dev);
Dave Airliefbf81762010-06-01 09:09:06 +1000240
241extern void drm_kms_helper_poll_disable(struct drm_device *dev);
242extern void drm_kms_helper_poll_enable(struct drm_device *dev);
Egbert Eich4ad640e2015-09-23 16:13:00 +0200243extern void drm_kms_helper_poll_enable_locked(struct drm_device *dev);
Ville Syrjäläd0d110e2011-12-20 00:33:24 +0200244
Dave Airlief453ba02008-11-07 14:05:41 -0800245#endif