drm: Pass 'name' to drm_encoder_init()
[deliverable/linux.git] / drivers / gpu / drm / i915 / intel_dsi.c
CommitLineData
4e646495
JN
1/*
2 * Copyright © 2013 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Author: Jani Nikula <jani.nikula@intel.com>
24 */
25
26#include <drm/drmP.h>
c6f95f27 27#include <drm/drm_atomic_helper.h>
4e646495
JN
28#include <drm/drm_crtc.h>
29#include <drm/drm_edid.h>
30#include <drm/i915_drm.h>
593e0622 31#include <drm/drm_panel.h>
7e9804fd 32#include <drm/drm_mipi_dsi.h>
4e646495 33#include <linux/slab.h>
fc45e821 34#include <linux/gpio/consumer.h>
4e646495
JN
35#include "i915_drv.h"
36#include "intel_drv.h"
37#include "intel_dsi.h"
4e646495 38
593e0622
JN
39static const struct {
40 u16 panel_id;
41 struct drm_panel * (*init)(struct intel_dsi *intel_dsi, u16 panel_id);
42} intel_dsi_drivers[] = {
2ab8b458
SK
43 {
44 .panel_id = MIPI_DSI_GENERIC_PANEL_ID,
593e0622 45 .init = vbt_panel_init,
2ab8b458 46 },
4e646495
JN
47};
48
7f6a6a4a 49static void wait_for_dsi_fifo_empty(struct intel_dsi *intel_dsi, enum port port)
3b1808bf
JN
50{
51 struct drm_encoder *encoder = &intel_dsi->base.base;
52 struct drm_device *dev = encoder->dev;
53 struct drm_i915_private *dev_priv = dev->dev_private;
3b1808bf
JN
54 u32 mask;
55
56 mask = LP_CTRL_FIFO_EMPTY | HS_CTRL_FIFO_EMPTY |
57 LP_DATA_FIFO_EMPTY | HS_DATA_FIFO_EMPTY;
58
59 if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & mask) == mask, 100))
60 DRM_ERROR("DPI FIFOs are not empty\n");
61}
62
f0f59a00
VS
63static void write_data(struct drm_i915_private *dev_priv,
64 i915_reg_t reg,
7e9804fd
JN
65 const u8 *data, u32 len)
66{
67 u32 i, j;
68
69 for (i = 0; i < len; i += 4) {
70 u32 val = 0;
71
72 for (j = 0; j < min_t(u32, len - i, 4); j++)
73 val |= *data++ << 8 * j;
74
75 I915_WRITE(reg, val);
76 }
77}
78
f0f59a00
VS
79static void read_data(struct drm_i915_private *dev_priv,
80 i915_reg_t reg,
7e9804fd
JN
81 u8 *data, u32 len)
82{
83 u32 i, j;
84
85 for (i = 0; i < len; i += 4) {
86 u32 val = I915_READ(reg);
87
88 for (j = 0; j < min_t(u32, len - i, 4); j++)
89 *data++ = val >> 8 * j;
90 }
91}
92
93static ssize_t intel_dsi_host_transfer(struct mipi_dsi_host *host,
94 const struct mipi_dsi_msg *msg)
95{
96 struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host);
97 struct drm_device *dev = intel_dsi_host->intel_dsi->base.base.dev;
98 struct drm_i915_private *dev_priv = dev->dev_private;
99 enum port port = intel_dsi_host->port;
100 struct mipi_dsi_packet packet;
101 ssize_t ret;
102 const u8 *header, *data;
f0f59a00
VS
103 i915_reg_t data_reg, ctrl_reg;
104 u32 data_mask, ctrl_mask;
7e9804fd
JN
105
106 ret = mipi_dsi_create_packet(&packet, msg);
107 if (ret < 0)
108 return ret;
109
110 header = packet.header;
111 data = packet.payload;
112
113 if (msg->flags & MIPI_DSI_MSG_USE_LPM) {
114 data_reg = MIPI_LP_GEN_DATA(port);
115 data_mask = LP_DATA_FIFO_FULL;
116 ctrl_reg = MIPI_LP_GEN_CTRL(port);
117 ctrl_mask = LP_CTRL_FIFO_FULL;
118 } else {
119 data_reg = MIPI_HS_GEN_DATA(port);
120 data_mask = HS_DATA_FIFO_FULL;
121 ctrl_reg = MIPI_HS_GEN_CTRL(port);
122 ctrl_mask = HS_CTRL_FIFO_FULL;
123 }
124
125 /* note: this is never true for reads */
126 if (packet.payload_length) {
127
128 if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & data_mask) == 0, 50))
129 DRM_ERROR("Timeout waiting for HS/LP DATA FIFO !full\n");
130
131 write_data(dev_priv, data_reg, packet.payload,
132 packet.payload_length);
133 }
134
135 if (msg->rx_len) {
136 I915_WRITE(MIPI_INTR_STAT(port), GEN_READ_DATA_AVAIL);
137 }
138
139 if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & ctrl_mask) == 0, 50)) {
140 DRM_ERROR("Timeout waiting for HS/LP CTRL FIFO !full\n");
141 }
142
143 I915_WRITE(ctrl_reg, header[2] << 16 | header[1] << 8 | header[0]);
144
145 /* ->rx_len is set only for reads */
146 if (msg->rx_len) {
147 data_mask = GEN_READ_DATA_AVAIL;
148 if (wait_for((I915_READ(MIPI_INTR_STAT(port)) & data_mask) == data_mask, 50))
149 DRM_ERROR("Timeout waiting for read data.\n");
150
151 read_data(dev_priv, data_reg, msg->rx_buf, msg->rx_len);
152 }
153
154 /* XXX: fix for reads and writes */
155 return 4 + packet.payload_length;
156}
157
158static int intel_dsi_host_attach(struct mipi_dsi_host *host,
159 struct mipi_dsi_device *dsi)
160{
161 return 0;
162}
163
164static int intel_dsi_host_detach(struct mipi_dsi_host *host,
165 struct mipi_dsi_device *dsi)
166{
167 return 0;
168}
169
170static const struct mipi_dsi_host_ops intel_dsi_host_ops = {
171 .attach = intel_dsi_host_attach,
172 .detach = intel_dsi_host_detach,
173 .transfer = intel_dsi_host_transfer,
174};
175
176static struct intel_dsi_host *intel_dsi_host_init(struct intel_dsi *intel_dsi,
177 enum port port)
178{
179 struct intel_dsi_host *host;
180 struct mipi_dsi_device *device;
181
182 host = kzalloc(sizeof(*host), GFP_KERNEL);
183 if (!host)
184 return NULL;
185
186 host->base.ops = &intel_dsi_host_ops;
187 host->intel_dsi = intel_dsi;
188 host->port = port;
189
190 /*
191 * We should call mipi_dsi_host_register(&host->base) here, but we don't
192 * have a host->dev, and we don't have OF stuff either. So just use the
193 * dsi framework as a library and hope for the best. Create the dsi
194 * devices by ourselves here too. Need to be careful though, because we
195 * don't initialize any of the driver model devices here.
196 */
197 device = kzalloc(sizeof(*device), GFP_KERNEL);
198 if (!device) {
199 kfree(host);
200 return NULL;
201 }
202
203 device->host = &host->base;
204 host->device = device;
205
206 return host;
207}
208
a2581a9e
JN
209/*
210 * send a video mode command
211 *
212 * XXX: commands with data in MIPI_DPI_DATA?
213 */
214static int dpi_send_cmd(struct intel_dsi *intel_dsi, u32 cmd, bool hs,
215 enum port port)
216{
217 struct drm_encoder *encoder = &intel_dsi->base.base;
218 struct drm_device *dev = encoder->dev;
219 struct drm_i915_private *dev_priv = dev->dev_private;
220 u32 mask;
221
222 /* XXX: pipe, hs */
223 if (hs)
224 cmd &= ~DPI_LP_MODE;
225 else
226 cmd |= DPI_LP_MODE;
227
228 /* clear bit */
229 I915_WRITE(MIPI_INTR_STAT(port), SPL_PKT_SENT_INTERRUPT);
230
231 /* XXX: old code skips write if control unchanged */
232 if (cmd == I915_READ(MIPI_DPI_CONTROL(port)))
233 DRM_ERROR("Same special packet %02x twice in a row.\n", cmd);
234
235 I915_WRITE(MIPI_DPI_CONTROL(port), cmd);
236
237 mask = SPL_PKT_SENT_INTERRUPT;
238 if (wait_for((I915_READ(MIPI_INTR_STAT(port)) & mask) == mask, 100))
239 DRM_ERROR("Video mode command 0x%08x send failed.\n", cmd);
240
241 return 0;
242}
243
e9fe51c6 244static void band_gap_reset(struct drm_i915_private *dev_priv)
4ce8c9a7 245{
a580516d 246 mutex_lock(&dev_priv->sb_lock);
4ce8c9a7 247
e9fe51c6
SK
248 vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
249 vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
250 vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
251 udelay(150);
252 vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
253 vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
4ce8c9a7 254
a580516d 255 mutex_unlock(&dev_priv->sb_lock);
4ce8c9a7
SK
256}
257
4e646495
JN
258static inline bool is_vid_mode(struct intel_dsi *intel_dsi)
259{
dfba2e2d 260 return intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE;
4e646495
JN
261}
262
263static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
264{
dfba2e2d 265 return intel_dsi->operation_mode == INTEL_DSI_COMMAND_MODE;
4e646495
JN
266}
267
4e646495 268static bool intel_dsi_compute_config(struct intel_encoder *encoder,
5cec258b 269 struct intel_crtc_state *config)
4e646495
JN
270{
271 struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
272 base);
273 struct intel_connector *intel_connector = intel_dsi->attached_connector;
274 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
2d112de7 275 struct drm_display_mode *adjusted_mode = &config->base.adjusted_mode;
4e646495
JN
276
277 DRM_DEBUG_KMS("\n");
278
279 if (fixed_mode)
280 intel_fixed_panel_mode(fixed_mode, adjusted_mode);
281
f573de5a
SK
282 /* DSI uses short packets for sync events, so clear mode flags for DSI */
283 adjusted_mode->flags = 0;
284
4e646495
JN
285 return true;
286}
287
37ab0810 288static void bxt_dsi_device_ready(struct intel_encoder *encoder)
5505a244 289{
37ab0810 290 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
5505a244 291 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
369602d3 292 enum port port;
37ab0810 293 u32 val;
5505a244 294
37ab0810 295 DRM_DEBUG_KMS("\n");
a9da9bce 296
37ab0810 297 /* Exit Low power state in 4 steps*/
369602d3 298 for_each_dsi_port(port, intel_dsi->ports) {
5505a244 299
37ab0810
SS
300 /* 1. Enable MIPI PHY transparent latch */
301 val = I915_READ(BXT_MIPI_PORT_CTRL(port));
302 I915_WRITE(BXT_MIPI_PORT_CTRL(port), val | LP_OUTPUT_HOLD);
303 usleep_range(2000, 2500);
304
305 /* 2. Enter ULPS */
306 val = I915_READ(MIPI_DEVICE_READY(port));
307 val &= ~ULPS_STATE_MASK;
308 val |= (ULPS_STATE_ENTER | DEVICE_READY);
309 I915_WRITE(MIPI_DEVICE_READY(port), val);
310 usleep_range(2, 3);
311
312 /* 3. Exit ULPS */
313 val = I915_READ(MIPI_DEVICE_READY(port));
314 val &= ~ULPS_STATE_MASK;
315 val |= (ULPS_STATE_EXIT | DEVICE_READY);
316 I915_WRITE(MIPI_DEVICE_READY(port), val);
317 usleep_range(1000, 1500);
5505a244 318
37ab0810
SS
319 /* Clear ULPS and set device ready */
320 val = I915_READ(MIPI_DEVICE_READY(port));
321 val &= ~ULPS_STATE_MASK;
322 val |= DEVICE_READY;
323 I915_WRITE(MIPI_DEVICE_READY(port), val);
369602d3 324 }
5505a244
GS
325}
326
37ab0810 327static void vlv_dsi_device_ready(struct intel_encoder *encoder)
4e646495 328{
1dbd7cb2 329 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
24ee0e64
GS
330 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
331 enum port port;
1dbd7cb2
SK
332 u32 val;
333
4e646495 334 DRM_DEBUG_KMS("\n");
4e646495 335
a580516d 336 mutex_lock(&dev_priv->sb_lock);
2095f9fc
SK
337 /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
338 * needed everytime after power gate */
339 vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
a580516d 340 mutex_unlock(&dev_priv->sb_lock);
2095f9fc
SK
341
342 /* bandgap reset is needed after everytime we do power gate */
343 band_gap_reset(dev_priv);
344
24ee0e64 345 for_each_dsi_port(port, intel_dsi->ports) {
aceb365c 346
24ee0e64
GS
347 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
348 usleep_range(2500, 3000);
aceb365c 349
bf344e80
GS
350 /* Enable MIPI PHY transparent latch
351 * Common bit for both MIPI Port A & MIPI Port C
352 * No similar bit in MIPI Port C reg
353 */
4ba7d93a 354 val = I915_READ(MIPI_PORT_CTRL(PORT_A));
bf344e80 355 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD);
24ee0e64 356 usleep_range(1000, 1500);
aceb365c 357
24ee0e64
GS
358 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
359 usleep_range(2500, 3000);
360
361 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
362 usleep_range(2500, 3000);
363 }
1dbd7cb2 364}
1dbd7cb2 365
37ab0810
SS
366static void intel_dsi_device_ready(struct intel_encoder *encoder)
367{
368 struct drm_device *dev = encoder->base.dev;
369
370 if (IS_VALLEYVIEW(dev))
371 vlv_dsi_device_ready(encoder);
372 else if (IS_BROXTON(dev))
373 bxt_dsi_device_ready(encoder);
374}
375
376static void intel_dsi_port_enable(struct intel_encoder *encoder)
377{
378 struct drm_device *dev = encoder->base.dev;
379 struct drm_i915_private *dev_priv = dev->dev_private;
380 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
381 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
382 enum port port;
37ab0810
SS
383
384 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
f0f59a00
VS
385 u32 temp;
386
37ab0810
SS
387 temp = I915_READ(VLV_CHICKEN_3);
388 temp &= ~PIXEL_OVERLAP_CNT_MASK |
389 intel_dsi->pixel_overlap <<
390 PIXEL_OVERLAP_CNT_SHIFT;
391 I915_WRITE(VLV_CHICKEN_3, temp);
392 }
393
394 for_each_dsi_port(port, intel_dsi->ports) {
f0f59a00
VS
395 i915_reg_t port_ctrl = IS_BROXTON(dev) ?
396 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
397 u32 temp;
37ab0810
SS
398
399 temp = I915_READ(port_ctrl);
400
401 temp &= ~LANE_CONFIGURATION_MASK;
402 temp &= ~DUAL_LINK_MODE_MASK;
403
404 if (intel_dsi->ports == ((1 << PORT_A) | (1 << PORT_C))) {
405 temp |= (intel_dsi->dual_link - 1)
406 << DUAL_LINK_MODE_SHIFT;
407 temp |= intel_crtc->pipe ?
408 LANE_CONFIGURATION_DUAL_LINK_B :
409 LANE_CONFIGURATION_DUAL_LINK_A;
410 }
411 /* assert ip_tg_enable signal */
412 I915_WRITE(port_ctrl, temp | DPI_ENABLE);
413 POSTING_READ(port_ctrl);
414 }
415}
416
417static void intel_dsi_port_disable(struct intel_encoder *encoder)
418{
419 struct drm_device *dev = encoder->base.dev;
420 struct drm_i915_private *dev_priv = dev->dev_private;
421 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
422 enum port port;
37ab0810
SS
423
424 for_each_dsi_port(port, intel_dsi->ports) {
f0f59a00
VS
425 i915_reg_t port_ctrl = IS_BROXTON(dev) ?
426 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
427 u32 temp;
428
37ab0810 429 /* de-assert ip_tg_enable signal */
b389a45c
SS
430 temp = I915_READ(port_ctrl);
431 I915_WRITE(port_ctrl, temp & ~DPI_ENABLE);
432 POSTING_READ(port_ctrl);
37ab0810
SS
433 }
434}
435
1dbd7cb2
SK
436static void intel_dsi_enable(struct intel_encoder *encoder)
437{
438 struct drm_device *dev = encoder->base.dev;
439 struct drm_i915_private *dev_priv = dev->dev_private;
1dbd7cb2 440 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
4934b656 441 enum port port;
1dbd7cb2
SK
442
443 DRM_DEBUG_KMS("\n");
b9f5e07d 444
4934b656
JN
445 if (is_cmd_mode(intel_dsi)) {
446 for_each_dsi_port(port, intel_dsi->ports)
447 I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
448 } else {
4e646495 449 msleep(20); /* XXX */
f03e4179 450 for_each_dsi_port(port, intel_dsi->ports)
a2581a9e 451 dpi_send_cmd(intel_dsi, TURN_ON, false, port);
4e646495
JN
452 msleep(100);
453
593e0622 454 drm_panel_enable(intel_dsi->panel);
2634fd7f 455
7f6a6a4a
JN
456 for_each_dsi_port(port, intel_dsi->ports)
457 wait_for_dsi_fifo_empty(intel_dsi, port);
1381308b 458
5505a244 459 intel_dsi_port_enable(encoder);
4e646495 460 }
b029e66f
SK
461
462 intel_panel_enable_backlight(intel_dsi->attached_connector);
2634fd7f
SK
463}
464
465static void intel_dsi_pre_enable(struct intel_encoder *encoder)
466{
20e5bf66
SK
467 struct drm_device *dev = encoder->base.dev;
468 struct drm_i915_private *dev_priv = dev->dev_private;
2634fd7f 469 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
20e5bf66
SK
470 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
471 enum pipe pipe = intel_crtc->pipe;
7f6a6a4a 472 enum port port;
20e5bf66 473 u32 tmp;
2634fd7f
SK
474
475 DRM_DEBUG_KMS("\n");
476
fc45e821
SK
477 /* Panel Enable over CRC PMIC */
478 if (intel_dsi->gpio_panel)
479 gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1);
480
481 msleep(intel_dsi->panel_on_delay);
482
37ab0810
SS
483 if (IS_VALLEYVIEW(dev)) {
484 /*
485 * Disable DPOunit clock gating, can stall pipe
486 * and we need DPLL REFA always enabled
487 */
488 tmp = I915_READ(DPLL(pipe));
489 tmp |= DPLL_REF_CLK_ENABLE_VLV;
490 I915_WRITE(DPLL(pipe), tmp);
491
492 /* update the hw state for DPLL */
493 intel_crtc->config->dpll_hw_state.dpll =
494 DPLL_INTEGRATED_REF_CLK_VLV |
495 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
496
497 tmp = I915_READ(DSPCLK_GATE_D);
498 tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
499 I915_WRITE(DSPCLK_GATE_D, tmp);
500 }
2634fd7f
SK
501
502 /* put device in ready state */
503 intel_dsi_device_ready(encoder);
4e646495 504
593e0622 505 drm_panel_prepare(intel_dsi->panel);
20e5bf66 506
7f6a6a4a
JN
507 for_each_dsi_port(port, intel_dsi->ports)
508 wait_for_dsi_fifo_empty(intel_dsi, port);
1381308b 509
2634fd7f
SK
510 /* Enable port in pre-enable phase itself because as per hw team
511 * recommendation, port should be enabled befor plane & pipe */
512 intel_dsi_enable(encoder);
513}
514
515static void intel_dsi_enable_nop(struct intel_encoder *encoder)
516{
517 DRM_DEBUG_KMS("\n");
518
519 /* for DSI port enable has to be done before pipe
520 * and plane enable, so port enable is done in
521 * pre_enable phase itself unlike other encoders
522 */
4e646495
JN
523}
524
c315faf8
ID
525static void intel_dsi_pre_disable(struct intel_encoder *encoder)
526{
527 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
f03e4179 528 enum port port;
c315faf8
ID
529
530 DRM_DEBUG_KMS("\n");
531
b029e66f
SK
532 intel_panel_disable_backlight(intel_dsi->attached_connector);
533
c315faf8
ID
534 if (is_vid_mode(intel_dsi)) {
535 /* Send Shutdown command to the panel in LP mode */
f03e4179 536 for_each_dsi_port(port, intel_dsi->ports)
a2581a9e 537 dpi_send_cmd(intel_dsi, SHUTDOWN, false, port);
c315faf8
ID
538 msleep(10);
539 }
540}
541
4e646495
JN
542static void intel_dsi_disable(struct intel_encoder *encoder)
543{
1dbd7cb2
SK
544 struct drm_device *dev = encoder->base.dev;
545 struct drm_i915_private *dev_priv = dev->dev_private;
4e646495 546 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
384f02a2 547 enum port port;
4e646495
JN
548 u32 temp;
549
550 DRM_DEBUG_KMS("\n");
551
4e646495 552 if (is_vid_mode(intel_dsi)) {
7f6a6a4a
JN
553 for_each_dsi_port(port, intel_dsi->ports)
554 wait_for_dsi_fifo_empty(intel_dsi, port);
1381308b 555
5505a244 556 intel_dsi_port_disable(encoder);
4e646495
JN
557 msleep(2);
558 }
559
384f02a2
GS
560 for_each_dsi_port(port, intel_dsi->ports) {
561 /* Panel commands can be sent when clock is in LP11 */
562 I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
339023ec 563
b389a45c 564 intel_dsi_reset_clocks(encoder, port);
384f02a2 565 I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
339023ec 566
384f02a2
GS
567 temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
568 temp &= ~VID_MODE_FORMAT_MASK;
569 I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
339023ec 570
384f02a2
GS
571 I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
572 }
1dbd7cb2
SK
573 /* if disable packets are sent before sending shutdown packet then in
574 * some next enable sequence send turn on packet error is observed */
593e0622 575 drm_panel_disable(intel_dsi->panel);
1381308b 576
7f6a6a4a
JN
577 for_each_dsi_port(port, intel_dsi->ports)
578 wait_for_dsi_fifo_empty(intel_dsi, port);
4e646495
JN
579}
580
1dbd7cb2 581static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
4e646495 582{
b389a45c 583 struct drm_device *dev = encoder->base.dev;
1dbd7cb2 584 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
384f02a2
GS
585 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
586 enum port port;
1dbd7cb2 587
4e646495 588 DRM_DEBUG_KMS("\n");
384f02a2 589 for_each_dsi_port(port, intel_dsi->ports) {
f0f59a00
VS
590 /* Common bit for both MIPI Port A & MIPI Port C on VLV/CHV */
591 i915_reg_t port_ctrl = IS_BROXTON(dev) ?
592 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(PORT_A);
593 u32 val;
be4fc046 594
384f02a2
GS
595 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
596 ULPS_STATE_ENTER);
597 usleep_range(2000, 2500);
598
599 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
600 ULPS_STATE_EXIT);
601 usleep_range(2000, 2500);
602
603 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
604 ULPS_STATE_ENTER);
605 usleep_range(2000, 2500);
606
607 /* Wait till Clock lanes are in LP-00 state for MIPI Port A
608 * only. MIPI Port C has no similar bit for checking
609 */
b389a45c
SS
610 if (wait_for(((I915_READ(port_ctrl) & AFE_LATCHOUT)
611 == 0x00000), 30))
384f02a2
GS
612 DRM_ERROR("DSI LP not going Low\n");
613
b389a45c
SS
614 /* Disable MIPI PHY transparent latch */
615 val = I915_READ(port_ctrl);
616 I915_WRITE(port_ctrl, val & ~LP_OUTPUT_HOLD);
384f02a2
GS
617 usleep_range(1000, 1500);
618
619 I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
620 usleep_range(2000, 2500);
621 }
1dbd7cb2 622
fe88fc68 623 intel_disable_dsi_pll(encoder);
4e646495 624}
20e5bf66 625
1dbd7cb2
SK
626static void intel_dsi_post_disable(struct intel_encoder *encoder)
627{
20e5bf66 628 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1dbd7cb2 629 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
20e5bf66 630 u32 val;
1dbd7cb2
SK
631
632 DRM_DEBUG_KMS("\n");
633
c315faf8
ID
634 intel_dsi_disable(encoder);
635
1dbd7cb2
SK
636 intel_dsi_clear_device_ready(encoder);
637
20e5bf66
SK
638 val = I915_READ(DSPCLK_GATE_D);
639 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
640 I915_WRITE(DSPCLK_GATE_D, val);
641
593e0622 642 drm_panel_unprepare(intel_dsi->panel);
df38e655
SK
643
644 msleep(intel_dsi->panel_off_delay);
645 msleep(intel_dsi->panel_pwr_cycle_delay);
fc45e821
SK
646
647 /* Panel Disable over CRC PMIC */
648 if (intel_dsi->gpio_panel)
649 gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0);
1dbd7cb2 650}
4e646495
JN
651
652static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
653 enum pipe *pipe)
654{
655 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
c0beefd2
GS
656 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
657 struct drm_device *dev = encoder->base.dev;
6d129bea 658 enum intel_display_power_domain power_domain;
e7d7cad0 659 enum port port;
4e646495
JN
660
661 DRM_DEBUG_KMS("\n");
662
6d129bea 663 power_domain = intel_display_port_power_domain(encoder);
f458ebbc 664 if (!intel_display_power_is_enabled(dev_priv, power_domain))
6d129bea
ID
665 return false;
666
4e646495 667 /* XXX: this only works for one DSI output */
c0beefd2 668 for_each_dsi_port(port, intel_dsi->ports) {
f0f59a00
VS
669 i915_reg_t ctrl_reg = IS_BROXTON(dev) ?
670 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
671 u32 dpi_enabled, func;
672
e7d7cad0 673 func = I915_READ(MIPI_DSI_FUNC_PRG(port));
baeac68a 674 dpi_enabled = I915_READ(ctrl_reg) & DPI_ENABLE;
c0beefd2
GS
675
676 /* Due to some hardware limitations on BYT, MIPI Port C DPI
677 * Enable bit does not get set. To check whether DSI Port C
678 * was enabled in BIOS, check the Pipe B enable bit
679 */
680 if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) &&
681 (port == PORT_C))
682 dpi_enabled = I915_READ(PIPECONF(PIPE_B)) &
683 PIPECONF_ENABLE;
4e646495 684
c0beefd2 685 if (dpi_enabled || (func & CMD_MODE_DATA_WIDTH_MASK)) {
e7d7cad0 686 if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
c0beefd2 687 *pipe = port == PORT_A ? PIPE_A : PIPE_B;
4e646495
JN
688 return true;
689 }
690 }
691 }
692
693 return false;
694}
695
696static void intel_dsi_get_config(struct intel_encoder *encoder,
5cec258b 697 struct intel_crtc_state *pipe_config)
4e646495 698{
ce0c9821 699 u32 pclk = 0;
4e646495
JN
700 DRM_DEBUG_KMS("\n");
701
f573de5a
SK
702 /*
703 * DPLL_MD is not used in case of DSI, reading will get some default value
704 * set dpll_md = 0
705 */
706 pipe_config->dpll_hw_state.dpll_md = 0;
707
ce0c9821
SS
708 if (IS_BROXTON(encoder->base.dev))
709 pclk = bxt_get_dsi_pclk(encoder, pipe_config->pipe_bpp);
710 else if (IS_VALLEYVIEW(encoder->base.dev))
711 pclk = vlv_get_dsi_pclk(encoder, pipe_config->pipe_bpp);
712
f573de5a
SK
713 if (!pclk)
714 return;
715
2d112de7 716 pipe_config->base.adjusted_mode.crtc_clock = pclk;
f573de5a 717 pipe_config->port_clock = pclk;
4e646495
JN
718}
719
c19de8eb
DL
720static enum drm_mode_status
721intel_dsi_mode_valid(struct drm_connector *connector,
722 struct drm_display_mode *mode)
4e646495
JN
723{
724 struct intel_connector *intel_connector = to_intel_connector(connector);
725 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
759a1e98 726 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
4e646495
JN
727
728 DRM_DEBUG_KMS("\n");
729
730 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
731 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
732 return MODE_NO_DBLESCAN;
733 }
734
735 if (fixed_mode) {
736 if (mode->hdisplay > fixed_mode->hdisplay)
737 return MODE_PANEL;
738 if (mode->vdisplay > fixed_mode->vdisplay)
739 return MODE_PANEL;
759a1e98
MK
740 if (fixed_mode->clock > max_dotclk)
741 return MODE_CLOCK_HIGH;
4e646495
JN
742 }
743
36d21f4c 744 return MODE_OK;
4e646495
JN
745}
746
747/* return txclkesc cycles in terms of divider and duration in us */
748static u16 txclkesc(u32 divider, unsigned int us)
749{
750 switch (divider) {
751 case ESCAPE_CLOCK_DIVIDER_1:
752 default:
753 return 20 * us;
754 case ESCAPE_CLOCK_DIVIDER_2:
755 return 10 * us;
756 case ESCAPE_CLOCK_DIVIDER_4:
757 return 5 * us;
758 }
759}
760
761/* return pixels in terms of txbyteclkhs */
7f0c8605
SK
762static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
763 u16 burst_mode_ratio)
4e646495 764{
7f0c8605 765 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
7f3de833 766 8 * 100), lane_count);
4e646495
JN
767}
768
769static void set_dsi_timings(struct drm_encoder *encoder,
5e7234c9 770 const struct drm_display_mode *adjusted_mode)
4e646495
JN
771{
772 struct drm_device *dev = encoder->dev;
773 struct drm_i915_private *dev_priv = dev->dev_private;
774 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
775 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
aa102d28 776 enum port port;
6e3c9717 777 unsigned int bpp = intel_crtc->config->pipe_bpp;
4e646495
JN
778 unsigned int lane_count = intel_dsi->lane_count;
779
780 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
781
aad941d5
VS
782 hactive = adjusted_mode->crtc_hdisplay;
783 hfp = adjusted_mode->crtc_hsync_start - adjusted_mode->crtc_hdisplay;
784 hsync = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
785 hbp = adjusted_mode->crtc_htotal - adjusted_mode->crtc_hsync_end;
4e646495 786
aa102d28
GS
787 if (intel_dsi->dual_link) {
788 hactive /= 2;
789 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
790 hactive += intel_dsi->pixel_overlap;
791 hfp /= 2;
792 hsync /= 2;
793 hbp /= 2;
794 }
795
aad941d5
VS
796 vfp = adjusted_mode->crtc_vsync_start - adjusted_mode->crtc_vdisplay;
797 vsync = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
798 vbp = adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vsync_end;
4e646495
JN
799
800 /* horizontal values are in terms of high speed byte clock */
7f0c8605 801 hactive = txbyteclkhs(hactive, bpp, lane_count,
7f3de833 802 intel_dsi->burst_mode_ratio);
7f0c8605
SK
803 hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
804 hsync = txbyteclkhs(hsync, bpp, lane_count,
7f3de833 805 intel_dsi->burst_mode_ratio);
7f0c8605 806 hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
4e646495 807
aa102d28 808 for_each_dsi_port(port, intel_dsi->ports) {
d2e08c0f
SS
809 if (IS_BROXTON(dev)) {
810 /*
811 * Program hdisplay and vdisplay on MIPI transcoder.
812 * This is different from calculated hactive and
813 * vactive, as they are calculated per channel basis,
814 * whereas these values should be based on resolution.
815 */
816 I915_WRITE(BXT_MIPI_TRANS_HACTIVE(port),
aad941d5 817 adjusted_mode->crtc_hdisplay);
d2e08c0f 818 I915_WRITE(BXT_MIPI_TRANS_VACTIVE(port),
aad941d5 819 adjusted_mode->crtc_vdisplay);
d2e08c0f 820 I915_WRITE(BXT_MIPI_TRANS_VTOTAL(port),
aad941d5 821 adjusted_mode->crtc_vtotal);
d2e08c0f
SS
822 }
823
aa102d28
GS
824 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
825 I915_WRITE(MIPI_HFP_COUNT(port), hfp);
826
827 /* meaningful for video mode non-burst sync pulse mode only,
828 * can be zero for non-burst sync events and burst modes */
829 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
830 I915_WRITE(MIPI_HBP_COUNT(port), hbp);
831
832 /* vertical values are in terms of lines */
833 I915_WRITE(MIPI_VFP_COUNT(port), vfp);
834 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
835 I915_WRITE(MIPI_VBP_COUNT(port), vbp);
836 }
4e646495
JN
837}
838
07e4fb9e 839static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
4e646495
JN
840{
841 struct drm_encoder *encoder = &intel_encoder->base;
842 struct drm_device *dev = encoder->dev;
843 struct drm_i915_private *dev_priv = dev->dev_private;
844 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
845 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
7c5f93b0 846 const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
24ee0e64 847 enum port port;
6e3c9717 848 unsigned int bpp = intel_crtc->config->pipe_bpp;
4e646495 849 u32 val, tmp;
24ee0e64 850 u16 mode_hdisplay;
4e646495 851
e7d7cad0 852 DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
4e646495 853
aad941d5 854 mode_hdisplay = adjusted_mode->crtc_hdisplay;
4e646495 855
24ee0e64
GS
856 if (intel_dsi->dual_link) {
857 mode_hdisplay /= 2;
858 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
859 mode_hdisplay += intel_dsi->pixel_overlap;
860 }
4e646495 861
24ee0e64 862 for_each_dsi_port(port, intel_dsi->ports) {
d2e08c0f
SS
863 if (IS_VALLEYVIEW(dev)) {
864 /*
865 * escape clock divider, 20MHz, shared for A and C.
866 * device ready must be off when doing this! txclkesc?
867 */
868 tmp = I915_READ(MIPI_CTRL(PORT_A));
869 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
870 I915_WRITE(MIPI_CTRL(PORT_A), tmp |
871 ESCAPE_CLOCK_DIVIDER_1);
872
873 /* read request priority is per pipe */
874 tmp = I915_READ(MIPI_CTRL(port));
875 tmp &= ~READ_REQUEST_PRIORITY_MASK;
876 I915_WRITE(MIPI_CTRL(port), tmp |
877 READ_REQUEST_PRIORITY_HIGH);
878 } else if (IS_BROXTON(dev)) {
879 /*
880 * FIXME:
881 * BXT can connect any PIPE to any MIPI port.
882 * Select the pipe based on the MIPI port read from
883 * VBT for now. Pick PIPE A for MIPI port A and C
884 * for port C.
885 */
886 tmp = I915_READ(MIPI_CTRL(port));
887 tmp &= ~BXT_PIPE_SELECT_MASK;
888
889 if (port == PORT_A)
890 tmp |= BXT_PIPE_SELECT_A;
891 else if (port == PORT_C)
892 tmp |= BXT_PIPE_SELECT_C;
893
894 I915_WRITE(MIPI_CTRL(port), tmp);
895 }
24ee0e64
GS
896
897 /* XXX: why here, why like this? handling in irq handler?! */
898 I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
899 I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
900
901 I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
902
903 I915_WRITE(MIPI_DPI_RESOLUTION(port),
aad941d5 904 adjusted_mode->crtc_vdisplay << VERTICAL_ADDRESS_SHIFT |
24ee0e64
GS
905 mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
906 }
4e646495
JN
907
908 set_dsi_timings(encoder, adjusted_mode);
909
910 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
911 if (is_cmd_mode(intel_dsi)) {
912 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
913 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
914 } else {
915 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
916
917 /* XXX: cross-check bpp vs. pixel format? */
918 val |= intel_dsi->pixel_format;
919 }
4e646495 920
24ee0e64
GS
921 tmp = 0;
922 if (intel_dsi->eotp_pkt == 0)
923 tmp |= EOT_DISABLE;
924 if (intel_dsi->clock_stop)
925 tmp |= CLOCKSTOP;
4e646495 926
24ee0e64
GS
927 for_each_dsi_port(port, intel_dsi->ports) {
928 I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
929
930 /* timeouts for recovery. one frame IIUC. if counter expires,
931 * EOT and stop state. */
932
933 /*
934 * In burst mode, value greater than one DPI line Time in byte
935 * clock (txbyteclkhs) To timeout this timer 1+ of the above
936 * said value is recommended.
937 *
938 * In non-burst mode, Value greater than one DPI frame time in
939 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
940 * said value is recommended.
941 *
942 * In DBI only mode, value greater than one DBI frame time in
943 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
944 * said value is recommended.
945 */
4e646495 946
24ee0e64
GS
947 if (is_vid_mode(intel_dsi) &&
948 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
949 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
aad941d5 950 txbyteclkhs(adjusted_mode->crtc_htotal, bpp,
124abe07
VS
951 intel_dsi->lane_count,
952 intel_dsi->burst_mode_ratio) + 1);
24ee0e64
GS
953 } else {
954 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
aad941d5
VS
955 txbyteclkhs(adjusted_mode->crtc_vtotal *
956 adjusted_mode->crtc_htotal,
124abe07
VS
957 bpp, intel_dsi->lane_count,
958 intel_dsi->burst_mode_ratio) + 1);
24ee0e64
GS
959 }
960 I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
961 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
962 intel_dsi->turn_arnd_val);
963 I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
964 intel_dsi->rst_timer_val);
f1c79f16 965
24ee0e64 966 /* dphy stuff */
f1c79f16 967
24ee0e64
GS
968 /* in terms of low power clock */
969 I915_WRITE(MIPI_INIT_COUNT(port),
970 txclkesc(intel_dsi->escape_clk_div, 100));
4e646495 971
d2e08c0f
SS
972 if (IS_BROXTON(dev) && (!intel_dsi->dual_link)) {
973 /*
974 * BXT spec says write MIPI_INIT_COUNT for
975 * both the ports, even if only one is
976 * getting used. So write the other port
977 * if not in dual link mode.
978 */
979 I915_WRITE(MIPI_INIT_COUNT(port ==
980 PORT_A ? PORT_C : PORT_A),
981 intel_dsi->init_count);
982 }
4e646495 983
24ee0e64 984 /* recovery disables */
87c54d0e 985 I915_WRITE(MIPI_EOT_DISABLE(port), tmp);
cf4dbd2e 986
24ee0e64
GS
987 /* in terms of low power clock */
988 I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
4e646495 989
24ee0e64
GS
990 /* in terms of txbyteclkhs. actual high to low switch +
991 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
992 *
993 * XXX: write MIPI_STOP_STATE_STALL?
994 */
995 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
996 intel_dsi->hs_to_lp_count);
997
998 /* XXX: low power clock equivalence in terms of byte clock.
999 * the number of byte clocks occupied in one low power clock.
1000 * based on txbyteclkhs and txclkesc.
1001 * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
1002 * ) / 105.???
1003 */
1004 I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
1005
1006 /* the bw essential for transmitting 16 long packets containing
1007 * 252 bytes meant for dcs write memory command is programmed in
1008 * this register in terms of byte clocks. based on dsi transfer
1009 * rate and the number of lanes configured the time taken to
1010 * transmit 16 long packets in a dsi stream varies. */
1011 I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
1012
1013 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
1014 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
1015 intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
1016
1017 if (is_vid_mode(intel_dsi))
1018 /* Some panels might have resolution which is not a
1019 * multiple of 64 like 1366 x 768. Enable RANDOM
1020 * resolution support for such panels by default */
1021 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
1022 intel_dsi->video_frmt_cfg_bits |
1023 intel_dsi->video_mode_format |
1024 IP_TG_CONFIG |
1025 RANDOM_DPI_DISPLAY_RESOLUTION);
1026 }
4e646495
JN
1027}
1028
07e4fb9e
DV
1029static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
1030{
1031 DRM_DEBUG_KMS("\n");
1032
1033 intel_dsi_prepare(encoder);
cfe01a5e 1034 intel_enable_dsi_pll(encoder);
07e4fb9e 1035
07e4fb9e
DV
1036}
1037
4e646495
JN
1038static enum drm_connector_status
1039intel_dsi_detect(struct drm_connector *connector, bool force)
1040{
36d21f4c 1041 return connector_status_connected;
4e646495
JN
1042}
1043
1044static int intel_dsi_get_modes(struct drm_connector *connector)
1045{
1046 struct intel_connector *intel_connector = to_intel_connector(connector);
1047 struct drm_display_mode *mode;
1048
1049 DRM_DEBUG_KMS("\n");
1050
1051 if (!intel_connector->panel.fixed_mode) {
1052 DRM_DEBUG_KMS("no fixed mode\n");
1053 return 0;
1054 }
1055
1056 mode = drm_mode_duplicate(connector->dev,
1057 intel_connector->panel.fixed_mode);
1058 if (!mode) {
1059 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
1060 return 0;
1061 }
1062
1063 drm_mode_probed_add(connector, mode);
1064 return 1;
1065}
1066
593e0622 1067static void intel_dsi_connector_destroy(struct drm_connector *connector)
4e646495
JN
1068{
1069 struct intel_connector *intel_connector = to_intel_connector(connector);
1070
1071 DRM_DEBUG_KMS("\n");
1072 intel_panel_fini(&intel_connector->panel);
4e646495
JN
1073 drm_connector_cleanup(connector);
1074 kfree(connector);
1075}
1076
593e0622
JN
1077static void intel_dsi_encoder_destroy(struct drm_encoder *encoder)
1078{
1079 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
1080
1081 if (intel_dsi->panel) {
1082 drm_panel_detach(intel_dsi->panel);
1083 /* XXX: Logically this call belongs in the panel driver. */
1084 drm_panel_remove(intel_dsi->panel);
1085 }
fc45e821
SK
1086
1087 /* dispose of the gpios */
1088 if (intel_dsi->gpio_panel)
1089 gpiod_put(intel_dsi->gpio_panel);
1090
593e0622
JN
1091 intel_encoder_destroy(encoder);
1092}
1093
4e646495 1094static const struct drm_encoder_funcs intel_dsi_funcs = {
593e0622 1095 .destroy = intel_dsi_encoder_destroy,
4e646495
JN
1096};
1097
1098static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
1099 .get_modes = intel_dsi_get_modes,
1100 .mode_valid = intel_dsi_mode_valid,
1101 .best_encoder = intel_best_encoder,
1102};
1103
1104static const struct drm_connector_funcs intel_dsi_connector_funcs = {
4d688a2a 1105 .dpms = drm_atomic_helper_connector_dpms,
4e646495 1106 .detect = intel_dsi_detect,
593e0622 1107 .destroy = intel_dsi_connector_destroy,
4e646495 1108 .fill_modes = drm_helper_probe_single_connector_modes,
2545e4a6 1109 .atomic_get_property = intel_connector_atomic_get_property,
c6f95f27 1110 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
98969725 1111 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
4e646495
JN
1112};
1113
4328633d 1114void intel_dsi_init(struct drm_device *dev)
4e646495
JN
1115{
1116 struct intel_dsi *intel_dsi;
1117 struct intel_encoder *intel_encoder;
1118 struct drm_encoder *encoder;
1119 struct intel_connector *intel_connector;
1120 struct drm_connector *connector;
593e0622 1121 struct drm_display_mode *scan, *fixed_mode = NULL;
b6fdd0f2 1122 struct drm_i915_private *dev_priv = dev->dev_private;
7e9804fd 1123 enum port port;
4e646495
JN
1124 unsigned int i;
1125
1126 DRM_DEBUG_KMS("\n");
1127
3e6bd011
SK
1128 /* There is no detection method for MIPI so rely on VBT */
1129 if (!dev_priv->vbt.has_mipi)
4328633d 1130 return;
3e6bd011 1131
868d665b
CJ
1132 if (IS_VALLEYVIEW(dev)) {
1133 dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
1134 } else {
1135 DRM_ERROR("Unsupported Mipi device to reg base");
1136 return;
1137 }
3e6bd011 1138
4e646495
JN
1139 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
1140 if (!intel_dsi)
4328633d 1141 return;
4e646495 1142
08d9bc92 1143 intel_connector = intel_connector_alloc();
4e646495
JN
1144 if (!intel_connector) {
1145 kfree(intel_dsi);
4328633d 1146 return;
4e646495
JN
1147 }
1148
1149 intel_encoder = &intel_dsi->base;
1150 encoder = &intel_encoder->base;
1151 intel_dsi->attached_connector = intel_connector;
1152
1153 connector = &intel_connector->base;
1154
13a3d91f
VS
1155 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI,
1156 NULL);
4e646495
JN
1157
1158 /* XXX: very likely not all of these are needed */
4e646495
JN
1159 intel_encoder->compute_config = intel_dsi_compute_config;
1160 intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
1161 intel_encoder->pre_enable = intel_dsi_pre_enable;
2634fd7f 1162 intel_encoder->enable = intel_dsi_enable_nop;
c315faf8 1163 intel_encoder->disable = intel_dsi_pre_disable;
4e646495
JN
1164 intel_encoder->post_disable = intel_dsi_post_disable;
1165 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
1166 intel_encoder->get_config = intel_dsi_get_config;
1167
1168 intel_connector->get_hw_state = intel_connector_get_hw_state;
4932e2c3 1169 intel_connector->unregister = intel_connector_unregister;
4e646495 1170
e7d7cad0 1171 /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
82425785 1172 if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
e7d7cad0 1173 intel_encoder->crtc_mask = (1 << PIPE_A);
17af40a8
JN
1174 intel_dsi->ports = (1 << PORT_A);
1175 } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
e7d7cad0 1176 intel_encoder->crtc_mask = (1 << PIPE_B);
17af40a8
JN
1177 intel_dsi->ports = (1 << PORT_C);
1178 }
e7d7cad0 1179
82425785
GS
1180 if (dev_priv->vbt.dsi.config->dual_link)
1181 intel_dsi->ports = ((1 << PORT_A) | (1 << PORT_C));
1182
7e9804fd
JN
1183 /* Create a DSI host (and a device) for each port. */
1184 for_each_dsi_port(port, intel_dsi->ports) {
1185 struct intel_dsi_host *host;
1186
1187 host = intel_dsi_host_init(intel_dsi, port);
1188 if (!host)
1189 goto err;
1190
1191 intel_dsi->dsi_hosts[port] = host;
1192 }
1193
593e0622
JN
1194 for (i = 0; i < ARRAY_SIZE(intel_dsi_drivers); i++) {
1195 intel_dsi->panel = intel_dsi_drivers[i].init(intel_dsi,
1196 intel_dsi_drivers[i].panel_id);
1197 if (intel_dsi->panel)
4e646495
JN
1198 break;
1199 }
1200
593e0622 1201 if (!intel_dsi->panel) {
4e646495
JN
1202 DRM_DEBUG_KMS("no device found\n");
1203 goto err;
1204 }
1205
fc45e821
SK
1206 /*
1207 * In case of BYT with CRC PMIC, we need to use GPIO for
1208 * Panel control.
1209 */
1210 if (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) {
1211 intel_dsi->gpio_panel =
1212 gpiod_get(dev->dev, "panel", GPIOD_OUT_HIGH);
1213
1214 if (IS_ERR(intel_dsi->gpio_panel)) {
1215 DRM_ERROR("Failed to own gpio for panel control\n");
1216 intel_dsi->gpio_panel = NULL;
1217 }
1218 }
1219
4e646495 1220 intel_encoder->type = INTEL_OUTPUT_DSI;
bc079e8b 1221 intel_encoder->cloneable = 0;
4e646495
JN
1222 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
1223 DRM_MODE_CONNECTOR_DSI);
1224
1225 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
1226
1227 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
1228 connector->interlace_allowed = false;
1229 connector->doublescan_allowed = false;
1230
1231 intel_connector_attach_encoder(intel_connector, intel_encoder);
1232
34ea3d38 1233 drm_connector_register(connector);
4e646495 1234
593e0622
JN
1235 drm_panel_attach(intel_dsi->panel, connector);
1236
1237 mutex_lock(&dev->mode_config.mutex);
1238 drm_panel_get_modes(intel_dsi->panel);
1239 list_for_each_entry(scan, &connector->probed_modes, head) {
1240 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
1241 fixed_mode = drm_mode_duplicate(dev, scan);
1242 break;
1243 }
1244 }
1245 mutex_unlock(&dev->mode_config.mutex);
1246
4e646495
JN
1247 if (!fixed_mode) {
1248 DRM_DEBUG_KMS("no fixed mode\n");
1249 goto err;
1250 }
1251
4b6ed685 1252 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
b029e66f 1253 intel_panel_setup_backlight(connector, INVALID_PIPE);
4e646495 1254
4328633d 1255 return;
4e646495
JN
1256
1257err:
1258 drm_encoder_cleanup(&intel_encoder->base);
1259 kfree(intel_dsi);
1260 kfree(intel_connector);
4e646495 1261}
This page took 0.217909 seconds and 5 git commands to generate.