blob: e20bb1f8879cc10a39dcba4e2385fc0ed0f78bb9 [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>
Matt Roperc6f95f22015-01-22 16:50:32 -080027#include <drm/drm_atomic_helper.h>
Jani Nikula4e646492013-08-27 15:12:20 +030028#include <drm/drm_crtc.h>
29#include <drm/drm_edid.h>
30#include <drm/i915_drm.h>
31#include <linux/slab.h>
32#include "i915_drv.h"
33#include "intel_drv.h"
34#include "intel_dsi.h"
35#include "intel_dsi_cmd.h"
36
37/* the sub-encoders aka panel drivers */
38static const struct intel_dsi_device intel_dsi_devices[] = {
Shobhit Kumar2ab8b452014-05-23 21:35:27 +053039 {
40 .panel_id = MIPI_DSI_GENERIC_PANEL_ID,
41 .name = "vbt-generic-dsi-vid-mode-display",
42 .dev_ops = &vbt_generic_dsi_display_ops,
43 },
Jani Nikula4e646492013-08-27 15:12:20 +030044};
45
Jani Nikula7f6a6a42015-01-16 14:27:19 +020046static void wait_for_dsi_fifo_empty(struct intel_dsi *intel_dsi, enum port port)
Jani Nikula3b1808b2015-01-16 14:27:18 +020047{
48 struct drm_encoder *encoder = &intel_dsi->base.base;
49 struct drm_device *dev = encoder->dev;
50 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula3b1808b2015-01-16 14:27:18 +020051 u32 mask;
52
53 mask = LP_CTRL_FIFO_EMPTY | HS_CTRL_FIFO_EMPTY |
54 LP_DATA_FIFO_EMPTY | HS_DATA_FIFO_EMPTY;
55
56 if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & mask) == mask, 100))
57 DRM_ERROR("DPI FIFOs are not empty\n");
58}
59
Shobhit Kumare9fe51c2013-12-10 12:14:55 +053060static void band_gap_reset(struct drm_i915_private *dev_priv)
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +030061{
62 mutex_lock(&dev_priv->dpio_lock);
63
Shobhit Kumare9fe51c2013-12-10 12:14:55 +053064 vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
65 vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
66 vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
67 udelay(150);
68 vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
69 vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +030070
71 mutex_unlock(&dev_priv->dpio_lock);
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +030072}
73
Jani Nikula4e646492013-08-27 15:12:20 +030074static inline bool is_vid_mode(struct intel_dsi *intel_dsi)
75{
Shobhit Kumardfba2e22014-04-14 11:18:24 +053076 return intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE;
Jani Nikula4e646492013-08-27 15:12:20 +030077}
78
79static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
80{
Shobhit Kumardfba2e22014-04-14 11:18:24 +053081 return intel_dsi->operation_mode == INTEL_DSI_COMMAND_MODE;
Jani Nikula4e646492013-08-27 15:12:20 +030082}
83
84static void intel_dsi_hot_plug(struct intel_encoder *encoder)
85{
86 DRM_DEBUG_KMS("\n");
87}
88
89static bool intel_dsi_compute_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020090 struct intel_crtc_state *config)
Jani Nikula4e646492013-08-27 15:12:20 +030091{
92 struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
93 base);
94 struct intel_connector *intel_connector = intel_dsi->attached_connector;
95 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020096 struct drm_display_mode *adjusted_mode = &config->base.adjusted_mode;
Jani Nikula4e646492013-08-27 15:12:20 +030097
98 DRM_DEBUG_KMS("\n");
99
100 if (fixed_mode)
101 intel_fixed_panel_mode(fixed_mode, adjusted_mode);
102
Shobhit Kumarf573de52014-07-30 20:32:37 +0530103 /* DSI uses short packets for sync events, so clear mode flags for DSI */
104 adjusted_mode->flags = 0;
105
Jani Nikula4e646492013-08-27 15:12:20 +0300106 return true;
107}
108
Gaurav K Singh5505a242014-12-04 10:58:47 +0530109static void intel_dsi_port_enable(struct intel_encoder *encoder)
110{
111 struct drm_device *dev = encoder->base.dev;
112 struct drm_i915_private *dev_priv = dev->dev_private;
113 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
114 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Gaurav K Singh369602d2014-12-05 14:09:28 +0530115 enum port port;
Gaurav K Singh5505a242014-12-04 10:58:47 +0530116 u32 temp;
117
Gaurav K Singha9da9bc2014-12-05 14:13:41 +0530118 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
119 temp = I915_READ(VLV_CHICKEN_3);
120 temp &= ~PIXEL_OVERLAP_CNT_MASK |
121 intel_dsi->pixel_overlap <<
122 PIXEL_OVERLAP_CNT_SHIFT;
123 I915_WRITE(VLV_CHICKEN_3, temp);
124 }
125
Gaurav K Singh369602d2014-12-05 14:09:28 +0530126 for_each_dsi_port(port, intel_dsi->ports) {
127 temp = I915_READ(MIPI_PORT_CTRL(port));
128 temp &= ~LANE_CONFIGURATION_MASK;
129 temp &= ~DUAL_LINK_MODE_MASK;
130
131 if (intel_dsi->ports == ((1 << PORT_A) | (1 << PORT_C))) {
132 temp |= (intel_dsi->dual_link - 1)
133 << DUAL_LINK_MODE_SHIFT;
134 temp |= intel_crtc->pipe ?
135 LANE_CONFIGURATION_DUAL_LINK_B :
136 LANE_CONFIGURATION_DUAL_LINK_A;
137 }
138 /* assert ip_tg_enable signal */
139 I915_WRITE(MIPI_PORT_CTRL(port), temp | DPI_ENABLE);
140 POSTING_READ(MIPI_PORT_CTRL(port));
141 }
Gaurav K Singh5505a242014-12-04 10:58:47 +0530142}
143
144static void intel_dsi_port_disable(struct intel_encoder *encoder)
145{
146 struct drm_device *dev = encoder->base.dev;
147 struct drm_i915_private *dev_priv = dev->dev_private;
Gaurav K Singh369602d2014-12-05 14:09:28 +0530148 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
149 enum port port;
Gaurav K Singh5505a242014-12-04 10:58:47 +0530150 u32 temp;
151
Gaurav K Singh369602d2014-12-05 14:09:28 +0530152 for_each_dsi_port(port, intel_dsi->ports) {
153 /* de-assert ip_tg_enable signal */
154 temp = I915_READ(MIPI_PORT_CTRL(port));
155 I915_WRITE(MIPI_PORT_CTRL(port), temp & ~DPI_ENABLE);
156 POSTING_READ(MIPI_PORT_CTRL(port));
157 }
Gaurav K Singh5505a242014-12-04 10:58:47 +0530158}
159
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530160static void intel_dsi_device_ready(struct intel_encoder *encoder)
161{
162 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530163 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
164 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530165 u32 val;
166
167 DRM_DEBUG_KMS("\n");
168
Shobhit Kumar2095f9f2014-04-09 13:59:30 +0530169 mutex_lock(&dev_priv->dpio_lock);
170 /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
171 * needed everytime after power gate */
172 vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
173 mutex_unlock(&dev_priv->dpio_lock);
174
175 /* bandgap reset is needed after everytime we do power gate */
176 band_gap_reset(dev_priv);
177
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530178 for_each_dsi_port(port, intel_dsi->ports) {
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530179
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530180 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
181 usleep_range(2500, 3000);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530182
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530183 val = I915_READ(MIPI_PORT_CTRL(port));
Gaurav K Singhbf344e82014-12-07 16:13:54 +0530184
185 /* Enable MIPI PHY transparent latch
186 * Common bit for both MIPI Port A & MIPI Port C
187 * No similar bit in MIPI Port C reg
188 */
189 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD);
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530190 usleep_range(1000, 1500);
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_EXIT);
193 usleep_range(2500, 3000);
194
195 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
196 usleep_range(2500, 3000);
197 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530198}
Jani Nikula4e646492013-08-27 15:12:20 +0300199
200static void intel_dsi_enable(struct intel_encoder *encoder)
201{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530202 struct drm_device *dev = encoder->base.dev;
203 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300204 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikula4934b652015-01-22 15:01:35 +0200205 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300206
207 DRM_DEBUG_KMS("\n");
208
Jani Nikula4934b652015-01-22 15:01:35 +0200209 if (is_cmd_mode(intel_dsi)) {
210 for_each_dsi_port(port, intel_dsi->ports)
211 I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
212 } else {
Jani Nikula4e646492013-08-27 15:12:20 +0300213 msleep(20); /* XXX */
Jani Nikulaf03e4172015-01-16 14:27:16 +0200214 for_each_dsi_port(port, intel_dsi->ports)
215 dpi_send_cmd(intel_dsi, TURN_ON, DPI_LP_MODE_EN, port);
Jani Nikula4e646492013-08-27 15:12:20 +0300216 msleep(100);
217
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530218 if (intel_dsi->dev.dev_ops->enable)
219 intel_dsi->dev.dev_ops->enable(&intel_dsi->dev);
220
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200221 for_each_dsi_port(port, intel_dsi->ports)
222 wait_for_dsi_fifo_empty(intel_dsi, port);
Shobhit Kumar13813082014-07-12 17:17:22 +0530223
Gaurav K Singh5505a242014-12-04 10:58:47 +0530224 intel_dsi_port_enable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300225 }
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530226}
Jani Nikula4e646492013-08-27 15:12:20 +0300227
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530228static void intel_dsi_pre_enable(struct intel_encoder *encoder)
229{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530230 struct drm_device *dev = encoder->base.dev;
231 struct drm_i915_private *dev_priv = dev->dev_private;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530232 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530233 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
234 enum pipe pipe = intel_crtc->pipe;
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200235 enum port port;
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530236 u32 tmp;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530237
238 DRM_DEBUG_KMS("\n");
239
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530240 /* Disable DPOunit clock gating, can stall pipe
241 * and we need DPLL REFA always enabled */
242 tmp = I915_READ(DPLL(pipe));
243 tmp |= DPLL_REFA_CLK_ENABLE_VLV;
244 I915_WRITE(DPLL(pipe), tmp);
245
Shobhit Kumarf573de52014-07-30 20:32:37 +0530246 /* update the hw state for DPLL */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200247 intel_crtc->config->dpll_hw_state.dpll = DPLL_INTEGRATED_CLOCK_VLV |
Daniel Vetter7f3de832014-07-30 22:34:27 +0200248 DPLL_REFA_CLK_ENABLE_VLV;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530249
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530250 tmp = I915_READ(DSPCLK_GATE_D);
251 tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
252 I915_WRITE(DSPCLK_GATE_D, tmp);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530253
254 /* put device in ready state */
255 intel_dsi_device_ready(encoder);
256
Shobhit Kumardf38e652014-04-14 11:18:26 +0530257 msleep(intel_dsi->panel_on_delay);
258
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530259 if (intel_dsi->dev.dev_ops->panel_reset)
260 intel_dsi->dev.dev_ops->panel_reset(&intel_dsi->dev);
261
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200262 for_each_dsi_port(port, intel_dsi->ports)
263 wait_for_dsi_fifo_empty(intel_dsi, port);
Shobhit Kumar13813082014-07-12 17:17:22 +0530264
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530265 /* Enable port in pre-enable phase itself because as per hw team
266 * recommendation, port should be enabled befor plane & pipe */
267 intel_dsi_enable(encoder);
268}
269
270static void intel_dsi_enable_nop(struct intel_encoder *encoder)
271{
272 DRM_DEBUG_KMS("\n");
273
274 /* for DSI port enable has to be done before pipe
275 * and plane enable, so port enable is done in
276 * pre_enable phase itself unlike other encoders
277 */
Jani Nikula4e646492013-08-27 15:12:20 +0300278}
279
Imre Deakc315faf2014-05-27 19:00:09 +0300280static void intel_dsi_pre_disable(struct intel_encoder *encoder)
281{
282 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikulaf03e4172015-01-16 14:27:16 +0200283 enum port port;
Imre Deakc315faf2014-05-27 19:00:09 +0300284
285 DRM_DEBUG_KMS("\n");
286
287 if (is_vid_mode(intel_dsi)) {
288 /* Send Shutdown command to the panel in LP mode */
Jani Nikulaf03e4172015-01-16 14:27:16 +0200289 for_each_dsi_port(port, intel_dsi->ports)
290 dpi_send_cmd(intel_dsi, SHUTDOWN, DPI_LP_MODE_EN, port);
Imre Deakc315faf2014-05-27 19:00:09 +0300291 msleep(10);
292 }
293}
294
Jani Nikula4e646492013-08-27 15:12:20 +0300295static void intel_dsi_disable(struct intel_encoder *encoder)
296{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530297 struct drm_device *dev = encoder->base.dev;
298 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300299 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530300 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300301 u32 temp;
302
303 DRM_DEBUG_KMS("\n");
304
Jani Nikula4e646492013-08-27 15:12:20 +0300305 if (is_vid_mode(intel_dsi)) {
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200306 for_each_dsi_port(port, intel_dsi->ports)
307 wait_for_dsi_fifo_empty(intel_dsi, port);
Shobhit Kumar13813082014-07-12 17:17:22 +0530308
Gaurav K Singh5505a242014-12-04 10:58:47 +0530309 intel_dsi_port_disable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300310 msleep(2);
311 }
312
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530313 for_each_dsi_port(port, intel_dsi->ports) {
314 /* Panel commands can be sent when clock is in LP11 */
315 I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530316
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530317 temp = I915_READ(MIPI_CTRL(port));
318 temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
319 I915_WRITE(MIPI_CTRL(port), temp |
320 intel_dsi->escape_clk_div <<
321 ESCAPE_CLOCK_DIVIDER_SHIFT);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530322
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530323 I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530324
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530325 temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
326 temp &= ~VID_MODE_FORMAT_MASK;
327 I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530328
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530329 I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
330 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530331 /* if disable packets are sent before sending shutdown packet then in
332 * some next enable sequence send turn on packet error is observed */
333 if (intel_dsi->dev.dev_ops->disable)
334 intel_dsi->dev.dev_ops->disable(&intel_dsi->dev);
Shobhit Kumar13813082014-07-12 17:17:22 +0530335
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200336 for_each_dsi_port(port, intel_dsi->ports)
337 wait_for_dsi_fifo_empty(intel_dsi, port);
Jani Nikula4e646492013-08-27 15:12:20 +0300338}
339
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530340static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300341{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530342 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530343 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
344 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530345 u32 val;
346
Jani Nikula4e646492013-08-27 15:12:20 +0300347 DRM_DEBUG_KMS("\n");
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530348 for_each_dsi_port(port, intel_dsi->ports) {
ymohanmabe4fc042013-08-27 23:40:56 +0300349
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530350 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
351 ULPS_STATE_ENTER);
352 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530353
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530354 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
355 ULPS_STATE_EXIT);
356 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530357
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530358 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
359 ULPS_STATE_ENTER);
360 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530361
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530362 /* Wait till Clock lanes are in LP-00 state for MIPI Port A
363 * only. MIPI Port C has no similar bit for checking
364 */
365 if (wait_for(((I915_READ(MIPI_PORT_CTRL(PORT_A)) & AFE_LATCHOUT)
366 == 0x00000), 30))
367 DRM_ERROR("DSI LP not going Low\n");
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530368
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530369 val = I915_READ(MIPI_PORT_CTRL(port));
370 /* Disable MIPI PHY transparent latch
371 * Common bit for both MIPI Port A & MIPI Port C
372 */
373 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val & ~LP_OUTPUT_HOLD);
374 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530375
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530376 I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
377 usleep_range(2000, 2500);
378 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530379
ymohanmabe4fc042013-08-27 23:40:56 +0300380 vlv_disable_dsi_pll(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300381}
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530382
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530383static void intel_dsi_post_disable(struct intel_encoder *encoder)
384{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530385 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530386 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530387 u32 val;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530388
389 DRM_DEBUG_KMS("\n");
390
Imre Deakc315faf2014-05-27 19:00:09 +0300391 intel_dsi_disable(encoder);
392
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530393 intel_dsi_clear_device_ready(encoder);
394
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530395 val = I915_READ(DSPCLK_GATE_D);
396 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
397 I915_WRITE(DSPCLK_GATE_D, val);
398
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530399 if (intel_dsi->dev.dev_ops->disable_panel_power)
400 intel_dsi->dev.dev_ops->disable_panel_power(&intel_dsi->dev);
Shobhit Kumardf38e652014-04-14 11:18:26 +0530401
402 msleep(intel_dsi->panel_off_delay);
403 msleep(intel_dsi->panel_pwr_cycle_delay);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530404}
Jani Nikula4e646492013-08-27 15:12:20 +0300405
406static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
407 enum pipe *pipe)
408{
409 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530410 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
411 struct drm_device *dev = encoder->base.dev;
Imre Deak6d129be2014-03-05 16:20:54 +0200412 enum intel_display_power_domain power_domain;
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530413 u32 dpi_enabled, func;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200414 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300415
416 DRM_DEBUG_KMS("\n");
417
Imre Deak6d129be2014-03-05 16:20:54 +0200418 power_domain = intel_display_port_power_domain(encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200419 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200420 return false;
421
Jani Nikula4e646492013-08-27 15:12:20 +0300422 /* XXX: this only works for one DSI output */
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530423 for_each_dsi_port(port, intel_dsi->ports) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200424 func = I915_READ(MIPI_DSI_FUNC_PRG(port));
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530425 dpi_enabled = I915_READ(MIPI_PORT_CTRL(port)) &
426 DPI_ENABLE;
Jani Nikula4e646492013-08-27 15:12:20 +0300427
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530428 /* Due to some hardware limitations on BYT, MIPI Port C DPI
429 * Enable bit does not get set. To check whether DSI Port C
430 * was enabled in BIOS, check the Pipe B enable bit
431 */
432 if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) &&
433 (port == PORT_C))
434 dpi_enabled = I915_READ(PIPECONF(PIPE_B)) &
435 PIPECONF_ENABLE;
436
437 if (dpi_enabled || (func & CMD_MODE_DATA_WIDTH_MASK)) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200438 if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530439 *pipe = port == PORT_A ? PIPE_A : PIPE_B;
Jani Nikula4e646492013-08-27 15:12:20 +0300440 return true;
441 }
442 }
443 }
444
445 return false;
446}
447
448static void intel_dsi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200449 struct intel_crtc_state *pipe_config)
Jani Nikula4e646492013-08-27 15:12:20 +0300450{
Shobhit Kumarf573de52014-07-30 20:32:37 +0530451 u32 pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300452 DRM_DEBUG_KMS("\n");
453
Shobhit Kumarf573de52014-07-30 20:32:37 +0530454 /*
455 * DPLL_MD is not used in case of DSI, reading will get some default value
456 * set dpll_md = 0
457 */
458 pipe_config->dpll_hw_state.dpll_md = 0;
459
460 pclk = vlv_get_dsi_pclk(encoder, pipe_config->pipe_bpp);
461 if (!pclk)
462 return;
463
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200464 pipe_config->base.adjusted_mode.crtc_clock = pclk;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530465 pipe_config->port_clock = pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300466}
467
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000468static enum drm_mode_status
469intel_dsi_mode_valid(struct drm_connector *connector,
470 struct drm_display_mode *mode)
Jani Nikula4e646492013-08-27 15:12:20 +0300471{
472 struct intel_connector *intel_connector = to_intel_connector(connector);
473 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Jani Nikula4e646492013-08-27 15:12:20 +0300474
475 DRM_DEBUG_KMS("\n");
476
477 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
478 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
479 return MODE_NO_DBLESCAN;
480 }
481
482 if (fixed_mode) {
483 if (mode->hdisplay > fixed_mode->hdisplay)
484 return MODE_PANEL;
485 if (mode->vdisplay > fixed_mode->vdisplay)
486 return MODE_PANEL;
487 }
488
Jani Nikula36d21f42015-01-16 14:27:20 +0200489 return MODE_OK;
Jani Nikula4e646492013-08-27 15:12:20 +0300490}
491
492/* return txclkesc cycles in terms of divider and duration in us */
493static u16 txclkesc(u32 divider, unsigned int us)
494{
495 switch (divider) {
496 case ESCAPE_CLOCK_DIVIDER_1:
497 default:
498 return 20 * us;
499 case ESCAPE_CLOCK_DIVIDER_2:
500 return 10 * us;
501 case ESCAPE_CLOCK_DIVIDER_4:
502 return 5 * us;
503 }
504}
505
506/* return pixels in terms of txbyteclkhs */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530507static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
508 u16 burst_mode_ratio)
Jani Nikula4e646492013-08-27 15:12:20 +0300509{
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530510 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200511 8 * 100), lane_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300512}
513
514static void set_dsi_timings(struct drm_encoder *encoder,
515 const struct drm_display_mode *mode)
516{
517 struct drm_device *dev = encoder->dev;
518 struct drm_i915_private *dev_priv = dev->dev_private;
519 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
520 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530521 enum port port;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200522 unsigned int bpp = intel_crtc->config->pipe_bpp;
Jani Nikula4e646492013-08-27 15:12:20 +0300523 unsigned int lane_count = intel_dsi->lane_count;
524
525 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
526
527 hactive = mode->hdisplay;
528 hfp = mode->hsync_start - mode->hdisplay;
529 hsync = mode->hsync_end - mode->hsync_start;
530 hbp = mode->htotal - mode->hsync_end;
531
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530532 if (intel_dsi->dual_link) {
533 hactive /= 2;
534 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
535 hactive += intel_dsi->pixel_overlap;
536 hfp /= 2;
537 hsync /= 2;
538 hbp /= 2;
539 }
540
Jani Nikula4e646492013-08-27 15:12:20 +0300541 vfp = mode->vsync_start - mode->vdisplay;
542 vsync = mode->vsync_end - mode->vsync_start;
543 vbp = mode->vtotal - mode->vsync_end;
544
545 /* horizontal values are in terms of high speed byte clock */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530546 hactive = txbyteclkhs(hactive, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200547 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530548 hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
549 hsync = txbyteclkhs(hsync, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200550 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530551 hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
Jani Nikula4e646492013-08-27 15:12:20 +0300552
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530553 for_each_dsi_port(port, intel_dsi->ports) {
554 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
555 I915_WRITE(MIPI_HFP_COUNT(port), hfp);
Jani Nikula4e646492013-08-27 15:12:20 +0300556
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530557 /* meaningful for video mode non-burst sync pulse mode only,
558 * can be zero for non-burst sync events and burst modes */
559 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
560 I915_WRITE(MIPI_HBP_COUNT(port), hbp);
Jani Nikula4e646492013-08-27 15:12:20 +0300561
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530562 /* vertical values are in terms of lines */
563 I915_WRITE(MIPI_VFP_COUNT(port), vfp);
564 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
565 I915_WRITE(MIPI_VBP_COUNT(port), vbp);
566 }
Jani Nikula4e646492013-08-27 15:12:20 +0300567}
568
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200569static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300570{
571 struct drm_encoder *encoder = &intel_encoder->base;
572 struct drm_device *dev = encoder->dev;
573 struct drm_i915_private *dev_priv = dev->dev_private;
574 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
575 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
576 struct drm_display_mode *adjusted_mode =
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200577 &intel_crtc->config->base.adjusted_mode;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530578 enum port port;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200579 unsigned int bpp = intel_crtc->config->pipe_bpp;
Jani Nikula4e646492013-08-27 15:12:20 +0300580 u32 val, tmp;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530581 u16 mode_hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300582
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200583 DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
Jani Nikula4e646492013-08-27 15:12:20 +0300584
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530585 mode_hdisplay = adjusted_mode->hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300586
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530587 if (intel_dsi->dual_link) {
588 mode_hdisplay /= 2;
589 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
590 mode_hdisplay += intel_dsi->pixel_overlap;
591 }
Jani Nikula4e646492013-08-27 15:12:20 +0300592
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530593 for_each_dsi_port(port, intel_dsi->ports) {
594 /* escape clock divider, 20MHz, shared for A and C.
595 * device ready must be off when doing this! txclkesc? */
596 tmp = I915_READ(MIPI_CTRL(PORT_A));
597 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
598 I915_WRITE(MIPI_CTRL(PORT_A), tmp | ESCAPE_CLOCK_DIVIDER_1);
Jani Nikula4e646492013-08-27 15:12:20 +0300599
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530600 /* read request priority is per pipe */
601 tmp = I915_READ(MIPI_CTRL(port));
602 tmp &= ~READ_REQUEST_PRIORITY_MASK;
603 I915_WRITE(MIPI_CTRL(port), tmp | READ_REQUEST_PRIORITY_HIGH);
Jani Nikula4e646492013-08-27 15:12:20 +0300604
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530605 /* XXX: why here, why like this? handling in irq handler?! */
606 I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
607 I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
608
609 I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
610
611 I915_WRITE(MIPI_DPI_RESOLUTION(port),
612 adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
613 mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
614 }
Jani Nikula4e646492013-08-27 15:12:20 +0300615
616 set_dsi_timings(encoder, adjusted_mode);
617
618 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
619 if (is_cmd_mode(intel_dsi)) {
620 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
621 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
622 } else {
623 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
624
625 /* XXX: cross-check bpp vs. pixel format? */
626 val |= intel_dsi->pixel_format;
627 }
Jani Nikula4e646492013-08-27 15:12:20 +0300628
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530629 tmp = 0;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530630 if (intel_dsi->eotp_pkt == 0)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530631 tmp |= EOT_DISABLE;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530632 if (intel_dsi->clock_stop)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530633 tmp |= CLOCKSTOP;
Jani Nikula4e646492013-08-27 15:12:20 +0300634
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530635 for_each_dsi_port(port, intel_dsi->ports) {
636 I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300637
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530638 /* timeouts for recovery. one frame IIUC. if counter expires,
639 * EOT and stop state. */
Shobhit Kumarcf4dbd22014-04-14 11:18:25 +0530640
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530641 /*
642 * In burst mode, value greater than one DPI line Time in byte
643 * clock (txbyteclkhs) To timeout this timer 1+ of the above
644 * said value is recommended.
645 *
646 * In non-burst mode, Value greater than one DPI frame time in
647 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
648 * said value is recommended.
649 *
650 * In DBI only mode, value greater than one DBI frame time in
651 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
652 * said value is recommended.
653 */
Jani Nikula4e646492013-08-27 15:12:20 +0300654
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530655 if (is_vid_mode(intel_dsi) &&
656 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
657 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
658 txbyteclkhs(adjusted_mode->htotal, bpp,
659 intel_dsi->lane_count,
660 intel_dsi->burst_mode_ratio) + 1);
661 } else {
662 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
663 txbyteclkhs(adjusted_mode->vtotal *
664 adjusted_mode->htotal,
665 bpp, intel_dsi->lane_count,
666 intel_dsi->burst_mode_ratio) + 1);
667 }
668 I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
669 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
670 intel_dsi->turn_arnd_val);
671 I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
672 intel_dsi->rst_timer_val);
Jani Nikula4e646492013-08-27 15:12:20 +0300673
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530674 /* dphy stuff */
Jani Nikula4e646492013-08-27 15:12:20 +0300675
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530676 /* in terms of low power clock */
677 I915_WRITE(MIPI_INIT_COUNT(port),
678 txclkesc(intel_dsi->escape_clk_div, 100));
Jani Nikula4e646492013-08-27 15:12:20 +0300679
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530680
681 /* recovery disables */
682 I915_WRITE(MIPI_EOT_DISABLE(port), val);
683
684 /* in terms of low power clock */
685 I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
686
687 /* in terms of txbyteclkhs. actual high to low switch +
688 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
689 *
690 * XXX: write MIPI_STOP_STATE_STALL?
691 */
692 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
693 intel_dsi->hs_to_lp_count);
694
695 /* XXX: low power clock equivalence in terms of byte clock.
696 * the number of byte clocks occupied in one low power clock.
697 * based on txbyteclkhs and txclkesc.
698 * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
699 * ) / 105.???
700 */
701 I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
702
703 /* the bw essential for transmitting 16 long packets containing
704 * 252 bytes meant for dcs write memory command is programmed in
705 * this register in terms of byte clocks. based on dsi transfer
706 * rate and the number of lanes configured the time taken to
707 * transmit 16 long packets in a dsi stream varies. */
708 I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
709
710 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
711 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
712 intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
713
714 if (is_vid_mode(intel_dsi))
715 /* Some panels might have resolution which is not a
716 * multiple of 64 like 1366 x 768. Enable RANDOM
717 * resolution support for such panels by default */
718 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
719 intel_dsi->video_frmt_cfg_bits |
720 intel_dsi->video_mode_format |
721 IP_TG_CONFIG |
722 RANDOM_DPI_DISPLAY_RESOLUTION);
723 }
Jani Nikula4e646492013-08-27 15:12:20 +0300724}
725
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200726static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
727{
728 DRM_DEBUG_KMS("\n");
729
730 intel_dsi_prepare(encoder);
731
732 vlv_enable_dsi_pll(encoder);
733}
734
Jani Nikula4e646492013-08-27 15:12:20 +0300735static enum drm_connector_status
736intel_dsi_detect(struct drm_connector *connector, bool force)
737{
Jani Nikula36d21f42015-01-16 14:27:20 +0200738 return connector_status_connected;
Jani Nikula4e646492013-08-27 15:12:20 +0300739}
740
741static int intel_dsi_get_modes(struct drm_connector *connector)
742{
743 struct intel_connector *intel_connector = to_intel_connector(connector);
744 struct drm_display_mode *mode;
745
746 DRM_DEBUG_KMS("\n");
747
748 if (!intel_connector->panel.fixed_mode) {
749 DRM_DEBUG_KMS("no fixed mode\n");
750 return 0;
751 }
752
753 mode = drm_mode_duplicate(connector->dev,
754 intel_connector->panel.fixed_mode);
755 if (!mode) {
756 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
757 return 0;
758 }
759
760 drm_mode_probed_add(connector, mode);
761 return 1;
762}
763
764static void intel_dsi_destroy(struct drm_connector *connector)
765{
766 struct intel_connector *intel_connector = to_intel_connector(connector);
767
768 DRM_DEBUG_KMS("\n");
769 intel_panel_fini(&intel_connector->panel);
Jani Nikula4e646492013-08-27 15:12:20 +0300770 drm_connector_cleanup(connector);
771 kfree(connector);
772}
773
774static const struct drm_encoder_funcs intel_dsi_funcs = {
775 .destroy = intel_encoder_destroy,
776};
777
778static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
779 .get_modes = intel_dsi_get_modes,
780 .mode_valid = intel_dsi_mode_valid,
781 .best_encoder = intel_best_encoder,
782};
783
784static const struct drm_connector_funcs intel_dsi_connector_funcs = {
785 .dpms = intel_connector_dpms,
786 .detect = intel_dsi_detect,
787 .destroy = intel_dsi_destroy,
788 .fill_modes = drm_helper_probe_single_connector_modes,
Matt Roperc6f95f22015-01-22 16:50:32 -0800789 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Jani Nikula4e646492013-08-27 15:12:20 +0300790};
791
Damien Lespiau4328633d2014-05-28 12:30:56 +0100792void intel_dsi_init(struct drm_device *dev)
Jani Nikula4e646492013-08-27 15:12:20 +0300793{
794 struct intel_dsi *intel_dsi;
795 struct intel_encoder *intel_encoder;
796 struct drm_encoder *encoder;
797 struct intel_connector *intel_connector;
798 struct drm_connector *connector;
799 struct drm_display_mode *fixed_mode = NULL;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530800 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300801 const struct intel_dsi_device *dsi;
802 unsigned int i;
803
804 DRM_DEBUG_KMS("\n");
805
Shobhit Kumar3e6bd012014-05-27 19:33:59 +0530806 /* There is no detection method for MIPI so rely on VBT */
807 if (!dev_priv->vbt.has_mipi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100808 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300809
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530810 if (IS_VALLEYVIEW(dev)) {
811 dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
812 } else {
813 DRM_ERROR("Unsupported Mipi device to reg base");
Christoph Jaeger868d6652014-06-13 21:51:22 +0200814 return;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530815 }
816
Jani Nikula4e646492013-08-27 15:12:20 +0300817 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
818 if (!intel_dsi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100819 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300820
821 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
822 if (!intel_connector) {
823 kfree(intel_dsi);
Damien Lespiau4328633d2014-05-28 12:30:56 +0100824 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300825 }
826
827 intel_encoder = &intel_dsi->base;
828 encoder = &intel_encoder->base;
829 intel_dsi->attached_connector = intel_connector;
830
Jani Nikula4e646492013-08-27 15:12:20 +0300831 connector = &intel_connector->base;
832
833 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
834
835 /* XXX: very likely not all of these are needed */
836 intel_encoder->hot_plug = intel_dsi_hot_plug;
837 intel_encoder->compute_config = intel_dsi_compute_config;
838 intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
839 intel_encoder->pre_enable = intel_dsi_pre_enable;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530840 intel_encoder->enable = intel_dsi_enable_nop;
Imre Deakc315faf2014-05-27 19:00:09 +0300841 intel_encoder->disable = intel_dsi_pre_disable;
Jani Nikula4e646492013-08-27 15:12:20 +0300842 intel_encoder->post_disable = intel_dsi_post_disable;
843 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
844 intel_encoder->get_config = intel_dsi_get_config;
845
846 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak4932e2c2014-02-11 17:12:48 +0200847 intel_connector->unregister = intel_connector_unregister;
Jani Nikula4e646492013-08-27 15:12:20 +0300848
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200849 /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
Jani Nikula17af40a2014-11-14 16:54:22 +0200850 if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200851 intel_encoder->crtc_mask = (1 << PIPE_A);
Jani Nikula17af40a2014-11-14 16:54:22 +0200852 intel_dsi->ports = (1 << PORT_A);
853 } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200854 intel_encoder->crtc_mask = (1 << PIPE_B);
Jani Nikula17af40a2014-11-14 16:54:22 +0200855 intel_dsi->ports = (1 << PORT_C);
856 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200857
Jani Nikula4e646492013-08-27 15:12:20 +0300858 for (i = 0; i < ARRAY_SIZE(intel_dsi_devices); i++) {
859 dsi = &intel_dsi_devices[i];
860 intel_dsi->dev = *dsi;
861
862 if (dsi->dev_ops->init(&intel_dsi->dev))
863 break;
864 }
865
866 if (i == ARRAY_SIZE(intel_dsi_devices)) {
867 DRM_DEBUG_KMS("no device found\n");
868 goto err;
869 }
870
871 intel_encoder->type = INTEL_OUTPUT_DSI;
Ville Syrjäläbc079e82014-03-03 16:15:28 +0200872 intel_encoder->cloneable = 0;
Jani Nikula4e646492013-08-27 15:12:20 +0300873 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
874 DRM_MODE_CONNECTOR_DSI);
875
876 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
877
878 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
879 connector->interlace_allowed = false;
880 connector->doublescan_allowed = false;
881
882 intel_connector_attach_encoder(intel_connector, intel_encoder);
883
Thomas Wood34ea3d32014-05-29 16:57:41 +0100884 drm_connector_register(connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300885
886 fixed_mode = dsi->dev_ops->get_modes(&intel_dsi->dev);
887 if (!fixed_mode) {
888 DRM_DEBUG_KMS("no fixed mode\n");
889 goto err;
890 }
891
892 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Vandana Kannan4b6ed682014-02-11 14:26:36 +0530893 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
Jani Nikula4e646492013-08-27 15:12:20 +0300894
Damien Lespiau4328633d2014-05-28 12:30:56 +0100895 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300896
897err:
898 drm_encoder_cleanup(&intel_encoder->base);
899 kfree(intel_dsi);
900 kfree(intel_connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300901}