blob: 4bb9886fa2cfb44864a123ac0f222d5a188ce15b [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
Shobhit Kumare9fe51c2013-12-10 12:14:55 +053045static void band_gap_reset(struct drm_i915_private *dev_priv)
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +030046{
47 mutex_lock(&dev_priv->dpio_lock);
48
Shobhit Kumare9fe51c2013-12-10 12:14:55 +053049 vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
50 vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
51 vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
52 udelay(150);
53 vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
54 vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +030055
56 mutex_unlock(&dev_priv->dpio_lock);
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +030057}
58
Jani Nikula4e646492013-08-27 15:12:20 +030059static struct intel_dsi *intel_attached_dsi(struct drm_connector *connector)
60{
61 return container_of(intel_attached_encoder(connector),
62 struct intel_dsi, base);
63}
64
65static inline bool is_vid_mode(struct intel_dsi *intel_dsi)
66{
Shobhit Kumardfba2e22014-04-14 11:18:24 +053067 return intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE;
Jani Nikula4e646492013-08-27 15:12:20 +030068}
69
70static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
71{
Shobhit Kumardfba2e22014-04-14 11:18:24 +053072 return intel_dsi->operation_mode == INTEL_DSI_COMMAND_MODE;
Jani Nikula4e646492013-08-27 15:12:20 +030073}
74
75static void intel_dsi_hot_plug(struct intel_encoder *encoder)
76{
77 DRM_DEBUG_KMS("\n");
78}
79
80static bool intel_dsi_compute_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020081 struct intel_crtc_state *config)
Jani Nikula4e646492013-08-27 15:12:20 +030082{
83 struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
84 base);
85 struct intel_connector *intel_connector = intel_dsi->attached_connector;
86 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020087 struct drm_display_mode *adjusted_mode = &config->base.adjusted_mode;
88 struct drm_display_mode *mode = &config->base.mode;
Jani Nikula4e646492013-08-27 15:12:20 +030089
90 DRM_DEBUG_KMS("\n");
91
92 if (fixed_mode)
93 intel_fixed_panel_mode(fixed_mode, adjusted_mode);
94
Shobhit Kumarf573de52014-07-30 20:32:37 +053095 /* DSI uses short packets for sync events, so clear mode flags for DSI */
96 adjusted_mode->flags = 0;
97
Jani Nikula4e646492013-08-27 15:12:20 +030098 if (intel_dsi->dev.dev_ops->mode_fixup)
99 return intel_dsi->dev.dev_ops->mode_fixup(&intel_dsi->dev,
100 mode, adjusted_mode);
101
102 return true;
103}
104
Gaurav K Singh5505a242014-12-04 10:58:47 +0530105static void intel_dsi_port_enable(struct intel_encoder *encoder)
106{
107 struct drm_device *dev = encoder->base.dev;
108 struct drm_i915_private *dev_priv = dev->dev_private;
109 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
110 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Gaurav K Singh369602d2014-12-05 14:09:28 +0530111 enum port port;
Gaurav K Singh5505a242014-12-04 10:58:47 +0530112 u32 temp;
113
Gaurav K Singha9da9bc2014-12-05 14:13:41 +0530114 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
115 temp = I915_READ(VLV_CHICKEN_3);
116 temp &= ~PIXEL_OVERLAP_CNT_MASK |
117 intel_dsi->pixel_overlap <<
118 PIXEL_OVERLAP_CNT_SHIFT;
119 I915_WRITE(VLV_CHICKEN_3, temp);
120 }
121
Gaurav K Singh369602d2014-12-05 14:09:28 +0530122 for_each_dsi_port(port, intel_dsi->ports) {
123 temp = I915_READ(MIPI_PORT_CTRL(port));
124 temp &= ~LANE_CONFIGURATION_MASK;
125 temp &= ~DUAL_LINK_MODE_MASK;
126
127 if (intel_dsi->ports == ((1 << PORT_A) | (1 << PORT_C))) {
128 temp |= (intel_dsi->dual_link - 1)
129 << DUAL_LINK_MODE_SHIFT;
130 temp |= intel_crtc->pipe ?
131 LANE_CONFIGURATION_DUAL_LINK_B :
132 LANE_CONFIGURATION_DUAL_LINK_A;
133 }
134 /* assert ip_tg_enable signal */
135 I915_WRITE(MIPI_PORT_CTRL(port), temp | DPI_ENABLE);
136 POSTING_READ(MIPI_PORT_CTRL(port));
137 }
Gaurav K Singh5505a242014-12-04 10:58:47 +0530138}
139
140static void intel_dsi_port_disable(struct intel_encoder *encoder)
141{
142 struct drm_device *dev = encoder->base.dev;
143 struct drm_i915_private *dev_priv = dev->dev_private;
Gaurav K Singh369602d2014-12-05 14:09:28 +0530144 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
145 enum port port;
Gaurav K Singh5505a242014-12-04 10:58:47 +0530146 u32 temp;
147
Gaurav K Singh369602d2014-12-05 14:09:28 +0530148 for_each_dsi_port(port, intel_dsi->ports) {
149 /* de-assert ip_tg_enable signal */
150 temp = I915_READ(MIPI_PORT_CTRL(port));
151 I915_WRITE(MIPI_PORT_CTRL(port), temp & ~DPI_ENABLE);
152 POSTING_READ(MIPI_PORT_CTRL(port));
153 }
Gaurav K Singh5505a242014-12-04 10:58:47 +0530154}
155
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530156static void intel_dsi_device_ready(struct intel_encoder *encoder)
157{
158 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530159 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
160 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530161 u32 val;
162
163 DRM_DEBUG_KMS("\n");
164
Shobhit Kumar2095f9f2014-04-09 13:59:30 +0530165 mutex_lock(&dev_priv->dpio_lock);
166 /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
167 * needed everytime after power gate */
168 vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
169 mutex_unlock(&dev_priv->dpio_lock);
170
171 /* bandgap reset is needed after everytime we do power gate */
172 band_gap_reset(dev_priv);
173
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530174 for_each_dsi_port(port, intel_dsi->ports) {
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530175
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530176 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
177 usleep_range(2500, 3000);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530178
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530179 val = I915_READ(MIPI_PORT_CTRL(port));
Gaurav K Singhbf344e82014-12-07 16:13:54 +0530180
181 /* Enable MIPI PHY transparent latch
182 * Common bit for both MIPI Port A & MIPI Port C
183 * No similar bit in MIPI Port C reg
184 */
185 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD);
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530186 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530187
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530188 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
189 usleep_range(2500, 3000);
190
191 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
192 usleep_range(2500, 3000);
193 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530194}
Jani Nikula4e646492013-08-27 15:12:20 +0300195
196static void intel_dsi_enable(struct intel_encoder *encoder)
197{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530198 struct drm_device *dev = encoder->base.dev;
199 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300200 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
201 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200202 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Jani Nikula4e646492013-08-27 15:12:20 +0300203
204 DRM_DEBUG_KMS("\n");
205
Jani Nikula4e646492013-08-27 15:12:20 +0300206 if (is_cmd_mode(intel_dsi))
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200207 I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530208 else {
Jani Nikula4e646492013-08-27 15:12:20 +0300209 msleep(20); /* XXX */
Jani Nikulaf03e4172015-01-16 14:27:16 +0200210 for_each_dsi_port(port, intel_dsi->ports)
211 dpi_send_cmd(intel_dsi, TURN_ON, DPI_LP_MODE_EN, port);
Jani Nikula4e646492013-08-27 15:12:20 +0300212 msleep(100);
213
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530214 if (intel_dsi->dev.dev_ops->enable)
215 intel_dsi->dev.dev_ops->enable(&intel_dsi->dev);
216
Shobhit Kumar13813082014-07-12 17:17:22 +0530217 wait_for_dsi_fifo_empty(intel_dsi);
218
Gaurav K Singh5505a242014-12-04 10:58:47 +0530219 intel_dsi_port_enable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300220 }
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530221}
Jani Nikula4e646492013-08-27 15:12:20 +0300222
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530223static void intel_dsi_pre_enable(struct intel_encoder *encoder)
224{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530225 struct drm_device *dev = encoder->base.dev;
226 struct drm_i915_private *dev_priv = dev->dev_private;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530227 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530228 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
229 enum pipe pipe = intel_crtc->pipe;
230 u32 tmp;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530231
232 DRM_DEBUG_KMS("\n");
233
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530234 /* Disable DPOunit clock gating, can stall pipe
235 * and we need DPLL REFA always enabled */
236 tmp = I915_READ(DPLL(pipe));
237 tmp |= DPLL_REFA_CLK_ENABLE_VLV;
238 I915_WRITE(DPLL(pipe), tmp);
239
Shobhit Kumarf573de52014-07-30 20:32:37 +0530240 /* update the hw state for DPLL */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200241 intel_crtc->config->dpll_hw_state.dpll = DPLL_INTEGRATED_CLOCK_VLV |
Daniel Vetter7f3de832014-07-30 22:34:27 +0200242 DPLL_REFA_CLK_ENABLE_VLV;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530243
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530244 tmp = I915_READ(DSPCLK_GATE_D);
245 tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
246 I915_WRITE(DSPCLK_GATE_D, tmp);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530247
248 /* put device in ready state */
249 intel_dsi_device_ready(encoder);
250
Shobhit Kumardf38e652014-04-14 11:18:26 +0530251 msleep(intel_dsi->panel_on_delay);
252
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530253 if (intel_dsi->dev.dev_ops->panel_reset)
254 intel_dsi->dev.dev_ops->panel_reset(&intel_dsi->dev);
255
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530256 if (intel_dsi->dev.dev_ops->send_otp_cmds)
257 intel_dsi->dev.dev_ops->send_otp_cmds(&intel_dsi->dev);
258
Shobhit Kumar13813082014-07-12 17:17:22 +0530259 wait_for_dsi_fifo_empty(intel_dsi);
260
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530261 /* Enable port in pre-enable phase itself because as per hw team
262 * recommendation, port should be enabled befor plane & pipe */
263 intel_dsi_enable(encoder);
264}
265
266static void intel_dsi_enable_nop(struct intel_encoder *encoder)
267{
268 DRM_DEBUG_KMS("\n");
269
270 /* for DSI port enable has to be done before pipe
271 * and plane enable, so port enable is done in
272 * pre_enable phase itself unlike other encoders
273 */
Jani Nikula4e646492013-08-27 15:12:20 +0300274}
275
Imre Deakc315faf2014-05-27 19:00:09 +0300276static void intel_dsi_pre_disable(struct intel_encoder *encoder)
277{
278 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikulaf03e4172015-01-16 14:27:16 +0200279 enum port port;
Imre Deakc315faf2014-05-27 19:00:09 +0300280
281 DRM_DEBUG_KMS("\n");
282
283 if (is_vid_mode(intel_dsi)) {
284 /* Send Shutdown command to the panel in LP mode */
Jani Nikulaf03e4172015-01-16 14:27:16 +0200285 for_each_dsi_port(port, intel_dsi->ports)
286 dpi_send_cmd(intel_dsi, SHUTDOWN, DPI_LP_MODE_EN, port);
Imre Deakc315faf2014-05-27 19:00:09 +0300287 msleep(10);
288 }
289}
290
Jani Nikula4e646492013-08-27 15:12:20 +0300291static void intel_dsi_disable(struct intel_encoder *encoder)
292{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530293 struct drm_device *dev = encoder->base.dev;
294 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300295 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530296 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300297 u32 temp;
298
299 DRM_DEBUG_KMS("\n");
300
Jani Nikula4e646492013-08-27 15:12:20 +0300301 if (is_vid_mode(intel_dsi)) {
Shobhit Kumar13813082014-07-12 17:17:22 +0530302 wait_for_dsi_fifo_empty(intel_dsi);
303
Gaurav K Singh5505a242014-12-04 10:58:47 +0530304 intel_dsi_port_disable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300305 msleep(2);
306 }
307
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530308 for_each_dsi_port(port, intel_dsi->ports) {
309 /* Panel commands can be sent when clock is in LP11 */
310 I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530311
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530312 temp = I915_READ(MIPI_CTRL(port));
313 temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
314 I915_WRITE(MIPI_CTRL(port), temp |
315 intel_dsi->escape_clk_div <<
316 ESCAPE_CLOCK_DIVIDER_SHIFT);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530317
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530318 I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530319
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530320 temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
321 temp &= ~VID_MODE_FORMAT_MASK;
322 I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530323
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530324 I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
325 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530326 /* if disable packets are sent before sending shutdown packet then in
327 * some next enable sequence send turn on packet error is observed */
328 if (intel_dsi->dev.dev_ops->disable)
329 intel_dsi->dev.dev_ops->disable(&intel_dsi->dev);
Shobhit Kumar13813082014-07-12 17:17:22 +0530330
331 wait_for_dsi_fifo_empty(intel_dsi);
Jani Nikula4e646492013-08-27 15:12:20 +0300332}
333
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530334static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300335{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530336 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530337 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
338 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530339 u32 val;
340
Jani Nikula4e646492013-08-27 15:12:20 +0300341 DRM_DEBUG_KMS("\n");
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530342 for_each_dsi_port(port, intel_dsi->ports) {
ymohanmabe4fc042013-08-27 23:40:56 +0300343
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530344 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
345 ULPS_STATE_ENTER);
346 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530347
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530348 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
349 ULPS_STATE_EXIT);
350 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530351
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530352 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
353 ULPS_STATE_ENTER);
354 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530355
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530356 /* Wait till Clock lanes are in LP-00 state for MIPI Port A
357 * only. MIPI Port C has no similar bit for checking
358 */
359 if (wait_for(((I915_READ(MIPI_PORT_CTRL(PORT_A)) & AFE_LATCHOUT)
360 == 0x00000), 30))
361 DRM_ERROR("DSI LP not going Low\n");
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530362
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530363 val = I915_READ(MIPI_PORT_CTRL(port));
364 /* Disable MIPI PHY transparent latch
365 * Common bit for both MIPI Port A & MIPI Port C
366 */
367 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val & ~LP_OUTPUT_HOLD);
368 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530369
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530370 I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
371 usleep_range(2000, 2500);
372 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530373
ymohanmabe4fc042013-08-27 23:40:56 +0300374 vlv_disable_dsi_pll(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300375}
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530376
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530377static void intel_dsi_post_disable(struct intel_encoder *encoder)
378{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530379 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530380 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530381 u32 val;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530382
383 DRM_DEBUG_KMS("\n");
384
Imre Deakc315faf2014-05-27 19:00:09 +0300385 intel_dsi_disable(encoder);
386
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530387 intel_dsi_clear_device_ready(encoder);
388
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530389 val = I915_READ(DSPCLK_GATE_D);
390 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
391 I915_WRITE(DSPCLK_GATE_D, val);
392
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530393 if (intel_dsi->dev.dev_ops->disable_panel_power)
394 intel_dsi->dev.dev_ops->disable_panel_power(&intel_dsi->dev);
Shobhit Kumardf38e652014-04-14 11:18:26 +0530395
396 msleep(intel_dsi->panel_off_delay);
397 msleep(intel_dsi->panel_pwr_cycle_delay);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530398}
Jani Nikula4e646492013-08-27 15:12:20 +0300399
400static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
401 enum pipe *pipe)
402{
403 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530404 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
405 struct drm_device *dev = encoder->base.dev;
Imre Deak6d129be2014-03-05 16:20:54 +0200406 enum intel_display_power_domain power_domain;
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530407 u32 dpi_enabled, func;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200408 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300409
410 DRM_DEBUG_KMS("\n");
411
Imre Deak6d129be2014-03-05 16:20:54 +0200412 power_domain = intel_display_port_power_domain(encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200413 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200414 return false;
415
Jani Nikula4e646492013-08-27 15:12:20 +0300416 /* XXX: this only works for one DSI output */
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530417 for_each_dsi_port(port, intel_dsi->ports) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200418 func = I915_READ(MIPI_DSI_FUNC_PRG(port));
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530419 dpi_enabled = I915_READ(MIPI_PORT_CTRL(port)) &
420 DPI_ENABLE;
Jani Nikula4e646492013-08-27 15:12:20 +0300421
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530422 /* Due to some hardware limitations on BYT, MIPI Port C DPI
423 * Enable bit does not get set. To check whether DSI Port C
424 * was enabled in BIOS, check the Pipe B enable bit
425 */
426 if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) &&
427 (port == PORT_C))
428 dpi_enabled = I915_READ(PIPECONF(PIPE_B)) &
429 PIPECONF_ENABLE;
430
431 if (dpi_enabled || (func & CMD_MODE_DATA_WIDTH_MASK)) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200432 if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530433 *pipe = port == PORT_A ? PIPE_A : PIPE_B;
Jani Nikula4e646492013-08-27 15:12:20 +0300434 return true;
435 }
436 }
437 }
438
439 return false;
440}
441
442static void intel_dsi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200443 struct intel_crtc_state *pipe_config)
Jani Nikula4e646492013-08-27 15:12:20 +0300444{
Shobhit Kumarf573de52014-07-30 20:32:37 +0530445 u32 pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300446 DRM_DEBUG_KMS("\n");
447
Shobhit Kumarf573de52014-07-30 20:32:37 +0530448 /*
449 * DPLL_MD is not used in case of DSI, reading will get some default value
450 * set dpll_md = 0
451 */
452 pipe_config->dpll_hw_state.dpll_md = 0;
453
454 pclk = vlv_get_dsi_pclk(encoder, pipe_config->pipe_bpp);
455 if (!pclk)
456 return;
457
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200458 pipe_config->base.adjusted_mode.crtc_clock = pclk;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530459 pipe_config->port_clock = pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300460}
461
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000462static enum drm_mode_status
463intel_dsi_mode_valid(struct drm_connector *connector,
464 struct drm_display_mode *mode)
Jani Nikula4e646492013-08-27 15:12:20 +0300465{
466 struct intel_connector *intel_connector = to_intel_connector(connector);
467 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
468 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
469
470 DRM_DEBUG_KMS("\n");
471
472 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
473 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
474 return MODE_NO_DBLESCAN;
475 }
476
477 if (fixed_mode) {
478 if (mode->hdisplay > fixed_mode->hdisplay)
479 return MODE_PANEL;
480 if (mode->vdisplay > fixed_mode->vdisplay)
481 return MODE_PANEL;
482 }
483
484 return intel_dsi->dev.dev_ops->mode_valid(&intel_dsi->dev, mode);
485}
486
487/* return txclkesc cycles in terms of divider and duration in us */
488static u16 txclkesc(u32 divider, unsigned int us)
489{
490 switch (divider) {
491 case ESCAPE_CLOCK_DIVIDER_1:
492 default:
493 return 20 * us;
494 case ESCAPE_CLOCK_DIVIDER_2:
495 return 10 * us;
496 case ESCAPE_CLOCK_DIVIDER_4:
497 return 5 * us;
498 }
499}
500
501/* return pixels in terms of txbyteclkhs */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530502static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
503 u16 burst_mode_ratio)
Jani Nikula4e646492013-08-27 15:12:20 +0300504{
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530505 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200506 8 * 100), lane_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300507}
508
509static void set_dsi_timings(struct drm_encoder *encoder,
510 const struct drm_display_mode *mode)
511{
512 struct drm_device *dev = encoder->dev;
513 struct drm_i915_private *dev_priv = dev->dev_private;
514 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
515 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530516 enum port port;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200517 unsigned int bpp = intel_crtc->config->pipe_bpp;
Jani Nikula4e646492013-08-27 15:12:20 +0300518 unsigned int lane_count = intel_dsi->lane_count;
519
520 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
521
522 hactive = mode->hdisplay;
523 hfp = mode->hsync_start - mode->hdisplay;
524 hsync = mode->hsync_end - mode->hsync_start;
525 hbp = mode->htotal - mode->hsync_end;
526
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530527 if (intel_dsi->dual_link) {
528 hactive /= 2;
529 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
530 hactive += intel_dsi->pixel_overlap;
531 hfp /= 2;
532 hsync /= 2;
533 hbp /= 2;
534 }
535
Jani Nikula4e646492013-08-27 15:12:20 +0300536 vfp = mode->vsync_start - mode->vdisplay;
537 vsync = mode->vsync_end - mode->vsync_start;
538 vbp = mode->vtotal - mode->vsync_end;
539
540 /* horizontal values are in terms of high speed byte clock */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530541 hactive = txbyteclkhs(hactive, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200542 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530543 hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
544 hsync = txbyteclkhs(hsync, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200545 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530546 hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
Jani Nikula4e646492013-08-27 15:12:20 +0300547
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530548 for_each_dsi_port(port, intel_dsi->ports) {
549 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
550 I915_WRITE(MIPI_HFP_COUNT(port), hfp);
Jani Nikula4e646492013-08-27 15:12:20 +0300551
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530552 /* meaningful for video mode non-burst sync pulse mode only,
553 * can be zero for non-burst sync events and burst modes */
554 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
555 I915_WRITE(MIPI_HBP_COUNT(port), hbp);
Jani Nikula4e646492013-08-27 15:12:20 +0300556
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530557 /* vertical values are in terms of lines */
558 I915_WRITE(MIPI_VFP_COUNT(port), vfp);
559 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
560 I915_WRITE(MIPI_VBP_COUNT(port), vbp);
561 }
Jani Nikula4e646492013-08-27 15:12:20 +0300562}
563
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200564static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300565{
566 struct drm_encoder *encoder = &intel_encoder->base;
567 struct drm_device *dev = encoder->dev;
568 struct drm_i915_private *dev_priv = dev->dev_private;
569 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
570 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
571 struct drm_display_mode *adjusted_mode =
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200572 &intel_crtc->config->base.adjusted_mode;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530573 enum port port;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200574 unsigned int bpp = intel_crtc->config->pipe_bpp;
Jani Nikula4e646492013-08-27 15:12:20 +0300575 u32 val, tmp;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530576 u16 mode_hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300577
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200578 DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
Jani Nikula4e646492013-08-27 15:12:20 +0300579
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530580 mode_hdisplay = adjusted_mode->hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300581
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530582 if (intel_dsi->dual_link) {
583 mode_hdisplay /= 2;
584 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
585 mode_hdisplay += intel_dsi->pixel_overlap;
586 }
Jani Nikula4e646492013-08-27 15:12:20 +0300587
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530588 for_each_dsi_port(port, intel_dsi->ports) {
589 /* escape clock divider, 20MHz, shared for A and C.
590 * device ready must be off when doing this! txclkesc? */
591 tmp = I915_READ(MIPI_CTRL(PORT_A));
592 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
593 I915_WRITE(MIPI_CTRL(PORT_A), tmp | ESCAPE_CLOCK_DIVIDER_1);
Jani Nikula4e646492013-08-27 15:12:20 +0300594
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530595 /* read request priority is per pipe */
596 tmp = I915_READ(MIPI_CTRL(port));
597 tmp &= ~READ_REQUEST_PRIORITY_MASK;
598 I915_WRITE(MIPI_CTRL(port), tmp | READ_REQUEST_PRIORITY_HIGH);
Jani Nikula4e646492013-08-27 15:12:20 +0300599
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530600 /* XXX: why here, why like this? handling in irq handler?! */
601 I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
602 I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
603
604 I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
605
606 I915_WRITE(MIPI_DPI_RESOLUTION(port),
607 adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
608 mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
609 }
Jani Nikula4e646492013-08-27 15:12:20 +0300610
611 set_dsi_timings(encoder, adjusted_mode);
612
613 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
614 if (is_cmd_mode(intel_dsi)) {
615 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
616 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
617 } else {
618 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
619
620 /* XXX: cross-check bpp vs. pixel format? */
621 val |= intel_dsi->pixel_format;
622 }
Jani Nikula4e646492013-08-27 15:12:20 +0300623
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530624 tmp = 0;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530625 if (intel_dsi->eotp_pkt == 0)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530626 tmp |= EOT_DISABLE;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530627 if (intel_dsi->clock_stop)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530628 tmp |= CLOCKSTOP;
Jani Nikula4e646492013-08-27 15:12:20 +0300629
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530630 for_each_dsi_port(port, intel_dsi->ports) {
631 I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300632
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530633 /* timeouts for recovery. one frame IIUC. if counter expires,
634 * EOT and stop state. */
Shobhit Kumarcf4dbd22014-04-14 11:18:25 +0530635
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530636 /*
637 * In burst mode, value greater than one DPI line Time in byte
638 * clock (txbyteclkhs) To timeout this timer 1+ of the above
639 * said value is recommended.
640 *
641 * In non-burst mode, Value greater than one DPI frame time in
642 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
643 * said value is recommended.
644 *
645 * In DBI only mode, value greater than one DBI frame time in
646 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
647 * said value is recommended.
648 */
Jani Nikula4e646492013-08-27 15:12:20 +0300649
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530650 if (is_vid_mode(intel_dsi) &&
651 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
652 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
653 txbyteclkhs(adjusted_mode->htotal, bpp,
654 intel_dsi->lane_count,
655 intel_dsi->burst_mode_ratio) + 1);
656 } else {
657 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
658 txbyteclkhs(adjusted_mode->vtotal *
659 adjusted_mode->htotal,
660 bpp, intel_dsi->lane_count,
661 intel_dsi->burst_mode_ratio) + 1);
662 }
663 I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
664 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
665 intel_dsi->turn_arnd_val);
666 I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
667 intel_dsi->rst_timer_val);
Jani Nikula4e646492013-08-27 15:12:20 +0300668
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530669 /* dphy stuff */
Jani Nikula4e646492013-08-27 15:12:20 +0300670
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530671 /* in terms of low power clock */
672 I915_WRITE(MIPI_INIT_COUNT(port),
673 txclkesc(intel_dsi->escape_clk_div, 100));
Jani Nikula4e646492013-08-27 15:12:20 +0300674
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530675
676 /* recovery disables */
677 I915_WRITE(MIPI_EOT_DISABLE(port), val);
678
679 /* in terms of low power clock */
680 I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
681
682 /* in terms of txbyteclkhs. actual high to low switch +
683 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
684 *
685 * XXX: write MIPI_STOP_STATE_STALL?
686 */
687 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
688 intel_dsi->hs_to_lp_count);
689
690 /* XXX: low power clock equivalence in terms of byte clock.
691 * the number of byte clocks occupied in one low power clock.
692 * based on txbyteclkhs and txclkesc.
693 * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
694 * ) / 105.???
695 */
696 I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
697
698 /* the bw essential for transmitting 16 long packets containing
699 * 252 bytes meant for dcs write memory command is programmed in
700 * this register in terms of byte clocks. based on dsi transfer
701 * rate and the number of lanes configured the time taken to
702 * transmit 16 long packets in a dsi stream varies. */
703 I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
704
705 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
706 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
707 intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
708
709 if (is_vid_mode(intel_dsi))
710 /* Some panels might have resolution which is not a
711 * multiple of 64 like 1366 x 768. Enable RANDOM
712 * resolution support for such panels by default */
713 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
714 intel_dsi->video_frmt_cfg_bits |
715 intel_dsi->video_mode_format |
716 IP_TG_CONFIG |
717 RANDOM_DPI_DISPLAY_RESOLUTION);
718 }
Jani Nikula4e646492013-08-27 15:12:20 +0300719}
720
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200721static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
722{
723 DRM_DEBUG_KMS("\n");
724
725 intel_dsi_prepare(encoder);
726
727 vlv_enable_dsi_pll(encoder);
728}
729
Jani Nikula4e646492013-08-27 15:12:20 +0300730static enum drm_connector_status
731intel_dsi_detect(struct drm_connector *connector, bool force)
732{
733 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
Imre Deak671dedd2014-03-05 16:20:53 +0200734 struct intel_encoder *intel_encoder = &intel_dsi->base;
735 enum intel_display_power_domain power_domain;
736 enum drm_connector_status connector_status;
737 struct drm_i915_private *dev_priv = intel_encoder->base.dev->dev_private;
738
Jani Nikula4e646492013-08-27 15:12:20 +0300739 DRM_DEBUG_KMS("\n");
Imre Deak671dedd2014-03-05 16:20:53 +0200740 power_domain = intel_display_port_power_domain(intel_encoder);
741
742 intel_display_power_get(dev_priv, power_domain);
743 connector_status = intel_dsi->dev.dev_ops->detect(&intel_dsi->dev);
744 intel_display_power_put(dev_priv, power_domain);
745
746 return connector_status;
Jani Nikula4e646492013-08-27 15:12:20 +0300747}
748
749static int intel_dsi_get_modes(struct drm_connector *connector)
750{
751 struct intel_connector *intel_connector = to_intel_connector(connector);
752 struct drm_display_mode *mode;
753
754 DRM_DEBUG_KMS("\n");
755
756 if (!intel_connector->panel.fixed_mode) {
757 DRM_DEBUG_KMS("no fixed mode\n");
758 return 0;
759 }
760
761 mode = drm_mode_duplicate(connector->dev,
762 intel_connector->panel.fixed_mode);
763 if (!mode) {
764 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
765 return 0;
766 }
767
768 drm_mode_probed_add(connector, mode);
769 return 1;
770}
771
772static void intel_dsi_destroy(struct drm_connector *connector)
773{
774 struct intel_connector *intel_connector = to_intel_connector(connector);
775
776 DRM_DEBUG_KMS("\n");
777 intel_panel_fini(&intel_connector->panel);
Jani Nikula4e646492013-08-27 15:12:20 +0300778 drm_connector_cleanup(connector);
779 kfree(connector);
780}
781
782static const struct drm_encoder_funcs intel_dsi_funcs = {
783 .destroy = intel_encoder_destroy,
784};
785
786static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
787 .get_modes = intel_dsi_get_modes,
788 .mode_valid = intel_dsi_mode_valid,
789 .best_encoder = intel_best_encoder,
790};
791
792static const struct drm_connector_funcs intel_dsi_connector_funcs = {
793 .dpms = intel_connector_dpms,
794 .detect = intel_dsi_detect,
795 .destroy = intel_dsi_destroy,
796 .fill_modes = drm_helper_probe_single_connector_modes,
797};
798
Damien Lespiau4328633d2014-05-28 12:30:56 +0100799void intel_dsi_init(struct drm_device *dev)
Jani Nikula4e646492013-08-27 15:12:20 +0300800{
801 struct intel_dsi *intel_dsi;
802 struct intel_encoder *intel_encoder;
803 struct drm_encoder *encoder;
804 struct intel_connector *intel_connector;
805 struct drm_connector *connector;
806 struct drm_display_mode *fixed_mode = NULL;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530807 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300808 const struct intel_dsi_device *dsi;
809 unsigned int i;
810
811 DRM_DEBUG_KMS("\n");
812
Shobhit Kumar3e6bd012014-05-27 19:33:59 +0530813 /* There is no detection method for MIPI so rely on VBT */
814 if (!dev_priv->vbt.has_mipi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100815 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300816
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530817 if (IS_VALLEYVIEW(dev)) {
818 dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
819 } else {
820 DRM_ERROR("Unsupported Mipi device to reg base");
Christoph Jaeger868d6652014-06-13 21:51:22 +0200821 return;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530822 }
823
Jani Nikula4e646492013-08-27 15:12:20 +0300824 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
825 if (!intel_dsi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100826 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300827
828 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
829 if (!intel_connector) {
830 kfree(intel_dsi);
Damien Lespiau4328633d2014-05-28 12:30:56 +0100831 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300832 }
833
834 intel_encoder = &intel_dsi->base;
835 encoder = &intel_encoder->base;
836 intel_dsi->attached_connector = intel_connector;
837
Jani Nikula4e646492013-08-27 15:12:20 +0300838 connector = &intel_connector->base;
839
840 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
841
842 /* XXX: very likely not all of these are needed */
843 intel_encoder->hot_plug = intel_dsi_hot_plug;
844 intel_encoder->compute_config = intel_dsi_compute_config;
845 intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
846 intel_encoder->pre_enable = intel_dsi_pre_enable;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530847 intel_encoder->enable = intel_dsi_enable_nop;
Imre Deakc315faf2014-05-27 19:00:09 +0300848 intel_encoder->disable = intel_dsi_pre_disable;
Jani Nikula4e646492013-08-27 15:12:20 +0300849 intel_encoder->post_disable = intel_dsi_post_disable;
850 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
851 intel_encoder->get_config = intel_dsi_get_config;
852
853 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak4932e2c2014-02-11 17:12:48 +0200854 intel_connector->unregister = intel_connector_unregister;
Jani Nikula4e646492013-08-27 15:12:20 +0300855
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200856 /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
Jani Nikula17af40a2014-11-14 16:54:22 +0200857 if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200858 intel_encoder->crtc_mask = (1 << PIPE_A);
Jani Nikula17af40a2014-11-14 16:54:22 +0200859 intel_dsi->ports = (1 << PORT_A);
860 } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200861 intel_encoder->crtc_mask = (1 << PIPE_B);
Jani Nikula17af40a2014-11-14 16:54:22 +0200862 intel_dsi->ports = (1 << PORT_C);
863 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200864
Jani Nikula4e646492013-08-27 15:12:20 +0300865 for (i = 0; i < ARRAY_SIZE(intel_dsi_devices); i++) {
866 dsi = &intel_dsi_devices[i];
867 intel_dsi->dev = *dsi;
868
869 if (dsi->dev_ops->init(&intel_dsi->dev))
870 break;
871 }
872
873 if (i == ARRAY_SIZE(intel_dsi_devices)) {
874 DRM_DEBUG_KMS("no device found\n");
875 goto err;
876 }
877
878 intel_encoder->type = INTEL_OUTPUT_DSI;
Ville Syrjäläbc079e82014-03-03 16:15:28 +0200879 intel_encoder->cloneable = 0;
Jani Nikula4e646492013-08-27 15:12:20 +0300880 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
881 DRM_MODE_CONNECTOR_DSI);
882
883 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
884
885 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
886 connector->interlace_allowed = false;
887 connector->doublescan_allowed = false;
888
889 intel_connector_attach_encoder(intel_connector, intel_encoder);
890
Thomas Wood34ea3d32014-05-29 16:57:41 +0100891 drm_connector_register(connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300892
893 fixed_mode = dsi->dev_ops->get_modes(&intel_dsi->dev);
894 if (!fixed_mode) {
895 DRM_DEBUG_KMS("no fixed mode\n");
896 goto err;
897 }
898
899 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Vandana Kannan4b6ed682014-02-11 14:26:36 +0530900 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
Jani Nikula4e646492013-08-27 15:12:20 +0300901
Damien Lespiau4328633d2014-05-28 12:30:56 +0100902 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300903
904err:
905 drm_encoder_cleanup(&intel_encoder->base);
906 kfree(intel_dsi);
907 kfree(intel_connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300908}