blob: 693736b88080324722029ed0467408c29c6e750f [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);
111 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
112 u32 temp;
113
114 /* assert ip_tg_enable signal */
115 temp = I915_READ(MIPI_PORT_CTRL(port)) & ~LANE_CONFIGURATION_MASK;
116 temp = temp | intel_dsi->port_bits;
117 I915_WRITE(MIPI_PORT_CTRL(port), temp | DPI_ENABLE);
118 POSTING_READ(MIPI_PORT_CTRL(port));
119}
120
121static void intel_dsi_port_disable(struct intel_encoder *encoder)
122{
123 struct drm_device *dev = encoder->base.dev;
124 struct drm_i915_private *dev_priv = dev->dev_private;
125 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
126 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
127 u32 temp;
128
129 /* de-assert ip_tg_enable signal */
130 temp = I915_READ(MIPI_PORT_CTRL(port));
131 I915_WRITE(MIPI_PORT_CTRL(port), temp & ~DPI_ENABLE);
132 POSTING_READ(MIPI_PORT_CTRL(port));
133}
134
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530135static void intel_dsi_device_ready(struct intel_encoder *encoder)
136{
137 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
138 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200139 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530140 u32 val;
141
142 DRM_DEBUG_KMS("\n");
143
Shobhit Kumar2095f9f2014-04-09 13:59:30 +0530144 mutex_lock(&dev_priv->dpio_lock);
145 /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
146 * needed everytime after power gate */
147 vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
148 mutex_unlock(&dev_priv->dpio_lock);
149
150 /* bandgap reset is needed after everytime we do power gate */
151 band_gap_reset(dev_priv);
152
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200153 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530154 usleep_range(2500, 3000);
155
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200156 val = I915_READ(MIPI_PORT_CTRL(port));
157 I915_WRITE(MIPI_PORT_CTRL(port), val | LP_OUTPUT_HOLD);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530158 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530159
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200160 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530161 usleep_range(2500, 3000);
162
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200163 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530164 usleep_range(2500, 3000);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530165}
Jani Nikula4e646492013-08-27 15:12:20 +0300166
167static void intel_dsi_enable(struct intel_encoder *encoder)
168{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530169 struct drm_device *dev = encoder->base.dev;
170 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300171 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
172 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200173 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Jani Nikula4e646492013-08-27 15:12:20 +0300174
175 DRM_DEBUG_KMS("\n");
176
Jani Nikula4e646492013-08-27 15:12:20 +0300177 if (is_cmd_mode(intel_dsi))
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200178 I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530179 else {
Jani Nikula4e646492013-08-27 15:12:20 +0300180 msleep(20); /* XXX */
Shobhit Kumare1047022014-04-09 13:59:35 +0530181 dpi_send_cmd(intel_dsi, TURN_ON, DPI_LP_MODE_EN);
Jani Nikula4e646492013-08-27 15:12:20 +0300182 msleep(100);
183
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530184 if (intel_dsi->dev.dev_ops->enable)
185 intel_dsi->dev.dev_ops->enable(&intel_dsi->dev);
186
Shobhit Kumar13813082014-07-12 17:17:22 +0530187 wait_for_dsi_fifo_empty(intel_dsi);
188
Gaurav K Singh5505a242014-12-04 10:58:47 +0530189 intel_dsi_port_enable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300190 }
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530191}
Jani Nikula4e646492013-08-27 15:12:20 +0300192
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530193static void intel_dsi_pre_enable(struct intel_encoder *encoder)
194{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530195 struct drm_device *dev = encoder->base.dev;
196 struct drm_i915_private *dev_priv = dev->dev_private;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530197 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530198 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
199 enum pipe pipe = intel_crtc->pipe;
200 u32 tmp;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530201
202 DRM_DEBUG_KMS("\n");
203
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530204 /* Disable DPOunit clock gating, can stall pipe
205 * and we need DPLL REFA always enabled */
206 tmp = I915_READ(DPLL(pipe));
207 tmp |= DPLL_REFA_CLK_ENABLE_VLV;
208 I915_WRITE(DPLL(pipe), tmp);
209
Shobhit Kumarf573de52014-07-30 20:32:37 +0530210 /* update the hw state for DPLL */
211 intel_crtc->config.dpll_hw_state.dpll = DPLL_INTEGRATED_CLOCK_VLV |
Daniel Vetter7f3de832014-07-30 22:34:27 +0200212 DPLL_REFA_CLK_ENABLE_VLV;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530213
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530214 tmp = I915_READ(DSPCLK_GATE_D);
215 tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
216 I915_WRITE(DSPCLK_GATE_D, tmp);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530217
218 /* put device in ready state */
219 intel_dsi_device_ready(encoder);
220
Shobhit Kumardf38e652014-04-14 11:18:26 +0530221 msleep(intel_dsi->panel_on_delay);
222
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530223 if (intel_dsi->dev.dev_ops->panel_reset)
224 intel_dsi->dev.dev_ops->panel_reset(&intel_dsi->dev);
225
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530226 if (intel_dsi->dev.dev_ops->send_otp_cmds)
227 intel_dsi->dev.dev_ops->send_otp_cmds(&intel_dsi->dev);
228
Shobhit Kumar13813082014-07-12 17:17:22 +0530229 wait_for_dsi_fifo_empty(intel_dsi);
230
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530231 /* Enable port in pre-enable phase itself because as per hw team
232 * recommendation, port should be enabled befor plane & pipe */
233 intel_dsi_enable(encoder);
234}
235
236static void intel_dsi_enable_nop(struct intel_encoder *encoder)
237{
238 DRM_DEBUG_KMS("\n");
239
240 /* for DSI port enable has to be done before pipe
241 * and plane enable, so port enable is done in
242 * pre_enable phase itself unlike other encoders
243 */
Jani Nikula4e646492013-08-27 15:12:20 +0300244}
245
Imre Deakc315faf2014-05-27 19:00:09 +0300246static void intel_dsi_pre_disable(struct intel_encoder *encoder)
247{
248 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
249
250 DRM_DEBUG_KMS("\n");
251
252 if (is_vid_mode(intel_dsi)) {
253 /* Send Shutdown command to the panel in LP mode */
254 dpi_send_cmd(intel_dsi, SHUTDOWN, DPI_LP_MODE_EN);
255 msleep(10);
256 }
257}
258
Jani Nikula4e646492013-08-27 15:12:20 +0300259static void intel_dsi_disable(struct intel_encoder *encoder)
260{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530261 struct drm_device *dev = encoder->base.dev;
262 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300263 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
264 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200265 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Jani Nikula4e646492013-08-27 15:12:20 +0300266 u32 temp;
267
268 DRM_DEBUG_KMS("\n");
269
Jani Nikula4e646492013-08-27 15:12:20 +0300270 if (is_vid_mode(intel_dsi)) {
Shobhit Kumar13813082014-07-12 17:17:22 +0530271 wait_for_dsi_fifo_empty(intel_dsi);
272
Gaurav K Singh5505a242014-12-04 10:58:47 +0530273 intel_dsi_port_disable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300274 msleep(2);
275 }
276
Shobhit Kumar339023e2014-04-09 13:59:34 +0530277 /* Panel commands can be sent when clock is in LP11 */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200278 I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530279
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200280 temp = I915_READ(MIPI_CTRL(port));
Shobhit Kumar339023e2014-04-09 13:59:34 +0530281 temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200282 I915_WRITE(MIPI_CTRL(port), temp |
Daniel Vetter7f3de832014-07-30 22:34:27 +0200283 intel_dsi->escape_clk_div <<
284 ESCAPE_CLOCK_DIVIDER_SHIFT);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530285
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200286 I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530287
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200288 temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
Shobhit Kumar339023e2014-04-09 13:59:34 +0530289 temp &= ~VID_MODE_FORMAT_MASK;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200290 I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530291
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200292 I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530293
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530294 /* if disable packets are sent before sending shutdown packet then in
295 * some next enable sequence send turn on packet error is observed */
296 if (intel_dsi->dev.dev_ops->disable)
297 intel_dsi->dev.dev_ops->disable(&intel_dsi->dev);
Shobhit Kumar13813082014-07-12 17:17:22 +0530298
299 wait_for_dsi_fifo_empty(intel_dsi);
Jani Nikula4e646492013-08-27 15:12:20 +0300300}
301
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530302static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300303{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530304 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
305 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200306 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530307 u32 val;
308
Jani Nikula4e646492013-08-27 15:12:20 +0300309 DRM_DEBUG_KMS("\n");
ymohanmabe4fc042013-08-27 23:40:56 +0300310
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200311 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | ULPS_STATE_ENTER);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530312 usleep_range(2000, 2500);
313
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200314 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | ULPS_STATE_EXIT);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530315 usleep_range(2000, 2500);
316
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200317 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | ULPS_STATE_ENTER);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530318 usleep_range(2000, 2500);
319
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200320 if (wait_for(((I915_READ(MIPI_PORT_CTRL(port)) & AFE_LATCHOUT)
Daniel Vetter7f3de832014-07-30 22:34:27 +0200321 == 0x00000), 30))
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530322 DRM_ERROR("DSI LP not going Low\n");
323
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200324 val = I915_READ(MIPI_PORT_CTRL(port));
325 I915_WRITE(MIPI_PORT_CTRL(port), val & ~LP_OUTPUT_HOLD);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530326 usleep_range(1000, 1500);
327
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200328 I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530329 usleep_range(2000, 2500);
330
ymohanmabe4fc042013-08-27 23:40:56 +0300331 vlv_disable_dsi_pll(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300332}
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530333
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530334static void intel_dsi_post_disable(struct intel_encoder *encoder)
335{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530336 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530337 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530338 u32 val;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530339
340 DRM_DEBUG_KMS("\n");
341
Imre Deakc315faf2014-05-27 19:00:09 +0300342 intel_dsi_disable(encoder);
343
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530344 intel_dsi_clear_device_ready(encoder);
345
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530346 val = I915_READ(DSPCLK_GATE_D);
347 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
348 I915_WRITE(DSPCLK_GATE_D, val);
349
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530350 if (intel_dsi->dev.dev_ops->disable_panel_power)
351 intel_dsi->dev.dev_ops->disable_panel_power(&intel_dsi->dev);
Shobhit Kumardf38e652014-04-14 11:18:26 +0530352
353 msleep(intel_dsi->panel_off_delay);
354 msleep(intel_dsi->panel_pwr_cycle_delay);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530355}
Jani Nikula4e646492013-08-27 15:12:20 +0300356
357static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
358 enum pipe *pipe)
359{
360 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Imre Deak6d129be2014-03-05 16:20:54 +0200361 enum intel_display_power_domain power_domain;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200362 u32 port_ctl, func;
363 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300364
365 DRM_DEBUG_KMS("\n");
366
Imre Deak6d129be2014-03-05 16:20:54 +0200367 power_domain = intel_display_port_power_domain(encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200368 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200369 return false;
370
Jani Nikula4e646492013-08-27 15:12:20 +0300371 /* XXX: this only works for one DSI output */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200372 for_each_dsi_port(port, (1 << PORT_A) | (1 << PORT_C)) {
373 port_ctl = I915_READ(MIPI_PORT_CTRL(port));
374 func = I915_READ(MIPI_DSI_FUNC_PRG(port));
Jani Nikula4e646492013-08-27 15:12:20 +0300375
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200376 if ((port_ctl & DPI_ENABLE) || (func & CMD_MODE_DATA_WIDTH_MASK)) {
377 if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
378 *pipe = port == PORT_A ? PIPE_A : PIPE_C;
Jani Nikula4e646492013-08-27 15:12:20 +0300379 return true;
380 }
381 }
382 }
383
384 return false;
385}
386
387static void intel_dsi_get_config(struct intel_encoder *encoder,
388 struct intel_crtc_config *pipe_config)
389{
Shobhit Kumarf573de52014-07-30 20:32:37 +0530390 u32 pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300391 DRM_DEBUG_KMS("\n");
392
Shobhit Kumarf573de52014-07-30 20:32:37 +0530393 /*
394 * DPLL_MD is not used in case of DSI, reading will get some default value
395 * set dpll_md = 0
396 */
397 pipe_config->dpll_hw_state.dpll_md = 0;
398
399 pclk = vlv_get_dsi_pclk(encoder, pipe_config->pipe_bpp);
400 if (!pclk)
401 return;
402
403 pipe_config->adjusted_mode.crtc_clock = pclk;
404 pipe_config->port_clock = pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300405}
406
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000407static enum drm_mode_status
408intel_dsi_mode_valid(struct drm_connector *connector,
409 struct drm_display_mode *mode)
Jani Nikula4e646492013-08-27 15:12:20 +0300410{
411 struct intel_connector *intel_connector = to_intel_connector(connector);
412 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
413 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
414
415 DRM_DEBUG_KMS("\n");
416
417 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
418 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
419 return MODE_NO_DBLESCAN;
420 }
421
422 if (fixed_mode) {
423 if (mode->hdisplay > fixed_mode->hdisplay)
424 return MODE_PANEL;
425 if (mode->vdisplay > fixed_mode->vdisplay)
426 return MODE_PANEL;
427 }
428
429 return intel_dsi->dev.dev_ops->mode_valid(&intel_dsi->dev, mode);
430}
431
432/* return txclkesc cycles in terms of divider and duration in us */
433static u16 txclkesc(u32 divider, unsigned int us)
434{
435 switch (divider) {
436 case ESCAPE_CLOCK_DIVIDER_1:
437 default:
438 return 20 * us;
439 case ESCAPE_CLOCK_DIVIDER_2:
440 return 10 * us;
441 case ESCAPE_CLOCK_DIVIDER_4:
442 return 5 * us;
443 }
444}
445
446/* return pixels in terms of txbyteclkhs */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530447static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
448 u16 burst_mode_ratio)
Jani Nikula4e646492013-08-27 15:12:20 +0300449{
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530450 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200451 8 * 100), lane_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300452}
453
454static void set_dsi_timings(struct drm_encoder *encoder,
455 const struct drm_display_mode *mode)
456{
457 struct drm_device *dev = encoder->dev;
458 struct drm_i915_private *dev_priv = dev->dev_private;
459 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
460 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200461 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Jani Nikula4e646492013-08-27 15:12:20 +0300462 unsigned int bpp = intel_crtc->config.pipe_bpp;
463 unsigned int lane_count = intel_dsi->lane_count;
464
465 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
466
467 hactive = mode->hdisplay;
468 hfp = mode->hsync_start - mode->hdisplay;
469 hsync = mode->hsync_end - mode->hsync_start;
470 hbp = mode->htotal - mode->hsync_end;
471
472 vfp = mode->vsync_start - mode->vdisplay;
473 vsync = mode->vsync_end - mode->vsync_start;
474 vbp = mode->vtotal - mode->vsync_end;
475
476 /* horizontal values are in terms of high speed byte clock */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530477 hactive = txbyteclkhs(hactive, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200478 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530479 hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
480 hsync = txbyteclkhs(hsync, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200481 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530482 hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
Jani Nikula4e646492013-08-27 15:12:20 +0300483
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200484 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
485 I915_WRITE(MIPI_HFP_COUNT(port), hfp);
Jani Nikula4e646492013-08-27 15:12:20 +0300486
487 /* meaningful for video mode non-burst sync pulse mode only, can be zero
488 * for non-burst sync events and burst modes */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200489 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
490 I915_WRITE(MIPI_HBP_COUNT(port), hbp);
Jani Nikula4e646492013-08-27 15:12:20 +0300491
492 /* vertical values are in terms of lines */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200493 I915_WRITE(MIPI_VFP_COUNT(port), vfp);
494 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
495 I915_WRITE(MIPI_VBP_COUNT(port), vbp);
Jani Nikula4e646492013-08-27 15:12:20 +0300496}
497
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200498static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300499{
500 struct drm_encoder *encoder = &intel_encoder->base;
501 struct drm_device *dev = encoder->dev;
502 struct drm_i915_private *dev_priv = dev->dev_private;
503 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
504 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
505 struct drm_display_mode *adjusted_mode =
506 &intel_crtc->config.adjusted_mode;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200507 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Jani Nikula4e646492013-08-27 15:12:20 +0300508 unsigned int bpp = intel_crtc->config.pipe_bpp;
509 u32 val, tmp;
510
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200511 DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
Jani Nikula4e646492013-08-27 15:12:20 +0300512
Jani Nikula4e646492013-08-27 15:12:20 +0300513 /* escape clock divider, 20MHz, shared for A and C. device ready must be
514 * off when doing this! txclkesc? */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200515 tmp = I915_READ(MIPI_CTRL(PORT_A));
Jani Nikula4e646492013-08-27 15:12:20 +0300516 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200517 I915_WRITE(MIPI_CTRL(PORT_A), tmp | ESCAPE_CLOCK_DIVIDER_1);
Jani Nikula4e646492013-08-27 15:12:20 +0300518
519 /* read request priority is per pipe */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200520 tmp = I915_READ(MIPI_CTRL(port));
Jani Nikula4e646492013-08-27 15:12:20 +0300521 tmp &= ~READ_REQUEST_PRIORITY_MASK;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200522 I915_WRITE(MIPI_CTRL(port), tmp | READ_REQUEST_PRIORITY_HIGH);
Jani Nikula4e646492013-08-27 15:12:20 +0300523
524 /* XXX: why here, why like this? handling in irq handler?! */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200525 I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
526 I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
Jani Nikula4e646492013-08-27 15:12:20 +0300527
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200528 I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
Jani Nikula4e646492013-08-27 15:12:20 +0300529
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200530 I915_WRITE(MIPI_DPI_RESOLUTION(port),
Jani Nikula4e646492013-08-27 15:12:20 +0300531 adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
532 adjusted_mode->hdisplay << HORIZONTAL_ADDRESS_SHIFT);
533
534 set_dsi_timings(encoder, adjusted_mode);
535
536 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
537 if (is_cmd_mode(intel_dsi)) {
538 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
539 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
540 } else {
541 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
542
543 /* XXX: cross-check bpp vs. pixel format? */
544 val |= intel_dsi->pixel_format;
545 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200546 I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300547
548 /* timeouts for recovery. one frame IIUC. if counter expires, EOT and
549 * stop state. */
550
551 /*
552 * In burst mode, value greater than one DPI line Time in byte clock
553 * (txbyteclkhs) To timeout this timer 1+ of the above said value is
554 * recommended.
555 *
556 * In non-burst mode, Value greater than one DPI frame time in byte
557 * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
558 * is recommended.
559 *
560 * In DBI only mode, value greater than one DBI frame time in byte
561 * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
562 * is recommended.
563 */
564
565 if (is_vid_mode(intel_dsi) &&
566 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200567 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
Jani Nikula4e646492013-08-27 15:12:20 +0300568 txbyteclkhs(adjusted_mode->htotal, bpp,
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530569 intel_dsi->lane_count,
570 intel_dsi->burst_mode_ratio) + 1);
Jani Nikula4e646492013-08-27 15:12:20 +0300571 } else {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200572 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
Jani Nikula4e646492013-08-27 15:12:20 +0300573 txbyteclkhs(adjusted_mode->vtotal *
574 adjusted_mode->htotal,
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530575 bpp, intel_dsi->lane_count,
576 intel_dsi->burst_mode_ratio) + 1);
Jani Nikula4e646492013-08-27 15:12:20 +0300577 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200578 I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
579 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port), intel_dsi->turn_arnd_val);
580 I915_WRITE(MIPI_DEVICE_RESET_TIMER(port), intel_dsi->rst_timer_val);
Jani Nikula4e646492013-08-27 15:12:20 +0300581
582 /* dphy stuff */
583
584 /* in terms of low power clock */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200585 I915_WRITE(MIPI_INIT_COUNT(port), txclkesc(intel_dsi->escape_clk_div, 100));
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530586
587 val = 0;
588 if (intel_dsi->eotp_pkt == 0)
589 val |= EOT_DISABLE;
590
591 if (intel_dsi->clock_stop)
592 val |= CLOCKSTOP;
Jani Nikula4e646492013-08-27 15:12:20 +0300593
594 /* recovery disables */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200595 I915_WRITE(MIPI_EOT_DISABLE(port), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300596
Shobhit Kumarcf4dbd22014-04-14 11:18:25 +0530597 /* in terms of low power clock */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200598 I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
Shobhit Kumarcf4dbd22014-04-14 11:18:25 +0530599
Jani Nikula4e646492013-08-27 15:12:20 +0300600 /* in terms of txbyteclkhs. actual high to low switch +
601 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
602 *
603 * XXX: write MIPI_STOP_STATE_STALL?
604 */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200605 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
Daniel Vetter7f3de832014-07-30 22:34:27 +0200606 intel_dsi->hs_to_lp_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300607
608 /* XXX: low power clock equivalence in terms of byte clock. the number
609 * of byte clocks occupied in one low power clock. based on txbyteclkhs
610 * and txclkesc. txclkesc time / txbyteclk time * (105 +
611 * MIPI_STOP_STATE_STALL) / 105.???
612 */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200613 I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
Jani Nikula4e646492013-08-27 15:12:20 +0300614
615 /* the bw essential for transmitting 16 long packets containing 252
616 * bytes meant for dcs write memory command is programmed in this
617 * register in terms of byte clocks. based on dsi transfer rate and the
618 * number of lanes configured the time taken to transmit 16 long packets
619 * in a dsi stream varies. */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200620 I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
Jani Nikula4e646492013-08-27 15:12:20 +0300621
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200622 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
Shobhit Kumarf6da2842013-12-10 12:15:00 +0530623 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
624 intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
Jani Nikula4e646492013-08-27 15:12:20 +0300625
626 if (is_vid_mode(intel_dsi))
Shobhit Kumar24d9c402014-04-09 13:59:36 +0530627 /* Some panels might have resolution which is not a multiple of
628 * 64 like 1366 x 768. Enable RANDOM resolution support for such
629 * panels by default */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200630 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
Daniel Vetter7f3de832014-07-30 22:34:27 +0200631 intel_dsi->video_frmt_cfg_bits |
632 intel_dsi->video_mode_format |
633 IP_TG_CONFIG |
634 RANDOM_DPI_DISPLAY_RESOLUTION);
Jani Nikula4e646492013-08-27 15:12:20 +0300635}
636
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200637static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
638{
639 DRM_DEBUG_KMS("\n");
640
641 intel_dsi_prepare(encoder);
642
643 vlv_enable_dsi_pll(encoder);
644}
645
Jani Nikula4e646492013-08-27 15:12:20 +0300646static enum drm_connector_status
647intel_dsi_detect(struct drm_connector *connector, bool force)
648{
649 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
Imre Deak671dedd2014-03-05 16:20:53 +0200650 struct intel_encoder *intel_encoder = &intel_dsi->base;
651 enum intel_display_power_domain power_domain;
652 enum drm_connector_status connector_status;
653 struct drm_i915_private *dev_priv = intel_encoder->base.dev->dev_private;
654
Jani Nikula4e646492013-08-27 15:12:20 +0300655 DRM_DEBUG_KMS("\n");
Imre Deak671dedd2014-03-05 16:20:53 +0200656 power_domain = intel_display_port_power_domain(intel_encoder);
657
658 intel_display_power_get(dev_priv, power_domain);
659 connector_status = intel_dsi->dev.dev_ops->detect(&intel_dsi->dev);
660 intel_display_power_put(dev_priv, power_domain);
661
662 return connector_status;
Jani Nikula4e646492013-08-27 15:12:20 +0300663}
664
665static int intel_dsi_get_modes(struct drm_connector *connector)
666{
667 struct intel_connector *intel_connector = to_intel_connector(connector);
668 struct drm_display_mode *mode;
669
670 DRM_DEBUG_KMS("\n");
671
672 if (!intel_connector->panel.fixed_mode) {
673 DRM_DEBUG_KMS("no fixed mode\n");
674 return 0;
675 }
676
677 mode = drm_mode_duplicate(connector->dev,
678 intel_connector->panel.fixed_mode);
679 if (!mode) {
680 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
681 return 0;
682 }
683
684 drm_mode_probed_add(connector, mode);
685 return 1;
686}
687
688static void intel_dsi_destroy(struct drm_connector *connector)
689{
690 struct intel_connector *intel_connector = to_intel_connector(connector);
691
692 DRM_DEBUG_KMS("\n");
693 intel_panel_fini(&intel_connector->panel);
Jani Nikula4e646492013-08-27 15:12:20 +0300694 drm_connector_cleanup(connector);
695 kfree(connector);
696}
697
698static const struct drm_encoder_funcs intel_dsi_funcs = {
699 .destroy = intel_encoder_destroy,
700};
701
702static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
703 .get_modes = intel_dsi_get_modes,
704 .mode_valid = intel_dsi_mode_valid,
705 .best_encoder = intel_best_encoder,
706};
707
708static const struct drm_connector_funcs intel_dsi_connector_funcs = {
709 .dpms = intel_connector_dpms,
710 .detect = intel_dsi_detect,
711 .destroy = intel_dsi_destroy,
712 .fill_modes = drm_helper_probe_single_connector_modes,
713};
714
Damien Lespiau4328633d2014-05-28 12:30:56 +0100715void intel_dsi_init(struct drm_device *dev)
Jani Nikula4e646492013-08-27 15:12:20 +0300716{
717 struct intel_dsi *intel_dsi;
718 struct intel_encoder *intel_encoder;
719 struct drm_encoder *encoder;
720 struct intel_connector *intel_connector;
721 struct drm_connector *connector;
722 struct drm_display_mode *fixed_mode = NULL;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530723 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300724 const struct intel_dsi_device *dsi;
725 unsigned int i;
726
727 DRM_DEBUG_KMS("\n");
728
Shobhit Kumar3e6bd012014-05-27 19:33:59 +0530729 /* There is no detection method for MIPI so rely on VBT */
730 if (!dev_priv->vbt.has_mipi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100731 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300732
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530733 if (IS_VALLEYVIEW(dev)) {
734 dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
735 } else {
736 DRM_ERROR("Unsupported Mipi device to reg base");
Christoph Jaeger868d6652014-06-13 21:51:22 +0200737 return;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530738 }
739
Jani Nikula4e646492013-08-27 15:12:20 +0300740 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
741 if (!intel_dsi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100742 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300743
744 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
745 if (!intel_connector) {
746 kfree(intel_dsi);
Damien Lespiau4328633d2014-05-28 12:30:56 +0100747 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300748 }
749
750 intel_encoder = &intel_dsi->base;
751 encoder = &intel_encoder->base;
752 intel_dsi->attached_connector = intel_connector;
753
Jani Nikula4e646492013-08-27 15:12:20 +0300754 connector = &intel_connector->base;
755
756 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
757
758 /* XXX: very likely not all of these are needed */
759 intel_encoder->hot_plug = intel_dsi_hot_plug;
760 intel_encoder->compute_config = intel_dsi_compute_config;
761 intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
762 intel_encoder->pre_enable = intel_dsi_pre_enable;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530763 intel_encoder->enable = intel_dsi_enable_nop;
Imre Deakc315faf2014-05-27 19:00:09 +0300764 intel_encoder->disable = intel_dsi_pre_disable;
Jani Nikula4e646492013-08-27 15:12:20 +0300765 intel_encoder->post_disable = intel_dsi_post_disable;
766 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
767 intel_encoder->get_config = intel_dsi_get_config;
768
769 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak4932e2c2014-02-11 17:12:48 +0200770 intel_connector->unregister = intel_connector_unregister;
Jani Nikula4e646492013-08-27 15:12:20 +0300771
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200772 /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
Jani Nikula17af40a2014-11-14 16:54:22 +0200773 if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200774 intel_encoder->crtc_mask = (1 << PIPE_A);
Jani Nikula17af40a2014-11-14 16:54:22 +0200775 intel_dsi->ports = (1 << PORT_A);
776 } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200777 intel_encoder->crtc_mask = (1 << PIPE_B);
Jani Nikula17af40a2014-11-14 16:54:22 +0200778 intel_dsi->ports = (1 << PORT_C);
779 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200780
Jani Nikula4e646492013-08-27 15:12:20 +0300781 for (i = 0; i < ARRAY_SIZE(intel_dsi_devices); i++) {
782 dsi = &intel_dsi_devices[i];
783 intel_dsi->dev = *dsi;
784
785 if (dsi->dev_ops->init(&intel_dsi->dev))
786 break;
787 }
788
789 if (i == ARRAY_SIZE(intel_dsi_devices)) {
790 DRM_DEBUG_KMS("no device found\n");
791 goto err;
792 }
793
794 intel_encoder->type = INTEL_OUTPUT_DSI;
Ville Syrjäläbc079e82014-03-03 16:15:28 +0200795 intel_encoder->cloneable = 0;
Jani Nikula4e646492013-08-27 15:12:20 +0300796 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
797 DRM_MODE_CONNECTOR_DSI);
798
799 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
800
801 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
802 connector->interlace_allowed = false;
803 connector->doublescan_allowed = false;
804
805 intel_connector_attach_encoder(intel_connector, intel_encoder);
806
Thomas Wood34ea3d32014-05-29 16:57:41 +0100807 drm_connector_register(connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300808
809 fixed_mode = dsi->dev_ops->get_modes(&intel_dsi->dev);
810 if (!fixed_mode) {
811 DRM_DEBUG_KMS("no fixed mode\n");
812 goto err;
813 }
814
815 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Vandana Kannan4b6ed682014-02-11 14:26:36 +0530816 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
Jani Nikula4e646492013-08-27 15:12:20 +0300817
Damien Lespiau4328633d2014-05-28 12:30:56 +0100818 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300819
820err:
821 drm_encoder_cleanup(&intel_encoder->base);
822 kfree(intel_dsi);
823 kfree(intel_connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300824}