Dhaval Patel | 14d46ce | 2017-01-17 16:28:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved. |
| 3 | * Copyright (C) 2013 Red Hat |
| 4 | * Author: Rob Clark <robdclark@gmail.com> |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 5 | * |
Dhaval Patel | 14d46ce | 2017-01-17 16:28:12 -0800 | [diff] [blame] | 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. |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 9 | * |
Dhaval Patel | 14d46ce | 2017-01-17 16:28:12 -0800 | [diff] [blame] | 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/>. |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 19 | #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__ |
Lloyd Atkinson | a878138 | 2017-07-17 10:20:43 -0400 | [diff] [blame] | 20 | #include <linux/kthread.h> |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 21 | #include <linux/debugfs.h> |
| 22 | #include <linux/seq_file.h> |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 23 | #include <linux/sde_rsc.h> |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 24 | |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 25 | #include "msm_drv.h" |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 26 | #include "sde_kms.h" |
| 27 | #include "drm_crtc.h" |
| 28 | #include "drm_crtc_helper.h" |
| 29 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 30 | #include "sde_hwio.h" |
| 31 | #include "sde_hw_catalog.h" |
| 32 | #include "sde_hw_intf.h" |
Clarence Ip | c475b08 | 2016-06-26 09:27:23 -0400 | [diff] [blame] | 33 | #include "sde_hw_ctl.h" |
| 34 | #include "sde_formats.h" |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 35 | #include "sde_encoder_phys.h" |
Dhaval Patel | 020f7e12 | 2016-11-15 14:39:18 -0800 | [diff] [blame] | 36 | #include "sde_power_handle.h" |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 37 | #include "sde_hw_dsc.h" |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 38 | #include "sde_crtc.h" |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 39 | #include "sde_trace.h" |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 40 | #include "sde_core_irq.h" |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 41 | |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 42 | #define SDE_DEBUG_ENC(e, fmt, ...) SDE_DEBUG("enc%d " fmt,\ |
| 43 | (e) ? (e)->base.base.id : -1, ##__VA_ARGS__) |
| 44 | |
| 45 | #define SDE_ERROR_ENC(e, fmt, ...) SDE_ERROR("enc%d " fmt,\ |
| 46 | (e) ? (e)->base.base.id : -1, ##__VA_ARGS__) |
| 47 | |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 48 | #define SDE_DEBUG_PHYS(p, fmt, ...) SDE_DEBUG("enc%d intf%d pp%d " fmt,\ |
| 49 | (p) ? (p)->parent->base.id : -1, \ |
| 50 | (p) ? (p)->intf_idx - INTF_0 : -1, \ |
| 51 | (p) ? ((p)->hw_pp ? (p)->hw_pp->idx - PINGPONG_0 : -1) : -1, \ |
| 52 | ##__VA_ARGS__) |
| 53 | |
| 54 | #define SDE_ERROR_PHYS(p, fmt, ...) SDE_ERROR("enc%d intf%d pp%d " fmt,\ |
| 55 | (p) ? (p)->parent->base.id : -1, \ |
| 56 | (p) ? (p)->intf_idx - INTF_0 : -1, \ |
| 57 | (p) ? ((p)->hw_pp ? (p)->hw_pp->idx - PINGPONG_0 : -1) : -1, \ |
| 58 | ##__VA_ARGS__) |
| 59 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 60 | /* |
| 61 | * Two to anticipate panels that can do cmd/vid dynamic switching |
| 62 | * plan is to create all possible physical encoder types, and switch between |
| 63 | * them at runtime |
| 64 | */ |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 65 | #define NUM_PHYS_ENCODER_TYPES 2 |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 66 | |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 67 | #define MAX_PHYS_ENCODERS_PER_VIRTUAL \ |
| 68 | (MAX_H_TILES_PER_DISPLAY * NUM_PHYS_ENCODER_TYPES) |
| 69 | |
Jeykumar Sankaran | fdd77a9 | 2016-11-02 12:34:29 -0700 | [diff] [blame] | 70 | #define MAX_CHANNELS_PER_ENC 2 |
| 71 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 72 | #define MISR_BUFF_SIZE 256 |
| 73 | |
Clarence Ip | 8962813 | 2017-07-27 13:33:51 -0400 | [diff] [blame] | 74 | #define IDLE_SHORT_TIMEOUT 1 |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 75 | |
Raviteja Tamatam | 3eebe96 | 2017-10-26 09:55:24 +0530 | [diff] [blame] | 76 | #define FAULT_TOLERENCE_DELTA_IN_MS 2 |
| 77 | |
| 78 | #define FAULT_TOLERENCE_WAIT_IN_MS 5 |
| 79 | |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 80 | /* Maximum number of VSYNC wait attempts for RSC state transition */ |
| 81 | #define MAX_RSC_WAIT 5 |
| 82 | |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 83 | /** |
| 84 | * enum sde_enc_rc_events - events for resource control state machine |
| 85 | * @SDE_ENC_RC_EVENT_KICKOFF: |
| 86 | * This event happens at NORMAL priority. |
| 87 | * Event that signals the start of the transfer. When this event is |
| 88 | * received, enable MDP/DSI core clocks and request RSC with CMD state. |
| 89 | * Regardless of the previous state, the resource should be in ON state |
| 90 | * at the end of this event. |
| 91 | * @SDE_ENC_RC_EVENT_FRAME_DONE: |
| 92 | * This event happens at INTERRUPT level. |
| 93 | * Event signals the end of the data transfer after the PP FRAME_DONE |
| 94 | * event. At the end of this event, a delayed work is scheduled to go to |
| 95 | * IDLE_PC state after IDLE_TIMEOUT time. |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 96 | * @SDE_ENC_RC_EVENT_PRE_STOP: |
| 97 | * This event happens at NORMAL priority. |
| 98 | * This event, when received during the ON state, set RSC to IDLE, and |
| 99 | * and leave the RC STATE in the PRE_OFF state. |
| 100 | * It should be followed by the STOP event as part of encoder disable. |
| 101 | * If received during IDLE or OFF states, it will do nothing. |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 102 | * @SDE_ENC_RC_EVENT_STOP: |
| 103 | * This event happens at NORMAL priority. |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 104 | * When this event is received, disable all the MDP/DSI core clocks, and |
| 105 | * disable IRQs. It should be called from the PRE_OFF or IDLE states. |
| 106 | * IDLE is expected when IDLE_PC has run, and PRE_OFF did nothing. |
| 107 | * PRE_OFF is expected when PRE_STOP was executed during the ON state. |
| 108 | * Resource state should be in OFF at the end of the event. |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 109 | * @SDE_ENC_RC_EVENT_PRE_MODESET: |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 110 | * This event happens at NORMAL priority from a work item. |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 111 | * Event signals that there is a seamless mode switch is in prgoress. A |
| 112 | * client needs to turn of only irq - leave clocks ON to reduce the mode |
| 113 | * switch latency. |
| 114 | * @SDE_ENC_RC_EVENT_POST_MODESET: |
| 115 | * This event happens at NORMAL priority from a work item. |
| 116 | * Event signals that seamless mode switch is complete and resources are |
| 117 | * acquired. Clients wants to turn on the irq again and update the rsc |
| 118 | * with new vtotal. |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 119 | * @SDE_ENC_RC_EVENT_ENTER_IDLE: |
| 120 | * This event happens at NORMAL priority from a work item. |
| 121 | * Event signals that there were no frame updates for IDLE_TIMEOUT time. |
| 122 | * This would disable MDP/DSI core clocks and request RSC with IDLE state |
| 123 | * and change the resource state to IDLE. |
| 124 | */ |
| 125 | enum sde_enc_rc_events { |
| 126 | SDE_ENC_RC_EVENT_KICKOFF = 1, |
| 127 | SDE_ENC_RC_EVENT_FRAME_DONE, |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 128 | SDE_ENC_RC_EVENT_PRE_STOP, |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 129 | SDE_ENC_RC_EVENT_STOP, |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 130 | SDE_ENC_RC_EVENT_PRE_MODESET, |
| 131 | SDE_ENC_RC_EVENT_POST_MODESET, |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 132 | SDE_ENC_RC_EVENT_ENTER_IDLE |
| 133 | }; |
| 134 | |
| 135 | /* |
| 136 | * enum sde_enc_rc_states - states that the resource control maintains |
| 137 | * @SDE_ENC_RC_STATE_OFF: Resource is in OFF state |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 138 | * @SDE_ENC_RC_STATE_PRE_OFF: Resource is transitioning to OFF state |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 139 | * @SDE_ENC_RC_STATE_ON: Resource is in ON state |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 140 | * @SDE_ENC_RC_STATE_MODESET: Resource is in modeset state |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 141 | * @SDE_ENC_RC_STATE_IDLE: Resource is in IDLE state |
| 142 | */ |
| 143 | enum sde_enc_rc_states { |
| 144 | SDE_ENC_RC_STATE_OFF, |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 145 | SDE_ENC_RC_STATE_PRE_OFF, |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 146 | SDE_ENC_RC_STATE_ON, |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 147 | SDE_ENC_RC_STATE_MODESET, |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 148 | SDE_ENC_RC_STATE_IDLE |
| 149 | }; |
| 150 | |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 151 | /** |
| 152 | * struct sde_encoder_virt - virtual encoder. Container of one or more physical |
| 153 | * encoders. Virtual encoder manages one "logical" display. Physical |
| 154 | * encoders manage one intf block, tied to a specific panel/sub-panel. |
| 155 | * Virtual encoder defers as much as possible to the physical encoders. |
| 156 | * Virtual encoder registers itself with the DRM Framework as the encoder. |
| 157 | * @base: drm_encoder base class for registration with DRM |
Lloyd Atkinson | 7d07094 | 2016-07-26 18:35:12 -0400 | [diff] [blame] | 158 | * @enc_spin_lock: Virtual-Encoder-Wide Spin Lock for IRQ purposes |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 159 | * @bus_scaling_client: Client handle to the bus scaling interface |
| 160 | * @num_phys_encs: Actual number of physical encoders contained. |
| 161 | * @phys_encs: Container of physical encoders managed. |
| 162 | * @cur_master: Pointer to the current master in this mode. Optimization |
| 163 | * Only valid after enable. Cleared as disable. |
Jeykumar Sankaran | fdd77a9 | 2016-11-02 12:34:29 -0700 | [diff] [blame] | 164 | * @hw_pp Handle to the pingpong blocks used for the display. No. |
Lloyd Atkinson | 66e7dde | 2017-02-08 15:52:53 -0500 | [diff] [blame] | 165 | * pingpong blocks can be different than num_phys_encs. |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 166 | * @hw_dsc: Array of DSC block handles used for the display. |
Lloyd Atkinson | 66e7dde | 2017-02-08 15:52:53 -0500 | [diff] [blame] | 167 | * @intfs_swapped Whether or not the phys_enc interfaces have been swapped |
| 168 | * for partial update right-only cases, such as pingpong |
| 169 | * split where virtual pingpong does not generate IRQs |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 170 | * @crtc_vblank_cb: Callback into the upper layer / CRTC for |
| 171 | * notification of the VBLANK |
| 172 | * @crtc_vblank_cb_data: Data from upper layer for VBLANK notification |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 173 | * @crtc_kickoff_cb: Callback into CRTC that will flush & start |
| 174 | * all CTL paths |
| 175 | * @crtc_kickoff_cb_data: Opaque user data given to crtc_kickoff_cb |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 176 | * @debugfs_root: Debug file system root file node |
| 177 | * @enc_lock: Lock around physical encoder create/destroy and |
| 178 | access. |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 179 | * @frame_busy_mask: Bitmask tracking which phys_enc we are still |
| 180 | * busy processing current command. |
| 181 | * Bit0 = phys_encs[0] etc. |
| 182 | * @crtc_frame_event_cb: callback handler for frame event |
| 183 | * @crtc_frame_event_cb_data: callback handler private data |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 184 | * @frame_done_timeout: frame done timeout in Hz |
| 185 | * @frame_done_timer: watchdog timer for frame done event |
Benjamin Chan | 9cd866d | 2017-08-15 14:56:34 -0400 | [diff] [blame] | 186 | * @vsync_event_timer: vsync timer |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 187 | * @rsc_client: rsc client pointer |
| 188 | * @rsc_state_init: boolean to indicate rsc config init |
| 189 | * @disp_info: local copy of msm_display_info struct |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 190 | * @misr_enable: misr enable/disable status |
Dhaval Patel | 010f517 | 2017-08-01 22:40:09 -0700 | [diff] [blame] | 191 | * @misr_frame_count: misr frame count before start capturing the data |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 192 | * @idle_pc_supported: indicate if idle power collaps is supported |
| 193 | * @rc_lock: resource control mutex lock to protect |
| 194 | * virt encoder over various state changes |
| 195 | * @rc_state: resource controller state |
| 196 | * @delayed_off_work: delayed worker to schedule disabling of |
| 197 | * clks and resources after IDLE_TIMEOUT time. |
Benjamin Chan | 9cd866d | 2017-08-15 14:56:34 -0400 | [diff] [blame] | 198 | * @vsync_event_work: worker to handle vsync event for autorefresh |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 199 | * @topology: topology of the display |
Veera Sundaram Sankaran | df79cc9 | 2017-10-10 22:32:46 -0700 | [diff] [blame] | 200 | * @vblank_enabled: boolean to track userspace vblank vote |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 201 | * @rsc_config: rsc configuration for display vtotal, fps, etc. |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 202 | * @cur_conn_roi: current connector roi |
| 203 | * @prv_conn_roi: previous connector roi to optimize if unchanged |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 204 | * @idle_timeout: idle timeout duration in milliseconds |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 205 | */ |
| 206 | struct sde_encoder_virt { |
| 207 | struct drm_encoder base; |
Lloyd Atkinson | 7d07094 | 2016-07-26 18:35:12 -0400 | [diff] [blame] | 208 | spinlock_t enc_spinlock; |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 209 | uint32_t bus_scaling_client; |
| 210 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 211 | uint32_t display_num_of_h_tiles; |
| 212 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 213 | unsigned int num_phys_encs; |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 214 | struct sde_encoder_phys *phys_encs[MAX_PHYS_ENCODERS_PER_VIRTUAL]; |
| 215 | struct sde_encoder_phys *cur_master; |
Jeykumar Sankaran | fdd77a9 | 2016-11-02 12:34:29 -0700 | [diff] [blame] | 216 | struct sde_hw_pingpong *hw_pp[MAX_CHANNELS_PER_ENC]; |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 217 | struct sde_hw_dsc *hw_dsc[MAX_CHANNELS_PER_ENC]; |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 218 | |
Lloyd Atkinson | 66e7dde | 2017-02-08 15:52:53 -0500 | [diff] [blame] | 219 | bool intfs_swapped; |
| 220 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 221 | void (*crtc_vblank_cb)(void *); |
| 222 | void *crtc_vblank_cb_data; |
| 223 | |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 224 | struct dentry *debugfs_root; |
| 225 | struct mutex enc_lock; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 226 | DECLARE_BITMAP(frame_busy_mask, MAX_PHYS_ENCODERS_PER_VIRTUAL); |
| 227 | void (*crtc_frame_event_cb)(void *, u32 event); |
| 228 | void *crtc_frame_event_cb_data; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 229 | |
| 230 | atomic_t frame_done_timeout; |
| 231 | struct timer_list frame_done_timer; |
Benjamin Chan | 9cd866d | 2017-08-15 14:56:34 -0400 | [diff] [blame] | 232 | struct timer_list vsync_event_timer; |
Dhaval Patel | 020f7e12 | 2016-11-15 14:39:18 -0800 | [diff] [blame] | 233 | |
| 234 | struct sde_rsc_client *rsc_client; |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 235 | bool rsc_state_init; |
Dhaval Patel | 020f7e12 | 2016-11-15 14:39:18 -0800 | [diff] [blame] | 236 | struct msm_display_info disp_info; |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 237 | bool misr_enable; |
Dhaval Patel | 010f517 | 2017-08-01 22:40:09 -0700 | [diff] [blame] | 238 | u32 misr_frame_count; |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 239 | |
| 240 | bool idle_pc_supported; |
| 241 | struct mutex rc_lock; |
| 242 | enum sde_enc_rc_states rc_state; |
Lloyd Atkinson | a878138 | 2017-07-17 10:20:43 -0400 | [diff] [blame] | 243 | struct kthread_delayed_work delayed_off_work; |
Benjamin Chan | 9cd866d | 2017-08-15 14:56:34 -0400 | [diff] [blame] | 244 | struct kthread_work vsync_event_work; |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 245 | struct msm_display_topology topology; |
Veera Sundaram Sankaran | df79cc9 | 2017-10-10 22:32:46 -0700 | [diff] [blame] | 246 | bool vblank_enabled; |
Alan Kwong | 56f1a94 | 2017-04-04 11:53:42 -0700 | [diff] [blame] | 247 | |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 248 | struct sde_rsc_cmd_config rsc_config; |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 249 | struct sde_rect cur_conn_roi; |
| 250 | struct sde_rect prv_conn_roi; |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 251 | |
| 252 | u32 idle_timeout; |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 253 | }; |
| 254 | |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 255 | #define to_sde_encoder_virt(x) container_of(x, struct sde_encoder_virt, base) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 256 | |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 257 | static struct drm_connector_state *_sde_encoder_get_conn_state( |
| 258 | struct drm_encoder *drm_enc) |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 259 | { |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 260 | struct msm_drm_private *priv; |
| 261 | struct sde_kms *sde_kms; |
| 262 | struct list_head *connector_list; |
| 263 | struct drm_connector *conn_iter; |
| 264 | |
| 265 | if (!drm_enc) { |
| 266 | SDE_ERROR("invalid argument\n"); |
| 267 | return NULL; |
| 268 | } |
| 269 | |
| 270 | priv = drm_enc->dev->dev_private; |
| 271 | sde_kms = to_sde_kms(priv->kms); |
| 272 | connector_list = &sde_kms->dev->mode_config.connector_list; |
| 273 | |
| 274 | list_for_each_entry(conn_iter, connector_list, head) |
| 275 | if (conn_iter->encoder == drm_enc) |
| 276 | return conn_iter->state; |
| 277 | |
| 278 | return NULL; |
| 279 | } |
| 280 | |
| 281 | static int _sde_encoder_get_mode_info(struct drm_encoder *drm_enc, |
| 282 | struct msm_mode_info *mode_info) |
| 283 | { |
| 284 | struct drm_connector_state *conn_state; |
| 285 | |
| 286 | if (!drm_enc || !mode_info) { |
| 287 | SDE_ERROR("invalid arguments\n"); |
| 288 | return -EINVAL; |
| 289 | } |
| 290 | |
| 291 | conn_state = _sde_encoder_get_conn_state(drm_enc); |
| 292 | if (!conn_state) { |
| 293 | SDE_ERROR("invalid connector state for the encoder: %d\n", |
| 294 | drm_enc->base.id); |
| 295 | return -EINVAL; |
| 296 | } |
| 297 | |
| 298 | return sde_connector_get_mode_info(conn_state, mode_info); |
| 299 | } |
| 300 | |
| 301 | static bool _sde_encoder_is_dsc_enabled(struct drm_encoder *drm_enc) |
| 302 | { |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 303 | struct msm_compression_info *comp_info; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 304 | struct msm_mode_info mode_info; |
| 305 | int rc = 0; |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 306 | |
| 307 | if (!drm_enc) |
| 308 | return false; |
| 309 | |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 310 | rc = _sde_encoder_get_mode_info(drm_enc, &mode_info); |
| 311 | if (rc) { |
| 312 | SDE_ERROR("failed to get mode info, enc: %d\n", |
| 313 | drm_enc->base.id); |
| 314 | return false; |
| 315 | } |
| 316 | |
| 317 | comp_info = &mode_info.comp_info; |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 318 | |
| 319 | return (comp_info->comp_type == MSM_DISPLAY_COMPRESSION_DSC); |
| 320 | } |
| 321 | |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 322 | void sde_encoder_set_idle_timeout(struct drm_encoder *drm_enc, u32 idle_timeout) |
| 323 | { |
| 324 | struct sde_encoder_virt *sde_enc; |
| 325 | |
| 326 | if (!drm_enc) |
| 327 | return; |
| 328 | |
| 329 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 330 | sde_enc->idle_timeout = idle_timeout; |
| 331 | } |
| 332 | |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 333 | bool sde_encoder_is_dsc_merge(struct drm_encoder *drm_enc) |
| 334 | { |
| 335 | enum sde_rm_topology_name topology; |
| 336 | struct sde_encoder_virt *sde_enc; |
| 337 | struct drm_connector *drm_conn; |
| 338 | |
| 339 | if (!drm_enc) |
| 340 | return false; |
| 341 | |
| 342 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 343 | if (!sde_enc->cur_master) |
| 344 | return false; |
| 345 | |
| 346 | drm_conn = sde_enc->cur_master->connector; |
| 347 | if (!drm_conn) |
| 348 | return false; |
| 349 | |
| 350 | topology = sde_connector_get_topology_name(drm_conn); |
| 351 | if (topology == SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE) |
| 352 | return true; |
| 353 | |
| 354 | return false; |
| 355 | } |
| 356 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 357 | static inline int _sde_encoder_power_enable(struct sde_encoder_virt *sde_enc, |
| 358 | bool enable) |
| 359 | { |
| 360 | struct drm_encoder *drm_enc; |
| 361 | struct msm_drm_private *priv; |
| 362 | struct sde_kms *sde_kms; |
| 363 | |
| 364 | if (!sde_enc) { |
| 365 | SDE_ERROR("invalid sde enc\n"); |
| 366 | return -EINVAL; |
| 367 | } |
| 368 | |
| 369 | drm_enc = &sde_enc->base; |
| 370 | if (!drm_enc->dev || !drm_enc->dev->dev_private) { |
| 371 | SDE_ERROR("drm device invalid\n"); |
| 372 | return -EINVAL; |
| 373 | } |
| 374 | |
| 375 | priv = drm_enc->dev->dev_private; |
| 376 | if (!priv->kms) { |
| 377 | SDE_ERROR("invalid kms\n"); |
| 378 | return -EINVAL; |
| 379 | } |
| 380 | |
| 381 | sde_kms = to_sde_kms(priv->kms); |
| 382 | |
| 383 | return sde_power_resource_enable(&priv->phandle, sde_kms->core_client, |
| 384 | enable); |
| 385 | } |
| 386 | |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 387 | void sde_encoder_helper_report_irq_timeout(struct sde_encoder_phys *phys_enc, |
| 388 | enum sde_intr_idx intr_idx) |
| 389 | { |
| 390 | SDE_EVT32(DRMID(phys_enc->parent), |
| 391 | phys_enc->intf_idx - INTF_0, |
| 392 | phys_enc->hw_pp->idx - PINGPONG_0, |
| 393 | intr_idx); |
| 394 | SDE_ERROR_PHYS(phys_enc, "irq %d timeout\n", intr_idx); |
| 395 | |
| 396 | if (phys_enc->parent_ops.handle_frame_done) |
| 397 | phys_enc->parent_ops.handle_frame_done( |
| 398 | phys_enc->parent, phys_enc, |
| 399 | SDE_ENCODER_FRAME_EVENT_ERROR); |
| 400 | } |
| 401 | |
| 402 | int sde_encoder_helper_wait_for_irq(struct sde_encoder_phys *phys_enc, |
| 403 | enum sde_intr_idx intr_idx, |
| 404 | struct sde_encoder_wait_info *wait_info) |
| 405 | { |
| 406 | struct sde_encoder_irq *irq; |
| 407 | u32 irq_status; |
| 408 | int ret; |
| 409 | |
| 410 | if (!phys_enc || !wait_info || intr_idx >= INTR_IDX_MAX) { |
| 411 | SDE_ERROR("invalid params\n"); |
| 412 | return -EINVAL; |
| 413 | } |
| 414 | irq = &phys_enc->irq[intr_idx]; |
| 415 | |
| 416 | /* note: do master / slave checking outside */ |
| 417 | |
| 418 | /* return EWOULDBLOCK since we know the wait isn't necessary */ |
| 419 | if (phys_enc->enable_state == SDE_ENC_DISABLED) { |
| 420 | SDE_ERROR_PHYS(phys_enc, "encoder is disabled\n"); |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 421 | SDE_EVT32(DRMID(phys_enc->parent), intr_idx, irq->hw_idx, |
| 422 | irq->irq_idx, intr_idx, SDE_EVTLOG_ERROR); |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 423 | return -EWOULDBLOCK; |
| 424 | } |
| 425 | |
| 426 | if (irq->irq_idx < 0) { |
| 427 | SDE_DEBUG_PHYS(phys_enc, "irq %s hw %d disabled, skip wait\n", |
| 428 | irq->name, irq->hw_idx); |
| 429 | SDE_EVT32(DRMID(phys_enc->parent), intr_idx, irq->hw_idx, |
| 430 | irq->irq_idx); |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | SDE_DEBUG_PHYS(phys_enc, "pending_cnt %d\n", |
| 435 | atomic_read(wait_info->atomic_cnt)); |
Dhaval Patel | a5f7595 | 2017-07-25 11:17:41 -0700 | [diff] [blame] | 436 | SDE_EVT32_VERBOSE(DRMID(phys_enc->parent), intr_idx, irq->hw_idx, |
| 437 | irq->irq_idx, phys_enc->hw_pp->idx - PINGPONG_0, |
| 438 | atomic_read(wait_info->atomic_cnt), SDE_EVTLOG_FUNC_ENTRY); |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 439 | |
| 440 | ret = sde_encoder_helper_wait_event_timeout( |
| 441 | DRMID(phys_enc->parent), |
| 442 | irq->hw_idx, |
| 443 | wait_info); |
| 444 | |
| 445 | if (ret <= 0) { |
| 446 | irq_status = sde_core_irq_read(phys_enc->sde_kms, |
| 447 | irq->irq_idx, true); |
| 448 | if (irq_status) { |
| 449 | unsigned long flags; |
| 450 | |
Dhaval Patel | a5f7595 | 2017-07-25 11:17:41 -0700 | [diff] [blame] | 451 | SDE_EVT32(DRMID(phys_enc->parent), intr_idx, |
| 452 | irq->hw_idx, irq->irq_idx, |
| 453 | phys_enc->hw_pp->idx - PINGPONG_0, |
| 454 | atomic_read(wait_info->atomic_cnt)); |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 455 | SDE_DEBUG_PHYS(phys_enc, |
| 456 | "done but irq %d not triggered\n", |
| 457 | irq->irq_idx); |
| 458 | local_irq_save(flags); |
| 459 | irq->cb.func(phys_enc, irq->irq_idx); |
| 460 | local_irq_restore(flags); |
| 461 | ret = 0; |
| 462 | } else { |
| 463 | ret = -ETIMEDOUT; |
Dhaval Patel | a5f7595 | 2017-07-25 11:17:41 -0700 | [diff] [blame] | 464 | SDE_EVT32(DRMID(phys_enc->parent), intr_idx, |
| 465 | irq->hw_idx, irq->irq_idx, |
| 466 | phys_enc->hw_pp->idx - PINGPONG_0, |
| 467 | atomic_read(wait_info->atomic_cnt), irq_status, |
| 468 | SDE_EVTLOG_ERROR); |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 469 | } |
| 470 | } else { |
| 471 | ret = 0; |
Dhaval Patel | a5f7595 | 2017-07-25 11:17:41 -0700 | [diff] [blame] | 472 | SDE_EVT32(DRMID(phys_enc->parent), intr_idx, irq->hw_idx, |
| 473 | irq->irq_idx, phys_enc->hw_pp->idx - PINGPONG_0, |
| 474 | atomic_read(wait_info->atomic_cnt)); |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 475 | } |
| 476 | |
Dhaval Patel | a5f7595 | 2017-07-25 11:17:41 -0700 | [diff] [blame] | 477 | SDE_EVT32_VERBOSE(DRMID(phys_enc->parent), intr_idx, irq->hw_idx, |
| 478 | irq->irq_idx, ret, phys_enc->hw_pp->idx - PINGPONG_0, |
| 479 | atomic_read(wait_info->atomic_cnt), SDE_EVTLOG_FUNC_EXIT); |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 480 | |
| 481 | return ret; |
| 482 | } |
| 483 | |
| 484 | int sde_encoder_helper_register_irq(struct sde_encoder_phys *phys_enc, |
| 485 | enum sde_intr_idx intr_idx) |
| 486 | { |
| 487 | struct sde_encoder_irq *irq; |
| 488 | int ret = 0; |
| 489 | |
| 490 | if (!phys_enc || intr_idx >= INTR_IDX_MAX) { |
| 491 | SDE_ERROR("invalid params\n"); |
| 492 | return -EINVAL; |
| 493 | } |
| 494 | irq = &phys_enc->irq[intr_idx]; |
| 495 | |
| 496 | if (irq->irq_idx >= 0) { |
Raviteja Tamatam | 68892de | 2017-06-20 04:47:19 +0530 | [diff] [blame] | 497 | SDE_DEBUG_PHYS(phys_enc, |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 498 | "skipping already registered irq %s type %d\n", |
| 499 | irq->name, irq->intr_type); |
| 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | irq->irq_idx = sde_core_irq_idx_lookup(phys_enc->sde_kms, |
| 504 | irq->intr_type, irq->hw_idx); |
| 505 | if (irq->irq_idx < 0) { |
| 506 | SDE_ERROR_PHYS(phys_enc, |
| 507 | "failed to lookup IRQ index for %s type:%d\n", |
| 508 | irq->name, irq->intr_type); |
| 509 | return -EINVAL; |
| 510 | } |
| 511 | |
| 512 | ret = sde_core_irq_register_callback(phys_enc->sde_kms, irq->irq_idx, |
| 513 | &irq->cb); |
| 514 | if (ret) { |
| 515 | SDE_ERROR_PHYS(phys_enc, |
| 516 | "failed to register IRQ callback for %s\n", |
| 517 | irq->name); |
| 518 | irq->irq_idx = -EINVAL; |
| 519 | return ret; |
| 520 | } |
| 521 | |
| 522 | ret = sde_core_irq_enable(phys_enc->sde_kms, &irq->irq_idx, 1); |
| 523 | if (ret) { |
| 524 | SDE_ERROR_PHYS(phys_enc, |
| 525 | "enable IRQ for intr:%s failed, irq_idx %d\n", |
| 526 | irq->name, irq->irq_idx); |
| 527 | |
| 528 | sde_core_irq_unregister_callback(phys_enc->sde_kms, |
| 529 | irq->irq_idx, &irq->cb); |
Lloyd Atkinson | de4270ab | 2017-06-27 16:43:53 -0400 | [diff] [blame] | 530 | |
| 531 | SDE_EVT32(DRMID(phys_enc->parent), intr_idx, irq->hw_idx, |
| 532 | irq->irq_idx, SDE_EVTLOG_ERROR); |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 533 | irq->irq_idx = -EINVAL; |
| 534 | return ret; |
| 535 | } |
| 536 | |
| 537 | SDE_EVT32(DRMID(phys_enc->parent), intr_idx, irq->hw_idx, irq->irq_idx); |
| 538 | SDE_DEBUG_PHYS(phys_enc, "registered irq %s idx: %d\n", |
| 539 | irq->name, irq->irq_idx); |
| 540 | |
| 541 | return ret; |
| 542 | } |
| 543 | |
| 544 | int sde_encoder_helper_unregister_irq(struct sde_encoder_phys *phys_enc, |
| 545 | enum sde_intr_idx intr_idx) |
| 546 | { |
| 547 | struct sde_encoder_irq *irq; |
Lloyd Atkinson | de4270ab | 2017-06-27 16:43:53 -0400 | [diff] [blame] | 548 | int ret; |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 549 | |
| 550 | if (!phys_enc) { |
| 551 | SDE_ERROR("invalid encoder\n"); |
| 552 | return -EINVAL; |
| 553 | } |
| 554 | irq = &phys_enc->irq[intr_idx]; |
| 555 | |
| 556 | /* silently skip irqs that weren't registered */ |
Lloyd Atkinson | de4270ab | 2017-06-27 16:43:53 -0400 | [diff] [blame] | 557 | if (irq->irq_idx < 0) { |
| 558 | SDE_ERROR( |
| 559 | "extra unregister irq, enc%d intr_idx:0x%x hw_idx:0x%x irq_idx:0x%x\n", |
| 560 | DRMID(phys_enc->parent), intr_idx, irq->hw_idx, |
| 561 | irq->irq_idx); |
| 562 | SDE_EVT32(DRMID(phys_enc->parent), intr_idx, irq->hw_idx, |
| 563 | irq->irq_idx, SDE_EVTLOG_ERROR); |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 564 | return 0; |
Lloyd Atkinson | de4270ab | 2017-06-27 16:43:53 -0400 | [diff] [blame] | 565 | } |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 566 | |
Lloyd Atkinson | de4270ab | 2017-06-27 16:43:53 -0400 | [diff] [blame] | 567 | ret = sde_core_irq_disable(phys_enc->sde_kms, &irq->irq_idx, 1); |
| 568 | if (ret) |
| 569 | SDE_EVT32(DRMID(phys_enc->parent), intr_idx, irq->hw_idx, |
| 570 | irq->irq_idx, ret, SDE_EVTLOG_ERROR); |
| 571 | |
| 572 | ret = sde_core_irq_unregister_callback(phys_enc->sde_kms, irq->irq_idx, |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 573 | &irq->cb); |
Lloyd Atkinson | de4270ab | 2017-06-27 16:43:53 -0400 | [diff] [blame] | 574 | if (ret) |
| 575 | SDE_EVT32(DRMID(phys_enc->parent), intr_idx, irq->hw_idx, |
| 576 | irq->irq_idx, ret, SDE_EVTLOG_ERROR); |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 577 | |
| 578 | SDE_EVT32(DRMID(phys_enc->parent), intr_idx, irq->hw_idx, irq->irq_idx); |
| 579 | SDE_DEBUG_PHYS(phys_enc, "unregistered %d\n", irq->irq_idx); |
| 580 | |
Lloyd Atkinson | de4270ab | 2017-06-27 16:43:53 -0400 | [diff] [blame] | 581 | irq->irq_idx = -EINVAL; |
| 582 | |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 583 | return 0; |
| 584 | } |
| 585 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 586 | void sde_encoder_get_hw_resources(struct drm_encoder *drm_enc, |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 587 | struct sde_encoder_hw_resources *hw_res, |
| 588 | struct drm_connector_state *conn_state) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 589 | { |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 590 | struct sde_encoder_virt *sde_enc = NULL; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 591 | struct msm_mode_info mode_info; |
| 592 | int rc, i = 0; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 593 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 594 | if (!hw_res || !drm_enc || !conn_state) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 595 | SDE_ERROR("invalid argument(s), drm_enc %d, res %d, state %d\n", |
| 596 | drm_enc != 0, hw_res != 0, conn_state != 0); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 597 | return; |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 598 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 599 | |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 600 | sde_enc = to_sde_encoder_virt(drm_enc); |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 601 | SDE_DEBUG_ENC(sde_enc, "\n"); |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 602 | |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 603 | /* Query resources used by phys encs, expected to be without overlap */ |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 604 | memset(hw_res, 0, sizeof(*hw_res)); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 605 | hw_res->display_num_of_h_tiles = sde_enc->display_num_of_h_tiles; |
| 606 | |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 607 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 608 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
| 609 | |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 610 | if (phys && phys->ops.get_hw_resources) |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 611 | phys->ops.get_hw_resources(phys, hw_res, conn_state); |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 612 | } |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 613 | |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 614 | /** |
| 615 | * NOTE: Do not use sde_encoder_get_mode_info here as this function is |
| 616 | * called from atomic_check phase. Use the below API to get mode |
| 617 | * information of the temporary conn_state passed. |
| 618 | */ |
| 619 | rc = sde_connector_get_mode_info(conn_state, &mode_info); |
| 620 | if (rc) { |
| 621 | SDE_ERROR_ENC(sde_enc, "failed to get mode info\n"); |
| 622 | return; |
| 623 | } |
| 624 | |
| 625 | hw_res->topology = mode_info.topology; |
Jeykumar Sankaran | 6f215d4 | 2017-09-12 16:15:23 -0700 | [diff] [blame] | 626 | hw_res->is_primary = sde_enc->disp_info.is_primary; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 627 | } |
| 628 | |
Clarence Ip | 3649f8b | 2016-10-31 09:59:44 -0400 | [diff] [blame] | 629 | void sde_encoder_destroy(struct drm_encoder *drm_enc) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 630 | { |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 631 | struct sde_encoder_virt *sde_enc = NULL; |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 632 | int i = 0; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 633 | |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 634 | if (!drm_enc) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 635 | SDE_ERROR("invalid encoder\n"); |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 636 | return; |
| 637 | } |
| 638 | |
| 639 | sde_enc = to_sde_encoder_virt(drm_enc); |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 640 | SDE_DEBUG_ENC(sde_enc, "\n"); |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 641 | |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 642 | mutex_lock(&sde_enc->enc_lock); |
Dhaval Patel | 020f7e12 | 2016-11-15 14:39:18 -0800 | [diff] [blame] | 643 | sde_rsc_client_destroy(sde_enc->rsc_client); |
| 644 | |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 645 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 646 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
| 647 | |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 648 | if (phys && phys->ops.destroy) { |
| 649 | phys->ops.destroy(phys); |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 650 | --sde_enc->num_phys_encs; |
| 651 | sde_enc->phys_encs[i] = NULL; |
| 652 | } |
| 653 | } |
| 654 | |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 655 | if (sde_enc->num_phys_encs) |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 656 | SDE_ERROR_ENC(sde_enc, "expected 0 num_phys_encs not %d\n", |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 657 | sde_enc->num_phys_encs); |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 658 | sde_enc->num_phys_encs = 0; |
| 659 | mutex_unlock(&sde_enc->enc_lock); |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 660 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 661 | drm_encoder_cleanup(drm_enc); |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 662 | mutex_destroy(&sde_enc->enc_lock); |
| 663 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 664 | kfree(sde_enc); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 667 | void sde_encoder_helper_split_config( |
| 668 | struct sde_encoder_phys *phys_enc, |
| 669 | enum sde_intf interface) |
| 670 | { |
| 671 | struct sde_encoder_virt *sde_enc; |
| 672 | struct split_pipe_cfg cfg = { 0 }; |
| 673 | struct sde_hw_mdp *hw_mdptop; |
| 674 | enum sde_rm_topology_name topology; |
Dhaval Patel | 5cd59a0 | 2017-06-13 16:29:40 -0700 | [diff] [blame] | 675 | struct msm_display_info *disp_info; |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 676 | |
| 677 | if (!phys_enc || !phys_enc->hw_mdptop || !phys_enc->parent) { |
| 678 | SDE_ERROR("invalid arg(s), encoder %d\n", phys_enc != 0); |
| 679 | return; |
| 680 | } |
| 681 | |
| 682 | sde_enc = to_sde_encoder_virt(phys_enc->parent); |
| 683 | hw_mdptop = phys_enc->hw_mdptop; |
Dhaval Patel | 5cd59a0 | 2017-06-13 16:29:40 -0700 | [diff] [blame] | 684 | disp_info = &sde_enc->disp_info; |
| 685 | |
| 686 | if (disp_info->intf_type != DRM_MODE_CONNECTOR_DSI) |
| 687 | return; |
Lloyd Atkinson | 66e7dde | 2017-02-08 15:52:53 -0500 | [diff] [blame] | 688 | |
| 689 | /** |
| 690 | * disable split modes since encoder will be operating in as the only |
| 691 | * encoder, either for the entire use case in the case of, for example, |
| 692 | * single DSI, or for this frame in the case of left/right only partial |
| 693 | * update. |
| 694 | */ |
| 695 | if (phys_enc->split_role == ENC_ROLE_SOLO) { |
| 696 | if (hw_mdptop->ops.setup_split_pipe) |
| 697 | hw_mdptop->ops.setup_split_pipe(hw_mdptop, &cfg); |
| 698 | if (hw_mdptop->ops.setup_pp_split) |
| 699 | hw_mdptop->ops.setup_pp_split(hw_mdptop, &cfg); |
| 700 | return; |
| 701 | } |
| 702 | |
| 703 | cfg.en = true; |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 704 | cfg.mode = phys_enc->intf_mode; |
| 705 | cfg.intf = interface; |
| 706 | |
| 707 | if (cfg.en && phys_enc->ops.needs_single_flush && |
| 708 | phys_enc->ops.needs_single_flush(phys_enc)) |
| 709 | cfg.split_flush_en = true; |
| 710 | |
| 711 | topology = sde_connector_get_topology_name(phys_enc->connector); |
| 712 | if (topology == SDE_RM_TOPOLOGY_PPSPLIT) |
| 713 | cfg.pp_split_slave = cfg.intf; |
| 714 | else |
| 715 | cfg.pp_split_slave = INTF_MAX; |
| 716 | |
Lloyd Atkinson | 66e7dde | 2017-02-08 15:52:53 -0500 | [diff] [blame] | 717 | if (phys_enc->split_role == ENC_ROLE_MASTER) { |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 718 | SDE_DEBUG_ENC(sde_enc, "enable %d\n", cfg.en); |
| 719 | |
| 720 | if (hw_mdptop->ops.setup_split_pipe) |
| 721 | hw_mdptop->ops.setup_split_pipe(hw_mdptop, &cfg); |
Lloyd Atkinson | 6a5359d | 2017-06-21 10:18:08 -0400 | [diff] [blame] | 722 | } else if (sde_enc->hw_pp[0]) { |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 723 | /* |
| 724 | * slave encoder |
| 725 | * - determine split index from master index, |
| 726 | * assume master is first pp |
| 727 | */ |
| 728 | cfg.pp_split_index = sde_enc->hw_pp[0]->idx - PINGPONG_0; |
| 729 | SDE_DEBUG_ENC(sde_enc, "master using pp%d\n", |
| 730 | cfg.pp_split_index); |
| 731 | |
| 732 | if (hw_mdptop->ops.setup_pp_split) |
| 733 | hw_mdptop->ops.setup_pp_split(hw_mdptop, &cfg); |
| 734 | } |
| 735 | } |
| 736 | |
Jeykumar Sankaran | eb49ff3 | 2017-04-12 16:33:25 -0700 | [diff] [blame] | 737 | static void _sde_encoder_adjust_mode(struct drm_connector *connector, |
| 738 | struct drm_display_mode *adj_mode) |
| 739 | { |
| 740 | struct drm_display_mode *cur_mode; |
| 741 | |
| 742 | if (!connector || !adj_mode) |
| 743 | return; |
| 744 | |
| 745 | list_for_each_entry(cur_mode, &connector->modes, head) { |
| 746 | if (cur_mode->vdisplay == adj_mode->vdisplay && |
| 747 | cur_mode->hdisplay == adj_mode->hdisplay && |
| 748 | cur_mode->vrefresh == adj_mode->vrefresh) { |
| 749 | adj_mode->private = cur_mode->private; |
Jeykumar Sankaran | 6993462 | 2017-05-31 18:16:25 -0700 | [diff] [blame] | 750 | adj_mode->private_flags |= cur_mode->private_flags; |
Jeykumar Sankaran | eb49ff3 | 2017-04-12 16:33:25 -0700 | [diff] [blame] | 751 | } |
| 752 | } |
| 753 | } |
| 754 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 755 | static int sde_encoder_virt_atomic_check( |
| 756 | struct drm_encoder *drm_enc, |
| 757 | struct drm_crtc_state *crtc_state, |
| 758 | struct drm_connector_state *conn_state) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 759 | { |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 760 | struct sde_encoder_virt *sde_enc; |
| 761 | struct msm_drm_private *priv; |
| 762 | struct sde_kms *sde_kms; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 763 | const struct drm_display_mode *mode; |
| 764 | struct drm_display_mode *adj_mode; |
Jeykumar Sankaran | 586d092 | 2017-09-18 15:01:33 -0700 | [diff] [blame] | 765 | struct sde_connector *sde_conn = NULL; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 766 | struct sde_connector_state *sde_conn_state = NULL; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 767 | int i = 0; |
| 768 | int ret = 0; |
| 769 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 770 | if (!drm_enc || !crtc_state || !conn_state) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 771 | SDE_ERROR("invalid arg(s), drm_enc %d, crtc/conn state %d/%d\n", |
| 772 | drm_enc != 0, crtc_state != 0, conn_state != 0); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 773 | return -EINVAL; |
| 774 | } |
| 775 | |
| 776 | sde_enc = to_sde_encoder_virt(drm_enc); |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 777 | SDE_DEBUG_ENC(sde_enc, "\n"); |
| 778 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 779 | priv = drm_enc->dev->dev_private; |
| 780 | sde_kms = to_sde_kms(priv->kms); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 781 | mode = &crtc_state->mode; |
| 782 | adj_mode = &crtc_state->adjusted_mode; |
Jeykumar Sankaran | 586d092 | 2017-09-18 15:01:33 -0700 | [diff] [blame] | 783 | sde_conn = to_sde_connector(conn_state->connector); |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 784 | sde_conn_state = to_sde_connector_state(conn_state); |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 785 | SDE_EVT32(DRMID(drm_enc)); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 786 | |
Jeykumar Sankaran | eb49ff3 | 2017-04-12 16:33:25 -0700 | [diff] [blame] | 787 | /* |
| 788 | * display drivers may populate private fields of the drm display mode |
| 789 | * structure while registering possible modes of a connector with DRM. |
| 790 | * These private fields are not populated back while DRM invokes |
| 791 | * the mode_set callbacks. This module retrieves and populates the |
| 792 | * private fields of the given mode. |
| 793 | */ |
| 794 | _sde_encoder_adjust_mode(conn_state->connector, adj_mode); |
| 795 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 796 | /* perform atomic check on the first physical encoder (master) */ |
| 797 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 798 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
| 799 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 800 | if (phys && phys->ops.atomic_check) |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 801 | ret = phys->ops.atomic_check(phys, crtc_state, |
| 802 | conn_state); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 803 | else if (phys && phys->ops.mode_fixup) |
| 804 | if (!phys->ops.mode_fixup(phys, mode, adj_mode)) |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 805 | ret = -EINVAL; |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 806 | |
| 807 | if (ret) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 808 | SDE_ERROR_ENC(sde_enc, |
| 809 | "mode unsupported, phys idx %d\n", i); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 810 | break; |
| 811 | } |
| 812 | } |
| 813 | |
Jeykumar Sankaran | 586d092 | 2017-09-18 15:01:33 -0700 | [diff] [blame] | 814 | |
| 815 | if (!ret && sde_conn && drm_atomic_crtc_needs_modeset(crtc_state)) { |
| 816 | struct msm_display_topology *topology = NULL; |
| 817 | |
| 818 | ret = sde_conn->ops.get_mode_info(adj_mode, |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 819 | &sde_conn_state->mode_info, |
Alan Kwong | b1bca60 | 2017-09-18 17:28:45 -0400 | [diff] [blame] | 820 | sde_kms->catalog->max_mixer_width, |
| 821 | sde_conn->display); |
Jeykumar Sankaran | 586d092 | 2017-09-18 15:01:33 -0700 | [diff] [blame] | 822 | if (ret) { |
| 823 | SDE_ERROR_ENC(sde_enc, |
| 824 | "failed to get mode info, rc = %d\n", ret); |
| 825 | return ret; |
| 826 | } |
| 827 | |
| 828 | /* Reserve dynamic resources, indicating atomic_check phase */ |
| 829 | ret = sde_rm_reserve(&sde_kms->rm, drm_enc, crtc_state, |
| 830 | conn_state, true); |
| 831 | if (ret) { |
| 832 | SDE_ERROR_ENC(sde_enc, |
| 833 | "RM failed to reserve resources, rc = %d\n", |
| 834 | ret); |
| 835 | return ret; |
| 836 | } |
| 837 | |
| 838 | /** |
| 839 | * Update connector state with the topology selected for the |
| 840 | * resource set validated. Reset the topology if we are |
| 841 | * de-activating crtc. |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 842 | */ |
Jeykumar Sankaran | 586d092 | 2017-09-18 15:01:33 -0700 | [diff] [blame] | 843 | if (crtc_state->active) |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 844 | topology = &sde_conn_state->mode_info.topology; |
Jeykumar Sankaran | 586d092 | 2017-09-18 15:01:33 -0700 | [diff] [blame] | 845 | |
| 846 | ret = sde_rm_update_topology(conn_state, topology); |
| 847 | if (ret) { |
| 848 | SDE_ERROR_ENC(sde_enc, |
| 849 | "RM failed to update topology, rc: %d\n", ret); |
| 850 | return ret; |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 851 | } |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 852 | |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 853 | ret = sde_connector_set_info(conn_state->connector, conn_state); |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 854 | if (ret) { |
| 855 | SDE_ERROR_ENC(sde_enc, |
| 856 | "connector failed to update info, rc: %d\n", |
| 857 | ret); |
| 858 | return ret; |
| 859 | } |
| 860 | |
| 861 | } |
| 862 | |
| 863 | ret = sde_connector_roi_v1_check_roi(conn_state); |
| 864 | if (ret) { |
| 865 | SDE_ERROR_ENC(sde_enc, "connector roi check failed, rc: %d", |
| 866 | ret); |
| 867 | return ret; |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 868 | } |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 869 | |
Gopikrishnaiah Anandan | 703eb90 | 2016-10-06 18:43:57 -0700 | [diff] [blame] | 870 | if (!ret) |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 871 | drm_mode_set_crtcinfo(adj_mode, 0); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 872 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 873 | SDE_EVT32(DRMID(drm_enc), adj_mode->flags, adj_mode->private_flags); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 874 | |
| 875 | return ret; |
| 876 | } |
| 877 | |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 878 | static int _sde_encoder_dsc_update_pic_dim(struct msm_display_dsc_info *dsc, |
| 879 | int pic_width, int pic_height) |
| 880 | { |
| 881 | if (!dsc || !pic_width || !pic_height) { |
| 882 | SDE_ERROR("invalid input: pic_width=%d pic_height=%d\n", |
| 883 | pic_width, pic_height); |
| 884 | return -EINVAL; |
| 885 | } |
| 886 | |
| 887 | if ((pic_width % dsc->slice_width) || |
| 888 | (pic_height % dsc->slice_height)) { |
| 889 | SDE_ERROR("pic_dim=%dx%d has to be multiple of slice=%dx%d\n", |
| 890 | pic_width, pic_height, |
| 891 | dsc->slice_width, dsc->slice_height); |
| 892 | return -EINVAL; |
| 893 | } |
| 894 | |
| 895 | dsc->pic_width = pic_width; |
| 896 | dsc->pic_height = pic_height; |
| 897 | |
| 898 | return 0; |
| 899 | } |
| 900 | |
| 901 | static void _sde_encoder_dsc_pclk_param_calc(struct msm_display_dsc_info *dsc, |
| 902 | int intf_width) |
| 903 | { |
| 904 | int slice_per_pkt, slice_per_intf; |
| 905 | int bytes_in_slice, total_bytes_per_intf; |
| 906 | |
| 907 | if (!dsc || !dsc->slice_width || !dsc->slice_per_pkt || |
| 908 | (intf_width < dsc->slice_width)) { |
| 909 | SDE_ERROR("invalid input: intf_width=%d slice_width=%d\n", |
| 910 | intf_width, dsc ? dsc->slice_width : -1); |
| 911 | return; |
| 912 | } |
| 913 | |
| 914 | slice_per_pkt = dsc->slice_per_pkt; |
| 915 | slice_per_intf = DIV_ROUND_UP(intf_width, dsc->slice_width); |
| 916 | |
| 917 | /* |
| 918 | * If slice_per_pkt is greater than slice_per_intf then default to 1. |
| 919 | * This can happen during partial update. |
| 920 | */ |
| 921 | if (slice_per_pkt > slice_per_intf) |
| 922 | slice_per_pkt = 1; |
| 923 | |
| 924 | bytes_in_slice = DIV_ROUND_UP(dsc->slice_width * dsc->bpp, 8); |
| 925 | total_bytes_per_intf = bytes_in_slice * slice_per_intf; |
| 926 | |
| 927 | dsc->eol_byte_num = total_bytes_per_intf % 3; |
| 928 | dsc->pclk_per_line = DIV_ROUND_UP(total_bytes_per_intf, 3); |
| 929 | dsc->bytes_in_slice = bytes_in_slice; |
| 930 | dsc->bytes_per_pkt = bytes_in_slice * slice_per_pkt; |
| 931 | dsc->pkt_per_line = slice_per_intf / slice_per_pkt; |
| 932 | } |
| 933 | |
| 934 | static int _sde_encoder_dsc_initial_line_calc(struct msm_display_dsc_info *dsc, |
| 935 | int enc_ip_width) |
| 936 | { |
| 937 | int ssm_delay, total_pixels, soft_slice_per_enc; |
| 938 | |
| 939 | soft_slice_per_enc = enc_ip_width / dsc->slice_width; |
| 940 | |
| 941 | /* |
| 942 | * minimum number of initial line pixels is a sum of: |
| 943 | * 1. sub-stream multiplexer delay (83 groups for 8bpc, |
| 944 | * 91 for 10 bpc) * 3 |
| 945 | * 2. for two soft slice cases, add extra sub-stream multiplexer * 3 |
| 946 | * 3. the initial xmit delay |
| 947 | * 4. total pipeline delay through the "lock step" of encoder (47) |
| 948 | * 5. 6 additional pixels as the output of the rate buffer is |
| 949 | * 48 bits wide |
| 950 | */ |
| 951 | ssm_delay = ((dsc->bpc < 10) ? 84 : 92); |
| 952 | total_pixels = ssm_delay * 3 + dsc->initial_xmit_delay + 47; |
| 953 | if (soft_slice_per_enc > 1) |
| 954 | total_pixels += (ssm_delay * 3); |
| 955 | dsc->initial_lines = DIV_ROUND_UP(total_pixels, dsc->slice_width); |
| 956 | return 0; |
| 957 | } |
| 958 | |
| 959 | static bool _sde_encoder_dsc_ich_reset_override_needed(bool pu_en, |
| 960 | struct msm_display_dsc_info *dsc) |
| 961 | { |
| 962 | /* |
| 963 | * As per the DSC spec, ICH_RESET can be either end of the slice line |
| 964 | * or at the end of the slice. HW internally generates ich_reset at |
| 965 | * end of the slice line if DSC_MERGE is used or encoder has two |
| 966 | * soft slices. However, if encoder has only 1 soft slice and DSC_MERGE |
| 967 | * is not used then it will generate ich_reset at the end of slice. |
| 968 | * |
| 969 | * Now as per the spec, during one PPS session, position where |
| 970 | * ich_reset is generated should not change. Now if full-screen frame |
| 971 | * has more than 1 soft slice then HW will automatically generate |
| 972 | * ich_reset at the end of slice_line. But for the same panel, if |
| 973 | * partial frame is enabled and only 1 encoder is used with 1 slice, |
| 974 | * then HW will generate ich_reset at end of the slice. This is a |
| 975 | * mismatch. Prevent this by overriding HW's decision. |
| 976 | */ |
| 977 | return pu_en && dsc && (dsc->full_frame_slices > 1) && |
| 978 | (dsc->slice_width == dsc->pic_width); |
| 979 | } |
| 980 | |
| 981 | static void _sde_encoder_dsc_pipe_cfg(struct sde_hw_dsc *hw_dsc, |
| 982 | struct sde_hw_pingpong *hw_pp, struct msm_display_dsc_info *dsc, |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 983 | u32 common_mode, bool ich_reset, bool enable) |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 984 | { |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 985 | if (!enable) { |
| 986 | if (hw_pp->ops.disable_dsc) |
| 987 | hw_pp->ops.disable_dsc(hw_pp); |
| 988 | return; |
| 989 | } |
| 990 | |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 991 | if (hw_dsc->ops.dsc_config) |
| 992 | hw_dsc->ops.dsc_config(hw_dsc, dsc, common_mode, ich_reset); |
| 993 | |
| 994 | if (hw_dsc->ops.dsc_config_thresh) |
| 995 | hw_dsc->ops.dsc_config_thresh(hw_dsc, dsc); |
| 996 | |
| 997 | if (hw_pp->ops.setup_dsc) |
| 998 | hw_pp->ops.setup_dsc(hw_pp); |
| 999 | |
| 1000 | if (hw_pp->ops.enable_dsc) |
| 1001 | hw_pp->ops.enable_dsc(hw_pp); |
| 1002 | } |
| 1003 | |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1004 | static void _sde_encoder_get_connector_roi( |
| 1005 | struct sde_encoder_virt *sde_enc, |
| 1006 | struct sde_rect *merged_conn_roi) |
| 1007 | { |
| 1008 | struct drm_connector *drm_conn; |
| 1009 | struct sde_connector_state *c_state; |
| 1010 | |
| 1011 | if (!sde_enc || !merged_conn_roi) |
| 1012 | return; |
| 1013 | |
| 1014 | drm_conn = sde_enc->phys_encs[0]->connector; |
| 1015 | |
| 1016 | if (!drm_conn || !drm_conn->state) |
| 1017 | return; |
| 1018 | |
| 1019 | c_state = to_sde_connector_state(drm_conn->state); |
| 1020 | sde_kms_rect_merge_rectangles(&c_state->rois, merged_conn_roi); |
| 1021 | } |
| 1022 | |
Ingrid Gallardo | 8353222 | 2017-06-02 16:48:51 -0700 | [diff] [blame] | 1023 | static int _sde_encoder_dsc_n_lm_1_enc_1_intf(struct sde_encoder_virt *sde_enc) |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1024 | { |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1025 | int this_frame_slices; |
| 1026 | int intf_ip_w, enc_ip_w; |
| 1027 | int ich_res, dsc_common_mode = 0; |
| 1028 | |
| 1029 | struct sde_hw_pingpong *hw_pp = sde_enc->hw_pp[0]; |
| 1030 | struct sde_hw_dsc *hw_dsc = sde_enc->hw_dsc[0]; |
| 1031 | struct sde_encoder_phys *enc_master = sde_enc->cur_master; |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1032 | const struct sde_rect *roi = &sde_enc->cur_conn_roi; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1033 | struct msm_mode_info mode_info; |
| 1034 | struct msm_display_dsc_info *dsc = NULL; |
| 1035 | int rc; |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1036 | |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1037 | if (hw_dsc == NULL || hw_pp == NULL || !enc_master) { |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1038 | SDE_ERROR_ENC(sde_enc, "invalid params for DSC\n"); |
| 1039 | return -EINVAL; |
| 1040 | } |
| 1041 | |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1042 | rc = _sde_encoder_get_mode_info(&sde_enc->base, &mode_info); |
| 1043 | if (rc) { |
| 1044 | SDE_ERROR_ENC(sde_enc, "failed to get mode info\n"); |
| 1045 | return -EINVAL; |
| 1046 | } |
| 1047 | |
| 1048 | dsc = &mode_info.comp_info.dsc_info; |
| 1049 | |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1050 | _sde_encoder_dsc_update_pic_dim(dsc, roi->w, roi->h); |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1051 | |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1052 | this_frame_slices = roi->w / dsc->slice_width; |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1053 | intf_ip_w = this_frame_slices * dsc->slice_width; |
| 1054 | _sde_encoder_dsc_pclk_param_calc(dsc, intf_ip_w); |
| 1055 | |
| 1056 | enc_ip_w = intf_ip_w; |
| 1057 | _sde_encoder_dsc_initial_line_calc(dsc, enc_ip_w); |
| 1058 | |
| 1059 | ich_res = _sde_encoder_dsc_ich_reset_override_needed(false, dsc); |
| 1060 | |
| 1061 | if (enc_master->intf_mode == INTF_MODE_VIDEO) |
| 1062 | dsc_common_mode = DSC_MODE_VIDEO; |
| 1063 | |
| 1064 | SDE_DEBUG_ENC(sde_enc, "pic_w: %d pic_h: %d mode:%d\n", |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1065 | roi->w, roi->h, dsc_common_mode); |
| 1066 | SDE_EVT32(DRMID(&sde_enc->base), roi->w, roi->h, dsc_common_mode); |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1067 | |
| 1068 | _sde_encoder_dsc_pipe_cfg(hw_dsc, hw_pp, dsc, dsc_common_mode, |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1069 | ich_res, true); |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1070 | |
| 1071 | return 0; |
| 1072 | } |
Ingrid Gallardo | 8353222 | 2017-06-02 16:48:51 -0700 | [diff] [blame] | 1073 | |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1074 | static int _sde_encoder_dsc_2_lm_2_enc_2_intf(struct sde_encoder_virt *sde_enc, |
| 1075 | struct sde_encoder_kickoff_params *params) |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1076 | { |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1077 | int this_frame_slices; |
| 1078 | int intf_ip_w, enc_ip_w; |
| 1079 | int ich_res, dsc_common_mode; |
| 1080 | |
| 1081 | struct sde_encoder_phys *enc_master = sde_enc->cur_master; |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1082 | const struct sde_rect *roi = &sde_enc->cur_conn_roi; |
| 1083 | struct sde_hw_dsc *hw_dsc[MAX_CHANNELS_PER_ENC]; |
| 1084 | struct sde_hw_pingpong *hw_pp[MAX_CHANNELS_PER_ENC]; |
| 1085 | struct msm_display_dsc_info dsc[MAX_CHANNELS_PER_ENC]; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1086 | struct msm_mode_info mode_info; |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1087 | bool half_panel_partial_update; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1088 | int i, rc; |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1089 | |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1090 | for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) { |
| 1091 | hw_pp[i] = sde_enc->hw_pp[i]; |
| 1092 | hw_dsc[i] = sde_enc->hw_dsc[i]; |
| 1093 | |
| 1094 | if (!hw_pp[i] || !hw_dsc[i]) { |
| 1095 | SDE_ERROR_ENC(sde_enc, "invalid params for DSC\n"); |
| 1096 | return -EINVAL; |
| 1097 | } |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1098 | } |
| 1099 | |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1100 | rc = _sde_encoder_get_mode_info(&sde_enc->base, &mode_info); |
| 1101 | if (rc) { |
| 1102 | SDE_ERROR_ENC(sde_enc, "failed to get mode info\n"); |
| 1103 | return -EINVAL; |
| 1104 | } |
| 1105 | |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1106 | half_panel_partial_update = |
| 1107 | hweight_long(params->affected_displays) == 1; |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1108 | |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1109 | dsc_common_mode = 0; |
| 1110 | if (!half_panel_partial_update) |
| 1111 | dsc_common_mode |= DSC_MODE_SPLIT_PANEL; |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1112 | if (enc_master->intf_mode == INTF_MODE_VIDEO) |
| 1113 | dsc_common_mode |= DSC_MODE_VIDEO; |
| 1114 | |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1115 | memcpy(&dsc[0], &mode_info.comp_info.dsc_info, sizeof(dsc[0])); |
| 1116 | memcpy(&dsc[1], &mode_info.comp_info.dsc_info, sizeof(dsc[1])); |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1117 | |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1118 | /* |
| 1119 | * Since both DSC use same pic dimension, set same pic dimension |
| 1120 | * to both DSC structures. |
| 1121 | */ |
| 1122 | _sde_encoder_dsc_update_pic_dim(&dsc[0], roi->w, roi->h); |
| 1123 | _sde_encoder_dsc_update_pic_dim(&dsc[1], roi->w, roi->h); |
| 1124 | |
| 1125 | this_frame_slices = roi->w / dsc[0].slice_width; |
| 1126 | intf_ip_w = this_frame_slices * dsc[0].slice_width; |
| 1127 | |
| 1128 | if (!half_panel_partial_update) |
| 1129 | intf_ip_w /= 2; |
| 1130 | |
| 1131 | /* |
| 1132 | * In this topology when both interfaces are active, they have same |
| 1133 | * load so intf_ip_w will be same. |
| 1134 | */ |
| 1135 | _sde_encoder_dsc_pclk_param_calc(&dsc[0], intf_ip_w); |
| 1136 | _sde_encoder_dsc_pclk_param_calc(&dsc[1], intf_ip_w); |
| 1137 | |
| 1138 | /* |
| 1139 | * In this topology, since there is no dsc_merge, uncompressed input |
| 1140 | * to encoder and interface is same. |
| 1141 | */ |
| 1142 | enc_ip_w = intf_ip_w; |
| 1143 | _sde_encoder_dsc_initial_line_calc(&dsc[0], enc_ip_w); |
| 1144 | _sde_encoder_dsc_initial_line_calc(&dsc[1], enc_ip_w); |
| 1145 | |
| 1146 | /* |
| 1147 | * __is_ich_reset_override_needed should be called only after |
| 1148 | * updating pic dimension, mdss_panel_dsc_update_pic_dim. |
| 1149 | */ |
| 1150 | ich_res = _sde_encoder_dsc_ich_reset_override_needed( |
| 1151 | half_panel_partial_update, &dsc[0]); |
| 1152 | |
| 1153 | SDE_DEBUG_ENC(sde_enc, "pic_w: %d pic_h: %d mode:%d\n", |
| 1154 | roi->w, roi->h, dsc_common_mode); |
| 1155 | |
| 1156 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 1157 | bool active = !!((1 << i) & params->affected_displays); |
| 1158 | |
| 1159 | SDE_EVT32(DRMID(&sde_enc->base), roi->w, roi->h, |
| 1160 | dsc_common_mode, i, active); |
| 1161 | _sde_encoder_dsc_pipe_cfg(hw_dsc[i], hw_pp[i], &dsc[i], |
| 1162 | dsc_common_mode, ich_res, active); |
| 1163 | } |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1164 | |
| 1165 | return 0; |
| 1166 | } |
| 1167 | |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 1168 | static int _sde_encoder_dsc_2_lm_2_enc_1_intf(struct sde_encoder_virt *sde_enc, |
| 1169 | struct sde_encoder_kickoff_params *params) |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1170 | { |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1171 | int this_frame_slices; |
| 1172 | int intf_ip_w, enc_ip_w; |
| 1173 | int ich_res, dsc_common_mode; |
| 1174 | |
| 1175 | struct sde_encoder_phys *enc_master = sde_enc->cur_master; |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1176 | const struct sde_rect *roi = &sde_enc->cur_conn_roi; |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 1177 | struct sde_hw_dsc *hw_dsc[MAX_CHANNELS_PER_ENC]; |
| 1178 | struct sde_hw_pingpong *hw_pp[MAX_CHANNELS_PER_ENC]; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1179 | struct msm_display_dsc_info *dsc = NULL; |
| 1180 | struct msm_mode_info mode_info; |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 1181 | bool half_panel_partial_update; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1182 | int i, rc; |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1183 | |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 1184 | for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) { |
| 1185 | hw_pp[i] = sde_enc->hw_pp[i]; |
| 1186 | hw_dsc[i] = sde_enc->hw_dsc[i]; |
| 1187 | |
| 1188 | if (!hw_pp[i] || !hw_dsc[i]) { |
| 1189 | SDE_ERROR_ENC(sde_enc, "invalid params for DSC\n"); |
| 1190 | return -EINVAL; |
| 1191 | } |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1192 | } |
| 1193 | |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1194 | rc = _sde_encoder_get_mode_info(&sde_enc->base, &mode_info); |
| 1195 | if (rc) { |
| 1196 | SDE_ERROR_ENC(sde_enc, "failed to get mode info\n"); |
| 1197 | return -EINVAL; |
| 1198 | } |
| 1199 | |
| 1200 | dsc = &mode_info.comp_info.dsc_info; |
| 1201 | |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 1202 | half_panel_partial_update = |
| 1203 | hweight_long(params->affected_displays) == 1; |
| 1204 | |
| 1205 | dsc_common_mode = 0; |
| 1206 | if (!half_panel_partial_update) |
| 1207 | dsc_common_mode |= DSC_MODE_SPLIT_PANEL | DSC_MODE_MULTIPLEX; |
| 1208 | if (enc_master->intf_mode == INTF_MODE_VIDEO) |
| 1209 | dsc_common_mode |= DSC_MODE_VIDEO; |
| 1210 | |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1211 | _sde_encoder_dsc_update_pic_dim(dsc, roi->w, roi->h); |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1212 | |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1213 | this_frame_slices = roi->w / dsc->slice_width; |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1214 | intf_ip_w = this_frame_slices * dsc->slice_width; |
| 1215 | _sde_encoder_dsc_pclk_param_calc(dsc, intf_ip_w); |
| 1216 | |
| 1217 | /* |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 1218 | * dsc merge case: when using 2 encoders for the same stream, |
| 1219 | * no. of slices need to be same on both the encoders. |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1220 | */ |
| 1221 | enc_ip_w = intf_ip_w / 2; |
| 1222 | _sde_encoder_dsc_initial_line_calc(dsc, enc_ip_w); |
| 1223 | |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 1224 | ich_res = _sde_encoder_dsc_ich_reset_override_needed( |
| 1225 | half_panel_partial_update, dsc); |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1226 | |
| 1227 | SDE_DEBUG_ENC(sde_enc, "pic_w: %d pic_h: %d mode:%d\n", |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1228 | roi->w, roi->h, dsc_common_mode); |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 1229 | SDE_EVT32(DRMID(&sde_enc->base), roi->w, roi->h, |
| 1230 | dsc_common_mode, i, params->affected_displays); |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1231 | |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 1232 | _sde_encoder_dsc_pipe_cfg(hw_dsc[0], hw_pp[0], dsc, dsc_common_mode, |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1233 | ich_res, true); |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 1234 | _sde_encoder_dsc_pipe_cfg(hw_dsc[1], hw_pp[1], dsc, dsc_common_mode, |
| 1235 | ich_res, !half_panel_partial_update); |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1236 | |
| 1237 | return 0; |
| 1238 | } |
| 1239 | |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1240 | static int _sde_encoder_update_roi(struct drm_encoder *drm_enc) |
| 1241 | { |
| 1242 | struct sde_encoder_virt *sde_enc; |
| 1243 | struct drm_connector *drm_conn; |
| 1244 | struct drm_display_mode *adj_mode; |
| 1245 | struct sde_rect roi; |
| 1246 | |
| 1247 | if (!drm_enc || !drm_enc->crtc || !drm_enc->crtc->state) |
| 1248 | return -EINVAL; |
| 1249 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 1250 | |
| 1251 | if (!sde_enc->cur_master) |
| 1252 | return -EINVAL; |
| 1253 | |
| 1254 | adj_mode = &sde_enc->base.crtc->state->adjusted_mode; |
| 1255 | drm_conn = sde_enc->cur_master->connector; |
| 1256 | |
| 1257 | _sde_encoder_get_connector_roi(sde_enc, &roi); |
| 1258 | if (sde_kms_rect_is_null(&roi)) { |
| 1259 | roi.w = adj_mode->hdisplay; |
| 1260 | roi.h = adj_mode->vdisplay; |
| 1261 | } |
| 1262 | |
| 1263 | memcpy(&sde_enc->prv_conn_roi, &sde_enc->cur_conn_roi, |
| 1264 | sizeof(sde_enc->prv_conn_roi)); |
| 1265 | memcpy(&sde_enc->cur_conn_roi, &roi, sizeof(sde_enc->cur_conn_roi)); |
| 1266 | |
| 1267 | return 0; |
| 1268 | } |
| 1269 | |
| 1270 | static int _sde_encoder_dsc_setup(struct sde_encoder_virt *sde_enc, |
| 1271 | struct sde_encoder_kickoff_params *params) |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1272 | { |
| 1273 | enum sde_rm_topology_name topology; |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1274 | struct drm_connector *drm_conn; |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1275 | int ret = 0; |
| 1276 | |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1277 | if (!sde_enc || !params || !sde_enc->phys_encs[0] || |
| 1278 | !sde_enc->phys_encs[0]->connector) |
| 1279 | return -EINVAL; |
| 1280 | |
| 1281 | drm_conn = sde_enc->phys_encs[0]->connector; |
| 1282 | |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1283 | topology = sde_connector_get_topology_name(drm_conn); |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 1284 | if (topology == SDE_RM_TOPOLOGY_NONE) { |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1285 | SDE_ERROR_ENC(sde_enc, "topology not set yet\n"); |
| 1286 | return -EINVAL; |
| 1287 | } |
| 1288 | |
Ingrid Gallardo | 8353222 | 2017-06-02 16:48:51 -0700 | [diff] [blame] | 1289 | SDE_DEBUG_ENC(sde_enc, "topology:%d\n", topology); |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1290 | SDE_EVT32(DRMID(&sde_enc->base)); |
| 1291 | |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1292 | if (sde_kms_rect_is_equal(&sde_enc->cur_conn_roi, |
| 1293 | &sde_enc->prv_conn_roi)) |
| 1294 | return ret; |
| 1295 | |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1296 | switch (topology) { |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 1297 | case SDE_RM_TOPOLOGY_SINGLEPIPE_DSC: |
Ingrid Gallardo | 8353222 | 2017-06-02 16:48:51 -0700 | [diff] [blame] | 1298 | case SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC: |
| 1299 | ret = _sde_encoder_dsc_n_lm_1_enc_1_intf(sde_enc); |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1300 | break; |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 1301 | case SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE: |
Lloyd Atkinson | 094780d | 2017-04-24 17:25:08 -0400 | [diff] [blame] | 1302 | ret = _sde_encoder_dsc_2_lm_2_enc_1_intf(sde_enc, params); |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1303 | break; |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 1304 | case SDE_RM_TOPOLOGY_DUALPIPE_DSC: |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 1305 | ret = _sde_encoder_dsc_2_lm_2_enc_2_intf(sde_enc, params); |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1306 | break; |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 1307 | default: |
| 1308 | SDE_ERROR_ENC(sde_enc, "No DSC support for topology %d", |
| 1309 | topology); |
| 1310 | return -EINVAL; |
| 1311 | }; |
| 1312 | |
| 1313 | return ret; |
| 1314 | } |
| 1315 | |
Dhaval Patel | aab9b52 | 2017-07-20 12:38:46 -0700 | [diff] [blame] | 1316 | static void _sde_encoder_update_vsync_source(struct sde_encoder_virt *sde_enc, |
| 1317 | struct msm_display_info *disp_info, bool is_dummy) |
| 1318 | { |
| 1319 | struct sde_vsync_source_cfg vsync_cfg = { 0 }; |
| 1320 | struct msm_drm_private *priv; |
| 1321 | struct sde_kms *sde_kms; |
| 1322 | struct sde_hw_mdp *hw_mdptop; |
| 1323 | struct drm_encoder *drm_enc; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1324 | struct msm_mode_info mode_info; |
| 1325 | int i, rc = 0; |
Dhaval Patel | aab9b52 | 2017-07-20 12:38:46 -0700 | [diff] [blame] | 1326 | |
| 1327 | if (!sde_enc || !disp_info) { |
| 1328 | SDE_ERROR("invalid param sde_enc:%d or disp_info:%d\n", |
| 1329 | sde_enc != NULL, disp_info != NULL); |
| 1330 | return; |
| 1331 | } else if (sde_enc->num_phys_encs > ARRAY_SIZE(sde_enc->hw_pp)) { |
| 1332 | SDE_ERROR("invalid num phys enc %d/%d\n", |
| 1333 | sde_enc->num_phys_encs, |
| 1334 | (int) ARRAY_SIZE(sde_enc->hw_pp)); |
| 1335 | return; |
| 1336 | } |
| 1337 | |
| 1338 | drm_enc = &sde_enc->base; |
| 1339 | /* this pointers are checked in virt_enable_helper */ |
| 1340 | priv = drm_enc->dev->dev_private; |
| 1341 | |
| 1342 | sde_kms = to_sde_kms(priv->kms); |
| 1343 | if (!sde_kms) { |
| 1344 | SDE_ERROR("invalid sde_kms\n"); |
| 1345 | return; |
| 1346 | } |
| 1347 | |
| 1348 | hw_mdptop = sde_kms->hw_mdp; |
| 1349 | if (!hw_mdptop) { |
| 1350 | SDE_ERROR("invalid mdptop\n"); |
| 1351 | return; |
| 1352 | } |
| 1353 | |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1354 | rc = _sde_encoder_get_mode_info(drm_enc, &mode_info); |
| 1355 | if (rc) { |
| 1356 | SDE_ERROR_ENC(sde_enc, "failed to get mode info\n"); |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 1357 | return; |
| 1358 | } |
| 1359 | |
Dhaval Patel | aab9b52 | 2017-07-20 12:38:46 -0700 | [diff] [blame] | 1360 | if (hw_mdptop->ops.setup_vsync_source && |
| 1361 | disp_info->capabilities & MSM_DISPLAY_CAP_CMD_MODE) { |
| 1362 | for (i = 0; i < sde_enc->num_phys_encs; i++) |
| 1363 | vsync_cfg.ppnumber[i] = sde_enc->hw_pp[i]->idx; |
| 1364 | |
| 1365 | vsync_cfg.pp_count = sde_enc->num_phys_encs; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1366 | vsync_cfg.frame_rate = mode_info.frame_rate; |
Dhaval Patel | aab9b52 | 2017-07-20 12:38:46 -0700 | [diff] [blame] | 1367 | if (is_dummy) |
| 1368 | vsync_cfg.vsync_source = SDE_VSYNC_SOURCE_WD_TIMER_1; |
| 1369 | else if (disp_info->is_te_using_watchdog_timer) |
| 1370 | vsync_cfg.vsync_source = SDE_VSYNC_SOURCE_WD_TIMER_0; |
| 1371 | else |
| 1372 | vsync_cfg.vsync_source = SDE_VSYNC0_SOURCE_GPIO; |
| 1373 | vsync_cfg.is_dummy = is_dummy; |
| 1374 | |
| 1375 | hw_mdptop->ops.setup_vsync_source(hw_mdptop, &vsync_cfg); |
| 1376 | } |
| 1377 | } |
| 1378 | |
Ingrid Gallardo | 2a2befb | 2017-08-07 15:02:51 -0700 | [diff] [blame] | 1379 | static int _sde_encoder_dsc_disable(struct sde_encoder_virt *sde_enc) |
| 1380 | { |
Ingrid Gallardo | 2a2befb | 2017-08-07 15:02:51 -0700 | [diff] [blame] | 1381 | int i, ret = 0; |
Jeykumar Sankaran | 586d092 | 2017-09-18 15:01:33 -0700 | [diff] [blame] | 1382 | struct sde_hw_pingpong *hw_pp = NULL; |
| 1383 | struct sde_hw_dsc *hw_dsc = NULL; |
Ingrid Gallardo | 2a2befb | 2017-08-07 15:02:51 -0700 | [diff] [blame] | 1384 | |
| 1385 | if (!sde_enc || !sde_enc->phys_encs[0] || |
| 1386 | !sde_enc->phys_encs[0]->connector) { |
| 1387 | SDE_ERROR("invalid params %d %d\n", |
| 1388 | !sde_enc, sde_enc ? !sde_enc->phys_encs[0] : -1); |
| 1389 | return -EINVAL; |
| 1390 | } |
| 1391 | |
Ingrid Gallardo | 2a2befb | 2017-08-07 15:02:51 -0700 | [diff] [blame] | 1392 | /* Disable DSC for all the pp's present in this topology */ |
Jeykumar Sankaran | 586d092 | 2017-09-18 15:01:33 -0700 | [diff] [blame] | 1393 | for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) { |
| 1394 | hw_pp = sde_enc->hw_pp[i]; |
| 1395 | hw_dsc = sde_enc->hw_dsc[i]; |
Ingrid Gallardo | 2a2befb | 2017-08-07 15:02:51 -0700 | [diff] [blame] | 1396 | |
Jeykumar Sankaran | 586d092 | 2017-09-18 15:01:33 -0700 | [diff] [blame] | 1397 | if (hw_pp && hw_pp->ops.disable_dsc) |
| 1398 | hw_pp->ops.disable_dsc(hw_pp); |
Ingrid Gallardo | 2a2befb | 2017-08-07 15:02:51 -0700 | [diff] [blame] | 1399 | |
Jeykumar Sankaran | 586d092 | 2017-09-18 15:01:33 -0700 | [diff] [blame] | 1400 | if (hw_dsc && hw_dsc->ops.dsc_disable) |
| 1401 | hw_dsc->ops.dsc_disable(hw_dsc); |
Ingrid Gallardo | 2a2befb | 2017-08-07 15:02:51 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | return ret; |
| 1405 | } |
| 1406 | |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1407 | static int _sde_encoder_update_rsc_client( |
Alan Kwong | 56f1a94 | 2017-04-04 11:53:42 -0700 | [diff] [blame] | 1408 | struct drm_encoder *drm_enc, |
| 1409 | struct sde_encoder_rsc_config *config, bool enable) |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1410 | { |
| 1411 | struct sde_encoder_virt *sde_enc; |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1412 | struct drm_crtc *crtc; |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1413 | enum sde_rsc_state rsc_state; |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1414 | struct sde_rsc_cmd_config *rsc_config; |
| 1415 | int ret, prefill_lines; |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1416 | struct msm_display_info *disp_info; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1417 | struct msm_mode_info mode_info; |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1418 | int wait_vblank_crtc_id = SDE_RSC_INVALID_CRTC_ID; |
| 1419 | int wait_count = 0; |
| 1420 | struct drm_crtc *primary_crtc; |
| 1421 | int pipe = -1; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1422 | int rc = 0; |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1423 | |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1424 | if (!drm_enc || !drm_enc->crtc || !drm_enc->dev) { |
| 1425 | SDE_ERROR("invalid arguments\n"); |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1426 | return -EINVAL; |
| 1427 | } |
| 1428 | |
| 1429 | sde_enc = to_sde_encoder_virt(drm_enc); |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1430 | crtc = drm_enc->crtc; |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1431 | disp_info = &sde_enc->disp_info; |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1432 | rsc_config = &sde_enc->rsc_config; |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1433 | |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1434 | if (!sde_enc->rsc_client) { |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1435 | SDE_DEBUG_ENC(sde_enc, "rsc client not created\n"); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1436 | return 0; |
| 1437 | } |
| 1438 | |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1439 | rc = _sde_encoder_get_mode_info(drm_enc, &mode_info); |
| 1440 | if (rc) { |
| 1441 | SDE_ERROR_ENC(sde_enc, "failed to mode info\n"); |
| 1442 | return 0; |
| 1443 | } |
| 1444 | |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1445 | /** |
| 1446 | * only primary command mode panel can request CMD state. |
| 1447 | * all other panels/displays can request for VID state including |
| 1448 | * secondary command mode panel. |
| 1449 | */ |
| 1450 | rsc_state = enable ? |
| 1451 | (((disp_info->capabilities & MSM_DISPLAY_CAP_CMD_MODE) && |
| 1452 | disp_info->is_primary) ? SDE_RSC_CMD_STATE : |
| 1453 | SDE_RSC_VID_STATE) : SDE_RSC_IDLE_STATE; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1454 | prefill_lines = config ? mode_info.prefill_lines + |
| 1455 | config->inline_rotate_prefill : mode_info.prefill_lines; |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1456 | |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1457 | /* compare specific items and reconfigure the rsc */ |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1458 | if ((rsc_config->fps != mode_info.frame_rate) || |
| 1459 | (rsc_config->vtotal != mode_info.vtotal) || |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1460 | (rsc_config->prefill_lines != prefill_lines) || |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1461 | (rsc_config->jitter_numer != mode_info.jitter_numer) || |
| 1462 | (rsc_config->jitter_denom != mode_info.jitter_denom)) { |
| 1463 | rsc_config->fps = mode_info.frame_rate; |
| 1464 | rsc_config->vtotal = mode_info.vtotal; |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1465 | rsc_config->prefill_lines = prefill_lines; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1466 | rsc_config->jitter_numer = mode_info.jitter_numer; |
| 1467 | rsc_config->jitter_denom = mode_info.jitter_denom; |
Alan Kwong | 56f1a94 | 2017-04-04 11:53:42 -0700 | [diff] [blame] | 1468 | sde_enc->rsc_state_init = false; |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1469 | } |
Alan Kwong | 56f1a94 | 2017-04-04 11:53:42 -0700 | [diff] [blame] | 1470 | |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1471 | if (rsc_state != SDE_RSC_IDLE_STATE && !sde_enc->rsc_state_init |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1472 | && disp_info->is_primary) { |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1473 | /* update it only once */ |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1474 | sde_enc->rsc_state_init = true; |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1475 | |
| 1476 | ret = sde_rsc_client_state_update(sde_enc->rsc_client, |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1477 | rsc_state, rsc_config, crtc->base.id, |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1478 | &wait_vblank_crtc_id); |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1479 | } else { |
| 1480 | ret = sde_rsc_client_state_update(sde_enc->rsc_client, |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1481 | rsc_state, NULL, crtc->base.id, |
| 1482 | &wait_vblank_crtc_id); |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1485 | /** |
| 1486 | * if RSC performed a state change that requires a VBLANK wait, it will |
| 1487 | * set wait_vblank_crtc_id to the CRTC whose VBLANK we must wait on. |
| 1488 | * |
| 1489 | * if we are the primary display, we will need to enable and wait |
| 1490 | * locally since we hold the commit thread |
| 1491 | * |
| 1492 | * if we are an external display, we must send a signal to the primary |
| 1493 | * to enable its VBLANK and wait one, since the RSC hardware is driven |
| 1494 | * by the primary panel's VBLANK signals |
| 1495 | */ |
| 1496 | SDE_EVT32_VERBOSE(DRMID(drm_enc), wait_vblank_crtc_id); |
| 1497 | if (ret) { |
| 1498 | SDE_ERROR_ENC(sde_enc, |
| 1499 | "sde rsc client update failed ret:%d\n", ret); |
| 1500 | return ret; |
| 1501 | } else if (wait_vblank_crtc_id == SDE_RSC_INVALID_CRTC_ID) { |
| 1502 | return ret; |
| 1503 | } |
| 1504 | |
| 1505 | if (crtc->base.id != wait_vblank_crtc_id) { |
| 1506 | primary_crtc = drm_crtc_find(drm_enc->dev, wait_vblank_crtc_id); |
| 1507 | if (!primary_crtc) { |
| 1508 | SDE_ERROR_ENC(sde_enc, |
| 1509 | "failed to find primary crtc id %d\n", |
| 1510 | wait_vblank_crtc_id); |
| 1511 | return -EINVAL; |
| 1512 | } |
| 1513 | pipe = drm_crtc_index(primary_crtc); |
| 1514 | } |
| 1515 | |
| 1516 | /** |
| 1517 | * note: VBLANK is expected to be enabled at this point in |
| 1518 | * resource control state machine if on primary CRTC |
| 1519 | */ |
| 1520 | for (wait_count = 0; wait_count < MAX_RSC_WAIT; wait_count++) { |
| 1521 | if (sde_rsc_client_is_state_update_complete( |
| 1522 | sde_enc->rsc_client)) |
| 1523 | break; |
| 1524 | |
| 1525 | if (crtc->base.id == wait_vblank_crtc_id) |
| 1526 | ret = sde_encoder_wait_for_event(drm_enc, |
| 1527 | MSM_ENC_VBLANK); |
| 1528 | else |
| 1529 | drm_wait_one_vblank(drm_enc->dev, pipe); |
| 1530 | |
| 1531 | if (ret) { |
| 1532 | SDE_ERROR_ENC(sde_enc, |
| 1533 | "wait for vblank failed ret:%d\n", ret); |
| 1534 | break; |
| 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | if (wait_count >= MAX_RSC_WAIT) |
| 1539 | SDE_EVT32(DRMID(drm_enc), wait_vblank_crtc_id, wait_count, |
| 1540 | SDE_EVTLOG_ERROR); |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1541 | |
| 1542 | return ret; |
| 1543 | } |
| 1544 | |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1545 | static void _sde_encoder_irq_control(struct drm_encoder *drm_enc, bool enable) |
| 1546 | { |
| 1547 | struct sde_encoder_virt *sde_enc; |
| 1548 | int i; |
| 1549 | |
| 1550 | if (!drm_enc) { |
| 1551 | SDE_ERROR("invalid encoder\n"); |
| 1552 | return; |
| 1553 | } |
| 1554 | |
| 1555 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 1556 | |
| 1557 | SDE_DEBUG_ENC(sde_enc, "enable:%d\n", enable); |
| 1558 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 1559 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
| 1560 | |
| 1561 | if (phys && phys->ops.irq_control) |
| 1562 | phys->ops.irq_control(phys, enable); |
| 1563 | } |
| 1564 | |
| 1565 | } |
| 1566 | |
Veera Sundaram Sankaran | df79cc9 | 2017-10-10 22:32:46 -0700 | [diff] [blame] | 1567 | /* keep track of the userspace vblank during modeset */ |
| 1568 | static void _sde_encoder_modeset_helper_locked(struct drm_encoder *drm_enc, |
| 1569 | u32 sw_event) |
| 1570 | { |
| 1571 | struct sde_encoder_virt *sde_enc; |
| 1572 | bool enable; |
| 1573 | int i; |
| 1574 | |
| 1575 | if (!drm_enc) { |
| 1576 | SDE_ERROR("invalid encoder\n"); |
| 1577 | return; |
| 1578 | } |
| 1579 | |
| 1580 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 1581 | SDE_DEBUG_ENC(sde_enc, "sw_event:%d, vblank_enabled:%d\n", |
| 1582 | sw_event, sde_enc->vblank_enabled); |
| 1583 | |
| 1584 | /* nothing to do if vblank not enabled by userspace */ |
| 1585 | if (!sde_enc->vblank_enabled) |
| 1586 | return; |
| 1587 | |
| 1588 | /* disable vblank on pre_modeset */ |
| 1589 | if (sw_event == SDE_ENC_RC_EVENT_PRE_MODESET) |
| 1590 | enable = false; |
| 1591 | /* enable vblank on post_modeset */ |
| 1592 | else if (sw_event == SDE_ENC_RC_EVENT_POST_MODESET) |
| 1593 | enable = true; |
| 1594 | else |
| 1595 | return; |
| 1596 | |
| 1597 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 1598 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
| 1599 | |
| 1600 | if (phys && phys->ops.control_vblank_irq) |
| 1601 | phys->ops.control_vblank_irq(phys, enable); |
| 1602 | } |
| 1603 | } |
| 1604 | |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1605 | struct sde_rsc_client *sde_encoder_get_rsc_client(struct drm_encoder *drm_enc) |
| 1606 | { |
| 1607 | struct sde_encoder_virt *sde_enc; |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1608 | |
| 1609 | if (!drm_enc) |
| 1610 | return NULL; |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1611 | sde_enc = to_sde_encoder_virt(drm_enc); |
Dhaval Patel | 5cd59a0 | 2017-06-13 16:29:40 -0700 | [diff] [blame] | 1612 | return sde_enc->rsc_client; |
Dhaval Patel | 30fae8a | 2017-04-21 18:42:41 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1615 | static void _sde_encoder_resource_control_rsc_update( |
| 1616 | struct drm_encoder *drm_enc, bool enable) |
| 1617 | { |
| 1618 | struct sde_encoder_virt *sde_enc = to_sde_encoder_virt(drm_enc); |
| 1619 | struct sde_encoder_rsc_config rsc_cfg = { 0 }; |
Dhaval Patel | c1e4bfc | 2017-09-15 14:51:36 -0700 | [diff] [blame] | 1620 | int i; |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1621 | |
| 1622 | if (enable) { |
| 1623 | rsc_cfg.inline_rotate_prefill = |
| 1624 | sde_crtc_get_inline_prefill(drm_enc->crtc); |
| 1625 | |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1626 | _sde_encoder_update_rsc_client(drm_enc, &rsc_cfg, true); |
| 1627 | } else { |
| 1628 | _sde_encoder_update_rsc_client(drm_enc, NULL, false); |
| 1629 | |
| 1630 | /** |
Dhaval Patel | c1e4bfc | 2017-09-15 14:51:36 -0700 | [diff] [blame] | 1631 | * disable the vsync source after updating the rsc state. rsc |
| 1632 | * state update might have vsync wait and vsync source must be |
| 1633 | * disabled after it. It will avoid generating any vsync from |
| 1634 | * this point till mode-2 entry. It is SW workaround for |
| 1635 | * HW limitation and should not be removed without checking the |
| 1636 | * updated design. |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1637 | */ |
Dhaval Patel | c1e4bfc | 2017-09-15 14:51:36 -0700 | [diff] [blame] | 1638 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 1639 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
| 1640 | |
| 1641 | if (phys && phys->ops.prepare_idle_pc) |
| 1642 | phys->ops.prepare_idle_pc(phys); |
| 1643 | } |
| 1644 | |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1645 | } |
| 1646 | } |
| 1647 | |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1648 | static void _sde_encoder_resource_control_helper(struct drm_encoder *drm_enc, |
| 1649 | bool enable) |
| 1650 | { |
| 1651 | struct msm_drm_private *priv; |
| 1652 | struct sde_kms *sde_kms; |
| 1653 | struct sde_encoder_virt *sde_enc; |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1654 | |
| 1655 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 1656 | priv = drm_enc->dev->dev_private; |
| 1657 | sde_kms = to_sde_kms(priv->kms); |
| 1658 | |
| 1659 | SDE_DEBUG_ENC(sde_enc, "enable:%d\n", enable); |
| 1660 | SDE_EVT32(DRMID(drm_enc), enable); |
| 1661 | |
| 1662 | if (!sde_enc->cur_master) { |
| 1663 | SDE_ERROR("encoder master not set\n"); |
| 1664 | return; |
| 1665 | } |
| 1666 | |
| 1667 | if (enable) { |
| 1668 | /* enable SDE core clks */ |
| 1669 | sde_power_resource_enable(&priv->phandle, |
| 1670 | sde_kms->core_client, true); |
| 1671 | |
| 1672 | /* enable DSI clks */ |
| 1673 | sde_connector_clk_ctrl(sde_enc->cur_master->connector, true); |
| 1674 | |
| 1675 | /* enable all the irq */ |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1676 | _sde_encoder_irq_control(drm_enc, true); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1677 | |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1678 | } else { |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1679 | /* disable all the irq */ |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1680 | _sde_encoder_irq_control(drm_enc, false); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1681 | |
| 1682 | /* disable DSI clks */ |
| 1683 | sde_connector_clk_ctrl(sde_enc->cur_master->connector, false); |
| 1684 | |
| 1685 | /* disable SDE core clks */ |
| 1686 | sde_power_resource_enable(&priv->phandle, |
| 1687 | sde_kms->core_client, false); |
| 1688 | } |
| 1689 | |
| 1690 | } |
| 1691 | |
| 1692 | static int sde_encoder_resource_control(struct drm_encoder *drm_enc, |
| 1693 | u32 sw_event) |
| 1694 | { |
Dhaval Patel | 99412a5 | 2017-07-24 19:16:45 -0700 | [diff] [blame] | 1695 | bool autorefresh_enabled = false; |
Clarence Ip | 8962813 | 2017-07-27 13:33:51 -0400 | [diff] [blame] | 1696 | unsigned int lp, idle_timeout; |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1697 | struct sde_encoder_virt *sde_enc; |
Lloyd Atkinson | a878138 | 2017-07-17 10:20:43 -0400 | [diff] [blame] | 1698 | struct msm_drm_private *priv; |
| 1699 | struct msm_drm_thread *disp_thread; |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1700 | int ret; |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 1701 | bool is_vid_mode = false; |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1702 | |
Lloyd Atkinson | a878138 | 2017-07-17 10:20:43 -0400 | [diff] [blame] | 1703 | if (!drm_enc || !drm_enc->dev || !drm_enc->dev->dev_private || |
| 1704 | !drm_enc->crtc) { |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1705 | SDE_ERROR("invalid parameters\n"); |
| 1706 | return -EINVAL; |
| 1707 | } |
| 1708 | sde_enc = to_sde_encoder_virt(drm_enc); |
Lloyd Atkinson | a878138 | 2017-07-17 10:20:43 -0400 | [diff] [blame] | 1709 | priv = drm_enc->dev->dev_private; |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 1710 | is_vid_mode = sde_enc->disp_info.capabilities & |
| 1711 | MSM_DISPLAY_CAP_VID_MODE; |
Lloyd Atkinson | a878138 | 2017-07-17 10:20:43 -0400 | [diff] [blame] | 1712 | |
| 1713 | if (drm_enc->crtc->index >= ARRAY_SIZE(priv->disp_thread)) { |
| 1714 | SDE_ERROR("invalid crtc index\n"); |
| 1715 | return -EINVAL; |
| 1716 | } |
| 1717 | disp_thread = &priv->disp_thread[drm_enc->crtc->index]; |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1718 | |
| 1719 | /* |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1720 | * when idle_pc is not supported, process only KICKOFF, STOP and MODESET |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 1721 | * events and return early for other events (ie wb display). |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1722 | */ |
| 1723 | if (!sde_enc->idle_pc_supported && |
| 1724 | (sw_event != SDE_ENC_RC_EVENT_KICKOFF && |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1725 | sw_event != SDE_ENC_RC_EVENT_PRE_MODESET && |
| 1726 | sw_event != SDE_ENC_RC_EVENT_POST_MODESET && |
| 1727 | sw_event != SDE_ENC_RC_EVENT_STOP && |
| 1728 | sw_event != SDE_ENC_RC_EVENT_PRE_STOP)) |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1729 | return 0; |
| 1730 | |
| 1731 | SDE_DEBUG_ENC(sde_enc, "sw_event:%d, idle_pc_supported:%d\n", sw_event, |
| 1732 | sde_enc->idle_pc_supported); |
Dhaval Patel | a5f7595 | 2017-07-25 11:17:41 -0700 | [diff] [blame] | 1733 | SDE_EVT32_VERBOSE(DRMID(drm_enc), sw_event, sde_enc->idle_pc_supported, |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1734 | sde_enc->rc_state, SDE_EVTLOG_FUNC_ENTRY); |
| 1735 | |
| 1736 | switch (sw_event) { |
| 1737 | case SDE_ENC_RC_EVENT_KICKOFF: |
| 1738 | /* cancel delayed off work, if any */ |
Lloyd Atkinson | a878138 | 2017-07-17 10:20:43 -0400 | [diff] [blame] | 1739 | if (kthread_cancel_delayed_work_sync( |
| 1740 | &sde_enc->delayed_off_work)) |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1741 | SDE_DEBUG_ENC(sde_enc, "sw_event:%d, work cancelled\n", |
| 1742 | sw_event); |
| 1743 | |
| 1744 | mutex_lock(&sde_enc->rc_lock); |
| 1745 | |
| 1746 | /* return if the resource control is already in ON state */ |
| 1747 | if (sde_enc->rc_state == SDE_ENC_RC_STATE_ON) { |
| 1748 | SDE_DEBUG_ENC(sde_enc, "sw_event:%d, rc in ON state\n", |
| 1749 | sw_event); |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 1750 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 1751 | SDE_EVTLOG_FUNC_CASE1); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1752 | mutex_unlock(&sde_enc->rc_lock); |
| 1753 | return 0; |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1754 | } else if (sde_enc->rc_state != SDE_ENC_RC_STATE_OFF && |
| 1755 | sde_enc->rc_state != SDE_ENC_RC_STATE_IDLE) { |
| 1756 | SDE_ERROR_ENC(sde_enc, "sw_event:%d, rc in state %d\n", |
| 1757 | sw_event, sde_enc->rc_state); |
| 1758 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 1759 | SDE_EVTLOG_ERROR); |
| 1760 | mutex_unlock(&sde_enc->rc_lock); |
| 1761 | return -EINVAL; |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 1764 | if (is_vid_mode && sde_enc->rc_state == SDE_ENC_RC_STATE_IDLE) { |
| 1765 | _sde_encoder_irq_control(drm_enc, true); |
| 1766 | } else { |
| 1767 | /* enable all the clks and resources */ |
| 1768 | _sde_encoder_resource_control_helper(drm_enc, true); |
| 1769 | _sde_encoder_resource_control_rsc_update(drm_enc, true); |
| 1770 | } |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1771 | |
| 1772 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 1773 | SDE_ENC_RC_STATE_ON, SDE_EVTLOG_FUNC_CASE1); |
| 1774 | sde_enc->rc_state = SDE_ENC_RC_STATE_ON; |
| 1775 | |
| 1776 | mutex_unlock(&sde_enc->rc_lock); |
| 1777 | break; |
| 1778 | |
| 1779 | case SDE_ENC_RC_EVENT_FRAME_DONE: |
| 1780 | /* |
| 1781 | * mutex lock is not used as this event happens at interrupt |
| 1782 | * context. And locking is not required as, the other events |
| 1783 | * like KICKOFF and STOP does a wait-for-idle before executing |
| 1784 | * the resource_control |
| 1785 | */ |
| 1786 | if (sde_enc->rc_state != SDE_ENC_RC_STATE_ON) { |
| 1787 | SDE_ERROR_ENC(sde_enc, "sw_event:%d,rc:%d-unexpected\n", |
| 1788 | sw_event, sde_enc->rc_state); |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1789 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 1790 | SDE_EVTLOG_ERROR); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1791 | return -EINVAL; |
| 1792 | } |
| 1793 | |
| 1794 | /* |
| 1795 | * schedule off work item only when there are no |
| 1796 | * frames pending |
| 1797 | */ |
| 1798 | if (sde_crtc_frame_pending(drm_enc->crtc) > 1) { |
| 1799 | SDE_DEBUG_ENC(sde_enc, "skip schedule work"); |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 1800 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 1801 | SDE_EVTLOG_FUNC_CASE2); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1802 | return 0; |
| 1803 | } |
| 1804 | |
Dhaval Patel | 99412a5 | 2017-07-24 19:16:45 -0700 | [diff] [blame] | 1805 | /* schedule delayed off work if autorefresh is disabled */ |
| 1806 | if (sde_enc->cur_master && |
| 1807 | sde_enc->cur_master->ops.is_autorefresh_enabled) |
| 1808 | autorefresh_enabled = |
| 1809 | sde_enc->cur_master->ops.is_autorefresh_enabled( |
| 1810 | sde_enc->cur_master); |
| 1811 | |
Clarence Ip | 8962813 | 2017-07-27 13:33:51 -0400 | [diff] [blame] | 1812 | /* set idle timeout based on master connector's lp value */ |
| 1813 | if (sde_enc->cur_master) |
| 1814 | lp = sde_connector_get_lp( |
| 1815 | sde_enc->cur_master->connector); |
| 1816 | else |
| 1817 | lp = SDE_MODE_DPMS_ON; |
| 1818 | |
| 1819 | if (lp == SDE_MODE_DPMS_LP2) |
| 1820 | idle_timeout = IDLE_SHORT_TIMEOUT; |
| 1821 | else |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 1822 | idle_timeout = sde_enc->idle_timeout; |
Clarence Ip | 8962813 | 2017-07-27 13:33:51 -0400 | [diff] [blame] | 1823 | |
Sravanthi Kollukuduru | 247adcf | 2017-10-11 16:19:23 +0530 | [diff] [blame] | 1824 | if (!autorefresh_enabled && idle_timeout) |
Dhaval Patel | 99412a5 | 2017-07-24 19:16:45 -0700 | [diff] [blame] | 1825 | kthread_queue_delayed_work( |
Lloyd Atkinson | a878138 | 2017-07-17 10:20:43 -0400 | [diff] [blame] | 1826 | &disp_thread->worker, |
| 1827 | &sde_enc->delayed_off_work, |
Clarence Ip | 8962813 | 2017-07-27 13:33:51 -0400 | [diff] [blame] | 1828 | msecs_to_jiffies(idle_timeout)); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1829 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
Clarence Ip | 8962813 | 2017-07-27 13:33:51 -0400 | [diff] [blame] | 1830 | autorefresh_enabled, |
| 1831 | idle_timeout, SDE_EVTLOG_FUNC_CASE2); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1832 | SDE_DEBUG_ENC(sde_enc, "sw_event:%d, work scheduled\n", |
| 1833 | sw_event); |
| 1834 | break; |
| 1835 | |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1836 | case SDE_ENC_RC_EVENT_PRE_STOP: |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1837 | /* cancel delayed off work, if any */ |
Lloyd Atkinson | a878138 | 2017-07-17 10:20:43 -0400 | [diff] [blame] | 1838 | if (kthread_cancel_delayed_work_sync( |
| 1839 | &sde_enc->delayed_off_work)) |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1840 | SDE_DEBUG_ENC(sde_enc, "sw_event:%d, work cancelled\n", |
| 1841 | sw_event); |
| 1842 | |
| 1843 | mutex_lock(&sde_enc->rc_lock); |
| 1844 | |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 1845 | if (is_vid_mode && |
| 1846 | sde_enc->rc_state == SDE_ENC_RC_STATE_IDLE) { |
| 1847 | _sde_encoder_irq_control(drm_enc, true); |
| 1848 | } |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1849 | /* skip if is already OFF or IDLE, resources are off already */ |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 1850 | else if (sde_enc->rc_state == SDE_ENC_RC_STATE_OFF || |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1851 | sde_enc->rc_state == SDE_ENC_RC_STATE_IDLE) { |
| 1852 | SDE_DEBUG_ENC(sde_enc, "sw_event:%d, rc in %d state\n", |
| 1853 | sw_event, sde_enc->rc_state); |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 1854 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 1855 | SDE_EVTLOG_FUNC_CASE3); |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1856 | mutex_unlock(&sde_enc->rc_lock); |
| 1857 | return 0; |
| 1858 | } |
| 1859 | |
| 1860 | /** |
| 1861 | * IRQs are still enabled currently, which allows wait for |
| 1862 | * VBLANK which RSC may require to correctly transition to OFF |
| 1863 | */ |
| 1864 | _sde_encoder_resource_control_rsc_update(drm_enc, false); |
| 1865 | |
| 1866 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 1867 | SDE_ENC_RC_STATE_PRE_OFF, |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1868 | SDE_EVTLOG_FUNC_CASE3); |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1869 | |
| 1870 | sde_enc->rc_state = SDE_ENC_RC_STATE_PRE_OFF; |
| 1871 | |
| 1872 | mutex_unlock(&sde_enc->rc_lock); |
| 1873 | break; |
| 1874 | |
| 1875 | case SDE_ENC_RC_EVENT_STOP: |
Jayant Shekhar | 12d908f | 2017-10-10 12:11:48 +0530 | [diff] [blame] | 1876 | /* cancel vsync event work */ |
| 1877 | kthread_cancel_work_sync(&sde_enc->vsync_event_work); |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1878 | |
Jayant Shekhar | 12d908f | 2017-10-10 12:11:48 +0530 | [diff] [blame] | 1879 | mutex_lock(&sde_enc->rc_lock); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1880 | /* return if the resource control is already in OFF state */ |
| 1881 | if (sde_enc->rc_state == SDE_ENC_RC_STATE_OFF) { |
| 1882 | SDE_DEBUG_ENC(sde_enc, "sw_event:%d, rc in OFF state\n", |
| 1883 | sw_event); |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 1884 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 1885 | SDE_EVTLOG_FUNC_CASE4); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1886 | mutex_unlock(&sde_enc->rc_lock); |
| 1887 | return 0; |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1888 | } else if (sde_enc->rc_state == SDE_ENC_RC_STATE_ON || |
| 1889 | sde_enc->rc_state == SDE_ENC_RC_STATE_MODESET) { |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1890 | SDE_ERROR_ENC(sde_enc, "sw_event:%d, rc in state %d\n", |
| 1891 | sw_event, sde_enc->rc_state); |
| 1892 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 1893 | SDE_EVTLOG_ERROR); |
| 1894 | mutex_unlock(&sde_enc->rc_lock); |
| 1895 | return -EINVAL; |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1896 | } |
| 1897 | |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1898 | /** |
| 1899 | * expect to arrive here only if in either idle state or pre-off |
| 1900 | * and in IDLE state the resources are already disabled |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1901 | */ |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1902 | if (sde_enc->rc_state == SDE_ENC_RC_STATE_PRE_OFF) |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1903 | _sde_encoder_resource_control_helper(drm_enc, false); |
| 1904 | |
| 1905 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1906 | SDE_ENC_RC_STATE_OFF, SDE_EVTLOG_FUNC_CASE4); |
Lloyd Atkinson | a878138 | 2017-07-17 10:20:43 -0400 | [diff] [blame] | 1907 | |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1908 | sde_enc->rc_state = SDE_ENC_RC_STATE_OFF; |
| 1909 | |
| 1910 | mutex_unlock(&sde_enc->rc_lock); |
| 1911 | break; |
| 1912 | |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1913 | case SDE_ENC_RC_EVENT_PRE_MODESET: |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1914 | /* cancel delayed off work, if any */ |
Lloyd Atkinson | a878138 | 2017-07-17 10:20:43 -0400 | [diff] [blame] | 1915 | if (kthread_cancel_delayed_work_sync( |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1916 | &sde_enc->delayed_off_work)) |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1917 | SDE_DEBUG_ENC(sde_enc, "sw_event:%d, work cancelled\n", |
| 1918 | sw_event); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1919 | |
| 1920 | mutex_lock(&sde_enc->rc_lock); |
| 1921 | |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1922 | /* return if the resource control is already in ON state */ |
| 1923 | if (sde_enc->rc_state != SDE_ENC_RC_STATE_ON) { |
| 1924 | /* enable all the clks and resources */ |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1925 | _sde_encoder_resource_control_helper(drm_enc, true); |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1926 | |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1927 | _sde_encoder_resource_control_rsc_update(drm_enc, true); |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1928 | |
| 1929 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 1930 | SDE_ENC_RC_STATE_ON, SDE_EVTLOG_FUNC_CASE5); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1931 | sde_enc->rc_state = SDE_ENC_RC_STATE_ON; |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1932 | } |
| 1933 | |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1934 | ret = sde_encoder_wait_for_event(drm_enc, MSM_ENC_TX_COMPLETE); |
| 1935 | if (ret && ret != -EWOULDBLOCK) { |
| 1936 | SDE_ERROR_ENC(sde_enc, |
| 1937 | "wait for commit done returned %d\n", |
| 1938 | ret); |
| 1939 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 1940 | ret, SDE_EVTLOG_ERROR); |
| 1941 | mutex_unlock(&sde_enc->rc_lock); |
| 1942 | return -EINVAL; |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1945 | _sde_encoder_irq_control(drm_enc, false); |
Veera Sundaram Sankaran | df79cc9 | 2017-10-10 22:32:46 -0700 | [diff] [blame] | 1946 | _sde_encoder_modeset_helper_locked(drm_enc, sw_event); |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1947 | |
| 1948 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 1949 | SDE_ENC_RC_STATE_MODESET, SDE_EVTLOG_FUNC_CASE5); |
| 1950 | |
| 1951 | sde_enc->rc_state = SDE_ENC_RC_STATE_MODESET; |
| 1952 | mutex_unlock(&sde_enc->rc_lock); |
| 1953 | break; |
| 1954 | |
| 1955 | case SDE_ENC_RC_EVENT_POST_MODESET: |
| 1956 | mutex_lock(&sde_enc->rc_lock); |
| 1957 | |
| 1958 | /* return if the resource control is already in ON state */ |
| 1959 | if (sde_enc->rc_state != SDE_ENC_RC_STATE_MODESET) { |
| 1960 | SDE_ERROR_ENC(sde_enc, |
| 1961 | "sw_event:%d, rc:%d !MODESET state\n", |
| 1962 | sw_event, sde_enc->rc_state); |
| 1963 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 1964 | SDE_EVTLOG_ERROR); |
| 1965 | mutex_unlock(&sde_enc->rc_lock); |
| 1966 | return -EINVAL; |
| 1967 | } |
| 1968 | |
Veera Sundaram Sankaran | df79cc9 | 2017-10-10 22:32:46 -0700 | [diff] [blame] | 1969 | _sde_encoder_modeset_helper_locked(drm_enc, sw_event); |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 1970 | _sde_encoder_irq_control(drm_enc, true); |
| 1971 | |
| 1972 | _sde_encoder_update_rsc_client(drm_enc, NULL, true); |
| 1973 | |
| 1974 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 1975 | SDE_ENC_RC_STATE_ON, SDE_EVTLOG_FUNC_CASE6); |
| 1976 | |
| 1977 | sde_enc->rc_state = SDE_ENC_RC_STATE_ON; |
| 1978 | |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1979 | mutex_unlock(&sde_enc->rc_lock); |
| 1980 | break; |
| 1981 | |
| 1982 | case SDE_ENC_RC_EVENT_ENTER_IDLE: |
| 1983 | mutex_lock(&sde_enc->rc_lock); |
| 1984 | |
| 1985 | if (sde_enc->rc_state != SDE_ENC_RC_STATE_ON) { |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1986 | SDE_ERROR_ENC(sde_enc, "sw_event:%d, rc:%d !ON state\n", |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 1987 | sw_event, sde_enc->rc_state); |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1988 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 1989 | SDE_EVTLOG_ERROR); |
Lloyd Atkinson | a878138 | 2017-07-17 10:20:43 -0400 | [diff] [blame] | 1990 | mutex_unlock(&sde_enc->rc_lock); |
| 1991 | return 0; |
| 1992 | } |
| 1993 | |
| 1994 | /* |
| 1995 | * if we are in ON but a frame was just kicked off, |
| 1996 | * ignore the IDLE event, it's probably a stale timer event |
| 1997 | */ |
| 1998 | if (sde_enc->frame_busy_mask[0]) { |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 1999 | SDE_ERROR_ENC(sde_enc, |
Lloyd Atkinson | a878138 | 2017-07-17 10:20:43 -0400 | [diff] [blame] | 2000 | "sw_event:%d, rc:%d frame pending\n", |
| 2001 | sw_event, sde_enc->rc_state); |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 2002 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
| 2003 | SDE_EVTLOG_ERROR); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 2004 | mutex_unlock(&sde_enc->rc_lock); |
| 2005 | return 0; |
| 2006 | } |
| 2007 | |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 2008 | if (is_vid_mode) { |
| 2009 | _sde_encoder_irq_control(drm_enc, false); |
| 2010 | } else { |
| 2011 | /* disable all the clks and resources */ |
| 2012 | _sde_encoder_resource_control_rsc_update(drm_enc, |
| 2013 | false); |
| 2014 | _sde_encoder_resource_control_helper(drm_enc, false); |
| 2015 | } |
| 2016 | |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 2017 | SDE_EVT32(DRMID(drm_enc), sw_event, sde_enc->rc_state, |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 2018 | SDE_ENC_RC_STATE_IDLE, SDE_EVTLOG_FUNC_CASE7); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 2019 | sde_enc->rc_state = SDE_ENC_RC_STATE_IDLE; |
| 2020 | |
| 2021 | mutex_unlock(&sde_enc->rc_lock); |
| 2022 | break; |
| 2023 | |
| 2024 | default: |
Dhaval Patel | a5f7595 | 2017-07-25 11:17:41 -0700 | [diff] [blame] | 2025 | SDE_EVT32(DRMID(drm_enc), sw_event, SDE_EVTLOG_ERROR); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 2026 | SDE_ERROR("unexpected sw_event: %d\n", sw_event); |
| 2027 | break; |
| 2028 | } |
| 2029 | |
Dhaval Patel | a5f7595 | 2017-07-25 11:17:41 -0700 | [diff] [blame] | 2030 | SDE_EVT32_VERBOSE(DRMID(drm_enc), sw_event, sde_enc->idle_pc_supported, |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 2031 | sde_enc->rc_state, SDE_EVTLOG_FUNC_EXIT); |
| 2032 | return 0; |
| 2033 | } |
| 2034 | |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2035 | static void sde_encoder_virt_mode_set(struct drm_encoder *drm_enc, |
| 2036 | struct drm_display_mode *mode, |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 2037 | struct drm_display_mode *adj_mode) |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2038 | { |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 2039 | struct sde_encoder_virt *sde_enc; |
| 2040 | struct msm_drm_private *priv; |
| 2041 | struct sde_kms *sde_kms; |
| 2042 | struct list_head *connector_list; |
| 2043 | struct drm_connector *conn = NULL, *conn_iter; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 2044 | struct sde_connector_state *sde_conn_state = NULL; |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 2045 | struct sde_connector *sde_conn = NULL; |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 2046 | struct sde_rm_hw_iter dsc_iter, pp_iter; |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 2047 | int i = 0, ret; |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2048 | |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 2049 | if (!drm_enc) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 2050 | SDE_ERROR("invalid encoder\n"); |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 2051 | return; |
| 2052 | } |
| 2053 | |
| 2054 | sde_enc = to_sde_encoder_virt(drm_enc); |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 2055 | SDE_DEBUG_ENC(sde_enc, "\n"); |
| 2056 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 2057 | priv = drm_enc->dev->dev_private; |
| 2058 | sde_kms = to_sde_kms(priv->kms); |
| 2059 | connector_list = &sde_kms->dev->mode_config.connector_list; |
| 2060 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 2061 | SDE_EVT32(DRMID(drm_enc)); |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 2062 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 2063 | list_for_each_entry(conn_iter, connector_list, head) |
| 2064 | if (conn_iter->encoder == drm_enc) |
| 2065 | conn = conn_iter; |
| 2066 | |
| 2067 | if (!conn) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 2068 | SDE_ERROR_ENC(sde_enc, "failed to find attached connector\n"); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 2069 | return; |
Lloyd Atkinson | 55987b0 | 2016-08-16 16:57:46 -0400 | [diff] [blame] | 2070 | } else if (!conn->state) { |
| 2071 | SDE_ERROR_ENC(sde_enc, "invalid connector state\n"); |
| 2072 | return; |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 2073 | } |
| 2074 | |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 2075 | sde_conn = to_sde_connector(conn); |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 2076 | sde_conn_state = to_sde_connector_state(conn->state); |
| 2077 | if (sde_conn && sde_conn_state) { |
| 2078 | ret = sde_conn->ops.get_mode_info(adj_mode, |
| 2079 | &sde_conn_state->mode_info, |
Alan Kwong | b1bca60 | 2017-09-18 17:28:45 -0400 | [diff] [blame] | 2080 | sde_kms->catalog->max_mixer_width, |
| 2081 | sde_conn->display); |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 2082 | if (ret) { |
| 2083 | SDE_ERROR_ENC(sde_enc, |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 2084 | "failed to get mode info from the display\n"); |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 2085 | return; |
| 2086 | } |
| 2087 | } |
| 2088 | |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 2089 | /* release resources before seamless mode change */ |
| 2090 | if (msm_is_mode_seamless_dms(adj_mode)) { |
| 2091 | /* restore resource state before releasing them */ |
| 2092 | ret = sde_encoder_resource_control(drm_enc, |
| 2093 | SDE_ENC_RC_EVENT_PRE_MODESET); |
| 2094 | if (ret) { |
| 2095 | SDE_ERROR_ENC(sde_enc, |
| 2096 | "sde resource control failed: %d\n", |
| 2097 | ret); |
| 2098 | return; |
| 2099 | } |
Ingrid Gallardo | 2a2befb | 2017-08-07 15:02:51 -0700 | [diff] [blame] | 2100 | |
| 2101 | /* |
| 2102 | * Disable dsc before switch the mode and after pre_modeset, |
| 2103 | * to guarantee that previous kickoff finished. |
| 2104 | */ |
| 2105 | _sde_encoder_dsc_disable(sde_enc); |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 2108 | /* Reserve dynamic resources now. Indicating non-AtomicTest phase */ |
| 2109 | ret = sde_rm_reserve(&sde_kms->rm, drm_enc, drm_enc->crtc->state, |
| 2110 | conn->state, false); |
| 2111 | if (ret) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 2112 | SDE_ERROR_ENC(sde_enc, |
| 2113 | "failed to reserve hw resources, %d\n", ret); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 2114 | return; |
| 2115 | } |
| 2116 | |
Jeykumar Sankaran | fdd77a9 | 2016-11-02 12:34:29 -0700 | [diff] [blame] | 2117 | sde_rm_init_hw_iter(&pp_iter, drm_enc->base.id, SDE_HW_BLK_PINGPONG); |
| 2118 | for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) { |
| 2119 | sde_enc->hw_pp[i] = NULL; |
| 2120 | if (!sde_rm_get_hw(&sde_kms->rm, &pp_iter)) |
| 2121 | break; |
| 2122 | sde_enc->hw_pp[i] = (struct sde_hw_pingpong *) pp_iter.hw; |
| 2123 | } |
| 2124 | |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 2125 | sde_rm_init_hw_iter(&dsc_iter, drm_enc->base.id, SDE_HW_BLK_DSC); |
| 2126 | for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) { |
| 2127 | sde_enc->hw_dsc[i] = NULL; |
| 2128 | if (!sde_rm_get_hw(&sde_kms->rm, &dsc_iter)) |
| 2129 | break; |
| 2130 | sde_enc->hw_dsc[i] = (struct sde_hw_dsc *) dsc_iter.hw; |
| 2131 | } |
| 2132 | |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2133 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 2134 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 2135 | |
Lloyd Atkinson | 55987b0 | 2016-08-16 16:57:46 -0400 | [diff] [blame] | 2136 | if (phys) { |
Jeykumar Sankaran | fdd77a9 | 2016-11-02 12:34:29 -0700 | [diff] [blame] | 2137 | if (!sde_enc->hw_pp[i]) { |
| 2138 | SDE_ERROR_ENC(sde_enc, |
| 2139 | "invalid pingpong block for the encoder\n"); |
| 2140 | return; |
| 2141 | } |
| 2142 | phys->hw_pp = sde_enc->hw_pp[i]; |
Lloyd Atkinson | 55987b0 | 2016-08-16 16:57:46 -0400 | [diff] [blame] | 2143 | phys->connector = conn->state->connector; |
| 2144 | if (phys->ops.mode_set) |
| 2145 | phys->ops.mode_set(phys, mode, adj_mode); |
| 2146 | } |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 2147 | } |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 2148 | |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 2149 | /* update resources after seamless mode change */ |
| 2150 | if (msm_is_mode_seamless_dms(adj_mode)) |
| 2151 | sde_encoder_resource_control(&sde_enc->base, |
| 2152 | SDE_ENC_RC_EVENT_POST_MODESET); |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2153 | } |
| 2154 | |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2155 | static void _sde_encoder_virt_enable_helper(struct drm_encoder *drm_enc) |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2156 | { |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 2157 | struct sde_encoder_virt *sde_enc = NULL; |
Clarence Ip | 3534826 | 2017-04-28 16:10:46 -0700 | [diff] [blame] | 2158 | struct msm_drm_private *priv; |
| 2159 | struct sde_kms *sde_kms; |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2160 | |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2161 | if (!drm_enc || !drm_enc->dev || !drm_enc->dev->dev_private) { |
| 2162 | SDE_ERROR("invalid parameters\n"); |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 2163 | return; |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2164 | } |
Dhaval Patel | aab9b52 | 2017-07-20 12:38:46 -0700 | [diff] [blame] | 2165 | |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2166 | priv = drm_enc->dev->dev_private; |
Dhaval Patel | aab9b52 | 2017-07-20 12:38:46 -0700 | [diff] [blame] | 2167 | sde_kms = to_sde_kms(priv->kms); |
| 2168 | if (!sde_kms) { |
| 2169 | SDE_ERROR("invalid sde_kms\n"); |
| 2170 | return; |
| 2171 | } |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2172 | |
| 2173 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 2174 | if (!sde_enc || !sde_enc->cur_master) { |
| 2175 | SDE_ERROR("invalid sde encoder/master\n"); |
Lloyd Atkinson | 5217336c | 2016-09-15 18:21:18 -0400 | [diff] [blame] | 2176 | return; |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 2177 | } |
| 2178 | |
Ajay Singh Parmar | 878ef14 | 2017-08-07 16:53:57 -0700 | [diff] [blame] | 2179 | if (sde_enc->disp_info.intf_type == DRM_MODE_CONNECTOR_DisplayPort && |
| 2180 | sde_enc->cur_master->hw_mdptop && |
| 2181 | sde_enc->cur_master->hw_mdptop->ops.intf_audio_select) |
| 2182 | sde_enc->cur_master->hw_mdptop->ops.intf_audio_select( |
| 2183 | sde_enc->cur_master->hw_mdptop); |
| 2184 | |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2185 | if (sde_enc->cur_master->hw_mdptop && |
| 2186 | sde_enc->cur_master->hw_mdptop->ops.reset_ubwc) |
| 2187 | sde_enc->cur_master->hw_mdptop->ops.reset_ubwc( |
| 2188 | sde_enc->cur_master->hw_mdptop, |
| 2189 | sde_kms->catalog); |
| 2190 | |
Dhaval Patel | aab9b52 | 2017-07-20 12:38:46 -0700 | [diff] [blame] | 2191 | _sde_encoder_update_vsync_source(sde_enc, &sde_enc->disp_info, false); |
Lloyd Atkinson | bc01cbd | 2017-06-05 14:26:57 -0400 | [diff] [blame] | 2192 | |
| 2193 | memset(&sde_enc->prv_conn_roi, 0, sizeof(sde_enc->prv_conn_roi)); |
| 2194 | memset(&sde_enc->cur_conn_roi, 0, sizeof(sde_enc->cur_conn_roi)); |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | void sde_encoder_virt_restore(struct drm_encoder *drm_enc) |
| 2198 | { |
| 2199 | struct sde_encoder_virt *sde_enc = NULL; |
| 2200 | int i; |
| 2201 | |
| 2202 | if (!drm_enc) { |
| 2203 | SDE_ERROR("invalid encoder\n"); |
| 2204 | return; |
| 2205 | } |
| 2206 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 2207 | |
| 2208 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 2209 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
| 2210 | |
| 2211 | if (phys && (phys != sde_enc->cur_master) && phys->ops.restore) |
| 2212 | phys->ops.restore(phys); |
| 2213 | } |
| 2214 | |
| 2215 | if (sde_enc->cur_master && sde_enc->cur_master->ops.restore) |
| 2216 | sde_enc->cur_master->ops.restore(sde_enc->cur_master); |
| 2217 | |
| 2218 | _sde_encoder_virt_enable_helper(drm_enc); |
| 2219 | } |
| 2220 | |
| 2221 | static void sde_encoder_virt_enable(struct drm_encoder *drm_enc) |
| 2222 | { |
| 2223 | struct sde_encoder_virt *sde_enc = NULL; |
| 2224 | int i, ret = 0; |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 2225 | struct msm_compression_info *comp_info = NULL; |
Jeykumar Sankaran | 6993462 | 2017-05-31 18:16:25 -0700 | [diff] [blame] | 2226 | struct drm_display_mode *cur_mode = NULL; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 2227 | struct msm_mode_info mode_info; |
Sandeep Panda | 318cff1 | 2017-10-20 13:16:03 +0530 | [diff] [blame] | 2228 | struct drm_connector *drm_conn = NULL; |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2229 | |
| 2230 | if (!drm_enc) { |
| 2231 | SDE_ERROR("invalid encoder\n"); |
| 2232 | return; |
| 2233 | } |
| 2234 | sde_enc = to_sde_encoder_virt(drm_enc); |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 2235 | |
| 2236 | ret = _sde_encoder_get_mode_info(drm_enc, &mode_info); |
| 2237 | if (ret) { |
| 2238 | SDE_ERROR_ENC(sde_enc, "failed to get mode info\n"); |
| 2239 | return; |
| 2240 | } |
| 2241 | |
| 2242 | comp_info = &mode_info.comp_info; |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 2243 | cur_mode = &sde_enc->base.crtc->state->adjusted_mode; |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2244 | |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 2245 | SDE_DEBUG_ENC(sde_enc, "\n"); |
Dhaval Patel | 1b5605b | 2017-07-26 18:19:50 -0700 | [diff] [blame] | 2246 | SDE_EVT32(DRMID(drm_enc), cur_mode->hdisplay, cur_mode->vdisplay); |
Jeykumar Sankaran | 6993462 | 2017-05-31 18:16:25 -0700 | [diff] [blame] | 2247 | |
Clarence Ip | a87f8ec | 2016-08-23 13:43:19 -0400 | [diff] [blame] | 2248 | sde_enc->cur_master = NULL; |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 2249 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 2250 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
| 2251 | |
| 2252 | if (phys && phys->ops.is_master && phys->ops.is_master(phys)) { |
| 2253 | SDE_DEBUG_ENC(sde_enc, "master is now idx %d\n", i); |
| 2254 | sde_enc->cur_master = phys; |
| 2255 | break; |
| 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | if (!sde_enc->cur_master) { |
| 2260 | SDE_ERROR("virt encoder has no master! num_phys %d\n", i); |
| 2261 | return; |
| 2262 | } |
| 2263 | |
| 2264 | ret = sde_encoder_resource_control(drm_enc, SDE_ENC_RC_EVENT_KICKOFF); |
| 2265 | if (ret) { |
| 2266 | SDE_ERROR_ENC(sde_enc, "sde resource control failed: %d\n", |
| 2267 | ret); |
| 2268 | return; |
| 2269 | } |
Dhaval Patel | 020f7e12 | 2016-11-15 14:39:18 -0800 | [diff] [blame] | 2270 | |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2271 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 2272 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 2273 | |
Jeykumar Sankaran | 6993462 | 2017-05-31 18:16:25 -0700 | [diff] [blame] | 2274 | if (!phys) |
| 2275 | continue; |
| 2276 | |
| 2277 | phys->comp_type = comp_info->comp_type; |
| 2278 | if (phys != sde_enc->cur_master) { |
| 2279 | /** |
| 2280 | * on DMS request, the encoder will be enabled |
| 2281 | * already. Invoke restore to reconfigure the |
| 2282 | * new mode. |
| 2283 | */ |
| 2284 | if (msm_is_mode_seamless_dms(cur_mode) && |
| 2285 | phys->ops.restore) |
| 2286 | phys->ops.restore(phys); |
| 2287 | else if (phys->ops.enable) |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 2288 | phys->ops.enable(phys); |
| 2289 | } |
Dhaval Patel | 010f517 | 2017-08-01 22:40:09 -0700 | [diff] [blame] | 2290 | |
| 2291 | if (sde_enc->misr_enable && (sde_enc->disp_info.capabilities & |
| 2292 | MSM_DISPLAY_CAP_VID_MODE) && phys->ops.setup_misr) |
| 2293 | phys->ops.setup_misr(phys, true, |
| 2294 | sde_enc->misr_frame_count); |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2295 | } |
Clarence Ip | a87f8ec | 2016-08-23 13:43:19 -0400 | [diff] [blame] | 2296 | |
Jeykumar Sankaran | 6993462 | 2017-05-31 18:16:25 -0700 | [diff] [blame] | 2297 | if (msm_is_mode_seamless_dms(cur_mode) && |
| 2298 | sde_enc->cur_master->ops.restore) |
| 2299 | sde_enc->cur_master->ops.restore(sde_enc->cur_master); |
| 2300 | else if (sde_enc->cur_master->ops.enable) |
Clarence Ip | a87f8ec | 2016-08-23 13:43:19 -0400 | [diff] [blame] | 2301 | sde_enc->cur_master->ops.enable(sde_enc->cur_master); |
Jeykumar Sankaran | 5c2f070 | 2017-03-09 18:03:15 -0800 | [diff] [blame] | 2302 | |
Veera Sundaram Sankaran | 82916e0 | 2017-03-29 18:44:22 -0700 | [diff] [blame] | 2303 | _sde_encoder_virt_enable_helper(drm_enc); |
Sandeep Panda | 318cff1 | 2017-10-20 13:16:03 +0530 | [diff] [blame] | 2304 | |
| 2305 | /* Enable ESD thread */ |
| 2306 | drm_conn = sde_enc->cur_master->connector; |
| 2307 | sde_connector_schedule_status_work(drm_conn, true); |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | static void sde_encoder_virt_disable(struct drm_encoder *drm_enc) |
| 2311 | { |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 2312 | struct sde_encoder_virt *sde_enc = NULL; |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 2313 | struct msm_drm_private *priv; |
| 2314 | struct sde_kms *sde_kms; |
Sandeep Panda | 318cff1 | 2017-10-20 13:16:03 +0530 | [diff] [blame] | 2315 | struct drm_connector *drm_conn = NULL; |
Clarence Ip | ed3327b | 2017-11-01 13:13:58 -0400 | [diff] [blame^] | 2316 | enum sde_intf_mode intf_mode; |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2317 | int i = 0; |
| 2318 | |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 2319 | if (!drm_enc) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 2320 | SDE_ERROR("invalid encoder\n"); |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 2321 | return; |
Lloyd Atkinson | 5217336c | 2016-09-15 18:21:18 -0400 | [diff] [blame] | 2322 | } else if (!drm_enc->dev) { |
| 2323 | SDE_ERROR("invalid dev\n"); |
| 2324 | return; |
| 2325 | } else if (!drm_enc->dev->dev_private) { |
| 2326 | SDE_ERROR("invalid dev_private\n"); |
| 2327 | return; |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | sde_enc = to_sde_encoder_virt(drm_enc); |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 2331 | SDE_DEBUG_ENC(sde_enc, "\n"); |
| 2332 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 2333 | priv = drm_enc->dev->dev_private; |
| 2334 | sde_kms = to_sde_kms(priv->kms); |
Clarence Ip | ed3327b | 2017-11-01 13:13:58 -0400 | [diff] [blame^] | 2335 | intf_mode = sde_encoder_get_intf_mode(drm_enc); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 2336 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 2337 | SDE_EVT32(DRMID(drm_enc)); |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 2338 | |
Sandeep Panda | 318cff1 | 2017-10-20 13:16:03 +0530 | [diff] [blame] | 2339 | /* Disable ESD thread */ |
| 2340 | drm_conn = sde_enc->cur_master->connector; |
| 2341 | sde_connector_schedule_status_work(drm_conn, false); |
| 2342 | |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 2343 | /* wait for idle */ |
| 2344 | sde_encoder_wait_for_event(drm_enc, MSM_ENC_TX_COMPLETE); |
| 2345 | |
Clarence Ip | ed3327b | 2017-11-01 13:13:58 -0400 | [diff] [blame^] | 2346 | /* |
| 2347 | * For primary command mode encoders, execute the resource control |
| 2348 | * pre-stop operations before the physical encoders are disabled, to |
| 2349 | * allow the rsc to transition its states properly. |
| 2350 | * |
| 2351 | * For other encoder types, rsc should not be enabled until after |
| 2352 | * they have been fully disabled, so delay the pre-stop operations |
| 2353 | * until after the physical disable calls have returned. |
| 2354 | */ |
| 2355 | if (sde_enc->disp_info.is_primary && intf_mode == INTF_MODE_CMD) { |
| 2356 | sde_encoder_resource_control(drm_enc, |
| 2357 | SDE_ENC_RC_EVENT_PRE_STOP); |
| 2358 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 2359 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 2360 | |
Clarence Ip | ed3327b | 2017-11-01 13:13:58 -0400 | [diff] [blame^] | 2361 | if (phys && phys->ops.disable) |
| 2362 | phys->ops.disable(phys); |
| 2363 | } |
| 2364 | } else { |
| 2365 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 2366 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2367 | |
Clarence Ip | ed3327b | 2017-11-01 13:13:58 -0400 | [diff] [blame^] | 2368 | if (phys && phys->ops.disable) |
| 2369 | phys->ops.disable(phys); |
| 2370 | } |
| 2371 | sde_encoder_resource_control(drm_enc, |
| 2372 | SDE_ENC_RC_EVENT_PRE_STOP); |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2373 | } |
| 2374 | |
Ingrid Gallardo | 2a2befb | 2017-08-07 15:02:51 -0700 | [diff] [blame] | 2375 | /* |
| 2376 | * disable dsc after the transfer is complete (for command mode) |
| 2377 | * and after physical encoder is disabled, to make sure timing |
| 2378 | * engine is already disabled (for video mode). |
| 2379 | */ |
| 2380 | _sde_encoder_dsc_disable(sde_enc); |
| 2381 | |
Lloyd Atkinson | 03810e3 | 2017-03-14 13:38:06 -0700 | [diff] [blame] | 2382 | /* after phys waits for frame-done, should be no more frames pending */ |
| 2383 | if (atomic_xchg(&sde_enc->frame_done_timeout, 0)) { |
| 2384 | SDE_ERROR("enc%d timeout pending\n", drm_enc->base.id); |
| 2385 | del_timer_sync(&sde_enc->frame_done_timer); |
| 2386 | } |
| 2387 | |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 2388 | sde_encoder_resource_control(drm_enc, SDE_ENC_RC_EVENT_STOP); |
| 2389 | |
Lloyd Atkinson | 07099ad | 2017-08-15 13:32:24 -0400 | [diff] [blame] | 2390 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 2391 | if (sde_enc->phys_encs[i]) |
| 2392 | sde_enc->phys_encs[i]->connector = NULL; |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 2393 | } |
| 2394 | |
Lloyd Atkinson | 07099ad | 2017-08-15 13:32:24 -0400 | [diff] [blame] | 2395 | sde_enc->cur_master = NULL; |
| 2396 | |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 2397 | SDE_DEBUG_ENC(sde_enc, "encoder disabled\n"); |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 2398 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 2399 | sde_rm_release(&sde_kms->rm, drm_enc); |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2400 | } |
| 2401 | |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2402 | static enum sde_intf sde_encoder_get_intf(struct sde_mdss_cfg *catalog, |
Lloyd Atkinson | 9a84031 | 2016-06-26 10:11:08 -0400 | [diff] [blame] | 2403 | enum sde_intf_type type, u32 controller_id) |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2404 | { |
| 2405 | int i = 0; |
| 2406 | |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2407 | for (i = 0; i < catalog->intf_count; i++) { |
| 2408 | if (catalog->intf[i].type == type |
Lloyd Atkinson | 9a84031 | 2016-06-26 10:11:08 -0400 | [diff] [blame] | 2409 | && catalog->intf[i].controller_id == controller_id) { |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2410 | return catalog->intf[i].id; |
| 2411 | } |
| 2412 | } |
| 2413 | |
| 2414 | return INTF_MAX; |
| 2415 | } |
| 2416 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 2417 | static enum sde_wb sde_encoder_get_wb(struct sde_mdss_cfg *catalog, |
| 2418 | enum sde_intf_type type, u32 controller_id) |
| 2419 | { |
| 2420 | if (controller_id < catalog->wb_count) |
| 2421 | return catalog->wb[controller_id].id; |
| 2422 | |
| 2423 | return WB_MAX; |
| 2424 | } |
| 2425 | |
Dhaval Patel | 81e8788 | 2016-10-19 21:41:56 -0700 | [diff] [blame] | 2426 | static void sde_encoder_vblank_callback(struct drm_encoder *drm_enc, |
| 2427 | struct sde_encoder_phys *phy_enc) |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2428 | { |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 2429 | struct sde_encoder_virt *sde_enc = NULL; |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2430 | unsigned long lock_flags; |
| 2431 | |
Dhaval Patel | 81e8788 | 2016-10-19 21:41:56 -0700 | [diff] [blame] | 2432 | if (!drm_enc || !phy_enc) |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 2433 | return; |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 2434 | |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 2435 | SDE_ATRACE_BEGIN("encoder_vblank_callback"); |
Lloyd Atkinson | f30546e | 2016-06-26 10:08:25 -0400 | [diff] [blame] | 2436 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 2437 | |
Lloyd Atkinson | 7d07094 | 2016-07-26 18:35:12 -0400 | [diff] [blame] | 2438 | spin_lock_irqsave(&sde_enc->enc_spinlock, lock_flags); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 2439 | if (sde_enc->crtc_vblank_cb) |
| 2440 | sde_enc->crtc_vblank_cb(sde_enc->crtc_vblank_cb_data); |
Lloyd Atkinson | 7d07094 | 2016-07-26 18:35:12 -0400 | [diff] [blame] | 2441 | spin_unlock_irqrestore(&sde_enc->enc_spinlock, lock_flags); |
Dhaval Patel | 81e8788 | 2016-10-19 21:41:56 -0700 | [diff] [blame] | 2442 | |
| 2443 | atomic_inc(&phy_enc->vsync_cnt); |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 2444 | SDE_ATRACE_END("encoder_vblank_callback"); |
Dhaval Patel | 81e8788 | 2016-10-19 21:41:56 -0700 | [diff] [blame] | 2445 | } |
| 2446 | |
| 2447 | static void sde_encoder_underrun_callback(struct drm_encoder *drm_enc, |
| 2448 | struct sde_encoder_phys *phy_enc) |
| 2449 | { |
| 2450 | if (!phy_enc) |
| 2451 | return; |
| 2452 | |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 2453 | SDE_ATRACE_BEGIN("encoder_underrun_callback"); |
Dhaval Patel | 81e8788 | 2016-10-19 21:41:56 -0700 | [diff] [blame] | 2454 | atomic_inc(&phy_enc->underrun_cnt); |
Lloyd Atkinson | 64b07dd | 2016-12-12 17:10:57 -0500 | [diff] [blame] | 2455 | SDE_EVT32(DRMID(drm_enc), atomic_read(&phy_enc->underrun_cnt)); |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 2456 | SDE_ATRACE_END("encoder_underrun_callback"); |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 2457 | } |
| 2458 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 2459 | void sde_encoder_register_vblank_callback(struct drm_encoder *drm_enc, |
| 2460 | void (*vbl_cb)(void *), void *vbl_data) |
| 2461 | { |
| 2462 | struct sde_encoder_virt *sde_enc = to_sde_encoder_virt(drm_enc); |
| 2463 | unsigned long lock_flags; |
| 2464 | bool enable; |
| 2465 | int i; |
| 2466 | |
| 2467 | enable = vbl_cb ? true : false; |
| 2468 | |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 2469 | if (!drm_enc) { |
| 2470 | SDE_ERROR("invalid encoder\n"); |
| 2471 | return; |
| 2472 | } |
| 2473 | SDE_DEBUG_ENC(sde_enc, "\n"); |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 2474 | SDE_EVT32(DRMID(drm_enc), enable); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 2475 | |
Lloyd Atkinson | 7d07094 | 2016-07-26 18:35:12 -0400 | [diff] [blame] | 2476 | spin_lock_irqsave(&sde_enc->enc_spinlock, lock_flags); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 2477 | sde_enc->crtc_vblank_cb = vbl_cb; |
| 2478 | sde_enc->crtc_vblank_cb_data = vbl_data; |
Lloyd Atkinson | 7d07094 | 2016-07-26 18:35:12 -0400 | [diff] [blame] | 2479 | spin_unlock_irqrestore(&sde_enc->enc_spinlock, lock_flags); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 2480 | |
| 2481 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 2482 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
| 2483 | |
| 2484 | if (phys && phys->ops.control_vblank_irq) |
| 2485 | phys->ops.control_vblank_irq(phys, enable); |
| 2486 | } |
Veera Sundaram Sankaran | df79cc9 | 2017-10-10 22:32:46 -0700 | [diff] [blame] | 2487 | sde_enc->vblank_enabled = enable; |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 2488 | } |
| 2489 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2490 | void sde_encoder_register_frame_event_callback(struct drm_encoder *drm_enc, |
| 2491 | void (*frame_event_cb)(void *, u32 event), |
| 2492 | void *frame_event_cb_data) |
| 2493 | { |
| 2494 | struct sde_encoder_virt *sde_enc = to_sde_encoder_virt(drm_enc); |
| 2495 | unsigned long lock_flags; |
| 2496 | bool enable; |
| 2497 | |
| 2498 | enable = frame_event_cb ? true : false; |
| 2499 | |
| 2500 | if (!drm_enc) { |
| 2501 | SDE_ERROR("invalid encoder\n"); |
| 2502 | return; |
| 2503 | } |
| 2504 | SDE_DEBUG_ENC(sde_enc, "\n"); |
| 2505 | SDE_EVT32(DRMID(drm_enc), enable, 0); |
| 2506 | |
| 2507 | spin_lock_irqsave(&sde_enc->enc_spinlock, lock_flags); |
| 2508 | sde_enc->crtc_frame_event_cb = frame_event_cb; |
| 2509 | sde_enc->crtc_frame_event_cb_data = frame_event_cb_data; |
| 2510 | spin_unlock_irqrestore(&sde_enc->enc_spinlock, lock_flags); |
| 2511 | } |
| 2512 | |
| 2513 | static void sde_encoder_frame_done_callback( |
| 2514 | struct drm_encoder *drm_enc, |
| 2515 | struct sde_encoder_phys *ready_phys, u32 event) |
| 2516 | { |
| 2517 | struct sde_encoder_virt *sde_enc = to_sde_encoder_virt(drm_enc); |
| 2518 | unsigned int i; |
| 2519 | |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 2520 | if (event & (SDE_ENCODER_FRAME_EVENT_DONE |
| 2521 | | SDE_ENCODER_FRAME_EVENT_ERROR |
| 2522 | | SDE_ENCODER_FRAME_EVENT_PANEL_DEAD)) { |
Lloyd Atkinson | d0fedd0 | 2017-03-01 13:25:40 -0500 | [diff] [blame] | 2523 | |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 2524 | if (!sde_enc->frame_busy_mask[0]) { |
| 2525 | /** |
| 2526 | * suppress frame_done without waiter, |
| 2527 | * likely autorefresh |
| 2528 | */ |
| 2529 | SDE_EVT32(DRMID(drm_enc), event, ready_phys->intf_idx); |
| 2530 | return; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2531 | } |
| 2532 | |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 2533 | /* One of the physical encoders has become idle */ |
| 2534 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 2535 | if (sde_enc->phys_encs[i] == ready_phys) { |
| 2536 | clear_bit(i, sde_enc->frame_busy_mask); |
| 2537 | SDE_EVT32_VERBOSE(DRMID(drm_enc), i, |
| 2538 | sde_enc->frame_busy_mask[0]); |
| 2539 | } |
| 2540 | } |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2541 | |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 2542 | if (!sde_enc->frame_busy_mask[0]) { |
| 2543 | atomic_set(&sde_enc->frame_done_timeout, 0); |
| 2544 | del_timer(&sde_enc->frame_done_timer); |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 2545 | |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 2546 | sde_encoder_resource_control(drm_enc, |
| 2547 | SDE_ENC_RC_EVENT_FRAME_DONE); |
| 2548 | |
| 2549 | if (sde_enc->crtc_frame_event_cb) |
| 2550 | sde_enc->crtc_frame_event_cb( |
| 2551 | sde_enc->crtc_frame_event_cb_data, |
| 2552 | event); |
| 2553 | } |
| 2554 | } else { |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2555 | if (sde_enc->crtc_frame_event_cb) |
| 2556 | sde_enc->crtc_frame_event_cb( |
Ingrid Gallardo | 79b4439 | 2017-05-30 16:30:52 -0700 | [diff] [blame] | 2557 | sde_enc->crtc_frame_event_cb_data, event); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 2558 | } |
| 2559 | } |
| 2560 | |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 2561 | static void sde_encoder_off_work(struct kthread_work *work) |
| 2562 | { |
| 2563 | struct sde_encoder_virt *sde_enc = container_of(work, |
| 2564 | struct sde_encoder_virt, delayed_off_work.work); |
| 2565 | |
| 2566 | if (!sde_enc) { |
| 2567 | SDE_ERROR("invalid sde encoder\n"); |
| 2568 | return; |
| 2569 | } |
| 2570 | |
| 2571 | sde_encoder_resource_control(&sde_enc->base, |
| 2572 | SDE_ENC_RC_EVENT_ENTER_IDLE); |
| 2573 | |
| 2574 | sde_encoder_frame_done_callback(&sde_enc->base, NULL, |
| 2575 | SDE_ENCODER_FRAME_EVENT_IDLE); |
| 2576 | } |
| 2577 | |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2578 | /** |
| 2579 | * _sde_encoder_trigger_flush - trigger flush for a physical encoder |
| 2580 | * drm_enc: Pointer to drm encoder structure |
| 2581 | * phys: Pointer to physical encoder structure |
| 2582 | * extra_flush_bits: Additional bit mask to include in flush trigger |
| 2583 | */ |
| 2584 | static inline void _sde_encoder_trigger_flush(struct drm_encoder *drm_enc, |
| 2585 | struct sde_encoder_phys *phys, uint32_t extra_flush_bits) |
| 2586 | { |
| 2587 | struct sde_hw_ctl *ctl; |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 2588 | int pending_kickoff_cnt; |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2589 | |
| 2590 | if (!drm_enc || !phys) { |
| 2591 | SDE_ERROR("invalid argument(s), drm_enc %d, phys_enc %d\n", |
| 2592 | drm_enc != 0, phys != 0); |
| 2593 | return; |
| 2594 | } |
| 2595 | |
Lloyd Atkinson | 6a5359d | 2017-06-21 10:18:08 -0400 | [diff] [blame] | 2596 | if (!phys->hw_pp) { |
| 2597 | SDE_ERROR("invalid pingpong hw\n"); |
| 2598 | return; |
| 2599 | } |
| 2600 | |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2601 | ctl = phys->hw_ctl; |
Alan Kwong | 4212dd4 | 2017-09-19 17:22:33 -0400 | [diff] [blame] | 2602 | if (!ctl || !phys->ops.trigger_flush) { |
| 2603 | SDE_ERROR("missing ctl/trigger cb\n"); |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2604 | return; |
| 2605 | } |
| 2606 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 2607 | if (phys->split_role == ENC_ROLE_SKIP) { |
| 2608 | SDE_DEBUG_ENC(to_sde_encoder_virt(phys->parent), |
| 2609 | "skip flush pp%d ctl%d\n", |
| 2610 | phys->hw_pp->idx - PINGPONG_0, |
| 2611 | ctl->idx - CTL_0); |
| 2612 | return; |
| 2613 | } |
| 2614 | |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 2615 | pending_kickoff_cnt = sde_encoder_phys_inc_pending(phys); |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 2616 | |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 2617 | if (phys->ops.is_master && phys->ops.is_master(phys)) |
| 2618 | atomic_inc(&phys->pending_retire_fence_cnt); |
| 2619 | |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2620 | if (extra_flush_bits && ctl->ops.update_pending_flush) |
| 2621 | ctl->ops.update_pending_flush(ctl, extra_flush_bits); |
| 2622 | |
Alan Kwong | 4212dd4 | 2017-09-19 17:22:33 -0400 | [diff] [blame] | 2623 | phys->ops.trigger_flush(phys); |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 2624 | |
| 2625 | if (ctl->ops.get_pending_flush) |
Clarence Ip | 569d5af | 2017-10-14 21:09:01 -0400 | [diff] [blame] | 2626 | SDE_EVT32(DRMID(drm_enc), phys->intf_idx - INTF_0, |
| 2627 | pending_kickoff_cnt, ctl->idx - CTL_0, |
| 2628 | ctl->ops.get_pending_flush(ctl)); |
Dhaval Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 2629 | else |
Clarence Ip | 569d5af | 2017-10-14 21:09:01 -0400 | [diff] [blame] | 2630 | SDE_EVT32(DRMID(drm_enc), phys->intf_idx - INTF_0, |
| 2631 | ctl->idx - CTL_0, pending_kickoff_cnt); |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2632 | } |
| 2633 | |
| 2634 | /** |
| 2635 | * _sde_encoder_trigger_start - trigger start for a physical encoder |
| 2636 | * phys: Pointer to physical encoder structure |
| 2637 | */ |
| 2638 | static inline void _sde_encoder_trigger_start(struct sde_encoder_phys *phys) |
| 2639 | { |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 2640 | struct sde_hw_ctl *ctl; |
| 2641 | |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2642 | if (!phys) { |
Lloyd Atkinson | 6a5359d | 2017-06-21 10:18:08 -0400 | [diff] [blame] | 2643 | SDE_ERROR("invalid argument(s)\n"); |
| 2644 | return; |
| 2645 | } |
| 2646 | |
| 2647 | if (!phys->hw_pp) { |
| 2648 | SDE_ERROR("invalid pingpong hw\n"); |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2649 | return; |
| 2650 | } |
| 2651 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 2652 | ctl = phys->hw_ctl; |
| 2653 | if (phys->split_role == ENC_ROLE_SKIP) { |
| 2654 | SDE_DEBUG_ENC(to_sde_encoder_virt(phys->parent), |
| 2655 | "skip start pp%d ctl%d\n", |
| 2656 | phys->hw_pp->idx - PINGPONG_0, |
| 2657 | ctl->idx - CTL_0); |
| 2658 | return; |
| 2659 | } |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2660 | if (phys->ops.trigger_start && phys->enable_state != SDE_ENC_DISABLED) |
| 2661 | phys->ops.trigger_start(phys); |
| 2662 | } |
| 2663 | |
Alan Kwong | 4212dd4 | 2017-09-19 17:22:33 -0400 | [diff] [blame] | 2664 | void sde_encoder_helper_trigger_flush(struct sde_encoder_phys *phys_enc) |
| 2665 | { |
| 2666 | struct sde_hw_ctl *ctl; |
| 2667 | |
| 2668 | if (!phys_enc) { |
| 2669 | SDE_ERROR("invalid encoder\n"); |
| 2670 | return; |
| 2671 | } |
| 2672 | |
| 2673 | ctl = phys_enc->hw_ctl; |
| 2674 | if (ctl && ctl->ops.trigger_flush) |
| 2675 | ctl->ops.trigger_flush(ctl); |
| 2676 | } |
| 2677 | |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2678 | void sde_encoder_helper_trigger_start(struct sde_encoder_phys *phys_enc) |
| 2679 | { |
| 2680 | struct sde_hw_ctl *ctl; |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2681 | |
| 2682 | if (!phys_enc) { |
| 2683 | SDE_ERROR("invalid encoder\n"); |
| 2684 | return; |
| 2685 | } |
| 2686 | |
| 2687 | ctl = phys_enc->hw_ctl; |
| 2688 | if (ctl && ctl->ops.trigger_start) { |
| 2689 | ctl->ops.trigger_start(ctl); |
Clarence Ip | 569d5af | 2017-10-14 21:09:01 -0400 | [diff] [blame] | 2690 | SDE_EVT32(DRMID(phys_enc->parent), ctl->idx - CTL_0); |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2691 | } |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2692 | } |
| 2693 | |
Raviteja Tamatam | 3eebe96 | 2017-10-26 09:55:24 +0530 | [diff] [blame] | 2694 | static int _sde_encoder_wait_timeout(int32_t drm_id, int32_t hw_id, |
| 2695 | s64 timeout_ms, struct sde_encoder_wait_info *info) |
Lloyd Atkinson | aa0dce9 | 2016-11-23 20:16:47 -0500 | [diff] [blame] | 2696 | { |
| 2697 | int rc = 0; |
Raviteja Tamatam | 3eebe96 | 2017-10-26 09:55:24 +0530 | [diff] [blame] | 2698 | s64 wait_time_jiffies = msecs_to_jiffies(timeout_ms); |
| 2699 | ktime_t cur_ktime; |
| 2700 | ktime_t exp_ktime = ktime_add_ms(ktime_get(), timeout_ms); |
Lloyd Atkinson | aa0dce9 | 2016-11-23 20:16:47 -0500 | [diff] [blame] | 2701 | |
| 2702 | do { |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 2703 | rc = wait_event_timeout(*(info->wq), |
Raviteja Tamatam | 3eebe96 | 2017-10-26 09:55:24 +0530 | [diff] [blame] | 2704 | atomic_read(info->atomic_cnt) == 0, wait_time_jiffies); |
| 2705 | cur_ktime = ktime_get(); |
Lloyd Atkinson | aa0dce9 | 2016-11-23 20:16:47 -0500 | [diff] [blame] | 2706 | |
Raviteja Tamatam | 3eebe96 | 2017-10-26 09:55:24 +0530 | [diff] [blame] | 2707 | SDE_EVT32(drm_id, hw_id, rc, ktime_to_ms(cur_ktime), |
| 2708 | timeout_ms, atomic_read(info->atomic_cnt)); |
Lloyd Atkinson | aa0dce9 | 2016-11-23 20:16:47 -0500 | [diff] [blame] | 2709 | /* If we timed out, counter is valid and time is less, wait again */ |
Lloyd Atkinson | 05ef823 | 2017-03-08 16:35:36 -0500 | [diff] [blame] | 2710 | } while (atomic_read(info->atomic_cnt) && (rc == 0) && |
Raviteja Tamatam | 3eebe96 | 2017-10-26 09:55:24 +0530 | [diff] [blame] | 2711 | (ktime_compare_safe(exp_ktime, cur_ktime) > 0)); |
| 2712 | |
| 2713 | return rc; |
| 2714 | } |
| 2715 | |
| 2716 | int sde_encoder_helper_wait_event_timeout(int32_t drm_id, int32_t hw_id, |
| 2717 | struct sde_encoder_wait_info *info) |
| 2718 | { |
| 2719 | int rc; |
| 2720 | ktime_t exp_ktime = ktime_add_ms(ktime_get(), info->timeout_ms); |
| 2721 | |
| 2722 | rc = _sde_encoder_wait_timeout(drm_id, hw_id, info->timeout_ms, info); |
| 2723 | |
| 2724 | /** |
| 2725 | * handle disabled irq case where timer irq is also delayed. |
| 2726 | * wait for additional timeout of FAULT_TOLERENCE_WAIT_IN_MS |
| 2727 | * if it event_timeout expired late detected. |
| 2728 | */ |
| 2729 | if (atomic_read(info->atomic_cnt) && (!rc) && |
| 2730 | (ktime_compare_safe(ktime_get(), ktime_add_ms(exp_ktime, |
| 2731 | FAULT_TOLERENCE_DELTA_IN_MS)) > 0)) |
| 2732 | rc = _sde_encoder_wait_timeout(drm_id, hw_id, |
| 2733 | FAULT_TOLERENCE_WAIT_IN_MS, info); |
Lloyd Atkinson | aa0dce9 | 2016-11-23 20:16:47 -0500 | [diff] [blame] | 2734 | |
| 2735 | return rc; |
| 2736 | } |
| 2737 | |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 2738 | void sde_encoder_helper_hw_reset(struct sde_encoder_phys *phys_enc) |
| 2739 | { |
| 2740 | struct sde_encoder_virt *sde_enc; |
| 2741 | struct sde_connector *sde_con; |
| 2742 | void *sde_con_disp; |
| 2743 | struct sde_hw_ctl *ctl; |
| 2744 | int rc; |
| 2745 | |
| 2746 | if (!phys_enc) { |
| 2747 | SDE_ERROR("invalid encoder\n"); |
| 2748 | return; |
| 2749 | } |
| 2750 | sde_enc = to_sde_encoder_virt(phys_enc->parent); |
| 2751 | ctl = phys_enc->hw_ctl; |
| 2752 | |
| 2753 | if (!ctl || !ctl->ops.reset) |
| 2754 | return; |
| 2755 | |
| 2756 | SDE_DEBUG_ENC(sde_enc, "ctl %d reset\n", ctl->idx); |
| 2757 | SDE_EVT32(DRMID(phys_enc->parent), ctl->idx); |
| 2758 | |
| 2759 | if (phys_enc->ops.is_master && phys_enc->ops.is_master(phys_enc) && |
| 2760 | phys_enc->connector) { |
| 2761 | sde_con = to_sde_connector(phys_enc->connector); |
| 2762 | sde_con_disp = sde_connector_get_display(phys_enc->connector); |
| 2763 | |
| 2764 | if (sde_con->ops.soft_reset) { |
| 2765 | rc = sde_con->ops.soft_reset(sde_con_disp); |
| 2766 | if (rc) { |
| 2767 | SDE_ERROR_ENC(sde_enc, |
| 2768 | "connector soft reset failure\n"); |
Dhaval Patel | 7ca510f | 2017-07-12 12:57:37 -0700 | [diff] [blame] | 2769 | SDE_DBG_DUMP("all", "dbg_bus", "vbif_dbg_bus", |
| 2770 | "panic"); |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 2771 | } |
| 2772 | } |
| 2773 | } |
| 2774 | |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 2775 | phys_enc->enable_state = SDE_ENC_ENABLED; |
| 2776 | } |
| 2777 | |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2778 | /** |
| 2779 | * _sde_encoder_kickoff_phys - handle physical encoder kickoff |
| 2780 | * Iterate through the physical encoders and perform consolidated flush |
| 2781 | * and/or control start triggering as needed. This is done in the virtual |
| 2782 | * encoder rather than the individual physical ones in order to handle |
| 2783 | * use cases that require visibility into multiple physical encoders at |
| 2784 | * a time. |
| 2785 | * sde_enc: Pointer to virtual encoder structure |
| 2786 | */ |
| 2787 | static void _sde_encoder_kickoff_phys(struct sde_encoder_virt *sde_enc) |
| 2788 | { |
| 2789 | struct sde_hw_ctl *ctl; |
| 2790 | uint32_t i, pending_flush; |
Lloyd Atkinson | 7d07094 | 2016-07-26 18:35:12 -0400 | [diff] [blame] | 2791 | unsigned long lock_flags; |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2792 | |
| 2793 | if (!sde_enc) { |
| 2794 | SDE_ERROR("invalid encoder\n"); |
| 2795 | return; |
| 2796 | } |
| 2797 | |
| 2798 | pending_flush = 0x0; |
| 2799 | |
Ingrid Gallardo | 61210ea | 2017-10-17 17:29:31 -0700 | [diff] [blame] | 2800 | /* |
| 2801 | * Trigger LUT DMA flush, this might need a wait, so we need |
| 2802 | * to do this outside of the atomic context |
| 2803 | */ |
| 2804 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 2805 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
| 2806 | bool wait_for_dma = false; |
| 2807 | |
| 2808 | if (!phys || phys->enable_state == SDE_ENC_DISABLED) |
| 2809 | continue; |
| 2810 | |
| 2811 | ctl = phys->hw_ctl; |
| 2812 | if (!ctl) |
| 2813 | continue; |
| 2814 | |
| 2815 | if (phys->ops.wait_dma_trigger) |
| 2816 | wait_for_dma = phys->ops.wait_dma_trigger(phys); |
| 2817 | |
| 2818 | if (phys->hw_ctl->ops.reg_dma_flush) |
| 2819 | phys->hw_ctl->ops.reg_dma_flush(phys->hw_ctl, |
| 2820 | wait_for_dma); |
| 2821 | } |
| 2822 | |
Lloyd Atkinson | 7d07094 | 2016-07-26 18:35:12 -0400 | [diff] [blame] | 2823 | /* update pending counts and trigger kickoff ctl flush atomically */ |
| 2824 | spin_lock_irqsave(&sde_enc->enc_spinlock, lock_flags); |
| 2825 | |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2826 | /* don't perform flush/start operations for slave encoders */ |
| 2827 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 2828 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 2829 | enum sde_rm_topology_name topology = SDE_RM_TOPOLOGY_NONE; |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 2830 | |
Lloyd Atkinson | 7d07094 | 2016-07-26 18:35:12 -0400 | [diff] [blame] | 2831 | if (!phys || phys->enable_state == SDE_ENC_DISABLED) |
| 2832 | continue; |
| 2833 | |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2834 | ctl = phys->hw_ctl; |
Lloyd Atkinson | 7d07094 | 2016-07-26 18:35:12 -0400 | [diff] [blame] | 2835 | if (!ctl) |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2836 | continue; |
| 2837 | |
Lloyd Atkinson | 8c50e15 | 2017-02-01 19:03:17 -0500 | [diff] [blame] | 2838 | if (phys->connector) |
| 2839 | topology = sde_connector_get_topology_name( |
| 2840 | phys->connector); |
| 2841 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 2842 | /* |
| 2843 | * don't wait on ppsplit slaves or skipped encoders because |
| 2844 | * they dont receive irqs |
| 2845 | */ |
Lloyd Atkinson | 8c50e15 | 2017-02-01 19:03:17 -0500 | [diff] [blame] | 2846 | if (!(topology == SDE_RM_TOPOLOGY_PPSPLIT && |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 2847 | phys->split_role == ENC_ROLE_SLAVE) && |
| 2848 | phys->split_role != ENC_ROLE_SKIP) |
Lloyd Atkinson | 8c50e15 | 2017-02-01 19:03:17 -0500 | [diff] [blame] | 2849 | set_bit(i, sde_enc->frame_busy_mask); |
Ingrid Gallardo | 61210ea | 2017-10-17 17:29:31 -0700 | [diff] [blame] | 2850 | |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 2851 | if (!phys->ops.needs_single_flush || |
| 2852 | !phys->ops.needs_single_flush(phys)) |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2853 | _sde_encoder_trigger_flush(&sde_enc->base, phys, 0x0); |
| 2854 | else if (ctl->ops.get_pending_flush) |
| 2855 | pending_flush |= ctl->ops.get_pending_flush(ctl); |
| 2856 | } |
| 2857 | |
| 2858 | /* for split flush, combine pending flush masks and send to master */ |
| 2859 | if (pending_flush && sde_enc->cur_master) { |
| 2860 | _sde_encoder_trigger_flush( |
| 2861 | &sde_enc->base, |
| 2862 | sde_enc->cur_master, |
| 2863 | pending_flush); |
| 2864 | } |
| 2865 | |
| 2866 | _sde_encoder_trigger_start(sde_enc->cur_master); |
Lloyd Atkinson | 7d07094 | 2016-07-26 18:35:12 -0400 | [diff] [blame] | 2867 | |
| 2868 | spin_unlock_irqrestore(&sde_enc->enc_spinlock, lock_flags); |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 2869 | } |
| 2870 | |
Lloyd Atkinson | 66e7dde | 2017-02-08 15:52:53 -0500 | [diff] [blame] | 2871 | static void _sde_encoder_ppsplit_swap_intf_for_right_only_update( |
| 2872 | struct drm_encoder *drm_enc, |
| 2873 | unsigned long *affected_displays, |
| 2874 | int num_active_phys) |
| 2875 | { |
| 2876 | struct sde_encoder_virt *sde_enc; |
| 2877 | struct sde_encoder_phys *master; |
| 2878 | enum sde_rm_topology_name topology; |
| 2879 | bool is_right_only; |
| 2880 | |
| 2881 | if (!drm_enc || !affected_displays) |
| 2882 | return; |
| 2883 | |
| 2884 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 2885 | master = sde_enc->cur_master; |
| 2886 | if (!master || !master->connector) |
| 2887 | return; |
| 2888 | |
| 2889 | topology = sde_connector_get_topology_name(master->connector); |
| 2890 | if (topology != SDE_RM_TOPOLOGY_PPSPLIT) |
| 2891 | return; |
| 2892 | |
| 2893 | /* |
| 2894 | * For pingpong split, the slave pingpong won't generate IRQs. For |
| 2895 | * right-only updates, we can't swap pingpongs, or simply swap the |
| 2896 | * master/slave assignment, we actually have to swap the interfaces |
| 2897 | * so that the master physical encoder will use a pingpong/interface |
| 2898 | * that generates irqs on which to wait. |
| 2899 | */ |
| 2900 | is_right_only = !test_bit(0, affected_displays) && |
| 2901 | test_bit(1, affected_displays); |
| 2902 | |
| 2903 | if (is_right_only && !sde_enc->intfs_swapped) { |
| 2904 | /* right-only update swap interfaces */ |
| 2905 | swap(sde_enc->phys_encs[0]->intf_idx, |
| 2906 | sde_enc->phys_encs[1]->intf_idx); |
| 2907 | sde_enc->intfs_swapped = true; |
| 2908 | } else if (!is_right_only && sde_enc->intfs_swapped) { |
| 2909 | /* left-only or full update, swap back */ |
| 2910 | swap(sde_enc->phys_encs[0]->intf_idx, |
| 2911 | sde_enc->phys_encs[1]->intf_idx); |
| 2912 | sde_enc->intfs_swapped = false; |
| 2913 | } |
| 2914 | |
| 2915 | SDE_DEBUG_ENC(sde_enc, |
| 2916 | "right_only %d swapped %d phys0->intf%d, phys1->intf%d\n", |
| 2917 | is_right_only, sde_enc->intfs_swapped, |
| 2918 | sde_enc->phys_encs[0]->intf_idx - INTF_0, |
| 2919 | sde_enc->phys_encs[1]->intf_idx - INTF_0); |
| 2920 | SDE_EVT32(DRMID(drm_enc), is_right_only, sde_enc->intfs_swapped, |
| 2921 | sde_enc->phys_encs[0]->intf_idx - INTF_0, |
| 2922 | sde_enc->phys_encs[1]->intf_idx - INTF_0, |
| 2923 | *affected_displays); |
| 2924 | |
| 2925 | /* ppsplit always uses master since ppslave invalid for irqs*/ |
| 2926 | if (num_active_phys == 1) |
| 2927 | *affected_displays = BIT(0); |
| 2928 | } |
| 2929 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 2930 | static void _sde_encoder_update_master(struct drm_encoder *drm_enc, |
| 2931 | struct sde_encoder_kickoff_params *params) |
| 2932 | { |
| 2933 | struct sde_encoder_virt *sde_enc; |
| 2934 | struct sde_encoder_phys *phys; |
| 2935 | int i, num_active_phys; |
| 2936 | bool master_assigned = false; |
| 2937 | |
| 2938 | if (!drm_enc || !params) |
| 2939 | return; |
| 2940 | |
| 2941 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 2942 | |
| 2943 | if (sde_enc->num_phys_encs <= 1) |
| 2944 | return; |
| 2945 | |
| 2946 | /* count bits set */ |
| 2947 | num_active_phys = hweight_long(params->affected_displays); |
| 2948 | |
| 2949 | SDE_DEBUG_ENC(sde_enc, "affected_displays 0x%lx num_active_phys %d\n", |
| 2950 | params->affected_displays, num_active_phys); |
| 2951 | |
Lloyd Atkinson | 66e7dde | 2017-02-08 15:52:53 -0500 | [diff] [blame] | 2952 | /* for left/right only update, ppsplit master switches interface */ |
| 2953 | _sde_encoder_ppsplit_swap_intf_for_right_only_update(drm_enc, |
| 2954 | ¶ms->affected_displays, num_active_phys); |
| 2955 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 2956 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 2957 | enum sde_enc_split_role prv_role, new_role; |
| 2958 | bool active; |
| 2959 | |
| 2960 | phys = sde_enc->phys_encs[i]; |
Lloyd Atkinson | 6a5359d | 2017-06-21 10:18:08 -0400 | [diff] [blame] | 2961 | if (!phys || !phys->ops.update_split_role || !phys->hw_pp) |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 2962 | continue; |
| 2963 | |
| 2964 | active = test_bit(i, ¶ms->affected_displays); |
| 2965 | prv_role = phys->split_role; |
| 2966 | |
| 2967 | if (active && num_active_phys == 1) |
| 2968 | new_role = ENC_ROLE_SOLO; |
| 2969 | else if (active && !master_assigned) |
| 2970 | new_role = ENC_ROLE_MASTER; |
| 2971 | else if (active) |
| 2972 | new_role = ENC_ROLE_SLAVE; |
| 2973 | else |
| 2974 | new_role = ENC_ROLE_SKIP; |
| 2975 | |
| 2976 | phys->ops.update_split_role(phys, new_role); |
| 2977 | if (new_role == ENC_ROLE_SOLO || new_role == ENC_ROLE_MASTER) { |
| 2978 | sde_enc->cur_master = phys; |
| 2979 | master_assigned = true; |
| 2980 | } |
| 2981 | |
| 2982 | SDE_DEBUG_ENC(sde_enc, "pp %d role prv %d new %d active %d\n", |
| 2983 | phys->hw_pp->idx - PINGPONG_0, prv_role, |
| 2984 | phys->split_role, active); |
Lloyd Atkinson | 66e7dde | 2017-02-08 15:52:53 -0500 | [diff] [blame] | 2985 | SDE_EVT32(DRMID(drm_enc), params->affected_displays, |
| 2986 | phys->hw_pp->idx - PINGPONG_0, prv_role, |
| 2987 | phys->split_role, active, num_active_phys); |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 2988 | } |
| 2989 | } |
| 2990 | |
Sravanthi Kollukuduru | 59d431a | 2017-07-05 00:10:41 +0530 | [diff] [blame] | 2991 | bool sde_encoder_check_mode(struct drm_encoder *drm_enc, u32 mode) |
Veera Sundaram Sankaran | 2c748e6 | 2017-06-13 17:01:48 -0700 | [diff] [blame] | 2992 | { |
| 2993 | struct sde_encoder_virt *sde_enc; |
| 2994 | struct msm_display_info *disp_info; |
| 2995 | |
| 2996 | if (!drm_enc) { |
| 2997 | SDE_ERROR("invalid encoder\n"); |
| 2998 | return false; |
| 2999 | } |
| 3000 | |
| 3001 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 3002 | disp_info = &sde_enc->disp_info; |
| 3003 | |
Sravanthi Kollukuduru | 59d431a | 2017-07-05 00:10:41 +0530 | [diff] [blame] | 3004 | return (disp_info->capabilities & mode); |
Veera Sundaram Sankaran | 2c748e6 | 2017-06-13 17:01:48 -0700 | [diff] [blame] | 3005 | } |
| 3006 | |
Dhaval Patel | 0e558f4 | 2017-04-30 00:51:40 -0700 | [diff] [blame] | 3007 | void sde_encoder_trigger_kickoff_pending(struct drm_encoder *drm_enc) |
| 3008 | { |
| 3009 | struct sde_encoder_virt *sde_enc; |
| 3010 | struct sde_encoder_phys *phys; |
| 3011 | unsigned int i; |
| 3012 | struct sde_hw_ctl *ctl; |
| 3013 | struct msm_display_info *disp_info; |
| 3014 | |
| 3015 | if (!drm_enc) { |
| 3016 | SDE_ERROR("invalid encoder\n"); |
| 3017 | return; |
| 3018 | } |
| 3019 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 3020 | disp_info = &sde_enc->disp_info; |
| 3021 | |
| 3022 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 3023 | phys = sde_enc->phys_encs[i]; |
| 3024 | |
| 3025 | if (phys && phys->hw_ctl) { |
| 3026 | ctl = phys->hw_ctl; |
| 3027 | if (ctl->ops.clear_pending_flush) |
| 3028 | ctl->ops.clear_pending_flush(ctl); |
| 3029 | |
| 3030 | /* update only for command mode primary ctl */ |
| 3031 | if ((phys == sde_enc->cur_master) && |
| 3032 | (disp_info->capabilities & MSM_DISPLAY_CAP_CMD_MODE) |
| 3033 | && ctl->ops.trigger_pending) |
| 3034 | ctl->ops.trigger_pending(ctl); |
| 3035 | } |
| 3036 | } |
| 3037 | } |
| 3038 | |
Ping Li | 8430ee1 | 2017-02-24 14:14:44 -0800 | [diff] [blame] | 3039 | static void _sde_encoder_setup_dither(struct sde_encoder_phys *phys) |
| 3040 | { |
| 3041 | void *dither_cfg; |
| 3042 | int ret = 0; |
| 3043 | size_t len = 0; |
| 3044 | enum sde_rm_topology_name topology; |
| 3045 | |
| 3046 | if (!phys || !phys->connector || !phys->hw_pp || |
| 3047 | !phys->hw_pp->ops.setup_dither) |
| 3048 | return; |
| 3049 | topology = sde_connector_get_topology_name(phys->connector); |
| 3050 | if ((topology == SDE_RM_TOPOLOGY_PPSPLIT) && |
| 3051 | (phys->split_role == ENC_ROLE_SLAVE)) |
| 3052 | return; |
| 3053 | |
| 3054 | ret = sde_connector_get_dither_cfg(phys->connector, |
| 3055 | phys->connector->state, &dither_cfg, &len); |
| 3056 | if (!ret) |
| 3057 | phys->hw_pp->ops.setup_dither(phys->hw_pp, dither_cfg, len); |
| 3058 | } |
| 3059 | |
Benjamin Chan | 9cd866d | 2017-08-15 14:56:34 -0400 | [diff] [blame] | 3060 | static u32 _sde_encoder_calculate_linetime(struct sde_encoder_virt *sde_enc, |
| 3061 | struct drm_display_mode *mode) |
| 3062 | { |
| 3063 | u64 pclk_rate; |
| 3064 | u32 pclk_period; |
| 3065 | u32 line_time; |
| 3066 | |
| 3067 | /* |
| 3068 | * For linetime calculation, only operate on master encoder. |
| 3069 | */ |
| 3070 | if (!sde_enc->cur_master) |
| 3071 | return 0; |
| 3072 | |
| 3073 | if (!sde_enc->cur_master->ops.get_line_count) { |
| 3074 | SDE_ERROR("get_line_count function not defined\n"); |
| 3075 | return 0; |
| 3076 | } |
| 3077 | |
| 3078 | pclk_rate = mode->clock; /* pixel clock in kHz */ |
| 3079 | if (pclk_rate == 0) { |
| 3080 | SDE_ERROR("pclk is 0, cannot calculate line time\n"); |
| 3081 | return 0; |
| 3082 | } |
| 3083 | |
| 3084 | pclk_period = DIV_ROUND_UP_ULL(1000000000ull, pclk_rate); |
| 3085 | if (pclk_period == 0) { |
| 3086 | SDE_ERROR("pclk period is 0\n"); |
| 3087 | return 0; |
| 3088 | } |
| 3089 | |
| 3090 | /* |
| 3091 | * Line time calculation based on Pixel clock and HTOTAL. |
| 3092 | * Final unit is in ns. |
| 3093 | */ |
| 3094 | line_time = (pclk_period * mode->htotal) / 1000; |
| 3095 | if (line_time == 0) { |
| 3096 | SDE_ERROR("line time calculation is 0\n"); |
| 3097 | return 0; |
| 3098 | } |
| 3099 | |
| 3100 | SDE_DEBUG_ENC(sde_enc, |
| 3101 | "clk_rate=%lldkHz, clk_period=%d, linetime=%dns\n", |
| 3102 | pclk_rate, pclk_period, line_time); |
| 3103 | |
| 3104 | return line_time; |
| 3105 | } |
| 3106 | |
| 3107 | static int _sde_encoder_wakeup_time(struct drm_encoder *drm_enc, |
| 3108 | ktime_t *wakeup_time) |
| 3109 | { |
| 3110 | struct drm_display_mode *mode; |
| 3111 | struct sde_encoder_virt *sde_enc; |
| 3112 | u32 cur_line; |
| 3113 | u32 line_time; |
| 3114 | u32 vtotal, time_to_vsync; |
| 3115 | ktime_t cur_time; |
| 3116 | |
| 3117 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 3118 | |
| 3119 | if (!drm_enc->crtc || !drm_enc->crtc->state) { |
| 3120 | SDE_ERROR("crtc/crtc state object is NULL\n"); |
| 3121 | return -EINVAL; |
| 3122 | } |
| 3123 | mode = &drm_enc->crtc->state->adjusted_mode; |
| 3124 | |
| 3125 | line_time = _sde_encoder_calculate_linetime(sde_enc, mode); |
| 3126 | if (!line_time) |
| 3127 | return -EINVAL; |
| 3128 | |
| 3129 | cur_line = sde_enc->cur_master->ops.get_line_count(sde_enc->cur_master); |
| 3130 | |
| 3131 | vtotal = mode->vtotal; |
| 3132 | if (cur_line >= vtotal) |
| 3133 | time_to_vsync = line_time * vtotal; |
| 3134 | else |
| 3135 | time_to_vsync = line_time * (vtotal - cur_line); |
| 3136 | |
| 3137 | if (time_to_vsync == 0) { |
| 3138 | SDE_ERROR("time to vsync should not be zero, vtotal=%d\n", |
| 3139 | vtotal); |
| 3140 | return -EINVAL; |
| 3141 | } |
| 3142 | |
| 3143 | cur_time = ktime_get(); |
| 3144 | *wakeup_time = ktime_add_ns(cur_time, time_to_vsync); |
| 3145 | |
| 3146 | SDE_DEBUG_ENC(sde_enc, |
| 3147 | "cur_line=%u vtotal=%u time_to_vsync=%u, cur_time=%lld, wakeup_time=%lld\n", |
| 3148 | cur_line, vtotal, time_to_vsync, |
| 3149 | ktime_to_ms(cur_time), |
| 3150 | ktime_to_ms(*wakeup_time)); |
| 3151 | return 0; |
| 3152 | } |
| 3153 | |
| 3154 | static void sde_encoder_vsync_event_handler(unsigned long data) |
| 3155 | { |
| 3156 | struct drm_encoder *drm_enc = (struct drm_encoder *) data; |
| 3157 | struct sde_encoder_virt *sde_enc; |
| 3158 | struct msm_drm_private *priv; |
| 3159 | struct msm_drm_thread *event_thread; |
Benjamin Chan | 9cd866d | 2017-08-15 14:56:34 -0400 | [diff] [blame] | 3160 | |
| 3161 | if (!drm_enc || !drm_enc->dev || !drm_enc->dev->dev_private || |
| 3162 | !drm_enc->crtc) { |
| 3163 | SDE_ERROR("invalid parameters\n"); |
| 3164 | return; |
| 3165 | } |
| 3166 | |
| 3167 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 3168 | priv = drm_enc->dev->dev_private; |
| 3169 | |
| 3170 | if (drm_enc->crtc->index >= ARRAY_SIZE(priv->event_thread)) { |
| 3171 | SDE_ERROR("invalid crtc index\n"); |
| 3172 | return; |
| 3173 | } |
| 3174 | event_thread = &priv->event_thread[drm_enc->crtc->index]; |
| 3175 | if (!event_thread) { |
| 3176 | SDE_ERROR("event_thread not found for crtc:%d\n", |
| 3177 | drm_enc->crtc->index); |
| 3178 | return; |
| 3179 | } |
| 3180 | |
Jayant Shekhar | 12d908f | 2017-10-10 12:11:48 +0530 | [diff] [blame] | 3181 | kthread_queue_work(&event_thread->worker, |
Benjamin Chan | 9cd866d | 2017-08-15 14:56:34 -0400 | [diff] [blame] | 3182 | &sde_enc->vsync_event_work); |
Benjamin Chan | 9cd866d | 2017-08-15 14:56:34 -0400 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | static void sde_encoder_vsync_event_work_handler(struct kthread_work *work) |
| 3186 | { |
| 3187 | struct sde_encoder_virt *sde_enc = container_of(work, |
| 3188 | struct sde_encoder_virt, vsync_event_work); |
Jayant Shekhar | 12d908f | 2017-10-10 12:11:48 +0530 | [diff] [blame] | 3189 | bool autorefresh_enabled = false; |
| 3190 | int rc = 0; |
Benjamin Chan | 9cd866d | 2017-08-15 14:56:34 -0400 | [diff] [blame] | 3191 | ktime_t wakeup_time; |
| 3192 | |
| 3193 | if (!sde_enc) { |
| 3194 | SDE_ERROR("invalid sde encoder\n"); |
| 3195 | return; |
| 3196 | } |
| 3197 | |
Jayant Shekhar | 12d908f | 2017-10-10 12:11:48 +0530 | [diff] [blame] | 3198 | rc = _sde_encoder_power_enable(sde_enc, true); |
| 3199 | if (rc) { |
| 3200 | SDE_ERROR_ENC(sde_enc, "sde enc power enabled failed:%d\n", rc); |
| 3201 | return; |
| 3202 | } |
| 3203 | |
| 3204 | if (sde_enc->cur_master && |
| 3205 | sde_enc->cur_master->ops.is_autorefresh_enabled) |
| 3206 | autorefresh_enabled = |
| 3207 | sde_enc->cur_master->ops.is_autorefresh_enabled( |
| 3208 | sde_enc->cur_master); |
| 3209 | |
| 3210 | _sde_encoder_power_enable(sde_enc, false); |
| 3211 | |
| 3212 | /* Update timer if autorefresh is enabled else return */ |
| 3213 | if (!autorefresh_enabled) |
| 3214 | return; |
| 3215 | |
Benjamin Chan | 9cd866d | 2017-08-15 14:56:34 -0400 | [diff] [blame] | 3216 | if (_sde_encoder_wakeup_time(&sde_enc->base, &wakeup_time)) |
| 3217 | return; |
| 3218 | |
| 3219 | SDE_EVT32_VERBOSE(ktime_to_ms(wakeup_time)); |
| 3220 | mod_timer(&sde_enc->vsync_event_timer, |
| 3221 | nsecs_to_jiffies(ktime_to_ns(wakeup_time))); |
| 3222 | } |
| 3223 | |
Clarence Ip | 85f4f453 | 2017-10-04 12:10:13 -0400 | [diff] [blame] | 3224 | int sde_encoder_prepare_for_kickoff(struct drm_encoder *drm_enc, |
Alan Kwong | 4aacd53 | 2017-02-04 18:51:33 -0800 | [diff] [blame] | 3225 | struct sde_encoder_kickoff_params *params) |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3226 | { |
| 3227 | struct sde_encoder_virt *sde_enc; |
| 3228 | struct sde_encoder_phys *phys; |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 3229 | bool needs_hw_reset = false; |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3230 | unsigned int i; |
Clarence Ip | 85f4f453 | 2017-10-04 12:10:13 -0400 | [diff] [blame] | 3231 | int rc, ret = 0; |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3232 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 3233 | if (!drm_enc || !params) { |
| 3234 | SDE_ERROR("invalid args\n"); |
Clarence Ip | 85f4f453 | 2017-10-04 12:10:13 -0400 | [diff] [blame] | 3235 | return -EINVAL; |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3236 | } |
| 3237 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 3238 | |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3239 | SDE_DEBUG_ENC(sde_enc, "\n"); |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 3240 | SDE_EVT32(DRMID(drm_enc)); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3241 | |
Lloyd Atkinson | aa0dce9 | 2016-11-23 20:16:47 -0500 | [diff] [blame] | 3242 | /* prepare for next kickoff, may include waiting on previous kickoff */ |
Veera Sundaram Sankaran | a90e139 | 2017-07-06 15:00:09 -0700 | [diff] [blame] | 3243 | SDE_ATRACE_BEGIN("enc_prepare_for_kickoff"); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3244 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3245 | phys = sde_enc->phys_encs[i]; |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 3246 | if (phys) { |
Clarence Ip | 85f4f453 | 2017-10-04 12:10:13 -0400 | [diff] [blame] | 3247 | if (phys->ops.prepare_for_kickoff) { |
| 3248 | rc = phys->ops.prepare_for_kickoff( |
| 3249 | phys, params); |
| 3250 | if (rc) |
| 3251 | ret = rc; |
| 3252 | } |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 3253 | if (phys->enable_state == SDE_ENC_ERR_NEEDS_HW_RESET) |
| 3254 | needs_hw_reset = true; |
Ping Li | 8430ee1 | 2017-02-24 14:14:44 -0800 | [diff] [blame] | 3255 | _sde_encoder_setup_dither(phys); |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 3256 | } |
| 3257 | } |
Veera Sundaram Sankaran | a90e139 | 2017-07-06 15:00:09 -0700 | [diff] [blame] | 3258 | SDE_ATRACE_END("enc_prepare_for_kickoff"); |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 3259 | |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 3260 | sde_encoder_resource_control(drm_enc, SDE_ENC_RC_EVENT_KICKOFF); |
| 3261 | |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 3262 | /* if any phys needs reset, reset all phys, in-order */ |
| 3263 | if (needs_hw_reset) { |
Dhaval Patel | 0e558f4 | 2017-04-30 00:51:40 -0700 | [diff] [blame] | 3264 | SDE_EVT32(DRMID(drm_enc), SDE_EVTLOG_FUNC_CASE1); |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 3265 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 3266 | phys = sde_enc->phys_encs[i]; |
| 3267 | if (phys && phys->ops.hw_reset) |
| 3268 | phys->ops.hw_reset(phys); |
| 3269 | } |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3270 | } |
Lloyd Atkinson | 05d7551 | 2017-01-17 14:45:51 -0500 | [diff] [blame] | 3271 | |
Lloyd Atkinson | 73fb809 | 2017-02-08 16:02:55 -0500 | [diff] [blame] | 3272 | _sde_encoder_update_master(drm_enc, params); |
| 3273 | |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 3274 | _sde_encoder_update_roi(drm_enc); |
| 3275 | |
Lloyd Atkinson | 05d7551 | 2017-01-17 14:45:51 -0500 | [diff] [blame] | 3276 | if (sde_enc->cur_master && sde_enc->cur_master->connector) { |
| 3277 | rc = sde_connector_pre_kickoff(sde_enc->cur_master->connector); |
Clarence Ip | 85f4f453 | 2017-10-04 12:10:13 -0400 | [diff] [blame] | 3278 | if (rc) { |
Lloyd Atkinson | 05d7551 | 2017-01-17 14:45:51 -0500 | [diff] [blame] | 3279 | SDE_ERROR_ENC(sde_enc, "kickoff conn%d failed rc %d\n", |
| 3280 | sde_enc->cur_master->connector->base.id, |
| 3281 | rc); |
Clarence Ip | 85f4f453 | 2017-10-04 12:10:13 -0400 | [diff] [blame] | 3282 | ret = rc; |
| 3283 | } |
Lloyd Atkinson | 05d7551 | 2017-01-17 14:45:51 -0500 | [diff] [blame] | 3284 | } |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 3285 | |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 3286 | if (_sde_encoder_is_dsc_enabled(drm_enc)) { |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 3287 | rc = _sde_encoder_dsc_setup(sde_enc, params); |
Clarence Ip | 85f4f453 | 2017-10-04 12:10:13 -0400 | [diff] [blame] | 3288 | if (rc) { |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 3289 | SDE_ERROR_ENC(sde_enc, "failed to setup DSC: %d\n", rc); |
Clarence Ip | 85f4f453 | 2017-10-04 12:10:13 -0400 | [diff] [blame] | 3290 | ret = rc; |
| 3291 | } |
Lloyd Atkinson | b22f9a4 | 2017-05-17 17:29:56 -0400 | [diff] [blame] | 3292 | } |
Clarence Ip | 85f4f453 | 2017-10-04 12:10:13 -0400 | [diff] [blame] | 3293 | |
| 3294 | return ret; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 3295 | } |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3296 | |
Clarence Ip | 662698e | 2017-09-12 18:34:16 -0400 | [diff] [blame] | 3297 | /** |
| 3298 | * _sde_encoder_reset_ctl_hw - reset h/w configuration for all ctl's associated |
| 3299 | * with the specified encoder, and unstage all pipes from it |
| 3300 | * @encoder: encoder pointer |
| 3301 | * Returns: 0 on success |
| 3302 | */ |
| 3303 | static int _sde_encoder_reset_ctl_hw(struct drm_encoder *drm_enc) |
| 3304 | { |
| 3305 | struct sde_encoder_virt *sde_enc; |
| 3306 | struct sde_encoder_phys *phys; |
| 3307 | unsigned int i; |
| 3308 | int rc = 0; |
| 3309 | |
| 3310 | if (!drm_enc) { |
| 3311 | SDE_ERROR("invalid encoder\n"); |
| 3312 | return -EINVAL; |
| 3313 | } |
| 3314 | |
| 3315 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 3316 | |
| 3317 | SDE_ATRACE_BEGIN("encoder_release_lm"); |
| 3318 | SDE_DEBUG_ENC(sde_enc, "\n"); |
| 3319 | |
| 3320 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 3321 | phys = sde_enc->phys_encs[i]; |
| 3322 | if (!phys) |
| 3323 | continue; |
| 3324 | |
| 3325 | SDE_EVT32(DRMID(drm_enc), phys->intf_idx - INTF_0); |
| 3326 | |
| 3327 | rc = sde_encoder_helper_reset_mixers(phys, NULL); |
| 3328 | if (rc) |
| 3329 | SDE_EVT32(DRMID(drm_enc), rc, SDE_EVTLOG_ERROR); |
| 3330 | } |
| 3331 | |
| 3332 | SDE_ATRACE_END("encoder_release_lm"); |
| 3333 | return rc; |
| 3334 | } |
| 3335 | |
| 3336 | void sde_encoder_kickoff(struct drm_encoder *drm_enc, bool is_error) |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 3337 | { |
| 3338 | struct sde_encoder_virt *sde_enc; |
| 3339 | struct sde_encoder_phys *phys; |
Benjamin Chan | 9cd866d | 2017-08-15 14:56:34 -0400 | [diff] [blame] | 3340 | ktime_t wakeup_time; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 3341 | unsigned int i; |
| 3342 | |
| 3343 | if (!drm_enc) { |
| 3344 | SDE_ERROR("invalid encoder\n"); |
| 3345 | return; |
| 3346 | } |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 3347 | SDE_ATRACE_BEGIN("encoder_kickoff"); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 3348 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 3349 | |
| 3350 | SDE_DEBUG_ENC(sde_enc, "\n"); |
| 3351 | |
| 3352 | atomic_set(&sde_enc->frame_done_timeout, |
Veera Sundaram Sankaran | 7ee9909 | 2017-06-13 11:19:36 -0700 | [diff] [blame] | 3353 | SDE_FRAME_DONE_TIMEOUT * 1000 / |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 3354 | drm_enc->crtc->state->adjusted_mode.vrefresh); |
| 3355 | mod_timer(&sde_enc->frame_done_timer, jiffies + |
| 3356 | ((atomic_read(&sde_enc->frame_done_timeout) * HZ) / 1000)); |
| 3357 | |
Clarence Ip | 662698e | 2017-09-12 18:34:16 -0400 | [diff] [blame] | 3358 | /* create a 'no pipes' commit to release buffers on errors */ |
| 3359 | if (is_error) |
| 3360 | _sde_encoder_reset_ctl_hw(drm_enc); |
| 3361 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 3362 | /* All phys encs are ready to go, trigger the kickoff */ |
Clarence Ip | 110d15c | 2016-08-16 14:44:41 -0400 | [diff] [blame] | 3363 | _sde_encoder_kickoff_phys(sde_enc); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3364 | |
Lloyd Atkinson | aa0dce9 | 2016-11-23 20:16:47 -0500 | [diff] [blame] | 3365 | /* allow phys encs to handle any post-kickoff business */ |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3366 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
Lloyd Atkinson | aa0dce9 | 2016-11-23 20:16:47 -0500 | [diff] [blame] | 3367 | phys = sde_enc->phys_encs[i]; |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3368 | if (phys && phys->ops.handle_post_kickoff) |
| 3369 | phys->ops.handle_post_kickoff(phys); |
| 3370 | } |
Benjamin Chan | 9cd866d | 2017-08-15 14:56:34 -0400 | [diff] [blame] | 3371 | |
| 3372 | if (sde_enc->disp_info.intf_type == DRM_MODE_CONNECTOR_DSI && |
| 3373 | !_sde_encoder_wakeup_time(drm_enc, &wakeup_time)) { |
| 3374 | SDE_EVT32_VERBOSE(ktime_to_ms(wakeup_time)); |
| 3375 | mod_timer(&sde_enc->vsync_event_timer, |
| 3376 | nsecs_to_jiffies(ktime_to_ns(wakeup_time))); |
| 3377 | } |
| 3378 | |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 3379 | SDE_ATRACE_END("encoder_kickoff"); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3380 | } |
| 3381 | |
Clarence Ip | 662698e | 2017-09-12 18:34:16 -0400 | [diff] [blame] | 3382 | int sde_encoder_helper_reset_mixers(struct sde_encoder_phys *phys_enc, |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 3383 | struct drm_framebuffer *fb) |
| 3384 | { |
| 3385 | struct drm_encoder *drm_enc; |
| 3386 | struct sde_hw_mixer_cfg mixer; |
| 3387 | struct sde_rm_hw_iter lm_iter; |
| 3388 | bool lm_valid = false; |
| 3389 | |
| 3390 | if (!phys_enc || !phys_enc->parent) { |
| 3391 | SDE_ERROR("invalid encoder\n"); |
| 3392 | return -EINVAL; |
| 3393 | } |
| 3394 | |
| 3395 | drm_enc = phys_enc->parent; |
| 3396 | memset(&mixer, 0, sizeof(mixer)); |
| 3397 | |
| 3398 | /* reset associated CTL/LMs */ |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 3399 | if (phys_enc->hw_ctl->ops.clear_all_blendstages) |
| 3400 | phys_enc->hw_ctl->ops.clear_all_blendstages(phys_enc->hw_ctl); |
| 3401 | |
| 3402 | sde_rm_init_hw_iter(&lm_iter, drm_enc->base.id, SDE_HW_BLK_LM); |
| 3403 | while (sde_rm_get_hw(&phys_enc->sde_kms->rm, &lm_iter)) { |
| 3404 | struct sde_hw_mixer *hw_lm = (struct sde_hw_mixer *)lm_iter.hw; |
| 3405 | |
| 3406 | if (!hw_lm) |
| 3407 | continue; |
| 3408 | |
| 3409 | /* need to flush LM to remove it */ |
| 3410 | if (phys_enc->hw_ctl->ops.get_bitmask_mixer && |
| 3411 | phys_enc->hw_ctl->ops.update_pending_flush) |
| 3412 | phys_enc->hw_ctl->ops.update_pending_flush( |
| 3413 | phys_enc->hw_ctl, |
| 3414 | phys_enc->hw_ctl->ops.get_bitmask_mixer( |
| 3415 | phys_enc->hw_ctl, hw_lm->idx)); |
| 3416 | |
| 3417 | if (fb) { |
| 3418 | /* assume a single LM if targeting a frame buffer */ |
| 3419 | if (lm_valid) |
| 3420 | continue; |
| 3421 | |
| 3422 | mixer.out_height = fb->height; |
| 3423 | mixer.out_width = fb->width; |
| 3424 | |
| 3425 | if (hw_lm->ops.setup_mixer_out) |
| 3426 | hw_lm->ops.setup_mixer_out(hw_lm, &mixer); |
| 3427 | } |
| 3428 | |
| 3429 | lm_valid = true; |
| 3430 | |
| 3431 | /* only enable border color on LM */ |
| 3432 | if (phys_enc->hw_ctl->ops.setup_blendstage) |
| 3433 | phys_enc->hw_ctl->ops.setup_blendstage( |
Dhaval Patel | 572cfd2 | 2017-06-12 19:33:39 -0700 | [diff] [blame] | 3434 | phys_enc->hw_ctl, hw_lm->idx, NULL); |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 3435 | } |
| 3436 | |
| 3437 | if (!lm_valid) { |
Clarence Ip | 662698e | 2017-09-12 18:34:16 -0400 | [diff] [blame] | 3438 | SDE_ERROR_ENC(to_sde_encoder_virt(drm_enc), "lm not found\n"); |
Clarence Ip | 9c65f7b | 2017-03-20 06:48:15 -0700 | [diff] [blame] | 3439 | return -EFAULT; |
| 3440 | } |
| 3441 | return 0; |
| 3442 | } |
| 3443 | |
Lloyd Atkinson | e123c17 | 2017-02-27 13:19:08 -0500 | [diff] [blame] | 3444 | void sde_encoder_prepare_commit(struct drm_encoder *drm_enc) |
| 3445 | { |
| 3446 | struct sde_encoder_virt *sde_enc; |
| 3447 | struct sde_encoder_phys *phys; |
| 3448 | int i; |
| 3449 | |
| 3450 | if (!drm_enc) { |
| 3451 | SDE_ERROR("invalid encoder\n"); |
| 3452 | return; |
| 3453 | } |
| 3454 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 3455 | |
| 3456 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 3457 | phys = sde_enc->phys_encs[i]; |
| 3458 | if (phys && phys->ops.prepare_commit) |
| 3459 | phys->ops.prepare_commit(phys); |
| 3460 | } |
| 3461 | } |
| 3462 | |
Lloyd Atkinson | c9fb338 | 2017-03-24 08:08:30 -0700 | [diff] [blame] | 3463 | #ifdef CONFIG_DEBUG_FS |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 3464 | static int _sde_encoder_status_show(struct seq_file *s, void *data) |
| 3465 | { |
| 3466 | struct sde_encoder_virt *sde_enc; |
| 3467 | int i; |
| 3468 | |
| 3469 | if (!s || !s->private) |
| 3470 | return -EINVAL; |
| 3471 | |
| 3472 | sde_enc = s->private; |
| 3473 | |
| 3474 | mutex_lock(&sde_enc->enc_lock); |
| 3475 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 3476 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
| 3477 | |
| 3478 | if (!phys) |
| 3479 | continue; |
| 3480 | |
| 3481 | seq_printf(s, "intf:%d vsync:%8d underrun:%8d ", |
| 3482 | phys->intf_idx - INTF_0, |
| 3483 | atomic_read(&phys->vsync_cnt), |
| 3484 | atomic_read(&phys->underrun_cnt)); |
| 3485 | |
| 3486 | switch (phys->intf_mode) { |
| 3487 | case INTF_MODE_VIDEO: |
| 3488 | seq_puts(s, "mode: video\n"); |
| 3489 | break; |
| 3490 | case INTF_MODE_CMD: |
| 3491 | seq_puts(s, "mode: command\n"); |
| 3492 | break; |
| 3493 | case INTF_MODE_WB_BLOCK: |
| 3494 | seq_puts(s, "mode: wb block\n"); |
| 3495 | break; |
| 3496 | case INTF_MODE_WB_LINE: |
| 3497 | seq_puts(s, "mode: wb line\n"); |
| 3498 | break; |
| 3499 | default: |
| 3500 | seq_puts(s, "mode: ???\n"); |
| 3501 | break; |
| 3502 | } |
| 3503 | } |
| 3504 | mutex_unlock(&sde_enc->enc_lock); |
| 3505 | |
| 3506 | return 0; |
| 3507 | } |
| 3508 | |
| 3509 | static int _sde_encoder_debugfs_status_open(struct inode *inode, |
| 3510 | struct file *file) |
| 3511 | { |
| 3512 | return single_open(file, _sde_encoder_status_show, inode->i_private); |
| 3513 | } |
| 3514 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3515 | static ssize_t _sde_encoder_misr_setup(struct file *file, |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3516 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 3517 | { |
| 3518 | struct sde_encoder_virt *sde_enc; |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3519 | int i = 0, rc; |
| 3520 | char buf[MISR_BUFF_SIZE + 1]; |
| 3521 | size_t buff_copy; |
| 3522 | u32 frame_count, enable; |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3523 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3524 | if (!file || !file->private_data) |
| 3525 | return -EINVAL; |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3526 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3527 | sde_enc = file->private_data; |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3528 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3529 | buff_copy = min_t(size_t, count, MISR_BUFF_SIZE); |
| 3530 | if (copy_from_user(buf, user_buf, buff_copy)) |
| 3531 | return -EINVAL; |
| 3532 | |
| 3533 | buf[buff_copy] = 0; /* end of string */ |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3534 | |
| 3535 | if (sscanf(buf, "%u %u", &enable, &frame_count) != 2) |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3536 | return -EINVAL; |
| 3537 | |
| 3538 | rc = _sde_encoder_power_enable(sde_enc, true); |
| 3539 | if (rc) |
| 3540 | return rc; |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3541 | |
| 3542 | mutex_lock(&sde_enc->enc_lock); |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3543 | sde_enc->misr_enable = enable; |
Dhaval Patel | 010f517 | 2017-08-01 22:40:09 -0700 | [diff] [blame] | 3544 | sde_enc->misr_frame_count = frame_count; |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3545 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 3546 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
| 3547 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3548 | if (!phys || !phys->ops.setup_misr) |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3549 | continue; |
| 3550 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3551 | phys->ops.setup_misr(phys, enable, frame_count); |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3552 | } |
| 3553 | mutex_unlock(&sde_enc->enc_lock); |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3554 | _sde_encoder_power_enable(sde_enc, false); |
| 3555 | |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3556 | return count; |
| 3557 | } |
| 3558 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3559 | static ssize_t _sde_encoder_misr_read(struct file *file, |
| 3560 | char __user *user_buff, size_t count, loff_t *ppos) |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3561 | { |
| 3562 | struct sde_encoder_virt *sde_enc; |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3563 | int i = 0, len = 0; |
| 3564 | char buf[MISR_BUFF_SIZE + 1] = {'\0'}; |
| 3565 | int rc; |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3566 | |
| 3567 | if (*ppos) |
| 3568 | return 0; |
| 3569 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3570 | if (!file || !file->private_data) |
| 3571 | return -EINVAL; |
| 3572 | |
| 3573 | sde_enc = file->private_data; |
| 3574 | |
| 3575 | rc = _sde_encoder_power_enable(sde_enc, true); |
| 3576 | if (rc) |
| 3577 | return rc; |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3578 | |
| 3579 | mutex_lock(&sde_enc->enc_lock); |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3580 | if (!sde_enc->misr_enable) { |
| 3581 | len += snprintf(buf + len, MISR_BUFF_SIZE - len, |
| 3582 | "disabled\n"); |
| 3583 | goto buff_check; |
| 3584 | } else if (sde_enc->disp_info.capabilities & |
| 3585 | ~MSM_DISPLAY_CAP_VID_MODE) { |
| 3586 | len += snprintf(buf + len, MISR_BUFF_SIZE - len, |
| 3587 | "unsupported\n"); |
| 3588 | goto buff_check; |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3589 | } |
| 3590 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3591 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 3592 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
| 3593 | if (!phys || !phys->ops.collect_misr) |
| 3594 | continue; |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3595 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3596 | len += snprintf(buf + len, MISR_BUFF_SIZE - len, |
| 3597 | "Intf idx:%d\n", phys->intf_idx - INTF_0); |
| 3598 | len += snprintf(buf + len, MISR_BUFF_SIZE - len, "0x%x\n", |
| 3599 | phys->ops.collect_misr(phys)); |
| 3600 | } |
| 3601 | |
| 3602 | buff_check: |
| 3603 | if (count <= len) { |
| 3604 | len = 0; |
| 3605 | goto end; |
| 3606 | } |
| 3607 | |
| 3608 | if (copy_to_user(user_buff, buf, len)) { |
| 3609 | len = -EFAULT; |
| 3610 | goto end; |
| 3611 | } |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3612 | |
| 3613 | *ppos += len; /* increase offset */ |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3614 | |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3615 | end: |
| 3616 | mutex_unlock(&sde_enc->enc_lock); |
| 3617 | _sde_encoder_power_enable(sde_enc, false); |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3618 | return len; |
| 3619 | } |
| 3620 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3621 | static int _sde_encoder_init_debugfs(struct drm_encoder *drm_enc) |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 3622 | { |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3623 | struct sde_encoder_virt *sde_enc; |
| 3624 | struct msm_drm_private *priv; |
| 3625 | struct sde_kms *sde_kms; |
Alan Kwong | f2debb0 | 2017-04-05 06:19:29 -0700 | [diff] [blame] | 3626 | int i; |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3627 | |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 3628 | static const struct file_operations debugfs_status_fops = { |
| 3629 | .open = _sde_encoder_debugfs_status_open, |
| 3630 | .read = seq_read, |
| 3631 | .llseek = seq_lseek, |
| 3632 | .release = single_release, |
| 3633 | }; |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3634 | |
| 3635 | static const struct file_operations debugfs_misr_fops = { |
| 3636 | .open = simple_open, |
| 3637 | .read = _sde_encoder_misr_read, |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3638 | .write = _sde_encoder_misr_setup, |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3639 | }; |
| 3640 | |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 3641 | char name[SDE_NAME_SIZE]; |
| 3642 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3643 | if (!drm_enc || !drm_enc->dev || !drm_enc->dev->dev_private) { |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 3644 | SDE_ERROR("invalid encoder or kms\n"); |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3645 | return -EINVAL; |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 3646 | } |
| 3647 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3648 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 3649 | priv = drm_enc->dev->dev_private; |
| 3650 | sde_kms = to_sde_kms(priv->kms); |
| 3651 | |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 3652 | snprintf(name, SDE_NAME_SIZE, "encoder%u", drm_enc->base.id); |
| 3653 | |
| 3654 | /* create overall sub-directory for the encoder */ |
| 3655 | sde_enc->debugfs_root = debugfs_create_dir(name, |
Lloyd Atkinson | 09e64bf | 2017-04-13 14:09:59 -0700 | [diff] [blame] | 3656 | drm_enc->dev->primary->debugfs_root); |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3657 | if (!sde_enc->debugfs_root) |
| 3658 | return -ENOMEM; |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3659 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3660 | /* don't error check these */ |
Lloyd Atkinson | 8de415a | 2017-05-23 11:31:16 -0400 | [diff] [blame] | 3661 | debugfs_create_file("status", 0600, |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3662 | sde_enc->debugfs_root, sde_enc, &debugfs_status_fops); |
Jayant Shekhar | 1d50ed2 | 2016-11-04 18:41:12 +0530 | [diff] [blame] | 3663 | |
Lloyd Atkinson | 8de415a | 2017-05-23 11:31:16 -0400 | [diff] [blame] | 3664 | debugfs_create_file("misr_data", 0600, |
Dhaval Patel | f9245d6 | 2017-03-28 16:24:00 -0700 | [diff] [blame] | 3665 | sde_enc->debugfs_root, sde_enc, &debugfs_misr_fops); |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3666 | |
Alan Kwong | f2debb0 | 2017-04-05 06:19:29 -0700 | [diff] [blame] | 3667 | for (i = 0; i < sde_enc->num_phys_encs; i++) |
| 3668 | if (sde_enc->phys_encs[i] && |
| 3669 | sde_enc->phys_encs[i]->ops.late_register) |
| 3670 | sde_enc->phys_encs[i]->ops.late_register( |
| 3671 | sde_enc->phys_encs[i], |
| 3672 | sde_enc->debugfs_root); |
| 3673 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3674 | return 0; |
| 3675 | } |
| 3676 | |
| 3677 | static void _sde_encoder_destroy_debugfs(struct drm_encoder *drm_enc) |
| 3678 | { |
| 3679 | struct sde_encoder_virt *sde_enc; |
| 3680 | |
| 3681 | if (!drm_enc) |
| 3682 | return; |
| 3683 | |
| 3684 | sde_enc = to_sde_encoder_virt(drm_enc); |
| 3685 | debugfs_remove_recursive(sde_enc->debugfs_root); |
| 3686 | } |
| 3687 | #else |
| 3688 | static int _sde_encoder_init_debugfs(struct drm_encoder *drm_enc) |
| 3689 | { |
| 3690 | return 0; |
| 3691 | } |
| 3692 | |
Lloyd Atkinson | c9fb338 | 2017-03-24 08:08:30 -0700 | [diff] [blame] | 3693 | static void _sde_encoder_destroy_debugfs(struct drm_encoder *drm_enc) |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3694 | { |
| 3695 | } |
| 3696 | #endif |
| 3697 | |
| 3698 | static int sde_encoder_late_register(struct drm_encoder *encoder) |
| 3699 | { |
| 3700 | return _sde_encoder_init_debugfs(encoder); |
| 3701 | } |
| 3702 | |
| 3703 | static void sde_encoder_early_unregister(struct drm_encoder *encoder) |
| 3704 | { |
| 3705 | _sde_encoder_destroy_debugfs(encoder); |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 3706 | } |
| 3707 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3708 | static int sde_encoder_virt_add_phys_encs( |
Clarence Ip | a403932 | 2016-07-15 16:23:59 -0400 | [diff] [blame] | 3709 | u32 display_caps, |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 3710 | struct sde_encoder_virt *sde_enc, |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3711 | struct sde_enc_phys_init_params *params) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3712 | { |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3713 | struct sde_encoder_phys *enc = NULL; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3714 | |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3715 | SDE_DEBUG_ENC(sde_enc, "\n"); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3716 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3717 | /* |
| 3718 | * We may create up to NUM_PHYS_ENCODER_TYPES physical encoder types |
| 3719 | * in this function, check up-front. |
| 3720 | */ |
| 3721 | if (sde_enc->num_phys_encs + NUM_PHYS_ENCODER_TYPES >= |
| 3722 | ARRAY_SIZE(sde_enc->phys_encs)) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3723 | SDE_ERROR_ENC(sde_enc, "too many physical encoders %d\n", |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 3724 | sde_enc->num_phys_encs); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3725 | return -EINVAL; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3726 | } |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 3727 | |
Clarence Ip | a403932 | 2016-07-15 16:23:59 -0400 | [diff] [blame] | 3728 | if (display_caps & MSM_DISPLAY_CAP_VID_MODE) { |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3729 | enc = sde_encoder_phys_vid_init(params); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3730 | |
| 3731 | if (IS_ERR_OR_NULL(enc)) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3732 | SDE_ERROR_ENC(sde_enc, "failed to init vid enc: %ld\n", |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3733 | PTR_ERR(enc)); |
| 3734 | return enc == 0 ? -EINVAL : PTR_ERR(enc); |
| 3735 | } |
| 3736 | |
| 3737 | sde_enc->phys_encs[sde_enc->num_phys_encs] = enc; |
| 3738 | ++sde_enc->num_phys_encs; |
| 3739 | } |
| 3740 | |
Clarence Ip | a403932 | 2016-07-15 16:23:59 -0400 | [diff] [blame] | 3741 | if (display_caps & MSM_DISPLAY_CAP_CMD_MODE) { |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3742 | enc = sde_encoder_phys_cmd_init(params); |
Lloyd Atkinson | a59eead | 2016-05-30 14:37:06 -0400 | [diff] [blame] | 3743 | |
| 3744 | if (IS_ERR_OR_NULL(enc)) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3745 | SDE_ERROR_ENC(sde_enc, "failed to init cmd enc: %ld\n", |
Lloyd Atkinson | a59eead | 2016-05-30 14:37:06 -0400 | [diff] [blame] | 3746 | PTR_ERR(enc)); |
| 3747 | return enc == 0 ? -EINVAL : PTR_ERR(enc); |
| 3748 | } |
| 3749 | |
| 3750 | sde_enc->phys_encs[sde_enc->num_phys_encs] = enc; |
| 3751 | ++sde_enc->num_phys_encs; |
| 3752 | } |
| 3753 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3754 | return 0; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3755 | } |
| 3756 | |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3757 | static int sde_encoder_virt_add_phys_enc_wb(struct sde_encoder_virt *sde_enc, |
| 3758 | struct sde_enc_phys_init_params *params) |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 3759 | { |
| 3760 | struct sde_encoder_phys *enc = NULL; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 3761 | |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3762 | if (!sde_enc) { |
| 3763 | SDE_ERROR("invalid encoder\n"); |
| 3764 | return -EINVAL; |
| 3765 | } |
| 3766 | |
| 3767 | SDE_DEBUG_ENC(sde_enc, "\n"); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 3768 | |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3769 | if (sde_enc->num_phys_encs + 1 >= ARRAY_SIZE(sde_enc->phys_encs)) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3770 | SDE_ERROR_ENC(sde_enc, "too many physical encoders %d\n", |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 3771 | sde_enc->num_phys_encs); |
| 3772 | return -EINVAL; |
| 3773 | } |
| 3774 | |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3775 | enc = sde_encoder_phys_wb_init(params); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 3776 | |
| 3777 | if (IS_ERR_OR_NULL(enc)) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3778 | SDE_ERROR_ENC(sde_enc, "failed to init wb enc: %ld\n", |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 3779 | PTR_ERR(enc)); |
| 3780 | return enc == 0 ? -EINVAL : PTR_ERR(enc); |
| 3781 | } |
| 3782 | |
| 3783 | sde_enc->phys_encs[sde_enc->num_phys_encs] = enc; |
| 3784 | ++sde_enc->num_phys_encs; |
| 3785 | |
| 3786 | return 0; |
| 3787 | } |
| 3788 | |
Lloyd Atkinson | 9a84031 | 2016-06-26 10:11:08 -0400 | [diff] [blame] | 3789 | static int sde_encoder_setup_display(struct sde_encoder_virt *sde_enc, |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3790 | struct sde_kms *sde_kms, |
Clarence Ip | a403932 | 2016-07-15 16:23:59 -0400 | [diff] [blame] | 3791 | struct msm_display_info *disp_info, |
Lloyd Atkinson | 9a84031 | 2016-06-26 10:11:08 -0400 | [diff] [blame] | 3792 | int *drm_enc_mode) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3793 | { |
| 3794 | int ret = 0; |
| 3795 | int i = 0; |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3796 | enum sde_intf_type intf_type; |
| 3797 | struct sde_encoder_virt_ops parent_ops = { |
| 3798 | sde_encoder_vblank_callback, |
Dhaval Patel | 81e8788 | 2016-10-19 21:41:56 -0700 | [diff] [blame] | 3799 | sde_encoder_underrun_callback, |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 3800 | sde_encoder_frame_done_callback, |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3801 | }; |
| 3802 | struct sde_enc_phys_init_params phys_params; |
| 3803 | |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3804 | if (!sde_enc || !sde_kms) { |
| 3805 | SDE_ERROR("invalid arg(s), enc %d kms %d\n", |
| 3806 | sde_enc != 0, sde_kms != 0); |
| 3807 | return -EINVAL; |
| 3808 | } |
| 3809 | |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3810 | memset(&phys_params, 0, sizeof(phys_params)); |
| 3811 | phys_params.sde_kms = sde_kms; |
| 3812 | phys_params.parent = &sde_enc->base; |
| 3813 | phys_params.parent_ops = parent_ops; |
Lloyd Atkinson | 7d07094 | 2016-07-26 18:35:12 -0400 | [diff] [blame] | 3814 | phys_params.enc_spinlock = &sde_enc->enc_spinlock; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3815 | |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3816 | SDE_DEBUG("\n"); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3817 | |
Clarence Ip | a403932 | 2016-07-15 16:23:59 -0400 | [diff] [blame] | 3818 | if (disp_info->intf_type == DRM_MODE_CONNECTOR_DSI) { |
Lloyd Atkinson | 9a84031 | 2016-06-26 10:11:08 -0400 | [diff] [blame] | 3819 | *drm_enc_mode = DRM_MODE_ENCODER_DSI; |
| 3820 | intf_type = INTF_DSI; |
Clarence Ip | a403932 | 2016-07-15 16:23:59 -0400 | [diff] [blame] | 3821 | } else if (disp_info->intf_type == DRM_MODE_CONNECTOR_HDMIA) { |
Lloyd Atkinson | 9a84031 | 2016-06-26 10:11:08 -0400 | [diff] [blame] | 3822 | *drm_enc_mode = DRM_MODE_ENCODER_TMDS; |
| 3823 | intf_type = INTF_HDMI; |
Padmanabhan Komanduru | 6375861 | 2017-05-23 01:47:18 -0700 | [diff] [blame] | 3824 | } else if (disp_info->intf_type == DRM_MODE_CONNECTOR_DisplayPort) { |
| 3825 | *drm_enc_mode = DRM_MODE_ENCODER_TMDS; |
| 3826 | intf_type = INTF_DP; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 3827 | } else if (disp_info->intf_type == DRM_MODE_CONNECTOR_VIRTUAL) { |
| 3828 | *drm_enc_mode = DRM_MODE_ENCODER_VIRTUAL; |
| 3829 | intf_type = INTF_WB; |
Lloyd Atkinson | 9a84031 | 2016-06-26 10:11:08 -0400 | [diff] [blame] | 3830 | } else { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3831 | SDE_ERROR_ENC(sde_enc, "unsupported display interface type\n"); |
Lloyd Atkinson | 9a84031 | 2016-06-26 10:11:08 -0400 | [diff] [blame] | 3832 | return -EINVAL; |
| 3833 | } |
| 3834 | |
Clarence Ip | 88270a6 | 2016-06-26 10:09:34 -0400 | [diff] [blame] | 3835 | WARN_ON(disp_info->num_of_h_tiles < 1); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3836 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 3837 | sde_enc->display_num_of_h_tiles = disp_info->num_of_h_tiles; |
| 3838 | |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3839 | SDE_DEBUG("dsi_info->num_of_h_tiles %d\n", disp_info->num_of_h_tiles); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3840 | |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 3841 | if ((disp_info->capabilities & MSM_DISPLAY_CAP_CMD_MODE) || |
| 3842 | (disp_info->capabilities & MSM_DISPLAY_CAP_VID_MODE)) |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 3843 | sde_enc->idle_pc_supported = sde_kms->catalog->has_idle_pc; |
| 3844 | |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 3845 | mutex_lock(&sde_enc->enc_lock); |
Clarence Ip | 88270a6 | 2016-06-26 10:09:34 -0400 | [diff] [blame] | 3846 | for (i = 0; i < disp_info->num_of_h_tiles && !ret; i++) { |
Lloyd Atkinson | 9a84031 | 2016-06-26 10:11:08 -0400 | [diff] [blame] | 3847 | /* |
| 3848 | * Left-most tile is at index 0, content is controller id |
| 3849 | * h_tile_instance_ids[2] = {0, 1}; DSI0 = left, DSI1 = right |
| 3850 | * h_tile_instance_ids[2] = {1, 0}; DSI1 = left, DSI0 = right |
| 3851 | */ |
Lloyd Atkinson | 9a84031 | 2016-06-26 10:11:08 -0400 | [diff] [blame] | 3852 | u32 controller_id = disp_info->h_tile_instance[i]; |
| 3853 | |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 3854 | if (disp_info->num_of_h_tiles > 1) { |
| 3855 | if (i == 0) |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3856 | phys_params.split_role = ENC_ROLE_MASTER; |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 3857 | else |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3858 | phys_params.split_role = ENC_ROLE_SLAVE; |
| 3859 | } else { |
| 3860 | phys_params.split_role = ENC_ROLE_SOLO; |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 3861 | } |
| 3862 | |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3863 | SDE_DEBUG("h_tile_instance %d = %d, split_role %d\n", |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3864 | i, controller_id, phys_params.split_role); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3865 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 3866 | if (intf_type == INTF_WB) { |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 3867 | phys_params.intf_idx = INTF_MAX; |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3868 | phys_params.wb_idx = sde_encoder_get_wb( |
| 3869 | sde_kms->catalog, |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 3870 | intf_type, controller_id); |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3871 | if (phys_params.wb_idx == WB_MAX) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3872 | SDE_ERROR_ENC(sde_enc, |
| 3873 | "could not get wb: type %d, id %d\n", |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3874 | intf_type, controller_id); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 3875 | ret = -EINVAL; |
| 3876 | } |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 3877 | } else { |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 3878 | phys_params.wb_idx = WB_MAX; |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3879 | phys_params.intf_idx = sde_encoder_get_intf( |
| 3880 | sde_kms->catalog, intf_type, |
| 3881 | controller_id); |
| 3882 | if (phys_params.intf_idx == INTF_MAX) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3883 | SDE_ERROR_ENC(sde_enc, |
| 3884 | "could not get wb: type %d, id %d\n", |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3885 | intf_type, controller_id); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 3886 | ret = -EINVAL; |
| 3887 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3888 | } |
| 3889 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 3890 | if (!ret) { |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 3891 | if (intf_type == INTF_WB) |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3892 | ret = sde_encoder_virt_add_phys_enc_wb(sde_enc, |
| 3893 | &phys_params); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 3894 | else |
| 3895 | ret = sde_encoder_virt_add_phys_encs( |
| 3896 | disp_info->capabilities, |
Lloyd Atkinson | 6ef6cb5 | 2016-07-06 11:49:18 -0400 | [diff] [blame] | 3897 | sde_enc, |
| 3898 | &phys_params); |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 3899 | if (ret) |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 3900 | SDE_ERROR_ENC(sde_enc, |
| 3901 | "failed to add phys encs\n"); |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 3902 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3903 | } |
Dhaval Patel | d4e583a | 2017-03-10 14:46:44 -0800 | [diff] [blame] | 3904 | |
| 3905 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 3906 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
| 3907 | |
| 3908 | if (phys) { |
| 3909 | atomic_set(&phys->vsync_cnt, 0); |
| 3910 | atomic_set(&phys->underrun_cnt, 0); |
| 3911 | } |
| 3912 | } |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 3913 | mutex_unlock(&sde_enc->enc_lock); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3914 | |
| 3915 | return ret; |
| 3916 | } |
| 3917 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 3918 | static void sde_encoder_frame_done_timeout(unsigned long data) |
| 3919 | { |
| 3920 | struct drm_encoder *drm_enc = (struct drm_encoder *) data; |
| 3921 | struct sde_encoder_virt *sde_enc = to_sde_encoder_virt(drm_enc); |
| 3922 | struct msm_drm_private *priv; |
Ingrid Gallardo | 79b4439 | 2017-05-30 16:30:52 -0700 | [diff] [blame] | 3923 | u32 event; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 3924 | |
| 3925 | if (!drm_enc || !drm_enc->dev || !drm_enc->dev->dev_private) { |
| 3926 | SDE_ERROR("invalid parameters\n"); |
| 3927 | return; |
| 3928 | } |
| 3929 | priv = drm_enc->dev->dev_private; |
| 3930 | |
| 3931 | if (!sde_enc->frame_busy_mask[0] || !sde_enc->crtc_frame_event_cb) { |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 3932 | SDE_DEBUG_ENC(sde_enc, "invalid timeout\n"); |
| 3933 | SDE_EVT32(DRMID(drm_enc), sde_enc->frame_busy_mask[0], 0); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 3934 | return; |
| 3935 | } else if (!atomic_xchg(&sde_enc->frame_done_timeout, 0)) { |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 3936 | SDE_ERROR_ENC(sde_enc, "invalid timeout\n"); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 3937 | SDE_EVT32(DRMID(drm_enc), 0, 1); |
| 3938 | return; |
| 3939 | } |
| 3940 | |
Ingrid Gallardo | 79b4439 | 2017-05-30 16:30:52 -0700 | [diff] [blame] | 3941 | SDE_ERROR_ENC(sde_enc, "frame done timeout\n"); |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 3942 | |
Veera Sundaram Sankaran | 7ee9909 | 2017-06-13 11:19:36 -0700 | [diff] [blame] | 3943 | event = SDE_ENCODER_FRAME_EVENT_ERROR; |
Ingrid Gallardo | 79b4439 | 2017-05-30 16:30:52 -0700 | [diff] [blame] | 3944 | SDE_EVT32(DRMID(drm_enc), event); |
| 3945 | sde_enc->crtc_frame_event_cb(sde_enc->crtc_frame_event_cb_data, event); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 3946 | } |
| 3947 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 3948 | static const struct drm_encoder_helper_funcs sde_encoder_helper_funcs = { |
| 3949 | .mode_set = sde_encoder_virt_mode_set, |
| 3950 | .disable = sde_encoder_virt_disable, |
| 3951 | .enable = sde_encoder_virt_enable, |
| 3952 | .atomic_check = sde_encoder_virt_atomic_check, |
| 3953 | }; |
| 3954 | |
| 3955 | static const struct drm_encoder_funcs sde_encoder_funcs = { |
| 3956 | .destroy = sde_encoder_destroy, |
| 3957 | .late_register = sde_encoder_late_register, |
| 3958 | .early_unregister = sde_encoder_early_unregister, |
| 3959 | }; |
| 3960 | |
Clarence Ip | 3649f8b | 2016-10-31 09:59:44 -0400 | [diff] [blame] | 3961 | struct drm_encoder *sde_encoder_init( |
| 3962 | struct drm_device *dev, |
| 3963 | struct msm_display_info *disp_info) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3964 | { |
| 3965 | struct msm_drm_private *priv = dev->dev_private; |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 3966 | struct sde_kms *sde_kms = to_sde_kms(priv->kms); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3967 | struct drm_encoder *drm_enc = NULL; |
Lloyd Atkinson | 09fed91 | 2016-06-24 18:14:13 -0400 | [diff] [blame] | 3968 | struct sde_encoder_virt *sde_enc = NULL; |
Lloyd Atkinson | 9a84031 | 2016-06-26 10:11:08 -0400 | [diff] [blame] | 3969 | int drm_enc_mode = DRM_MODE_ENCODER_NONE; |
Dhaval Patel | 020f7e12 | 2016-11-15 14:39:18 -0800 | [diff] [blame] | 3970 | char name[SDE_NAME_SIZE]; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3971 | int ret = 0; |
| 3972 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3973 | sde_enc = kzalloc(sizeof(*sde_enc), GFP_KERNEL); |
| 3974 | if (!sde_enc) { |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 3975 | ret = -ENOMEM; |
| 3976 | goto fail; |
| 3977 | } |
| 3978 | |
Dhaval Patel | 22ef6df | 2016-10-20 14:42:52 -0700 | [diff] [blame] | 3979 | mutex_init(&sde_enc->enc_lock); |
Lloyd Atkinson | 9a84031 | 2016-06-26 10:11:08 -0400 | [diff] [blame] | 3980 | ret = sde_encoder_setup_display(sde_enc, sde_kms, disp_info, |
| 3981 | &drm_enc_mode); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3982 | if (ret) |
| 3983 | goto fail; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 3984 | |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 3985 | sde_enc->cur_master = NULL; |
Lloyd Atkinson | 7d07094 | 2016-07-26 18:35:12 -0400 | [diff] [blame] | 3986 | spin_lock_init(&sde_enc->enc_spinlock); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3987 | drm_enc = &sde_enc->base; |
Dhaval Patel | 04c7e8e | 2016-09-26 20:14:31 -0700 | [diff] [blame] | 3988 | drm_encoder_init(dev, drm_enc, &sde_encoder_funcs, drm_enc_mode, NULL); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 3989 | drm_encoder_helper_add(drm_enc, &sde_encoder_helper_funcs); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 3990 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 3991 | atomic_set(&sde_enc->frame_done_timeout, 0); |
| 3992 | setup_timer(&sde_enc->frame_done_timer, sde_encoder_frame_done_timeout, |
| 3993 | (unsigned long) sde_enc); |
| 3994 | |
Benjamin Chan | 9cd866d | 2017-08-15 14:56:34 -0400 | [diff] [blame] | 3995 | if ((disp_info->intf_type == DRM_MODE_CONNECTOR_DSI) && |
| 3996 | disp_info->is_primary) |
| 3997 | setup_timer(&sde_enc->vsync_event_timer, |
| 3998 | sde_encoder_vsync_event_handler, |
| 3999 | (unsigned long)sde_enc); |
| 4000 | |
Dhaval Patel | 020f7e12 | 2016-11-15 14:39:18 -0800 | [diff] [blame] | 4001 | snprintf(name, SDE_NAME_SIZE, "rsc_enc%u", drm_enc->base.id); |
| 4002 | sde_enc->rsc_client = sde_rsc_client_create(SDE_RSC_INDEX, name, |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 4003 | disp_info->is_primary); |
Dhaval Patel | 020f7e12 | 2016-11-15 14:39:18 -0800 | [diff] [blame] | 4004 | if (IS_ERR_OR_NULL(sde_enc->rsc_client)) { |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 4005 | SDE_DEBUG("sde rsc client create failed :%ld\n", |
Dhaval Patel | 020f7e12 | 2016-11-15 14:39:18 -0800 | [diff] [blame] | 4006 | PTR_ERR(sde_enc->rsc_client)); |
| 4007 | sde_enc->rsc_client = NULL; |
| 4008 | } |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 4009 | |
Veera Sundaram Sankaran | c9efbec | 2017-03-29 18:59:05 -0700 | [diff] [blame] | 4010 | mutex_init(&sde_enc->rc_lock); |
Lloyd Atkinson | a878138 | 2017-07-17 10:20:43 -0400 | [diff] [blame] | 4011 | kthread_init_delayed_work(&sde_enc->delayed_off_work, |
| 4012 | sde_encoder_off_work); |
Dhaval Patel | e17e0ee | 2017-08-23 18:01:42 -0700 | [diff] [blame] | 4013 | sde_enc->idle_timeout = IDLE_TIMEOUT; |
Veera Sundaram Sankaran | df79cc9 | 2017-10-10 22:32:46 -0700 | [diff] [blame] | 4014 | sde_enc->vblank_enabled = false; |
Benjamin Chan | 9cd866d | 2017-08-15 14:56:34 -0400 | [diff] [blame] | 4015 | |
| 4016 | kthread_init_work(&sde_enc->vsync_event_work, |
| 4017 | sde_encoder_vsync_event_work_handler); |
| 4018 | |
Dhaval Patel | 020f7e12 | 2016-11-15 14:39:18 -0800 | [diff] [blame] | 4019 | memcpy(&sde_enc->disp_info, disp_info, sizeof(*disp_info)); |
| 4020 | |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 4021 | SDE_DEBUG_ENC(sde_enc, "created\n"); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 4022 | |
| 4023 | return drm_enc; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 4024 | |
| 4025 | fail: |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 4026 | SDE_ERROR("failed to create encoder\n"); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 4027 | if (drm_enc) |
| 4028 | sde_encoder_destroy(drm_enc); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 4029 | |
| 4030 | return ERR_PTR(ret); |
| 4031 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 4032 | |
Jeykumar Sankaran | dfaeec9 | 2017-06-06 15:21:51 -0700 | [diff] [blame] | 4033 | int sde_encoder_wait_for_event(struct drm_encoder *drm_enc, |
| 4034 | enum msm_event_wait event) |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 4035 | { |
Jeykumar Sankaran | dfaeec9 | 2017-06-06 15:21:51 -0700 | [diff] [blame] | 4036 | int (*fn_wait)(struct sde_encoder_phys *phys_enc) = NULL; |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 4037 | struct sde_encoder_virt *sde_enc = NULL; |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 4038 | int i, ret = 0; |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 4039 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 4040 | if (!drm_enc) { |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 4041 | SDE_ERROR("invalid encoder\n"); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 4042 | return -EINVAL; |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 4043 | } |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 4044 | sde_enc = to_sde_encoder_virt(drm_enc); |
Clarence Ip | 19af136 | 2016-09-23 14:57:51 -0400 | [diff] [blame] | 4045 | SDE_DEBUG_ENC(sde_enc, "\n"); |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 4046 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 4047 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 4048 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 4049 | |
Jeykumar Sankaran | dfaeec9 | 2017-06-06 15:21:51 -0700 | [diff] [blame] | 4050 | switch (event) { |
| 4051 | case MSM_ENC_COMMIT_DONE: |
| 4052 | fn_wait = phys->ops.wait_for_commit_done; |
| 4053 | break; |
| 4054 | case MSM_ENC_TX_COMPLETE: |
| 4055 | fn_wait = phys->ops.wait_for_tx_complete; |
| 4056 | break; |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 4057 | case MSM_ENC_VBLANK: |
| 4058 | fn_wait = phys->ops.wait_for_vblank; |
| 4059 | break; |
| 4060 | default: |
| 4061 | SDE_ERROR_ENC(sde_enc, "unknown wait event %d\n", |
| 4062 | event); |
| 4063 | return -EINVAL; |
Jeykumar Sankaran | dfaeec9 | 2017-06-06 15:21:51 -0700 | [diff] [blame] | 4064 | }; |
| 4065 | |
| 4066 | if (phys && fn_wait) { |
Veera Sundaram Sankaran | a90e139 | 2017-07-06 15:00:09 -0700 | [diff] [blame] | 4067 | SDE_ATRACE_BEGIN("wait_for_completion_event"); |
Jeykumar Sankaran | dfaeec9 | 2017-06-06 15:21:51 -0700 | [diff] [blame] | 4068 | ret = fn_wait(phys); |
Veera Sundaram Sankaran | a90e139 | 2017-07-06 15:00:09 -0700 | [diff] [blame] | 4069 | SDE_ATRACE_END("wait_for_completion_event"); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 4070 | if (ret) |
| 4071 | return ret; |
| 4072 | } |
| 4073 | } |
| 4074 | |
| 4075 | return ret; |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 4076 | } |
| 4077 | |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 4078 | enum sde_intf_mode sde_encoder_get_intf_mode(struct drm_encoder *encoder) |
| 4079 | { |
| 4080 | struct sde_encoder_virt *sde_enc = NULL; |
| 4081 | int i; |
| 4082 | |
| 4083 | if (!encoder) { |
| 4084 | SDE_ERROR("invalid encoder\n"); |
| 4085 | return INTF_MODE_NONE; |
| 4086 | } |
| 4087 | sde_enc = to_sde_encoder_virt(encoder); |
| 4088 | |
| 4089 | if (sde_enc->cur_master) |
| 4090 | return sde_enc->cur_master->intf_mode; |
| 4091 | |
| 4092 | for (i = 0; i < sde_enc->num_phys_encs; i++) { |
| 4093 | struct sde_encoder_phys *phys = sde_enc->phys_encs[i]; |
| 4094 | |
| 4095 | if (phys) |
| 4096 | return phys->intf_mode; |
| 4097 | } |
| 4098 | |
| 4099 | return INTF_MODE_NONE; |
| 4100 | } |