Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #define pr_fmt(fmt) "dsi-hw:" fmt |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/iopoll.h> |
| 18 | |
Sandeep Panda | 7945000 | 2017-05-08 17:14:24 +0530 | [diff] [blame] | 19 | #include "dsi_catalog.h" |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 20 | #include "dsi_ctrl_hw.h" |
| 21 | #include "dsi_ctrl_reg.h" |
| 22 | #include "dsi_hw.h" |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 23 | #include "dsi_panel.h" |
Rajkumar Subbiah | 01e6dd64 | 2017-07-05 14:47:47 -0400 | [diff] [blame] | 24 | #include "dsi_catalog.h" |
Raviteja Tamatam | 68892de | 2017-06-20 04:47:19 +0530 | [diff] [blame] | 25 | #include "sde_dbg.h" |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 26 | |
| 27 | #define MMSS_MISC_CLAMP_REG_OFF 0x0014 |
Clarence Ip | 9de0bbc | 2017-03-02 09:56:06 -0500 | [diff] [blame] | 28 | #define DSI_CTRL_DYNAMIC_FORCE_ON (0x23F|BIT(8)|BIT(9)|BIT(11)|BIT(21)) |
Rajkumar Subbiah | 01e6dd64 | 2017-07-05 14:47:47 -0400 | [diff] [blame] | 29 | #define DSI_CTRL_CMD_MISR_ENABLE BIT(28) |
| 30 | #define DSI_CTRL_VIDEO_MISR_ENABLE BIT(16) |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 31 | |
| 32 | /* Unsupported formats default to RGB888 */ |
| 33 | static const u8 cmd_mode_format_map[DSI_PIXEL_FORMAT_MAX] = { |
| 34 | 0x6, 0x7, 0x8, 0x8, 0x0, 0x3, 0x4 }; |
| 35 | static const u8 video_mode_format_map[DSI_PIXEL_FORMAT_MAX] = { |
| 36 | 0x0, 0x1, 0x2, 0x3, 0x3, 0x3, 0x3 }; |
| 37 | |
| 38 | /** |
| 39 | * dsi_setup_trigger_controls() - setup dsi trigger configurations |
| 40 | * @ctrl: Pointer to the controller host hardware. |
| 41 | * @cfg: DSI host configuration that is common to both video and |
| 42 | * command modes. |
| 43 | */ |
| 44 | static void dsi_setup_trigger_controls(struct dsi_ctrl_hw *ctrl, |
| 45 | struct dsi_host_common_cfg *cfg) |
| 46 | { |
| 47 | u32 reg = 0; |
| 48 | const u8 trigger_map[DSI_TRIGGER_MAX] = { |
| 49 | 0x0, 0x2, 0x1, 0x4, 0x5, 0x6 }; |
| 50 | |
| 51 | reg |= (cfg->te_mode == DSI_TE_ON_EXT_PIN) ? BIT(31) : 0; |
| 52 | reg |= (trigger_map[cfg->dma_cmd_trigger] & 0x7); |
| 53 | reg |= (trigger_map[cfg->mdp_cmd_trigger] & 0x7) << 4; |
| 54 | DSI_W32(ctrl, DSI_TRIG_CTRL, reg); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * dsi_ctrl_hw_cmn_host_setup() - setup dsi host configuration |
| 59 | * @ctrl: Pointer to the controller host hardware. |
| 60 | * @cfg: DSI host configuration that is common to both video and |
| 61 | * command modes. |
| 62 | */ |
| 63 | void dsi_ctrl_hw_cmn_host_setup(struct dsi_ctrl_hw *ctrl, |
| 64 | struct dsi_host_common_cfg *cfg) |
| 65 | { |
| 66 | u32 reg_value = 0; |
| 67 | |
| 68 | dsi_setup_trigger_controls(ctrl, cfg); |
| 69 | |
| 70 | /* Setup clocking timing controls */ |
| 71 | reg_value = ((cfg->t_clk_post & 0x3F) << 8); |
| 72 | reg_value |= (cfg->t_clk_pre & 0x3F); |
| 73 | DSI_W32(ctrl, DSI_CLKOUT_TIMING_CTRL, reg_value); |
| 74 | |
| 75 | /* EOT packet control */ |
| 76 | reg_value = cfg->append_tx_eot ? 1 : 0; |
| 77 | reg_value |= (cfg->ignore_rx_eot ? (1 << 4) : 0); |
| 78 | DSI_W32(ctrl, DSI_EOT_PACKET_CTRL, reg_value); |
| 79 | |
| 80 | /* Turn on dsi clocks */ |
| 81 | DSI_W32(ctrl, DSI_CLK_CTRL, 0x23F); |
| 82 | |
| 83 | /* Setup DSI control register */ |
Jeykumar Sankaran | a7c7bbe | 2017-05-31 18:12:05 -0700 | [diff] [blame] | 84 | reg_value = DSI_R32(ctrl, DSI_CTRL); |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 85 | reg_value |= (cfg->en_crc_check ? BIT(24) : 0); |
| 86 | reg_value |= (cfg->en_ecc_check ? BIT(20) : 0); |
| 87 | reg_value |= BIT(8); /* Clock lane */ |
| 88 | reg_value |= ((cfg->data_lanes & DSI_DATA_LANE_3) ? BIT(7) : 0); |
| 89 | reg_value |= ((cfg->data_lanes & DSI_DATA_LANE_2) ? BIT(6) : 0); |
| 90 | reg_value |= ((cfg->data_lanes & DSI_DATA_LANE_1) ? BIT(5) : 0); |
| 91 | reg_value |= ((cfg->data_lanes & DSI_DATA_LANE_0) ? BIT(4) : 0); |
| 92 | |
| 93 | DSI_W32(ctrl, DSI_CTRL, reg_value); |
| 94 | |
Dhaval Patel | abfaa08 | 2017-07-28 12:41:10 -0700 | [diff] [blame] | 95 | if (ctrl->phy_isolation_enabled) |
| 96 | DSI_W32(ctrl, DSI_DEBUG_CTRL, BIT(28)); |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 97 | pr_debug("[DSI_%d]Host configuration complete\n", ctrl->index); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * phy_sw_reset() - perform a soft reset on the PHY. |
| 102 | * @ctrl: Pointer to the controller host hardware. |
| 103 | */ |
| 104 | void dsi_ctrl_hw_cmn_phy_sw_reset(struct dsi_ctrl_hw *ctrl) |
| 105 | { |
Clarence Ip | 9de0bbc | 2017-03-02 09:56:06 -0500 | [diff] [blame] | 106 | DSI_W32(ctrl, DSI_PHY_SW_RESET, BIT(24)|BIT(0)); |
| 107 | wmb(); /* make sure reset is asserted */ |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 108 | udelay(1000); |
| 109 | DSI_W32(ctrl, DSI_PHY_SW_RESET, 0x0); |
Clarence Ip | 9de0bbc | 2017-03-02 09:56:06 -0500 | [diff] [blame] | 110 | wmb(); /* ensure reset is cleared before waiting */ |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 111 | udelay(100); |
| 112 | |
| 113 | pr_debug("[DSI_%d] phy sw reset done\n", ctrl->index); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * soft_reset() - perform a soft reset on DSI controller |
| 118 | * @ctrl: Pointer to the controller host hardware. |
| 119 | * |
Clarence Ip | 9de0bbc | 2017-03-02 09:56:06 -0500 | [diff] [blame] | 120 | * The video, command and controller engines will be disabled before the |
| 121 | * reset is triggered and re-enabled after the reset is complete. |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 122 | * |
| 123 | * If the reset is done while MDP timing engine is turned on, the video |
| 124 | * enigne should be re-enabled only during the vertical blanking time. |
| 125 | */ |
| 126 | void dsi_ctrl_hw_cmn_soft_reset(struct dsi_ctrl_hw *ctrl) |
| 127 | { |
| 128 | u32 reg = 0; |
| 129 | u32 reg_ctrl = 0; |
| 130 | |
| 131 | /* Clear DSI_EN, VIDEO_MODE_EN, CMD_MODE_EN */ |
| 132 | reg_ctrl = DSI_R32(ctrl, DSI_CTRL); |
| 133 | DSI_W32(ctrl, DSI_CTRL, reg_ctrl & ~0x7); |
Clarence Ip | 9de0bbc | 2017-03-02 09:56:06 -0500 | [diff] [blame] | 134 | wmb(); /* wait controller to be disabled before reset */ |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 135 | |
| 136 | /* Force enable PCLK, BYTECLK, AHBM_HCLK */ |
| 137 | reg = DSI_R32(ctrl, DSI_CLK_CTRL); |
Clarence Ip | 9de0bbc | 2017-03-02 09:56:06 -0500 | [diff] [blame] | 138 | DSI_W32(ctrl, DSI_CLK_CTRL, reg | DSI_CTRL_DYNAMIC_FORCE_ON); |
| 139 | wmb(); /* wait for clocks to be enabled */ |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 140 | |
| 141 | /* Trigger soft reset */ |
| 142 | DSI_W32(ctrl, DSI_SOFT_RESET, 0x1); |
Clarence Ip | 9de0bbc | 2017-03-02 09:56:06 -0500 | [diff] [blame] | 143 | wmb(); /* wait for reset to assert before waiting */ |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 144 | udelay(1); |
| 145 | DSI_W32(ctrl, DSI_SOFT_RESET, 0x0); |
Clarence Ip | 9de0bbc | 2017-03-02 09:56:06 -0500 | [diff] [blame] | 146 | wmb(); /* ensure reset is cleared */ |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 147 | |
| 148 | /* Disable force clock on */ |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 149 | DSI_W32(ctrl, DSI_CLK_CTRL, reg); |
Clarence Ip | 9de0bbc | 2017-03-02 09:56:06 -0500 | [diff] [blame] | 150 | wmb(); /* make sure clocks are restored */ |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 151 | |
| 152 | /* Re-enable DSI controller */ |
| 153 | DSI_W32(ctrl, DSI_CTRL, reg_ctrl); |
Clarence Ip | 9de0bbc | 2017-03-02 09:56:06 -0500 | [diff] [blame] | 154 | wmb(); /* make sure DSI controller is enabled again */ |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 155 | pr_debug("[DSI_%d] ctrl soft reset done\n", ctrl->index); |
| 156 | } |
| 157 | |
| 158 | /** |
Rajkumar Subbiah | 01e6dd64 | 2017-07-05 14:47:47 -0400 | [diff] [blame] | 159 | * setup_misr() - Setup frame MISR |
| 160 | * @ctrl: Pointer to the controller host hardware. |
| 161 | * @panel_mode: CMD or VIDEO mode indicator |
| 162 | * @enable: Enable/disable MISR. |
| 163 | * @frame_count: Number of frames to accumulate MISR. |
| 164 | */ |
| 165 | void dsi_ctrl_hw_cmn_setup_misr(struct dsi_ctrl_hw *ctrl, |
| 166 | enum dsi_op_mode panel_mode, |
| 167 | bool enable, |
| 168 | u32 frame_count) |
| 169 | { |
| 170 | u32 addr; |
| 171 | u32 config = 0; |
| 172 | |
| 173 | if (panel_mode == DSI_OP_CMD_MODE) { |
| 174 | addr = DSI_MISR_CMD_CTRL; |
| 175 | if (enable) |
| 176 | config = DSI_CTRL_CMD_MISR_ENABLE; |
| 177 | } else { |
| 178 | addr = DSI_MISR_VIDEO_CTRL; |
| 179 | if (enable) |
| 180 | config = DSI_CTRL_VIDEO_MISR_ENABLE; |
| 181 | if (frame_count > 255) |
| 182 | frame_count = 255; |
| 183 | config |= frame_count << 8; |
| 184 | } |
| 185 | |
| 186 | pr_debug("[DSI_%d] MISR ctrl: 0x%x\n", ctrl->index, |
| 187 | config); |
| 188 | DSI_W32(ctrl, addr, config); |
| 189 | wmb(); /* make sure MISR is configured */ |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * collect_misr() - Read frame MISR |
| 194 | * @ctrl: Pointer to the controller host hardware. |
| 195 | * @panel_mode: CMD or VIDEO mode indicator |
| 196 | */ |
| 197 | u32 dsi_ctrl_hw_cmn_collect_misr(struct dsi_ctrl_hw *ctrl, |
| 198 | enum dsi_op_mode panel_mode) |
| 199 | { |
| 200 | u32 addr; |
| 201 | u32 enabled; |
| 202 | u32 misr = 0; |
| 203 | |
| 204 | if (panel_mode == DSI_OP_CMD_MODE) { |
| 205 | addr = DSI_MISR_CMD_MDP0_32BIT; |
| 206 | enabled = DSI_R32(ctrl, DSI_MISR_CMD_CTRL) & |
| 207 | DSI_CTRL_CMD_MISR_ENABLE; |
| 208 | } else { |
| 209 | addr = DSI_MISR_VIDEO_32BIT; |
| 210 | enabled = DSI_R32(ctrl, DSI_MISR_VIDEO_CTRL) & |
| 211 | DSI_CTRL_VIDEO_MISR_ENABLE; |
| 212 | } |
| 213 | |
| 214 | if (enabled) |
| 215 | misr = DSI_R32(ctrl, addr); |
| 216 | |
| 217 | pr_debug("[DSI_%d] MISR enabled %x value: 0x%x\n", ctrl->index, |
| 218 | enabled, misr); |
| 219 | return misr; |
| 220 | } |
| 221 | |
| 222 | /** |
Raviteja Tamatam | 68892de | 2017-06-20 04:47:19 +0530 | [diff] [blame] | 223 | * set_timing_db() - enable/disable Timing DB register |
| 224 | * @ctrl: Pointer to controller host hardware. |
| 225 | * @enable: Enable/Disable flag. |
| 226 | * |
| 227 | * Enable or Disabe the Timing DB register. |
| 228 | */ |
| 229 | void dsi_ctrl_hw_cmn_set_timing_db(struct dsi_ctrl_hw *ctrl, |
| 230 | bool enable) |
| 231 | { |
| 232 | if (enable) |
| 233 | DSI_W32(ctrl, DSI_DSI_TIMING_DB_MODE, 0x1); |
| 234 | else |
| 235 | DSI_W32(ctrl, DSI_DSI_TIMING_DB_MODE, 0x0); |
| 236 | |
| 237 | wmb(); /* make sure timing db registers are set */ |
| 238 | pr_debug("[DSI_%d] ctrl timing DB set:%d\n", ctrl->index, |
| 239 | enable); |
| 240 | SDE_EVT32(ctrl->index, enable); |
| 241 | } |
| 242 | |
| 243 | /** |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 244 | * set_video_timing() - set up the timing for video frame |
| 245 | * @ctrl: Pointer to controller host hardware. |
| 246 | * @mode: Video mode information. |
| 247 | * |
| 248 | * Set up the video timing parameters for the DSI video mode operation. |
| 249 | */ |
| 250 | void dsi_ctrl_hw_cmn_set_video_timing(struct dsi_ctrl_hw *ctrl, |
| 251 | struct dsi_mode_info *mode) |
| 252 | { |
| 253 | u32 reg = 0; |
| 254 | u32 hs_start = 0; |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 255 | u32 hs_end, active_h_start, active_h_end, h_total, width = 0; |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 256 | u32 vs_start = 0, vs_end = 0; |
| 257 | u32 vpos_start = 0, vpos_end, active_v_start, active_v_end, v_total; |
| 258 | |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 259 | if (mode->dsc_enabled && mode->dsc) { |
| 260 | width = mode->dsc->pclk_per_line; |
| 261 | reg = mode->dsc->bytes_per_pkt << 16; |
| 262 | reg |= (0x0b << 8); /* dtype of compressed image */ |
| 263 | /* |
| 264 | * pkt_per_line: |
| 265 | * 0 == 1 pkt |
| 266 | * 1 == 2 pkt |
| 267 | * 2 == 4 pkt |
| 268 | * 3 pkt is not support |
| 269 | */ |
| 270 | if (mode->dsc->pkt_per_line == 4) |
| 271 | reg |= (mode->dsc->pkt_per_line - 2) << 6; |
| 272 | else |
| 273 | reg |= (mode->dsc->pkt_per_line - 1) << 6; |
| 274 | reg |= mode->dsc->eol_byte_num << 4; |
| 275 | reg |= 1; |
| 276 | DSI_W32(ctrl, DSI_VIDEO_COMPRESSION_MODE_CTRL, reg); |
| 277 | } else { |
| 278 | width = mode->h_active; |
| 279 | } |
| 280 | |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 281 | hs_end = mode->h_sync_width; |
| 282 | active_h_start = mode->h_sync_width + mode->h_back_porch; |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 283 | active_h_end = active_h_start + width; |
| 284 | h_total = (mode->h_sync_width + mode->h_back_porch + width + |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 285 | mode->h_front_porch) - 1; |
| 286 | |
| 287 | vpos_end = mode->v_sync_width; |
| 288 | active_v_start = mode->v_sync_width + mode->v_back_porch; |
| 289 | active_v_end = active_v_start + mode->v_active; |
| 290 | v_total = (mode->v_sync_width + mode->v_back_porch + mode->v_active + |
| 291 | mode->v_front_porch) - 1; |
| 292 | |
| 293 | reg = ((active_h_end & 0xFFFF) << 16) | (active_h_start & 0xFFFF); |
| 294 | DSI_W32(ctrl, DSI_VIDEO_MODE_ACTIVE_H, reg); |
| 295 | |
| 296 | reg = ((active_v_end & 0xFFFF) << 16) | (active_v_start & 0xFFFF); |
| 297 | DSI_W32(ctrl, DSI_VIDEO_MODE_ACTIVE_V, reg); |
| 298 | |
| 299 | reg = ((v_total & 0xFFFF) << 16) | (h_total & 0xFFFF); |
| 300 | DSI_W32(ctrl, DSI_VIDEO_MODE_TOTAL, reg); |
| 301 | |
| 302 | reg = ((hs_end & 0xFFFF) << 16) | (hs_start & 0xFFFF); |
| 303 | DSI_W32(ctrl, DSI_VIDEO_MODE_HSYNC, reg); |
| 304 | |
| 305 | reg = ((vs_end & 0xFFFF) << 16) | (vs_start & 0xFFFF); |
| 306 | DSI_W32(ctrl, DSI_VIDEO_MODE_VSYNC, reg); |
| 307 | |
| 308 | reg = ((vpos_end & 0xFFFF) << 16) | (vpos_start & 0xFFFF); |
| 309 | DSI_W32(ctrl, DSI_VIDEO_MODE_VSYNC_VPOS, reg); |
| 310 | |
| 311 | /* TODO: HS TIMER value? */ |
| 312 | DSI_W32(ctrl, DSI_HS_TIMER_CTRL, 0x3FD08); |
| 313 | DSI_W32(ctrl, DSI_MISR_VIDEO_CTRL, 0x10100); |
| 314 | DSI_W32(ctrl, DSI_DSI_TIMING_FLUSH, 0x1); |
| 315 | pr_debug("[DSI_%d] ctrl video parameters updated\n", ctrl->index); |
Raviteja Tamatam | 68892de | 2017-06-20 04:47:19 +0530 | [diff] [blame] | 316 | SDE_EVT32(v_total, h_total); |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | /** |
| 320 | * setup_cmd_stream() - set up parameters for command pixel streams |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 321 | * @ctrl: Pointer to controller host hardware. |
| 322 | * @mode: Pointer to mode information. |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 323 | * @h_stride: Horizontal stride in bytes. |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 324 | * @vc_id: stream_id |
| 325 | * |
| 326 | * Setup parameters for command mode pixel stream size. |
| 327 | */ |
| 328 | void dsi_ctrl_hw_cmn_setup_cmd_stream(struct dsi_ctrl_hw *ctrl, |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 329 | struct dsi_mode_info *mode, |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 330 | u32 h_stride, |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 331 | u32 vc_id, |
| 332 | struct dsi_rect *roi) |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 333 | { |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 334 | u32 width_final, stride_final; |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 335 | u32 height_final; |
| 336 | u32 stream_total = 0, stream_ctrl = 0; |
Sravanthi Kollukuduru | d880932 | 2017-10-26 15:24:13 +0530 | [diff] [blame] | 337 | u32 reg_ctrl = 0, reg_ctrl2 = 0, data = 0; |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 338 | |
| 339 | if (roi && (!roi->w || !roi->h)) |
| 340 | return; |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 341 | |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 342 | if (mode->dsc_enabled && mode->dsc) { |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 343 | u32 reg = 0; |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 344 | u32 offset = 0; |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 345 | int pic_width, this_frame_slices, intf_ip_w; |
| 346 | struct msm_display_dsc_info dsc; |
| 347 | |
| 348 | memcpy(&dsc, mode->dsc, sizeof(dsc)); |
| 349 | pic_width = roi ? roi->w : mode->h_active; |
| 350 | this_frame_slices = pic_width / dsc.slice_width; |
| 351 | intf_ip_w = this_frame_slices * dsc.slice_width; |
| 352 | dsi_dsc_pclk_param_calc(&dsc, intf_ip_w); |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 353 | |
| 354 | if (vc_id != 0) |
| 355 | offset = 16; |
| 356 | reg_ctrl = DSI_R32(ctrl, DSI_COMMAND_COMPRESSION_MODE_CTRL); |
| 357 | reg_ctrl2 = DSI_R32(ctrl, DSI_COMMAND_COMPRESSION_MODE_CTRL2); |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 358 | width_final = dsc.pclk_per_line; |
| 359 | stride_final = dsc.bytes_per_pkt; |
| 360 | height_final = roi ? roi->h : mode->v_active; |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 361 | |
| 362 | reg = 0x39 << 8; |
| 363 | /* |
| 364 | * pkt_per_line: |
| 365 | * 0 == 1 pkt |
| 366 | * 1 == 2 pkt |
| 367 | * 2 == 4 pkt |
| 368 | * 3 pkt is not support |
| 369 | */ |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 370 | if (dsc.pkt_per_line == 4) |
| 371 | reg |= (dsc.pkt_per_line - 2) << 6; |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 372 | else |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 373 | reg |= (dsc.pkt_per_line - 1) << 6; |
| 374 | reg |= dsc.eol_byte_num << 4; |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 375 | reg |= 1; |
| 376 | |
| 377 | reg_ctrl &= ~(0xFFFF << offset); |
| 378 | reg_ctrl |= (reg << offset); |
| 379 | reg_ctrl2 &= ~(0xFFFF << offset); |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 380 | reg_ctrl2 |= (dsc.bytes_in_slice << offset); |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 381 | |
| 382 | pr_debug("ctrl %d reg_ctrl 0x%x reg_ctrl2 0x%x\n", ctrl->index, |
| 383 | reg_ctrl, reg_ctrl2); |
| 384 | } else if (roi) { |
| 385 | width_final = roi->w; |
| 386 | stride_final = roi->w * 3; |
| 387 | height_final = roi->h; |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 388 | } else { |
| 389 | width_final = mode->h_active; |
| 390 | stride_final = h_stride; |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 391 | height_final = mode->v_active; |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 392 | } |
| 393 | |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 394 | /* HS Timer value */ |
| 395 | DSI_W32(ctrl, DSI_HS_TIMER_CTRL, 0x3FD08); |
| 396 | |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 397 | stream_ctrl = (stride_final + 1) << 16; |
| 398 | stream_ctrl |= (vc_id & 0x3) << 8; |
| 399 | stream_ctrl |= 0x39; /* packet data type */ |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 400 | |
Ingrid Gallardo | 2a2befb | 2017-08-07 15:02:51 -0700 | [diff] [blame] | 401 | DSI_W32(ctrl, DSI_COMMAND_COMPRESSION_MODE_CTRL, reg_ctrl); |
| 402 | DSI_W32(ctrl, DSI_COMMAND_COMPRESSION_MODE_CTRL2, reg_ctrl2); |
| 403 | |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 404 | DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_STREAM0_CTRL, stream_ctrl); |
| 405 | DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_STREAM1_CTRL, stream_ctrl); |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 406 | |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 407 | stream_total = (height_final << 16) | width_final; |
| 408 | DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_STREAM0_TOTAL, stream_total); |
| 409 | DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_STREAM1_TOTAL, stream_total); |
| 410 | |
Sravanthi Kollukuduru | d880932 | 2017-10-26 15:24:13 +0530 | [diff] [blame] | 411 | if (ctrl->null_insertion_enabled) { |
| 412 | /* enable null packet insertion */ |
| 413 | data = (vc_id << 1); |
| 414 | data |= 0 << 16; |
| 415 | data |= 0x1; |
| 416 | DSI_W32(ctrl, DSI_COMMAND_MODE_NULL_INSERTION_CTRL, data); |
| 417 | } |
| 418 | |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 419 | pr_debug("ctrl %d stream_ctrl 0x%x stream_total 0x%x\n", ctrl->index, |
| 420 | stream_ctrl, stream_total); |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /** |
| 424 | * video_engine_setup() - Setup dsi host controller for video mode |
| 425 | * @ctrl: Pointer to controller host hardware. |
| 426 | * @common_cfg: Common configuration parameters. |
| 427 | * @cfg: Video mode configuration. |
| 428 | * |
| 429 | * Set up DSI video engine with a specific configuration. Controller and |
| 430 | * video engine are not enabled as part of this function. |
| 431 | */ |
| 432 | void dsi_ctrl_hw_cmn_video_engine_setup(struct dsi_ctrl_hw *ctrl, |
| 433 | struct dsi_host_common_cfg *common_cfg, |
| 434 | struct dsi_video_engine_cfg *cfg) |
| 435 | { |
| 436 | u32 reg = 0; |
| 437 | |
| 438 | reg |= (cfg->last_line_interleave_en ? BIT(31) : 0); |
| 439 | reg |= (cfg->pulse_mode_hsa_he ? BIT(28) : 0); |
| 440 | reg |= (cfg->hfp_lp11_en ? BIT(24) : 0); |
| 441 | reg |= (cfg->hbp_lp11_en ? BIT(20) : 0); |
| 442 | reg |= (cfg->hsa_lp11_en ? BIT(16) : 0); |
| 443 | reg |= (cfg->eof_bllp_lp11_en ? BIT(15) : 0); |
| 444 | reg |= (cfg->bllp_lp11_en ? BIT(12) : 0); |
| 445 | reg |= (cfg->traffic_mode & 0x3) << 8; |
| 446 | reg |= (cfg->vc_id & 0x3); |
| 447 | reg |= (video_mode_format_map[common_cfg->dst_format] & 0x3) << 4; |
| 448 | DSI_W32(ctrl, DSI_VIDEO_MODE_CTRL, reg); |
| 449 | |
| 450 | reg = (common_cfg->swap_mode & 0x7) << 12; |
| 451 | reg |= (common_cfg->bit_swap_red ? BIT(0) : 0); |
| 452 | reg |= (common_cfg->bit_swap_green ? BIT(4) : 0); |
| 453 | reg |= (common_cfg->bit_swap_blue ? BIT(8) : 0); |
| 454 | DSI_W32(ctrl, DSI_VIDEO_MODE_DATA_CTRL, reg); |
Shashank Babu Chinta Venkata | 2f24e98 | 2017-04-21 14:57:53 -0700 | [diff] [blame] | 455 | /* Disable Timing double buffering */ |
| 456 | DSI_W32(ctrl, DSI_DSI_TIMING_DB_MODE, 0x0); |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 457 | |
| 458 | |
| 459 | pr_debug("[DSI_%d] Video engine setup done\n", ctrl->index); |
| 460 | } |
| 461 | |
Dhaval Patel | f9f3ffe | 2017-08-16 16:03:10 -0700 | [diff] [blame] | 462 | void dsi_ctrl_hw_cmn_debug_bus(struct dsi_ctrl_hw *ctrl) |
| 463 | { |
| 464 | u32 reg = 0; |
| 465 | |
| 466 | DSI_W32(ctrl, DSI_DEBUG_BUS_CTL, 0x181); |
| 467 | |
| 468 | /* make sure that debug test point is enabled */ |
| 469 | wmb(); |
| 470 | reg = DSI_R32(ctrl, DSI_DEBUG_BUS_STATUS); |
| 471 | |
| 472 | pr_err("[DSI_%d] debug bus status:0x%x\n", ctrl->index, reg); |
| 473 | } |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 474 | /** |
| 475 | * cmd_engine_setup() - setup dsi host controller for command mode |
| 476 | * @ctrl: Pointer to the controller host hardware. |
| 477 | * @common_cfg: Common configuration parameters. |
| 478 | * @cfg: Command mode configuration. |
| 479 | * |
| 480 | * Setup DSI CMD engine with a specific configuration. Controller and |
| 481 | * command engine are not enabled as part of this function. |
| 482 | */ |
| 483 | void dsi_ctrl_hw_cmn_cmd_engine_setup(struct dsi_ctrl_hw *ctrl, |
| 484 | struct dsi_host_common_cfg *common_cfg, |
| 485 | struct dsi_cmd_engine_cfg *cfg) |
| 486 | { |
| 487 | u32 reg = 0; |
| 488 | |
| 489 | reg = (cfg->max_cmd_packets_interleave & 0xF) << 20; |
| 490 | reg |= (common_cfg->bit_swap_red ? BIT(4) : 0); |
| 491 | reg |= (common_cfg->bit_swap_green ? BIT(8) : 0); |
| 492 | reg |= (common_cfg->bit_swap_blue ? BIT(12) : 0); |
| 493 | reg |= cmd_mode_format_map[common_cfg->dst_format]; |
| 494 | DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_CTRL, reg); |
| 495 | |
| 496 | reg = DSI_R32(ctrl, DSI_COMMAND_MODE_MDP_CTRL2); |
| 497 | reg |= BIT(16); |
| 498 | DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_CTRL2, reg); |
| 499 | |
| 500 | reg = cfg->wr_mem_start & 0xFF; |
| 501 | reg |= (cfg->wr_mem_continue & 0xFF) << 8; |
| 502 | reg |= (cfg->insert_dcs_command ? BIT(16) : 0); |
| 503 | DSI_W32(ctrl, DSI_COMMAND_MODE_MDP_DCS_CMD_CTRL, reg); |
| 504 | |
| 505 | pr_debug("[DSI_%d] Cmd engine setup done\n", ctrl->index); |
| 506 | } |
| 507 | |
| 508 | /** |
| 509 | * video_engine_en() - enable DSI video engine |
| 510 | * @ctrl: Pointer to controller host hardware. |
| 511 | * @on: Enable/disabel video engine. |
| 512 | */ |
| 513 | void dsi_ctrl_hw_cmn_video_engine_en(struct dsi_ctrl_hw *ctrl, bool on) |
| 514 | { |
| 515 | u32 reg = 0; |
| 516 | |
| 517 | /* Set/Clear VIDEO_MODE_EN bit */ |
| 518 | reg = DSI_R32(ctrl, DSI_CTRL); |
| 519 | if (on) |
| 520 | reg |= BIT(1); |
| 521 | else |
| 522 | reg &= ~BIT(1); |
| 523 | |
| 524 | DSI_W32(ctrl, DSI_CTRL, reg); |
| 525 | |
| 526 | pr_debug("[DSI_%d] Video engine = %d\n", ctrl->index, on); |
| 527 | } |
| 528 | |
| 529 | /** |
| 530 | * ctrl_en() - enable DSI controller engine |
| 531 | * @ctrl: Pointer to the controller host hardware. |
| 532 | * @on: turn on/off the DSI controller engine. |
| 533 | */ |
| 534 | void dsi_ctrl_hw_cmn_ctrl_en(struct dsi_ctrl_hw *ctrl, bool on) |
| 535 | { |
| 536 | u32 reg = 0; |
Clarence Ip | 9de0bbc | 2017-03-02 09:56:06 -0500 | [diff] [blame] | 537 | u32 clk_ctrl; |
| 538 | |
| 539 | clk_ctrl = DSI_R32(ctrl, DSI_CLK_CTRL); |
| 540 | DSI_W32(ctrl, DSI_CLK_CTRL, clk_ctrl | DSI_CTRL_DYNAMIC_FORCE_ON); |
| 541 | wmb(); /* wait for clocks to enable */ |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 542 | |
| 543 | /* Set/Clear DSI_EN bit */ |
| 544 | reg = DSI_R32(ctrl, DSI_CTRL); |
| 545 | if (on) |
| 546 | reg |= BIT(0); |
| 547 | else |
| 548 | reg &= ~BIT(0); |
| 549 | |
| 550 | DSI_W32(ctrl, DSI_CTRL, reg); |
Clarence Ip | 9de0bbc | 2017-03-02 09:56:06 -0500 | [diff] [blame] | 551 | wmb(); /* wait for DSI_EN update before disabling clocks */ |
| 552 | |
| 553 | DSI_W32(ctrl, DSI_CLK_CTRL, clk_ctrl); |
| 554 | wmb(); /* make sure clocks are restored */ |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 555 | |
| 556 | pr_debug("[DSI_%d] Controller engine = %d\n", ctrl->index, on); |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * cmd_engine_en() - enable DSI controller command engine |
| 561 | * @ctrl: Pointer to the controller host hardware. |
| 562 | * @on: Turn on/off the DSI command engine. |
| 563 | */ |
| 564 | void dsi_ctrl_hw_cmn_cmd_engine_en(struct dsi_ctrl_hw *ctrl, bool on) |
| 565 | { |
| 566 | u32 reg = 0; |
| 567 | |
| 568 | /* Set/Clear CMD_MODE_EN bit */ |
| 569 | reg = DSI_R32(ctrl, DSI_CTRL); |
| 570 | if (on) |
| 571 | reg |= BIT(2); |
| 572 | else |
| 573 | reg &= ~BIT(2); |
| 574 | |
| 575 | DSI_W32(ctrl, DSI_CTRL, reg); |
| 576 | |
| 577 | pr_debug("[DSI_%d] command engine = %d\n", ctrl->index, on); |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * kickoff_command() - transmits commands stored in memory |
| 582 | * @ctrl: Pointer to the controller host hardware. |
| 583 | * @cmd: Command information. |
| 584 | * @flags: Modifiers for command transmission. |
| 585 | * |
| 586 | * The controller hardware is programmed with address and size of the |
| 587 | * command buffer. The transmission is kicked off if |
| 588 | * DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER flag is not set. If this flag is |
| 589 | * set, caller should make a separate call to trigger_command_dma() to |
| 590 | * transmit the command. |
| 591 | */ |
| 592 | void dsi_ctrl_hw_cmn_kickoff_command(struct dsi_ctrl_hw *ctrl, |
| 593 | struct dsi_ctrl_cmd_dma_info *cmd, |
| 594 | u32 flags) |
| 595 | { |
| 596 | u32 reg = 0; |
| 597 | |
| 598 | /*Set BROADCAST_EN and EMBEDDED_MODE */ |
| 599 | reg = DSI_R32(ctrl, DSI_COMMAND_MODE_DMA_CTRL); |
| 600 | if (cmd->en_broadcast) |
| 601 | reg |= BIT(31); |
| 602 | else |
| 603 | reg &= ~BIT(31); |
| 604 | |
| 605 | if (cmd->is_master) |
| 606 | reg |= BIT(30); |
| 607 | else |
| 608 | reg &= ~BIT(30); |
| 609 | |
| 610 | if (cmd->use_lpm) |
| 611 | reg |= BIT(26); |
| 612 | else |
| 613 | reg &= ~BIT(26); |
| 614 | |
Vara Reddy | dbeab89 | 2017-11-17 16:38:16 -0800 | [diff] [blame] | 615 | reg |= BIT(28);/* Select embedded mode */ |
| 616 | reg &= ~BIT(24);/* packet type */ |
| 617 | reg &= ~BIT(29);/* WC_SEL to 0 */ |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 618 | DSI_W32(ctrl, DSI_COMMAND_MODE_DMA_CTRL, reg); |
| 619 | |
Vara Reddy | dbeab89 | 2017-11-17 16:38:16 -0800 | [diff] [blame] | 620 | reg = DSI_R32(ctrl, DSI_DMA_FIFO_CTRL); |
| 621 | reg &= ~BIT(20);/* Enable write watermark*/ |
| 622 | reg &= ~BIT(16);/* Enable read watermark */ |
| 623 | |
| 624 | |
| 625 | DSI_W32(ctrl, DSI_DMA_FIFO_CTRL, reg); |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 626 | DSI_W32(ctrl, DSI_DMA_CMD_OFFSET, cmd->offset); |
| 627 | DSI_W32(ctrl, DSI_DMA_CMD_LENGTH, (cmd->length & 0xFFFFFF)); |
| 628 | |
| 629 | /* wait for writes to complete before kick off */ |
| 630 | wmb(); |
| 631 | |
| 632 | if (!(flags & DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER)) |
| 633 | DSI_W32(ctrl, DSI_CMD_MODE_DMA_SW_TRIGGER, 0x1); |
| 634 | } |
| 635 | |
| 636 | /** |
| 637 | * kickoff_fifo_command() - transmits a command using FIFO in dsi |
| 638 | * hardware. |
| 639 | * @ctrl: Pointer to the controller host hardware. |
| 640 | * @cmd: Command information. |
| 641 | * @flags: Modifiers for command transmission. |
| 642 | * |
| 643 | * The controller hardware FIFO is programmed with command header and |
| 644 | * payload. The transmission is kicked off if |
| 645 | * DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER flag is not set. If this flag is |
| 646 | * set, caller should make a separate call to trigger_command_dma() to |
| 647 | * transmit the command. |
| 648 | */ |
| 649 | void dsi_ctrl_hw_cmn_kickoff_fifo_command(struct dsi_ctrl_hw *ctrl, |
| 650 | struct dsi_ctrl_cmd_dma_fifo_info *cmd, |
| 651 | u32 flags) |
| 652 | { |
| 653 | u32 reg = 0, i = 0; |
| 654 | u32 *ptr = cmd->command; |
| 655 | /* |
| 656 | * Set CMD_DMA_TPG_EN, TPG_DMA_FIFO_MODE and |
| 657 | * CMD_DMA_PATTERN_SEL = custom pattern stored in TPG DMA FIFO |
| 658 | */ |
| 659 | reg = (BIT(1) | BIT(2) | (0x3 << 16)); |
| 660 | DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg); |
| 661 | |
| 662 | /* |
| 663 | * Program the FIFO with command buffer. Hardware requires an extra |
| 664 | * DWORD (set to zero) if the length of command buffer is odd DWORDS. |
| 665 | */ |
| 666 | for (i = 0; i < cmd->size; i += 4) { |
| 667 | DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_DMA_INIT_VAL, *ptr); |
| 668 | ptr++; |
| 669 | } |
| 670 | |
| 671 | if ((cmd->size / 4) & 0x1) |
| 672 | DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_DMA_INIT_VAL, 0); |
| 673 | |
| 674 | /*Set BROADCAST_EN and EMBEDDED_MODE */ |
| 675 | reg = DSI_R32(ctrl, DSI_COMMAND_MODE_DMA_CTRL); |
| 676 | if (cmd->en_broadcast) |
| 677 | reg |= BIT(31); |
| 678 | else |
| 679 | reg &= ~BIT(31); |
| 680 | |
| 681 | if (cmd->is_master) |
| 682 | reg |= BIT(30); |
| 683 | else |
| 684 | reg &= ~BIT(30); |
| 685 | |
| 686 | if (cmd->use_lpm) |
| 687 | reg |= BIT(26); |
| 688 | else |
| 689 | reg &= ~BIT(26); |
| 690 | |
| 691 | reg |= BIT(28); |
| 692 | |
| 693 | DSI_W32(ctrl, DSI_COMMAND_MODE_DMA_CTRL, reg); |
| 694 | |
| 695 | DSI_W32(ctrl, DSI_DMA_CMD_LENGTH, (cmd->size & 0xFFFFFFFF)); |
| 696 | /* Finish writes before command trigger */ |
| 697 | wmb(); |
| 698 | |
| 699 | if (!(flags & DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER)) |
| 700 | DSI_W32(ctrl, DSI_CMD_MODE_DMA_SW_TRIGGER, 0x1); |
| 701 | |
| 702 | pr_debug("[DSI_%d]size=%d, trigger = %d\n", |
| 703 | ctrl->index, cmd->size, |
| 704 | (flags & DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER) ? false : true); |
| 705 | } |
| 706 | |
| 707 | void dsi_ctrl_hw_cmn_reset_cmd_fifo(struct dsi_ctrl_hw *ctrl) |
| 708 | { |
| 709 | /* disable cmd dma tpg */ |
| 710 | DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, 0x0); |
| 711 | |
| 712 | DSI_W32(ctrl, DSI_TPG_DMA_FIFO_RESET, 0x1); |
| 713 | udelay(1); |
| 714 | DSI_W32(ctrl, DSI_TPG_DMA_FIFO_RESET, 0x0); |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * trigger_command_dma() - trigger transmission of command buffer. |
| 719 | * @ctrl: Pointer to the controller host hardware. |
| 720 | * |
| 721 | * This trigger can be only used if there was a prior call to |
| 722 | * kickoff_command() of kickoff_fifo_command() with |
| 723 | * DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER flag. |
| 724 | */ |
| 725 | void dsi_ctrl_hw_cmn_trigger_command_dma(struct dsi_ctrl_hw *ctrl) |
| 726 | { |
| 727 | DSI_W32(ctrl, DSI_CMD_MODE_DMA_SW_TRIGGER, 0x1); |
| 728 | pr_debug("[DSI_%d] CMD DMA triggered\n", ctrl->index); |
| 729 | } |
| 730 | |
| 731 | /** |
Sandeep Panda | 7945000 | 2017-05-08 17:14:24 +0530 | [diff] [blame] | 732 | * clear_rdbk_reg() - clear previously read panel data. |
| 733 | * @ctrl: Pointer to the controller host hardware. |
| 734 | * |
| 735 | * This function is called before sending DSI Rx command to |
| 736 | * panel in order to clear if any stale data remaining from |
| 737 | * previous read operation. |
| 738 | */ |
| 739 | void dsi_ctrl_hw_cmn_clear_rdbk_reg(struct dsi_ctrl_hw *ctrl) |
| 740 | { |
| 741 | DSI_W32(ctrl, DSI_RDBK_DATA_CTRL, 0x1); |
| 742 | wmb(); /* ensure read back register is reset */ |
| 743 | DSI_W32(ctrl, DSI_RDBK_DATA_CTRL, 0x0); |
| 744 | wmb(); /* ensure read back register is cleared */ |
| 745 | } |
| 746 | |
| 747 | /** |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 748 | * get_cmd_read_data() - get data read from the peripheral |
| 749 | * @ctrl: Pointer to the controller host hardware. |
| 750 | * @rd_buf: Buffer where data will be read into. |
| 751 | * @total_read_len: Number of bytes to read. |
| 752 | * |
| 753 | * return: number of bytes read. |
| 754 | */ |
| 755 | u32 dsi_ctrl_hw_cmn_get_cmd_read_data(struct dsi_ctrl_hw *ctrl, |
| 756 | u8 *rd_buf, |
| 757 | u32 read_offset, |
Sandeep Panda | 7945000 | 2017-05-08 17:14:24 +0530 | [diff] [blame] | 758 | u32 rx_byte, |
| 759 | u32 pkt_size, |
| 760 | u32 *hw_read_cnt) |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 761 | { |
| 762 | u32 *lp, *temp, data; |
Sandeep Panda | 7945000 | 2017-05-08 17:14:24 +0530 | [diff] [blame] | 763 | int i, j = 0, cnt, off; |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 764 | u32 read_cnt; |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 765 | u32 repeated_bytes = 0; |
| 766 | u8 reg[16] = {0}; |
Sandeep Panda | 7945000 | 2017-05-08 17:14:24 +0530 | [diff] [blame] | 767 | bool ack_err = false; |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 768 | |
| 769 | lp = (u32 *)rd_buf; |
| 770 | temp = (u32 *)reg; |
| 771 | cnt = (rx_byte + 3) >> 2; |
| 772 | |
| 773 | if (cnt > 4) |
| 774 | cnt = 4; |
| 775 | |
Sandeep Panda | 7945000 | 2017-05-08 17:14:24 +0530 | [diff] [blame] | 776 | read_cnt = (DSI_R32(ctrl, DSI_RDBK_DATA_CTRL) >> 16); |
| 777 | ack_err = (rx_byte == 4) ? (read_cnt == 8) : |
| 778 | ((read_cnt - 4) == (pkt_size + 6)); |
| 779 | |
| 780 | if (ack_err) |
| 781 | read_cnt -= 4; |
| 782 | if (!read_cnt) { |
| 783 | pr_err("Panel detected error, no data read\n"); |
| 784 | return 0; |
| 785 | } |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 786 | |
| 787 | if (read_cnt > 16) { |
Sandeep Panda | 7945000 | 2017-05-08 17:14:24 +0530 | [diff] [blame] | 788 | int bytes_shifted, data_lost = 0, rem_header = 0; |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 789 | |
Sandeep Panda | 7945000 | 2017-05-08 17:14:24 +0530 | [diff] [blame] | 790 | bytes_shifted = read_cnt - rx_byte; |
| 791 | if (bytes_shifted >= 4) |
| 792 | data_lost = bytes_shifted - 4; /* remove DCS header */ |
| 793 | else |
| 794 | rem_header = 4 - bytes_shifted; /* remaining header */ |
| 795 | |
| 796 | repeated_bytes = (read_offset - 4) - data_lost + rem_header; |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 797 | } |
| 798 | |
Sandeep Panda | 7945000 | 2017-05-08 17:14:24 +0530 | [diff] [blame] | 799 | off = DSI_RDBK_DATA0; |
| 800 | off += ((cnt - 1) * 4); |
| 801 | |
| 802 | for (i = 0; i < cnt; i++) { |
| 803 | data = DSI_R32(ctrl, off); |
| 804 | if (!repeated_bytes) |
| 805 | *lp++ = ntohl(data); |
| 806 | else |
| 807 | *temp++ = ntohl(data); |
| 808 | off -= 4; |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 809 | } |
| 810 | |
Sandeep Panda | 7945000 | 2017-05-08 17:14:24 +0530 | [diff] [blame] | 811 | if (repeated_bytes) { |
| 812 | for (i = repeated_bytes; i < 16; i++) |
| 813 | rd_buf[j++] = reg[i]; |
| 814 | } |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 815 | |
Sandeep Panda | 7945000 | 2017-05-08 17:14:24 +0530 | [diff] [blame] | 816 | *hw_read_cnt = read_cnt; |
| 817 | pr_debug("[DSI_%d] Read %d bytes\n", ctrl->index, rx_byte); |
| 818 | return rx_byte; |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | /** |
| 822 | * get_interrupt_status() - returns the interrupt status |
| 823 | * @ctrl: Pointer to the controller host hardware. |
| 824 | * |
| 825 | * Returns the ORed list of interrupts(enum dsi_status_int_type) that |
| 826 | * are active. This list does not include any error interrupts. Caller |
| 827 | * should call get_error_status for error interrupts. |
| 828 | * |
| 829 | * Return: List of active interrupts. |
| 830 | */ |
| 831 | u32 dsi_ctrl_hw_cmn_get_interrupt_status(struct dsi_ctrl_hw *ctrl) |
| 832 | { |
| 833 | u32 reg = 0; |
| 834 | u32 ints = 0; |
| 835 | |
| 836 | reg = DSI_R32(ctrl, DSI_INT_CTRL); |
| 837 | |
| 838 | if (reg & BIT(0)) |
| 839 | ints |= DSI_CMD_MODE_DMA_DONE; |
| 840 | if (reg & BIT(8)) |
| 841 | ints |= DSI_CMD_FRAME_DONE; |
| 842 | if (reg & BIT(10)) |
| 843 | ints |= DSI_CMD_STREAM0_FRAME_DONE; |
| 844 | if (reg & BIT(12)) |
| 845 | ints |= DSI_CMD_STREAM1_FRAME_DONE; |
| 846 | if (reg & BIT(14)) |
| 847 | ints |= DSI_CMD_STREAM2_FRAME_DONE; |
| 848 | if (reg & BIT(16)) |
| 849 | ints |= DSI_VIDEO_MODE_FRAME_DONE; |
| 850 | if (reg & BIT(20)) |
| 851 | ints |= DSI_BTA_DONE; |
| 852 | if (reg & BIT(28)) |
| 853 | ints |= DSI_DYN_REFRESH_DONE; |
| 854 | if (reg & BIT(30)) |
| 855 | ints |= DSI_DESKEW_DONE; |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 856 | if (reg & BIT(24)) |
| 857 | ints |= DSI_ERROR; |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 858 | |
| 859 | pr_debug("[DSI_%d] Interrupt status = 0x%x, INT_CTRL=0x%x\n", |
| 860 | ctrl->index, ints, reg); |
| 861 | return ints; |
| 862 | } |
| 863 | |
| 864 | /** |
| 865 | * clear_interrupt_status() - clears the specified interrupts |
| 866 | * @ctrl: Pointer to the controller host hardware. |
| 867 | * @ints: List of interrupts to be cleared. |
| 868 | */ |
| 869 | void dsi_ctrl_hw_cmn_clear_interrupt_status(struct dsi_ctrl_hw *ctrl, u32 ints) |
| 870 | { |
| 871 | u32 reg = 0; |
| 872 | |
Clarence Ip | 80ada7f | 2017-05-04 09:55:21 -0700 | [diff] [blame] | 873 | reg = DSI_R32(ctrl, DSI_INT_CTRL); |
| 874 | |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 875 | if (ints & DSI_CMD_MODE_DMA_DONE) |
| 876 | reg |= BIT(0); |
| 877 | if (ints & DSI_CMD_FRAME_DONE) |
| 878 | reg |= BIT(8); |
| 879 | if (ints & DSI_CMD_STREAM0_FRAME_DONE) |
| 880 | reg |= BIT(10); |
| 881 | if (ints & DSI_CMD_STREAM1_FRAME_DONE) |
| 882 | reg |= BIT(12); |
| 883 | if (ints & DSI_CMD_STREAM2_FRAME_DONE) |
| 884 | reg |= BIT(14); |
| 885 | if (ints & DSI_VIDEO_MODE_FRAME_DONE) |
| 886 | reg |= BIT(16); |
| 887 | if (ints & DSI_BTA_DONE) |
| 888 | reg |= BIT(20); |
| 889 | if (ints & DSI_DYN_REFRESH_DONE) |
| 890 | reg |= BIT(28); |
| 891 | if (ints & DSI_DESKEW_DONE) |
| 892 | reg |= BIT(30); |
| 893 | |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 894 | /* |
| 895 | * Do not clear error status. |
| 896 | * It will be cleared as part of |
| 897 | * error handler function. |
| 898 | */ |
| 899 | reg &= ~BIT(24); |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 900 | DSI_W32(ctrl, DSI_INT_CTRL, reg); |
| 901 | |
| 902 | pr_debug("[DSI_%d] Clear interrupts, ints = 0x%x, INT_CTRL=0x%x\n", |
| 903 | ctrl->index, ints, reg); |
| 904 | } |
| 905 | |
| 906 | /** |
| 907 | * enable_status_interrupts() - enable the specified interrupts |
| 908 | * @ctrl: Pointer to the controller host hardware. |
| 909 | * @ints: List of interrupts to be enabled. |
| 910 | * |
| 911 | * Enables the specified interrupts. This list will override the |
| 912 | * previous interrupts enabled through this function. Caller has to |
| 913 | * maintain the state of the interrupts enabled. To disable all |
| 914 | * interrupts, set ints to 0. |
| 915 | */ |
| 916 | void dsi_ctrl_hw_cmn_enable_status_interrupts( |
| 917 | struct dsi_ctrl_hw *ctrl, u32 ints) |
| 918 | { |
| 919 | u32 reg = 0; |
| 920 | |
| 921 | /* Do not change value of DSI_ERROR_MASK bit */ |
| 922 | reg |= (DSI_R32(ctrl, DSI_INT_CTRL) & BIT(25)); |
| 923 | if (ints & DSI_CMD_MODE_DMA_DONE) |
| 924 | reg |= BIT(1); |
| 925 | if (ints & DSI_CMD_FRAME_DONE) |
| 926 | reg |= BIT(9); |
| 927 | if (ints & DSI_CMD_STREAM0_FRAME_DONE) |
| 928 | reg |= BIT(11); |
| 929 | if (ints & DSI_CMD_STREAM1_FRAME_DONE) |
| 930 | reg |= BIT(13); |
| 931 | if (ints & DSI_CMD_STREAM2_FRAME_DONE) |
| 932 | reg |= BIT(15); |
| 933 | if (ints & DSI_VIDEO_MODE_FRAME_DONE) |
| 934 | reg |= BIT(17); |
| 935 | if (ints & DSI_BTA_DONE) |
| 936 | reg |= BIT(21); |
| 937 | if (ints & DSI_DYN_REFRESH_DONE) |
| 938 | reg |= BIT(29); |
| 939 | if (ints & DSI_DESKEW_DONE) |
| 940 | reg |= BIT(31); |
| 941 | |
| 942 | DSI_W32(ctrl, DSI_INT_CTRL, reg); |
| 943 | |
| 944 | pr_debug("[DSI_%d] Enable interrupts 0x%x, INT_CTRL=0x%x\n", |
| 945 | ctrl->index, ints, reg); |
| 946 | } |
| 947 | |
| 948 | /** |
| 949 | * get_error_status() - returns the error status |
| 950 | * @ctrl: Pointer to the controller host hardware. |
| 951 | * |
| 952 | * Returns the ORed list of errors(enum dsi_error_int_type) that are |
| 953 | * active. This list does not include any status interrupts. Caller |
| 954 | * should call get_interrupt_status for status interrupts. |
| 955 | * |
| 956 | * Return: List of active error interrupts. |
| 957 | */ |
| 958 | u64 dsi_ctrl_hw_cmn_get_error_status(struct dsi_ctrl_hw *ctrl) |
| 959 | { |
| 960 | u32 dln0_phy_err; |
| 961 | u32 fifo_status; |
| 962 | u32 ack_error; |
| 963 | u32 timeout_errors; |
| 964 | u32 clk_error; |
| 965 | u32 dsi_status; |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 966 | u64 errors = 0, shift = 0x1; |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 967 | |
| 968 | dln0_phy_err = DSI_R32(ctrl, DSI_DLN0_PHY_ERR); |
| 969 | if (dln0_phy_err & BIT(0)) |
| 970 | errors |= DSI_DLN0_ESC_ENTRY_ERR; |
| 971 | if (dln0_phy_err & BIT(4)) |
| 972 | errors |= DSI_DLN0_ESC_SYNC_ERR; |
| 973 | if (dln0_phy_err & BIT(8)) |
| 974 | errors |= DSI_DLN0_LP_CONTROL_ERR; |
| 975 | if (dln0_phy_err & BIT(12)) |
| 976 | errors |= DSI_DLN0_LP0_CONTENTION; |
| 977 | if (dln0_phy_err & BIT(16)) |
| 978 | errors |= DSI_DLN0_LP1_CONTENTION; |
| 979 | |
| 980 | fifo_status = DSI_R32(ctrl, DSI_FIFO_STATUS); |
| 981 | if (fifo_status & BIT(7)) |
| 982 | errors |= DSI_CMD_MDP_FIFO_UNDERFLOW; |
| 983 | if (fifo_status & BIT(10)) |
| 984 | errors |= DSI_CMD_DMA_FIFO_UNDERFLOW; |
| 985 | if (fifo_status & BIT(18)) |
| 986 | errors |= DSI_DLN0_HS_FIFO_OVERFLOW; |
| 987 | if (fifo_status & BIT(19)) |
| 988 | errors |= DSI_DLN0_HS_FIFO_UNDERFLOW; |
| 989 | if (fifo_status & BIT(22)) |
| 990 | errors |= DSI_DLN1_HS_FIFO_OVERFLOW; |
| 991 | if (fifo_status & BIT(23)) |
| 992 | errors |= DSI_DLN1_HS_FIFO_UNDERFLOW; |
| 993 | if (fifo_status & BIT(26)) |
| 994 | errors |= DSI_DLN2_HS_FIFO_OVERFLOW; |
| 995 | if (fifo_status & BIT(27)) |
| 996 | errors |= DSI_DLN2_HS_FIFO_UNDERFLOW; |
| 997 | if (fifo_status & BIT(30)) |
| 998 | errors |= DSI_DLN3_HS_FIFO_OVERFLOW; |
| 999 | if (fifo_status & BIT(31)) |
| 1000 | errors |= DSI_DLN3_HS_FIFO_UNDERFLOW; |
| 1001 | |
| 1002 | ack_error = DSI_R32(ctrl, DSI_ACK_ERR_STATUS); |
| 1003 | if (ack_error & BIT(16)) |
| 1004 | errors |= DSI_RDBK_SINGLE_ECC_ERR; |
| 1005 | if (ack_error & BIT(17)) |
| 1006 | errors |= DSI_RDBK_MULTI_ECC_ERR; |
| 1007 | if (ack_error & BIT(20)) |
| 1008 | errors |= DSI_RDBK_CRC_ERR; |
| 1009 | if (ack_error & BIT(23)) |
| 1010 | errors |= DSI_RDBK_INCOMPLETE_PKT; |
| 1011 | if (ack_error & BIT(24)) |
| 1012 | errors |= DSI_PERIPH_ERROR_PKT; |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 1013 | if (ack_error & BIT(15)) |
| 1014 | errors |= (shift << DSI_EINT_PANEL_SPECIFIC_ERR); |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 1015 | |
| 1016 | timeout_errors = DSI_R32(ctrl, DSI_TIMEOUT_STATUS); |
| 1017 | if (timeout_errors & BIT(0)) |
| 1018 | errors |= DSI_HS_TX_TIMEOUT; |
| 1019 | if (timeout_errors & BIT(4)) |
| 1020 | errors |= DSI_LP_RX_TIMEOUT; |
| 1021 | if (timeout_errors & BIT(8)) |
| 1022 | errors |= DSI_BTA_TIMEOUT; |
| 1023 | |
| 1024 | clk_error = DSI_R32(ctrl, DSI_CLK_STATUS); |
| 1025 | if (clk_error & BIT(16)) |
| 1026 | errors |= DSI_PLL_UNLOCK; |
| 1027 | |
| 1028 | dsi_status = DSI_R32(ctrl, DSI_STATUS); |
| 1029 | if (dsi_status & BIT(31)) |
| 1030 | errors |= DSI_INTERLEAVE_OP_CONTENTION; |
| 1031 | |
| 1032 | pr_debug("[DSI_%d] Error status = 0x%llx, phy=0x%x, fifo=0x%x", |
| 1033 | ctrl->index, errors, dln0_phy_err, fifo_status); |
| 1034 | pr_debug("[DSI_%d] ack=0x%x, timeout=0x%x, clk=0x%x, dsi=0x%x\n", |
| 1035 | ctrl->index, ack_error, timeout_errors, clk_error, dsi_status); |
| 1036 | return errors; |
| 1037 | } |
| 1038 | |
| 1039 | /** |
| 1040 | * clear_error_status() - clears the specified errors |
| 1041 | * @ctrl: Pointer to the controller host hardware. |
| 1042 | * @errors: List of errors to be cleared. |
| 1043 | */ |
| 1044 | void dsi_ctrl_hw_cmn_clear_error_status(struct dsi_ctrl_hw *ctrl, u64 errors) |
| 1045 | { |
| 1046 | u32 dln0_phy_err = 0; |
| 1047 | u32 fifo_status = 0; |
| 1048 | u32 ack_error = 0; |
| 1049 | u32 timeout_error = 0; |
| 1050 | u32 clk_error = 0; |
| 1051 | u32 dsi_status = 0; |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 1052 | |
| 1053 | if (errors & DSI_RDBK_SINGLE_ECC_ERR) |
| 1054 | ack_error |= BIT(16); |
| 1055 | if (errors & DSI_RDBK_MULTI_ECC_ERR) |
| 1056 | ack_error |= BIT(17); |
| 1057 | if (errors & DSI_RDBK_CRC_ERR) |
| 1058 | ack_error |= BIT(20); |
| 1059 | if (errors & DSI_RDBK_INCOMPLETE_PKT) |
| 1060 | ack_error |= BIT(23); |
| 1061 | if (errors & DSI_PERIPH_ERROR_PKT) |
| 1062 | ack_error |= BIT(24); |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 1063 | if (errors & DSI_PANEL_SPECIFIC_ERR) |
| 1064 | ack_error |= BIT(15); |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 1065 | |
| 1066 | if (errors & DSI_LP_RX_TIMEOUT) |
| 1067 | timeout_error |= BIT(4); |
| 1068 | if (errors & DSI_HS_TX_TIMEOUT) |
| 1069 | timeout_error |= BIT(0); |
| 1070 | if (errors & DSI_BTA_TIMEOUT) |
| 1071 | timeout_error |= BIT(8); |
| 1072 | |
| 1073 | if (errors & DSI_PLL_UNLOCK) |
| 1074 | clk_error |= BIT(16); |
| 1075 | |
| 1076 | if (errors & DSI_DLN0_LP0_CONTENTION) |
| 1077 | dln0_phy_err |= BIT(12); |
| 1078 | if (errors & DSI_DLN0_LP1_CONTENTION) |
| 1079 | dln0_phy_err |= BIT(16); |
| 1080 | if (errors & DSI_DLN0_ESC_ENTRY_ERR) |
| 1081 | dln0_phy_err |= BIT(0); |
| 1082 | if (errors & DSI_DLN0_ESC_SYNC_ERR) |
| 1083 | dln0_phy_err |= BIT(4); |
| 1084 | if (errors & DSI_DLN0_LP_CONTROL_ERR) |
| 1085 | dln0_phy_err |= BIT(8); |
| 1086 | |
| 1087 | if (errors & DSI_CMD_DMA_FIFO_UNDERFLOW) |
| 1088 | fifo_status |= BIT(10); |
| 1089 | if (errors & DSI_CMD_MDP_FIFO_UNDERFLOW) |
| 1090 | fifo_status |= BIT(7); |
| 1091 | if (errors & DSI_DLN0_HS_FIFO_OVERFLOW) |
| 1092 | fifo_status |= BIT(18); |
| 1093 | if (errors & DSI_DLN1_HS_FIFO_OVERFLOW) |
| 1094 | fifo_status |= BIT(22); |
| 1095 | if (errors & DSI_DLN2_HS_FIFO_OVERFLOW) |
| 1096 | fifo_status |= BIT(26); |
| 1097 | if (errors & DSI_DLN3_HS_FIFO_OVERFLOW) |
| 1098 | fifo_status |= BIT(30); |
| 1099 | if (errors & DSI_DLN0_HS_FIFO_UNDERFLOW) |
| 1100 | fifo_status |= BIT(19); |
| 1101 | if (errors & DSI_DLN1_HS_FIFO_UNDERFLOW) |
| 1102 | fifo_status |= BIT(23); |
| 1103 | if (errors & DSI_DLN2_HS_FIFO_UNDERFLOW) |
| 1104 | fifo_status |= BIT(27); |
| 1105 | if (errors & DSI_DLN3_HS_FIFO_UNDERFLOW) |
| 1106 | fifo_status |= BIT(31); |
| 1107 | |
| 1108 | if (errors & DSI_INTERLEAVE_OP_CONTENTION) |
| 1109 | dsi_status |= BIT(31); |
| 1110 | |
| 1111 | DSI_W32(ctrl, DSI_DLN0_PHY_ERR, dln0_phy_err); |
| 1112 | DSI_W32(ctrl, DSI_FIFO_STATUS, fifo_status); |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 1113 | /* Writing of an extra 0 is needed to clear ack error bits */ |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 1114 | DSI_W32(ctrl, DSI_ACK_ERR_STATUS, ack_error); |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 1115 | wmb(); /* make sure register is committed */ |
| 1116 | DSI_W32(ctrl, DSI_ACK_ERR_STATUS, 0x0); |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 1117 | DSI_W32(ctrl, DSI_TIMEOUT_STATUS, timeout_error); |
| 1118 | DSI_W32(ctrl, DSI_CLK_STATUS, clk_error); |
| 1119 | DSI_W32(ctrl, DSI_STATUS, dsi_status); |
| 1120 | |
Padmanabhan Komanduru | 8ee8ee5 | 2016-12-19 12:10:51 +0530 | [diff] [blame] | 1121 | pr_debug("[DSI_%d] clear errors = 0x%llx, phy=0x%x, fifo=0x%x", |
| 1122 | ctrl->index, errors, dln0_phy_err, fifo_status); |
| 1123 | pr_debug("[DSI_%d] ack=0x%x, timeout=0x%x, clk=0x%x, dsi=0x%x\n", |
| 1124 | ctrl->index, ack_error, timeout_error, clk_error, dsi_status); |
| 1125 | } |
| 1126 | |
| 1127 | /** |
| 1128 | * enable_error_interrupts() - enable the specified interrupts |
| 1129 | * @ctrl: Pointer to the controller host hardware. |
| 1130 | * @errors: List of errors to be enabled. |
| 1131 | * |
| 1132 | * Enables the specified interrupts. This list will override the |
| 1133 | * previous interrupts enabled through this function. Caller has to |
| 1134 | * maintain the state of the interrupts enabled. To disable all |
| 1135 | * interrupts, set errors to 0. |
| 1136 | */ |
| 1137 | void dsi_ctrl_hw_cmn_enable_error_interrupts(struct dsi_ctrl_hw *ctrl, |
| 1138 | u64 errors) |
| 1139 | { |
| 1140 | u32 int_ctrl = 0; |
| 1141 | u32 int_mask0 = 0x7FFF3BFF; |
| 1142 | |
| 1143 | int_ctrl = DSI_R32(ctrl, DSI_INT_CTRL); |
| 1144 | if (errors) |
| 1145 | int_ctrl |= BIT(25); |
| 1146 | else |
| 1147 | int_ctrl &= ~BIT(25); |
| 1148 | |
| 1149 | if (errors & DSI_RDBK_SINGLE_ECC_ERR) |
| 1150 | int_mask0 &= ~BIT(0); |
| 1151 | if (errors & DSI_RDBK_MULTI_ECC_ERR) |
| 1152 | int_mask0 &= ~BIT(1); |
| 1153 | if (errors & DSI_RDBK_CRC_ERR) |
| 1154 | int_mask0 &= ~BIT(2); |
| 1155 | if (errors & DSI_RDBK_INCOMPLETE_PKT) |
| 1156 | int_mask0 &= ~BIT(3); |
| 1157 | if (errors & DSI_PERIPH_ERROR_PKT) |
| 1158 | int_mask0 &= ~BIT(4); |
| 1159 | |
| 1160 | if (errors & DSI_LP_RX_TIMEOUT) |
| 1161 | int_mask0 &= ~BIT(5); |
| 1162 | if (errors & DSI_HS_TX_TIMEOUT) |
| 1163 | int_mask0 &= ~BIT(6); |
| 1164 | if (errors & DSI_BTA_TIMEOUT) |
| 1165 | int_mask0 &= ~BIT(7); |
| 1166 | |
| 1167 | if (errors & DSI_PLL_UNLOCK) |
| 1168 | int_mask0 &= ~BIT(28); |
| 1169 | |
| 1170 | if (errors & DSI_DLN0_LP0_CONTENTION) |
| 1171 | int_mask0 &= ~BIT(24); |
| 1172 | if (errors & DSI_DLN0_LP1_CONTENTION) |
| 1173 | int_mask0 &= ~BIT(25); |
| 1174 | if (errors & DSI_DLN0_ESC_ENTRY_ERR) |
| 1175 | int_mask0 &= ~BIT(21); |
| 1176 | if (errors & DSI_DLN0_ESC_SYNC_ERR) |
| 1177 | int_mask0 &= ~BIT(22); |
| 1178 | if (errors & DSI_DLN0_LP_CONTROL_ERR) |
| 1179 | int_mask0 &= ~BIT(23); |
| 1180 | |
| 1181 | if (errors & DSI_CMD_DMA_FIFO_UNDERFLOW) |
| 1182 | int_mask0 &= ~BIT(9); |
| 1183 | if (errors & DSI_CMD_MDP_FIFO_UNDERFLOW) |
| 1184 | int_mask0 &= ~BIT(11); |
| 1185 | if (errors & DSI_DLN0_HS_FIFO_OVERFLOW) |
| 1186 | int_mask0 &= ~BIT(16); |
| 1187 | if (errors & DSI_DLN1_HS_FIFO_OVERFLOW) |
| 1188 | int_mask0 &= ~BIT(17); |
| 1189 | if (errors & DSI_DLN2_HS_FIFO_OVERFLOW) |
| 1190 | int_mask0 &= ~BIT(18); |
| 1191 | if (errors & DSI_DLN3_HS_FIFO_OVERFLOW) |
| 1192 | int_mask0 &= ~BIT(19); |
| 1193 | if (errors & DSI_DLN0_HS_FIFO_UNDERFLOW) |
| 1194 | int_mask0 &= ~BIT(26); |
| 1195 | if (errors & DSI_DLN1_HS_FIFO_UNDERFLOW) |
| 1196 | int_mask0 &= ~BIT(27); |
| 1197 | if (errors & DSI_DLN2_HS_FIFO_UNDERFLOW) |
| 1198 | int_mask0 &= ~BIT(29); |
| 1199 | if (errors & DSI_DLN3_HS_FIFO_UNDERFLOW) |
| 1200 | int_mask0 &= ~BIT(30); |
| 1201 | |
| 1202 | if (errors & DSI_INTERLEAVE_OP_CONTENTION) |
| 1203 | int_mask0 &= ~BIT(8); |
| 1204 | |
| 1205 | DSI_W32(ctrl, DSI_INT_CTRL, int_ctrl); |
| 1206 | DSI_W32(ctrl, DSI_ERR_INT_MASK0, int_mask0); |
| 1207 | |
| 1208 | pr_debug("[DSI_%d] enable errors = 0x%llx, int_mask0=0x%x\n", |
| 1209 | ctrl->index, errors, int_mask0); |
| 1210 | } |
| 1211 | |
| 1212 | /** |
| 1213 | * video_test_pattern_setup() - setup test pattern engine for video mode |
| 1214 | * @ctrl: Pointer to the controller host hardware. |
| 1215 | * @type: Type of test pattern. |
| 1216 | * @init_val: Initial value to use for generating test pattern. |
| 1217 | */ |
| 1218 | void dsi_ctrl_hw_cmn_video_test_pattern_setup(struct dsi_ctrl_hw *ctrl, |
| 1219 | enum dsi_test_pattern type, |
| 1220 | u32 init_val) |
| 1221 | { |
| 1222 | u32 reg = 0; |
| 1223 | |
| 1224 | DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_VIDEO_INIT_VAL, init_val); |
| 1225 | |
| 1226 | switch (type) { |
| 1227 | case DSI_TEST_PATTERN_FIXED: |
| 1228 | reg |= (0x2 << 4); |
| 1229 | break; |
| 1230 | case DSI_TEST_PATTERN_INC: |
| 1231 | reg |= (0x1 << 4); |
| 1232 | break; |
| 1233 | case DSI_TEST_PATTERN_POLY: |
| 1234 | DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_VIDEO_POLY, 0xF0F0F); |
| 1235 | break; |
| 1236 | default: |
| 1237 | break; |
| 1238 | } |
| 1239 | |
| 1240 | DSI_W32(ctrl, DSI_TPG_MAIN_CONTROL, 0x100); |
| 1241 | DSI_W32(ctrl, DSI_TPG_VIDEO_CONFIG, 0x5); |
| 1242 | DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg); |
| 1243 | |
| 1244 | pr_debug("[DSI_%d] Video test pattern setup done\n", ctrl->index); |
| 1245 | } |
| 1246 | |
| 1247 | /** |
| 1248 | * cmd_test_pattern_setup() - setup test patttern engine for cmd mode |
| 1249 | * @ctrl: Pointer to the controller host hardware. |
| 1250 | * @type: Type of test pattern. |
| 1251 | * @init_val: Initial value to use for generating test pattern. |
| 1252 | * @stream_id: Stream Id on which packets are generated. |
| 1253 | */ |
| 1254 | void dsi_ctrl_hw_cmn_cmd_test_pattern_setup(struct dsi_ctrl_hw *ctrl, |
| 1255 | enum dsi_test_pattern type, |
| 1256 | u32 init_val, |
| 1257 | u32 stream_id) |
| 1258 | { |
| 1259 | u32 reg = 0; |
| 1260 | u32 init_offset; |
| 1261 | u32 poly_offset; |
| 1262 | u32 pattern_sel_shift; |
| 1263 | |
| 1264 | switch (stream_id) { |
| 1265 | case 0: |
| 1266 | init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL0; |
| 1267 | poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM0_POLY; |
| 1268 | pattern_sel_shift = 8; |
| 1269 | break; |
| 1270 | case 1: |
| 1271 | init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL1; |
| 1272 | poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM1_POLY; |
| 1273 | pattern_sel_shift = 12; |
| 1274 | break; |
| 1275 | case 2: |
| 1276 | init_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_INIT_VAL2; |
| 1277 | poly_offset = DSI_TEST_PATTERN_GEN_CMD_MDP_STREAM2_POLY; |
| 1278 | pattern_sel_shift = 20; |
| 1279 | break; |
| 1280 | default: |
| 1281 | return; |
| 1282 | } |
| 1283 | |
| 1284 | DSI_W32(ctrl, init_offset, init_val); |
| 1285 | |
| 1286 | switch (type) { |
| 1287 | case DSI_TEST_PATTERN_FIXED: |
| 1288 | reg |= (0x2 << pattern_sel_shift); |
| 1289 | break; |
| 1290 | case DSI_TEST_PATTERN_INC: |
| 1291 | reg |= (0x1 << pattern_sel_shift); |
| 1292 | break; |
| 1293 | case DSI_TEST_PATTERN_POLY: |
| 1294 | DSI_W32(ctrl, poly_offset, 0xF0F0F); |
| 1295 | break; |
| 1296 | default: |
| 1297 | break; |
| 1298 | } |
| 1299 | |
| 1300 | DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg); |
| 1301 | pr_debug("[DSI_%d] Cmd test pattern setup done\n", ctrl->index); |
| 1302 | } |
| 1303 | |
| 1304 | /** |
| 1305 | * test_pattern_enable() - enable test pattern engine |
| 1306 | * @ctrl: Pointer to the controller host hardware. |
| 1307 | * @enable: Enable/Disable test pattern engine. |
| 1308 | */ |
| 1309 | void dsi_ctrl_hw_cmn_test_pattern_enable(struct dsi_ctrl_hw *ctrl, |
| 1310 | bool enable) |
| 1311 | { |
| 1312 | u32 reg = DSI_R32(ctrl, DSI_TEST_PATTERN_GEN_CTRL); |
| 1313 | |
| 1314 | if (enable) |
| 1315 | reg |= BIT(0); |
| 1316 | else |
| 1317 | reg &= ~BIT(0); |
| 1318 | |
| 1319 | DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CTRL, reg); |
| 1320 | |
| 1321 | pr_debug("[DSI_%d] Test pattern enable=%d\n", ctrl->index, enable); |
| 1322 | } |
| 1323 | |
| 1324 | /** |
| 1325 | * trigger_cmd_test_pattern() - trigger a command mode frame update with |
| 1326 | * test pattern |
| 1327 | * @ctrl: Pointer to the controller host hardware. |
| 1328 | * @stream_id: Stream on which frame update is sent. |
| 1329 | */ |
| 1330 | void dsi_ctrl_hw_cmn_trigger_cmd_test_pattern(struct dsi_ctrl_hw *ctrl, |
| 1331 | u32 stream_id) |
| 1332 | { |
| 1333 | switch (stream_id) { |
| 1334 | case 0: |
| 1335 | DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM0_TRIGGER, 0x1); |
| 1336 | break; |
| 1337 | case 1: |
| 1338 | DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM1_TRIGGER, 0x1); |
| 1339 | break; |
| 1340 | case 2: |
| 1341 | DSI_W32(ctrl, DSI_TEST_PATTERN_GEN_CMD_STREAM2_TRIGGER, 0x1); |
| 1342 | break; |
| 1343 | default: |
| 1344 | break; |
| 1345 | } |
| 1346 | |
| 1347 | pr_debug("[DSI_%d] Cmd Test pattern trigger\n", ctrl->index); |
| 1348 | } |
| 1349 | |
| 1350 | void dsi_ctrl_hw_dln0_phy_err(struct dsi_ctrl_hw *ctrl) |
| 1351 | { |
| 1352 | u32 status = 0; |
| 1353 | /* |
| 1354 | * Clear out any phy errors prior to exiting ULPS |
| 1355 | * This fixes certain instances where phy does not exit |
| 1356 | * ULPS cleanly. Also, do not print error during such cases. |
| 1357 | */ |
| 1358 | status = DSI_R32(ctrl, DSI_DLN0_PHY_ERR); |
| 1359 | if (status & 0x011111) { |
| 1360 | DSI_W32(ctrl, DSI_DLN0_PHY_ERR, status); |
| 1361 | pr_err("%s: phy_err_status = %x\n", __func__, status); |
| 1362 | } |
| 1363 | } |
| 1364 | |
| 1365 | void dsi_ctrl_hw_cmn_phy_reset_config(struct dsi_ctrl_hw *ctrl, |
| 1366 | bool enable) |
| 1367 | { |
| 1368 | u32 reg = 0; |
| 1369 | |
| 1370 | reg = DSI_MMSS_MISC_R32(ctrl, MMSS_MISC_CLAMP_REG_OFF); |
| 1371 | |
| 1372 | /* Mask/unmask disable PHY reset bit */ |
| 1373 | if (enable) |
| 1374 | reg |= BIT(30); |
| 1375 | else |
| 1376 | reg &= ~BIT(30); |
| 1377 | |
| 1378 | DSI_MMSS_MISC_W32(ctrl, MMSS_MISC_CLAMP_REG_OFF, reg); |
| 1379 | } |
| 1380 | |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 1381 | int dsi_ctrl_hw_cmn_ctrl_reset(struct dsi_ctrl_hw *ctrl, |
| 1382 | int mask) |
| 1383 | { |
| 1384 | int rc = 0; |
| 1385 | u32 data; |
| 1386 | |
| 1387 | pr_debug("DSI CTRL and PHY reset. ctrl-num = %d %d\n", |
| 1388 | ctrl->index, mask); |
| 1389 | |
| 1390 | data = DSI_R32(ctrl, 0x0004); |
| 1391 | /* Disable DSI video mode */ |
| 1392 | DSI_W32(ctrl, 0x004, (data & ~BIT(1))); |
| 1393 | wmb(); /* ensure register committed */ |
| 1394 | /* Disable DSI controller */ |
| 1395 | DSI_W32(ctrl, 0x004, (data & ~(BIT(0) | BIT(1)))); |
| 1396 | wmb(); /* ensure register committed */ |
| 1397 | /* "Force On" all dynamic clocks */ |
| 1398 | DSI_W32(ctrl, 0x11c, 0x100a00); |
| 1399 | |
| 1400 | /* DSI_SW_RESET */ |
| 1401 | DSI_W32(ctrl, 0x118, 0x1); |
| 1402 | wmb(); /* ensure register is committed */ |
| 1403 | DSI_W32(ctrl, 0x118, 0x0); |
| 1404 | wmb(); /* ensure register is committed */ |
| 1405 | |
| 1406 | /* Remove "Force On" all dynamic clocks */ |
| 1407 | DSI_W32(ctrl, 0x11c, 0x00); |
| 1408 | /* Enable DSI controller */ |
| 1409 | DSI_W32(ctrl, 0x004, (data & ~BIT(1))); |
| 1410 | wmb(); /* ensure register committed */ |
| 1411 | |
| 1412 | return rc; |
| 1413 | } |
| 1414 | |
| 1415 | void dsi_ctrl_hw_cmn_mask_error_intr(struct dsi_ctrl_hw *ctrl, u32 idx, bool en) |
| 1416 | { |
| 1417 | u32 reg = 0; |
| 1418 | |
| 1419 | reg = DSI_R32(ctrl, 0x10c); |
| 1420 | |
| 1421 | if (idx & BIT(DSI_FIFO_OVERFLOW)) { |
| 1422 | if (en) |
| 1423 | reg |= (0xf << 16); |
| 1424 | else |
| 1425 | reg &= ~(0xf << 16); |
| 1426 | } |
| 1427 | |
| 1428 | if (idx & BIT(DSI_FIFO_UNDERFLOW)) { |
| 1429 | if (en) |
| 1430 | reg |= (0xf << 26); |
| 1431 | else |
| 1432 | reg &= ~(0xf << 26); |
| 1433 | } |
| 1434 | |
| 1435 | if (idx & BIT(DSI_LP_Rx_TIMEOUT)) { |
| 1436 | if (en) |
| 1437 | reg |= (0x7 << 23); |
| 1438 | else |
| 1439 | reg &= ~(0x7 << 23); |
| 1440 | } |
| 1441 | |
| 1442 | DSI_W32(ctrl, 0x10c, reg); |
| 1443 | wmb(); /* ensure error is masked */ |
| 1444 | } |
| 1445 | |
| 1446 | void dsi_ctrl_hw_cmn_error_intr_ctrl(struct dsi_ctrl_hw *ctrl, bool en) |
| 1447 | { |
| 1448 | u32 reg = 0; |
| 1449 | u32 dsi_total_mask = 0x2222AA02; |
| 1450 | |
| 1451 | reg = DSI_R32(ctrl, 0x110); |
| 1452 | reg &= dsi_total_mask; |
| 1453 | |
| 1454 | if (en) |
| 1455 | reg |= (BIT(24) | BIT(25)); |
| 1456 | else |
| 1457 | reg &= ~BIT(25); |
| 1458 | |
| 1459 | DSI_W32(ctrl, 0x110, reg); |
| 1460 | wmb(); /* ensure error is masked */ |
| 1461 | } |
| 1462 | |
| 1463 | u32 dsi_ctrl_hw_cmn_get_error_mask(struct dsi_ctrl_hw *ctrl) |
| 1464 | { |
| 1465 | u32 reg = 0; |
| 1466 | |
| 1467 | reg = DSI_R32(ctrl, 0x10c); |
| 1468 | |
| 1469 | return reg; |
| 1470 | } |
| 1471 | |
| 1472 | u32 dsi_ctrl_hw_cmn_get_hw_version(struct dsi_ctrl_hw *ctrl) |
| 1473 | { |
| 1474 | u32 reg = 0; |
| 1475 | |
| 1476 | reg = DSI_R32(ctrl, 0x0); |
| 1477 | |
| 1478 | return reg; |
| 1479 | } |