blob: d8eccda04767012eaf3a041e0e749415e84b88cd [file] [log] [blame]
Jani Nikula4e646492013-08-27 15:12:20 +03001/*
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[] = {
38};
39
Shobhit Kumare9fe51c2013-12-10 12:14:55 +053040static void band_gap_reset(struct drm_i915_private *dev_priv)
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +030041{
42 mutex_lock(&dev_priv->dpio_lock);
43
Shobhit Kumare9fe51c2013-12-10 12:14:55 +053044 vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
45 vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
46 vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
47 udelay(150);
48 vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
49 vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +030050
51 mutex_unlock(&dev_priv->dpio_lock);
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +030052}
53
Jani Nikula4e646492013-08-27 15:12:20 +030054static struct intel_dsi *intel_attached_dsi(struct drm_connector *connector)
55{
56 return container_of(intel_attached_encoder(connector),
57 struct intel_dsi, base);
58}
59
60static inline bool is_vid_mode(struct intel_dsi *intel_dsi)
61{
62 return intel_dsi->dev.type == INTEL_DSI_VIDEO_MODE;
63}
64
65static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
66{
67 return intel_dsi->dev.type == INTEL_DSI_COMMAND_MODE;
68}
69
70static void intel_dsi_hot_plug(struct intel_encoder *encoder)
71{
72 DRM_DEBUG_KMS("\n");
73}
74
75static bool intel_dsi_compute_config(struct intel_encoder *encoder,
76 struct intel_crtc_config *config)
77{
78 struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
79 base);
80 struct intel_connector *intel_connector = intel_dsi->attached_connector;
81 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
82 struct drm_display_mode *adjusted_mode = &config->adjusted_mode;
83 struct drm_display_mode *mode = &config->requested_mode;
84
85 DRM_DEBUG_KMS("\n");
86
87 if (fixed_mode)
88 intel_fixed_panel_mode(fixed_mode, adjusted_mode);
89
90 if (intel_dsi->dev.dev_ops->mode_fixup)
91 return intel_dsi->dev.dev_ops->mode_fixup(&intel_dsi->dev,
92 mode, adjusted_mode);
93
94 return true;
95}
96
97static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
98{
99 DRM_DEBUG_KMS("\n");
ymohanmabe4fc042013-08-27 23:40:56 +0300100
101 vlv_enable_dsi_pll(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300102}
103
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530104static void intel_dsi_device_ready(struct intel_encoder *encoder)
105{
106 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
107 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
108 int pipe = intel_crtc->pipe;
109 u32 val;
110
111 DRM_DEBUG_KMS("\n");
112
Shobhit Kumar2095f9f2014-04-09 13:59:30 +0530113 mutex_lock(&dev_priv->dpio_lock);
114 /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
115 * needed everytime after power gate */
116 vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
117 mutex_unlock(&dev_priv->dpio_lock);
118
119 /* bandgap reset is needed after everytime we do power gate */
120 band_gap_reset(dev_priv);
121
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530122 val = I915_READ(MIPI_PORT_CTRL(pipe));
123 I915_WRITE(MIPI_PORT_CTRL(pipe), val | LP_OUTPUT_HOLD);
124 usleep_range(1000, 1500);
125 I915_WRITE(MIPI_DEVICE_READY(pipe), DEVICE_READY | ULPS_STATE_EXIT);
126 usleep_range(2000, 2500);
127 I915_WRITE(MIPI_DEVICE_READY(pipe), DEVICE_READY);
128 usleep_range(2000, 2500);
129 I915_WRITE(MIPI_DEVICE_READY(pipe), 0x00);
130 usleep_range(2000, 2500);
131 I915_WRITE(MIPI_DEVICE_READY(pipe), DEVICE_READY);
132 usleep_range(2000, 2500);
133}
Jani Nikula4e646492013-08-27 15:12:20 +0300134
135static void intel_dsi_enable(struct intel_encoder *encoder)
136{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530137 struct drm_device *dev = encoder->base.dev;
138 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300139 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
140 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
141 int pipe = intel_crtc->pipe;
142 u32 temp;
143
144 DRM_DEBUG_KMS("\n");
145
Jani Nikula4e646492013-08-27 15:12:20 +0300146 if (is_cmd_mode(intel_dsi))
147 I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(pipe), 8 * 4);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530148 else {
Jani Nikula4e646492013-08-27 15:12:20 +0300149 msleep(20); /* XXX */
150 dpi_send_cmd(intel_dsi, TURN_ON);
151 msleep(100);
152
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530153 if (intel_dsi->dev.dev_ops->enable)
154 intel_dsi->dev.dev_ops->enable(&intel_dsi->dev);
155
Jani Nikula4e646492013-08-27 15:12:20 +0300156 /* assert ip_tg_enable signal */
Shobhit Kumarf6da2842013-12-10 12:15:00 +0530157 temp = I915_READ(MIPI_PORT_CTRL(pipe)) & ~LANE_CONFIGURATION_MASK;
158 temp = temp | intel_dsi->port_bits;
Jani Nikula4e646492013-08-27 15:12:20 +0300159 I915_WRITE(MIPI_PORT_CTRL(pipe), temp | DPI_ENABLE);
160 POSTING_READ(MIPI_PORT_CTRL(pipe));
161 }
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530162}
Jani Nikula4e646492013-08-27 15:12:20 +0300163
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530164static void intel_dsi_pre_enable(struct intel_encoder *encoder)
165{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530166 struct drm_device *dev = encoder->base.dev;
167 struct drm_i915_private *dev_priv = dev->dev_private;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530168 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530169 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
170 enum pipe pipe = intel_crtc->pipe;
171 u32 tmp;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530172
173 DRM_DEBUG_KMS("\n");
174
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530175 /* Disable DPOunit clock gating, can stall pipe
176 * and we need DPLL REFA always enabled */
177 tmp = I915_READ(DPLL(pipe));
178 tmp |= DPLL_REFA_CLK_ENABLE_VLV;
179 I915_WRITE(DPLL(pipe), tmp);
180
181 tmp = I915_READ(DSPCLK_GATE_D);
182 tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
183 I915_WRITE(DSPCLK_GATE_D, tmp);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530184
185 /* put device in ready state */
186 intel_dsi_device_ready(encoder);
187
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530188 if (intel_dsi->dev.dev_ops->panel_reset)
189 intel_dsi->dev.dev_ops->panel_reset(&intel_dsi->dev);
190
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530191 if (intel_dsi->dev.dev_ops->send_otp_cmds)
192 intel_dsi->dev.dev_ops->send_otp_cmds(&intel_dsi->dev);
193
194 /* Enable port in pre-enable phase itself because as per hw team
195 * recommendation, port should be enabled befor plane & pipe */
196 intel_dsi_enable(encoder);
197}
198
199static void intel_dsi_enable_nop(struct intel_encoder *encoder)
200{
201 DRM_DEBUG_KMS("\n");
202
203 /* for DSI port enable has to be done before pipe
204 * and plane enable, so port enable is done in
205 * pre_enable phase itself unlike other encoders
206 */
Jani Nikula4e646492013-08-27 15:12:20 +0300207}
208
209static void intel_dsi_disable(struct intel_encoder *encoder)
210{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530211 struct drm_device *dev = encoder->base.dev;
212 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300213 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
214 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
215 int pipe = intel_crtc->pipe;
216 u32 temp;
217
218 DRM_DEBUG_KMS("\n");
219
Jani Nikula4e646492013-08-27 15:12:20 +0300220 if (is_vid_mode(intel_dsi)) {
221 dpi_send_cmd(intel_dsi, SHUTDOWN);
222 msleep(10);
223
224 /* de-assert ip_tg_enable signal */
225 temp = I915_READ(MIPI_PORT_CTRL(pipe));
226 I915_WRITE(MIPI_PORT_CTRL(pipe), temp & ~DPI_ENABLE);
227 POSTING_READ(MIPI_PORT_CTRL(pipe));
228
229 msleep(2);
230 }
231
Shobhit Kumar339023e2014-04-09 13:59:34 +0530232 /* Panel commands can be sent when clock is in LP11 */
233 I915_WRITE(MIPI_DEVICE_READY(pipe), 0x0);
234
235 temp = I915_READ(MIPI_CTRL(pipe));
236 temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
237 I915_WRITE(MIPI_CTRL(pipe), temp |
238 intel_dsi->escape_clk_div <<
239 ESCAPE_CLOCK_DIVIDER_SHIFT);
240
241 I915_WRITE(MIPI_EOT_DISABLE(pipe), CLOCKSTOP);
242
243 temp = I915_READ(MIPI_DSI_FUNC_PRG(pipe));
244 temp &= ~VID_MODE_FORMAT_MASK;
245 I915_WRITE(MIPI_DSI_FUNC_PRG(pipe), temp);
246
247 I915_WRITE(MIPI_DEVICE_READY(pipe), 0x1);
248
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530249 /* if disable packets are sent before sending shutdown packet then in
250 * some next enable sequence send turn on packet error is observed */
251 if (intel_dsi->dev.dev_ops->disable)
252 intel_dsi->dev.dev_ops->disable(&intel_dsi->dev);
Jani Nikula4e646492013-08-27 15:12:20 +0300253}
254
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530255static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300256{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530257 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
258 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
259 int pipe = intel_crtc->pipe;
260 u32 val;
261
Jani Nikula4e646492013-08-27 15:12:20 +0300262 DRM_DEBUG_KMS("\n");
ymohanmabe4fc042013-08-27 23:40:56 +0300263
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530264 I915_WRITE(MIPI_DEVICE_READY(pipe), ULPS_STATE_ENTER);
265 usleep_range(2000, 2500);
266
267 I915_WRITE(MIPI_DEVICE_READY(pipe), ULPS_STATE_EXIT);
268 usleep_range(2000, 2500);
269
270 I915_WRITE(MIPI_DEVICE_READY(pipe), ULPS_STATE_ENTER);
271 usleep_range(2000, 2500);
272
273 val = I915_READ(MIPI_PORT_CTRL(pipe));
274 I915_WRITE(MIPI_PORT_CTRL(pipe), val & ~LP_OUTPUT_HOLD);
275 usleep_range(1000, 1500);
276
277 if (wait_for(((I915_READ(MIPI_PORT_CTRL(pipe)) & AFE_LATCHOUT)
278 == 0x00000), 30))
279 DRM_ERROR("DSI LP not going Low\n");
280
281 I915_WRITE(MIPI_DEVICE_READY(pipe), 0x00);
282 usleep_range(2000, 2500);
283
ymohanmabe4fc042013-08-27 23:40:56 +0300284 vlv_disable_dsi_pll(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300285}
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530286
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530287static void intel_dsi_post_disable(struct intel_encoder *encoder)
288{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530289 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530290 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530291 u32 val;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530292
293 DRM_DEBUG_KMS("\n");
294
295 intel_dsi_clear_device_ready(encoder);
296
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530297 val = I915_READ(DSPCLK_GATE_D);
298 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
299 I915_WRITE(DSPCLK_GATE_D, val);
300
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530301 if (intel_dsi->dev.dev_ops->disable_panel_power)
302 intel_dsi->dev.dev_ops->disable_panel_power(&intel_dsi->dev);
303}
Jani Nikula4e646492013-08-27 15:12:20 +0300304
305static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
306 enum pipe *pipe)
307{
308 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Imre Deak6d129be2014-03-05 16:20:54 +0200309 enum intel_display_power_domain power_domain;
Jani Nikula4e646492013-08-27 15:12:20 +0300310 u32 port, func;
311 enum pipe p;
312
313 DRM_DEBUG_KMS("\n");
314
Imre Deak6d129be2014-03-05 16:20:54 +0200315 power_domain = intel_display_port_power_domain(encoder);
316 if (!intel_display_power_enabled(dev_priv, power_domain))
317 return false;
318
Jani Nikula4e646492013-08-27 15:12:20 +0300319 /* XXX: this only works for one DSI output */
320 for (p = PIPE_A; p <= PIPE_B; p++) {
321 port = I915_READ(MIPI_PORT_CTRL(p));
322 func = I915_READ(MIPI_DSI_FUNC_PRG(p));
323
324 if ((port & DPI_ENABLE) || (func & CMD_MODE_DATA_WIDTH_MASK)) {
325 if (I915_READ(MIPI_DEVICE_READY(p)) & DEVICE_READY) {
326 *pipe = p;
327 return true;
328 }
329 }
330 }
331
332 return false;
333}
334
335static void intel_dsi_get_config(struct intel_encoder *encoder,
336 struct intel_crtc_config *pipe_config)
337{
338 DRM_DEBUG_KMS("\n");
339
340 /* XXX: read flags, set to adjusted_mode */
341}
342
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000343static enum drm_mode_status
344intel_dsi_mode_valid(struct drm_connector *connector,
345 struct drm_display_mode *mode)
Jani Nikula4e646492013-08-27 15:12:20 +0300346{
347 struct intel_connector *intel_connector = to_intel_connector(connector);
348 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
349 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
350
351 DRM_DEBUG_KMS("\n");
352
353 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
354 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
355 return MODE_NO_DBLESCAN;
356 }
357
358 if (fixed_mode) {
359 if (mode->hdisplay > fixed_mode->hdisplay)
360 return MODE_PANEL;
361 if (mode->vdisplay > fixed_mode->vdisplay)
362 return MODE_PANEL;
363 }
364
365 return intel_dsi->dev.dev_ops->mode_valid(&intel_dsi->dev, mode);
366}
367
368/* return txclkesc cycles in terms of divider and duration in us */
369static u16 txclkesc(u32 divider, unsigned int us)
370{
371 switch (divider) {
372 case ESCAPE_CLOCK_DIVIDER_1:
373 default:
374 return 20 * us;
375 case ESCAPE_CLOCK_DIVIDER_2:
376 return 10 * us;
377 case ESCAPE_CLOCK_DIVIDER_4:
378 return 5 * us;
379 }
380}
381
382/* return pixels in terms of txbyteclkhs */
383static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count)
384{
385 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp, 8), lane_count);
386}
387
388static void set_dsi_timings(struct drm_encoder *encoder,
389 const struct drm_display_mode *mode)
390{
391 struct drm_device *dev = encoder->dev;
392 struct drm_i915_private *dev_priv = dev->dev_private;
393 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
394 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
395 int pipe = intel_crtc->pipe;
396 unsigned int bpp = intel_crtc->config.pipe_bpp;
397 unsigned int lane_count = intel_dsi->lane_count;
398
399 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
400
401 hactive = mode->hdisplay;
402 hfp = mode->hsync_start - mode->hdisplay;
403 hsync = mode->hsync_end - mode->hsync_start;
404 hbp = mode->htotal - mode->hsync_end;
405
406 vfp = mode->vsync_start - mode->vdisplay;
407 vsync = mode->vsync_end - mode->vsync_start;
408 vbp = mode->vtotal - mode->vsync_end;
409
410 /* horizontal values are in terms of high speed byte clock */
411 hactive = txbyteclkhs(hactive, bpp, lane_count);
412 hfp = txbyteclkhs(hfp, bpp, lane_count);
413 hsync = txbyteclkhs(hsync, bpp, lane_count);
414 hbp = txbyteclkhs(hbp, bpp, lane_count);
415
416 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(pipe), hactive);
417 I915_WRITE(MIPI_HFP_COUNT(pipe), hfp);
418
419 /* meaningful for video mode non-burst sync pulse mode only, can be zero
420 * for non-burst sync events and burst modes */
421 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(pipe), hsync);
422 I915_WRITE(MIPI_HBP_COUNT(pipe), hbp);
423
424 /* vertical values are in terms of lines */
425 I915_WRITE(MIPI_VFP_COUNT(pipe), vfp);
426 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(pipe), vsync);
427 I915_WRITE(MIPI_VBP_COUNT(pipe), vbp);
428}
429
430static void intel_dsi_mode_set(struct intel_encoder *intel_encoder)
431{
432 struct drm_encoder *encoder = &intel_encoder->base;
433 struct drm_device *dev = encoder->dev;
434 struct drm_i915_private *dev_priv = dev->dev_private;
435 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
436 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
437 struct drm_display_mode *adjusted_mode =
438 &intel_crtc->config.adjusted_mode;
439 int pipe = intel_crtc->pipe;
440 unsigned int bpp = intel_crtc->config.pipe_bpp;
441 u32 val, tmp;
442
Damien Lespiau6f2bcce2013-10-16 12:29:54 +0100443 DRM_DEBUG_KMS("pipe %c\n", pipe_name(pipe));
Jani Nikula4e646492013-08-27 15:12:20 +0300444
Jani Nikula4e646492013-08-27 15:12:20 +0300445 /* escape clock divider, 20MHz, shared for A and C. device ready must be
446 * off when doing this! txclkesc? */
447 tmp = I915_READ(MIPI_CTRL(0));
448 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
449 I915_WRITE(MIPI_CTRL(0), tmp | ESCAPE_CLOCK_DIVIDER_1);
450
451 /* read request priority is per pipe */
452 tmp = I915_READ(MIPI_CTRL(pipe));
453 tmp &= ~READ_REQUEST_PRIORITY_MASK;
454 I915_WRITE(MIPI_CTRL(pipe), tmp | READ_REQUEST_PRIORITY_HIGH);
455
456 /* XXX: why here, why like this? handling in irq handler?! */
457 I915_WRITE(MIPI_INTR_STAT(pipe), 0xffffffff);
458 I915_WRITE(MIPI_INTR_EN(pipe), 0xffffffff);
459
Shobhit Kumarf6da2842013-12-10 12:15:00 +0530460 I915_WRITE(MIPI_DPHY_PARAM(pipe), intel_dsi->dphy_reg);
Jani Nikula4e646492013-08-27 15:12:20 +0300461
462 I915_WRITE(MIPI_DPI_RESOLUTION(pipe),
463 adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
464 adjusted_mode->hdisplay << HORIZONTAL_ADDRESS_SHIFT);
465
466 set_dsi_timings(encoder, adjusted_mode);
467
468 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
469 if (is_cmd_mode(intel_dsi)) {
470 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
471 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
472 } else {
473 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
474
475 /* XXX: cross-check bpp vs. pixel format? */
476 val |= intel_dsi->pixel_format;
477 }
478 I915_WRITE(MIPI_DSI_FUNC_PRG(pipe), val);
479
480 /* timeouts for recovery. one frame IIUC. if counter expires, EOT and
481 * stop state. */
482
483 /*
484 * In burst mode, value greater than one DPI line Time in byte clock
485 * (txbyteclkhs) To timeout this timer 1+ of the above said value is
486 * recommended.
487 *
488 * In non-burst mode, Value greater than one DPI frame time in byte
489 * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
490 * is recommended.
491 *
492 * In DBI only mode, value greater than one DBI frame time in byte
493 * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
494 * is recommended.
495 */
496
497 if (is_vid_mode(intel_dsi) &&
498 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
499 I915_WRITE(MIPI_HS_TX_TIMEOUT(pipe),
500 txbyteclkhs(adjusted_mode->htotal, bpp,
501 intel_dsi->lane_count) + 1);
502 } else {
503 I915_WRITE(MIPI_HS_TX_TIMEOUT(pipe),
504 txbyteclkhs(adjusted_mode->vtotal *
505 adjusted_mode->htotal,
506 bpp, intel_dsi->lane_count) + 1);
507 }
Shobhit Kumarf6da2842013-12-10 12:15:00 +0530508 I915_WRITE(MIPI_LP_RX_TIMEOUT(pipe), intel_dsi->lp_rx_timeout);
509 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(pipe), intel_dsi->turn_arnd_val);
510 I915_WRITE(MIPI_DEVICE_RESET_TIMER(pipe), intel_dsi->rst_timer_val);
Jani Nikula4e646492013-08-27 15:12:20 +0300511
512 /* dphy stuff */
513
514 /* in terms of low power clock */
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530515 I915_WRITE(MIPI_INIT_COUNT(pipe), txclkesc(intel_dsi->escape_clk_div, 100));
516
517 val = 0;
518 if (intel_dsi->eotp_pkt == 0)
519 val |= EOT_DISABLE;
520
521 if (intel_dsi->clock_stop)
522 val |= CLOCKSTOP;
Jani Nikula4e646492013-08-27 15:12:20 +0300523
524 /* recovery disables */
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530525 I915_WRITE(MIPI_EOT_DISABLE(pipe), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300526
527 /* in terms of txbyteclkhs. actual high to low switch +
528 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
529 *
530 * XXX: write MIPI_STOP_STATE_STALL?
531 */
Shobhit Kumarf6da2842013-12-10 12:15:00 +0530532 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(pipe),
533 intel_dsi->hs_to_lp_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300534
535 /* XXX: low power clock equivalence in terms of byte clock. the number
536 * of byte clocks occupied in one low power clock. based on txbyteclkhs
537 * and txclkesc. txclkesc time / txbyteclk time * (105 +
538 * MIPI_STOP_STATE_STALL) / 105.???
539 */
Shobhit Kumarf6da2842013-12-10 12:15:00 +0530540 I915_WRITE(MIPI_LP_BYTECLK(pipe), intel_dsi->lp_byte_clk);
Jani Nikula4e646492013-08-27 15:12:20 +0300541
542 /* the bw essential for transmitting 16 long packets containing 252
543 * bytes meant for dcs write memory command is programmed in this
544 * register in terms of byte clocks. based on dsi transfer rate and the
545 * number of lanes configured the time taken to transmit 16 long packets
546 * in a dsi stream varies. */
Shobhit Kumarf6da2842013-12-10 12:15:00 +0530547 I915_WRITE(MIPI_DBI_BW_CTRL(pipe), intel_dsi->bw_timer);
Jani Nikula4e646492013-08-27 15:12:20 +0300548
549 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(pipe),
Shobhit Kumarf6da2842013-12-10 12:15:00 +0530550 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
551 intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
Jani Nikula4e646492013-08-27 15:12:20 +0300552
553 if (is_vid_mode(intel_dsi))
554 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(pipe),
Shobhit Kumarf6da2842013-12-10 12:15:00 +0530555 intel_dsi->video_frmt_cfg_bits |
556 intel_dsi->video_mode_format);
Jani Nikula4e646492013-08-27 15:12:20 +0300557}
558
559static enum drm_connector_status
560intel_dsi_detect(struct drm_connector *connector, bool force)
561{
562 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
Imre Deak671dedd2014-03-05 16:20:53 +0200563 struct intel_encoder *intel_encoder = &intel_dsi->base;
564 enum intel_display_power_domain power_domain;
565 enum drm_connector_status connector_status;
566 struct drm_i915_private *dev_priv = intel_encoder->base.dev->dev_private;
567
Jani Nikula4e646492013-08-27 15:12:20 +0300568 DRM_DEBUG_KMS("\n");
Imre Deak671dedd2014-03-05 16:20:53 +0200569 power_domain = intel_display_port_power_domain(intel_encoder);
570
571 intel_display_power_get(dev_priv, power_domain);
572 connector_status = intel_dsi->dev.dev_ops->detect(&intel_dsi->dev);
573 intel_display_power_put(dev_priv, power_domain);
574
575 return connector_status;
Jani Nikula4e646492013-08-27 15:12:20 +0300576}
577
578static int intel_dsi_get_modes(struct drm_connector *connector)
579{
580 struct intel_connector *intel_connector = to_intel_connector(connector);
581 struct drm_display_mode *mode;
582
583 DRM_DEBUG_KMS("\n");
584
585 if (!intel_connector->panel.fixed_mode) {
586 DRM_DEBUG_KMS("no fixed mode\n");
587 return 0;
588 }
589
590 mode = drm_mode_duplicate(connector->dev,
591 intel_connector->panel.fixed_mode);
592 if (!mode) {
593 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
594 return 0;
595 }
596
597 drm_mode_probed_add(connector, mode);
598 return 1;
599}
600
601static void intel_dsi_destroy(struct drm_connector *connector)
602{
603 struct intel_connector *intel_connector = to_intel_connector(connector);
604
605 DRM_DEBUG_KMS("\n");
606 intel_panel_fini(&intel_connector->panel);
Jani Nikula4e646492013-08-27 15:12:20 +0300607 drm_connector_cleanup(connector);
608 kfree(connector);
609}
610
611static const struct drm_encoder_funcs intel_dsi_funcs = {
612 .destroy = intel_encoder_destroy,
613};
614
615static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
616 .get_modes = intel_dsi_get_modes,
617 .mode_valid = intel_dsi_mode_valid,
618 .best_encoder = intel_best_encoder,
619};
620
621static const struct drm_connector_funcs intel_dsi_connector_funcs = {
622 .dpms = intel_connector_dpms,
623 .detect = intel_dsi_detect,
624 .destroy = intel_dsi_destroy,
625 .fill_modes = drm_helper_probe_single_connector_modes,
626};
627
628bool intel_dsi_init(struct drm_device *dev)
629{
630 struct intel_dsi *intel_dsi;
631 struct intel_encoder *intel_encoder;
632 struct drm_encoder *encoder;
633 struct intel_connector *intel_connector;
634 struct drm_connector *connector;
635 struct drm_display_mode *fixed_mode = NULL;
636 const struct intel_dsi_device *dsi;
637 unsigned int i;
638
639 DRM_DEBUG_KMS("\n");
640
641 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
642 if (!intel_dsi)
643 return false;
644
645 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
646 if (!intel_connector) {
647 kfree(intel_dsi);
648 return false;
649 }
650
651 intel_encoder = &intel_dsi->base;
652 encoder = &intel_encoder->base;
653 intel_dsi->attached_connector = intel_connector;
654
655 connector = &intel_connector->base;
656
657 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
658
659 /* XXX: very likely not all of these are needed */
660 intel_encoder->hot_plug = intel_dsi_hot_plug;
661 intel_encoder->compute_config = intel_dsi_compute_config;
662 intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
663 intel_encoder->pre_enable = intel_dsi_pre_enable;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530664 intel_encoder->enable = intel_dsi_enable_nop;
Jani Nikula4e646492013-08-27 15:12:20 +0300665 intel_encoder->mode_set = intel_dsi_mode_set;
666 intel_encoder->disable = intel_dsi_disable;
667 intel_encoder->post_disable = intel_dsi_post_disable;
668 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
669 intel_encoder->get_config = intel_dsi_get_config;
670
671 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak4932e2c2014-02-11 17:12:48 +0200672 intel_connector->unregister = intel_connector_unregister;
Jani Nikula4e646492013-08-27 15:12:20 +0300673
674 for (i = 0; i < ARRAY_SIZE(intel_dsi_devices); i++) {
675 dsi = &intel_dsi_devices[i];
676 intel_dsi->dev = *dsi;
677
678 if (dsi->dev_ops->init(&intel_dsi->dev))
679 break;
680 }
681
682 if (i == ARRAY_SIZE(intel_dsi_devices)) {
683 DRM_DEBUG_KMS("no device found\n");
684 goto err;
685 }
686
687 intel_encoder->type = INTEL_OUTPUT_DSI;
688 intel_encoder->crtc_mask = (1 << 0); /* XXX */
689
Ville Syrjäläbc079e82014-03-03 16:15:28 +0200690 intel_encoder->cloneable = 0;
Jani Nikula4e646492013-08-27 15:12:20 +0300691 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
692 DRM_MODE_CONNECTOR_DSI);
693
694 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
695
696 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
697 connector->interlace_allowed = false;
698 connector->doublescan_allowed = false;
699
700 intel_connector_attach_encoder(intel_connector, intel_encoder);
701
702 drm_sysfs_connector_add(connector);
703
704 fixed_mode = dsi->dev_ops->get_modes(&intel_dsi->dev);
705 if (!fixed_mode) {
706 DRM_DEBUG_KMS("no fixed mode\n");
707 goto err;
708 }
709
710 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Vandana Kannan4b6ed682014-02-11 14:26:36 +0530711 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
Jani Nikula4e646492013-08-27 15:12:20 +0300712
713 return true;
714
715err:
716 drm_encoder_cleanup(&intel_encoder->base);
717 kfree(intel_dsi);
718 kfree(intel_connector);
719
720 return false;
721}