blob: 94865eb22c930d71a77dd54bd5f6bac67704a791 [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[] = {
Shobhit Kumar2ab8b452014-05-23 21:35:27 +053038 {
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 },
Jani Nikula4e646492013-08-27 15:12:20 +030043};
44
Jani Nikula3b1808b2015-01-16 14:27:18 +020045static void wait_for_dsi_fifo_empty(struct intel_dsi *intel_dsi)
46{
47 struct drm_encoder *encoder = &intel_dsi->base.base;
48 struct drm_device *dev = encoder->dev;
49 struct drm_i915_private *dev_priv = dev->dev_private;
50 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
51 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
52 u32 mask;
53
54 mask = LP_CTRL_FIFO_EMPTY | HS_CTRL_FIFO_EMPTY |
55 LP_DATA_FIFO_EMPTY | HS_DATA_FIFO_EMPTY;
56
57 if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & mask) == mask, 100))
58 DRM_ERROR("DPI FIFOs are not empty\n");
59}
60
Shobhit Kumare9fe51c2013-12-10 12:14:55 +053061static void band_gap_reset(struct drm_i915_private *dev_priv)
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +030062{
63 mutex_lock(&dev_priv->dpio_lock);
64
Shobhit Kumare9fe51c2013-12-10 12:14:55 +053065 vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
66 vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
67 vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
68 udelay(150);
69 vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
70 vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +030071
72 mutex_unlock(&dev_priv->dpio_lock);
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +030073}
74
Jani Nikula4e646492013-08-27 15:12:20 +030075static struct intel_dsi *intel_attached_dsi(struct drm_connector *connector)
76{
77 return container_of(intel_attached_encoder(connector),
78 struct intel_dsi, base);
79}
80
81static inline bool is_vid_mode(struct intel_dsi *intel_dsi)
82{
Shobhit Kumardfba2e22014-04-14 11:18:24 +053083 return intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE;
Jani Nikula4e646492013-08-27 15:12:20 +030084}
85
86static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
87{
Shobhit Kumardfba2e22014-04-14 11:18:24 +053088 return intel_dsi->operation_mode == INTEL_DSI_COMMAND_MODE;
Jani Nikula4e646492013-08-27 15:12:20 +030089}
90
91static void intel_dsi_hot_plug(struct intel_encoder *encoder)
92{
93 DRM_DEBUG_KMS("\n");
94}
95
96static bool intel_dsi_compute_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020097 struct intel_crtc_state *config)
Jani Nikula4e646492013-08-27 15:12:20 +030098{
99 struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
100 base);
101 struct intel_connector *intel_connector = intel_dsi->attached_connector;
102 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200103 struct drm_display_mode *adjusted_mode = &config->base.adjusted_mode;
104 struct drm_display_mode *mode = &config->base.mode;
Jani Nikula4e646492013-08-27 15:12:20 +0300105
106 DRM_DEBUG_KMS("\n");
107
108 if (fixed_mode)
109 intel_fixed_panel_mode(fixed_mode, adjusted_mode);
110
Shobhit Kumarf573de52014-07-30 20:32:37 +0530111 /* DSI uses short packets for sync events, so clear mode flags for DSI */
112 adjusted_mode->flags = 0;
113
Jani Nikula4e646492013-08-27 15:12:20 +0300114 if (intel_dsi->dev.dev_ops->mode_fixup)
115 return intel_dsi->dev.dev_ops->mode_fixup(&intel_dsi->dev,
116 mode, adjusted_mode);
117
118 return true;
119}
120
Gaurav K Singh5505a242014-12-04 10:58:47 +0530121static void intel_dsi_port_enable(struct intel_encoder *encoder)
122{
123 struct drm_device *dev = encoder->base.dev;
124 struct drm_i915_private *dev_priv = dev->dev_private;
125 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
126 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Gaurav K Singh369602d2014-12-05 14:09:28 +0530127 enum port port;
Gaurav K Singh5505a242014-12-04 10:58:47 +0530128 u32 temp;
129
Gaurav K Singha9da9bc2014-12-05 14:13:41 +0530130 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
131 temp = I915_READ(VLV_CHICKEN_3);
132 temp &= ~PIXEL_OVERLAP_CNT_MASK |
133 intel_dsi->pixel_overlap <<
134 PIXEL_OVERLAP_CNT_SHIFT;
135 I915_WRITE(VLV_CHICKEN_3, temp);
136 }
137
Gaurav K Singh369602d2014-12-05 14:09:28 +0530138 for_each_dsi_port(port, intel_dsi->ports) {
139 temp = I915_READ(MIPI_PORT_CTRL(port));
140 temp &= ~LANE_CONFIGURATION_MASK;
141 temp &= ~DUAL_LINK_MODE_MASK;
142
143 if (intel_dsi->ports == ((1 << PORT_A) | (1 << PORT_C))) {
144 temp |= (intel_dsi->dual_link - 1)
145 << DUAL_LINK_MODE_SHIFT;
146 temp |= intel_crtc->pipe ?
147 LANE_CONFIGURATION_DUAL_LINK_B :
148 LANE_CONFIGURATION_DUAL_LINK_A;
149 }
150 /* assert ip_tg_enable signal */
151 I915_WRITE(MIPI_PORT_CTRL(port), temp | DPI_ENABLE);
152 POSTING_READ(MIPI_PORT_CTRL(port));
153 }
Gaurav K Singh5505a242014-12-04 10:58:47 +0530154}
155
156static void intel_dsi_port_disable(struct intel_encoder *encoder)
157{
158 struct drm_device *dev = encoder->base.dev;
159 struct drm_i915_private *dev_priv = dev->dev_private;
Gaurav K Singh369602d2014-12-05 14:09:28 +0530160 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
161 enum port port;
Gaurav K Singh5505a242014-12-04 10:58:47 +0530162 u32 temp;
163
Gaurav K Singh369602d2014-12-05 14:09:28 +0530164 for_each_dsi_port(port, intel_dsi->ports) {
165 /* de-assert ip_tg_enable signal */
166 temp = I915_READ(MIPI_PORT_CTRL(port));
167 I915_WRITE(MIPI_PORT_CTRL(port), temp & ~DPI_ENABLE);
168 POSTING_READ(MIPI_PORT_CTRL(port));
169 }
Gaurav K Singh5505a242014-12-04 10:58:47 +0530170}
171
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530172static void intel_dsi_device_ready(struct intel_encoder *encoder)
173{
174 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530175 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
176 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530177 u32 val;
178
179 DRM_DEBUG_KMS("\n");
180
Shobhit Kumar2095f9f2014-04-09 13:59:30 +0530181 mutex_lock(&dev_priv->dpio_lock);
182 /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
183 * needed everytime after power gate */
184 vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
185 mutex_unlock(&dev_priv->dpio_lock);
186
187 /* bandgap reset is needed after everytime we do power gate */
188 band_gap_reset(dev_priv);
189
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530190 for_each_dsi_port(port, intel_dsi->ports) {
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530191
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530192 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
193 usleep_range(2500, 3000);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530194
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530195 val = I915_READ(MIPI_PORT_CTRL(port));
Gaurav K Singhbf344e82014-12-07 16:13:54 +0530196
197 /* Enable MIPI PHY transparent latch
198 * Common bit for both MIPI Port A & MIPI Port C
199 * No similar bit in MIPI Port C reg
200 */
201 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD);
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530202 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530203
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530204 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
205 usleep_range(2500, 3000);
206
207 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
208 usleep_range(2500, 3000);
209 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530210}
Jani Nikula4e646492013-08-27 15:12:20 +0300211
212static void intel_dsi_enable(struct intel_encoder *encoder)
213{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530214 struct drm_device *dev = encoder->base.dev;
215 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300216 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikula4934b652015-01-22 15:01:35 +0200217 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300218
219 DRM_DEBUG_KMS("\n");
220
Jani Nikula4934b652015-01-22 15:01:35 +0200221 if (is_cmd_mode(intel_dsi)) {
222 for_each_dsi_port(port, intel_dsi->ports)
223 I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
224 } else {
Jani Nikula4e646492013-08-27 15:12:20 +0300225 msleep(20); /* XXX */
Jani Nikulaf03e4172015-01-16 14:27:16 +0200226 for_each_dsi_port(port, intel_dsi->ports)
227 dpi_send_cmd(intel_dsi, TURN_ON, DPI_LP_MODE_EN, port);
Jani Nikula4e646492013-08-27 15:12:20 +0300228 msleep(100);
229
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530230 if (intel_dsi->dev.dev_ops->enable)
231 intel_dsi->dev.dev_ops->enable(&intel_dsi->dev);
232
Shobhit Kumar13813082014-07-12 17:17:22 +0530233 wait_for_dsi_fifo_empty(intel_dsi);
234
Gaurav K Singh5505a242014-12-04 10:58:47 +0530235 intel_dsi_port_enable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300236 }
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530237}
Jani Nikula4e646492013-08-27 15:12:20 +0300238
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530239static void intel_dsi_pre_enable(struct intel_encoder *encoder)
240{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530241 struct drm_device *dev = encoder->base.dev;
242 struct drm_i915_private *dev_priv = dev->dev_private;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530243 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530244 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
245 enum pipe pipe = intel_crtc->pipe;
246 u32 tmp;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530247
248 DRM_DEBUG_KMS("\n");
249
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530250 /* Disable DPOunit clock gating, can stall pipe
251 * and we need DPLL REFA always enabled */
252 tmp = I915_READ(DPLL(pipe));
253 tmp |= DPLL_REFA_CLK_ENABLE_VLV;
254 I915_WRITE(DPLL(pipe), tmp);
255
Shobhit Kumarf573de52014-07-30 20:32:37 +0530256 /* update the hw state for DPLL */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200257 intel_crtc->config->dpll_hw_state.dpll = DPLL_INTEGRATED_CLOCK_VLV |
Daniel Vetter7f3de832014-07-30 22:34:27 +0200258 DPLL_REFA_CLK_ENABLE_VLV;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530259
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530260 tmp = I915_READ(DSPCLK_GATE_D);
261 tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
262 I915_WRITE(DSPCLK_GATE_D, tmp);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530263
264 /* put device in ready state */
265 intel_dsi_device_ready(encoder);
266
Shobhit Kumardf38e652014-04-14 11:18:26 +0530267 msleep(intel_dsi->panel_on_delay);
268
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530269 if (intel_dsi->dev.dev_ops->panel_reset)
270 intel_dsi->dev.dev_ops->panel_reset(&intel_dsi->dev);
271
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530272 if (intel_dsi->dev.dev_ops->send_otp_cmds)
273 intel_dsi->dev.dev_ops->send_otp_cmds(&intel_dsi->dev);
274
Shobhit Kumar13813082014-07-12 17:17:22 +0530275 wait_for_dsi_fifo_empty(intel_dsi);
276
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530277 /* Enable port in pre-enable phase itself because as per hw team
278 * recommendation, port should be enabled befor plane & pipe */
279 intel_dsi_enable(encoder);
280}
281
282static void intel_dsi_enable_nop(struct intel_encoder *encoder)
283{
284 DRM_DEBUG_KMS("\n");
285
286 /* for DSI port enable has to be done before pipe
287 * and plane enable, so port enable is done in
288 * pre_enable phase itself unlike other encoders
289 */
Jani Nikula4e646492013-08-27 15:12:20 +0300290}
291
Imre Deakc315faf2014-05-27 19:00:09 +0300292static void intel_dsi_pre_disable(struct intel_encoder *encoder)
293{
294 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikulaf03e4172015-01-16 14:27:16 +0200295 enum port port;
Imre Deakc315faf2014-05-27 19:00:09 +0300296
297 DRM_DEBUG_KMS("\n");
298
299 if (is_vid_mode(intel_dsi)) {
300 /* Send Shutdown command to the panel in LP mode */
Jani Nikulaf03e4172015-01-16 14:27:16 +0200301 for_each_dsi_port(port, intel_dsi->ports)
302 dpi_send_cmd(intel_dsi, SHUTDOWN, DPI_LP_MODE_EN, port);
Imre Deakc315faf2014-05-27 19:00:09 +0300303 msleep(10);
304 }
305}
306
Jani Nikula4e646492013-08-27 15:12:20 +0300307static void intel_dsi_disable(struct intel_encoder *encoder)
308{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530309 struct drm_device *dev = encoder->base.dev;
310 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300311 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530312 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300313 u32 temp;
314
315 DRM_DEBUG_KMS("\n");
316
Jani Nikula4e646492013-08-27 15:12:20 +0300317 if (is_vid_mode(intel_dsi)) {
Shobhit Kumar13813082014-07-12 17:17:22 +0530318 wait_for_dsi_fifo_empty(intel_dsi);
319
Gaurav K Singh5505a242014-12-04 10:58:47 +0530320 intel_dsi_port_disable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300321 msleep(2);
322 }
323
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530324 for_each_dsi_port(port, intel_dsi->ports) {
325 /* Panel commands can be sent when clock is in LP11 */
326 I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530327
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530328 temp = I915_READ(MIPI_CTRL(port));
329 temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
330 I915_WRITE(MIPI_CTRL(port), temp |
331 intel_dsi->escape_clk_div <<
332 ESCAPE_CLOCK_DIVIDER_SHIFT);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530333
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530334 I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530335
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530336 temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
337 temp &= ~VID_MODE_FORMAT_MASK;
338 I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530339
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530340 I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
341 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530342 /* if disable packets are sent before sending shutdown packet then in
343 * some next enable sequence send turn on packet error is observed */
344 if (intel_dsi->dev.dev_ops->disable)
345 intel_dsi->dev.dev_ops->disable(&intel_dsi->dev);
Shobhit Kumar13813082014-07-12 17:17:22 +0530346
347 wait_for_dsi_fifo_empty(intel_dsi);
Jani Nikula4e646492013-08-27 15:12:20 +0300348}
349
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530350static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300351{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530352 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530353 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
354 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530355 u32 val;
356
Jani Nikula4e646492013-08-27 15:12:20 +0300357 DRM_DEBUG_KMS("\n");
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530358 for_each_dsi_port(port, intel_dsi->ports) {
ymohanmabe4fc042013-08-27 23:40:56 +0300359
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530360 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
361 ULPS_STATE_ENTER);
362 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530363
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530364 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
365 ULPS_STATE_EXIT);
366 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530367
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530368 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
369 ULPS_STATE_ENTER);
370 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530371
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530372 /* Wait till Clock lanes are in LP-00 state for MIPI Port A
373 * only. MIPI Port C has no similar bit for checking
374 */
375 if (wait_for(((I915_READ(MIPI_PORT_CTRL(PORT_A)) & AFE_LATCHOUT)
376 == 0x00000), 30))
377 DRM_ERROR("DSI LP not going Low\n");
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530378
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530379 val = I915_READ(MIPI_PORT_CTRL(port));
380 /* Disable MIPI PHY transparent latch
381 * Common bit for both MIPI Port A & MIPI Port C
382 */
383 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val & ~LP_OUTPUT_HOLD);
384 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530385
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530386 I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
387 usleep_range(2000, 2500);
388 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530389
ymohanmabe4fc042013-08-27 23:40:56 +0300390 vlv_disable_dsi_pll(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300391}
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530392
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530393static void intel_dsi_post_disable(struct intel_encoder *encoder)
394{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530395 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530396 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530397 u32 val;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530398
399 DRM_DEBUG_KMS("\n");
400
Imre Deakc315faf2014-05-27 19:00:09 +0300401 intel_dsi_disable(encoder);
402
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530403 intel_dsi_clear_device_ready(encoder);
404
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530405 val = I915_READ(DSPCLK_GATE_D);
406 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
407 I915_WRITE(DSPCLK_GATE_D, val);
408
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530409 if (intel_dsi->dev.dev_ops->disable_panel_power)
410 intel_dsi->dev.dev_ops->disable_panel_power(&intel_dsi->dev);
Shobhit Kumardf38e652014-04-14 11:18:26 +0530411
412 msleep(intel_dsi->panel_off_delay);
413 msleep(intel_dsi->panel_pwr_cycle_delay);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530414}
Jani Nikula4e646492013-08-27 15:12:20 +0300415
416static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
417 enum pipe *pipe)
418{
419 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530420 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
421 struct drm_device *dev = encoder->base.dev;
Imre Deak6d129be2014-03-05 16:20:54 +0200422 enum intel_display_power_domain power_domain;
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530423 u32 dpi_enabled, func;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200424 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300425
426 DRM_DEBUG_KMS("\n");
427
Imre Deak6d129be2014-03-05 16:20:54 +0200428 power_domain = intel_display_port_power_domain(encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200429 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200430 return false;
431
Jani Nikula4e646492013-08-27 15:12:20 +0300432 /* XXX: this only works for one DSI output */
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530433 for_each_dsi_port(port, intel_dsi->ports) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200434 func = I915_READ(MIPI_DSI_FUNC_PRG(port));
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530435 dpi_enabled = I915_READ(MIPI_PORT_CTRL(port)) &
436 DPI_ENABLE;
Jani Nikula4e646492013-08-27 15:12:20 +0300437
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530438 /* Due to some hardware limitations on BYT, MIPI Port C DPI
439 * Enable bit does not get set. To check whether DSI Port C
440 * was enabled in BIOS, check the Pipe B enable bit
441 */
442 if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) &&
443 (port == PORT_C))
444 dpi_enabled = I915_READ(PIPECONF(PIPE_B)) &
445 PIPECONF_ENABLE;
446
447 if (dpi_enabled || (func & CMD_MODE_DATA_WIDTH_MASK)) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200448 if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530449 *pipe = port == PORT_A ? PIPE_A : PIPE_B;
Jani Nikula4e646492013-08-27 15:12:20 +0300450 return true;
451 }
452 }
453 }
454
455 return false;
456}
457
458static void intel_dsi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200459 struct intel_crtc_state *pipe_config)
Jani Nikula4e646492013-08-27 15:12:20 +0300460{
Shobhit Kumarf573de52014-07-30 20:32:37 +0530461 u32 pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300462 DRM_DEBUG_KMS("\n");
463
Shobhit Kumarf573de52014-07-30 20:32:37 +0530464 /*
465 * DPLL_MD is not used in case of DSI, reading will get some default value
466 * set dpll_md = 0
467 */
468 pipe_config->dpll_hw_state.dpll_md = 0;
469
470 pclk = vlv_get_dsi_pclk(encoder, pipe_config->pipe_bpp);
471 if (!pclk)
472 return;
473
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200474 pipe_config->base.adjusted_mode.crtc_clock = pclk;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530475 pipe_config->port_clock = pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300476}
477
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000478static enum drm_mode_status
479intel_dsi_mode_valid(struct drm_connector *connector,
480 struct drm_display_mode *mode)
Jani Nikula4e646492013-08-27 15:12:20 +0300481{
482 struct intel_connector *intel_connector = to_intel_connector(connector);
483 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
484 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
485
486 DRM_DEBUG_KMS("\n");
487
488 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
489 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
490 return MODE_NO_DBLESCAN;
491 }
492
493 if (fixed_mode) {
494 if (mode->hdisplay > fixed_mode->hdisplay)
495 return MODE_PANEL;
496 if (mode->vdisplay > fixed_mode->vdisplay)
497 return MODE_PANEL;
498 }
499
500 return intel_dsi->dev.dev_ops->mode_valid(&intel_dsi->dev, mode);
501}
502
503/* return txclkesc cycles in terms of divider and duration in us */
504static u16 txclkesc(u32 divider, unsigned int us)
505{
506 switch (divider) {
507 case ESCAPE_CLOCK_DIVIDER_1:
508 default:
509 return 20 * us;
510 case ESCAPE_CLOCK_DIVIDER_2:
511 return 10 * us;
512 case ESCAPE_CLOCK_DIVIDER_4:
513 return 5 * us;
514 }
515}
516
517/* return pixels in terms of txbyteclkhs */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530518static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
519 u16 burst_mode_ratio)
Jani Nikula4e646492013-08-27 15:12:20 +0300520{
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530521 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200522 8 * 100), lane_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300523}
524
525static void set_dsi_timings(struct drm_encoder *encoder,
526 const struct drm_display_mode *mode)
527{
528 struct drm_device *dev = encoder->dev;
529 struct drm_i915_private *dev_priv = dev->dev_private;
530 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
531 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530532 enum port port;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200533 unsigned int bpp = intel_crtc->config->pipe_bpp;
Jani Nikula4e646492013-08-27 15:12:20 +0300534 unsigned int lane_count = intel_dsi->lane_count;
535
536 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
537
538 hactive = mode->hdisplay;
539 hfp = mode->hsync_start - mode->hdisplay;
540 hsync = mode->hsync_end - mode->hsync_start;
541 hbp = mode->htotal - mode->hsync_end;
542
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530543 if (intel_dsi->dual_link) {
544 hactive /= 2;
545 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
546 hactive += intel_dsi->pixel_overlap;
547 hfp /= 2;
548 hsync /= 2;
549 hbp /= 2;
550 }
551
Jani Nikula4e646492013-08-27 15:12:20 +0300552 vfp = mode->vsync_start - mode->vdisplay;
553 vsync = mode->vsync_end - mode->vsync_start;
554 vbp = mode->vtotal - mode->vsync_end;
555
556 /* horizontal values are in terms of high speed byte clock */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530557 hactive = txbyteclkhs(hactive, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200558 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530559 hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
560 hsync = txbyteclkhs(hsync, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200561 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530562 hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
Jani Nikula4e646492013-08-27 15:12:20 +0300563
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530564 for_each_dsi_port(port, intel_dsi->ports) {
565 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
566 I915_WRITE(MIPI_HFP_COUNT(port), hfp);
Jani Nikula4e646492013-08-27 15:12:20 +0300567
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530568 /* meaningful for video mode non-burst sync pulse mode only,
569 * can be zero for non-burst sync events and burst modes */
570 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
571 I915_WRITE(MIPI_HBP_COUNT(port), hbp);
Jani Nikula4e646492013-08-27 15:12:20 +0300572
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530573 /* vertical values are in terms of lines */
574 I915_WRITE(MIPI_VFP_COUNT(port), vfp);
575 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
576 I915_WRITE(MIPI_VBP_COUNT(port), vbp);
577 }
Jani Nikula4e646492013-08-27 15:12:20 +0300578}
579
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200580static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300581{
582 struct drm_encoder *encoder = &intel_encoder->base;
583 struct drm_device *dev = encoder->dev;
584 struct drm_i915_private *dev_priv = dev->dev_private;
585 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
586 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
587 struct drm_display_mode *adjusted_mode =
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200588 &intel_crtc->config->base.adjusted_mode;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530589 enum port port;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200590 unsigned int bpp = intel_crtc->config->pipe_bpp;
Jani Nikula4e646492013-08-27 15:12:20 +0300591 u32 val, tmp;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530592 u16 mode_hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300593
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200594 DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
Jani Nikula4e646492013-08-27 15:12:20 +0300595
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530596 mode_hdisplay = adjusted_mode->hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300597
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530598 if (intel_dsi->dual_link) {
599 mode_hdisplay /= 2;
600 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
601 mode_hdisplay += intel_dsi->pixel_overlap;
602 }
Jani Nikula4e646492013-08-27 15:12:20 +0300603
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530604 for_each_dsi_port(port, intel_dsi->ports) {
605 /* escape clock divider, 20MHz, shared for A and C.
606 * device ready must be off when doing this! txclkesc? */
607 tmp = I915_READ(MIPI_CTRL(PORT_A));
608 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
609 I915_WRITE(MIPI_CTRL(PORT_A), tmp | ESCAPE_CLOCK_DIVIDER_1);
Jani Nikula4e646492013-08-27 15:12:20 +0300610
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530611 /* read request priority is per pipe */
612 tmp = I915_READ(MIPI_CTRL(port));
613 tmp &= ~READ_REQUEST_PRIORITY_MASK;
614 I915_WRITE(MIPI_CTRL(port), tmp | READ_REQUEST_PRIORITY_HIGH);
Jani Nikula4e646492013-08-27 15:12:20 +0300615
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530616 /* XXX: why here, why like this? handling in irq handler?! */
617 I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
618 I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
619
620 I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
621
622 I915_WRITE(MIPI_DPI_RESOLUTION(port),
623 adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
624 mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
625 }
Jani Nikula4e646492013-08-27 15:12:20 +0300626
627 set_dsi_timings(encoder, adjusted_mode);
628
629 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
630 if (is_cmd_mode(intel_dsi)) {
631 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
632 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
633 } else {
634 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
635
636 /* XXX: cross-check bpp vs. pixel format? */
637 val |= intel_dsi->pixel_format;
638 }
Jani Nikula4e646492013-08-27 15:12:20 +0300639
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530640 tmp = 0;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530641 if (intel_dsi->eotp_pkt == 0)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530642 tmp |= EOT_DISABLE;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530643 if (intel_dsi->clock_stop)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530644 tmp |= CLOCKSTOP;
Jani Nikula4e646492013-08-27 15:12:20 +0300645
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530646 for_each_dsi_port(port, intel_dsi->ports) {
647 I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300648
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530649 /* timeouts for recovery. one frame IIUC. if counter expires,
650 * EOT and stop state. */
Shobhit Kumarcf4dbd22014-04-14 11:18:25 +0530651
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530652 /*
653 * In burst mode, value greater than one DPI line Time in byte
654 * clock (txbyteclkhs) To timeout this timer 1+ of the above
655 * said value is recommended.
656 *
657 * In non-burst mode, Value greater than one DPI frame time in
658 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
659 * said value is recommended.
660 *
661 * In DBI only mode, value greater than one DBI frame time in
662 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
663 * said value is recommended.
664 */
Jani Nikula4e646492013-08-27 15:12:20 +0300665
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530666 if (is_vid_mode(intel_dsi) &&
667 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
668 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
669 txbyteclkhs(adjusted_mode->htotal, bpp,
670 intel_dsi->lane_count,
671 intel_dsi->burst_mode_ratio) + 1);
672 } else {
673 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
674 txbyteclkhs(adjusted_mode->vtotal *
675 adjusted_mode->htotal,
676 bpp, intel_dsi->lane_count,
677 intel_dsi->burst_mode_ratio) + 1);
678 }
679 I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
680 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
681 intel_dsi->turn_arnd_val);
682 I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
683 intel_dsi->rst_timer_val);
Jani Nikula4e646492013-08-27 15:12:20 +0300684
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530685 /* dphy stuff */
Jani Nikula4e646492013-08-27 15:12:20 +0300686
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530687 /* in terms of low power clock */
688 I915_WRITE(MIPI_INIT_COUNT(port),
689 txclkesc(intel_dsi->escape_clk_div, 100));
Jani Nikula4e646492013-08-27 15:12:20 +0300690
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530691
692 /* recovery disables */
693 I915_WRITE(MIPI_EOT_DISABLE(port), val);
694
695 /* in terms of low power clock */
696 I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
697
698 /* in terms of txbyteclkhs. actual high to low switch +
699 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
700 *
701 * XXX: write MIPI_STOP_STATE_STALL?
702 */
703 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
704 intel_dsi->hs_to_lp_count);
705
706 /* XXX: low power clock equivalence in terms of byte clock.
707 * the number of byte clocks occupied in one low power clock.
708 * based on txbyteclkhs and txclkesc.
709 * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
710 * ) / 105.???
711 */
712 I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
713
714 /* the bw essential for transmitting 16 long packets containing
715 * 252 bytes meant for dcs write memory command is programmed in
716 * this register in terms of byte clocks. based on dsi transfer
717 * rate and the number of lanes configured the time taken to
718 * transmit 16 long packets in a dsi stream varies. */
719 I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
720
721 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
722 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
723 intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
724
725 if (is_vid_mode(intel_dsi))
726 /* Some panels might have resolution which is not a
727 * multiple of 64 like 1366 x 768. Enable RANDOM
728 * resolution support for such panels by default */
729 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
730 intel_dsi->video_frmt_cfg_bits |
731 intel_dsi->video_mode_format |
732 IP_TG_CONFIG |
733 RANDOM_DPI_DISPLAY_RESOLUTION);
734 }
Jani Nikula4e646492013-08-27 15:12:20 +0300735}
736
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200737static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
738{
739 DRM_DEBUG_KMS("\n");
740
741 intel_dsi_prepare(encoder);
742
743 vlv_enable_dsi_pll(encoder);
744}
745
Jani Nikula4e646492013-08-27 15:12:20 +0300746static enum drm_connector_status
747intel_dsi_detect(struct drm_connector *connector, bool force)
748{
749 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
Imre Deak671dedd2014-03-05 16:20:53 +0200750 struct intel_encoder *intel_encoder = &intel_dsi->base;
751 enum intel_display_power_domain power_domain;
752 enum drm_connector_status connector_status;
753 struct drm_i915_private *dev_priv = intel_encoder->base.dev->dev_private;
754
Jani Nikula4e646492013-08-27 15:12:20 +0300755 DRM_DEBUG_KMS("\n");
Imre Deak671dedd2014-03-05 16:20:53 +0200756 power_domain = intel_display_port_power_domain(intel_encoder);
757
758 intel_display_power_get(dev_priv, power_domain);
759 connector_status = intel_dsi->dev.dev_ops->detect(&intel_dsi->dev);
760 intel_display_power_put(dev_priv, power_domain);
761
762 return connector_status;
Jani Nikula4e646492013-08-27 15:12:20 +0300763}
764
765static int intel_dsi_get_modes(struct drm_connector *connector)
766{
767 struct intel_connector *intel_connector = to_intel_connector(connector);
768 struct drm_display_mode *mode;
769
770 DRM_DEBUG_KMS("\n");
771
772 if (!intel_connector->panel.fixed_mode) {
773 DRM_DEBUG_KMS("no fixed mode\n");
774 return 0;
775 }
776
777 mode = drm_mode_duplicate(connector->dev,
778 intel_connector->panel.fixed_mode);
779 if (!mode) {
780 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
781 return 0;
782 }
783
784 drm_mode_probed_add(connector, mode);
785 return 1;
786}
787
788static void intel_dsi_destroy(struct drm_connector *connector)
789{
790 struct intel_connector *intel_connector = to_intel_connector(connector);
791
792 DRM_DEBUG_KMS("\n");
793 intel_panel_fini(&intel_connector->panel);
Jani Nikula4e646492013-08-27 15:12:20 +0300794 drm_connector_cleanup(connector);
795 kfree(connector);
796}
797
798static const struct drm_encoder_funcs intel_dsi_funcs = {
799 .destroy = intel_encoder_destroy,
800};
801
802static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
803 .get_modes = intel_dsi_get_modes,
804 .mode_valid = intel_dsi_mode_valid,
805 .best_encoder = intel_best_encoder,
806};
807
808static const struct drm_connector_funcs intel_dsi_connector_funcs = {
809 .dpms = intel_connector_dpms,
810 .detect = intel_dsi_detect,
811 .destroy = intel_dsi_destroy,
812 .fill_modes = drm_helper_probe_single_connector_modes,
813};
814
Damien Lespiau4328633d2014-05-28 12:30:56 +0100815void intel_dsi_init(struct drm_device *dev)
Jani Nikula4e646492013-08-27 15:12:20 +0300816{
817 struct intel_dsi *intel_dsi;
818 struct intel_encoder *intel_encoder;
819 struct drm_encoder *encoder;
820 struct intel_connector *intel_connector;
821 struct drm_connector *connector;
822 struct drm_display_mode *fixed_mode = NULL;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530823 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300824 const struct intel_dsi_device *dsi;
825 unsigned int i;
826
827 DRM_DEBUG_KMS("\n");
828
Shobhit Kumar3e6bd012014-05-27 19:33:59 +0530829 /* There is no detection method for MIPI so rely on VBT */
830 if (!dev_priv->vbt.has_mipi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100831 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300832
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530833 if (IS_VALLEYVIEW(dev)) {
834 dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
835 } else {
836 DRM_ERROR("Unsupported Mipi device to reg base");
Christoph Jaeger868d6652014-06-13 21:51:22 +0200837 return;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530838 }
839
Jani Nikula4e646492013-08-27 15:12:20 +0300840 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
841 if (!intel_dsi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100842 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300843
844 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
845 if (!intel_connector) {
846 kfree(intel_dsi);
Damien Lespiau4328633d2014-05-28 12:30:56 +0100847 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300848 }
849
850 intel_encoder = &intel_dsi->base;
851 encoder = &intel_encoder->base;
852 intel_dsi->attached_connector = intel_connector;
853
Jani Nikula4e646492013-08-27 15:12:20 +0300854 connector = &intel_connector->base;
855
856 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
857
858 /* XXX: very likely not all of these are needed */
859 intel_encoder->hot_plug = intel_dsi_hot_plug;
860 intel_encoder->compute_config = intel_dsi_compute_config;
861 intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
862 intel_encoder->pre_enable = intel_dsi_pre_enable;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530863 intel_encoder->enable = intel_dsi_enable_nop;
Imre Deakc315faf2014-05-27 19:00:09 +0300864 intel_encoder->disable = intel_dsi_pre_disable;
Jani Nikula4e646492013-08-27 15:12:20 +0300865 intel_encoder->post_disable = intel_dsi_post_disable;
866 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
867 intel_encoder->get_config = intel_dsi_get_config;
868
869 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak4932e2c2014-02-11 17:12:48 +0200870 intel_connector->unregister = intel_connector_unregister;
Jani Nikula4e646492013-08-27 15:12:20 +0300871
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200872 /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
Jani Nikula17af40a2014-11-14 16:54:22 +0200873 if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200874 intel_encoder->crtc_mask = (1 << PIPE_A);
Jani Nikula17af40a2014-11-14 16:54:22 +0200875 intel_dsi->ports = (1 << PORT_A);
876 } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200877 intel_encoder->crtc_mask = (1 << PIPE_B);
Jani Nikula17af40a2014-11-14 16:54:22 +0200878 intel_dsi->ports = (1 << PORT_C);
879 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200880
Jani Nikula4e646492013-08-27 15:12:20 +0300881 for (i = 0; i < ARRAY_SIZE(intel_dsi_devices); i++) {
882 dsi = &intel_dsi_devices[i];
883 intel_dsi->dev = *dsi;
884
885 if (dsi->dev_ops->init(&intel_dsi->dev))
886 break;
887 }
888
889 if (i == ARRAY_SIZE(intel_dsi_devices)) {
890 DRM_DEBUG_KMS("no device found\n");
891 goto err;
892 }
893
894 intel_encoder->type = INTEL_OUTPUT_DSI;
Ville Syrjäläbc079e82014-03-03 16:15:28 +0200895 intel_encoder->cloneable = 0;
Jani Nikula4e646492013-08-27 15:12:20 +0300896 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
897 DRM_MODE_CONNECTOR_DSI);
898
899 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
900
901 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
902 connector->interlace_allowed = false;
903 connector->doublescan_allowed = false;
904
905 intel_connector_attach_encoder(intel_connector, intel_encoder);
906
Thomas Wood34ea3d32014-05-29 16:57:41 +0100907 drm_connector_register(connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300908
909 fixed_mode = dsi->dev_ops->get_modes(&intel_dsi->dev);
910 if (!fixed_mode) {
911 DRM_DEBUG_KMS("no fixed mode\n");
912 goto err;
913 }
914
915 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Vandana Kannan4b6ed682014-02-11 14:26:36 +0530916 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
Jani Nikula4e646492013-08-27 15:12:20 +0300917
Damien Lespiau4328633d2014-05-28 12:30:56 +0100918 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300919
920err:
921 drm_encoder_cleanup(&intel_encoder->base);
922 kfree(intel_dsi);
923 kfree(intel_connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300924}