blob: 6620124eccc2bc151e6b0ed58c6de47314ed4b64 [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 */
Shobhit Kumare1047022014-04-09 13:59:35 +0530210 dpi_send_cmd(intel_dsi, TURN_ON, DPI_LP_MODE_EN);
Jani Nikula4e646492013-08-27 15:12:20 +0300211 msleep(100);
212
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530213 if (intel_dsi->dev.dev_ops->enable)
214 intel_dsi->dev.dev_ops->enable(&intel_dsi->dev);
215
Shobhit Kumar13813082014-07-12 17:17:22 +0530216 wait_for_dsi_fifo_empty(intel_dsi);
217
Gaurav K Singh5505a242014-12-04 10:58:47 +0530218 intel_dsi_port_enable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300219 }
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530220}
Jani Nikula4e646492013-08-27 15:12:20 +0300221
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530222static void intel_dsi_pre_enable(struct intel_encoder *encoder)
223{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530224 struct drm_device *dev = encoder->base.dev;
225 struct drm_i915_private *dev_priv = dev->dev_private;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530226 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530227 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
228 enum pipe pipe = intel_crtc->pipe;
229 u32 tmp;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530230
231 DRM_DEBUG_KMS("\n");
232
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530233 /* Disable DPOunit clock gating, can stall pipe
234 * and we need DPLL REFA always enabled */
235 tmp = I915_READ(DPLL(pipe));
236 tmp |= DPLL_REFA_CLK_ENABLE_VLV;
237 I915_WRITE(DPLL(pipe), tmp);
238
Shobhit Kumarf573de52014-07-30 20:32:37 +0530239 /* update the hw state for DPLL */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200240 intel_crtc->config->dpll_hw_state.dpll = DPLL_INTEGRATED_CLOCK_VLV |
Daniel Vetter7f3de832014-07-30 22:34:27 +0200241 DPLL_REFA_CLK_ENABLE_VLV;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530242
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530243 tmp = I915_READ(DSPCLK_GATE_D);
244 tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
245 I915_WRITE(DSPCLK_GATE_D, tmp);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530246
247 /* put device in ready state */
248 intel_dsi_device_ready(encoder);
249
Shobhit Kumardf38e652014-04-14 11:18:26 +0530250 msleep(intel_dsi->panel_on_delay);
251
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530252 if (intel_dsi->dev.dev_ops->panel_reset)
253 intel_dsi->dev.dev_ops->panel_reset(&intel_dsi->dev);
254
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530255 if (intel_dsi->dev.dev_ops->send_otp_cmds)
256 intel_dsi->dev.dev_ops->send_otp_cmds(&intel_dsi->dev);
257
Shobhit Kumar13813082014-07-12 17:17:22 +0530258 wait_for_dsi_fifo_empty(intel_dsi);
259
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530260 /* Enable port in pre-enable phase itself because as per hw team
261 * recommendation, port should be enabled befor plane & pipe */
262 intel_dsi_enable(encoder);
263}
264
265static void intel_dsi_enable_nop(struct intel_encoder *encoder)
266{
267 DRM_DEBUG_KMS("\n");
268
269 /* for DSI port enable has to be done before pipe
270 * and plane enable, so port enable is done in
271 * pre_enable phase itself unlike other encoders
272 */
Jani Nikula4e646492013-08-27 15:12:20 +0300273}
274
Imre Deakc315faf2014-05-27 19:00:09 +0300275static void intel_dsi_pre_disable(struct intel_encoder *encoder)
276{
277 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
278
279 DRM_DEBUG_KMS("\n");
280
281 if (is_vid_mode(intel_dsi)) {
282 /* Send Shutdown command to the panel in LP mode */
283 dpi_send_cmd(intel_dsi, SHUTDOWN, DPI_LP_MODE_EN);
284 msleep(10);
285 }
286}
287
Jani Nikula4e646492013-08-27 15:12:20 +0300288static void intel_dsi_disable(struct intel_encoder *encoder)
289{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530290 struct drm_device *dev = encoder->base.dev;
291 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300292 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530293 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300294 u32 temp;
295
296 DRM_DEBUG_KMS("\n");
297
Jani Nikula4e646492013-08-27 15:12:20 +0300298 if (is_vid_mode(intel_dsi)) {
Shobhit Kumar13813082014-07-12 17:17:22 +0530299 wait_for_dsi_fifo_empty(intel_dsi);
300
Gaurav K Singh5505a242014-12-04 10:58:47 +0530301 intel_dsi_port_disable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300302 msleep(2);
303 }
304
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530305 for_each_dsi_port(port, intel_dsi->ports) {
306 /* Panel commands can be sent when clock is in LP11 */
307 I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530308
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530309 temp = I915_READ(MIPI_CTRL(port));
310 temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
311 I915_WRITE(MIPI_CTRL(port), temp |
312 intel_dsi->escape_clk_div <<
313 ESCAPE_CLOCK_DIVIDER_SHIFT);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530314
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530315 I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530316
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530317 temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
318 temp &= ~VID_MODE_FORMAT_MASK;
319 I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530320
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530321 I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
322 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530323 /* if disable packets are sent before sending shutdown packet then in
324 * some next enable sequence send turn on packet error is observed */
325 if (intel_dsi->dev.dev_ops->disable)
326 intel_dsi->dev.dev_ops->disable(&intel_dsi->dev);
Shobhit Kumar13813082014-07-12 17:17:22 +0530327
328 wait_for_dsi_fifo_empty(intel_dsi);
Jani Nikula4e646492013-08-27 15:12:20 +0300329}
330
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530331static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300332{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530333 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530334 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
335 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530336 u32 val;
337
Jani Nikula4e646492013-08-27 15:12:20 +0300338 DRM_DEBUG_KMS("\n");
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530339 for_each_dsi_port(port, intel_dsi->ports) {
ymohanmabe4fc042013-08-27 23:40:56 +0300340
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530341 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
342 ULPS_STATE_ENTER);
343 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530344
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530345 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
346 ULPS_STATE_EXIT);
347 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530348
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 /* Wait till Clock lanes are in LP-00 state for MIPI Port A
354 * only. MIPI Port C has no similar bit for checking
355 */
356 if (wait_for(((I915_READ(MIPI_PORT_CTRL(PORT_A)) & AFE_LATCHOUT)
357 == 0x00000), 30))
358 DRM_ERROR("DSI LP not going Low\n");
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530359
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530360 val = I915_READ(MIPI_PORT_CTRL(port));
361 /* Disable MIPI PHY transparent latch
362 * Common bit for both MIPI Port A & MIPI Port C
363 */
364 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val & ~LP_OUTPUT_HOLD);
365 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530366
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530367 I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
368 usleep_range(2000, 2500);
369 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530370
ymohanmabe4fc042013-08-27 23:40:56 +0300371 vlv_disable_dsi_pll(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300372}
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530373
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530374static void intel_dsi_post_disable(struct intel_encoder *encoder)
375{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530376 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530377 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530378 u32 val;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530379
380 DRM_DEBUG_KMS("\n");
381
Imre Deakc315faf2014-05-27 19:00:09 +0300382 intel_dsi_disable(encoder);
383
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530384 intel_dsi_clear_device_ready(encoder);
385
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530386 val = I915_READ(DSPCLK_GATE_D);
387 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
388 I915_WRITE(DSPCLK_GATE_D, val);
389
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530390 if (intel_dsi->dev.dev_ops->disable_panel_power)
391 intel_dsi->dev.dev_ops->disable_panel_power(&intel_dsi->dev);
Shobhit Kumardf38e652014-04-14 11:18:26 +0530392
393 msleep(intel_dsi->panel_off_delay);
394 msleep(intel_dsi->panel_pwr_cycle_delay);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530395}
Jani Nikula4e646492013-08-27 15:12:20 +0300396
397static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
398 enum pipe *pipe)
399{
400 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530401 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
402 struct drm_device *dev = encoder->base.dev;
Imre Deak6d129be2014-03-05 16:20:54 +0200403 enum intel_display_power_domain power_domain;
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530404 u32 dpi_enabled, func;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200405 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300406
407 DRM_DEBUG_KMS("\n");
408
Imre Deak6d129be2014-03-05 16:20:54 +0200409 power_domain = intel_display_port_power_domain(encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200410 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200411 return false;
412
Jani Nikula4e646492013-08-27 15:12:20 +0300413 /* XXX: this only works for one DSI output */
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530414 for_each_dsi_port(port, intel_dsi->ports) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200415 func = I915_READ(MIPI_DSI_FUNC_PRG(port));
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530416 dpi_enabled = I915_READ(MIPI_PORT_CTRL(port)) &
417 DPI_ENABLE;
Jani Nikula4e646492013-08-27 15:12:20 +0300418
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530419 /* Due to some hardware limitations on BYT, MIPI Port C DPI
420 * Enable bit does not get set. To check whether DSI Port C
421 * was enabled in BIOS, check the Pipe B enable bit
422 */
423 if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) &&
424 (port == PORT_C))
425 dpi_enabled = I915_READ(PIPECONF(PIPE_B)) &
426 PIPECONF_ENABLE;
427
428 if (dpi_enabled || (func & CMD_MODE_DATA_WIDTH_MASK)) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200429 if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530430 *pipe = port == PORT_A ? PIPE_A : PIPE_B;
Jani Nikula4e646492013-08-27 15:12:20 +0300431 return true;
432 }
433 }
434 }
435
436 return false;
437}
438
439static void intel_dsi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200440 struct intel_crtc_state *pipe_config)
Jani Nikula4e646492013-08-27 15:12:20 +0300441{
Shobhit Kumarf573de52014-07-30 20:32:37 +0530442 u32 pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300443 DRM_DEBUG_KMS("\n");
444
Shobhit Kumarf573de52014-07-30 20:32:37 +0530445 /*
446 * DPLL_MD is not used in case of DSI, reading will get some default value
447 * set dpll_md = 0
448 */
449 pipe_config->dpll_hw_state.dpll_md = 0;
450
451 pclk = vlv_get_dsi_pclk(encoder, pipe_config->pipe_bpp);
452 if (!pclk)
453 return;
454
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200455 pipe_config->base.adjusted_mode.crtc_clock = pclk;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530456 pipe_config->port_clock = pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300457}
458
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000459static enum drm_mode_status
460intel_dsi_mode_valid(struct drm_connector *connector,
461 struct drm_display_mode *mode)
Jani Nikula4e646492013-08-27 15:12:20 +0300462{
463 struct intel_connector *intel_connector = to_intel_connector(connector);
464 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
465 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
466
467 DRM_DEBUG_KMS("\n");
468
469 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
470 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
471 return MODE_NO_DBLESCAN;
472 }
473
474 if (fixed_mode) {
475 if (mode->hdisplay > fixed_mode->hdisplay)
476 return MODE_PANEL;
477 if (mode->vdisplay > fixed_mode->vdisplay)
478 return MODE_PANEL;
479 }
480
481 return intel_dsi->dev.dev_ops->mode_valid(&intel_dsi->dev, mode);
482}
483
484/* return txclkesc cycles in terms of divider and duration in us */
485static u16 txclkesc(u32 divider, unsigned int us)
486{
487 switch (divider) {
488 case ESCAPE_CLOCK_DIVIDER_1:
489 default:
490 return 20 * us;
491 case ESCAPE_CLOCK_DIVIDER_2:
492 return 10 * us;
493 case ESCAPE_CLOCK_DIVIDER_4:
494 return 5 * us;
495 }
496}
497
498/* return pixels in terms of txbyteclkhs */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530499static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
500 u16 burst_mode_ratio)
Jani Nikula4e646492013-08-27 15:12:20 +0300501{
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530502 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200503 8 * 100), lane_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300504}
505
506static void set_dsi_timings(struct drm_encoder *encoder,
507 const struct drm_display_mode *mode)
508{
509 struct drm_device *dev = encoder->dev;
510 struct drm_i915_private *dev_priv = dev->dev_private;
511 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
512 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530513 enum port port;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200514 unsigned int bpp = intel_crtc->config->pipe_bpp;
Jani Nikula4e646492013-08-27 15:12:20 +0300515 unsigned int lane_count = intel_dsi->lane_count;
516
517 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
518
519 hactive = mode->hdisplay;
520 hfp = mode->hsync_start - mode->hdisplay;
521 hsync = mode->hsync_end - mode->hsync_start;
522 hbp = mode->htotal - mode->hsync_end;
523
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530524 if (intel_dsi->dual_link) {
525 hactive /= 2;
526 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
527 hactive += intel_dsi->pixel_overlap;
528 hfp /= 2;
529 hsync /= 2;
530 hbp /= 2;
531 }
532
Jani Nikula4e646492013-08-27 15:12:20 +0300533 vfp = mode->vsync_start - mode->vdisplay;
534 vsync = mode->vsync_end - mode->vsync_start;
535 vbp = mode->vtotal - mode->vsync_end;
536
537 /* horizontal values are in terms of high speed byte clock */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530538 hactive = txbyteclkhs(hactive, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200539 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530540 hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
541 hsync = txbyteclkhs(hsync, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200542 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530543 hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
Jani Nikula4e646492013-08-27 15:12:20 +0300544
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530545 for_each_dsi_port(port, intel_dsi->ports) {
546 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
547 I915_WRITE(MIPI_HFP_COUNT(port), hfp);
Jani Nikula4e646492013-08-27 15:12:20 +0300548
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530549 /* meaningful for video mode non-burst sync pulse mode only,
550 * can be zero for non-burst sync events and burst modes */
551 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
552 I915_WRITE(MIPI_HBP_COUNT(port), hbp);
Jani Nikula4e646492013-08-27 15:12:20 +0300553
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530554 /* vertical values are in terms of lines */
555 I915_WRITE(MIPI_VFP_COUNT(port), vfp);
556 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
557 I915_WRITE(MIPI_VBP_COUNT(port), vbp);
558 }
Jani Nikula4e646492013-08-27 15:12:20 +0300559}
560
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200561static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300562{
563 struct drm_encoder *encoder = &intel_encoder->base;
564 struct drm_device *dev = encoder->dev;
565 struct drm_i915_private *dev_priv = dev->dev_private;
566 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
567 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
568 struct drm_display_mode *adjusted_mode =
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200569 &intel_crtc->config->base.adjusted_mode;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530570 enum port port;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200571 unsigned int bpp = intel_crtc->config->pipe_bpp;
Jani Nikula4e646492013-08-27 15:12:20 +0300572 u32 val, tmp;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530573 u16 mode_hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300574
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200575 DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
Jani Nikula4e646492013-08-27 15:12:20 +0300576
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530577 mode_hdisplay = adjusted_mode->hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300578
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530579 if (intel_dsi->dual_link) {
580 mode_hdisplay /= 2;
581 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
582 mode_hdisplay += intel_dsi->pixel_overlap;
583 }
Jani Nikula4e646492013-08-27 15:12:20 +0300584
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530585 for_each_dsi_port(port, intel_dsi->ports) {
586 /* escape clock divider, 20MHz, shared for A and C.
587 * device ready must be off when doing this! txclkesc? */
588 tmp = I915_READ(MIPI_CTRL(PORT_A));
589 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
590 I915_WRITE(MIPI_CTRL(PORT_A), tmp | ESCAPE_CLOCK_DIVIDER_1);
Jani Nikula4e646492013-08-27 15:12:20 +0300591
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530592 /* read request priority is per pipe */
593 tmp = I915_READ(MIPI_CTRL(port));
594 tmp &= ~READ_REQUEST_PRIORITY_MASK;
595 I915_WRITE(MIPI_CTRL(port), tmp | READ_REQUEST_PRIORITY_HIGH);
Jani Nikula4e646492013-08-27 15:12:20 +0300596
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530597 /* XXX: why here, why like this? handling in irq handler?! */
598 I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
599 I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
600
601 I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
602
603 I915_WRITE(MIPI_DPI_RESOLUTION(port),
604 adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
605 mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
606 }
Jani Nikula4e646492013-08-27 15:12:20 +0300607
608 set_dsi_timings(encoder, adjusted_mode);
609
610 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
611 if (is_cmd_mode(intel_dsi)) {
612 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
613 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
614 } else {
615 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
616
617 /* XXX: cross-check bpp vs. pixel format? */
618 val |= intel_dsi->pixel_format;
619 }
Jani Nikula4e646492013-08-27 15:12:20 +0300620
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530621 tmp = 0;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530622 if (intel_dsi->eotp_pkt == 0)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530623 tmp |= EOT_DISABLE;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530624 if (intel_dsi->clock_stop)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530625 tmp |= CLOCKSTOP;
Jani Nikula4e646492013-08-27 15:12:20 +0300626
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530627 for_each_dsi_port(port, intel_dsi->ports) {
628 I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300629
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530630 /* timeouts for recovery. one frame IIUC. if counter expires,
631 * EOT and stop state. */
Shobhit Kumarcf4dbd22014-04-14 11:18:25 +0530632
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530633 /*
634 * In burst mode, value greater than one DPI line Time in byte
635 * clock (txbyteclkhs) To timeout this timer 1+ of the above
636 * said value is recommended.
637 *
638 * In non-burst mode, Value greater than one DPI frame time in
639 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
640 * said value is recommended.
641 *
642 * In DBI only mode, value greater than one DBI frame time in
643 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
644 * said value is recommended.
645 */
Jani Nikula4e646492013-08-27 15:12:20 +0300646
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530647 if (is_vid_mode(intel_dsi) &&
648 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
649 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
650 txbyteclkhs(adjusted_mode->htotal, bpp,
651 intel_dsi->lane_count,
652 intel_dsi->burst_mode_ratio) + 1);
653 } else {
654 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
655 txbyteclkhs(adjusted_mode->vtotal *
656 adjusted_mode->htotal,
657 bpp, intel_dsi->lane_count,
658 intel_dsi->burst_mode_ratio) + 1);
659 }
660 I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
661 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
662 intel_dsi->turn_arnd_val);
663 I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
664 intel_dsi->rst_timer_val);
Jani Nikula4e646492013-08-27 15:12:20 +0300665
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530666 /* dphy stuff */
Jani Nikula4e646492013-08-27 15:12:20 +0300667
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530668 /* in terms of low power clock */
669 I915_WRITE(MIPI_INIT_COUNT(port),
670 txclkesc(intel_dsi->escape_clk_div, 100));
Jani Nikula4e646492013-08-27 15:12:20 +0300671
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530672
673 /* recovery disables */
674 I915_WRITE(MIPI_EOT_DISABLE(port), val);
675
676 /* in terms of low power clock */
677 I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
678
679 /* in terms of txbyteclkhs. actual high to low switch +
680 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
681 *
682 * XXX: write MIPI_STOP_STATE_STALL?
683 */
684 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
685 intel_dsi->hs_to_lp_count);
686
687 /* XXX: low power clock equivalence in terms of byte clock.
688 * the number of byte clocks occupied in one low power clock.
689 * based on txbyteclkhs and txclkesc.
690 * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
691 * ) / 105.???
692 */
693 I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
694
695 /* the bw essential for transmitting 16 long packets containing
696 * 252 bytes meant for dcs write memory command is programmed in
697 * this register in terms of byte clocks. based on dsi transfer
698 * rate and the number of lanes configured the time taken to
699 * transmit 16 long packets in a dsi stream varies. */
700 I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
701
702 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
703 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
704 intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
705
706 if (is_vid_mode(intel_dsi))
707 /* Some panels might have resolution which is not a
708 * multiple of 64 like 1366 x 768. Enable RANDOM
709 * resolution support for such panels by default */
710 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
711 intel_dsi->video_frmt_cfg_bits |
712 intel_dsi->video_mode_format |
713 IP_TG_CONFIG |
714 RANDOM_DPI_DISPLAY_RESOLUTION);
715 }
Jani Nikula4e646492013-08-27 15:12:20 +0300716}
717
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200718static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
719{
720 DRM_DEBUG_KMS("\n");
721
722 intel_dsi_prepare(encoder);
723
724 vlv_enable_dsi_pll(encoder);
725}
726
Jani Nikula4e646492013-08-27 15:12:20 +0300727static enum drm_connector_status
728intel_dsi_detect(struct drm_connector *connector, bool force)
729{
730 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
Imre Deak671dedd2014-03-05 16:20:53 +0200731 struct intel_encoder *intel_encoder = &intel_dsi->base;
732 enum intel_display_power_domain power_domain;
733 enum drm_connector_status connector_status;
734 struct drm_i915_private *dev_priv = intel_encoder->base.dev->dev_private;
735
Jani Nikula4e646492013-08-27 15:12:20 +0300736 DRM_DEBUG_KMS("\n");
Imre Deak671dedd2014-03-05 16:20:53 +0200737 power_domain = intel_display_port_power_domain(intel_encoder);
738
739 intel_display_power_get(dev_priv, power_domain);
740 connector_status = intel_dsi->dev.dev_ops->detect(&intel_dsi->dev);
741 intel_display_power_put(dev_priv, power_domain);
742
743 return connector_status;
Jani Nikula4e646492013-08-27 15:12:20 +0300744}
745
746static int intel_dsi_get_modes(struct drm_connector *connector)
747{
748 struct intel_connector *intel_connector = to_intel_connector(connector);
749 struct drm_display_mode *mode;
750
751 DRM_DEBUG_KMS("\n");
752
753 if (!intel_connector->panel.fixed_mode) {
754 DRM_DEBUG_KMS("no fixed mode\n");
755 return 0;
756 }
757
758 mode = drm_mode_duplicate(connector->dev,
759 intel_connector->panel.fixed_mode);
760 if (!mode) {
761 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
762 return 0;
763 }
764
765 drm_mode_probed_add(connector, mode);
766 return 1;
767}
768
769static void intel_dsi_destroy(struct drm_connector *connector)
770{
771 struct intel_connector *intel_connector = to_intel_connector(connector);
772
773 DRM_DEBUG_KMS("\n");
774 intel_panel_fini(&intel_connector->panel);
Jani Nikula4e646492013-08-27 15:12:20 +0300775 drm_connector_cleanup(connector);
776 kfree(connector);
777}
778
779static const struct drm_encoder_funcs intel_dsi_funcs = {
780 .destroy = intel_encoder_destroy,
781};
782
783static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
784 .get_modes = intel_dsi_get_modes,
785 .mode_valid = intel_dsi_mode_valid,
786 .best_encoder = intel_best_encoder,
787};
788
789static const struct drm_connector_funcs intel_dsi_connector_funcs = {
790 .dpms = intel_connector_dpms,
791 .detect = intel_dsi_detect,
792 .destroy = intel_dsi_destroy,
793 .fill_modes = drm_helper_probe_single_connector_modes,
794};
795
Damien Lespiau4328633d2014-05-28 12:30:56 +0100796void intel_dsi_init(struct drm_device *dev)
Jani Nikula4e646492013-08-27 15:12:20 +0300797{
798 struct intel_dsi *intel_dsi;
799 struct intel_encoder *intel_encoder;
800 struct drm_encoder *encoder;
801 struct intel_connector *intel_connector;
802 struct drm_connector *connector;
803 struct drm_display_mode *fixed_mode = NULL;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530804 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300805 const struct intel_dsi_device *dsi;
806 unsigned int i;
807
808 DRM_DEBUG_KMS("\n");
809
Shobhit Kumar3e6bd012014-05-27 19:33:59 +0530810 /* There is no detection method for MIPI so rely on VBT */
811 if (!dev_priv->vbt.has_mipi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100812 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300813
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530814 if (IS_VALLEYVIEW(dev)) {
815 dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
816 } else {
817 DRM_ERROR("Unsupported Mipi device to reg base");
Christoph Jaeger868d6652014-06-13 21:51:22 +0200818 return;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530819 }
820
Jani Nikula4e646492013-08-27 15:12:20 +0300821 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
822 if (!intel_dsi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100823 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300824
825 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
826 if (!intel_connector) {
827 kfree(intel_dsi);
Damien Lespiau4328633d2014-05-28 12:30:56 +0100828 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300829 }
830
831 intel_encoder = &intel_dsi->base;
832 encoder = &intel_encoder->base;
833 intel_dsi->attached_connector = intel_connector;
834
Jani Nikula4e646492013-08-27 15:12:20 +0300835 connector = &intel_connector->base;
836
837 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
838
839 /* XXX: very likely not all of these are needed */
840 intel_encoder->hot_plug = intel_dsi_hot_plug;
841 intel_encoder->compute_config = intel_dsi_compute_config;
842 intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
843 intel_encoder->pre_enable = intel_dsi_pre_enable;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530844 intel_encoder->enable = intel_dsi_enable_nop;
Imre Deakc315faf2014-05-27 19:00:09 +0300845 intel_encoder->disable = intel_dsi_pre_disable;
Jani Nikula4e646492013-08-27 15:12:20 +0300846 intel_encoder->post_disable = intel_dsi_post_disable;
847 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
848 intel_encoder->get_config = intel_dsi_get_config;
849
850 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak4932e2c2014-02-11 17:12:48 +0200851 intel_connector->unregister = intel_connector_unregister;
Jani Nikula4e646492013-08-27 15:12:20 +0300852
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200853 /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
Jani Nikula17af40a2014-11-14 16:54:22 +0200854 if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200855 intel_encoder->crtc_mask = (1 << PIPE_A);
Jani Nikula17af40a2014-11-14 16:54:22 +0200856 intel_dsi->ports = (1 << PORT_A);
857 } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200858 intel_encoder->crtc_mask = (1 << PIPE_B);
Jani Nikula17af40a2014-11-14 16:54:22 +0200859 intel_dsi->ports = (1 << PORT_C);
860 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200861
Jani Nikula4e646492013-08-27 15:12:20 +0300862 for (i = 0; i < ARRAY_SIZE(intel_dsi_devices); i++) {
863 dsi = &intel_dsi_devices[i];
864 intel_dsi->dev = *dsi;
865
866 if (dsi->dev_ops->init(&intel_dsi->dev))
867 break;
868 }
869
870 if (i == ARRAY_SIZE(intel_dsi_devices)) {
871 DRM_DEBUG_KMS("no device found\n");
872 goto err;
873 }
874
875 intel_encoder->type = INTEL_OUTPUT_DSI;
Ville Syrjäläbc079e82014-03-03 16:15:28 +0200876 intel_encoder->cloneable = 0;
Jani Nikula4e646492013-08-27 15:12:20 +0300877 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
878 DRM_MODE_CONNECTOR_DSI);
879
880 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
881
882 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
883 connector->interlace_allowed = false;
884 connector->doublescan_allowed = false;
885
886 intel_connector_attach_encoder(intel_connector, intel_encoder);
887
Thomas Wood34ea3d32014-05-29 16:57:41 +0100888 drm_connector_register(connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300889
890 fixed_mode = dsi->dev_ops->get_modes(&intel_dsi->dev);
891 if (!fixed_mode) {
892 DRM_DEBUG_KMS("no fixed mode\n");
893 goto err;
894 }
895
896 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Vandana Kannan4b6ed682014-02-11 14:26:36 +0530897 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
Jani Nikula4e646492013-08-27 15:12:20 +0300898
Damien Lespiau4328633d2014-05-28 12:30:56 +0100899 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300900
901err:
902 drm_encoder_cleanup(&intel_encoder->base);
903 kfree(intel_dsi);
904 kfree(intel_connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300905}