1 /* 2 * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. 3 * Copyright (C) 2013 Red Hat 4 * Author: Rob Clark <robdclark@gmail.com> 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 as published by 8 * the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 * 15 * You should have received a copy of the GNU General Public License along with 16 * this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef __DPU_ENCODER_H__ 20 #define __DPU_ENCODER_H__ 21 22 #include <drm/drm_crtc.h> 23 #include "dpu_hw_mdss.h" 24 25 #define DPU_ENCODER_FRAME_EVENT_DONE BIT(0) 26 #define DPU_ENCODER_FRAME_EVENT_ERROR BIT(1) 27 #define DPU_ENCODER_FRAME_EVENT_PANEL_DEAD BIT(2) 28 #define DPU_ENCODER_FRAME_EVENT_IDLE BIT(3) 29 30 #define IDLE_TIMEOUT (66 - 16/2) 31 32 /** 33 * Encoder functions and data types 34 * @intfs: Interfaces this encoder is using, INTF_MODE_NONE if unused 35 */ 36 struct dpu_encoder_hw_resources { 37 enum dpu_intf_mode intfs[INTF_MAX]; 38 }; 39 40 /** 41 * dpu_encoder_kickoff_params - info encoder requires at kickoff 42 * @affected_displays: bitmask, bit set means the ROI of the commit lies within 43 * the bounds of the physical display at the bit index 44 */ 45 struct dpu_encoder_kickoff_params { 46 unsigned long affected_displays; 47 }; 48 49 /** 50 * dpu_encoder_get_hw_resources - Populate table of required hardware resources 51 * @encoder: encoder pointer 52 * @hw_res: resource table to populate with encoder required resources 53 */ 54 void dpu_encoder_get_hw_resources(struct drm_encoder *encoder, 55 struct dpu_encoder_hw_resources *hw_res); 56 57 /** 58 * dpu_encoder_assign_crtc - Link the encoder to the crtc it's assigned to 59 * @encoder: encoder pointer 60 * @crtc: crtc pointer 61 */ 62 void dpu_encoder_assign_crtc(struct drm_encoder *encoder, 63 struct drm_crtc *crtc); 64 65 /** 66 * dpu_encoder_toggle_vblank_for_crtc - Toggles vblank interrupts on or off if 67 * the encoder is assigned to the given crtc 68 * @encoder: encoder pointer 69 * @crtc: crtc pointer 70 * @enable: true if vblank should be enabled 71 */ 72 void dpu_encoder_toggle_vblank_for_crtc(struct drm_encoder *encoder, 73 struct drm_crtc *crtc, bool enable); 74 75 /** 76 * dpu_encoder_register_frame_event_callback - provide callback to encoder that 77 * will be called after the request is complete, or other events. 78 * @encoder: encoder pointer 79 * @cb: callback pointer, provide NULL to deregister 80 * @data: user data provided to callback 81 */ 82 void dpu_encoder_register_frame_event_callback(struct drm_encoder *encoder, 83 void (*cb)(void *, u32), void *data); 84 85 /** 86 * dpu_encoder_prepare_for_kickoff - schedule double buffer flip of the ctl 87 * path (i.e. ctl flush and start) at next appropriate time. 88 * Immediately: if no previous commit is outstanding. 89 * Delayed: Block until next trigger can be issued. 90 * @encoder: encoder pointer 91 * @params: kickoff time parameters 92 * @async: true if this is an asynchronous commit 93 */ 94 void dpu_encoder_prepare_for_kickoff(struct drm_encoder *encoder, 95 struct dpu_encoder_kickoff_params *params, bool async); 96 97 /** 98 * dpu_encoder_trigger_kickoff_pending - Clear the flush bits from previous 99 * kickoff and trigger the ctl prepare progress for command mode display. 100 * @encoder: encoder pointer 101 */ 102 void dpu_encoder_trigger_kickoff_pending(struct drm_encoder *encoder); 103 104 /** 105 * dpu_encoder_kickoff - trigger a double buffer flip of the ctl path 106 * (i.e. ctl flush and start) immediately. 107 * @encoder: encoder pointer 108 * @async: true if this is an asynchronous commit 109 */ 110 void dpu_encoder_kickoff(struct drm_encoder *encoder, bool async); 111 112 /** 113 * dpu_encoder_wait_for_event - Waits for encoder events 114 * @encoder: encoder pointer 115 * @event: event to wait for 116 * MSM_ENC_COMMIT_DONE - Wait for hardware to have flushed the current pending 117 * frames to hardware at a vblank or ctl_start 118 * Encoders will map this differently depending on the 119 * panel type. 120 * vid mode -> vsync_irq 121 * cmd mode -> ctl_start 122 * MSM_ENC_TX_COMPLETE - Wait for the hardware to transfer all the pixels to 123 * the panel. Encoders will map this differently 124 * depending on the panel type. 125 * vid mode -> vsync_irq 126 * cmd mode -> pp_done 127 * Returns: 0 on success, -EWOULDBLOCK if already signaled, error otherwise 128 */ 129 int dpu_encoder_wait_for_event(struct drm_encoder *drm_encoder, 130 enum msm_event_wait event); 131 132 /* 133 * dpu_encoder_get_intf_mode - get interface mode of the given encoder 134 * @encoder: Pointer to drm encoder object 135 */ 136 enum dpu_intf_mode dpu_encoder_get_intf_mode(struct drm_encoder *encoder); 137 138 /** 139 * dpu_encoder_virt_runtime_resume - pm runtime resume the encoder configs 140 * @encoder: encoder pointer 141 */ 142 void dpu_encoder_virt_runtime_resume(struct drm_encoder *encoder); 143 144 /** 145 * dpu_encoder_init - initialize virtual encoder object 146 * @dev: Pointer to drm device structure 147 * @disp_info: Pointer to display information structure 148 * Returns: Pointer to newly created drm encoder 149 */ 150 struct drm_encoder *dpu_encoder_init( 151 struct drm_device *dev, 152 int drm_enc_mode); 153 154 /** 155 * dpu_encoder_setup - setup dpu_encoder for the display probed 156 * @dev: Pointer to drm device structure 157 * @enc: Pointer to the drm_encoder 158 * @disp_info: Pointer to the display info 159 */ 160 int dpu_encoder_setup(struct drm_device *dev, struct drm_encoder *enc, 161 struct msm_display_info *disp_info); 162 163 /** 164 * dpu_encoder_prepare_commit - prepare encoder at the very beginning of an 165 * atomic commit, before any registers are written 166 * @drm_enc: Pointer to previously created drm encoder structure 167 */ 168 void dpu_encoder_prepare_commit(struct drm_encoder *drm_enc); 169 170 /** 171 * dpu_encoder_set_idle_timeout - set the idle timeout for video 172 * and command mode encoders. 173 * @drm_enc: Pointer to previously created drm encoder structure 174 * @idle_timeout: idle timeout duration in milliseconds 175 */ 176 void dpu_encoder_set_idle_timeout(struct drm_encoder *drm_enc, 177 u32 idle_timeout); 178 179 #endif /* __DPU_ENCODER_H__ */ 180