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
26b07eb15dSHans de Goede #include <linux/dmi.h>
27379bc100SJani Nikula #include <linux/slab.h>
28379bc100SJani Nikula
29379bc100SJani Nikula #include <drm/drm_atomic_helper.h>
30379bc100SJani Nikula #include <drm/drm_crtc.h>
31379bc100SJani Nikula #include <drm/drm_edid.h>
32379bc100SJani Nikula #include <drm/drm_mipi_dsi.h>
33379bc100SJani Nikula
34379bc100SJani Nikula #include "i915_drv.h"
35801543b2SJani Nikula #include "i915_reg.h"
36379bc100SJani Nikula #include "intel_atomic.h"
376cc42fbeSJani Nikula #include "intel_backlight.h"
38379bc100SJani Nikula #include "intel_connector.h"
397c53e628SJani Nikula #include "intel_crtc.h"
407785ae0bSVille Syrjälä #include "intel_de.h"
411d455f8dSJani Nikula #include "intel_display_types.h"
42379bc100SJani Nikula #include "intel_dsi.h"
43aebdd742SJani Nikula #include "intel_dsi_vbt.h"
44379bc100SJani Nikula #include "intel_fifo_underrun.h"
45379bc100SJani Nikula #include "intel_panel.h"
46714b1cdbSDave Airlie #include "skl_scaler.h"
477570d06dSJani Nikula #include "vlv_dsi.h"
4801e52628SJani Nikula #include "vlv_dsi_pll.h"
492b72a38cSJani Nikula #include "vlv_dsi_regs.h"
501eecf31eSJani Nikula #include "vlv_sideband.h"
51379bc100SJani Nikula
52379bc100SJani Nikula /* return pixels in terms of txbyteclkhs */
txbyteclkhs(u16 pixels,int bpp,int lane_count,u16 burst_mode_ratio)53379bc100SJani Nikula static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
54379bc100SJani Nikula u16 burst_mode_ratio)
55379bc100SJani Nikula {
56379bc100SJani Nikula return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
57379bc100SJani Nikula 8 * 100), lane_count);
58379bc100SJani Nikula }
59379bc100SJani Nikula
60379bc100SJani Nikula /* return pixels equvalent to txbyteclkhs */
pixels_from_txbyteclkhs(u16 clk_hs,int bpp,int lane_count,u16 burst_mode_ratio)61379bc100SJani Nikula static u16 pixels_from_txbyteclkhs(u16 clk_hs, int bpp, int lane_count,
62379bc100SJani Nikula u16 burst_mode_ratio)
63379bc100SJani Nikula {
64379bc100SJani Nikula return DIV_ROUND_UP((clk_hs * lane_count * 8 * 100),
65379bc100SJani Nikula (bpp * burst_mode_ratio));
66379bc100SJani Nikula }
67379bc100SJani Nikula
pixel_format_from_register_bits(u32 fmt)68379bc100SJani Nikula enum mipi_dsi_pixel_format pixel_format_from_register_bits(u32 fmt)
69379bc100SJani Nikula {
70379bc100SJani Nikula /* It just so happens the VBT matches register contents. */
71379bc100SJani Nikula switch (fmt) {
72379bc100SJani Nikula case VID_MODE_FORMAT_RGB888:
73379bc100SJani Nikula return MIPI_DSI_FMT_RGB888;
74379bc100SJani Nikula case VID_MODE_FORMAT_RGB666:
75379bc100SJani Nikula return MIPI_DSI_FMT_RGB666;
76379bc100SJani Nikula case VID_MODE_FORMAT_RGB666_PACKED:
77379bc100SJani Nikula return MIPI_DSI_FMT_RGB666_PACKED;
78379bc100SJani Nikula case VID_MODE_FORMAT_RGB565:
79379bc100SJani Nikula return MIPI_DSI_FMT_RGB565;
80379bc100SJani Nikula default:
81379bc100SJani Nikula MISSING_CASE(fmt);
82379bc100SJani Nikula return MIPI_DSI_FMT_RGB666;
83379bc100SJani Nikula }
84379bc100SJani Nikula }
85379bc100SJani Nikula
vlv_dsi_wait_for_fifo_empty(struct intel_dsi * intel_dsi,enum port port)86379bc100SJani Nikula void vlv_dsi_wait_for_fifo_empty(struct intel_dsi *intel_dsi, enum port port)
87379bc100SJani Nikula {
886068bc20SJani Nikula struct intel_display *display = to_intel_display(&intel_dsi->base);
89379bc100SJani Nikula u32 mask;
90379bc100SJani Nikula
91379bc100SJani Nikula mask = LP_CTRL_FIFO_EMPTY | HS_CTRL_FIFO_EMPTY |
92379bc100SJani Nikula LP_DATA_FIFO_EMPTY | HS_DATA_FIFO_EMPTY;
93379bc100SJani Nikula
946068bc20SJani Nikula if (intel_de_wait_for_set(display, MIPI_GEN_FIFO_STAT(display, port),
954cb3b44dSDaniele Ceraolo Spurio mask, 100))
966068bc20SJani Nikula drm_err(display->drm, "DPI FIFOs are not empty\n");
97379bc100SJani Nikula }
98379bc100SJani Nikula
write_data(struct intel_display * display,i915_reg_t reg,const u8 * data,u32 len)996068bc20SJani Nikula static void write_data(struct intel_display *display,
100379bc100SJani Nikula i915_reg_t reg,
101379bc100SJani Nikula const u8 *data, u32 len)
102379bc100SJani Nikula {
103379bc100SJani Nikula u32 i, j;
104379bc100SJani Nikula
105379bc100SJani Nikula for (i = 0; i < len; i += 4) {
106379bc100SJani Nikula u32 val = 0;
107379bc100SJani Nikula
108379bc100SJani Nikula for (j = 0; j < min_t(u32, len - i, 4); j++)
109379bc100SJani Nikula val |= *data++ << 8 * j;
110379bc100SJani Nikula
1116068bc20SJani Nikula intel_de_write(display, reg, val);
112379bc100SJani Nikula }
113379bc100SJani Nikula }
114379bc100SJani Nikula
read_data(struct intel_display * display,i915_reg_t reg,u8 * data,u32 len)1156068bc20SJani Nikula static void read_data(struct intel_display *display,
116379bc100SJani Nikula i915_reg_t reg,
117379bc100SJani Nikula u8 *data, u32 len)
118379bc100SJani Nikula {
119379bc100SJani Nikula u32 i, j;
120379bc100SJani Nikula
121379bc100SJani Nikula for (i = 0; i < len; i += 4) {
1226068bc20SJani Nikula u32 val = intel_de_read(display, reg);
123379bc100SJani Nikula
124379bc100SJani Nikula for (j = 0; j < min_t(u32, len - i, 4); j++)
125379bc100SJani Nikula *data++ = val >> 8 * j;
126379bc100SJani Nikula }
127379bc100SJani Nikula }
128379bc100SJani Nikula
intel_dsi_host_transfer(struct mipi_dsi_host * host,const struct mipi_dsi_msg * msg)129379bc100SJani Nikula static ssize_t intel_dsi_host_transfer(struct mipi_dsi_host *host,
130379bc100SJani Nikula const struct mipi_dsi_msg *msg)
131379bc100SJani Nikula {
132379bc100SJani Nikula struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host);
1334cfff967SJani Nikula struct intel_dsi *intel_dsi = intel_dsi_host->intel_dsi;
1346068bc20SJani Nikula struct intel_display *display = to_intel_display(&intel_dsi->base);
135379bc100SJani Nikula enum port port = intel_dsi_host->port;
136379bc100SJani Nikula struct mipi_dsi_packet packet;
137379bc100SJani Nikula ssize_t ret;
138ac12d250SJani Nikula const u8 *header;
139379bc100SJani Nikula i915_reg_t data_reg, ctrl_reg;
140379bc100SJani Nikula u32 data_mask, ctrl_mask;
141379bc100SJani Nikula
142379bc100SJani Nikula ret = mipi_dsi_create_packet(&packet, msg);
143379bc100SJani Nikula if (ret < 0)
144379bc100SJani Nikula return ret;
145379bc100SJani Nikula
146379bc100SJani Nikula header = packet.header;
147379bc100SJani Nikula
148379bc100SJani Nikula if (msg->flags & MIPI_DSI_MSG_USE_LPM) {
1496068bc20SJani Nikula data_reg = MIPI_LP_GEN_DATA(display, port);
150379bc100SJani Nikula data_mask = LP_DATA_FIFO_FULL;
1516068bc20SJani Nikula ctrl_reg = MIPI_LP_GEN_CTRL(display, port);
152379bc100SJani Nikula ctrl_mask = LP_CTRL_FIFO_FULL;
153379bc100SJani Nikula } else {
1546068bc20SJani Nikula data_reg = MIPI_HS_GEN_DATA(display, port);
155379bc100SJani Nikula data_mask = HS_DATA_FIFO_FULL;
1566068bc20SJani Nikula ctrl_reg = MIPI_HS_GEN_CTRL(display, port);
157379bc100SJani Nikula ctrl_mask = HS_CTRL_FIFO_FULL;
158379bc100SJani Nikula }
159379bc100SJani Nikula
160379bc100SJani Nikula /* note: this is never true for reads */
161379bc100SJani Nikula if (packet.payload_length) {
1626068bc20SJani Nikula if (intel_de_wait_for_clear(display, MIPI_GEN_FIFO_STAT(display, port),
1634cb3b44dSDaniele Ceraolo Spurio data_mask, 50))
1646068bc20SJani Nikula drm_err(display->drm,
165f1f76d7aSWambui Karuga "Timeout waiting for HS/LP DATA FIFO !full\n");
166379bc100SJani Nikula
1676068bc20SJani Nikula write_data(display, data_reg, packet.payload,
168379bc100SJani Nikula packet.payload_length);
169379bc100SJani Nikula }
170379bc100SJani Nikula
171379bc100SJani Nikula if (msg->rx_len) {
1726068bc20SJani Nikula intel_de_write(display, MIPI_INTR_STAT(display, port),
173992d4694SJani Nikula GEN_READ_DATA_AVAIL);
174379bc100SJani Nikula }
175379bc100SJani Nikula
1766068bc20SJani Nikula if (intel_de_wait_for_clear(display, MIPI_GEN_FIFO_STAT(display, port),
1774cb3b44dSDaniele Ceraolo Spurio ctrl_mask, 50)) {
1786068bc20SJani Nikula drm_err(display->drm,
179f1f76d7aSWambui Karuga "Timeout waiting for HS/LP CTRL FIFO !full\n");
180379bc100SJani Nikula }
181379bc100SJani Nikula
1826068bc20SJani Nikula intel_de_write(display, ctrl_reg,
183992d4694SJani Nikula header[2] << 16 | header[1] << 8 | header[0]);
184379bc100SJani Nikula
185379bc100SJani Nikula /* ->rx_len is set only for reads */
186379bc100SJani Nikula if (msg->rx_len) {
187379bc100SJani Nikula data_mask = GEN_READ_DATA_AVAIL;
1886068bc20SJani Nikula if (intel_de_wait_for_set(display, MIPI_INTR_STAT(display, port),
1894cb3b44dSDaniele Ceraolo Spurio data_mask, 50))
1906068bc20SJani Nikula drm_err(display->drm,
191f1f76d7aSWambui Karuga "Timeout waiting for read data.\n");
192379bc100SJani Nikula
1936068bc20SJani Nikula read_data(display, data_reg, msg->rx_buf, msg->rx_len);
194379bc100SJani Nikula }
195379bc100SJani Nikula
196379bc100SJani Nikula /* XXX: fix for reads and writes */
197379bc100SJani Nikula return 4 + packet.payload_length;
198379bc100SJani Nikula }
199379bc100SJani Nikula
intel_dsi_host_attach(struct mipi_dsi_host * host,struct mipi_dsi_device * dsi)200379bc100SJani Nikula static int intel_dsi_host_attach(struct mipi_dsi_host *host,
201379bc100SJani Nikula struct mipi_dsi_device *dsi)
202379bc100SJani Nikula {
203379bc100SJani Nikula return 0;
204379bc100SJani Nikula }
205379bc100SJani Nikula
intel_dsi_host_detach(struct mipi_dsi_host * host,struct mipi_dsi_device * dsi)206379bc100SJani Nikula static int intel_dsi_host_detach(struct mipi_dsi_host *host,
207379bc100SJani Nikula struct mipi_dsi_device *dsi)
208379bc100SJani Nikula {
209379bc100SJani Nikula return 0;
210379bc100SJani Nikula }
211379bc100SJani Nikula
212379bc100SJani Nikula static const struct mipi_dsi_host_ops intel_dsi_host_ops = {
213379bc100SJani Nikula .attach = intel_dsi_host_attach,
214379bc100SJani Nikula .detach = intel_dsi_host_detach,
215379bc100SJani Nikula .transfer = intel_dsi_host_transfer,
216379bc100SJani Nikula };
217379bc100SJani Nikula
218379bc100SJani Nikula /*
219379bc100SJani Nikula * send a video mode command
220379bc100SJani Nikula *
221379bc100SJani Nikula * XXX: commands with data in MIPI_DPI_DATA?
222379bc100SJani Nikula */
dpi_send_cmd(struct intel_dsi * intel_dsi,u32 cmd,bool hs,enum port port)223379bc100SJani Nikula static int dpi_send_cmd(struct intel_dsi *intel_dsi, u32 cmd, bool hs,
224379bc100SJani Nikula enum port port)
225379bc100SJani Nikula {
2266068bc20SJani Nikula struct intel_display *display = to_intel_display(&intel_dsi->base);
227379bc100SJani Nikula u32 mask;
228379bc100SJani Nikula
229379bc100SJani Nikula /* XXX: pipe, hs */
230379bc100SJani Nikula if (hs)
231379bc100SJani Nikula cmd &= ~DPI_LP_MODE;
232379bc100SJani Nikula else
233379bc100SJani Nikula cmd |= DPI_LP_MODE;
234379bc100SJani Nikula
235379bc100SJani Nikula /* clear bit */
2366068bc20SJani Nikula intel_de_write(display, MIPI_INTR_STAT(display, port), SPL_PKT_SENT_INTERRUPT);
237379bc100SJani Nikula
238379bc100SJani Nikula /* XXX: old code skips write if control unchanged */
2396068bc20SJani Nikula if (cmd == intel_de_read(display, MIPI_DPI_CONTROL(display, port)))
2406068bc20SJani Nikula drm_dbg_kms(display->drm,
241f1f76d7aSWambui Karuga "Same special packet %02x twice in a row.\n", cmd);
242379bc100SJani Nikula
2436068bc20SJani Nikula intel_de_write(display, MIPI_DPI_CONTROL(display, port), cmd);
244379bc100SJani Nikula
245379bc100SJani Nikula mask = SPL_PKT_SENT_INTERRUPT;
2466068bc20SJani Nikula if (intel_de_wait_for_set(display, MIPI_INTR_STAT(display, port), mask, 100))
2476068bc20SJani Nikula drm_err(display->drm,
248f1f76d7aSWambui Karuga "Video mode command 0x%08x send failed.\n", cmd);
249379bc100SJani Nikula
250379bc100SJani Nikula return 0;
251379bc100SJani Nikula }
252379bc100SJani Nikula
band_gap_reset(struct drm_i915_private * dev_priv)253379bc100SJani Nikula static void band_gap_reset(struct drm_i915_private *dev_priv)
254379bc100SJani Nikula {
255379bc100SJani Nikula vlv_flisdsi_get(dev_priv);
256379bc100SJani Nikula
257379bc100SJani Nikula vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
258379bc100SJani Nikula vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
259379bc100SJani Nikula vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
260379bc100SJani Nikula udelay(150);
261379bc100SJani Nikula vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
262379bc100SJani Nikula vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
263379bc100SJani Nikula
264379bc100SJani Nikula vlv_flisdsi_put(dev_priv);
265379bc100SJani Nikula }
266379bc100SJani Nikula
intel_dsi_compute_config(struct intel_encoder * encoder,struct intel_crtc_state * pipe_config,struct drm_connector_state * conn_state)267379bc100SJani Nikula static int intel_dsi_compute_config(struct intel_encoder *encoder,
268379bc100SJani Nikula struct intel_crtc_state *pipe_config,
269379bc100SJani Nikula struct drm_connector_state *conn_state)
270379bc100SJani Nikula {
271379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2729eae5bacSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
273379bc100SJani Nikula struct intel_connector *intel_connector = intel_dsi->attached_connector;
2741326a92cSMaarten Lankhorst struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
275379bc100SJani Nikula int ret;
276379bc100SJani Nikula
277f1f76d7aSWambui Karuga drm_dbg_kms(&dev_priv->drm, "\n");
278a04d27cdSAnkit Nautiyal pipe_config->sink_format = INTEL_OUTPUT_FORMAT_RGB;
279379bc100SJani Nikula pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
280379bc100SJani Nikula
281cff4c2c6SVille Syrjälä ret = intel_panel_compute_config(intel_connector, adjusted_mode);
282cff4c2c6SVille Syrjälä if (ret)
283cff4c2c6SVille Syrjälä return ret;
284379bc100SJani Nikula
2854b93f49dSJani Nikula ret = intel_panel_fitting(pipe_config, conn_state);
286d7ff281cSVille Syrjälä if (ret)
287d7ff281cSVille Syrjälä return ret;
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
30070bfb307SMatt Roper if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(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
glk_dsi_enable_io(struct intel_encoder * encoder)325379bc100SJani Nikula static bool glk_dsi_enable_io(struct intel_encoder *encoder)
326379bc100SJani Nikula {
3276068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
328b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
329379bc100SJani Nikula enum port port;
330379bc100SJani Nikula bool cold_boot = false;
331379bc100SJani Nikula
332379bc100SJani Nikula /* Set the MIPI mode
333379bc100SJani Nikula * If MIPI_Mode is off, then writing to LP_Wake bit is not reflecting.
334379bc100SJani Nikula * Power ON MIPI IO first and then write into IO reset and LP wake bits
335379bc100SJani Nikula */
33628cbe92bSAndrzej Hajda for_each_dsi_port(port, intel_dsi->ports)
3376068bc20SJani Nikula intel_de_rmw(display, MIPI_CTRL(display, port), 0, GLK_MIPIIO_ENABLE);
338379bc100SJani Nikula
339379bc100SJani Nikula /* Put the IO into reset */
3406068bc20SJani Nikula intel_de_rmw(display, MIPI_CTRL(display, PORT_A), GLK_MIPIIO_RESET_RELEASED, 0);
341379bc100SJani Nikula
342379bc100SJani Nikula /* Program LP Wake */
343379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
3446068bc20SJani Nikula u32 tmp = intel_de_read(display, MIPI_DEVICE_READY(display, port));
3456068bc20SJani Nikula
3466068bc20SJani Nikula intel_de_rmw(display, MIPI_CTRL(display, port),
34728cbe92bSAndrzej Hajda GLK_LP_WAKE, (tmp & DEVICE_READY) ? GLK_LP_WAKE : 0);
348379bc100SJani Nikula }
349379bc100SJani Nikula
350379bc100SJani Nikula /* Wait for Pwr ACK */
351379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
3526068bc20SJani Nikula if (intel_de_wait_for_set(display, MIPI_CTRL(display, port),
3534cb3b44dSDaniele Ceraolo Spurio GLK_MIPIIO_PORT_POWERED, 20))
3546068bc20SJani Nikula drm_err(display->drm, "MIPIO port is powergated\n");
355379bc100SJani Nikula }
356379bc100SJani Nikula
357379bc100SJani Nikula /* Check for cold boot scenario */
358379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
359379bc100SJani Nikula cold_boot |=
3606068bc20SJani Nikula !(intel_de_read(display, MIPI_DEVICE_READY(display, port)) & DEVICE_READY);
361379bc100SJani Nikula }
362379bc100SJani Nikula
363379bc100SJani Nikula return cold_boot;
364379bc100SJani Nikula }
365379bc100SJani Nikula
glk_dsi_device_ready(struct intel_encoder * encoder)366379bc100SJani Nikula static void glk_dsi_device_ready(struct intel_encoder *encoder)
367379bc100SJani Nikula {
3686068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
369b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
370379bc100SJani Nikula enum port port;
371379bc100SJani Nikula
372379bc100SJani Nikula /* Wait for MIPI PHY status bit to set */
373379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
3746068bc20SJani Nikula if (intel_de_wait_for_set(display, MIPI_CTRL(display, port),
3754cb3b44dSDaniele Ceraolo Spurio GLK_PHY_STATUS_PORT_READY, 20))
3766068bc20SJani Nikula drm_err(display->drm, "PHY is not ON\n");
377379bc100SJani Nikula }
378379bc100SJani Nikula
379379bc100SJani Nikula /* Get IO out of reset */
3806068bc20SJani Nikula intel_de_rmw(display, MIPI_CTRL(display, PORT_A), 0, GLK_MIPIIO_RESET_RELEASED);
381379bc100SJani Nikula
382379bc100SJani Nikula /* Get IO out of Low power state*/
383379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
3846068bc20SJani Nikula if (!(intel_de_read(display, MIPI_DEVICE_READY(display, port)) & DEVICE_READY)) {
3856068bc20SJani Nikula intel_de_rmw(display, MIPI_DEVICE_READY(display, port),
38628cbe92bSAndrzej Hajda ULPS_STATE_MASK, DEVICE_READY);
387379bc100SJani Nikula usleep_range(10, 15);
388379bc100SJani Nikula } else {
389379bc100SJani Nikula /* Enter ULPS */
3906068bc20SJani Nikula intel_de_rmw(display, MIPI_DEVICE_READY(display, port),
39128cbe92bSAndrzej Hajda ULPS_STATE_MASK, ULPS_STATE_ENTER | DEVICE_READY);
392379bc100SJani Nikula
393379bc100SJani Nikula /* Wait for ULPS active */
3946068bc20SJani Nikula if (intel_de_wait_for_clear(display, MIPI_CTRL(display, port),
3954cb3b44dSDaniele Ceraolo Spurio GLK_ULPS_NOT_ACTIVE, 20))
3966068bc20SJani Nikula drm_err(display->drm, "ULPS not active\n");
397379bc100SJani Nikula
398379bc100SJani Nikula /* Exit ULPS */
3996068bc20SJani Nikula intel_de_rmw(display, MIPI_DEVICE_READY(display, port),
40028cbe92bSAndrzej Hajda ULPS_STATE_MASK, ULPS_STATE_EXIT | DEVICE_READY);
401379bc100SJani Nikula
402379bc100SJani Nikula /* Enter Normal Mode */
4036068bc20SJani Nikula intel_de_rmw(display, MIPI_DEVICE_READY(display, port),
40428cbe92bSAndrzej Hajda ULPS_STATE_MASK,
40528cbe92bSAndrzej Hajda ULPS_STATE_NORMAL_OPERATION | DEVICE_READY);
406379bc100SJani Nikula
4076068bc20SJani Nikula intel_de_rmw(display, MIPI_CTRL(display, port), GLK_LP_WAKE, 0);
408379bc100SJani Nikula }
409379bc100SJani Nikula }
410379bc100SJani Nikula
411379bc100SJani Nikula /* Wait for Stop state */
412379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
4136068bc20SJani Nikula if (intel_de_wait_for_set(display, MIPI_CTRL(display, port),
4144cb3b44dSDaniele Ceraolo Spurio GLK_DATA_LANE_STOP_STATE, 20))
4156068bc20SJani Nikula drm_err(display->drm,
416f1f76d7aSWambui Karuga "Date lane not in STOP state\n");
417379bc100SJani Nikula }
418379bc100SJani Nikula
419379bc100SJani Nikula /* Wait for AFE LATCH */
420379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
4216068bc20SJani Nikula if (intel_de_wait_for_set(display, BXT_MIPI_PORT_CTRL(port),
4224cb3b44dSDaniele Ceraolo Spurio AFE_LATCHOUT, 20))
4236068bc20SJani Nikula drm_err(display->drm,
424f1f76d7aSWambui Karuga "D-PHY not entering LP-11 state\n");
425379bc100SJani Nikula }
426379bc100SJani Nikula }
427379bc100SJani Nikula
bxt_dsi_device_ready(struct intel_encoder * encoder)428379bc100SJani Nikula static void bxt_dsi_device_ready(struct intel_encoder *encoder)
429379bc100SJani Nikula {
4306068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
431b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
432379bc100SJani Nikula enum port port;
433379bc100SJani Nikula u32 val;
434379bc100SJani Nikula
4356068bc20SJani Nikula drm_dbg_kms(display->drm, "\n");
436379bc100SJani Nikula
437379bc100SJani Nikula /* Enable MIPI PHY transparent latch */
438379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
4396068bc20SJani Nikula intel_de_rmw(display, BXT_MIPI_PORT_CTRL(port), 0, LP_OUTPUT_HOLD);
440379bc100SJani Nikula usleep_range(2000, 2500);
441379bc100SJani Nikula }
442379bc100SJani Nikula
443379bc100SJani Nikula /* Clear ULPS and set device ready */
444379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
4456068bc20SJani Nikula val = intel_de_read(display, MIPI_DEVICE_READY(display, port));
446379bc100SJani Nikula val &= ~ULPS_STATE_MASK;
4476068bc20SJani Nikula intel_de_write(display, MIPI_DEVICE_READY(display, port), val);
448379bc100SJani Nikula usleep_range(2000, 2500);
449379bc100SJani Nikula val |= DEVICE_READY;
4506068bc20SJani Nikula intel_de_write(display, MIPI_DEVICE_READY(display, port), val);
451379bc100SJani Nikula }
452379bc100SJani Nikula }
453379bc100SJani Nikula
vlv_dsi_device_ready(struct intel_encoder * encoder)454379bc100SJani Nikula static void vlv_dsi_device_ready(struct intel_encoder *encoder)
455379bc100SJani Nikula {
4566068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
457379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
458b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
459379bc100SJani Nikula enum port port;
460379bc100SJani Nikula
4616068bc20SJani Nikula drm_dbg_kms(display->drm, "\n");
462379bc100SJani Nikula
463379bc100SJani Nikula vlv_flisdsi_get(dev_priv);
464379bc100SJani Nikula /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
465379bc100SJani Nikula * needed everytime after power gate */
466379bc100SJani Nikula vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
467379bc100SJani Nikula vlv_flisdsi_put(dev_priv);
468379bc100SJani Nikula
469379bc100SJani Nikula /* bandgap reset is needed after everytime we do power gate */
470379bc100SJani Nikula band_gap_reset(dev_priv);
471379bc100SJani Nikula
472379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
473379bc100SJani Nikula
4746068bc20SJani Nikula intel_de_write(display, MIPI_DEVICE_READY(display, port),
475992d4694SJani Nikula ULPS_STATE_ENTER);
476379bc100SJani Nikula usleep_range(2500, 3000);
477379bc100SJani Nikula
478379bc100SJani Nikula /* Enable MIPI PHY transparent latch
479379bc100SJani Nikula * Common bit for both MIPI Port A & MIPI Port C
480379bc100SJani Nikula * No similar bit in MIPI Port C reg
481379bc100SJani Nikula */
4826068bc20SJani Nikula intel_de_rmw(display, VLV_MIPI_PORT_CTRL(PORT_A), 0, LP_OUTPUT_HOLD);
483379bc100SJani Nikula usleep_range(1000, 1500);
484379bc100SJani Nikula
4856068bc20SJani Nikula intel_de_write(display, MIPI_DEVICE_READY(display, port),
486992d4694SJani Nikula ULPS_STATE_EXIT);
487379bc100SJani Nikula usleep_range(2500, 3000);
488379bc100SJani Nikula
4896068bc20SJani Nikula intel_de_write(display, MIPI_DEVICE_READY(display, port),
490992d4694SJani Nikula DEVICE_READY);
491379bc100SJani Nikula usleep_range(2500, 3000);
492379bc100SJani Nikula }
493379bc100SJani Nikula }
494379bc100SJani Nikula
intel_dsi_device_ready(struct intel_encoder * encoder)495379bc100SJani Nikula static void intel_dsi_device_ready(struct intel_encoder *encoder)
496379bc100SJani Nikula {
497379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
498379bc100SJani Nikula
499379bc100SJani Nikula if (IS_GEMINILAKE(dev_priv))
500379bc100SJani Nikula glk_dsi_device_ready(encoder);
50170bfb307SMatt Roper else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
502379bc100SJani Nikula bxt_dsi_device_ready(encoder);
503379bc100SJani Nikula else
504379bc100SJani Nikula vlv_dsi_device_ready(encoder);
505379bc100SJani Nikula }
506379bc100SJani Nikula
glk_dsi_enter_low_power_mode(struct intel_encoder * encoder)507379bc100SJani Nikula static void glk_dsi_enter_low_power_mode(struct intel_encoder *encoder)
508379bc100SJani Nikula {
5096068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
510b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
511379bc100SJani Nikula enum port port;
512379bc100SJani Nikula
513379bc100SJani Nikula /* Enter ULPS */
51428cbe92bSAndrzej Hajda for_each_dsi_port(port, intel_dsi->ports)
5156068bc20SJani Nikula intel_de_rmw(display, MIPI_DEVICE_READY(display, port),
51628cbe92bSAndrzej Hajda ULPS_STATE_MASK, ULPS_STATE_ENTER | DEVICE_READY);
517379bc100SJani Nikula
518379bc100SJani Nikula /* Wait for MIPI PHY status bit to unset */
519379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
5206068bc20SJani Nikula if (intel_de_wait_for_clear(display, MIPI_CTRL(display, port),
5214cb3b44dSDaniele Ceraolo Spurio GLK_PHY_STATUS_PORT_READY, 20))
5226068bc20SJani Nikula drm_err(display->drm, "PHY is not turning OFF\n");
523379bc100SJani Nikula }
524379bc100SJani Nikula
525379bc100SJani Nikula /* Wait for Pwr ACK bit to unset */
526379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
5276068bc20SJani Nikula if (intel_de_wait_for_clear(display, MIPI_CTRL(display, port),
5284cb3b44dSDaniele Ceraolo Spurio GLK_MIPIIO_PORT_POWERED, 20))
5296068bc20SJani Nikula drm_err(display->drm,
530f1f76d7aSWambui Karuga "MIPI IO Port is not powergated\n");
531379bc100SJani Nikula }
532379bc100SJani Nikula }
533379bc100SJani Nikula
glk_dsi_disable_mipi_io(struct intel_encoder * encoder)534379bc100SJani Nikula static void glk_dsi_disable_mipi_io(struct intel_encoder *encoder)
535379bc100SJani Nikula {
5366068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
537b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
538379bc100SJani Nikula enum port port;
539379bc100SJani Nikula
540379bc100SJani Nikula /* Put the IO into reset */
5416068bc20SJani Nikula intel_de_rmw(display, MIPI_CTRL(display, PORT_A), GLK_MIPIIO_RESET_RELEASED, 0);
542379bc100SJani Nikula
543379bc100SJani Nikula /* Wait for MIPI PHY status bit to unset */
544379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
5456068bc20SJani Nikula if (intel_de_wait_for_clear(display, MIPI_CTRL(display, port),
5464cb3b44dSDaniele Ceraolo Spurio GLK_PHY_STATUS_PORT_READY, 20))
5476068bc20SJani Nikula drm_err(display->drm, "PHY is not turning OFF\n");
548379bc100SJani Nikula }
549379bc100SJani Nikula
550379bc100SJani Nikula /* Clear MIPI mode */
55128cbe92bSAndrzej Hajda for_each_dsi_port(port, intel_dsi->ports)
5526068bc20SJani Nikula intel_de_rmw(display, MIPI_CTRL(display, port), GLK_MIPIIO_ENABLE, 0);
553379bc100SJani Nikula }
554379bc100SJani Nikula
glk_dsi_clear_device_ready(struct intel_encoder * encoder)555379bc100SJani Nikula static void glk_dsi_clear_device_ready(struct intel_encoder *encoder)
556379bc100SJani Nikula {
557379bc100SJani Nikula glk_dsi_enter_low_power_mode(encoder);
558379bc100SJani Nikula glk_dsi_disable_mipi_io(encoder);
559379bc100SJani Nikula }
560379bc100SJani Nikula
port_ctrl_reg(struct drm_i915_private * i915,enum port port)561bda4a7abSVille Syrjälä static i915_reg_t port_ctrl_reg(struct drm_i915_private *i915, enum port port)
562bda4a7abSVille Syrjälä {
563bda4a7abSVille Syrjälä return IS_GEMINILAKE(i915) || IS_BROXTON(i915) ?
5644229dd0bSJani Nikula BXT_MIPI_PORT_CTRL(port) : VLV_MIPI_PORT_CTRL(port);
565bda4a7abSVille Syrjälä }
566bda4a7abSVille Syrjälä
vlv_dsi_clear_device_ready(struct intel_encoder * encoder)567379bc100SJani Nikula static void vlv_dsi_clear_device_ready(struct intel_encoder *encoder)
568379bc100SJani Nikula {
5696068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
570379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
571b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
572379bc100SJani Nikula enum port port;
573379bc100SJani Nikula
5746068bc20SJani Nikula drm_dbg_kms(display->drm, "\n");
575379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
576379bc100SJani Nikula /* Common bit for both MIPI Port A & MIPI Port C on VLV/CHV */
577cf6e1165SVille Syrjälä i915_reg_t port_ctrl = IS_BROXTON(dev_priv) ?
5784229dd0bSJani Nikula BXT_MIPI_PORT_CTRL(port) : VLV_MIPI_PORT_CTRL(PORT_A);
579379bc100SJani Nikula
5806068bc20SJani Nikula intel_de_write(display, MIPI_DEVICE_READY(display, port),
581992d4694SJani Nikula DEVICE_READY | ULPS_STATE_ENTER);
582379bc100SJani Nikula usleep_range(2000, 2500);
583379bc100SJani Nikula
5846068bc20SJani Nikula intel_de_write(display, MIPI_DEVICE_READY(display, port),
585992d4694SJani Nikula DEVICE_READY | ULPS_STATE_EXIT);
586379bc100SJani Nikula usleep_range(2000, 2500);
587379bc100SJani Nikula
5886068bc20SJani Nikula intel_de_write(display, MIPI_DEVICE_READY(display, port),
589992d4694SJani Nikula DEVICE_READY | ULPS_STATE_ENTER);
590379bc100SJani Nikula usleep_range(2000, 2500);
591379bc100SJani Nikula
592379bc100SJani Nikula /*
593379bc100SJani Nikula * On VLV/CHV, wait till Clock lanes are in LP-00 state for MIPI
594379bc100SJani Nikula * Port A only. MIPI Port C has no similar bit for checking.
595379bc100SJani Nikula */
596cf6e1165SVille Syrjälä if ((IS_BROXTON(dev_priv) || port == PORT_A) &&
5976068bc20SJani Nikula intel_de_wait_for_clear(display, port_ctrl,
5984cb3b44dSDaniele Ceraolo Spurio AFE_LATCHOUT, 30))
5996068bc20SJani Nikula drm_err(display->drm, "DSI LP not going Low\n");
600379bc100SJani Nikula
601379bc100SJani Nikula /* Disable MIPI PHY transparent latch */
6026068bc20SJani Nikula intel_de_rmw(display, port_ctrl, LP_OUTPUT_HOLD, 0);
603379bc100SJani Nikula usleep_range(1000, 1500);
604379bc100SJani Nikula
6056068bc20SJani Nikula intel_de_write(display, MIPI_DEVICE_READY(display, port), 0x00);
606379bc100SJani Nikula usleep_range(2000, 2500);
607379bc100SJani Nikula }
608379bc100SJani Nikula }
609379bc100SJani Nikula
intel_dsi_port_enable(struct intel_encoder * encoder,const struct intel_crtc_state * crtc_state)610379bc100SJani Nikula static void intel_dsi_port_enable(struct intel_encoder *encoder,
611379bc100SJani Nikula const struct intel_crtc_state *crtc_state)
612379bc100SJani Nikula {
6136068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
614379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6152225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
616b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
617379bc100SJani Nikula enum port port;
618379bc100SJani Nikula
619379bc100SJani Nikula if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
620fceeca7fSAndrzej Hajda u32 temp = intel_dsi->pixel_overlap;
621fceeca7fSAndrzej Hajda
62270bfb307SMatt Roper if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
623fceeca7fSAndrzej Hajda for_each_dsi_port(port, intel_dsi->ports)
6246068bc20SJani Nikula intel_de_rmw(display, MIPI_CTRL(display, port),
625fceeca7fSAndrzej Hajda BXT_PIXEL_OVERLAP_CNT_MASK,
626fceeca7fSAndrzej Hajda temp << BXT_PIXEL_OVERLAP_CNT_SHIFT);
627379bc100SJani Nikula } else {
6286068bc20SJani Nikula intel_de_rmw(display, VLV_CHICKEN_3,
629fceeca7fSAndrzej Hajda PIXEL_OVERLAP_CNT_MASK,
630fceeca7fSAndrzej Hajda temp << PIXEL_OVERLAP_CNT_SHIFT);
631379bc100SJani Nikula }
632379bc100SJani Nikula }
633379bc100SJani Nikula
634379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
635bda4a7abSVille Syrjälä i915_reg_t port_ctrl = port_ctrl_reg(dev_priv, port);
636379bc100SJani Nikula u32 temp;
637379bc100SJani Nikula
6386068bc20SJani Nikula temp = intel_de_read(display, port_ctrl);
639379bc100SJani Nikula
640379bc100SJani Nikula temp &= ~LANE_CONFIGURATION_MASK;
641379bc100SJani Nikula temp &= ~DUAL_LINK_MODE_MASK;
642379bc100SJani Nikula
643379bc100SJani Nikula if (intel_dsi->ports == (BIT(PORT_A) | BIT(PORT_C))) {
644379bc100SJani Nikula temp |= (intel_dsi->dual_link - 1)
645379bc100SJani Nikula << DUAL_LINK_MODE_SHIFT;
646379bc100SJani Nikula if (IS_BROXTON(dev_priv))
647379bc100SJani Nikula temp |= LANE_CONFIGURATION_DUAL_LINK_A;
648379bc100SJani Nikula else
649379bc100SJani Nikula temp |= crtc->pipe ?
650379bc100SJani Nikula LANE_CONFIGURATION_DUAL_LINK_B :
651379bc100SJani Nikula LANE_CONFIGURATION_DUAL_LINK_A;
652379bc100SJani Nikula }
653379bc100SJani Nikula
654379bc100SJani Nikula if (intel_dsi->pixel_format != MIPI_DSI_FMT_RGB888)
655379bc100SJani Nikula temp |= DITHERING_ENABLE;
656379bc100SJani Nikula
657379bc100SJani Nikula /* assert ip_tg_enable signal */
6586068bc20SJani Nikula intel_de_write(display, port_ctrl, temp | DPI_ENABLE);
6596068bc20SJani Nikula intel_de_posting_read(display, port_ctrl);
660379bc100SJani Nikula }
661379bc100SJani Nikula }
662379bc100SJani Nikula
intel_dsi_port_disable(struct intel_encoder * encoder)663379bc100SJani Nikula static void intel_dsi_port_disable(struct intel_encoder *encoder)
664379bc100SJani Nikula {
6656068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
6664cfff967SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
667b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
668379bc100SJani Nikula enum port port;
669379bc100SJani Nikula
670379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
671bda4a7abSVille Syrjälä i915_reg_t port_ctrl = port_ctrl_reg(dev_priv, port);
672379bc100SJani Nikula
673379bc100SJani Nikula /* de-assert ip_tg_enable signal */
6746068bc20SJani Nikula intel_de_rmw(display, port_ctrl, DPI_ENABLE, 0);
6756068bc20SJani Nikula intel_de_posting_read(display, port_ctrl);
676379bc100SJani Nikula }
677379bc100SJani Nikula }
6784cfff967SJani Nikula
6794cfff967SJani Nikula static void intel_dsi_prepare(struct intel_encoder *encoder,
680379bc100SJani Nikula const struct intel_crtc_state *pipe_config);
681379bc100SJani Nikula static void intel_dsi_unprepare(struct intel_encoder *encoder);
682379bc100SJani Nikula
683379bc100SJani Nikula /*
684379bc100SJani Nikula * Panel enable/disable sequences from the VBT spec.
685379bc100SJani Nikula *
686379bc100SJani Nikula * Note the spec has AssertReset / DeassertReset swapped from their
687379bc100SJani Nikula * usual naming. We use the normal names to avoid confusion (so below
688379bc100SJani Nikula * they are swapped compared to the spec).
689379bc100SJani Nikula *
690379bc100SJani Nikula * Steps starting with MIPI refer to VBT sequences, note that for v2
691379bc100SJani Nikula * VBTs several steps which have a VBT in v2 are expected to be handled
692379bc100SJani Nikula * directly by the driver, by directly driving gpios for example.
693379bc100SJani Nikula *
694379bc100SJani Nikula * v2 video mode seq v3 video mode seq command mode seq
695379bc100SJani Nikula * - power on - MIPIPanelPowerOn - power on
696379bc100SJani Nikula * - wait t1+t2 - wait t1+t2
697379bc100SJani Nikula * - MIPIDeassertResetPin - MIPIDeassertResetPin - MIPIDeassertResetPin
698379bc100SJani Nikula * - io lines to lp-11 - io lines to lp-11 - io lines to lp-11
699379bc100SJani Nikula * - MIPISendInitialDcsCmds - MIPISendInitialDcsCmds - MIPISendInitialDcsCmds
700379bc100SJani Nikula * - MIPITearOn
701379bc100SJani Nikula * - MIPIDisplayOn
702379bc100SJani Nikula * - turn on DPI - turn on DPI - set pipe to dsr mode
703379bc100SJani Nikula * - MIPIDisplayOn - MIPIDisplayOn
704379bc100SJani Nikula * - wait t5 - wait t5
705379bc100SJani Nikula * - backlight on - MIPIBacklightOn - backlight on
706379bc100SJani Nikula * ... ... ... issue mem cmds ...
707379bc100SJani Nikula * - backlight off - MIPIBacklightOff - backlight off
708379bc100SJani Nikula * - wait t6 - wait t6
709379bc100SJani Nikula * - MIPIDisplayOff
710379bc100SJani Nikula * - turn off DPI - turn off DPI - disable pipe dsr mode
711379bc100SJani Nikula * - MIPITearOff
712379bc100SJani Nikula * - MIPIDisplayOff - MIPIDisplayOff
713379bc100SJani Nikula * - io lines to lp-00 - io lines to lp-00 - io lines to lp-00
714379bc100SJani Nikula * - MIPIAssertResetPin - MIPIAssertResetPin - MIPIAssertResetPin
715379bc100SJani Nikula * - wait t3 - wait t3
716379bc100SJani Nikula * - power off - MIPIPanelPowerOff - power off
717379bc100SJani Nikula * - wait t4 - wait t4
718379bc100SJani Nikula */
719379bc100SJani Nikula
720379bc100SJani Nikula /*
721379bc100SJani Nikula * DSI port enable has to be done before pipe and plane enable, so we do it in
722379bc100SJani Nikula * the pre_enable hook instead of the enable hook.
723379bc100SJani Nikula */
intel_dsi_pre_enable(struct intel_atomic_state * state,struct intel_encoder * encoder,const struct intel_crtc_state * pipe_config,const struct drm_connector_state * conn_state)724ede9771dSVille Syrjälä static void intel_dsi_pre_enable(struct intel_atomic_state *state,
725ede9771dSVille Syrjälä struct intel_encoder *encoder,
726379bc100SJani Nikula const struct intel_crtc_state *pipe_config,
727379bc100SJani Nikula const struct drm_connector_state *conn_state)
728379bc100SJani Nikula {
7296068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
730b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
731f15f01a7SVille Syrjälä struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
732f15f01a7SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
733f15f01a7SVille Syrjälä enum pipe pipe = crtc->pipe;
734379bc100SJani Nikula enum port port;
735379bc100SJani Nikula bool glk_cold_boot = false;
736379bc100SJani Nikula
7376068bc20SJani Nikula drm_dbg_kms(display->drm, "\n");
738379bc100SJani Nikula
739c87eba80SHans de Goede intel_dsi_wait_panel_power_cycle(intel_dsi);
740c87eba80SHans de Goede
741379bc100SJani Nikula intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
742379bc100SJani Nikula
743379bc100SJani Nikula /*
744379bc100SJani Nikula * The BIOS may leave the PLL in a wonky state where it doesn't
745379bc100SJani Nikula * lock. It needs to be fully powered down to fix it.
746379bc100SJani Nikula */
74770bfb307SMatt Roper if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
748379bc100SJani Nikula bxt_dsi_pll_disable(encoder);
749379bc100SJani Nikula bxt_dsi_pll_enable(encoder, pipe_config);
750379bc100SJani Nikula } else {
751379bc100SJani Nikula vlv_dsi_pll_disable(encoder);
752379bc100SJani Nikula vlv_dsi_pll_enable(encoder, pipe_config);
753379bc100SJani Nikula }
754379bc100SJani Nikula
755379bc100SJani Nikula if (IS_BROXTON(dev_priv)) {
756379bc100SJani Nikula /* Add MIPI IO reset programming for modeset */
7576068bc20SJani Nikula intel_de_rmw(display, BXT_P_CR_GT_DISP_PWRON, 0, MIPIO_RST_CTRL);
758379bc100SJani Nikula
759379bc100SJani Nikula /* Power up DSI regulator */
7606068bc20SJani Nikula intel_de_write(display, BXT_P_DSI_REGULATOR_CFG, STAP_SELECT);
7616068bc20SJani Nikula intel_de_write(display, BXT_P_DSI_REGULATOR_TX_CTRL, 0);
762379bc100SJani Nikula }
763379bc100SJani Nikula
764379bc100SJani Nikula if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
765379bc100SJani Nikula /* Disable DPOunit clock gating, can stall pipe */
7666068bc20SJani Nikula intel_de_rmw(display, DSPCLK_GATE_D(dev_priv),
76728cbe92bSAndrzej Hajda 0, DPOUNIT_CLOCK_GATE_DISABLE);
768379bc100SJani Nikula }
769379bc100SJani Nikula
770379bc100SJani Nikula if (!IS_GEMINILAKE(dev_priv))
771379bc100SJani Nikula intel_dsi_prepare(encoder, pipe_config);
772379bc100SJani Nikula
773fa83c121SHans de Goede /* Give the panel time to power-on and then deassert its reset */
774379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_ON);
7756fdb335fSHans de Goede msleep(intel_dsi->panel_on_delay);
776fa83c121SHans de Goede intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DEASSERT_RESET);
777379bc100SJani Nikula
778379bc100SJani Nikula if (IS_GEMINILAKE(dev_priv)) {
779379bc100SJani Nikula glk_cold_boot = glk_dsi_enable_io(encoder);
780379bc100SJani Nikula
781379bc100SJani Nikula /* Prepare port in cold boot(s3/s4) scenario */
782379bc100SJani Nikula if (glk_cold_boot)
783379bc100SJani Nikula intel_dsi_prepare(encoder, pipe_config);
784379bc100SJani Nikula }
785379bc100SJani Nikula
786379bc100SJani Nikula /* Put device in ready state (LP-11) */
787379bc100SJani Nikula intel_dsi_device_ready(encoder);
788379bc100SJani Nikula
789379bc100SJani Nikula /* Prepare port in normal boot scenario */
790379bc100SJani Nikula if (IS_GEMINILAKE(dev_priv) && !glk_cold_boot)
791379bc100SJani Nikula intel_dsi_prepare(encoder, pipe_config);
792379bc100SJani Nikula
793379bc100SJani Nikula /* Send initialization commands in LP mode */
794379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_INIT_OTP);
795379bc100SJani Nikula
796b83478b6Szuoqilin /*
797b83478b6Szuoqilin * Enable port in pre-enable phase itself because as per hw team
798b83478b6Szuoqilin * recommendation, port should be enabled before plane & pipe
799b83478b6Szuoqilin */
800379bc100SJani Nikula if (is_cmd_mode(intel_dsi)) {
801379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports)
8026068bc20SJani Nikula intel_de_write(display,
8036068bc20SJani Nikula MIPI_MAX_RETURN_PKT_SIZE(display, port), 8 * 4);
804379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_TEAR_ON);
805379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON);
806379bc100SJani Nikula } else {
807379bc100SJani Nikula msleep(20); /* XXX */
808379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports)
809379bc100SJani Nikula dpi_send_cmd(intel_dsi, TURN_ON, false, port);
810fa83c121SHans de Goede msleep(100);
811379bc100SJani Nikula
812379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON);
813379bc100SJani Nikula
814379bc100SJani Nikula intel_dsi_port_enable(encoder, pipe_config);
815379bc100SJani Nikula }
816379bc100SJani Nikula
817c0a52f8bSJani Nikula intel_backlight_enable(pipe_config, conn_state);
818379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_ON);
819379bc100SJani Nikula }
820379bc100SJani Nikula
bxt_dsi_enable(struct intel_atomic_state * state,struct intel_encoder * encoder,const struct intel_crtc_state * crtc_state,const struct drm_connector_state * conn_state)821ede9771dSVille Syrjälä static void bxt_dsi_enable(struct intel_atomic_state *state,
822ede9771dSVille Syrjälä struct intel_encoder *encoder,
82321fd23acSJani Nikula const struct intel_crtc_state *crtc_state,
82421fd23acSJani Nikula const struct drm_connector_state *conn_state)
82521fd23acSJani Nikula {
82621fd23acSJani Nikula intel_crtc_vblank_on(crtc_state);
82721fd23acSJani Nikula }
82821fd23acSJani Nikula
829379bc100SJani Nikula /*
830379bc100SJani Nikula * DSI port disable has to be done after pipe and plane disable, so we do it in
831379bc100SJani Nikula * the post_disable hook.
832379bc100SJani Nikula */
intel_dsi_disable(struct intel_atomic_state * state,struct intel_encoder * encoder,const struct intel_crtc_state * old_crtc_state,const struct drm_connector_state * old_conn_state)833ede9771dSVille Syrjälä static void intel_dsi_disable(struct intel_atomic_state *state,
834ede9771dSVille Syrjälä struct intel_encoder *encoder,
835379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state,
836379bc100SJani Nikula const struct drm_connector_state *old_conn_state)
837379bc100SJani Nikula {
838dd10a80fSJani Nikula struct drm_i915_private *i915 = to_i915(encoder->base.dev);
839b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
840379bc100SJani Nikula enum port port;
841379bc100SJani Nikula
842dd10a80fSJani Nikula drm_dbg_kms(&i915->drm, "\n");
843379bc100SJani Nikula
844379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_OFF);
845c0a52f8bSJani Nikula intel_backlight_disable(old_conn_state);
846379bc100SJani Nikula
847379bc100SJani Nikula /*
848379bc100SJani Nikula * According to the spec we should send SHUTDOWN before
849379bc100SJani Nikula * MIPI_SEQ_DISPLAY_OFF only for v3+ VBTs, but field testing
850379bc100SJani Nikula * has shown that the v3 sequence works for v2 VBTs too
851379bc100SJani Nikula */
852379bc100SJani Nikula if (is_vid_mode(intel_dsi)) {
853379bc100SJani Nikula /* Send Shutdown command to the panel in LP mode */
854379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports)
855379bc100SJani Nikula dpi_send_cmd(intel_dsi, SHUTDOWN, false, port);
856379bc100SJani Nikula msleep(10);
857379bc100SJani Nikula }
858379bc100SJani Nikula }
859379bc100SJani Nikula
intel_dsi_clear_device_ready(struct intel_encoder * encoder)860379bc100SJani Nikula static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
861379bc100SJani Nikula {
862379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
863379bc100SJani Nikula
864379bc100SJani Nikula if (IS_GEMINILAKE(dev_priv))
865379bc100SJani Nikula glk_dsi_clear_device_ready(encoder);
866379bc100SJani Nikula else
867379bc100SJani Nikula vlv_dsi_clear_device_ready(encoder);
868379bc100SJani Nikula }
869379bc100SJani Nikula
intel_dsi_post_disable(struct intel_atomic_state * state,struct intel_encoder * encoder,const struct intel_crtc_state * old_crtc_state,const struct drm_connector_state * old_conn_state)870ede9771dSVille Syrjälä static void intel_dsi_post_disable(struct intel_atomic_state *state,
871ede9771dSVille Syrjälä struct intel_encoder *encoder,
872773b4b54SVille Syrjälä const struct intel_crtc_state *old_crtc_state,
873773b4b54SVille Syrjälä const struct drm_connector_state *old_conn_state)
874379bc100SJani Nikula {
8756068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
876379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
877b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
878379bc100SJani Nikula enum port port;
879379bc100SJani Nikula
8806068bc20SJani Nikula drm_dbg_kms(display->drm, "\n");
881379bc100SJani Nikula
88270bfb307SMatt Roper if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
883773b4b54SVille Syrjälä intel_crtc_vblank_off(old_crtc_state);
884773b4b54SVille Syrjälä
885f6df4d46SLucas De Marchi skl_scaler_disable(old_crtc_state);
886773b4b54SVille Syrjälä }
887773b4b54SVille Syrjälä
888379bc100SJani Nikula if (is_vid_mode(intel_dsi)) {
889379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports)
890379bc100SJani Nikula vlv_dsi_wait_for_fifo_empty(intel_dsi, port);
891379bc100SJani Nikula
892379bc100SJani Nikula intel_dsi_port_disable(encoder);
893379bc100SJani Nikula usleep_range(2000, 5000);
894379bc100SJani Nikula }
895379bc100SJani Nikula
896379bc100SJani Nikula intel_dsi_unprepare(encoder);
897379bc100SJani Nikula
898379bc100SJani Nikula /*
899379bc100SJani Nikula * if disable packets are sent before sending shutdown packet then in
900379bc100SJani Nikula * some next enable sequence send turn on packet error is observed
901379bc100SJani Nikula */
902379bc100SJani Nikula if (is_cmd_mode(intel_dsi))
903379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_TEAR_OFF);
904379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_OFF);
905379bc100SJani Nikula
906379bc100SJani Nikula /* Transition to LP-00 */
907379bc100SJani Nikula intel_dsi_clear_device_ready(encoder);
908379bc100SJani Nikula
909379bc100SJani Nikula if (IS_BROXTON(dev_priv)) {
910379bc100SJani Nikula /* Power down DSI regulator to save power */
9116068bc20SJani Nikula intel_de_write(display, BXT_P_DSI_REGULATOR_CFG, STAP_SELECT);
9126068bc20SJani Nikula intel_de_write(display, BXT_P_DSI_REGULATOR_TX_CTRL,
913992d4694SJani Nikula HS_IO_CTRL_SELECT);
914379bc100SJani Nikula
915379bc100SJani Nikula /* Add MIPI IO reset programming for modeset */
9166068bc20SJani Nikula intel_de_rmw(display, BXT_P_CR_GT_DISP_PWRON, MIPIO_RST_CTRL, 0);
917379bc100SJani Nikula }
918379bc100SJani Nikula
91970bfb307SMatt Roper if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
920379bc100SJani Nikula bxt_dsi_pll_disable(encoder);
921379bc100SJani Nikula } else {
922379bc100SJani Nikula vlv_dsi_pll_disable(encoder);
923379bc100SJani Nikula
9246068bc20SJani Nikula intel_de_rmw(display, DSPCLK_GATE_D(dev_priv),
92528cbe92bSAndrzej Hajda DPOUNIT_CLOCK_GATE_DISABLE, 0);
926379bc100SJani Nikula }
927379bc100SJani Nikula
928379bc100SJani Nikula /* Assert reset */
929379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_ASSERT_RESET);
930379bc100SJani Nikula
931fa83c121SHans de Goede msleep(intel_dsi->panel_off_delay);
932379bc100SJani Nikula intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_OFF);
933379bc100SJani Nikula
934c87eba80SHans de Goede intel_dsi->panel_power_off_time = ktime_get_boottime();
935379bc100SJani Nikula }
936379bc100SJani Nikula
intel_dsi_get_hw_state(struct intel_encoder * encoder,enum pipe * pipe)937379bc100SJani Nikula static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
938379bc100SJani Nikula enum pipe *pipe)
939379bc100SJani Nikula {
9406068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
941379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
942b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
943379bc100SJani Nikula intel_wakeref_t wakeref;
944379bc100SJani Nikula enum port port;
945379bc100SJani Nikula bool active = false;
946379bc100SJani Nikula
9476068bc20SJani Nikula drm_dbg_kms(display->drm, "\n");
948379bc100SJani Nikula
949379bc100SJani Nikula wakeref = intel_display_power_get_if_enabled(dev_priv,
950379bc100SJani Nikula encoder->power_domain);
951379bc100SJani Nikula if (!wakeref)
952379bc100SJani Nikula return false;
953379bc100SJani Nikula
954379bc100SJani Nikula /*
955379bc100SJani Nikula * On Broxton the PLL needs to be enabled with a valid divider
956379bc100SJani Nikula * configuration, otherwise accessing DSI registers will hang the
957379bc100SJani Nikula * machine. See BSpec North Display Engine registers/MIPI[BXT].
958379bc100SJani Nikula */
95970bfb307SMatt Roper if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
96070bfb307SMatt Roper !bxt_dsi_pll_is_enabled(dev_priv))
961379bc100SJani Nikula goto out_put_power;
962379bc100SJani Nikula
963379bc100SJani Nikula /* XXX: this only works for one DSI output */
964379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
965bda4a7abSVille Syrjälä i915_reg_t port_ctrl = port_ctrl_reg(dev_priv, port);
9666068bc20SJani Nikula bool enabled = intel_de_read(display, port_ctrl) & DPI_ENABLE;
967379bc100SJani Nikula
968379bc100SJani Nikula /*
969379bc100SJani Nikula * Due to some hardware limitations on VLV/CHV, the DPI enable
970379bc100SJani Nikula * bit in port C control register does not get set. As a
971379bc100SJani Nikula * workaround, check pipe B conf instead.
972379bc100SJani Nikula */
973379bc100SJani Nikula if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
974379bc100SJani Nikula port == PORT_C)
975*984b61c3SJani Nikula enabled = intel_de_read(display,
976*984b61c3SJani Nikula TRANSCONF(dev_priv, PIPE_B)) & TRANSCONF_ENABLE;
977379bc100SJani Nikula
978379bc100SJani Nikula /* Try command mode if video mode not enabled */
979379bc100SJani Nikula if (!enabled) {
9806068bc20SJani Nikula u32 tmp = intel_de_read(display,
9816068bc20SJani Nikula MIPI_DSI_FUNC_PRG(display, port));
982379bc100SJani Nikula enabled = tmp & CMD_MODE_DATA_WIDTH_MASK;
983379bc100SJani Nikula }
984379bc100SJani Nikula
985379bc100SJani Nikula if (!enabled)
986379bc100SJani Nikula continue;
987379bc100SJani Nikula
9886068bc20SJani Nikula if (!(intel_de_read(display, MIPI_DEVICE_READY(display, port)) & DEVICE_READY))
989379bc100SJani Nikula continue;
990379bc100SJani Nikula
99170bfb307SMatt Roper if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
9926068bc20SJani Nikula u32 tmp = intel_de_read(display, MIPI_CTRL(display, port));
993379bc100SJani Nikula tmp &= BXT_PIPE_SELECT_MASK;
994379bc100SJani Nikula tmp >>= BXT_PIPE_SELECT_SHIFT;
995379bc100SJani Nikula
9966068bc20SJani Nikula if (drm_WARN_ON(display->drm, tmp > PIPE_C))
997379bc100SJani Nikula continue;
998379bc100SJani Nikula
999379bc100SJani Nikula *pipe = tmp;
1000379bc100SJani Nikula } else {
1001379bc100SJani Nikula *pipe = port == PORT_A ? PIPE_A : PIPE_B;
1002379bc100SJani Nikula }
1003379bc100SJani Nikula
1004379bc100SJani Nikula active = true;
1005379bc100SJani Nikula break;
1006379bc100SJani Nikula }
1007379bc100SJani Nikula
1008379bc100SJani Nikula out_put_power:
1009379bc100SJani Nikula intel_display_power_put(dev_priv, encoder->power_domain, wakeref);
1010379bc100SJani Nikula
1011379bc100SJani Nikula return active;
1012379bc100SJani Nikula }
1013379bc100SJani Nikula
bxt_dsi_get_pipe_config(struct intel_encoder * encoder,struct intel_crtc_state * pipe_config)1014379bc100SJani Nikula static void bxt_dsi_get_pipe_config(struct intel_encoder *encoder,
1015379bc100SJani Nikula struct intel_crtc_state *pipe_config)
1016379bc100SJani Nikula {
10176068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
1018379bc100SJani Nikula struct drm_display_mode *adjusted_mode =
10191326a92cSMaarten Lankhorst &pipe_config->hw.adjusted_mode;
1020379bc100SJani Nikula struct drm_display_mode *adjusted_mode_sw;
10212225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
1022b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
1023379bc100SJani Nikula unsigned int lane_count = intel_dsi->lane_count;
1024379bc100SJani Nikula unsigned int bpp, fmt;
1025379bc100SJani Nikula enum port port;
10261fdac123SJani Nikula u16 hactive, hfp, hsync, hbp, vfp, vsync;
1027379bc100SJani Nikula u16 hfp_sw, hsync_sw, hbp_sw;
1028379bc100SJani Nikula u16 crtc_htotal_sw, crtc_hsync_start_sw, crtc_hsync_end_sw,
1029379bc100SJani Nikula crtc_hblank_start_sw, crtc_hblank_end_sw;
1030379bc100SJani Nikula
1031379bc100SJani Nikula /* FIXME: hw readout should not depend on SW state */
10321326a92cSMaarten Lankhorst adjusted_mode_sw = &crtc->config->hw.adjusted_mode;
1033379bc100SJani Nikula
1034379bc100SJani Nikula /*
1035379bc100SJani Nikula * Atleast one port is active as encoder->get_config called only if
1036379bc100SJani Nikula * encoder->get_hw_state() returns true.
1037379bc100SJani Nikula */
1038379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
10396068bc20SJani Nikula if (intel_de_read(display, BXT_MIPI_PORT_CTRL(port)) & DPI_ENABLE)
1040379bc100SJani Nikula break;
1041379bc100SJani Nikula }
1042379bc100SJani Nikula
10436068bc20SJani Nikula fmt = intel_de_read(display, MIPI_DSI_FUNC_PRG(display, port)) & VID_MODE_FORMAT_MASK;
1044379bc100SJani Nikula bpp = mipi_dsi_pixel_format_to_bpp(
1045379bc100SJani Nikula pixel_format_from_register_bits(fmt));
1046379bc100SJani Nikula
1047c640f6c5SVille Syrjälä pipe_config->pipe_bpp = bdw_get_pipe_misc_bpp(crtc);
1048379bc100SJani Nikula
1049379bc100SJani Nikula /* Enable Frame time stamo based scanline reporting */
1050af157b76SVille Syrjälä pipe_config->mode_flags |=
1051379bc100SJani Nikula I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP;
1052379bc100SJani Nikula
1053379bc100SJani Nikula /* In terms of pixels */
1054379bc100SJani Nikula adjusted_mode->crtc_hdisplay =
10556068bc20SJani Nikula intel_de_read(display,
1056992d4694SJani Nikula BXT_MIPI_TRANS_HACTIVE(port));
1057379bc100SJani Nikula adjusted_mode->crtc_vdisplay =
10586068bc20SJani Nikula intel_de_read(display,
1059992d4694SJani Nikula BXT_MIPI_TRANS_VACTIVE(port));
1060379bc100SJani Nikula adjusted_mode->crtc_vtotal =
10616068bc20SJani Nikula intel_de_read(display,
1062992d4694SJani Nikula BXT_MIPI_TRANS_VTOTAL(port));
1063379bc100SJani Nikula
1064379bc100SJani Nikula hactive = adjusted_mode->crtc_hdisplay;
10656068bc20SJani Nikula hfp = intel_de_read(display, MIPI_HFP_COUNT(display, port));
1066379bc100SJani Nikula
1067379bc100SJani Nikula /*
1068379bc100SJani Nikula * Meaningful for video mode non-burst sync pulse mode only,
1069379bc100SJani Nikula * can be zero for non-burst sync events and burst modes
1070379bc100SJani Nikula */
10716068bc20SJani Nikula hsync = intel_de_read(display, MIPI_HSYNC_PADDING_COUNT(display, port));
10726068bc20SJani Nikula hbp = intel_de_read(display, MIPI_HBP_COUNT(display, port));
1073379bc100SJani Nikula
1074379bc100SJani Nikula /* harizontal values are in terms of high speed byte clock */
1075379bc100SJani Nikula hfp = pixels_from_txbyteclkhs(hfp, bpp, lane_count,
1076379bc100SJani Nikula intel_dsi->burst_mode_ratio);
1077379bc100SJani Nikula hsync = pixels_from_txbyteclkhs(hsync, bpp, lane_count,
1078379bc100SJani Nikula intel_dsi->burst_mode_ratio);
1079379bc100SJani Nikula hbp = pixels_from_txbyteclkhs(hbp, bpp, lane_count,
1080379bc100SJani Nikula intel_dsi->burst_mode_ratio);
1081379bc100SJani Nikula
1082379bc100SJani Nikula if (intel_dsi->dual_link) {
1083379bc100SJani Nikula hfp *= 2;
1084379bc100SJani Nikula hsync *= 2;
1085379bc100SJani Nikula hbp *= 2;
1086379bc100SJani Nikula }
1087379bc100SJani Nikula
1088379bc100SJani Nikula /* vertical values are in terms of lines */
10896068bc20SJani Nikula vfp = intel_de_read(display, MIPI_VFP_COUNT(display, port));
10906068bc20SJani Nikula vsync = intel_de_read(display, MIPI_VSYNC_PADDING_COUNT(display, port));
1091379bc100SJani Nikula
1092379bc100SJani Nikula adjusted_mode->crtc_htotal = hactive + hfp + hsync + hbp;
1093379bc100SJani Nikula adjusted_mode->crtc_hsync_start = hfp + adjusted_mode->crtc_hdisplay;
1094379bc100SJani Nikula adjusted_mode->crtc_hsync_end = hsync + adjusted_mode->crtc_hsync_start;
1095379bc100SJani Nikula adjusted_mode->crtc_hblank_start = adjusted_mode->crtc_hdisplay;
1096379bc100SJani Nikula adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_htotal;
1097379bc100SJani Nikula
1098379bc100SJani Nikula adjusted_mode->crtc_vsync_start = vfp + adjusted_mode->crtc_vdisplay;
1099379bc100SJani Nikula adjusted_mode->crtc_vsync_end = vsync + adjusted_mode->crtc_vsync_start;
1100379bc100SJani Nikula adjusted_mode->crtc_vblank_start = adjusted_mode->crtc_vdisplay;
1101379bc100SJani Nikula adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vtotal;
1102379bc100SJani Nikula
1103379bc100SJani Nikula /*
1104379bc100SJani Nikula * In BXT DSI there is no regs programmed with few horizontal timings
1105379bc100SJani Nikula * in Pixels but txbyteclkhs.. So retrieval process adds some
1106379bc100SJani Nikula * ROUND_UP ERRORS in the process of PIXELS<==>txbyteclkhs.
1107379bc100SJani Nikula * Actually here for the given adjusted_mode, we are calculating the
1108379bc100SJani Nikula * value programmed to the port and then back to the horizontal timing
1109379bc100SJani Nikula * param in pixels. This is the expected value, including roundup errors
1110379bc100SJani Nikula * And if that is same as retrieved value from port, then
1111379bc100SJani Nikula * (HW state) adjusted_mode's horizontal timings are corrected to
1112379bc100SJani Nikula * match with SW state to nullify the errors.
1113379bc100SJani Nikula */
1114379bc100SJani Nikula /* Calculating the value programmed to the Port register */
1115379bc100SJani Nikula hfp_sw = adjusted_mode_sw->crtc_hsync_start -
1116379bc100SJani Nikula adjusted_mode_sw->crtc_hdisplay;
1117379bc100SJani Nikula hsync_sw = adjusted_mode_sw->crtc_hsync_end -
1118379bc100SJani Nikula adjusted_mode_sw->crtc_hsync_start;
1119379bc100SJani Nikula hbp_sw = adjusted_mode_sw->crtc_htotal -
1120379bc100SJani Nikula adjusted_mode_sw->crtc_hsync_end;
1121379bc100SJani Nikula
1122379bc100SJani Nikula if (intel_dsi->dual_link) {
1123379bc100SJani Nikula hfp_sw /= 2;
1124379bc100SJani Nikula hsync_sw /= 2;
1125379bc100SJani Nikula hbp_sw /= 2;
1126379bc100SJani Nikula }
1127379bc100SJani Nikula
1128379bc100SJani Nikula hfp_sw = txbyteclkhs(hfp_sw, bpp, lane_count,
1129379bc100SJani Nikula intel_dsi->burst_mode_ratio);
1130379bc100SJani Nikula hsync_sw = txbyteclkhs(hsync_sw, bpp, lane_count,
1131379bc100SJani Nikula intel_dsi->burst_mode_ratio);
1132379bc100SJani Nikula hbp_sw = txbyteclkhs(hbp_sw, bpp, lane_count,
1133379bc100SJani Nikula intel_dsi->burst_mode_ratio);
1134379bc100SJani Nikula
1135379bc100SJani Nikula /* Reverse calculating the adjusted mode parameters from port reg vals*/
1136379bc100SJani Nikula hfp_sw = pixels_from_txbyteclkhs(hfp_sw, bpp, lane_count,
1137379bc100SJani Nikula intel_dsi->burst_mode_ratio);
1138379bc100SJani Nikula hsync_sw = pixels_from_txbyteclkhs(hsync_sw, bpp, lane_count,
1139379bc100SJani Nikula intel_dsi->burst_mode_ratio);
1140379bc100SJani Nikula hbp_sw = pixels_from_txbyteclkhs(hbp_sw, bpp, lane_count,
1141379bc100SJani Nikula intel_dsi->burst_mode_ratio);
1142379bc100SJani Nikula
1143379bc100SJani Nikula if (intel_dsi->dual_link) {
1144379bc100SJani Nikula hfp_sw *= 2;
1145379bc100SJani Nikula hsync_sw *= 2;
1146379bc100SJani Nikula hbp_sw *= 2;
1147379bc100SJani Nikula }
1148379bc100SJani Nikula
1149379bc100SJani Nikula crtc_htotal_sw = adjusted_mode_sw->crtc_hdisplay + hfp_sw +
1150379bc100SJani Nikula hsync_sw + hbp_sw;
1151379bc100SJani Nikula crtc_hsync_start_sw = hfp_sw + adjusted_mode_sw->crtc_hdisplay;
1152379bc100SJani Nikula crtc_hsync_end_sw = hsync_sw + crtc_hsync_start_sw;
1153379bc100SJani Nikula crtc_hblank_start_sw = adjusted_mode_sw->crtc_hdisplay;
1154379bc100SJani Nikula crtc_hblank_end_sw = crtc_htotal_sw;
1155379bc100SJani Nikula
1156379bc100SJani Nikula if (adjusted_mode->crtc_htotal == crtc_htotal_sw)
1157379bc100SJani Nikula adjusted_mode->crtc_htotal = adjusted_mode_sw->crtc_htotal;
1158379bc100SJani Nikula
1159379bc100SJani Nikula if (adjusted_mode->crtc_hsync_start == crtc_hsync_start_sw)
1160379bc100SJani Nikula adjusted_mode->crtc_hsync_start =
1161379bc100SJani Nikula adjusted_mode_sw->crtc_hsync_start;
1162379bc100SJani Nikula
1163379bc100SJani Nikula if (adjusted_mode->crtc_hsync_end == crtc_hsync_end_sw)
1164379bc100SJani Nikula adjusted_mode->crtc_hsync_end =
1165379bc100SJani Nikula adjusted_mode_sw->crtc_hsync_end;
1166379bc100SJani Nikula
1167379bc100SJani Nikula if (adjusted_mode->crtc_hblank_start == crtc_hblank_start_sw)
1168379bc100SJani Nikula adjusted_mode->crtc_hblank_start =
1169379bc100SJani Nikula adjusted_mode_sw->crtc_hblank_start;
1170379bc100SJani Nikula
1171379bc100SJani Nikula if (adjusted_mode->crtc_hblank_end == crtc_hblank_end_sw)
1172379bc100SJani Nikula adjusted_mode->crtc_hblank_end =
1173379bc100SJani Nikula adjusted_mode_sw->crtc_hblank_end;
1174379bc100SJani Nikula }
1175379bc100SJani Nikula
intel_dsi_get_config(struct intel_encoder * encoder,struct intel_crtc_state * pipe_config)1176379bc100SJani Nikula static void intel_dsi_get_config(struct intel_encoder *encoder,
1177379bc100SJani Nikula struct intel_crtc_state *pipe_config)
1178379bc100SJani Nikula {
1179379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
118041211134SHans de Goede struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
1181379bc100SJani Nikula u32 pclk;
118241211134SHans de Goede
1183f1f76d7aSWambui Karuga drm_dbg_kms(&dev_priv->drm, "\n");
1184379bc100SJani Nikula
1185379bc100SJani Nikula pipe_config->output_types |= BIT(INTEL_OUTPUT_DSI);
1186379bc100SJani Nikula
118770bfb307SMatt Roper if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
1188379bc100SJani Nikula bxt_dsi_get_pipe_config(encoder, pipe_config);
1189379bc100SJani Nikula pclk = bxt_dsi_get_pclk(encoder, pipe_config);
1190379bc100SJani Nikula } else {
1191379bc100SJani Nikula pclk = vlv_dsi_get_pclk(encoder, pipe_config);
1192379bc100SJani Nikula }
1193379bc100SJani Nikula
1194379bc100SJani Nikula pipe_config->port_clock = pclk;
1195665a7b04SVille Syrjälä
1196665a7b04SVille Syrjälä /* FIXME definitely not right for burst/cmd mode/pixel overlap */
1197665a7b04SVille Syrjälä pipe_config->hw.adjusted_mode.crtc_clock = pclk;
1198665a7b04SVille Syrjälä if (intel_dsi->dual_link)
1199665a7b04SVille Syrjälä pipe_config->hw.adjusted_mode.crtc_clock *= 2;
1200379bc100SJani Nikula }
1201379bc100SJani Nikula
1202379bc100SJani Nikula /* return txclkesc cycles in terms of divider and duration in us */
txclkesc(u32 divider,unsigned int us)1203379bc100SJani Nikula static u16 txclkesc(u32 divider, unsigned int us)
1204379bc100SJani Nikula {
1205379bc100SJani Nikula switch (divider) {
1206379bc100SJani Nikula case ESCAPE_CLOCK_DIVIDER_1:
1207379bc100SJani Nikula default:
1208379bc100SJani Nikula return 20 * us;
1209379bc100SJani Nikula case ESCAPE_CLOCK_DIVIDER_2:
1210379bc100SJani Nikula return 10 * us;
1211379bc100SJani Nikula case ESCAPE_CLOCK_DIVIDER_4:
1212379bc100SJani Nikula return 5 * us;
1213379bc100SJani Nikula }
1214379bc100SJani Nikula }
1215379bc100SJani Nikula
set_dsi_timings(struct intel_encoder * encoder,const struct drm_display_mode * adjusted_mode)12164cfff967SJani Nikula static void set_dsi_timings(struct intel_encoder *encoder,
1217379bc100SJani Nikula const struct drm_display_mode *adjusted_mode)
1218379bc100SJani Nikula {
12196068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
12204cfff967SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
12214cfff967SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
1222379bc100SJani Nikula enum port port;
1223379bc100SJani Nikula unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
1224379bc100SJani Nikula unsigned int lane_count = intel_dsi->lane_count;
1225379bc100SJani Nikula
1226379bc100SJani Nikula u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
1227379bc100SJani Nikula
1228379bc100SJani Nikula hactive = adjusted_mode->crtc_hdisplay;
1229379bc100SJani Nikula hfp = adjusted_mode->crtc_hsync_start - adjusted_mode->crtc_hdisplay;
1230379bc100SJani Nikula hsync = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
1231379bc100SJani Nikula hbp = adjusted_mode->crtc_htotal - adjusted_mode->crtc_hsync_end;
1232379bc100SJani Nikula
1233379bc100SJani Nikula if (intel_dsi->dual_link) {
1234379bc100SJani Nikula hactive /= 2;
1235379bc100SJani Nikula if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
1236379bc100SJani Nikula hactive += intel_dsi->pixel_overlap;
1237379bc100SJani Nikula hfp /= 2;
1238379bc100SJani Nikula hsync /= 2;
1239379bc100SJani Nikula hbp /= 2;
1240379bc100SJani Nikula }
1241379bc100SJani Nikula
1242379bc100SJani Nikula vfp = adjusted_mode->crtc_vsync_start - adjusted_mode->crtc_vdisplay;
1243379bc100SJani Nikula vsync = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
1244379bc100SJani Nikula vbp = adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vsync_end;
1245379bc100SJani Nikula
1246379bc100SJani Nikula /* horizontal values are in terms of high speed byte clock */
1247379bc100SJani Nikula hactive = txbyteclkhs(hactive, bpp, lane_count,
1248379bc100SJani Nikula intel_dsi->burst_mode_ratio);
1249379bc100SJani Nikula hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
1250379bc100SJani Nikula hsync = txbyteclkhs(hsync, bpp, lane_count,
1251379bc100SJani Nikula intel_dsi->burst_mode_ratio);
1252379bc100SJani Nikula hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
1253379bc100SJani Nikula
1254379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
125570bfb307SMatt Roper if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
1256379bc100SJani Nikula /*
1257379bc100SJani Nikula * Program hdisplay and vdisplay on MIPI transcoder.
1258379bc100SJani Nikula * This is different from calculated hactive and
1259379bc100SJani Nikula * vactive, as they are calculated per channel basis,
1260379bc100SJani Nikula * whereas these values should be based on resolution.
1261379bc100SJani Nikula */
12626068bc20SJani Nikula intel_de_write(display, BXT_MIPI_TRANS_HACTIVE(port),
1263379bc100SJani Nikula adjusted_mode->crtc_hdisplay);
12646068bc20SJani Nikula intel_de_write(display, BXT_MIPI_TRANS_VACTIVE(port),
1265379bc100SJani Nikula adjusted_mode->crtc_vdisplay);
12666068bc20SJani Nikula intel_de_write(display, BXT_MIPI_TRANS_VTOTAL(port),
1267379bc100SJani Nikula adjusted_mode->crtc_vtotal);
1268379bc100SJani Nikula }
1269379bc100SJani Nikula
12706068bc20SJani Nikula intel_de_write(display, MIPI_HACTIVE_AREA_COUNT(display, port),
1271992d4694SJani Nikula hactive);
12726068bc20SJani Nikula intel_de_write(display, MIPI_HFP_COUNT(display, port), hfp);
1273379bc100SJani Nikula
1274379bc100SJani Nikula /* meaningful for video mode non-burst sync pulse mode only,
1275379bc100SJani Nikula * can be zero for non-burst sync events and burst modes */
12766068bc20SJani Nikula intel_de_write(display, MIPI_HSYNC_PADDING_COUNT(display, port),
1277992d4694SJani Nikula hsync);
12786068bc20SJani Nikula intel_de_write(display, MIPI_HBP_COUNT(display, port), hbp);
1279379bc100SJani Nikula
1280379bc100SJani Nikula /* vertical values are in terms of lines */
12816068bc20SJani Nikula intel_de_write(display, MIPI_VFP_COUNT(display, port), vfp);
12826068bc20SJani Nikula intel_de_write(display, MIPI_VSYNC_PADDING_COUNT(display, port),
1283992d4694SJani Nikula vsync);
12846068bc20SJani Nikula intel_de_write(display, MIPI_VBP_COUNT(display, port), vbp);
1285379bc100SJani Nikula }
1286379bc100SJani Nikula }
1287379bc100SJani Nikula
pixel_format_to_reg(enum mipi_dsi_pixel_format fmt)1288379bc100SJani Nikula static u32 pixel_format_to_reg(enum mipi_dsi_pixel_format fmt)
1289379bc100SJani Nikula {
1290379bc100SJani Nikula switch (fmt) {
1291379bc100SJani Nikula case MIPI_DSI_FMT_RGB888:
1292379bc100SJani Nikula return VID_MODE_FORMAT_RGB888;
1293379bc100SJani Nikula case MIPI_DSI_FMT_RGB666:
1294379bc100SJani Nikula return VID_MODE_FORMAT_RGB666;
1295379bc100SJani Nikula case MIPI_DSI_FMT_RGB666_PACKED:
1296379bc100SJani Nikula return VID_MODE_FORMAT_RGB666_PACKED;
1297379bc100SJani Nikula case MIPI_DSI_FMT_RGB565:
1298379bc100SJani Nikula return VID_MODE_FORMAT_RGB565;
1299379bc100SJani Nikula default:
1300379bc100SJani Nikula MISSING_CASE(fmt);
1301379bc100SJani Nikula return VID_MODE_FORMAT_RGB666;
1302379bc100SJani Nikula }
1303379bc100SJani Nikula }
1304379bc100SJani Nikula
intel_dsi_prepare(struct intel_encoder * encoder,const struct intel_crtc_state * pipe_config)13054cfff967SJani Nikula static void intel_dsi_prepare(struct intel_encoder *encoder,
1306379bc100SJani Nikula const struct intel_crtc_state *pipe_config)
1307379bc100SJani Nikula {
13086068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
13094cfff967SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1310f15f01a7SVille Syrjälä struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
13114cfff967SJani Nikula struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
13121326a92cSMaarten Lankhorst const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
1313379bc100SJani Nikula enum port port;
1314379bc100SJani Nikula unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
1315379bc100SJani Nikula u32 val, tmp;
1316379bc100SJani Nikula u16 mode_hdisplay;
1317379bc100SJani Nikula
13186068bc20SJani Nikula drm_dbg_kms(display->drm, "pipe %c\n", pipe_name(crtc->pipe));
1319379bc100SJani Nikula
1320379bc100SJani Nikula mode_hdisplay = adjusted_mode->crtc_hdisplay;
1321379bc100SJani Nikula
1322379bc100SJani Nikula if (intel_dsi->dual_link) {
1323379bc100SJani Nikula mode_hdisplay /= 2;
1324379bc100SJani Nikula if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
1325379bc100SJani Nikula mode_hdisplay += intel_dsi->pixel_overlap;
1326379bc100SJani Nikula }
1327379bc100SJani Nikula
1328379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
1329379bc100SJani Nikula if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1330379bc100SJani Nikula /*
1331379bc100SJani Nikula * escape clock divider, 20MHz, shared for A and C.
1332379bc100SJani Nikula * device ready must be off when doing this! txclkesc?
1333379bc100SJani Nikula */
13346068bc20SJani Nikula tmp = intel_de_read(display, MIPI_CTRL(display, PORT_A));
1335379bc100SJani Nikula tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
13366068bc20SJani Nikula intel_de_write(display, MIPI_CTRL(display, PORT_A),
1337992d4694SJani Nikula tmp | ESCAPE_CLOCK_DIVIDER_1);
1338379bc100SJani Nikula
1339379bc100SJani Nikula /* read request priority is per pipe */
13406068bc20SJani Nikula tmp = intel_de_read(display, MIPI_CTRL(display, port));
1341379bc100SJani Nikula tmp &= ~READ_REQUEST_PRIORITY_MASK;
13426068bc20SJani Nikula intel_de_write(display, MIPI_CTRL(display, port),
1343992d4694SJani Nikula tmp | READ_REQUEST_PRIORITY_HIGH);
134470bfb307SMatt Roper } else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
1345f15f01a7SVille Syrjälä enum pipe pipe = crtc->pipe;
1346379bc100SJani Nikula
13476068bc20SJani Nikula intel_de_rmw(display, MIPI_CTRL(display, port),
134828cbe92bSAndrzej Hajda BXT_PIPE_SELECT_MASK, BXT_PIPE_SELECT(pipe));
1349379bc100SJani Nikula }
1350379bc100SJani Nikula
1351379bc100SJani Nikula /* XXX: why here, why like this? handling in irq handler?! */
13526068bc20SJani Nikula intel_de_write(display, MIPI_INTR_STAT(display, port), 0xffffffff);
13536068bc20SJani Nikula intel_de_write(display, MIPI_INTR_EN(display, port), 0xffffffff);
1354379bc100SJani Nikula
13556068bc20SJani Nikula intel_de_write(display, MIPI_DPHY_PARAM(display, port),
1356992d4694SJani Nikula intel_dsi->dphy_reg);
1357379bc100SJani Nikula
13586068bc20SJani Nikula intel_de_write(display, MIPI_DPI_RESOLUTION(display, port),
1359992d4694SJani Nikula adjusted_mode->crtc_vdisplay << VERTICAL_ADDRESS_SHIFT | mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
1360379bc100SJani Nikula }
1361379bc100SJani Nikula
1362379bc100SJani Nikula set_dsi_timings(encoder, adjusted_mode);
1363379bc100SJani Nikula
1364379bc100SJani Nikula val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
1365379bc100SJani Nikula if (is_cmd_mode(intel_dsi)) {
1366379bc100SJani Nikula val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
1367379bc100SJani Nikula val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
1368379bc100SJani Nikula } else {
1369379bc100SJani Nikula val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
1370379bc100SJani Nikula val |= pixel_format_to_reg(intel_dsi->pixel_format);
1371379bc100SJani Nikula }
1372379bc100SJani Nikula
1373379bc100SJani Nikula tmp = 0;
1374379bc100SJani Nikula if (intel_dsi->eotp_pkt == 0)
1375379bc100SJani Nikula tmp |= EOT_DISABLE;
1376379bc100SJani Nikula if (intel_dsi->clock_stop)
1377379bc100SJani Nikula tmp |= CLOCKSTOP;
1378379bc100SJani Nikula
137970bfb307SMatt Roper if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
1380379bc100SJani Nikula tmp |= BXT_DPHY_DEFEATURE_EN;
1381379bc100SJani Nikula if (!is_cmd_mode(intel_dsi))
1382379bc100SJani Nikula tmp |= BXT_DEFEATURE_DPI_FIFO_CTR;
1383379bc100SJani Nikula }
1384379bc100SJani Nikula
1385379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
13866068bc20SJani Nikula intel_de_write(display, MIPI_DSI_FUNC_PRG(display, port), val);
1387379bc100SJani Nikula
1388379bc100SJani Nikula /* timeouts for recovery. one frame IIUC. if counter expires,
1389379bc100SJani Nikula * EOT and stop state. */
1390379bc100SJani Nikula
1391379bc100SJani Nikula /*
1392379bc100SJani Nikula * In burst mode, value greater than one DPI line Time in byte
1393379bc100SJani Nikula * clock (txbyteclkhs) To timeout this timer 1+ of the above
1394379bc100SJani Nikula * said value is recommended.
1395379bc100SJani Nikula *
1396379bc100SJani Nikula * In non-burst mode, Value greater than one DPI frame time in
1397379bc100SJani Nikula * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
1398379bc100SJani Nikula * said value is recommended.
1399379bc100SJani Nikula *
1400379bc100SJani Nikula * In DBI only mode, value greater than one DBI frame time in
1401379bc100SJani Nikula * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
1402379bc100SJani Nikula * said value is recommended.
1403379bc100SJani Nikula */
1404379bc100SJani Nikula
1405379bc100SJani Nikula if (is_vid_mode(intel_dsi) &&
14068f0991ccSJani Nikula intel_dsi->video_mode == BURST_MODE) {
14076068bc20SJani Nikula intel_de_write(display, MIPI_HS_TX_TIMEOUT(display, port),
1408992d4694SJani Nikula txbyteclkhs(adjusted_mode->crtc_htotal, bpp, intel_dsi->lane_count, intel_dsi->burst_mode_ratio) + 1);
1409379bc100SJani Nikula } else {
14106068bc20SJani Nikula intel_de_write(display, MIPI_HS_TX_TIMEOUT(display, port),
1411992d4694SJani Nikula txbyteclkhs(adjusted_mode->crtc_vtotal * adjusted_mode->crtc_htotal, bpp, intel_dsi->lane_count, intel_dsi->burst_mode_ratio) + 1);
1412379bc100SJani Nikula }
14136068bc20SJani Nikula intel_de_write(display, MIPI_LP_RX_TIMEOUT(display, port),
1414992d4694SJani Nikula intel_dsi->lp_rx_timeout);
14156068bc20SJani Nikula intel_de_write(display, MIPI_TURN_AROUND_TIMEOUT(display, port),
1416379bc100SJani Nikula intel_dsi->turn_arnd_val);
14176068bc20SJani Nikula intel_de_write(display, MIPI_DEVICE_RESET_TIMER(display, port),
1418379bc100SJani Nikula intel_dsi->rst_timer_val);
1419379bc100SJani Nikula
1420379bc100SJani Nikula /* dphy stuff */
1421379bc100SJani Nikula
1422379bc100SJani Nikula /* in terms of low power clock */
14236068bc20SJani Nikula intel_de_write(display, MIPI_INIT_COUNT(display, port),
1424379bc100SJani Nikula txclkesc(intel_dsi->escape_clk_div, 100));
1425379bc100SJani Nikula
142670bfb307SMatt Roper if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
142770bfb307SMatt Roper !intel_dsi->dual_link) {
1428379bc100SJani Nikula /*
1429379bc100SJani Nikula * BXT spec says write MIPI_INIT_COUNT for
1430379bc100SJani Nikula * both the ports, even if only one is
1431379bc100SJani Nikula * getting used. So write the other port
1432379bc100SJani Nikula * if not in dual link mode.
1433379bc100SJani Nikula */
14346068bc20SJani Nikula intel_de_write(display,
14356068bc20SJani Nikula MIPI_INIT_COUNT(display, port == PORT_A ? PORT_C : PORT_A),
1436379bc100SJani Nikula intel_dsi->init_count);
1437379bc100SJani Nikula }
1438379bc100SJani Nikula
1439379bc100SJani Nikula /* recovery disables */
14406068bc20SJani Nikula intel_de_write(display, MIPI_EOT_DISABLE(display, port), tmp);
1441379bc100SJani Nikula
1442379bc100SJani Nikula /* in terms of low power clock */
14436068bc20SJani Nikula intel_de_write(display, MIPI_INIT_COUNT(display, port),
1444992d4694SJani Nikula intel_dsi->init_count);
1445379bc100SJani Nikula
1446379bc100SJani Nikula /* in terms of txbyteclkhs. actual high to low switch +
1447379bc100SJani Nikula * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
1448379bc100SJani Nikula *
1449379bc100SJani Nikula * XXX: write MIPI_STOP_STATE_STALL?
1450379bc100SJani Nikula */
14516068bc20SJani Nikula intel_de_write(display, MIPI_HIGH_LOW_SWITCH_COUNT(display, port),
1452379bc100SJani Nikula intel_dsi->hs_to_lp_count);
1453379bc100SJani Nikula
1454379bc100SJani Nikula /* XXX: low power clock equivalence in terms of byte clock.
1455379bc100SJani Nikula * the number of byte clocks occupied in one low power clock.
1456379bc100SJani Nikula * based on txbyteclkhs and txclkesc.
1457379bc100SJani Nikula * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
1458379bc100SJani Nikula * ) / 105.???
1459379bc100SJani Nikula */
14606068bc20SJani Nikula intel_de_write(display, MIPI_LP_BYTECLK(display, port),
1461992d4694SJani Nikula intel_dsi->lp_byte_clk);
1462379bc100SJani Nikula
1463379bc100SJani Nikula if (IS_GEMINILAKE(dev_priv)) {
14646068bc20SJani Nikula intel_de_write(display, MIPI_TLPX_TIME_COUNT(display, port),
1465379bc100SJani Nikula intel_dsi->lp_byte_clk);
1466379bc100SJani Nikula /* Shadow of DPHY reg */
14676068bc20SJani Nikula intel_de_write(display, MIPI_CLK_LANE_TIMING(display, port),
1468379bc100SJani Nikula intel_dsi->dphy_reg);
1469379bc100SJani Nikula }
1470379bc100SJani Nikula
1471379bc100SJani Nikula /* the bw essential for transmitting 16 long packets containing
1472379bc100SJani Nikula * 252 bytes meant for dcs write memory command is programmed in
1473379bc100SJani Nikula * this register in terms of byte clocks. based on dsi transfer
1474379bc100SJani Nikula * rate and the number of lanes configured the time taken to
1475379bc100SJani Nikula * transmit 16 long packets in a dsi stream varies. */
14766068bc20SJani Nikula intel_de_write(display, MIPI_DBI_BW_CTRL(display, port),
1477992d4694SJani Nikula intel_dsi->bw_timer);
1478379bc100SJani Nikula
14796068bc20SJani Nikula intel_de_write(display, MIPI_CLK_LANE_SWITCH_TIME_CNT(display, port),
1480992d4694SJani 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);
1481379bc100SJani Nikula
14828f0991ccSJani Nikula if (is_vid_mode(intel_dsi)) {
14838f0991ccSJani Nikula u32 fmt = intel_dsi->video_frmt_cfg_bits | IP_TG_CONFIG;
14848f0991ccSJani Nikula
14858f0991ccSJani Nikula /*
14868f0991ccSJani Nikula * Some panels might have resolution which is not a
1487379bc100SJani Nikula * multiple of 64 like 1366 x 768. Enable RANDOM
14888f0991ccSJani Nikula * resolution support for such panels by default.
14898f0991ccSJani Nikula */
14908f0991ccSJani Nikula fmt |= RANDOM_DPI_DISPLAY_RESOLUTION;
14918f0991ccSJani Nikula
14928f0991ccSJani Nikula switch (intel_dsi->video_mode) {
14938f0991ccSJani Nikula default:
14948f0991ccSJani Nikula MISSING_CASE(intel_dsi->video_mode);
14958f0991ccSJani Nikula fallthrough;
14968f0991ccSJani Nikula case NON_BURST_SYNC_EVENTS:
14978f0991ccSJani Nikula fmt |= VIDEO_MODE_NON_BURST_WITH_SYNC_EVENTS;
14988f0991ccSJani Nikula break;
14998f0991ccSJani Nikula case NON_BURST_SYNC_PULSE:
15008f0991ccSJani Nikula fmt |= VIDEO_MODE_NON_BURST_WITH_SYNC_PULSE;
15018f0991ccSJani Nikula break;
15028f0991ccSJani Nikula case BURST_MODE:
15038f0991ccSJani Nikula fmt |= VIDEO_MODE_BURST;
15048f0991ccSJani Nikula break;
15058f0991ccSJani Nikula }
15068f0991ccSJani Nikula
15076068bc20SJani Nikula intel_de_write(display, MIPI_VIDEO_MODE_FORMAT(display, port), fmt);
15088f0991ccSJani Nikula }
1509379bc100SJani Nikula }
1510379bc100SJani Nikula }
1511379bc100SJani Nikula
intel_dsi_unprepare(struct intel_encoder * encoder)1512379bc100SJani Nikula static void intel_dsi_unprepare(struct intel_encoder *encoder)
1513379bc100SJani Nikula {
15146068bc20SJani Nikula struct intel_display *display = to_intel_display(encoder);
1515379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1516b7d02c3aSVille Syrjälä struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
1517379bc100SJani Nikula enum port port;
1518379bc100SJani Nikula
1519379bc100SJani Nikula if (IS_GEMINILAKE(dev_priv))
1520379bc100SJani Nikula return;
1521379bc100SJani Nikula
1522379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
1523379bc100SJani Nikula /* Panel commands can be sent when clock is in LP11 */
15246068bc20SJani Nikula intel_de_write(display, MIPI_DEVICE_READY(display, port), 0x0);
1525379bc100SJani Nikula
152670bfb307SMatt Roper if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
1527379bc100SJani Nikula bxt_dsi_reset_clocks(encoder, port);
1528379bc100SJani Nikula else
1529379bc100SJani Nikula vlv_dsi_reset_clocks(encoder, port);
15306068bc20SJani Nikula intel_de_write(display, MIPI_EOT_DISABLE(display, port), CLOCKSTOP);
1531379bc100SJani Nikula
15326068bc20SJani Nikula intel_de_rmw(display, MIPI_DSI_FUNC_PRG(display, port), VID_MODE_FORMAT_MASK, 0);
1533379bc100SJani Nikula
15346068bc20SJani Nikula intel_de_write(display, MIPI_DEVICE_READY(display, port), 0x1);
1535379bc100SJani Nikula }
1536379bc100SJani Nikula }
1537379bc100SJani Nikula
1538379bc100SJani Nikula static const struct drm_encoder_funcs intel_dsi_funcs = {
15394de77156SHans de Goede .destroy = intel_encoder_destroy,
1540379bc100SJani Nikula };
1541379bc100SJani Nikula
vlv_dsi_mode_valid(struct drm_connector * connector,struct drm_display_mode * mode)1542e0ef2daaSVille Syrjälä static enum drm_mode_status vlv_dsi_mode_valid(struct drm_connector *connector,
1543e0ef2daaSVille Syrjälä struct drm_display_mode *mode)
1544e0ef2daaSVille Syrjälä {
1545e0ef2daaSVille Syrjälä struct drm_i915_private *i915 = to_i915(connector->dev);
1546e0ef2daaSVille Syrjälä
1547e0ef2daaSVille Syrjälä if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915)) {
1548e0ef2daaSVille Syrjälä enum drm_mode_status status;
1549e0ef2daaSVille Syrjälä
1550e0ef2daaSVille Syrjälä status = intel_cpu_transcoder_mode_valid(i915, mode);
1551e0ef2daaSVille Syrjälä if (status != MODE_OK)
1552e0ef2daaSVille Syrjälä return status;
1553e0ef2daaSVille Syrjälä }
1554e0ef2daaSVille Syrjälä
1555e0ef2daaSVille Syrjälä return intel_dsi_mode_valid(connector, mode);
1556e0ef2daaSVille Syrjälä }
1557e0ef2daaSVille Syrjälä
1558379bc100SJani Nikula static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
1559379bc100SJani Nikula .get_modes = intel_dsi_get_modes,
1560e0ef2daaSVille Syrjälä .mode_valid = vlv_dsi_mode_valid,
1561379bc100SJani Nikula .atomic_check = intel_digital_connector_atomic_check,
1562379bc100SJani Nikula };
1563379bc100SJani Nikula
1564379bc100SJani Nikula static const struct drm_connector_funcs intel_dsi_connector_funcs = {
1565b81dddb9SVille Syrjälä .detect = intel_panel_detect,
1566379bc100SJani Nikula .late_register = intel_connector_register,
1567379bc100SJani Nikula .early_unregister = intel_connector_unregister,
1568379bc100SJani Nikula .destroy = intel_connector_destroy,
1569379bc100SJani Nikula .fill_modes = drm_helper_probe_single_connector_modes,
1570379bc100SJani Nikula .atomic_get_property = intel_digital_connector_atomic_get_property,
1571379bc100SJani Nikula .atomic_set_property = intel_digital_connector_atomic_set_property,
1572379bc100SJani Nikula .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
1573379bc100SJani Nikula .atomic_duplicate_state = intel_digital_connector_duplicate_state,
1574379bc100SJani Nikula };
1575379bc100SJani Nikula
vlv_dsi_add_properties(struct intel_connector * connector)1576f6d39f56SVille Syrjälä static void vlv_dsi_add_properties(struct intel_connector *connector)
1577379bc100SJani Nikula {
1578f6d39f56SVille Syrjälä const struct drm_display_mode *fixed_mode =
1579f6d39f56SVille Syrjälä intel_panel_preferred_fixed_mode(connector);
1580379bc100SJani Nikula
15816ac2f04bSVille Syrjälä intel_attach_scaling_mode_property(&connector->base);
1582379bc100SJani Nikula
15837eadfbfeSVille Syrjälä drm_connector_set_panel_orientation_with_quirk(&connector->base,
15841ca002adSHans de Goede intel_dsi_get_panel_orientation(connector),
1585dee54887SVille Syrjälä fixed_mode->hdisplay,
1586dee54887SVille Syrjälä fixed_mode->vdisplay);
1587379bc100SJani Nikula }
1588379bc100SJani Nikula
1589379bc100SJani Nikula #define NS_KHZ_RATIO 1000000
1590379bc100SJani Nikula
1591379bc100SJani Nikula #define PREPARE_CNT_MAX 0x3F
1592379bc100SJani Nikula #define EXIT_ZERO_CNT_MAX 0x3F
1593379bc100SJani Nikula #define CLK_ZERO_CNT_MAX 0xFF
1594379bc100SJani Nikula #define TRAIL_CNT_MAX 0x1F
1595379bc100SJani Nikula
vlv_dphy_param_init(struct intel_dsi * intel_dsi)1596379bc100SJani Nikula static void vlv_dphy_param_init(struct intel_dsi *intel_dsi)
1597379bc100SJani Nikula {
15984cfff967SJani Nikula struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
15993cf05076SVille Syrjälä struct intel_connector *connector = intel_dsi->attached_connector;
16003cf05076SVille Syrjälä struct mipi_config *mipi_config = connector->panel.vbt.dsi.config;
1601379bc100SJani Nikula u32 tlpx_ns, extra_byte_count, tlpx_ui;
1602379bc100SJani Nikula u32 ui_num, ui_den;
1603379bc100SJani Nikula u32 prepare_cnt, exit_zero_cnt, clk_zero_cnt, trail_cnt;
1604379bc100SJani Nikula u32 ths_prepare_ns, tclk_trail_ns;
1605379bc100SJani Nikula u32 tclk_prepare_clkzero, ths_prepare_hszero;
1606379bc100SJani Nikula u32 lp_to_hs_switch, hs_to_lp_switch;
1607379bc100SJani Nikula u32 mul;
1608379bc100SJani Nikula
1609379bc100SJani Nikula tlpx_ns = intel_dsi_tlpx_ns(intel_dsi);
1610379bc100SJani Nikula
1611379bc100SJani Nikula switch (intel_dsi->lane_count) {
1612379bc100SJani Nikula case 1:
1613379bc100SJani Nikula case 2:
1614379bc100SJani Nikula extra_byte_count = 2;
1615379bc100SJani Nikula break;
1616379bc100SJani Nikula case 3:
1617379bc100SJani Nikula extra_byte_count = 4;
1618379bc100SJani Nikula break;
1619379bc100SJani Nikula case 4:
1620379bc100SJani Nikula default:
1621379bc100SJani Nikula extra_byte_count = 3;
1622379bc100SJani Nikula break;
1623379bc100SJani Nikula }
1624379bc100SJani Nikula
1625379bc100SJani Nikula /* in Kbps */
1626379bc100SJani Nikula ui_num = NS_KHZ_RATIO;
1627379bc100SJani Nikula ui_den = intel_dsi_bitrate(intel_dsi);
1628379bc100SJani Nikula
1629379bc100SJani Nikula tclk_prepare_clkzero = mipi_config->tclk_prepare_clkzero;
1630379bc100SJani Nikula ths_prepare_hszero = mipi_config->ths_prepare_hszero;
1631379bc100SJani Nikula
1632379bc100SJani Nikula /*
1633379bc100SJani Nikula * B060
1634379bc100SJani Nikula * LP byte clock = TLPX/ (8UI)
1635379bc100SJani Nikula */
1636379bc100SJani Nikula intel_dsi->lp_byte_clk = DIV_ROUND_UP(tlpx_ns * ui_den, 8 * ui_num);
1637379bc100SJani Nikula
1638379bc100SJani Nikula /* DDR clock period = 2 * UI
1639379bc100SJani Nikula * UI(sec) = 1/(bitrate * 10^3) (bitrate is in KHZ)
1640379bc100SJani Nikula * UI(nsec) = 10^6 / bitrate
1641379bc100SJani Nikula * DDR clock period (nsec) = 2 * UI = (2 * 10^6)/ bitrate
1642379bc100SJani Nikula * DDR clock count = ns_value / DDR clock period
1643379bc100SJani Nikula *
1644379bc100SJani Nikula * For GEMINILAKE dphy_param_reg will be programmed in terms of
1645379bc100SJani Nikula * HS byte clock count for other platform in HS ddr clock count
1646379bc100SJani Nikula */
1647379bc100SJani Nikula mul = IS_GEMINILAKE(dev_priv) ? 8 : 2;
1648379bc100SJani Nikula ths_prepare_ns = max(mipi_config->ths_prepare,
1649379bc100SJani Nikula mipi_config->tclk_prepare);
1650379bc100SJani Nikula
1651379bc100SJani Nikula /* prepare count */
1652379bc100SJani Nikula prepare_cnt = DIV_ROUND_UP(ths_prepare_ns * ui_den, ui_num * mul);
1653379bc100SJani Nikula
1654379bc100SJani Nikula if (prepare_cnt > PREPARE_CNT_MAX) {
1655f1f76d7aSWambui Karuga drm_dbg_kms(&dev_priv->drm, "prepare count too high %u\n",
1656f1f76d7aSWambui Karuga prepare_cnt);
1657379bc100SJani Nikula prepare_cnt = PREPARE_CNT_MAX;
1658379bc100SJani Nikula }
1659379bc100SJani Nikula
1660379bc100SJani Nikula /* exit zero count */
1661379bc100SJani Nikula exit_zero_cnt = DIV_ROUND_UP(
1662379bc100SJani Nikula (ths_prepare_hszero - ths_prepare_ns) * ui_den,
1663379bc100SJani Nikula ui_num * mul
1664379bc100SJani Nikula );
1665379bc100SJani Nikula
1666379bc100SJani Nikula /*
1667379bc100SJani Nikula * Exit zero is unified val ths_zero and ths_exit
1668379bc100SJani Nikula * minimum value for ths_exit = 110ns
1669379bc100SJani Nikula * min (exit_zero_cnt * 2) = 110/UI
1670379bc100SJani Nikula * exit_zero_cnt = 55/UI
1671379bc100SJani Nikula */
1672379bc100SJani Nikula if (exit_zero_cnt < (55 * ui_den / ui_num) && (55 * ui_den) % ui_num)
1673379bc100SJani Nikula exit_zero_cnt += 1;
1674379bc100SJani Nikula
1675379bc100SJani Nikula if (exit_zero_cnt > EXIT_ZERO_CNT_MAX) {
1676f1f76d7aSWambui Karuga drm_dbg_kms(&dev_priv->drm, "exit zero count too high %u\n",
1677f1f76d7aSWambui Karuga exit_zero_cnt);
1678379bc100SJani Nikula exit_zero_cnt = EXIT_ZERO_CNT_MAX;
1679379bc100SJani Nikula }
1680379bc100SJani Nikula
1681379bc100SJani Nikula /* clk zero count */
1682379bc100SJani Nikula clk_zero_cnt = DIV_ROUND_UP(
1683379bc100SJani Nikula (tclk_prepare_clkzero - ths_prepare_ns)
1684379bc100SJani Nikula * ui_den, ui_num * mul);
1685379bc100SJani Nikula
1686379bc100SJani Nikula if (clk_zero_cnt > CLK_ZERO_CNT_MAX) {
1687f1f76d7aSWambui Karuga drm_dbg_kms(&dev_priv->drm, "clock zero count too high %u\n",
1688f1f76d7aSWambui Karuga clk_zero_cnt);
1689379bc100SJani Nikula clk_zero_cnt = CLK_ZERO_CNT_MAX;
1690379bc100SJani Nikula }
1691379bc100SJani Nikula
1692379bc100SJani Nikula /* trail count */
1693379bc100SJani Nikula tclk_trail_ns = max(mipi_config->tclk_trail, mipi_config->ths_trail);
1694379bc100SJani Nikula trail_cnt = DIV_ROUND_UP(tclk_trail_ns * ui_den, ui_num * mul);
1695379bc100SJani Nikula
1696379bc100SJani Nikula if (trail_cnt > TRAIL_CNT_MAX) {
1697f1f76d7aSWambui Karuga drm_dbg_kms(&dev_priv->drm, "trail count too high %u\n",
1698f1f76d7aSWambui Karuga trail_cnt);
1699379bc100SJani Nikula trail_cnt = TRAIL_CNT_MAX;
1700379bc100SJani Nikula }
1701379bc100SJani Nikula
1702379bc100SJani Nikula /* B080 */
1703379bc100SJani Nikula intel_dsi->dphy_reg = exit_zero_cnt << 24 | trail_cnt << 16 |
1704379bc100SJani Nikula clk_zero_cnt << 8 | prepare_cnt;
1705379bc100SJani Nikula
1706379bc100SJani Nikula /*
1707379bc100SJani Nikula * LP to HS switch count = 4TLPX + PREP_COUNT * mul + EXIT_ZERO_COUNT *
1708379bc100SJani Nikula * mul + 10UI + Extra Byte Count
1709379bc100SJani Nikula *
1710379bc100SJani Nikula * HS to LP switch count = THS-TRAIL + 2TLPX + Extra Byte Count
1711379bc100SJani Nikula * Extra Byte Count is calculated according to number of lanes.
1712379bc100SJani Nikula * High Low Switch Count is the Max of LP to HS and
1713379bc100SJani Nikula * HS to LP switch count
1714379bc100SJani Nikula *
1715379bc100SJani Nikula */
1716379bc100SJani Nikula tlpx_ui = DIV_ROUND_UP(tlpx_ns * ui_den, ui_num);
1717379bc100SJani Nikula
1718379bc100SJani Nikula /* B044 */
1719379bc100SJani Nikula /* FIXME:
1720379bc100SJani Nikula * The comment above does not match with the code */
1721379bc100SJani Nikula lp_to_hs_switch = DIV_ROUND_UP(4 * tlpx_ui + prepare_cnt * mul +
1722379bc100SJani Nikula exit_zero_cnt * mul + 10, 8);
1723379bc100SJani Nikula
1724379bc100SJani Nikula hs_to_lp_switch = DIV_ROUND_UP(mipi_config->ths_trail + 2 * tlpx_ui, 8);
1725379bc100SJani Nikula
1726379bc100SJani Nikula intel_dsi->hs_to_lp_count = max(lp_to_hs_switch, hs_to_lp_switch);
1727379bc100SJani Nikula intel_dsi->hs_to_lp_count += extra_byte_count;
1728379bc100SJani Nikula
1729379bc100SJani Nikula /* B088 */
1730379bc100SJani Nikula /* LP -> HS for clock lanes
1731379bc100SJani Nikula * LP clk sync + LP11 + LP01 + tclk_prepare + tclk_zero +
1732379bc100SJani Nikula * extra byte count
1733379bc100SJani Nikula * 2TPLX + 1TLPX + 1 TPLX(in ns) + prepare_cnt * 2 + clk_zero_cnt *
1734379bc100SJani Nikula * 2(in UI) + extra byte count
1735379bc100SJani Nikula * In byteclks = (4TLPX + prepare_cnt * 2 + clk_zero_cnt *2 (in UI)) /
1736379bc100SJani Nikula * 8 + extra byte count
1737379bc100SJani Nikula */
1738379bc100SJani Nikula intel_dsi->clk_lp_to_hs_count =
1739379bc100SJani Nikula DIV_ROUND_UP(
1740379bc100SJani Nikula 4 * tlpx_ui + prepare_cnt * 2 +
1741379bc100SJani Nikula clk_zero_cnt * 2,
1742379bc100SJani Nikula 8);
1743379bc100SJani Nikula
1744379bc100SJani Nikula intel_dsi->clk_lp_to_hs_count += extra_byte_count;
1745379bc100SJani Nikula
1746379bc100SJani Nikula /* HS->LP for Clock Lanes
1747379bc100SJani Nikula * Low Power clock synchronisations + 1Tx byteclk + tclk_trail +
1748379bc100SJani Nikula * Extra byte count
1749379bc100SJani Nikula * 2TLPX + 8UI + (trail_count*2)(in UI) + Extra byte count
1750379bc100SJani Nikula * In byteclks = (2*TLpx(in UI) + trail_count*2 +8)(in UI)/8 +
1751379bc100SJani Nikula * Extra byte count
1752379bc100SJani Nikula */
1753379bc100SJani Nikula intel_dsi->clk_hs_to_lp_count =
1754379bc100SJani Nikula DIV_ROUND_UP(2 * tlpx_ui + trail_cnt * 2 + 8,
1755379bc100SJani Nikula 8);
1756379bc100SJani Nikula intel_dsi->clk_hs_to_lp_count += extra_byte_count;
1757379bc100SJani Nikula
1758379bc100SJani Nikula intel_dsi_log_params(intel_dsi);
1759379bc100SJani Nikula }
1760379bc100SJani Nikula
1761b07eb15dSHans de Goede typedef void (*vlv_dsi_dmi_quirk_func)(struct intel_dsi *intel_dsi);
1762b07eb15dSHans de Goede
1763b07eb15dSHans de Goede /*
1764b07eb15dSHans de Goede * Vtotal is wrong on the Asus TF103C leading to the last line of the display
1765b07eb15dSHans de Goede * being shown as the first line. The factory installed Android has a hardcoded
1766b07eb15dSHans de Goede * modeline, causing it to not suffer from this BIOS bug.
1767b07eb15dSHans de Goede *
1768b07eb15dSHans de Goede * Original mode: "1280x800": 60 67700 1280 1312 1328 1376 800 808 812 820 0x8 0xa
1769b07eb15dSHans de Goede * Fixed mode: "1280x800": 60 67700 1280 1312 1328 1376 800 808 812 816 0x8 0xa
1770b07eb15dSHans de Goede *
1771b07eb15dSHans de Goede * https://gitlab.freedesktop.org/drm/intel/-/issues/9381
1772b07eb15dSHans de Goede */
vlv_dsi_asus_tf103c_mode_fixup(struct intel_dsi * intel_dsi)1773b07eb15dSHans de Goede static void vlv_dsi_asus_tf103c_mode_fixup(struct intel_dsi *intel_dsi)
1774b07eb15dSHans de Goede {
1775b07eb15dSHans de Goede /* Cast away the const as we want to fixup the mode */
1776b07eb15dSHans de Goede struct drm_display_mode *fixed_mode = (struct drm_display_mode *)
1777b07eb15dSHans de Goede intel_panel_preferred_fixed_mode(intel_dsi->attached_connector);
1778b07eb15dSHans de Goede
1779b07eb15dSHans de Goede if (fixed_mode->vtotal == 820)
1780b07eb15dSHans de Goede fixed_mode->vtotal -= 4;
1781b07eb15dSHans de Goede }
1782b07eb15dSHans de Goede
17832cac4ed9SHans de Goede /*
17842cac4ed9SHans de Goede * On the Lenovo Yoga Tablet 2 830 / 1050 there are 2 problems:
17852cac4ed9SHans de Goede * 1. The I2C MIPI sequence elements reference bus 3. ACPI has I2C1 - I2C7
17862cac4ed9SHans de Goede * which under Linux become bus 0 - 6. And the MIPI sequence reference
17872cac4ed9SHans de Goede * to bus 3 is indented for I2C3 which is bus 2 under Linux.
17882cac4ed9SHans de Goede *
17892cac4ed9SHans de Goede * Note mipi_exec_i2c() cannot just subtract 1 from the bus
17902cac4ed9SHans de Goede * given in the I2C MIPI sequence element. Since on other
17912cac4ed9SHans de Goede * devices the I2C bus-numbers used in the MIPI sequences do
17922cac4ed9SHans de Goede * actually start at 0.
17932cac4ed9SHans de Goede *
17942cac4ed9SHans de Goede * 2. width_/height_mm contain a bogus 192mm x 120mm size. This is
17952cac4ed9SHans de Goede * especially a problem on the 8" 830 version which uses a 10:16
17962cac4ed9SHans de Goede * portrait screen where as the bogus size is 16:10.
17972cac4ed9SHans de Goede *
17982cac4ed9SHans de Goede * https://gitlab.freedesktop.org/drm/intel/-/issues/9379
17992cac4ed9SHans de Goede */
vlv_dsi_lenovo_yoga_tab2_size_fixup(struct intel_dsi * intel_dsi)18002cac4ed9SHans de Goede static void vlv_dsi_lenovo_yoga_tab2_size_fixup(struct intel_dsi *intel_dsi)
18012cac4ed9SHans de Goede {
18022cac4ed9SHans de Goede const struct drm_display_mode *fixed_mode =
18032cac4ed9SHans de Goede intel_panel_preferred_fixed_mode(intel_dsi->attached_connector);
18042cac4ed9SHans de Goede struct drm_display_info *info = &intel_dsi->attached_connector->base.display_info;
18052cac4ed9SHans de Goede
18062cac4ed9SHans de Goede intel_dsi->i2c_bus_num = 2;
18072cac4ed9SHans de Goede
18082cac4ed9SHans de Goede /*
18092cac4ed9SHans de Goede * The 10" 1050 uses a 1920x1200 landscape screen, where as the 8" 830
18102cac4ed9SHans de Goede * uses a 1200x1920 portrait screen.
18112cac4ed9SHans de Goede */
18122cac4ed9SHans de Goede if (fixed_mode->hdisplay == 1920) {
18132cac4ed9SHans de Goede info->width_mm = 216;
18142cac4ed9SHans de Goede info->height_mm = 135;
18152cac4ed9SHans de Goede } else {
18162cac4ed9SHans de Goede info->width_mm = 107;
18172cac4ed9SHans de Goede info->height_mm = 171;
18182cac4ed9SHans de Goede }
18192cac4ed9SHans de Goede }
18202cac4ed9SHans de Goede
1821f6f4a086SHans de Goede /*
1822f6f4a086SHans de Goede * On the Lenovo Yoga Tab 3 Pro YT3-X90F there are 2 problems:
1823f6f4a086SHans de Goede * 1. i2c_acpi_find_adapter() picks the wrong adapter causing mipi_exec_i2c()
1824f6f4a086SHans de Goede * to not work. Fix this by setting i2c_bus_num.
1825f6f4a086SHans de Goede * 2. There is no backlight off MIPI sequence, causing the backlight to stay on.
1826f6f4a086SHans de Goede * Add a backlight off sequence mirroring the existing backlight on sequence.
1827f6f4a086SHans de Goede *
1828f6f4a086SHans de Goede * https://gitlab.freedesktop.org/drm/intel/-/issues/9380
1829f6f4a086SHans de Goede */
vlv_dsi_lenovo_yoga_tab3_backlight_fixup(struct intel_dsi * intel_dsi)1830f6f4a086SHans de Goede static void vlv_dsi_lenovo_yoga_tab3_backlight_fixup(struct intel_dsi *intel_dsi)
1831f6f4a086SHans de Goede {
1832f6f4a086SHans de Goede static const u8 backlight_off_sequence[16] = {
1833f6f4a086SHans de Goede /* Header Seq-id 7, length after header 11 bytes */
1834f6f4a086SHans de Goede 0x07, 0x0b, 0x00, 0x00, 0x00,
1835f6f4a086SHans de Goede /* MIPI_SEQ_ELEM_I2C bus 0 addr 0x2c reg 0x00 data-len 1 data 0x00 */
1836f6f4a086SHans de Goede 0x04, 0x08, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x01, 0x00,
1837f6f4a086SHans de Goede /* MIPI_SEQ_ELEM_END */
1838f6f4a086SHans de Goede 0x00
1839f6f4a086SHans de Goede };
1840f6f4a086SHans de Goede struct intel_connector *connector = intel_dsi->attached_connector;
1841f6f4a086SHans de Goede
1842f6f4a086SHans de Goede intel_dsi->i2c_bus_num = 0;
1843f6f4a086SHans de Goede connector->panel.vbt.dsi.sequence[MIPI_SEQ_BACKLIGHT_OFF] = backlight_off_sequence;
1844f6f4a086SHans de Goede }
1845f6f4a086SHans de Goede
1846b07eb15dSHans de Goede static const struct dmi_system_id vlv_dsi_dmi_quirk_table[] = {
1847b07eb15dSHans de Goede {
1848b07eb15dSHans de Goede /* Asus Transformer Pad TF103C */
1849b07eb15dSHans de Goede .matches = {
1850b07eb15dSHans de Goede DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
1851b07eb15dSHans de Goede DMI_MATCH(DMI_PRODUCT_NAME, "TF103C"),
1852b07eb15dSHans de Goede },
1853b07eb15dSHans de Goede .driver_data = (void *)vlv_dsi_asus_tf103c_mode_fixup,
1854b07eb15dSHans de Goede },
18552cac4ed9SHans de Goede {
18562cac4ed9SHans de Goede /*
18572cac4ed9SHans de Goede * Lenovo Yoga Tablet 2 830F/L or 1050F/L (The 8" and 10"
18582cac4ed9SHans de Goede * Lenovo Yoga Tablet 2 use the same mainboard)
18592cac4ed9SHans de Goede */
18602cac4ed9SHans de Goede .matches = {
18612cac4ed9SHans de Goede DMI_MATCH(DMI_SYS_VENDOR, "Intel Corp."),
18622cac4ed9SHans de Goede DMI_MATCH(DMI_PRODUCT_NAME, "VALLEYVIEW C0 PLATFORM"),
18632cac4ed9SHans de Goede DMI_MATCH(DMI_BOARD_NAME, "BYT-T FFD8"),
18642cac4ed9SHans de Goede /* Partial match on beginning of BIOS version */
18652cac4ed9SHans de Goede DMI_MATCH(DMI_BIOS_VERSION, "BLADE_21"),
18662cac4ed9SHans de Goede },
18672cac4ed9SHans de Goede .driver_data = (void *)vlv_dsi_lenovo_yoga_tab2_size_fixup,
18682cac4ed9SHans de Goede },
1869f6f4a086SHans de Goede {
1870f6f4a086SHans de Goede /* Lenovo Yoga Tab 3 Pro YT3-X90F */
1871f6f4a086SHans de Goede .matches = {
1872f6f4a086SHans de Goede DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
1873f6f4a086SHans de Goede DMI_MATCH(DMI_PRODUCT_VERSION, "Blade3-10A-001"),
1874f6f4a086SHans de Goede },
1875f6f4a086SHans de Goede .driver_data = (void *)vlv_dsi_lenovo_yoga_tab3_backlight_fixup,
1876f6f4a086SHans de Goede },
1877b07eb15dSHans de Goede { }
1878b07eb15dSHans de Goede };
1879b07eb15dSHans de Goede
vlv_dsi_init(struct drm_i915_private * dev_priv)1880379bc100SJani Nikula void vlv_dsi_init(struct drm_i915_private *dev_priv)
1881379bc100SJani Nikula {
1882379bc100SJani Nikula struct intel_display *display = &dev_priv->display;
18834cfff967SJani Nikula struct intel_dsi *intel_dsi;
18844cfff967SJani Nikula struct intel_encoder *encoder;
1885db10c14aSVille Syrjälä struct intel_connector *connector;
1886b07eb15dSHans de Goede struct drm_display_mode *current_mode;
1887379bc100SJani Nikula const struct dmi_system_id *dmi_id;
18886c0a878eSHans de Goede enum port port;
1889379bc100SJani Nikula enum pipe pipe;
1890f1f76d7aSWambui Karuga
1891379bc100SJani Nikula drm_dbg_kms(&dev_priv->drm, "\n");
1892379bc100SJani Nikula
1893379bc100SJani Nikula /* There is no detection method for MIPI so rely on VBT */
1894379bc100SJani Nikula if (!intel_bios_is_dsi_present(display, &port))
1895379bc100SJani Nikula return;
189670bfb307SMatt Roper
189790b87cf2SJani Nikula if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
1898379bc100SJani Nikula dev_priv->display.dsi.mmio_base = BXT_MIPI_BASE;
189990b87cf2SJani Nikula else
1900379bc100SJani Nikula dev_priv->display.dsi.mmio_base = VLV_MIPI_BASE;
1901379bc100SJani Nikula
1902379bc100SJani Nikula intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
1903379bc100SJani Nikula if (!intel_dsi)
1904379bc100SJani Nikula return;
19054cfff967SJani Nikula
19064cfff967SJani Nikula connector = intel_connector_alloc();
1907379bc100SJani Nikula if (!connector) {
1908379bc100SJani Nikula kfree(intel_dsi);
1909379bc100SJani Nikula return;
1910379bc100SJani Nikula }
19114cfff967SJani Nikula
19124cfff967SJani Nikula encoder = &intel_dsi->base;
1913379bc100SJani Nikula intel_dsi->attached_connector = connector;
19144cfff967SJani Nikula
19154cfff967SJani Nikula drm_encoder_init(&dev_priv->drm, &encoder->base, &intel_dsi_funcs,
1916379bc100SJani Nikula DRM_MODE_ENCODER_DSI, "DSI %c", port_name(port));
19174cfff967SJani Nikula
19184cfff967SJani Nikula encoder->compute_config = intel_dsi_compute_config;
191970bfb307SMatt Roper encoder->pre_enable = intel_dsi_pre_enable;
19204cfff967SJani Nikula if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
19214cfff967SJani Nikula encoder->enable = bxt_dsi_enable;
19224cfff967SJani Nikula encoder->disable = intel_dsi_disable;
19234cfff967SJani Nikula encoder->post_disable = intel_dsi_post_disable;
19244cfff967SJani Nikula encoder->get_hw_state = intel_dsi_get_hw_state;
19254cfff967SJani Nikula encoder->get_config = intel_dsi_get_config;
19264cfff967SJani Nikula encoder->update_pipe = intel_backlight_update;
1927379bc100SJani Nikula encoder->shutdown = intel_dsi_shutdown;
19284cfff967SJani Nikula
1929379bc100SJani Nikula connector->get_hw_state = intel_connector_get_hw_state;
19304cfff967SJani Nikula
19314cfff967SJani Nikula encoder->port = port;
19324cfff967SJani Nikula encoder->type = INTEL_OUTPUT_DSI;
19334cfff967SJani Nikula encoder->power_domain = POWER_DOMAIN_PORT_DSI;
1934379bc100SJani Nikula encoder->cloneable = 0;
1935379bc100SJani Nikula
1936379bc100SJani Nikula /*
1937379bc100SJani Nikula * On BYT/CHV, pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI
1938379bc100SJani Nikula * port C. BXT isn't limited like this.
193970bfb307SMatt Roper */
19404cfff967SJani Nikula if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
1941379bc100SJani Nikula encoder->pipe_mask = ~0;
19424cfff967SJani Nikula else if (port == PORT_A)
1943379bc100SJani Nikula encoder->pipe_mask = BIT(PIPE_A);
19444cfff967SJani Nikula else
1945379bc100SJani Nikula encoder->pipe_mask = BIT(PIPE_B);
1946c87eba80SHans de Goede
1947c87eba80SHans de Goede intel_dsi->panel_power_off_time = ktime_get_boottime();
19484cfff967SJani Nikula
19493cf05076SVille Syrjälä intel_bios_init_panel_late(display, &connector->panel, NULL, NULL);
19504cfff967SJani Nikula
1951379bc100SJani Nikula if (connector->panel.vbt.dsi.config->dual_link)
1952379bc100SJani Nikula intel_dsi->ports = BIT(PORT_A) | BIT(PORT_C);
1953379bc100SJani Nikula else
1954379bc100SJani Nikula intel_dsi->ports = BIT(port);
19554cfff967SJani Nikula
19564cfff967SJani Nikula if (drm_WARN_ON(&dev_priv->drm, connector->panel.vbt.dsi.bl_ports & ~intel_dsi->ports))
1957f4a6c7a4SJani Nikula connector->panel.vbt.dsi.bl_ports &= intel_dsi->ports;
19584cfff967SJani Nikula
19594cfff967SJani Nikula if (drm_WARN_ON(&dev_priv->drm, connector->panel.vbt.dsi.cabc_ports & ~intel_dsi->ports))
1960f4a6c7a4SJani Nikula connector->panel.vbt.dsi.cabc_ports &= intel_dsi->ports;
1961379bc100SJani Nikula
1962379bc100SJani Nikula /* Create a DSI host (and a device) for each port. */
1963379bc100SJani Nikula for_each_dsi_port(port, intel_dsi->ports) {
1964379bc100SJani Nikula struct intel_dsi_host *host;
1965379bc100SJani Nikula
1966379bc100SJani Nikula host = intel_dsi_host_init(intel_dsi, &intel_dsi_host_ops,
1967379bc100SJani Nikula port);
1968379bc100SJani Nikula if (!host)
1969379bc100SJani Nikula goto err;
1970379bc100SJani Nikula
1971379bc100SJani Nikula intel_dsi->dsi_hosts[port] = host;
1972379bc100SJani Nikula }
1973379bc100SJani Nikula
1974f1f76d7aSWambui Karuga if (!intel_dsi_vbt_init(intel_dsi, MIPI_DSI_GENERIC_PANEL_ID)) {
1975379bc100SJani Nikula drm_dbg_kms(&dev_priv->drm, "no device found\n");
1976379bc100SJani Nikula goto err;
1977379bc100SJani Nikula }
1978379bc100SJani Nikula
19794cfff967SJani Nikula /* Use clock read-back from current hw-state for fastboot */
1980379bc100SJani Nikula current_mode = intel_encoder_current_mode(encoder);
1981f1f76d7aSWambui Karuga if (current_mode) {
1982379bc100SJani Nikula drm_dbg_kms(&dev_priv->drm, "Calculated pclk %d GOP %d\n",
1983379bc100SJani Nikula intel_dsi->pclk, current_mode->clock);
1984379bc100SJani Nikula if (intel_fuzzy_clock_check(intel_dsi->pclk,
1985f1f76d7aSWambui Karuga current_mode->clock)) {
1986379bc100SJani Nikula drm_dbg_kms(&dev_priv->drm, "Using GOP pclk\n");
1987379bc100SJani Nikula intel_dsi->pclk = current_mode->clock;
1988379bc100SJani Nikula }
1989379bc100SJani Nikula
1990379bc100SJani Nikula kfree(current_mode);
1991379bc100SJani Nikula }
1992379bc100SJani Nikula
1993379bc100SJani Nikula vlv_dphy_param_init(intel_dsi);
19946c0a878eSHans de Goede
19954cfff967SJani Nikula intel_dsi_vbt_gpio_init(intel_dsi,
1996379bc100SJani Nikula intel_dsi_get_hw_state(encoder, &pipe));
19974cfff967SJani Nikula
1998379bc100SJani Nikula drm_connector_init(&dev_priv->drm, &connector->base, &intel_dsi_connector_funcs,
1999379bc100SJani Nikula DRM_MODE_CONNECTOR_DSI);
20004cfff967SJani Nikula
2001379bc100SJani Nikula drm_connector_helper_add(&connector->base, &intel_dsi_connector_helper_funcs);
20024cfff967SJani Nikula
2003379bc100SJani Nikula connector->base.display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
20044cfff967SJani Nikula
2005379bc100SJani Nikula intel_connector_attach_encoder(connector, encoder);
20063703060dSAndrzej Hajda
20074cfff967SJani Nikula mutex_lock(&dev_priv->drm.mode_config.mutex);
20083703060dSAndrzej Hajda intel_panel_add_vbt_lfp_fixed_mode(connector);
2009379bc100SJani Nikula mutex_unlock(&dev_priv->drm.mode_config.mutex);
20104cfff967SJani Nikula
2011f1f76d7aSWambui Karuga if (!intel_panel_preferred_fixed_mode(connector)) {
2012379bc100SJani Nikula drm_dbg_kms(&dev_priv->drm, "no fixed mode\n");
2013379bc100SJani Nikula goto err_cleanup_connector;
2014379bc100SJani Nikula }
2015b07eb15dSHans de Goede
2016b07eb15dSHans de Goede dmi_id = dmi_first_match(vlv_dsi_dmi_quirk_table);
2017b07eb15dSHans de Goede if (dmi_id) {
2018b07eb15dSHans de Goede vlv_dsi_dmi_quirk_func quirk_func =
2019b07eb15dSHans de Goede (vlv_dsi_dmi_quirk_func)dmi_id->driver_data;
2020b07eb15dSHans de Goede
2021b07eb15dSHans de Goede quirk_func(intel_dsi);
2022b07eb15dSHans de Goede }
20234cfff967SJani Nikula
2024db10c14aSVille Syrjälä intel_panel_init(connector, NULL);
20254cfff967SJani Nikula
2026379bc100SJani Nikula intel_backlight_setup(connector, INVALID_PIPE);
20274cfff967SJani Nikula
2028379bc100SJani Nikula vlv_dsi_add_properties(connector);
2029379bc100SJani Nikula
2030379bc100SJani Nikula return;
2031379bc100SJani Nikula
20324cfff967SJani Nikula err_cleanup_connector:
2033379bc100SJani Nikula drm_connector_cleanup(&connector->base);
20344cfff967SJani Nikula err:
2035379bc100SJani Nikula drm_encoder_cleanup(&encoder->base);
20364cfff967SJani Nikula kfree(intel_dsi);
2037379bc100SJani Nikula kfree(connector);
2038 }
2039