blob: 8f8b952eaa9259f22a9aba4a01d325f1b6f153fe [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 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));
180 I915_WRITE(MIPI_PORT_CTRL(port), val | LP_OUTPUT_HOLD);
181 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530182
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530183 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
184 usleep_range(2500, 3000);
185
186 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
187 usleep_range(2500, 3000);
188 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530189}
Jani Nikula4e646492013-08-27 15:12:20 +0300190
191static void intel_dsi_enable(struct intel_encoder *encoder)
192{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530193 struct drm_device *dev = encoder->base.dev;
194 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300195 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
196 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200197 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Jani Nikula4e646492013-08-27 15:12:20 +0300198
199 DRM_DEBUG_KMS("\n");
200
Jani Nikula4e646492013-08-27 15:12:20 +0300201 if (is_cmd_mode(intel_dsi))
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200202 I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530203 else {
Jani Nikula4e646492013-08-27 15:12:20 +0300204 msleep(20); /* XXX */
Shobhit Kumare1047022014-04-09 13:59:35 +0530205 dpi_send_cmd(intel_dsi, TURN_ON, DPI_LP_MODE_EN);
Jani Nikula4e646492013-08-27 15:12:20 +0300206 msleep(100);
207
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530208 if (intel_dsi->dev.dev_ops->enable)
209 intel_dsi->dev.dev_ops->enable(&intel_dsi->dev);
210
Shobhit Kumar13813082014-07-12 17:17:22 +0530211 wait_for_dsi_fifo_empty(intel_dsi);
212
Gaurav K Singh5505a242014-12-04 10:58:47 +0530213 intel_dsi_port_enable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300214 }
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530215}
Jani Nikula4e646492013-08-27 15:12:20 +0300216
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530217static void intel_dsi_pre_enable(struct intel_encoder *encoder)
218{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530219 struct drm_device *dev = encoder->base.dev;
220 struct drm_i915_private *dev_priv = dev->dev_private;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530221 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530222 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
223 enum pipe pipe = intel_crtc->pipe;
224 u32 tmp;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530225
226 DRM_DEBUG_KMS("\n");
227
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530228 /* Disable DPOunit clock gating, can stall pipe
229 * and we need DPLL REFA always enabled */
230 tmp = I915_READ(DPLL(pipe));
231 tmp |= DPLL_REFA_CLK_ENABLE_VLV;
232 I915_WRITE(DPLL(pipe), tmp);
233
Shobhit Kumarf573de52014-07-30 20:32:37 +0530234 /* update the hw state for DPLL */
235 intel_crtc->config.dpll_hw_state.dpll = DPLL_INTEGRATED_CLOCK_VLV |
Daniel Vetter7f3de832014-07-30 22:34:27 +0200236 DPLL_REFA_CLK_ENABLE_VLV;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530237
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530238 tmp = I915_READ(DSPCLK_GATE_D);
239 tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
240 I915_WRITE(DSPCLK_GATE_D, tmp);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530241
242 /* put device in ready state */
243 intel_dsi_device_ready(encoder);
244
Shobhit Kumardf38e652014-04-14 11:18:26 +0530245 msleep(intel_dsi->panel_on_delay);
246
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530247 if (intel_dsi->dev.dev_ops->panel_reset)
248 intel_dsi->dev.dev_ops->panel_reset(&intel_dsi->dev);
249
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530250 if (intel_dsi->dev.dev_ops->send_otp_cmds)
251 intel_dsi->dev.dev_ops->send_otp_cmds(&intel_dsi->dev);
252
Shobhit Kumar13813082014-07-12 17:17:22 +0530253 wait_for_dsi_fifo_empty(intel_dsi);
254
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530255 /* Enable port in pre-enable phase itself because as per hw team
256 * recommendation, port should be enabled befor plane & pipe */
257 intel_dsi_enable(encoder);
258}
259
260static void intel_dsi_enable_nop(struct intel_encoder *encoder)
261{
262 DRM_DEBUG_KMS("\n");
263
264 /* for DSI port enable has to be done before pipe
265 * and plane enable, so port enable is done in
266 * pre_enable phase itself unlike other encoders
267 */
Jani Nikula4e646492013-08-27 15:12:20 +0300268}
269
Imre Deakc315faf2014-05-27 19:00:09 +0300270static void intel_dsi_pre_disable(struct intel_encoder *encoder)
271{
272 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
273
274 DRM_DEBUG_KMS("\n");
275
276 if (is_vid_mode(intel_dsi)) {
277 /* Send Shutdown command to the panel in LP mode */
278 dpi_send_cmd(intel_dsi, SHUTDOWN, DPI_LP_MODE_EN);
279 msleep(10);
280 }
281}
282
Jani Nikula4e646492013-08-27 15:12:20 +0300283static void intel_dsi_disable(struct intel_encoder *encoder)
284{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530285 struct drm_device *dev = encoder->base.dev;
286 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300287 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530288 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300289 u32 temp;
290
291 DRM_DEBUG_KMS("\n");
292
Jani Nikula4e646492013-08-27 15:12:20 +0300293 if (is_vid_mode(intel_dsi)) {
Shobhit Kumar13813082014-07-12 17:17:22 +0530294 wait_for_dsi_fifo_empty(intel_dsi);
295
Gaurav K Singh5505a242014-12-04 10:58:47 +0530296 intel_dsi_port_disable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300297 msleep(2);
298 }
299
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530300 for_each_dsi_port(port, intel_dsi->ports) {
301 /* Panel commands can be sent when clock is in LP11 */
302 I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530303
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530304 temp = I915_READ(MIPI_CTRL(port));
305 temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
306 I915_WRITE(MIPI_CTRL(port), temp |
307 intel_dsi->escape_clk_div <<
308 ESCAPE_CLOCK_DIVIDER_SHIFT);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530309
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530310 I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530311
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530312 temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
313 temp &= ~VID_MODE_FORMAT_MASK;
314 I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530315
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530316 I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
317 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530318 /* if disable packets are sent before sending shutdown packet then in
319 * some next enable sequence send turn on packet error is observed */
320 if (intel_dsi->dev.dev_ops->disable)
321 intel_dsi->dev.dev_ops->disable(&intel_dsi->dev);
Shobhit Kumar13813082014-07-12 17:17:22 +0530322
323 wait_for_dsi_fifo_empty(intel_dsi);
Jani Nikula4e646492013-08-27 15:12:20 +0300324}
325
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530326static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300327{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530328 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530329 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
330 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530331 u32 val;
332
Jani Nikula4e646492013-08-27 15:12:20 +0300333 DRM_DEBUG_KMS("\n");
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530334 for_each_dsi_port(port, intel_dsi->ports) {
ymohanmabe4fc042013-08-27 23:40:56 +0300335
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530336 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
337 ULPS_STATE_ENTER);
338 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530339
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530340 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
341 ULPS_STATE_EXIT);
342 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530343
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 /* Wait till Clock lanes are in LP-00 state for MIPI Port A
349 * only. MIPI Port C has no similar bit for checking
350 */
351 if (wait_for(((I915_READ(MIPI_PORT_CTRL(PORT_A)) & AFE_LATCHOUT)
352 == 0x00000), 30))
353 DRM_ERROR("DSI LP not going Low\n");
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530354
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530355 val = I915_READ(MIPI_PORT_CTRL(port));
356 /* Disable MIPI PHY transparent latch
357 * Common bit for both MIPI Port A & MIPI Port C
358 */
359 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val & ~LP_OUTPUT_HOLD);
360 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530361
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530362 I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
363 usleep_range(2000, 2500);
364 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530365
ymohanmabe4fc042013-08-27 23:40:56 +0300366 vlv_disable_dsi_pll(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300367}
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530368
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530369static void intel_dsi_post_disable(struct intel_encoder *encoder)
370{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530371 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530372 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530373 u32 val;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530374
375 DRM_DEBUG_KMS("\n");
376
Imre Deakc315faf2014-05-27 19:00:09 +0300377 intel_dsi_disable(encoder);
378
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530379 intel_dsi_clear_device_ready(encoder);
380
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530381 val = I915_READ(DSPCLK_GATE_D);
382 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
383 I915_WRITE(DSPCLK_GATE_D, val);
384
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530385 if (intel_dsi->dev.dev_ops->disable_panel_power)
386 intel_dsi->dev.dev_ops->disable_panel_power(&intel_dsi->dev);
Shobhit Kumardf38e652014-04-14 11:18:26 +0530387
388 msleep(intel_dsi->panel_off_delay);
389 msleep(intel_dsi->panel_pwr_cycle_delay);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530390}
Jani Nikula4e646492013-08-27 15:12:20 +0300391
392static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
393 enum pipe *pipe)
394{
395 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Imre Deak6d129be2014-03-05 16:20:54 +0200396 enum intel_display_power_domain power_domain;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200397 u32 port_ctl, func;
398 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300399
400 DRM_DEBUG_KMS("\n");
401
Imre Deak6d129be2014-03-05 16:20:54 +0200402 power_domain = intel_display_port_power_domain(encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200403 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200404 return false;
405
Jani Nikula4e646492013-08-27 15:12:20 +0300406 /* XXX: this only works for one DSI output */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200407 for_each_dsi_port(port, (1 << PORT_A) | (1 << PORT_C)) {
408 port_ctl = I915_READ(MIPI_PORT_CTRL(port));
409 func = I915_READ(MIPI_DSI_FUNC_PRG(port));
Jani Nikula4e646492013-08-27 15:12:20 +0300410
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200411 if ((port_ctl & DPI_ENABLE) || (func & CMD_MODE_DATA_WIDTH_MASK)) {
412 if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
413 *pipe = port == PORT_A ? PIPE_A : PIPE_C;
Jani Nikula4e646492013-08-27 15:12:20 +0300414 return true;
415 }
416 }
417 }
418
419 return false;
420}
421
422static void intel_dsi_get_config(struct intel_encoder *encoder,
423 struct intel_crtc_config *pipe_config)
424{
Shobhit Kumarf573de52014-07-30 20:32:37 +0530425 u32 pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300426 DRM_DEBUG_KMS("\n");
427
Shobhit Kumarf573de52014-07-30 20:32:37 +0530428 /*
429 * DPLL_MD is not used in case of DSI, reading will get some default value
430 * set dpll_md = 0
431 */
432 pipe_config->dpll_hw_state.dpll_md = 0;
433
434 pclk = vlv_get_dsi_pclk(encoder, pipe_config->pipe_bpp);
435 if (!pclk)
436 return;
437
438 pipe_config->adjusted_mode.crtc_clock = pclk;
439 pipe_config->port_clock = pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300440}
441
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000442static enum drm_mode_status
443intel_dsi_mode_valid(struct drm_connector *connector,
444 struct drm_display_mode *mode)
Jani Nikula4e646492013-08-27 15:12:20 +0300445{
446 struct intel_connector *intel_connector = to_intel_connector(connector);
447 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
448 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
449
450 DRM_DEBUG_KMS("\n");
451
452 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
453 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
454 return MODE_NO_DBLESCAN;
455 }
456
457 if (fixed_mode) {
458 if (mode->hdisplay > fixed_mode->hdisplay)
459 return MODE_PANEL;
460 if (mode->vdisplay > fixed_mode->vdisplay)
461 return MODE_PANEL;
462 }
463
464 return intel_dsi->dev.dev_ops->mode_valid(&intel_dsi->dev, mode);
465}
466
467/* return txclkesc cycles in terms of divider and duration in us */
468static u16 txclkesc(u32 divider, unsigned int us)
469{
470 switch (divider) {
471 case ESCAPE_CLOCK_DIVIDER_1:
472 default:
473 return 20 * us;
474 case ESCAPE_CLOCK_DIVIDER_2:
475 return 10 * us;
476 case ESCAPE_CLOCK_DIVIDER_4:
477 return 5 * us;
478 }
479}
480
481/* return pixels in terms of txbyteclkhs */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530482static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
483 u16 burst_mode_ratio)
Jani Nikula4e646492013-08-27 15:12:20 +0300484{
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530485 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200486 8 * 100), lane_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300487}
488
489static void set_dsi_timings(struct drm_encoder *encoder,
490 const struct drm_display_mode *mode)
491{
492 struct drm_device *dev = encoder->dev;
493 struct drm_i915_private *dev_priv = dev->dev_private;
494 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
495 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530496 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300497 unsigned int bpp = intel_crtc->config.pipe_bpp;
498 unsigned int lane_count = intel_dsi->lane_count;
499
500 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
501
502 hactive = mode->hdisplay;
503 hfp = mode->hsync_start - mode->hdisplay;
504 hsync = mode->hsync_end - mode->hsync_start;
505 hbp = mode->htotal - mode->hsync_end;
506
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530507 if (intel_dsi->dual_link) {
508 hactive /= 2;
509 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
510 hactive += intel_dsi->pixel_overlap;
511 hfp /= 2;
512 hsync /= 2;
513 hbp /= 2;
514 }
515
Jani Nikula4e646492013-08-27 15:12:20 +0300516 vfp = mode->vsync_start - mode->vdisplay;
517 vsync = mode->vsync_end - mode->vsync_start;
518 vbp = mode->vtotal - mode->vsync_end;
519
520 /* horizontal values are in terms of high speed byte clock */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530521 hactive = txbyteclkhs(hactive, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200522 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530523 hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
524 hsync = txbyteclkhs(hsync, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200525 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530526 hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
Jani Nikula4e646492013-08-27 15:12:20 +0300527
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530528 for_each_dsi_port(port, intel_dsi->ports) {
529 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
530 I915_WRITE(MIPI_HFP_COUNT(port), hfp);
Jani Nikula4e646492013-08-27 15:12:20 +0300531
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530532 /* meaningful for video mode non-burst sync pulse mode only,
533 * can be zero for non-burst sync events and burst modes */
534 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
535 I915_WRITE(MIPI_HBP_COUNT(port), hbp);
Jani Nikula4e646492013-08-27 15:12:20 +0300536
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530537 /* vertical values are in terms of lines */
538 I915_WRITE(MIPI_VFP_COUNT(port), vfp);
539 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
540 I915_WRITE(MIPI_VBP_COUNT(port), vbp);
541 }
Jani Nikula4e646492013-08-27 15:12:20 +0300542}
543
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200544static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300545{
546 struct drm_encoder *encoder = &intel_encoder->base;
547 struct drm_device *dev = encoder->dev;
548 struct drm_i915_private *dev_priv = dev->dev_private;
549 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
550 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
551 struct drm_display_mode *adjusted_mode =
552 &intel_crtc->config.adjusted_mode;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530553 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300554 unsigned int bpp = intel_crtc->config.pipe_bpp;
555 u32 val, tmp;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530556 u16 mode_hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300557
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200558 DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
Jani Nikula4e646492013-08-27 15:12:20 +0300559
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530560 mode_hdisplay = adjusted_mode->hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300561
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530562 if (intel_dsi->dual_link) {
563 mode_hdisplay /= 2;
564 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
565 mode_hdisplay += intel_dsi->pixel_overlap;
566 }
Jani Nikula4e646492013-08-27 15:12:20 +0300567
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530568 for_each_dsi_port(port, intel_dsi->ports) {
569 /* escape clock divider, 20MHz, shared for A and C.
570 * device ready must be off when doing this! txclkesc? */
571 tmp = I915_READ(MIPI_CTRL(PORT_A));
572 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
573 I915_WRITE(MIPI_CTRL(PORT_A), tmp | ESCAPE_CLOCK_DIVIDER_1);
Jani Nikula4e646492013-08-27 15:12:20 +0300574
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530575 /* read request priority is per pipe */
576 tmp = I915_READ(MIPI_CTRL(port));
577 tmp &= ~READ_REQUEST_PRIORITY_MASK;
578 I915_WRITE(MIPI_CTRL(port), tmp | READ_REQUEST_PRIORITY_HIGH);
Jani Nikula4e646492013-08-27 15:12:20 +0300579
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530580 /* XXX: why here, why like this? handling in irq handler?! */
581 I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
582 I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
583
584 I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
585
586 I915_WRITE(MIPI_DPI_RESOLUTION(port),
587 adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
588 mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
589 }
Jani Nikula4e646492013-08-27 15:12:20 +0300590
591 set_dsi_timings(encoder, adjusted_mode);
592
593 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
594 if (is_cmd_mode(intel_dsi)) {
595 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
596 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
597 } else {
598 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
599
600 /* XXX: cross-check bpp vs. pixel format? */
601 val |= intel_dsi->pixel_format;
602 }
Jani Nikula4e646492013-08-27 15:12:20 +0300603
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530604 tmp = 0;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530605 if (intel_dsi->eotp_pkt == 0)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530606 tmp |= EOT_DISABLE;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530607 if (intel_dsi->clock_stop)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530608 tmp |= CLOCKSTOP;
Jani Nikula4e646492013-08-27 15:12:20 +0300609
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530610 for_each_dsi_port(port, intel_dsi->ports) {
611 I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300612
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530613 /* timeouts for recovery. one frame IIUC. if counter expires,
614 * EOT and stop state. */
Shobhit Kumarcf4dbd22014-04-14 11:18:25 +0530615
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530616 /*
617 * In burst mode, value greater than one DPI line Time in byte
618 * clock (txbyteclkhs) To timeout this timer 1+ of the above
619 * said value is recommended.
620 *
621 * In non-burst mode, Value greater than one DPI frame time in
622 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
623 * said value is recommended.
624 *
625 * In DBI only mode, value greater than one DBI frame time in
626 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
627 * said value is recommended.
628 */
Jani Nikula4e646492013-08-27 15:12:20 +0300629
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530630 if (is_vid_mode(intel_dsi) &&
631 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
632 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
633 txbyteclkhs(adjusted_mode->htotal, bpp,
634 intel_dsi->lane_count,
635 intel_dsi->burst_mode_ratio) + 1);
636 } else {
637 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
638 txbyteclkhs(adjusted_mode->vtotal *
639 adjusted_mode->htotal,
640 bpp, intel_dsi->lane_count,
641 intel_dsi->burst_mode_ratio) + 1);
642 }
643 I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
644 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
645 intel_dsi->turn_arnd_val);
646 I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
647 intel_dsi->rst_timer_val);
Jani Nikula4e646492013-08-27 15:12:20 +0300648
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530649 /* dphy stuff */
Jani Nikula4e646492013-08-27 15:12:20 +0300650
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530651 /* in terms of low power clock */
652 I915_WRITE(MIPI_INIT_COUNT(port),
653 txclkesc(intel_dsi->escape_clk_div, 100));
Jani Nikula4e646492013-08-27 15:12:20 +0300654
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530655
656 /* recovery disables */
657 I915_WRITE(MIPI_EOT_DISABLE(port), val);
658
659 /* in terms of low power clock */
660 I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
661
662 /* in terms of txbyteclkhs. actual high to low switch +
663 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
664 *
665 * XXX: write MIPI_STOP_STATE_STALL?
666 */
667 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
668 intel_dsi->hs_to_lp_count);
669
670 /* XXX: low power clock equivalence in terms of byte clock.
671 * the number of byte clocks occupied in one low power clock.
672 * based on txbyteclkhs and txclkesc.
673 * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
674 * ) / 105.???
675 */
676 I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
677
678 /* the bw essential for transmitting 16 long packets containing
679 * 252 bytes meant for dcs write memory command is programmed in
680 * this register in terms of byte clocks. based on dsi transfer
681 * rate and the number of lanes configured the time taken to
682 * transmit 16 long packets in a dsi stream varies. */
683 I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
684
685 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
686 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
687 intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
688
689 if (is_vid_mode(intel_dsi))
690 /* Some panels might have resolution which is not a
691 * multiple of 64 like 1366 x 768. Enable RANDOM
692 * resolution support for such panels by default */
693 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
694 intel_dsi->video_frmt_cfg_bits |
695 intel_dsi->video_mode_format |
696 IP_TG_CONFIG |
697 RANDOM_DPI_DISPLAY_RESOLUTION);
698 }
Jani Nikula4e646492013-08-27 15:12:20 +0300699}
700
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200701static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
702{
703 DRM_DEBUG_KMS("\n");
704
705 intel_dsi_prepare(encoder);
706
707 vlv_enable_dsi_pll(encoder);
708}
709
Jani Nikula4e646492013-08-27 15:12:20 +0300710static enum drm_connector_status
711intel_dsi_detect(struct drm_connector *connector, bool force)
712{
713 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
Imre Deak671dedd2014-03-05 16:20:53 +0200714 struct intel_encoder *intel_encoder = &intel_dsi->base;
715 enum intel_display_power_domain power_domain;
716 enum drm_connector_status connector_status;
717 struct drm_i915_private *dev_priv = intel_encoder->base.dev->dev_private;
718
Jani Nikula4e646492013-08-27 15:12:20 +0300719 DRM_DEBUG_KMS("\n");
Imre Deak671dedd2014-03-05 16:20:53 +0200720 power_domain = intel_display_port_power_domain(intel_encoder);
721
722 intel_display_power_get(dev_priv, power_domain);
723 connector_status = intel_dsi->dev.dev_ops->detect(&intel_dsi->dev);
724 intel_display_power_put(dev_priv, power_domain);
725
726 return connector_status;
Jani Nikula4e646492013-08-27 15:12:20 +0300727}
728
729static int intel_dsi_get_modes(struct drm_connector *connector)
730{
731 struct intel_connector *intel_connector = to_intel_connector(connector);
732 struct drm_display_mode *mode;
733
734 DRM_DEBUG_KMS("\n");
735
736 if (!intel_connector->panel.fixed_mode) {
737 DRM_DEBUG_KMS("no fixed mode\n");
738 return 0;
739 }
740
741 mode = drm_mode_duplicate(connector->dev,
742 intel_connector->panel.fixed_mode);
743 if (!mode) {
744 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
745 return 0;
746 }
747
748 drm_mode_probed_add(connector, mode);
749 return 1;
750}
751
752static void intel_dsi_destroy(struct drm_connector *connector)
753{
754 struct intel_connector *intel_connector = to_intel_connector(connector);
755
756 DRM_DEBUG_KMS("\n");
757 intel_panel_fini(&intel_connector->panel);
Jani Nikula4e646492013-08-27 15:12:20 +0300758 drm_connector_cleanup(connector);
759 kfree(connector);
760}
761
762static const struct drm_encoder_funcs intel_dsi_funcs = {
763 .destroy = intel_encoder_destroy,
764};
765
766static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
767 .get_modes = intel_dsi_get_modes,
768 .mode_valid = intel_dsi_mode_valid,
769 .best_encoder = intel_best_encoder,
770};
771
772static const struct drm_connector_funcs intel_dsi_connector_funcs = {
773 .dpms = intel_connector_dpms,
774 .detect = intel_dsi_detect,
775 .destroy = intel_dsi_destroy,
776 .fill_modes = drm_helper_probe_single_connector_modes,
777};
778
Damien Lespiau4328633d2014-05-28 12:30:56 +0100779void intel_dsi_init(struct drm_device *dev)
Jani Nikula4e646492013-08-27 15:12:20 +0300780{
781 struct intel_dsi *intel_dsi;
782 struct intel_encoder *intel_encoder;
783 struct drm_encoder *encoder;
784 struct intel_connector *intel_connector;
785 struct drm_connector *connector;
786 struct drm_display_mode *fixed_mode = NULL;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530787 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300788 const struct intel_dsi_device *dsi;
789 unsigned int i;
790
791 DRM_DEBUG_KMS("\n");
792
Shobhit Kumar3e6bd012014-05-27 19:33:59 +0530793 /* There is no detection method for MIPI so rely on VBT */
794 if (!dev_priv->vbt.has_mipi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100795 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300796
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530797 if (IS_VALLEYVIEW(dev)) {
798 dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
799 } else {
800 DRM_ERROR("Unsupported Mipi device to reg base");
Christoph Jaeger868d6652014-06-13 21:51:22 +0200801 return;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530802 }
803
Jani Nikula4e646492013-08-27 15:12:20 +0300804 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
805 if (!intel_dsi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100806 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300807
808 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
809 if (!intel_connector) {
810 kfree(intel_dsi);
Damien Lespiau4328633d2014-05-28 12:30:56 +0100811 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300812 }
813
814 intel_encoder = &intel_dsi->base;
815 encoder = &intel_encoder->base;
816 intel_dsi->attached_connector = intel_connector;
817
Jani Nikula4e646492013-08-27 15:12:20 +0300818 connector = &intel_connector->base;
819
820 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
821
822 /* XXX: very likely not all of these are needed */
823 intel_encoder->hot_plug = intel_dsi_hot_plug;
824 intel_encoder->compute_config = intel_dsi_compute_config;
825 intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
826 intel_encoder->pre_enable = intel_dsi_pre_enable;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530827 intel_encoder->enable = intel_dsi_enable_nop;
Imre Deakc315faf2014-05-27 19:00:09 +0300828 intel_encoder->disable = intel_dsi_pre_disable;
Jani Nikula4e646492013-08-27 15:12:20 +0300829 intel_encoder->post_disable = intel_dsi_post_disable;
830 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
831 intel_encoder->get_config = intel_dsi_get_config;
832
833 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak4932e2c2014-02-11 17:12:48 +0200834 intel_connector->unregister = intel_connector_unregister;
Jani Nikula4e646492013-08-27 15:12:20 +0300835
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200836 /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
Jani Nikula17af40a2014-11-14 16:54:22 +0200837 if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200838 intel_encoder->crtc_mask = (1 << PIPE_A);
Jani Nikula17af40a2014-11-14 16:54:22 +0200839 intel_dsi->ports = (1 << PORT_A);
840 } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200841 intel_encoder->crtc_mask = (1 << PIPE_B);
Jani Nikula17af40a2014-11-14 16:54:22 +0200842 intel_dsi->ports = (1 << PORT_C);
843 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200844
Jani Nikula4e646492013-08-27 15:12:20 +0300845 for (i = 0; i < ARRAY_SIZE(intel_dsi_devices); i++) {
846 dsi = &intel_dsi_devices[i];
847 intel_dsi->dev = *dsi;
848
849 if (dsi->dev_ops->init(&intel_dsi->dev))
850 break;
851 }
852
853 if (i == ARRAY_SIZE(intel_dsi_devices)) {
854 DRM_DEBUG_KMS("no device found\n");
855 goto err;
856 }
857
858 intel_encoder->type = INTEL_OUTPUT_DSI;
Ville Syrjäläbc079e82014-03-03 16:15:28 +0200859 intel_encoder->cloneable = 0;
Jani Nikula4e646492013-08-27 15:12:20 +0300860 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
861 DRM_MODE_CONNECTOR_DSI);
862
863 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
864
865 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
866 connector->interlace_allowed = false;
867 connector->doublescan_allowed = false;
868
869 intel_connector_attach_encoder(intel_connector, intel_encoder);
870
Thomas Wood34ea3d32014-05-29 16:57:41 +0100871 drm_connector_register(connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300872
873 fixed_mode = dsi->dev_ops->get_modes(&intel_dsi->dev);
874 if (!fixed_mode) {
875 DRM_DEBUG_KMS("no fixed mode\n");
876 goto err;
877 }
878
879 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Vandana Kannan4b6ed682014-02-11 14:26:36 +0530880 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
Jani Nikula4e646492013-08-27 15:12:20 +0300881
Damien Lespiau4328633d2014-05-28 12:30:56 +0100882 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300883
884err:
885 drm_encoder_cleanup(&intel_encoder->base);
886 kfree(intel_dsi);
887 kfree(intel_connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300888}