Home | History | Annotate | Line # | Download | only in display
      1  1.1  riastrad /*	$NetBSD: icl_dsi.c,v 1.2 2021/12/18 23:45:29 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright  2018 Intel Corporation
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice (including the next
     14  1.1  riastrad  * paragraph) shall be included in all copies or substantial portions of the
     15  1.1  riastrad  * Software.
     16  1.1  riastrad  *
     17  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     18  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     19  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     20  1.1  riastrad  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     21  1.1  riastrad  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     22  1.1  riastrad  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     23  1.1  riastrad  * DEALINGS IN THE SOFTWARE.
     24  1.1  riastrad  *
     25  1.1  riastrad  * Authors:
     26  1.1  riastrad  *   Madhav Chauhan <madhav.chauhan (at) intel.com>
     27  1.1  riastrad  *   Jani Nikula <jani.nikula (at) intel.com>
     28  1.1  riastrad  */
     29  1.1  riastrad 
     30  1.1  riastrad #include <sys/cdefs.h>
     31  1.1  riastrad __KERNEL_RCSID(0, "$NetBSD: icl_dsi.c,v 1.2 2021/12/18 23:45:29 riastradh Exp $");
     32  1.1  riastrad 
     33  1.1  riastrad #include <drm/drm_atomic_helper.h>
     34  1.1  riastrad #include <drm/drm_mipi_dsi.h>
     35  1.1  riastrad 
     36  1.1  riastrad #include "intel_atomic.h"
     37  1.1  riastrad #include "intel_combo_phy.h"
     38  1.1  riastrad #include "intel_connector.h"
     39  1.1  riastrad #include "intel_ddi.h"
     40  1.1  riastrad #include "intel_dsi.h"
     41  1.1  riastrad #include "intel_panel.h"
     42  1.1  riastrad #include "intel_vdsc.h"
     43  1.1  riastrad 
     44  1.1  riastrad static inline int header_credits_available(struct drm_i915_private *dev_priv,
     45  1.1  riastrad 					   enum transcoder dsi_trans)
     46  1.1  riastrad {
     47  1.1  riastrad 	return (I915_READ(DSI_CMD_TXCTL(dsi_trans)) & FREE_HEADER_CREDIT_MASK)
     48  1.1  riastrad 		>> FREE_HEADER_CREDIT_SHIFT;
     49  1.1  riastrad }
     50  1.1  riastrad 
     51  1.1  riastrad static inline int payload_credits_available(struct drm_i915_private *dev_priv,
     52  1.1  riastrad 					    enum transcoder dsi_trans)
     53  1.1  riastrad {
     54  1.1  riastrad 	return (I915_READ(DSI_CMD_TXCTL(dsi_trans)) & FREE_PLOAD_CREDIT_MASK)
     55  1.1  riastrad 		>> FREE_PLOAD_CREDIT_SHIFT;
     56  1.1  riastrad }
     57  1.1  riastrad 
     58  1.1  riastrad static void wait_for_header_credits(struct drm_i915_private *dev_priv,
     59  1.1  riastrad 				    enum transcoder dsi_trans)
     60  1.1  riastrad {
     61  1.1  riastrad 	if (wait_for_us(header_credits_available(dev_priv, dsi_trans) >=
     62  1.1  riastrad 			MAX_HEADER_CREDIT, 100))
     63  1.1  riastrad 		DRM_ERROR("DSI header credits not released\n");
     64  1.1  riastrad }
     65  1.1  riastrad 
     66  1.1  riastrad static void wait_for_payload_credits(struct drm_i915_private *dev_priv,
     67  1.1  riastrad 				     enum transcoder dsi_trans)
     68  1.1  riastrad {
     69  1.1  riastrad 	if (wait_for_us(payload_credits_available(dev_priv, dsi_trans) >=
     70  1.1  riastrad 			MAX_PLOAD_CREDIT, 100))
     71  1.1  riastrad 		DRM_ERROR("DSI payload credits not released\n");
     72  1.1  riastrad }
     73  1.1  riastrad 
     74  1.1  riastrad static enum transcoder dsi_port_to_transcoder(enum port port)
     75  1.1  riastrad {
     76  1.1  riastrad 	if (port == PORT_A)
     77  1.1  riastrad 		return TRANSCODER_DSI_0;
     78  1.1  riastrad 	else
     79  1.1  riastrad 		return TRANSCODER_DSI_1;
     80  1.1  riastrad }
     81  1.1  riastrad 
     82  1.1  riastrad static void wait_for_cmds_dispatched_to_panel(struct intel_encoder *encoder)
     83  1.1  riastrad {
     84  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
     85  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
     86  1.1  riastrad 	struct mipi_dsi_device *dsi;
     87  1.1  riastrad 	enum port port;
     88  1.1  riastrad 	enum transcoder dsi_trans;
     89  1.1  riastrad 	int ret;
     90  1.1  riastrad 
     91  1.1  riastrad 	/* wait for header/payload credits to be released */
     92  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
     93  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
     94  1.1  riastrad 		wait_for_header_credits(dev_priv, dsi_trans);
     95  1.1  riastrad 		wait_for_payload_credits(dev_priv, dsi_trans);
     96  1.1  riastrad 	}
     97  1.1  riastrad 
     98  1.1  riastrad 	/* send nop DCS command */
     99  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    100  1.1  riastrad 		dsi = intel_dsi->dsi_hosts[port]->device;
    101  1.1  riastrad 		dsi->mode_flags |= MIPI_DSI_MODE_LPM;
    102  1.1  riastrad 		dsi->channel = 0;
    103  1.1  riastrad 		ret = mipi_dsi_dcs_nop(dsi);
    104  1.1  riastrad 		if (ret < 0)
    105  1.1  riastrad 			DRM_ERROR("error sending DCS NOP command\n");
    106  1.1  riastrad 	}
    107  1.1  riastrad 
    108  1.1  riastrad 	/* wait for header credits to be released */
    109  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    110  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
    111  1.1  riastrad 		wait_for_header_credits(dev_priv, dsi_trans);
    112  1.1  riastrad 	}
    113  1.1  riastrad 
    114  1.1  riastrad 	/* wait for LP TX in progress bit to be cleared */
    115  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    116  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
    117  1.1  riastrad 		if (wait_for_us(!(I915_READ(DSI_LP_MSG(dsi_trans)) &
    118  1.1  riastrad 				  LPTX_IN_PROGRESS), 20))
    119  1.1  riastrad 			DRM_ERROR("LPTX bit not cleared\n");
    120  1.1  riastrad 	}
    121  1.1  riastrad }
    122  1.1  riastrad 
    123  1.1  riastrad static bool add_payld_to_queue(struct intel_dsi_host *host, const u8 *data,
    124  1.1  riastrad 			       u32 len)
    125  1.1  riastrad {
    126  1.1  riastrad 	struct intel_dsi *intel_dsi = host->intel_dsi;
    127  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
    128  1.1  riastrad 	enum transcoder dsi_trans = dsi_port_to_transcoder(host->port);
    129  1.1  riastrad 	int free_credits;
    130  1.1  riastrad 	int i, j;
    131  1.1  riastrad 
    132  1.1  riastrad 	for (i = 0; i < len; i += 4) {
    133  1.1  riastrad 		u32 tmp = 0;
    134  1.1  riastrad 
    135  1.1  riastrad 		free_credits = payload_credits_available(dev_priv, dsi_trans);
    136  1.1  riastrad 		if (free_credits < 1) {
    137  1.1  riastrad 			DRM_ERROR("Payload credit not available\n");
    138  1.1  riastrad 			return false;
    139  1.1  riastrad 		}
    140  1.1  riastrad 
    141  1.1  riastrad 		for (j = 0; j < min_t(u32, len - i, 4); j++)
    142  1.1  riastrad 			tmp |= *data++ << 8 * j;
    143  1.1  riastrad 
    144  1.1  riastrad 		I915_WRITE(DSI_CMD_TXPYLD(dsi_trans), tmp);
    145  1.1  riastrad 	}
    146  1.1  riastrad 
    147  1.1  riastrad 	return true;
    148  1.1  riastrad }
    149  1.1  riastrad 
    150  1.1  riastrad static int dsi_send_pkt_hdr(struct intel_dsi_host *host,
    151  1.1  riastrad 			    struct mipi_dsi_packet pkt, bool enable_lpdt)
    152  1.1  riastrad {
    153  1.1  riastrad 	struct intel_dsi *intel_dsi = host->intel_dsi;
    154  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
    155  1.1  riastrad 	enum transcoder dsi_trans = dsi_port_to_transcoder(host->port);
    156  1.1  riastrad 	u32 tmp;
    157  1.1  riastrad 	int free_credits;
    158  1.1  riastrad 
    159  1.1  riastrad 	/* check if header credit available */
    160  1.1  riastrad 	free_credits = header_credits_available(dev_priv, dsi_trans);
    161  1.1  riastrad 	if (free_credits < 1) {
    162  1.1  riastrad 		DRM_ERROR("send pkt header failed, not enough hdr credits\n");
    163  1.1  riastrad 		return -1;
    164  1.1  riastrad 	}
    165  1.1  riastrad 
    166  1.1  riastrad 	tmp = I915_READ(DSI_CMD_TXHDR(dsi_trans));
    167  1.1  riastrad 
    168  1.1  riastrad 	if (pkt.payload)
    169  1.1  riastrad 		tmp |= PAYLOAD_PRESENT;
    170  1.1  riastrad 	else
    171  1.1  riastrad 		tmp &= ~PAYLOAD_PRESENT;
    172  1.1  riastrad 
    173  1.1  riastrad 	tmp &= ~VBLANK_FENCE;
    174  1.1  riastrad 
    175  1.1  riastrad 	if (enable_lpdt)
    176  1.1  riastrad 		tmp |= LP_DATA_TRANSFER;
    177  1.1  riastrad 
    178  1.1  riastrad 	tmp &= ~(PARAM_WC_MASK | VC_MASK | DT_MASK);
    179  1.1  riastrad 	tmp |= ((pkt.header[0] & VC_MASK) << VC_SHIFT);
    180  1.1  riastrad 	tmp |= ((pkt.header[0] & DT_MASK) << DT_SHIFT);
    181  1.1  riastrad 	tmp |= (pkt.header[1] << PARAM_WC_LOWER_SHIFT);
    182  1.1  riastrad 	tmp |= (pkt.header[2] << PARAM_WC_UPPER_SHIFT);
    183  1.1  riastrad 	I915_WRITE(DSI_CMD_TXHDR(dsi_trans), tmp);
    184  1.1  riastrad 
    185  1.1  riastrad 	return 0;
    186  1.1  riastrad }
    187  1.1  riastrad 
    188  1.1  riastrad static int dsi_send_pkt_payld(struct intel_dsi_host *host,
    189  1.1  riastrad 			      struct mipi_dsi_packet pkt)
    190  1.1  riastrad {
    191  1.1  riastrad 	/* payload queue can accept *256 bytes*, check limit */
    192  1.1  riastrad 	if (pkt.payload_length > MAX_PLOAD_CREDIT * 4) {
    193  1.1  riastrad 		DRM_ERROR("payload size exceeds max queue limit\n");
    194  1.1  riastrad 		return -1;
    195  1.1  riastrad 	}
    196  1.1  riastrad 
    197  1.1  riastrad 	/* load data into command payload queue */
    198  1.1  riastrad 	if (!add_payld_to_queue(host, pkt.payload,
    199  1.1  riastrad 				pkt.payload_length)) {
    200  1.1  riastrad 		DRM_ERROR("adding payload to queue failed\n");
    201  1.1  riastrad 		return -1;
    202  1.1  riastrad 	}
    203  1.1  riastrad 
    204  1.1  riastrad 	return 0;
    205  1.1  riastrad }
    206  1.1  riastrad 
    207  1.1  riastrad static void dsi_program_swing_and_deemphasis(struct intel_encoder *encoder)
    208  1.1  riastrad {
    209  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    210  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    211  1.1  riastrad 	enum phy phy;
    212  1.1  riastrad 	u32 tmp;
    213  1.1  riastrad 	int lane;
    214  1.1  riastrad 
    215  1.1  riastrad 	for_each_dsi_phy(phy, intel_dsi->phys) {
    216  1.1  riastrad 		/*
    217  1.1  riastrad 		 * Program voltage swing and pre-emphasis level values as per
    218  1.1  riastrad 		 * table in BSPEC under DDI buffer programing
    219  1.1  riastrad 		 */
    220  1.1  riastrad 		tmp = I915_READ(ICL_PORT_TX_DW5_LN0(phy));
    221  1.1  riastrad 		tmp &= ~(SCALING_MODE_SEL_MASK | RTERM_SELECT_MASK);
    222  1.1  riastrad 		tmp |= SCALING_MODE_SEL(0x2);
    223  1.1  riastrad 		tmp |= TAP2_DISABLE | TAP3_DISABLE;
    224  1.1  riastrad 		tmp |= RTERM_SELECT(0x6);
    225  1.1  riastrad 		I915_WRITE(ICL_PORT_TX_DW5_GRP(phy), tmp);
    226  1.1  riastrad 
    227  1.1  riastrad 		tmp = I915_READ(ICL_PORT_TX_DW5_AUX(phy));
    228  1.1  riastrad 		tmp &= ~(SCALING_MODE_SEL_MASK | RTERM_SELECT_MASK);
    229  1.1  riastrad 		tmp |= SCALING_MODE_SEL(0x2);
    230  1.1  riastrad 		tmp |= TAP2_DISABLE | TAP3_DISABLE;
    231  1.1  riastrad 		tmp |= RTERM_SELECT(0x6);
    232  1.1  riastrad 		I915_WRITE(ICL_PORT_TX_DW5_AUX(phy), tmp);
    233  1.1  riastrad 
    234  1.1  riastrad 		tmp = I915_READ(ICL_PORT_TX_DW2_LN0(phy));
    235  1.1  riastrad 		tmp &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK |
    236  1.1  riastrad 			 RCOMP_SCALAR_MASK);
    237  1.1  riastrad 		tmp |= SWING_SEL_UPPER(0x2);
    238  1.1  riastrad 		tmp |= SWING_SEL_LOWER(0x2);
    239  1.1  riastrad 		tmp |= RCOMP_SCALAR(0x98);
    240  1.1  riastrad 		I915_WRITE(ICL_PORT_TX_DW2_GRP(phy), tmp);
    241  1.1  riastrad 
    242  1.1  riastrad 		tmp = I915_READ(ICL_PORT_TX_DW2_AUX(phy));
    243  1.1  riastrad 		tmp &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK |
    244  1.1  riastrad 			 RCOMP_SCALAR_MASK);
    245  1.1  riastrad 		tmp |= SWING_SEL_UPPER(0x2);
    246  1.1  riastrad 		tmp |= SWING_SEL_LOWER(0x2);
    247  1.1  riastrad 		tmp |= RCOMP_SCALAR(0x98);
    248  1.1  riastrad 		I915_WRITE(ICL_PORT_TX_DW2_AUX(phy), tmp);
    249  1.1  riastrad 
    250  1.1  riastrad 		tmp = I915_READ(ICL_PORT_TX_DW4_AUX(phy));
    251  1.1  riastrad 		tmp &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK |
    252  1.1  riastrad 			 CURSOR_COEFF_MASK);
    253  1.1  riastrad 		tmp |= POST_CURSOR_1(0x0);
    254  1.1  riastrad 		tmp |= POST_CURSOR_2(0x0);
    255  1.1  riastrad 		tmp |= CURSOR_COEFF(0x3f);
    256  1.1  riastrad 		I915_WRITE(ICL_PORT_TX_DW4_AUX(phy), tmp);
    257  1.1  riastrad 
    258  1.1  riastrad 		for (lane = 0; lane <= 3; lane++) {
    259  1.1  riastrad 			/* Bspec: must not use GRP register for write */
    260  1.1  riastrad 			tmp = I915_READ(ICL_PORT_TX_DW4_LN(lane, phy));
    261  1.1  riastrad 			tmp &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK |
    262  1.1  riastrad 				 CURSOR_COEFF_MASK);
    263  1.1  riastrad 			tmp |= POST_CURSOR_1(0x0);
    264  1.1  riastrad 			tmp |= POST_CURSOR_2(0x0);
    265  1.1  riastrad 			tmp |= CURSOR_COEFF(0x3f);
    266  1.1  riastrad 			I915_WRITE(ICL_PORT_TX_DW4_LN(lane, phy), tmp);
    267  1.1  riastrad 		}
    268  1.1  riastrad 	}
    269  1.1  riastrad }
    270  1.1  riastrad 
    271  1.1  riastrad static void configure_dual_link_mode(struct intel_encoder *encoder,
    272  1.1  riastrad 				     const struct intel_crtc_state *pipe_config)
    273  1.1  riastrad {
    274  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    275  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    276  1.1  riastrad 	u32 dss_ctl1;
    277  1.1  riastrad 
    278  1.1  riastrad 	dss_ctl1 = I915_READ(DSS_CTL1);
    279  1.1  riastrad 	dss_ctl1 |= SPLITTER_ENABLE;
    280  1.1  riastrad 	dss_ctl1 &= ~OVERLAP_PIXELS_MASK;
    281  1.1  riastrad 	dss_ctl1 |= OVERLAP_PIXELS(intel_dsi->pixel_overlap);
    282  1.1  riastrad 
    283  1.1  riastrad 	if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
    284  1.1  riastrad 		const struct drm_display_mode *adjusted_mode =
    285  1.1  riastrad 					&pipe_config->hw.adjusted_mode;
    286  1.1  riastrad 		u32 dss_ctl2;
    287  1.1  riastrad 		u16 hactive = adjusted_mode->crtc_hdisplay;
    288  1.1  riastrad 		u16 dl_buffer_depth;
    289  1.1  riastrad 
    290  1.1  riastrad 		dss_ctl1 &= ~DUAL_LINK_MODE_INTERLEAVE;
    291  1.1  riastrad 		dl_buffer_depth = hactive / 2 + intel_dsi->pixel_overlap;
    292  1.1  riastrad 
    293  1.1  riastrad 		if (dl_buffer_depth > MAX_DL_BUFFER_TARGET_DEPTH)
    294  1.1  riastrad 			DRM_ERROR("DL buffer depth exceed max value\n");
    295  1.1  riastrad 
    296  1.1  riastrad 		dss_ctl1 &= ~LEFT_DL_BUF_TARGET_DEPTH_MASK;
    297  1.1  riastrad 		dss_ctl1 |= LEFT_DL_BUF_TARGET_DEPTH(dl_buffer_depth);
    298  1.1  riastrad 		dss_ctl2 = I915_READ(DSS_CTL2);
    299  1.1  riastrad 		dss_ctl2 &= ~RIGHT_DL_BUF_TARGET_DEPTH_MASK;
    300  1.1  riastrad 		dss_ctl2 |= RIGHT_DL_BUF_TARGET_DEPTH(dl_buffer_depth);
    301  1.1  riastrad 		I915_WRITE(DSS_CTL2, dss_ctl2);
    302  1.1  riastrad 	} else {
    303  1.1  riastrad 		/* Interleave */
    304  1.1  riastrad 		dss_ctl1 |= DUAL_LINK_MODE_INTERLEAVE;
    305  1.1  riastrad 	}
    306  1.1  riastrad 
    307  1.1  riastrad 	I915_WRITE(DSS_CTL1, dss_ctl1);
    308  1.1  riastrad }
    309  1.1  riastrad 
    310  1.1  riastrad /* aka DSI 8X clock */
    311  1.1  riastrad static int afe_clk(struct intel_encoder *encoder,
    312  1.1  riastrad 		   const struct intel_crtc_state *crtc_state)
    313  1.1  riastrad {
    314  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    315  1.1  riastrad 	int bpp;
    316  1.1  riastrad 
    317  1.1  riastrad 	if (crtc_state->dsc.compression_enable)
    318  1.1  riastrad 		bpp = crtc_state->dsc.compressed_bpp;
    319  1.1  riastrad 	else
    320  1.1  riastrad 		bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
    321  1.1  riastrad 
    322  1.1  riastrad 	return DIV_ROUND_CLOSEST(intel_dsi->pclk * bpp, intel_dsi->lane_count);
    323  1.1  riastrad }
    324  1.1  riastrad 
    325  1.1  riastrad static void gen11_dsi_program_esc_clk_div(struct intel_encoder *encoder,
    326  1.1  riastrad 					  const struct intel_crtc_state *crtc_state)
    327  1.1  riastrad {
    328  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    329  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    330  1.1  riastrad 	enum port port;
    331  1.1  riastrad 	int afe_clk_khz;
    332  1.1  riastrad 	u32 esc_clk_div_m;
    333  1.1  riastrad 
    334  1.1  riastrad 	afe_clk_khz = afe_clk(encoder, crtc_state);
    335  1.1  riastrad 	esc_clk_div_m = DIV_ROUND_UP(afe_clk_khz, DSI_MAX_ESC_CLK);
    336  1.1  riastrad 
    337  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    338  1.1  riastrad 		I915_WRITE(ICL_DSI_ESC_CLK_DIV(port),
    339  1.1  riastrad 			   esc_clk_div_m & ICL_ESC_CLK_DIV_MASK);
    340  1.1  riastrad 		POSTING_READ(ICL_DSI_ESC_CLK_DIV(port));
    341  1.1  riastrad 	}
    342  1.1  riastrad 
    343  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    344  1.1  riastrad 		I915_WRITE(ICL_DPHY_ESC_CLK_DIV(port),
    345  1.1  riastrad 			   esc_clk_div_m & ICL_ESC_CLK_DIV_MASK);
    346  1.1  riastrad 		POSTING_READ(ICL_DPHY_ESC_CLK_DIV(port));
    347  1.1  riastrad 	}
    348  1.1  riastrad }
    349  1.1  riastrad 
    350  1.1  riastrad static void get_dsi_io_power_domains(struct drm_i915_private *dev_priv,
    351  1.1  riastrad 				     struct intel_dsi *intel_dsi)
    352  1.1  riastrad {
    353  1.1  riastrad 	enum port port;
    354  1.1  riastrad 
    355  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    356  1.1  riastrad 		WARN_ON(intel_dsi->io_wakeref[port]);
    357  1.1  riastrad 		intel_dsi->io_wakeref[port] =
    358  1.1  riastrad 			intel_display_power_get(dev_priv,
    359  1.1  riastrad 						port == PORT_A ?
    360  1.1  riastrad 						POWER_DOMAIN_PORT_DDI_A_IO :
    361  1.1  riastrad 						POWER_DOMAIN_PORT_DDI_B_IO);
    362  1.1  riastrad 	}
    363  1.1  riastrad }
    364  1.1  riastrad 
    365  1.1  riastrad static void gen11_dsi_enable_io_power(struct intel_encoder *encoder)
    366  1.1  riastrad {
    367  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    368  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    369  1.1  riastrad 	enum port port;
    370  1.1  riastrad 	u32 tmp;
    371  1.1  riastrad 
    372  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    373  1.1  riastrad 		tmp = I915_READ(ICL_DSI_IO_MODECTL(port));
    374  1.1  riastrad 		tmp |= COMBO_PHY_MODE_DSI;
    375  1.1  riastrad 		I915_WRITE(ICL_DSI_IO_MODECTL(port), tmp);
    376  1.1  riastrad 	}
    377  1.1  riastrad 
    378  1.1  riastrad 	get_dsi_io_power_domains(dev_priv, intel_dsi);
    379  1.1  riastrad }
    380  1.1  riastrad 
    381  1.1  riastrad static void gen11_dsi_power_up_lanes(struct intel_encoder *encoder)
    382  1.1  riastrad {
    383  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    384  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    385  1.1  riastrad 	enum phy phy;
    386  1.1  riastrad 
    387  1.1  riastrad 	for_each_dsi_phy(phy, intel_dsi->phys)
    388  1.1  riastrad 		intel_combo_phy_power_up_lanes(dev_priv, phy, true,
    389  1.1  riastrad 					       intel_dsi->lane_count, false);
    390  1.1  riastrad }
    391  1.1  riastrad 
    392  1.1  riastrad static void gen11_dsi_config_phy_lanes_sequence(struct intel_encoder *encoder)
    393  1.1  riastrad {
    394  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    395  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    396  1.1  riastrad 	enum phy phy;
    397  1.1  riastrad 	u32 tmp;
    398  1.1  riastrad 	int lane;
    399  1.1  riastrad 
    400  1.1  riastrad 	/* Step 4b(i) set loadgen select for transmit and aux lanes */
    401  1.1  riastrad 	for_each_dsi_phy(phy, intel_dsi->phys) {
    402  1.1  riastrad 		tmp = I915_READ(ICL_PORT_TX_DW4_AUX(phy));
    403  1.1  riastrad 		tmp &= ~LOADGEN_SELECT;
    404  1.1  riastrad 		I915_WRITE(ICL_PORT_TX_DW4_AUX(phy), tmp);
    405  1.1  riastrad 		for (lane = 0; lane <= 3; lane++) {
    406  1.1  riastrad 			tmp = I915_READ(ICL_PORT_TX_DW4_LN(lane, phy));
    407  1.1  riastrad 			tmp &= ~LOADGEN_SELECT;
    408  1.1  riastrad 			if (lane != 2)
    409  1.1  riastrad 				tmp |= LOADGEN_SELECT;
    410  1.1  riastrad 			I915_WRITE(ICL_PORT_TX_DW4_LN(lane, phy), tmp);
    411  1.1  riastrad 		}
    412  1.1  riastrad 	}
    413  1.1  riastrad 
    414  1.1  riastrad 	/* Step 4b(ii) set latency optimization for transmit and aux lanes */
    415  1.1  riastrad 	for_each_dsi_phy(phy, intel_dsi->phys) {
    416  1.1  riastrad 		tmp = I915_READ(ICL_PORT_TX_DW2_AUX(phy));
    417  1.1  riastrad 		tmp &= ~FRC_LATENCY_OPTIM_MASK;
    418  1.1  riastrad 		tmp |= FRC_LATENCY_OPTIM_VAL(0x5);
    419  1.1  riastrad 		I915_WRITE(ICL_PORT_TX_DW2_AUX(phy), tmp);
    420  1.1  riastrad 		tmp = I915_READ(ICL_PORT_TX_DW2_LN0(phy));
    421  1.1  riastrad 		tmp &= ~FRC_LATENCY_OPTIM_MASK;
    422  1.1  riastrad 		tmp |= FRC_LATENCY_OPTIM_VAL(0x5);
    423  1.1  riastrad 		I915_WRITE(ICL_PORT_TX_DW2_GRP(phy), tmp);
    424  1.1  riastrad 
    425  1.1  riastrad 		/* For EHL, TGL, set latency optimization for PCS_DW1 lanes */
    426  1.1  riastrad 		if (IS_ELKHARTLAKE(dev_priv) || (INTEL_GEN(dev_priv) >= 12)) {
    427  1.1  riastrad 			tmp = I915_READ(ICL_PORT_PCS_DW1_AUX(phy));
    428  1.1  riastrad 			tmp &= ~LATENCY_OPTIM_MASK;
    429  1.1  riastrad 			tmp |= LATENCY_OPTIM_VAL(0);
    430  1.1  riastrad 			I915_WRITE(ICL_PORT_PCS_DW1_AUX(phy), tmp);
    431  1.1  riastrad 
    432  1.1  riastrad 			tmp = I915_READ(ICL_PORT_PCS_DW1_LN0(phy));
    433  1.1  riastrad 			tmp &= ~LATENCY_OPTIM_MASK;
    434  1.1  riastrad 			tmp |= LATENCY_OPTIM_VAL(0x1);
    435  1.1  riastrad 			I915_WRITE(ICL_PORT_PCS_DW1_GRP(phy), tmp);
    436  1.1  riastrad 		}
    437  1.1  riastrad 	}
    438  1.1  riastrad 
    439  1.1  riastrad }
    440  1.1  riastrad 
    441  1.1  riastrad static void gen11_dsi_voltage_swing_program_seq(struct intel_encoder *encoder)
    442  1.1  riastrad {
    443  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    444  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    445  1.1  riastrad 	u32 tmp;
    446  1.1  riastrad 	enum phy phy;
    447  1.1  riastrad 
    448  1.1  riastrad 	/* clear common keeper enable bit */
    449  1.1  riastrad 	for_each_dsi_phy(phy, intel_dsi->phys) {
    450  1.1  riastrad 		tmp = I915_READ(ICL_PORT_PCS_DW1_LN0(phy));
    451  1.1  riastrad 		tmp &= ~COMMON_KEEPER_EN;
    452  1.1  riastrad 		I915_WRITE(ICL_PORT_PCS_DW1_GRP(phy), tmp);
    453  1.1  riastrad 		tmp = I915_READ(ICL_PORT_PCS_DW1_AUX(phy));
    454  1.1  riastrad 		tmp &= ~COMMON_KEEPER_EN;
    455  1.1  riastrad 		I915_WRITE(ICL_PORT_PCS_DW1_AUX(phy), tmp);
    456  1.1  riastrad 	}
    457  1.1  riastrad 
    458  1.1  riastrad 	/*
    459  1.1  riastrad 	 * Set SUS Clock Config bitfield to 11b
    460  1.1  riastrad 	 * Note: loadgen select program is done
    461  1.1  riastrad 	 * as part of lane phy sequence configuration
    462  1.1  riastrad 	 */
    463  1.1  riastrad 	for_each_dsi_phy(phy, intel_dsi->phys) {
    464  1.1  riastrad 		tmp = I915_READ(ICL_PORT_CL_DW5(phy));
    465  1.1  riastrad 		tmp |= SUS_CLOCK_CONFIG;
    466  1.1  riastrad 		I915_WRITE(ICL_PORT_CL_DW5(phy), tmp);
    467  1.1  riastrad 	}
    468  1.1  riastrad 
    469  1.1  riastrad 	/* Clear training enable to change swing values */
    470  1.1  riastrad 	for_each_dsi_phy(phy, intel_dsi->phys) {
    471  1.1  riastrad 		tmp = I915_READ(ICL_PORT_TX_DW5_LN0(phy));
    472  1.1  riastrad 		tmp &= ~TX_TRAINING_EN;
    473  1.1  riastrad 		I915_WRITE(ICL_PORT_TX_DW5_GRP(phy), tmp);
    474  1.1  riastrad 		tmp = I915_READ(ICL_PORT_TX_DW5_AUX(phy));
    475  1.1  riastrad 		tmp &= ~TX_TRAINING_EN;
    476  1.1  riastrad 		I915_WRITE(ICL_PORT_TX_DW5_AUX(phy), tmp);
    477  1.1  riastrad 	}
    478  1.1  riastrad 
    479  1.1  riastrad 	/* Program swing and de-emphasis */
    480  1.1  riastrad 	dsi_program_swing_and_deemphasis(encoder);
    481  1.1  riastrad 
    482  1.1  riastrad 	/* Set training enable to trigger update */
    483  1.1  riastrad 	for_each_dsi_phy(phy, intel_dsi->phys) {
    484  1.1  riastrad 		tmp = I915_READ(ICL_PORT_TX_DW5_LN0(phy));
    485  1.1  riastrad 		tmp |= TX_TRAINING_EN;
    486  1.1  riastrad 		I915_WRITE(ICL_PORT_TX_DW5_GRP(phy), tmp);
    487  1.1  riastrad 		tmp = I915_READ(ICL_PORT_TX_DW5_AUX(phy));
    488  1.1  riastrad 		tmp |= TX_TRAINING_EN;
    489  1.1  riastrad 		I915_WRITE(ICL_PORT_TX_DW5_AUX(phy), tmp);
    490  1.1  riastrad 	}
    491  1.1  riastrad }
    492  1.1  riastrad 
    493  1.1  riastrad static void gen11_dsi_enable_ddi_buffer(struct intel_encoder *encoder)
    494  1.1  riastrad {
    495  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    496  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    497  1.1  riastrad 	u32 tmp;
    498  1.1  riastrad 	enum port port;
    499  1.1  riastrad 
    500  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    501  1.1  riastrad 		tmp = I915_READ(DDI_BUF_CTL(port));
    502  1.1  riastrad 		tmp |= DDI_BUF_CTL_ENABLE;
    503  1.1  riastrad 		I915_WRITE(DDI_BUF_CTL(port), tmp);
    504  1.1  riastrad 
    505  1.1  riastrad 		if (wait_for_us(!(I915_READ(DDI_BUF_CTL(port)) &
    506  1.1  riastrad 				  DDI_BUF_IS_IDLE),
    507  1.1  riastrad 				  500))
    508  1.1  riastrad 			DRM_ERROR("DDI port:%c buffer idle\n", port_name(port));
    509  1.1  riastrad 	}
    510  1.1  riastrad }
    511  1.1  riastrad 
    512  1.1  riastrad static void
    513  1.1  riastrad gen11_dsi_setup_dphy_timings(struct intel_encoder *encoder,
    514  1.1  riastrad 			     const struct intel_crtc_state *crtc_state)
    515  1.1  riastrad {
    516  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    517  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    518  1.1  riastrad 	u32 tmp;
    519  1.1  riastrad 	enum port port;
    520  1.1  riastrad 	enum phy phy;
    521  1.1  riastrad 
    522  1.1  riastrad 	/* Program T-INIT master registers */
    523  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    524  1.1  riastrad 		tmp = I915_READ(ICL_DSI_T_INIT_MASTER(port));
    525  1.1  riastrad 		tmp &= ~MASTER_INIT_TIMER_MASK;
    526  1.1  riastrad 		tmp |= intel_dsi->init_count;
    527  1.1  riastrad 		I915_WRITE(ICL_DSI_T_INIT_MASTER(port), tmp);
    528  1.1  riastrad 	}
    529  1.1  riastrad 
    530  1.1  riastrad 	/* Program DPHY clock lanes timings */
    531  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    532  1.1  riastrad 		I915_WRITE(DPHY_CLK_TIMING_PARAM(port), intel_dsi->dphy_reg);
    533  1.1  riastrad 
    534  1.1  riastrad 		/* shadow register inside display core */
    535  1.1  riastrad 		I915_WRITE(DSI_CLK_TIMING_PARAM(port), intel_dsi->dphy_reg);
    536  1.1  riastrad 	}
    537  1.1  riastrad 
    538  1.1  riastrad 	/* Program DPHY data lanes timings */
    539  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    540  1.1  riastrad 		I915_WRITE(DPHY_DATA_TIMING_PARAM(port),
    541  1.1  riastrad 			   intel_dsi->dphy_data_lane_reg);
    542  1.1  riastrad 
    543  1.1  riastrad 		/* shadow register inside display core */
    544  1.1  riastrad 		I915_WRITE(DSI_DATA_TIMING_PARAM(port),
    545  1.1  riastrad 			   intel_dsi->dphy_data_lane_reg);
    546  1.1  riastrad 	}
    547  1.1  riastrad 
    548  1.1  riastrad 	/*
    549  1.1  riastrad 	 * If DSI link operating at or below an 800 MHz,
    550  1.1  riastrad 	 * TA_SURE should be override and programmed to
    551  1.1  riastrad 	 * a value '0' inside TA_PARAM_REGISTERS otherwise
    552  1.1  riastrad 	 * leave all fields at HW default values.
    553  1.1  riastrad 	 */
    554  1.1  riastrad 	if (IS_GEN(dev_priv, 11)) {
    555  1.1  riastrad 		if (afe_clk(encoder, crtc_state) <= 800000) {
    556  1.1  riastrad 			for_each_dsi_port(port, intel_dsi->ports) {
    557  1.1  riastrad 				tmp = I915_READ(DPHY_TA_TIMING_PARAM(port));
    558  1.1  riastrad 				tmp &= ~TA_SURE_MASK;
    559  1.1  riastrad 				tmp |= TA_SURE_OVERRIDE | TA_SURE(0);
    560  1.1  riastrad 				I915_WRITE(DPHY_TA_TIMING_PARAM(port), tmp);
    561  1.1  riastrad 
    562  1.1  riastrad 				/* shadow register inside display core */
    563  1.1  riastrad 				tmp = I915_READ(DSI_TA_TIMING_PARAM(port));
    564  1.1  riastrad 				tmp &= ~TA_SURE_MASK;
    565  1.1  riastrad 				tmp |= TA_SURE_OVERRIDE | TA_SURE(0);
    566  1.1  riastrad 				I915_WRITE(DSI_TA_TIMING_PARAM(port), tmp);
    567  1.1  riastrad 			}
    568  1.1  riastrad 		}
    569  1.1  riastrad 	}
    570  1.1  riastrad 
    571  1.1  riastrad 	if (IS_ELKHARTLAKE(dev_priv)) {
    572  1.1  riastrad 		for_each_dsi_phy(phy, intel_dsi->phys) {
    573  1.1  riastrad 			tmp = I915_READ(ICL_DPHY_CHKN(phy));
    574  1.1  riastrad 			tmp |= ICL_DPHY_CHKN_AFE_OVER_PPI_STRAP;
    575  1.1  riastrad 			I915_WRITE(ICL_DPHY_CHKN(phy), tmp);
    576  1.1  riastrad 		}
    577  1.1  riastrad 	}
    578  1.1  riastrad }
    579  1.1  riastrad 
    580  1.1  riastrad static void gen11_dsi_gate_clocks(struct intel_encoder *encoder)
    581  1.1  riastrad {
    582  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    583  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    584  1.1  riastrad 	u32 tmp;
    585  1.1  riastrad 	enum phy phy;
    586  1.1  riastrad 
    587  1.1  riastrad 	mutex_lock(&dev_priv->dpll_lock);
    588  1.1  riastrad 	tmp = I915_READ(ICL_DPCLKA_CFGCR0);
    589  1.1  riastrad 	for_each_dsi_phy(phy, intel_dsi->phys)
    590  1.1  riastrad 		tmp |= ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy);
    591  1.1  riastrad 
    592  1.1  riastrad 	I915_WRITE(ICL_DPCLKA_CFGCR0, tmp);
    593  1.1  riastrad 	mutex_unlock(&dev_priv->dpll_lock);
    594  1.1  riastrad }
    595  1.1  riastrad 
    596  1.1  riastrad static void gen11_dsi_ungate_clocks(struct intel_encoder *encoder)
    597  1.1  riastrad {
    598  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    599  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    600  1.1  riastrad 	u32 tmp;
    601  1.1  riastrad 	enum phy phy;
    602  1.1  riastrad 
    603  1.1  riastrad 	mutex_lock(&dev_priv->dpll_lock);
    604  1.1  riastrad 	tmp = I915_READ(ICL_DPCLKA_CFGCR0);
    605  1.1  riastrad 	for_each_dsi_phy(phy, intel_dsi->phys)
    606  1.1  riastrad 		tmp &= ~ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy);
    607  1.1  riastrad 
    608  1.1  riastrad 	I915_WRITE(ICL_DPCLKA_CFGCR0, tmp);
    609  1.1  riastrad 	mutex_unlock(&dev_priv->dpll_lock);
    610  1.1  riastrad }
    611  1.1  riastrad 
    612  1.1  riastrad static void gen11_dsi_map_pll(struct intel_encoder *encoder,
    613  1.1  riastrad 			      const struct intel_crtc_state *crtc_state)
    614  1.1  riastrad {
    615  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    616  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    617  1.1  riastrad 	struct intel_shared_dpll *pll = crtc_state->shared_dpll;
    618  1.1  riastrad 	enum phy phy;
    619  1.1  riastrad 	u32 val;
    620  1.1  riastrad 
    621  1.1  riastrad 	mutex_lock(&dev_priv->dpll_lock);
    622  1.1  riastrad 
    623  1.1  riastrad 	val = I915_READ(ICL_DPCLKA_CFGCR0);
    624  1.1  riastrad 	for_each_dsi_phy(phy, intel_dsi->phys) {
    625  1.1  riastrad 		val &= ~ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
    626  1.1  riastrad 		val |= ICL_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy);
    627  1.1  riastrad 	}
    628  1.1  riastrad 	I915_WRITE(ICL_DPCLKA_CFGCR0, val);
    629  1.1  riastrad 
    630  1.1  riastrad 	for_each_dsi_phy(phy, intel_dsi->phys) {
    631  1.1  riastrad 		if (INTEL_GEN(dev_priv) >= 12)
    632  1.1  riastrad 			val |= ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy);
    633  1.1  riastrad 		else
    634  1.1  riastrad 			val &= ~ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy);
    635  1.1  riastrad 	}
    636  1.1  riastrad 	I915_WRITE(ICL_DPCLKA_CFGCR0, val);
    637  1.1  riastrad 
    638  1.1  riastrad 	POSTING_READ(ICL_DPCLKA_CFGCR0);
    639  1.1  riastrad 
    640  1.1  riastrad 	mutex_unlock(&dev_priv->dpll_lock);
    641  1.1  riastrad }
    642  1.1  riastrad 
    643  1.1  riastrad static void
    644  1.1  riastrad gen11_dsi_configure_transcoder(struct intel_encoder *encoder,
    645  1.1  riastrad 			       const struct intel_crtc_state *pipe_config)
    646  1.1  riastrad {
    647  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    648  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    649  1.1  riastrad 	struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc);
    650  1.1  riastrad 	enum pipe pipe = intel_crtc->pipe;
    651  1.1  riastrad 	u32 tmp;
    652  1.1  riastrad 	enum port port;
    653  1.1  riastrad 	enum transcoder dsi_trans;
    654  1.1  riastrad 
    655  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    656  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
    657  1.1  riastrad 		tmp = I915_READ(DSI_TRANS_FUNC_CONF(dsi_trans));
    658  1.1  riastrad 
    659  1.1  riastrad 		if (intel_dsi->eotp_pkt)
    660  1.1  riastrad 			tmp &= ~EOTP_DISABLED;
    661  1.1  riastrad 		else
    662  1.1  riastrad 			tmp |= EOTP_DISABLED;
    663  1.1  riastrad 
    664  1.1  riastrad 		/* enable link calibration if freq > 1.5Gbps */
    665  1.1  riastrad 		if (afe_clk(encoder, pipe_config) >= 1500 * 1000) {
    666  1.1  riastrad 			tmp &= ~LINK_CALIBRATION_MASK;
    667  1.1  riastrad 			tmp |= CALIBRATION_ENABLED_INITIAL_ONLY;
    668  1.1  riastrad 		}
    669  1.1  riastrad 
    670  1.1  riastrad 		/* configure continuous clock */
    671  1.1  riastrad 		tmp &= ~CONTINUOUS_CLK_MASK;
    672  1.1  riastrad 		if (intel_dsi->clock_stop)
    673  1.1  riastrad 			tmp |= CLK_ENTER_LP_AFTER_DATA;
    674  1.1  riastrad 		else
    675  1.1  riastrad 			tmp |= CLK_HS_CONTINUOUS;
    676  1.1  riastrad 
    677  1.1  riastrad 		/* configure buffer threshold limit to minimum */
    678  1.1  riastrad 		tmp &= ~PIX_BUF_THRESHOLD_MASK;
    679  1.1  riastrad 		tmp |= PIX_BUF_THRESHOLD_1_4;
    680  1.1  riastrad 
    681  1.1  riastrad 		/* set virtual channel to '0' */
    682  1.1  riastrad 		tmp &= ~PIX_VIRT_CHAN_MASK;
    683  1.1  riastrad 		tmp |= PIX_VIRT_CHAN(0);
    684  1.1  riastrad 
    685  1.1  riastrad 		/* program BGR transmission */
    686  1.1  riastrad 		if (intel_dsi->bgr_enabled)
    687  1.1  riastrad 			tmp |= BGR_TRANSMISSION;
    688  1.1  riastrad 
    689  1.1  riastrad 		/* select pixel format */
    690  1.1  riastrad 		tmp &= ~PIX_FMT_MASK;
    691  1.1  riastrad 		if (pipe_config->dsc.compression_enable) {
    692  1.1  riastrad 			tmp |= PIX_FMT_COMPRESSED;
    693  1.1  riastrad 		} else {
    694  1.1  riastrad 			switch (intel_dsi->pixel_format) {
    695  1.1  riastrad 			default:
    696  1.1  riastrad 				MISSING_CASE(intel_dsi->pixel_format);
    697  1.1  riastrad 				/* fallthrough */
    698  1.1  riastrad 			case MIPI_DSI_FMT_RGB565:
    699  1.1  riastrad 				tmp |= PIX_FMT_RGB565;
    700  1.1  riastrad 				break;
    701  1.1  riastrad 			case MIPI_DSI_FMT_RGB666_PACKED:
    702  1.1  riastrad 				tmp |= PIX_FMT_RGB666_PACKED;
    703  1.1  riastrad 				break;
    704  1.1  riastrad 			case MIPI_DSI_FMT_RGB666:
    705  1.1  riastrad 				tmp |= PIX_FMT_RGB666_LOOSE;
    706  1.1  riastrad 				break;
    707  1.1  riastrad 			case MIPI_DSI_FMT_RGB888:
    708  1.1  riastrad 				tmp |= PIX_FMT_RGB888;
    709  1.1  riastrad 				break;
    710  1.1  riastrad 			}
    711  1.1  riastrad 		}
    712  1.1  riastrad 
    713  1.1  riastrad 		if (INTEL_GEN(dev_priv) >= 12) {
    714  1.1  riastrad 			if (is_vid_mode(intel_dsi))
    715  1.1  riastrad 				tmp |= BLANKING_PACKET_ENABLE;
    716  1.1  riastrad 		}
    717  1.1  riastrad 
    718  1.1  riastrad 		/* program DSI operation mode */
    719  1.1  riastrad 		if (is_vid_mode(intel_dsi)) {
    720  1.1  riastrad 			tmp &= ~OP_MODE_MASK;
    721  1.1  riastrad 			switch (intel_dsi->video_mode_format) {
    722  1.1  riastrad 			default:
    723  1.1  riastrad 				MISSING_CASE(intel_dsi->video_mode_format);
    724  1.1  riastrad 				/* fallthrough */
    725  1.1  riastrad 			case VIDEO_MODE_NON_BURST_WITH_SYNC_EVENTS:
    726  1.1  riastrad 				tmp |= VIDEO_MODE_SYNC_EVENT;
    727  1.1  riastrad 				break;
    728  1.1  riastrad 			case VIDEO_MODE_NON_BURST_WITH_SYNC_PULSE:
    729  1.1  riastrad 				tmp |= VIDEO_MODE_SYNC_PULSE;
    730  1.1  riastrad 				break;
    731  1.1  riastrad 			}
    732  1.1  riastrad 		}
    733  1.1  riastrad 
    734  1.1  riastrad 		I915_WRITE(DSI_TRANS_FUNC_CONF(dsi_trans), tmp);
    735  1.1  riastrad 	}
    736  1.1  riastrad 
    737  1.1  riastrad 	/* enable port sync mode if dual link */
    738  1.1  riastrad 	if (intel_dsi->dual_link) {
    739  1.1  riastrad 		for_each_dsi_port(port, intel_dsi->ports) {
    740  1.1  riastrad 			dsi_trans = dsi_port_to_transcoder(port);
    741  1.1  riastrad 			tmp = I915_READ(TRANS_DDI_FUNC_CTL2(dsi_trans));
    742  1.1  riastrad 			tmp |= PORT_SYNC_MODE_ENABLE;
    743  1.1  riastrad 			I915_WRITE(TRANS_DDI_FUNC_CTL2(dsi_trans), tmp);
    744  1.1  riastrad 		}
    745  1.1  riastrad 
    746  1.1  riastrad 		/* configure stream splitting */
    747  1.1  riastrad 		configure_dual_link_mode(encoder, pipe_config);
    748  1.1  riastrad 	}
    749  1.1  riastrad 
    750  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    751  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
    752  1.1  riastrad 
    753  1.1  riastrad 		/* select data lane width */
    754  1.1  riastrad 		tmp = I915_READ(TRANS_DDI_FUNC_CTL(dsi_trans));
    755  1.1  riastrad 		tmp &= ~DDI_PORT_WIDTH_MASK;
    756  1.1  riastrad 		tmp |= DDI_PORT_WIDTH(intel_dsi->lane_count);
    757  1.1  riastrad 
    758  1.1  riastrad 		/* select input pipe */
    759  1.1  riastrad 		tmp &= ~TRANS_DDI_EDP_INPUT_MASK;
    760  1.1  riastrad 		switch (pipe) {
    761  1.1  riastrad 		default:
    762  1.1  riastrad 			MISSING_CASE(pipe);
    763  1.1  riastrad 			/* fallthrough */
    764  1.1  riastrad 		case PIPE_A:
    765  1.1  riastrad 			tmp |= TRANS_DDI_EDP_INPUT_A_ON;
    766  1.1  riastrad 			break;
    767  1.1  riastrad 		case PIPE_B:
    768  1.1  riastrad 			tmp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
    769  1.1  riastrad 			break;
    770  1.1  riastrad 		case PIPE_C:
    771  1.1  riastrad 			tmp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
    772  1.1  riastrad 			break;
    773  1.1  riastrad 		case PIPE_D:
    774  1.1  riastrad 			tmp |= TRANS_DDI_EDP_INPUT_D_ONOFF;
    775  1.1  riastrad 			break;
    776  1.1  riastrad 		}
    777  1.1  riastrad 
    778  1.1  riastrad 		/* enable DDI buffer */
    779  1.1  riastrad 		tmp |= TRANS_DDI_FUNC_ENABLE;
    780  1.1  riastrad 		I915_WRITE(TRANS_DDI_FUNC_CTL(dsi_trans), tmp);
    781  1.1  riastrad 	}
    782  1.1  riastrad 
    783  1.1  riastrad 	/* wait for link ready */
    784  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    785  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
    786  1.1  riastrad 		if (wait_for_us((I915_READ(DSI_TRANS_FUNC_CONF(dsi_trans)) &
    787  1.1  riastrad 				LINK_READY), 2500))
    788  1.1  riastrad 			DRM_ERROR("DSI link not ready\n");
    789  1.1  riastrad 	}
    790  1.1  riastrad }
    791  1.1  riastrad 
    792  1.1  riastrad static void
    793  1.1  riastrad gen11_dsi_set_transcoder_timings(struct intel_encoder *encoder,
    794  1.1  riastrad 				 const struct intel_crtc_state *crtc_state)
    795  1.1  riastrad {
    796  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    797  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    798  1.1  riastrad 	const struct drm_display_mode *adjusted_mode =
    799  1.1  riastrad 		&crtc_state->hw.adjusted_mode;
    800  1.1  riastrad 	enum port port;
    801  1.1  riastrad 	enum transcoder dsi_trans;
    802  1.1  riastrad 	/* horizontal timings */
    803  1.1  riastrad 	u16 htotal, hactive, hsync_start, hsync_end, hsync_size;
    804  1.1  riastrad 	u16 hback_porch;
    805  1.1  riastrad 	/* vertical timings */
    806  1.1  riastrad 	u16 vtotal, vactive, vsync_start, vsync_end, vsync_shift;
    807  1.1  riastrad 	int mul = 1, div = 1;
    808  1.1  riastrad 
    809  1.1  riastrad 	/*
    810  1.1  riastrad 	 * Adjust horizontal timings (htotal, hsync_start, hsync_end) to account
    811  1.1  riastrad 	 * for slower link speed if DSC is enabled.
    812  1.1  riastrad 	 *
    813  1.1  riastrad 	 * The compression frequency ratio is the ratio between compressed and
    814  1.1  riastrad 	 * non-compressed link speeds, and simplifies down to the ratio between
    815  1.1  riastrad 	 * compressed and non-compressed bpp.
    816  1.1  riastrad 	 */
    817  1.1  riastrad 	if (crtc_state->dsc.compression_enable) {
    818  1.1  riastrad 		mul = crtc_state->dsc.compressed_bpp;
    819  1.1  riastrad 		div = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
    820  1.1  riastrad 	}
    821  1.1  riastrad 
    822  1.1  riastrad 	hactive = adjusted_mode->crtc_hdisplay;
    823  1.1  riastrad 	htotal = DIV_ROUND_UP(adjusted_mode->crtc_htotal * mul, div);
    824  1.1  riastrad 	hsync_start = DIV_ROUND_UP(adjusted_mode->crtc_hsync_start * mul, div);
    825  1.1  riastrad 	hsync_end = DIV_ROUND_UP(adjusted_mode->crtc_hsync_end * mul, div);
    826  1.1  riastrad 	hsync_size  = hsync_end - hsync_start;
    827  1.1  riastrad 	hback_porch = (adjusted_mode->crtc_htotal -
    828  1.1  riastrad 		       adjusted_mode->crtc_hsync_end);
    829  1.1  riastrad 	vactive = adjusted_mode->crtc_vdisplay;
    830  1.1  riastrad 	vtotal = adjusted_mode->crtc_vtotal;
    831  1.1  riastrad 	vsync_start = adjusted_mode->crtc_vsync_start;
    832  1.1  riastrad 	vsync_end = adjusted_mode->crtc_vsync_end;
    833  1.1  riastrad 	vsync_shift = hsync_start - htotal / 2;
    834  1.1  riastrad 
    835  1.1  riastrad 	if (intel_dsi->dual_link) {
    836  1.1  riastrad 		hactive /= 2;
    837  1.1  riastrad 		if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
    838  1.1  riastrad 			hactive += intel_dsi->pixel_overlap;
    839  1.1  riastrad 		htotal /= 2;
    840  1.1  riastrad 	}
    841  1.1  riastrad 
    842  1.1  riastrad 	/* minimum hactive as per bspec: 256 pixels */
    843  1.1  riastrad 	if (adjusted_mode->crtc_hdisplay < 256)
    844  1.1  riastrad 		DRM_ERROR("hactive is less then 256 pixels\n");
    845  1.1  riastrad 
    846  1.1  riastrad 	/* if RGB666 format, then hactive must be multiple of 4 pixels */
    847  1.1  riastrad 	if (intel_dsi->pixel_format == MIPI_DSI_FMT_RGB666 && hactive % 4 != 0)
    848  1.1  riastrad 		DRM_ERROR("hactive pixels are not multiple of 4\n");
    849  1.1  riastrad 
    850  1.1  riastrad 	/* program TRANS_HTOTAL register */
    851  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    852  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
    853  1.1  riastrad 		I915_WRITE(HTOTAL(dsi_trans),
    854  1.1  riastrad 			   (hactive - 1) | ((htotal - 1) << 16));
    855  1.1  riastrad 	}
    856  1.1  riastrad 
    857  1.1  riastrad 	/* TRANS_HSYNC register to be programmed only for video mode */
    858  1.1  riastrad 	if (intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE) {
    859  1.1  riastrad 		if (intel_dsi->video_mode_format ==
    860  1.1  riastrad 		    VIDEO_MODE_NON_BURST_WITH_SYNC_PULSE) {
    861  1.1  riastrad 			/* BSPEC: hsync size should be atleast 16 pixels */
    862  1.1  riastrad 			if (hsync_size < 16)
    863  1.1  riastrad 				DRM_ERROR("hsync size < 16 pixels\n");
    864  1.1  riastrad 		}
    865  1.1  riastrad 
    866  1.1  riastrad 		if (hback_porch < 16)
    867  1.1  riastrad 			DRM_ERROR("hback porch < 16 pixels\n");
    868  1.1  riastrad 
    869  1.1  riastrad 		if (intel_dsi->dual_link) {
    870  1.1  riastrad 			hsync_start /= 2;
    871  1.1  riastrad 			hsync_end /= 2;
    872  1.1  riastrad 		}
    873  1.1  riastrad 
    874  1.1  riastrad 		for_each_dsi_port(port, intel_dsi->ports) {
    875  1.1  riastrad 			dsi_trans = dsi_port_to_transcoder(port);
    876  1.1  riastrad 			I915_WRITE(HSYNC(dsi_trans),
    877  1.1  riastrad 				   (hsync_start - 1) | ((hsync_end - 1) << 16));
    878  1.1  riastrad 		}
    879  1.1  riastrad 	}
    880  1.1  riastrad 
    881  1.1  riastrad 	/* program TRANS_VTOTAL register */
    882  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    883  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
    884  1.1  riastrad 		/*
    885  1.1  riastrad 		 * FIXME: Programing this by assuming progressive mode, since
    886  1.1  riastrad 		 * non-interlaced info from VBT is not saved inside
    887  1.1  riastrad 		 * struct drm_display_mode.
    888  1.1  riastrad 		 * For interlace mode: program required pixel minus 2
    889  1.1  riastrad 		 */
    890  1.1  riastrad 		I915_WRITE(VTOTAL(dsi_trans),
    891  1.1  riastrad 			   (vactive - 1) | ((vtotal - 1) << 16));
    892  1.1  riastrad 	}
    893  1.1  riastrad 
    894  1.1  riastrad 	if (vsync_end < vsync_start || vsync_end > vtotal)
    895  1.1  riastrad 		DRM_ERROR("Invalid vsync_end value\n");
    896  1.1  riastrad 
    897  1.1  riastrad 	if (vsync_start < vactive)
    898  1.1  riastrad 		DRM_ERROR("vsync_start less than vactive\n");
    899  1.1  riastrad 
    900  1.1  riastrad 	/* program TRANS_VSYNC register */
    901  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    902  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
    903  1.1  riastrad 		I915_WRITE(VSYNC(dsi_trans),
    904  1.1  riastrad 			   (vsync_start - 1) | ((vsync_end - 1) << 16));
    905  1.1  riastrad 	}
    906  1.1  riastrad 
    907  1.1  riastrad 	/*
    908  1.1  riastrad 	 * FIXME: It has to be programmed only for interlaced
    909  1.1  riastrad 	 * modes. Put the check condition here once interlaced
    910  1.1  riastrad 	 * info available as described above.
    911  1.1  riastrad 	 * program TRANS_VSYNCSHIFT register
    912  1.1  riastrad 	 */
    913  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    914  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
    915  1.1  riastrad 		I915_WRITE(VSYNCSHIFT(dsi_trans), vsync_shift);
    916  1.1  riastrad 	}
    917  1.1  riastrad 
    918  1.1  riastrad 	/* program TRANS_VBLANK register, should be same as vtotal programmed */
    919  1.1  riastrad 	if (INTEL_GEN(dev_priv) >= 12) {
    920  1.1  riastrad 		for_each_dsi_port(port, intel_dsi->ports) {
    921  1.1  riastrad 			dsi_trans = dsi_port_to_transcoder(port);
    922  1.1  riastrad 			I915_WRITE(VBLANK(dsi_trans),
    923  1.1  riastrad 				   (vactive - 1) | ((vtotal - 1) << 16));
    924  1.1  riastrad 		}
    925  1.1  riastrad 	}
    926  1.1  riastrad }
    927  1.1  riastrad 
    928  1.1  riastrad static void gen11_dsi_enable_transcoder(struct intel_encoder *encoder)
    929  1.1  riastrad {
    930  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    931  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    932  1.1  riastrad 	enum port port;
    933  1.1  riastrad 	enum transcoder dsi_trans;
    934  1.1  riastrad 	u32 tmp;
    935  1.1  riastrad 
    936  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    937  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
    938  1.1  riastrad 		tmp = I915_READ(PIPECONF(dsi_trans));
    939  1.1  riastrad 		tmp |= PIPECONF_ENABLE;
    940  1.1  riastrad 		I915_WRITE(PIPECONF(dsi_trans), tmp);
    941  1.1  riastrad 
    942  1.1  riastrad 		/* wait for transcoder to be enabled */
    943  1.1  riastrad 		if (intel_de_wait_for_set(dev_priv, PIPECONF(dsi_trans),
    944  1.1  riastrad 					  I965_PIPECONF_ACTIVE, 10))
    945  1.1  riastrad 			DRM_ERROR("DSI transcoder not enabled\n");
    946  1.1  riastrad 	}
    947  1.1  riastrad }
    948  1.1  riastrad 
    949  1.1  riastrad static void gen11_dsi_setup_timeouts(struct intel_encoder *encoder,
    950  1.1  riastrad 				     const struct intel_crtc_state *crtc_state)
    951  1.1  riastrad {
    952  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
    953  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
    954  1.1  riastrad 	enum port port;
    955  1.1  riastrad 	enum transcoder dsi_trans;
    956  1.1  riastrad 	u32 tmp, hs_tx_timeout, lp_rx_timeout, ta_timeout, divisor, mul;
    957  1.1  riastrad 
    958  1.1  riastrad 	/*
    959  1.1  riastrad 	 * escape clock count calculation:
    960  1.1  riastrad 	 * BYTE_CLK_COUNT = TIME_NS/(8 * UI)
    961  1.1  riastrad 	 * UI (nsec) = (10^6)/Bitrate
    962  1.1  riastrad 	 * TIME_NS = (BYTE_CLK_COUNT * 8 * 10^6)/ Bitrate
    963  1.1  riastrad 	 * ESCAPE_CLK_COUNT  = TIME_NS/ESC_CLK_NS
    964  1.1  riastrad 	 */
    965  1.1  riastrad 	divisor = intel_dsi_tlpx_ns(intel_dsi) * afe_clk(encoder, crtc_state) * 1000;
    966  1.1  riastrad 	mul = 8 * 1000000;
    967  1.1  riastrad 	hs_tx_timeout = DIV_ROUND_UP(intel_dsi->hs_tx_timeout * mul,
    968  1.1  riastrad 				     divisor);
    969  1.1  riastrad 	lp_rx_timeout = DIV_ROUND_UP(intel_dsi->lp_rx_timeout * mul, divisor);
    970  1.1  riastrad 	ta_timeout = DIV_ROUND_UP(intel_dsi->turn_arnd_val * mul, divisor);
    971  1.1  riastrad 
    972  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
    973  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
    974  1.1  riastrad 
    975  1.1  riastrad 		/* program hst_tx_timeout */
    976  1.1  riastrad 		tmp = I915_READ(DSI_HSTX_TO(dsi_trans));
    977  1.1  riastrad 		tmp &= ~HSTX_TIMEOUT_VALUE_MASK;
    978  1.1  riastrad 		tmp |= HSTX_TIMEOUT_VALUE(hs_tx_timeout);
    979  1.1  riastrad 		I915_WRITE(DSI_HSTX_TO(dsi_trans), tmp);
    980  1.1  riastrad 
    981  1.1  riastrad 		/* FIXME: DSI_CALIB_TO */
    982  1.1  riastrad 
    983  1.1  riastrad 		/* program lp_rx_host timeout */
    984  1.1  riastrad 		tmp = I915_READ(DSI_LPRX_HOST_TO(dsi_trans));
    985  1.1  riastrad 		tmp &= ~LPRX_TIMEOUT_VALUE_MASK;
    986  1.1  riastrad 		tmp |= LPRX_TIMEOUT_VALUE(lp_rx_timeout);
    987  1.1  riastrad 		I915_WRITE(DSI_LPRX_HOST_TO(dsi_trans), tmp);
    988  1.1  riastrad 
    989  1.1  riastrad 		/* FIXME: DSI_PWAIT_TO */
    990  1.1  riastrad 
    991  1.1  riastrad 		/* program turn around timeout */
    992  1.1  riastrad 		tmp = I915_READ(DSI_TA_TO(dsi_trans));
    993  1.1  riastrad 		tmp &= ~TA_TIMEOUT_VALUE_MASK;
    994  1.1  riastrad 		tmp |= TA_TIMEOUT_VALUE(ta_timeout);
    995  1.1  riastrad 		I915_WRITE(DSI_TA_TO(dsi_trans), tmp);
    996  1.1  riastrad 	}
    997  1.1  riastrad }
    998  1.1  riastrad 
    999  1.1  riastrad static void
   1000  1.1  riastrad gen11_dsi_enable_port_and_phy(struct intel_encoder *encoder,
   1001  1.1  riastrad 			      const struct intel_crtc_state *crtc_state)
   1002  1.1  riastrad {
   1003  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
   1004  1.1  riastrad 
   1005  1.1  riastrad 	/* step 4a: power up all lanes of the DDI used by DSI */
   1006  1.1  riastrad 	gen11_dsi_power_up_lanes(encoder);
   1007  1.1  riastrad 
   1008  1.1  riastrad 	/* step 4b: configure lane sequencing of the Combo-PHY transmitters */
   1009  1.1  riastrad 	gen11_dsi_config_phy_lanes_sequence(encoder);
   1010  1.1  riastrad 
   1011  1.1  riastrad 	/* step 4c: configure voltage swing and skew */
   1012  1.1  riastrad 	gen11_dsi_voltage_swing_program_seq(encoder);
   1013  1.1  riastrad 
   1014  1.1  riastrad 	/* enable DDI buffer */
   1015  1.1  riastrad 	gen11_dsi_enable_ddi_buffer(encoder);
   1016  1.1  riastrad 
   1017  1.1  riastrad 	/* setup D-PHY timings */
   1018  1.1  riastrad 	gen11_dsi_setup_dphy_timings(encoder, crtc_state);
   1019  1.1  riastrad 
   1020  1.1  riastrad 	/* step 4h: setup DSI protocol timeouts */
   1021  1.1  riastrad 	gen11_dsi_setup_timeouts(encoder, crtc_state);
   1022  1.1  riastrad 
   1023  1.1  riastrad 	/* Step (4h, 4i, 4j, 4k): Configure transcoder */
   1024  1.1  riastrad 	gen11_dsi_configure_transcoder(encoder, crtc_state);
   1025  1.1  riastrad 
   1026  1.1  riastrad 	/* Step 4l: Gate DDI clocks */
   1027  1.1  riastrad 	if (IS_GEN(dev_priv, 11))
   1028  1.1  riastrad 		gen11_dsi_gate_clocks(encoder);
   1029  1.1  riastrad }
   1030  1.1  riastrad 
   1031  1.1  riastrad static void gen11_dsi_powerup_panel(struct intel_encoder *encoder)
   1032  1.1  riastrad {
   1033  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
   1034  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
   1035  1.1  riastrad 	struct mipi_dsi_device *dsi;
   1036  1.1  riastrad 	enum port port;
   1037  1.1  riastrad 	enum transcoder dsi_trans;
   1038  1.1  riastrad 	u32 tmp;
   1039  1.1  riastrad 	int ret;
   1040  1.1  riastrad 
   1041  1.1  riastrad 	/* set maximum return packet size */
   1042  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
   1043  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
   1044  1.1  riastrad 
   1045  1.1  riastrad 		/*
   1046  1.1  riastrad 		 * FIXME: This uses the number of DW's currently in the payload
   1047  1.1  riastrad 		 * receive queue. This is probably not what we want here.
   1048  1.1  riastrad 		 */
   1049  1.1  riastrad 		tmp = I915_READ(DSI_CMD_RXCTL(dsi_trans));
   1050  1.1  riastrad 		tmp &= NUMBER_RX_PLOAD_DW_MASK;
   1051  1.1  riastrad 		/* multiply "Number Rx Payload DW" by 4 to get max value */
   1052  1.1  riastrad 		tmp = tmp * 4;
   1053  1.1  riastrad 		dsi = intel_dsi->dsi_hosts[port]->device;
   1054  1.1  riastrad 		ret = mipi_dsi_set_maximum_return_packet_size(dsi, tmp);
   1055  1.1  riastrad 		if (ret < 0)
   1056  1.1  riastrad 			DRM_ERROR("error setting max return pkt size%d\n", tmp);
   1057  1.1  riastrad 	}
   1058  1.1  riastrad 
   1059  1.1  riastrad 	/* panel power on related mipi dsi vbt sequences */
   1060  1.1  riastrad 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_ON);
   1061  1.1  riastrad 	intel_dsi_msleep(intel_dsi, intel_dsi->panel_on_delay);
   1062  1.1  riastrad 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DEASSERT_RESET);
   1063  1.1  riastrad 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_INIT_OTP);
   1064  1.1  riastrad 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON);
   1065  1.1  riastrad 
   1066  1.1  riastrad 	/* ensure all panel commands dispatched before enabling transcoder */
   1067  1.1  riastrad 	wait_for_cmds_dispatched_to_panel(encoder);
   1068  1.1  riastrad }
   1069  1.1  riastrad 
   1070  1.1  riastrad static void gen11_dsi_pre_pll_enable(struct intel_encoder *encoder,
   1071  1.1  riastrad 				     const struct intel_crtc_state *crtc_state,
   1072  1.1  riastrad 				     const struct drm_connector_state *conn_state)
   1073  1.1  riastrad {
   1074  1.1  riastrad 	/* step2: enable IO power */
   1075  1.1  riastrad 	gen11_dsi_enable_io_power(encoder);
   1076  1.1  riastrad 
   1077  1.1  riastrad 	/* step3: enable DSI PLL */
   1078  1.1  riastrad 	gen11_dsi_program_esc_clk_div(encoder, crtc_state);
   1079  1.1  riastrad }
   1080  1.1  riastrad 
   1081  1.1  riastrad static void gen11_dsi_pre_enable(struct intel_encoder *encoder,
   1082  1.1  riastrad 				 const struct intel_crtc_state *pipe_config,
   1083  1.1  riastrad 				 const struct drm_connector_state *conn_state)
   1084  1.1  riastrad {
   1085  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
   1086  1.1  riastrad 
   1087  1.1  riastrad 	/* step3b */
   1088  1.1  riastrad 	gen11_dsi_map_pll(encoder, pipe_config);
   1089  1.1  riastrad 
   1090  1.1  riastrad 	/* step4: enable DSI port and DPHY */
   1091  1.1  riastrad 	gen11_dsi_enable_port_and_phy(encoder, pipe_config);
   1092  1.1  riastrad 
   1093  1.1  riastrad 	/* step5: program and powerup panel */
   1094  1.1  riastrad 	gen11_dsi_powerup_panel(encoder);
   1095  1.1  riastrad 
   1096  1.1  riastrad 	intel_dsc_enable(encoder, pipe_config);
   1097  1.1  riastrad 
   1098  1.1  riastrad 	/* step6c: configure transcoder timings */
   1099  1.1  riastrad 	gen11_dsi_set_transcoder_timings(encoder, pipe_config);
   1100  1.1  riastrad 
   1101  1.1  riastrad 	/* step6d: enable dsi transcoder */
   1102  1.1  riastrad 	gen11_dsi_enable_transcoder(encoder);
   1103  1.1  riastrad 
   1104  1.1  riastrad 	/* step7: enable backlight */
   1105  1.1  riastrad 	intel_panel_enable_backlight(pipe_config, conn_state);
   1106  1.1  riastrad 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_ON);
   1107  1.1  riastrad }
   1108  1.1  riastrad 
   1109  1.1  riastrad static void gen11_dsi_disable_transcoder(struct intel_encoder *encoder)
   1110  1.1  riastrad {
   1111  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
   1112  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
   1113  1.1  riastrad 	enum port port;
   1114  1.1  riastrad 	enum transcoder dsi_trans;
   1115  1.1  riastrad 	u32 tmp;
   1116  1.1  riastrad 
   1117  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
   1118  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
   1119  1.1  riastrad 
   1120  1.1  riastrad 		/* disable transcoder */
   1121  1.1  riastrad 		tmp = I915_READ(PIPECONF(dsi_trans));
   1122  1.1  riastrad 		tmp &= ~PIPECONF_ENABLE;
   1123  1.1  riastrad 		I915_WRITE(PIPECONF(dsi_trans), tmp);
   1124  1.1  riastrad 
   1125  1.1  riastrad 		/* wait for transcoder to be disabled */
   1126  1.1  riastrad 		if (intel_de_wait_for_clear(dev_priv, PIPECONF(dsi_trans),
   1127  1.1  riastrad 					    I965_PIPECONF_ACTIVE, 50))
   1128  1.1  riastrad 			DRM_ERROR("DSI trancoder not disabled\n");
   1129  1.1  riastrad 	}
   1130  1.1  riastrad }
   1131  1.1  riastrad 
   1132  1.1  riastrad static void gen11_dsi_powerdown_panel(struct intel_encoder *encoder)
   1133  1.1  riastrad {
   1134  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
   1135  1.1  riastrad 
   1136  1.1  riastrad 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_OFF);
   1137  1.1  riastrad 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_ASSERT_RESET);
   1138  1.1  riastrad 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_OFF);
   1139  1.1  riastrad 
   1140  1.1  riastrad 	/* ensure cmds dispatched to panel */
   1141  1.1  riastrad 	wait_for_cmds_dispatched_to_panel(encoder);
   1142  1.1  riastrad }
   1143  1.1  riastrad 
   1144  1.1  riastrad static void gen11_dsi_deconfigure_trancoder(struct intel_encoder *encoder)
   1145  1.1  riastrad {
   1146  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
   1147  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
   1148  1.1  riastrad 	enum port port;
   1149  1.1  riastrad 	enum transcoder dsi_trans;
   1150  1.1  riastrad 	u32 tmp;
   1151  1.1  riastrad 
   1152  1.1  riastrad 	/* put dsi link in ULPS */
   1153  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
   1154  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
   1155  1.1  riastrad 		tmp = I915_READ(DSI_LP_MSG(dsi_trans));
   1156  1.1  riastrad 		tmp |= LINK_ENTER_ULPS;
   1157  1.1  riastrad 		tmp &= ~LINK_ULPS_TYPE_LP11;
   1158  1.1  riastrad 		I915_WRITE(DSI_LP_MSG(dsi_trans), tmp);
   1159  1.1  riastrad 
   1160  1.1  riastrad 		if (wait_for_us((I915_READ(DSI_LP_MSG(dsi_trans)) &
   1161  1.1  riastrad 				LINK_IN_ULPS),
   1162  1.1  riastrad 				10))
   1163  1.1  riastrad 			DRM_ERROR("DSI link not in ULPS\n");
   1164  1.1  riastrad 	}
   1165  1.1  riastrad 
   1166  1.1  riastrad 	/* disable ddi function */
   1167  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
   1168  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
   1169  1.1  riastrad 		tmp = I915_READ(TRANS_DDI_FUNC_CTL(dsi_trans));
   1170  1.1  riastrad 		tmp &= ~TRANS_DDI_FUNC_ENABLE;
   1171  1.1  riastrad 		I915_WRITE(TRANS_DDI_FUNC_CTL(dsi_trans), tmp);
   1172  1.1  riastrad 	}
   1173  1.1  riastrad 
   1174  1.1  riastrad 	/* disable port sync mode if dual link */
   1175  1.1  riastrad 	if (intel_dsi->dual_link) {
   1176  1.1  riastrad 		for_each_dsi_port(port, intel_dsi->ports) {
   1177  1.1  riastrad 			dsi_trans = dsi_port_to_transcoder(port);
   1178  1.1  riastrad 			tmp = I915_READ(TRANS_DDI_FUNC_CTL2(dsi_trans));
   1179  1.1  riastrad 			tmp &= ~PORT_SYNC_MODE_ENABLE;
   1180  1.1  riastrad 			I915_WRITE(TRANS_DDI_FUNC_CTL2(dsi_trans), tmp);
   1181  1.1  riastrad 		}
   1182  1.1  riastrad 	}
   1183  1.1  riastrad }
   1184  1.1  riastrad 
   1185  1.1  riastrad static void gen11_dsi_disable_port(struct intel_encoder *encoder)
   1186  1.1  riastrad {
   1187  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
   1188  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
   1189  1.1  riastrad 	u32 tmp;
   1190  1.1  riastrad 	enum port port;
   1191  1.1  riastrad 
   1192  1.1  riastrad 	gen11_dsi_ungate_clocks(encoder);
   1193  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
   1194  1.1  riastrad 		tmp = I915_READ(DDI_BUF_CTL(port));
   1195  1.1  riastrad 		tmp &= ~DDI_BUF_CTL_ENABLE;
   1196  1.1  riastrad 		I915_WRITE(DDI_BUF_CTL(port), tmp);
   1197  1.1  riastrad 
   1198  1.1  riastrad 		if (wait_for_us((I915_READ(DDI_BUF_CTL(port)) &
   1199  1.1  riastrad 				 DDI_BUF_IS_IDLE),
   1200  1.1  riastrad 				 8))
   1201  1.1  riastrad 			DRM_ERROR("DDI port:%c buffer not idle\n",
   1202  1.1  riastrad 				  port_name(port));
   1203  1.1  riastrad 	}
   1204  1.1  riastrad 	gen11_dsi_gate_clocks(encoder);
   1205  1.1  riastrad }
   1206  1.1  riastrad 
   1207  1.1  riastrad static void gen11_dsi_disable_io_power(struct intel_encoder *encoder)
   1208  1.1  riastrad {
   1209  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
   1210  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
   1211  1.1  riastrad 	enum port port;
   1212  1.1  riastrad 	u32 tmp;
   1213  1.1  riastrad 
   1214  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
   1215  1.1  riastrad 		intel_wakeref_t wakeref;
   1216  1.1  riastrad 
   1217  1.1  riastrad 		wakeref = fetch_and_zero(&intel_dsi->io_wakeref[port]);
   1218  1.1  riastrad 		intel_display_power_put(dev_priv,
   1219  1.1  riastrad 					port == PORT_A ?
   1220  1.1  riastrad 					POWER_DOMAIN_PORT_DDI_A_IO :
   1221  1.1  riastrad 					POWER_DOMAIN_PORT_DDI_B_IO,
   1222  1.1  riastrad 					wakeref);
   1223  1.1  riastrad 	}
   1224  1.1  riastrad 
   1225  1.1  riastrad 	/* set mode to DDI */
   1226  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
   1227  1.1  riastrad 		tmp = I915_READ(ICL_DSI_IO_MODECTL(port));
   1228  1.1  riastrad 		tmp &= ~COMBO_PHY_MODE_DSI;
   1229  1.1  riastrad 		I915_WRITE(ICL_DSI_IO_MODECTL(port), tmp);
   1230  1.1  riastrad 	}
   1231  1.1  riastrad }
   1232  1.1  riastrad 
   1233  1.1  riastrad static void gen11_dsi_disable(struct intel_encoder *encoder,
   1234  1.1  riastrad 			      const struct intel_crtc_state *old_crtc_state,
   1235  1.1  riastrad 			      const struct drm_connector_state *old_conn_state)
   1236  1.1  riastrad {
   1237  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
   1238  1.1  riastrad 
   1239  1.1  riastrad 	/* step1: turn off backlight */
   1240  1.1  riastrad 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_OFF);
   1241  1.1  riastrad 	intel_panel_disable_backlight(old_conn_state);
   1242  1.1  riastrad 
   1243  1.1  riastrad 	/* step2d,e: disable transcoder and wait */
   1244  1.1  riastrad 	gen11_dsi_disable_transcoder(encoder);
   1245  1.1  riastrad 
   1246  1.1  riastrad 	/* step2f,g: powerdown panel */
   1247  1.1  riastrad 	gen11_dsi_powerdown_panel(encoder);
   1248  1.1  riastrad 
   1249  1.1  riastrad 	/* step2h,i,j: deconfig trancoder */
   1250  1.1  riastrad 	gen11_dsi_deconfigure_trancoder(encoder);
   1251  1.1  riastrad 
   1252  1.1  riastrad 	/* step3: disable port */
   1253  1.1  riastrad 	gen11_dsi_disable_port(encoder);
   1254  1.1  riastrad 
   1255  1.1  riastrad 	/* step4: disable IO power */
   1256  1.1  riastrad 	gen11_dsi_disable_io_power(encoder);
   1257  1.1  riastrad }
   1258  1.1  riastrad 
   1259  1.1  riastrad static void gen11_dsi_post_disable(struct intel_encoder *encoder,
   1260  1.1  riastrad 				   const struct intel_crtc_state *old_crtc_state,
   1261  1.1  riastrad 				   const struct drm_connector_state *old_conn_state)
   1262  1.1  riastrad {
   1263  1.1  riastrad 	intel_crtc_vblank_off(old_crtc_state);
   1264  1.1  riastrad 
   1265  1.1  riastrad 	intel_dsc_disable(old_crtc_state);
   1266  1.1  riastrad 
   1267  1.1  riastrad 	skl_scaler_disable(old_crtc_state);
   1268  1.1  riastrad }
   1269  1.1  riastrad 
   1270  1.1  riastrad static enum drm_mode_status gen11_dsi_mode_valid(struct drm_connector *connector,
   1271  1.1  riastrad 						 struct drm_display_mode *mode)
   1272  1.1  riastrad {
   1273  1.1  riastrad 	/* FIXME: DSC? */
   1274  1.1  riastrad 	return intel_dsi_mode_valid(connector, mode);
   1275  1.1  riastrad }
   1276  1.1  riastrad 
   1277  1.1  riastrad static void gen11_dsi_get_timings(struct intel_encoder *encoder,
   1278  1.1  riastrad 				  struct intel_crtc_state *pipe_config)
   1279  1.1  riastrad {
   1280  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
   1281  1.1  riastrad 	struct drm_display_mode *adjusted_mode =
   1282  1.1  riastrad 					&pipe_config->hw.adjusted_mode;
   1283  1.1  riastrad 
   1284  1.1  riastrad 	if (pipe_config->dsc.compressed_bpp) {
   1285  1.1  riastrad 		int div = pipe_config->dsc.compressed_bpp;
   1286  1.1  riastrad 		int mul = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
   1287  1.1  riastrad 
   1288  1.1  riastrad 		adjusted_mode->crtc_htotal =
   1289  1.1  riastrad 			DIV_ROUND_UP(adjusted_mode->crtc_htotal * mul, div);
   1290  1.1  riastrad 		adjusted_mode->crtc_hsync_start =
   1291  1.1  riastrad 			DIV_ROUND_UP(adjusted_mode->crtc_hsync_start * mul, div);
   1292  1.1  riastrad 		adjusted_mode->crtc_hsync_end =
   1293  1.1  riastrad 			DIV_ROUND_UP(adjusted_mode->crtc_hsync_end * mul, div);
   1294  1.1  riastrad 	}
   1295  1.1  riastrad 
   1296  1.1  riastrad 	if (intel_dsi->dual_link) {
   1297  1.1  riastrad 		adjusted_mode->crtc_hdisplay *= 2;
   1298  1.1  riastrad 		if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
   1299  1.1  riastrad 			adjusted_mode->crtc_hdisplay -=
   1300  1.1  riastrad 						intel_dsi->pixel_overlap;
   1301  1.1  riastrad 		adjusted_mode->crtc_htotal *= 2;
   1302  1.1  riastrad 	}
   1303  1.1  riastrad 	adjusted_mode->crtc_hblank_start = adjusted_mode->crtc_hdisplay;
   1304  1.1  riastrad 	adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_htotal;
   1305  1.1  riastrad 
   1306  1.1  riastrad 	if (intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE) {
   1307  1.1  riastrad 		if (intel_dsi->dual_link) {
   1308  1.1  riastrad 			adjusted_mode->crtc_hsync_start *= 2;
   1309  1.1  riastrad 			adjusted_mode->crtc_hsync_end *= 2;
   1310  1.1  riastrad 		}
   1311  1.1  riastrad 	}
   1312  1.1  riastrad 	adjusted_mode->crtc_vblank_start = adjusted_mode->crtc_vdisplay;
   1313  1.1  riastrad 	adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vtotal;
   1314  1.1  riastrad }
   1315  1.1  riastrad 
   1316  1.1  riastrad static void gen11_dsi_get_config(struct intel_encoder *encoder,
   1317  1.1  riastrad 				 struct intel_crtc_state *pipe_config)
   1318  1.1  riastrad {
   1319  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
   1320  1.1  riastrad 	struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
   1321  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
   1322  1.1  riastrad 
   1323  1.1  riastrad 	intel_dsc_get_config(encoder, pipe_config);
   1324  1.1  riastrad 
   1325  1.1  riastrad 	/* FIXME: adapt icl_ddi_clock_get() for DSI and use that? */
   1326  1.1  riastrad 	pipe_config->port_clock =
   1327  1.1  riastrad 		cnl_calc_wrpll_link(dev_priv, &pipe_config->dpll_hw_state);
   1328  1.1  riastrad 
   1329  1.1  riastrad 	pipe_config->hw.adjusted_mode.crtc_clock = intel_dsi->pclk;
   1330  1.1  riastrad 	if (intel_dsi->dual_link)
   1331  1.1  riastrad 		pipe_config->hw.adjusted_mode.crtc_clock *= 2;
   1332  1.1  riastrad 
   1333  1.1  riastrad 	gen11_dsi_get_timings(encoder, pipe_config);
   1334  1.1  riastrad 	pipe_config->output_types |= BIT(INTEL_OUTPUT_DSI);
   1335  1.1  riastrad 	pipe_config->pipe_bpp = bdw_get_pipemisc_bpp(crtc);
   1336  1.1  riastrad }
   1337  1.1  riastrad 
   1338  1.1  riastrad static int gen11_dsi_dsc_compute_config(struct intel_encoder *encoder,
   1339  1.1  riastrad 					struct intel_crtc_state *crtc_state)
   1340  1.1  riastrad {
   1341  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
   1342  1.1  riastrad 	struct drm_dsc_config *vdsc_cfg = &crtc_state->dsc.config;
   1343  1.1  riastrad 	int dsc_max_bpc = INTEL_GEN(dev_priv) >= 12 ? 12 : 10;
   1344  1.1  riastrad 	bool use_dsc;
   1345  1.1  riastrad 	int ret;
   1346  1.1  riastrad 
   1347  1.1  riastrad 	use_dsc = intel_bios_get_dsc_params(encoder, crtc_state, dsc_max_bpc);
   1348  1.1  riastrad 	if (!use_dsc)
   1349  1.1  riastrad 		return 0;
   1350  1.1  riastrad 
   1351  1.1  riastrad 	if (crtc_state->pipe_bpp < 8 * 3)
   1352  1.1  riastrad 		return -EINVAL;
   1353  1.1  riastrad 
   1354  1.1  riastrad 	/* FIXME: split only when necessary */
   1355  1.1  riastrad 	if (crtc_state->dsc.slice_count > 1)
   1356  1.1  riastrad 		crtc_state->dsc.dsc_split = true;
   1357  1.1  riastrad 
   1358  1.1  riastrad 	vdsc_cfg->convert_rgb = true;
   1359  1.1  riastrad 
   1360  1.1  riastrad 	ret = intel_dsc_compute_params(encoder, crtc_state);
   1361  1.1  riastrad 	if (ret)
   1362  1.1  riastrad 		return ret;
   1363  1.1  riastrad 
   1364  1.1  riastrad 	/* DSI specific sanity checks on the common code */
   1365  1.1  riastrad 	WARN_ON(vdsc_cfg->vbr_enable);
   1366  1.1  riastrad 	WARN_ON(vdsc_cfg->simple_422);
   1367  1.1  riastrad 	WARN_ON(vdsc_cfg->pic_width % vdsc_cfg->slice_width);
   1368  1.1  riastrad 	WARN_ON(vdsc_cfg->slice_height < 8);
   1369  1.1  riastrad 	WARN_ON(vdsc_cfg->pic_height % vdsc_cfg->slice_height);
   1370  1.1  riastrad 
   1371  1.1  riastrad 	ret = drm_dsc_compute_rc_parameters(vdsc_cfg);
   1372  1.1  riastrad 	if (ret)
   1373  1.1  riastrad 		return ret;
   1374  1.1  riastrad 
   1375  1.1  riastrad 	crtc_state->dsc.compression_enable = true;
   1376  1.1  riastrad 
   1377  1.1  riastrad 	return 0;
   1378  1.1  riastrad }
   1379  1.1  riastrad 
   1380  1.1  riastrad static int gen11_dsi_compute_config(struct intel_encoder *encoder,
   1381  1.1  riastrad 				    struct intel_crtc_state *pipe_config,
   1382  1.1  riastrad 				    struct drm_connector_state *conn_state)
   1383  1.1  riastrad {
   1384  1.1  riastrad 	struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
   1385  1.1  riastrad 						   base);
   1386  1.1  riastrad 	struct intel_connector *intel_connector = intel_dsi->attached_connector;
   1387  1.1  riastrad 	struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
   1388  1.1  riastrad 	const struct drm_display_mode *fixed_mode =
   1389  1.1  riastrad 					intel_connector->panel.fixed_mode;
   1390  1.1  riastrad 	struct drm_display_mode *adjusted_mode =
   1391  1.1  riastrad 					&pipe_config->hw.adjusted_mode;
   1392  1.1  riastrad 
   1393  1.1  riastrad 	pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
   1394  1.1  riastrad 	intel_fixed_panel_mode(fixed_mode, adjusted_mode);
   1395  1.1  riastrad 	intel_pch_panel_fitting(crtc, pipe_config, conn_state->scaling_mode);
   1396  1.1  riastrad 
   1397  1.1  riastrad 	adjusted_mode->flags = 0;
   1398  1.1  riastrad 
   1399  1.1  riastrad 	/* Dual link goes to trancoder DSI'0' */
   1400  1.1  riastrad 	if (intel_dsi->ports == BIT(PORT_B))
   1401  1.1  riastrad 		pipe_config->cpu_transcoder = TRANSCODER_DSI_1;
   1402  1.1  riastrad 	else
   1403  1.1  riastrad 		pipe_config->cpu_transcoder = TRANSCODER_DSI_0;
   1404  1.1  riastrad 
   1405  1.1  riastrad 	if (intel_dsi->pixel_format == MIPI_DSI_FMT_RGB888)
   1406  1.1  riastrad 		pipe_config->pipe_bpp = 24;
   1407  1.1  riastrad 	else
   1408  1.1  riastrad 		pipe_config->pipe_bpp = 18;
   1409  1.1  riastrad 
   1410  1.1  riastrad 	pipe_config->clock_set = true;
   1411  1.1  riastrad 
   1412  1.1  riastrad 	if (gen11_dsi_dsc_compute_config(encoder, pipe_config))
   1413  1.1  riastrad 		DRM_DEBUG_KMS("Attempting to use DSC failed\n");
   1414  1.1  riastrad 
   1415  1.1  riastrad 	pipe_config->port_clock = afe_clk(encoder, pipe_config) / 5;
   1416  1.1  riastrad 
   1417  1.1  riastrad 	return 0;
   1418  1.1  riastrad }
   1419  1.1  riastrad 
   1420  1.1  riastrad static void gen11_dsi_get_power_domains(struct intel_encoder *encoder,
   1421  1.1  riastrad 					struct intel_crtc_state *crtc_state)
   1422  1.1  riastrad {
   1423  1.1  riastrad 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
   1424  1.1  riastrad 
   1425  1.1  riastrad 	get_dsi_io_power_domains(i915,
   1426  1.1  riastrad 				 enc_to_intel_dsi(encoder));
   1427  1.1  riastrad 
   1428  1.1  riastrad 	if (crtc_state->dsc.compression_enable)
   1429  1.1  riastrad 		intel_display_power_get(i915,
   1430  1.1  riastrad 					intel_dsc_power_domain(crtc_state));
   1431  1.1  riastrad }
   1432  1.1  riastrad 
   1433  1.1  riastrad static bool gen11_dsi_get_hw_state(struct intel_encoder *encoder,
   1434  1.1  riastrad 				   enum pipe *pipe)
   1435  1.1  riastrad {
   1436  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
   1437  1.1  riastrad 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
   1438  1.1  riastrad 	enum transcoder dsi_trans;
   1439  1.1  riastrad 	intel_wakeref_t wakeref;
   1440  1.1  riastrad 	enum port port;
   1441  1.1  riastrad 	bool ret = false;
   1442  1.1  riastrad 	u32 tmp;
   1443  1.1  riastrad 
   1444  1.1  riastrad 	wakeref = intel_display_power_get_if_enabled(dev_priv,
   1445  1.1  riastrad 						     encoder->power_domain);
   1446  1.1  riastrad 	if (!wakeref)
   1447  1.1  riastrad 		return false;
   1448  1.1  riastrad 
   1449  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
   1450  1.1  riastrad 		dsi_trans = dsi_port_to_transcoder(port);
   1451  1.1  riastrad 		tmp = I915_READ(TRANS_DDI_FUNC_CTL(dsi_trans));
   1452  1.1  riastrad 		switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
   1453  1.1  riastrad 		case TRANS_DDI_EDP_INPUT_A_ON:
   1454  1.1  riastrad 			*pipe = PIPE_A;
   1455  1.1  riastrad 			break;
   1456  1.1  riastrad 		case TRANS_DDI_EDP_INPUT_B_ONOFF:
   1457  1.1  riastrad 			*pipe = PIPE_B;
   1458  1.1  riastrad 			break;
   1459  1.1  riastrad 		case TRANS_DDI_EDP_INPUT_C_ONOFF:
   1460  1.1  riastrad 			*pipe = PIPE_C;
   1461  1.1  riastrad 			break;
   1462  1.1  riastrad 		case TRANS_DDI_EDP_INPUT_D_ONOFF:
   1463  1.1  riastrad 			*pipe = PIPE_D;
   1464  1.1  riastrad 			break;
   1465  1.1  riastrad 		default:
   1466  1.1  riastrad 			DRM_ERROR("Invalid PIPE input\n");
   1467  1.1  riastrad 			goto out;
   1468  1.1  riastrad 		}
   1469  1.1  riastrad 
   1470  1.1  riastrad 		tmp = I915_READ(PIPECONF(dsi_trans));
   1471  1.1  riastrad 		ret = tmp & PIPECONF_ENABLE;
   1472  1.1  riastrad 	}
   1473  1.1  riastrad out:
   1474  1.1  riastrad 	intel_display_power_put(dev_priv, encoder->power_domain, wakeref);
   1475  1.1  riastrad 	return ret;
   1476  1.1  riastrad }
   1477  1.1  riastrad 
   1478  1.1  riastrad static void gen11_dsi_encoder_destroy(struct drm_encoder *encoder)
   1479  1.1  riastrad {
   1480  1.1  riastrad 	intel_encoder_destroy(encoder);
   1481  1.1  riastrad }
   1482  1.1  riastrad 
   1483  1.1  riastrad static const struct drm_encoder_funcs gen11_dsi_encoder_funcs = {
   1484  1.1  riastrad 	.destroy = gen11_dsi_encoder_destroy,
   1485  1.1  riastrad };
   1486  1.1  riastrad 
   1487  1.1  riastrad static const struct drm_connector_funcs gen11_dsi_connector_funcs = {
   1488  1.1  riastrad 	.late_register = intel_connector_register,
   1489  1.1  riastrad 	.early_unregister = intel_connector_unregister,
   1490  1.1  riastrad 	.destroy = intel_connector_destroy,
   1491  1.1  riastrad 	.fill_modes = drm_helper_probe_single_connector_modes,
   1492  1.1  riastrad 	.atomic_get_property = intel_digital_connector_atomic_get_property,
   1493  1.1  riastrad 	.atomic_set_property = intel_digital_connector_atomic_set_property,
   1494  1.1  riastrad 	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
   1495  1.1  riastrad 	.atomic_duplicate_state = intel_digital_connector_duplicate_state,
   1496  1.1  riastrad };
   1497  1.1  riastrad 
   1498  1.1  riastrad static const struct drm_connector_helper_funcs gen11_dsi_connector_helper_funcs = {
   1499  1.1  riastrad 	.get_modes = intel_dsi_get_modes,
   1500  1.1  riastrad 	.mode_valid = gen11_dsi_mode_valid,
   1501  1.1  riastrad 	.atomic_check = intel_digital_connector_atomic_check,
   1502  1.1  riastrad };
   1503  1.1  riastrad 
   1504  1.1  riastrad static int gen11_dsi_host_attach(struct mipi_dsi_host *host,
   1505  1.1  riastrad 				 struct mipi_dsi_device *dsi)
   1506  1.1  riastrad {
   1507  1.1  riastrad 	return 0;
   1508  1.1  riastrad }
   1509  1.1  riastrad 
   1510  1.1  riastrad static int gen11_dsi_host_detach(struct mipi_dsi_host *host,
   1511  1.1  riastrad 				 struct mipi_dsi_device *dsi)
   1512  1.1  riastrad {
   1513  1.1  riastrad 	return 0;
   1514  1.1  riastrad }
   1515  1.1  riastrad 
   1516  1.1  riastrad static ssize_t gen11_dsi_host_transfer(struct mipi_dsi_host *host,
   1517  1.1  riastrad 				       const struct mipi_dsi_msg *msg)
   1518  1.1  riastrad {
   1519  1.1  riastrad 	struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host);
   1520  1.1  riastrad 	struct mipi_dsi_packet dsi_pkt;
   1521  1.1  riastrad 	ssize_t ret;
   1522  1.1  riastrad 	bool enable_lpdt = false;
   1523  1.1  riastrad 
   1524  1.1  riastrad 	ret = mipi_dsi_create_packet(&dsi_pkt, msg);
   1525  1.1  riastrad 	if (ret < 0)
   1526  1.1  riastrad 		return ret;
   1527  1.1  riastrad 
   1528  1.1  riastrad 	if (msg->flags & MIPI_DSI_MSG_USE_LPM)
   1529  1.1  riastrad 		enable_lpdt = true;
   1530  1.1  riastrad 
   1531  1.1  riastrad 	/* send packet header */
   1532  1.1  riastrad 	ret  = dsi_send_pkt_hdr(intel_dsi_host, dsi_pkt, enable_lpdt);
   1533  1.1  riastrad 	if (ret < 0)
   1534  1.1  riastrad 		return ret;
   1535  1.1  riastrad 
   1536  1.1  riastrad 	/* only long packet contains payload */
   1537  1.1  riastrad 	if (mipi_dsi_packet_format_is_long(msg->type)) {
   1538  1.1  riastrad 		ret = dsi_send_pkt_payld(intel_dsi_host, dsi_pkt);
   1539  1.1  riastrad 		if (ret < 0)
   1540  1.1  riastrad 			return ret;
   1541  1.1  riastrad 	}
   1542  1.1  riastrad 
   1543  1.1  riastrad 	//TODO: add payload receive code if needed
   1544  1.1  riastrad 
   1545  1.1  riastrad 	ret = sizeof(dsi_pkt.header) + dsi_pkt.payload_length;
   1546  1.1  riastrad 
   1547  1.1  riastrad 	return ret;
   1548  1.1  riastrad }
   1549  1.1  riastrad 
   1550  1.1  riastrad static const struct mipi_dsi_host_ops gen11_dsi_host_ops = {
   1551  1.1  riastrad 	.attach = gen11_dsi_host_attach,
   1552  1.1  riastrad 	.detach = gen11_dsi_host_detach,
   1553  1.1  riastrad 	.transfer = gen11_dsi_host_transfer,
   1554  1.1  riastrad };
   1555  1.1  riastrad 
   1556  1.1  riastrad #define ICL_PREPARE_CNT_MAX	0x7
   1557  1.1  riastrad #define ICL_CLK_ZERO_CNT_MAX	0xf
   1558  1.1  riastrad #define ICL_TRAIL_CNT_MAX	0x7
   1559  1.1  riastrad #define ICL_TCLK_PRE_CNT_MAX	0x3
   1560  1.1  riastrad #define ICL_TCLK_POST_CNT_MAX	0x7
   1561  1.1  riastrad #define ICL_HS_ZERO_CNT_MAX	0xf
   1562  1.1  riastrad #define ICL_EXIT_ZERO_CNT_MAX	0x7
   1563  1.1  riastrad 
   1564  1.1  riastrad static void icl_dphy_param_init(struct intel_dsi *intel_dsi)
   1565  1.1  riastrad {
   1566  1.1  riastrad 	struct drm_device *dev = intel_dsi->base.base.dev;
   1567  1.1  riastrad 	struct drm_i915_private *dev_priv = to_i915(dev);
   1568  1.1  riastrad 	struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;
   1569  1.1  riastrad 	u32 tlpx_ns;
   1570  1.1  riastrad 	u32 prepare_cnt, exit_zero_cnt, clk_zero_cnt, trail_cnt;
   1571  1.1  riastrad 	u32 ths_prepare_ns, tclk_trail_ns;
   1572  1.1  riastrad 	u32 hs_zero_cnt;
   1573  1.1  riastrad 	u32 tclk_pre_cnt, tclk_post_cnt;
   1574  1.1  riastrad 
   1575  1.1  riastrad 	tlpx_ns = intel_dsi_tlpx_ns(intel_dsi);
   1576  1.1  riastrad 
   1577  1.1  riastrad 	tclk_trail_ns = max(mipi_config->tclk_trail, mipi_config->ths_trail);
   1578  1.1  riastrad 	ths_prepare_ns = max(mipi_config->ths_prepare,
   1579  1.1  riastrad 			     mipi_config->tclk_prepare);
   1580  1.1  riastrad 
   1581  1.1  riastrad 	/*
   1582  1.1  riastrad 	 * prepare cnt in escape clocks
   1583  1.1  riastrad 	 * this field represents a hexadecimal value with a precision
   1584  1.1  riastrad 	 * of 1.2  i.e. the most significant bit is the integer
   1585  1.1  riastrad 	 * and the least significant 2 bits are fraction bits.
   1586  1.1  riastrad 	 * so, the field can represent a range of 0.25 to 1.75
   1587  1.1  riastrad 	 */
   1588  1.1  riastrad 	prepare_cnt = DIV_ROUND_UP(ths_prepare_ns * 4, tlpx_ns);
   1589  1.1  riastrad 	if (prepare_cnt > ICL_PREPARE_CNT_MAX) {
   1590  1.1  riastrad 		DRM_DEBUG_KMS("prepare_cnt out of range (%d)\n", prepare_cnt);
   1591  1.1  riastrad 		prepare_cnt = ICL_PREPARE_CNT_MAX;
   1592  1.1  riastrad 	}
   1593  1.1  riastrad 
   1594  1.1  riastrad 	/* clk zero count in escape clocks */
   1595  1.1  riastrad 	clk_zero_cnt = DIV_ROUND_UP(mipi_config->tclk_prepare_clkzero -
   1596  1.1  riastrad 				    ths_prepare_ns, tlpx_ns);
   1597  1.1  riastrad 	if (clk_zero_cnt > ICL_CLK_ZERO_CNT_MAX) {
   1598  1.1  riastrad 		DRM_DEBUG_KMS("clk_zero_cnt out of range (%d)\n", clk_zero_cnt);
   1599  1.1  riastrad 		clk_zero_cnt = ICL_CLK_ZERO_CNT_MAX;
   1600  1.1  riastrad 	}
   1601  1.1  riastrad 
   1602  1.1  riastrad 	/* trail cnt in escape clocks*/
   1603  1.1  riastrad 	trail_cnt = DIV_ROUND_UP(tclk_trail_ns, tlpx_ns);
   1604  1.1  riastrad 	if (trail_cnt > ICL_TRAIL_CNT_MAX) {
   1605  1.1  riastrad 		DRM_DEBUG_KMS("trail_cnt out of range (%d)\n", trail_cnt);
   1606  1.1  riastrad 		trail_cnt = ICL_TRAIL_CNT_MAX;
   1607  1.1  riastrad 	}
   1608  1.1  riastrad 
   1609  1.1  riastrad 	/* tclk pre count in escape clocks */
   1610  1.1  riastrad 	tclk_pre_cnt = DIV_ROUND_UP(mipi_config->tclk_pre, tlpx_ns);
   1611  1.1  riastrad 	if (tclk_pre_cnt > ICL_TCLK_PRE_CNT_MAX) {
   1612  1.1  riastrad 		DRM_DEBUG_KMS("tclk_pre_cnt out of range (%d)\n", tclk_pre_cnt);
   1613  1.1  riastrad 		tclk_pre_cnt = ICL_TCLK_PRE_CNT_MAX;
   1614  1.1  riastrad 	}
   1615  1.1  riastrad 
   1616  1.1  riastrad 	/* tclk post count in escape clocks */
   1617  1.1  riastrad 	tclk_post_cnt = DIV_ROUND_UP(mipi_config->tclk_post, tlpx_ns);
   1618  1.1  riastrad 	if (tclk_post_cnt > ICL_TCLK_POST_CNT_MAX) {
   1619  1.1  riastrad 		DRM_DEBUG_KMS("tclk_post_cnt out of range (%d)\n", tclk_post_cnt);
   1620  1.1  riastrad 		tclk_post_cnt = ICL_TCLK_POST_CNT_MAX;
   1621  1.1  riastrad 	}
   1622  1.1  riastrad 
   1623  1.1  riastrad 	/* hs zero cnt in escape clocks */
   1624  1.1  riastrad 	hs_zero_cnt = DIV_ROUND_UP(mipi_config->ths_prepare_hszero -
   1625  1.1  riastrad 				   ths_prepare_ns, tlpx_ns);
   1626  1.1  riastrad 	if (hs_zero_cnt > ICL_HS_ZERO_CNT_MAX) {
   1627  1.1  riastrad 		DRM_DEBUG_KMS("hs_zero_cnt out of range (%d)\n", hs_zero_cnt);
   1628  1.1  riastrad 		hs_zero_cnt = ICL_HS_ZERO_CNT_MAX;
   1629  1.1  riastrad 	}
   1630  1.1  riastrad 
   1631  1.1  riastrad 	/* hs exit zero cnt in escape clocks */
   1632  1.1  riastrad 	exit_zero_cnt = DIV_ROUND_UP(mipi_config->ths_exit, tlpx_ns);
   1633  1.1  riastrad 	if (exit_zero_cnt > ICL_EXIT_ZERO_CNT_MAX) {
   1634  1.1  riastrad 		DRM_DEBUG_KMS("exit_zero_cnt out of range (%d)\n", exit_zero_cnt);
   1635  1.1  riastrad 		exit_zero_cnt = ICL_EXIT_ZERO_CNT_MAX;
   1636  1.1  riastrad 	}
   1637  1.1  riastrad 
   1638  1.1  riastrad 	/* clock lane dphy timings */
   1639  1.1  riastrad 	intel_dsi->dphy_reg = (CLK_PREPARE_OVERRIDE |
   1640  1.1  riastrad 			       CLK_PREPARE(prepare_cnt) |
   1641  1.1  riastrad 			       CLK_ZERO_OVERRIDE |
   1642  1.1  riastrad 			       CLK_ZERO(clk_zero_cnt) |
   1643  1.1  riastrad 			       CLK_PRE_OVERRIDE |
   1644  1.1  riastrad 			       CLK_PRE(tclk_pre_cnt) |
   1645  1.1  riastrad 			       CLK_POST_OVERRIDE |
   1646  1.1  riastrad 			       CLK_POST(tclk_post_cnt) |
   1647  1.1  riastrad 			       CLK_TRAIL_OVERRIDE |
   1648  1.1  riastrad 			       CLK_TRAIL(trail_cnt));
   1649  1.1  riastrad 
   1650  1.1  riastrad 	/* data lanes dphy timings */
   1651  1.1  riastrad 	intel_dsi->dphy_data_lane_reg = (HS_PREPARE_OVERRIDE |
   1652  1.1  riastrad 					 HS_PREPARE(prepare_cnt) |
   1653  1.1  riastrad 					 HS_ZERO_OVERRIDE |
   1654  1.1  riastrad 					 HS_ZERO(hs_zero_cnt) |
   1655  1.1  riastrad 					 HS_TRAIL_OVERRIDE |
   1656  1.1  riastrad 					 HS_TRAIL(trail_cnt) |
   1657  1.1  riastrad 					 HS_EXIT_OVERRIDE |
   1658  1.1  riastrad 					 HS_EXIT(exit_zero_cnt));
   1659  1.1  riastrad 
   1660  1.1  riastrad 	intel_dsi_log_params(intel_dsi);
   1661  1.1  riastrad }
   1662  1.1  riastrad 
   1663  1.1  riastrad static void icl_dsi_add_properties(struct intel_connector *connector)
   1664  1.1  riastrad {
   1665  1.1  riastrad 	u32 allowed_scalers;
   1666  1.1  riastrad 
   1667  1.1  riastrad 	allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) |
   1668  1.1  riastrad 			   BIT(DRM_MODE_SCALE_FULLSCREEN) |
   1669  1.1  riastrad 			   BIT(DRM_MODE_SCALE_CENTER);
   1670  1.1  riastrad 
   1671  1.1  riastrad 	drm_connector_attach_scaling_mode_property(&connector->base,
   1672  1.1  riastrad 						   allowed_scalers);
   1673  1.1  riastrad 
   1674  1.1  riastrad 	connector->base.state->scaling_mode = DRM_MODE_SCALE_ASPECT;
   1675  1.1  riastrad 
   1676  1.1  riastrad 	connector->base.display_info.panel_orientation =
   1677  1.1  riastrad 			intel_dsi_get_panel_orientation(connector);
   1678  1.1  riastrad 	drm_connector_init_panel_orientation_property(&connector->base,
   1679  1.1  riastrad 				connector->panel.fixed_mode->hdisplay,
   1680  1.1  riastrad 				connector->panel.fixed_mode->vdisplay);
   1681  1.1  riastrad }
   1682  1.1  riastrad 
   1683  1.1  riastrad void icl_dsi_init(struct drm_i915_private *dev_priv)
   1684  1.1  riastrad {
   1685  1.1  riastrad 	struct drm_device *dev = &dev_priv->drm;
   1686  1.1  riastrad 	struct intel_dsi *intel_dsi;
   1687  1.1  riastrad 	struct intel_encoder *encoder;
   1688  1.1  riastrad 	struct intel_connector *intel_connector;
   1689  1.1  riastrad 	struct drm_connector *connector;
   1690  1.1  riastrad 	struct drm_display_mode *fixed_mode;
   1691  1.1  riastrad 	enum port port;
   1692  1.1  riastrad 
   1693  1.1  riastrad 	if (!intel_bios_is_dsi_present(dev_priv, &port))
   1694  1.1  riastrad 		return;
   1695  1.1  riastrad 
   1696  1.1  riastrad 	intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
   1697  1.1  riastrad 	if (!intel_dsi)
   1698  1.1  riastrad 		return;
   1699  1.1  riastrad 
   1700  1.1  riastrad 	intel_connector = intel_connector_alloc();
   1701  1.1  riastrad 	if (!intel_connector) {
   1702  1.1  riastrad 		kfree(intel_dsi);
   1703  1.1  riastrad 		return;
   1704  1.1  riastrad 	}
   1705  1.1  riastrad 
   1706  1.1  riastrad 	encoder = &intel_dsi->base;
   1707  1.1  riastrad 	intel_dsi->attached_connector = intel_connector;
   1708  1.1  riastrad 	connector = &intel_connector->base;
   1709  1.1  riastrad 
   1710  1.1  riastrad 	/* register DSI encoder with DRM subsystem */
   1711  1.1  riastrad 	drm_encoder_init(dev, &encoder->base, &gen11_dsi_encoder_funcs,
   1712  1.1  riastrad 			 DRM_MODE_ENCODER_DSI, "DSI %c", port_name(port));
   1713  1.1  riastrad 
   1714  1.1  riastrad 	encoder->pre_pll_enable = gen11_dsi_pre_pll_enable;
   1715  1.1  riastrad 	encoder->pre_enable = gen11_dsi_pre_enable;
   1716  1.1  riastrad 	encoder->disable = gen11_dsi_disable;
   1717  1.1  riastrad 	encoder->post_disable = gen11_dsi_post_disable;
   1718  1.1  riastrad 	encoder->port = port;
   1719  1.1  riastrad 	encoder->get_config = gen11_dsi_get_config;
   1720  1.1  riastrad 	encoder->update_pipe = intel_panel_update_backlight;
   1721  1.1  riastrad 	encoder->compute_config = gen11_dsi_compute_config;
   1722  1.1  riastrad 	encoder->get_hw_state = gen11_dsi_get_hw_state;
   1723  1.1  riastrad 	encoder->type = INTEL_OUTPUT_DSI;
   1724  1.1  riastrad 	encoder->cloneable = 0;
   1725  1.1  riastrad 	encoder->pipe_mask = ~0;
   1726  1.1  riastrad 	encoder->power_domain = POWER_DOMAIN_PORT_DSI;
   1727  1.1  riastrad 	encoder->get_power_domains = gen11_dsi_get_power_domains;
   1728  1.1  riastrad 
   1729  1.1  riastrad 	/* register DSI connector with DRM subsystem */
   1730  1.1  riastrad 	drm_connector_init(dev, connector, &gen11_dsi_connector_funcs,
   1731  1.1  riastrad 			   DRM_MODE_CONNECTOR_DSI);
   1732  1.1  riastrad 	drm_connector_helper_add(connector, &gen11_dsi_connector_helper_funcs);
   1733  1.1  riastrad 	connector->display_info.subpixel_order = SubPixelHorizontalRGB;
   1734  1.1  riastrad 	connector->interlace_allowed = false;
   1735  1.1  riastrad 	connector->doublescan_allowed = false;
   1736  1.1  riastrad 	intel_connector->get_hw_state = intel_connector_get_hw_state;
   1737  1.1  riastrad 
   1738  1.1  riastrad 	/* attach connector to encoder */
   1739  1.1  riastrad 	intel_connector_attach_encoder(intel_connector, encoder);
   1740  1.1  riastrad 
   1741  1.1  riastrad 	mutex_lock(&dev->mode_config.mutex);
   1742  1.1  riastrad 	fixed_mode = intel_panel_vbt_fixed_mode(intel_connector);
   1743  1.1  riastrad 	mutex_unlock(&dev->mode_config.mutex);
   1744  1.1  riastrad 
   1745  1.1  riastrad 	if (!fixed_mode) {
   1746  1.1  riastrad 		DRM_ERROR("DSI fixed mode info missing\n");
   1747  1.1  riastrad 		goto err;
   1748  1.1  riastrad 	}
   1749  1.1  riastrad 
   1750  1.1  riastrad 	intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
   1751  1.1  riastrad 	intel_panel_setup_backlight(connector, INVALID_PIPE);
   1752  1.1  riastrad 
   1753  1.1  riastrad 	if (dev_priv->vbt.dsi.config->dual_link)
   1754  1.1  riastrad 		intel_dsi->ports = BIT(PORT_A) | BIT(PORT_B);
   1755  1.1  riastrad 	else
   1756  1.1  riastrad 		intel_dsi->ports = BIT(port);
   1757  1.1  riastrad 
   1758  1.1  riastrad 	intel_dsi->dcs_backlight_ports = dev_priv->vbt.dsi.bl_ports;
   1759  1.1  riastrad 	intel_dsi->dcs_cabc_ports = dev_priv->vbt.dsi.cabc_ports;
   1760  1.1  riastrad 
   1761  1.1  riastrad 	for_each_dsi_port(port, intel_dsi->ports) {
   1762  1.1  riastrad 		struct intel_dsi_host *host;
   1763  1.1  riastrad 
   1764  1.1  riastrad 		host = intel_dsi_host_init(intel_dsi, &gen11_dsi_host_ops, port);
   1765  1.1  riastrad 		if (!host)
   1766  1.1  riastrad 			goto err;
   1767  1.1  riastrad 
   1768  1.1  riastrad 		intel_dsi->dsi_hosts[port] = host;
   1769  1.1  riastrad 	}
   1770  1.1  riastrad 
   1771  1.1  riastrad 	if (!intel_dsi_vbt_init(intel_dsi, MIPI_DSI_GENERIC_PANEL_ID)) {
   1772  1.1  riastrad 		DRM_DEBUG_KMS("no device found\n");
   1773  1.1  riastrad 		goto err;
   1774  1.1  riastrad 	}
   1775  1.1  riastrad 
   1776  1.1  riastrad 	icl_dphy_param_init(intel_dsi);
   1777  1.1  riastrad 
   1778  1.1  riastrad 	icl_dsi_add_properties(intel_connector);
   1779  1.1  riastrad 	return;
   1780  1.1  riastrad 
   1781  1.1  riastrad err:
   1782  1.1  riastrad 	drm_encoder_cleanup(&encoder->base);
   1783  1.1  riastrad 	kfree(intel_dsi);
   1784  1.1  riastrad 	kfree(intel_connector);
   1785  1.1  riastrad }
   1786