blob: fd4d3972c8cda998433b2cd48efea24b9324610e [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,
81 struct intel_crtc_config *config)
82{
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;
87 struct drm_display_mode *adjusted_mode = &config->adjusted_mode;
88 struct drm_display_mode *mode = &config->requested_mode;
89
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 Singh369602d2014-12-05 14:09:28 +0530114 for_each_dsi_port(port, intel_dsi->ports) {
115 temp = I915_READ(MIPI_PORT_CTRL(port));
116 temp &= ~LANE_CONFIGURATION_MASK;
117 temp &= ~DUAL_LINK_MODE_MASK;
118
119 if (intel_dsi->ports == ((1 << PORT_A) | (1 << PORT_C))) {
120 temp |= (intel_dsi->dual_link - 1)
121 << DUAL_LINK_MODE_SHIFT;
122 temp |= intel_crtc->pipe ?
123 LANE_CONFIGURATION_DUAL_LINK_B :
124 LANE_CONFIGURATION_DUAL_LINK_A;
125 }
126 /* assert ip_tg_enable signal */
127 I915_WRITE(MIPI_PORT_CTRL(port), temp | DPI_ENABLE);
128 POSTING_READ(MIPI_PORT_CTRL(port));
129 }
Gaurav K Singh5505a242014-12-04 10:58:47 +0530130}
131
132static void intel_dsi_port_disable(struct intel_encoder *encoder)
133{
134 struct drm_device *dev = encoder->base.dev;
135 struct drm_i915_private *dev_priv = dev->dev_private;
Gaurav K Singh369602d2014-12-05 14:09:28 +0530136 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
137 enum port port;
Gaurav K Singh5505a242014-12-04 10:58:47 +0530138 u32 temp;
139
Gaurav K Singh369602d2014-12-05 14:09:28 +0530140 for_each_dsi_port(port, intel_dsi->ports) {
141 /* de-assert ip_tg_enable signal */
142 temp = I915_READ(MIPI_PORT_CTRL(port));
143 I915_WRITE(MIPI_PORT_CTRL(port), temp & ~DPI_ENABLE);
144 POSTING_READ(MIPI_PORT_CTRL(port));
145 }
Gaurav K Singh5505a242014-12-04 10:58:47 +0530146}
147
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530148static void intel_dsi_device_ready(struct intel_encoder *encoder)
149{
150 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
151 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200152 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530153 u32 val;
154
155 DRM_DEBUG_KMS("\n");
156
Shobhit Kumar2095f9f2014-04-09 13:59:30 +0530157 mutex_lock(&dev_priv->dpio_lock);
158 /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
159 * needed everytime after power gate */
160 vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
161 mutex_unlock(&dev_priv->dpio_lock);
162
163 /* bandgap reset is needed after everytime we do power gate */
164 band_gap_reset(dev_priv);
165
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200166 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530167 usleep_range(2500, 3000);
168
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200169 val = I915_READ(MIPI_PORT_CTRL(port));
170 I915_WRITE(MIPI_PORT_CTRL(port), val | LP_OUTPUT_HOLD);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530171 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530172
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200173 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530174 usleep_range(2500, 3000);
175
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200176 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530177 usleep_range(2500, 3000);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530178}
Jani Nikula4e646492013-08-27 15:12:20 +0300179
180static void intel_dsi_enable(struct intel_encoder *encoder)
181{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530182 struct drm_device *dev = encoder->base.dev;
183 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300184 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
185 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200186 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Jani Nikula4e646492013-08-27 15:12:20 +0300187
188 DRM_DEBUG_KMS("\n");
189
Jani Nikula4e646492013-08-27 15:12:20 +0300190 if (is_cmd_mode(intel_dsi))
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200191 I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530192 else {
Jani Nikula4e646492013-08-27 15:12:20 +0300193 msleep(20); /* XXX */
Shobhit Kumare1047022014-04-09 13:59:35 +0530194 dpi_send_cmd(intel_dsi, TURN_ON, DPI_LP_MODE_EN);
Jani Nikula4e646492013-08-27 15:12:20 +0300195 msleep(100);
196
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530197 if (intel_dsi->dev.dev_ops->enable)
198 intel_dsi->dev.dev_ops->enable(&intel_dsi->dev);
199
Shobhit Kumar13813082014-07-12 17:17:22 +0530200 wait_for_dsi_fifo_empty(intel_dsi);
201
Gaurav K Singh5505a242014-12-04 10:58:47 +0530202 intel_dsi_port_enable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300203 }
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530204}
Jani Nikula4e646492013-08-27 15:12:20 +0300205
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530206static void intel_dsi_pre_enable(struct intel_encoder *encoder)
207{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530208 struct drm_device *dev = encoder->base.dev;
209 struct drm_i915_private *dev_priv = dev->dev_private;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530210 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530211 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
212 enum pipe pipe = intel_crtc->pipe;
213 u32 tmp;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530214
215 DRM_DEBUG_KMS("\n");
216
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530217 /* Disable DPOunit clock gating, can stall pipe
218 * and we need DPLL REFA always enabled */
219 tmp = I915_READ(DPLL(pipe));
220 tmp |= DPLL_REFA_CLK_ENABLE_VLV;
221 I915_WRITE(DPLL(pipe), tmp);
222
Shobhit Kumarf573de52014-07-30 20:32:37 +0530223 /* update the hw state for DPLL */
224 intel_crtc->config.dpll_hw_state.dpll = DPLL_INTEGRATED_CLOCK_VLV |
Daniel Vetter7f3de832014-07-30 22:34:27 +0200225 DPLL_REFA_CLK_ENABLE_VLV;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530226
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530227 tmp = I915_READ(DSPCLK_GATE_D);
228 tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
229 I915_WRITE(DSPCLK_GATE_D, tmp);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530230
231 /* put device in ready state */
232 intel_dsi_device_ready(encoder);
233
Shobhit Kumardf38e652014-04-14 11:18:26 +0530234 msleep(intel_dsi->panel_on_delay);
235
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530236 if (intel_dsi->dev.dev_ops->panel_reset)
237 intel_dsi->dev.dev_ops->panel_reset(&intel_dsi->dev);
238
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530239 if (intel_dsi->dev.dev_ops->send_otp_cmds)
240 intel_dsi->dev.dev_ops->send_otp_cmds(&intel_dsi->dev);
241
Shobhit Kumar13813082014-07-12 17:17:22 +0530242 wait_for_dsi_fifo_empty(intel_dsi);
243
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530244 /* Enable port in pre-enable phase itself because as per hw team
245 * recommendation, port should be enabled befor plane & pipe */
246 intel_dsi_enable(encoder);
247}
248
249static void intel_dsi_enable_nop(struct intel_encoder *encoder)
250{
251 DRM_DEBUG_KMS("\n");
252
253 /* for DSI port enable has to be done before pipe
254 * and plane enable, so port enable is done in
255 * pre_enable phase itself unlike other encoders
256 */
Jani Nikula4e646492013-08-27 15:12:20 +0300257}
258
Imre Deakc315faf2014-05-27 19:00:09 +0300259static void intel_dsi_pre_disable(struct intel_encoder *encoder)
260{
261 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
262
263 DRM_DEBUG_KMS("\n");
264
265 if (is_vid_mode(intel_dsi)) {
266 /* Send Shutdown command to the panel in LP mode */
267 dpi_send_cmd(intel_dsi, SHUTDOWN, DPI_LP_MODE_EN);
268 msleep(10);
269 }
270}
271
Jani Nikula4e646492013-08-27 15:12:20 +0300272static void intel_dsi_disable(struct intel_encoder *encoder)
273{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530274 struct drm_device *dev = encoder->base.dev;
275 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300276 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
277 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200278 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Jani Nikula4e646492013-08-27 15:12:20 +0300279 u32 temp;
280
281 DRM_DEBUG_KMS("\n");
282
Jani Nikula4e646492013-08-27 15:12:20 +0300283 if (is_vid_mode(intel_dsi)) {
Shobhit Kumar13813082014-07-12 17:17:22 +0530284 wait_for_dsi_fifo_empty(intel_dsi);
285
Gaurav K Singh5505a242014-12-04 10:58:47 +0530286 intel_dsi_port_disable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300287 msleep(2);
288 }
289
Shobhit Kumar339023e2014-04-09 13:59:34 +0530290 /* Panel commands can be sent when clock is in LP11 */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200291 I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530292
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200293 temp = I915_READ(MIPI_CTRL(port));
Shobhit Kumar339023e2014-04-09 13:59:34 +0530294 temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200295 I915_WRITE(MIPI_CTRL(port), temp |
Daniel Vetter7f3de832014-07-30 22:34:27 +0200296 intel_dsi->escape_clk_div <<
297 ESCAPE_CLOCK_DIVIDER_SHIFT);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530298
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200299 I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530300
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200301 temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
Shobhit Kumar339023e2014-04-09 13:59:34 +0530302 temp &= ~VID_MODE_FORMAT_MASK;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200303 I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530304
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200305 I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530306
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530307 /* if disable packets are sent before sending shutdown packet then in
308 * some next enable sequence send turn on packet error is observed */
309 if (intel_dsi->dev.dev_ops->disable)
310 intel_dsi->dev.dev_ops->disable(&intel_dsi->dev);
Shobhit Kumar13813082014-07-12 17:17:22 +0530311
312 wait_for_dsi_fifo_empty(intel_dsi);
Jani Nikula4e646492013-08-27 15:12:20 +0300313}
314
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530315static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300316{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530317 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
318 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200319 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530320 u32 val;
321
Jani Nikula4e646492013-08-27 15:12:20 +0300322 DRM_DEBUG_KMS("\n");
ymohanmabe4fc042013-08-27 23:40:56 +0300323
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200324 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | ULPS_STATE_ENTER);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530325 usleep_range(2000, 2500);
326
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200327 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | ULPS_STATE_EXIT);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530328 usleep_range(2000, 2500);
329
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200330 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | ULPS_STATE_ENTER);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530331 usleep_range(2000, 2500);
332
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200333 if (wait_for(((I915_READ(MIPI_PORT_CTRL(port)) & AFE_LATCHOUT)
Daniel Vetter7f3de832014-07-30 22:34:27 +0200334 == 0x00000), 30))
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530335 DRM_ERROR("DSI LP not going Low\n");
336
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200337 val = I915_READ(MIPI_PORT_CTRL(port));
338 I915_WRITE(MIPI_PORT_CTRL(port), val & ~LP_OUTPUT_HOLD);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530339 usleep_range(1000, 1500);
340
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200341 I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530342 usleep_range(2000, 2500);
343
ymohanmabe4fc042013-08-27 23:40:56 +0300344 vlv_disable_dsi_pll(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300345}
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530346
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530347static void intel_dsi_post_disable(struct intel_encoder *encoder)
348{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530349 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530350 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530351 u32 val;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530352
353 DRM_DEBUG_KMS("\n");
354
Imre Deakc315faf2014-05-27 19:00:09 +0300355 intel_dsi_disable(encoder);
356
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530357 intel_dsi_clear_device_ready(encoder);
358
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530359 val = I915_READ(DSPCLK_GATE_D);
360 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
361 I915_WRITE(DSPCLK_GATE_D, val);
362
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530363 if (intel_dsi->dev.dev_ops->disable_panel_power)
364 intel_dsi->dev.dev_ops->disable_panel_power(&intel_dsi->dev);
Shobhit Kumardf38e652014-04-14 11:18:26 +0530365
366 msleep(intel_dsi->panel_off_delay);
367 msleep(intel_dsi->panel_pwr_cycle_delay);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530368}
Jani Nikula4e646492013-08-27 15:12:20 +0300369
370static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
371 enum pipe *pipe)
372{
373 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Imre Deak6d129be2014-03-05 16:20:54 +0200374 enum intel_display_power_domain power_domain;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200375 u32 port_ctl, func;
376 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300377
378 DRM_DEBUG_KMS("\n");
379
Imre Deak6d129be2014-03-05 16:20:54 +0200380 power_domain = intel_display_port_power_domain(encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200381 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200382 return false;
383
Jani Nikula4e646492013-08-27 15:12:20 +0300384 /* XXX: this only works for one DSI output */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200385 for_each_dsi_port(port, (1 << PORT_A) | (1 << PORT_C)) {
386 port_ctl = I915_READ(MIPI_PORT_CTRL(port));
387 func = I915_READ(MIPI_DSI_FUNC_PRG(port));
Jani Nikula4e646492013-08-27 15:12:20 +0300388
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200389 if ((port_ctl & DPI_ENABLE) || (func & CMD_MODE_DATA_WIDTH_MASK)) {
390 if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
391 *pipe = port == PORT_A ? PIPE_A : PIPE_C;
Jani Nikula4e646492013-08-27 15:12:20 +0300392 return true;
393 }
394 }
395 }
396
397 return false;
398}
399
400static void intel_dsi_get_config(struct intel_encoder *encoder,
401 struct intel_crtc_config *pipe_config)
402{
Shobhit Kumarf573de52014-07-30 20:32:37 +0530403 u32 pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300404 DRM_DEBUG_KMS("\n");
405
Shobhit Kumarf573de52014-07-30 20:32:37 +0530406 /*
407 * DPLL_MD is not used in case of DSI, reading will get some default value
408 * set dpll_md = 0
409 */
410 pipe_config->dpll_hw_state.dpll_md = 0;
411
412 pclk = vlv_get_dsi_pclk(encoder, pipe_config->pipe_bpp);
413 if (!pclk)
414 return;
415
416 pipe_config->adjusted_mode.crtc_clock = pclk;
417 pipe_config->port_clock = pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300418}
419
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000420static enum drm_mode_status
421intel_dsi_mode_valid(struct drm_connector *connector,
422 struct drm_display_mode *mode)
Jani Nikula4e646492013-08-27 15:12:20 +0300423{
424 struct intel_connector *intel_connector = to_intel_connector(connector);
425 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
426 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
427
428 DRM_DEBUG_KMS("\n");
429
430 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
431 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
432 return MODE_NO_DBLESCAN;
433 }
434
435 if (fixed_mode) {
436 if (mode->hdisplay > fixed_mode->hdisplay)
437 return MODE_PANEL;
438 if (mode->vdisplay > fixed_mode->vdisplay)
439 return MODE_PANEL;
440 }
441
442 return intel_dsi->dev.dev_ops->mode_valid(&intel_dsi->dev, mode);
443}
444
445/* return txclkesc cycles in terms of divider and duration in us */
446static u16 txclkesc(u32 divider, unsigned int us)
447{
448 switch (divider) {
449 case ESCAPE_CLOCK_DIVIDER_1:
450 default:
451 return 20 * us;
452 case ESCAPE_CLOCK_DIVIDER_2:
453 return 10 * us;
454 case ESCAPE_CLOCK_DIVIDER_4:
455 return 5 * us;
456 }
457}
458
459/* return pixels in terms of txbyteclkhs */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530460static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
461 u16 burst_mode_ratio)
Jani Nikula4e646492013-08-27 15:12:20 +0300462{
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530463 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200464 8 * 100), lane_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300465}
466
467static void set_dsi_timings(struct drm_encoder *encoder,
468 const struct drm_display_mode *mode)
469{
470 struct drm_device *dev = encoder->dev;
471 struct drm_i915_private *dev_priv = dev->dev_private;
472 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
473 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200474 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Jani Nikula4e646492013-08-27 15:12:20 +0300475 unsigned int bpp = intel_crtc->config.pipe_bpp;
476 unsigned int lane_count = intel_dsi->lane_count;
477
478 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
479
480 hactive = mode->hdisplay;
481 hfp = mode->hsync_start - mode->hdisplay;
482 hsync = mode->hsync_end - mode->hsync_start;
483 hbp = mode->htotal - mode->hsync_end;
484
485 vfp = mode->vsync_start - mode->vdisplay;
486 vsync = mode->vsync_end - mode->vsync_start;
487 vbp = mode->vtotal - mode->vsync_end;
488
489 /* horizontal values are in terms of high speed byte clock */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530490 hactive = txbyteclkhs(hactive, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200491 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530492 hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
493 hsync = txbyteclkhs(hsync, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200494 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530495 hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
Jani Nikula4e646492013-08-27 15:12:20 +0300496
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200497 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
498 I915_WRITE(MIPI_HFP_COUNT(port), hfp);
Jani Nikula4e646492013-08-27 15:12:20 +0300499
500 /* meaningful for video mode non-burst sync pulse mode only, can be zero
501 * for non-burst sync events and burst modes */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200502 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
503 I915_WRITE(MIPI_HBP_COUNT(port), hbp);
Jani Nikula4e646492013-08-27 15:12:20 +0300504
505 /* vertical values are in terms of lines */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200506 I915_WRITE(MIPI_VFP_COUNT(port), vfp);
507 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
508 I915_WRITE(MIPI_VBP_COUNT(port), vbp);
Jani Nikula4e646492013-08-27 15:12:20 +0300509}
510
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200511static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300512{
513 struct drm_encoder *encoder = &intel_encoder->base;
514 struct drm_device *dev = encoder->dev;
515 struct drm_i915_private *dev_priv = dev->dev_private;
516 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
517 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
518 struct drm_display_mode *adjusted_mode =
519 &intel_crtc->config.adjusted_mode;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200520 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Jani Nikula4e646492013-08-27 15:12:20 +0300521 unsigned int bpp = intel_crtc->config.pipe_bpp;
522 u32 val, tmp;
523
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200524 DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
Jani Nikula4e646492013-08-27 15:12:20 +0300525
Jani Nikula4e646492013-08-27 15:12:20 +0300526 /* escape clock divider, 20MHz, shared for A and C. device ready must be
527 * off when doing this! txclkesc? */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200528 tmp = I915_READ(MIPI_CTRL(PORT_A));
Jani Nikula4e646492013-08-27 15:12:20 +0300529 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200530 I915_WRITE(MIPI_CTRL(PORT_A), tmp | ESCAPE_CLOCK_DIVIDER_1);
Jani Nikula4e646492013-08-27 15:12:20 +0300531
532 /* read request priority is per pipe */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200533 tmp = I915_READ(MIPI_CTRL(port));
Jani Nikula4e646492013-08-27 15:12:20 +0300534 tmp &= ~READ_REQUEST_PRIORITY_MASK;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200535 I915_WRITE(MIPI_CTRL(port), tmp | READ_REQUEST_PRIORITY_HIGH);
Jani Nikula4e646492013-08-27 15:12:20 +0300536
537 /* XXX: why here, why like this? handling in irq handler?! */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200538 I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
539 I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
Jani Nikula4e646492013-08-27 15:12:20 +0300540
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200541 I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
Jani Nikula4e646492013-08-27 15:12:20 +0300542
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200543 I915_WRITE(MIPI_DPI_RESOLUTION(port),
Jani Nikula4e646492013-08-27 15:12:20 +0300544 adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
545 adjusted_mode->hdisplay << HORIZONTAL_ADDRESS_SHIFT);
546
547 set_dsi_timings(encoder, adjusted_mode);
548
549 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
550 if (is_cmd_mode(intel_dsi)) {
551 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
552 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
553 } else {
554 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
555
556 /* XXX: cross-check bpp vs. pixel format? */
557 val |= intel_dsi->pixel_format;
558 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200559 I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300560
561 /* timeouts for recovery. one frame IIUC. if counter expires, EOT and
562 * stop state. */
563
564 /*
565 * In burst mode, value greater than one DPI line Time in byte clock
566 * (txbyteclkhs) To timeout this timer 1+ of the above said value is
567 * recommended.
568 *
569 * In non-burst mode, Value greater than one DPI frame time in byte
570 * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
571 * is recommended.
572 *
573 * In DBI only mode, value greater than one DBI frame time in byte
574 * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
575 * is recommended.
576 */
577
578 if (is_vid_mode(intel_dsi) &&
579 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200580 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
Jani Nikula4e646492013-08-27 15:12:20 +0300581 txbyteclkhs(adjusted_mode->htotal, bpp,
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530582 intel_dsi->lane_count,
583 intel_dsi->burst_mode_ratio) + 1);
Jani Nikula4e646492013-08-27 15:12:20 +0300584 } else {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200585 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
Jani Nikula4e646492013-08-27 15:12:20 +0300586 txbyteclkhs(adjusted_mode->vtotal *
587 adjusted_mode->htotal,
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530588 bpp, intel_dsi->lane_count,
589 intel_dsi->burst_mode_ratio) + 1);
Jani Nikula4e646492013-08-27 15:12:20 +0300590 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200591 I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
592 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port), intel_dsi->turn_arnd_val);
593 I915_WRITE(MIPI_DEVICE_RESET_TIMER(port), intel_dsi->rst_timer_val);
Jani Nikula4e646492013-08-27 15:12:20 +0300594
595 /* dphy stuff */
596
597 /* in terms of low power clock */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200598 I915_WRITE(MIPI_INIT_COUNT(port), txclkesc(intel_dsi->escape_clk_div, 100));
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530599
600 val = 0;
601 if (intel_dsi->eotp_pkt == 0)
602 val |= EOT_DISABLE;
603
604 if (intel_dsi->clock_stop)
605 val |= CLOCKSTOP;
Jani Nikula4e646492013-08-27 15:12:20 +0300606
607 /* recovery disables */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200608 I915_WRITE(MIPI_EOT_DISABLE(port), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300609
Shobhit Kumarcf4dbd22014-04-14 11:18:25 +0530610 /* in terms of low power clock */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200611 I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
Shobhit Kumarcf4dbd22014-04-14 11:18:25 +0530612
Jani Nikula4e646492013-08-27 15:12:20 +0300613 /* in terms of txbyteclkhs. actual high to low switch +
614 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
615 *
616 * XXX: write MIPI_STOP_STATE_STALL?
617 */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200618 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
Daniel Vetter7f3de832014-07-30 22:34:27 +0200619 intel_dsi->hs_to_lp_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300620
621 /* XXX: low power clock equivalence in terms of byte clock. the number
622 * of byte clocks occupied in one low power clock. based on txbyteclkhs
623 * and txclkesc. txclkesc time / txbyteclk time * (105 +
624 * MIPI_STOP_STATE_STALL) / 105.???
625 */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200626 I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
Jani Nikula4e646492013-08-27 15:12:20 +0300627
628 /* the bw essential for transmitting 16 long packets containing 252
629 * bytes meant for dcs write memory command is programmed in this
630 * register in terms of byte clocks. based on dsi transfer rate and the
631 * number of lanes configured the time taken to transmit 16 long packets
632 * in a dsi stream varies. */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200633 I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
Jani Nikula4e646492013-08-27 15:12:20 +0300634
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200635 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
Shobhit Kumarf6da2842013-12-10 12:15:00 +0530636 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
637 intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
Jani Nikula4e646492013-08-27 15:12:20 +0300638
639 if (is_vid_mode(intel_dsi))
Shobhit Kumar24d9c402014-04-09 13:59:36 +0530640 /* Some panels might have resolution which is not a multiple of
641 * 64 like 1366 x 768. Enable RANDOM resolution support for such
642 * panels by default */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200643 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
Daniel Vetter7f3de832014-07-30 22:34:27 +0200644 intel_dsi->video_frmt_cfg_bits |
645 intel_dsi->video_mode_format |
646 IP_TG_CONFIG |
647 RANDOM_DPI_DISPLAY_RESOLUTION);
Jani Nikula4e646492013-08-27 15:12:20 +0300648}
649
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200650static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
651{
652 DRM_DEBUG_KMS("\n");
653
654 intel_dsi_prepare(encoder);
655
656 vlv_enable_dsi_pll(encoder);
657}
658
Jani Nikula4e646492013-08-27 15:12:20 +0300659static enum drm_connector_status
660intel_dsi_detect(struct drm_connector *connector, bool force)
661{
662 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
Imre Deak671dedd2014-03-05 16:20:53 +0200663 struct intel_encoder *intel_encoder = &intel_dsi->base;
664 enum intel_display_power_domain power_domain;
665 enum drm_connector_status connector_status;
666 struct drm_i915_private *dev_priv = intel_encoder->base.dev->dev_private;
667
Jani Nikula4e646492013-08-27 15:12:20 +0300668 DRM_DEBUG_KMS("\n");
Imre Deak671dedd2014-03-05 16:20:53 +0200669 power_domain = intel_display_port_power_domain(intel_encoder);
670
671 intel_display_power_get(dev_priv, power_domain);
672 connector_status = intel_dsi->dev.dev_ops->detect(&intel_dsi->dev);
673 intel_display_power_put(dev_priv, power_domain);
674
675 return connector_status;
Jani Nikula4e646492013-08-27 15:12:20 +0300676}
677
678static int intel_dsi_get_modes(struct drm_connector *connector)
679{
680 struct intel_connector *intel_connector = to_intel_connector(connector);
681 struct drm_display_mode *mode;
682
683 DRM_DEBUG_KMS("\n");
684
685 if (!intel_connector->panel.fixed_mode) {
686 DRM_DEBUG_KMS("no fixed mode\n");
687 return 0;
688 }
689
690 mode = drm_mode_duplicate(connector->dev,
691 intel_connector->panel.fixed_mode);
692 if (!mode) {
693 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
694 return 0;
695 }
696
697 drm_mode_probed_add(connector, mode);
698 return 1;
699}
700
701static void intel_dsi_destroy(struct drm_connector *connector)
702{
703 struct intel_connector *intel_connector = to_intel_connector(connector);
704
705 DRM_DEBUG_KMS("\n");
706 intel_panel_fini(&intel_connector->panel);
Jani Nikula4e646492013-08-27 15:12:20 +0300707 drm_connector_cleanup(connector);
708 kfree(connector);
709}
710
711static const struct drm_encoder_funcs intel_dsi_funcs = {
712 .destroy = intel_encoder_destroy,
713};
714
715static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
716 .get_modes = intel_dsi_get_modes,
717 .mode_valid = intel_dsi_mode_valid,
718 .best_encoder = intel_best_encoder,
719};
720
721static const struct drm_connector_funcs intel_dsi_connector_funcs = {
722 .dpms = intel_connector_dpms,
723 .detect = intel_dsi_detect,
724 .destroy = intel_dsi_destroy,
725 .fill_modes = drm_helper_probe_single_connector_modes,
726};
727
Damien Lespiau4328633d2014-05-28 12:30:56 +0100728void intel_dsi_init(struct drm_device *dev)
Jani Nikula4e646492013-08-27 15:12:20 +0300729{
730 struct intel_dsi *intel_dsi;
731 struct intel_encoder *intel_encoder;
732 struct drm_encoder *encoder;
733 struct intel_connector *intel_connector;
734 struct drm_connector *connector;
735 struct drm_display_mode *fixed_mode = NULL;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530736 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300737 const struct intel_dsi_device *dsi;
738 unsigned int i;
739
740 DRM_DEBUG_KMS("\n");
741
Shobhit Kumar3e6bd012014-05-27 19:33:59 +0530742 /* There is no detection method for MIPI so rely on VBT */
743 if (!dev_priv->vbt.has_mipi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100744 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300745
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530746 if (IS_VALLEYVIEW(dev)) {
747 dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
748 } else {
749 DRM_ERROR("Unsupported Mipi device to reg base");
Christoph Jaeger868d6652014-06-13 21:51:22 +0200750 return;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530751 }
752
Jani Nikula4e646492013-08-27 15:12:20 +0300753 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
754 if (!intel_dsi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100755 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300756
757 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
758 if (!intel_connector) {
759 kfree(intel_dsi);
Damien Lespiau4328633d2014-05-28 12:30:56 +0100760 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300761 }
762
763 intel_encoder = &intel_dsi->base;
764 encoder = &intel_encoder->base;
765 intel_dsi->attached_connector = intel_connector;
766
Jani Nikula4e646492013-08-27 15:12:20 +0300767 connector = &intel_connector->base;
768
769 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
770
771 /* XXX: very likely not all of these are needed */
772 intel_encoder->hot_plug = intel_dsi_hot_plug;
773 intel_encoder->compute_config = intel_dsi_compute_config;
774 intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
775 intel_encoder->pre_enable = intel_dsi_pre_enable;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530776 intel_encoder->enable = intel_dsi_enable_nop;
Imre Deakc315faf2014-05-27 19:00:09 +0300777 intel_encoder->disable = intel_dsi_pre_disable;
Jani Nikula4e646492013-08-27 15:12:20 +0300778 intel_encoder->post_disable = intel_dsi_post_disable;
779 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
780 intel_encoder->get_config = intel_dsi_get_config;
781
782 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak4932e2c2014-02-11 17:12:48 +0200783 intel_connector->unregister = intel_connector_unregister;
Jani Nikula4e646492013-08-27 15:12:20 +0300784
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200785 /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
Jani Nikula17af40a2014-11-14 16:54:22 +0200786 if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200787 intel_encoder->crtc_mask = (1 << PIPE_A);
Jani Nikula17af40a2014-11-14 16:54:22 +0200788 intel_dsi->ports = (1 << PORT_A);
789 } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200790 intel_encoder->crtc_mask = (1 << PIPE_B);
Jani Nikula17af40a2014-11-14 16:54:22 +0200791 intel_dsi->ports = (1 << PORT_C);
792 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200793
Jani Nikula4e646492013-08-27 15:12:20 +0300794 for (i = 0; i < ARRAY_SIZE(intel_dsi_devices); i++) {
795 dsi = &intel_dsi_devices[i];
796 intel_dsi->dev = *dsi;
797
798 if (dsi->dev_ops->init(&intel_dsi->dev))
799 break;
800 }
801
802 if (i == ARRAY_SIZE(intel_dsi_devices)) {
803 DRM_DEBUG_KMS("no device found\n");
804 goto err;
805 }
806
807 intel_encoder->type = INTEL_OUTPUT_DSI;
Ville Syrjäläbc079e82014-03-03 16:15:28 +0200808 intel_encoder->cloneable = 0;
Jani Nikula4e646492013-08-27 15:12:20 +0300809 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
810 DRM_MODE_CONNECTOR_DSI);
811
812 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
813
814 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
815 connector->interlace_allowed = false;
816 connector->doublescan_allowed = false;
817
818 intel_connector_attach_encoder(intel_connector, intel_encoder);
819
Thomas Wood34ea3d32014-05-29 16:57:41 +0100820 drm_connector_register(connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300821
822 fixed_mode = dsi->dev_ops->get_modes(&intel_dsi->dev);
823 if (!fixed_mode) {
824 DRM_DEBUG_KMS("no fixed mode\n");
825 goto err;
826 }
827
828 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Vandana Kannan4b6ed682014-02-11 14:26:36 +0530829 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
Jani Nikula4e646492013-08-27 15:12:20 +0300830
Damien Lespiau4328633d2014-05-28 12:30:56 +0100831 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300832
833err:
834 drm_encoder_cleanup(&intel_encoder->base);
835 kfree(intel_dsi);
836 kfree(intel_connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300837}