2 * Copyright © 2018 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Madhav Chauhan <madhav.chauhan@intel.com>
25 * Jani Nikula <jani.nikula@intel.com>
28 #include <drm/drm_mipi_dsi.h>
29 #include <drm/drm_atomic_helper.h>
30 #include "intel_dsi.h"
32 static inline int header_credits_available(struct drm_i915_private *dev_priv,
33 enum transcoder dsi_trans)
35 return (I915_READ(DSI_CMD_TXCTL(dsi_trans)) & FREE_HEADER_CREDIT_MASK)
36 >> FREE_HEADER_CREDIT_SHIFT;
39 static inline int payload_credits_available(struct drm_i915_private *dev_priv,
40 enum transcoder dsi_trans)
42 return (I915_READ(DSI_CMD_TXCTL(dsi_trans)) & FREE_PLOAD_CREDIT_MASK)
43 >> FREE_PLOAD_CREDIT_SHIFT;
46 static void wait_for_header_credits(struct drm_i915_private *dev_priv,
47 enum transcoder dsi_trans)
49 if (wait_for_us(header_credits_available(dev_priv, dsi_trans) >=
50 MAX_HEADER_CREDIT, 100))
51 DRM_ERROR("DSI header credits not released\n");
54 static void wait_for_payload_credits(struct drm_i915_private *dev_priv,
55 enum transcoder dsi_trans)
57 if (wait_for_us(payload_credits_available(dev_priv, dsi_trans) >=
58 MAX_PLOAD_CREDIT, 100))
59 DRM_ERROR("DSI payload credits not released\n");
62 static enum transcoder dsi_port_to_transcoder(enum port port)
65 return TRANSCODER_DSI_0;
67 return TRANSCODER_DSI_1;
70 static void wait_for_cmds_dispatched_to_panel(struct intel_encoder *encoder)
72 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
73 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
74 struct mipi_dsi_device *dsi;
76 enum transcoder dsi_trans;
79 /* wait for header/payload credits to be released */
80 for_each_dsi_port(port, intel_dsi->ports) {
81 dsi_trans = dsi_port_to_transcoder(port);
82 wait_for_header_credits(dev_priv, dsi_trans);
83 wait_for_payload_credits(dev_priv, dsi_trans);
86 /* send nop DCS command */
87 for_each_dsi_port(port, intel_dsi->ports) {
88 dsi = intel_dsi->dsi_hosts[port]->device;
89 dsi->mode_flags |= MIPI_DSI_MODE_LPM;
91 ret = mipi_dsi_dcs_nop(dsi);
93 DRM_ERROR("error sending DCS NOP command\n");
96 /* wait for header credits to be released */
97 for_each_dsi_port(port, intel_dsi->ports) {
98 dsi_trans = dsi_port_to_transcoder(port);
99 wait_for_header_credits(dev_priv, dsi_trans);
102 /* wait for LP TX in progress bit to be cleared */
103 for_each_dsi_port(port, intel_dsi->ports) {
104 dsi_trans = dsi_port_to_transcoder(port);
105 if (wait_for_us(!(I915_READ(DSI_LP_MSG(dsi_trans)) &
106 LPTX_IN_PROGRESS), 20))
107 DRM_ERROR("LPTX bit not cleared\n");
111 static bool add_payld_to_queue(struct intel_dsi_host *host, const u8 *data,
114 struct intel_dsi *intel_dsi = host->intel_dsi;
115 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
116 enum transcoder dsi_trans = dsi_port_to_transcoder(host->port);
120 for (i = 0; i < len; i += 4) {
123 free_credits = payload_credits_available(dev_priv, dsi_trans);
124 if (free_credits < 1) {
125 DRM_ERROR("Payload credit not available\n");
129 for (j = 0; j < min_t(u32, len - i, 4); j++)
130 tmp |= *data++ << 8 * j;
132 I915_WRITE(DSI_CMD_TXPYLD(dsi_trans), tmp);
138 static int dsi_send_pkt_hdr(struct intel_dsi_host *host,
139 struct mipi_dsi_packet pkt, bool enable_lpdt)
141 struct intel_dsi *intel_dsi = host->intel_dsi;
142 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
143 enum transcoder dsi_trans = dsi_port_to_transcoder(host->port);
147 /* check if header credit available */
148 free_credits = header_credits_available(dev_priv, dsi_trans);
149 if (free_credits < 1) {
150 DRM_ERROR("send pkt header failed, not enough hdr credits\n");
154 tmp = I915_READ(DSI_CMD_TXHDR(dsi_trans));
157 tmp |= PAYLOAD_PRESENT;
159 tmp &= ~PAYLOAD_PRESENT;
161 tmp &= ~VBLANK_FENCE;
164 tmp |= LP_DATA_TRANSFER;
166 tmp &= ~(PARAM_WC_MASK | VC_MASK | DT_MASK);
167 tmp |= ((pkt.header[0] & VC_MASK) << VC_SHIFT);
168 tmp |= ((pkt.header[0] & DT_MASK) << DT_SHIFT);
169 tmp |= (pkt.header[1] << PARAM_WC_LOWER_SHIFT);
170 tmp |= (pkt.header[2] << PARAM_WC_UPPER_SHIFT);
171 I915_WRITE(DSI_CMD_TXHDR(dsi_trans), tmp);
176 static int dsi_send_pkt_payld(struct intel_dsi_host *host,
177 struct mipi_dsi_packet pkt)
179 /* payload queue can accept *256 bytes*, check limit */
180 if (pkt.payload_length > MAX_PLOAD_CREDIT * 4) {
181 DRM_ERROR("payload size exceeds max queue limit\n");
185 /* load data into command payload queue */
186 if (!add_payld_to_queue(host, pkt.payload,
187 pkt.payload_length)) {
188 DRM_ERROR("adding payload to queue failed\n");
195 static void dsi_program_swing_and_deemphasis(struct intel_encoder *encoder)
197 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
198 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
203 for_each_dsi_port(port, intel_dsi->ports) {
206 * Program voltage swing and pre-emphasis level values as per
207 * table in BSPEC under DDI buffer programing
209 tmp = I915_READ(ICL_PORT_TX_DW5_LN0(port));
210 tmp &= ~(SCALING_MODE_SEL_MASK | RTERM_SELECT_MASK);
211 tmp |= SCALING_MODE_SEL(0x2);
212 tmp |= TAP2_DISABLE | TAP3_DISABLE;
213 tmp |= RTERM_SELECT(0x6);
214 I915_WRITE(ICL_PORT_TX_DW5_GRP(port), tmp);
216 tmp = I915_READ(ICL_PORT_TX_DW5_AUX(port));
217 tmp &= ~(SCALING_MODE_SEL_MASK | RTERM_SELECT_MASK);
218 tmp |= SCALING_MODE_SEL(0x2);
219 tmp |= TAP2_DISABLE | TAP3_DISABLE;
220 tmp |= RTERM_SELECT(0x6);
221 I915_WRITE(ICL_PORT_TX_DW5_AUX(port), tmp);
223 tmp = I915_READ(ICL_PORT_TX_DW2_LN0(port));
224 tmp &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK |
226 tmp |= SWING_SEL_UPPER(0x2);
227 tmp |= SWING_SEL_LOWER(0x2);
228 tmp |= RCOMP_SCALAR(0x98);
229 I915_WRITE(ICL_PORT_TX_DW2_GRP(port), tmp);
231 tmp = I915_READ(ICL_PORT_TX_DW2_AUX(port));
232 tmp &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK |
234 tmp |= SWING_SEL_UPPER(0x2);
235 tmp |= SWING_SEL_LOWER(0x2);
236 tmp |= RCOMP_SCALAR(0x98);
237 I915_WRITE(ICL_PORT_TX_DW2_AUX(port), tmp);
239 tmp = I915_READ(ICL_PORT_TX_DW4_AUX(port));
240 tmp &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK |
242 tmp |= POST_CURSOR_1(0x0);
243 tmp |= POST_CURSOR_2(0x0);
244 tmp |= CURSOR_COEFF(0x3f);
245 I915_WRITE(ICL_PORT_TX_DW4_AUX(port), tmp);
247 for (lane = 0; lane <= 3; lane++) {
248 /* Bspec: must not use GRP register for write */
249 tmp = I915_READ(ICL_PORT_TX_DW4_LN(port, lane));
250 tmp &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK |
252 tmp |= POST_CURSOR_1(0x0);
253 tmp |= POST_CURSOR_2(0x0);
254 tmp |= CURSOR_COEFF(0x3f);
255 I915_WRITE(ICL_PORT_TX_DW4_LN(port, lane), tmp);
260 static void configure_dual_link_mode(struct intel_encoder *encoder,
261 const struct intel_crtc_state *pipe_config)
263 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
264 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
267 dss_ctl1 = I915_READ(DSS_CTL1);
268 dss_ctl1 |= SPLITTER_ENABLE;
269 dss_ctl1 &= ~OVERLAP_PIXELS_MASK;
270 dss_ctl1 |= OVERLAP_PIXELS(intel_dsi->pixel_overlap);
272 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
273 const struct drm_display_mode *adjusted_mode =
274 &pipe_config->base.adjusted_mode;
276 u16 hactive = adjusted_mode->crtc_hdisplay;
279 dss_ctl1 &= ~DUAL_LINK_MODE_INTERLEAVE;
280 dl_buffer_depth = hactive / 2 + intel_dsi->pixel_overlap;
282 if (dl_buffer_depth > MAX_DL_BUFFER_TARGET_DEPTH)
283 DRM_ERROR("DL buffer depth exceed max value\n");
285 dss_ctl1 &= ~LEFT_DL_BUF_TARGET_DEPTH_MASK;
286 dss_ctl1 |= LEFT_DL_BUF_TARGET_DEPTH(dl_buffer_depth);
287 dss_ctl2 = I915_READ(DSS_CTL2);
288 dss_ctl2 &= ~RIGHT_DL_BUF_TARGET_DEPTH_MASK;
289 dss_ctl2 |= RIGHT_DL_BUF_TARGET_DEPTH(dl_buffer_depth);
290 I915_WRITE(DSS_CTL2, dss_ctl2);
293 dss_ctl1 |= DUAL_LINK_MODE_INTERLEAVE;
296 I915_WRITE(DSS_CTL1, dss_ctl1);
299 static void gen11_dsi_program_esc_clk_div(struct intel_encoder *encoder)
301 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
302 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
304 u32 bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
305 u32 afe_clk_khz; /* 8X Clock */
308 afe_clk_khz = DIV_ROUND_CLOSEST(intel_dsi->pclk * bpp,
309 intel_dsi->lane_count);
311 esc_clk_div_m = DIV_ROUND_UP(afe_clk_khz, DSI_MAX_ESC_CLK);
313 for_each_dsi_port(port, intel_dsi->ports) {
314 I915_WRITE(ICL_DSI_ESC_CLK_DIV(port),
315 esc_clk_div_m & ICL_ESC_CLK_DIV_MASK);
316 POSTING_READ(ICL_DSI_ESC_CLK_DIV(port));
319 for_each_dsi_port(port, intel_dsi->ports) {
320 I915_WRITE(ICL_DPHY_ESC_CLK_DIV(port),
321 esc_clk_div_m & ICL_ESC_CLK_DIV_MASK);
322 POSTING_READ(ICL_DPHY_ESC_CLK_DIV(port));
326 static void gen11_dsi_enable_io_power(struct intel_encoder *encoder)
328 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
329 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
333 for_each_dsi_port(port, intel_dsi->ports) {
334 tmp = I915_READ(ICL_DSI_IO_MODECTL(port));
335 tmp |= COMBO_PHY_MODE_DSI;
336 I915_WRITE(ICL_DSI_IO_MODECTL(port), tmp);
339 for_each_dsi_port(port, intel_dsi->ports) {
340 intel_dsi->io_wakeref[port] =
341 intel_display_power_get(dev_priv,
343 POWER_DOMAIN_PORT_DDI_A_IO :
344 POWER_DOMAIN_PORT_DDI_B_IO);
348 static void gen11_dsi_power_up_lanes(struct intel_encoder *encoder)
350 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
351 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
356 switch (intel_dsi->lane_count) {
358 lane_mask = PWR_DOWN_LN_3_1_0;
361 lane_mask = PWR_DOWN_LN_3_1;
364 lane_mask = PWR_DOWN_LN_3;
368 lane_mask = PWR_UP_ALL_LANES;
372 for_each_dsi_port(port, intel_dsi->ports) {
373 tmp = I915_READ(ICL_PORT_CL_DW10(port));
374 tmp &= ~PWR_DOWN_LN_MASK;
375 I915_WRITE(ICL_PORT_CL_DW10(port), tmp | lane_mask);
379 static void gen11_dsi_config_phy_lanes_sequence(struct intel_encoder *encoder)
381 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
382 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
387 /* Step 4b(i) set loadgen select for transmit and aux lanes */
388 for_each_dsi_port(port, intel_dsi->ports) {
389 tmp = I915_READ(ICL_PORT_TX_DW4_AUX(port));
390 tmp &= ~LOADGEN_SELECT;
391 I915_WRITE(ICL_PORT_TX_DW4_AUX(port), tmp);
392 for (lane = 0; lane <= 3; lane++) {
393 tmp = I915_READ(ICL_PORT_TX_DW4_LN(port, lane));
394 tmp &= ~LOADGEN_SELECT;
396 tmp |= LOADGEN_SELECT;
397 I915_WRITE(ICL_PORT_TX_DW4_LN(port, lane), tmp);
401 /* Step 4b(ii) set latency optimization for transmit and aux lanes */
402 for_each_dsi_port(port, intel_dsi->ports) {
403 tmp = I915_READ(ICL_PORT_TX_DW2_AUX(port));
404 tmp &= ~FRC_LATENCY_OPTIM_MASK;
405 tmp |= FRC_LATENCY_OPTIM_VAL(0x5);
406 I915_WRITE(ICL_PORT_TX_DW2_AUX(port), tmp);
407 tmp = I915_READ(ICL_PORT_TX_DW2_LN0(port));
408 tmp &= ~FRC_LATENCY_OPTIM_MASK;
409 tmp |= FRC_LATENCY_OPTIM_VAL(0x5);
410 I915_WRITE(ICL_PORT_TX_DW2_GRP(port), tmp);
415 static void gen11_dsi_voltage_swing_program_seq(struct intel_encoder *encoder)
417 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
418 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
422 /* clear common keeper enable bit */
423 for_each_dsi_port(port, intel_dsi->ports) {
424 tmp = I915_READ(ICL_PORT_PCS_DW1_LN0(port));
425 tmp &= ~COMMON_KEEPER_EN;
426 I915_WRITE(ICL_PORT_PCS_DW1_GRP(port), tmp);
427 tmp = I915_READ(ICL_PORT_PCS_DW1_AUX(port));
428 tmp &= ~COMMON_KEEPER_EN;
429 I915_WRITE(ICL_PORT_PCS_DW1_AUX(port), tmp);
433 * Set SUS Clock Config bitfield to 11b
434 * Note: loadgen select program is done
435 * as part of lane phy sequence configuration
437 for_each_dsi_port(port, intel_dsi->ports) {
438 tmp = I915_READ(ICL_PORT_CL_DW5(port));
439 tmp |= SUS_CLOCK_CONFIG;
440 I915_WRITE(ICL_PORT_CL_DW5(port), tmp);
443 /* Clear training enable to change swing values */
444 for_each_dsi_port(port, intel_dsi->ports) {
445 tmp = I915_READ(ICL_PORT_TX_DW5_LN0(port));
446 tmp &= ~TX_TRAINING_EN;
447 I915_WRITE(ICL_PORT_TX_DW5_GRP(port), tmp);
448 tmp = I915_READ(ICL_PORT_TX_DW5_AUX(port));
449 tmp &= ~TX_TRAINING_EN;
450 I915_WRITE(ICL_PORT_TX_DW5_AUX(port), tmp);
453 /* Program swing and de-emphasis */
454 dsi_program_swing_and_deemphasis(encoder);
456 /* Set training enable to trigger update */
457 for_each_dsi_port(port, intel_dsi->ports) {
458 tmp = I915_READ(ICL_PORT_TX_DW5_LN0(port));
459 tmp |= TX_TRAINING_EN;
460 I915_WRITE(ICL_PORT_TX_DW5_GRP(port), tmp);
461 tmp = I915_READ(ICL_PORT_TX_DW5_AUX(port));
462 tmp |= TX_TRAINING_EN;
463 I915_WRITE(ICL_PORT_TX_DW5_AUX(port), tmp);
467 static void gen11_dsi_enable_ddi_buffer(struct intel_encoder *encoder)
469 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
470 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
474 for_each_dsi_port(port, intel_dsi->ports) {
475 tmp = I915_READ(DDI_BUF_CTL(port));
476 tmp |= DDI_BUF_CTL_ENABLE;
477 I915_WRITE(DDI_BUF_CTL(port), tmp);
479 if (wait_for_us(!(I915_READ(DDI_BUF_CTL(port)) &
482 DRM_ERROR("DDI port:%c buffer idle\n", port_name(port));
486 static void gen11_dsi_setup_dphy_timings(struct intel_encoder *encoder)
488 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
489 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
493 /* Program T-INIT master registers */
494 for_each_dsi_port(port, intel_dsi->ports) {
495 tmp = I915_READ(ICL_DSI_T_INIT_MASTER(port));
496 tmp &= ~MASTER_INIT_TIMER_MASK;
497 tmp |= intel_dsi->init_count;
498 I915_WRITE(ICL_DSI_T_INIT_MASTER(port), tmp);
501 /* Program DPHY clock lanes timings */
502 for_each_dsi_port(port, intel_dsi->ports) {
503 I915_WRITE(DPHY_CLK_TIMING_PARAM(port), intel_dsi->dphy_reg);
505 /* shadow register inside display core */
506 I915_WRITE(DSI_CLK_TIMING_PARAM(port), intel_dsi->dphy_reg);
509 /* Program DPHY data lanes timings */
510 for_each_dsi_port(port, intel_dsi->ports) {
511 I915_WRITE(DPHY_DATA_TIMING_PARAM(port),
512 intel_dsi->dphy_data_lane_reg);
514 /* shadow register inside display core */
515 I915_WRITE(DSI_DATA_TIMING_PARAM(port),
516 intel_dsi->dphy_data_lane_reg);
520 * If DSI link operating at or below an 800 MHz,
521 * TA_SURE should be override and programmed to
522 * a value '0' inside TA_PARAM_REGISTERS otherwise
523 * leave all fields at HW default values.
525 if (intel_dsi_bitrate(intel_dsi) <= 800000) {
526 for_each_dsi_port(port, intel_dsi->ports) {
527 tmp = I915_READ(DPHY_TA_TIMING_PARAM(port));
528 tmp &= ~TA_SURE_MASK;
529 tmp |= TA_SURE_OVERRIDE | TA_SURE(0);
530 I915_WRITE(DPHY_TA_TIMING_PARAM(port), tmp);
532 /* shadow register inside display core */
533 tmp = I915_READ(DSI_TA_TIMING_PARAM(port));
534 tmp &= ~TA_SURE_MASK;
535 tmp |= TA_SURE_OVERRIDE | TA_SURE(0);
536 I915_WRITE(DSI_TA_TIMING_PARAM(port), tmp);
541 static void gen11_dsi_gate_clocks(struct intel_encoder *encoder)
543 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
544 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
548 mutex_lock(&dev_priv->dpll_lock);
549 tmp = I915_READ(DPCLKA_CFGCR0_ICL);
550 for_each_dsi_port(port, intel_dsi->ports) {
551 tmp |= DPCLKA_CFGCR0_DDI_CLK_OFF(port);
554 I915_WRITE(DPCLKA_CFGCR0_ICL, tmp);
555 mutex_unlock(&dev_priv->dpll_lock);
558 static void gen11_dsi_ungate_clocks(struct intel_encoder *encoder)
560 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
561 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
565 mutex_lock(&dev_priv->dpll_lock);
566 tmp = I915_READ(DPCLKA_CFGCR0_ICL);
567 for_each_dsi_port(port, intel_dsi->ports) {
568 tmp &= ~DPCLKA_CFGCR0_DDI_CLK_OFF(port);
571 I915_WRITE(DPCLKA_CFGCR0_ICL, tmp);
572 mutex_unlock(&dev_priv->dpll_lock);
575 static void gen11_dsi_map_pll(struct intel_encoder *encoder,
576 const struct intel_crtc_state *crtc_state)
578 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
579 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
580 struct intel_shared_dpll *pll = crtc_state->shared_dpll;
584 mutex_lock(&dev_priv->dpll_lock);
586 val = I915_READ(DPCLKA_CFGCR0_ICL);
587 for_each_dsi_port(port, intel_dsi->ports) {
588 val &= ~DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
589 val |= DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, port);
591 I915_WRITE(DPCLKA_CFGCR0_ICL, val);
592 POSTING_READ(DPCLKA_CFGCR0_ICL);
594 mutex_unlock(&dev_priv->dpll_lock);
598 gen11_dsi_configure_transcoder(struct intel_encoder *encoder,
599 const struct intel_crtc_state *pipe_config)
601 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
602 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
603 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
604 enum pipe pipe = intel_crtc->pipe;
607 enum transcoder dsi_trans;
609 for_each_dsi_port(port, intel_dsi->ports) {
610 dsi_trans = dsi_port_to_transcoder(port);
611 tmp = I915_READ(DSI_TRANS_FUNC_CONF(dsi_trans));
613 if (intel_dsi->eotp_pkt)
614 tmp &= ~EOTP_DISABLED;
616 tmp |= EOTP_DISABLED;
618 /* enable link calibration if freq > 1.5Gbps */
619 if (intel_dsi_bitrate(intel_dsi) >= 1500 * 1000) {
620 tmp &= ~LINK_CALIBRATION_MASK;
621 tmp |= CALIBRATION_ENABLED_INITIAL_ONLY;
624 /* configure continuous clock */
625 tmp &= ~CONTINUOUS_CLK_MASK;
626 if (intel_dsi->clock_stop)
627 tmp |= CLK_ENTER_LP_AFTER_DATA;
629 tmp |= CLK_HS_CONTINUOUS;
631 /* configure buffer threshold limit to minimum */
632 tmp &= ~PIX_BUF_THRESHOLD_MASK;
633 tmp |= PIX_BUF_THRESHOLD_1_4;
635 /* set virtual channel to '0' */
636 tmp &= ~PIX_VIRT_CHAN_MASK;
637 tmp |= PIX_VIRT_CHAN(0);
639 /* program BGR transmission */
640 if (intel_dsi->bgr_enabled)
641 tmp |= BGR_TRANSMISSION;
643 /* select pixel format */
644 tmp &= ~PIX_FMT_MASK;
645 switch (intel_dsi->pixel_format) {
647 MISSING_CASE(intel_dsi->pixel_format);
649 case MIPI_DSI_FMT_RGB565:
650 tmp |= PIX_FMT_RGB565;
652 case MIPI_DSI_FMT_RGB666_PACKED:
653 tmp |= PIX_FMT_RGB666_PACKED;
655 case MIPI_DSI_FMT_RGB666:
656 tmp |= PIX_FMT_RGB666_LOOSE;
658 case MIPI_DSI_FMT_RGB888:
659 tmp |= PIX_FMT_RGB888;
663 /* program DSI operation mode */
664 if (is_vid_mode(intel_dsi)) {
665 tmp &= ~OP_MODE_MASK;
666 switch (intel_dsi->video_mode_format) {
668 MISSING_CASE(intel_dsi->video_mode_format);
670 case VIDEO_MODE_NON_BURST_WITH_SYNC_EVENTS:
671 tmp |= VIDEO_MODE_SYNC_EVENT;
673 case VIDEO_MODE_NON_BURST_WITH_SYNC_PULSE:
674 tmp |= VIDEO_MODE_SYNC_PULSE;
679 I915_WRITE(DSI_TRANS_FUNC_CONF(dsi_trans), tmp);
682 /* enable port sync mode if dual link */
683 if (intel_dsi->dual_link) {
684 for_each_dsi_port(port, intel_dsi->ports) {
685 dsi_trans = dsi_port_to_transcoder(port);
686 tmp = I915_READ(TRANS_DDI_FUNC_CTL2(dsi_trans));
687 tmp |= PORT_SYNC_MODE_ENABLE;
688 I915_WRITE(TRANS_DDI_FUNC_CTL2(dsi_trans), tmp);
691 /* configure stream splitting */
692 configure_dual_link_mode(encoder, pipe_config);
695 for_each_dsi_port(port, intel_dsi->ports) {
696 dsi_trans = dsi_port_to_transcoder(port);
698 /* select data lane width */
699 tmp = I915_READ(TRANS_DDI_FUNC_CTL(dsi_trans));
700 tmp &= ~DDI_PORT_WIDTH_MASK;
701 tmp |= DDI_PORT_WIDTH(intel_dsi->lane_count);
703 /* select input pipe */
704 tmp &= ~TRANS_DDI_EDP_INPUT_MASK;
710 tmp |= TRANS_DDI_EDP_INPUT_A_ON;
713 tmp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
716 tmp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
720 /* enable DDI buffer */
721 tmp |= TRANS_DDI_FUNC_ENABLE;
722 I915_WRITE(TRANS_DDI_FUNC_CTL(dsi_trans), tmp);
725 /* wait for link ready */
726 for_each_dsi_port(port, intel_dsi->ports) {
727 dsi_trans = dsi_port_to_transcoder(port);
728 if (wait_for_us((I915_READ(DSI_TRANS_FUNC_CONF(dsi_trans)) &
730 DRM_ERROR("DSI link not ready\n");
735 gen11_dsi_set_transcoder_timings(struct intel_encoder *encoder,
736 const struct intel_crtc_state *pipe_config)
738 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
739 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
740 const struct drm_display_mode *adjusted_mode =
741 &pipe_config->base.adjusted_mode;
743 enum transcoder dsi_trans;
744 /* horizontal timings */
745 u16 htotal, hactive, hsync_start, hsync_end, hsync_size;
746 u16 hfront_porch, hback_porch;
747 /* vertical timings */
748 u16 vtotal, vactive, vsync_start, vsync_end, vsync_shift;
750 hactive = adjusted_mode->crtc_hdisplay;
751 htotal = adjusted_mode->crtc_htotal;
752 hsync_start = adjusted_mode->crtc_hsync_start;
753 hsync_end = adjusted_mode->crtc_hsync_end;
754 hsync_size = hsync_end - hsync_start;
755 hfront_porch = (adjusted_mode->crtc_hsync_start -
756 adjusted_mode->crtc_hdisplay);
757 hback_porch = (adjusted_mode->crtc_htotal -
758 adjusted_mode->crtc_hsync_end);
759 vactive = adjusted_mode->crtc_vdisplay;
760 vtotal = adjusted_mode->crtc_vtotal;
761 vsync_start = adjusted_mode->crtc_vsync_start;
762 vsync_end = adjusted_mode->crtc_vsync_end;
763 vsync_shift = hsync_start - htotal / 2;
765 if (intel_dsi->dual_link) {
767 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
768 hactive += intel_dsi->pixel_overlap;
772 /* minimum hactive as per bspec: 256 pixels */
773 if (adjusted_mode->crtc_hdisplay < 256)
774 DRM_ERROR("hactive is less then 256 pixels\n");
776 /* if RGB666 format, then hactive must be multiple of 4 pixels */
777 if (intel_dsi->pixel_format == MIPI_DSI_FMT_RGB666 && hactive % 4 != 0)
778 DRM_ERROR("hactive pixels are not multiple of 4\n");
780 /* program TRANS_HTOTAL register */
781 for_each_dsi_port(port, intel_dsi->ports) {
782 dsi_trans = dsi_port_to_transcoder(port);
783 I915_WRITE(HTOTAL(dsi_trans),
784 (hactive - 1) | ((htotal - 1) << 16));
787 /* TRANS_HSYNC register to be programmed only for video mode */
788 if (intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE) {
789 if (intel_dsi->video_mode_format ==
790 VIDEO_MODE_NON_BURST_WITH_SYNC_PULSE) {
791 /* BSPEC: hsync size should be atleast 16 pixels */
793 DRM_ERROR("hsync size < 16 pixels\n");
796 if (hback_porch < 16)
797 DRM_ERROR("hback porch < 16 pixels\n");
799 if (intel_dsi->dual_link) {
804 for_each_dsi_port(port, intel_dsi->ports) {
805 dsi_trans = dsi_port_to_transcoder(port);
806 I915_WRITE(HSYNC(dsi_trans),
807 (hsync_start - 1) | ((hsync_end - 1) << 16));
811 /* program TRANS_VTOTAL register */
812 for_each_dsi_port(port, intel_dsi->ports) {
813 dsi_trans = dsi_port_to_transcoder(port);
815 * FIXME: Programing this by assuming progressive mode, since
816 * non-interlaced info from VBT is not saved inside
817 * struct drm_display_mode.
818 * For interlace mode: program required pixel minus 2
820 I915_WRITE(VTOTAL(dsi_trans),
821 (vactive - 1) | ((vtotal - 1) << 16));
824 if (vsync_end < vsync_start || vsync_end > vtotal)
825 DRM_ERROR("Invalid vsync_end value\n");
827 if (vsync_start < vactive)
828 DRM_ERROR("vsync_start less than vactive\n");
830 /* program TRANS_VSYNC register */
831 for_each_dsi_port(port, intel_dsi->ports) {
832 dsi_trans = dsi_port_to_transcoder(port);
833 I915_WRITE(VSYNC(dsi_trans),
834 (vsync_start - 1) | ((vsync_end - 1) << 16));
838 * FIXME: It has to be programmed only for interlaced
839 * modes. Put the check condition here once interlaced
840 * info available as described above.
841 * program TRANS_VSYNCSHIFT register
843 for_each_dsi_port(port, intel_dsi->ports) {
844 dsi_trans = dsi_port_to_transcoder(port);
845 I915_WRITE(VSYNCSHIFT(dsi_trans), vsync_shift);
849 static void gen11_dsi_enable_transcoder(struct intel_encoder *encoder)
851 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
852 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
854 enum transcoder dsi_trans;
857 for_each_dsi_port(port, intel_dsi->ports) {
858 dsi_trans = dsi_port_to_transcoder(port);
859 tmp = I915_READ(PIPECONF(dsi_trans));
860 tmp |= PIPECONF_ENABLE;
861 I915_WRITE(PIPECONF(dsi_trans), tmp);
863 /* wait for transcoder to be enabled */
864 if (intel_wait_for_register(dev_priv, PIPECONF(dsi_trans),
865 I965_PIPECONF_ACTIVE,
866 I965_PIPECONF_ACTIVE, 10))
867 DRM_ERROR("DSI transcoder not enabled\n");
871 static void gen11_dsi_setup_timeouts(struct intel_encoder *encoder)
873 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
874 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
876 enum transcoder dsi_trans;
877 u32 tmp, hs_tx_timeout, lp_rx_timeout, ta_timeout, divisor, mul;
880 * escape clock count calculation:
881 * BYTE_CLK_COUNT = TIME_NS/(8 * UI)
882 * UI (nsec) = (10^6)/Bitrate
883 * TIME_NS = (BYTE_CLK_COUNT * 8 * 10^6)/ Bitrate
884 * ESCAPE_CLK_COUNT = TIME_NS/ESC_CLK_NS
886 divisor = intel_dsi_tlpx_ns(intel_dsi) * intel_dsi_bitrate(intel_dsi) * 1000;
888 hs_tx_timeout = DIV_ROUND_UP(intel_dsi->hs_tx_timeout * mul,
890 lp_rx_timeout = DIV_ROUND_UP(intel_dsi->lp_rx_timeout * mul, divisor);
891 ta_timeout = DIV_ROUND_UP(intel_dsi->turn_arnd_val * mul, divisor);
893 for_each_dsi_port(port, intel_dsi->ports) {
894 dsi_trans = dsi_port_to_transcoder(port);
896 /* program hst_tx_timeout */
897 tmp = I915_READ(DSI_HSTX_TO(dsi_trans));
898 tmp &= ~HSTX_TIMEOUT_VALUE_MASK;
899 tmp |= HSTX_TIMEOUT_VALUE(hs_tx_timeout);
900 I915_WRITE(DSI_HSTX_TO(dsi_trans), tmp);
902 /* FIXME: DSI_CALIB_TO */
904 /* program lp_rx_host timeout */
905 tmp = I915_READ(DSI_LPRX_HOST_TO(dsi_trans));
906 tmp &= ~LPRX_TIMEOUT_VALUE_MASK;
907 tmp |= LPRX_TIMEOUT_VALUE(lp_rx_timeout);
908 I915_WRITE(DSI_LPRX_HOST_TO(dsi_trans), tmp);
910 /* FIXME: DSI_PWAIT_TO */
912 /* program turn around timeout */
913 tmp = I915_READ(DSI_TA_TO(dsi_trans));
914 tmp &= ~TA_TIMEOUT_VALUE_MASK;
915 tmp |= TA_TIMEOUT_VALUE(ta_timeout);
916 I915_WRITE(DSI_TA_TO(dsi_trans), tmp);
921 gen11_dsi_enable_port_and_phy(struct intel_encoder *encoder,
922 const struct intel_crtc_state *pipe_config)
924 /* step 4a: power up all lanes of the DDI used by DSI */
925 gen11_dsi_power_up_lanes(encoder);
927 /* step 4b: configure lane sequencing of the Combo-PHY transmitters */
928 gen11_dsi_config_phy_lanes_sequence(encoder);
930 /* step 4c: configure voltage swing and skew */
931 gen11_dsi_voltage_swing_program_seq(encoder);
933 /* enable DDI buffer */
934 gen11_dsi_enable_ddi_buffer(encoder);
936 /* setup D-PHY timings */
937 gen11_dsi_setup_dphy_timings(encoder);
939 /* step 4h: setup DSI protocol timeouts */
940 gen11_dsi_setup_timeouts(encoder);
942 /* Step (4h, 4i, 4j, 4k): Configure transcoder */
943 gen11_dsi_configure_transcoder(encoder, pipe_config);
945 /* Step 4l: Gate DDI clocks */
946 gen11_dsi_gate_clocks(encoder);
949 static void gen11_dsi_powerup_panel(struct intel_encoder *encoder)
951 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
952 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
953 struct mipi_dsi_device *dsi;
955 enum transcoder dsi_trans;
959 /* set maximum return packet size */
960 for_each_dsi_port(port, intel_dsi->ports) {
961 dsi_trans = dsi_port_to_transcoder(port);
964 * FIXME: This uses the number of DW's currently in the payload
965 * receive queue. This is probably not what we want here.
967 tmp = I915_READ(DSI_CMD_RXCTL(dsi_trans));
968 tmp &= NUMBER_RX_PLOAD_DW_MASK;
969 /* multiply "Number Rx Payload DW" by 4 to get max value */
971 dsi = intel_dsi->dsi_hosts[port]->device;
972 ret = mipi_dsi_set_maximum_return_packet_size(dsi, tmp);
974 DRM_ERROR("error setting max return pkt size%d\n", tmp);
977 /* panel power on related mipi dsi vbt sequences */
978 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_ON);
979 intel_dsi_msleep(intel_dsi, intel_dsi->panel_on_delay);
980 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DEASSERT_RESET);
981 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_INIT_OTP);
982 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON);
984 /* ensure all panel commands dispatched before enabling transcoder */
985 wait_for_cmds_dispatched_to_panel(encoder);
988 static void gen11_dsi_pre_pll_enable(struct intel_encoder *encoder,
989 const struct intel_crtc_state *pipe_config,
990 const struct drm_connector_state *conn_state)
992 /* step2: enable IO power */
993 gen11_dsi_enable_io_power(encoder);
995 /* step3: enable DSI PLL */
996 gen11_dsi_program_esc_clk_div(encoder);
999 static void gen11_dsi_pre_enable(struct intel_encoder *encoder,
1000 const struct intel_crtc_state *pipe_config,
1001 const struct drm_connector_state *conn_state)
1003 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
1006 gen11_dsi_map_pll(encoder, pipe_config);
1008 /* step4: enable DSI port and DPHY */
1009 gen11_dsi_enable_port_and_phy(encoder, pipe_config);
1011 /* step5: program and powerup panel */
1012 gen11_dsi_powerup_panel(encoder);
1014 /* step6c: configure transcoder timings */
1015 gen11_dsi_set_transcoder_timings(encoder, pipe_config);
1017 /* step6d: enable dsi transcoder */
1018 gen11_dsi_enable_transcoder(encoder);
1020 /* step7: enable backlight */
1021 intel_panel_enable_backlight(pipe_config, conn_state);
1022 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_ON);
1025 static void gen11_dsi_disable_transcoder(struct intel_encoder *encoder)
1027 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1028 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
1030 enum transcoder dsi_trans;
1033 for_each_dsi_port(port, intel_dsi->ports) {
1034 dsi_trans = dsi_port_to_transcoder(port);
1036 /* disable transcoder */
1037 tmp = I915_READ(PIPECONF(dsi_trans));
1038 tmp &= ~PIPECONF_ENABLE;
1039 I915_WRITE(PIPECONF(dsi_trans), tmp);
1041 /* wait for transcoder to be disabled */
1042 if (intel_wait_for_register(dev_priv, PIPECONF(dsi_trans),
1043 I965_PIPECONF_ACTIVE, 0, 50))
1044 DRM_ERROR("DSI trancoder not disabled\n");
1048 static void gen11_dsi_powerdown_panel(struct intel_encoder *encoder)
1050 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
1052 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_OFF);
1053 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_ASSERT_RESET);
1054 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_OFF);
1056 /* ensure cmds dispatched to panel */
1057 wait_for_cmds_dispatched_to_panel(encoder);
1060 static void gen11_dsi_deconfigure_trancoder(struct intel_encoder *encoder)
1062 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1063 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
1065 enum transcoder dsi_trans;
1068 /* put dsi link in ULPS */
1069 for_each_dsi_port(port, intel_dsi->ports) {
1070 dsi_trans = dsi_port_to_transcoder(port);
1071 tmp = I915_READ(DSI_LP_MSG(dsi_trans));
1072 tmp |= LINK_ENTER_ULPS;
1073 tmp &= ~LINK_ULPS_TYPE_LP11;
1074 I915_WRITE(DSI_LP_MSG(dsi_trans), tmp);
1076 if (wait_for_us((I915_READ(DSI_LP_MSG(dsi_trans)) &
1079 DRM_ERROR("DSI link not in ULPS\n");
1082 /* disable ddi function */
1083 for_each_dsi_port(port, intel_dsi->ports) {
1084 dsi_trans = dsi_port_to_transcoder(port);
1085 tmp = I915_READ(TRANS_DDI_FUNC_CTL(dsi_trans));
1086 tmp &= ~TRANS_DDI_FUNC_ENABLE;
1087 I915_WRITE(TRANS_DDI_FUNC_CTL(dsi_trans), tmp);
1090 /* disable port sync mode if dual link */
1091 if (intel_dsi->dual_link) {
1092 for_each_dsi_port(port, intel_dsi->ports) {
1093 dsi_trans = dsi_port_to_transcoder(port);
1094 tmp = I915_READ(TRANS_DDI_FUNC_CTL2(dsi_trans));
1095 tmp &= ~PORT_SYNC_MODE_ENABLE;
1096 I915_WRITE(TRANS_DDI_FUNC_CTL2(dsi_trans), tmp);
1101 static void gen11_dsi_disable_port(struct intel_encoder *encoder)
1103 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1104 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
1108 gen11_dsi_ungate_clocks(encoder);
1109 for_each_dsi_port(port, intel_dsi->ports) {
1110 tmp = I915_READ(DDI_BUF_CTL(port));
1111 tmp &= ~DDI_BUF_CTL_ENABLE;
1112 I915_WRITE(DDI_BUF_CTL(port), tmp);
1114 if (wait_for_us((I915_READ(DDI_BUF_CTL(port)) &
1117 DRM_ERROR("DDI port:%c buffer not idle\n",
1120 gen11_dsi_ungate_clocks(encoder);
1123 static void gen11_dsi_disable_io_power(struct intel_encoder *encoder)
1125 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1126 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
1130 for_each_dsi_port(port, intel_dsi->ports) {
1131 intel_wakeref_t wakeref;
1133 wakeref = fetch_and_zero(&intel_dsi->io_wakeref[port]);
1135 intel_display_power_put(dev_priv,
1137 POWER_DOMAIN_PORT_DDI_A_IO :
1138 POWER_DOMAIN_PORT_DDI_B_IO,
1143 /* set mode to DDI */
1144 for_each_dsi_port(port, intel_dsi->ports) {
1145 tmp = I915_READ(ICL_DSI_IO_MODECTL(port));
1146 tmp &= ~COMBO_PHY_MODE_DSI;
1147 I915_WRITE(ICL_DSI_IO_MODECTL(port), tmp);
1151 static void gen11_dsi_disable(struct intel_encoder *encoder,
1152 const struct intel_crtc_state *old_crtc_state,
1153 const struct drm_connector_state *old_conn_state)
1155 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
1157 /* step1: turn off backlight */
1158 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_OFF);
1159 intel_panel_disable_backlight(old_conn_state);
1161 /* step2d,e: disable transcoder and wait */
1162 gen11_dsi_disable_transcoder(encoder);
1164 /* step2f,g: powerdown panel */
1165 gen11_dsi_powerdown_panel(encoder);
1167 /* step2h,i,j: deconfig trancoder */
1168 gen11_dsi_deconfigure_trancoder(encoder);
1170 /* step3: disable port */
1171 gen11_dsi_disable_port(encoder);
1173 /* step4: disable IO power */
1174 gen11_dsi_disable_io_power(encoder);
1177 static void gen11_dsi_get_config(struct intel_encoder *encoder,
1178 struct intel_crtc_state *pipe_config)
1180 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1181 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
1184 /* FIXME: adapt icl_ddi_clock_get() for DSI and use that? */
1185 pll_id = intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll);
1186 pipe_config->port_clock = cnl_calc_wrpll_link(dev_priv, pll_id);
1187 pipe_config->base.adjusted_mode.crtc_clock = intel_dsi->pclk;
1188 pipe_config->output_types |= BIT(INTEL_OUTPUT_DSI);
1191 static int gen11_dsi_compute_config(struct intel_encoder *encoder,
1192 struct intel_crtc_state *pipe_config,
1193 struct drm_connector_state *conn_state)
1195 struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
1197 struct intel_connector *intel_connector = intel_dsi->attached_connector;
1198 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
1199 const struct drm_display_mode *fixed_mode =
1200 intel_connector->panel.fixed_mode;
1201 struct drm_display_mode *adjusted_mode =
1202 &pipe_config->base.adjusted_mode;
1204 intel_fixed_panel_mode(fixed_mode, adjusted_mode);
1205 intel_pch_panel_fitting(crtc, pipe_config, conn_state->scaling_mode);
1207 adjusted_mode->flags = 0;
1209 /* Dual link goes to trancoder DSI'0' */
1210 if (intel_dsi->ports == BIT(PORT_B))
1211 pipe_config->cpu_transcoder = TRANSCODER_DSI_1;
1213 pipe_config->cpu_transcoder = TRANSCODER_DSI_0;
1215 pipe_config->clock_set = true;
1216 pipe_config->port_clock = intel_dsi_bitrate(intel_dsi) / 5;
1221 static u64 gen11_dsi_get_power_domains(struct intel_encoder *encoder,
1222 struct intel_crtc_state *crtc_state)
1224 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
1228 for_each_dsi_port(port, intel_dsi->ports)
1230 domains |= BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO);
1232 domains |= BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO);
1237 static bool gen11_dsi_get_hw_state(struct intel_encoder *encoder,
1240 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1241 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
1242 enum transcoder dsi_trans;
1243 intel_wakeref_t wakeref;
1248 wakeref = intel_display_power_get_if_enabled(dev_priv,
1249 encoder->power_domain);
1253 for_each_dsi_port(port, intel_dsi->ports) {
1254 dsi_trans = dsi_port_to_transcoder(port);
1255 tmp = I915_READ(TRANS_DDI_FUNC_CTL(dsi_trans));
1256 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1257 case TRANS_DDI_EDP_INPUT_A_ON:
1260 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1263 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1267 DRM_ERROR("Invalid PIPE input\n");
1271 tmp = I915_READ(PIPECONF(dsi_trans));
1272 ret = tmp & PIPECONF_ENABLE;
1275 intel_display_power_put(dev_priv, encoder->power_domain, wakeref);
1279 static void gen11_dsi_encoder_destroy(struct drm_encoder *encoder)
1281 intel_encoder_destroy(encoder);
1284 static const struct drm_encoder_funcs gen11_dsi_encoder_funcs = {
1285 .destroy = gen11_dsi_encoder_destroy,
1288 static const struct drm_connector_funcs gen11_dsi_connector_funcs = {
1289 .late_register = intel_connector_register,
1290 .early_unregister = intel_connector_unregister,
1291 .destroy = intel_connector_destroy,
1292 .fill_modes = drm_helper_probe_single_connector_modes,
1293 .atomic_get_property = intel_digital_connector_atomic_get_property,
1294 .atomic_set_property = intel_digital_connector_atomic_set_property,
1295 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
1296 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
1299 static const struct drm_connector_helper_funcs gen11_dsi_connector_helper_funcs = {
1300 .get_modes = intel_dsi_get_modes,
1301 .mode_valid = intel_dsi_mode_valid,
1302 .atomic_check = intel_digital_connector_atomic_check,
1305 static int gen11_dsi_host_attach(struct mipi_dsi_host *host,
1306 struct mipi_dsi_device *dsi)
1311 static int gen11_dsi_host_detach(struct mipi_dsi_host *host,
1312 struct mipi_dsi_device *dsi)
1317 static ssize_t gen11_dsi_host_transfer(struct mipi_dsi_host *host,
1318 const struct mipi_dsi_msg *msg)
1320 struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host);
1321 struct mipi_dsi_packet dsi_pkt;
1323 bool enable_lpdt = false;
1325 ret = mipi_dsi_create_packet(&dsi_pkt, msg);
1329 if (msg->flags & MIPI_DSI_MSG_USE_LPM)
1332 /* send packet header */
1333 ret = dsi_send_pkt_hdr(intel_dsi_host, dsi_pkt, enable_lpdt);
1337 /* only long packet contains payload */
1338 if (mipi_dsi_packet_format_is_long(msg->type)) {
1339 ret = dsi_send_pkt_payld(intel_dsi_host, dsi_pkt);
1344 //TODO: add payload receive code if needed
1346 ret = sizeof(dsi_pkt.header) + dsi_pkt.payload_length;
1351 static const struct mipi_dsi_host_ops gen11_dsi_host_ops = {
1352 .attach = gen11_dsi_host_attach,
1353 .detach = gen11_dsi_host_detach,
1354 .transfer = gen11_dsi_host_transfer,
1357 void icl_dsi_init(struct drm_i915_private *dev_priv)
1359 struct drm_device *dev = &dev_priv->drm;
1360 struct intel_dsi *intel_dsi;
1361 struct intel_encoder *encoder;
1362 struct intel_connector *intel_connector;
1363 struct drm_connector *connector;
1364 struct drm_display_mode *scan, *fixed_mode = NULL;
1367 if (!intel_bios_is_dsi_present(dev_priv, &port))
1370 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
1374 intel_connector = intel_connector_alloc();
1375 if (!intel_connector) {
1380 encoder = &intel_dsi->base;
1381 intel_dsi->attached_connector = intel_connector;
1382 connector = &intel_connector->base;
1384 /* register DSI encoder with DRM subsystem */
1385 drm_encoder_init(dev, &encoder->base, &gen11_dsi_encoder_funcs,
1386 DRM_MODE_ENCODER_DSI, "DSI %c", port_name(port));
1388 encoder->pre_pll_enable = gen11_dsi_pre_pll_enable;
1389 encoder->pre_enable = gen11_dsi_pre_enable;
1390 encoder->disable = gen11_dsi_disable;
1391 encoder->port = port;
1392 encoder->get_config = gen11_dsi_get_config;
1393 encoder->update_pipe = intel_panel_update_backlight;
1394 encoder->compute_config = gen11_dsi_compute_config;
1395 encoder->get_hw_state = gen11_dsi_get_hw_state;
1396 encoder->type = INTEL_OUTPUT_DSI;
1397 encoder->cloneable = 0;
1398 encoder->crtc_mask = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C);
1399 encoder->power_domain = POWER_DOMAIN_PORT_DSI;
1400 encoder->get_power_domains = gen11_dsi_get_power_domains;
1402 /* register DSI connector with DRM subsystem */
1403 drm_connector_init(dev, connector, &gen11_dsi_connector_funcs,
1404 DRM_MODE_CONNECTOR_DSI);
1405 drm_connector_helper_add(connector, &gen11_dsi_connector_helper_funcs);
1406 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
1407 connector->interlace_allowed = false;
1408 connector->doublescan_allowed = false;
1409 intel_connector->get_hw_state = intel_connector_get_hw_state;
1411 /* attach connector to encoder */
1412 intel_connector_attach_encoder(intel_connector, encoder);
1414 /* fill mode info from VBT */
1415 mutex_lock(&dev->mode_config.mutex);
1416 intel_dsi_vbt_get_modes(intel_dsi);
1417 list_for_each_entry(scan, &connector->probed_modes, head) {
1418 if (scan->type & DRM_MODE_TYPE_PREFERRED) {
1419 fixed_mode = drm_mode_duplicate(dev, scan);
1423 mutex_unlock(&dev->mode_config.mutex);
1426 DRM_ERROR("DSI fixed mode info missing\n");
1430 connector->display_info.width_mm = fixed_mode->width_mm;
1431 connector->display_info.height_mm = fixed_mode->height_mm;
1432 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
1433 intel_panel_setup_backlight(connector, INVALID_PIPE);
1436 if (dev_priv->vbt.dsi.config->dual_link)
1437 intel_dsi->ports = BIT(PORT_A) | BIT(PORT_B);
1439 intel_dsi->ports = BIT(port);
1441 intel_dsi->dcs_backlight_ports = dev_priv->vbt.dsi.bl_ports;
1442 intel_dsi->dcs_cabc_ports = dev_priv->vbt.dsi.cabc_ports;
1444 for_each_dsi_port(port, intel_dsi->ports) {
1445 struct intel_dsi_host *host;
1447 host = intel_dsi_host_init(intel_dsi, &gen11_dsi_host_ops, port);
1451 intel_dsi->dsi_hosts[port] = host;
1454 if (!intel_dsi_vbt_init(intel_dsi, MIPI_DSI_GENERIC_PANEL_ID)) {
1455 DRM_DEBUG_KMS("no device found\n");
1462 drm_encoder_cleanup(&encoder->base);
1464 kfree(intel_connector);