blob: a1b93c5590256031165bf53e0168fe49094dbede [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;
159 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200160 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
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
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200174 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530175 usleep_range(2500, 3000);
176
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200177 val = I915_READ(MIPI_PORT_CTRL(port));
178 I915_WRITE(MIPI_PORT_CTRL(port), val | LP_OUTPUT_HOLD);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530179 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530180
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200181 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530182 usleep_range(2500, 3000);
183
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200184 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530185 usleep_range(2500, 3000);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530186}
Jani Nikula4e646492013-08-27 15:12:20 +0300187
188static void intel_dsi_enable(struct intel_encoder *encoder)
189{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530190 struct drm_device *dev = encoder->base.dev;
191 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300192 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
193 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200194 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Jani Nikula4e646492013-08-27 15:12:20 +0300195
196 DRM_DEBUG_KMS("\n");
197
Jani Nikula4e646492013-08-27 15:12:20 +0300198 if (is_cmd_mode(intel_dsi))
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200199 I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530200 else {
Jani Nikula4e646492013-08-27 15:12:20 +0300201 msleep(20); /* XXX */
Shobhit Kumare1047022014-04-09 13:59:35 +0530202 dpi_send_cmd(intel_dsi, TURN_ON, DPI_LP_MODE_EN);
Jani Nikula4e646492013-08-27 15:12:20 +0300203 msleep(100);
204
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530205 if (intel_dsi->dev.dev_ops->enable)
206 intel_dsi->dev.dev_ops->enable(&intel_dsi->dev);
207
Shobhit Kumar13813082014-07-12 17:17:22 +0530208 wait_for_dsi_fifo_empty(intel_dsi);
209
Gaurav K Singh5505a242014-12-04 10:58:47 +0530210 intel_dsi_port_enable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300211 }
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530212}
Jani Nikula4e646492013-08-27 15:12:20 +0300213
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530214static void intel_dsi_pre_enable(struct intel_encoder *encoder)
215{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530216 struct drm_device *dev = encoder->base.dev;
217 struct drm_i915_private *dev_priv = dev->dev_private;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530218 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530219 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
220 enum pipe pipe = intel_crtc->pipe;
221 u32 tmp;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530222
223 DRM_DEBUG_KMS("\n");
224
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530225 /* Disable DPOunit clock gating, can stall pipe
226 * and we need DPLL REFA always enabled */
227 tmp = I915_READ(DPLL(pipe));
228 tmp |= DPLL_REFA_CLK_ENABLE_VLV;
229 I915_WRITE(DPLL(pipe), tmp);
230
Shobhit Kumarf573de52014-07-30 20:32:37 +0530231 /* update the hw state for DPLL */
232 intel_crtc->config.dpll_hw_state.dpll = DPLL_INTEGRATED_CLOCK_VLV |
Daniel Vetter7f3de832014-07-30 22:34:27 +0200233 DPLL_REFA_CLK_ENABLE_VLV;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530234
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530235 tmp = I915_READ(DSPCLK_GATE_D);
236 tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
237 I915_WRITE(DSPCLK_GATE_D, tmp);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530238
239 /* put device in ready state */
240 intel_dsi_device_ready(encoder);
241
Shobhit Kumardf38e652014-04-14 11:18:26 +0530242 msleep(intel_dsi->panel_on_delay);
243
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530244 if (intel_dsi->dev.dev_ops->panel_reset)
245 intel_dsi->dev.dev_ops->panel_reset(&intel_dsi->dev);
246
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530247 if (intel_dsi->dev.dev_ops->send_otp_cmds)
248 intel_dsi->dev.dev_ops->send_otp_cmds(&intel_dsi->dev);
249
Shobhit Kumar13813082014-07-12 17:17:22 +0530250 wait_for_dsi_fifo_empty(intel_dsi);
251
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530252 /* Enable port in pre-enable phase itself because as per hw team
253 * recommendation, port should be enabled befor plane & pipe */
254 intel_dsi_enable(encoder);
255}
256
257static void intel_dsi_enable_nop(struct intel_encoder *encoder)
258{
259 DRM_DEBUG_KMS("\n");
260
261 /* for DSI port enable has to be done before pipe
262 * and plane enable, so port enable is done in
263 * pre_enable phase itself unlike other encoders
264 */
Jani Nikula4e646492013-08-27 15:12:20 +0300265}
266
Imre Deakc315faf2014-05-27 19:00:09 +0300267static void intel_dsi_pre_disable(struct intel_encoder *encoder)
268{
269 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
270
271 DRM_DEBUG_KMS("\n");
272
273 if (is_vid_mode(intel_dsi)) {
274 /* Send Shutdown command to the panel in LP mode */
275 dpi_send_cmd(intel_dsi, SHUTDOWN, DPI_LP_MODE_EN);
276 msleep(10);
277 }
278}
279
Jani Nikula4e646492013-08-27 15:12:20 +0300280static void intel_dsi_disable(struct intel_encoder *encoder)
281{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530282 struct drm_device *dev = encoder->base.dev;
283 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300284 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
285 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200286 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Jani Nikula4e646492013-08-27 15:12:20 +0300287 u32 temp;
288
289 DRM_DEBUG_KMS("\n");
290
Jani Nikula4e646492013-08-27 15:12:20 +0300291 if (is_vid_mode(intel_dsi)) {
Shobhit Kumar13813082014-07-12 17:17:22 +0530292 wait_for_dsi_fifo_empty(intel_dsi);
293
Gaurav K Singh5505a242014-12-04 10:58:47 +0530294 intel_dsi_port_disable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300295 msleep(2);
296 }
297
Shobhit Kumar339023e2014-04-09 13:59:34 +0530298 /* Panel commands can be sent when clock is in LP11 */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200299 I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530300
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200301 temp = I915_READ(MIPI_CTRL(port));
Shobhit Kumar339023e2014-04-09 13:59:34 +0530302 temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200303 I915_WRITE(MIPI_CTRL(port), temp |
Daniel Vetter7f3de832014-07-30 22:34:27 +0200304 intel_dsi->escape_clk_div <<
305 ESCAPE_CLOCK_DIVIDER_SHIFT);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530306
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200307 I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530308
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200309 temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
Shobhit Kumar339023e2014-04-09 13:59:34 +0530310 temp &= ~VID_MODE_FORMAT_MASK;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200311 I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530312
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200313 I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530314
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530315 /* if disable packets are sent before sending shutdown packet then in
316 * some next enable sequence send turn on packet error is observed */
317 if (intel_dsi->dev.dev_ops->disable)
318 intel_dsi->dev.dev_ops->disable(&intel_dsi->dev);
Shobhit Kumar13813082014-07-12 17:17:22 +0530319
320 wait_for_dsi_fifo_empty(intel_dsi);
Jani Nikula4e646492013-08-27 15:12:20 +0300321}
322
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530323static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300324{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530325 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
326 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200327 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530328 u32 val;
329
Jani Nikula4e646492013-08-27 15:12:20 +0300330 DRM_DEBUG_KMS("\n");
ymohanmabe4fc042013-08-27 23:40:56 +0300331
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200332 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | ULPS_STATE_ENTER);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530333 usleep_range(2000, 2500);
334
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200335 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | ULPS_STATE_EXIT);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530336 usleep_range(2000, 2500);
337
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200338 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | ULPS_STATE_ENTER);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530339 usleep_range(2000, 2500);
340
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200341 if (wait_for(((I915_READ(MIPI_PORT_CTRL(port)) & AFE_LATCHOUT)
Daniel Vetter7f3de832014-07-30 22:34:27 +0200342 == 0x00000), 30))
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530343 DRM_ERROR("DSI LP not going Low\n");
344
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200345 val = I915_READ(MIPI_PORT_CTRL(port));
346 I915_WRITE(MIPI_PORT_CTRL(port), val & ~LP_OUTPUT_HOLD);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530347 usleep_range(1000, 1500);
348
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200349 I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530350 usleep_range(2000, 2500);
351
ymohanmabe4fc042013-08-27 23:40:56 +0300352 vlv_disable_dsi_pll(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300353}
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530354
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530355static void intel_dsi_post_disable(struct intel_encoder *encoder)
356{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530357 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530358 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530359 u32 val;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530360
361 DRM_DEBUG_KMS("\n");
362
Imre Deakc315faf2014-05-27 19:00:09 +0300363 intel_dsi_disable(encoder);
364
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530365 intel_dsi_clear_device_ready(encoder);
366
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530367 val = I915_READ(DSPCLK_GATE_D);
368 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
369 I915_WRITE(DSPCLK_GATE_D, val);
370
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530371 if (intel_dsi->dev.dev_ops->disable_panel_power)
372 intel_dsi->dev.dev_ops->disable_panel_power(&intel_dsi->dev);
Shobhit Kumardf38e652014-04-14 11:18:26 +0530373
374 msleep(intel_dsi->panel_off_delay);
375 msleep(intel_dsi->panel_pwr_cycle_delay);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530376}
Jani Nikula4e646492013-08-27 15:12:20 +0300377
378static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
379 enum pipe *pipe)
380{
381 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Imre Deak6d129be2014-03-05 16:20:54 +0200382 enum intel_display_power_domain power_domain;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200383 u32 port_ctl, func;
384 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300385
386 DRM_DEBUG_KMS("\n");
387
Imre Deak6d129be2014-03-05 16:20:54 +0200388 power_domain = intel_display_port_power_domain(encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200389 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200390 return false;
391
Jani Nikula4e646492013-08-27 15:12:20 +0300392 /* XXX: this only works for one DSI output */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200393 for_each_dsi_port(port, (1 << PORT_A) | (1 << PORT_C)) {
394 port_ctl = I915_READ(MIPI_PORT_CTRL(port));
395 func = I915_READ(MIPI_DSI_FUNC_PRG(port));
Jani Nikula4e646492013-08-27 15:12:20 +0300396
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200397 if ((port_ctl & DPI_ENABLE) || (func & CMD_MODE_DATA_WIDTH_MASK)) {
398 if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
399 *pipe = port == PORT_A ? PIPE_A : PIPE_C;
Jani Nikula4e646492013-08-27 15:12:20 +0300400 return true;
401 }
402 }
403 }
404
405 return false;
406}
407
408static void intel_dsi_get_config(struct intel_encoder *encoder,
409 struct intel_crtc_config *pipe_config)
410{
Shobhit Kumarf573de52014-07-30 20:32:37 +0530411 u32 pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300412 DRM_DEBUG_KMS("\n");
413
Shobhit Kumarf573de52014-07-30 20:32:37 +0530414 /*
415 * DPLL_MD is not used in case of DSI, reading will get some default value
416 * set dpll_md = 0
417 */
418 pipe_config->dpll_hw_state.dpll_md = 0;
419
420 pclk = vlv_get_dsi_pclk(encoder, pipe_config->pipe_bpp);
421 if (!pclk)
422 return;
423
424 pipe_config->adjusted_mode.crtc_clock = pclk;
425 pipe_config->port_clock = pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300426}
427
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000428static enum drm_mode_status
429intel_dsi_mode_valid(struct drm_connector *connector,
430 struct drm_display_mode *mode)
Jani Nikula4e646492013-08-27 15:12:20 +0300431{
432 struct intel_connector *intel_connector = to_intel_connector(connector);
433 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
434 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
435
436 DRM_DEBUG_KMS("\n");
437
438 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
439 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
440 return MODE_NO_DBLESCAN;
441 }
442
443 if (fixed_mode) {
444 if (mode->hdisplay > fixed_mode->hdisplay)
445 return MODE_PANEL;
446 if (mode->vdisplay > fixed_mode->vdisplay)
447 return MODE_PANEL;
448 }
449
450 return intel_dsi->dev.dev_ops->mode_valid(&intel_dsi->dev, mode);
451}
452
453/* return txclkesc cycles in terms of divider and duration in us */
454static u16 txclkesc(u32 divider, unsigned int us)
455{
456 switch (divider) {
457 case ESCAPE_CLOCK_DIVIDER_1:
458 default:
459 return 20 * us;
460 case ESCAPE_CLOCK_DIVIDER_2:
461 return 10 * us;
462 case ESCAPE_CLOCK_DIVIDER_4:
463 return 5 * us;
464 }
465}
466
467/* return pixels in terms of txbyteclkhs */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530468static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
469 u16 burst_mode_ratio)
Jani Nikula4e646492013-08-27 15:12:20 +0300470{
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530471 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200472 8 * 100), lane_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300473}
474
475static void set_dsi_timings(struct drm_encoder *encoder,
476 const struct drm_display_mode *mode)
477{
478 struct drm_device *dev = encoder->dev;
479 struct drm_i915_private *dev_priv = dev->dev_private;
480 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
481 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200482 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Jani Nikula4e646492013-08-27 15:12:20 +0300483 unsigned int bpp = intel_crtc->config.pipe_bpp;
484 unsigned int lane_count = intel_dsi->lane_count;
485
486 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
487
488 hactive = mode->hdisplay;
489 hfp = mode->hsync_start - mode->hdisplay;
490 hsync = mode->hsync_end - mode->hsync_start;
491 hbp = mode->htotal - mode->hsync_end;
492
493 vfp = mode->vsync_start - mode->vdisplay;
494 vsync = mode->vsync_end - mode->vsync_start;
495 vbp = mode->vtotal - mode->vsync_end;
496
497 /* horizontal values are in terms of high speed byte clock */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530498 hactive = txbyteclkhs(hactive, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200499 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530500 hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
501 hsync = txbyteclkhs(hsync, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200502 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530503 hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
Jani Nikula4e646492013-08-27 15:12:20 +0300504
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200505 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
506 I915_WRITE(MIPI_HFP_COUNT(port), hfp);
Jani Nikula4e646492013-08-27 15:12:20 +0300507
508 /* meaningful for video mode non-burst sync pulse mode only, can be zero
509 * for non-burst sync events and burst modes */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200510 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
511 I915_WRITE(MIPI_HBP_COUNT(port), hbp);
Jani Nikula4e646492013-08-27 15:12:20 +0300512
513 /* vertical values are in terms of lines */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200514 I915_WRITE(MIPI_VFP_COUNT(port), vfp);
515 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
516 I915_WRITE(MIPI_VBP_COUNT(port), vbp);
Jani Nikula4e646492013-08-27 15:12:20 +0300517}
518
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200519static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300520{
521 struct drm_encoder *encoder = &intel_encoder->base;
522 struct drm_device *dev = encoder->dev;
523 struct drm_i915_private *dev_priv = dev->dev_private;
524 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
525 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
526 struct drm_display_mode *adjusted_mode =
527 &intel_crtc->config.adjusted_mode;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200528 enum port port = intel_dsi_pipe_to_port(intel_crtc->pipe);
Jani Nikula4e646492013-08-27 15:12:20 +0300529 unsigned int bpp = intel_crtc->config.pipe_bpp;
530 u32 val, tmp;
531
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200532 DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
Jani Nikula4e646492013-08-27 15:12:20 +0300533
Jani Nikula4e646492013-08-27 15:12:20 +0300534 /* escape clock divider, 20MHz, shared for A and C. device ready must be
535 * off when doing this! txclkesc? */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200536 tmp = I915_READ(MIPI_CTRL(PORT_A));
Jani Nikula4e646492013-08-27 15:12:20 +0300537 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200538 I915_WRITE(MIPI_CTRL(PORT_A), tmp | ESCAPE_CLOCK_DIVIDER_1);
Jani Nikula4e646492013-08-27 15:12:20 +0300539
540 /* read request priority is per pipe */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200541 tmp = I915_READ(MIPI_CTRL(port));
Jani Nikula4e646492013-08-27 15:12:20 +0300542 tmp &= ~READ_REQUEST_PRIORITY_MASK;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200543 I915_WRITE(MIPI_CTRL(port), tmp | READ_REQUEST_PRIORITY_HIGH);
Jani Nikula4e646492013-08-27 15:12:20 +0300544
545 /* XXX: why here, why like this? handling in irq handler?! */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200546 I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
547 I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
Jani Nikula4e646492013-08-27 15:12:20 +0300548
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200549 I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
Jani Nikula4e646492013-08-27 15:12:20 +0300550
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200551 I915_WRITE(MIPI_DPI_RESOLUTION(port),
Jani Nikula4e646492013-08-27 15:12:20 +0300552 adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
553 adjusted_mode->hdisplay << HORIZONTAL_ADDRESS_SHIFT);
554
555 set_dsi_timings(encoder, adjusted_mode);
556
557 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
558 if (is_cmd_mode(intel_dsi)) {
559 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
560 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
561 } else {
562 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
563
564 /* XXX: cross-check bpp vs. pixel format? */
565 val |= intel_dsi->pixel_format;
566 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200567 I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300568
569 /* timeouts for recovery. one frame IIUC. if counter expires, EOT and
570 * stop state. */
571
572 /*
573 * In burst mode, value greater than one DPI line Time in byte clock
574 * (txbyteclkhs) To timeout this timer 1+ of the above said value is
575 * recommended.
576 *
577 * In non-burst mode, Value greater than one DPI frame time in byte
578 * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
579 * is recommended.
580 *
581 * In DBI only mode, value greater than one DBI frame time in byte
582 * clock(txbyteclkhs) To timeout this timer 1+ of the above said value
583 * is recommended.
584 */
585
586 if (is_vid_mode(intel_dsi) &&
587 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200588 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
Jani Nikula4e646492013-08-27 15:12:20 +0300589 txbyteclkhs(adjusted_mode->htotal, bpp,
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530590 intel_dsi->lane_count,
591 intel_dsi->burst_mode_ratio) + 1);
Jani Nikula4e646492013-08-27 15:12:20 +0300592 } else {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200593 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
Jani Nikula4e646492013-08-27 15:12:20 +0300594 txbyteclkhs(adjusted_mode->vtotal *
595 adjusted_mode->htotal,
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530596 bpp, intel_dsi->lane_count,
597 intel_dsi->burst_mode_ratio) + 1);
Jani Nikula4e646492013-08-27 15:12:20 +0300598 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200599 I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
600 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port), intel_dsi->turn_arnd_val);
601 I915_WRITE(MIPI_DEVICE_RESET_TIMER(port), intel_dsi->rst_timer_val);
Jani Nikula4e646492013-08-27 15:12:20 +0300602
603 /* dphy stuff */
604
605 /* in terms of low power clock */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200606 I915_WRITE(MIPI_INIT_COUNT(port), txclkesc(intel_dsi->escape_clk_div, 100));
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530607
608 val = 0;
609 if (intel_dsi->eotp_pkt == 0)
610 val |= EOT_DISABLE;
611
612 if (intel_dsi->clock_stop)
613 val |= CLOCKSTOP;
Jani Nikula4e646492013-08-27 15:12:20 +0300614
615 /* recovery disables */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200616 I915_WRITE(MIPI_EOT_DISABLE(port), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300617
Shobhit Kumarcf4dbd22014-04-14 11:18:25 +0530618 /* in terms of low power clock */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200619 I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
Shobhit Kumarcf4dbd22014-04-14 11:18:25 +0530620
Jani Nikula4e646492013-08-27 15:12:20 +0300621 /* in terms of txbyteclkhs. actual high to low switch +
622 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
623 *
624 * XXX: write MIPI_STOP_STATE_STALL?
625 */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200626 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
Daniel Vetter7f3de832014-07-30 22:34:27 +0200627 intel_dsi->hs_to_lp_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300628
629 /* XXX: low power clock equivalence in terms of byte clock. the number
630 * of byte clocks occupied in one low power clock. based on txbyteclkhs
631 * and txclkesc. txclkesc time / txbyteclk time * (105 +
632 * MIPI_STOP_STATE_STALL) / 105.???
633 */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200634 I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
Jani Nikula4e646492013-08-27 15:12:20 +0300635
636 /* the bw essential for transmitting 16 long packets containing 252
637 * bytes meant for dcs write memory command is programmed in this
638 * register in terms of byte clocks. based on dsi transfer rate and the
639 * number of lanes configured the time taken to transmit 16 long packets
640 * in a dsi stream varies. */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200641 I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
Jani Nikula4e646492013-08-27 15:12:20 +0300642
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200643 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
Shobhit Kumarf6da2842013-12-10 12:15:00 +0530644 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
645 intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
Jani Nikula4e646492013-08-27 15:12:20 +0300646
647 if (is_vid_mode(intel_dsi))
Shobhit Kumar24d9c402014-04-09 13:59:36 +0530648 /* Some panels might have resolution which is not a multiple of
649 * 64 like 1366 x 768. Enable RANDOM resolution support for such
650 * panels by default */
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200651 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
Daniel Vetter7f3de832014-07-30 22:34:27 +0200652 intel_dsi->video_frmt_cfg_bits |
653 intel_dsi->video_mode_format |
654 IP_TG_CONFIG |
655 RANDOM_DPI_DISPLAY_RESOLUTION);
Jani Nikula4e646492013-08-27 15:12:20 +0300656}
657
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200658static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
659{
660 DRM_DEBUG_KMS("\n");
661
662 intel_dsi_prepare(encoder);
663
664 vlv_enable_dsi_pll(encoder);
665}
666
Jani Nikula4e646492013-08-27 15:12:20 +0300667static enum drm_connector_status
668intel_dsi_detect(struct drm_connector *connector, bool force)
669{
670 struct intel_dsi *intel_dsi = intel_attached_dsi(connector);
Imre Deak671dedd2014-03-05 16:20:53 +0200671 struct intel_encoder *intel_encoder = &intel_dsi->base;
672 enum intel_display_power_domain power_domain;
673 enum drm_connector_status connector_status;
674 struct drm_i915_private *dev_priv = intel_encoder->base.dev->dev_private;
675
Jani Nikula4e646492013-08-27 15:12:20 +0300676 DRM_DEBUG_KMS("\n");
Imre Deak671dedd2014-03-05 16:20:53 +0200677 power_domain = intel_display_port_power_domain(intel_encoder);
678
679 intel_display_power_get(dev_priv, power_domain);
680 connector_status = intel_dsi->dev.dev_ops->detect(&intel_dsi->dev);
681 intel_display_power_put(dev_priv, power_domain);
682
683 return connector_status;
Jani Nikula4e646492013-08-27 15:12:20 +0300684}
685
686static int intel_dsi_get_modes(struct drm_connector *connector)
687{
688 struct intel_connector *intel_connector = to_intel_connector(connector);
689 struct drm_display_mode *mode;
690
691 DRM_DEBUG_KMS("\n");
692
693 if (!intel_connector->panel.fixed_mode) {
694 DRM_DEBUG_KMS("no fixed mode\n");
695 return 0;
696 }
697
698 mode = drm_mode_duplicate(connector->dev,
699 intel_connector->panel.fixed_mode);
700 if (!mode) {
701 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
702 return 0;
703 }
704
705 drm_mode_probed_add(connector, mode);
706 return 1;
707}
708
709static void intel_dsi_destroy(struct drm_connector *connector)
710{
711 struct intel_connector *intel_connector = to_intel_connector(connector);
712
713 DRM_DEBUG_KMS("\n");
714 intel_panel_fini(&intel_connector->panel);
Jani Nikula4e646492013-08-27 15:12:20 +0300715 drm_connector_cleanup(connector);
716 kfree(connector);
717}
718
719static const struct drm_encoder_funcs intel_dsi_funcs = {
720 .destroy = intel_encoder_destroy,
721};
722
723static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
724 .get_modes = intel_dsi_get_modes,
725 .mode_valid = intel_dsi_mode_valid,
726 .best_encoder = intel_best_encoder,
727};
728
729static const struct drm_connector_funcs intel_dsi_connector_funcs = {
730 .dpms = intel_connector_dpms,
731 .detect = intel_dsi_detect,
732 .destroy = intel_dsi_destroy,
733 .fill_modes = drm_helper_probe_single_connector_modes,
734};
735
Damien Lespiau4328633d2014-05-28 12:30:56 +0100736void intel_dsi_init(struct drm_device *dev)
Jani Nikula4e646492013-08-27 15:12:20 +0300737{
738 struct intel_dsi *intel_dsi;
739 struct intel_encoder *intel_encoder;
740 struct drm_encoder *encoder;
741 struct intel_connector *intel_connector;
742 struct drm_connector *connector;
743 struct drm_display_mode *fixed_mode = NULL;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530744 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300745 const struct intel_dsi_device *dsi;
746 unsigned int i;
747
748 DRM_DEBUG_KMS("\n");
749
Shobhit Kumar3e6bd012014-05-27 19:33:59 +0530750 /* There is no detection method for MIPI so rely on VBT */
751 if (!dev_priv->vbt.has_mipi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100752 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300753
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530754 if (IS_VALLEYVIEW(dev)) {
755 dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
756 } else {
757 DRM_ERROR("Unsupported Mipi device to reg base");
Christoph Jaeger868d6652014-06-13 21:51:22 +0200758 return;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530759 }
760
Jani Nikula4e646492013-08-27 15:12:20 +0300761 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
762 if (!intel_dsi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100763 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300764
765 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
766 if (!intel_connector) {
767 kfree(intel_dsi);
Damien Lespiau4328633d2014-05-28 12:30:56 +0100768 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300769 }
770
771 intel_encoder = &intel_dsi->base;
772 encoder = &intel_encoder->base;
773 intel_dsi->attached_connector = intel_connector;
774
Jani Nikula4e646492013-08-27 15:12:20 +0300775 connector = &intel_connector->base;
776
777 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
778
779 /* XXX: very likely not all of these are needed */
780 intel_encoder->hot_plug = intel_dsi_hot_plug;
781 intel_encoder->compute_config = intel_dsi_compute_config;
782 intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
783 intel_encoder->pre_enable = intel_dsi_pre_enable;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530784 intel_encoder->enable = intel_dsi_enable_nop;
Imre Deakc315faf2014-05-27 19:00:09 +0300785 intel_encoder->disable = intel_dsi_pre_disable;
Jani Nikula4e646492013-08-27 15:12:20 +0300786 intel_encoder->post_disable = intel_dsi_post_disable;
787 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
788 intel_encoder->get_config = intel_dsi_get_config;
789
790 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak4932e2c2014-02-11 17:12:48 +0200791 intel_connector->unregister = intel_connector_unregister;
Jani Nikula4e646492013-08-27 15:12:20 +0300792
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200793 /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
Jani Nikula17af40a2014-11-14 16:54:22 +0200794 if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200795 intel_encoder->crtc_mask = (1 << PIPE_A);
Jani Nikula17af40a2014-11-14 16:54:22 +0200796 intel_dsi->ports = (1 << PORT_A);
797 } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200798 intel_encoder->crtc_mask = (1 << PIPE_B);
Jani Nikula17af40a2014-11-14 16:54:22 +0200799 intel_dsi->ports = (1 << PORT_C);
800 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200801
Jani Nikula4e646492013-08-27 15:12:20 +0300802 for (i = 0; i < ARRAY_SIZE(intel_dsi_devices); i++) {
803 dsi = &intel_dsi_devices[i];
804 intel_dsi->dev = *dsi;
805
806 if (dsi->dev_ops->init(&intel_dsi->dev))
807 break;
808 }
809
810 if (i == ARRAY_SIZE(intel_dsi_devices)) {
811 DRM_DEBUG_KMS("no device found\n");
812 goto err;
813 }
814
815 intel_encoder->type = INTEL_OUTPUT_DSI;
Ville Syrjäläbc079e82014-03-03 16:15:28 +0200816 intel_encoder->cloneable = 0;
Jani Nikula4e646492013-08-27 15:12:20 +0300817 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
818 DRM_MODE_CONNECTOR_DSI);
819
820 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
821
822 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
823 connector->interlace_allowed = false;
824 connector->doublescan_allowed = false;
825
826 intel_connector_attach_encoder(intel_connector, intel_encoder);
827
Thomas Wood34ea3d32014-05-29 16:57:41 +0100828 drm_connector_register(connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300829
830 fixed_mode = dsi->dev_ops->get_modes(&intel_dsi->dev);
831 if (!fixed_mode) {
832 DRM_DEBUG_KMS("no fixed mode\n");
833 goto err;
834 }
835
836 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
Vandana Kannan4b6ed682014-02-11 14:26:36 +0530837 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
Jani Nikula4e646492013-08-27 15:12:20 +0300838
Damien Lespiau4328633d2014-05-28 12:30:56 +0100839 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300840
841err:
842 drm_encoder_cleanup(&intel_encoder->base);
843 kfree(intel_dsi);
844 kfree(intel_connector);
Jani Nikula4e646492013-08-27 15:12:20 +0300845}