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" 37379bc100SJani Nikula 38379bc100SJani Nikula static inline int header_credits_available(struct drm_i915_private *dev_priv, 39379bc100SJani Nikula enum transcoder dsi_trans) 40379bc100SJani Nikula { 41379bc100SJani Nikula return (I915_READ(DSI_CMD_TXCTL(dsi_trans)) & FREE_HEADER_CREDIT_MASK) 42379bc100SJani Nikula >> FREE_HEADER_CREDIT_SHIFT; 43379bc100SJani Nikula } 44379bc100SJani Nikula 45379bc100SJani Nikula static inline int payload_credits_available(struct drm_i915_private *dev_priv, 46379bc100SJani Nikula enum transcoder dsi_trans) 47379bc100SJani Nikula { 48379bc100SJani Nikula return (I915_READ(DSI_CMD_TXCTL(dsi_trans)) & FREE_PLOAD_CREDIT_MASK) 49379bc100SJani Nikula >> FREE_PLOAD_CREDIT_SHIFT; 50379bc100SJani Nikula } 51379bc100SJani Nikula 52379bc100SJani Nikula static void wait_for_header_credits(struct drm_i915_private *dev_priv, 53379bc100SJani Nikula enum transcoder dsi_trans) 54379bc100SJani Nikula { 55379bc100SJani Nikula if (wait_for_us(header_credits_available(dev_priv, dsi_trans) >= 56379bc100SJani Nikula MAX_HEADER_CREDIT, 100)) 57379bc100SJani Nikula DRM_ERROR("DSI header credits not released\n"); 58379bc100SJani Nikula } 59379bc100SJani Nikula 60379bc100SJani Nikula static void wait_for_payload_credits(struct drm_i915_private *dev_priv, 61379bc100SJani Nikula enum transcoder dsi_trans) 62379bc100SJani Nikula { 63379bc100SJani Nikula if (wait_for_us(payload_credits_available(dev_priv, dsi_trans) >= 64379bc100SJani Nikula MAX_PLOAD_CREDIT, 100)) 65379bc100SJani Nikula DRM_ERROR("DSI payload credits not released\n"); 66379bc100SJani Nikula } 67379bc100SJani Nikula 68379bc100SJani Nikula static enum transcoder dsi_port_to_transcoder(enum port port) 69379bc100SJani Nikula { 70379bc100SJani Nikula if (port == PORT_A) 71379bc100SJani Nikula return TRANSCODER_DSI_0; 72379bc100SJani Nikula else 73379bc100SJani Nikula return TRANSCODER_DSI_1; 74379bc100SJani Nikula } 75379bc100SJani Nikula 76379bc100SJani Nikula static void wait_for_cmds_dispatched_to_panel(struct intel_encoder *encoder) 77379bc100SJani Nikula { 78379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 79379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 80379bc100SJani Nikula struct mipi_dsi_device *dsi; 81379bc100SJani Nikula enum port port; 82379bc100SJani Nikula enum transcoder dsi_trans; 83379bc100SJani Nikula int ret; 84379bc100SJani Nikula 85379bc100SJani Nikula /* wait for header/payload credits to be released */ 86379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 87379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 88379bc100SJani Nikula wait_for_header_credits(dev_priv, dsi_trans); 89379bc100SJani Nikula wait_for_payload_credits(dev_priv, dsi_trans); 90379bc100SJani Nikula } 91379bc100SJani Nikula 92379bc100SJani Nikula /* send nop DCS command */ 93379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 94379bc100SJani Nikula dsi = intel_dsi->dsi_hosts[port]->device; 95379bc100SJani Nikula dsi->mode_flags |= MIPI_DSI_MODE_LPM; 96379bc100SJani Nikula dsi->channel = 0; 97379bc100SJani Nikula ret = mipi_dsi_dcs_nop(dsi); 98379bc100SJani Nikula if (ret < 0) 99379bc100SJani Nikula DRM_ERROR("error sending DCS NOP command\n"); 100379bc100SJani Nikula } 101379bc100SJani Nikula 102379bc100SJani Nikula /* wait for header credits to be released */ 103379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 104379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 105379bc100SJani Nikula wait_for_header_credits(dev_priv, dsi_trans); 106379bc100SJani Nikula } 107379bc100SJani Nikula 108379bc100SJani Nikula /* wait for LP TX in progress bit to be cleared */ 109379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 110379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 111379bc100SJani Nikula if (wait_for_us(!(I915_READ(DSI_LP_MSG(dsi_trans)) & 112379bc100SJani Nikula LPTX_IN_PROGRESS), 20)) 113379bc100SJani Nikula DRM_ERROR("LPTX bit not cleared\n"); 114379bc100SJani Nikula } 115379bc100SJani Nikula } 116379bc100SJani Nikula 117379bc100SJani Nikula static bool add_payld_to_queue(struct intel_dsi_host *host, const u8 *data, 118379bc100SJani Nikula u32 len) 119379bc100SJani Nikula { 120379bc100SJani Nikula struct intel_dsi *intel_dsi = host->intel_dsi; 121379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev); 122379bc100SJani Nikula enum transcoder dsi_trans = dsi_port_to_transcoder(host->port); 123379bc100SJani Nikula int free_credits; 124379bc100SJani Nikula int i, j; 125379bc100SJani Nikula 126379bc100SJani Nikula for (i = 0; i < len; i += 4) { 127379bc100SJani Nikula u32 tmp = 0; 128379bc100SJani Nikula 129379bc100SJani Nikula free_credits = payload_credits_available(dev_priv, dsi_trans); 130379bc100SJani Nikula if (free_credits < 1) { 131379bc100SJani Nikula DRM_ERROR("Payload credit not available\n"); 132379bc100SJani Nikula return false; 133379bc100SJani Nikula } 134379bc100SJani Nikula 135379bc100SJani Nikula for (j = 0; j < min_t(u32, len - i, 4); j++) 136379bc100SJani Nikula tmp |= *data++ << 8 * j; 137379bc100SJani Nikula 138379bc100SJani Nikula I915_WRITE(DSI_CMD_TXPYLD(dsi_trans), tmp); 139379bc100SJani Nikula } 140379bc100SJani Nikula 141379bc100SJani Nikula return true; 142379bc100SJani Nikula } 143379bc100SJani Nikula 144379bc100SJani Nikula static int dsi_send_pkt_hdr(struct intel_dsi_host *host, 145379bc100SJani Nikula struct mipi_dsi_packet pkt, bool enable_lpdt) 146379bc100SJani Nikula { 147379bc100SJani Nikula struct intel_dsi *intel_dsi = host->intel_dsi; 148379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev); 149379bc100SJani Nikula enum transcoder dsi_trans = dsi_port_to_transcoder(host->port); 150379bc100SJani Nikula u32 tmp; 151379bc100SJani Nikula int free_credits; 152379bc100SJani Nikula 153379bc100SJani Nikula /* check if header credit available */ 154379bc100SJani Nikula free_credits = header_credits_available(dev_priv, dsi_trans); 155379bc100SJani Nikula if (free_credits < 1) { 156379bc100SJani Nikula DRM_ERROR("send pkt header failed, not enough hdr credits\n"); 157379bc100SJani Nikula return -1; 158379bc100SJani Nikula } 159379bc100SJani Nikula 160379bc100SJani Nikula tmp = I915_READ(DSI_CMD_TXHDR(dsi_trans)); 161379bc100SJani Nikula 162379bc100SJani Nikula if (pkt.payload) 163379bc100SJani Nikula tmp |= PAYLOAD_PRESENT; 164379bc100SJani Nikula else 165379bc100SJani Nikula tmp &= ~PAYLOAD_PRESENT; 166379bc100SJani Nikula 167379bc100SJani Nikula tmp &= ~VBLANK_FENCE; 168379bc100SJani Nikula 169379bc100SJani Nikula if (enable_lpdt) 170379bc100SJani Nikula tmp |= LP_DATA_TRANSFER; 171379bc100SJani Nikula 172379bc100SJani Nikula tmp &= ~(PARAM_WC_MASK | VC_MASK | DT_MASK); 173379bc100SJani Nikula tmp |= ((pkt.header[0] & VC_MASK) << VC_SHIFT); 174379bc100SJani Nikula tmp |= ((pkt.header[0] & DT_MASK) << DT_SHIFT); 175379bc100SJani Nikula tmp |= (pkt.header[1] << PARAM_WC_LOWER_SHIFT); 176379bc100SJani Nikula tmp |= (pkt.header[2] << PARAM_WC_UPPER_SHIFT); 177379bc100SJani Nikula I915_WRITE(DSI_CMD_TXHDR(dsi_trans), tmp); 178379bc100SJani Nikula 179379bc100SJani Nikula return 0; 180379bc100SJani Nikula } 181379bc100SJani Nikula 182379bc100SJani Nikula static int dsi_send_pkt_payld(struct intel_dsi_host *host, 183379bc100SJani Nikula struct mipi_dsi_packet pkt) 184379bc100SJani Nikula { 185379bc100SJani Nikula /* payload queue can accept *256 bytes*, check limit */ 186379bc100SJani Nikula if (pkt.payload_length > MAX_PLOAD_CREDIT * 4) { 187379bc100SJani Nikula DRM_ERROR("payload size exceeds max queue limit\n"); 188379bc100SJani Nikula return -1; 189379bc100SJani Nikula } 190379bc100SJani Nikula 191379bc100SJani Nikula /* load data into command payload queue */ 192379bc100SJani Nikula if (!add_payld_to_queue(host, pkt.payload, 193379bc100SJani Nikula pkt.payload_length)) { 194379bc100SJani Nikula DRM_ERROR("adding payload to queue failed\n"); 195379bc100SJani Nikula return -1; 196379bc100SJani Nikula } 197379bc100SJani Nikula 198379bc100SJani Nikula return 0; 199379bc100SJani Nikula } 200379bc100SJani Nikula 201379bc100SJani Nikula static void dsi_program_swing_and_deemphasis(struct intel_encoder *encoder) 202379bc100SJani Nikula { 203379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 204379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 205dc867bc7SMatt Roper enum phy phy; 206379bc100SJani Nikula u32 tmp; 207379bc100SJani Nikula int lane; 208379bc100SJani Nikula 209dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 210379bc100SJani Nikula /* 211379bc100SJani Nikula * Program voltage swing and pre-emphasis level values as per 212379bc100SJani Nikula * table in BSPEC under DDI buffer programing 213379bc100SJani Nikula */ 214dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_TX_DW5_LN0(phy)); 215379bc100SJani Nikula tmp &= ~(SCALING_MODE_SEL_MASK | RTERM_SELECT_MASK); 216379bc100SJani Nikula tmp |= SCALING_MODE_SEL(0x2); 217379bc100SJani Nikula tmp |= TAP2_DISABLE | TAP3_DISABLE; 218379bc100SJani Nikula tmp |= RTERM_SELECT(0x6); 219dc867bc7SMatt Roper I915_WRITE(ICL_PORT_TX_DW5_GRP(phy), tmp); 220379bc100SJani Nikula 221dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_TX_DW5_AUX(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); 226dc867bc7SMatt Roper I915_WRITE(ICL_PORT_TX_DW5_AUX(phy), tmp); 227379bc100SJani Nikula 228dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_TX_DW2_LN0(phy)); 229379bc100SJani Nikula tmp &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK | 230379bc100SJani Nikula RCOMP_SCALAR_MASK); 231379bc100SJani Nikula tmp |= SWING_SEL_UPPER(0x2); 232379bc100SJani Nikula tmp |= SWING_SEL_LOWER(0x2); 233379bc100SJani Nikula tmp |= RCOMP_SCALAR(0x98); 234dc867bc7SMatt Roper I915_WRITE(ICL_PORT_TX_DW2_GRP(phy), tmp); 235379bc100SJani Nikula 236dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_TX_DW2_AUX(phy)); 237379bc100SJani Nikula tmp &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK | 238379bc100SJani Nikula RCOMP_SCALAR_MASK); 239379bc100SJani Nikula tmp |= SWING_SEL_UPPER(0x2); 240379bc100SJani Nikula tmp |= SWING_SEL_LOWER(0x2); 241379bc100SJani Nikula tmp |= RCOMP_SCALAR(0x98); 242dc867bc7SMatt Roper I915_WRITE(ICL_PORT_TX_DW2_AUX(phy), tmp); 243379bc100SJani Nikula 244dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_TX_DW4_AUX(phy)); 245379bc100SJani Nikula tmp &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK | 246379bc100SJani Nikula CURSOR_COEFF_MASK); 247379bc100SJani Nikula tmp |= POST_CURSOR_1(0x0); 248379bc100SJani Nikula tmp |= POST_CURSOR_2(0x0); 249379bc100SJani Nikula tmp |= CURSOR_COEFF(0x3f); 250dc867bc7SMatt Roper I915_WRITE(ICL_PORT_TX_DW4_AUX(phy), tmp); 251379bc100SJani Nikula 252379bc100SJani Nikula for (lane = 0; lane <= 3; lane++) { 253379bc100SJani Nikula /* Bspec: must not use GRP register for write */ 254dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_TX_DW4_LN(lane, phy)); 255379bc100SJani Nikula tmp &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK | 256379bc100SJani Nikula CURSOR_COEFF_MASK); 257379bc100SJani Nikula tmp |= POST_CURSOR_1(0x0); 258379bc100SJani Nikula tmp |= POST_CURSOR_2(0x0); 259379bc100SJani Nikula tmp |= CURSOR_COEFF(0x3f); 260dc867bc7SMatt Roper I915_WRITE(ICL_PORT_TX_DW4_LN(lane, phy), tmp); 261379bc100SJani Nikula } 262379bc100SJani Nikula } 263379bc100SJani Nikula } 264379bc100SJani Nikula 265379bc100SJani Nikula static void configure_dual_link_mode(struct intel_encoder *encoder, 266379bc100SJani Nikula const struct intel_crtc_state *pipe_config) 267379bc100SJani Nikula { 268379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 269379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 270379bc100SJani Nikula u32 dss_ctl1; 271379bc100SJani Nikula 272379bc100SJani Nikula dss_ctl1 = I915_READ(DSS_CTL1); 273379bc100SJani Nikula dss_ctl1 |= SPLITTER_ENABLE; 274379bc100SJani Nikula dss_ctl1 &= ~OVERLAP_PIXELS_MASK; 275379bc100SJani Nikula dss_ctl1 |= OVERLAP_PIXELS(intel_dsi->pixel_overlap); 276379bc100SJani Nikula 277379bc100SJani Nikula if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) { 278379bc100SJani Nikula const struct drm_display_mode *adjusted_mode = 279379bc100SJani Nikula &pipe_config->base.adjusted_mode; 280379bc100SJani Nikula u32 dss_ctl2; 281379bc100SJani Nikula u16 hactive = adjusted_mode->crtc_hdisplay; 282379bc100SJani Nikula u16 dl_buffer_depth; 283379bc100SJani Nikula 284379bc100SJani Nikula dss_ctl1 &= ~DUAL_LINK_MODE_INTERLEAVE; 285379bc100SJani Nikula dl_buffer_depth = hactive / 2 + intel_dsi->pixel_overlap; 286379bc100SJani Nikula 287379bc100SJani Nikula if (dl_buffer_depth > MAX_DL_BUFFER_TARGET_DEPTH) 288379bc100SJani Nikula DRM_ERROR("DL buffer depth exceed max value\n"); 289379bc100SJani Nikula 290379bc100SJani Nikula dss_ctl1 &= ~LEFT_DL_BUF_TARGET_DEPTH_MASK; 291379bc100SJani Nikula dss_ctl1 |= LEFT_DL_BUF_TARGET_DEPTH(dl_buffer_depth); 292379bc100SJani Nikula dss_ctl2 = I915_READ(DSS_CTL2); 293379bc100SJani Nikula dss_ctl2 &= ~RIGHT_DL_BUF_TARGET_DEPTH_MASK; 294379bc100SJani Nikula dss_ctl2 |= RIGHT_DL_BUF_TARGET_DEPTH(dl_buffer_depth); 295379bc100SJani Nikula I915_WRITE(DSS_CTL2, dss_ctl2); 296379bc100SJani Nikula } else { 297379bc100SJani Nikula /* Interleave */ 298379bc100SJani Nikula dss_ctl1 |= DUAL_LINK_MODE_INTERLEAVE; 299379bc100SJani Nikula } 300379bc100SJani Nikula 301379bc100SJani Nikula I915_WRITE(DSS_CTL1, dss_ctl1); 302379bc100SJani Nikula } 303379bc100SJani Nikula 304379bc100SJani Nikula static void gen11_dsi_program_esc_clk_div(struct intel_encoder *encoder) 305379bc100SJani Nikula { 306379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 307379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 308379bc100SJani Nikula enum port port; 309379bc100SJani Nikula u32 bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); 310379bc100SJani Nikula u32 afe_clk_khz; /* 8X Clock */ 311379bc100SJani Nikula u32 esc_clk_div_m; 312379bc100SJani Nikula 313379bc100SJani Nikula afe_clk_khz = DIV_ROUND_CLOSEST(intel_dsi->pclk * bpp, 314379bc100SJani Nikula intel_dsi->lane_count); 315379bc100SJani Nikula 316379bc100SJani Nikula esc_clk_div_m = DIV_ROUND_UP(afe_clk_khz, DSI_MAX_ESC_CLK); 317379bc100SJani Nikula 318379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 319379bc100SJani Nikula I915_WRITE(ICL_DSI_ESC_CLK_DIV(port), 320379bc100SJani Nikula esc_clk_div_m & ICL_ESC_CLK_DIV_MASK); 321379bc100SJani Nikula POSTING_READ(ICL_DSI_ESC_CLK_DIV(port)); 322379bc100SJani Nikula } 323379bc100SJani Nikula 324379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 325379bc100SJani Nikula I915_WRITE(ICL_DPHY_ESC_CLK_DIV(port), 326379bc100SJani Nikula esc_clk_div_m & ICL_ESC_CLK_DIV_MASK); 327379bc100SJani Nikula POSTING_READ(ICL_DPHY_ESC_CLK_DIV(port)); 328379bc100SJani Nikula } 329379bc100SJani Nikula } 330379bc100SJani Nikula 331379bc100SJani Nikula static void get_dsi_io_power_domains(struct drm_i915_private *dev_priv, 332379bc100SJani Nikula struct intel_dsi *intel_dsi) 333379bc100SJani Nikula { 334379bc100SJani Nikula enum port port; 335379bc100SJani Nikula 336379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 337379bc100SJani Nikula WARN_ON(intel_dsi->io_wakeref[port]); 338379bc100SJani Nikula intel_dsi->io_wakeref[port] = 339379bc100SJani Nikula intel_display_power_get(dev_priv, 340379bc100SJani Nikula port == PORT_A ? 341379bc100SJani Nikula POWER_DOMAIN_PORT_DDI_A_IO : 342379bc100SJani Nikula POWER_DOMAIN_PORT_DDI_B_IO); 343379bc100SJani Nikula } 344379bc100SJani Nikula } 345379bc100SJani Nikula 346379bc100SJani Nikula static void gen11_dsi_enable_io_power(struct intel_encoder *encoder) 347379bc100SJani Nikula { 348379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 349379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 350379bc100SJani Nikula enum port port; 351379bc100SJani Nikula u32 tmp; 352379bc100SJani Nikula 353379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 354379bc100SJani Nikula tmp = I915_READ(ICL_DSI_IO_MODECTL(port)); 355379bc100SJani Nikula tmp |= COMBO_PHY_MODE_DSI; 356379bc100SJani Nikula I915_WRITE(ICL_DSI_IO_MODECTL(port), tmp); 357379bc100SJani Nikula } 358379bc100SJani Nikula 359379bc100SJani Nikula get_dsi_io_power_domains(dev_priv, intel_dsi); 360379bc100SJani Nikula } 361379bc100SJani Nikula 362379bc100SJani Nikula static void gen11_dsi_power_up_lanes(struct intel_encoder *encoder) 363379bc100SJani Nikula { 364379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 365379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 366dc867bc7SMatt Roper enum phy phy; 367379bc100SJani Nikula 368dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) 369dc867bc7SMatt Roper intel_combo_phy_power_up_lanes(dev_priv, phy, true, 370379bc100SJani Nikula intel_dsi->lane_count, false); 371379bc100SJani Nikula } 372379bc100SJani Nikula 373379bc100SJani Nikula static void gen11_dsi_config_phy_lanes_sequence(struct intel_encoder *encoder) 374379bc100SJani Nikula { 375379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 376379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 377dc867bc7SMatt Roper enum phy phy; 378379bc100SJani Nikula u32 tmp; 379379bc100SJani Nikula int lane; 380379bc100SJani Nikula 381379bc100SJani Nikula /* Step 4b(i) set loadgen select for transmit and aux lanes */ 382dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 383dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_TX_DW4_AUX(phy)); 384379bc100SJani Nikula tmp &= ~LOADGEN_SELECT; 385dc867bc7SMatt Roper I915_WRITE(ICL_PORT_TX_DW4_AUX(phy), tmp); 386379bc100SJani Nikula for (lane = 0; lane <= 3; lane++) { 387dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_TX_DW4_LN(lane, phy)); 388379bc100SJani Nikula tmp &= ~LOADGEN_SELECT; 389379bc100SJani Nikula if (lane != 2) 390379bc100SJani Nikula tmp |= LOADGEN_SELECT; 391dc867bc7SMatt Roper I915_WRITE(ICL_PORT_TX_DW4_LN(lane, phy), tmp); 392379bc100SJani Nikula } 393379bc100SJani Nikula } 394379bc100SJani Nikula 395379bc100SJani Nikula /* Step 4b(ii) set latency optimization for transmit and aux lanes */ 396dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 397dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_TX_DW2_AUX(phy)); 398379bc100SJani Nikula tmp &= ~FRC_LATENCY_OPTIM_MASK; 399379bc100SJani Nikula tmp |= FRC_LATENCY_OPTIM_VAL(0x5); 400dc867bc7SMatt Roper I915_WRITE(ICL_PORT_TX_DW2_AUX(phy), tmp); 401dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_TX_DW2_LN0(phy)); 402379bc100SJani Nikula tmp &= ~FRC_LATENCY_OPTIM_MASK; 403379bc100SJani Nikula tmp |= FRC_LATENCY_OPTIM_VAL(0x5); 404dc867bc7SMatt Roper I915_WRITE(ICL_PORT_TX_DW2_GRP(phy), tmp); 4056a7bafe8SVandita Kulkarni 406960e9836SVandita Kulkarni /* For EHL, TGL, set latency optimization for PCS_DW1 lanes */ 407960e9836SVandita Kulkarni if (IS_ELKHARTLAKE(dev_priv) || (INTEL_GEN(dev_priv) >= 12)) { 408dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_PCS_DW1_AUX(phy)); 4096a7bafe8SVandita Kulkarni tmp &= ~LATENCY_OPTIM_MASK; 4106a7bafe8SVandita Kulkarni tmp |= LATENCY_OPTIM_VAL(0); 411dc867bc7SMatt Roper I915_WRITE(ICL_PORT_PCS_DW1_AUX(phy), tmp); 4126a7bafe8SVandita Kulkarni 413dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_PCS_DW1_LN0(phy)); 4146a7bafe8SVandita Kulkarni tmp &= ~LATENCY_OPTIM_MASK; 4156a7bafe8SVandita Kulkarni tmp |= LATENCY_OPTIM_VAL(0x1); 416dc867bc7SMatt Roper I915_WRITE(ICL_PORT_PCS_DW1_GRP(phy), tmp); 4176a7bafe8SVandita Kulkarni } 418379bc100SJani Nikula } 419379bc100SJani Nikula 420379bc100SJani Nikula } 421379bc100SJani Nikula 422379bc100SJani Nikula static void gen11_dsi_voltage_swing_program_seq(struct intel_encoder *encoder) 423379bc100SJani Nikula { 424379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 425379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 426379bc100SJani Nikula u32 tmp; 427dc867bc7SMatt Roper enum phy phy; 428379bc100SJani Nikula 429379bc100SJani Nikula /* clear common keeper enable bit */ 430dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 431dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_PCS_DW1_LN0(phy)); 432379bc100SJani Nikula tmp &= ~COMMON_KEEPER_EN; 433dc867bc7SMatt Roper I915_WRITE(ICL_PORT_PCS_DW1_GRP(phy), tmp); 434dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_PCS_DW1_AUX(phy)); 435379bc100SJani Nikula tmp &= ~COMMON_KEEPER_EN; 436dc867bc7SMatt Roper I915_WRITE(ICL_PORT_PCS_DW1_AUX(phy), tmp); 437379bc100SJani Nikula } 438379bc100SJani Nikula 439379bc100SJani Nikula /* 440379bc100SJani Nikula * Set SUS Clock Config bitfield to 11b 441379bc100SJani Nikula * Note: loadgen select program is done 442379bc100SJani Nikula * as part of lane phy sequence configuration 443379bc100SJani Nikula */ 444dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 445dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_CL_DW5(phy)); 446379bc100SJani Nikula tmp |= SUS_CLOCK_CONFIG; 447dc867bc7SMatt Roper I915_WRITE(ICL_PORT_CL_DW5(phy), tmp); 448379bc100SJani Nikula } 449379bc100SJani Nikula 450379bc100SJani Nikula /* Clear training enable to change swing values */ 451dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 452dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_TX_DW5_LN0(phy)); 453379bc100SJani Nikula tmp &= ~TX_TRAINING_EN; 454dc867bc7SMatt Roper I915_WRITE(ICL_PORT_TX_DW5_GRP(phy), tmp); 455dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_TX_DW5_AUX(phy)); 456379bc100SJani Nikula tmp &= ~TX_TRAINING_EN; 457dc867bc7SMatt Roper I915_WRITE(ICL_PORT_TX_DW5_AUX(phy), tmp); 458379bc100SJani Nikula } 459379bc100SJani Nikula 460379bc100SJani Nikula /* Program swing and de-emphasis */ 461379bc100SJani Nikula dsi_program_swing_and_deemphasis(encoder); 462379bc100SJani Nikula 463379bc100SJani Nikula /* Set training enable to trigger update */ 464dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 465dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_TX_DW5_LN0(phy)); 466379bc100SJani Nikula tmp |= TX_TRAINING_EN; 467dc867bc7SMatt Roper I915_WRITE(ICL_PORT_TX_DW5_GRP(phy), tmp); 468dc867bc7SMatt Roper tmp = I915_READ(ICL_PORT_TX_DW5_AUX(phy)); 469379bc100SJani Nikula tmp |= TX_TRAINING_EN; 470dc867bc7SMatt Roper I915_WRITE(ICL_PORT_TX_DW5_AUX(phy), tmp); 471379bc100SJani Nikula } 472379bc100SJani Nikula } 473379bc100SJani Nikula 474379bc100SJani Nikula static void gen11_dsi_enable_ddi_buffer(struct intel_encoder *encoder) 475379bc100SJani Nikula { 476379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 477379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 478379bc100SJani Nikula u32 tmp; 479379bc100SJani Nikula enum port port; 480379bc100SJani Nikula 481379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 482379bc100SJani Nikula tmp = I915_READ(DDI_BUF_CTL(port)); 483379bc100SJani Nikula tmp |= DDI_BUF_CTL_ENABLE; 484379bc100SJani Nikula I915_WRITE(DDI_BUF_CTL(port), tmp); 485379bc100SJani Nikula 486379bc100SJani Nikula if (wait_for_us(!(I915_READ(DDI_BUF_CTL(port)) & 487379bc100SJani Nikula DDI_BUF_IS_IDLE), 488379bc100SJani Nikula 500)) 489379bc100SJani Nikula DRM_ERROR("DDI port:%c buffer idle\n", port_name(port)); 490379bc100SJani Nikula } 491379bc100SJani Nikula } 492379bc100SJani Nikula 493379bc100SJani Nikula static void gen11_dsi_setup_dphy_timings(struct intel_encoder *encoder) 494379bc100SJani Nikula { 495379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 496379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 497379bc100SJani Nikula u32 tmp; 498379bc100SJani Nikula enum port port; 499dc867bc7SMatt Roper enum phy phy; 500379bc100SJani Nikula 501379bc100SJani Nikula /* Program T-INIT master registers */ 502379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 503379bc100SJani Nikula tmp = I915_READ(ICL_DSI_T_INIT_MASTER(port)); 504379bc100SJani Nikula tmp &= ~MASTER_INIT_TIMER_MASK; 505379bc100SJani Nikula tmp |= intel_dsi->init_count; 506379bc100SJani Nikula I915_WRITE(ICL_DSI_T_INIT_MASTER(port), tmp); 507379bc100SJani Nikula } 508379bc100SJani Nikula 509379bc100SJani Nikula /* Program DPHY clock lanes timings */ 510379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 511379bc100SJani Nikula I915_WRITE(DPHY_CLK_TIMING_PARAM(port), intel_dsi->dphy_reg); 512379bc100SJani Nikula 513379bc100SJani Nikula /* shadow register inside display core */ 514379bc100SJani Nikula I915_WRITE(DSI_CLK_TIMING_PARAM(port), intel_dsi->dphy_reg); 515379bc100SJani Nikula } 516379bc100SJani Nikula 517379bc100SJani Nikula /* Program DPHY data lanes timings */ 518379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 519379bc100SJani Nikula I915_WRITE(DPHY_DATA_TIMING_PARAM(port), 520379bc100SJani Nikula intel_dsi->dphy_data_lane_reg); 521379bc100SJani Nikula 522379bc100SJani Nikula /* shadow register inside display core */ 523379bc100SJani Nikula I915_WRITE(DSI_DATA_TIMING_PARAM(port), 524379bc100SJani Nikula intel_dsi->dphy_data_lane_reg); 525379bc100SJani Nikula } 526379bc100SJani Nikula 527379bc100SJani Nikula /* 528379bc100SJani Nikula * If DSI link operating at or below an 800 MHz, 529379bc100SJani Nikula * TA_SURE should be override and programmed to 530379bc100SJani Nikula * a value '0' inside TA_PARAM_REGISTERS otherwise 531379bc100SJani Nikula * leave all fields at HW default values. 532379bc100SJani Nikula */ 5337b864f95SVandita Kulkarni if (IS_GEN(dev_priv, 11)) { 534379bc100SJani Nikula if (intel_dsi_bitrate(intel_dsi) <= 800000) { 535379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 536379bc100SJani Nikula tmp = I915_READ(DPHY_TA_TIMING_PARAM(port)); 537379bc100SJani Nikula tmp &= ~TA_SURE_MASK; 538379bc100SJani Nikula tmp |= TA_SURE_OVERRIDE | TA_SURE(0); 539379bc100SJani Nikula I915_WRITE(DPHY_TA_TIMING_PARAM(port), tmp); 540379bc100SJani Nikula 541379bc100SJani Nikula /* shadow register inside display core */ 542379bc100SJani Nikula tmp = I915_READ(DSI_TA_TIMING_PARAM(port)); 543379bc100SJani Nikula tmp &= ~TA_SURE_MASK; 544379bc100SJani Nikula tmp |= TA_SURE_OVERRIDE | TA_SURE(0); 545379bc100SJani Nikula I915_WRITE(DSI_TA_TIMING_PARAM(port), tmp); 546379bc100SJani Nikula } 547379bc100SJani Nikula } 5487b864f95SVandita Kulkarni } 549683d672cSJosé Roberto de Souza 550683d672cSJosé Roberto de Souza if (IS_ELKHARTLAKE(dev_priv)) { 551dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 552dc867bc7SMatt Roper tmp = I915_READ(ICL_DPHY_CHKN(phy)); 553683d672cSJosé Roberto de Souza tmp |= ICL_DPHY_CHKN_AFE_OVER_PPI_STRAP; 554dc867bc7SMatt Roper I915_WRITE(ICL_DPHY_CHKN(phy), tmp); 555683d672cSJosé Roberto de Souza } 556683d672cSJosé Roberto de Souza } 557379bc100SJani Nikula } 558379bc100SJani Nikula 559379bc100SJani Nikula static void gen11_dsi_gate_clocks(struct intel_encoder *encoder) 560379bc100SJani Nikula { 561379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 562379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 563379bc100SJani Nikula u32 tmp; 564befa372bSMatt Roper enum phy phy; 565379bc100SJani Nikula 566379bc100SJani Nikula mutex_lock(&dev_priv->dpll_lock); 567befa372bSMatt Roper tmp = I915_READ(ICL_DPCLKA_CFGCR0); 568dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) 569befa372bSMatt Roper tmp |= ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy); 570379bc100SJani Nikula 571befa372bSMatt Roper I915_WRITE(ICL_DPCLKA_CFGCR0, tmp); 572379bc100SJani Nikula mutex_unlock(&dev_priv->dpll_lock); 573379bc100SJani Nikula } 574379bc100SJani Nikula 575379bc100SJani Nikula static void gen11_dsi_ungate_clocks(struct intel_encoder *encoder) 576379bc100SJani Nikula { 577379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 578379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 579379bc100SJani Nikula u32 tmp; 580befa372bSMatt Roper enum phy phy; 581379bc100SJani Nikula 582379bc100SJani Nikula mutex_lock(&dev_priv->dpll_lock); 583befa372bSMatt Roper tmp = I915_READ(ICL_DPCLKA_CFGCR0); 584dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) 585befa372bSMatt Roper tmp &= ~ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy); 586379bc100SJani Nikula 587befa372bSMatt Roper I915_WRITE(ICL_DPCLKA_CFGCR0, tmp); 588379bc100SJani Nikula mutex_unlock(&dev_priv->dpll_lock); 589379bc100SJani Nikula } 590379bc100SJani Nikula 591379bc100SJani Nikula static void gen11_dsi_map_pll(struct intel_encoder *encoder, 592379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 593379bc100SJani Nikula { 594379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 595379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 596379bc100SJani Nikula struct intel_shared_dpll *pll = crtc_state->shared_dpll; 597befa372bSMatt Roper enum phy phy; 598379bc100SJani Nikula u32 val; 599379bc100SJani Nikula 600379bc100SJani Nikula mutex_lock(&dev_priv->dpll_lock); 601379bc100SJani Nikula 602befa372bSMatt Roper val = I915_READ(ICL_DPCLKA_CFGCR0); 603dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 604befa372bSMatt Roper val &= ~ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy); 605befa372bSMatt Roper val |= ICL_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy); 606379bc100SJani Nikula } 607befa372bSMatt Roper I915_WRITE(ICL_DPCLKA_CFGCR0, val); 608379bc100SJani Nikula 609dc867bc7SMatt Roper for_each_dsi_phy(phy, intel_dsi->phys) { 610991d9557SVandita Kulkarni if (INTEL_GEN(dev_priv) >= 12) 611991d9557SVandita Kulkarni val |= ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy); 612991d9557SVandita Kulkarni else 613befa372bSMatt Roper val &= ~ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy); 614379bc100SJani Nikula } 615befa372bSMatt Roper I915_WRITE(ICL_DPCLKA_CFGCR0, val); 616379bc100SJani Nikula 617befa372bSMatt Roper POSTING_READ(ICL_DPCLKA_CFGCR0); 618379bc100SJani Nikula 619379bc100SJani Nikula mutex_unlock(&dev_priv->dpll_lock); 620379bc100SJani Nikula } 621379bc100SJani Nikula 622379bc100SJani Nikula static void 623379bc100SJani Nikula gen11_dsi_configure_transcoder(struct intel_encoder *encoder, 624379bc100SJani Nikula const struct intel_crtc_state *pipe_config) 625379bc100SJani Nikula { 626379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 627379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 628379bc100SJani Nikula struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc); 629379bc100SJani Nikula enum pipe pipe = intel_crtc->pipe; 630379bc100SJani Nikula u32 tmp; 631379bc100SJani Nikula enum port port; 632379bc100SJani Nikula enum transcoder dsi_trans; 633379bc100SJani Nikula 634379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 635379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 636379bc100SJani Nikula tmp = I915_READ(DSI_TRANS_FUNC_CONF(dsi_trans)); 637379bc100SJani Nikula 638379bc100SJani Nikula if (intel_dsi->eotp_pkt) 639379bc100SJani Nikula tmp &= ~EOTP_DISABLED; 640379bc100SJani Nikula else 641379bc100SJani Nikula tmp |= EOTP_DISABLED; 642379bc100SJani Nikula 643379bc100SJani Nikula /* enable link calibration if freq > 1.5Gbps */ 644379bc100SJani Nikula if (intel_dsi_bitrate(intel_dsi) >= 1500 * 1000) { 645379bc100SJani Nikula tmp &= ~LINK_CALIBRATION_MASK; 646379bc100SJani Nikula tmp |= CALIBRATION_ENABLED_INITIAL_ONLY; 647379bc100SJani Nikula } 648379bc100SJani Nikula 649379bc100SJani Nikula /* configure continuous clock */ 650379bc100SJani Nikula tmp &= ~CONTINUOUS_CLK_MASK; 651379bc100SJani Nikula if (intel_dsi->clock_stop) 652379bc100SJani Nikula tmp |= CLK_ENTER_LP_AFTER_DATA; 653379bc100SJani Nikula else 654379bc100SJani Nikula tmp |= CLK_HS_CONTINUOUS; 655379bc100SJani Nikula 656379bc100SJani Nikula /* configure buffer threshold limit to minimum */ 657379bc100SJani Nikula tmp &= ~PIX_BUF_THRESHOLD_MASK; 658379bc100SJani Nikula tmp |= PIX_BUF_THRESHOLD_1_4; 659379bc100SJani Nikula 660379bc100SJani Nikula /* set virtual channel to '0' */ 661379bc100SJani Nikula tmp &= ~PIX_VIRT_CHAN_MASK; 662379bc100SJani Nikula tmp |= PIX_VIRT_CHAN(0); 663379bc100SJani Nikula 664379bc100SJani Nikula /* program BGR transmission */ 665379bc100SJani Nikula if (intel_dsi->bgr_enabled) 666379bc100SJani Nikula tmp |= BGR_TRANSMISSION; 667379bc100SJani Nikula 668379bc100SJani Nikula /* select pixel format */ 669379bc100SJani Nikula tmp &= ~PIX_FMT_MASK; 670379bc100SJani Nikula switch (intel_dsi->pixel_format) { 671379bc100SJani Nikula default: 672379bc100SJani Nikula MISSING_CASE(intel_dsi->pixel_format); 673379bc100SJani Nikula /* fallthrough */ 674379bc100SJani Nikula case MIPI_DSI_FMT_RGB565: 675379bc100SJani Nikula tmp |= PIX_FMT_RGB565; 676379bc100SJani Nikula break; 677379bc100SJani Nikula case MIPI_DSI_FMT_RGB666_PACKED: 678379bc100SJani Nikula tmp |= PIX_FMT_RGB666_PACKED; 679379bc100SJani Nikula break; 680379bc100SJani Nikula case MIPI_DSI_FMT_RGB666: 681379bc100SJani Nikula tmp |= PIX_FMT_RGB666_LOOSE; 682379bc100SJani Nikula break; 683379bc100SJani Nikula case MIPI_DSI_FMT_RGB888: 684379bc100SJani Nikula tmp |= PIX_FMT_RGB888; 685379bc100SJani Nikula break; 686379bc100SJani Nikula } 687379bc100SJani Nikula 68832d38e6cSVandita Kulkarni if (INTEL_GEN(dev_priv) >= 12) { 68932d38e6cSVandita Kulkarni if (is_vid_mode(intel_dsi)) 69032d38e6cSVandita Kulkarni tmp |= BLANKING_PACKET_ENABLE; 69132d38e6cSVandita Kulkarni } 69232d38e6cSVandita Kulkarni 693379bc100SJani Nikula /* program DSI operation mode */ 694379bc100SJani Nikula if (is_vid_mode(intel_dsi)) { 695379bc100SJani Nikula tmp &= ~OP_MODE_MASK; 696379bc100SJani Nikula switch (intel_dsi->video_mode_format) { 697379bc100SJani Nikula default: 698379bc100SJani Nikula MISSING_CASE(intel_dsi->video_mode_format); 699379bc100SJani Nikula /* fallthrough */ 700379bc100SJani Nikula case VIDEO_MODE_NON_BURST_WITH_SYNC_EVENTS: 701379bc100SJani Nikula tmp |= VIDEO_MODE_SYNC_EVENT; 702379bc100SJani Nikula break; 703379bc100SJani Nikula case VIDEO_MODE_NON_BURST_WITH_SYNC_PULSE: 704379bc100SJani Nikula tmp |= VIDEO_MODE_SYNC_PULSE; 705379bc100SJani Nikula break; 706379bc100SJani Nikula } 707379bc100SJani Nikula } 708379bc100SJani Nikula 709379bc100SJani Nikula I915_WRITE(DSI_TRANS_FUNC_CONF(dsi_trans), tmp); 710379bc100SJani Nikula } 711379bc100SJani Nikula 712379bc100SJani Nikula /* enable port sync mode if dual link */ 713379bc100SJani Nikula if (intel_dsi->dual_link) { 714379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 715379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 716379bc100SJani Nikula tmp = I915_READ(TRANS_DDI_FUNC_CTL2(dsi_trans)); 717379bc100SJani Nikula tmp |= PORT_SYNC_MODE_ENABLE; 718379bc100SJani Nikula I915_WRITE(TRANS_DDI_FUNC_CTL2(dsi_trans), tmp); 719379bc100SJani Nikula } 720379bc100SJani Nikula 721379bc100SJani Nikula /* configure stream splitting */ 722379bc100SJani Nikula configure_dual_link_mode(encoder, pipe_config); 723379bc100SJani Nikula } 724379bc100SJani Nikula 725379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 726379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 727379bc100SJani Nikula 728379bc100SJani Nikula /* select data lane width */ 729379bc100SJani Nikula tmp = I915_READ(TRANS_DDI_FUNC_CTL(dsi_trans)); 730379bc100SJani Nikula tmp &= ~DDI_PORT_WIDTH_MASK; 731379bc100SJani Nikula tmp |= DDI_PORT_WIDTH(intel_dsi->lane_count); 732379bc100SJani Nikula 733379bc100SJani Nikula /* select input pipe */ 734379bc100SJani Nikula tmp &= ~TRANS_DDI_EDP_INPUT_MASK; 735379bc100SJani Nikula switch (pipe) { 736379bc100SJani Nikula default: 737379bc100SJani Nikula MISSING_CASE(pipe); 738379bc100SJani Nikula /* fallthrough */ 739379bc100SJani Nikula case PIPE_A: 740379bc100SJani Nikula tmp |= TRANS_DDI_EDP_INPUT_A_ON; 741379bc100SJani Nikula break; 742379bc100SJani Nikula case PIPE_B: 743379bc100SJani Nikula tmp |= TRANS_DDI_EDP_INPUT_B_ONOFF; 744379bc100SJani Nikula break; 745379bc100SJani Nikula case PIPE_C: 746379bc100SJani Nikula tmp |= TRANS_DDI_EDP_INPUT_C_ONOFF; 747379bc100SJani Nikula break; 748379bc100SJani Nikula } 749379bc100SJani Nikula 750379bc100SJani Nikula /* enable DDI buffer */ 751379bc100SJani Nikula tmp |= TRANS_DDI_FUNC_ENABLE; 752379bc100SJani Nikula I915_WRITE(TRANS_DDI_FUNC_CTL(dsi_trans), tmp); 753379bc100SJani Nikula } 754379bc100SJani Nikula 755379bc100SJani Nikula /* wait for link ready */ 756379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 757379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 758379bc100SJani Nikula if (wait_for_us((I915_READ(DSI_TRANS_FUNC_CONF(dsi_trans)) & 759379bc100SJani Nikula LINK_READY), 2500)) 760379bc100SJani Nikula DRM_ERROR("DSI link not ready\n"); 761379bc100SJani Nikula } 762379bc100SJani Nikula } 763379bc100SJani Nikula 764379bc100SJani Nikula static void 765379bc100SJani Nikula gen11_dsi_set_transcoder_timings(struct intel_encoder *encoder, 766379bc100SJani Nikula const struct intel_crtc_state *pipe_config) 767379bc100SJani Nikula { 768379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 769379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 770379bc100SJani Nikula const struct drm_display_mode *adjusted_mode = 771379bc100SJani Nikula &pipe_config->base.adjusted_mode; 772379bc100SJani Nikula enum port port; 773379bc100SJani Nikula enum transcoder dsi_trans; 774379bc100SJani Nikula /* horizontal timings */ 775379bc100SJani Nikula u16 htotal, hactive, hsync_start, hsync_end, hsync_size; 7760cc35a9cSYueHaibing u16 hback_porch; 777379bc100SJani Nikula /* vertical timings */ 778379bc100SJani Nikula u16 vtotal, vactive, vsync_start, vsync_end, vsync_shift; 779379bc100SJani Nikula 780379bc100SJani Nikula hactive = adjusted_mode->crtc_hdisplay; 781379bc100SJani Nikula htotal = adjusted_mode->crtc_htotal; 782379bc100SJani Nikula hsync_start = adjusted_mode->crtc_hsync_start; 783379bc100SJani Nikula hsync_end = adjusted_mode->crtc_hsync_end; 784379bc100SJani Nikula hsync_size = hsync_end - hsync_start; 785379bc100SJani Nikula hback_porch = (adjusted_mode->crtc_htotal - 786379bc100SJani Nikula adjusted_mode->crtc_hsync_end); 787379bc100SJani Nikula vactive = adjusted_mode->crtc_vdisplay; 788379bc100SJani Nikula vtotal = adjusted_mode->crtc_vtotal; 789379bc100SJani Nikula vsync_start = adjusted_mode->crtc_vsync_start; 790379bc100SJani Nikula vsync_end = adjusted_mode->crtc_vsync_end; 791379bc100SJani Nikula vsync_shift = hsync_start - htotal / 2; 792379bc100SJani Nikula 793379bc100SJani Nikula if (intel_dsi->dual_link) { 794379bc100SJani Nikula hactive /= 2; 795379bc100SJani Nikula if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) 796379bc100SJani Nikula hactive += intel_dsi->pixel_overlap; 797379bc100SJani Nikula htotal /= 2; 798379bc100SJani Nikula } 799379bc100SJani Nikula 800379bc100SJani Nikula /* minimum hactive as per bspec: 256 pixels */ 801379bc100SJani Nikula if (adjusted_mode->crtc_hdisplay < 256) 802379bc100SJani Nikula DRM_ERROR("hactive is less then 256 pixels\n"); 803379bc100SJani Nikula 804379bc100SJani Nikula /* if RGB666 format, then hactive must be multiple of 4 pixels */ 805379bc100SJani Nikula if (intel_dsi->pixel_format == MIPI_DSI_FMT_RGB666 && hactive % 4 != 0) 806379bc100SJani Nikula DRM_ERROR("hactive pixels are not multiple of 4\n"); 807379bc100SJani Nikula 808379bc100SJani Nikula /* program TRANS_HTOTAL register */ 809379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 810379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 811379bc100SJani Nikula I915_WRITE(HTOTAL(dsi_trans), 812379bc100SJani Nikula (hactive - 1) | ((htotal - 1) << 16)); 813379bc100SJani Nikula } 814379bc100SJani Nikula 815379bc100SJani Nikula /* TRANS_HSYNC register to be programmed only for video mode */ 816379bc100SJani Nikula if (intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE) { 817379bc100SJani Nikula if (intel_dsi->video_mode_format == 818379bc100SJani Nikula VIDEO_MODE_NON_BURST_WITH_SYNC_PULSE) { 819379bc100SJani Nikula /* BSPEC: hsync size should be atleast 16 pixels */ 820379bc100SJani Nikula if (hsync_size < 16) 821379bc100SJani Nikula DRM_ERROR("hsync size < 16 pixels\n"); 822379bc100SJani Nikula } 823379bc100SJani Nikula 824379bc100SJani Nikula if (hback_porch < 16) 825379bc100SJani Nikula DRM_ERROR("hback porch < 16 pixels\n"); 826379bc100SJani Nikula 827379bc100SJani Nikula if (intel_dsi->dual_link) { 828379bc100SJani Nikula hsync_start /= 2; 829379bc100SJani Nikula hsync_end /= 2; 830379bc100SJani Nikula } 831379bc100SJani Nikula 832379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 833379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 834379bc100SJani Nikula I915_WRITE(HSYNC(dsi_trans), 835379bc100SJani Nikula (hsync_start - 1) | ((hsync_end - 1) << 16)); 836379bc100SJani Nikula } 837379bc100SJani Nikula } 838379bc100SJani Nikula 839379bc100SJani Nikula /* program TRANS_VTOTAL register */ 840379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 841379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 842379bc100SJani Nikula /* 843379bc100SJani Nikula * FIXME: Programing this by assuming progressive mode, since 844379bc100SJani Nikula * non-interlaced info from VBT is not saved inside 845379bc100SJani Nikula * struct drm_display_mode. 846379bc100SJani Nikula * For interlace mode: program required pixel minus 2 847379bc100SJani Nikula */ 848379bc100SJani Nikula I915_WRITE(VTOTAL(dsi_trans), 849379bc100SJani Nikula (vactive - 1) | ((vtotal - 1) << 16)); 850379bc100SJani Nikula } 851379bc100SJani Nikula 852379bc100SJani Nikula if (vsync_end < vsync_start || vsync_end > vtotal) 853379bc100SJani Nikula DRM_ERROR("Invalid vsync_end value\n"); 854379bc100SJani Nikula 855379bc100SJani Nikula if (vsync_start < vactive) 856379bc100SJani Nikula DRM_ERROR("vsync_start less than vactive\n"); 857379bc100SJani Nikula 858379bc100SJani Nikula /* program TRANS_VSYNC register */ 859379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 860379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 861379bc100SJani Nikula I915_WRITE(VSYNC(dsi_trans), 862379bc100SJani Nikula (vsync_start - 1) | ((vsync_end - 1) << 16)); 863379bc100SJani Nikula } 864379bc100SJani Nikula 865379bc100SJani Nikula /* 866379bc100SJani Nikula * FIXME: It has to be programmed only for interlaced 867379bc100SJani Nikula * modes. Put the check condition here once interlaced 868379bc100SJani Nikula * info available as described above. 869379bc100SJani Nikula * program TRANS_VSYNCSHIFT register 870379bc100SJani Nikula */ 871379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 872379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 873379bc100SJani Nikula I915_WRITE(VSYNCSHIFT(dsi_trans), vsync_shift); 874379bc100SJani Nikula } 8753522a33aSVandita Kulkarni 8763522a33aSVandita Kulkarni /* program TRANS_VBLANK register, should be same as vtotal programmed */ 8773522a33aSVandita Kulkarni if (INTEL_GEN(dev_priv) >= 12) { 8783522a33aSVandita Kulkarni for_each_dsi_port(port, intel_dsi->ports) { 8793522a33aSVandita Kulkarni dsi_trans = dsi_port_to_transcoder(port); 8803522a33aSVandita Kulkarni I915_WRITE(VBLANK(dsi_trans), 8813522a33aSVandita Kulkarni (vactive - 1) | ((vtotal - 1) << 16)); 8823522a33aSVandita Kulkarni } 8833522a33aSVandita Kulkarni } 884379bc100SJani Nikula } 885379bc100SJani Nikula 886379bc100SJani Nikula static void gen11_dsi_enable_transcoder(struct intel_encoder *encoder) 887379bc100SJani Nikula { 888379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 889379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 890379bc100SJani Nikula enum port port; 891379bc100SJani Nikula enum transcoder dsi_trans; 892379bc100SJani Nikula u32 tmp; 893379bc100SJani Nikula 894379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 895379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 896379bc100SJani Nikula tmp = I915_READ(PIPECONF(dsi_trans)); 897379bc100SJani Nikula tmp |= PIPECONF_ENABLE; 898379bc100SJani Nikula I915_WRITE(PIPECONF(dsi_trans), tmp); 899379bc100SJani Nikula 900379bc100SJani Nikula /* wait for transcoder to be enabled */ 901*4cb3b44dSDaniele Ceraolo Spurio if (intel_de_wait_for_set(dev_priv, PIPECONF(dsi_trans), 902379bc100SJani Nikula I965_PIPECONF_ACTIVE, 10)) 903379bc100SJani Nikula DRM_ERROR("DSI transcoder not enabled\n"); 904379bc100SJani Nikula } 905379bc100SJani Nikula } 906379bc100SJani Nikula 907379bc100SJani Nikula static void gen11_dsi_setup_timeouts(struct intel_encoder *encoder) 908379bc100SJani Nikula { 909379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 910379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 911379bc100SJani Nikula enum port port; 912379bc100SJani Nikula enum transcoder dsi_trans; 913379bc100SJani Nikula u32 tmp, hs_tx_timeout, lp_rx_timeout, ta_timeout, divisor, mul; 914379bc100SJani Nikula 915379bc100SJani Nikula /* 916379bc100SJani Nikula * escape clock count calculation: 917379bc100SJani Nikula * BYTE_CLK_COUNT = TIME_NS/(8 * UI) 918379bc100SJani Nikula * UI (nsec) = (10^6)/Bitrate 919379bc100SJani Nikula * TIME_NS = (BYTE_CLK_COUNT * 8 * 10^6)/ Bitrate 920379bc100SJani Nikula * ESCAPE_CLK_COUNT = TIME_NS/ESC_CLK_NS 921379bc100SJani Nikula */ 922379bc100SJani Nikula divisor = intel_dsi_tlpx_ns(intel_dsi) * intel_dsi_bitrate(intel_dsi) * 1000; 923379bc100SJani Nikula mul = 8 * 1000000; 924379bc100SJani Nikula hs_tx_timeout = DIV_ROUND_UP(intel_dsi->hs_tx_timeout * mul, 925379bc100SJani Nikula divisor); 926379bc100SJani Nikula lp_rx_timeout = DIV_ROUND_UP(intel_dsi->lp_rx_timeout * mul, divisor); 927379bc100SJani Nikula ta_timeout = DIV_ROUND_UP(intel_dsi->turn_arnd_val * mul, divisor); 928379bc100SJani Nikula 929379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 930379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 931379bc100SJani Nikula 932379bc100SJani Nikula /* program hst_tx_timeout */ 933379bc100SJani Nikula tmp = I915_READ(DSI_HSTX_TO(dsi_trans)); 934379bc100SJani Nikula tmp &= ~HSTX_TIMEOUT_VALUE_MASK; 935379bc100SJani Nikula tmp |= HSTX_TIMEOUT_VALUE(hs_tx_timeout); 936379bc100SJani Nikula I915_WRITE(DSI_HSTX_TO(dsi_trans), tmp); 937379bc100SJani Nikula 938379bc100SJani Nikula /* FIXME: DSI_CALIB_TO */ 939379bc100SJani Nikula 940379bc100SJani Nikula /* program lp_rx_host timeout */ 941379bc100SJani Nikula tmp = I915_READ(DSI_LPRX_HOST_TO(dsi_trans)); 942379bc100SJani Nikula tmp &= ~LPRX_TIMEOUT_VALUE_MASK; 943379bc100SJani Nikula tmp |= LPRX_TIMEOUT_VALUE(lp_rx_timeout); 944379bc100SJani Nikula I915_WRITE(DSI_LPRX_HOST_TO(dsi_trans), tmp); 945379bc100SJani Nikula 946379bc100SJani Nikula /* FIXME: DSI_PWAIT_TO */ 947379bc100SJani Nikula 948379bc100SJani Nikula /* program turn around timeout */ 949379bc100SJani Nikula tmp = I915_READ(DSI_TA_TO(dsi_trans)); 950379bc100SJani Nikula tmp &= ~TA_TIMEOUT_VALUE_MASK; 951379bc100SJani Nikula tmp |= TA_TIMEOUT_VALUE(ta_timeout); 952379bc100SJani Nikula I915_WRITE(DSI_TA_TO(dsi_trans), tmp); 953379bc100SJani Nikula } 954379bc100SJani Nikula } 955379bc100SJani Nikula 956379bc100SJani Nikula static void 957379bc100SJani Nikula gen11_dsi_enable_port_and_phy(struct intel_encoder *encoder, 958379bc100SJani Nikula const struct intel_crtc_state *pipe_config) 959379bc100SJani Nikula { 960991d9557SVandita Kulkarni struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 961991d9557SVandita Kulkarni 962379bc100SJani Nikula /* step 4a: power up all lanes of the DDI used by DSI */ 963379bc100SJani Nikula gen11_dsi_power_up_lanes(encoder); 964379bc100SJani Nikula 965379bc100SJani Nikula /* step 4b: configure lane sequencing of the Combo-PHY transmitters */ 966379bc100SJani Nikula gen11_dsi_config_phy_lanes_sequence(encoder); 967379bc100SJani Nikula 968379bc100SJani Nikula /* step 4c: configure voltage swing and skew */ 969379bc100SJani Nikula gen11_dsi_voltage_swing_program_seq(encoder); 970379bc100SJani Nikula 971379bc100SJani Nikula /* enable DDI buffer */ 972379bc100SJani Nikula gen11_dsi_enable_ddi_buffer(encoder); 973379bc100SJani Nikula 974379bc100SJani Nikula /* setup D-PHY timings */ 975379bc100SJani Nikula gen11_dsi_setup_dphy_timings(encoder); 976379bc100SJani Nikula 977379bc100SJani Nikula /* step 4h: setup DSI protocol timeouts */ 978379bc100SJani Nikula gen11_dsi_setup_timeouts(encoder); 979379bc100SJani Nikula 980379bc100SJani Nikula /* Step (4h, 4i, 4j, 4k): Configure transcoder */ 981379bc100SJani Nikula gen11_dsi_configure_transcoder(encoder, pipe_config); 982379bc100SJani Nikula 983379bc100SJani Nikula /* Step 4l: Gate DDI clocks */ 984991d9557SVandita Kulkarni if (IS_GEN(dev_priv, 11)) 985379bc100SJani Nikula gen11_dsi_gate_clocks(encoder); 986379bc100SJani Nikula } 987379bc100SJani Nikula 988379bc100SJani Nikula static void gen11_dsi_powerup_panel(struct intel_encoder *encoder) 989379bc100SJani Nikula { 990379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 991379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 992379bc100SJani Nikula struct mipi_dsi_device *dsi; 993379bc100SJani Nikula enum port port; 994379bc100SJani Nikula enum transcoder dsi_trans; 995379bc100SJani Nikula u32 tmp; 996379bc100SJani Nikula int ret; 997379bc100SJani Nikula 998379bc100SJani Nikula /* set maximum return packet size */ 999379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1000379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 1001379bc100SJani Nikula 1002379bc100SJani Nikula /* 1003379bc100SJani Nikula * FIXME: This uses the number of DW's currently in the payload 1004379bc100SJani Nikula * receive queue. This is probably not what we want here. 1005379bc100SJani Nikula */ 1006379bc100SJani Nikula tmp = I915_READ(DSI_CMD_RXCTL(dsi_trans)); 1007379bc100SJani Nikula tmp &= NUMBER_RX_PLOAD_DW_MASK; 1008379bc100SJani Nikula /* multiply "Number Rx Payload DW" by 4 to get max value */ 1009379bc100SJani Nikula tmp = tmp * 4; 1010379bc100SJani Nikula dsi = intel_dsi->dsi_hosts[port]->device; 1011379bc100SJani Nikula ret = mipi_dsi_set_maximum_return_packet_size(dsi, tmp); 1012379bc100SJani Nikula if (ret < 0) 1013379bc100SJani Nikula DRM_ERROR("error setting max return pkt size%d\n", tmp); 1014379bc100SJani Nikula } 1015379bc100SJani Nikula 1016379bc100SJani Nikula /* panel power on related mipi dsi vbt sequences */ 1017379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_ON); 1018379bc100SJani Nikula intel_dsi_msleep(intel_dsi, intel_dsi->panel_on_delay); 1019379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DEASSERT_RESET); 1020379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_INIT_OTP); 1021379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON); 1022379bc100SJani Nikula 1023379bc100SJani Nikula /* ensure all panel commands dispatched before enabling transcoder */ 1024379bc100SJani Nikula wait_for_cmds_dispatched_to_panel(encoder); 1025379bc100SJani Nikula } 1026379bc100SJani Nikula 1027379bc100SJani Nikula static void gen11_dsi_pre_pll_enable(struct intel_encoder *encoder, 1028379bc100SJani Nikula const struct intel_crtc_state *pipe_config, 1029379bc100SJani Nikula const struct drm_connector_state *conn_state) 1030379bc100SJani Nikula { 1031379bc100SJani Nikula /* step2: enable IO power */ 1032379bc100SJani Nikula gen11_dsi_enable_io_power(encoder); 1033379bc100SJani Nikula 1034379bc100SJani Nikula /* step3: enable DSI PLL */ 1035379bc100SJani Nikula gen11_dsi_program_esc_clk_div(encoder); 1036379bc100SJani Nikula } 1037379bc100SJani Nikula 1038379bc100SJani Nikula static void gen11_dsi_pre_enable(struct intel_encoder *encoder, 1039379bc100SJani Nikula const struct intel_crtc_state *pipe_config, 1040379bc100SJani Nikula const struct drm_connector_state *conn_state) 1041379bc100SJani Nikula { 1042379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1043379bc100SJani Nikula 1044379bc100SJani Nikula /* step3b */ 1045379bc100SJani Nikula gen11_dsi_map_pll(encoder, pipe_config); 1046379bc100SJani Nikula 1047379bc100SJani Nikula /* step4: enable DSI port and DPHY */ 1048379bc100SJani Nikula gen11_dsi_enable_port_and_phy(encoder, pipe_config); 1049379bc100SJani Nikula 1050379bc100SJani Nikula /* step5: program and powerup panel */ 1051379bc100SJani Nikula gen11_dsi_powerup_panel(encoder); 1052379bc100SJani Nikula 1053379bc100SJani Nikula /* step6c: configure transcoder timings */ 1054379bc100SJani Nikula gen11_dsi_set_transcoder_timings(encoder, pipe_config); 1055379bc100SJani Nikula 1056379bc100SJani Nikula /* step6d: enable dsi transcoder */ 1057379bc100SJani Nikula gen11_dsi_enable_transcoder(encoder); 1058379bc100SJani Nikula 1059379bc100SJani Nikula /* step7: enable backlight */ 1060379bc100SJani Nikula intel_panel_enable_backlight(pipe_config, conn_state); 1061379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_ON); 1062379bc100SJani Nikula } 1063379bc100SJani Nikula 1064379bc100SJani Nikula static void gen11_dsi_disable_transcoder(struct intel_encoder *encoder) 1065379bc100SJani Nikula { 1066379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1067379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1068379bc100SJani Nikula enum port port; 1069379bc100SJani Nikula enum transcoder dsi_trans; 1070379bc100SJani Nikula u32 tmp; 1071379bc100SJani Nikula 1072379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1073379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 1074379bc100SJani Nikula 1075379bc100SJani Nikula /* disable transcoder */ 1076379bc100SJani Nikula tmp = I915_READ(PIPECONF(dsi_trans)); 1077379bc100SJani Nikula tmp &= ~PIPECONF_ENABLE; 1078379bc100SJani Nikula I915_WRITE(PIPECONF(dsi_trans), tmp); 1079379bc100SJani Nikula 1080379bc100SJani Nikula /* wait for transcoder to be disabled */ 1081*4cb3b44dSDaniele Ceraolo Spurio if (intel_de_wait_for_clear(dev_priv, PIPECONF(dsi_trans), 1082*4cb3b44dSDaniele Ceraolo Spurio I965_PIPECONF_ACTIVE, 50)) 1083379bc100SJani Nikula DRM_ERROR("DSI trancoder not disabled\n"); 1084379bc100SJani Nikula } 1085379bc100SJani Nikula } 1086379bc100SJani Nikula 1087379bc100SJani Nikula static void gen11_dsi_powerdown_panel(struct intel_encoder *encoder) 1088379bc100SJani Nikula { 1089379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1090379bc100SJani Nikula 1091379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_OFF); 1092379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_ASSERT_RESET); 1093379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_OFF); 1094379bc100SJani Nikula 1095379bc100SJani Nikula /* ensure cmds dispatched to panel */ 1096379bc100SJani Nikula wait_for_cmds_dispatched_to_panel(encoder); 1097379bc100SJani Nikula } 1098379bc100SJani Nikula 1099379bc100SJani Nikula static void gen11_dsi_deconfigure_trancoder(struct intel_encoder *encoder) 1100379bc100SJani Nikula { 1101379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1102379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1103379bc100SJani Nikula enum port port; 1104379bc100SJani Nikula enum transcoder dsi_trans; 1105379bc100SJani Nikula u32 tmp; 1106379bc100SJani Nikula 1107379bc100SJani Nikula /* put dsi link in ULPS */ 1108379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1109379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 1110379bc100SJani Nikula tmp = I915_READ(DSI_LP_MSG(dsi_trans)); 1111379bc100SJani Nikula tmp |= LINK_ENTER_ULPS; 1112379bc100SJani Nikula tmp &= ~LINK_ULPS_TYPE_LP11; 1113379bc100SJani Nikula I915_WRITE(DSI_LP_MSG(dsi_trans), tmp); 1114379bc100SJani Nikula 1115379bc100SJani Nikula if (wait_for_us((I915_READ(DSI_LP_MSG(dsi_trans)) & 1116379bc100SJani Nikula LINK_IN_ULPS), 1117379bc100SJani Nikula 10)) 1118379bc100SJani Nikula DRM_ERROR("DSI link not in ULPS\n"); 1119379bc100SJani Nikula } 1120379bc100SJani Nikula 1121379bc100SJani Nikula /* disable ddi function */ 1122379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1123379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 1124379bc100SJani Nikula tmp = I915_READ(TRANS_DDI_FUNC_CTL(dsi_trans)); 1125379bc100SJani Nikula tmp &= ~TRANS_DDI_FUNC_ENABLE; 1126379bc100SJani Nikula I915_WRITE(TRANS_DDI_FUNC_CTL(dsi_trans), tmp); 1127379bc100SJani Nikula } 1128379bc100SJani Nikula 1129379bc100SJani Nikula /* disable port sync mode if dual link */ 1130379bc100SJani Nikula if (intel_dsi->dual_link) { 1131379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1132379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 1133379bc100SJani Nikula tmp = I915_READ(TRANS_DDI_FUNC_CTL2(dsi_trans)); 1134379bc100SJani Nikula tmp &= ~PORT_SYNC_MODE_ENABLE; 1135379bc100SJani Nikula I915_WRITE(TRANS_DDI_FUNC_CTL2(dsi_trans), tmp); 1136379bc100SJani Nikula } 1137379bc100SJani Nikula } 1138379bc100SJani Nikula } 1139379bc100SJani Nikula 1140379bc100SJani Nikula static void gen11_dsi_disable_port(struct intel_encoder *encoder) 1141379bc100SJani Nikula { 1142379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1143379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1144379bc100SJani Nikula u32 tmp; 1145379bc100SJani Nikula enum port port; 1146379bc100SJani Nikula 1147379bc100SJani Nikula gen11_dsi_ungate_clocks(encoder); 1148379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1149379bc100SJani Nikula tmp = I915_READ(DDI_BUF_CTL(port)); 1150379bc100SJani Nikula tmp &= ~DDI_BUF_CTL_ENABLE; 1151379bc100SJani Nikula I915_WRITE(DDI_BUF_CTL(port), tmp); 1152379bc100SJani Nikula 1153379bc100SJani Nikula if (wait_for_us((I915_READ(DDI_BUF_CTL(port)) & 1154379bc100SJani Nikula DDI_BUF_IS_IDLE), 1155379bc100SJani Nikula 8)) 1156379bc100SJani Nikula DRM_ERROR("DDI port:%c buffer not idle\n", 1157379bc100SJani Nikula port_name(port)); 1158379bc100SJani Nikula } 1159379bc100SJani Nikula gen11_dsi_gate_clocks(encoder); 1160379bc100SJani Nikula } 1161379bc100SJani Nikula 1162379bc100SJani Nikula static void gen11_dsi_disable_io_power(struct intel_encoder *encoder) 1163379bc100SJani Nikula { 1164379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1165379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1166379bc100SJani Nikula enum port port; 1167379bc100SJani Nikula u32 tmp; 1168379bc100SJani Nikula 1169379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1170379bc100SJani Nikula intel_wakeref_t wakeref; 1171379bc100SJani Nikula 1172379bc100SJani Nikula wakeref = fetch_and_zero(&intel_dsi->io_wakeref[port]); 1173379bc100SJani Nikula intel_display_power_put(dev_priv, 1174379bc100SJani Nikula port == PORT_A ? 1175379bc100SJani Nikula POWER_DOMAIN_PORT_DDI_A_IO : 1176379bc100SJani Nikula POWER_DOMAIN_PORT_DDI_B_IO, 1177379bc100SJani Nikula wakeref); 1178379bc100SJani Nikula } 1179379bc100SJani Nikula 1180379bc100SJani Nikula /* set mode to DDI */ 1181379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1182379bc100SJani Nikula tmp = I915_READ(ICL_DSI_IO_MODECTL(port)); 1183379bc100SJani Nikula tmp &= ~COMBO_PHY_MODE_DSI; 1184379bc100SJani Nikula I915_WRITE(ICL_DSI_IO_MODECTL(port), tmp); 1185379bc100SJani Nikula } 1186379bc100SJani Nikula } 1187379bc100SJani Nikula 1188379bc100SJani Nikula static void gen11_dsi_disable(struct intel_encoder *encoder, 1189379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 1190379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 1191379bc100SJani Nikula { 1192379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1193379bc100SJani Nikula 1194379bc100SJani Nikula /* step1: turn off backlight */ 1195379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_OFF); 1196379bc100SJani Nikula intel_panel_disable_backlight(old_conn_state); 1197379bc100SJani Nikula 1198379bc100SJani Nikula /* step2d,e: disable transcoder and wait */ 1199379bc100SJani Nikula gen11_dsi_disable_transcoder(encoder); 1200379bc100SJani Nikula 1201379bc100SJani Nikula /* step2f,g: powerdown panel */ 1202379bc100SJani Nikula gen11_dsi_powerdown_panel(encoder); 1203379bc100SJani Nikula 1204379bc100SJani Nikula /* step2h,i,j: deconfig trancoder */ 1205379bc100SJani Nikula gen11_dsi_deconfigure_trancoder(encoder); 1206379bc100SJani Nikula 1207379bc100SJani Nikula /* step3: disable port */ 1208379bc100SJani Nikula gen11_dsi_disable_port(encoder); 1209379bc100SJani Nikula 1210379bc100SJani Nikula /* step4: disable IO power */ 1211379bc100SJani Nikula gen11_dsi_disable_io_power(encoder); 1212379bc100SJani Nikula } 1213379bc100SJani Nikula 1214379bc100SJani Nikula static void gen11_dsi_get_timings(struct intel_encoder *encoder, 1215379bc100SJani Nikula struct intel_crtc_state *pipe_config) 1216379bc100SJani Nikula { 1217379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1218379bc100SJani Nikula struct drm_display_mode *adjusted_mode = 1219379bc100SJani Nikula &pipe_config->base.adjusted_mode; 1220379bc100SJani Nikula 1221379bc100SJani Nikula if (intel_dsi->dual_link) { 1222379bc100SJani Nikula adjusted_mode->crtc_hdisplay *= 2; 1223379bc100SJani Nikula if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) 1224379bc100SJani Nikula adjusted_mode->crtc_hdisplay -= 1225379bc100SJani Nikula intel_dsi->pixel_overlap; 1226379bc100SJani Nikula adjusted_mode->crtc_htotal *= 2; 1227379bc100SJani Nikula } 1228379bc100SJani Nikula adjusted_mode->crtc_hblank_start = adjusted_mode->crtc_hdisplay; 1229379bc100SJani Nikula adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_htotal; 1230379bc100SJani Nikula 1231379bc100SJani Nikula if (intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE) { 1232379bc100SJani Nikula if (intel_dsi->dual_link) { 1233379bc100SJani Nikula adjusted_mode->crtc_hsync_start *= 2; 1234379bc100SJani Nikula adjusted_mode->crtc_hsync_end *= 2; 1235379bc100SJani Nikula } 1236379bc100SJani Nikula } 1237379bc100SJani Nikula adjusted_mode->crtc_vblank_start = adjusted_mode->crtc_vdisplay; 1238379bc100SJani Nikula adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vtotal; 1239379bc100SJani Nikula } 1240379bc100SJani Nikula 1241379bc100SJani Nikula static void gen11_dsi_get_config(struct intel_encoder *encoder, 1242379bc100SJani Nikula struct intel_crtc_state *pipe_config) 1243379bc100SJani Nikula { 1244379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1245379bc100SJani Nikula struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc); 1246379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1247379bc100SJani Nikula 1248379bc100SJani Nikula /* FIXME: adapt icl_ddi_clock_get() for DSI and use that? */ 1249379bc100SJani Nikula pipe_config->port_clock = 1250379bc100SJani Nikula cnl_calc_wrpll_link(dev_priv, &pipe_config->dpll_hw_state); 1251379bc100SJani Nikula 1252379bc100SJani Nikula pipe_config->base.adjusted_mode.crtc_clock = intel_dsi->pclk; 1253379bc100SJani Nikula if (intel_dsi->dual_link) 1254379bc100SJani Nikula pipe_config->base.adjusted_mode.crtc_clock *= 2; 1255379bc100SJani Nikula 1256379bc100SJani Nikula gen11_dsi_get_timings(encoder, pipe_config); 1257379bc100SJani Nikula pipe_config->output_types |= BIT(INTEL_OUTPUT_DSI); 1258379bc100SJani Nikula pipe_config->pipe_bpp = bdw_get_pipemisc_bpp(crtc); 1259379bc100SJani Nikula } 1260379bc100SJani Nikula 1261379bc100SJani Nikula static int gen11_dsi_compute_config(struct intel_encoder *encoder, 1262379bc100SJani Nikula struct intel_crtc_state *pipe_config, 1263379bc100SJani Nikula struct drm_connector_state *conn_state) 1264379bc100SJani Nikula { 1265379bc100SJani Nikula struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi, 1266379bc100SJani Nikula base); 1267379bc100SJani Nikula struct intel_connector *intel_connector = intel_dsi->attached_connector; 1268379bc100SJani Nikula struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc); 1269379bc100SJani Nikula const struct drm_display_mode *fixed_mode = 1270379bc100SJani Nikula intel_connector->panel.fixed_mode; 1271379bc100SJani Nikula struct drm_display_mode *adjusted_mode = 1272379bc100SJani Nikula &pipe_config->base.adjusted_mode; 1273379bc100SJani Nikula 1274379bc100SJani Nikula pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; 1275379bc100SJani Nikula intel_fixed_panel_mode(fixed_mode, adjusted_mode); 1276379bc100SJani Nikula intel_pch_panel_fitting(crtc, pipe_config, conn_state->scaling_mode); 1277379bc100SJani Nikula 1278379bc100SJani Nikula adjusted_mode->flags = 0; 1279379bc100SJani Nikula 1280379bc100SJani Nikula /* Dual link goes to trancoder DSI'0' */ 1281379bc100SJani Nikula if (intel_dsi->ports == BIT(PORT_B)) 1282379bc100SJani Nikula pipe_config->cpu_transcoder = TRANSCODER_DSI_1; 1283379bc100SJani Nikula else 1284379bc100SJani Nikula pipe_config->cpu_transcoder = TRANSCODER_DSI_0; 1285379bc100SJani Nikula 1286379bc100SJani Nikula pipe_config->clock_set = true; 1287379bc100SJani Nikula pipe_config->port_clock = intel_dsi_bitrate(intel_dsi) / 5; 1288379bc100SJani Nikula 1289379bc100SJani Nikula return 0; 1290379bc100SJani Nikula } 1291379bc100SJani Nikula 1292379bc100SJani Nikula static void gen11_dsi_get_power_domains(struct intel_encoder *encoder, 1293379bc100SJani Nikula struct intel_crtc_state *crtc_state) 1294379bc100SJani Nikula { 1295379bc100SJani Nikula get_dsi_io_power_domains(to_i915(encoder->base.dev), 1296379bc100SJani Nikula enc_to_intel_dsi(&encoder->base)); 1297379bc100SJani Nikula } 1298379bc100SJani Nikula 1299379bc100SJani Nikula static bool gen11_dsi_get_hw_state(struct intel_encoder *encoder, 1300379bc100SJani Nikula enum pipe *pipe) 1301379bc100SJani Nikula { 1302379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1303379bc100SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1304379bc100SJani Nikula enum transcoder dsi_trans; 1305379bc100SJani Nikula intel_wakeref_t wakeref; 1306379bc100SJani Nikula enum port port; 1307379bc100SJani Nikula bool ret = false; 1308379bc100SJani Nikula u32 tmp; 1309379bc100SJani Nikula 1310379bc100SJani Nikula wakeref = intel_display_power_get_if_enabled(dev_priv, 1311379bc100SJani Nikula encoder->power_domain); 1312379bc100SJani Nikula if (!wakeref) 1313379bc100SJani Nikula return false; 1314379bc100SJani Nikula 1315379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1316379bc100SJani Nikula dsi_trans = dsi_port_to_transcoder(port); 1317379bc100SJani Nikula tmp = I915_READ(TRANS_DDI_FUNC_CTL(dsi_trans)); 1318379bc100SJani Nikula switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { 1319379bc100SJani Nikula case TRANS_DDI_EDP_INPUT_A_ON: 1320379bc100SJani Nikula *pipe = PIPE_A; 1321379bc100SJani Nikula break; 1322379bc100SJani Nikula case TRANS_DDI_EDP_INPUT_B_ONOFF: 1323379bc100SJani Nikula *pipe = PIPE_B; 1324379bc100SJani Nikula break; 1325379bc100SJani Nikula case TRANS_DDI_EDP_INPUT_C_ONOFF: 1326379bc100SJani Nikula *pipe = PIPE_C; 1327379bc100SJani Nikula break; 1328379bc100SJani Nikula default: 1329379bc100SJani Nikula DRM_ERROR("Invalid PIPE input\n"); 1330379bc100SJani Nikula goto out; 1331379bc100SJani Nikula } 1332379bc100SJani Nikula 1333379bc100SJani Nikula tmp = I915_READ(PIPECONF(dsi_trans)); 1334379bc100SJani Nikula ret = tmp & PIPECONF_ENABLE; 1335379bc100SJani Nikula } 1336379bc100SJani Nikula out: 1337379bc100SJani Nikula intel_display_power_put(dev_priv, encoder->power_domain, wakeref); 1338379bc100SJani Nikula return ret; 1339379bc100SJani Nikula } 1340379bc100SJani Nikula 1341379bc100SJani Nikula static void gen11_dsi_encoder_destroy(struct drm_encoder *encoder) 1342379bc100SJani Nikula { 1343379bc100SJani Nikula intel_encoder_destroy(encoder); 1344379bc100SJani Nikula } 1345379bc100SJani Nikula 1346379bc100SJani Nikula static const struct drm_encoder_funcs gen11_dsi_encoder_funcs = { 1347379bc100SJani Nikula .destroy = gen11_dsi_encoder_destroy, 1348379bc100SJani Nikula }; 1349379bc100SJani Nikula 1350379bc100SJani Nikula static const struct drm_connector_funcs gen11_dsi_connector_funcs = { 1351379bc100SJani Nikula .late_register = intel_connector_register, 1352379bc100SJani Nikula .early_unregister = intel_connector_unregister, 1353379bc100SJani Nikula .destroy = intel_connector_destroy, 1354379bc100SJani Nikula .fill_modes = drm_helper_probe_single_connector_modes, 1355379bc100SJani Nikula .atomic_get_property = intel_digital_connector_atomic_get_property, 1356379bc100SJani Nikula .atomic_set_property = intel_digital_connector_atomic_set_property, 1357379bc100SJani Nikula .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 1358379bc100SJani Nikula .atomic_duplicate_state = intel_digital_connector_duplicate_state, 1359379bc100SJani Nikula }; 1360379bc100SJani Nikula 1361379bc100SJani Nikula static const struct drm_connector_helper_funcs gen11_dsi_connector_helper_funcs = { 1362379bc100SJani Nikula .get_modes = intel_dsi_get_modes, 1363379bc100SJani Nikula .mode_valid = intel_dsi_mode_valid, 1364379bc100SJani Nikula .atomic_check = intel_digital_connector_atomic_check, 1365379bc100SJani Nikula }; 1366379bc100SJani Nikula 1367379bc100SJani Nikula static int gen11_dsi_host_attach(struct mipi_dsi_host *host, 1368379bc100SJani Nikula struct mipi_dsi_device *dsi) 1369379bc100SJani Nikula { 1370379bc100SJani Nikula return 0; 1371379bc100SJani Nikula } 1372379bc100SJani Nikula 1373379bc100SJani Nikula static int gen11_dsi_host_detach(struct mipi_dsi_host *host, 1374379bc100SJani Nikula struct mipi_dsi_device *dsi) 1375379bc100SJani Nikula { 1376379bc100SJani Nikula return 0; 1377379bc100SJani Nikula } 1378379bc100SJani Nikula 1379379bc100SJani Nikula static ssize_t gen11_dsi_host_transfer(struct mipi_dsi_host *host, 1380379bc100SJani Nikula const struct mipi_dsi_msg *msg) 1381379bc100SJani Nikula { 1382379bc100SJani Nikula struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host); 1383379bc100SJani Nikula struct mipi_dsi_packet dsi_pkt; 1384379bc100SJani Nikula ssize_t ret; 1385379bc100SJani Nikula bool enable_lpdt = false; 1386379bc100SJani Nikula 1387379bc100SJani Nikula ret = mipi_dsi_create_packet(&dsi_pkt, msg); 1388379bc100SJani Nikula if (ret < 0) 1389379bc100SJani Nikula return ret; 1390379bc100SJani Nikula 1391379bc100SJani Nikula if (msg->flags & MIPI_DSI_MSG_USE_LPM) 1392379bc100SJani Nikula enable_lpdt = true; 1393379bc100SJani Nikula 1394379bc100SJani Nikula /* send packet header */ 1395379bc100SJani Nikula ret = dsi_send_pkt_hdr(intel_dsi_host, dsi_pkt, enable_lpdt); 1396379bc100SJani Nikula if (ret < 0) 1397379bc100SJani Nikula return ret; 1398379bc100SJani Nikula 1399379bc100SJani Nikula /* only long packet contains payload */ 1400379bc100SJani Nikula if (mipi_dsi_packet_format_is_long(msg->type)) { 1401379bc100SJani Nikula ret = dsi_send_pkt_payld(intel_dsi_host, dsi_pkt); 1402379bc100SJani Nikula if (ret < 0) 1403379bc100SJani Nikula return ret; 1404379bc100SJani Nikula } 1405379bc100SJani Nikula 1406379bc100SJani Nikula //TODO: add payload receive code if needed 1407379bc100SJani Nikula 1408379bc100SJani Nikula ret = sizeof(dsi_pkt.header) + dsi_pkt.payload_length; 1409379bc100SJani Nikula 1410379bc100SJani Nikula return ret; 1411379bc100SJani Nikula } 1412379bc100SJani Nikula 1413379bc100SJani Nikula static const struct mipi_dsi_host_ops gen11_dsi_host_ops = { 1414379bc100SJani Nikula .attach = gen11_dsi_host_attach, 1415379bc100SJani Nikula .detach = gen11_dsi_host_detach, 1416379bc100SJani Nikula .transfer = gen11_dsi_host_transfer, 1417379bc100SJani Nikula }; 1418379bc100SJani Nikula 1419379bc100SJani Nikula #define ICL_PREPARE_CNT_MAX 0x7 1420379bc100SJani Nikula #define ICL_CLK_ZERO_CNT_MAX 0xf 1421379bc100SJani Nikula #define ICL_TRAIL_CNT_MAX 0x7 1422379bc100SJani Nikula #define ICL_TCLK_PRE_CNT_MAX 0x3 1423379bc100SJani Nikula #define ICL_TCLK_POST_CNT_MAX 0x7 1424379bc100SJani Nikula #define ICL_HS_ZERO_CNT_MAX 0xf 1425379bc100SJani Nikula #define ICL_EXIT_ZERO_CNT_MAX 0x7 1426379bc100SJani Nikula 1427379bc100SJani Nikula static void icl_dphy_param_init(struct intel_dsi *intel_dsi) 1428379bc100SJani Nikula { 1429379bc100SJani Nikula struct drm_device *dev = intel_dsi->base.base.dev; 1430379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(dev); 1431379bc100SJani Nikula struct mipi_config *mipi_config = dev_priv->vbt.dsi.config; 1432379bc100SJani Nikula u32 tlpx_ns; 1433379bc100SJani Nikula u32 prepare_cnt, exit_zero_cnt, clk_zero_cnt, trail_cnt; 1434379bc100SJani Nikula u32 ths_prepare_ns, tclk_trail_ns; 1435379bc100SJani Nikula u32 hs_zero_cnt; 1436379bc100SJani Nikula u32 tclk_pre_cnt, tclk_post_cnt; 1437379bc100SJani Nikula 1438379bc100SJani Nikula tlpx_ns = intel_dsi_tlpx_ns(intel_dsi); 1439379bc100SJani Nikula 1440379bc100SJani Nikula tclk_trail_ns = max(mipi_config->tclk_trail, mipi_config->ths_trail); 1441379bc100SJani Nikula ths_prepare_ns = max(mipi_config->ths_prepare, 1442379bc100SJani Nikula mipi_config->tclk_prepare); 1443379bc100SJani Nikula 1444379bc100SJani Nikula /* 1445379bc100SJani Nikula * prepare cnt in escape clocks 1446379bc100SJani Nikula * this field represents a hexadecimal value with a precision 1447379bc100SJani Nikula * of 1.2 – i.e. the most significant bit is the integer 1448379bc100SJani Nikula * and the least significant 2 bits are fraction bits. 1449379bc100SJani Nikula * so, the field can represent a range of 0.25 to 1.75 1450379bc100SJani Nikula */ 1451379bc100SJani Nikula prepare_cnt = DIV_ROUND_UP(ths_prepare_ns * 4, tlpx_ns); 1452379bc100SJani Nikula if (prepare_cnt > ICL_PREPARE_CNT_MAX) { 1453379bc100SJani Nikula DRM_DEBUG_KMS("prepare_cnt out of range (%d)\n", prepare_cnt); 1454379bc100SJani Nikula prepare_cnt = ICL_PREPARE_CNT_MAX; 1455379bc100SJani Nikula } 1456379bc100SJani Nikula 1457379bc100SJani Nikula /* clk zero count in escape clocks */ 1458379bc100SJani Nikula clk_zero_cnt = DIV_ROUND_UP(mipi_config->tclk_prepare_clkzero - 1459379bc100SJani Nikula ths_prepare_ns, tlpx_ns); 1460379bc100SJani Nikula if (clk_zero_cnt > ICL_CLK_ZERO_CNT_MAX) { 1461379bc100SJani Nikula DRM_DEBUG_KMS("clk_zero_cnt out of range (%d)\n", clk_zero_cnt); 1462379bc100SJani Nikula clk_zero_cnt = ICL_CLK_ZERO_CNT_MAX; 1463379bc100SJani Nikula } 1464379bc100SJani Nikula 1465379bc100SJani Nikula /* trail cnt in escape clocks*/ 1466379bc100SJani Nikula trail_cnt = DIV_ROUND_UP(tclk_trail_ns, tlpx_ns); 1467379bc100SJani Nikula if (trail_cnt > ICL_TRAIL_CNT_MAX) { 1468379bc100SJani Nikula DRM_DEBUG_KMS("trail_cnt out of range (%d)\n", trail_cnt); 1469379bc100SJani Nikula trail_cnt = ICL_TRAIL_CNT_MAX; 1470379bc100SJani Nikula } 1471379bc100SJani Nikula 1472379bc100SJani Nikula /* tclk pre count in escape clocks */ 1473379bc100SJani Nikula tclk_pre_cnt = DIV_ROUND_UP(mipi_config->tclk_pre, tlpx_ns); 1474379bc100SJani Nikula if (tclk_pre_cnt > ICL_TCLK_PRE_CNT_MAX) { 1475379bc100SJani Nikula DRM_DEBUG_KMS("tclk_pre_cnt out of range (%d)\n", tclk_pre_cnt); 1476379bc100SJani Nikula tclk_pre_cnt = ICL_TCLK_PRE_CNT_MAX; 1477379bc100SJani Nikula } 1478379bc100SJani Nikula 1479379bc100SJani Nikula /* tclk post count in escape clocks */ 1480379bc100SJani Nikula tclk_post_cnt = DIV_ROUND_UP(mipi_config->tclk_post, tlpx_ns); 1481379bc100SJani Nikula if (tclk_post_cnt > ICL_TCLK_POST_CNT_MAX) { 1482379bc100SJani Nikula DRM_DEBUG_KMS("tclk_post_cnt out of range (%d)\n", tclk_post_cnt); 1483379bc100SJani Nikula tclk_post_cnt = ICL_TCLK_POST_CNT_MAX; 1484379bc100SJani Nikula } 1485379bc100SJani Nikula 1486379bc100SJani Nikula /* hs zero cnt in escape clocks */ 1487379bc100SJani Nikula hs_zero_cnt = DIV_ROUND_UP(mipi_config->ths_prepare_hszero - 1488379bc100SJani Nikula ths_prepare_ns, tlpx_ns); 1489379bc100SJani Nikula if (hs_zero_cnt > ICL_HS_ZERO_CNT_MAX) { 1490379bc100SJani Nikula DRM_DEBUG_KMS("hs_zero_cnt out of range (%d)\n", hs_zero_cnt); 1491379bc100SJani Nikula hs_zero_cnt = ICL_HS_ZERO_CNT_MAX; 1492379bc100SJani Nikula } 1493379bc100SJani Nikula 1494379bc100SJani Nikula /* hs exit zero cnt in escape clocks */ 1495379bc100SJani Nikula exit_zero_cnt = DIV_ROUND_UP(mipi_config->ths_exit, tlpx_ns); 1496379bc100SJani Nikula if (exit_zero_cnt > ICL_EXIT_ZERO_CNT_MAX) { 1497379bc100SJani Nikula DRM_DEBUG_KMS("exit_zero_cnt out of range (%d)\n", exit_zero_cnt); 1498379bc100SJani Nikula exit_zero_cnt = ICL_EXIT_ZERO_CNT_MAX; 1499379bc100SJani Nikula } 1500379bc100SJani Nikula 1501379bc100SJani Nikula /* clock lane dphy timings */ 1502379bc100SJani Nikula intel_dsi->dphy_reg = (CLK_PREPARE_OVERRIDE | 1503379bc100SJani Nikula CLK_PREPARE(prepare_cnt) | 1504379bc100SJani Nikula CLK_ZERO_OVERRIDE | 1505379bc100SJani Nikula CLK_ZERO(clk_zero_cnt) | 1506379bc100SJani Nikula CLK_PRE_OVERRIDE | 1507379bc100SJani Nikula CLK_PRE(tclk_pre_cnt) | 1508379bc100SJani Nikula CLK_POST_OVERRIDE | 1509379bc100SJani Nikula CLK_POST(tclk_post_cnt) | 1510379bc100SJani Nikula CLK_TRAIL_OVERRIDE | 1511379bc100SJani Nikula CLK_TRAIL(trail_cnt)); 1512379bc100SJani Nikula 1513379bc100SJani Nikula /* data lanes dphy timings */ 1514379bc100SJani Nikula intel_dsi->dphy_data_lane_reg = (HS_PREPARE_OVERRIDE | 1515379bc100SJani Nikula HS_PREPARE(prepare_cnt) | 1516379bc100SJani Nikula HS_ZERO_OVERRIDE | 1517379bc100SJani Nikula HS_ZERO(hs_zero_cnt) | 1518379bc100SJani Nikula HS_TRAIL_OVERRIDE | 1519379bc100SJani Nikula HS_TRAIL(trail_cnt) | 1520379bc100SJani Nikula HS_EXIT_OVERRIDE | 1521379bc100SJani Nikula HS_EXIT(exit_zero_cnt)); 1522379bc100SJani Nikula 1523379bc100SJani Nikula intel_dsi_log_params(intel_dsi); 1524379bc100SJani Nikula } 1525379bc100SJani Nikula 1526f384e48dSVandita Kulkarni static void icl_dsi_add_properties(struct intel_connector *connector) 1527f384e48dSVandita Kulkarni { 1528f384e48dSVandita Kulkarni u32 allowed_scalers; 1529f384e48dSVandita Kulkarni 1530f384e48dSVandita Kulkarni allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | 1531f384e48dSVandita Kulkarni BIT(DRM_MODE_SCALE_FULLSCREEN) | 1532f384e48dSVandita Kulkarni BIT(DRM_MODE_SCALE_CENTER); 1533f384e48dSVandita Kulkarni 1534f384e48dSVandita Kulkarni drm_connector_attach_scaling_mode_property(&connector->base, 1535f384e48dSVandita Kulkarni allowed_scalers); 1536f384e48dSVandita Kulkarni 1537f384e48dSVandita Kulkarni connector->base.state->scaling_mode = DRM_MODE_SCALE_ASPECT; 1538f384e48dSVandita Kulkarni 1539f384e48dSVandita Kulkarni connector->base.display_info.panel_orientation = 1540f384e48dSVandita Kulkarni intel_dsi_get_panel_orientation(connector); 1541f384e48dSVandita Kulkarni drm_connector_init_panel_orientation_property(&connector->base, 1542f384e48dSVandita Kulkarni connector->panel.fixed_mode->hdisplay, 1543f384e48dSVandita Kulkarni connector->panel.fixed_mode->vdisplay); 1544f384e48dSVandita Kulkarni } 1545f384e48dSVandita Kulkarni 1546379bc100SJani Nikula void icl_dsi_init(struct drm_i915_private *dev_priv) 1547379bc100SJani Nikula { 1548379bc100SJani Nikula struct drm_device *dev = &dev_priv->drm; 1549379bc100SJani Nikula struct intel_dsi *intel_dsi; 1550379bc100SJani Nikula struct intel_encoder *encoder; 1551379bc100SJani Nikula struct intel_connector *intel_connector; 1552379bc100SJani Nikula struct drm_connector *connector; 1553379bc100SJani Nikula struct drm_display_mode *fixed_mode; 1554379bc100SJani Nikula enum port port; 1555379bc100SJani Nikula 1556379bc100SJani Nikula if (!intel_bios_is_dsi_present(dev_priv, &port)) 1557379bc100SJani Nikula return; 1558379bc100SJani Nikula 1559379bc100SJani Nikula intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL); 1560379bc100SJani Nikula if (!intel_dsi) 1561379bc100SJani Nikula return; 1562379bc100SJani Nikula 1563379bc100SJani Nikula intel_connector = intel_connector_alloc(); 1564379bc100SJani Nikula if (!intel_connector) { 1565379bc100SJani Nikula kfree(intel_dsi); 1566379bc100SJani Nikula return; 1567379bc100SJani Nikula } 1568379bc100SJani Nikula 1569379bc100SJani Nikula encoder = &intel_dsi->base; 1570379bc100SJani Nikula intel_dsi->attached_connector = intel_connector; 1571379bc100SJani Nikula connector = &intel_connector->base; 1572379bc100SJani Nikula 1573379bc100SJani Nikula /* register DSI encoder with DRM subsystem */ 1574379bc100SJani Nikula drm_encoder_init(dev, &encoder->base, &gen11_dsi_encoder_funcs, 1575379bc100SJani Nikula DRM_MODE_ENCODER_DSI, "DSI %c", port_name(port)); 1576379bc100SJani Nikula 1577379bc100SJani Nikula encoder->pre_pll_enable = gen11_dsi_pre_pll_enable; 1578379bc100SJani Nikula encoder->pre_enable = gen11_dsi_pre_enable; 1579379bc100SJani Nikula encoder->disable = gen11_dsi_disable; 1580379bc100SJani Nikula encoder->port = port; 1581379bc100SJani Nikula encoder->get_config = gen11_dsi_get_config; 1582379bc100SJani Nikula encoder->update_pipe = intel_panel_update_backlight; 1583379bc100SJani Nikula encoder->compute_config = gen11_dsi_compute_config; 1584379bc100SJani Nikula encoder->get_hw_state = gen11_dsi_get_hw_state; 1585379bc100SJani Nikula encoder->type = INTEL_OUTPUT_DSI; 1586379bc100SJani Nikula encoder->cloneable = 0; 1587379bc100SJani Nikula encoder->crtc_mask = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C); 1588379bc100SJani Nikula encoder->power_domain = POWER_DOMAIN_PORT_DSI; 1589379bc100SJani Nikula encoder->get_power_domains = gen11_dsi_get_power_domains; 1590379bc100SJani Nikula 1591379bc100SJani Nikula /* register DSI connector with DRM subsystem */ 1592379bc100SJani Nikula drm_connector_init(dev, connector, &gen11_dsi_connector_funcs, 1593379bc100SJani Nikula DRM_MODE_CONNECTOR_DSI); 1594379bc100SJani Nikula drm_connector_helper_add(connector, &gen11_dsi_connector_helper_funcs); 1595379bc100SJani Nikula connector->display_info.subpixel_order = SubPixelHorizontalRGB; 1596379bc100SJani Nikula connector->interlace_allowed = false; 1597379bc100SJani Nikula connector->doublescan_allowed = false; 1598379bc100SJani Nikula intel_connector->get_hw_state = intel_connector_get_hw_state; 1599379bc100SJani Nikula 1600379bc100SJani Nikula /* attach connector to encoder */ 1601379bc100SJani Nikula intel_connector_attach_encoder(intel_connector, encoder); 1602379bc100SJani Nikula 1603379bc100SJani Nikula mutex_lock(&dev->mode_config.mutex); 1604379bc100SJani Nikula fixed_mode = intel_panel_vbt_fixed_mode(intel_connector); 1605379bc100SJani Nikula mutex_unlock(&dev->mode_config.mutex); 1606379bc100SJani Nikula 1607379bc100SJani Nikula if (!fixed_mode) { 1608379bc100SJani Nikula DRM_ERROR("DSI fixed mode info missing\n"); 1609379bc100SJani Nikula goto err; 1610379bc100SJani Nikula } 1611379bc100SJani Nikula 1612379bc100SJani Nikula intel_panel_init(&intel_connector->panel, fixed_mode, NULL); 1613379bc100SJani Nikula intel_panel_setup_backlight(connector, INVALID_PIPE); 1614379bc100SJani Nikula 1615379bc100SJani Nikula if (dev_priv->vbt.dsi.config->dual_link) 1616379bc100SJani Nikula intel_dsi->ports = BIT(PORT_A) | BIT(PORT_B); 1617379bc100SJani Nikula else 1618379bc100SJani Nikula intel_dsi->ports = BIT(port); 1619379bc100SJani Nikula 1620379bc100SJani Nikula intel_dsi->dcs_backlight_ports = dev_priv->vbt.dsi.bl_ports; 1621379bc100SJani Nikula intel_dsi->dcs_cabc_ports = dev_priv->vbt.dsi.cabc_ports; 1622379bc100SJani Nikula 1623379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) { 1624379bc100SJani Nikula struct intel_dsi_host *host; 1625379bc100SJani Nikula 1626379bc100SJani Nikula host = intel_dsi_host_init(intel_dsi, &gen11_dsi_host_ops, port); 1627379bc100SJani Nikula if (!host) 1628379bc100SJani Nikula goto err; 1629379bc100SJani Nikula 1630379bc100SJani Nikula intel_dsi->dsi_hosts[port] = host; 1631379bc100SJani Nikula } 1632379bc100SJani Nikula 1633379bc100SJani Nikula if (!intel_dsi_vbt_init(intel_dsi, MIPI_DSI_GENERIC_PANEL_ID)) { 1634379bc100SJani Nikula DRM_DEBUG_KMS("no device found\n"); 1635379bc100SJani Nikula goto err; 1636379bc100SJani Nikula } 1637379bc100SJani Nikula 1638379bc100SJani Nikula icl_dphy_param_init(intel_dsi); 1639f384e48dSVandita Kulkarni 1640f384e48dSVandita Kulkarni icl_dsi_add_properties(intel_connector); 1641379bc100SJani Nikula return; 1642379bc100SJani Nikula 1643379bc100SJani Nikula err: 1644379bc100SJani Nikula drm_encoder_cleanup(&encoder->base); 1645379bc100SJani Nikula kfree(intel_dsi); 1646379bc100SJani Nikula kfree(intel_connector); 1647379bc100SJani Nikula } 1648