blob: 1e151e00a614778f9fe3650254c9566464d2d5ac [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>
Jani Nikula593e0622015-01-23 15:30:56 +020031#include <drm/drm_panel.h>
Jani Nikula4e646492013-08-27 15:12:20 +030032#include <linux/slab.h>
33#include "i915_drv.h"
34#include "intel_drv.h"
35#include "intel_dsi.h"
36#include "intel_dsi_cmd.h"
37
Jani Nikula593e0622015-01-23 15:30:56 +020038static const struct {
39 u16 panel_id;
40 struct drm_panel * (*init)(struct intel_dsi *intel_dsi, u16 panel_id);
41} intel_dsi_drivers[] = {
Shobhit Kumar2ab8b452014-05-23 21:35:27 +053042 {
43 .panel_id = MIPI_DSI_GENERIC_PANEL_ID,
Jani Nikula593e0622015-01-23 15:30:56 +020044 .init = vbt_panel_init,
Shobhit Kumar2ab8b452014-05-23 21:35:27 +053045 },
Jani Nikula4e646492013-08-27 15:12:20 +030046};
47
Jani Nikula7f6a6a42015-01-16 14:27:19 +020048static void wait_for_dsi_fifo_empty(struct intel_dsi *intel_dsi, enum port port)
Jani Nikula3b1808b2015-01-16 14:27:18 +020049{
50 struct drm_encoder *encoder = &intel_dsi->base.base;
51 struct drm_device *dev = encoder->dev;
52 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula3b1808b2015-01-16 14:27:18 +020053 u32 mask;
54
55 mask = LP_CTRL_FIFO_EMPTY | HS_CTRL_FIFO_EMPTY |
56 LP_DATA_FIFO_EMPTY | HS_DATA_FIFO_EMPTY;
57
58 if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & mask) == mask, 100))
59 DRM_ERROR("DPI FIFOs are not empty\n");
60}
61
Shobhit Kumare9fe51c2013-12-10 12:14:55 +053062static void band_gap_reset(struct drm_i915_private *dev_priv)
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +030063{
64 mutex_lock(&dev_priv->dpio_lock);
65
Shobhit Kumare9fe51c2013-12-10 12:14:55 +053066 vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
67 vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
68 vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
69 udelay(150);
70 vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
71 vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +030072
73 mutex_unlock(&dev_priv->dpio_lock);
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +030074}
75
Jani Nikula4e646492013-08-27 15:12:20 +030076static inline bool is_vid_mode(struct intel_dsi *intel_dsi)
77{
Shobhit Kumardfba2e22014-04-14 11:18:24 +053078 return intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE;
Jani Nikula4e646492013-08-27 15:12:20 +030079}
80
81static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
82{
Shobhit Kumardfba2e22014-04-14 11:18:24 +053083 return intel_dsi->operation_mode == INTEL_DSI_COMMAND_MODE;
Jani Nikula4e646492013-08-27 15:12:20 +030084}
85
86static void intel_dsi_hot_plug(struct intel_encoder *encoder)
87{
88 DRM_DEBUG_KMS("\n");
89}
90
91static bool intel_dsi_compute_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020092 struct intel_crtc_state *config)
Jani Nikula4e646492013-08-27 15:12:20 +030093{
94 struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
95 base);
96 struct intel_connector *intel_connector = intel_dsi->attached_connector;
97 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020098 struct drm_display_mode *adjusted_mode = &config->base.adjusted_mode;
Jani Nikula4e646492013-08-27 15:12:20 +030099
100 DRM_DEBUG_KMS("\n");
101
102 if (fixed_mode)
103 intel_fixed_panel_mode(fixed_mode, adjusted_mode);
104
Shobhit Kumarf573de52014-07-30 20:32:37 +0530105 /* DSI uses short packets for sync events, so clear mode flags for DSI */
106 adjusted_mode->flags = 0;
107
Jani Nikula4e646492013-08-27 15:12:20 +0300108 return true;
109}
110
Gaurav K Singh5505a242014-12-04 10:58:47 +0530111static void intel_dsi_port_enable(struct intel_encoder *encoder)
112{
113 struct drm_device *dev = encoder->base.dev;
114 struct drm_i915_private *dev_priv = dev->dev_private;
115 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
116 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Gaurav K Singh369602d2014-12-05 14:09:28 +0530117 enum port port;
Gaurav K Singh5505a242014-12-04 10:58:47 +0530118 u32 temp;
119
Gaurav K Singha9da9bc2014-12-05 14:13:41 +0530120 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
121 temp = I915_READ(VLV_CHICKEN_3);
122 temp &= ~PIXEL_OVERLAP_CNT_MASK |
123 intel_dsi->pixel_overlap <<
124 PIXEL_OVERLAP_CNT_SHIFT;
125 I915_WRITE(VLV_CHICKEN_3, temp);
126 }
127
Gaurav K Singh369602d2014-12-05 14:09:28 +0530128 for_each_dsi_port(port, intel_dsi->ports) {
129 temp = I915_READ(MIPI_PORT_CTRL(port));
130 temp &= ~LANE_CONFIGURATION_MASK;
131 temp &= ~DUAL_LINK_MODE_MASK;
132
133 if (intel_dsi->ports == ((1 << PORT_A) | (1 << PORT_C))) {
134 temp |= (intel_dsi->dual_link - 1)
135 << DUAL_LINK_MODE_SHIFT;
136 temp |= intel_crtc->pipe ?
137 LANE_CONFIGURATION_DUAL_LINK_B :
138 LANE_CONFIGURATION_DUAL_LINK_A;
139 }
140 /* assert ip_tg_enable signal */
141 I915_WRITE(MIPI_PORT_CTRL(port), temp | DPI_ENABLE);
142 POSTING_READ(MIPI_PORT_CTRL(port));
143 }
Gaurav K Singh5505a242014-12-04 10:58:47 +0530144}
145
146static void intel_dsi_port_disable(struct intel_encoder *encoder)
147{
148 struct drm_device *dev = encoder->base.dev;
149 struct drm_i915_private *dev_priv = dev->dev_private;
Gaurav K Singh369602d2014-12-05 14:09:28 +0530150 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
151 enum port port;
Gaurav K Singh5505a242014-12-04 10:58:47 +0530152 u32 temp;
153
Gaurav K Singh369602d2014-12-05 14:09:28 +0530154 for_each_dsi_port(port, intel_dsi->ports) {
155 /* de-assert ip_tg_enable signal */
156 temp = I915_READ(MIPI_PORT_CTRL(port));
157 I915_WRITE(MIPI_PORT_CTRL(port), temp & ~DPI_ENABLE);
158 POSTING_READ(MIPI_PORT_CTRL(port));
159 }
Gaurav K Singh5505a242014-12-04 10:58:47 +0530160}
161
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530162static void intel_dsi_device_ready(struct intel_encoder *encoder)
163{
164 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530165 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
166 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530167 u32 val;
168
169 DRM_DEBUG_KMS("\n");
170
Shobhit Kumar2095f9f2014-04-09 13:59:30 +0530171 mutex_lock(&dev_priv->dpio_lock);
172 /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
173 * needed everytime after power gate */
174 vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
175 mutex_unlock(&dev_priv->dpio_lock);
176
177 /* bandgap reset is needed after everytime we do power gate */
178 band_gap_reset(dev_priv);
179
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530180 for_each_dsi_port(port, intel_dsi->ports) {
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530181
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530182 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
183 usleep_range(2500, 3000);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530184
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530185 val = I915_READ(MIPI_PORT_CTRL(port));
Gaurav K Singhbf344e82014-12-07 16:13:54 +0530186
187 /* Enable MIPI PHY transparent latch
188 * Common bit for both MIPI Port A & MIPI Port C
189 * No similar bit in MIPI Port C reg
190 */
191 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD);
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530192 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530193
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530194 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
195 usleep_range(2500, 3000);
196
197 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
198 usleep_range(2500, 3000);
199 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530200}
Jani Nikula4e646492013-08-27 15:12:20 +0300201
202static void intel_dsi_enable(struct intel_encoder *encoder)
203{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530204 struct drm_device *dev = encoder->base.dev;
205 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300206 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikula4934b652015-01-22 15:01:35 +0200207 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300208
209 DRM_DEBUG_KMS("\n");
210
Jani Nikula4934b652015-01-22 15:01:35 +0200211 if (is_cmd_mode(intel_dsi)) {
212 for_each_dsi_port(port, intel_dsi->ports)
213 I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
214 } else {
Jani Nikula4e646492013-08-27 15:12:20 +0300215 msleep(20); /* XXX */
Jani Nikulaf03e4172015-01-16 14:27:16 +0200216 for_each_dsi_port(port, intel_dsi->ports)
217 dpi_send_cmd(intel_dsi, TURN_ON, DPI_LP_MODE_EN, port);
Jani Nikula4e646492013-08-27 15:12:20 +0300218 msleep(100);
219
Jani Nikula593e0622015-01-23 15:30:56 +0200220 drm_panel_enable(intel_dsi->panel);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530221
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200222 for_each_dsi_port(port, intel_dsi->ports)
223 wait_for_dsi_fifo_empty(intel_dsi, port);
Shobhit Kumar13813082014-07-12 17:17:22 +0530224
Gaurav K Singh5505a242014-12-04 10:58:47 +0530225 intel_dsi_port_enable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300226 }
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530227}
Jani Nikula4e646492013-08-27 15:12:20 +0300228
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530229static void intel_dsi_pre_enable(struct intel_encoder *encoder)
230{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530231 struct drm_device *dev = encoder->base.dev;
232 struct drm_i915_private *dev_priv = dev->dev_private;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530233 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530234 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
235 enum pipe pipe = intel_crtc->pipe;
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200236 enum port port;
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530237 u32 tmp;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530238
239 DRM_DEBUG_KMS("\n");
240
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530241 /* Disable DPOunit clock gating, can stall pipe
242 * and we need DPLL REFA always enabled */
243 tmp = I915_READ(DPLL(pipe));
244 tmp |= DPLL_REFA_CLK_ENABLE_VLV;
245 I915_WRITE(DPLL(pipe), tmp);
246
Shobhit Kumarf573de52014-07-30 20:32:37 +0530247 /* update the hw state for DPLL */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200248 intel_crtc->config->dpll_hw_state.dpll = DPLL_INTEGRATED_CLOCK_VLV |
Daniel Vetter7f3de832014-07-30 22:34:27 +0200249 DPLL_REFA_CLK_ENABLE_VLV;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530250
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530251 tmp = I915_READ(DSPCLK_GATE_D);
252 tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
253 I915_WRITE(DSPCLK_GATE_D, tmp);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530254
255 /* put device in ready state */
256 intel_dsi_device_ready(encoder);
257
Shobhit Kumardf38e652014-04-14 11:18:26 +0530258 msleep(intel_dsi->panel_on_delay);
259
Jani Nikula593e0622015-01-23 15:30:56 +0200260 drm_panel_prepare(intel_dsi->panel);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530261
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 */
Jani Nikula593e0622015-01-23 15:30:56 +0200333 drm_panel_disable(intel_dsi->panel);
Shobhit Kumar13813082014-07-12 17:17:22 +0530334
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200335 for_each_dsi_port(port, intel_dsi->ports)
336 wait_for_dsi_fifo_empty(intel_dsi, port);
Jani Nikula4e646492013-08-27 15:12:20 +0300337}
338
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530339static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300340{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530341 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530342 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
343 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530344 u32 val;
345
Jani Nikula4e646492013-08-27 15:12:20 +0300346 DRM_DEBUG_KMS("\n");
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530347 for_each_dsi_port(port, intel_dsi->ports) {
ymohanmabe4fc042013-08-27 23:40:56 +0300348
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530349 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
350 ULPS_STATE_ENTER);
351 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530352
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530353 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
354 ULPS_STATE_EXIT);
355 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530356
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530357 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
358 ULPS_STATE_ENTER);
359 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530360
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530361 /* Wait till Clock lanes are in LP-00 state for MIPI Port A
362 * only. MIPI Port C has no similar bit for checking
363 */
364 if (wait_for(((I915_READ(MIPI_PORT_CTRL(PORT_A)) & AFE_LATCHOUT)
365 == 0x00000), 30))
366 DRM_ERROR("DSI LP not going Low\n");
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530367
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530368 val = I915_READ(MIPI_PORT_CTRL(port));
369 /* Disable MIPI PHY transparent latch
370 * Common bit for both MIPI Port A & MIPI Port C
371 */
372 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val & ~LP_OUTPUT_HOLD);
373 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530374
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530375 I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
376 usleep_range(2000, 2500);
377 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530378
ymohanmabe4fc042013-08-27 23:40:56 +0300379 vlv_disable_dsi_pll(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300380}
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530381
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530382static void intel_dsi_post_disable(struct intel_encoder *encoder)
383{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530384 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530385 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530386 u32 val;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530387
388 DRM_DEBUG_KMS("\n");
389
Imre Deakc315faf2014-05-27 19:00:09 +0300390 intel_dsi_disable(encoder);
391
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530392 intel_dsi_clear_device_ready(encoder);
393
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530394 val = I915_READ(DSPCLK_GATE_D);
395 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
396 I915_WRITE(DSPCLK_GATE_D, val);
397
Jani Nikula593e0622015-01-23 15:30:56 +0200398 drm_panel_unprepare(intel_dsi->panel);
Shobhit Kumardf38e652014-04-14 11:18:26 +0530399
400 msleep(intel_dsi->panel_off_delay);
401 msleep(intel_dsi->panel_pwr_cycle_delay);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530402}
Jani Nikula4e646492013-08-27 15:12:20 +0300403
404static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
405 enum pipe *pipe)
406{
407 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530408 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
409 struct drm_device *dev = encoder->base.dev;
Imre Deak6d129be2014-03-05 16:20:54 +0200410 enum intel_display_power_domain power_domain;
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530411 u32 dpi_enabled, func;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200412 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300413
414 DRM_DEBUG_KMS("\n");
415
Imre Deak6d129be2014-03-05 16:20:54 +0200416 power_domain = intel_display_port_power_domain(encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200417 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200418 return false;
419
Jani Nikula4e646492013-08-27 15:12:20 +0300420 /* XXX: this only works for one DSI output */
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530421 for_each_dsi_port(port, intel_dsi->ports) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200422 func = I915_READ(MIPI_DSI_FUNC_PRG(port));
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530423 dpi_enabled = I915_READ(MIPI_PORT_CTRL(port)) &
424 DPI_ENABLE;
Jani Nikula4e646492013-08-27 15:12:20 +0300425
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530426 /* Due to some hardware limitations on BYT, MIPI Port C DPI
427 * Enable bit does not get set. To check whether DSI Port C
428 * was enabled in BIOS, check the Pipe B enable bit
429 */
430 if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) &&
431 (port == PORT_C))
432 dpi_enabled = I915_READ(PIPECONF(PIPE_B)) &
433 PIPECONF_ENABLE;
434
435 if (dpi_enabled || (func & CMD_MODE_DATA_WIDTH_MASK)) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200436 if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530437 *pipe = port == PORT_A ? PIPE_A : PIPE_B;
Jani Nikula4e646492013-08-27 15:12:20 +0300438 return true;
439 }
440 }
441 }
442
443 return false;
444}
445
446static void intel_dsi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200447 struct intel_crtc_state *pipe_config)
Jani Nikula4e646492013-08-27 15:12:20 +0300448{
Shobhit Kumarf573de52014-07-30 20:32:37 +0530449 u32 pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300450 DRM_DEBUG_KMS("\n");
451
Shobhit Kumarf573de52014-07-30 20:32:37 +0530452 /*
453 * DPLL_MD is not used in case of DSI, reading will get some default value
454 * set dpll_md = 0
455 */
456 pipe_config->dpll_hw_state.dpll_md = 0;
457
458 pclk = vlv_get_dsi_pclk(encoder, pipe_config->pipe_bpp);
459 if (!pclk)
460 return;
461
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200462 pipe_config->base.adjusted_mode.crtc_clock = pclk;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530463 pipe_config->port_clock = pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300464}
465
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000466static enum drm_mode_status
467intel_dsi_mode_valid(struct drm_connector *connector,
468 struct drm_display_mode *mode)
Jani Nikula4e646492013-08-27 15:12:20 +0300469{
470 struct intel_connector *intel_connector = to_intel_connector(connector);
471 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Jani Nikula4e646492013-08-27 15:12:20 +0300472
473 DRM_DEBUG_KMS("\n");
474
475 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
476 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
477 return MODE_NO_DBLESCAN;
478 }
479
480 if (fixed_mode) {
481 if (mode->hdisplay > fixed_mode->hdisplay)
482 return MODE_PANEL;
483 if (mode->vdisplay > fixed_mode->vdisplay)
484 return MODE_PANEL;
485 }
486
Jani Nikula36d21f42015-01-16 14:27:20 +0200487 return MODE_OK;
Jani Nikula4e646492013-08-27 15:12:20 +0300488}
489
490/* return txclkesc cycles in terms of divider and duration in us */
491static u16 txclkesc(u32 divider, unsigned int us)
492{
493 switch (divider) {
494 case ESCAPE_CLOCK_DIVIDER_1:
495 default:
496 return 20 * us;
497 case ESCAPE_CLOCK_DIVIDER_2:
498 return 10 * us;
499 case ESCAPE_CLOCK_DIVIDER_4:
500 return 5 * us;
501 }
502}
503
504/* return pixels in terms of txbyteclkhs */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530505static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
506 u16 burst_mode_ratio)
Jani Nikula4e646492013-08-27 15:12:20 +0300507{
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530508 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200509 8 * 100), lane_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300510}
511
512static void set_dsi_timings(struct drm_encoder *encoder,
513 const struct drm_display_mode *mode)
514{
515 struct drm_device *dev = encoder->dev;
516 struct drm_i915_private *dev_priv = dev->dev_private;
517 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
518 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530519 enum port port;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200520 unsigned int bpp = intel_crtc->config->pipe_bpp;
Jani Nikula4e646492013-08-27 15:12:20 +0300521 unsigned int lane_count = intel_dsi->lane_count;
522
523 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
524
525 hactive = mode->hdisplay;
526 hfp = mode->hsync_start - mode->hdisplay;
527 hsync = mode->hsync_end - mode->hsync_start;
528 hbp = mode->htotal - mode->hsync_end;
529
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530530 if (intel_dsi->dual_link) {
531 hactive /= 2;
532 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
533 hactive += intel_dsi->pixel_overlap;
534 hfp /= 2;
535 hsync /= 2;
536 hbp /= 2;
537 }
538
Jani Nikula4e646492013-08-27 15:12:20 +0300539 vfp = mode->vsync_start - mode->vdisplay;
540 vsync = mode->vsync_end - mode->vsync_start;
541 vbp = mode->vtotal - mode->vsync_end;
542
543 /* horizontal values are in terms of high speed byte clock */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530544 hactive = txbyteclkhs(hactive, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200545 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530546 hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
547 hsync = txbyteclkhs(hsync, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200548 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530549 hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
Jani Nikula4e646492013-08-27 15:12:20 +0300550
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530551 for_each_dsi_port(port, intel_dsi->ports) {
552 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
553 I915_WRITE(MIPI_HFP_COUNT(port), hfp);
Jani Nikula4e646492013-08-27 15:12:20 +0300554
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530555 /* meaningful for video mode non-burst sync pulse mode only,
556 * can be zero for non-burst sync events and burst modes */
557 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
558 I915_WRITE(MIPI_HBP_COUNT(port), hbp);
Jani Nikula4e646492013-08-27 15:12:20 +0300559
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530560 /* vertical values are in terms of lines */
561 I915_WRITE(MIPI_VFP_COUNT(port), vfp);
562 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
563 I915_WRITE(MIPI_VBP_COUNT(port), vbp);
564 }
Jani Nikula4e646492013-08-27 15:12:20 +0300565}
566
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200567static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300568{
569 struct drm_encoder *encoder = &intel_encoder->base;
570 struct drm_device *dev = encoder->dev;
571 struct drm_i915_private *dev_priv = dev->dev_private;
572 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
573 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
574 struct drm_display_mode *adjusted_mode =
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200575 &intel_crtc->config->base.adjusted_mode;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530576 enum port port;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200577 unsigned int bpp = intel_crtc->config->pipe_bpp;
Jani Nikula4e646492013-08-27 15:12:20 +0300578 u32 val, tmp;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530579 u16 mode_hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300580
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200581 DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
Jani Nikula4e646492013-08-27 15:12:20 +0300582
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530583 mode_hdisplay = adjusted_mode->hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300584
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530585 if (intel_dsi->dual_link) {
586 mode_hdisplay /= 2;
587 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
588 mode_hdisplay += intel_dsi->pixel_overlap;
589 }
Jani Nikula4e646492013-08-27 15:12:20 +0300590
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530591 for_each_dsi_port(port, intel_dsi->ports) {
592 /* escape clock divider, 20MHz, shared for A and C.
593 * device ready must be off when doing this! txclkesc? */
594 tmp = I915_READ(MIPI_CTRL(PORT_A));
595 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
596 I915_WRITE(MIPI_CTRL(PORT_A), tmp | ESCAPE_CLOCK_DIVIDER_1);
Jani Nikula4e646492013-08-27 15:12:20 +0300597
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530598 /* read request priority is per pipe */
599 tmp = I915_READ(MIPI_CTRL(port));
600 tmp &= ~READ_REQUEST_PRIORITY_MASK;
601 I915_WRITE(MIPI_CTRL(port), tmp | READ_REQUEST_PRIORITY_HIGH);
Jani Nikula4e646492013-08-27 15:12:20 +0300602
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530603 /* XXX: why here, why like this? handling in irq handler?! */
604 I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
605 I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
606
607 I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
608
609 I915_WRITE(MIPI_DPI_RESOLUTION(port),
610 adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
611 mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
612 }
Jani Nikula4e646492013-08-27 15:12:20 +0300613
614 set_dsi_timings(encoder, adjusted_mode);
615
616 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
617 if (is_cmd_mode(intel_dsi)) {
618 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
619 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
620 } else {
621 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
622
623 /* XXX: cross-check bpp vs. pixel format? */
624 val |= intel_dsi->pixel_format;
625 }
Jani Nikula4e646492013-08-27 15:12:20 +0300626
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530627 tmp = 0;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530628 if (intel_dsi->eotp_pkt == 0)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530629 tmp |= EOT_DISABLE;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530630 if (intel_dsi->clock_stop)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530631 tmp |= CLOCKSTOP;
Jani Nikula4e646492013-08-27 15:12:20 +0300632
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530633 for_each_dsi_port(port, intel_dsi->ports) {
634 I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300635
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530636 /* timeouts for recovery. one frame IIUC. if counter expires,
637 * EOT and stop state. */
Shobhit Kumarcf4dbd22014-04-14 11:18:25 +0530638
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530639 /*
640 * In burst mode, value greater than one DPI line Time in byte
641 * clock (txbyteclkhs) To timeout this timer 1+ of the above
642 * said value is recommended.
643 *
644 * In non-burst mode, Value greater than one DPI frame time in
645 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
646 * said value is recommended.
647 *
648 * In DBI only mode, value greater than one DBI frame time in
649 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
650 * said value is recommended.
651 */
Jani Nikula4e646492013-08-27 15:12:20 +0300652
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530653 if (is_vid_mode(intel_dsi) &&
654 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
655 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
656 txbyteclkhs(adjusted_mode->htotal, bpp,
657 intel_dsi->lane_count,
658 intel_dsi->burst_mode_ratio) + 1);
659 } else {
660 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
661 txbyteclkhs(adjusted_mode->vtotal *
662 adjusted_mode->htotal,
663 bpp, intel_dsi->lane_count,
664 intel_dsi->burst_mode_ratio) + 1);
665 }
666 I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
667 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
668 intel_dsi->turn_arnd_val);
669 I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
670 intel_dsi->rst_timer_val);
Jani Nikula4e646492013-08-27 15:12:20 +0300671
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530672 /* dphy stuff */
Jani Nikula4e646492013-08-27 15:12:20 +0300673
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530674 /* in terms of low power clock */
675 I915_WRITE(MIPI_INIT_COUNT(port),
676 txclkesc(intel_dsi->escape_clk_div, 100));
Jani Nikula4e646492013-08-27 15:12:20 +0300677
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530678
679 /* recovery disables */
680 I915_WRITE(MIPI_EOT_DISABLE(port), val);
681
682 /* in terms of low power clock */
683 I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
684
685 /* in terms of txbyteclkhs. actual high to low switch +
686 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
687 *
688 * XXX: write MIPI_STOP_STATE_STALL?
689 */
690 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
691 intel_dsi->hs_to_lp_count);
692
693 /* XXX: low power clock equivalence in terms of byte clock.
694 * the number of byte clocks occupied in one low power clock.
695 * based on txbyteclkhs and txclkesc.
696 * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
697 * ) / 105.???
698 */
699 I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
700
701 /* the bw essential for transmitting 16 long packets containing
702 * 252 bytes meant for dcs write memory command is programmed in
703 * this register in terms of byte clocks. based on dsi transfer
704 * rate and the number of lanes configured the time taken to
705 * transmit 16 long packets in a dsi stream varies. */
706 I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
707
708 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
709 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
710 intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
711
712 if (is_vid_mode(intel_dsi))
713 /* Some panels might have resolution which is not a
714 * multiple of 64 like 1366 x 768. Enable RANDOM
715 * resolution support for such panels by default */
716 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
717 intel_dsi->video_frmt_cfg_bits |
718 intel_dsi->video_mode_format |
719 IP_TG_CONFIG |
720 RANDOM_DPI_DISPLAY_RESOLUTION);
721 }
Jani Nikula4e646492013-08-27 15:12:20 +0300722}
723
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200724static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
725{
726 DRM_DEBUG_KMS("\n");
727
728 intel_dsi_prepare(encoder);
729
730 vlv_enable_dsi_pll(encoder);
731}
732
Jani Nikula4e646492013-08-27 15:12:20 +0300733static enum drm_connector_status
734intel_dsi_detect(struct drm_connector *connector, bool force)
735{
Jani Nikula36d21f42015-01-16 14:27:20 +0200736 return connector_status_connected;
Jani Nikula4e646492013-08-27 15:12:20 +0300737}
738
739static int intel_dsi_get_modes(struct drm_connector *connector)
740{
741 struct intel_connector *intel_connector = to_intel_connector(connector);
742 struct drm_display_mode *mode;
743
744 DRM_DEBUG_KMS("\n");
745
746 if (!intel_connector->panel.fixed_mode) {
747 DRM_DEBUG_KMS("no fixed mode\n");
748 return 0;
749 }
750
751 mode = drm_mode_duplicate(connector->dev,
752 intel_connector->panel.fixed_mode);
753 if (!mode) {
754 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
755 return 0;
756 }
757
758 drm_mode_probed_add(connector, mode);
759 return 1;
760}
761
Jani Nikula593e0622015-01-23 15:30:56 +0200762static void intel_dsi_connector_destroy(struct drm_connector *connector)
Jani Nikula4e646492013-08-27 15:12:20 +0300763{
764 struct intel_connector *intel_connector = to_intel_connector(connector);
765
766 DRM_DEBUG_KMS("\n");
767 intel_panel_fini(&intel_connector->panel);
Jani Nikula4e646492013-08-27 15:12:20 +0300768 drm_connector_cleanup(connector);
769 kfree(connector);
770}
771
Jani Nikula593e0622015-01-23 15:30:56 +0200772static void intel_dsi_encoder_destroy(struct drm_encoder *encoder)
773{
774 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
775
776 if (intel_dsi->panel) {
777 drm_panel_detach(intel_dsi->panel);
778 /* XXX: Logically this call belongs in the panel driver. */
779 drm_panel_remove(intel_dsi->panel);
780 }
781 intel_encoder_destroy(encoder);
782}
783
Jani Nikula4e646492013-08-27 15:12:20 +0300784static const struct drm_encoder_funcs intel_dsi_funcs = {
Jani Nikula593e0622015-01-23 15:30:56 +0200785 .destroy = intel_dsi_encoder_destroy,
Jani Nikula4e646492013-08-27 15:12:20 +0300786};
787
788static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
789 .get_modes = intel_dsi_get_modes,
790 .mode_valid = intel_dsi_mode_valid,
791 .best_encoder = intel_best_encoder,
792};
793
794static const struct drm_connector_funcs intel_dsi_connector_funcs = {
795 .dpms = intel_connector_dpms,
796 .detect = intel_dsi_detect,
Jani Nikula593e0622015-01-23 15:30:56 +0200797 .destroy = intel_dsi_connector_destroy,
Jani Nikula4e646492013-08-27 15:12:20 +0300798 .fill_modes = drm_helper_probe_single_connector_modes,
Matt Roper2545e4a2015-01-22 16:51:27 -0800799 .atomic_get_property = intel_connector_atomic_get_property,
Matt Roperc6f95f22015-01-22 16:50:32 -0800800 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Jani Nikula4e646492013-08-27 15:12:20 +0300801};
802
Damien Lespiau4328633d2014-05-28 12:30:56 +0100803void intel_dsi_init(struct drm_device *dev)
Jani Nikula4e646492013-08-27 15:12:20 +0300804{
805 struct intel_dsi *intel_dsi;
806 struct intel_encoder *intel_encoder;
807 struct drm_encoder *encoder;
808 struct intel_connector *intel_connector;
809 struct drm_connector *connector;
Jani Nikula593e0622015-01-23 15:30:56 +0200810 struct drm_display_mode *scan, *fixed_mode = NULL;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530811 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300812 unsigned int i;
813
814 DRM_DEBUG_KMS("\n");
815
Shobhit Kumar3e6bd012014-05-27 19:33:59 +0530816 /* There is no detection method for MIPI so rely on VBT */
817 if (!dev_priv->vbt.has_mipi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100818 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300819
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530820 if (IS_VALLEYVIEW(dev)) {
821 dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
822 } else {
823 DRM_ERROR("Unsupported Mipi device to reg base");
Christoph Jaeger868d6652014-06-13 21:51:22 +0200824 return;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530825 }
826
Jani Nikula4e646492013-08-27 15:12:20 +0300827 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
828 if (!intel_dsi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100829 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300830
831 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
832 if (!intel_connector) {
833 kfree(intel_dsi);
Damien Lespiau4328633d2014-05-28 12:30:56 +0100834 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300835 }
836
837 intel_encoder = &intel_dsi->base;
838 encoder = &intel_encoder->base;
839 intel_dsi->attached_connector = intel_connector;
840
Jani Nikula4e646492013-08-27 15:12:20 +0300841 connector = &intel_connector->base;
842
843 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
844
845 /* XXX: very likely not all of these are needed */
846 intel_encoder->hot_plug = intel_dsi_hot_plug;
847 intel_encoder->compute_config = intel_dsi_compute_config;
848 intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
849 intel_encoder->pre_enable = intel_dsi_pre_enable;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530850 intel_encoder->enable = intel_dsi_enable_nop;
Imre Deakc315faf2014-05-27 19:00:09 +0300851 intel_encoder->disable = intel_dsi_pre_disable;
Jani Nikula4e646492013-08-27 15:12:20 +0300852 intel_encoder->post_disable = intel_dsi_post_disable;
853 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
854 intel_encoder->get_config = intel_dsi_get_config;
855
856 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak4932e2c2014-02-11 17:12:48 +0200857 intel_connector->unregister = intel_connector_unregister;
Jani Nikula4e646492013-08-27 15:12:20 +0300858
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200859 /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
Jani Nikula17af40a2014-11-14 16:54:22 +0200860 if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200861 intel_encoder->crtc_mask = (1 << PIPE_A);
Jani Nikula17af40a2014-11-14 16:54:22 +0200862 intel_dsi->ports = (1 << PORT_A);
863 } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200864 intel_encoder->crtc_mask = (1 << PIPE_B);
Jani Nikula17af40a2014-11-14 16:54:22 +0200865 intel_dsi->ports = (1 << PORT_C);
866 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200867
Jani Nikula593e0622015-01-23 15:30:56 +0200868 for (i = 0; i < ARRAY_SIZE(intel_dsi_drivers); i++) {
869 intel_dsi->panel = intel_dsi_drivers[i].init(intel_dsi,
870 intel_dsi_drivers[i].panel_id);
871 if (intel_dsi->panel)
Jani Nikula4e646492013-08-27 15:12:20 +0300872 break;
873 }
874
Jani Nikula593e0622015-01-23 15:30:56 +0200875 if (!intel_dsi->panel) {
Jani Nikula4e646492013-08-27 15:12:20 +0300876 DRM_DEBUG_KMS("no device found\n");
877 goto err;
878 }
879
880 intel_encoder->type = INTEL_OUTPUT_DSI;
Ville Syrjäläbc079e82014-03-03 16:15:28 +0200881 intel_encoder->cloneable = 0;
Jani Nikula4e646492013-08-27 15:12:20 +0300882 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
883 DRM_MODE_CONNECTOR_DSI);
884
885 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
886
887 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
888 connector->interlace_allowed = false;
889 connector->doublescan_allowed = false;
890
891 intel_connector_attach_encoder(intel_connector, intel_encoder);
892
Thomas Wood34ea3d32014-05-29 16:57:41 +0100893 drm_connector_register(connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300894
Jani Nikula593e0622015-01-23 15:30:56 +0200895 drm_panel_attach(intel_dsi->panel, connector);
896
897 mutex_lock(&dev->mode_config.mutex);
898 drm_panel_get_modes(intel_dsi->panel);
899 list_for_each_entry(scan, &connector->probed_modes, head) {
900 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
901 fixed_mode = drm_mode_duplicate(dev, scan);
902 break;
903 }
904 }
905 mutex_unlock(&dev->mode_config.mutex);
906
Jani Nikula4e646492013-08-27 15:12:20 +0300907 if (!fixed_mode) {
908 DRM_DEBUG_KMS("no fixed mode\n");
909 goto err;
910 }
911
Vandana Kannan4b6ed682014-02-11 14:26:36 +0530912 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
Jani Nikula4e646492013-08-27 15:12:20 +0300913
Damien Lespiau4328633d2014-05-28 12:30:56 +0100914 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300915
916err:
917 drm_encoder_cleanup(&intel_encoder->base);
918 kfree(intel_dsi);
919 kfree(intel_connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300920}