1379bc100SJani Nikula /* 2379bc100SJani Nikula * Copyright © 2018 Intel Corporation 3379bc100SJani Nikula * 4379bc100SJani Nikula * Permission is hereby granted, free of charge, to any person obtaining a 5379bc100SJani Nikula * copy of this software and associated documentation files (the "Software"), 6379bc100SJani Nikula * to deal in the Software without restriction, including without limitation 7379bc100SJani Nikula * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8379bc100SJani Nikula * and/or sell copies of the Software, and to permit persons to whom the 9379bc100SJani Nikula * Software is furnished to do so, subject to the following conditions: 10379bc100SJani Nikula * 11379bc100SJani Nikula * The above copyright notice and this permission notice (including the next 12379bc100SJani Nikula * paragraph) shall be included in all copies or substantial portions of the 13379bc100SJani Nikula * Software. 14379bc100SJani Nikula * 15379bc100SJani Nikula * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16379bc100SJani Nikula * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17379bc100SJani Nikula * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18379bc100SJani Nikula * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19379bc100SJani Nikula * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20379bc100SJani Nikula * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21379bc100SJani Nikula * DEALINGS IN THE SOFTWARE. 22379bc100SJani Nikula * 23379bc100SJani Nikula * Authors: 24379bc100SJani Nikula * Madhav Chauhan <madhav.chauhan@intel.com> 25379bc100SJani Nikula * Jani Nikula <jani.nikula@intel.com> 26379bc100SJani Nikula */ 27379bc100SJani Nikula 28379bc100SJani Nikula #include <drm/drm_atomic_helper.h> 29379bc100SJani Nikula #include <drm/drm_mipi_dsi.h> 30379bc100SJani Nikula 31379bc100SJani Nikula #include "intel_atomic.h" 32379bc100SJani Nikula #include "intel_combo_phy.h" 33379bc100SJani Nikula #include "intel_connector.h" 34379bc100SJani Nikula #include "intel_ddi.h" 35379bc100SJani Nikula #include "intel_dsi.h" 36379bc100SJani Nikula #include "intel_panel.h" 372b68392eSJani Nikula #include "intel_vdsc.h" 38379bc100SJani Nikula 3981b55ef1SJani Nikula static int header_credits_available(struct drm_i915_private *dev_priv, 40379bc100SJani Nikula enum transcoder dsi_trans) 41379bc100SJani Nikula { 421c63f6dfSJani Nikula return (intel_de_read(dev_priv, DSI_CMD_TXCTL(dsi_trans)) & FREE_HEADER_CREDIT_MASK) 43379bc100SJani Nikula >> FREE_HEADER_CREDIT_SHIFT; 44379bc100SJani Nikula } 45379bc100SJani Nikula 4681b55ef1SJani Nikula static int payload_credits_available(struct drm_i915_private *dev_priv, 47379bc100SJani Nikula enum transcoder dsi_trans) 48379bc100SJani Nikula { 491c63f6dfSJani Nikula return (intel_de_read(dev_priv, DSI_CMD_TXCTL(dsi_trans)) & FREE_PLOAD_CREDIT_MASK) 50379bc100SJani Nikula >> FREE_PLOAD_CREDIT_SHIFT; 51379bc100SJani Nikula } 52379bc100SJani Nikula 53379bc100SJani Nikula static void wait_for_header_credits(struct drm_i915_private *dev_priv, 54379bc100SJani Nikula enum transcoder dsi_trans) 55379bc100SJani Nikula { 56379bc100SJani Nikula if (wait_for_us(header_credits_available(dev_priv, dsi_trans) >= 57379bc100SJani Nikula MAX_HEADER_CREDIT, 100)) 58b5280cd0SWambui Karuga drm_err(&dev_priv->drm, "DSI header credits not released\n"); 59379bc100SJani Nikula } 60379bc100SJani Nikula 61379bc100SJani Nikula static void wait_for_payload_credits(struct drm_i915_private *dev_priv, 62379bc100SJani Nikula enum transcoder dsi_trans) 63379bc100SJani Nikula { 64379bc100SJani Nikula if (wait_for_us(payload_credits_available(dev_priv, dsi_trans) >= 65379bc100SJani Nikula MAX_PLOAD_CREDIT, 100)) 66b5280cd0SWambui Karuga drm_err(&dev_priv->drm, "DSI payload credits not released\n"); 67379bc100SJani Nikula } 68379bc100SJani Nikula 69379bc100SJani Nikula static enum transcoder dsi_port_to_transcoder(enum port port) 70379bc100SJani Nikula { 71379bc100SJani Nikula if (port == PORT_A) 72379bc100SJani Nikula return TRANSCODER_DSI_0; 73379bc100SJani Nikula else 74379bc100SJani Nikula return TRANSCODER_DSI_1; 75379bc100SJani Nikula } 76379bc100SJani Nikula 77379bc100SJani Nikula static void wait_for_cmds_dispatched_to_panel(struct intel_encoder *encoder) 78379bc100SJani Nikula { 79379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 80b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 81379bc100SJani Nikula struct mipi_dsi_device *dsi; 82379bc100SJani Nikula enum port port; 83379bc100SJani Nikula enum transcoder dsi_trans; 84379bc100SJani Nikula int ret; 85379bc100SJani Nikula 86379bc100SJani Nikula /* wait for header/payload credits to be released */ 87379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 88379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 89379bc100SJani Nikula wait_for_header_credits(dev_priv, dsi_trans); 90379bc100SJani Nikula wait_for_payload_credits(dev_priv, dsi_trans); 91379bc100SJani Nikula } 92379bc100SJani Nikula 93379bc100SJani Nikula /* send nop DCS command */ 94379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 95379bc100SJani Nikula dsi = intel_dsi->dsi_hosts[port]->device; 96379bc100SJani Nikula dsi->mode_flags |= MIPI_DSI_MODE_LPM; 97379bc100SJani Nikula dsi->channel = 0; 98379bc100SJani Nikula ret = mipi_dsi_dcs_nop(dsi); 99379bc100SJani Nikula if (ret < 0) 100b5280cd0SWambui Karuga drm_err(&dev_priv->drm, 101b5280cd0SWambui Karuga "error sending DCS NOP command\n"); 102379bc100SJani Nikula } 103379bc100SJani Nikula 104379bc100SJani Nikula /* wait for header credits to be released */ 105379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 106379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 107379bc100SJani Nikula wait_for_header_credits(dev_priv, dsi_trans); 108379bc100SJani Nikula } 109379bc100SJani Nikula 110379bc100SJani Nikula /* wait for LP TX in progress bit to be cleared */ 111379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 112379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 1131c63f6dfSJani Nikula if (wait_for_us(!(intel_de_read(dev_priv, DSI_LP_MSG(dsi_trans)) & 114379bc100SJani Nikula LPTX_IN_PROGRESS), 20)) 115b5280cd0SWambui Karuga drm_err(&dev_priv->drm, "LPTX bit not cleared\n"); 116379bc100SJani Nikula } 117379bc100SJani Nikula } 118379bc100SJani Nikula 119379bc100SJani Nikula static bool add_payld_to_queue(struct intel_dsi_host *host, const u8 *data, 120379bc100SJani Nikula u32 len) 121379bc100SJani Nikula { 122379bc100SJani Nikula struct intel_dsi *intel_dsi = host->intel_dsi; 123379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev); 124379bc100SJani Nikula enum transcoder dsi_trans = dsi_port_to_transcoder(host->port); 125379bc100SJani Nikula int free_credits; 126379bc100SJani Nikula int i, j; 127379bc100SJani Nikula 128379bc100SJani Nikula for (i = 0; i < len; i += 4) { 129379bc100SJani Nikula u32 tmp = 0; 130379bc100SJani Nikula 131379bc100SJani Nikula free_credits = payload_credits_available(dev_priv, dsi_trans); 132379bc100SJani Nikula if (free_credits < 1) { 133b5280cd0SWambui Karuga drm_err(&dev_priv->drm, 134b5280cd0SWambui Karuga "Payload credit not available\n"); 135379bc100SJani Nikula return false; 136379bc100SJani Nikula } 137379bc100SJani Nikula 138379bc100SJani Nikula for (j = 0; j < min_t(u32, len - i, 4); j++) 139379bc100SJani Nikula tmp |= *data++ << 8 * j; 140379bc100SJani Nikula 1411c63f6dfSJani Nikula intel_de_write(dev_priv, DSI_CMD_TXPYLD(dsi_trans), tmp); 142379bc100SJani Nikula } 143379bc100SJani Nikula 144379bc100SJani Nikula return true; 145379bc100SJani Nikula } 146379bc100SJani Nikula 147379bc100SJani Nikula static int dsi_send_pkt_hdr(struct intel_dsi_host *host, 148379bc100SJani Nikula struct mipi_dsi_packet pkt, bool enable_lpdt) 149379bc100SJani Nikula { 150379bc100SJani Nikula struct intel_dsi *intel_dsi = host->intel_dsi; 151379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev); 152379bc100SJani Nikula enum transcoder dsi_trans = dsi_port_to_transcoder(host->port); 153379bc100SJani Nikula u32 tmp; 154379bc100SJani Nikula int free_credits; 155379bc100SJani Nikula 156379bc100SJani Nikula /* check if header credit available */ 157379bc100SJani Nikula free_credits = header_credits_available(dev_priv, dsi_trans); 158379bc100SJani Nikula if (free_credits < 1) { 159b5280cd0SWambui Karuga drm_err(&dev_priv->drm, 160b5280cd0SWambui Karuga "send pkt header failed, not enough hdr credits\n"); 161379bc100SJani Nikula return -1; 162379bc100SJani Nikula } 163379bc100SJani Nikula 1641c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, DSI_CMD_TXHDR(dsi_trans)); 165379bc100SJani Nikula 166379bc100SJani Nikula if (pkt.payload) 167379bc100SJani Nikula tmp |= PAYLOAD_PRESENT; 168379bc100SJani Nikula else 169379bc100SJani Nikula tmp &= ~PAYLOAD_PRESENT; 170379bc100SJani Nikula 171379bc100SJani Nikula tmp &= ~VBLANK_FENCE; 172379bc100SJani Nikula 173379bc100SJani Nikula if (enable_lpdt) 174379bc100SJani Nikula tmp |= LP_DATA_TRANSFER; 175379bc100SJani Nikula 176379bc100SJani Nikula tmp &= ~(PARAM_WC_MASK | VC_MASK | DT_MASK); 177379bc100SJani Nikula tmp |= ((pkt.header[0] & VC_MASK) << VC_SHIFT); 178379bc100SJani Nikula tmp |= ((pkt.header[0] & DT_MASK) << DT_SHIFT); 179379bc100SJani Nikula tmp |= (pkt.header[1] << PARAM_WC_LOWER_SHIFT); 180379bc100SJani Nikula tmp |= (pkt.header[2] << PARAM_WC_UPPER_SHIFT); 1811c63f6dfSJani Nikula intel_de_write(dev_priv, DSI_CMD_TXHDR(dsi_trans), tmp); 182379bc100SJani Nikula 183379bc100SJani Nikula return 0; 184379bc100SJani Nikula } 185379bc100SJani Nikula 186379bc100SJani Nikula static int dsi_send_pkt_payld(struct intel_dsi_host *host, 187379bc100SJani Nikula struct mipi_dsi_packet pkt) 188379bc100SJani Nikula { 189dd10a80fSJani Nikula struct intel_dsi *intel_dsi = host->intel_dsi; 190dd10a80fSJani Nikula struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev); 191dd10a80fSJani Nikula 192379bc100SJani Nikula /* payload queue can accept *256 bytes*, check limit */ 193379bc100SJani Nikula if (pkt.payload_length > MAX_PLOAD_CREDIT * 4) { 194dd10a80fSJani Nikula drm_err(&i915->drm, "payload size exceeds max queue limit\n"); 195379bc100SJani Nikula return -1; 196379bc100SJani Nikula } 197379bc100SJani Nikula 198379bc100SJani Nikula /* load data into command payload queue */ 199379bc100SJani Nikula if (!add_payld_to_queue(host, pkt.payload, 200379bc100SJani Nikula pkt.payload_length)) { 201dd10a80fSJani Nikula drm_err(&i915->drm, "adding payload to queue failed\n"); 202379bc100SJani Nikula return -1; 203379bc100SJani Nikula } 204379bc100SJani Nikula 205379bc100SJani Nikula return 0; 206379bc100SJani Nikula } 207379bc100SJani Nikula 208379bc100SJani Nikula static void dsi_program_swing_and_deemphasis(struct intel_encoder *encoder) 209379bc100SJani Nikula { 210379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 211b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 212dc867bc7SMatt Roper enum phy phy; 213379bc100SJani Nikula u32 tmp; 214379bc100SJani Nikula int lane; 215379bc100SJani Nikula 216dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 217379bc100SJani Nikula /* 218379bc100SJani Nikula * Program voltage swing and pre-emphasis level values as per 219379bc100SJani Nikula * table in BSPEC under DDI buffer programing 220379bc100SJani Nikula */ 2211c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy)); 222379bc100SJani Nikula tmp &= ~(SCALING_MODE_SEL_MASK | RTERM_SELECT_MASK); 223379bc100SJani Nikula tmp |= SCALING_MODE_SEL(0x2); 224379bc100SJani Nikula tmp |= TAP2_DISABLE | TAP3_DISABLE; 225379bc100SJani Nikula tmp |= RTERM_SELECT(0x6); 2261c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), tmp); 227379bc100SJani Nikula 2281c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW5_AUX(phy)); 229379bc100SJani Nikula tmp &= ~(SCALING_MODE_SEL_MASK | RTERM_SELECT_MASK); 230379bc100SJani Nikula tmp |= SCALING_MODE_SEL(0x2); 231379bc100SJani Nikula tmp |= TAP2_DISABLE | TAP3_DISABLE; 232379bc100SJani Nikula tmp |= RTERM_SELECT(0x6); 2331c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW5_AUX(phy), tmp); 234379bc100SJani Nikula 2351c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW2_LN0(phy)); 236379bc100SJani Nikula tmp &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK | 237379bc100SJani Nikula RCOMP_SCALAR_MASK); 238379bc100SJani Nikula tmp |= SWING_SEL_UPPER(0x2); 239379bc100SJani Nikula tmp |= SWING_SEL_LOWER(0x2); 240379bc100SJani Nikula tmp |= RCOMP_SCALAR(0x98); 2411c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW2_GRP(phy), tmp); 242379bc100SJani Nikula 2431c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW2_AUX(phy)); 244379bc100SJani Nikula tmp &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK | 245379bc100SJani Nikula RCOMP_SCALAR_MASK); 246379bc100SJani Nikula tmp |= SWING_SEL_UPPER(0x2); 247379bc100SJani Nikula tmp |= SWING_SEL_LOWER(0x2); 248379bc100SJani Nikula tmp |= RCOMP_SCALAR(0x98); 2491c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW2_AUX(phy), tmp); 250379bc100SJani Nikula 2511c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW4_AUX(phy)); 252379bc100SJani Nikula tmp &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK | 253379bc100SJani Nikula CURSOR_COEFF_MASK); 254379bc100SJani Nikula tmp |= POST_CURSOR_1(0x0); 255379bc100SJani Nikula tmp |= POST_CURSOR_2(0x0); 256379bc100SJani Nikula tmp |= CURSOR_COEFF(0x3f); 2571c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW4_AUX(phy), tmp); 258379bc100SJani Nikula 259379bc100SJani Nikula for (lane = 0; lane <= 3; lane++) { 260379bc100SJani Nikula /* Bspec: must not use GRP register for write */ 2611c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, 2621c63f6dfSJani Nikula ICL_PORT_TX_DW4_LN(lane, phy)); 263379bc100SJani Nikula tmp &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK | 264379bc100SJani Nikula CURSOR_COEFF_MASK); 265379bc100SJani Nikula tmp |= POST_CURSOR_1(0x0); 266379bc100SJani Nikula tmp |= POST_CURSOR_2(0x0); 267379bc100SJani Nikula tmp |= CURSOR_COEFF(0x3f); 2681c63f6dfSJani Nikula intel_de_write(dev_priv, 2691c63f6dfSJani Nikula ICL_PORT_TX_DW4_LN(lane, phy), tmp); 270379bc100SJani Nikula } 271379bc100SJani Nikula } 272379bc100SJani Nikula } 273379bc100SJani Nikula 274379bc100SJani Nikula static void configure_dual_link_mode(struct intel_encoder *encoder, 275379bc100SJani Nikula const struct intel_crtc_state *pipe_config) 276379bc100SJani Nikula { 277379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 278b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 279379bc100SJani Nikula u32 dss_ctl1; 280379bc100SJani Nikula 2811c63f6dfSJani Nikula dss_ctl1 = intel_de_read(dev_priv, DSS_CTL1); 282379bc100SJani Nikula dss_ctl1 |= SPLITTER_ENABLE; 283379bc100SJani Nikula dss_ctl1 &= ~OVERLAP_PIXELS_MASK; 284379bc100SJani Nikula dss_ctl1 |= OVERLAP_PIXELS(intel_dsi->pixel_overlap); 285379bc100SJani Nikula 286379bc100SJani Nikula if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) { 287379bc100SJani Nikula const struct drm_display_mode *adjusted_mode = 2881326a92cSMaarten Lankhorst &pipe_config->hw.adjusted_mode; 289379bc100SJani Nikula u32 dss_ctl2; 290379bc100SJani Nikula u16 hactive = adjusted_mode->crtc_hdisplay; 291379bc100SJani Nikula u16 dl_buffer_depth; 292379bc100SJani Nikula 293379bc100SJani Nikula dss_ctl1 &= ~DUAL_LINK_MODE_INTERLEAVE; 294379bc100SJani Nikula dl_buffer_depth = hactive / 2 + intel_dsi->pixel_overlap; 295379bc100SJani Nikula 296379bc100SJani Nikula if (dl_buffer_depth > MAX_DL_BUFFER_TARGET_DEPTH) 297b5280cd0SWambui Karuga drm_err(&dev_priv->drm, 298b5280cd0SWambui Karuga "DL buffer depth exceed max value\n"); 299379bc100SJani Nikula 300379bc100SJani Nikula dss_ctl1 &= ~LEFT_DL_BUF_TARGET_DEPTH_MASK; 301379bc100SJani Nikula dss_ctl1 |= LEFT_DL_BUF_TARGET_DEPTH(dl_buffer_depth); 3021c63f6dfSJani Nikula dss_ctl2 = intel_de_read(dev_priv, DSS_CTL2); 303379bc100SJani Nikula dss_ctl2 &= ~RIGHT_DL_BUF_TARGET_DEPTH_MASK; 304379bc100SJani Nikula dss_ctl2 |= RIGHT_DL_BUF_TARGET_DEPTH(dl_buffer_depth); 3051c63f6dfSJani Nikula intel_de_write(dev_priv, DSS_CTL2, dss_ctl2); 306379bc100SJani Nikula } else { 307379bc100SJani Nikula /* Interleave */ 308379bc100SJani Nikula dss_ctl1 |= DUAL_LINK_MODE_INTERLEAVE; 309379bc100SJani Nikula } 310379bc100SJani Nikula 3111c63f6dfSJani Nikula intel_de_write(dev_priv, DSS_CTL1, dss_ctl1); 312379bc100SJani Nikula } 313379bc100SJani Nikula 31454ed6902SJani Nikula /* aka DSI 8X clock */ 31504865139SJani Nikula static int afe_clk(struct intel_encoder *encoder, 31604865139SJani Nikula const struct intel_crtc_state *crtc_state) 31754ed6902SJani Nikula { 318b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 31954ed6902SJani Nikula int bpp; 32054ed6902SJani Nikula 32104865139SJani Nikula if (crtc_state->dsc.compression_enable) 32204865139SJani Nikula bpp = crtc_state->dsc.compressed_bpp; 32304865139SJani Nikula else 32454ed6902SJani Nikula bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); 32554ed6902SJani Nikula 32654ed6902SJani Nikula return DIV_ROUND_CLOSEST(intel_dsi->pclk * bpp, intel_dsi->lane_count); 32754ed6902SJani Nikula } 32854ed6902SJani Nikula 32904865139SJani Nikula static void gen11_dsi_program_esc_clk_div(struct intel_encoder *encoder, 33004865139SJani Nikula const struct intel_crtc_state *crtc_state) 331379bc100SJani Nikula { 332379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 333b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 334379bc100SJani Nikula enum port port; 33554ed6902SJani Nikula int afe_clk_khz; 336379bc100SJani Nikula u32 esc_clk_div_m; 337379bc100SJani Nikula 33804865139SJani Nikula afe_clk_khz = afe_clk(encoder, crtc_state); 339379bc100SJani Nikula esc_clk_div_m = DIV_ROUND_UP(afe_clk_khz, DSI_MAX_ESC_CLK); 340379bc100SJani Nikula 341379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 3421c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_DSI_ESC_CLK_DIV(port), 343379bc100SJani Nikula esc_clk_div_m & ICL_ESC_CLK_DIV_MASK); 3441c63f6dfSJani Nikula intel_de_posting_read(dev_priv, ICL_DSI_ESC_CLK_DIV(port)); 345379bc100SJani Nikula } 346379bc100SJani Nikula 347379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 3481c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_DPHY_ESC_CLK_DIV(port), 349379bc100SJani Nikula esc_clk_div_m & ICL_ESC_CLK_DIV_MASK); 3501c63f6dfSJani Nikula intel_de_posting_read(dev_priv, ICL_DPHY_ESC_CLK_DIV(port)); 351379bc100SJani Nikula } 352379bc100SJani Nikula } 353379bc100SJani Nikula 354379bc100SJani Nikula static void get_dsi_io_power_domains(struct drm_i915_private *dev_priv, 355379bc100SJani Nikula struct intel_dsi *intel_dsi) 356379bc100SJani Nikula { 357379bc100SJani Nikula enum port port; 358379bc100SJani Nikula 359379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 3603dbe5e11SPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, intel_dsi->io_wakeref[port]); 361379bc100SJani Nikula intel_dsi->io_wakeref[port] = 362379bc100SJani Nikula intel_display_power_get(dev_priv, 363379bc100SJani Nikula port == PORT_A ? 364379bc100SJani Nikula POWER_DOMAIN_PORT_DDI_A_IO : 365379bc100SJani Nikula POWER_DOMAIN_PORT_DDI_B_IO); 366379bc100SJani Nikula } 367379bc100SJani Nikula } 368379bc100SJani Nikula 369379bc100SJani Nikula static void gen11_dsi_enable_io_power(struct intel_encoder *encoder) 370379bc100SJani Nikula { 371379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 372b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 373379bc100SJani Nikula enum port port; 374379bc100SJani Nikula u32 tmp; 375379bc100SJani Nikula 376379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 3771c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_DSI_IO_MODECTL(port)); 378379bc100SJani Nikula tmp |= COMBO_PHY_MODE_DSI; 3791c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_DSI_IO_MODECTL(port), tmp); 380379bc100SJani Nikula } 381379bc100SJani Nikula 382379bc100SJani Nikula get_dsi_io_power_domains(dev_priv, intel_dsi); 383379bc100SJani Nikula } 384379bc100SJani Nikula 385379bc100SJani Nikula static void gen11_dsi_power_up_lanes(struct intel_encoder *encoder) 386379bc100SJani Nikula { 387379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 388b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 389dc867bc7SMatt Roper enum phy phy; 390379bc100SJani Nikula 391dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) 392dc867bc7SMatt Roper intel_combo_phy_power_up_lanes(dev_priv, phy, true, 393379bc100SJani Nikula intel_dsi->lane_count, false); 394379bc100SJani Nikula } 395379bc100SJani Nikula 396379bc100SJani Nikula static void gen11_dsi_config_phy_lanes_sequence(struct intel_encoder *encoder) 397379bc100SJani Nikula { 398379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 399b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 400dc867bc7SMatt Roper enum phy phy; 401379bc100SJani Nikula u32 tmp; 402379bc100SJani Nikula int lane; 403379bc100SJani Nikula 404379bc100SJani Nikula /* Step 4b(i) set loadgen select for transmit and aux lanes */ 405dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 4061c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW4_AUX(phy)); 407379bc100SJani Nikula tmp &= ~LOADGEN_SELECT; 4081c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW4_AUX(phy), tmp); 409379bc100SJani Nikula for (lane = 0; lane <= 3; lane++) { 4101c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, 4111c63f6dfSJani Nikula ICL_PORT_TX_DW4_LN(lane, phy)); 412379bc100SJani Nikula tmp &= ~LOADGEN_SELECT; 413379bc100SJani Nikula if (lane != 2) 414379bc100SJani Nikula tmp |= LOADGEN_SELECT; 4151c63f6dfSJani Nikula intel_de_write(dev_priv, 4161c63f6dfSJani Nikula ICL_PORT_TX_DW4_LN(lane, phy), tmp); 417379bc100SJani Nikula } 418379bc100SJani Nikula } 419379bc100SJani Nikula 420379bc100SJani Nikula /* Step 4b(ii) set latency optimization for transmit and aux lanes */ 421dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 4221c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW2_AUX(phy)); 423379bc100SJani Nikula tmp &= ~FRC_LATENCY_OPTIM_MASK; 424379bc100SJani Nikula tmp |= FRC_LATENCY_OPTIM_VAL(0x5); 4251c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW2_AUX(phy), tmp); 4261c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW2_LN0(phy)); 427379bc100SJani Nikula tmp &= ~FRC_LATENCY_OPTIM_MASK; 428379bc100SJani Nikula tmp |= FRC_LATENCY_OPTIM_VAL(0x5); 4291c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW2_GRP(phy), tmp); 4306a7bafe8SVandita Kulkarni 431960e9836SVandita Kulkarni /* For EHL, TGL, set latency optimization for PCS_DW1 lanes */ 432960e9836SVandita Kulkarni if (IS_ELKHARTLAKE(dev_priv) || (INTEL_GEN(dev_priv) >= 12)) { 4331c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, 4341c63f6dfSJani Nikula ICL_PORT_PCS_DW1_AUX(phy)); 4356a7bafe8SVandita Kulkarni tmp &= ~LATENCY_OPTIM_MASK; 4366a7bafe8SVandita Kulkarni tmp |= LATENCY_OPTIM_VAL(0); 4371c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_PCS_DW1_AUX(phy), 4381c63f6dfSJani Nikula tmp); 4396a7bafe8SVandita Kulkarni 4401c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, 4411c63f6dfSJani Nikula ICL_PORT_PCS_DW1_LN0(phy)); 4426a7bafe8SVandita Kulkarni tmp &= ~LATENCY_OPTIM_MASK; 4436a7bafe8SVandita Kulkarni tmp |= LATENCY_OPTIM_VAL(0x1); 4441c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_PCS_DW1_GRP(phy), 4451c63f6dfSJani Nikula tmp); 4466a7bafe8SVandita Kulkarni } 447379bc100SJani Nikula } 448379bc100SJani Nikula 449379bc100SJani Nikula } 450379bc100SJani Nikula 451379bc100SJani Nikula static void gen11_dsi_voltage_swing_program_seq(struct intel_encoder *encoder) 452379bc100SJani Nikula { 453379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 454b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 455379bc100SJani Nikula u32 tmp; 456dc867bc7SMatt Roper enum phy phy; 457379bc100SJani Nikula 458379bc100SJani Nikula /* clear common keeper enable bit */ 459dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 4601c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_PORT_PCS_DW1_LN0(phy)); 461379bc100SJani Nikula tmp &= ~COMMON_KEEPER_EN; 4621c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_PCS_DW1_GRP(phy), tmp); 4631c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_PORT_PCS_DW1_AUX(phy)); 464379bc100SJani Nikula tmp &= ~COMMON_KEEPER_EN; 4651c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_PCS_DW1_AUX(phy), tmp); 466379bc100SJani Nikula } 467379bc100SJani Nikula 468379bc100SJani Nikula /* 469379bc100SJani Nikula * Set SUS Clock Config bitfield to 11b 470379bc100SJani Nikula * Note: loadgen select program is done 471379bc100SJani Nikula * as part of lane phy sequence configuration 472379bc100SJani Nikula */ 473dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 4741c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_PORT_CL_DW5(phy)); 475379bc100SJani Nikula tmp |= SUS_CLOCK_CONFIG; 4761c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_CL_DW5(phy), tmp); 477379bc100SJani Nikula } 478379bc100SJani Nikula 479379bc100SJani Nikula /* Clear training enable to change swing values */ 480dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 4811c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy)); 482379bc100SJani Nikula tmp &= ~TX_TRAINING_EN; 4831c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), tmp); 4841c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW5_AUX(phy)); 485379bc100SJani Nikula tmp &= ~TX_TRAINING_EN; 4861c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW5_AUX(phy), tmp); 487379bc100SJani Nikula } 488379bc100SJani Nikula 489379bc100SJani Nikula /* Program swing and de-emphasis */ 490379bc100SJani Nikula dsi_program_swing_and_deemphasis(encoder); 491379bc100SJani Nikula 492379bc100SJani Nikula /* Set training enable to trigger update */ 493dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 4941c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy)); 495379bc100SJani Nikula tmp |= TX_TRAINING_EN; 4961c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), tmp); 4971c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_PORT_TX_DW5_AUX(phy)); 498379bc100SJani Nikula tmp |= TX_TRAINING_EN; 4991c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW5_AUX(phy), tmp); 500379bc100SJani Nikula } 501379bc100SJani Nikula } 502379bc100SJani Nikula 503379bc100SJani Nikula static void gen11_dsi_enable_ddi_buffer(struct intel_encoder *encoder) 504379bc100SJani Nikula { 505379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 506b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 507379bc100SJani Nikula u32 tmp; 508379bc100SJani Nikula enum port port; 509379bc100SJani Nikula 510379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 5111c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, DDI_BUF_CTL(port)); 512379bc100SJani Nikula tmp |= DDI_BUF_CTL_ENABLE; 5131c63f6dfSJani Nikula intel_de_write(dev_priv, DDI_BUF_CTL(port), tmp); 514379bc100SJani Nikula 5151c63f6dfSJani Nikula if (wait_for_us(!(intel_de_read(dev_priv, DDI_BUF_CTL(port)) & 516379bc100SJani Nikula DDI_BUF_IS_IDLE), 517379bc100SJani Nikula 500)) 518b5280cd0SWambui Karuga drm_err(&dev_priv->drm, "DDI port:%c buffer idle\n", 519b5280cd0SWambui Karuga port_name(port)); 520379bc100SJani Nikula } 521379bc100SJani Nikula } 522379bc100SJani Nikula 52304865139SJani Nikula static void 52404865139SJani Nikula gen11_dsi_setup_dphy_timings(struct intel_encoder *encoder, 52504865139SJani Nikula const struct intel_crtc_state *crtc_state) 526379bc100SJani Nikula { 527379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 528b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 529379bc100SJani Nikula u32 tmp; 530379bc100SJani Nikula enum port port; 531dc867bc7SMatt Roper enum phy phy; 532379bc100SJani Nikula 533379bc100SJani Nikula /* Program T-INIT master registers */ 534379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 5351c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_DSI_T_INIT_MASTER(port)); 536379bc100SJani Nikula tmp &= ~MASTER_INIT_TIMER_MASK; 537379bc100SJani Nikula tmp |= intel_dsi->init_count; 5381c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_DSI_T_INIT_MASTER(port), tmp); 539379bc100SJani Nikula } 540379bc100SJani Nikula 541379bc100SJani Nikula /* Program DPHY clock lanes timings */ 542379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 5431c63f6dfSJani Nikula intel_de_write(dev_priv, DPHY_CLK_TIMING_PARAM(port), 5441c63f6dfSJani Nikula intel_dsi->dphy_reg); 545379bc100SJani Nikula 546379bc100SJani Nikula /* shadow register inside display core */ 5471c63f6dfSJani Nikula intel_de_write(dev_priv, DSI_CLK_TIMING_PARAM(port), 5481c63f6dfSJani Nikula intel_dsi->dphy_reg); 549379bc100SJani Nikula } 550379bc100SJani Nikula 551379bc100SJani Nikula /* Program DPHY data lanes timings */ 552379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 5531c63f6dfSJani Nikula intel_de_write(dev_priv, DPHY_DATA_TIMING_PARAM(port), 554379bc100SJani Nikula intel_dsi->dphy_data_lane_reg); 555379bc100SJani Nikula 556379bc100SJani Nikula /* shadow register inside display core */ 5571c63f6dfSJani Nikula intel_de_write(dev_priv, DSI_DATA_TIMING_PARAM(port), 558379bc100SJani Nikula intel_dsi->dphy_data_lane_reg); 559379bc100SJani Nikula } 560379bc100SJani Nikula 561379bc100SJani Nikula /* 562379bc100SJani Nikula * If DSI link operating at or below an 800 MHz, 563379bc100SJani Nikula * TA_SURE should be override and programmed to 564379bc100SJani Nikula * a value '0' inside TA_PARAM_REGISTERS otherwise 565379bc100SJani Nikula * leave all fields at HW default values. 566379bc100SJani Nikula */ 5677b864f95SVandita Kulkarni if (IS_GEN(dev_priv, 11)) { 56804865139SJani Nikula if (afe_clk(encoder, crtc_state) <= 800000) { 569379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 5701c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, 5711c63f6dfSJani Nikula DPHY_TA_TIMING_PARAM(port)); 572379bc100SJani Nikula tmp &= ~TA_SURE_MASK; 573379bc100SJani Nikula tmp |= TA_SURE_OVERRIDE | TA_SURE(0); 5741c63f6dfSJani Nikula intel_de_write(dev_priv, 5751c63f6dfSJani Nikula DPHY_TA_TIMING_PARAM(port), 5761c63f6dfSJani Nikula tmp); 577379bc100SJani Nikula 578379bc100SJani Nikula /* shadow register inside display core */ 5791c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, 5801c63f6dfSJani Nikula DSI_TA_TIMING_PARAM(port)); 581379bc100SJani Nikula tmp &= ~TA_SURE_MASK; 582379bc100SJani Nikula tmp |= TA_SURE_OVERRIDE | TA_SURE(0); 5831c63f6dfSJani Nikula intel_de_write(dev_priv, 5841c63f6dfSJani Nikula DSI_TA_TIMING_PARAM(port), tmp); 585379bc100SJani Nikula } 586379bc100SJani Nikula } 5877b864f95SVandita Kulkarni } 588683d672cSJosé Roberto de Souza 589683d672cSJosé Roberto de Souza if (IS_ELKHARTLAKE(dev_priv)) { 590dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 5911c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_DPHY_CHKN(phy)); 592683d672cSJosé Roberto de Souza tmp |= ICL_DPHY_CHKN_AFE_OVER_PPI_STRAP; 5931c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_DPHY_CHKN(phy), tmp); 594683d672cSJosé Roberto de Souza } 595683d672cSJosé Roberto de Souza } 596379bc100SJani Nikula } 597379bc100SJani Nikula 598379bc100SJani Nikula static void gen11_dsi_gate_clocks(struct intel_encoder *encoder) 599379bc100SJani Nikula { 600379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 601b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 602379bc100SJani Nikula u32 tmp; 603befa372bSMatt Roper enum phy phy; 604379bc100SJani Nikula 605353ad959SImre Deak mutex_lock(&dev_priv->dpll.lock); 6061c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0); 607dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) 608befa372bSMatt Roper tmp |= ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy); 609379bc100SJani Nikula 6101c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, tmp); 611353ad959SImre Deak mutex_unlock(&dev_priv->dpll.lock); 612379bc100SJani Nikula } 613379bc100SJani Nikula 614379bc100SJani Nikula static void gen11_dsi_ungate_clocks(struct intel_encoder *encoder) 615379bc100SJani Nikula { 616379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 617b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 618379bc100SJani Nikula u32 tmp; 619befa372bSMatt Roper enum phy phy; 620379bc100SJani Nikula 621353ad959SImre Deak mutex_lock(&dev_priv->dpll.lock); 6221c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0); 623dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) 624befa372bSMatt Roper tmp &= ~ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy); 625379bc100SJani Nikula 6261c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, tmp); 627353ad959SImre Deak mutex_unlock(&dev_priv->dpll.lock); 628379bc100SJani Nikula } 629379bc100SJani Nikula 630379bc100SJani Nikula static void gen11_dsi_map_pll(struct intel_encoder *encoder, 631379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 632379bc100SJani Nikula { 633379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 634b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 635379bc100SJani Nikula struct intel_shared_dpll *pll = crtc_state->shared_dpll; 636befa372bSMatt Roper enum phy phy; 637379bc100SJani Nikula u32 val; 638379bc100SJani Nikula 639353ad959SImre Deak mutex_lock(&dev_priv->dpll.lock); 640379bc100SJani Nikula 6411c63f6dfSJani Nikula val = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0); 642dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 643befa372bSMatt Roper val &= ~ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy); 644befa372bSMatt Roper val |= ICL_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy); 645379bc100SJani Nikula } 6461c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val); 647379bc100SJani Nikula 648dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 649991d9557SVandita Kulkarni if (INTEL_GEN(dev_priv) >= 12) 650991d9557SVandita Kulkarni val |= ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy); 651991d9557SVandita Kulkarni else 652befa372bSMatt Roper val &= ~ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy); 653379bc100SJani Nikula } 6541c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val); 655379bc100SJani Nikula 6561c63f6dfSJani Nikula intel_de_posting_read(dev_priv, ICL_DPCLKA_CFGCR0); 657379bc100SJani Nikula 658353ad959SImre Deak mutex_unlock(&dev_priv->dpll.lock); 659379bc100SJani Nikula } 660379bc100SJani Nikula 661379bc100SJani Nikula static void 662379bc100SJani Nikula gen11_dsi_configure_transcoder(struct intel_encoder *encoder, 663379bc100SJani Nikula const struct intel_crtc_state *pipe_config) 664379bc100SJani Nikula { 665379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 666b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 6672225f3c6SMaarten Lankhorst struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc); 668379bc100SJani Nikula enum pipe pipe = intel_crtc->pipe; 669379bc100SJani Nikula u32 tmp; 670379bc100SJani Nikula enum port port; 671379bc100SJani Nikula enum transcoder dsi_trans; 672379bc100SJani Nikula 673379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 674379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 6751c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, DSI_TRANS_FUNC_CONF(dsi_trans)); 676379bc100SJani Nikula 677379bc100SJani Nikula if (intel_dsi->eotp_pkt) 678379bc100SJani Nikula tmp &= ~EOTP_DISABLED; 679379bc100SJani Nikula else 680379bc100SJani Nikula tmp |= EOTP_DISABLED; 681379bc100SJani Nikula 682379bc100SJani Nikula /* enable link calibration if freq > 1.5Gbps */ 68304865139SJani Nikula if (afe_clk(encoder, pipe_config) >= 1500 * 1000) { 684379bc100SJani Nikula tmp &= ~LINK_CALIBRATION_MASK; 685379bc100SJani Nikula tmp |= CALIBRATION_ENABLED_INITIAL_ONLY; 686379bc100SJani Nikula } 687379bc100SJani Nikula 688379bc100SJani Nikula /* configure continuous clock */ 689379bc100SJani Nikula tmp &= ~CONTINUOUS_CLK_MASK; 690379bc100SJani Nikula if (intel_dsi->clock_stop) 691379bc100SJani Nikula tmp |= CLK_ENTER_LP_AFTER_DATA; 692379bc100SJani Nikula else 693379bc100SJani Nikula tmp |= CLK_HS_CONTINUOUS; 694379bc100SJani Nikula 695379bc100SJani Nikula /* configure buffer threshold limit to minimum */ 696379bc100SJani Nikula tmp &= ~PIX_BUF_THRESHOLD_MASK; 697379bc100SJani Nikula tmp |= PIX_BUF_THRESHOLD_1_4; 698379bc100SJani Nikula 699379bc100SJani Nikula /* set virtual channel to '0' */ 700379bc100SJani Nikula tmp &= ~PIX_VIRT_CHAN_MASK; 701379bc100SJani Nikula tmp |= PIX_VIRT_CHAN(0); 702379bc100SJani Nikula 703379bc100SJani Nikula /* program BGR transmission */ 704379bc100SJani Nikula if (intel_dsi->bgr_enabled) 705379bc100SJani Nikula tmp |= BGR_TRANSMISSION; 706379bc100SJani Nikula 707379bc100SJani Nikula /* select pixel format */ 708379bc100SJani Nikula tmp &= ~PIX_FMT_MASK; 70938b89881SJani Nikula if (pipe_config->dsc.compression_enable) { 71038b89881SJani Nikula tmp |= PIX_FMT_COMPRESSED; 71138b89881SJani Nikula } else { 712379bc100SJani Nikula switch (intel_dsi->pixel_format) { 713379bc100SJani Nikula default: 714379bc100SJani Nikula MISSING_CASE(intel_dsi->pixel_format); 715379bc100SJani Nikula /* fallthrough */ 716379bc100SJani Nikula case MIPI_DSI_FMT_RGB565: 717379bc100SJani Nikula tmp |= PIX_FMT_RGB565; 718379bc100SJani Nikula break; 719379bc100SJani Nikula case MIPI_DSI_FMT_RGB666_PACKED: 720379bc100SJani Nikula tmp |= PIX_FMT_RGB666_PACKED; 721379bc100SJani Nikula break; 722379bc100SJani Nikula case MIPI_DSI_FMT_RGB666: 723379bc100SJani Nikula tmp |= PIX_FMT_RGB666_LOOSE; 724379bc100SJani Nikula break; 725379bc100SJani Nikula case MIPI_DSI_FMT_RGB888: 726379bc100SJani Nikula tmp |= PIX_FMT_RGB888; 727379bc100SJani Nikula break; 728379bc100SJani Nikula } 72938b89881SJani Nikula } 730379bc100SJani Nikula 73132d38e6cSVandita Kulkarni if (INTEL_GEN(dev_priv) >= 12) { 73232d38e6cSVandita Kulkarni if (is_vid_mode(intel_dsi)) 73332d38e6cSVandita Kulkarni tmp |= BLANKING_PACKET_ENABLE; 73432d38e6cSVandita Kulkarni } 73532d38e6cSVandita Kulkarni 736379bc100SJani Nikula /* program DSI operation mode */ 737379bc100SJani Nikula if (is_vid_mode(intel_dsi)) { 738379bc100SJani Nikula tmp &= ~OP_MODE_MASK; 739379bc100SJani Nikula switch (intel_dsi->video_mode_format) { 740379bc100SJani Nikula default: 741379bc100SJani Nikula MISSING_CASE(intel_dsi->video_mode_format); 742379bc100SJani Nikula /* fallthrough */ 743379bc100SJani Nikula case VIDEO_MODE_NON_BURST_WITH_SYNC_EVENTS: 744379bc100SJani Nikula tmp |= VIDEO_MODE_SYNC_EVENT; 745379bc100SJani Nikula break; 746379bc100SJani Nikula case VIDEO_MODE_NON_BURST_WITH_SYNC_PULSE: 747379bc100SJani Nikula tmp |= VIDEO_MODE_SYNC_PULSE; 748379bc100SJani Nikula break; 749379bc100SJani Nikula } 750b4b95b05SVandita Kulkarni } else { 751b4b95b05SVandita Kulkarni /* 752b4b95b05SVandita Kulkarni * FIXME: Retrieve this info from VBT. 753b4b95b05SVandita Kulkarni * As per the spec when dsi transcoder is operating 754b4b95b05SVandita Kulkarni * in TE GATE mode, TE comes from GPIO 755b4b95b05SVandita Kulkarni * which is UTIL PIN for DSI 0. 756b4b95b05SVandita Kulkarni * Also this GPIO would not be used for other 757b4b95b05SVandita Kulkarni * purposes is an assumption. 758b4b95b05SVandita Kulkarni */ 759b4b95b05SVandita Kulkarni tmp &= ~OP_MODE_MASK; 760b4b95b05SVandita Kulkarni tmp |= CMD_MODE_TE_GATE; 761b4b95b05SVandita Kulkarni tmp |= TE_SOURCE_GPIO; 762379bc100SJani Nikula } 763379bc100SJani Nikula 7641c63f6dfSJani Nikula intel_de_write(dev_priv, DSI_TRANS_FUNC_CONF(dsi_trans), tmp); 765379bc100SJani Nikula } 766379bc100SJani Nikula 767379bc100SJani Nikula /* enable port sync mode if dual link */ 768379bc100SJani Nikula if (intel_dsi->dual_link) { 769379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 770379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 7711c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, 7721c63f6dfSJani Nikula TRANS_DDI_FUNC_CTL2(dsi_trans)); 773379bc100SJani Nikula tmp |= PORT_SYNC_MODE_ENABLE; 7741c63f6dfSJani Nikula intel_de_write(dev_priv, 7751c63f6dfSJani Nikula TRANS_DDI_FUNC_CTL2(dsi_trans), tmp); 776379bc100SJani Nikula } 777379bc100SJani Nikula 778379bc100SJani Nikula /* configure stream splitting */ 779379bc100SJani Nikula configure_dual_link_mode(encoder, pipe_config); 780379bc100SJani Nikula } 781379bc100SJani Nikula 782379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 783379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 784379bc100SJani Nikula 785379bc100SJani Nikula /* select data lane width */ 7861c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(dsi_trans)); 787379bc100SJani Nikula tmp &= ~DDI_PORT_WIDTH_MASK; 788379bc100SJani Nikula tmp |= DDI_PORT_WIDTH(intel_dsi->lane_count); 789379bc100SJani Nikula 790379bc100SJani Nikula /* select input pipe */ 791379bc100SJani Nikula tmp &= ~TRANS_DDI_EDP_INPUT_MASK; 792379bc100SJani Nikula switch (pipe) { 793379bc100SJani Nikula default: 794379bc100SJani Nikula MISSING_CASE(pipe); 795379bc100SJani Nikula /* fallthrough */ 796379bc100SJani Nikula case PIPE_A: 797379bc100SJani Nikula tmp |= TRANS_DDI_EDP_INPUT_A_ON; 798379bc100SJani Nikula break; 799379bc100SJani Nikula case PIPE_B: 800379bc100SJani Nikula tmp |= TRANS_DDI_EDP_INPUT_B_ONOFF; 801379bc100SJani Nikula break; 802379bc100SJani Nikula case PIPE_C: 803379bc100SJani Nikula tmp |= TRANS_DDI_EDP_INPUT_C_ONOFF; 804379bc100SJani Nikula break; 8054d89adc7SJosé Roberto de Souza case PIPE_D: 8064d89adc7SJosé Roberto de Souza tmp |= TRANS_DDI_EDP_INPUT_D_ONOFF; 8074d89adc7SJosé Roberto de Souza break; 808379bc100SJani Nikula } 809379bc100SJani Nikula 810379bc100SJani Nikula /* enable DDI buffer */ 811379bc100SJani Nikula tmp |= TRANS_DDI_FUNC_ENABLE; 8121c63f6dfSJani Nikula intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(dsi_trans), tmp); 813379bc100SJani Nikula } 814379bc100SJani Nikula 815379bc100SJani Nikula /* wait for link ready */ 816379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 817379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 8181c63f6dfSJani Nikula if (wait_for_us((intel_de_read(dev_priv, DSI_TRANS_FUNC_CONF(dsi_trans)) & 819379bc100SJani Nikula LINK_READY), 2500)) 820b5280cd0SWambui Karuga drm_err(&dev_priv->drm, "DSI link not ready\n"); 821379bc100SJani Nikula } 822379bc100SJani Nikula } 823379bc100SJani Nikula 824379bc100SJani Nikula static void 825379bc100SJani Nikula gen11_dsi_set_transcoder_timings(struct intel_encoder *encoder, 82653693f02SJani Nikula const struct intel_crtc_state *crtc_state) 827379bc100SJani Nikula { 828379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 829b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 830379bc100SJani Nikula const struct drm_display_mode *adjusted_mode = 83153693f02SJani Nikula &crtc_state->hw.adjusted_mode; 832379bc100SJani Nikula enum port port; 833379bc100SJani Nikula enum transcoder dsi_trans; 834379bc100SJani Nikula /* horizontal timings */ 835379bc100SJani Nikula u16 htotal, hactive, hsync_start, hsync_end, hsync_size; 8360cc35a9cSYueHaibing u16 hback_porch; 837379bc100SJani Nikula /* vertical timings */ 838379bc100SJani Nikula u16 vtotal, vactive, vsync_start, vsync_end, vsync_shift; 83953693f02SJani Nikula int mul = 1, div = 1; 84053693f02SJani Nikula 84153693f02SJani Nikula /* 84253693f02SJani Nikula * Adjust horizontal timings (htotal, hsync_start, hsync_end) to account 84353693f02SJani Nikula * for slower link speed if DSC is enabled. 84453693f02SJani Nikula * 84553693f02SJani Nikula * The compression frequency ratio is the ratio between compressed and 84653693f02SJani Nikula * non-compressed link speeds, and simplifies down to the ratio between 84753693f02SJani Nikula * compressed and non-compressed bpp. 84853693f02SJani Nikula */ 84953693f02SJani Nikula if (crtc_state->dsc.compression_enable) { 85053693f02SJani Nikula mul = crtc_state->dsc.compressed_bpp; 85153693f02SJani Nikula div = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); 85253693f02SJani Nikula } 853379bc100SJani Nikula 854379bc100SJani Nikula hactive = adjusted_mode->crtc_hdisplay; 855b9277832SVandita Kulkarni 856b9277832SVandita Kulkarni if (is_vid_mode(intel_dsi)) 85753693f02SJani Nikula htotal = DIV_ROUND_UP(adjusted_mode->crtc_htotal * mul, div); 858b9277832SVandita Kulkarni else 859b9277832SVandita Kulkarni htotal = DIV_ROUND_UP((hactive + 160) * mul, div); 860b9277832SVandita Kulkarni 86153693f02SJani Nikula hsync_start = DIV_ROUND_UP(adjusted_mode->crtc_hsync_start * mul, div); 86253693f02SJani Nikula hsync_end = DIV_ROUND_UP(adjusted_mode->crtc_hsync_end * mul, div); 863379bc100SJani Nikula hsync_size = hsync_end - hsync_start; 864379bc100SJani Nikula hback_porch = (adjusted_mode->crtc_htotal - 865379bc100SJani Nikula adjusted_mode->crtc_hsync_end); 866379bc100SJani Nikula vactive = adjusted_mode->crtc_vdisplay; 867b9277832SVandita Kulkarni 868b9277832SVandita Kulkarni if (is_vid_mode(intel_dsi)) { 869379bc100SJani Nikula vtotal = adjusted_mode->crtc_vtotal; 870b9277832SVandita Kulkarni } else { 871b9277832SVandita Kulkarni int bpp, line_time_us, byte_clk_period_ns; 872b9277832SVandita Kulkarni 873b9277832SVandita Kulkarni if (crtc_state->dsc.compression_enable) 874b9277832SVandita Kulkarni bpp = crtc_state->dsc.compressed_bpp; 875b9277832SVandita Kulkarni else 876b9277832SVandita Kulkarni bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); 877b9277832SVandita Kulkarni 878b9277832SVandita Kulkarni byte_clk_period_ns = 1000000 / afe_clk(encoder, crtc_state); 879b9277832SVandita Kulkarni line_time_us = (htotal * (bpp / 8) * byte_clk_period_ns) / (1000 * intel_dsi->lane_count); 880b9277832SVandita Kulkarni vtotal = vactive + DIV_ROUND_UP(400, line_time_us); 881b9277832SVandita Kulkarni } 882379bc100SJani Nikula vsync_start = adjusted_mode->crtc_vsync_start; 883379bc100SJani Nikula vsync_end = adjusted_mode->crtc_vsync_end; 884379bc100SJani Nikula vsync_shift = hsync_start - htotal / 2; 885379bc100SJani Nikula 886379bc100SJani Nikula if (intel_dsi->dual_link) { 887379bc100SJani Nikula hactive /= 2; 888379bc100SJani Nikula if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) 889379bc100SJani Nikula hactive += intel_dsi->pixel_overlap; 890379bc100SJani Nikula htotal /= 2; 891379bc100SJani Nikula } 892379bc100SJani Nikula 893379bc100SJani Nikula /* minimum hactive as per bspec: 256 pixels */ 894379bc100SJani Nikula if (adjusted_mode->crtc_hdisplay < 256) 895b5280cd0SWambui Karuga drm_err(&dev_priv->drm, "hactive is less then 256 pixels\n"); 896379bc100SJani Nikula 897379bc100SJani Nikula /* if RGB666 format, then hactive must be multiple of 4 pixels */ 898379bc100SJani Nikula if (intel_dsi->pixel_format == MIPI_DSI_FMT_RGB666 && hactive % 4 != 0) 899b5280cd0SWambui Karuga drm_err(&dev_priv->drm, 900b5280cd0SWambui Karuga "hactive pixels are not multiple of 4\n"); 901379bc100SJani Nikula 902379bc100SJani Nikula /* program TRANS_HTOTAL register */ 903379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 904379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 9051c63f6dfSJani Nikula intel_de_write(dev_priv, HTOTAL(dsi_trans), 906379bc100SJani Nikula (hactive - 1) | ((htotal - 1) << 16)); 907379bc100SJani Nikula } 908379bc100SJani Nikula 909379bc100SJani Nikula /* TRANS_HSYNC register to be programmed only for video mode */ 910b9277832SVandita Kulkarni if (is_vid_mode(intel_dsi)) { 911379bc100SJani Nikula if (intel_dsi->video_mode_format == 912379bc100SJani Nikula VIDEO_MODE_NON_BURST_WITH_SYNC_PULSE) { 913379bc100SJani Nikula /* BSPEC: hsync size should be atleast 16 pixels */ 914379bc100SJani Nikula if (hsync_size < 16) 915b5280cd0SWambui Karuga drm_err(&dev_priv->drm, 916b5280cd0SWambui Karuga "hsync size < 16 pixels\n"); 917379bc100SJani Nikula } 918379bc100SJani Nikula 919379bc100SJani Nikula if (hback_porch < 16) 920b5280cd0SWambui Karuga drm_err(&dev_priv->drm, "hback porch < 16 pixels\n"); 921379bc100SJani Nikula 922379bc100SJani Nikula if (intel_dsi->dual_link) { 923379bc100SJani Nikula hsync_start /= 2; 924379bc100SJani Nikula hsync_end /= 2; 925379bc100SJani Nikula } 926379bc100SJani Nikula 927379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 928379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 9291c63f6dfSJani Nikula intel_de_write(dev_priv, HSYNC(dsi_trans), 930379bc100SJani Nikula (hsync_start - 1) | ((hsync_end - 1) << 16)); 931379bc100SJani Nikula } 932379bc100SJani Nikula } 933379bc100SJani Nikula 934379bc100SJani Nikula /* program TRANS_VTOTAL register */ 935379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 936379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 937379bc100SJani Nikula /* 938379bc100SJani Nikula * FIXME: Programing this by assuming progressive mode, since 939379bc100SJani Nikula * non-interlaced info from VBT is not saved inside 940379bc100SJani Nikula * struct drm_display_mode. 941379bc100SJani Nikula * For interlace mode: program required pixel minus 2 942379bc100SJani Nikula */ 9431c63f6dfSJani Nikula intel_de_write(dev_priv, VTOTAL(dsi_trans), 944379bc100SJani Nikula (vactive - 1) | ((vtotal - 1) << 16)); 945379bc100SJani Nikula } 946379bc100SJani Nikula 947379bc100SJani Nikula if (vsync_end < vsync_start || vsync_end > vtotal) 948b5280cd0SWambui Karuga drm_err(&dev_priv->drm, "Invalid vsync_end value\n"); 949379bc100SJani Nikula 950379bc100SJani Nikula if (vsync_start < vactive) 951b5280cd0SWambui Karuga drm_err(&dev_priv->drm, "vsync_start less than vactive\n"); 952379bc100SJani Nikula 953b9277832SVandita Kulkarni /* program TRANS_VSYNC register for video mode only */ 954b9277832SVandita Kulkarni if (is_vid_mode(intel_dsi)) { 955379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 956379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 9571c63f6dfSJani Nikula intel_de_write(dev_priv, VSYNC(dsi_trans), 958379bc100SJani Nikula (vsync_start - 1) | ((vsync_end - 1) << 16)); 959379bc100SJani Nikula } 960b9277832SVandita Kulkarni } 961379bc100SJani Nikula 962379bc100SJani Nikula /* 963b9277832SVandita Kulkarni * FIXME: It has to be programmed only for video modes and interlaced 964379bc100SJani Nikula * modes. Put the check condition here once interlaced 965379bc100SJani Nikula * info available as described above. 966379bc100SJani Nikula * program TRANS_VSYNCSHIFT register 967379bc100SJani Nikula */ 968b9277832SVandita Kulkarni if (is_vid_mode(intel_dsi)) { 969379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 970379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 971b9277832SVandita Kulkarni intel_de_write(dev_priv, VSYNCSHIFT(dsi_trans), 972b9277832SVandita Kulkarni vsync_shift); 973b9277832SVandita Kulkarni } 974379bc100SJani Nikula } 9753522a33aSVandita Kulkarni 9763522a33aSVandita Kulkarni /* program TRANS_VBLANK register, should be same as vtotal programmed */ 9773522a33aSVandita Kulkarni if (INTEL_GEN(dev_priv) >= 12) { 9783522a33aSVandita Kulkarni for_each_dsi_port(port, intel_dsi->ports) { 9793522a33aSVandita Kulkarni dsi_trans = dsi_port_to_transcoder(port); 9801c63f6dfSJani Nikula intel_de_write(dev_priv, VBLANK(dsi_trans), 9813522a33aSVandita Kulkarni (vactive - 1) | ((vtotal - 1) << 16)); 9823522a33aSVandita Kulkarni } 9833522a33aSVandita Kulkarni } 984379bc100SJani Nikula } 985379bc100SJani Nikula 986379bc100SJani Nikula static void gen11_dsi_enable_transcoder(struct intel_encoder *encoder) 987379bc100SJani Nikula { 988379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 989b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 990379bc100SJani Nikula enum port port; 991379bc100SJani Nikula enum transcoder dsi_trans; 992379bc100SJani Nikula u32 tmp; 993379bc100SJani Nikula 994379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 995379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 9961c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, PIPECONF(dsi_trans)); 997379bc100SJani Nikula tmp |= PIPECONF_ENABLE; 9981c63f6dfSJani Nikula intel_de_write(dev_priv, PIPECONF(dsi_trans), tmp); 999379bc100SJani Nikula 1000379bc100SJani Nikula /* wait for transcoder to be enabled */ 10014cb3b44dSDaniele Ceraolo Spurio if (intel_de_wait_for_set(dev_priv, PIPECONF(dsi_trans), 1002379bc100SJani Nikula I965_PIPECONF_ACTIVE, 10)) 1003b5280cd0SWambui Karuga drm_err(&dev_priv->drm, 1004b5280cd0SWambui Karuga "DSI transcoder not enabled\n"); 1005379bc100SJani Nikula } 1006379bc100SJani Nikula } 1007379bc100SJani Nikula 100804865139SJani Nikula static void gen11_dsi_setup_timeouts(struct intel_encoder *encoder, 100904865139SJani Nikula const struct intel_crtc_state *crtc_state) 1010379bc100SJani Nikula { 1011379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1012b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1013379bc100SJani Nikula enum port port; 1014379bc100SJani Nikula enum transcoder dsi_trans; 1015379bc100SJani Nikula u32 tmp, hs_tx_timeout, lp_rx_timeout, ta_timeout, divisor, mul; 1016379bc100SJani Nikula 1017379bc100SJani Nikula /* 1018379bc100SJani Nikula * escape clock count calculation: 1019379bc100SJani Nikula * BYTE_CLK_COUNT = TIME_NS/(8 * UI) 1020379bc100SJani Nikula * UI (nsec) = (10^6)/Bitrate 1021379bc100SJani Nikula * TIME_NS = (BYTE_CLK_COUNT * 8 * 10^6)/ Bitrate 1022379bc100SJani Nikula * ESCAPE_CLK_COUNT = TIME_NS/ESC_CLK_NS 1023379bc100SJani Nikula */ 102404865139SJani Nikula divisor = intel_dsi_tlpx_ns(intel_dsi) * afe_clk(encoder, crtc_state) * 1000; 1025379bc100SJani Nikula mul = 8 * 1000000; 1026379bc100SJani Nikula hs_tx_timeout = DIV_ROUND_UP(intel_dsi->hs_tx_timeout * mul, 1027379bc100SJani Nikula divisor); 1028379bc100SJani Nikula lp_rx_timeout = DIV_ROUND_UP(intel_dsi->lp_rx_timeout * mul, divisor); 1029379bc100SJani Nikula ta_timeout = DIV_ROUND_UP(intel_dsi->turn_arnd_val * mul, divisor); 1030379bc100SJani Nikula 1031379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1032379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 1033379bc100SJani Nikula 1034379bc100SJani Nikula /* program hst_tx_timeout */ 10351c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, DSI_HSTX_TO(dsi_trans)); 1036379bc100SJani Nikula tmp &= ~HSTX_TIMEOUT_VALUE_MASK; 1037379bc100SJani Nikula tmp |= HSTX_TIMEOUT_VALUE(hs_tx_timeout); 10381c63f6dfSJani Nikula intel_de_write(dev_priv, DSI_HSTX_TO(dsi_trans), tmp); 1039379bc100SJani Nikula 1040379bc100SJani Nikula /* FIXME: DSI_CALIB_TO */ 1041379bc100SJani Nikula 1042379bc100SJani Nikula /* program lp_rx_host timeout */ 10431c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, DSI_LPRX_HOST_TO(dsi_trans)); 1044379bc100SJani Nikula tmp &= ~LPRX_TIMEOUT_VALUE_MASK; 1045379bc100SJani Nikula tmp |= LPRX_TIMEOUT_VALUE(lp_rx_timeout); 10461c63f6dfSJani Nikula intel_de_write(dev_priv, DSI_LPRX_HOST_TO(dsi_trans), tmp); 1047379bc100SJani Nikula 1048379bc100SJani Nikula /* FIXME: DSI_PWAIT_TO */ 1049379bc100SJani Nikula 1050379bc100SJani Nikula /* program turn around timeout */ 10511c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, DSI_TA_TO(dsi_trans)); 1052379bc100SJani Nikula tmp &= ~TA_TIMEOUT_VALUE_MASK; 1053379bc100SJani Nikula tmp |= TA_TIMEOUT_VALUE(ta_timeout); 10541c63f6dfSJani Nikula intel_de_write(dev_priv, DSI_TA_TO(dsi_trans), tmp); 1055379bc100SJani Nikula } 1056379bc100SJani Nikula } 1057379bc100SJani Nikula 1058b4b95b05SVandita Kulkarni static void gen11_dsi_config_util_pin(struct intel_encoder *encoder, 1059b4b95b05SVandita Kulkarni bool enable) 1060b4b95b05SVandita Kulkarni { 1061b4b95b05SVandita Kulkarni struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1062b4b95b05SVandita Kulkarni struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1063b4b95b05SVandita Kulkarni u32 tmp; 1064b4b95b05SVandita Kulkarni 1065b4b95b05SVandita Kulkarni /* 1066b4b95b05SVandita Kulkarni * used as TE i/p for DSI0, 1067b4b95b05SVandita Kulkarni * for dual link/DSI1 TE is from slave DSI1 1068b4b95b05SVandita Kulkarni * through GPIO. 1069b4b95b05SVandita Kulkarni */ 1070b4b95b05SVandita Kulkarni if (is_vid_mode(intel_dsi) || (intel_dsi->ports & BIT(PORT_B))) 1071b4b95b05SVandita Kulkarni return; 1072b4b95b05SVandita Kulkarni 1073b4b95b05SVandita Kulkarni tmp = intel_de_read(dev_priv, UTIL_PIN_CTL); 1074b4b95b05SVandita Kulkarni 1075b4b95b05SVandita Kulkarni if (enable) { 1076b4b95b05SVandita Kulkarni tmp |= UTIL_PIN_DIRECTION_INPUT; 1077b4b95b05SVandita Kulkarni tmp |= UTIL_PIN_ENABLE; 1078b4b95b05SVandita Kulkarni } else { 1079b4b95b05SVandita Kulkarni tmp &= ~UTIL_PIN_ENABLE; 1080b4b95b05SVandita Kulkarni } 1081b4b95b05SVandita Kulkarni intel_de_write(dev_priv, UTIL_PIN_CTL, tmp); 1082b4b95b05SVandita Kulkarni } 1083b4b95b05SVandita Kulkarni 1084379bc100SJani Nikula static void 1085379bc100SJani Nikula gen11_dsi_enable_port_and_phy(struct intel_encoder *encoder, 108604865139SJani Nikula const struct intel_crtc_state *crtc_state) 1087379bc100SJani Nikula { 1088991d9557SVandita Kulkarni struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1089991d9557SVandita Kulkarni 1090379bc100SJani Nikula /* step 4a: power up all lanes of the DDI used by DSI */ 1091379bc100SJani Nikula gen11_dsi_power_up_lanes(encoder); 1092379bc100SJani Nikula 1093379bc100SJani Nikula /* step 4b: configure lane sequencing of the Combo-PHY transmitters */ 1094379bc100SJani Nikula gen11_dsi_config_phy_lanes_sequence(encoder); 1095379bc100SJani Nikula 1096379bc100SJani Nikula /* step 4c: configure voltage swing and skew */ 1097379bc100SJani Nikula gen11_dsi_voltage_swing_program_seq(encoder); 1098379bc100SJani Nikula 1099379bc100SJani Nikula /* enable DDI buffer */ 1100379bc100SJani Nikula gen11_dsi_enable_ddi_buffer(encoder); 1101379bc100SJani Nikula 1102379bc100SJani Nikula /* setup D-PHY timings */ 110304865139SJani Nikula gen11_dsi_setup_dphy_timings(encoder, crtc_state); 1104379bc100SJani Nikula 1105b4b95b05SVandita Kulkarni /* Since transcoder is configured to take events from GPIO */ 1106b4b95b05SVandita Kulkarni gen11_dsi_config_util_pin(encoder, true); 1107b4b95b05SVandita Kulkarni 1108379bc100SJani Nikula /* step 4h: setup DSI protocol timeouts */ 110904865139SJani Nikula gen11_dsi_setup_timeouts(encoder, crtc_state); 1110379bc100SJani Nikula 1111379bc100SJani Nikula /* Step (4h, 4i, 4j, 4k): Configure transcoder */ 111204865139SJani Nikula gen11_dsi_configure_transcoder(encoder, crtc_state); 1113379bc100SJani Nikula 1114379bc100SJani Nikula /* Step 4l: Gate DDI clocks */ 1115991d9557SVandita Kulkarni if (IS_GEN(dev_priv, 11)) 1116379bc100SJani Nikula gen11_dsi_gate_clocks(encoder); 1117379bc100SJani Nikula } 1118379bc100SJani Nikula 1119379bc100SJani Nikula static void gen11_dsi_powerup_panel(struct intel_encoder *encoder) 1120379bc100SJani Nikula { 1121379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1122b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1123379bc100SJani Nikula struct mipi_dsi_device *dsi; 1124379bc100SJani Nikula enum port port; 1125379bc100SJani Nikula enum transcoder dsi_trans; 1126379bc100SJani Nikula u32 tmp; 1127379bc100SJani Nikula int ret; 1128379bc100SJani Nikula 1129379bc100SJani Nikula /* set maximum return packet size */ 1130379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1131379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 1132379bc100SJani Nikula 1133379bc100SJani Nikula /* 1134379bc100SJani Nikula * FIXME: This uses the number of DW's currently in the payload 1135379bc100SJani Nikula * receive queue. This is probably not what we want here. 1136379bc100SJani Nikula */ 11371c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, DSI_CMD_RXCTL(dsi_trans)); 1138379bc100SJani Nikula tmp &= NUMBER_RX_PLOAD_DW_MASK; 1139379bc100SJani Nikula /* multiply "Number Rx Payload DW" by 4 to get max value */ 1140379bc100SJani Nikula tmp = tmp * 4; 1141379bc100SJani Nikula dsi = intel_dsi->dsi_hosts[port]->device; 1142379bc100SJani Nikula ret = mipi_dsi_set_maximum_return_packet_size(dsi, tmp); 1143379bc100SJani Nikula if (ret < 0) 1144b5280cd0SWambui Karuga drm_err(&dev_priv->drm, 1145b5280cd0SWambui Karuga "error setting max return pkt size%d\n", tmp); 1146379bc100SJani Nikula } 1147379bc100SJani Nikula 1148379bc100SJani Nikula /* panel power on related mipi dsi vbt sequences */ 1149379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_ON); 1150379bc100SJani Nikula intel_dsi_msleep(intel_dsi, intel_dsi->panel_on_delay); 1151379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DEASSERT_RESET); 1152379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_INIT_OTP); 1153379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON); 1154379bc100SJani Nikula 1155379bc100SJani Nikula /* ensure all panel commands dispatched before enabling transcoder */ 1156379bc100SJani Nikula wait_for_cmds_dispatched_to_panel(encoder); 1157379bc100SJani Nikula } 1158379bc100SJani Nikula 1159ede9771dSVille Syrjälä static void gen11_dsi_pre_pll_enable(struct intel_atomic_state *state, 1160ede9771dSVille Syrjälä struct intel_encoder *encoder, 116104865139SJani Nikula const struct intel_crtc_state *crtc_state, 1162379bc100SJani Nikula const struct drm_connector_state *conn_state) 1163379bc100SJani Nikula { 1164379bc100SJani Nikula /* step2: enable IO power */ 1165379bc100SJani Nikula gen11_dsi_enable_io_power(encoder); 1166379bc100SJani Nikula 1167379bc100SJani Nikula /* step3: enable DSI PLL */ 116804865139SJani Nikula gen11_dsi_program_esc_clk_div(encoder, crtc_state); 1169379bc100SJani Nikula } 1170379bc100SJani Nikula 1171ede9771dSVille Syrjälä static void gen11_dsi_pre_enable(struct intel_atomic_state *state, 1172ede9771dSVille Syrjälä struct intel_encoder *encoder, 1173379bc100SJani Nikula const struct intel_crtc_state *pipe_config, 1174379bc100SJani Nikula const struct drm_connector_state *conn_state) 1175379bc100SJani Nikula { 1176379bc100SJani Nikula /* step3b */ 1177379bc100SJani Nikula gen11_dsi_map_pll(encoder, pipe_config); 1178379bc100SJani Nikula 1179379bc100SJani Nikula /* step4: enable DSI port and DPHY */ 1180379bc100SJani Nikula gen11_dsi_enable_port_and_phy(encoder, pipe_config); 1181379bc100SJani Nikula 1182379bc100SJani Nikula /* step5: program and powerup panel */ 1183379bc100SJani Nikula gen11_dsi_powerup_panel(encoder); 1184379bc100SJani Nikula 11852b68392eSJani Nikula intel_dsc_enable(encoder, pipe_config); 11862b68392eSJani Nikula 1187379bc100SJani Nikula /* step6c: configure transcoder timings */ 1188379bc100SJani Nikula gen11_dsi_set_transcoder_timings(encoder, pipe_config); 1189379bc100SJani Nikula } 1190379bc100SJani Nikula 1191ede9771dSVille Syrjälä static void gen11_dsi_enable(struct intel_atomic_state *state, 1192ede9771dSVille Syrjälä struct intel_encoder *encoder, 119321fd23acSJani Nikula const struct intel_crtc_state *crtc_state, 119421fd23acSJani Nikula const struct drm_connector_state *conn_state) 119521fd23acSJani Nikula { 119687e9bb49SVandita Kulkarni struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 119787e9bb49SVandita Kulkarni 1198*61198fe1SPankaj Bharadiya drm_WARN_ON(state->base.dev, crtc_state->has_pch_encoder); 119921fd23acSJani Nikula 120087e9bb49SVandita Kulkarni /* step6d: enable dsi transcoder */ 120187e9bb49SVandita Kulkarni gen11_dsi_enable_transcoder(encoder); 120287e9bb49SVandita Kulkarni 120387e9bb49SVandita Kulkarni /* step7: enable backlight */ 120487e9bb49SVandita Kulkarni intel_panel_enable_backlight(crtc_state, conn_state); 120587e9bb49SVandita Kulkarni intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_ON); 120687e9bb49SVandita Kulkarni 120721fd23acSJani Nikula intel_crtc_vblank_on(crtc_state); 120821fd23acSJani Nikula } 120921fd23acSJani Nikula 1210379bc100SJani Nikula static void gen11_dsi_disable_transcoder(struct intel_encoder *encoder) 1211379bc100SJani Nikula { 1212379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1213b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1214379bc100SJani Nikula enum port port; 1215379bc100SJani Nikula enum transcoder dsi_trans; 1216379bc100SJani Nikula u32 tmp; 1217379bc100SJani Nikula 1218379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1219379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 1220379bc100SJani Nikula 1221379bc100SJani Nikula /* disable transcoder */ 12221c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, PIPECONF(dsi_trans)); 1223379bc100SJani Nikula tmp &= ~PIPECONF_ENABLE; 12241c63f6dfSJani Nikula intel_de_write(dev_priv, PIPECONF(dsi_trans), tmp); 1225379bc100SJani Nikula 1226379bc100SJani Nikula /* wait for transcoder to be disabled */ 12274cb3b44dSDaniele Ceraolo Spurio if (intel_de_wait_for_clear(dev_priv, PIPECONF(dsi_trans), 12284cb3b44dSDaniele Ceraolo Spurio I965_PIPECONF_ACTIVE, 50)) 1229b5280cd0SWambui Karuga drm_err(&dev_priv->drm, 1230b5280cd0SWambui Karuga "DSI trancoder not disabled\n"); 1231379bc100SJani Nikula } 1232379bc100SJani Nikula } 1233379bc100SJani Nikula 1234379bc100SJani Nikula static void gen11_dsi_powerdown_panel(struct intel_encoder *encoder) 1235379bc100SJani Nikula { 1236b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1237379bc100SJani Nikula 1238379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_OFF); 1239379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_ASSERT_RESET); 1240379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_OFF); 1241379bc100SJani Nikula 1242379bc100SJani Nikula /* ensure cmds dispatched to panel */ 1243379bc100SJani Nikula wait_for_cmds_dispatched_to_panel(encoder); 1244379bc100SJani Nikula } 1245379bc100SJani Nikula 1246379bc100SJani Nikula static void gen11_dsi_deconfigure_trancoder(struct intel_encoder *encoder) 1247379bc100SJani Nikula { 1248379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1249b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1250379bc100SJani Nikula enum port port; 1251379bc100SJani Nikula enum transcoder dsi_trans; 1252379bc100SJani Nikula u32 tmp; 1253379bc100SJani Nikula 1254b4b95b05SVandita Kulkarni /* disable periodic update mode */ 1255b4b95b05SVandita Kulkarni if (is_cmd_mode(intel_dsi)) { 1256b4b95b05SVandita Kulkarni for_each_dsi_port(port, intel_dsi->ports) { 1257b4b95b05SVandita Kulkarni tmp = intel_de_read(dev_priv, DSI_CMD_FRMCTL(port)); 1258b4b95b05SVandita Kulkarni tmp &= ~DSI_PERIODIC_FRAME_UPDATE_ENABLE; 1259b4b95b05SVandita Kulkarni intel_de_write(dev_priv, DSI_CMD_FRMCTL(port), tmp); 1260b4b95b05SVandita Kulkarni } 1261b4b95b05SVandita Kulkarni } 1262b4b95b05SVandita Kulkarni 1263379bc100SJani Nikula /* put dsi link in ULPS */ 1264379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1265379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 12661c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, DSI_LP_MSG(dsi_trans)); 1267379bc100SJani Nikula tmp |= LINK_ENTER_ULPS; 1268379bc100SJani Nikula tmp &= ~LINK_ULPS_TYPE_LP11; 12691c63f6dfSJani Nikula intel_de_write(dev_priv, DSI_LP_MSG(dsi_trans), tmp); 1270379bc100SJani Nikula 12711c63f6dfSJani Nikula if (wait_for_us((intel_de_read(dev_priv, DSI_LP_MSG(dsi_trans)) & 1272379bc100SJani Nikula LINK_IN_ULPS), 1273379bc100SJani Nikula 10)) 1274b5280cd0SWambui Karuga drm_err(&dev_priv->drm, "DSI link not in ULPS\n"); 1275379bc100SJani Nikula } 1276379bc100SJani Nikula 1277379bc100SJani Nikula /* disable ddi function */ 1278379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1279379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 12801c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(dsi_trans)); 1281379bc100SJani Nikula tmp &= ~TRANS_DDI_FUNC_ENABLE; 12821c63f6dfSJani Nikula intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(dsi_trans), tmp); 1283379bc100SJani Nikula } 1284379bc100SJani Nikula 1285379bc100SJani Nikula /* disable port sync mode if dual link */ 1286379bc100SJani Nikula if (intel_dsi->dual_link) { 1287379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1288379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 12891c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, 12901c63f6dfSJani Nikula TRANS_DDI_FUNC_CTL2(dsi_trans)); 1291379bc100SJani Nikula tmp &= ~PORT_SYNC_MODE_ENABLE; 12921c63f6dfSJani Nikula intel_de_write(dev_priv, 12931c63f6dfSJani Nikula TRANS_DDI_FUNC_CTL2(dsi_trans), tmp); 1294379bc100SJani Nikula } 1295379bc100SJani Nikula } 1296379bc100SJani Nikula } 1297379bc100SJani Nikula 1298379bc100SJani Nikula static void gen11_dsi_disable_port(struct intel_encoder *encoder) 1299379bc100SJani Nikula { 1300379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1301b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1302379bc100SJani Nikula u32 tmp; 1303379bc100SJani Nikula enum port port; 1304379bc100SJani Nikula 1305379bc100SJani Nikula gen11_dsi_ungate_clocks(encoder); 1306379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 13071c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, DDI_BUF_CTL(port)); 1308379bc100SJani Nikula tmp &= ~DDI_BUF_CTL_ENABLE; 13091c63f6dfSJani Nikula intel_de_write(dev_priv, DDI_BUF_CTL(port), tmp); 1310379bc100SJani Nikula 13111c63f6dfSJani Nikula if (wait_for_us((intel_de_read(dev_priv, DDI_BUF_CTL(port)) & 1312379bc100SJani Nikula DDI_BUF_IS_IDLE), 1313379bc100SJani Nikula 8)) 1314b5280cd0SWambui Karuga drm_err(&dev_priv->drm, 1315b5280cd0SWambui Karuga "DDI port:%c buffer not idle\n", 1316379bc100SJani Nikula port_name(port)); 1317379bc100SJani Nikula } 1318379bc100SJani Nikula gen11_dsi_gate_clocks(encoder); 1319379bc100SJani Nikula } 1320379bc100SJani Nikula 1321379bc100SJani Nikula static void gen11_dsi_disable_io_power(struct intel_encoder *encoder) 1322379bc100SJani Nikula { 1323379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1324b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1325379bc100SJani Nikula enum port port; 1326379bc100SJani Nikula u32 tmp; 1327379bc100SJani Nikula 1328379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1329379bc100SJani Nikula intel_wakeref_t wakeref; 1330379bc100SJani Nikula 1331379bc100SJani Nikula wakeref = fetch_and_zero(&intel_dsi->io_wakeref[port]); 1332379bc100SJani Nikula intel_display_power_put(dev_priv, 1333379bc100SJani Nikula port == PORT_A ? 1334379bc100SJani Nikula POWER_DOMAIN_PORT_DDI_A_IO : 1335379bc100SJani Nikula POWER_DOMAIN_PORT_DDI_B_IO, 1336379bc100SJani Nikula wakeref); 1337379bc100SJani Nikula } 1338379bc100SJani Nikula 1339379bc100SJani Nikula /* set mode to DDI */ 1340379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 13411c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, ICL_DSI_IO_MODECTL(port)); 1342379bc100SJani Nikula tmp &= ~COMBO_PHY_MODE_DSI; 13431c63f6dfSJani Nikula intel_de_write(dev_priv, ICL_DSI_IO_MODECTL(port), tmp); 1344379bc100SJani Nikula } 1345379bc100SJani Nikula } 1346379bc100SJani Nikula 1347ede9771dSVille Syrjälä static void gen11_dsi_disable(struct intel_atomic_state *state, 1348ede9771dSVille Syrjälä struct intel_encoder *encoder, 1349379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 1350379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 1351379bc100SJani Nikula { 1352b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1353379bc100SJani Nikula 1354379bc100SJani Nikula /* step1: turn off backlight */ 1355379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_OFF); 1356379bc100SJani Nikula intel_panel_disable_backlight(old_conn_state); 1357379bc100SJani Nikula 1358379bc100SJani Nikula /* step2d,e: disable transcoder and wait */ 1359379bc100SJani Nikula gen11_dsi_disable_transcoder(encoder); 1360379bc100SJani Nikula 1361379bc100SJani Nikula /* step2f,g: powerdown panel */ 1362379bc100SJani Nikula gen11_dsi_powerdown_panel(encoder); 1363379bc100SJani Nikula 1364379bc100SJani Nikula /* step2h,i,j: deconfig trancoder */ 1365379bc100SJani Nikula gen11_dsi_deconfigure_trancoder(encoder); 1366379bc100SJani Nikula 1367379bc100SJani Nikula /* step3: disable port */ 1368379bc100SJani Nikula gen11_dsi_disable_port(encoder); 1369379bc100SJani Nikula 1370b4b95b05SVandita Kulkarni gen11_dsi_config_util_pin(encoder, false); 1371b4b95b05SVandita Kulkarni 1372379bc100SJani Nikula /* step4: disable IO power */ 1373379bc100SJani Nikula gen11_dsi_disable_io_power(encoder); 1374379bc100SJani Nikula } 1375379bc100SJani Nikula 1376ede9771dSVille Syrjälä static void gen11_dsi_post_disable(struct intel_atomic_state *state, 1377ede9771dSVille Syrjälä struct intel_encoder *encoder, 1378773b4b54SVille Syrjälä const struct intel_crtc_state *old_crtc_state, 1379773b4b54SVille Syrjälä const struct drm_connector_state *old_conn_state) 1380773b4b54SVille Syrjälä { 1381773b4b54SVille Syrjälä intel_crtc_vblank_off(old_crtc_state); 1382773b4b54SVille Syrjälä 1383773b4b54SVille Syrjälä intel_dsc_disable(old_crtc_state); 1384773b4b54SVille Syrjälä 1385f6df4d46SLucas De Marchi skl_scaler_disable(old_crtc_state); 1386773b4b54SVille Syrjälä } 1387773b4b54SVille Syrjälä 13882b68392eSJani Nikula static enum drm_mode_status gen11_dsi_mode_valid(struct drm_connector *connector, 13892b68392eSJani Nikula struct drm_display_mode *mode) 13902b68392eSJani Nikula { 13912b68392eSJani Nikula /* FIXME: DSC? */ 13922b68392eSJani Nikula return intel_dsi_mode_valid(connector, mode); 13932b68392eSJani Nikula } 13942b68392eSJani Nikula 1395379bc100SJani Nikula static void gen11_dsi_get_timings(struct intel_encoder *encoder, 1396379bc100SJani Nikula struct intel_crtc_state *pipe_config) 1397379bc100SJani Nikula { 1398b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1399379bc100SJani Nikula struct drm_display_mode *adjusted_mode = 14001326a92cSMaarten Lankhorst &pipe_config->hw.adjusted_mode; 1401379bc100SJani Nikula 1402c2bb35e9SVandita Kulkarni if (pipe_config->dsc.compressed_bpp) { 1403c2bb35e9SVandita Kulkarni int div = pipe_config->dsc.compressed_bpp; 1404c2bb35e9SVandita Kulkarni int mul = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); 1405c2bb35e9SVandita Kulkarni 1406c2bb35e9SVandita Kulkarni adjusted_mode->crtc_htotal = 1407c2bb35e9SVandita Kulkarni DIV_ROUND_UP(adjusted_mode->crtc_htotal * mul, div); 1408c2bb35e9SVandita Kulkarni adjusted_mode->crtc_hsync_start = 1409c2bb35e9SVandita Kulkarni DIV_ROUND_UP(adjusted_mode->crtc_hsync_start * mul, div); 1410c2bb35e9SVandita Kulkarni adjusted_mode->crtc_hsync_end = 1411c2bb35e9SVandita Kulkarni DIV_ROUND_UP(adjusted_mode->crtc_hsync_end * mul, div); 1412c2bb35e9SVandita Kulkarni } 1413c2bb35e9SVandita Kulkarni 1414379bc100SJani Nikula if (intel_dsi->dual_link) { 1415379bc100SJani Nikula adjusted_mode->crtc_hdisplay *= 2; 1416379bc100SJani Nikula if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) 1417379bc100SJani Nikula adjusted_mode->crtc_hdisplay -= 1418379bc100SJani Nikula intel_dsi->pixel_overlap; 1419379bc100SJani Nikula adjusted_mode->crtc_htotal *= 2; 1420379bc100SJani Nikula } 1421379bc100SJani Nikula adjusted_mode->crtc_hblank_start = adjusted_mode->crtc_hdisplay; 1422379bc100SJani Nikula adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_htotal; 1423379bc100SJani Nikula 1424379bc100SJani Nikula if (intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE) { 1425379bc100SJani Nikula if (intel_dsi->dual_link) { 1426379bc100SJani Nikula adjusted_mode->crtc_hsync_start *= 2; 1427379bc100SJani Nikula adjusted_mode->crtc_hsync_end *= 2; 1428379bc100SJani Nikula } 1429379bc100SJani Nikula } 1430379bc100SJani Nikula adjusted_mode->crtc_vblank_start = adjusted_mode->crtc_vdisplay; 1431379bc100SJani Nikula adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vtotal; 1432379bc100SJani Nikula } 1433379bc100SJani Nikula 1434cebb28acSVandita Kulkarni static bool gen11_dsi_is_periodic_cmd_mode(struct intel_dsi *intel_dsi) 1435cebb28acSVandita Kulkarni { 1436cebb28acSVandita Kulkarni struct drm_device *dev = intel_dsi->base.base.dev; 1437cebb28acSVandita Kulkarni struct drm_i915_private *dev_priv = to_i915(dev); 1438cebb28acSVandita Kulkarni enum transcoder dsi_trans; 1439cebb28acSVandita Kulkarni u32 val; 1440cebb28acSVandita Kulkarni 1441cebb28acSVandita Kulkarni if (intel_dsi->ports == BIT(PORT_B)) 1442cebb28acSVandita Kulkarni dsi_trans = TRANSCODER_DSI_1; 1443cebb28acSVandita Kulkarni else 1444cebb28acSVandita Kulkarni dsi_trans = TRANSCODER_DSI_0; 1445cebb28acSVandita Kulkarni 1446cebb28acSVandita Kulkarni val = intel_de_read(dev_priv, DSI_TRANS_FUNC_CONF(dsi_trans)); 1447cebb28acSVandita Kulkarni return (val & DSI_PERIODIC_FRAME_UPDATE_ENABLE); 1448cebb28acSVandita Kulkarni } 1449cebb28acSVandita Kulkarni 1450379bc100SJani Nikula static void gen11_dsi_get_config(struct intel_encoder *encoder, 1451379bc100SJani Nikula struct intel_crtc_state *pipe_config) 1452379bc100SJani Nikula { 1453b953eb21SImre Deak struct drm_i915_private *i915 = to_i915(encoder->base.dev); 14542225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 1455b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1456379bc100SJani Nikula 14572b68392eSJani Nikula intel_dsc_get_config(encoder, pipe_config); 14582b68392eSJani Nikula 1459379bc100SJani Nikula /* FIXME: adapt icl_ddi_clock_get() for DSI and use that? */ 1460b953eb21SImre Deak pipe_config->port_clock = intel_dpll_get_freq(i915, 1461b953eb21SImre Deak pipe_config->shared_dpll); 1462379bc100SJani Nikula 14631326a92cSMaarten Lankhorst pipe_config->hw.adjusted_mode.crtc_clock = intel_dsi->pclk; 1464379bc100SJani Nikula if (intel_dsi->dual_link) 14651326a92cSMaarten Lankhorst pipe_config->hw.adjusted_mode.crtc_clock *= 2; 1466379bc100SJani Nikula 1467379bc100SJani Nikula gen11_dsi_get_timings(encoder, pipe_config); 1468379bc100SJani Nikula pipe_config->output_types |= BIT(INTEL_OUTPUT_DSI); 1469379bc100SJani Nikula pipe_config->pipe_bpp = bdw_get_pipemisc_bpp(crtc); 1470cebb28acSVandita Kulkarni 1471cebb28acSVandita Kulkarni if (gen11_dsi_is_periodic_cmd_mode(intel_dsi)) 1472cebb28acSVandita Kulkarni pipe_config->hw.adjusted_mode.private_flags |= 1473cebb28acSVandita Kulkarni I915_MODE_FLAG_DSI_PERIODIC_CMD_MODE; 1474379bc100SJani Nikula } 1475379bc100SJani Nikula 14762b68392eSJani Nikula static int gen11_dsi_dsc_compute_config(struct intel_encoder *encoder, 14772b68392eSJani Nikula struct intel_crtc_state *crtc_state) 14782b68392eSJani Nikula { 14792b68392eSJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 14802b68392eSJani Nikula struct drm_dsc_config *vdsc_cfg = &crtc_state->dsc.config; 14812b68392eSJani Nikula int dsc_max_bpc = INTEL_GEN(dev_priv) >= 12 ? 12 : 10; 14822b68392eSJani Nikula bool use_dsc; 14832b68392eSJani Nikula int ret; 14842b68392eSJani Nikula 14852b68392eSJani Nikula use_dsc = intel_bios_get_dsc_params(encoder, crtc_state, dsc_max_bpc); 14862b68392eSJani Nikula if (!use_dsc) 14872b68392eSJani Nikula return 0; 14882b68392eSJani Nikula 14892b68392eSJani Nikula if (crtc_state->pipe_bpp < 8 * 3) 14902b68392eSJani Nikula return -EINVAL; 14912b68392eSJani Nikula 14922b68392eSJani Nikula /* FIXME: split only when necessary */ 14932b68392eSJani Nikula if (crtc_state->dsc.slice_count > 1) 14942b68392eSJani Nikula crtc_state->dsc.dsc_split = true; 14952b68392eSJani Nikula 14962b68392eSJani Nikula vdsc_cfg->convert_rgb = true; 14972b68392eSJani Nikula 14982b68392eSJani Nikula ret = intel_dsc_compute_params(encoder, crtc_state); 14992b68392eSJani Nikula if (ret) 15002b68392eSJani Nikula return ret; 15012b68392eSJani Nikula 15022b68392eSJani Nikula /* DSI specific sanity checks on the common code */ 15033dbe5e11SPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, vdsc_cfg->vbr_enable); 15043dbe5e11SPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, vdsc_cfg->simple_422); 15053dbe5e11SPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, 15063dbe5e11SPankaj Bharadiya vdsc_cfg->pic_width % vdsc_cfg->slice_width); 15073dbe5e11SPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, vdsc_cfg->slice_height < 8); 15083dbe5e11SPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, 15093dbe5e11SPankaj Bharadiya vdsc_cfg->pic_height % vdsc_cfg->slice_height); 15102b68392eSJani Nikula 15112b68392eSJani Nikula ret = drm_dsc_compute_rc_parameters(vdsc_cfg); 15122b68392eSJani Nikula if (ret) 15132b68392eSJani Nikula return ret; 15142b68392eSJani Nikula 15152b68392eSJani Nikula crtc_state->dsc.compression_enable = true; 15162b68392eSJani Nikula 15172b68392eSJani Nikula return 0; 15182b68392eSJani Nikula } 15192b68392eSJani Nikula 1520379bc100SJani Nikula static int gen11_dsi_compute_config(struct intel_encoder *encoder, 1521379bc100SJani Nikula struct intel_crtc_state *pipe_config, 1522379bc100SJani Nikula struct drm_connector_state *conn_state) 1523379bc100SJani Nikula { 1524dd10a80fSJani Nikula struct drm_i915_private *i915 = to_i915(encoder->base.dev); 1525379bc100SJani Nikula struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi, 1526379bc100SJani Nikula base); 1527379bc100SJani Nikula struct intel_connector *intel_connector = intel_dsi->attached_connector; 15282225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 1529379bc100SJani Nikula const struct drm_display_mode *fixed_mode = 1530379bc100SJani Nikula intel_connector->panel.fixed_mode; 1531379bc100SJani Nikula struct drm_display_mode *adjusted_mode = 15321326a92cSMaarten Lankhorst &pipe_config->hw.adjusted_mode; 1533379bc100SJani Nikula 1534379bc100SJani Nikula pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; 1535379bc100SJani Nikula intel_fixed_panel_mode(fixed_mode, adjusted_mode); 1536379bc100SJani Nikula intel_pch_panel_fitting(crtc, pipe_config, conn_state->scaling_mode); 1537379bc100SJani Nikula 1538379bc100SJani Nikula adjusted_mode->flags = 0; 1539379bc100SJani Nikula 1540379bc100SJani Nikula /* Dual link goes to trancoder DSI'0' */ 1541379bc100SJani Nikula if (intel_dsi->ports == BIT(PORT_B)) 1542379bc100SJani Nikula pipe_config->cpu_transcoder = TRANSCODER_DSI_1; 1543379bc100SJani Nikula else 1544379bc100SJani Nikula pipe_config->cpu_transcoder = TRANSCODER_DSI_0; 1545379bc100SJani Nikula 154650003bf5SJani Nikula if (intel_dsi->pixel_format == MIPI_DSI_FMT_RGB888) 154750003bf5SJani Nikula pipe_config->pipe_bpp = 24; 154850003bf5SJani Nikula else 154950003bf5SJani Nikula pipe_config->pipe_bpp = 18; 155050003bf5SJani Nikula 1551379bc100SJani Nikula pipe_config->clock_set = true; 15522b68392eSJani Nikula 15532b68392eSJani Nikula if (gen11_dsi_dsc_compute_config(encoder, pipe_config)) 1554dd10a80fSJani Nikula drm_dbg_kms(&i915->drm, "Attempting to use DSC failed\n"); 15552b68392eSJani Nikula 155604865139SJani Nikula pipe_config->port_clock = afe_clk(encoder, pipe_config) / 5; 1557379bc100SJani Nikula 1558cebb28acSVandita Kulkarni /* We would not operate in periodic command mode */ 1559cebb28acSVandita Kulkarni pipe_config->hw.adjusted_mode.private_flags &= 1560cebb28acSVandita Kulkarni ~I915_MODE_FLAG_DSI_PERIODIC_CMD_MODE; 1561cebb28acSVandita Kulkarni 1562f78a862dSVandita Kulkarni /* 1563f78a862dSVandita Kulkarni * In case of TE GATE cmd mode, we 1564f78a862dSVandita Kulkarni * receive TE from the slave if 1565f78a862dSVandita Kulkarni * dual link is enabled 1566f78a862dSVandita Kulkarni */ 1567f78a862dSVandita Kulkarni if (is_cmd_mode(intel_dsi)) { 1568f78a862dSVandita Kulkarni if (intel_dsi->ports == (BIT(PORT_B) | BIT(PORT_A))) 1569f78a862dSVandita Kulkarni pipe_config->hw.adjusted_mode.private_flags |= 1570f78a862dSVandita Kulkarni I915_MODE_FLAG_DSI_USE_TE1 | 1571f78a862dSVandita Kulkarni I915_MODE_FLAG_DSI_USE_TE0; 1572f78a862dSVandita Kulkarni else if (intel_dsi->ports == BIT(PORT_B)) 1573f78a862dSVandita Kulkarni pipe_config->hw.adjusted_mode.private_flags |= 1574f78a862dSVandita Kulkarni I915_MODE_FLAG_DSI_USE_TE1; 1575f78a862dSVandita Kulkarni else 1576f78a862dSVandita Kulkarni pipe_config->hw.adjusted_mode.private_flags |= 1577f78a862dSVandita Kulkarni I915_MODE_FLAG_DSI_USE_TE0; 1578f78a862dSVandita Kulkarni } 1579f78a862dSVandita Kulkarni 1580379bc100SJani Nikula return 0; 1581379bc100SJani Nikula } 1582379bc100SJani Nikula 1583379bc100SJani Nikula static void gen11_dsi_get_power_domains(struct intel_encoder *encoder, 1584379bc100SJani Nikula struct intel_crtc_state *crtc_state) 1585379bc100SJani Nikula { 15862b68392eSJani Nikula struct drm_i915_private *i915 = to_i915(encoder->base.dev); 15872b68392eSJani Nikula 1588b7d02c3aSVille Syrjälä get_dsi_io_power_domains(i915, 1589b7d02c3aSVille Syrjälä enc_to_intel_dsi(encoder)); 15902b68392eSJani Nikula 15912b68392eSJani Nikula if (crtc_state->dsc.compression_enable) 15922b68392eSJani Nikula intel_display_power_get(i915, 15932b68392eSJani Nikula intel_dsc_power_domain(crtc_state)); 1594379bc100SJani Nikula } 1595379bc100SJani Nikula 1596379bc100SJani Nikula static bool gen11_dsi_get_hw_state(struct intel_encoder *encoder, 1597379bc100SJani Nikula enum pipe *pipe) 1598379bc100SJani Nikula { 1599379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1600b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1601379bc100SJani Nikula enum transcoder dsi_trans; 1602379bc100SJani Nikula intel_wakeref_t wakeref; 1603379bc100SJani Nikula enum port port; 1604379bc100SJani Nikula bool ret = false; 1605379bc100SJani Nikula u32 tmp; 1606379bc100SJani Nikula 1607379bc100SJani Nikula wakeref = intel_display_power_get_if_enabled(dev_priv, 1608379bc100SJani Nikula encoder->power_domain); 1609379bc100SJani Nikula if (!wakeref) 1610379bc100SJani Nikula return false; 1611379bc100SJani Nikula 1612379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1613379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 16141c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(dsi_trans)); 1615379bc100SJani Nikula switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { 1616379bc100SJani Nikula case TRANS_DDI_EDP_INPUT_A_ON: 1617379bc100SJani Nikula *pipe = PIPE_A; 1618379bc100SJani Nikula break; 1619379bc100SJani Nikula case TRANS_DDI_EDP_INPUT_B_ONOFF: 1620379bc100SJani Nikula *pipe = PIPE_B; 1621379bc100SJani Nikula break; 1622379bc100SJani Nikula case TRANS_DDI_EDP_INPUT_C_ONOFF: 1623379bc100SJani Nikula *pipe = PIPE_C; 1624379bc100SJani Nikula break; 16254d89adc7SJosé Roberto de Souza case TRANS_DDI_EDP_INPUT_D_ONOFF: 16264d89adc7SJosé Roberto de Souza *pipe = PIPE_D; 16274d89adc7SJosé Roberto de Souza break; 1628379bc100SJani Nikula default: 1629b5280cd0SWambui Karuga drm_err(&dev_priv->drm, "Invalid PIPE input\n"); 1630379bc100SJani Nikula goto out; 1631379bc100SJani Nikula } 1632379bc100SJani Nikula 16331c63f6dfSJani Nikula tmp = intel_de_read(dev_priv, PIPECONF(dsi_trans)); 1634379bc100SJani Nikula ret = tmp & PIPECONF_ENABLE; 1635379bc100SJani Nikula } 1636379bc100SJani Nikula out: 1637379bc100SJani Nikula intel_display_power_put(dev_priv, encoder->power_domain, wakeref); 1638379bc100SJani Nikula return ret; 1639379bc100SJani Nikula } 1640379bc100SJani Nikula 1641379bc100SJani Nikula static void gen11_dsi_encoder_destroy(struct drm_encoder *encoder) 1642379bc100SJani Nikula { 1643379bc100SJani Nikula intel_encoder_destroy(encoder); 1644379bc100SJani Nikula } 1645379bc100SJani Nikula 1646379bc100SJani Nikula static const struct drm_encoder_funcs gen11_dsi_encoder_funcs = { 1647379bc100SJani Nikula .destroy = gen11_dsi_encoder_destroy, 1648379bc100SJani Nikula }; 1649379bc100SJani Nikula 1650379bc100SJani Nikula static const struct drm_connector_funcs gen11_dsi_connector_funcs = { 1651379bc100SJani Nikula .late_register = intel_connector_register, 1652379bc100SJani Nikula .early_unregister = intel_connector_unregister, 1653379bc100SJani Nikula .destroy = intel_connector_destroy, 1654379bc100SJani Nikula .fill_modes = drm_helper_probe_single_connector_modes, 1655379bc100SJani Nikula .atomic_get_property = intel_digital_connector_atomic_get_property, 1656379bc100SJani Nikula .atomic_set_property = intel_digital_connector_atomic_set_property, 1657379bc100SJani Nikula .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 1658379bc100SJani Nikula .atomic_duplicate_state = intel_digital_connector_duplicate_state, 1659379bc100SJani Nikula }; 1660379bc100SJani Nikula 1661379bc100SJani Nikula static const struct drm_connector_helper_funcs gen11_dsi_connector_helper_funcs = { 1662379bc100SJani Nikula .get_modes = intel_dsi_get_modes, 16632b68392eSJani Nikula .mode_valid = gen11_dsi_mode_valid, 1664379bc100SJani Nikula .atomic_check = intel_digital_connector_atomic_check, 1665379bc100SJani Nikula }; 1666379bc100SJani Nikula 1667379bc100SJani Nikula static int gen11_dsi_host_attach(struct mipi_dsi_host *host, 1668379bc100SJani Nikula struct mipi_dsi_device *dsi) 1669379bc100SJani Nikula { 1670379bc100SJani Nikula return 0; 1671379bc100SJani Nikula } 1672379bc100SJani Nikula 1673379bc100SJani Nikula static int gen11_dsi_host_detach(struct mipi_dsi_host *host, 1674379bc100SJani Nikula struct mipi_dsi_device *dsi) 1675379bc100SJani Nikula { 1676379bc100SJani Nikula return 0; 1677379bc100SJani Nikula } 1678379bc100SJani Nikula 1679379bc100SJani Nikula static ssize_t gen11_dsi_host_transfer(struct mipi_dsi_host *host, 1680379bc100SJani Nikula const struct mipi_dsi_msg *msg) 1681379bc100SJani Nikula { 1682379bc100SJani Nikula struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host); 1683379bc100SJani Nikula struct mipi_dsi_packet dsi_pkt; 1684379bc100SJani Nikula ssize_t ret; 1685379bc100SJani Nikula bool enable_lpdt = false; 1686379bc100SJani Nikula 1687379bc100SJani Nikula ret = mipi_dsi_create_packet(&dsi_pkt, msg); 1688379bc100SJani Nikula if (ret < 0) 1689379bc100SJani Nikula return ret; 1690379bc100SJani Nikula 1691379bc100SJani Nikula if (msg->flags & MIPI_DSI_MSG_USE_LPM) 1692379bc100SJani Nikula enable_lpdt = true; 1693379bc100SJani Nikula 1694379bc100SJani Nikula /* send packet header */ 1695379bc100SJani Nikula ret = dsi_send_pkt_hdr(intel_dsi_host, dsi_pkt, enable_lpdt); 1696379bc100SJani Nikula if (ret < 0) 1697379bc100SJani Nikula return ret; 1698379bc100SJani Nikula 1699379bc100SJani Nikula /* only long packet contains payload */ 1700379bc100SJani Nikula if (mipi_dsi_packet_format_is_long(msg->type)) { 1701379bc100SJani Nikula ret = dsi_send_pkt_payld(intel_dsi_host, dsi_pkt); 1702379bc100SJani Nikula if (ret < 0) 1703379bc100SJani Nikula return ret; 1704379bc100SJani Nikula } 1705379bc100SJani Nikula 1706379bc100SJani Nikula //TODO: add payload receive code if needed 1707379bc100SJani Nikula 1708379bc100SJani Nikula ret = sizeof(dsi_pkt.header) + dsi_pkt.payload_length; 1709379bc100SJani Nikula 1710379bc100SJani Nikula return ret; 1711379bc100SJani Nikula } 1712379bc100SJani Nikula 1713379bc100SJani Nikula static const struct mipi_dsi_host_ops gen11_dsi_host_ops = { 1714379bc100SJani Nikula .attach = gen11_dsi_host_attach, 1715379bc100SJani Nikula .detach = gen11_dsi_host_detach, 1716379bc100SJani Nikula .transfer = gen11_dsi_host_transfer, 1717379bc100SJani Nikula }; 1718379bc100SJani Nikula 1719379bc100SJani Nikula #define ICL_PREPARE_CNT_MAX 0x7 1720379bc100SJani Nikula #define ICL_CLK_ZERO_CNT_MAX 0xf 1721379bc100SJani Nikula #define ICL_TRAIL_CNT_MAX 0x7 1722379bc100SJani Nikula #define ICL_TCLK_PRE_CNT_MAX 0x3 1723379bc100SJani Nikula #define ICL_TCLK_POST_CNT_MAX 0x7 1724379bc100SJani Nikula #define ICL_HS_ZERO_CNT_MAX 0xf 1725379bc100SJani Nikula #define ICL_EXIT_ZERO_CNT_MAX 0x7 1726379bc100SJani Nikula 1727379bc100SJani Nikula static void icl_dphy_param_init(struct intel_dsi *intel_dsi) 1728379bc100SJani Nikula { 1729379bc100SJani Nikula struct drm_device *dev = intel_dsi->base.base.dev; 1730379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(dev); 1731379bc100SJani Nikula struct mipi_config *mipi_config = dev_priv->vbt.dsi.config; 1732379bc100SJani Nikula u32 tlpx_ns; 1733379bc100SJani Nikula u32 prepare_cnt, exit_zero_cnt, clk_zero_cnt, trail_cnt; 1734379bc100SJani Nikula u32 ths_prepare_ns, tclk_trail_ns; 1735379bc100SJani Nikula u32 hs_zero_cnt; 1736379bc100SJani Nikula u32 tclk_pre_cnt, tclk_post_cnt; 1737379bc100SJani Nikula 1738379bc100SJani Nikula tlpx_ns = intel_dsi_tlpx_ns(intel_dsi); 1739379bc100SJani Nikula 1740379bc100SJani Nikula tclk_trail_ns = max(mipi_config->tclk_trail, mipi_config->ths_trail); 1741379bc100SJani Nikula ths_prepare_ns = max(mipi_config->ths_prepare, 1742379bc100SJani Nikula mipi_config->tclk_prepare); 1743379bc100SJani Nikula 1744379bc100SJani Nikula /* 1745379bc100SJani Nikula * prepare cnt in escape clocks 1746379bc100SJani Nikula * this field represents a hexadecimal value with a precision 1747379bc100SJani Nikula * of 1.2 – i.e. the most significant bit is the integer 1748379bc100SJani Nikula * and the least significant 2 bits are fraction bits. 1749379bc100SJani Nikula * so, the field can represent a range of 0.25 to 1.75 1750379bc100SJani Nikula */ 1751379bc100SJani Nikula prepare_cnt = DIV_ROUND_UP(ths_prepare_ns * 4, tlpx_ns); 1752379bc100SJani Nikula if (prepare_cnt > ICL_PREPARE_CNT_MAX) { 1753b5280cd0SWambui Karuga drm_dbg_kms(&dev_priv->drm, "prepare_cnt out of range (%d)\n", 1754b5280cd0SWambui Karuga prepare_cnt); 1755379bc100SJani Nikula prepare_cnt = ICL_PREPARE_CNT_MAX; 1756379bc100SJani Nikula } 1757379bc100SJani Nikula 1758379bc100SJani Nikula /* clk zero count in escape clocks */ 1759379bc100SJani Nikula clk_zero_cnt = DIV_ROUND_UP(mipi_config->tclk_prepare_clkzero - 1760379bc100SJani Nikula ths_prepare_ns, tlpx_ns); 1761379bc100SJani Nikula if (clk_zero_cnt > ICL_CLK_ZERO_CNT_MAX) { 1762b5280cd0SWambui Karuga drm_dbg_kms(&dev_priv->drm, 1763b5280cd0SWambui Karuga "clk_zero_cnt out of range (%d)\n", clk_zero_cnt); 1764379bc100SJani Nikula clk_zero_cnt = ICL_CLK_ZERO_CNT_MAX; 1765379bc100SJani Nikula } 1766379bc100SJani Nikula 1767379bc100SJani Nikula /* trail cnt in escape clocks*/ 1768379bc100SJani Nikula trail_cnt = DIV_ROUND_UP(tclk_trail_ns, tlpx_ns); 1769379bc100SJani Nikula if (trail_cnt > ICL_TRAIL_CNT_MAX) { 1770b5280cd0SWambui Karuga drm_dbg_kms(&dev_priv->drm, "trail_cnt out of range (%d)\n", 1771b5280cd0SWambui Karuga trail_cnt); 1772379bc100SJani Nikula trail_cnt = ICL_TRAIL_CNT_MAX; 1773379bc100SJani Nikula } 1774379bc100SJani Nikula 1775379bc100SJani Nikula /* tclk pre count in escape clocks */ 1776379bc100SJani Nikula tclk_pre_cnt = DIV_ROUND_UP(mipi_config->tclk_pre, tlpx_ns); 1777379bc100SJani Nikula if (tclk_pre_cnt > ICL_TCLK_PRE_CNT_MAX) { 1778b5280cd0SWambui Karuga drm_dbg_kms(&dev_priv->drm, 1779b5280cd0SWambui Karuga "tclk_pre_cnt out of range (%d)\n", tclk_pre_cnt); 1780379bc100SJani Nikula tclk_pre_cnt = ICL_TCLK_PRE_CNT_MAX; 1781379bc100SJani Nikula } 1782379bc100SJani Nikula 1783379bc100SJani Nikula /* tclk post count in escape clocks */ 1784379bc100SJani Nikula tclk_post_cnt = DIV_ROUND_UP(mipi_config->tclk_post, tlpx_ns); 1785379bc100SJani Nikula if (tclk_post_cnt > ICL_TCLK_POST_CNT_MAX) { 1786b5280cd0SWambui Karuga drm_dbg_kms(&dev_priv->drm, 1787b5280cd0SWambui Karuga "tclk_post_cnt out of range (%d)\n", 1788b5280cd0SWambui Karuga tclk_post_cnt); 1789379bc100SJani Nikula tclk_post_cnt = ICL_TCLK_POST_CNT_MAX; 1790379bc100SJani Nikula } 1791379bc100SJani Nikula 1792379bc100SJani Nikula /* hs zero cnt in escape clocks */ 1793379bc100SJani Nikula hs_zero_cnt = DIV_ROUND_UP(mipi_config->ths_prepare_hszero - 1794379bc100SJani Nikula ths_prepare_ns, tlpx_ns); 1795379bc100SJani Nikula if (hs_zero_cnt > ICL_HS_ZERO_CNT_MAX) { 1796b5280cd0SWambui Karuga drm_dbg_kms(&dev_priv->drm, "hs_zero_cnt out of range (%d)\n", 1797b5280cd0SWambui Karuga hs_zero_cnt); 1798379bc100SJani Nikula hs_zero_cnt = ICL_HS_ZERO_CNT_MAX; 1799379bc100SJani Nikula } 1800379bc100SJani Nikula 1801379bc100SJani Nikula /* hs exit zero cnt in escape clocks */ 1802379bc100SJani Nikula exit_zero_cnt = DIV_ROUND_UP(mipi_config->ths_exit, tlpx_ns); 1803379bc100SJani Nikula if (exit_zero_cnt > ICL_EXIT_ZERO_CNT_MAX) { 1804b5280cd0SWambui Karuga drm_dbg_kms(&dev_priv->drm, 1805b5280cd0SWambui Karuga "exit_zero_cnt out of range (%d)\n", 1806b5280cd0SWambui Karuga exit_zero_cnt); 1807379bc100SJani Nikula exit_zero_cnt = ICL_EXIT_ZERO_CNT_MAX; 1808379bc100SJani Nikula } 1809379bc100SJani Nikula 1810379bc100SJani Nikula /* clock lane dphy timings */ 1811379bc100SJani Nikula intel_dsi->dphy_reg = (CLK_PREPARE_OVERRIDE | 1812379bc100SJani Nikula CLK_PREPARE(prepare_cnt) | 1813379bc100SJani Nikula CLK_ZERO_OVERRIDE | 1814379bc100SJani Nikula CLK_ZERO(clk_zero_cnt) | 1815379bc100SJani Nikula CLK_PRE_OVERRIDE | 1816379bc100SJani Nikula CLK_PRE(tclk_pre_cnt) | 1817379bc100SJani Nikula CLK_POST_OVERRIDE | 1818379bc100SJani Nikula CLK_POST(tclk_post_cnt) | 1819379bc100SJani Nikula CLK_TRAIL_OVERRIDE | 1820379bc100SJani Nikula CLK_TRAIL(trail_cnt)); 1821379bc100SJani Nikula 1822379bc100SJani Nikula /* data lanes dphy timings */ 1823379bc100SJani Nikula intel_dsi->dphy_data_lane_reg = (HS_PREPARE_OVERRIDE | 1824379bc100SJani Nikula HS_PREPARE(prepare_cnt) | 1825379bc100SJani Nikula HS_ZERO_OVERRIDE | 1826379bc100SJani Nikula HS_ZERO(hs_zero_cnt) | 1827379bc100SJani Nikula HS_TRAIL_OVERRIDE | 1828379bc100SJani Nikula HS_TRAIL(trail_cnt) | 1829379bc100SJani Nikula HS_EXIT_OVERRIDE | 1830379bc100SJani Nikula HS_EXIT(exit_zero_cnt)); 1831379bc100SJani Nikula 1832379bc100SJani Nikula intel_dsi_log_params(intel_dsi); 1833379bc100SJani Nikula } 1834379bc100SJani Nikula 1835f384e48dSVandita Kulkarni static void icl_dsi_add_properties(struct intel_connector *connector) 1836f384e48dSVandita Kulkarni { 1837f384e48dSVandita Kulkarni u32 allowed_scalers; 1838f384e48dSVandita Kulkarni 1839f384e48dSVandita Kulkarni allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | 1840f384e48dSVandita Kulkarni BIT(DRM_MODE_SCALE_FULLSCREEN) | 1841f384e48dSVandita Kulkarni BIT(DRM_MODE_SCALE_CENTER); 1842f384e48dSVandita Kulkarni 1843f384e48dSVandita Kulkarni drm_connector_attach_scaling_mode_property(&connector->base, 1844f384e48dSVandita Kulkarni allowed_scalers); 1845f384e48dSVandita Kulkarni 1846f384e48dSVandita Kulkarni connector->base.state->scaling_mode = DRM_MODE_SCALE_ASPECT; 1847f384e48dSVandita Kulkarni 184869654c63SDerek Basehore drm_connector_set_panel_orientation_with_quirk(&connector->base, 184969654c63SDerek Basehore intel_dsi_get_panel_orientation(connector), 1850f384e48dSVandita Kulkarni connector->panel.fixed_mode->hdisplay, 1851f384e48dSVandita Kulkarni connector->panel.fixed_mode->vdisplay); 1852f384e48dSVandita Kulkarni } 1853f384e48dSVandita Kulkarni 1854379bc100SJani Nikula void icl_dsi_init(struct drm_i915_private *dev_priv) 1855379bc100SJani Nikula { 1856379bc100SJani Nikula struct drm_device *dev = &dev_priv->drm; 1857379bc100SJani Nikula struct intel_dsi *intel_dsi; 1858379bc100SJani Nikula struct intel_encoder *encoder; 1859379bc100SJani Nikula struct intel_connector *intel_connector; 1860379bc100SJani Nikula struct drm_connector *connector; 1861379bc100SJani Nikula struct drm_display_mode *fixed_mode; 1862379bc100SJani Nikula enum port port; 1863379bc100SJani Nikula 1864379bc100SJani Nikula if (!intel_bios_is_dsi_present(dev_priv, &port)) 1865379bc100SJani Nikula return; 1866379bc100SJani Nikula 1867379bc100SJani Nikula intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL); 1868379bc100SJani Nikula if (!intel_dsi) 1869379bc100SJani Nikula return; 1870379bc100SJani Nikula 1871379bc100SJani Nikula intel_connector = intel_connector_alloc(); 1872379bc100SJani Nikula if (!intel_connector) { 1873379bc100SJani Nikula kfree(intel_dsi); 1874379bc100SJani Nikula return; 1875379bc100SJani Nikula } 1876379bc100SJani Nikula 1877379bc100SJani Nikula encoder = &intel_dsi->base; 1878379bc100SJani Nikula intel_dsi->attached_connector = intel_connector; 1879379bc100SJani Nikula connector = &intel_connector->base; 1880379bc100SJani Nikula 1881379bc100SJani Nikula /* register DSI encoder with DRM subsystem */ 1882379bc100SJani Nikula drm_encoder_init(dev, &encoder->base, &gen11_dsi_encoder_funcs, 1883379bc100SJani Nikula DRM_MODE_ENCODER_DSI, "DSI %c", port_name(port)); 1884379bc100SJani Nikula 1885379bc100SJani Nikula encoder->pre_pll_enable = gen11_dsi_pre_pll_enable; 1886379bc100SJani Nikula encoder->pre_enable = gen11_dsi_pre_enable; 188721fd23acSJani Nikula encoder->enable = gen11_dsi_enable; 1888379bc100SJani Nikula encoder->disable = gen11_dsi_disable; 1889773b4b54SVille Syrjälä encoder->post_disable = gen11_dsi_post_disable; 1890379bc100SJani Nikula encoder->port = port; 1891379bc100SJani Nikula encoder->get_config = gen11_dsi_get_config; 1892379bc100SJani Nikula encoder->update_pipe = intel_panel_update_backlight; 1893379bc100SJani Nikula encoder->compute_config = gen11_dsi_compute_config; 1894379bc100SJani Nikula encoder->get_hw_state = gen11_dsi_get_hw_state; 1895379bc100SJani Nikula encoder->type = INTEL_OUTPUT_DSI; 1896379bc100SJani Nikula encoder->cloneable = 0; 189734053ee1SVille Syrjälä encoder->pipe_mask = ~0; 1898379bc100SJani Nikula encoder->power_domain = POWER_DOMAIN_PORT_DSI; 1899379bc100SJani Nikula encoder->get_power_domains = gen11_dsi_get_power_domains; 1900379bc100SJani Nikula 1901379bc100SJani Nikula /* register DSI connector with DRM subsystem */ 1902379bc100SJani Nikula drm_connector_init(dev, connector, &gen11_dsi_connector_funcs, 1903379bc100SJani Nikula DRM_MODE_CONNECTOR_DSI); 1904379bc100SJani Nikula drm_connector_helper_add(connector, &gen11_dsi_connector_helper_funcs); 1905379bc100SJani Nikula connector->display_info.subpixel_order = SubPixelHorizontalRGB; 1906379bc100SJani Nikula connector->interlace_allowed = false; 1907379bc100SJani Nikula connector->doublescan_allowed = false; 1908379bc100SJani Nikula intel_connector->get_hw_state = intel_connector_get_hw_state; 1909379bc100SJani Nikula 1910379bc100SJani Nikula /* attach connector to encoder */ 1911379bc100SJani Nikula intel_connector_attach_encoder(intel_connector, encoder); 1912379bc100SJani Nikula 1913379bc100SJani Nikula mutex_lock(&dev->mode_config.mutex); 1914379bc100SJani Nikula fixed_mode = intel_panel_vbt_fixed_mode(intel_connector); 1915379bc100SJani Nikula mutex_unlock(&dev->mode_config.mutex); 1916379bc100SJani Nikula 1917379bc100SJani Nikula if (!fixed_mode) { 1918b5280cd0SWambui Karuga drm_err(&dev_priv->drm, "DSI fixed mode info missing\n"); 1919379bc100SJani Nikula goto err; 1920379bc100SJani Nikula } 1921379bc100SJani Nikula 1922379bc100SJani Nikula intel_panel_init(&intel_connector->panel, fixed_mode, NULL); 1923379bc100SJani Nikula intel_panel_setup_backlight(connector, INVALID_PIPE); 1924379bc100SJani Nikula 1925379bc100SJani Nikula if (dev_priv->vbt.dsi.config->dual_link) 1926379bc100SJani Nikula intel_dsi->ports = BIT(PORT_A) | BIT(PORT_B); 1927379bc100SJani Nikula else 1928379bc100SJani Nikula intel_dsi->ports = BIT(port); 1929379bc100SJani Nikula 1930379bc100SJani Nikula intel_dsi->dcs_backlight_ports = dev_priv->vbt.dsi.bl_ports; 1931379bc100SJani Nikula intel_dsi->dcs_cabc_ports = dev_priv->vbt.dsi.cabc_ports; 1932379bc100SJani Nikula 1933379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1934379bc100SJani Nikula struct intel_dsi_host *host; 1935379bc100SJani Nikula 1936379bc100SJani Nikula host = intel_dsi_host_init(intel_dsi, &gen11_dsi_host_ops, port); 1937379bc100SJani Nikula if (!host) 1938379bc100SJani Nikula goto err; 1939379bc100SJani Nikula 1940379bc100SJani Nikula intel_dsi->dsi_hosts[port] = host; 1941379bc100SJani Nikula } 1942379bc100SJani Nikula 1943379bc100SJani Nikula if (!intel_dsi_vbt_init(intel_dsi, MIPI_DSI_GENERIC_PANEL_ID)) { 1944b5280cd0SWambui Karuga drm_dbg_kms(&dev_priv->drm, "no device found\n"); 1945379bc100SJani Nikula goto err; 1946379bc100SJani Nikula } 1947379bc100SJani Nikula 1948379bc100SJani Nikula icl_dphy_param_init(intel_dsi); 1949f384e48dSVandita Kulkarni 1950f384e48dSVandita Kulkarni icl_dsi_add_properties(intel_connector); 1951379bc100SJani Nikula return; 1952379bc100SJani Nikula 1953379bc100SJani Nikula err: 1954379bc100SJani Nikula drm_encoder_cleanup(&encoder->base); 1955379bc100SJani Nikula kfree(intel_dsi); 1956379bc100SJani Nikula kfree(intel_connector); 1957379bc100SJani Nikula } 1958