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