drm/i915: Update the DSI disable path to support dual link panel disabling
[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>
27#include <drm/drm_crtc.h>
28#include <drm/drm_edid.h>
29#include <drm/i915_drm.h>
30#include <linux/slab.h>
31#include "i915_drv.h"
32#include "intel_drv.h"
33#include "intel_dsi.h"
34#include "intel_dsi_cmd.h"
35
36/* the sub-encoders aka panel drivers */
37static const struct intel_dsi_device intel_dsi_devices[] = {
2ab8b458
SK
38 {
39 .panel_id = MIPI_DSI_GENERIC_PANEL_ID,
40 .name = "vbt-generic-dsi-vid-mode-display",
41 .dev_ops = &vbt_generic_dsi_display_ops,
42 },
4e646495
JN
43};
44
e9fe51c6 45static void band_gap_reset(struct drm_i915_private *dev_priv)
4ce8c9a7
SK
46{
47 mutex_lock(&dev_priv->dpio_lock);
48
e9fe51c6
SK
49 vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
50 vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
51 vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
52 udelay(150);
53 vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
54 vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
4ce8c9a7
SK
55
56 mutex_unlock(&dev_priv->dpio_lock);
4ce8c9a7
SK
57}
58
4e646495
JN
59static struct intel_dsi *intel_attached_dsi(struct drm_connector *connector)
60{
61 return container_of(intel_attached_encoder(connector),
62 struct intel_dsi, base);
63}
64
65static inline bool is_vid_mode(struct intel_dsi *intel_dsi)
66{
dfba2e2d 67 return intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE;
4e646495
JN
68}
69
70static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
71{
dfba2e2d 72 return intel_dsi->operation_mode == INTEL_DSI_COMMAND_MODE;
4e646495
JN
73}
74
75static void intel_dsi_hot_plug(struct intel_encoder *encoder)
76{
77 DRM_DEBUG_KMS("\n");
78}
79
80static bool intel_dsi_compute_config(struct intel_encoder *encoder,
81 struct intel_crtc_config *config)
82{
83 struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
84 base);
85 struct intel_connector *intel_connector = intel_dsi->attached_connector;
86 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
87 struct drm_display_mode *adjusted_mode = &config->adjusted_mode;
88 struct drm_display_mode *mode = &config->requested_mode;
89
90 DRM_DEBUG_KMS("\n");
91
92 if (fixed_mode)
93 intel_fixed_panel_mode(fixed_mode, adjusted_mode);
94
f573de5a
SK
95 /* DSI uses short packets for sync events, so clear mode flags for DSI */
96 adjusted_mode->flags = 0;
97
4e646495
JN
98 if (intel_dsi->dev.dev_ops->mode_fixup)
99 return intel_dsi->dev.dev_ops->mode_fixup(&intel_dsi->dev,
100 mode, adjusted_mode);
101
102 return true;
103}
104
5505a244
GS
105static void intel_dsi_port_enable(struct intel_encoder *encoder)
106{
107 struct drm_device *dev = encoder->base.dev;
108 struct drm_i915_private *dev_priv = dev->dev_private;
109 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
110 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
369602d3 111 enum port port;
5505a244
GS
112 u32 temp;
113
a9da9bce
GS
114 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
115 temp = I915_READ(VLV_CHICKEN_3);
116 temp &= ~PIXEL_OVERLAP_CNT_MASK |
117 intel_dsi->pixel_overlap <<
118 PIXEL_OVERLAP_CNT_SHIFT;
119 I915_WRITE(VLV_CHICKEN_3, temp);
120 }
121
369602d3
GS
122 for_each_dsi_port(port, intel_dsi->ports) {
123 temp = I915_READ(MIPI_PORT_CTRL(port));
124 temp &= ~LANE_CONFIGURATION_MASK;
125 temp &= ~DUAL_LINK_MODE_MASK;
126
127 if (intel_dsi->ports == ((1 << PORT_A) | (1 << PORT_C))) {
128 temp |= (intel_dsi->dual_link - 1)
129 << DUAL_LINK_MODE_SHIFT;
130 temp |= intel_crtc->pipe ?
131 LANE_CONFIGURATION_DUAL_LINK_B :
132 LANE_CONFIGURATION_DUAL_LINK_A;
133 }
134 /* assert ip_tg_enable signal */
135 I915_WRITE(MIPI_PORT_CTRL(port), temp | DPI_ENABLE);
136 POSTING_READ(MIPI_PORT_CTRL(port));
137 }
5505a244
GS
138}
139
140static void intel_dsi_port_disable(struct intel_encoder *encoder)
141{
142 struct drm_device *dev = encoder->base.dev;
143 struct drm_i915_private *dev_priv = dev->dev_private;
369602d3
GS
144 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
145 enum port port;
5505a244
GS
146 u32 temp;
147
369602d3
GS
148 for_each_dsi_port(port, intel_dsi->ports) {
149 /* de-assert ip_tg_enable signal */
150 temp = I915_READ(MIPI_PORT_CTRL(port));
151 I915_WRITE(MIPI_PORT_CTRL(port), temp & ~DPI_ENABLE);
152 POSTING_READ(MIPI_PORT_CTRL(port));
153 }
5505a244
GS
154}
155
1dbd7cb2 156static void intel_dsi_device_ready(struct intel_encoder *encoder)
4e646495 157{
1dbd7cb2
SK
158 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
159 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
e7d7cad0 160 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
1dbd7cb2
SK
161 u32 val;
162
4e646495 163 DRM_DEBUG_KMS("\n");
4e646495 164
2095f9fc
SK
165 mutex_lock(&dev_priv->dpio_lock);
166 /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
167 * needed everytime after power gate */
168 vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
169 mutex_unlock(&dev_priv->dpio_lock);
170
171 /* bandgap reset is needed after everytime we do power gate */
172 band_gap_reset(dev_priv);
173
e7d7cad0 174 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
aceb365c
SK
175 usleep_range(2500, 3000);
176
e7d7cad0
JN
177 val = I915_READ(MIPI_PORT_CTRL(port));
178 I915_WRITE(MIPI_PORT_CTRL(port), val | LP_OUTPUT_HOLD);
1dbd7cb2 179 usleep_range(1000, 1500);
aceb365c 180
e7d7cad0 181 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
aceb365c
SK
182 usleep_range(2500, 3000);
183
e7d7cad0 184 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
aceb365c 185 usleep_range(2500, 3000);
1dbd7cb2 186}
1dbd7cb2
SK
187
188static void intel_dsi_enable(struct intel_encoder *encoder)
189{
190 struct drm_device *dev = encoder->base.dev;
191 struct drm_i915_private *dev_priv = dev->dev_private;
192 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
193 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
e7d7cad0 194 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
1dbd7cb2
SK
195
196 DRM_DEBUG_KMS("\n");
b9f5e07d 197
4e646495 198 if (is_cmd_mode(intel_dsi))
e7d7cad0 199 I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
1dbd7cb2 200 else {
4e646495 201 msleep(20); /* XXX */
e1047028 202 dpi_send_cmd(intel_dsi, TURN_ON, DPI_LP_MODE_EN);
4e646495
JN
203 msleep(100);
204
2634fd7f
SK
205 if (intel_dsi->dev.dev_ops->enable)
206 intel_dsi->dev.dev_ops->enable(&intel_dsi->dev);
207
1381308b
SK
208 wait_for_dsi_fifo_empty(intel_dsi);
209
5505a244 210 intel_dsi_port_enable(encoder);
4e646495 211 }
2634fd7f
SK
212}
213
214static void intel_dsi_pre_enable(struct intel_encoder *encoder)
215{
20e5bf66
SK
216 struct drm_device *dev = encoder->base.dev;
217 struct drm_i915_private *dev_priv = dev->dev_private;
2634fd7f 218 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
20e5bf66
SK
219 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
220 enum pipe pipe = intel_crtc->pipe;
221 u32 tmp;
2634fd7f
SK
222
223 DRM_DEBUG_KMS("\n");
224
20e5bf66
SK
225 /* Disable DPOunit clock gating, can stall pipe
226 * and we need DPLL REFA always enabled */
227 tmp = I915_READ(DPLL(pipe));
228 tmp |= DPLL_REFA_CLK_ENABLE_VLV;
229 I915_WRITE(DPLL(pipe), tmp);
230
f573de5a
SK
231 /* update the hw state for DPLL */
232 intel_crtc->config.dpll_hw_state.dpll = DPLL_INTEGRATED_CLOCK_VLV |
7f3de833 233 DPLL_REFA_CLK_ENABLE_VLV;
f573de5a 234
20e5bf66
SK
235 tmp = I915_READ(DSPCLK_GATE_D);
236 tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
237 I915_WRITE(DSPCLK_GATE_D, tmp);
2634fd7f
SK
238
239 /* put device in ready state */
240 intel_dsi_device_ready(encoder);
4e646495 241
df38e655
SK
242 msleep(intel_dsi->panel_on_delay);
243
20e5bf66
SK
244 if (intel_dsi->dev.dev_ops->panel_reset)
245 intel_dsi->dev.dev_ops->panel_reset(&intel_dsi->dev);
246
2634fd7f
SK
247 if (intel_dsi->dev.dev_ops->send_otp_cmds)
248 intel_dsi->dev.dev_ops->send_otp_cmds(&intel_dsi->dev);
249
1381308b
SK
250 wait_for_dsi_fifo_empty(intel_dsi);
251
2634fd7f
SK
252 /* Enable port in pre-enable phase itself because as per hw team
253 * recommendation, port should be enabled befor plane & pipe */
254 intel_dsi_enable(encoder);
255}
256
257static void intel_dsi_enable_nop(struct intel_encoder *encoder)
258{
259 DRM_DEBUG_KMS("\n");
260
261 /* for DSI port enable has to be done before pipe
262 * and plane enable, so port enable is done in
263 * pre_enable phase itself unlike other encoders
264 */
4e646495
JN
265}
266
c315faf8
ID
267static void intel_dsi_pre_disable(struct intel_encoder *encoder)
268{
269 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
270
271 DRM_DEBUG_KMS("\n");
272
273 if (is_vid_mode(intel_dsi)) {
274 /* Send Shutdown command to the panel in LP mode */
275 dpi_send_cmd(intel_dsi, SHUTDOWN, DPI_LP_MODE_EN);
276 msleep(10);
277 }
278}
279
4e646495
JN
280static void intel_dsi_disable(struct intel_encoder *encoder)
281{
1dbd7cb2
SK
282 struct drm_device *dev = encoder->base.dev;
283 struct drm_i915_private *dev_priv = dev->dev_private;
4e646495 284 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
384f02a2 285 enum port port;
4e646495
JN
286 u32 temp;
287
288 DRM_DEBUG_KMS("\n");
289
4e646495 290 if (is_vid_mode(intel_dsi)) {
1381308b
SK
291 wait_for_dsi_fifo_empty(intel_dsi);
292
5505a244 293 intel_dsi_port_disable(encoder);
4e646495
JN
294 msleep(2);
295 }
296
384f02a2
GS
297 for_each_dsi_port(port, intel_dsi->ports) {
298 /* Panel commands can be sent when clock is in LP11 */
299 I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
339023ec 300
384f02a2
GS
301 temp = I915_READ(MIPI_CTRL(port));
302 temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
303 I915_WRITE(MIPI_CTRL(port), temp |
304 intel_dsi->escape_clk_div <<
305 ESCAPE_CLOCK_DIVIDER_SHIFT);
339023ec 306
384f02a2 307 I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
339023ec 308
384f02a2
GS
309 temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
310 temp &= ~VID_MODE_FORMAT_MASK;
311 I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
339023ec 312
384f02a2
GS
313 I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
314 }
1dbd7cb2
SK
315 /* if disable packets are sent before sending shutdown packet then in
316 * some next enable sequence send turn on packet error is observed */
317 if (intel_dsi->dev.dev_ops->disable)
318 intel_dsi->dev.dev_ops->disable(&intel_dsi->dev);
1381308b
SK
319
320 wait_for_dsi_fifo_empty(intel_dsi);
4e646495
JN
321}
322
1dbd7cb2 323static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
4e646495 324{
1dbd7cb2 325 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
384f02a2
GS
326 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
327 enum port port;
1dbd7cb2
SK
328 u32 val;
329
4e646495 330 DRM_DEBUG_KMS("\n");
384f02a2 331 for_each_dsi_port(port, intel_dsi->ports) {
be4fc046 332
384f02a2
GS
333 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
334 ULPS_STATE_ENTER);
335 usleep_range(2000, 2500);
336
337 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
338 ULPS_STATE_EXIT);
339 usleep_range(2000, 2500);
340
341 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
342 ULPS_STATE_ENTER);
343 usleep_range(2000, 2500);
344
345 /* Wait till Clock lanes are in LP-00 state for MIPI Port A
346 * only. MIPI Port C has no similar bit for checking
347 */
348 if (wait_for(((I915_READ(MIPI_PORT_CTRL(PORT_A)) & AFE_LATCHOUT)
349 == 0x00000), 30))
350 DRM_ERROR("DSI LP not going Low\n");
351
352 val = I915_READ(MIPI_PORT_CTRL(port));
353 /* Disable MIPI PHY transparent latch
354 * Common bit for both MIPI Port A & MIPI Port C
355 */
356 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val & ~LP_OUTPUT_HOLD);
357 usleep_range(1000, 1500);
358
359 I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
360 usleep_range(2000, 2500);
361 }
1dbd7cb2 362
be4fc046 363 vlv_disable_dsi_pll(encoder);
4e646495 364}
20e5bf66 365
1dbd7cb2
SK
366static void intel_dsi_post_disable(struct intel_encoder *encoder)
367{
20e5bf66 368 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1dbd7cb2 369 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
20e5bf66 370 u32 val;
1dbd7cb2
SK
371
372 DRM_DEBUG_KMS("\n");
373
c315faf8
ID
374 intel_dsi_disable(encoder);
375
1dbd7cb2
SK
376 intel_dsi_clear_device_ready(encoder);
377
20e5bf66
SK
378 val = I915_READ(DSPCLK_GATE_D);
379 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
380 I915_WRITE(DSPCLK_GATE_D, val);
381
1dbd7cb2
SK
382 if (intel_dsi->dev.dev_ops->disable_panel_power)
383 intel_dsi->dev.dev_ops->disable_panel_power(&intel_dsi->dev);
df38e655
SK
384
385 msleep(intel_dsi->panel_off_delay);
386 msleep(intel_dsi->panel_pwr_cycle_delay);
1dbd7cb2 387}
4e646495
JN
388
389static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
390 enum pipe *pipe)
391{
392 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
6d129bea 393 enum intel_display_power_domain power_domain;
e7d7cad0
JN
394 u32 port_ctl, func;
395 enum port port;
4e646495
JN
396
397 DRM_DEBUG_KMS("\n");
398
6d129bea 399 power_domain = intel_display_port_power_domain(encoder);
f458ebbc 400 if (!intel_display_power_is_enabled(dev_priv, power_domain))
6d129bea
ID
401 return false;
402
4e646495 403 /* XXX: this only works for one DSI output */
e7d7cad0
JN
404 for_each_dsi_port(port, (1 << PORT_A) | (1 << PORT_C)) {
405 port_ctl = I915_READ(MIPI_PORT_CTRL(port));
406 func = I915_READ(MIPI_DSI_FUNC_PRG(port));
4e646495 407
e7d7cad0
JN
408 if ((port_ctl & DPI_ENABLE) || (func & CMD_MODE_DATA_WIDTH_MASK)) {
409 if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
410 *pipe = port == PORT_A ? PIPE_A : PIPE_C;
4e646495
JN
411 return true;
412 }
413 }
414 }
415
416 return false;
417}
418
419static void intel_dsi_get_config(struct intel_encoder *encoder,
420 struct intel_crtc_config *pipe_config)
421{
f573de5a 422 u32 pclk;
4e646495
JN
423 DRM_DEBUG_KMS("\n");
424
f573de5a
SK
425 /*
426 * DPLL_MD is not used in case of DSI, reading will get some default value
427 * set dpll_md = 0
428 */
429 pipe_config->dpll_hw_state.dpll_md = 0;
430
431 pclk = vlv_get_dsi_pclk(encoder, pipe_config->pipe_bpp);
432 if (!pclk)
433 return;
434
435 pipe_config->adjusted_mode.crtc_clock = pclk;
436 pipe_config->port_clock = pclk;
4e646495
JN
437}
438
c19de8eb
DL
439static enum drm_mode_status
440intel_dsi_mode_valid(struct drm_connector *connector,
441 struct drm_display_mode *mode)
4e646495
JN
442{
443 struct intel_connector *intel_connector = to_intel_connector(connector);
444 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
445 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
446
447 DRM_DEBUG_KMS("\n");
448
449 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
450 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
451 return MODE_NO_DBLESCAN;
452 }
453
454 if (fixed_mode) {
455 if (mode->hdisplay > fixed_mode->hdisplay)
456 return MODE_PANEL;
457 if (mode->vdisplay > fixed_mode->vdisplay)
458 return MODE_PANEL;
459 }
460
461 return intel_dsi->dev.dev_ops->mode_valid(&intel_dsi->dev, mode);
462}
463
464/* return txclkesc cycles in terms of divider and duration in us */
465static u16 txclkesc(u32 divider, unsigned int us)
466{
467 switch (divider) {
468 case ESCAPE_CLOCK_DIVIDER_1:
469 default:
470 return 20 * us;
471 case ESCAPE_CLOCK_DIVIDER_2:
472 return 10 * us;
473 case ESCAPE_CLOCK_DIVIDER_4:
474 return 5 * us;
475 }
476}
477
478/* return pixels in terms of txbyteclkhs */
7f0c8605
SK
479static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
480 u16 burst_mode_ratio)
4e646495 481{
7f0c8605 482 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
7f3de833 483 8 * 100), lane_count);
4e646495
JN
484}
485
486static void set_dsi_timings(struct drm_encoder *encoder,
487 const struct drm_display_mode *mode)
488{
489 struct drm_device *dev = encoder->dev;
490 struct drm_i915_private *dev_priv = dev->dev_private;
491 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
492 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
aa102d28 493 enum port port;
4e646495
JN
494 unsigned int bpp = intel_crtc->config.pipe_bpp;
495 unsigned int lane_count = intel_dsi->lane_count;
496
497 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
498
499 hactive = mode->hdisplay;
500 hfp = mode->hsync_start - mode->hdisplay;
501 hsync = mode->hsync_end - mode->hsync_start;
502 hbp = mode->htotal - mode->hsync_end;
503
aa102d28
GS
504 if (intel_dsi->dual_link) {
505 hactive /= 2;
506 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
507 hactive += intel_dsi->pixel_overlap;
508 hfp /= 2;
509 hsync /= 2;
510 hbp /= 2;
511 }
512
4e646495
JN
513 vfp = mode->vsync_start - mode->vdisplay;
514 vsync = mode->vsync_end - mode->vsync_start;
515 vbp = mode->vtotal - mode->vsync_end;
516
517 /* horizontal values are in terms of high speed byte clock */
7f0c8605 518 hactive = txbyteclkhs(hactive, bpp, lane_count,
7f3de833 519 intel_dsi->burst_mode_ratio);
7f0c8605
SK
520 hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
521 hsync = txbyteclkhs(hsync, bpp, lane_count,
7f3de833 522 intel_dsi->burst_mode_ratio);
7f0c8605 523 hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
4e646495 524
aa102d28
GS
525 for_each_dsi_port(port, intel_dsi->ports) {
526 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
527 I915_WRITE(MIPI_HFP_COUNT(port), hfp);
528
529 /* meaningful for video mode non-burst sync pulse mode only,
530 * can be zero for non-burst sync events and burst modes */
531 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
532 I915_WRITE(MIPI_HBP_COUNT(port), hbp);
533
534 /* vertical values are in terms of lines */
535 I915_WRITE(MIPI_VFP_COUNT(port), vfp);
536 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
537 I915_WRITE(MIPI_VBP_COUNT(port), vbp);
538 }
4e646495
JN
539}
540
07e4fb9e 541static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
4e646495
JN
542{
543 struct drm_encoder *encoder = &intel_encoder->base;
544 struct drm_device *dev = encoder->dev;
545 struct drm_i915_private *dev_priv = dev->dev_private;
546 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
547 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
548 struct drm_display_mode *adjusted_mode =
549 &intel_crtc->config.adjusted_mode;
e7d7cad0 550 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
4e646495
JN
551 unsigned int bpp = intel_crtc->config.pipe_bpp;
552 u32 val, tmp;
553
e7d7cad0 554 DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
4e646495
JN
555
556 /* escape clock divider, 20MHz, shared for A and C. device ready must be
557 * off when doing this! txclkesc? */
e7d7cad0 558 tmp = I915_READ(MIPI_CTRL(PORT_A));
4e646495 559 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
e7d7cad0 560 I915_WRITE(MIPI_CTRL(PORT_A), tmp | ESCAPE_CLOCK_DIVIDER_1);
4e646495
JN
561
562 /* read request priority is per pipe */
e7d7cad0 563 tmp = I915_READ(MIPI_CTRL(port));
4e646495 564 tmp &= ~READ_REQUEST_PRIORITY_MASK;
e7d7cad0 565 I915_WRITE(MIPI_CTRL(port), tmp | READ_REQUEST_PRIORITY_HIGH);
4e646495
JN
566
567 /* XXX: why here, why like this? handling in irq handler?! */
e7d7cad0
JN
568 I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
569 I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
4e646495 570
e7d7cad0 571 I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
4e646495 572
e7d7cad0 573 I915_WRITE(MIPI_DPI_RESOLUTION(port),
4e646495
JN
574 adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
575 adjusted_mode->hdisplay << HORIZONTAL_ADDRESS_SHIFT);
576
577 set_dsi_timings(encoder, adjusted_mode);
578
579 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
580 if (is_cmd_mode(intel_dsi)) {
581 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
582 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
583 } else {
584 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
585
586 /* XXX: cross-check bpp vs. pixel format? */
587 val |= intel_dsi->pixel_format;
588 }
e7d7cad0 589 I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
4e646495
JN
590
591 /* timeouts for recovery. one frame IIUC. if counter expires, EOT and
592 * stop state. */
593
594 /*
595 * In burst mode, value greater than one DPI line Time in byte clock
596 * (txbyteclkhs) To timeout this timer 1+ of the above said value is
597 * recommended.
598 *
599 * In non-burst mode, Value greater than one DPI frame time in byte
600 * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
601 * is recommended.
602 *
603 * In DBI only mode, value greater than one DBI frame time in byte
604 * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
605 * is recommended.
606 */
607
608 if (is_vid_mode(intel_dsi) &&
609 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
e7d7cad0 610 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
4e646495 611 txbyteclkhs(adjusted_mode->htotal, bpp,
7f0c8605
SK
612 intel_dsi->lane_count,
613 intel_dsi->burst_mode_ratio) + 1);
4e646495 614 } else {
e7d7cad0 615 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
4e646495
JN
616 txbyteclkhs(adjusted_mode->vtotal *
617 adjusted_mode->htotal,
7f0c8605
SK
618 bpp, intel_dsi->lane_count,
619 intel_dsi->burst_mode_ratio) + 1);
4e646495 620 }
e7d7cad0
JN
621 I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
622 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port), intel_dsi->turn_arnd_val);
623 I915_WRITE(MIPI_DEVICE_RESET_TIMER(port), intel_dsi->rst_timer_val);
4e646495
JN
624
625 /* dphy stuff */
626
627 /* in terms of low power clock */
e7d7cad0 628 I915_WRITE(MIPI_INIT_COUNT(port), txclkesc(intel_dsi->escape_clk_div, 100));
f1c79f16
SK
629
630 val = 0;
631 if (intel_dsi->eotp_pkt == 0)
632 val |= EOT_DISABLE;
633
634 if (intel_dsi->clock_stop)
635 val |= CLOCKSTOP;
4e646495
JN
636
637 /* recovery disables */
e7d7cad0 638 I915_WRITE(MIPI_EOT_DISABLE(port), val);
4e646495 639
cf4dbd2e 640 /* in terms of low power clock */
e7d7cad0 641 I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
cf4dbd2e 642
4e646495
JN
643 /* in terms of txbyteclkhs. actual high to low switch +
644 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
645 *
646 * XXX: write MIPI_STOP_STATE_STALL?
647 */
e7d7cad0 648 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
7f3de833 649 intel_dsi->hs_to_lp_count);
4e646495
JN
650
651 /* XXX: low power clock equivalence in terms of byte clock. the number
652 * of byte clocks occupied in one low power clock. based on txbyteclkhs
653 * and txclkesc. txclkesc time / txbyteclk time * (105 +
654 * MIPI_STOP_STATE_STALL) / 105.???
655 */
e7d7cad0 656 I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
4e646495
JN
657
658 /* the bw essential for transmitting 16 long packets containing 252
659 * bytes meant for dcs write memory command is programmed in this
660 * register in terms of byte clocks. based on dsi transfer rate and the
661 * number of lanes configured the time taken to transmit 16 long packets
662 * in a dsi stream varies. */
e7d7cad0 663 I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
4e646495 664
e7d7cad0 665 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
f6da2842
SK
666 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
667 intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
4e646495
JN
668
669 if (is_vid_mode(intel_dsi))
24d9c401
SK
670 /* Some panels might have resolution which is not a multiple of
671 * 64 like 1366 x 768. Enable RANDOM resolution support for such
672 * panels by default */
e7d7cad0 673 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
7f3de833
DV
674 intel_dsi->video_frmt_cfg_bits |
675 intel_dsi->video_mode_format |
676 IP_TG_CONFIG |
677 RANDOM_DPI_DISPLAY_RESOLUTION);
4e646495
JN
678}
679
07e4fb9e
DV
680static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
681{
682 DRM_DEBUG_KMS("\n");
683
684 intel_dsi_prepare(encoder);
685
686 vlv_enable_dsi_pll(encoder);
687}
688
4e646495
JN
689static enum drm_connector_status
690intel_dsi_detect(struct drm_connector *connector, bool force)
691{
692 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
671dedd2
ID
693 struct intel_encoder *intel_encoder = &intel_dsi->base;
694 enum intel_display_power_domain power_domain;
695 enum drm_connector_status connector_status;
696 struct drm_i915_private *dev_priv = intel_encoder->base.dev->dev_private;
697
4e646495 698 DRM_DEBUG_KMS("\n");
671dedd2
ID
699 power_domain = intel_display_port_power_domain(intel_encoder);
700
701 intel_display_power_get(dev_priv, power_domain);
702 connector_status = intel_dsi->dev.dev_ops->detect(&intel_dsi->dev);
703 intel_display_power_put(dev_priv, power_domain);
704
705 return connector_status;
4e646495
JN
706}
707
708static int intel_dsi_get_modes(struct drm_connector *connector)
709{
710 struct intel_connector *intel_connector = to_intel_connector(connector);
711 struct drm_display_mode *mode;
712
713 DRM_DEBUG_KMS("\n");
714
715 if (!intel_connector->panel.fixed_mode) {
716 DRM_DEBUG_KMS("no fixed mode\n");
717 return 0;
718 }
719
720 mode = drm_mode_duplicate(connector->dev,
721 intel_connector->panel.fixed_mode);
722 if (!mode) {
723 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
724 return 0;
725 }
726
727 drm_mode_probed_add(connector, mode);
728 return 1;
729}
730
731static void intel_dsi_destroy(struct drm_connector *connector)
732{
733 struct intel_connector *intel_connector = to_intel_connector(connector);
734
735 DRM_DEBUG_KMS("\n");
736 intel_panel_fini(&intel_connector->panel);
4e646495
JN
737 drm_connector_cleanup(connector);
738 kfree(connector);
739}
740
741static const struct drm_encoder_funcs intel_dsi_funcs = {
742 .destroy = intel_encoder_destroy,
743};
744
745static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
746 .get_modes = intel_dsi_get_modes,
747 .mode_valid = intel_dsi_mode_valid,
748 .best_encoder = intel_best_encoder,
749};
750
751static const struct drm_connector_funcs intel_dsi_connector_funcs = {
752 .dpms = intel_connector_dpms,
753 .detect = intel_dsi_detect,
754 .destroy = intel_dsi_destroy,
755 .fill_modes = drm_helper_probe_single_connector_modes,
756};
757
4328633d 758void intel_dsi_init(struct drm_device *dev)
4e646495
JN
759{
760 struct intel_dsi *intel_dsi;
761 struct intel_encoder *intel_encoder;
762 struct drm_encoder *encoder;
763 struct intel_connector *intel_connector;
764 struct drm_connector *connector;
765 struct drm_display_mode *fixed_mode = NULL;
b6fdd0f2 766 struct drm_i915_private *dev_priv = dev->dev_private;
4e646495
JN
767 const struct intel_dsi_device *dsi;
768 unsigned int i;
769
770 DRM_DEBUG_KMS("\n");
771
3e6bd011
SK
772 /* There is no detection method for MIPI so rely on VBT */
773 if (!dev_priv->vbt.has_mipi)
4328633d 774 return;
3e6bd011 775
868d665b
CJ
776 if (IS_VALLEYVIEW(dev)) {
777 dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
778 } else {
779 DRM_ERROR("Unsupported Mipi device to reg base");
780 return;
781 }
3e6bd011 782
4e646495
JN
783 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
784 if (!intel_dsi)
4328633d 785 return;
4e646495
JN
786
787 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
788 if (!intel_connector) {
789 kfree(intel_dsi);
4328633d 790 return;
4e646495
JN
791 }
792
793 intel_encoder = &intel_dsi->base;
794 encoder = &intel_encoder->base;
795 intel_dsi->attached_connector = intel_connector;
796
797 connector = &intel_connector->base;
798
799 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
800
801 /* XXX: very likely not all of these are needed */
802 intel_encoder->hot_plug = intel_dsi_hot_plug;
803 intel_encoder->compute_config = intel_dsi_compute_config;
804 intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
805 intel_encoder->pre_enable = intel_dsi_pre_enable;
2634fd7f 806 intel_encoder->enable = intel_dsi_enable_nop;
c315faf8 807 intel_encoder->disable = intel_dsi_pre_disable;
4e646495
JN
808 intel_encoder->post_disable = intel_dsi_post_disable;
809 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
810 intel_encoder->get_config = intel_dsi_get_config;
811
812 intel_connector->get_hw_state = intel_connector_get_hw_state;
4932e2c3 813 intel_connector->unregister = intel_connector_unregister;
4e646495 814
e7d7cad0 815 /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
17af40a8 816 if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
e7d7cad0 817 intel_encoder->crtc_mask = (1 << PIPE_A);
17af40a8
JN
818 intel_dsi->ports = (1 << PORT_A);
819 } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
e7d7cad0 820 intel_encoder->crtc_mask = (1 << PIPE_B);
17af40a8
JN
821 intel_dsi->ports = (1 << PORT_C);
822 }
e7d7cad0 823
4e646495
JN
824 for (i = 0; i < ARRAY_SIZE(intel_dsi_devices); i++) {
825 dsi = &intel_dsi_devices[i];
826 intel_dsi->dev = *dsi;
827
828 if (dsi->dev_ops->init(&intel_dsi->dev))
829 break;
830 }
831
832 if (i == ARRAY_SIZE(intel_dsi_devices)) {
833 DRM_DEBUG_KMS("no device found\n");
834 goto err;
835 }
836
837 intel_encoder->type = INTEL_OUTPUT_DSI;
bc079e8b 838 intel_encoder->cloneable = 0;
4e646495
JN
839 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
840 DRM_MODE_CONNECTOR_DSI);
841
842 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
843
844 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
845 connector->interlace_allowed = false;
846 connector->doublescan_allowed = false;
847
848 intel_connector_attach_encoder(intel_connector, intel_encoder);
849
34ea3d38 850 drm_connector_register(connector);
4e646495
JN
851
852 fixed_mode = dsi->dev_ops->get_modes(&intel_dsi->dev);
853 if (!fixed_mode) {
854 DRM_DEBUG_KMS("no fixed mode\n");
855 goto err;
856 }
857
858 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
4b6ed685 859 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
4e646495 860
4328633d 861 return;
4e646495
JN
862
863err:
864 drm_encoder_cleanup(&intel_encoder->base);
865 kfree(intel_dsi);
866 kfree(intel_connector);
4e646495 867}
This page took 0.133316 seconds and 5 git commands to generate.