Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 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 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 36 | #include <linux/spinlock.h> |
| 37 | #include <linux/types.h> |
| 38 | #include <linux/idr.h> |
| 39 | |
| 40 | #include <linux/fb.h> |
| 41 | |
Thierry Reding | 6d11a2f | 2014-12-17 16:41:42 +0100 | [diff] [blame] | 42 | #include <drm/drm_crtc.h> |
| 43 | |
Jason Wessel | 21c74a8 | 2010-10-13 14:09:44 -0500 | [diff] [blame] | 44 | enum mode_set_atomic { |
| 45 | LEAVE_ATOMIC_MODE_SET, |
| 46 | ENTER_ATOMIC_MODE_SET, |
| 47 | }; |
| 48 | |
Laurent Pinchart | 3b02ab8 | 2012-05-17 13:27:20 +0200 | [diff] [blame] | 49 | /** |
Thierry Reding | 7552e7d | 2014-12-17 16:41:43 +0100 | [diff] [blame] | 50 | * 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 Pinchart | 3b02ab8 | 2012-05-17 13:27:20 +0200 | [diff] [blame] | 55 | * @mode_set: set this mode |
Thierry Reding | 7552e7d | 2014-12-17 16:41:43 +0100 | [diff] [blame] | 56 | * @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 Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 61 | * @enable: enable CRTC |
Thierry Reding | 7552e7d | 2014-12-17 16:41:43 +0100 | [diff] [blame] | 62 | * @atomic_check: check for validity of an atomic state |
| 63 | * @atomic_begin: begin atomic update |
| 64 | * @atomic_flush: flush atomic update |
Laurent Pinchart | 3b02ab8 | 2012-05-17 13:27:20 +0200 | [diff] [blame] | 65 | * |
| 66 | * The helper operations are called by the mid-layer CRTC helper. |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 67 | * |
| 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 Pinchart | 3b02ab8 | 2012-05-17 13:27:20 +0200 | [diff] [blame] | 74 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 75 | struct 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 Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 86 | const struct drm_display_mode *mode, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 87 | struct drm_display_mode *adjusted_mode); |
| 88 | /* Actually set the mode */ |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 89 | 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 Vetter | c982bd9 | 2015-02-22 12:24:20 +0100 | [diff] [blame] | 92 | /* Actually set the mode for atomic helpers, optional */ |
Daniel Vetter | 2f324b4 | 2014-10-29 11:13:47 +0100 | [diff] [blame] | 93 | void (*mode_set_nofb)(struct drm_crtc *crtc); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 94 | |
| 95 | /* Move the crtc on the current fb to the given position *optional* */ |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 96 | int (*mode_set_base)(struct drm_crtc *crtc, int x, int y, |
| 97 | struct drm_framebuffer *old_fb); |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 98 | int (*mode_set_base_atomic)(struct drm_crtc *crtc, |
Jason Wessel | 413d45d | 2010-09-26 06:47:25 -0500 | [diff] [blame] | 99 | struct drm_framebuffer *fb, int x, int y, |
Jason Wessel | 21c74a8 | 2010-10-13 14:09:44 -0500 | [diff] [blame] | 100 | enum mode_set_atomic); |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 101 | |
| 102 | /* reload the current crtc LUT */ |
| 103 | void (*load_lut)(struct drm_crtc *crtc); |
Alex Deucher | 5c8d717 | 2010-06-11 17:04:35 -0400 | [diff] [blame] | 104 | |
Alex Deucher | 5c8d717 | 2010-06-11 17:04:35 -0400 | [diff] [blame] | 105 | void (*disable)(struct drm_crtc *crtc); |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 106 | void (*enable)(struct drm_crtc *crtc); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 107 | |
| 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 Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 113 | }; |
| 114 | |
Laurent Pinchart | 3b02ab8 | 2012-05-17 13:27:20 +0200 | [diff] [blame] | 115 | /** |
Thierry Reding | 7552e7d | 2014-12-17 16:41:43 +0100 | [diff] [blame] | 116 | * 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 Pinchart | 3b02ab8 | 2012-05-17 13:27:20 +0200 | [diff] [blame] | 120 | * @mode_fixup: try to fixup proposed mode for this connector |
Thierry Reding | 7552e7d | 2014-12-17 16:41:43 +0100 | [diff] [blame] | 121 | * @prepare: part of the disable sequence, called before the CRTC modeset |
| 122 | * @commit: called after the CRTC modeset |
Daniel Vetter | c982bd9 | 2015-02-22 12:24:20 +0100 | [diff] [blame] | 123 | * @mode_set: set this mode, optional for atomic helpers |
Thierry Reding | 7552e7d | 2014-12-17 16:41:43 +0100 | [diff] [blame] | 124 | * @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 Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 127 | * @enable: enable encoder |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 128 | * @atomic_check: check for validity of an atomic update |
Laurent Pinchart | 3b02ab8 | 2012-05-17 13:27:20 +0200 | [diff] [blame] | 129 | * |
| 130 | * The helper operations are called by the mid-layer CRTC helper. |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 131 | * |
| 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 Pinchart | 3b02ab8 | 2012-05-17 13:27:20 +0200 | [diff] [blame] | 138 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 139 | struct 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 Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 145 | const struct drm_display_mode *mode, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 146 | 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 Barnes | 7bec756 | 2009-02-23 16:09:34 -0800 | [diff] [blame] | 152 | struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 153 | /* detect for DAC style encoders */ |
| 154 | enum drm_connector_status (*detect)(struct drm_encoder *encoder, |
| 155 | struct drm_connector *connector); |
Dave Airlie | a3a0544 | 2009-08-31 15:16:30 +1000 | [diff] [blame] | 156 | void (*disable)(struct drm_encoder *encoder); |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 157 | |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 158 | void (*enable)(struct drm_encoder *encoder); |
Dave Airlie | 21773f1 | 2015-01-28 09:34:27 +1000 | [diff] [blame] | 159 | |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 160 | /* 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 Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 164 | }; |
| 165 | |
Laurent Pinchart | 3b02ab8 | 2012-05-17 13:27:20 +0200 | [diff] [blame] | 166 | /** |
Thierry Reding | 7552e7d | 2014-12-17 16:41:43 +0100 | [diff] [blame] | 167 | * struct drm_connector_helper_funcs - helper operations for connectors |
Laurent Pinchart | 3b02ab8 | 2012-05-17 13:27:20 +0200 | [diff] [blame] | 168 | * @get_modes: get mode list for this connector |
Thierry Reding | 7552e7d | 2014-12-17 16:41:43 +0100 | [diff] [blame] | 169 | * @mode_valid: is this mode valid on the given connector? (optional) |
| 170 | * @best_encoder: return the preferred encoder for this connector |
Laurent Pinchart | 3b02ab8 | 2012-05-17 13:27:20 +0200 | [diff] [blame] | 171 | * |
| 172 | * The helper operations are called by the mid-layer CRTC helper. |
| 173 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 174 | struct drm_connector_helper_funcs { |
| 175 | int (*get_modes)(struct drm_connector *connector); |
Damien Lespiau | 0993f1d | 2013-11-28 15:29:17 +0000 | [diff] [blame] | 176 | enum drm_mode_status (*mode_valid)(struct drm_connector *connector, |
| 177 | struct drm_display_mode *mode); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 178 | struct drm_encoder *(*best_encoder)(struct drm_connector *connector); |
| 179 | }; |
| 180 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 181 | extern void drm_helper_disable_unused_functions(struct drm_device *dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 182 | extern int drm_crtc_helper_set_config(struct drm_mode_set *set); |
| 183 | extern bool drm_crtc_helper_set_mode(struct drm_crtc *crtc, |
| 184 | struct drm_display_mode *mode, |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 185 | int x, int y, |
| 186 | struct drm_framebuffer *old_fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 187 | extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc); |
Maarten Maathuis | f380ef8 | 2009-08-19 00:56:44 +0200 | [diff] [blame] | 188 | extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 189 | |
Keith Packard | c9fb15f | 2009-05-30 20:42:28 -0700 | [diff] [blame] | 190 | extern void drm_helper_connector_dpms(struct drm_connector *connector, int mode); |
| 191 | |
Daniel Vetter | cfc1a06 | 2012-10-27 15:52:04 +0200 | [diff] [blame] | 192 | extern void drm_helper_move_panel_connectors_to_head(struct drm_device *); |
| 193 | |
Daniel Vetter | 9fd9378 | 2014-01-23 22:16:24 +0100 | [diff] [blame] | 194 | extern void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb, |
| 195 | struct drm_mode_fb_cmd2 *mode_cmd); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 196 | |
| 197 | static inline void drm_crtc_helper_add(struct drm_crtc *crtc, |
| 198 | const struct drm_crtc_helper_funcs *funcs) |
| 199 | { |
Jani Nikula | 9a436ee | 2015-04-13 11:21:42 +0300 | [diff] [blame] | 200 | crtc->helper_private = funcs; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | static inline void drm_encoder_helper_add(struct drm_encoder *encoder, |
| 204 | const struct drm_encoder_helper_funcs *funcs) |
| 205 | { |
Jani Nikula | 9a436ee | 2015-04-13 11:21:42 +0300 | [diff] [blame] | 206 | encoder->helper_private = funcs; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 207 | } |
| 208 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 209 | static inline void drm_connector_helper_add(struct drm_connector *connector, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 210 | const struct drm_connector_helper_funcs *funcs) |
| 211 | { |
Jani Nikula | 9a436ee | 2015-04-13 11:21:42 +0300 | [diff] [blame] | 212 | connector->helper_private = funcs; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 213 | } |
| 214 | |
Daniel Vetter | 00d762c | 2014-01-23 22:28:30 +0100 | [diff] [blame] | 215 | extern void drm_helper_resume_force_mode(struct drm_device *dev); |
Daniel Vetter | 8d75454 | 2014-04-10 10:51:11 +0200 | [diff] [blame] | 216 | |
Daniel Vetter | 2f324b4 | 2014-10-29 11:13:47 +0100 | [diff] [blame] | 217 | int 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); |
| 220 | int drm_helper_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, |
| 221 | struct drm_framebuffer *old_fb); |
| 222 | |
Daniel Vetter | 8d75454 | 2014-04-10 10:51:11 +0200 | [diff] [blame] | 223 | /* drm_probe_helper.c */ |
| 224 | extern int drm_helper_probe_single_connector_modes(struct drm_connector |
| 225 | *connector, uint32_t maxX, |
| 226 | uint32_t maxY); |
Dave Airlie | b87577b | 2014-05-01 09:26:53 +1000 | [diff] [blame] | 227 | extern int drm_helper_probe_single_connector_modes_nomerge(struct drm_connector |
| 228 | *connector, |
| 229 | uint32_t maxX, |
| 230 | uint32_t maxY); |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 231 | extern void drm_kms_helper_poll_init(struct drm_device *dev); |
| 232 | extern void drm_kms_helper_poll_fini(struct drm_device *dev); |
Marc-André Lureau | b8206d3 | 2013-10-18 16:11:28 +0200 | [diff] [blame] | 233 | extern bool drm_helper_hpd_irq_event(struct drm_device *dev); |
Daniel Vetter | 3d3683f | 2012-10-23 18:23:32 +0000 | [diff] [blame] | 234 | extern void drm_kms_helper_hotplug_event(struct drm_device *dev); |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 235 | |
| 236 | extern void drm_kms_helper_poll_disable(struct drm_device *dev); |
| 237 | extern void drm_kms_helper_poll_enable(struct drm_device *dev); |
Ville Syrjälä | d0d110e | 2011-12-20 00:33:24 +0200 | [diff] [blame] | 238 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 239 | #endif |