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