blob: c250a22b39aba09a58aa4d7843e6ae4e7033c524 [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 Vetter2f324b42014-10-29 11:13:47 +010092 void (*mode_set_nofb)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -080093
94 /* Move the crtc on the current fb to the given position *optional* */
Chris Wilson5c3b82e2009-02-11 13:25:09 +000095 int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
96 struct drm_framebuffer *old_fb);
Jesse Barnes1a7aba72010-08-05 09:22:31 -050097 int (*mode_set_base_atomic)(struct drm_crtc *crtc,
Jason Wessel413d45d2010-09-26 06:47:25 -050098 struct drm_framebuffer *fb, int x, int y,
Jason Wessel21c74a82010-10-13 14:09:44 -050099 enum mode_set_atomic);
Dave Airlie068143d2009-10-05 09:58:02 +1000100
101 /* reload the current crtc LUT */
102 void (*load_lut)(struct drm_crtc *crtc);
Alex Deucher5c8d7172010-06-11 17:04:35 -0400103
Alex Deucher5c8d7172010-06-11 17:04:35 -0400104 void (*disable)(struct drm_crtc *crtc);
Daniel Vetteree0a89c2015-01-22 16:36:24 +0100105 void (*enable)(struct drm_crtc *crtc);
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100106
107 /* atomic helpers */
108 int (*atomic_check)(struct drm_crtc *crtc,
109 struct drm_crtc_state *state);
110 void (*atomic_begin)(struct drm_crtc *crtc);
111 void (*atomic_flush)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800112};
113
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200114/**
Thierry Reding7552e7d2014-12-17 16:41:43 +0100115 * struct drm_encoder_helper_funcs - helper operations for encoders
116 * @dpms: set power state
117 * @save: save connector state
118 * @restore: restore connector state
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200119 * @mode_fixup: try to fixup proposed mode for this connector
Thierry Reding7552e7d2014-12-17 16:41:43 +0100120 * @prepare: part of the disable sequence, called before the CRTC modeset
121 * @commit: called after the CRTC modeset
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200122 * @mode_set: set this mode
Thierry Reding7552e7d2014-12-17 16:41:43 +0100123 * @get_crtc: return CRTC that the encoder is currently attached to
124 * @detect: connection status detection
125 * @disable: disable encoder when not in use (overrides DPMS off)
Daniel Vetteree0a89c2015-01-22 16:36:24 +0100126 * @enable: enable encoder
Thierry Reding4cd4df82014-12-03 16:44:34 +0100127 * @atomic_check: check for validity of an atomic update
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200128 *
129 * The helper operations are called by the mid-layer CRTC helper.
Daniel Vetteree0a89c2015-01-22 16:36:24 +0100130 *
131 * Note that with atomic helpers @dpms, @prepare and @commit hooks are
132 * deprecated. Used @enable and @disable instead exclusively.
133 *
134 * With legacy crtc helpers there's a big semantic difference between @disable
135 * and the other hooks: @disable also needs to release any resources acquired in
136 * @mode_set (like shared PLLs).
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200137 */
Dave Airlief453ba02008-11-07 14:05:41 -0800138struct drm_encoder_helper_funcs {
139 void (*dpms)(struct drm_encoder *encoder, int mode);
140 void (*save)(struct drm_encoder *encoder);
141 void (*restore)(struct drm_encoder *encoder);
142
143 bool (*mode_fixup)(struct drm_encoder *encoder,
Laurent Pincharte811f5a2012-07-17 17:56:50 +0200144 const struct drm_display_mode *mode,
Dave Airlief453ba02008-11-07 14:05:41 -0800145 struct drm_display_mode *adjusted_mode);
146 void (*prepare)(struct drm_encoder *encoder);
147 void (*commit)(struct drm_encoder *encoder);
148 void (*mode_set)(struct drm_encoder *encoder,
149 struct drm_display_mode *mode,
150 struct drm_display_mode *adjusted_mode);
Jesse Barnes7bec7562009-02-23 16:09:34 -0800151 struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -0800152 /* detect for DAC style encoders */
153 enum drm_connector_status (*detect)(struct drm_encoder *encoder,
154 struct drm_connector *connector);
Dave Airliea3a05442009-08-31 15:16:30 +1000155 void (*disable)(struct drm_encoder *encoder);
Thierry Reding4cd4df82014-12-03 16:44:34 +0100156
Daniel Vetteree0a89c2015-01-22 16:36:24 +0100157 void (*enable)(struct drm_encoder *encoder);
Dave Airlie21773f12015-01-28 09:34:27 +1000158
Thierry Reding4cd4df82014-12-03 16:44:34 +0100159 /* atomic helpers */
160 int (*atomic_check)(struct drm_encoder *encoder,
161 struct drm_crtc_state *crtc_state,
162 struct drm_connector_state *conn_state);
Dave Airlief453ba02008-11-07 14:05:41 -0800163};
164
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200165/**
Thierry Reding7552e7d2014-12-17 16:41:43 +0100166 * struct drm_connector_helper_funcs - helper operations for connectors
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200167 * @get_modes: get mode list for this connector
Thierry Reding7552e7d2014-12-17 16:41:43 +0100168 * @mode_valid: is this mode valid on the given connector? (optional)
169 * @best_encoder: return the preferred encoder for this connector
Laurent Pinchart3b02ab82012-05-17 13:27:20 +0200170 *
171 * The helper operations are called by the mid-layer CRTC helper.
172 */
Dave Airlief453ba02008-11-07 14:05:41 -0800173struct drm_connector_helper_funcs {
174 int (*get_modes)(struct drm_connector *connector);
Damien Lespiau0993f1d2013-11-28 15:29:17 +0000175 enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
176 struct drm_display_mode *mode);
Dave Airlief453ba02008-11-07 14:05:41 -0800177 struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
178};
179
Dave Airlief453ba02008-11-07 14:05:41 -0800180extern void drm_helper_disable_unused_functions(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -0800181extern int drm_crtc_helper_set_config(struct drm_mode_set *set);
182extern bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
183 struct drm_display_mode *mode,
Kristian Høgsberg3c4fdcf2008-12-17 22:14:46 -0500184 int x, int y,
185 struct drm_framebuffer *old_fb);
Dave Airlief453ba02008-11-07 14:05:41 -0800186extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc);
Maarten Maathuisf380ef82009-08-19 00:56:44 +0200187extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -0800188
Keith Packardc9fb15f2009-05-30 20:42:28 -0700189extern void drm_helper_connector_dpms(struct drm_connector *connector, int mode);
190
Daniel Vettercfc1a062012-10-27 15:52:04 +0200191extern void drm_helper_move_panel_connectors_to_head(struct drm_device *);
192
Daniel Vetter9fd93782014-01-23 22:16:24 +0100193extern void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
194 struct drm_mode_fb_cmd2 *mode_cmd);
Dave Airlief453ba02008-11-07 14:05:41 -0800195
196static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
197 const struct drm_crtc_helper_funcs *funcs)
198{
199 crtc->helper_private = (void *)funcs;
200}
201
202static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
203 const struct drm_encoder_helper_funcs *funcs)
204{
205 encoder->helper_private = (void *)funcs;
206}
207
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000208static inline void drm_connector_helper_add(struct drm_connector *connector,
Dave Airlief453ba02008-11-07 14:05:41 -0800209 const struct drm_connector_helper_funcs *funcs)
210{
211 connector->helper_private = (void *)funcs;
Dave Airlief453ba02008-11-07 14:05:41 -0800212}
213
Daniel Vetter00d762c2014-01-23 22:28:30 +0100214extern void drm_helper_resume_force_mode(struct drm_device *dev);
Daniel Vetter8d754542014-04-10 10:51:11 +0200215
Daniel Vetter2f324b42014-10-29 11:13:47 +0100216int drm_helper_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode,
217 struct drm_display_mode *adjusted_mode, int x, int y,
218 struct drm_framebuffer *old_fb);
219int drm_helper_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
220 struct drm_framebuffer *old_fb);
221
Daniel Vetter8d754542014-04-10 10:51:11 +0200222/* drm_probe_helper.c */
223extern int drm_helper_probe_single_connector_modes(struct drm_connector
224 *connector, uint32_t maxX,
225 uint32_t maxY);
Dave Airlieb87577b2014-05-01 09:26:53 +1000226extern int drm_helper_probe_single_connector_modes_nomerge(struct drm_connector
227 *connector,
228 uint32_t maxX,
229 uint32_t maxY);
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000230extern void drm_kms_helper_poll_init(struct drm_device *dev);
231extern void drm_kms_helper_poll_fini(struct drm_device *dev);
Marc-André Lureaub8206d32013-10-18 16:11:28 +0200232extern bool drm_helper_hpd_irq_event(struct drm_device *dev);
Daniel Vetter3d3683f2012-10-23 18:23:32 +0000233extern void drm_kms_helper_hotplug_event(struct drm_device *dev);
Dave Airliefbf81762010-06-01 09:09:06 +1000234
235extern void drm_kms_helper_poll_disable(struct drm_device *dev);
236extern void drm_kms_helper_poll_enable(struct drm_device *dev);
Ville Syrjäläd0d110e2011-12-20 00:33:24 +0200237
Dave Airlief453ba02008-11-07 14:05:41 -0800238#endif