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