1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * Copyright (C) 2016 Noralf Trønnes 4*4882a593Smuzhiyun */ 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun #ifndef __LINUX_DRM_SIMPLE_KMS_HELPER_H 7*4882a593Smuzhiyun #define __LINUX_DRM_SIMPLE_KMS_HELPER_H 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun #include <drm/drm_crtc.h> 10*4882a593Smuzhiyun #include <drm/drm_encoder.h> 11*4882a593Smuzhiyun #include <drm/drm_plane.h> 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun struct drm_simple_display_pipe; 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun /** 16*4882a593Smuzhiyun * struct drm_simple_display_pipe_funcs - helper operations for a simple 17*4882a593Smuzhiyun * display pipeline 18*4882a593Smuzhiyun */ 19*4882a593Smuzhiyun struct drm_simple_display_pipe_funcs { 20*4882a593Smuzhiyun /** 21*4882a593Smuzhiyun * @mode_valid: 22*4882a593Smuzhiyun * 23*4882a593Smuzhiyun * This callback is used to check if a specific mode is valid in the 24*4882a593Smuzhiyun * crtc used in this simple display pipe. This should be implemented 25*4882a593Smuzhiyun * if the display pipe has some sort of restriction in the modes 26*4882a593Smuzhiyun * it can display. For example, a given display pipe may be responsible 27*4882a593Smuzhiyun * to set a clock value. If the clock can not produce all the values 28*4882a593Smuzhiyun * for the available modes then this callback can be used to restrict 29*4882a593Smuzhiyun * the number of modes to only the ones that can be displayed. Another 30*4882a593Smuzhiyun * reason can be bandwidth mitigation: the memory port on the display 31*4882a593Smuzhiyun * controller can have bandwidth limitations not allowing pixel data 32*4882a593Smuzhiyun * to be fetched at any rate. 33*4882a593Smuzhiyun * 34*4882a593Smuzhiyun * This hook is used by the probe helpers to filter the mode list in 35*4882a593Smuzhiyun * drm_helper_probe_single_connector_modes(), and it is used by the 36*4882a593Smuzhiyun * atomic helpers to validate modes supplied by userspace in 37*4882a593Smuzhiyun * drm_atomic_helper_check_modeset(). 38*4882a593Smuzhiyun * 39*4882a593Smuzhiyun * This function is optional. 40*4882a593Smuzhiyun * 41*4882a593Smuzhiyun * NOTE: 42*4882a593Smuzhiyun * 43*4882a593Smuzhiyun * Since this function is both called from the check phase of an atomic 44*4882a593Smuzhiyun * commit, and the mode validation in the probe paths it is not allowed 45*4882a593Smuzhiyun * to look at anything else but the passed-in mode, and validate it 46*4882a593Smuzhiyun * against configuration-invariant hardware constraints. 47*4882a593Smuzhiyun * 48*4882a593Smuzhiyun * RETURNS: 49*4882a593Smuzhiyun * 50*4882a593Smuzhiyun * drm_mode_status Enum 51*4882a593Smuzhiyun */ 52*4882a593Smuzhiyun enum drm_mode_status (*mode_valid)(struct drm_simple_display_pipe *pipe, 53*4882a593Smuzhiyun const struct drm_display_mode *mode); 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun /** 56*4882a593Smuzhiyun * @enable: 57*4882a593Smuzhiyun * 58*4882a593Smuzhiyun * This function should be used to enable the pipeline. 59*4882a593Smuzhiyun * It is called when the underlying crtc is enabled. 60*4882a593Smuzhiyun * This hook is optional. 61*4882a593Smuzhiyun */ 62*4882a593Smuzhiyun void (*enable)(struct drm_simple_display_pipe *pipe, 63*4882a593Smuzhiyun struct drm_crtc_state *crtc_state, 64*4882a593Smuzhiyun struct drm_plane_state *plane_state); 65*4882a593Smuzhiyun /** 66*4882a593Smuzhiyun * @disable: 67*4882a593Smuzhiyun * 68*4882a593Smuzhiyun * This function should be used to disable the pipeline. 69*4882a593Smuzhiyun * It is called when the underlying crtc is disabled. 70*4882a593Smuzhiyun * This hook is optional. 71*4882a593Smuzhiyun */ 72*4882a593Smuzhiyun void (*disable)(struct drm_simple_display_pipe *pipe); 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun /** 75*4882a593Smuzhiyun * @check: 76*4882a593Smuzhiyun * 77*4882a593Smuzhiyun * This function is called in the check phase of an atomic update, 78*4882a593Smuzhiyun * specifically when the underlying plane is checked. 79*4882a593Smuzhiyun * The simple display pipeline helpers already check that the plane is 80*4882a593Smuzhiyun * not scaled, fills the entire visible area and is always enabled 81*4882a593Smuzhiyun * when the crtc is also enabled. 82*4882a593Smuzhiyun * This hook is optional. 83*4882a593Smuzhiyun * 84*4882a593Smuzhiyun * RETURNS: 85*4882a593Smuzhiyun * 86*4882a593Smuzhiyun * 0 on success, -EINVAL if the state or the transition can't be 87*4882a593Smuzhiyun * supported, -ENOMEM on memory allocation failure and -EDEADLK if an 88*4882a593Smuzhiyun * attempt to obtain another state object ran into a &drm_modeset_lock 89*4882a593Smuzhiyun * deadlock. 90*4882a593Smuzhiyun */ 91*4882a593Smuzhiyun int (*check)(struct drm_simple_display_pipe *pipe, 92*4882a593Smuzhiyun struct drm_plane_state *plane_state, 93*4882a593Smuzhiyun struct drm_crtc_state *crtc_state); 94*4882a593Smuzhiyun /** 95*4882a593Smuzhiyun * @update: 96*4882a593Smuzhiyun * 97*4882a593Smuzhiyun * This function is called when the underlying plane state is updated. 98*4882a593Smuzhiyun * This hook is optional. 99*4882a593Smuzhiyun * 100*4882a593Smuzhiyun * This is the function drivers should submit the 101*4882a593Smuzhiyun * &drm_pending_vblank_event from. Using either 102*4882a593Smuzhiyun * drm_crtc_arm_vblank_event(), when the driver supports vblank 103*4882a593Smuzhiyun * interrupt handling, or drm_crtc_send_vblank_event() for more 104*4882a593Smuzhiyun * complex case. In case the hardware lacks vblank support entirely, 105*4882a593Smuzhiyun * drivers can set &struct drm_crtc_state.no_vblank in 106*4882a593Smuzhiyun * &struct drm_simple_display_pipe_funcs.check and let DRM's 107*4882a593Smuzhiyun * atomic helper fake a vblank event. 108*4882a593Smuzhiyun */ 109*4882a593Smuzhiyun void (*update)(struct drm_simple_display_pipe *pipe, 110*4882a593Smuzhiyun struct drm_plane_state *old_plane_state); 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun /** 113*4882a593Smuzhiyun * @prepare_fb: 114*4882a593Smuzhiyun * 115*4882a593Smuzhiyun * Optional, called by &drm_plane_helper_funcs.prepare_fb. Please read 116*4882a593Smuzhiyun * the documentation for the &drm_plane_helper_funcs.prepare_fb hook for 117*4882a593Smuzhiyun * more details. 118*4882a593Smuzhiyun * 119*4882a593Smuzhiyun * Drivers which always have their buffers pinned should use 120*4882a593Smuzhiyun * drm_gem_fb_simple_display_pipe_prepare_fb() for this hook. 121*4882a593Smuzhiyun */ 122*4882a593Smuzhiyun int (*prepare_fb)(struct drm_simple_display_pipe *pipe, 123*4882a593Smuzhiyun struct drm_plane_state *plane_state); 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun /** 126*4882a593Smuzhiyun * @cleanup_fb: 127*4882a593Smuzhiyun * 128*4882a593Smuzhiyun * Optional, called by &drm_plane_helper_funcs.cleanup_fb. Please read 129*4882a593Smuzhiyun * the documentation for the &drm_plane_helper_funcs.cleanup_fb hook for 130*4882a593Smuzhiyun * more details. 131*4882a593Smuzhiyun */ 132*4882a593Smuzhiyun void (*cleanup_fb)(struct drm_simple_display_pipe *pipe, 133*4882a593Smuzhiyun struct drm_plane_state *plane_state); 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun /** 136*4882a593Smuzhiyun * @enable_vblank: 137*4882a593Smuzhiyun * 138*4882a593Smuzhiyun * Optional, called by &drm_crtc_funcs.enable_vblank. Please read 139*4882a593Smuzhiyun * the documentation for the &drm_crtc_funcs.enable_vblank hook for 140*4882a593Smuzhiyun * more details. 141*4882a593Smuzhiyun */ 142*4882a593Smuzhiyun int (*enable_vblank)(struct drm_simple_display_pipe *pipe); 143*4882a593Smuzhiyun 144*4882a593Smuzhiyun /** 145*4882a593Smuzhiyun * @disable_vblank: 146*4882a593Smuzhiyun * 147*4882a593Smuzhiyun * Optional, called by &drm_crtc_funcs.disable_vblank. Please read 148*4882a593Smuzhiyun * the documentation for the &drm_crtc_funcs.disable_vblank hook for 149*4882a593Smuzhiyun * more details. 150*4882a593Smuzhiyun */ 151*4882a593Smuzhiyun void (*disable_vblank)(struct drm_simple_display_pipe *pipe); 152*4882a593Smuzhiyun }; 153*4882a593Smuzhiyun 154*4882a593Smuzhiyun /** 155*4882a593Smuzhiyun * struct drm_simple_display_pipe - simple display pipeline 156*4882a593Smuzhiyun * @crtc: CRTC control structure 157*4882a593Smuzhiyun * @plane: Plane control structure 158*4882a593Smuzhiyun * @encoder: Encoder control structure 159*4882a593Smuzhiyun * @connector: Connector control structure 160*4882a593Smuzhiyun * @funcs: Pipeline control functions (optional) 161*4882a593Smuzhiyun * 162*4882a593Smuzhiyun * Simple display pipeline with plane, crtc and encoder collapsed into one 163*4882a593Smuzhiyun * entity. It should be initialized by calling drm_simple_display_pipe_init(). 164*4882a593Smuzhiyun */ 165*4882a593Smuzhiyun struct drm_simple_display_pipe { 166*4882a593Smuzhiyun struct drm_crtc crtc; 167*4882a593Smuzhiyun struct drm_plane plane; 168*4882a593Smuzhiyun struct drm_encoder encoder; 169*4882a593Smuzhiyun struct drm_connector *connector; 170*4882a593Smuzhiyun 171*4882a593Smuzhiyun const struct drm_simple_display_pipe_funcs *funcs; 172*4882a593Smuzhiyun }; 173*4882a593Smuzhiyun 174*4882a593Smuzhiyun int drm_simple_display_pipe_attach_bridge(struct drm_simple_display_pipe *pipe, 175*4882a593Smuzhiyun struct drm_bridge *bridge); 176*4882a593Smuzhiyun 177*4882a593Smuzhiyun int drm_simple_display_pipe_init(struct drm_device *dev, 178*4882a593Smuzhiyun struct drm_simple_display_pipe *pipe, 179*4882a593Smuzhiyun const struct drm_simple_display_pipe_funcs *funcs, 180*4882a593Smuzhiyun const uint32_t *formats, unsigned int format_count, 181*4882a593Smuzhiyun const uint64_t *format_modifiers, 182*4882a593Smuzhiyun struct drm_connector *connector); 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun int drm_simple_encoder_init(struct drm_device *dev, 185*4882a593Smuzhiyun struct drm_encoder *encoder, 186*4882a593Smuzhiyun int encoder_type); 187*4882a593Smuzhiyun 188*4882a593Smuzhiyun #endif /* __LINUX_DRM_SIMPLE_KMS_HELPER_H */ 189