xref: /linux/drivers/gpu/drm/i915/display/vlv_dsi.c (revision 714b1cdb02ee670be1ec5b1190377fef3845acd9)
1379bc100SJani Nikula /*
2379bc100SJani Nikula  * Copyright © 2013 Intel Corporation
3379bc100SJani Nikula  *
4379bc100SJani Nikula  * Permission is hereby granted, free of charge, to any person obtaining a
5379bc100SJani Nikula  * copy of this software and associated documentation files (the "Software"),
6379bc100SJani Nikula  * to deal in the Software without restriction, including without limitation
7379bc100SJani Nikula  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8379bc100SJani Nikula  * and/or sell copies of the Software, and to permit persons to whom the
9379bc100SJani Nikula  * Software is furnished to do so, subject to the following conditions:
10379bc100SJani Nikula  *
11379bc100SJani Nikula  * The above copyright notice and this permission notice (including the next
12379bc100SJani Nikula  * paragraph) shall be included in all copies or substantial portions of the
13379bc100SJani Nikula  * Software.
14379bc100SJani Nikula  *
15379bc100SJani Nikula  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16379bc100SJani Nikula  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17379bc100SJani Nikula  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18379bc100SJani Nikula  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19379bc100SJani Nikula  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20379bc100SJani Nikula  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21379bc100SJani Nikula  * DEALINGS IN THE SOFTWARE.
22379bc100SJani Nikula  *
23379bc100SJani Nikula  * Author: Jani Nikula <jani.nikula@intel.com>
24379bc100SJani Nikula  */
25379bc100SJani Nikula 
26379bc100SJani Nikula #include <linux/slab.h>
27379bc100SJani Nikula 
28379bc100SJani Nikula #include <drm/drm_atomic_helper.h>
29379bc100SJani Nikula #include <drm/drm_crtc.h>
30379bc100SJani Nikula #include <drm/drm_edid.h>
31379bc100SJani Nikula #include <drm/drm_mipi_dsi.h>
32379bc100SJani Nikula 
33379bc100SJani Nikula #include "i915_drv.h"
34379bc100SJani Nikula #include "intel_atomic.h"
35379bc100SJani Nikula #include "intel_connector.h"
361d455f8dSJani Nikula #include "intel_display_types.h"
37379bc100SJani Nikula #include "intel_dsi.h"
38379bc100SJani Nikula #include "intel_fifo_underrun.h"
39379bc100SJani Nikula #include "intel_panel.h"
40379bc100SJani Nikula #include "intel_sideband.h"
41*714b1cdbSDave Airlie #include "skl_scaler.h"
42379bc100SJani Nikula 
43379bc100SJani Nikula /* return pixels in terms of txbyteclkhs */
44379bc100SJani Nikula static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
45379bc100SJani Nikula 		       u16 burst_mode_ratio)
46379bc100SJani Nikula {
47379bc100SJani Nikula 	return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
48379bc100SJani Nikula 					 8 * 100), lane_count);
49379bc100SJani Nikula }
50379bc100SJani Nikula 
51379bc100SJani Nikula /* return pixels equvalent to txbyteclkhs */
52379bc100SJani Nikula static u16 pixels_from_txbyteclkhs(u16 clk_hs, int bpp, int lane_count,
53379bc100SJani Nikula 			u16 burst_mode_ratio)
54379bc100SJani Nikula {
55379bc100SJani Nikula 	return DIV_ROUND_UP((clk_hs * lane_count * 8 * 100),
56379bc100SJani Nikula 						(bpp * burst_mode_ratio));
57379bc100SJani Nikula }
58379bc100SJani Nikula 
59379bc100SJani Nikula enum mipi_dsi_pixel_format pixel_format_from_register_bits(u32 fmt)
60379bc100SJani Nikula {
61379bc100SJani Nikula 	/* It just so happens the VBT matches register contents. */
62379bc100SJani Nikula 	switch (fmt) {
63379bc100SJani Nikula 	case VID_MODE_FORMAT_RGB888:
64379bc100SJani Nikula 		return MIPI_DSI_FMT_RGB888;
65379bc100SJani Nikula 	case VID_MODE_FORMAT_RGB666:
66379bc100SJani Nikula 		return MIPI_DSI_FMT_RGB666;
67379bc100SJani Nikula 	case VID_MODE_FORMAT_RGB666_PACKED:
68379bc100SJani Nikula 		return MIPI_DSI_FMT_RGB666_PACKED;
69379bc100SJani Nikula 	case VID_MODE_FORMAT_RGB565:
70379bc100SJani Nikula 		return MIPI_DSI_FMT_RGB565;
71379bc100SJani Nikula 	default:
72379bc100SJani Nikula 		MISSING_CASE(fmt);
73379bc100SJani Nikula 		return MIPI_DSI_FMT_RGB666;
74379bc100SJani Nikula 	}
75379bc100SJani Nikula }
76379bc100SJani Nikula 
77379bc100SJani Nikula void vlv_dsi_wait_for_fifo_empty(struct intel_dsi *intel_dsi, enum port port)
78379bc100SJani Nikula {
79379bc100SJani Nikula 	struct drm_encoder *encoder = &intel_dsi->base.base;
80379bc100SJani Nikula 	struct drm_device *dev = encoder->dev;
81379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
82379bc100SJani Nikula 	u32 mask;
83379bc100SJani Nikula 
84379bc100SJani Nikula 	mask = LP_CTRL_FIFO_EMPTY | HS_CTRL_FIFO_EMPTY |
85379bc100SJani Nikula 		LP_DATA_FIFO_EMPTY | HS_DATA_FIFO_EMPTY;
86379bc100SJani Nikula 
874cb3b44dSDaniele Ceraolo Spurio 	if (intel_de_wait_for_set(dev_priv, MIPI_GEN_FIFO_STAT(port),
884cb3b44dSDaniele Ceraolo Spurio 				  mask, 100))
89f1f76d7aSWambui Karuga 		drm_err(&dev_priv->drm, "DPI FIFOs are not empty\n");
90379bc100SJani Nikula }
91379bc100SJani Nikula 
92379bc100SJani Nikula static void write_data(struct drm_i915_private *dev_priv,
93379bc100SJani Nikula 		       i915_reg_t reg,
94379bc100SJani Nikula 		       const u8 *data, u32 len)
95379bc100SJani Nikula {
96379bc100SJani Nikula 	u32 i, j;
97379bc100SJani Nikula 
98379bc100SJani Nikula 	for (i = 0; i < len; i += 4) {
99379bc100SJani Nikula 		u32 val = 0;
100379bc100SJani Nikula 
101379bc100SJani Nikula 		for (j = 0; j < min_t(u32, len - i, 4); j++)
102379bc100SJani Nikula 			val |= *data++ << 8 * j;
103379bc100SJani Nikula 
104992d4694SJani Nikula 		intel_de_write(dev_priv, reg, val);
105379bc100SJani Nikula 	}
106379bc100SJani Nikula }
107379bc100SJani Nikula 
108379bc100SJani Nikula static void read_data(struct drm_i915_private *dev_priv,
109379bc100SJani Nikula 		      i915_reg_t reg,
110379bc100SJani Nikula 		      u8 *data, u32 len)
111379bc100SJani Nikula {
112379bc100SJani Nikula 	u32 i, j;
113379bc100SJani Nikula 
114379bc100SJani Nikula 	for (i = 0; i < len; i += 4) {
115992d4694SJani Nikula 		u32 val = intel_de_read(dev_priv, reg);
116379bc100SJani Nikula 
117379bc100SJani Nikula 		for (j = 0; j < min_t(u32, len - i, 4); j++)
118379bc100SJani Nikula 			*data++ = val >> 8 * j;
119379bc100SJani Nikula 	}
120379bc100SJani Nikula }
121379bc100SJani Nikula 
122379bc100SJani Nikula static ssize_t intel_dsi_host_transfer(struct mipi_dsi_host *host,
123379bc100SJani Nikula 				       const struct mipi_dsi_msg *msg)
124379bc100SJani Nikula {
125379bc100SJani Nikula 	struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host);
126379bc100SJani Nikula 	struct drm_device *dev = intel_dsi_host->intel_dsi->base.base.dev;
127379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
128379bc100SJani Nikula 	enum port port = intel_dsi_host->port;
129379bc100SJani Nikula 	struct mipi_dsi_packet packet;
130379bc100SJani Nikula 	ssize_t ret;
131379bc100SJani Nikula 	const u8 *header, *data;
132379bc100SJani Nikula 	i915_reg_t data_reg, ctrl_reg;
133379bc100SJani Nikula 	u32 data_mask, ctrl_mask;
134379bc100SJani Nikula 
135379bc100SJani Nikula 	ret = mipi_dsi_create_packet(&packet, msg);
136379bc100SJani Nikula 	if (ret < 0)
137379bc100SJani Nikula 		return ret;
138379bc100SJani Nikula 
139379bc100SJani Nikula 	header = packet.header;
140379bc100SJani Nikula 	data = packet.payload;
141379bc100SJani Nikula 
142379bc100SJani Nikula 	if (msg->flags & MIPI_DSI_MSG_USE_LPM) {
143379bc100SJani Nikula 		data_reg = MIPI_LP_GEN_DATA(port);
144379bc100SJani Nikula 		data_mask = LP_DATA_FIFO_FULL;
145379bc100SJani Nikula 		ctrl_reg = MIPI_LP_GEN_CTRL(port);
146379bc100SJani Nikula 		ctrl_mask = LP_CTRL_FIFO_FULL;
147379bc100SJani Nikula 	} else {
148379bc100SJani Nikula 		data_reg = MIPI_HS_GEN_DATA(port);
149379bc100SJani Nikula 		data_mask = HS_DATA_FIFO_FULL;
150379bc100SJani Nikula 		ctrl_reg = MIPI_HS_GEN_CTRL(port);
151379bc100SJani Nikula 		ctrl_mask = HS_CTRL_FIFO_FULL;
152379bc100SJani Nikula 	}
153379bc100SJani Nikula 
154379bc100SJani Nikula 	/* note: this is never true for reads */
155379bc100SJani Nikula 	if (packet.payload_length) {
1564cb3b44dSDaniele Ceraolo Spurio 		if (intel_de_wait_for_clear(dev_priv, MIPI_GEN_FIFO_STAT(port),
1574cb3b44dSDaniele Ceraolo Spurio 					    data_mask, 50))
158f1f76d7aSWambui Karuga 			drm_err(&dev_priv->drm,
159f1f76d7aSWambui Karuga 				"Timeout waiting for HS/LP DATA FIFO !full\n");
160379bc100SJani Nikula 
161379bc100SJani Nikula 		write_data(dev_priv, data_reg, packet.payload,
162379bc100SJani Nikula 			   packet.payload_length);
163379bc100SJani Nikula 	}
164379bc100SJani Nikula 
165379bc100SJani Nikula 	if (msg->rx_len) {
166992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_INTR_STAT(port),
167992d4694SJani Nikula 			       GEN_READ_DATA_AVAIL);
168379bc100SJani Nikula 	}
169379bc100SJani Nikula 
1704cb3b44dSDaniele Ceraolo Spurio 	if (intel_de_wait_for_clear(dev_priv, MIPI_GEN_FIFO_STAT(port),
1714cb3b44dSDaniele Ceraolo Spurio 				    ctrl_mask, 50)) {
172f1f76d7aSWambui Karuga 		drm_err(&dev_priv->drm,
173f1f76d7aSWambui Karuga 			"Timeout waiting for HS/LP CTRL FIFO !full\n");
174379bc100SJani Nikula 	}
175379bc100SJani Nikula 
176992d4694SJani Nikula 	intel_de_write(dev_priv, ctrl_reg,
177992d4694SJani Nikula 		       header[2] << 16 | header[1] << 8 | header[0]);
178379bc100SJani Nikula 
179379bc100SJani Nikula 	/* ->rx_len is set only for reads */
180379bc100SJani Nikula 	if (msg->rx_len) {
181379bc100SJani Nikula 		data_mask = GEN_READ_DATA_AVAIL;
1824cb3b44dSDaniele Ceraolo Spurio 		if (intel_de_wait_for_set(dev_priv, MIPI_INTR_STAT(port),
1834cb3b44dSDaniele Ceraolo Spurio 					  data_mask, 50))
184f1f76d7aSWambui Karuga 			drm_err(&dev_priv->drm,
185f1f76d7aSWambui Karuga 				"Timeout waiting for read data.\n");
186379bc100SJani Nikula 
187379bc100SJani Nikula 		read_data(dev_priv, data_reg, msg->rx_buf, msg->rx_len);
188379bc100SJani Nikula 	}
189379bc100SJani Nikula 
190379bc100SJani Nikula 	/* XXX: fix for reads and writes */
191379bc100SJani Nikula 	return 4 + packet.payload_length;
192379bc100SJani Nikula }
193379bc100SJani Nikula 
194379bc100SJani Nikula static int intel_dsi_host_attach(struct mipi_dsi_host *host,
195379bc100SJani Nikula 				 struct mipi_dsi_device *dsi)
196379bc100SJani Nikula {
197379bc100SJani Nikula 	return 0;
198379bc100SJani Nikula }
199379bc100SJani Nikula 
200379bc100SJani Nikula static int intel_dsi_host_detach(struct mipi_dsi_host *host,
201379bc100SJani Nikula 				 struct mipi_dsi_device *dsi)
202379bc100SJani Nikula {
203379bc100SJani Nikula 	return 0;
204379bc100SJani Nikula }
205379bc100SJani Nikula 
206379bc100SJani Nikula static const struct mipi_dsi_host_ops intel_dsi_host_ops = {
207379bc100SJani Nikula 	.attach = intel_dsi_host_attach,
208379bc100SJani Nikula 	.detach = intel_dsi_host_detach,
209379bc100SJani Nikula 	.transfer = intel_dsi_host_transfer,
210379bc100SJani Nikula };
211379bc100SJani Nikula 
212379bc100SJani Nikula /*
213379bc100SJani Nikula  * send a video mode command
214379bc100SJani Nikula  *
215379bc100SJani Nikula  * XXX: commands with data in MIPI_DPI_DATA?
216379bc100SJani Nikula  */
217379bc100SJani Nikula static int dpi_send_cmd(struct intel_dsi *intel_dsi, u32 cmd, bool hs,
218379bc100SJani Nikula 			enum port port)
219379bc100SJani Nikula {
220379bc100SJani Nikula 	struct drm_encoder *encoder = &intel_dsi->base.base;
221379bc100SJani Nikula 	struct drm_device *dev = encoder->dev;
222379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
223379bc100SJani Nikula 	u32 mask;
224379bc100SJani Nikula 
225379bc100SJani Nikula 	/* XXX: pipe, hs */
226379bc100SJani Nikula 	if (hs)
227379bc100SJani Nikula 		cmd &= ~DPI_LP_MODE;
228379bc100SJani Nikula 	else
229379bc100SJani Nikula 		cmd |= DPI_LP_MODE;
230379bc100SJani Nikula 
231379bc100SJani Nikula 	/* clear bit */
232992d4694SJani Nikula 	intel_de_write(dev_priv, MIPI_INTR_STAT(port), SPL_PKT_SENT_INTERRUPT);
233379bc100SJani Nikula 
234379bc100SJani Nikula 	/* XXX: old code skips write if control unchanged */
235992d4694SJani Nikula 	if (cmd == intel_de_read(dev_priv, MIPI_DPI_CONTROL(port)))
236f1f76d7aSWambui Karuga 		drm_dbg_kms(&dev_priv->drm,
237f1f76d7aSWambui Karuga 			    "Same special packet %02x twice in a row.\n", cmd);
238379bc100SJani Nikula 
239992d4694SJani Nikula 	intel_de_write(dev_priv, MIPI_DPI_CONTROL(port), cmd);
240379bc100SJani Nikula 
241379bc100SJani Nikula 	mask = SPL_PKT_SENT_INTERRUPT;
2424cb3b44dSDaniele Ceraolo Spurio 	if (intel_de_wait_for_set(dev_priv, MIPI_INTR_STAT(port), mask, 100))
243f1f76d7aSWambui Karuga 		drm_err(&dev_priv->drm,
244f1f76d7aSWambui Karuga 			"Video mode command 0x%08x send failed.\n", cmd);
245379bc100SJani Nikula 
246379bc100SJani Nikula 	return 0;
247379bc100SJani Nikula }
248379bc100SJani Nikula 
249379bc100SJani Nikula static void band_gap_reset(struct drm_i915_private *dev_priv)
250379bc100SJani Nikula {
251379bc100SJani Nikula 	vlv_flisdsi_get(dev_priv);
252379bc100SJani Nikula 
253379bc100SJani Nikula 	vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
254379bc100SJani Nikula 	vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
255379bc100SJani Nikula 	vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
256379bc100SJani Nikula 	udelay(150);
257379bc100SJani Nikula 	vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
258379bc100SJani Nikula 	vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
259379bc100SJani Nikula 
260379bc100SJani Nikula 	vlv_flisdsi_put(dev_priv);
261379bc100SJani Nikula }
262379bc100SJani Nikula 
263379bc100SJani Nikula static int intel_dsi_compute_config(struct intel_encoder *encoder,
264379bc100SJani Nikula 				    struct intel_crtc_state *pipe_config,
265379bc100SJani Nikula 				    struct drm_connector_state *conn_state)
266379bc100SJani Nikula {
267379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
268379bc100SJani Nikula 	struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
269379bc100SJani Nikula 						   base);
270379bc100SJani Nikula 	struct intel_connector *intel_connector = intel_dsi->attached_connector;
271379bc100SJani Nikula 	const struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
2721326a92cSMaarten Lankhorst 	struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
273379bc100SJani Nikula 	int ret;
274379bc100SJani Nikula 
275f1f76d7aSWambui Karuga 	drm_dbg_kms(&dev_priv->drm, "\n");
276379bc100SJani Nikula 	pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
277379bc100SJani Nikula 
278379bc100SJani Nikula 	if (fixed_mode) {
279379bc100SJani Nikula 		intel_fixed_panel_mode(fixed_mode, adjusted_mode);
280379bc100SJani Nikula 
281379bc100SJani Nikula 		if (HAS_GMCH(dev_priv))
282d7ff281cSVille Syrjälä 			ret = intel_gmch_panel_fitting(pipe_config, conn_state);
283379bc100SJani Nikula 		else
284d7ff281cSVille Syrjälä 			ret = intel_pch_panel_fitting(pipe_config, conn_state);
285d7ff281cSVille Syrjälä 		if (ret)
286d7ff281cSVille Syrjälä 			return ret;
287379bc100SJani Nikula 	}
288379bc100SJani Nikula 
289379bc100SJani Nikula 	if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
290379bc100SJani Nikula 		return -EINVAL;
291379bc100SJani Nikula 
292379bc100SJani Nikula 	/* DSI uses short packets for sync events, so clear mode flags for DSI */
293379bc100SJani Nikula 	adjusted_mode->flags = 0;
294379bc100SJani Nikula 
295379bc100SJani Nikula 	if (intel_dsi->pixel_format == MIPI_DSI_FMT_RGB888)
296379bc100SJani Nikula 		pipe_config->pipe_bpp = 24;
297379bc100SJani Nikula 	else
298379bc100SJani Nikula 		pipe_config->pipe_bpp = 18;
299379bc100SJani Nikula 
300379bc100SJani Nikula 	if (IS_GEN9_LP(dev_priv)) {
301379bc100SJani Nikula 		/* Enable Frame time stamp based scanline reporting */
302af157b76SVille Syrjälä 		pipe_config->mode_flags |=
303379bc100SJani Nikula 			I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP;
304379bc100SJani Nikula 
305379bc100SJani Nikula 		/* Dual link goes to DSI transcoder A. */
306379bc100SJani Nikula 		if (intel_dsi->ports == BIT(PORT_C))
307379bc100SJani Nikula 			pipe_config->cpu_transcoder = TRANSCODER_DSI_C;
308379bc100SJani Nikula 		else
309379bc100SJani Nikula 			pipe_config->cpu_transcoder = TRANSCODER_DSI_A;
310379bc100SJani Nikula 
311379bc100SJani Nikula 		ret = bxt_dsi_pll_compute(encoder, pipe_config);
312379bc100SJani Nikula 		if (ret)
313379bc100SJani Nikula 			return -EINVAL;
314379bc100SJani Nikula 	} else {
315379bc100SJani Nikula 		ret = vlv_dsi_pll_compute(encoder, pipe_config);
316379bc100SJani Nikula 		if (ret)
317379bc100SJani Nikula 			return -EINVAL;
318379bc100SJani Nikula 	}
319379bc100SJani Nikula 
320379bc100SJani Nikula 	pipe_config->clock_set = true;
321379bc100SJani Nikula 
322379bc100SJani Nikula 	return 0;
323379bc100SJani Nikula }
324379bc100SJani Nikula 
325379bc100SJani Nikula static bool glk_dsi_enable_io(struct intel_encoder *encoder)
326379bc100SJani Nikula {
327379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
328b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
329379bc100SJani Nikula 	enum port port;
330379bc100SJani Nikula 	u32 tmp;
331379bc100SJani Nikula 	bool cold_boot = false;
332379bc100SJani Nikula 
333379bc100SJani Nikula 	/* Set the MIPI mode
334379bc100SJani Nikula 	 * If MIPI_Mode is off, then writing to LP_Wake bit is not reflecting.
335379bc100SJani Nikula 	 * Power ON MIPI IO first and then write into IO reset and LP wake bits
336379bc100SJani Nikula 	 */
337379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
338992d4694SJani Nikula 		tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
339992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_CTRL(port),
340992d4694SJani Nikula 			       tmp | GLK_MIPIIO_ENABLE);
341379bc100SJani Nikula 	}
342379bc100SJani Nikula 
343379bc100SJani Nikula 	/* Put the IO into reset */
344992d4694SJani Nikula 	tmp = intel_de_read(dev_priv, MIPI_CTRL(PORT_A));
345379bc100SJani Nikula 	tmp &= ~GLK_MIPIIO_RESET_RELEASED;
346992d4694SJani Nikula 	intel_de_write(dev_priv, MIPI_CTRL(PORT_A), tmp);
347379bc100SJani Nikula 
348379bc100SJani Nikula 	/* Program LP Wake */
349379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
350992d4694SJani Nikula 		tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
351992d4694SJani Nikula 		if (!(intel_de_read(dev_priv, MIPI_DEVICE_READY(port)) & DEVICE_READY))
352379bc100SJani Nikula 			tmp &= ~GLK_LP_WAKE;
353379bc100SJani Nikula 		else
354379bc100SJani Nikula 			tmp |= GLK_LP_WAKE;
355992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_CTRL(port), tmp);
356379bc100SJani Nikula 	}
357379bc100SJani Nikula 
358379bc100SJani Nikula 	/* Wait for Pwr ACK */
359379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
3604cb3b44dSDaniele Ceraolo Spurio 		if (intel_de_wait_for_set(dev_priv, MIPI_CTRL(port),
3614cb3b44dSDaniele Ceraolo Spurio 					  GLK_MIPIIO_PORT_POWERED, 20))
362f1f76d7aSWambui Karuga 			drm_err(&dev_priv->drm, "MIPIO port is powergated\n");
363379bc100SJani Nikula 	}
364379bc100SJani Nikula 
365379bc100SJani Nikula 	/* Check for cold boot scenario */
366379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
367379bc100SJani Nikula 		cold_boot |=
368992d4694SJani Nikula 			!(intel_de_read(dev_priv, MIPI_DEVICE_READY(port)) & DEVICE_READY);
369379bc100SJani Nikula 	}
370379bc100SJani Nikula 
371379bc100SJani Nikula 	return cold_boot;
372379bc100SJani Nikula }
373379bc100SJani Nikula 
374379bc100SJani Nikula static void glk_dsi_device_ready(struct intel_encoder *encoder)
375379bc100SJani Nikula {
376379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
377b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
378379bc100SJani Nikula 	enum port port;
379379bc100SJani Nikula 	u32 val;
380379bc100SJani Nikula 
381379bc100SJani Nikula 	/* Wait for MIPI PHY status bit to set */
382379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
3834cb3b44dSDaniele Ceraolo Spurio 		if (intel_de_wait_for_set(dev_priv, MIPI_CTRL(port),
3844cb3b44dSDaniele Ceraolo Spurio 					  GLK_PHY_STATUS_PORT_READY, 20))
385f1f76d7aSWambui Karuga 			drm_err(&dev_priv->drm, "PHY is not ON\n");
386379bc100SJani Nikula 	}
387379bc100SJani Nikula 
388379bc100SJani Nikula 	/* Get IO out of reset */
389992d4694SJani Nikula 	val = intel_de_read(dev_priv, MIPI_CTRL(PORT_A));
390992d4694SJani Nikula 	intel_de_write(dev_priv, MIPI_CTRL(PORT_A),
391992d4694SJani Nikula 		       val | GLK_MIPIIO_RESET_RELEASED);
392379bc100SJani Nikula 
393379bc100SJani Nikula 	/* Get IO out of Low power state*/
394379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
395992d4694SJani Nikula 		if (!(intel_de_read(dev_priv, MIPI_DEVICE_READY(port)) & DEVICE_READY)) {
396992d4694SJani Nikula 			val = intel_de_read(dev_priv, MIPI_DEVICE_READY(port));
397379bc100SJani Nikula 			val &= ~ULPS_STATE_MASK;
398379bc100SJani Nikula 			val |= DEVICE_READY;
399992d4694SJani Nikula 			intel_de_write(dev_priv, MIPI_DEVICE_READY(port), val);
400379bc100SJani Nikula 			usleep_range(10, 15);
401379bc100SJani Nikula 		} else {
402379bc100SJani Nikula 			/* Enter ULPS */
403992d4694SJani Nikula 			val = intel_de_read(dev_priv, MIPI_DEVICE_READY(port));
404379bc100SJani Nikula 			val &= ~ULPS_STATE_MASK;
405379bc100SJani Nikula 			val |= (ULPS_STATE_ENTER | DEVICE_READY);
406992d4694SJani Nikula 			intel_de_write(dev_priv, MIPI_DEVICE_READY(port), val);
407379bc100SJani Nikula 
408379bc100SJani Nikula 			/* Wait for ULPS active */
4094cb3b44dSDaniele Ceraolo Spurio 			if (intel_de_wait_for_clear(dev_priv, MIPI_CTRL(port),
4104cb3b44dSDaniele Ceraolo Spurio 						    GLK_ULPS_NOT_ACTIVE, 20))
411f1f76d7aSWambui Karuga 				drm_err(&dev_priv->drm, "ULPS not active\n");
412379bc100SJani Nikula 
413379bc100SJani Nikula 			/* Exit ULPS */
414992d4694SJani Nikula 			val = intel_de_read(dev_priv, MIPI_DEVICE_READY(port));
415379bc100SJani Nikula 			val &= ~ULPS_STATE_MASK;
416379bc100SJani Nikula 			val |= (ULPS_STATE_EXIT | DEVICE_READY);
417992d4694SJani Nikula 			intel_de_write(dev_priv, MIPI_DEVICE_READY(port), val);
418379bc100SJani Nikula 
419379bc100SJani Nikula 			/* Enter Normal Mode */
420992d4694SJani Nikula 			val = intel_de_read(dev_priv, MIPI_DEVICE_READY(port));
421379bc100SJani Nikula 			val &= ~ULPS_STATE_MASK;
422379bc100SJani Nikula 			val |= (ULPS_STATE_NORMAL_OPERATION | DEVICE_READY);
423992d4694SJani Nikula 			intel_de_write(dev_priv, MIPI_DEVICE_READY(port), val);
424379bc100SJani Nikula 
425992d4694SJani Nikula 			val = intel_de_read(dev_priv, MIPI_CTRL(port));
426379bc100SJani Nikula 			val &= ~GLK_LP_WAKE;
427992d4694SJani Nikula 			intel_de_write(dev_priv, MIPI_CTRL(port), val);
428379bc100SJani Nikula 		}
429379bc100SJani Nikula 	}
430379bc100SJani Nikula 
431379bc100SJani Nikula 	/* Wait for Stop state */
432379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
4334cb3b44dSDaniele Ceraolo Spurio 		if (intel_de_wait_for_set(dev_priv, MIPI_CTRL(port),
4344cb3b44dSDaniele Ceraolo Spurio 					  GLK_DATA_LANE_STOP_STATE, 20))
435f1f76d7aSWambui Karuga 			drm_err(&dev_priv->drm,
436f1f76d7aSWambui Karuga 				"Date lane not in STOP state\n");
437379bc100SJani Nikula 	}
438379bc100SJani Nikula 
439379bc100SJani Nikula 	/* Wait for AFE LATCH */
440379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
4414cb3b44dSDaniele Ceraolo Spurio 		if (intel_de_wait_for_set(dev_priv, BXT_MIPI_PORT_CTRL(port),
4424cb3b44dSDaniele Ceraolo Spurio 					  AFE_LATCHOUT, 20))
443f1f76d7aSWambui Karuga 			drm_err(&dev_priv->drm,
444f1f76d7aSWambui Karuga 				"D-PHY not entering LP-11 state\n");
445379bc100SJani Nikula 	}
446379bc100SJani Nikula }
447379bc100SJani Nikula 
448379bc100SJani Nikula static void bxt_dsi_device_ready(struct intel_encoder *encoder)
449379bc100SJani Nikula {
450379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
451b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
452379bc100SJani Nikula 	enum port port;
453379bc100SJani Nikula 	u32 val;
454379bc100SJani Nikula 
455f1f76d7aSWambui Karuga 	drm_dbg_kms(&dev_priv->drm, "\n");
456379bc100SJani Nikula 
457379bc100SJani Nikula 	/* Enable MIPI PHY transparent latch */
458379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
459992d4694SJani Nikula 		val = intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port));
460992d4694SJani Nikula 		intel_de_write(dev_priv, BXT_MIPI_PORT_CTRL(port),
461992d4694SJani Nikula 			       val | LP_OUTPUT_HOLD);
462379bc100SJani Nikula 		usleep_range(2000, 2500);
463379bc100SJani Nikula 	}
464379bc100SJani Nikula 
465379bc100SJani Nikula 	/* Clear ULPS and set device ready */
466379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
467992d4694SJani Nikula 		val = intel_de_read(dev_priv, MIPI_DEVICE_READY(port));
468379bc100SJani Nikula 		val &= ~ULPS_STATE_MASK;
469992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DEVICE_READY(port), val);
470379bc100SJani Nikula 		usleep_range(2000, 2500);
471379bc100SJani Nikula 		val |= DEVICE_READY;
472992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DEVICE_READY(port), val);
473379bc100SJani Nikula 	}
474379bc100SJani Nikula }
475379bc100SJani Nikula 
476379bc100SJani Nikula static void vlv_dsi_device_ready(struct intel_encoder *encoder)
477379bc100SJani Nikula {
478379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
479b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
480379bc100SJani Nikula 	enum port port;
481379bc100SJani Nikula 	u32 val;
482379bc100SJani Nikula 
483f1f76d7aSWambui Karuga 	drm_dbg_kms(&dev_priv->drm, "\n");
484379bc100SJani Nikula 
485379bc100SJani Nikula 	vlv_flisdsi_get(dev_priv);
486379bc100SJani Nikula 	/* program rcomp for compliance, reduce from 50 ohms to 45 ohms
487379bc100SJani Nikula 	 * needed everytime after power gate */
488379bc100SJani Nikula 	vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
489379bc100SJani Nikula 	vlv_flisdsi_put(dev_priv);
490379bc100SJani Nikula 
491379bc100SJani Nikula 	/* bandgap reset is needed after everytime we do power gate */
492379bc100SJani Nikula 	band_gap_reset(dev_priv);
493379bc100SJani Nikula 
494379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
495379bc100SJani Nikula 
496992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DEVICE_READY(port),
497992d4694SJani Nikula 			       ULPS_STATE_ENTER);
498379bc100SJani Nikula 		usleep_range(2500, 3000);
499379bc100SJani Nikula 
500379bc100SJani Nikula 		/* Enable MIPI PHY transparent latch
501379bc100SJani Nikula 		 * Common bit for both MIPI Port A & MIPI Port C
502379bc100SJani Nikula 		 * No similar bit in MIPI Port C reg
503379bc100SJani Nikula 		 */
504992d4694SJani Nikula 		val = intel_de_read(dev_priv, MIPI_PORT_CTRL(PORT_A));
505992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_PORT_CTRL(PORT_A),
506992d4694SJani Nikula 			       val | LP_OUTPUT_HOLD);
507379bc100SJani Nikula 		usleep_range(1000, 1500);
508379bc100SJani Nikula 
509992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DEVICE_READY(port),
510992d4694SJani Nikula 			       ULPS_STATE_EXIT);
511379bc100SJani Nikula 		usleep_range(2500, 3000);
512379bc100SJani Nikula 
513992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DEVICE_READY(port),
514992d4694SJani Nikula 			       DEVICE_READY);
515379bc100SJani Nikula 		usleep_range(2500, 3000);
516379bc100SJani Nikula 	}
517379bc100SJani Nikula }
518379bc100SJani Nikula 
519379bc100SJani Nikula static void intel_dsi_device_ready(struct intel_encoder *encoder)
520379bc100SJani Nikula {
521379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
522379bc100SJani Nikula 
523379bc100SJani Nikula 	if (IS_GEMINILAKE(dev_priv))
524379bc100SJani Nikula 		glk_dsi_device_ready(encoder);
525379bc100SJani Nikula 	else if (IS_GEN9_LP(dev_priv))
526379bc100SJani Nikula 		bxt_dsi_device_ready(encoder);
527379bc100SJani Nikula 	else
528379bc100SJani Nikula 		vlv_dsi_device_ready(encoder);
529379bc100SJani Nikula }
530379bc100SJani Nikula 
531379bc100SJani Nikula static void glk_dsi_enter_low_power_mode(struct intel_encoder *encoder)
532379bc100SJani Nikula {
533379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
534b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
535379bc100SJani Nikula 	enum port port;
536379bc100SJani Nikula 	u32 val;
537379bc100SJani Nikula 
538379bc100SJani Nikula 	/* Enter ULPS */
539379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
540992d4694SJani Nikula 		val = intel_de_read(dev_priv, MIPI_DEVICE_READY(port));
541379bc100SJani Nikula 		val &= ~ULPS_STATE_MASK;
542379bc100SJani Nikula 		val |= (ULPS_STATE_ENTER | DEVICE_READY);
543992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DEVICE_READY(port), val);
544379bc100SJani Nikula 	}
545379bc100SJani Nikula 
546379bc100SJani Nikula 	/* Wait for MIPI PHY status bit to unset */
547379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
5484cb3b44dSDaniele Ceraolo Spurio 		if (intel_de_wait_for_clear(dev_priv, MIPI_CTRL(port),
5494cb3b44dSDaniele Ceraolo Spurio 					    GLK_PHY_STATUS_PORT_READY, 20))
550f1f76d7aSWambui Karuga 			drm_err(&dev_priv->drm, "PHY is not turning OFF\n");
551379bc100SJani Nikula 	}
552379bc100SJani Nikula 
553379bc100SJani Nikula 	/* Wait for Pwr ACK bit to unset */
554379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
5554cb3b44dSDaniele Ceraolo Spurio 		if (intel_de_wait_for_clear(dev_priv, MIPI_CTRL(port),
5564cb3b44dSDaniele Ceraolo Spurio 					    GLK_MIPIIO_PORT_POWERED, 20))
557f1f76d7aSWambui Karuga 			drm_err(&dev_priv->drm,
558f1f76d7aSWambui Karuga 				"MIPI IO Port is not powergated\n");
559379bc100SJani Nikula 	}
560379bc100SJani Nikula }
561379bc100SJani Nikula 
562379bc100SJani Nikula static void glk_dsi_disable_mipi_io(struct intel_encoder *encoder)
563379bc100SJani Nikula {
564379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
565b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
566379bc100SJani Nikula 	enum port port;
567379bc100SJani Nikula 	u32 tmp;
568379bc100SJani Nikula 
569379bc100SJani Nikula 	/* Put the IO into reset */
570992d4694SJani Nikula 	tmp = intel_de_read(dev_priv, MIPI_CTRL(PORT_A));
571379bc100SJani Nikula 	tmp &= ~GLK_MIPIIO_RESET_RELEASED;
572992d4694SJani Nikula 	intel_de_write(dev_priv, MIPI_CTRL(PORT_A), tmp);
573379bc100SJani Nikula 
574379bc100SJani Nikula 	/* Wait for MIPI PHY status bit to unset */
575379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
5764cb3b44dSDaniele Ceraolo Spurio 		if (intel_de_wait_for_clear(dev_priv, MIPI_CTRL(port),
5774cb3b44dSDaniele Ceraolo Spurio 					    GLK_PHY_STATUS_PORT_READY, 20))
578f1f76d7aSWambui Karuga 			drm_err(&dev_priv->drm, "PHY is not turning OFF\n");
579379bc100SJani Nikula 	}
580379bc100SJani Nikula 
581379bc100SJani Nikula 	/* Clear MIPI mode */
582379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
583992d4694SJani Nikula 		tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
584379bc100SJani Nikula 		tmp &= ~GLK_MIPIIO_ENABLE;
585992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_CTRL(port), tmp);
586379bc100SJani Nikula 	}
587379bc100SJani Nikula }
588379bc100SJani Nikula 
589379bc100SJani Nikula static void glk_dsi_clear_device_ready(struct intel_encoder *encoder)
590379bc100SJani Nikula {
591379bc100SJani Nikula 	glk_dsi_enter_low_power_mode(encoder);
592379bc100SJani Nikula 	glk_dsi_disable_mipi_io(encoder);
593379bc100SJani Nikula }
594379bc100SJani Nikula 
595379bc100SJani Nikula static void vlv_dsi_clear_device_ready(struct intel_encoder *encoder)
596379bc100SJani Nikula {
597379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
598b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
599379bc100SJani Nikula 	enum port port;
600379bc100SJani Nikula 
601f1f76d7aSWambui Karuga 	drm_dbg_kms(&dev_priv->drm, "\n");
602379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
603379bc100SJani Nikula 		/* Common bit for both MIPI Port A & MIPI Port C on VLV/CHV */
604379bc100SJani Nikula 		i915_reg_t port_ctrl = IS_GEN9_LP(dev_priv) ?
605379bc100SJani Nikula 			BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(PORT_A);
606379bc100SJani Nikula 		u32 val;
607379bc100SJani Nikula 
608992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DEVICE_READY(port),
609992d4694SJani Nikula 			       DEVICE_READY | ULPS_STATE_ENTER);
610379bc100SJani Nikula 		usleep_range(2000, 2500);
611379bc100SJani Nikula 
612992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DEVICE_READY(port),
613992d4694SJani Nikula 			       DEVICE_READY | ULPS_STATE_EXIT);
614379bc100SJani Nikula 		usleep_range(2000, 2500);
615379bc100SJani Nikula 
616992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DEVICE_READY(port),
617992d4694SJani Nikula 			       DEVICE_READY | ULPS_STATE_ENTER);
618379bc100SJani Nikula 		usleep_range(2000, 2500);
619379bc100SJani Nikula 
620379bc100SJani Nikula 		/*
621379bc100SJani Nikula 		 * On VLV/CHV, wait till Clock lanes are in LP-00 state for MIPI
622379bc100SJani Nikula 		 * Port A only. MIPI Port C has no similar bit for checking.
623379bc100SJani Nikula 		 */
624379bc100SJani Nikula 		if ((IS_GEN9_LP(dev_priv) || port == PORT_A) &&
6254cb3b44dSDaniele Ceraolo Spurio 		    intel_de_wait_for_clear(dev_priv, port_ctrl,
6264cb3b44dSDaniele Ceraolo Spurio 					    AFE_LATCHOUT, 30))
627f1f76d7aSWambui Karuga 			drm_err(&dev_priv->drm, "DSI LP not going Low\n");
628379bc100SJani Nikula 
629379bc100SJani Nikula 		/* Disable MIPI PHY transparent latch */
630992d4694SJani Nikula 		val = intel_de_read(dev_priv, port_ctrl);
631992d4694SJani Nikula 		intel_de_write(dev_priv, port_ctrl, val & ~LP_OUTPUT_HOLD);
632379bc100SJani Nikula 		usleep_range(1000, 1500);
633379bc100SJani Nikula 
634992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DEVICE_READY(port), 0x00);
635379bc100SJani Nikula 		usleep_range(2000, 2500);
636379bc100SJani Nikula 	}
637379bc100SJani Nikula }
638379bc100SJani Nikula 
639379bc100SJani Nikula static void intel_dsi_port_enable(struct intel_encoder *encoder,
640379bc100SJani Nikula 				  const struct intel_crtc_state *crtc_state)
641379bc100SJani Nikula {
642379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6432225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
644b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
645379bc100SJani Nikula 	enum port port;
646379bc100SJani Nikula 
647379bc100SJani Nikula 	if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
648379bc100SJani Nikula 		u32 temp;
649379bc100SJani Nikula 		if (IS_GEN9_LP(dev_priv)) {
650379bc100SJani Nikula 			for_each_dsi_port(port, intel_dsi->ports) {
651992d4694SJani Nikula 				temp = intel_de_read(dev_priv,
652992d4694SJani Nikula 						     MIPI_CTRL(port));
653379bc100SJani Nikula 				temp &= ~BXT_PIXEL_OVERLAP_CNT_MASK |
654379bc100SJani Nikula 					intel_dsi->pixel_overlap <<
655379bc100SJani Nikula 					BXT_PIXEL_OVERLAP_CNT_SHIFT;
656992d4694SJani Nikula 				intel_de_write(dev_priv, MIPI_CTRL(port),
657992d4694SJani Nikula 					       temp);
658379bc100SJani Nikula 			}
659379bc100SJani Nikula 		} else {
660992d4694SJani Nikula 			temp = intel_de_read(dev_priv, VLV_CHICKEN_3);
661379bc100SJani Nikula 			temp &= ~PIXEL_OVERLAP_CNT_MASK |
662379bc100SJani Nikula 					intel_dsi->pixel_overlap <<
663379bc100SJani Nikula 					PIXEL_OVERLAP_CNT_SHIFT;
664992d4694SJani Nikula 			intel_de_write(dev_priv, VLV_CHICKEN_3, temp);
665379bc100SJani Nikula 		}
666379bc100SJani Nikula 	}
667379bc100SJani Nikula 
668379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
669379bc100SJani Nikula 		i915_reg_t port_ctrl = IS_GEN9_LP(dev_priv) ?
670379bc100SJani Nikula 			BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
671379bc100SJani Nikula 		u32 temp;
672379bc100SJani Nikula 
673992d4694SJani Nikula 		temp = intel_de_read(dev_priv, port_ctrl);
674379bc100SJani Nikula 
675379bc100SJani Nikula 		temp &= ~LANE_CONFIGURATION_MASK;
676379bc100SJani Nikula 		temp &= ~DUAL_LINK_MODE_MASK;
677379bc100SJani Nikula 
678379bc100SJani Nikula 		if (intel_dsi->ports == (BIT(PORT_A) | BIT(PORT_C))) {
679379bc100SJani Nikula 			temp |= (intel_dsi->dual_link - 1)
680379bc100SJani Nikula 						<< DUAL_LINK_MODE_SHIFT;
681379bc100SJani Nikula 			if (IS_BROXTON(dev_priv))
682379bc100SJani Nikula 				temp |= LANE_CONFIGURATION_DUAL_LINK_A;
683379bc100SJani Nikula 			else
684379bc100SJani Nikula 				temp |= crtc->pipe ?
685379bc100SJani Nikula 					LANE_CONFIGURATION_DUAL_LINK_B :
686379bc100SJani Nikula 					LANE_CONFIGURATION_DUAL_LINK_A;
687379bc100SJani Nikula 		}
688379bc100SJani Nikula 
689379bc100SJani Nikula 		if (intel_dsi->pixel_format != MIPI_DSI_FMT_RGB888)
690379bc100SJani Nikula 			temp |= DITHERING_ENABLE;
691379bc100SJani Nikula 
692379bc100SJani Nikula 		/* assert ip_tg_enable signal */
693992d4694SJani Nikula 		intel_de_write(dev_priv, port_ctrl, temp | DPI_ENABLE);
694992d4694SJani Nikula 		intel_de_posting_read(dev_priv, port_ctrl);
695379bc100SJani Nikula 	}
696379bc100SJani Nikula }
697379bc100SJani Nikula 
698379bc100SJani Nikula static void intel_dsi_port_disable(struct intel_encoder *encoder)
699379bc100SJani Nikula {
700379bc100SJani Nikula 	struct drm_device *dev = encoder->base.dev;
701379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
702b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
703379bc100SJani Nikula 	enum port port;
704379bc100SJani Nikula 
705379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
706379bc100SJani Nikula 		i915_reg_t port_ctrl = IS_GEN9_LP(dev_priv) ?
707379bc100SJani Nikula 			BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
708379bc100SJani Nikula 		u32 temp;
709379bc100SJani Nikula 
710379bc100SJani Nikula 		/* de-assert ip_tg_enable signal */
711992d4694SJani Nikula 		temp = intel_de_read(dev_priv, port_ctrl);
712992d4694SJani Nikula 		intel_de_write(dev_priv, port_ctrl, temp & ~DPI_ENABLE);
713992d4694SJani Nikula 		intel_de_posting_read(dev_priv, port_ctrl);
714379bc100SJani Nikula 	}
715379bc100SJani Nikula }
716379bc100SJani Nikula 
717379bc100SJani Nikula static void intel_dsi_prepare(struct intel_encoder *intel_encoder,
718379bc100SJani Nikula 			      const struct intel_crtc_state *pipe_config);
719379bc100SJani Nikula static void intel_dsi_unprepare(struct intel_encoder *encoder);
720379bc100SJani Nikula 
721379bc100SJani Nikula /*
722379bc100SJani Nikula  * Panel enable/disable sequences from the VBT spec.
723379bc100SJani Nikula  *
724379bc100SJani Nikula  * Note the spec has AssertReset / DeassertReset swapped from their
725379bc100SJani Nikula  * usual naming. We use the normal names to avoid confusion (so below
726379bc100SJani Nikula  * they are swapped compared to the spec).
727379bc100SJani Nikula  *
728379bc100SJani Nikula  * Steps starting with MIPI refer to VBT sequences, note that for v2
729379bc100SJani Nikula  * VBTs several steps which have a VBT in v2 are expected to be handled
730379bc100SJani Nikula  * directly by the driver, by directly driving gpios for example.
731379bc100SJani Nikula  *
732379bc100SJani Nikula  * v2 video mode seq         v3 video mode seq         command mode seq
733379bc100SJani Nikula  * - power on                - MIPIPanelPowerOn        - power on
734379bc100SJani Nikula  * - wait t1+t2                                        - wait t1+t2
735379bc100SJani Nikula  * - MIPIDeassertResetPin    - MIPIDeassertResetPin    - MIPIDeassertResetPin
736379bc100SJani Nikula  * - io lines to lp-11       - io lines to lp-11       - io lines to lp-11
737379bc100SJani Nikula  * - MIPISendInitialDcsCmds  - MIPISendInitialDcsCmds  - MIPISendInitialDcsCmds
738379bc100SJani Nikula  *                                                     - MIPITearOn
739379bc100SJani Nikula  *                                                     - MIPIDisplayOn
740379bc100SJani Nikula  * - turn on DPI             - turn on DPI             - set pipe to dsr mode
741379bc100SJani Nikula  * - MIPIDisplayOn           - MIPIDisplayOn
742379bc100SJani Nikula  * - wait t5                                           - wait t5
743379bc100SJani Nikula  * - backlight on            - MIPIBacklightOn         - backlight on
744379bc100SJani Nikula  * ...                       ...                       ... issue mem cmds ...
745379bc100SJani Nikula  * - backlight off           - MIPIBacklightOff        - backlight off
746379bc100SJani Nikula  * - wait t6                                           - wait t6
747379bc100SJani Nikula  * - MIPIDisplayOff
748379bc100SJani Nikula  * - turn off DPI            - turn off DPI            - disable pipe dsr mode
749379bc100SJani Nikula  *                                                     - MIPITearOff
750379bc100SJani Nikula  *                           - MIPIDisplayOff          - MIPIDisplayOff
751379bc100SJani Nikula  * - io lines to lp-00       - io lines to lp-00       - io lines to lp-00
752379bc100SJani Nikula  * - MIPIAssertResetPin      - MIPIAssertResetPin      - MIPIAssertResetPin
753379bc100SJani Nikula  * - wait t3                                           - wait t3
754379bc100SJani Nikula  * - power off               - MIPIPanelPowerOff       - power off
755379bc100SJani Nikula  * - wait t4                                           - wait t4
756379bc100SJani Nikula  */
757379bc100SJani Nikula 
758379bc100SJani Nikula /*
759379bc100SJani Nikula  * DSI port enable has to be done before pipe and plane enable, so we do it in
760379bc100SJani Nikula  * the pre_enable hook instead of the enable hook.
761379bc100SJani Nikula  */
762ede9771dSVille Syrjälä static void intel_dsi_pre_enable(struct intel_atomic_state *state,
763ede9771dSVille Syrjälä 				 struct intel_encoder *encoder,
764379bc100SJani Nikula 				 const struct intel_crtc_state *pipe_config,
765379bc100SJani Nikula 				 const struct drm_connector_state *conn_state)
766379bc100SJani Nikula {
767b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
7682225f3c6SMaarten Lankhorst 	struct drm_crtc *crtc = pipe_config->uapi.crtc;
769379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(crtc->dev);
770379bc100SJani Nikula 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
771d048a268SVille Syrjälä 	enum pipe pipe = intel_crtc->pipe;
772379bc100SJani Nikula 	enum port port;
773379bc100SJani Nikula 	u32 val;
774379bc100SJani Nikula 	bool glk_cold_boot = false;
775379bc100SJani Nikula 
776f1f76d7aSWambui Karuga 	drm_dbg_kms(&dev_priv->drm, "\n");
777379bc100SJani Nikula 
778379bc100SJani Nikula 	intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
779379bc100SJani Nikula 
780379bc100SJani Nikula 	/*
781379bc100SJani Nikula 	 * The BIOS may leave the PLL in a wonky state where it doesn't
782379bc100SJani Nikula 	 * lock. It needs to be fully powered down to fix it.
783379bc100SJani Nikula 	 */
784379bc100SJani Nikula 	if (IS_GEN9_LP(dev_priv)) {
785379bc100SJani Nikula 		bxt_dsi_pll_disable(encoder);
786379bc100SJani Nikula 		bxt_dsi_pll_enable(encoder, pipe_config);
787379bc100SJani Nikula 	} else {
788379bc100SJani Nikula 		vlv_dsi_pll_disable(encoder);
789379bc100SJani Nikula 		vlv_dsi_pll_enable(encoder, pipe_config);
790379bc100SJani Nikula 	}
791379bc100SJani Nikula 
792379bc100SJani Nikula 	if (IS_BROXTON(dev_priv)) {
793379bc100SJani Nikula 		/* Add MIPI IO reset programming for modeset */
794992d4694SJani Nikula 		val = intel_de_read(dev_priv, BXT_P_CR_GT_DISP_PWRON);
795992d4694SJani Nikula 		intel_de_write(dev_priv, BXT_P_CR_GT_DISP_PWRON,
796379bc100SJani Nikula 			       val | MIPIO_RST_CTRL);
797379bc100SJani Nikula 
798379bc100SJani Nikula 		/* Power up DSI regulator */
799992d4694SJani Nikula 		intel_de_write(dev_priv, BXT_P_DSI_REGULATOR_CFG, STAP_SELECT);
800992d4694SJani Nikula 		intel_de_write(dev_priv, BXT_P_DSI_REGULATOR_TX_CTRL, 0);
801379bc100SJani Nikula 	}
802379bc100SJani Nikula 
803379bc100SJani Nikula 	if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
804379bc100SJani Nikula 		u32 val;
805379bc100SJani Nikula 
806379bc100SJani Nikula 		/* Disable DPOunit clock gating, can stall pipe */
807992d4694SJani Nikula 		val = intel_de_read(dev_priv, DSPCLK_GATE_D);
808379bc100SJani Nikula 		val |= DPOUNIT_CLOCK_GATE_DISABLE;
809992d4694SJani Nikula 		intel_de_write(dev_priv, DSPCLK_GATE_D, val);
810379bc100SJani Nikula 	}
811379bc100SJani Nikula 
812379bc100SJani Nikula 	if (!IS_GEMINILAKE(dev_priv))
813379bc100SJani Nikula 		intel_dsi_prepare(encoder, pipe_config);
814379bc100SJani Nikula 
815379bc100SJani Nikula 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_ON);
816379bc100SJani Nikula 
8176fdb335fSHans de Goede 	/*
8186fdb335fSHans de Goede 	 * Give the panel time to power-on and then deassert its reset.
8196fdb335fSHans de Goede 	 * Depending on the VBT MIPI sequences version the deassert-seq
8206fdb335fSHans de Goede 	 * may contain the necessary delay, intel_dsi_msleep() will skip
8216fdb335fSHans de Goede 	 * the delay in that case. If there is no deassert-seq, then an
8226fdb335fSHans de Goede 	 * unconditional msleep is used to give the panel time to power-on.
8236fdb335fSHans de Goede 	 */
8246fdb335fSHans de Goede 	if (dev_priv->vbt.dsi.sequence[MIPI_SEQ_DEASSERT_RESET]) {
8256fdb335fSHans de Goede 		intel_dsi_msleep(intel_dsi, intel_dsi->panel_on_delay);
826379bc100SJani Nikula 		intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DEASSERT_RESET);
8276fdb335fSHans de Goede 	} else {
8286fdb335fSHans de Goede 		msleep(intel_dsi->panel_on_delay);
8296fdb335fSHans de Goede 	}
830379bc100SJani Nikula 
831379bc100SJani Nikula 	if (IS_GEMINILAKE(dev_priv)) {
832379bc100SJani Nikula 		glk_cold_boot = glk_dsi_enable_io(encoder);
833379bc100SJani Nikula 
834379bc100SJani Nikula 		/* Prepare port in cold boot(s3/s4) scenario */
835379bc100SJani Nikula 		if (glk_cold_boot)
836379bc100SJani Nikula 			intel_dsi_prepare(encoder, pipe_config);
837379bc100SJani Nikula 	}
838379bc100SJani Nikula 
839379bc100SJani Nikula 	/* Put device in ready state (LP-11) */
840379bc100SJani Nikula 	intel_dsi_device_ready(encoder);
841379bc100SJani Nikula 
842379bc100SJani Nikula 	/* Prepare port in normal boot scenario */
843379bc100SJani Nikula 	if (IS_GEMINILAKE(dev_priv) && !glk_cold_boot)
844379bc100SJani Nikula 		intel_dsi_prepare(encoder, pipe_config);
845379bc100SJani Nikula 
846379bc100SJani Nikula 	/* Send initialization commands in LP mode */
847379bc100SJani Nikula 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_INIT_OTP);
848379bc100SJani Nikula 
849379bc100SJani Nikula 	/* Enable port in pre-enable phase itself because as per hw team
850379bc100SJani Nikula 	 * recommendation, port should be enabled befor plane & pipe */
851379bc100SJani Nikula 	if (is_cmd_mode(intel_dsi)) {
852379bc100SJani Nikula 		for_each_dsi_port(port, intel_dsi->ports)
853992d4694SJani Nikula 			intel_de_write(dev_priv,
854992d4694SJani Nikula 				       MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
855379bc100SJani Nikula 		intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_TEAR_ON);
856379bc100SJani Nikula 		intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON);
857379bc100SJani Nikula 	} else {
858379bc100SJani Nikula 		msleep(20); /* XXX */
859379bc100SJani Nikula 		for_each_dsi_port(port, intel_dsi->ports)
860379bc100SJani Nikula 			dpi_send_cmd(intel_dsi, TURN_ON, false, port);
861379bc100SJani Nikula 		intel_dsi_msleep(intel_dsi, 100);
862379bc100SJani Nikula 
863379bc100SJani Nikula 		intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON);
864379bc100SJani Nikula 
865379bc100SJani Nikula 		intel_dsi_port_enable(encoder, pipe_config);
866379bc100SJani Nikula 	}
867379bc100SJani Nikula 
868379bc100SJani Nikula 	intel_panel_enable_backlight(pipe_config, conn_state);
869379bc100SJani Nikula 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_ON);
870379bc100SJani Nikula }
871379bc100SJani Nikula 
872ede9771dSVille Syrjälä static void bxt_dsi_enable(struct intel_atomic_state *state,
873ede9771dSVille Syrjälä 			   struct intel_encoder *encoder,
87421fd23acSJani Nikula 			   const struct intel_crtc_state *crtc_state,
87521fd23acSJani Nikula 			   const struct drm_connector_state *conn_state)
87621fd23acSJani Nikula {
877007ff34eSPankaj Bharadiya 	drm_WARN_ON(state->base.dev, crtc_state->has_pch_encoder);
87821fd23acSJani Nikula 
87921fd23acSJani Nikula 	intel_crtc_vblank_on(crtc_state);
88021fd23acSJani Nikula }
88121fd23acSJani Nikula 
882379bc100SJani Nikula /*
883379bc100SJani Nikula  * DSI port disable has to be done after pipe and plane disable, so we do it in
884379bc100SJani Nikula  * the post_disable hook.
885379bc100SJani Nikula  */
886ede9771dSVille Syrjälä static void intel_dsi_disable(struct intel_atomic_state *state,
887ede9771dSVille Syrjälä 			      struct intel_encoder *encoder,
888379bc100SJani Nikula 			      const struct intel_crtc_state *old_crtc_state,
889379bc100SJani Nikula 			      const struct drm_connector_state *old_conn_state)
890379bc100SJani Nikula {
891dd10a80fSJani Nikula 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
892b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
893379bc100SJani Nikula 	enum port port;
894379bc100SJani Nikula 
895dd10a80fSJani Nikula 	drm_dbg_kms(&i915->drm, "\n");
896379bc100SJani Nikula 
897379bc100SJani Nikula 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_OFF);
898379bc100SJani Nikula 	intel_panel_disable_backlight(old_conn_state);
899379bc100SJani Nikula 
900379bc100SJani Nikula 	/*
901379bc100SJani Nikula 	 * According to the spec we should send SHUTDOWN before
902379bc100SJani Nikula 	 * MIPI_SEQ_DISPLAY_OFF only for v3+ VBTs, but field testing
903379bc100SJani Nikula 	 * has shown that the v3 sequence works for v2 VBTs too
904379bc100SJani Nikula 	 */
905379bc100SJani Nikula 	if (is_vid_mode(intel_dsi)) {
906379bc100SJani Nikula 		/* Send Shutdown command to the panel in LP mode */
907379bc100SJani Nikula 		for_each_dsi_port(port, intel_dsi->ports)
908379bc100SJani Nikula 			dpi_send_cmd(intel_dsi, SHUTDOWN, false, port);
909379bc100SJani Nikula 		msleep(10);
910379bc100SJani Nikula 	}
911379bc100SJani Nikula }
912379bc100SJani Nikula 
913379bc100SJani Nikula static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
914379bc100SJani Nikula {
915379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
916379bc100SJani Nikula 
917379bc100SJani Nikula 	if (IS_GEMINILAKE(dev_priv))
918379bc100SJani Nikula 		glk_dsi_clear_device_ready(encoder);
919379bc100SJani Nikula 	else
920379bc100SJani Nikula 		vlv_dsi_clear_device_ready(encoder);
921379bc100SJani Nikula }
922379bc100SJani Nikula 
923ede9771dSVille Syrjälä static void intel_dsi_post_disable(struct intel_atomic_state *state,
924ede9771dSVille Syrjälä 				   struct intel_encoder *encoder,
925773b4b54SVille Syrjälä 				   const struct intel_crtc_state *old_crtc_state,
926773b4b54SVille Syrjälä 				   const struct drm_connector_state *old_conn_state)
927379bc100SJani Nikula {
928379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
929b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
930379bc100SJani Nikula 	enum port port;
931379bc100SJani Nikula 	u32 val;
932379bc100SJani Nikula 
933f1f76d7aSWambui Karuga 	drm_dbg_kms(&dev_priv->drm, "\n");
934379bc100SJani Nikula 
935773b4b54SVille Syrjälä 	if (IS_GEN9_LP(dev_priv)) {
936773b4b54SVille Syrjälä 		intel_crtc_vblank_off(old_crtc_state);
937773b4b54SVille Syrjälä 
938f6df4d46SLucas De Marchi 		skl_scaler_disable(old_crtc_state);
939773b4b54SVille Syrjälä 	}
940773b4b54SVille Syrjälä 
941379bc100SJani Nikula 	if (is_vid_mode(intel_dsi)) {
942379bc100SJani Nikula 		for_each_dsi_port(port, intel_dsi->ports)
943379bc100SJani Nikula 			vlv_dsi_wait_for_fifo_empty(intel_dsi, port);
944379bc100SJani Nikula 
945379bc100SJani Nikula 		intel_dsi_port_disable(encoder);
946379bc100SJani Nikula 		usleep_range(2000, 5000);
947379bc100SJani Nikula 	}
948379bc100SJani Nikula 
949379bc100SJani Nikula 	intel_dsi_unprepare(encoder);
950379bc100SJani Nikula 
951379bc100SJani Nikula 	/*
952379bc100SJani Nikula 	 * if disable packets are sent before sending shutdown packet then in
953379bc100SJani Nikula 	 * some next enable sequence send turn on packet error is observed
954379bc100SJani Nikula 	 */
955379bc100SJani Nikula 	if (is_cmd_mode(intel_dsi))
956379bc100SJani Nikula 		intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_TEAR_OFF);
957379bc100SJani Nikula 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_OFF);
958379bc100SJani Nikula 
959379bc100SJani Nikula 	/* Transition to LP-00 */
960379bc100SJani Nikula 	intel_dsi_clear_device_ready(encoder);
961379bc100SJani Nikula 
962379bc100SJani Nikula 	if (IS_BROXTON(dev_priv)) {
963379bc100SJani Nikula 		/* Power down DSI regulator to save power */
964992d4694SJani Nikula 		intel_de_write(dev_priv, BXT_P_DSI_REGULATOR_CFG, STAP_SELECT);
965992d4694SJani Nikula 		intel_de_write(dev_priv, BXT_P_DSI_REGULATOR_TX_CTRL,
966992d4694SJani Nikula 			       HS_IO_CTRL_SELECT);
967379bc100SJani Nikula 
968379bc100SJani Nikula 		/* Add MIPI IO reset programming for modeset */
969992d4694SJani Nikula 		val = intel_de_read(dev_priv, BXT_P_CR_GT_DISP_PWRON);
970992d4694SJani Nikula 		intel_de_write(dev_priv, BXT_P_CR_GT_DISP_PWRON,
971379bc100SJani Nikula 			       val & ~MIPIO_RST_CTRL);
972379bc100SJani Nikula 	}
973379bc100SJani Nikula 
974379bc100SJani Nikula 	if (IS_GEN9_LP(dev_priv)) {
975379bc100SJani Nikula 		bxt_dsi_pll_disable(encoder);
976379bc100SJani Nikula 	} else {
977379bc100SJani Nikula 		u32 val;
978379bc100SJani Nikula 
979379bc100SJani Nikula 		vlv_dsi_pll_disable(encoder);
980379bc100SJani Nikula 
981992d4694SJani Nikula 		val = intel_de_read(dev_priv, DSPCLK_GATE_D);
982379bc100SJani Nikula 		val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
983992d4694SJani Nikula 		intel_de_write(dev_priv, DSPCLK_GATE_D, val);
984379bc100SJani Nikula 	}
985379bc100SJani Nikula 
986379bc100SJani Nikula 	/* Assert reset */
987379bc100SJani Nikula 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_ASSERT_RESET);
988379bc100SJani Nikula 
989379bc100SJani Nikula 	intel_dsi_msleep(intel_dsi, intel_dsi->panel_off_delay);
990379bc100SJani Nikula 	intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_OFF);
991379bc100SJani Nikula 
992379bc100SJani Nikula 	/*
993379bc100SJani Nikula 	 * FIXME As we do with eDP, just make a note of the time here
994379bc100SJani Nikula 	 * and perform the wait before the next panel power on.
995379bc100SJani Nikula 	 */
996379bc100SJani Nikula 	intel_dsi_msleep(intel_dsi, intel_dsi->panel_pwr_cycle_delay);
997379bc100SJani Nikula }
998379bc100SJani Nikula 
999f13c2a00SVille Syrjälä static void intel_dsi_shutdown(struct intel_encoder *encoder)
1000f13c2a00SVille Syrjälä {
1001f13c2a00SVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
1002f13c2a00SVille Syrjälä 
1003f13c2a00SVille Syrjälä 	intel_dsi_msleep(intel_dsi, intel_dsi->panel_pwr_cycle_delay);
1004f13c2a00SVille Syrjälä }
1005f13c2a00SVille Syrjälä 
1006379bc100SJani Nikula static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
1007379bc100SJani Nikula 				   enum pipe *pipe)
1008379bc100SJani Nikula {
1009379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1010b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
1011379bc100SJani Nikula 	intel_wakeref_t wakeref;
1012379bc100SJani Nikula 	enum port port;
1013379bc100SJani Nikula 	bool active = false;
1014379bc100SJani Nikula 
1015f1f76d7aSWambui Karuga 	drm_dbg_kms(&dev_priv->drm, "\n");
1016379bc100SJani Nikula 
1017379bc100SJani Nikula 	wakeref = intel_display_power_get_if_enabled(dev_priv,
1018379bc100SJani Nikula 						     encoder->power_domain);
1019379bc100SJani Nikula 	if (!wakeref)
1020379bc100SJani Nikula 		return false;
1021379bc100SJani Nikula 
1022379bc100SJani Nikula 	/*
1023379bc100SJani Nikula 	 * On Broxton the PLL needs to be enabled with a valid divider
1024379bc100SJani Nikula 	 * configuration, otherwise accessing DSI registers will hang the
1025379bc100SJani Nikula 	 * machine. See BSpec North Display Engine registers/MIPI[BXT].
1026379bc100SJani Nikula 	 */
1027379bc100SJani Nikula 	if (IS_GEN9_LP(dev_priv) && !bxt_dsi_pll_is_enabled(dev_priv))
1028379bc100SJani Nikula 		goto out_put_power;
1029379bc100SJani Nikula 
1030379bc100SJani Nikula 	/* XXX: this only works for one DSI output */
1031379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
1032379bc100SJani Nikula 		i915_reg_t ctrl_reg = IS_GEN9_LP(dev_priv) ?
1033379bc100SJani Nikula 			BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
1034992d4694SJani Nikula 		bool enabled = intel_de_read(dev_priv, ctrl_reg) & DPI_ENABLE;
1035379bc100SJani Nikula 
1036379bc100SJani Nikula 		/*
1037379bc100SJani Nikula 		 * Due to some hardware limitations on VLV/CHV, the DPI enable
1038379bc100SJani Nikula 		 * bit in port C control register does not get set. As a
1039379bc100SJani Nikula 		 * workaround, check pipe B conf instead.
1040379bc100SJani Nikula 		 */
1041379bc100SJani Nikula 		if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1042379bc100SJani Nikula 		    port == PORT_C)
1043992d4694SJani Nikula 			enabled = intel_de_read(dev_priv, PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
1044379bc100SJani Nikula 
1045379bc100SJani Nikula 		/* Try command mode if video mode not enabled */
1046379bc100SJani Nikula 		if (!enabled) {
1047992d4694SJani Nikula 			u32 tmp = intel_de_read(dev_priv,
1048992d4694SJani Nikula 						MIPI_DSI_FUNC_PRG(port));
1049379bc100SJani Nikula 			enabled = tmp & CMD_MODE_DATA_WIDTH_MASK;
1050379bc100SJani Nikula 		}
1051379bc100SJani Nikula 
1052379bc100SJani Nikula 		if (!enabled)
1053379bc100SJani Nikula 			continue;
1054379bc100SJani Nikula 
1055992d4694SJani Nikula 		if (!(intel_de_read(dev_priv, MIPI_DEVICE_READY(port)) & DEVICE_READY))
1056379bc100SJani Nikula 			continue;
1057379bc100SJani Nikula 
1058379bc100SJani Nikula 		if (IS_GEN9_LP(dev_priv)) {
1059992d4694SJani Nikula 			u32 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
1060379bc100SJani Nikula 			tmp &= BXT_PIPE_SELECT_MASK;
1061379bc100SJani Nikula 			tmp >>= BXT_PIPE_SELECT_SHIFT;
1062379bc100SJani Nikula 
1063f4224a4cSPankaj Bharadiya 			if (drm_WARN_ON(&dev_priv->drm, tmp > PIPE_C))
1064379bc100SJani Nikula 				continue;
1065379bc100SJani Nikula 
1066379bc100SJani Nikula 			*pipe = tmp;
1067379bc100SJani Nikula 		} else {
1068379bc100SJani Nikula 			*pipe = port == PORT_A ? PIPE_A : PIPE_B;
1069379bc100SJani Nikula 		}
1070379bc100SJani Nikula 
1071379bc100SJani Nikula 		active = true;
1072379bc100SJani Nikula 		break;
1073379bc100SJani Nikula 	}
1074379bc100SJani Nikula 
1075379bc100SJani Nikula out_put_power:
1076379bc100SJani Nikula 	intel_display_power_put(dev_priv, encoder->power_domain, wakeref);
1077379bc100SJani Nikula 
1078379bc100SJani Nikula 	return active;
1079379bc100SJani Nikula }
1080379bc100SJani Nikula 
1081379bc100SJani Nikula static void bxt_dsi_get_pipe_config(struct intel_encoder *encoder,
1082379bc100SJani Nikula 				    struct intel_crtc_state *pipe_config)
1083379bc100SJani Nikula {
1084379bc100SJani Nikula 	struct drm_device *dev = encoder->base.dev;
1085379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
1086379bc100SJani Nikula 	struct drm_display_mode *adjusted_mode =
10871326a92cSMaarten Lankhorst 					&pipe_config->hw.adjusted_mode;
1088379bc100SJani Nikula 	struct drm_display_mode *adjusted_mode_sw;
10892225f3c6SMaarten Lankhorst 	struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
1090b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
1091379bc100SJani Nikula 	unsigned int lane_count = intel_dsi->lane_count;
1092379bc100SJani Nikula 	unsigned int bpp, fmt;
1093379bc100SJani Nikula 	enum port port;
1094379bc100SJani Nikula 	u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
1095379bc100SJani Nikula 	u16 hfp_sw, hsync_sw, hbp_sw;
1096379bc100SJani Nikula 	u16 crtc_htotal_sw, crtc_hsync_start_sw, crtc_hsync_end_sw,
1097379bc100SJani Nikula 				crtc_hblank_start_sw, crtc_hblank_end_sw;
1098379bc100SJani Nikula 
1099379bc100SJani Nikula 	/* FIXME: hw readout should not depend on SW state */
11001326a92cSMaarten Lankhorst 	adjusted_mode_sw = &crtc->config->hw.adjusted_mode;
1101379bc100SJani Nikula 
1102379bc100SJani Nikula 	/*
1103379bc100SJani Nikula 	 * Atleast one port is active as encoder->get_config called only if
1104379bc100SJani Nikula 	 * encoder->get_hw_state() returns true.
1105379bc100SJani Nikula 	 */
1106379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
1107992d4694SJani Nikula 		if (intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port)) & DPI_ENABLE)
1108379bc100SJani Nikula 			break;
1109379bc100SJani Nikula 	}
1110379bc100SJani Nikula 
1111992d4694SJani Nikula 	fmt = intel_de_read(dev_priv, MIPI_DSI_FUNC_PRG(port)) & VID_MODE_FORMAT_MASK;
1112379bc100SJani Nikula 	bpp = mipi_dsi_pixel_format_to_bpp(
1113379bc100SJani Nikula 			pixel_format_from_register_bits(fmt));
1114379bc100SJani Nikula 
1115379bc100SJani Nikula 	pipe_config->pipe_bpp = bdw_get_pipemisc_bpp(crtc);
1116379bc100SJani Nikula 
1117379bc100SJani Nikula 	/* Enable Frame time stamo based scanline reporting */
1118af157b76SVille Syrjälä 	pipe_config->mode_flags |=
1119379bc100SJani Nikula 		I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP;
1120379bc100SJani Nikula 
1121379bc100SJani Nikula 	/* In terms of pixels */
1122379bc100SJani Nikula 	adjusted_mode->crtc_hdisplay =
1123992d4694SJani Nikula 				intel_de_read(dev_priv,
1124992d4694SJani Nikula 				              BXT_MIPI_TRANS_HACTIVE(port));
1125379bc100SJani Nikula 	adjusted_mode->crtc_vdisplay =
1126992d4694SJani Nikula 				intel_de_read(dev_priv,
1127992d4694SJani Nikula 				              BXT_MIPI_TRANS_VACTIVE(port));
1128379bc100SJani Nikula 	adjusted_mode->crtc_vtotal =
1129992d4694SJani Nikula 				intel_de_read(dev_priv,
1130992d4694SJani Nikula 				              BXT_MIPI_TRANS_VTOTAL(port));
1131379bc100SJani Nikula 
1132379bc100SJani Nikula 	hactive = adjusted_mode->crtc_hdisplay;
1133992d4694SJani Nikula 	hfp = intel_de_read(dev_priv, MIPI_HFP_COUNT(port));
1134379bc100SJani Nikula 
1135379bc100SJani Nikula 	/*
1136379bc100SJani Nikula 	 * Meaningful for video mode non-burst sync pulse mode only,
1137379bc100SJani Nikula 	 * can be zero for non-burst sync events and burst modes
1138379bc100SJani Nikula 	 */
1139992d4694SJani Nikula 	hsync = intel_de_read(dev_priv, MIPI_HSYNC_PADDING_COUNT(port));
1140992d4694SJani Nikula 	hbp = intel_de_read(dev_priv, MIPI_HBP_COUNT(port));
1141379bc100SJani Nikula 
1142379bc100SJani Nikula 	/* harizontal values are in terms of high speed byte clock */
1143379bc100SJani Nikula 	hfp = pixels_from_txbyteclkhs(hfp, bpp, lane_count,
1144379bc100SJani Nikula 						intel_dsi->burst_mode_ratio);
1145379bc100SJani Nikula 	hsync = pixels_from_txbyteclkhs(hsync, bpp, lane_count,
1146379bc100SJani Nikula 						intel_dsi->burst_mode_ratio);
1147379bc100SJani Nikula 	hbp = pixels_from_txbyteclkhs(hbp, bpp, lane_count,
1148379bc100SJani Nikula 						intel_dsi->burst_mode_ratio);
1149379bc100SJani Nikula 
1150379bc100SJani Nikula 	if (intel_dsi->dual_link) {
1151379bc100SJani Nikula 		hfp *= 2;
1152379bc100SJani Nikula 		hsync *= 2;
1153379bc100SJani Nikula 		hbp *= 2;
1154379bc100SJani Nikula 	}
1155379bc100SJani Nikula 
1156379bc100SJani Nikula 	/* vertical values are in terms of lines */
1157992d4694SJani Nikula 	vfp = intel_de_read(dev_priv, MIPI_VFP_COUNT(port));
1158992d4694SJani Nikula 	vsync = intel_de_read(dev_priv, MIPI_VSYNC_PADDING_COUNT(port));
1159992d4694SJani Nikula 	vbp = intel_de_read(dev_priv, MIPI_VBP_COUNT(port));
1160379bc100SJani Nikula 
1161379bc100SJani Nikula 	adjusted_mode->crtc_htotal = hactive + hfp + hsync + hbp;
1162379bc100SJani Nikula 	adjusted_mode->crtc_hsync_start = hfp + adjusted_mode->crtc_hdisplay;
1163379bc100SJani Nikula 	adjusted_mode->crtc_hsync_end = hsync + adjusted_mode->crtc_hsync_start;
1164379bc100SJani Nikula 	adjusted_mode->crtc_hblank_start = adjusted_mode->crtc_hdisplay;
1165379bc100SJani Nikula 	adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_htotal;
1166379bc100SJani Nikula 
1167379bc100SJani Nikula 	adjusted_mode->crtc_vsync_start = vfp + adjusted_mode->crtc_vdisplay;
1168379bc100SJani Nikula 	adjusted_mode->crtc_vsync_end = vsync + adjusted_mode->crtc_vsync_start;
1169379bc100SJani Nikula 	adjusted_mode->crtc_vblank_start = adjusted_mode->crtc_vdisplay;
1170379bc100SJani Nikula 	adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vtotal;
1171379bc100SJani Nikula 
1172379bc100SJani Nikula 	/*
1173379bc100SJani Nikula 	 * In BXT DSI there is no regs programmed with few horizontal timings
1174379bc100SJani Nikula 	 * in Pixels but txbyteclkhs.. So retrieval process adds some
1175379bc100SJani Nikula 	 * ROUND_UP ERRORS in the process of PIXELS<==>txbyteclkhs.
1176379bc100SJani Nikula 	 * Actually here for the given adjusted_mode, we are calculating the
1177379bc100SJani Nikula 	 * value programmed to the port and then back to the horizontal timing
1178379bc100SJani Nikula 	 * param in pixels. This is the expected value, including roundup errors
1179379bc100SJani Nikula 	 * And if that is same as retrieved value from port, then
1180379bc100SJani Nikula 	 * (HW state) adjusted_mode's horizontal timings are corrected to
1181379bc100SJani Nikula 	 * match with SW state to nullify the errors.
1182379bc100SJani Nikula 	 */
1183379bc100SJani Nikula 	/* Calculating the value programmed to the Port register */
1184379bc100SJani Nikula 	hfp_sw = adjusted_mode_sw->crtc_hsync_start -
1185379bc100SJani Nikula 					adjusted_mode_sw->crtc_hdisplay;
1186379bc100SJani Nikula 	hsync_sw = adjusted_mode_sw->crtc_hsync_end -
1187379bc100SJani Nikula 					adjusted_mode_sw->crtc_hsync_start;
1188379bc100SJani Nikula 	hbp_sw = adjusted_mode_sw->crtc_htotal -
1189379bc100SJani Nikula 					adjusted_mode_sw->crtc_hsync_end;
1190379bc100SJani Nikula 
1191379bc100SJani Nikula 	if (intel_dsi->dual_link) {
1192379bc100SJani Nikula 		hfp_sw /= 2;
1193379bc100SJani Nikula 		hsync_sw /= 2;
1194379bc100SJani Nikula 		hbp_sw /= 2;
1195379bc100SJani Nikula 	}
1196379bc100SJani Nikula 
1197379bc100SJani Nikula 	hfp_sw = txbyteclkhs(hfp_sw, bpp, lane_count,
1198379bc100SJani Nikula 						intel_dsi->burst_mode_ratio);
1199379bc100SJani Nikula 	hsync_sw = txbyteclkhs(hsync_sw, bpp, lane_count,
1200379bc100SJani Nikula 			    intel_dsi->burst_mode_ratio);
1201379bc100SJani Nikula 	hbp_sw = txbyteclkhs(hbp_sw, bpp, lane_count,
1202379bc100SJani Nikula 						intel_dsi->burst_mode_ratio);
1203379bc100SJani Nikula 
1204379bc100SJani Nikula 	/* Reverse calculating the adjusted mode parameters from port reg vals*/
1205379bc100SJani Nikula 	hfp_sw = pixels_from_txbyteclkhs(hfp_sw, bpp, lane_count,
1206379bc100SJani Nikula 						intel_dsi->burst_mode_ratio);
1207379bc100SJani Nikula 	hsync_sw = pixels_from_txbyteclkhs(hsync_sw, bpp, lane_count,
1208379bc100SJani Nikula 						intel_dsi->burst_mode_ratio);
1209379bc100SJani Nikula 	hbp_sw = pixels_from_txbyteclkhs(hbp_sw, bpp, lane_count,
1210379bc100SJani Nikula 						intel_dsi->burst_mode_ratio);
1211379bc100SJani Nikula 
1212379bc100SJani Nikula 	if (intel_dsi->dual_link) {
1213379bc100SJani Nikula 		hfp_sw *= 2;
1214379bc100SJani Nikula 		hsync_sw *= 2;
1215379bc100SJani Nikula 		hbp_sw *= 2;
1216379bc100SJani Nikula 	}
1217379bc100SJani Nikula 
1218379bc100SJani Nikula 	crtc_htotal_sw = adjusted_mode_sw->crtc_hdisplay + hfp_sw +
1219379bc100SJani Nikula 							hsync_sw + hbp_sw;
1220379bc100SJani Nikula 	crtc_hsync_start_sw = hfp_sw + adjusted_mode_sw->crtc_hdisplay;
1221379bc100SJani Nikula 	crtc_hsync_end_sw = hsync_sw + crtc_hsync_start_sw;
1222379bc100SJani Nikula 	crtc_hblank_start_sw = adjusted_mode_sw->crtc_hdisplay;
1223379bc100SJani Nikula 	crtc_hblank_end_sw = crtc_htotal_sw;
1224379bc100SJani Nikula 
1225379bc100SJani Nikula 	if (adjusted_mode->crtc_htotal == crtc_htotal_sw)
1226379bc100SJani Nikula 		adjusted_mode->crtc_htotal = adjusted_mode_sw->crtc_htotal;
1227379bc100SJani Nikula 
1228379bc100SJani Nikula 	if (adjusted_mode->crtc_hsync_start == crtc_hsync_start_sw)
1229379bc100SJani Nikula 		adjusted_mode->crtc_hsync_start =
1230379bc100SJani Nikula 					adjusted_mode_sw->crtc_hsync_start;
1231379bc100SJani Nikula 
1232379bc100SJani Nikula 	if (adjusted_mode->crtc_hsync_end == crtc_hsync_end_sw)
1233379bc100SJani Nikula 		adjusted_mode->crtc_hsync_end =
1234379bc100SJani Nikula 					adjusted_mode_sw->crtc_hsync_end;
1235379bc100SJani Nikula 
1236379bc100SJani Nikula 	if (adjusted_mode->crtc_hblank_start == crtc_hblank_start_sw)
1237379bc100SJani Nikula 		adjusted_mode->crtc_hblank_start =
1238379bc100SJani Nikula 					adjusted_mode_sw->crtc_hblank_start;
1239379bc100SJani Nikula 
1240379bc100SJani Nikula 	if (adjusted_mode->crtc_hblank_end == crtc_hblank_end_sw)
1241379bc100SJani Nikula 		adjusted_mode->crtc_hblank_end =
1242379bc100SJani Nikula 					adjusted_mode_sw->crtc_hblank_end;
1243379bc100SJani Nikula }
1244379bc100SJani Nikula 
1245379bc100SJani Nikula static void intel_dsi_get_config(struct intel_encoder *encoder,
1246379bc100SJani Nikula 				 struct intel_crtc_state *pipe_config)
1247379bc100SJani Nikula {
1248379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1249379bc100SJani Nikula 	u32 pclk;
1250f1f76d7aSWambui Karuga 	drm_dbg_kms(&dev_priv->drm, "\n");
1251379bc100SJani Nikula 
1252379bc100SJani Nikula 	pipe_config->output_types |= BIT(INTEL_OUTPUT_DSI);
1253379bc100SJani Nikula 
1254379bc100SJani Nikula 	if (IS_GEN9_LP(dev_priv)) {
1255379bc100SJani Nikula 		bxt_dsi_get_pipe_config(encoder, pipe_config);
1256379bc100SJani Nikula 		pclk = bxt_dsi_get_pclk(encoder, pipe_config);
1257379bc100SJani Nikula 	} else {
1258379bc100SJani Nikula 		pclk = vlv_dsi_get_pclk(encoder, pipe_config);
1259379bc100SJani Nikula 	}
1260379bc100SJani Nikula 
1261379bc100SJani Nikula 	if (pclk) {
12621326a92cSMaarten Lankhorst 		pipe_config->hw.adjusted_mode.crtc_clock = pclk;
1263379bc100SJani Nikula 		pipe_config->port_clock = pclk;
1264379bc100SJani Nikula 	}
1265379bc100SJani Nikula }
1266379bc100SJani Nikula 
1267379bc100SJani Nikula /* return txclkesc cycles in terms of divider and duration in us */
1268379bc100SJani Nikula static u16 txclkesc(u32 divider, unsigned int us)
1269379bc100SJani Nikula {
1270379bc100SJani Nikula 	switch (divider) {
1271379bc100SJani Nikula 	case ESCAPE_CLOCK_DIVIDER_1:
1272379bc100SJani Nikula 	default:
1273379bc100SJani Nikula 		return 20 * us;
1274379bc100SJani Nikula 	case ESCAPE_CLOCK_DIVIDER_2:
1275379bc100SJani Nikula 		return 10 * us;
1276379bc100SJani Nikula 	case ESCAPE_CLOCK_DIVIDER_4:
1277379bc100SJani Nikula 		return 5 * us;
1278379bc100SJani Nikula 	}
1279379bc100SJani Nikula }
1280379bc100SJani Nikula 
1281379bc100SJani Nikula static void set_dsi_timings(struct drm_encoder *encoder,
1282379bc100SJani Nikula 			    const struct drm_display_mode *adjusted_mode)
1283379bc100SJani Nikula {
1284379bc100SJani Nikula 	struct drm_device *dev = encoder->dev;
1285379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
1286b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(encoder));
1287379bc100SJani Nikula 	enum port port;
1288379bc100SJani Nikula 	unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
1289379bc100SJani Nikula 	unsigned int lane_count = intel_dsi->lane_count;
1290379bc100SJani Nikula 
1291379bc100SJani Nikula 	u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
1292379bc100SJani Nikula 
1293379bc100SJani Nikula 	hactive = adjusted_mode->crtc_hdisplay;
1294379bc100SJani Nikula 	hfp = adjusted_mode->crtc_hsync_start - adjusted_mode->crtc_hdisplay;
1295379bc100SJani Nikula 	hsync = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
1296379bc100SJani Nikula 	hbp = adjusted_mode->crtc_htotal - adjusted_mode->crtc_hsync_end;
1297379bc100SJani Nikula 
1298379bc100SJani Nikula 	if (intel_dsi->dual_link) {
1299379bc100SJani Nikula 		hactive /= 2;
1300379bc100SJani Nikula 		if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
1301379bc100SJani Nikula 			hactive += intel_dsi->pixel_overlap;
1302379bc100SJani Nikula 		hfp /= 2;
1303379bc100SJani Nikula 		hsync /= 2;
1304379bc100SJani Nikula 		hbp /= 2;
1305379bc100SJani Nikula 	}
1306379bc100SJani Nikula 
1307379bc100SJani Nikula 	vfp = adjusted_mode->crtc_vsync_start - adjusted_mode->crtc_vdisplay;
1308379bc100SJani Nikula 	vsync = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
1309379bc100SJani Nikula 	vbp = adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vsync_end;
1310379bc100SJani Nikula 
1311379bc100SJani Nikula 	/* horizontal values are in terms of high speed byte clock */
1312379bc100SJani Nikula 	hactive = txbyteclkhs(hactive, bpp, lane_count,
1313379bc100SJani Nikula 			      intel_dsi->burst_mode_ratio);
1314379bc100SJani Nikula 	hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
1315379bc100SJani Nikula 	hsync = txbyteclkhs(hsync, bpp, lane_count,
1316379bc100SJani Nikula 			    intel_dsi->burst_mode_ratio);
1317379bc100SJani Nikula 	hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
1318379bc100SJani Nikula 
1319379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
1320379bc100SJani Nikula 		if (IS_GEN9_LP(dev_priv)) {
1321379bc100SJani Nikula 			/*
1322379bc100SJani Nikula 			 * Program hdisplay and vdisplay on MIPI transcoder.
1323379bc100SJani Nikula 			 * This is different from calculated hactive and
1324379bc100SJani Nikula 			 * vactive, as they are calculated per channel basis,
1325379bc100SJani Nikula 			 * whereas these values should be based on resolution.
1326379bc100SJani Nikula 			 */
1327992d4694SJani Nikula 			intel_de_write(dev_priv, BXT_MIPI_TRANS_HACTIVE(port),
1328379bc100SJani Nikula 				       adjusted_mode->crtc_hdisplay);
1329992d4694SJani Nikula 			intel_de_write(dev_priv, BXT_MIPI_TRANS_VACTIVE(port),
1330379bc100SJani Nikula 				       adjusted_mode->crtc_vdisplay);
1331992d4694SJani Nikula 			intel_de_write(dev_priv, BXT_MIPI_TRANS_VTOTAL(port),
1332379bc100SJani Nikula 				       adjusted_mode->crtc_vtotal);
1333379bc100SJani Nikula 		}
1334379bc100SJani Nikula 
1335992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_HACTIVE_AREA_COUNT(port),
1336992d4694SJani Nikula 			       hactive);
1337992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_HFP_COUNT(port), hfp);
1338379bc100SJani Nikula 
1339379bc100SJani Nikula 		/* meaningful for video mode non-burst sync pulse mode only,
1340379bc100SJani Nikula 		 * can be zero for non-burst sync events and burst modes */
1341992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_HSYNC_PADDING_COUNT(port),
1342992d4694SJani Nikula 			       hsync);
1343992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_HBP_COUNT(port), hbp);
1344379bc100SJani Nikula 
1345379bc100SJani Nikula 		/* vertical values are in terms of lines */
1346992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_VFP_COUNT(port), vfp);
1347992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_VSYNC_PADDING_COUNT(port),
1348992d4694SJani Nikula 			       vsync);
1349992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_VBP_COUNT(port), vbp);
1350379bc100SJani Nikula 	}
1351379bc100SJani Nikula }
1352379bc100SJani Nikula 
1353379bc100SJani Nikula static u32 pixel_format_to_reg(enum mipi_dsi_pixel_format fmt)
1354379bc100SJani Nikula {
1355379bc100SJani Nikula 	switch (fmt) {
1356379bc100SJani Nikula 	case MIPI_DSI_FMT_RGB888:
1357379bc100SJani Nikula 		return VID_MODE_FORMAT_RGB888;
1358379bc100SJani Nikula 	case MIPI_DSI_FMT_RGB666:
1359379bc100SJani Nikula 		return VID_MODE_FORMAT_RGB666;
1360379bc100SJani Nikula 	case MIPI_DSI_FMT_RGB666_PACKED:
1361379bc100SJani Nikula 		return VID_MODE_FORMAT_RGB666_PACKED;
1362379bc100SJani Nikula 	case MIPI_DSI_FMT_RGB565:
1363379bc100SJani Nikula 		return VID_MODE_FORMAT_RGB565;
1364379bc100SJani Nikula 	default:
1365379bc100SJani Nikula 		MISSING_CASE(fmt);
1366379bc100SJani Nikula 		return VID_MODE_FORMAT_RGB666;
1367379bc100SJani Nikula 	}
1368379bc100SJani Nikula }
1369379bc100SJani Nikula 
1370379bc100SJani Nikula static void intel_dsi_prepare(struct intel_encoder *intel_encoder,
1371379bc100SJani Nikula 			      const struct intel_crtc_state *pipe_config)
1372379bc100SJani Nikula {
1373379bc100SJani Nikula 	struct drm_encoder *encoder = &intel_encoder->base;
1374379bc100SJani Nikula 	struct drm_device *dev = encoder->dev;
1375379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
13762225f3c6SMaarten Lankhorst 	struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc);
1377b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(encoder));
13781326a92cSMaarten Lankhorst 	const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
1379379bc100SJani Nikula 	enum port port;
1380379bc100SJani Nikula 	unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
1381379bc100SJani Nikula 	u32 val, tmp;
1382379bc100SJani Nikula 	u16 mode_hdisplay;
1383379bc100SJani Nikula 
1384f1f76d7aSWambui Karuga 	drm_dbg_kms(&dev_priv->drm, "pipe %c\n", pipe_name(intel_crtc->pipe));
1385379bc100SJani Nikula 
1386379bc100SJani Nikula 	mode_hdisplay = adjusted_mode->crtc_hdisplay;
1387379bc100SJani Nikula 
1388379bc100SJani Nikula 	if (intel_dsi->dual_link) {
1389379bc100SJani Nikula 		mode_hdisplay /= 2;
1390379bc100SJani Nikula 		if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
1391379bc100SJani Nikula 			mode_hdisplay += intel_dsi->pixel_overlap;
1392379bc100SJani Nikula 	}
1393379bc100SJani Nikula 
1394379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
1395379bc100SJani Nikula 		if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1396379bc100SJani Nikula 			/*
1397379bc100SJani Nikula 			 * escape clock divider, 20MHz, shared for A and C.
1398379bc100SJani Nikula 			 * device ready must be off when doing this! txclkesc?
1399379bc100SJani Nikula 			 */
1400992d4694SJani Nikula 			tmp = intel_de_read(dev_priv, MIPI_CTRL(PORT_A));
1401379bc100SJani Nikula 			tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
1402992d4694SJani Nikula 			intel_de_write(dev_priv, MIPI_CTRL(PORT_A),
1403992d4694SJani Nikula 				       tmp | ESCAPE_CLOCK_DIVIDER_1);
1404379bc100SJani Nikula 
1405379bc100SJani Nikula 			/* read request priority is per pipe */
1406992d4694SJani Nikula 			tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
1407379bc100SJani Nikula 			tmp &= ~READ_REQUEST_PRIORITY_MASK;
1408992d4694SJani Nikula 			intel_de_write(dev_priv, MIPI_CTRL(port),
1409992d4694SJani Nikula 				       tmp | READ_REQUEST_PRIORITY_HIGH);
1410379bc100SJani Nikula 		} else if (IS_GEN9_LP(dev_priv)) {
1411379bc100SJani Nikula 			enum pipe pipe = intel_crtc->pipe;
1412379bc100SJani Nikula 
1413992d4694SJani Nikula 			tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
1414379bc100SJani Nikula 			tmp &= ~BXT_PIPE_SELECT_MASK;
1415379bc100SJani Nikula 
1416379bc100SJani Nikula 			tmp |= BXT_PIPE_SELECT(pipe);
1417992d4694SJani Nikula 			intel_de_write(dev_priv, MIPI_CTRL(port), tmp);
1418379bc100SJani Nikula 		}
1419379bc100SJani Nikula 
1420379bc100SJani Nikula 		/* XXX: why here, why like this? handling in irq handler?! */
1421992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_INTR_STAT(port), 0xffffffff);
1422992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_INTR_EN(port), 0xffffffff);
1423379bc100SJani Nikula 
1424992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DPHY_PARAM(port),
1425992d4694SJani Nikula 			       intel_dsi->dphy_reg);
1426379bc100SJani Nikula 
1427992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DPI_RESOLUTION(port),
1428992d4694SJani Nikula 			       adjusted_mode->crtc_vdisplay << VERTICAL_ADDRESS_SHIFT | mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
1429379bc100SJani Nikula 	}
1430379bc100SJani Nikula 
1431379bc100SJani Nikula 	set_dsi_timings(encoder, adjusted_mode);
1432379bc100SJani Nikula 
1433379bc100SJani Nikula 	val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
1434379bc100SJani Nikula 	if (is_cmd_mode(intel_dsi)) {
1435379bc100SJani Nikula 		val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
1436379bc100SJani Nikula 		val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
1437379bc100SJani Nikula 	} else {
1438379bc100SJani Nikula 		val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
1439379bc100SJani Nikula 		val |= pixel_format_to_reg(intel_dsi->pixel_format);
1440379bc100SJani Nikula 	}
1441379bc100SJani Nikula 
1442379bc100SJani Nikula 	tmp = 0;
1443379bc100SJani Nikula 	if (intel_dsi->eotp_pkt == 0)
1444379bc100SJani Nikula 		tmp |= EOT_DISABLE;
1445379bc100SJani Nikula 	if (intel_dsi->clock_stop)
1446379bc100SJani Nikula 		tmp |= CLOCKSTOP;
1447379bc100SJani Nikula 
1448379bc100SJani Nikula 	if (IS_GEN9_LP(dev_priv)) {
1449379bc100SJani Nikula 		tmp |= BXT_DPHY_DEFEATURE_EN;
1450379bc100SJani Nikula 		if (!is_cmd_mode(intel_dsi))
1451379bc100SJani Nikula 			tmp |= BXT_DEFEATURE_DPI_FIFO_CTR;
1452379bc100SJani Nikula 	}
1453379bc100SJani Nikula 
1454379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
1455992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DSI_FUNC_PRG(port), val);
1456379bc100SJani Nikula 
1457379bc100SJani Nikula 		/* timeouts for recovery. one frame IIUC. if counter expires,
1458379bc100SJani Nikula 		 * EOT and stop state. */
1459379bc100SJani Nikula 
1460379bc100SJani Nikula 		/*
1461379bc100SJani Nikula 		 * In burst mode, value greater than one DPI line Time in byte
1462379bc100SJani Nikula 		 * clock (txbyteclkhs) To timeout this timer 1+ of the above
1463379bc100SJani Nikula 		 * said value is recommended.
1464379bc100SJani Nikula 		 *
1465379bc100SJani Nikula 		 * In non-burst mode, Value greater than one DPI frame time in
1466379bc100SJani Nikula 		 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
1467379bc100SJani Nikula 		 * said value is recommended.
1468379bc100SJani Nikula 		 *
1469379bc100SJani Nikula 		 * In DBI only mode, value greater than one DBI frame time in
1470379bc100SJani Nikula 		 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
1471379bc100SJani Nikula 		 * said value is recommended.
1472379bc100SJani Nikula 		 */
1473379bc100SJani Nikula 
1474379bc100SJani Nikula 		if (is_vid_mode(intel_dsi) &&
1475379bc100SJani Nikula 			intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
1476992d4694SJani Nikula 			intel_de_write(dev_priv, MIPI_HS_TX_TIMEOUT(port),
1477992d4694SJani Nikula 				       txbyteclkhs(adjusted_mode->crtc_htotal, bpp, intel_dsi->lane_count, intel_dsi->burst_mode_ratio) + 1);
1478379bc100SJani Nikula 		} else {
1479992d4694SJani Nikula 			intel_de_write(dev_priv, MIPI_HS_TX_TIMEOUT(port),
1480992d4694SJani Nikula 				       txbyteclkhs(adjusted_mode->crtc_vtotal * adjusted_mode->crtc_htotal, bpp, intel_dsi->lane_count, intel_dsi->burst_mode_ratio) + 1);
1481379bc100SJani Nikula 		}
1482992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_LP_RX_TIMEOUT(port),
1483992d4694SJani Nikula 			       intel_dsi->lp_rx_timeout);
1484992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_TURN_AROUND_TIMEOUT(port),
1485379bc100SJani Nikula 			       intel_dsi->turn_arnd_val);
1486992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DEVICE_RESET_TIMER(port),
1487379bc100SJani Nikula 			       intel_dsi->rst_timer_val);
1488379bc100SJani Nikula 
1489379bc100SJani Nikula 		/* dphy stuff */
1490379bc100SJani Nikula 
1491379bc100SJani Nikula 		/* in terms of low power clock */
1492992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_INIT_COUNT(port),
1493379bc100SJani Nikula 			       txclkesc(intel_dsi->escape_clk_div, 100));
1494379bc100SJani Nikula 
1495379bc100SJani Nikula 		if (IS_GEN9_LP(dev_priv) && (!intel_dsi->dual_link)) {
1496379bc100SJani Nikula 			/*
1497379bc100SJani Nikula 			 * BXT spec says write MIPI_INIT_COUNT for
1498379bc100SJani Nikula 			 * both the ports, even if only one is
1499379bc100SJani Nikula 			 * getting used. So write the other port
1500379bc100SJani Nikula 			 * if not in dual link mode.
1501379bc100SJani Nikula 			 */
1502992d4694SJani Nikula 			intel_de_write(dev_priv,
1503992d4694SJani Nikula 				       MIPI_INIT_COUNT(port == PORT_A ? PORT_C : PORT_A),
1504379bc100SJani Nikula 				       intel_dsi->init_count);
1505379bc100SJani Nikula 		}
1506379bc100SJani Nikula 
1507379bc100SJani Nikula 		/* recovery disables */
1508992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_EOT_DISABLE(port), tmp);
1509379bc100SJani Nikula 
1510379bc100SJani Nikula 		/* in terms of low power clock */
1511992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_INIT_COUNT(port),
1512992d4694SJani Nikula 			       intel_dsi->init_count);
1513379bc100SJani Nikula 
1514379bc100SJani Nikula 		/* in terms of txbyteclkhs. actual high to low switch +
1515379bc100SJani Nikula 		 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
1516379bc100SJani Nikula 		 *
1517379bc100SJani Nikula 		 * XXX: write MIPI_STOP_STATE_STALL?
1518379bc100SJani Nikula 		 */
1519992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_HIGH_LOW_SWITCH_COUNT(port),
1520379bc100SJani Nikula 			       intel_dsi->hs_to_lp_count);
1521379bc100SJani Nikula 
1522379bc100SJani Nikula 		/* XXX: low power clock equivalence in terms of byte clock.
1523379bc100SJani Nikula 		 * the number of byte clocks occupied in one low power clock.
1524379bc100SJani Nikula 		 * based on txbyteclkhs and txclkesc.
1525379bc100SJani Nikula 		 * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
1526379bc100SJani Nikula 		 * ) / 105.???
1527379bc100SJani Nikula 		 */
1528992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_LP_BYTECLK(port),
1529992d4694SJani Nikula 			       intel_dsi->lp_byte_clk);
1530379bc100SJani Nikula 
1531379bc100SJani Nikula 		if (IS_GEMINILAKE(dev_priv)) {
1532992d4694SJani Nikula 			intel_de_write(dev_priv, MIPI_TLPX_TIME_COUNT(port),
1533379bc100SJani Nikula 				       intel_dsi->lp_byte_clk);
1534379bc100SJani Nikula 			/* Shadow of DPHY reg */
1535992d4694SJani Nikula 			intel_de_write(dev_priv, MIPI_CLK_LANE_TIMING(port),
1536379bc100SJani Nikula 				       intel_dsi->dphy_reg);
1537379bc100SJani Nikula 		}
1538379bc100SJani Nikula 
1539379bc100SJani Nikula 		/* the bw essential for transmitting 16 long packets containing
1540379bc100SJani Nikula 		 * 252 bytes meant for dcs write memory command is programmed in
1541379bc100SJani Nikula 		 * this register in terms of byte clocks. based on dsi transfer
1542379bc100SJani Nikula 		 * rate and the number of lanes configured the time taken to
1543379bc100SJani Nikula 		 * transmit 16 long packets in a dsi stream varies. */
1544992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DBI_BW_CTRL(port),
1545992d4694SJani Nikula 			       intel_dsi->bw_timer);
1546379bc100SJani Nikula 
1547992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
1548992d4694SJani Nikula 			       intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT | intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
1549379bc100SJani Nikula 
1550379bc100SJani Nikula 		if (is_vid_mode(intel_dsi))
1551379bc100SJani Nikula 			/* Some panels might have resolution which is not a
1552379bc100SJani Nikula 			 * multiple of 64 like 1366 x 768. Enable RANDOM
1553379bc100SJani Nikula 			 * resolution support for such panels by default */
1554992d4694SJani Nikula 			intel_de_write(dev_priv, MIPI_VIDEO_MODE_FORMAT(port),
1555992d4694SJani Nikula 				       intel_dsi->video_frmt_cfg_bits | intel_dsi->video_mode_format | IP_TG_CONFIG | RANDOM_DPI_DISPLAY_RESOLUTION);
1556379bc100SJani Nikula 	}
1557379bc100SJani Nikula }
1558379bc100SJani Nikula 
1559379bc100SJani Nikula static void intel_dsi_unprepare(struct intel_encoder *encoder)
1560379bc100SJani Nikula {
1561379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1562b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
1563379bc100SJani Nikula 	enum port port;
1564379bc100SJani Nikula 	u32 val;
1565379bc100SJani Nikula 
1566379bc100SJani Nikula 	if (IS_GEMINILAKE(dev_priv))
1567379bc100SJani Nikula 		return;
1568379bc100SJani Nikula 
1569379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
1570379bc100SJani Nikula 		/* Panel commands can be sent when clock is in LP11 */
1571992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DEVICE_READY(port), 0x0);
1572379bc100SJani Nikula 
1573379bc100SJani Nikula 		if (IS_GEN9_LP(dev_priv))
1574379bc100SJani Nikula 			bxt_dsi_reset_clocks(encoder, port);
1575379bc100SJani Nikula 		else
1576379bc100SJani Nikula 			vlv_dsi_reset_clocks(encoder, port);
1577992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_EOT_DISABLE(port), CLOCKSTOP);
1578379bc100SJani Nikula 
1579992d4694SJani Nikula 		val = intel_de_read(dev_priv, MIPI_DSI_FUNC_PRG(port));
1580379bc100SJani Nikula 		val &= ~VID_MODE_FORMAT_MASK;
1581992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DSI_FUNC_PRG(port), val);
1582379bc100SJani Nikula 
1583992d4694SJani Nikula 		intel_de_write(dev_priv, MIPI_DEVICE_READY(port), 0x1);
1584379bc100SJani Nikula 	}
1585379bc100SJani Nikula }
1586379bc100SJani Nikula 
1587379bc100SJani Nikula static void intel_dsi_encoder_destroy(struct drm_encoder *encoder)
1588379bc100SJani Nikula {
1589b7d02c3aSVille Syrjälä 	struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(encoder));
1590379bc100SJani Nikula 
1591ea0fe672SHans de Goede 	intel_dsi_vbt_gpio_cleanup(intel_dsi);
1592379bc100SJani Nikula 	intel_encoder_destroy(encoder);
1593379bc100SJani Nikula }
1594379bc100SJani Nikula 
1595379bc100SJani Nikula static const struct drm_encoder_funcs intel_dsi_funcs = {
1596379bc100SJani Nikula 	.destroy = intel_dsi_encoder_destroy,
1597379bc100SJani Nikula };
1598379bc100SJani Nikula 
1599379bc100SJani Nikula static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
1600379bc100SJani Nikula 	.get_modes = intel_dsi_get_modes,
1601379bc100SJani Nikula 	.mode_valid = intel_dsi_mode_valid,
1602379bc100SJani Nikula 	.atomic_check = intel_digital_connector_atomic_check,
1603379bc100SJani Nikula };
1604379bc100SJani Nikula 
1605379bc100SJani Nikula static const struct drm_connector_funcs intel_dsi_connector_funcs = {
1606b81dddb9SVille Syrjälä 	.detect = intel_panel_detect,
1607379bc100SJani Nikula 	.late_register = intel_connector_register,
1608379bc100SJani Nikula 	.early_unregister = intel_connector_unregister,
1609379bc100SJani Nikula 	.destroy = intel_connector_destroy,
1610379bc100SJani Nikula 	.fill_modes = drm_helper_probe_single_connector_modes,
1611379bc100SJani Nikula 	.atomic_get_property = intel_digital_connector_atomic_get_property,
1612379bc100SJani Nikula 	.atomic_set_property = intel_digital_connector_atomic_set_property,
1613379bc100SJani Nikula 	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
1614379bc100SJani Nikula 	.atomic_duplicate_state = intel_digital_connector_duplicate_state,
1615379bc100SJani Nikula };
1616379bc100SJani Nikula 
1617f384e48dSVandita Kulkarni static void vlv_dsi_add_properties(struct intel_connector *connector)
1618379bc100SJani Nikula {
1619379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
1620379bc100SJani Nikula 
1621379bc100SJani Nikula 	if (connector->panel.fixed_mode) {
1622379bc100SJani Nikula 		u32 allowed_scalers;
1623379bc100SJani Nikula 
1624379bc100SJani Nikula 		allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
1625379bc100SJani Nikula 		if (!HAS_GMCH(dev_priv))
1626379bc100SJani Nikula 			allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
1627379bc100SJani Nikula 
1628379bc100SJani Nikula 		drm_connector_attach_scaling_mode_property(&connector->base,
1629379bc100SJani Nikula 								allowed_scalers);
1630379bc100SJani Nikula 
1631379bc100SJani Nikula 		connector->base.state->scaling_mode = DRM_MODE_SCALE_ASPECT;
1632379bc100SJani Nikula 
163369654c63SDerek Basehore 		drm_connector_set_panel_orientation_with_quirk(
1634379bc100SJani Nikula 				&connector->base,
16351ca002adSHans de Goede 				intel_dsi_get_panel_orientation(connector),
1636379bc100SJani Nikula 				connector->panel.fixed_mode->hdisplay,
1637379bc100SJani Nikula 				connector->panel.fixed_mode->vdisplay);
1638379bc100SJani Nikula 	}
1639379bc100SJani Nikula }
1640379bc100SJani Nikula 
1641379bc100SJani Nikula #define NS_KHZ_RATIO		1000000
1642379bc100SJani Nikula 
1643379bc100SJani Nikula #define PREPARE_CNT_MAX		0x3F
1644379bc100SJani Nikula #define EXIT_ZERO_CNT_MAX	0x3F
1645379bc100SJani Nikula #define CLK_ZERO_CNT_MAX	0xFF
1646379bc100SJani Nikula #define TRAIL_CNT_MAX		0x1F
1647379bc100SJani Nikula 
1648379bc100SJani Nikula static void vlv_dphy_param_init(struct intel_dsi *intel_dsi)
1649379bc100SJani Nikula {
1650379bc100SJani Nikula 	struct drm_device *dev = intel_dsi->base.base.dev;
1651379bc100SJani Nikula 	struct drm_i915_private *dev_priv = to_i915(dev);
1652379bc100SJani Nikula 	struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;
1653379bc100SJani Nikula 	u32 tlpx_ns, extra_byte_count, tlpx_ui;
1654379bc100SJani Nikula 	u32 ui_num, ui_den;
1655379bc100SJani Nikula 	u32 prepare_cnt, exit_zero_cnt, clk_zero_cnt, trail_cnt;
1656379bc100SJani Nikula 	u32 ths_prepare_ns, tclk_trail_ns;
1657379bc100SJani Nikula 	u32 tclk_prepare_clkzero, ths_prepare_hszero;
1658379bc100SJani Nikula 	u32 lp_to_hs_switch, hs_to_lp_switch;
1659379bc100SJani Nikula 	u32 mul;
1660379bc100SJani Nikula 
1661379bc100SJani Nikula 	tlpx_ns = intel_dsi_tlpx_ns(intel_dsi);
1662379bc100SJani Nikula 
1663379bc100SJani Nikula 	switch (intel_dsi->lane_count) {
1664379bc100SJani Nikula 	case 1:
1665379bc100SJani Nikula 	case 2:
1666379bc100SJani Nikula 		extra_byte_count = 2;
1667379bc100SJani Nikula 		break;
1668379bc100SJani Nikula 	case 3:
1669379bc100SJani Nikula 		extra_byte_count = 4;
1670379bc100SJani Nikula 		break;
1671379bc100SJani Nikula 	case 4:
1672379bc100SJani Nikula 	default:
1673379bc100SJani Nikula 		extra_byte_count = 3;
1674379bc100SJani Nikula 		break;
1675379bc100SJani Nikula 	}
1676379bc100SJani Nikula 
1677379bc100SJani Nikula 	/* in Kbps */
1678379bc100SJani Nikula 	ui_num = NS_KHZ_RATIO;
1679379bc100SJani Nikula 	ui_den = intel_dsi_bitrate(intel_dsi);
1680379bc100SJani Nikula 
1681379bc100SJani Nikula 	tclk_prepare_clkzero = mipi_config->tclk_prepare_clkzero;
1682379bc100SJani Nikula 	ths_prepare_hszero = mipi_config->ths_prepare_hszero;
1683379bc100SJani Nikula 
1684379bc100SJani Nikula 	/*
1685379bc100SJani Nikula 	 * B060
1686379bc100SJani Nikula 	 * LP byte clock = TLPX/ (8UI)
1687379bc100SJani Nikula 	 */
1688379bc100SJani Nikula 	intel_dsi->lp_byte_clk = DIV_ROUND_UP(tlpx_ns * ui_den, 8 * ui_num);
1689379bc100SJani Nikula 
1690379bc100SJani Nikula 	/* DDR clock period = 2 * UI
1691379bc100SJani Nikula 	 * UI(sec) = 1/(bitrate * 10^3) (bitrate is in KHZ)
1692379bc100SJani Nikula 	 * UI(nsec) = 10^6 / bitrate
1693379bc100SJani Nikula 	 * DDR clock period (nsec) = 2 * UI = (2 * 10^6)/ bitrate
1694379bc100SJani Nikula 	 * DDR clock count  = ns_value / DDR clock period
1695379bc100SJani Nikula 	 *
1696379bc100SJani Nikula 	 * For GEMINILAKE dphy_param_reg will be programmed in terms of
1697379bc100SJani Nikula 	 * HS byte clock count for other platform in HS ddr clock count
1698379bc100SJani Nikula 	 */
1699379bc100SJani Nikula 	mul = IS_GEMINILAKE(dev_priv) ? 8 : 2;
1700379bc100SJani Nikula 	ths_prepare_ns = max(mipi_config->ths_prepare,
1701379bc100SJani Nikula 			     mipi_config->tclk_prepare);
1702379bc100SJani Nikula 
1703379bc100SJani Nikula 	/* prepare count */
1704379bc100SJani Nikula 	prepare_cnt = DIV_ROUND_UP(ths_prepare_ns * ui_den, ui_num * mul);
1705379bc100SJani Nikula 
1706379bc100SJani Nikula 	if (prepare_cnt > PREPARE_CNT_MAX) {
1707f1f76d7aSWambui Karuga 		drm_dbg_kms(&dev_priv->drm, "prepare count too high %u\n",
1708f1f76d7aSWambui Karuga 			    prepare_cnt);
1709379bc100SJani Nikula 		prepare_cnt = PREPARE_CNT_MAX;
1710379bc100SJani Nikula 	}
1711379bc100SJani Nikula 
1712379bc100SJani Nikula 	/* exit zero count */
1713379bc100SJani Nikula 	exit_zero_cnt = DIV_ROUND_UP(
1714379bc100SJani Nikula 				(ths_prepare_hszero - ths_prepare_ns) * ui_den,
1715379bc100SJani Nikula 				ui_num * mul
1716379bc100SJani Nikula 				);
1717379bc100SJani Nikula 
1718379bc100SJani Nikula 	/*
1719379bc100SJani Nikula 	 * Exit zero is unified val ths_zero and ths_exit
1720379bc100SJani Nikula 	 * minimum value for ths_exit = 110ns
1721379bc100SJani Nikula 	 * min (exit_zero_cnt * 2) = 110/UI
1722379bc100SJani Nikula 	 * exit_zero_cnt = 55/UI
1723379bc100SJani Nikula 	 */
1724379bc100SJani Nikula 	if (exit_zero_cnt < (55 * ui_den / ui_num) && (55 * ui_den) % ui_num)
1725379bc100SJani Nikula 		exit_zero_cnt += 1;
1726379bc100SJani Nikula 
1727379bc100SJani Nikula 	if (exit_zero_cnt > EXIT_ZERO_CNT_MAX) {
1728f1f76d7aSWambui Karuga 		drm_dbg_kms(&dev_priv->drm, "exit zero count too high %u\n",
1729f1f76d7aSWambui Karuga 			    exit_zero_cnt);
1730379bc100SJani Nikula 		exit_zero_cnt = EXIT_ZERO_CNT_MAX;
1731379bc100SJani Nikula 	}
1732379bc100SJani Nikula 
1733379bc100SJani Nikula 	/* clk zero count */
1734379bc100SJani Nikula 	clk_zero_cnt = DIV_ROUND_UP(
1735379bc100SJani Nikula 				(tclk_prepare_clkzero -	ths_prepare_ns)
1736379bc100SJani Nikula 				* ui_den, ui_num * mul);
1737379bc100SJani Nikula 
1738379bc100SJani Nikula 	if (clk_zero_cnt > CLK_ZERO_CNT_MAX) {
1739f1f76d7aSWambui Karuga 		drm_dbg_kms(&dev_priv->drm, "clock zero count too high %u\n",
1740f1f76d7aSWambui Karuga 			    clk_zero_cnt);
1741379bc100SJani Nikula 		clk_zero_cnt = CLK_ZERO_CNT_MAX;
1742379bc100SJani Nikula 	}
1743379bc100SJani Nikula 
1744379bc100SJani Nikula 	/* trail count */
1745379bc100SJani Nikula 	tclk_trail_ns = max(mipi_config->tclk_trail, mipi_config->ths_trail);
1746379bc100SJani Nikula 	trail_cnt = DIV_ROUND_UP(tclk_trail_ns * ui_den, ui_num * mul);
1747379bc100SJani Nikula 
1748379bc100SJani Nikula 	if (trail_cnt > TRAIL_CNT_MAX) {
1749f1f76d7aSWambui Karuga 		drm_dbg_kms(&dev_priv->drm, "trail count too high %u\n",
1750f1f76d7aSWambui Karuga 			    trail_cnt);
1751379bc100SJani Nikula 		trail_cnt = TRAIL_CNT_MAX;
1752379bc100SJani Nikula 	}
1753379bc100SJani Nikula 
1754379bc100SJani Nikula 	/* B080 */
1755379bc100SJani Nikula 	intel_dsi->dphy_reg = exit_zero_cnt << 24 | trail_cnt << 16 |
1756379bc100SJani Nikula 						clk_zero_cnt << 8 | prepare_cnt;
1757379bc100SJani Nikula 
1758379bc100SJani Nikula 	/*
1759379bc100SJani Nikula 	 * LP to HS switch count = 4TLPX + PREP_COUNT * mul + EXIT_ZERO_COUNT *
1760379bc100SJani Nikula 	 *					mul + 10UI + Extra Byte Count
1761379bc100SJani Nikula 	 *
1762379bc100SJani Nikula 	 * HS to LP switch count = THS-TRAIL + 2TLPX + Extra Byte Count
1763379bc100SJani Nikula 	 * Extra Byte Count is calculated according to number of lanes.
1764379bc100SJani Nikula 	 * High Low Switch Count is the Max of LP to HS and
1765379bc100SJani Nikula 	 * HS to LP switch count
1766379bc100SJani Nikula 	 *
1767379bc100SJani Nikula 	 */
1768379bc100SJani Nikula 	tlpx_ui = DIV_ROUND_UP(tlpx_ns * ui_den, ui_num);
1769379bc100SJani Nikula 
1770379bc100SJani Nikula 	/* B044 */
1771379bc100SJani Nikula 	/* FIXME:
1772379bc100SJani Nikula 	 * The comment above does not match with the code */
1773379bc100SJani Nikula 	lp_to_hs_switch = DIV_ROUND_UP(4 * tlpx_ui + prepare_cnt * mul +
1774379bc100SJani Nikula 						exit_zero_cnt * mul + 10, 8);
1775379bc100SJani Nikula 
1776379bc100SJani Nikula 	hs_to_lp_switch = DIV_ROUND_UP(mipi_config->ths_trail + 2 * tlpx_ui, 8);
1777379bc100SJani Nikula 
1778379bc100SJani Nikula 	intel_dsi->hs_to_lp_count = max(lp_to_hs_switch, hs_to_lp_switch);
1779379bc100SJani Nikula 	intel_dsi->hs_to_lp_count += extra_byte_count;
1780379bc100SJani Nikula 
1781379bc100SJani Nikula 	/* B088 */
1782379bc100SJani Nikula 	/* LP -> HS for clock lanes
1783379bc100SJani Nikula 	 * LP clk sync + LP11 + LP01 + tclk_prepare + tclk_zero +
1784379bc100SJani Nikula 	 *						extra byte count
1785379bc100SJani Nikula 	 * 2TPLX + 1TLPX + 1 TPLX(in ns) + prepare_cnt * 2 + clk_zero_cnt *
1786379bc100SJani Nikula 	 *					2(in UI) + extra byte count
1787379bc100SJani Nikula 	 * In byteclks = (4TLPX + prepare_cnt * 2 + clk_zero_cnt *2 (in UI)) /
1788379bc100SJani Nikula 	 *					8 + extra byte count
1789379bc100SJani Nikula 	 */
1790379bc100SJani Nikula 	intel_dsi->clk_lp_to_hs_count =
1791379bc100SJani Nikula 		DIV_ROUND_UP(
1792379bc100SJani Nikula 			4 * tlpx_ui + prepare_cnt * 2 +
1793379bc100SJani Nikula 			clk_zero_cnt * 2,
1794379bc100SJani Nikula 			8);
1795379bc100SJani Nikula 
1796379bc100SJani Nikula 	intel_dsi->clk_lp_to_hs_count += extra_byte_count;
1797379bc100SJani Nikula 
1798379bc100SJani Nikula 	/* HS->LP for Clock Lanes
1799379bc100SJani Nikula 	 * Low Power clock synchronisations + 1Tx byteclk + tclk_trail +
1800379bc100SJani Nikula 	 *						Extra byte count
1801379bc100SJani Nikula 	 * 2TLPX + 8UI + (trail_count*2)(in UI) + Extra byte count
1802379bc100SJani Nikula 	 * In byteclks = (2*TLpx(in UI) + trail_count*2 +8)(in UI)/8 +
1803379bc100SJani Nikula 	 *						Extra byte count
1804379bc100SJani Nikula 	 */
1805379bc100SJani Nikula 	intel_dsi->clk_hs_to_lp_count =
1806379bc100SJani Nikula 		DIV_ROUND_UP(2 * tlpx_ui + trail_cnt * 2 + 8,
1807379bc100SJani Nikula 			8);
1808379bc100SJani Nikula 	intel_dsi->clk_hs_to_lp_count += extra_byte_count;
1809379bc100SJani Nikula 
1810379bc100SJani Nikula 	intel_dsi_log_params(intel_dsi);
1811379bc100SJani Nikula }
1812379bc100SJani Nikula 
1813379bc100SJani Nikula void vlv_dsi_init(struct drm_i915_private *dev_priv)
1814379bc100SJani Nikula {
1815379bc100SJani Nikula 	struct drm_device *dev = &dev_priv->drm;
1816379bc100SJani Nikula 	struct intel_dsi *intel_dsi;
1817379bc100SJani Nikula 	struct intel_encoder *intel_encoder;
1818379bc100SJani Nikula 	struct drm_encoder *encoder;
1819379bc100SJani Nikula 	struct intel_connector *intel_connector;
1820379bc100SJani Nikula 	struct drm_connector *connector;
1821379bc100SJani Nikula 	struct drm_display_mode *current_mode, *fixed_mode;
1822379bc100SJani Nikula 	enum port port;
18236c0a878eSHans de Goede 	enum pipe pipe;
1824379bc100SJani Nikula 
1825f1f76d7aSWambui Karuga 	drm_dbg_kms(&dev_priv->drm, "\n");
1826379bc100SJani Nikula 
1827379bc100SJani Nikula 	/* There is no detection method for MIPI so rely on VBT */
1828379bc100SJani Nikula 	if (!intel_bios_is_dsi_present(dev_priv, &port))
1829379bc100SJani Nikula 		return;
1830379bc100SJani Nikula 
1831379bc100SJani Nikula 	if (IS_GEN9_LP(dev_priv))
1832379bc100SJani Nikula 		dev_priv->mipi_mmio_base = BXT_MIPI_BASE;
1833379bc100SJani Nikula 	else
1834379bc100SJani Nikula 		dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
1835379bc100SJani Nikula 
1836379bc100SJani Nikula 	intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
1837379bc100SJani Nikula 	if (!intel_dsi)
1838379bc100SJani Nikula 		return;
1839379bc100SJani Nikula 
1840379bc100SJani Nikula 	intel_connector = intel_connector_alloc();
1841379bc100SJani Nikula 	if (!intel_connector) {
1842379bc100SJani Nikula 		kfree(intel_dsi);
1843379bc100SJani Nikula 		return;
1844379bc100SJani Nikula 	}
1845379bc100SJani Nikula 
1846379bc100SJani Nikula 	intel_encoder = &intel_dsi->base;
1847379bc100SJani Nikula 	encoder = &intel_encoder->base;
1848379bc100SJani Nikula 	intel_dsi->attached_connector = intel_connector;
1849379bc100SJani Nikula 
1850379bc100SJani Nikula 	connector = &intel_connector->base;
1851379bc100SJani Nikula 
1852379bc100SJani Nikula 	drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI,
1853379bc100SJani Nikula 			 "DSI %c", port_name(port));
1854379bc100SJani Nikula 
1855379bc100SJani Nikula 	intel_encoder->compute_config = intel_dsi_compute_config;
1856379bc100SJani Nikula 	intel_encoder->pre_enable = intel_dsi_pre_enable;
185721fd23acSJani Nikula 	if (IS_GEN9_LP(dev_priv))
185821fd23acSJani Nikula 		intel_encoder->enable = bxt_dsi_enable;
1859379bc100SJani Nikula 	intel_encoder->disable = intel_dsi_disable;
1860379bc100SJani Nikula 	intel_encoder->post_disable = intel_dsi_post_disable;
1861379bc100SJani Nikula 	intel_encoder->get_hw_state = intel_dsi_get_hw_state;
1862379bc100SJani Nikula 	intel_encoder->get_config = intel_dsi_get_config;
1863379bc100SJani Nikula 	intel_encoder->update_pipe = intel_panel_update_backlight;
1864f13c2a00SVille Syrjälä 	intel_encoder->shutdown = intel_dsi_shutdown;
1865379bc100SJani Nikula 
1866379bc100SJani Nikula 	intel_connector->get_hw_state = intel_connector_get_hw_state;
1867379bc100SJani Nikula 
1868379bc100SJani Nikula 	intel_encoder->port = port;
1869379bc100SJani Nikula 	intel_encoder->type = INTEL_OUTPUT_DSI;
1870379bc100SJani Nikula 	intel_encoder->power_domain = POWER_DOMAIN_PORT_DSI;
1871379bc100SJani Nikula 	intel_encoder->cloneable = 0;
1872379bc100SJani Nikula 
1873379bc100SJani Nikula 	/*
1874379bc100SJani Nikula 	 * On BYT/CHV, pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI
1875379bc100SJani Nikula 	 * port C. BXT isn't limited like this.
1876379bc100SJani Nikula 	 */
1877379bc100SJani Nikula 	if (IS_GEN9_LP(dev_priv))
187834053ee1SVille Syrjälä 		intel_encoder->pipe_mask = ~0;
1879379bc100SJani Nikula 	else if (port == PORT_A)
1880981329ceSVille Syrjälä 		intel_encoder->pipe_mask = BIT(PIPE_A);
1881379bc100SJani Nikula 	else
1882981329ceSVille Syrjälä 		intel_encoder->pipe_mask = BIT(PIPE_B);
1883379bc100SJani Nikula 
1884379bc100SJani Nikula 	if (dev_priv->vbt.dsi.config->dual_link)
1885379bc100SJani Nikula 		intel_dsi->ports = BIT(PORT_A) | BIT(PORT_C);
1886379bc100SJani Nikula 	else
1887379bc100SJani Nikula 		intel_dsi->ports = BIT(port);
1888379bc100SJani Nikula 
1889379bc100SJani Nikula 	intel_dsi->dcs_backlight_ports = dev_priv->vbt.dsi.bl_ports;
1890379bc100SJani Nikula 	intel_dsi->dcs_cabc_ports = dev_priv->vbt.dsi.cabc_ports;
1891379bc100SJani Nikula 
1892379bc100SJani Nikula 	/* Create a DSI host (and a device) for each port. */
1893379bc100SJani Nikula 	for_each_dsi_port(port, intel_dsi->ports) {
1894379bc100SJani Nikula 		struct intel_dsi_host *host;
1895379bc100SJani Nikula 
1896379bc100SJani Nikula 		host = intel_dsi_host_init(intel_dsi, &intel_dsi_host_ops,
1897379bc100SJani Nikula 					   port);
1898379bc100SJani Nikula 		if (!host)
1899379bc100SJani Nikula 			goto err;
1900379bc100SJani Nikula 
1901379bc100SJani Nikula 		intel_dsi->dsi_hosts[port] = host;
1902379bc100SJani Nikula 	}
1903379bc100SJani Nikula 
1904379bc100SJani Nikula 	if (!intel_dsi_vbt_init(intel_dsi, MIPI_DSI_GENERIC_PANEL_ID)) {
1905f1f76d7aSWambui Karuga 		drm_dbg_kms(&dev_priv->drm, "no device found\n");
1906379bc100SJani Nikula 		goto err;
1907379bc100SJani Nikula 	}
1908379bc100SJani Nikula 
1909379bc100SJani Nikula 	/* Use clock read-back from current hw-state for fastboot */
1910379bc100SJani Nikula 	current_mode = intel_encoder_current_mode(intel_encoder);
1911379bc100SJani Nikula 	if (current_mode) {
1912f1f76d7aSWambui Karuga 		drm_dbg_kms(&dev_priv->drm, "Calculated pclk %d GOP %d\n",
1913379bc100SJani Nikula 			    intel_dsi->pclk, current_mode->clock);
1914379bc100SJani Nikula 		if (intel_fuzzy_clock_check(intel_dsi->pclk,
1915379bc100SJani Nikula 					    current_mode->clock)) {
1916f1f76d7aSWambui Karuga 			drm_dbg_kms(&dev_priv->drm, "Using GOP pclk\n");
1917379bc100SJani Nikula 			intel_dsi->pclk = current_mode->clock;
1918379bc100SJani Nikula 		}
1919379bc100SJani Nikula 
1920379bc100SJani Nikula 		kfree(current_mode);
1921379bc100SJani Nikula 	}
1922379bc100SJani Nikula 
1923379bc100SJani Nikula 	vlv_dphy_param_init(intel_dsi);
1924379bc100SJani Nikula 
19256c0a878eSHans de Goede 	intel_dsi_vbt_gpio_init(intel_dsi,
19266c0a878eSHans de Goede 				intel_dsi_get_hw_state(intel_encoder, &pipe));
1927379bc100SJani Nikula 
1928379bc100SJani Nikula 	drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
1929379bc100SJani Nikula 			   DRM_MODE_CONNECTOR_DSI);
1930379bc100SJani Nikula 
1931379bc100SJani Nikula 	drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
1932379bc100SJani Nikula 
1933379bc100SJani Nikula 	connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
1934379bc100SJani Nikula 	connector->interlace_allowed = false;
1935379bc100SJani Nikula 	connector->doublescan_allowed = false;
1936379bc100SJani Nikula 
1937379bc100SJani Nikula 	intel_connector_attach_encoder(intel_connector, intel_encoder);
1938379bc100SJani Nikula 
1939379bc100SJani Nikula 	mutex_lock(&dev->mode_config.mutex);
1940379bc100SJani Nikula 	fixed_mode = intel_panel_vbt_fixed_mode(intel_connector);
1941379bc100SJani Nikula 	mutex_unlock(&dev->mode_config.mutex);
1942379bc100SJani Nikula 
1943379bc100SJani Nikula 	if (!fixed_mode) {
1944f1f76d7aSWambui Karuga 		drm_dbg_kms(&dev_priv->drm, "no fixed mode\n");
1945379bc100SJani Nikula 		goto err_cleanup_connector;
1946379bc100SJani Nikula 	}
1947379bc100SJani Nikula 
1948379bc100SJani Nikula 	intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
1949379bc100SJani Nikula 	intel_panel_setup_backlight(connector, INVALID_PIPE);
1950379bc100SJani Nikula 
1951f384e48dSVandita Kulkarni 	vlv_dsi_add_properties(intel_connector);
1952379bc100SJani Nikula 
1953379bc100SJani Nikula 	return;
1954379bc100SJani Nikula 
1955379bc100SJani Nikula err_cleanup_connector:
1956379bc100SJani Nikula 	drm_connector_cleanup(&intel_connector->base);
1957379bc100SJani Nikula err:
1958379bc100SJani Nikula 	drm_encoder_cleanup(&intel_encoder->base);
1959379bc100SJani Nikula 	kfree(intel_dsi);
1960379bc100SJani Nikula 	kfree(intel_connector);
1961379bc100SJani Nikula }
1962