1f453ba04SDave Airlie /* 2f453ba04SDave Airlie * Copyright © 2006 Keith Packard 3f453ba04SDave Airlie * Copyright © 2007-2008 Dave Airlie 4f453ba04SDave Airlie * Copyright © 2007-2008 Intel Corporation 5f453ba04SDave Airlie * Jesse Barnes <jesse.barnes@intel.com> 6f453ba04SDave Airlie * 7f453ba04SDave Airlie * Permission is hereby granted, free of charge, to any person obtaining a 8f453ba04SDave Airlie * copy of this software and associated documentation files (the "Software"), 9f453ba04SDave Airlie * to deal in the Software without restriction, including without limitation 10f453ba04SDave Airlie * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11f453ba04SDave Airlie * and/or sell copies of the Software, and to permit persons to whom the 12f453ba04SDave Airlie * Software is furnished to do so, subject to the following conditions: 13f453ba04SDave Airlie * 14f453ba04SDave Airlie * The above copyright notice and this permission notice shall be included in 15f453ba04SDave Airlie * all copies or substantial portions of the Software. 16f453ba04SDave Airlie * 17f453ba04SDave Airlie * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18f453ba04SDave Airlie * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19f453ba04SDave Airlie * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20f453ba04SDave Airlie * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 21f453ba04SDave Airlie * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22f453ba04SDave Airlie * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23f453ba04SDave Airlie * OTHER DEALINGS IN THE SOFTWARE. 24f453ba04SDave Airlie */ 25f453ba04SDave Airlie 26f453ba04SDave Airlie /* 27f453ba04SDave Airlie * The DRM mode setting helper functions are common code for drivers to use if 28f453ba04SDave Airlie * they wish. Drivers are not forced to use this code in their 29f453ba04SDave Airlie * implementations but it would be useful if they code they do use at least 30f453ba04SDave Airlie * provides a consistent interface and operation to userspace 31f453ba04SDave Airlie */ 32f453ba04SDave Airlie 33f453ba04SDave Airlie #ifndef __DRM_CRTC_HELPER_H__ 34f453ba04SDave Airlie #define __DRM_CRTC_HELPER_H__ 35f453ba04SDave Airlie 36f453ba04SDave Airlie #include <linux/spinlock.h> 37f453ba04SDave Airlie #include <linux/types.h> 38f453ba04SDave Airlie #include <linux/idr.h> 39f453ba04SDave Airlie 40f453ba04SDave Airlie #include <linux/fb.h> 41f453ba04SDave Airlie 426d11a2f0SThierry Reding #include <drm/drm_crtc.h> 436d11a2f0SThierry Reding 4421c74a8eSJason Wessel enum mode_set_atomic { 4521c74a8eSJason Wessel LEAVE_ATOMIC_MODE_SET, 4621c74a8eSJason Wessel ENTER_ATOMIC_MODE_SET, 4721c74a8eSJason Wessel }; 4821c74a8eSJason Wessel 493b02ab88SLaurent Pinchart /** 503b02ab88SLaurent Pinchart * drm_crtc_helper_funcs - helper operations for CRTCs 513b02ab88SLaurent Pinchart * @mode_fixup: try to fixup proposed mode for this connector 523b02ab88SLaurent Pinchart * @mode_set: set this mode 533b02ab88SLaurent Pinchart * 543b02ab88SLaurent Pinchart * The helper operations are called by the mid-layer CRTC helper. 553b02ab88SLaurent Pinchart */ 56f453ba04SDave Airlie struct drm_crtc_helper_funcs { 57f453ba04SDave Airlie /* 58f453ba04SDave Airlie * Control power levels on the CRTC. If the mode passed in is 59f453ba04SDave Airlie * unsupported, the provider must use the next lowest power level. 60f453ba04SDave Airlie */ 61f453ba04SDave Airlie void (*dpms)(struct drm_crtc *crtc, int mode); 62f453ba04SDave Airlie void (*prepare)(struct drm_crtc *crtc); 63f453ba04SDave Airlie void (*commit)(struct drm_crtc *crtc); 64f453ba04SDave Airlie 65f453ba04SDave Airlie /* Provider can fixup or change mode timings before modeset occurs */ 66f453ba04SDave Airlie bool (*mode_fixup)(struct drm_crtc *crtc, 67e811f5aeSLaurent Pinchart const struct drm_display_mode *mode, 68f453ba04SDave Airlie struct drm_display_mode *adjusted_mode); 69f453ba04SDave Airlie /* Actually set the mode */ 705c3b82e2SChris Wilson int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode, 713c4fdcfbSKristian Høgsberg struct drm_display_mode *adjusted_mode, int x, int y, 723c4fdcfbSKristian Høgsberg struct drm_framebuffer *old_fb); 732f324b42SDaniel Vetter void (*mode_set_nofb)(struct drm_crtc *crtc); 74f453ba04SDave Airlie 75f453ba04SDave Airlie /* Move the crtc on the current fb to the given position *optional* */ 765c3b82e2SChris Wilson int (*mode_set_base)(struct drm_crtc *crtc, int x, int y, 773c4fdcfbSKristian Høgsberg struct drm_framebuffer *old_fb); 781a7aba7fSJesse Barnes int (*mode_set_base_atomic)(struct drm_crtc *crtc, 79413d45d3SJason Wessel struct drm_framebuffer *fb, int x, int y, 8021c74a8eSJason Wessel enum mode_set_atomic); 81068143d3SDave Airlie 82068143d3SDave Airlie /* reload the current crtc LUT */ 83068143d3SDave Airlie void (*load_lut)(struct drm_crtc *crtc); 845c8d7171SAlex Deucher 855c8d7171SAlex Deucher /* disable crtc when not in use - more explicit than dpms off */ 865c8d7171SAlex Deucher void (*disable)(struct drm_crtc *crtc); 87c2fcd274SDaniel Vetter 88c2fcd274SDaniel Vetter /* atomic helpers */ 89c2fcd274SDaniel Vetter int (*atomic_check)(struct drm_crtc *crtc, 90c2fcd274SDaniel Vetter struct drm_crtc_state *state); 91c2fcd274SDaniel Vetter void (*atomic_begin)(struct drm_crtc *crtc); 92c2fcd274SDaniel Vetter void (*atomic_flush)(struct drm_crtc *crtc); 93f453ba04SDave Airlie }; 94f453ba04SDave Airlie 953b02ab88SLaurent Pinchart /** 963b02ab88SLaurent Pinchart * drm_encoder_helper_funcs - helper operations for encoders 973b02ab88SLaurent Pinchart * @mode_fixup: try to fixup proposed mode for this connector 983b02ab88SLaurent Pinchart * @mode_set: set this mode 993b02ab88SLaurent Pinchart * 1003b02ab88SLaurent Pinchart * The helper operations are called by the mid-layer CRTC helper. 1013b02ab88SLaurent Pinchart */ 102f453ba04SDave Airlie struct drm_encoder_helper_funcs { 103f453ba04SDave Airlie void (*dpms)(struct drm_encoder *encoder, int mode); 104f453ba04SDave Airlie void (*save)(struct drm_encoder *encoder); 105f453ba04SDave Airlie void (*restore)(struct drm_encoder *encoder); 106f453ba04SDave Airlie 107f453ba04SDave Airlie bool (*mode_fixup)(struct drm_encoder *encoder, 108e811f5aeSLaurent Pinchart const struct drm_display_mode *mode, 109f453ba04SDave Airlie struct drm_display_mode *adjusted_mode); 110f453ba04SDave Airlie void (*prepare)(struct drm_encoder *encoder); 111f453ba04SDave Airlie void (*commit)(struct drm_encoder *encoder); 112f453ba04SDave Airlie void (*mode_set)(struct drm_encoder *encoder, 113f453ba04SDave Airlie struct drm_display_mode *mode, 114f453ba04SDave Airlie struct drm_display_mode *adjusted_mode); 1157bec756cSJesse Barnes struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder); 116f453ba04SDave Airlie /* detect for DAC style encoders */ 117f453ba04SDave Airlie enum drm_connector_status (*detect)(struct drm_encoder *encoder, 118f453ba04SDave Airlie struct drm_connector *connector); 119a3a0544bSDave Airlie /* disable encoder when not in use - more explicit than dpms off */ 120a3a0544bSDave Airlie void (*disable)(struct drm_encoder *encoder); 121f453ba04SDave Airlie }; 122f453ba04SDave Airlie 1233b02ab88SLaurent Pinchart /** 1243b02ab88SLaurent Pinchart * drm_connector_helper_funcs - helper operations for connectors 1253b02ab88SLaurent Pinchart * @get_modes: get mode list for this connector 126f9b0e251SAndrzej Hajda * @mode_valid (optional): is this mode valid on the given connector? 1273b02ab88SLaurent Pinchart * 1283b02ab88SLaurent Pinchart * The helper operations are called by the mid-layer CRTC helper. 1293b02ab88SLaurent Pinchart */ 130f453ba04SDave Airlie struct drm_connector_helper_funcs { 131f453ba04SDave Airlie int (*get_modes)(struct drm_connector *connector); 1320993f1d0SDamien Lespiau enum drm_mode_status (*mode_valid)(struct drm_connector *connector, 133f453ba04SDave Airlie struct drm_display_mode *mode); 134f453ba04SDave Airlie struct drm_encoder *(*best_encoder)(struct drm_connector *connector); 135f453ba04SDave Airlie }; 136f453ba04SDave Airlie 137f453ba04SDave Airlie extern void drm_helper_disable_unused_functions(struct drm_device *dev); 138f453ba04SDave Airlie extern int drm_crtc_helper_set_config(struct drm_mode_set *set); 139f453ba04SDave Airlie extern bool drm_crtc_helper_set_mode(struct drm_crtc *crtc, 140f453ba04SDave Airlie struct drm_display_mode *mode, 1413c4fdcfbSKristian Høgsberg int x, int y, 1423c4fdcfbSKristian Høgsberg struct drm_framebuffer *old_fb); 143f453ba04SDave Airlie extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc); 144f380ef86SMaarten Maathuis extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder); 145f453ba04SDave Airlie 146c9fb15f6SKeith Packard extern void drm_helper_connector_dpms(struct drm_connector *connector, int mode); 147c9fb15f6SKeith Packard 148cfc1a062SDaniel Vetter extern void drm_helper_move_panel_connectors_to_head(struct drm_device *); 149cfc1a062SDaniel Vetter 1509fd93784SDaniel Vetter extern void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb, 151308e5bcbSJesse Barnes struct drm_mode_fb_cmd2 *mode_cmd); 152f453ba04SDave Airlie 153f453ba04SDave Airlie static inline void drm_crtc_helper_add(struct drm_crtc *crtc, 154f453ba04SDave Airlie const struct drm_crtc_helper_funcs *funcs) 155f453ba04SDave Airlie { 156f453ba04SDave Airlie crtc->helper_private = (void *)funcs; 157f453ba04SDave Airlie } 158f453ba04SDave Airlie 159f453ba04SDave Airlie static inline void drm_encoder_helper_add(struct drm_encoder *encoder, 160f453ba04SDave Airlie const struct drm_encoder_helper_funcs *funcs) 161f453ba04SDave Airlie { 162f453ba04SDave Airlie encoder->helper_private = (void *)funcs; 163f453ba04SDave Airlie } 164f453ba04SDave Airlie 1650b4c0f3fSDave Airlie static inline void drm_connector_helper_add(struct drm_connector *connector, 166f453ba04SDave Airlie const struct drm_connector_helper_funcs *funcs) 167f453ba04SDave Airlie { 168f453ba04SDave Airlie connector->helper_private = (void *)funcs; 169f453ba04SDave Airlie } 170f453ba04SDave Airlie 17100d762cbSDaniel Vetter extern void drm_helper_resume_force_mode(struct drm_device *dev); 1728d754544SDaniel Vetter 1732f324b42SDaniel Vetter int drm_helper_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode, 1742f324b42SDaniel Vetter struct drm_display_mode *adjusted_mode, int x, int y, 1752f324b42SDaniel Vetter struct drm_framebuffer *old_fb); 1762f324b42SDaniel Vetter int drm_helper_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, 1772f324b42SDaniel Vetter struct drm_framebuffer *old_fb); 1782f324b42SDaniel Vetter 1798d754544SDaniel Vetter /* drm_probe_helper.c */ 1808d754544SDaniel Vetter extern int drm_helper_probe_single_connector_modes(struct drm_connector 1818d754544SDaniel Vetter *connector, uint32_t maxX, 1828d754544SDaniel Vetter uint32_t maxY); 183b87577b7SDave Airlie extern int drm_helper_probe_single_connector_modes_nomerge(struct drm_connector 184b87577b7SDave Airlie *connector, 185b87577b7SDave Airlie uint32_t maxX, 186b87577b7SDave Airlie uint32_t maxY); 187eb1f8e4fSDave Airlie extern void drm_kms_helper_poll_init(struct drm_device *dev); 188eb1f8e4fSDave Airlie extern void drm_kms_helper_poll_fini(struct drm_device *dev); 189b8206d39SMarc-André Lureau extern bool drm_helper_hpd_irq_event(struct drm_device *dev); 1903d3683f0SDaniel Vetter extern void drm_kms_helper_hotplug_event(struct drm_device *dev); 191fbf81762SDave Airlie 192fbf81762SDave Airlie extern void drm_kms_helper_poll_disable(struct drm_device *dev); 193fbf81762SDave Airlie extern void drm_kms_helper_poll_enable(struct drm_device *dev); 194d0d110e0SVille Syrjälä 195f453ba04SDave Airlie #endif 196