blob: 96ea3f741a89e56354fe3a1014bade68849e543f [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>
Matt Roperc6f95f22015-01-22 16:50:32 -080027#include <drm/drm_atomic_helper.h>
Jani Nikula4e646492013-08-27 15:12:20 +030028#include <drm/drm_crtc.h>
29#include <drm/drm_edid.h>
30#include <drm/i915_drm.h>
Jani Nikula593e0622015-01-23 15:30:56 +020031#include <drm/drm_panel.h>
Jani Nikula7e9804f2015-01-16 14:27:23 +020032#include <drm/drm_mipi_dsi.h>
Jani Nikula4e646492013-08-27 15:12:20 +030033#include <linux/slab.h>
Shobhit Kumarfc45e822015-06-26 14:32:09 +053034#include <linux/gpio/consumer.h>
Jani Nikula4e646492013-08-27 15:12:20 +030035#include "i915_drv.h"
36#include "intel_drv.h"
37#include "intel_dsi.h"
Jani Nikula4e646492013-08-27 15:12:20 +030038
Jani Nikula593e0622015-01-23 15:30:56 +020039static const struct {
40 u16 panel_id;
41 struct drm_panel * (*init)(struct intel_dsi *intel_dsi, u16 panel_id);
42} intel_dsi_drivers[] = {
Shobhit Kumar2ab8b452014-05-23 21:35:27 +053043 {
44 .panel_id = MIPI_DSI_GENERIC_PANEL_ID,
Jani Nikula593e0622015-01-23 15:30:56 +020045 .init = vbt_panel_init,
Shobhit Kumar2ab8b452014-05-23 21:35:27 +053046 },
Jani Nikula4e646492013-08-27 15:12:20 +030047};
48
Jani Nikula7f6a6a42015-01-16 14:27:19 +020049static void wait_for_dsi_fifo_empty(struct intel_dsi *intel_dsi, enum port port)
Jani Nikula3b1808b2015-01-16 14:27:18 +020050{
51 struct drm_encoder *encoder = &intel_dsi->base.base;
52 struct drm_device *dev = encoder->dev;
53 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula3b1808b2015-01-16 14:27:18 +020054 u32 mask;
55
56 mask = LP_CTRL_FIFO_EMPTY | HS_CTRL_FIFO_EMPTY |
57 LP_DATA_FIFO_EMPTY | HS_DATA_FIFO_EMPTY;
58
59 if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & mask) == mask, 100))
60 DRM_ERROR("DPI FIFOs are not empty\n");
61}
62
Ville Syrjäläf0f59a02015-11-18 15:33:26 +020063static void write_data(struct drm_i915_private *dev_priv,
64 i915_reg_t reg,
Jani Nikula7e9804f2015-01-16 14:27:23 +020065 const u8 *data, u32 len)
66{
67 u32 i, j;
68
69 for (i = 0; i < len; i += 4) {
70 u32 val = 0;
71
72 for (j = 0; j < min_t(u32, len - i, 4); j++)
73 val |= *data++ << 8 * j;
74
75 I915_WRITE(reg, val);
76 }
77}
78
Ville Syrjäläf0f59a02015-11-18 15:33:26 +020079static void read_data(struct drm_i915_private *dev_priv,
80 i915_reg_t reg,
Jani Nikula7e9804f2015-01-16 14:27:23 +020081 u8 *data, u32 len)
82{
83 u32 i, j;
84
85 for (i = 0; i < len; i += 4) {
86 u32 val = I915_READ(reg);
87
88 for (j = 0; j < min_t(u32, len - i, 4); j++)
89 *data++ = val >> 8 * j;
90 }
91}
92
93static ssize_t intel_dsi_host_transfer(struct mipi_dsi_host *host,
94 const struct mipi_dsi_msg *msg)
95{
96 struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host);
97 struct drm_device *dev = intel_dsi_host->intel_dsi->base.base.dev;
98 struct drm_i915_private *dev_priv = dev->dev_private;
99 enum port port = intel_dsi_host->port;
100 struct mipi_dsi_packet packet;
101 ssize_t ret;
102 const u8 *header, *data;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200103 i915_reg_t data_reg, ctrl_reg;
104 u32 data_mask, ctrl_mask;
Jani Nikula7e9804f2015-01-16 14:27:23 +0200105
106 ret = mipi_dsi_create_packet(&packet, msg);
107 if (ret < 0)
108 return ret;
109
110 header = packet.header;
111 data = packet.payload;
112
113 if (msg->flags & MIPI_DSI_MSG_USE_LPM) {
114 data_reg = MIPI_LP_GEN_DATA(port);
115 data_mask = LP_DATA_FIFO_FULL;
116 ctrl_reg = MIPI_LP_GEN_CTRL(port);
117 ctrl_mask = LP_CTRL_FIFO_FULL;
118 } else {
119 data_reg = MIPI_HS_GEN_DATA(port);
120 data_mask = HS_DATA_FIFO_FULL;
121 ctrl_reg = MIPI_HS_GEN_CTRL(port);
122 ctrl_mask = HS_CTRL_FIFO_FULL;
123 }
124
125 /* note: this is never true for reads */
126 if (packet.payload_length) {
127
128 if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & data_mask) == 0, 50))
129 DRM_ERROR("Timeout waiting for HS/LP DATA FIFO !full\n");
130
131 write_data(dev_priv, data_reg, packet.payload,
132 packet.payload_length);
133 }
134
135 if (msg->rx_len) {
136 I915_WRITE(MIPI_INTR_STAT(port), GEN_READ_DATA_AVAIL);
137 }
138
139 if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & ctrl_mask) == 0, 50)) {
140 DRM_ERROR("Timeout waiting for HS/LP CTRL FIFO !full\n");
141 }
142
143 I915_WRITE(ctrl_reg, header[2] << 16 | header[1] << 8 | header[0]);
144
145 /* ->rx_len is set only for reads */
146 if (msg->rx_len) {
147 data_mask = GEN_READ_DATA_AVAIL;
148 if (wait_for((I915_READ(MIPI_INTR_STAT(port)) & data_mask) == data_mask, 50))
149 DRM_ERROR("Timeout waiting for read data.\n");
150
151 read_data(dev_priv, data_reg, msg->rx_buf, msg->rx_len);
152 }
153
154 /* XXX: fix for reads and writes */
155 return 4 + packet.payload_length;
156}
157
158static int intel_dsi_host_attach(struct mipi_dsi_host *host,
159 struct mipi_dsi_device *dsi)
160{
161 return 0;
162}
163
164static int intel_dsi_host_detach(struct mipi_dsi_host *host,
165 struct mipi_dsi_device *dsi)
166{
167 return 0;
168}
169
170static const struct mipi_dsi_host_ops intel_dsi_host_ops = {
171 .attach = intel_dsi_host_attach,
172 .detach = intel_dsi_host_detach,
173 .transfer = intel_dsi_host_transfer,
174};
175
176static struct intel_dsi_host *intel_dsi_host_init(struct intel_dsi *intel_dsi,
177 enum port port)
178{
179 struct intel_dsi_host *host;
180 struct mipi_dsi_device *device;
181
182 host = kzalloc(sizeof(*host), GFP_KERNEL);
183 if (!host)
184 return NULL;
185
186 host->base.ops = &intel_dsi_host_ops;
187 host->intel_dsi = intel_dsi;
188 host->port = port;
189
190 /*
191 * We should call mipi_dsi_host_register(&host->base) here, but we don't
192 * have a host->dev, and we don't have OF stuff either. So just use the
193 * dsi framework as a library and hope for the best. Create the dsi
194 * devices by ourselves here too. Need to be careful though, because we
195 * don't initialize any of the driver model devices here.
196 */
197 device = kzalloc(sizeof(*device), GFP_KERNEL);
198 if (!device) {
199 kfree(host);
200 return NULL;
201 }
202
203 device->host = &host->base;
204 host->device = device;
205
206 return host;
207}
208
Jani Nikulaa2581a92015-01-16 14:27:26 +0200209/*
210 * send a video mode command
211 *
212 * XXX: commands with data in MIPI_DPI_DATA?
213 */
214static int dpi_send_cmd(struct intel_dsi *intel_dsi, u32 cmd, bool hs,
215 enum port port)
216{
217 struct drm_encoder *encoder = &intel_dsi->base.base;
218 struct drm_device *dev = encoder->dev;
219 struct drm_i915_private *dev_priv = dev->dev_private;
220 u32 mask;
221
222 /* XXX: pipe, hs */
223 if (hs)
224 cmd &= ~DPI_LP_MODE;
225 else
226 cmd |= DPI_LP_MODE;
227
228 /* clear bit */
229 I915_WRITE(MIPI_INTR_STAT(port), SPL_PKT_SENT_INTERRUPT);
230
231 /* XXX: old code skips write if control unchanged */
232 if (cmd == I915_READ(MIPI_DPI_CONTROL(port)))
233 DRM_ERROR("Same special packet %02x twice in a row.\n", cmd);
234
235 I915_WRITE(MIPI_DPI_CONTROL(port), cmd);
236
237 mask = SPL_PKT_SENT_INTERRUPT;
238 if (wait_for((I915_READ(MIPI_INTR_STAT(port)) & mask) == mask, 100))
239 DRM_ERROR("Video mode command 0x%08x send failed.\n", cmd);
240
241 return 0;
242}
243
Shobhit Kumare9fe51c2013-12-10 12:14:55 +0530244static void band_gap_reset(struct drm_i915_private *dev_priv)
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +0300245{
Ville Syrjäläa5805162015-05-26 20:42:30 +0300246 mutex_lock(&dev_priv->sb_lock);
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +0300247
Shobhit Kumare9fe51c2013-12-10 12:14:55 +0530248 vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
249 vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
250 vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
251 udelay(150);
252 vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
253 vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +0300254
Ville Syrjäläa5805162015-05-26 20:42:30 +0300255 mutex_unlock(&dev_priv->sb_lock);
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +0300256}
257
Jani Nikula4e646492013-08-27 15:12:20 +0300258static inline bool is_vid_mode(struct intel_dsi *intel_dsi)
259{
Shobhit Kumardfba2e22014-04-14 11:18:24 +0530260 return intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE;
Jani Nikula4e646492013-08-27 15:12:20 +0300261}
262
263static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
264{
Shobhit Kumardfba2e22014-04-14 11:18:24 +0530265 return intel_dsi->operation_mode == INTEL_DSI_COMMAND_MODE;
Jani Nikula4e646492013-08-27 15:12:20 +0300266}
267
Jani Nikula4e646492013-08-27 15:12:20 +0300268static bool intel_dsi_compute_config(struct intel_encoder *encoder,
Jani Nikulaa65347b2015-11-27 12:21:46 +0200269 struct intel_crtc_state *pipe_config)
Jani Nikula4e646492013-08-27 15:12:20 +0300270{
Jani Nikula4d1de972016-03-18 17:05:42 +0200271 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300272 struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
273 base);
274 struct intel_connector *intel_connector = intel_dsi->attached_connector;
275 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Jani Nikulaa65347b2015-11-27 12:21:46 +0200276 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Jani Nikula4e646492013-08-27 15:12:20 +0300277
278 DRM_DEBUG_KMS("\n");
279
Jani Nikulaa65347b2015-11-27 12:21:46 +0200280 pipe_config->has_dsi_encoder = true;
281
Jani Nikula4e646492013-08-27 15:12:20 +0300282 if (fixed_mode)
283 intel_fixed_panel_mode(fixed_mode, adjusted_mode);
284
Shobhit Kumarf573de52014-07-30 20:32:37 +0530285 /* DSI uses short packets for sync events, so clear mode flags for DSI */
286 adjusted_mode->flags = 0;
287
Jani Nikula4d1de972016-03-18 17:05:42 +0200288 if (IS_BROXTON(dev_priv)) {
289 /* Dual link goes to DSI transcoder A. */
290 if (intel_dsi->ports == BIT(PORT_C))
291 pipe_config->cpu_transcoder = TRANSCODER_DSI_C;
292 else
293 pipe_config->cpu_transcoder = TRANSCODER_DSI_A;
294 }
295
Jani Nikula4e646492013-08-27 15:12:20 +0300296 return true;
297}
298
Shashank Sharma37ab0812015-09-01 19:41:42 +0530299static void bxt_dsi_device_ready(struct intel_encoder *encoder)
Gaurav K Singh5505a242014-12-04 10:58:47 +0530300{
Shashank Sharma37ab0812015-09-01 19:41:42 +0530301 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh5505a242014-12-04 10:58:47 +0530302 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Gaurav K Singh369602d2014-12-05 14:09:28 +0530303 enum port port;
Shashank Sharma37ab0812015-09-01 19:41:42 +0530304 u32 val;
Gaurav K Singh5505a242014-12-04 10:58:47 +0530305
Shashank Sharma37ab0812015-09-01 19:41:42 +0530306 DRM_DEBUG_KMS("\n");
Gaurav K Singha9da9bc2014-12-05 14:13:41 +0530307
Shashank Sharma37ab0812015-09-01 19:41:42 +0530308 /* Exit Low power state in 4 steps*/
Gaurav K Singh369602d2014-12-05 14:09:28 +0530309 for_each_dsi_port(port, intel_dsi->ports) {
Gaurav K Singh369602d2014-12-05 14:09:28 +0530310
Shashank Sharma37ab0812015-09-01 19:41:42 +0530311 /* 1. Enable MIPI PHY transparent latch */
312 val = I915_READ(BXT_MIPI_PORT_CTRL(port));
313 I915_WRITE(BXT_MIPI_PORT_CTRL(port), val | LP_OUTPUT_HOLD);
314 usleep_range(2000, 2500);
315
316 /* 2. Enter ULPS */
317 val = I915_READ(MIPI_DEVICE_READY(port));
318 val &= ~ULPS_STATE_MASK;
319 val |= (ULPS_STATE_ENTER | DEVICE_READY);
320 I915_WRITE(MIPI_DEVICE_READY(port), val);
321 usleep_range(2, 3);
322
323 /* 3. Exit ULPS */
324 val = I915_READ(MIPI_DEVICE_READY(port));
325 val &= ~ULPS_STATE_MASK;
326 val |= (ULPS_STATE_EXIT | DEVICE_READY);
327 I915_WRITE(MIPI_DEVICE_READY(port), val);
328 usleep_range(1000, 1500);
329
330 /* Clear ULPS and set device ready */
331 val = I915_READ(MIPI_DEVICE_READY(port));
332 val &= ~ULPS_STATE_MASK;
333 val |= DEVICE_READY;
334 I915_WRITE(MIPI_DEVICE_READY(port), val);
Gaurav K Singh369602d2014-12-05 14:09:28 +0530335 }
Gaurav K Singh5505a242014-12-04 10:58:47 +0530336}
337
Shashank Sharma37ab0812015-09-01 19:41:42 +0530338static void vlv_dsi_device_ready(struct intel_encoder *encoder)
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530339{
340 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530341 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
342 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530343 u32 val;
344
345 DRM_DEBUG_KMS("\n");
346
Ville Syrjäläa5805162015-05-26 20:42:30 +0300347 mutex_lock(&dev_priv->sb_lock);
Shobhit Kumar2095f9f2014-04-09 13:59:30 +0530348 /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
349 * needed everytime after power gate */
350 vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
Ville Syrjäläa5805162015-05-26 20:42:30 +0300351 mutex_unlock(&dev_priv->sb_lock);
Shobhit Kumar2095f9f2014-04-09 13:59:30 +0530352
353 /* bandgap reset is needed after everytime we do power gate */
354 band_gap_reset(dev_priv);
355
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530356 for_each_dsi_port(port, intel_dsi->ports) {
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530357
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530358 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
359 usleep_range(2500, 3000);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530360
Gaurav K Singhbf344e82014-12-07 16:13:54 +0530361 /* Enable MIPI PHY transparent latch
362 * Common bit for both MIPI Port A & MIPI Port C
363 * No similar bit in MIPI Port C reg
364 */
Shobhit Kumar4ba7d932015-02-05 17:08:45 +0530365 val = I915_READ(MIPI_PORT_CTRL(PORT_A));
Gaurav K Singhbf344e82014-12-07 16:13:54 +0530366 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD);
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530367 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530368
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530369 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
370 usleep_range(2500, 3000);
371
372 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
373 usleep_range(2500, 3000);
374 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530375}
Jani Nikula4e646492013-08-27 15:12:20 +0300376
Shashank Sharma37ab0812015-09-01 19:41:42 +0530377static void intel_dsi_device_ready(struct intel_encoder *encoder)
378{
379 struct drm_device *dev = encoder->base.dev;
380
Wayne Boyer666a4532015-12-09 12:29:35 -0800381 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Shashank Sharma37ab0812015-09-01 19:41:42 +0530382 vlv_dsi_device_ready(encoder);
383 else if (IS_BROXTON(dev))
384 bxt_dsi_device_ready(encoder);
385}
386
387static void intel_dsi_port_enable(struct intel_encoder *encoder)
388{
389 struct drm_device *dev = encoder->base.dev;
390 struct drm_i915_private *dev_priv = dev->dev_private;
391 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
392 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
393 enum port port;
Shashank Sharma37ab0812015-09-01 19:41:42 +0530394
395 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200396 u32 temp;
397
Shashank Sharma37ab0812015-09-01 19:41:42 +0530398 temp = I915_READ(VLV_CHICKEN_3);
399 temp &= ~PIXEL_OVERLAP_CNT_MASK |
400 intel_dsi->pixel_overlap <<
401 PIXEL_OVERLAP_CNT_SHIFT;
402 I915_WRITE(VLV_CHICKEN_3, temp);
403 }
404
405 for_each_dsi_port(port, intel_dsi->ports) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200406 i915_reg_t port_ctrl = IS_BROXTON(dev) ?
407 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
408 u32 temp;
Shashank Sharma37ab0812015-09-01 19:41:42 +0530409
410 temp = I915_READ(port_ctrl);
411
412 temp &= ~LANE_CONFIGURATION_MASK;
413 temp &= ~DUAL_LINK_MODE_MASK;
414
Jani Nikula701d25b2016-03-18 17:05:43 +0200415 if (intel_dsi->ports == (BIT(PORT_A) | BIT(PORT_C))) {
Shashank Sharma37ab0812015-09-01 19:41:42 +0530416 temp |= (intel_dsi->dual_link - 1)
417 << DUAL_LINK_MODE_SHIFT;
418 temp |= intel_crtc->pipe ?
419 LANE_CONFIGURATION_DUAL_LINK_B :
420 LANE_CONFIGURATION_DUAL_LINK_A;
421 }
422 /* assert ip_tg_enable signal */
423 I915_WRITE(port_ctrl, temp | DPI_ENABLE);
424 POSTING_READ(port_ctrl);
425 }
426}
427
428static void intel_dsi_port_disable(struct intel_encoder *encoder)
429{
430 struct drm_device *dev = encoder->base.dev;
431 struct drm_i915_private *dev_priv = dev->dev_private;
432 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
433 enum port port;
Shashank Sharma37ab0812015-09-01 19:41:42 +0530434
435 for_each_dsi_port(port, intel_dsi->ports) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200436 i915_reg_t port_ctrl = IS_BROXTON(dev) ?
437 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
438 u32 temp;
439
Shashank Sharma37ab0812015-09-01 19:41:42 +0530440 /* de-assert ip_tg_enable signal */
Shashank Sharmab389a452015-09-01 19:41:44 +0530441 temp = I915_READ(port_ctrl);
442 I915_WRITE(port_ctrl, temp & ~DPI_ENABLE);
443 POSTING_READ(port_ctrl);
Shashank Sharma37ab0812015-09-01 19:41:42 +0530444 }
445}
446
Jani Nikula4e646492013-08-27 15:12:20 +0300447static void intel_dsi_enable(struct intel_encoder *encoder)
448{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530449 struct drm_device *dev = encoder->base.dev;
450 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300451 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikula4934b652015-01-22 15:01:35 +0200452 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300453
454 DRM_DEBUG_KMS("\n");
455
Jani Nikula4934b652015-01-22 15:01:35 +0200456 if (is_cmd_mode(intel_dsi)) {
457 for_each_dsi_port(port, intel_dsi->ports)
458 I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
459 } else {
Jani Nikula4e646492013-08-27 15:12:20 +0300460 msleep(20); /* XXX */
Jani Nikulaf03e4172015-01-16 14:27:16 +0200461 for_each_dsi_port(port, intel_dsi->ports)
Jani Nikulaa2581a92015-01-16 14:27:26 +0200462 dpi_send_cmd(intel_dsi, TURN_ON, false, port);
Jani Nikula4e646492013-08-27 15:12:20 +0300463 msleep(100);
464
Jani Nikula593e0622015-01-23 15:30:56 +0200465 drm_panel_enable(intel_dsi->panel);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530466
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200467 for_each_dsi_port(port, intel_dsi->ports)
468 wait_for_dsi_fifo_empty(intel_dsi, port);
Shobhit Kumar13813082014-07-12 17:17:22 +0530469
Gaurav K Singh5505a242014-12-04 10:58:47 +0530470 intel_dsi_port_enable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300471 }
Shobhit Kumarb029e662015-06-26 14:32:10 +0530472
473 intel_panel_enable_backlight(intel_dsi->attached_connector);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530474}
Jani Nikula4e646492013-08-27 15:12:20 +0300475
Jani Nikulae3488e72015-11-27 12:21:44 +0200476static void intel_dsi_prepare(struct intel_encoder *intel_encoder);
477
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530478static void intel_dsi_pre_enable(struct intel_encoder *encoder)
479{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530480 struct drm_device *dev = encoder->base.dev;
481 struct drm_i915_private *dev_priv = dev->dev_private;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530482 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530483 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
484 enum pipe pipe = intel_crtc->pipe;
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200485 enum port port;
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530486 u32 tmp;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530487
488 DRM_DEBUG_KMS("\n");
489
Jani Nikulae3488e72015-11-27 12:21:44 +0200490 intel_enable_dsi_pll(encoder);
Ramalingam C58d4d322016-02-03 18:20:46 +0530491 intel_dsi_prepare(encoder);
Jani Nikulae3488e72015-11-27 12:21:44 +0200492
Shobhit Kumarfc45e822015-06-26 14:32:09 +0530493 /* Panel Enable over CRC PMIC */
494 if (intel_dsi->gpio_panel)
495 gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1);
496
497 msleep(intel_dsi->panel_on_delay);
498
Wayne Boyer666a4532015-12-09 12:29:35 -0800499 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Shashank Sharma37ab0812015-09-01 19:41:42 +0530500 /*
501 * Disable DPOunit clock gating, can stall pipe
502 * and we need DPLL REFA always enabled
503 */
504 tmp = I915_READ(DPLL(pipe));
505 tmp |= DPLL_REF_CLK_ENABLE_VLV;
506 I915_WRITE(DPLL(pipe), tmp);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530507
Shashank Sharma37ab0812015-09-01 19:41:42 +0530508 /* update the hw state for DPLL */
509 intel_crtc->config->dpll_hw_state.dpll =
510 DPLL_INTEGRATED_REF_CLK_VLV |
511 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530512
Shashank Sharma37ab0812015-09-01 19:41:42 +0530513 tmp = I915_READ(DSPCLK_GATE_D);
514 tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
515 I915_WRITE(DSPCLK_GATE_D, tmp);
516 }
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530517
518 /* put device in ready state */
519 intel_dsi_device_ready(encoder);
520
Jani Nikula593e0622015-01-23 15:30:56 +0200521 drm_panel_prepare(intel_dsi->panel);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530522
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200523 for_each_dsi_port(port, intel_dsi->ports)
524 wait_for_dsi_fifo_empty(intel_dsi, port);
Shobhit Kumar13813082014-07-12 17:17:22 +0530525
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530526 /* Enable port in pre-enable phase itself because as per hw team
527 * recommendation, port should be enabled befor plane & pipe */
528 intel_dsi_enable(encoder);
529}
530
531static void intel_dsi_enable_nop(struct intel_encoder *encoder)
532{
533 DRM_DEBUG_KMS("\n");
534
535 /* for DSI port enable has to be done before pipe
536 * and plane enable, so port enable is done in
537 * pre_enable phase itself unlike other encoders
538 */
Jani Nikula4e646492013-08-27 15:12:20 +0300539}
540
Imre Deakc315faf2014-05-27 19:00:09 +0300541static void intel_dsi_pre_disable(struct intel_encoder *encoder)
542{
543 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikulaf03e4172015-01-16 14:27:16 +0200544 enum port port;
Imre Deakc315faf2014-05-27 19:00:09 +0300545
546 DRM_DEBUG_KMS("\n");
547
Shobhit Kumarb029e662015-06-26 14:32:10 +0530548 intel_panel_disable_backlight(intel_dsi->attached_connector);
549
Imre Deakc315faf2014-05-27 19:00:09 +0300550 if (is_vid_mode(intel_dsi)) {
551 /* Send Shutdown command to the panel in LP mode */
Jani Nikulaf03e4172015-01-16 14:27:16 +0200552 for_each_dsi_port(port, intel_dsi->ports)
Jani Nikulaa2581a92015-01-16 14:27:26 +0200553 dpi_send_cmd(intel_dsi, SHUTDOWN, false, port);
Imre Deakc315faf2014-05-27 19:00:09 +0300554 msleep(10);
555 }
556}
557
Jani Nikula4e646492013-08-27 15:12:20 +0300558static void intel_dsi_disable(struct intel_encoder *encoder)
559{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530560 struct drm_device *dev = encoder->base.dev;
561 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300562 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530563 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300564 u32 temp;
565
566 DRM_DEBUG_KMS("\n");
567
Jani Nikula4e646492013-08-27 15:12:20 +0300568 if (is_vid_mode(intel_dsi)) {
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200569 for_each_dsi_port(port, intel_dsi->ports)
570 wait_for_dsi_fifo_empty(intel_dsi, port);
Shobhit Kumar13813082014-07-12 17:17:22 +0530571
Gaurav K Singh5505a242014-12-04 10:58:47 +0530572 intel_dsi_port_disable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300573 msleep(2);
574 }
575
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530576 for_each_dsi_port(port, intel_dsi->ports) {
577 /* Panel commands can be sent when clock is in LP11 */
578 I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530579
Shashank Sharmab389a452015-09-01 19:41:44 +0530580 intel_dsi_reset_clocks(encoder, port);
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530581 I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530582
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530583 temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
584 temp &= ~VID_MODE_FORMAT_MASK;
585 I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530586
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530587 I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
588 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530589 /* if disable packets are sent before sending shutdown packet then in
590 * some next enable sequence send turn on packet error is observed */
Jani Nikula593e0622015-01-23 15:30:56 +0200591 drm_panel_disable(intel_dsi->panel);
Shobhit Kumar13813082014-07-12 17:17:22 +0530592
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200593 for_each_dsi_port(port, intel_dsi->ports)
594 wait_for_dsi_fifo_empty(intel_dsi, port);
Jani Nikula4e646492013-08-27 15:12:20 +0300595}
596
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530597static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300598{
Shashank Sharmab389a452015-09-01 19:41:44 +0530599 struct drm_device *dev = encoder->base.dev;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530600 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530601 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
602 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530603
Jani Nikula4e646492013-08-27 15:12:20 +0300604 DRM_DEBUG_KMS("\n");
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530605 for_each_dsi_port(port, intel_dsi->ports) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200606 /* Common bit for both MIPI Port A & MIPI Port C on VLV/CHV */
607 i915_reg_t port_ctrl = IS_BROXTON(dev) ?
608 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(PORT_A);
609 u32 val;
ymohanmabe4fc042013-08-27 23:40:56 +0300610
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530611 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
612 ULPS_STATE_ENTER);
613 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530614
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530615 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
616 ULPS_STATE_EXIT);
617 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530618
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530619 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
620 ULPS_STATE_ENTER);
621 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530622
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530623 /* Wait till Clock lanes are in LP-00 state for MIPI Port A
624 * only. MIPI Port C has no similar bit for checking
625 */
Shashank Sharmab389a452015-09-01 19:41:44 +0530626 if (wait_for(((I915_READ(port_ctrl) & AFE_LATCHOUT)
627 == 0x00000), 30))
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530628 DRM_ERROR("DSI LP not going Low\n");
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530629
Shashank Sharmab389a452015-09-01 19:41:44 +0530630 /* Disable MIPI PHY transparent latch */
631 val = I915_READ(port_ctrl);
632 I915_WRITE(port_ctrl, val & ~LP_OUTPUT_HOLD);
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530633 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530634
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530635 I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
636 usleep_range(2000, 2500);
637 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530638
Shashank Sharmafe88fc62015-09-01 19:41:39 +0530639 intel_disable_dsi_pll(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300640}
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530641
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530642static void intel_dsi_post_disable(struct intel_encoder *encoder)
643{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530644 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530645 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
646
647 DRM_DEBUG_KMS("\n");
648
Imre Deakc315faf2014-05-27 19:00:09 +0300649 intel_dsi_disable(encoder);
650
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530651 intel_dsi_clear_device_ready(encoder);
652
Uma Shankard6e3af52016-02-18 13:49:26 +0200653 if (!IS_BROXTON(dev_priv)) {
654 u32 val;
655
656 val = I915_READ(DSPCLK_GATE_D);
657 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
658 I915_WRITE(DSPCLK_GATE_D, val);
659 }
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530660
Jani Nikula593e0622015-01-23 15:30:56 +0200661 drm_panel_unprepare(intel_dsi->panel);
Shobhit Kumardf38e652014-04-14 11:18:26 +0530662
663 msleep(intel_dsi->panel_off_delay);
664 msleep(intel_dsi->panel_pwr_cycle_delay);
Shobhit Kumarfc45e822015-06-26 14:32:09 +0530665
666 /* Panel Disable over CRC PMIC */
667 if (intel_dsi->gpio_panel)
668 gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530669}
Jani Nikula4e646492013-08-27 15:12:20 +0300670
671static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
672 enum pipe *pipe)
673{
674 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530675 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
676 struct drm_device *dev = encoder->base.dev;
Imre Deak6d129be2014-03-05 16:20:54 +0200677 enum intel_display_power_domain power_domain;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200678 enum port port;
Jani Nikula1dcec2f2016-03-15 21:51:11 +0200679 bool active = false;
Jani Nikula4e646492013-08-27 15:12:20 +0300680
681 DRM_DEBUG_KMS("\n");
682
Imre Deak6d129be2014-03-05 16:20:54 +0200683 power_domain = intel_display_port_power_domain(encoder);
Imre Deak3f3f42b2016-02-12 18:55:19 +0200684 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200685 return false;
686
Jani Nikula4e646492013-08-27 15:12:20 +0300687 /* XXX: this only works for one DSI output */
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530688 for_each_dsi_port(port, intel_dsi->ports) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200689 i915_reg_t ctrl_reg = IS_BROXTON(dev) ?
690 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
Jani Nikula1dcec2f2016-03-15 21:51:11 +0200691 bool enabled = I915_READ(ctrl_reg) & DPI_ENABLE;
Jani Nikula4e646492013-08-27 15:12:20 +0300692
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530693 /* Due to some hardware limitations on BYT, MIPI Port C DPI
694 * Enable bit does not get set. To check whether DSI Port C
695 * was enabled in BIOS, check the Pipe B enable bit
696 */
Wayne Boyer666a4532015-12-09 12:29:35 -0800697 if (IS_VALLEYVIEW(dev) && port == PORT_C)
Jani Nikula1dcec2f2016-03-15 21:51:11 +0200698 enabled = I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530699
Jani Nikula1dcec2f2016-03-15 21:51:11 +0200700 /* Try command mode if video mode not enabled */
701 if (!enabled) {
702 u32 tmp = I915_READ(MIPI_DSI_FUNC_PRG(port));
703 enabled = tmp & CMD_MODE_DATA_WIDTH_MASK;
Jani Nikula4e646492013-08-27 15:12:20 +0300704 }
Jani Nikula1dcec2f2016-03-15 21:51:11 +0200705
706 if (!enabled)
707 continue;
708
709 if (!(I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY))
710 continue;
711
Jani Nikula6b93e9c2016-03-15 21:51:12 +0200712 if (IS_BROXTON(dev_priv)) {
713 u32 tmp = I915_READ(MIPI_CTRL(port));
714 tmp &= BXT_PIPE_SELECT_MASK;
715 tmp >>= BXT_PIPE_SELECT_SHIFT;
716
717 if (WARN_ON(tmp > PIPE_C))
718 continue;
719
720 *pipe = tmp;
721 } else {
722 *pipe = port == PORT_A ? PIPE_A : PIPE_B;
723 }
724
Jani Nikula1dcec2f2016-03-15 21:51:11 +0200725 active = true;
726 break;
Jani Nikula4e646492013-08-27 15:12:20 +0300727 }
Jani Nikula1dcec2f2016-03-15 21:51:11 +0200728
Imre Deak3f3f42b2016-02-12 18:55:19 +0200729 intel_display_power_put(dev_priv, power_domain);
Jani Nikula4e646492013-08-27 15:12:20 +0300730
Jani Nikula1dcec2f2016-03-15 21:51:11 +0200731 return active;
Jani Nikula4e646492013-08-27 15:12:20 +0300732}
733
734static void intel_dsi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200735 struct intel_crtc_state *pipe_config)
Jani Nikula4e646492013-08-27 15:12:20 +0300736{
Jani Nikulad7d85d82016-01-08 12:45:39 +0200737 u32 pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300738 DRM_DEBUG_KMS("\n");
739
Jani Nikulaa65347b2015-11-27 12:21:46 +0200740 pipe_config->has_dsi_encoder = true;
741
Shobhit Kumarf573de52014-07-30 20:32:37 +0530742 /*
743 * DPLL_MD is not used in case of DSI, reading will get some default value
744 * set dpll_md = 0
745 */
746 pipe_config->dpll_hw_state.dpll_md = 0;
747
Jani Nikulad7d85d82016-01-08 12:45:39 +0200748 pclk = intel_dsi_get_pclk(encoder, pipe_config->pipe_bpp);
Shobhit Kumarf573de52014-07-30 20:32:37 +0530749 if (!pclk)
750 return;
751
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200752 pipe_config->base.adjusted_mode.crtc_clock = pclk;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530753 pipe_config->port_clock = pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300754}
755
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000756static enum drm_mode_status
757intel_dsi_mode_valid(struct drm_connector *connector,
758 struct drm_display_mode *mode)
Jani Nikula4e646492013-08-27 15:12:20 +0300759{
760 struct intel_connector *intel_connector = to_intel_connector(connector);
761 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Mika Kahola759a1e92015-08-18 14:37:01 +0300762 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
Jani Nikula4e646492013-08-27 15:12:20 +0300763
764 DRM_DEBUG_KMS("\n");
765
766 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
767 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
768 return MODE_NO_DBLESCAN;
769 }
770
771 if (fixed_mode) {
772 if (mode->hdisplay > fixed_mode->hdisplay)
773 return MODE_PANEL;
774 if (mode->vdisplay > fixed_mode->vdisplay)
775 return MODE_PANEL;
Mika Kahola759a1e92015-08-18 14:37:01 +0300776 if (fixed_mode->clock > max_dotclk)
777 return MODE_CLOCK_HIGH;
Jani Nikula4e646492013-08-27 15:12:20 +0300778 }
779
Jani Nikula36d21f42015-01-16 14:27:20 +0200780 return MODE_OK;
Jani Nikula4e646492013-08-27 15:12:20 +0300781}
782
783/* return txclkesc cycles in terms of divider and duration in us */
784static u16 txclkesc(u32 divider, unsigned int us)
785{
786 switch (divider) {
787 case ESCAPE_CLOCK_DIVIDER_1:
788 default:
789 return 20 * us;
790 case ESCAPE_CLOCK_DIVIDER_2:
791 return 10 * us;
792 case ESCAPE_CLOCK_DIVIDER_4:
793 return 5 * us;
794 }
795}
796
797/* return pixels in terms of txbyteclkhs */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530798static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
799 u16 burst_mode_ratio)
Jani Nikula4e646492013-08-27 15:12:20 +0300800{
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530801 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200802 8 * 100), lane_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300803}
804
805static void set_dsi_timings(struct drm_encoder *encoder,
Ville Syrjälä5e7234c2015-09-25 16:37:43 +0300806 const struct drm_display_mode *adjusted_mode)
Jani Nikula4e646492013-08-27 15:12:20 +0300807{
808 struct drm_device *dev = encoder->dev;
809 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300810 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530811 enum port port;
Jani Nikula1e78aa02016-03-16 12:21:40 +0200812 unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
Jani Nikula4e646492013-08-27 15:12:20 +0300813 unsigned int lane_count = intel_dsi->lane_count;
814
815 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
816
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300817 hactive = adjusted_mode->crtc_hdisplay;
818 hfp = adjusted_mode->crtc_hsync_start - adjusted_mode->crtc_hdisplay;
819 hsync = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
820 hbp = adjusted_mode->crtc_htotal - adjusted_mode->crtc_hsync_end;
Jani Nikula4e646492013-08-27 15:12:20 +0300821
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530822 if (intel_dsi->dual_link) {
823 hactive /= 2;
824 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
825 hactive += intel_dsi->pixel_overlap;
826 hfp /= 2;
827 hsync /= 2;
828 hbp /= 2;
829 }
830
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300831 vfp = adjusted_mode->crtc_vsync_start - adjusted_mode->crtc_vdisplay;
832 vsync = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
833 vbp = adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vsync_end;
Jani Nikula4e646492013-08-27 15:12:20 +0300834
835 /* horizontal values are in terms of high speed byte clock */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530836 hactive = txbyteclkhs(hactive, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200837 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530838 hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
839 hsync = txbyteclkhs(hsync, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200840 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530841 hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
Jani Nikula4e646492013-08-27 15:12:20 +0300842
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530843 for_each_dsi_port(port, intel_dsi->ports) {
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530844 if (IS_BROXTON(dev)) {
845 /*
846 * Program hdisplay and vdisplay on MIPI transcoder.
847 * This is different from calculated hactive and
848 * vactive, as they are calculated per channel basis,
849 * whereas these values should be based on resolution.
850 */
851 I915_WRITE(BXT_MIPI_TRANS_HACTIVE(port),
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300852 adjusted_mode->crtc_hdisplay);
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530853 I915_WRITE(BXT_MIPI_TRANS_VACTIVE(port),
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300854 adjusted_mode->crtc_vdisplay);
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530855 I915_WRITE(BXT_MIPI_TRANS_VTOTAL(port),
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300856 adjusted_mode->crtc_vtotal);
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530857 }
858
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530859 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
860 I915_WRITE(MIPI_HFP_COUNT(port), hfp);
Jani Nikula4e646492013-08-27 15:12:20 +0300861
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530862 /* meaningful for video mode non-burst sync pulse mode only,
863 * can be zero for non-burst sync events and burst modes */
864 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
865 I915_WRITE(MIPI_HBP_COUNT(port), hbp);
Jani Nikula4e646492013-08-27 15:12:20 +0300866
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530867 /* vertical values are in terms of lines */
868 I915_WRITE(MIPI_VFP_COUNT(port), vfp);
869 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
870 I915_WRITE(MIPI_VBP_COUNT(port), vbp);
871 }
Jani Nikula4e646492013-08-27 15:12:20 +0300872}
873
Jani Nikula1e78aa02016-03-16 12:21:40 +0200874static u32 pixel_format_to_reg(enum mipi_dsi_pixel_format fmt)
875{
876 switch (fmt) {
877 case MIPI_DSI_FMT_RGB888:
878 return VID_MODE_FORMAT_RGB888;
879 case MIPI_DSI_FMT_RGB666:
880 return VID_MODE_FORMAT_RGB666;
881 case MIPI_DSI_FMT_RGB666_PACKED:
882 return VID_MODE_FORMAT_RGB666_PACKED;
883 case MIPI_DSI_FMT_RGB565:
884 return VID_MODE_FORMAT_RGB565;
885 default:
886 MISSING_CASE(fmt);
887 return VID_MODE_FORMAT_RGB666;
888 }
889}
890
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200891static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300892{
893 struct drm_encoder *encoder = &intel_encoder->base;
894 struct drm_device *dev = encoder->dev;
895 struct drm_i915_private *dev_priv = dev->dev_private;
896 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
897 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +0300898 const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530899 enum port port;
Jani Nikula1e78aa02016-03-16 12:21:40 +0200900 unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
Jani Nikula4e646492013-08-27 15:12:20 +0300901 u32 val, tmp;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530902 u16 mode_hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300903
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200904 DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
Jani Nikula4e646492013-08-27 15:12:20 +0300905
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300906 mode_hdisplay = adjusted_mode->crtc_hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300907
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530908 if (intel_dsi->dual_link) {
909 mode_hdisplay /= 2;
910 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
911 mode_hdisplay += intel_dsi->pixel_overlap;
912 }
Jani Nikula4e646492013-08-27 15:12:20 +0300913
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530914 for_each_dsi_port(port, intel_dsi->ports) {
Wayne Boyer666a4532015-12-09 12:29:35 -0800915 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530916 /*
917 * escape clock divider, 20MHz, shared for A and C.
918 * device ready must be off when doing this! txclkesc?
919 */
920 tmp = I915_READ(MIPI_CTRL(PORT_A));
921 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
922 I915_WRITE(MIPI_CTRL(PORT_A), tmp |
923 ESCAPE_CLOCK_DIVIDER_1);
Jani Nikula4e646492013-08-27 15:12:20 +0300924
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530925 /* read request priority is per pipe */
926 tmp = I915_READ(MIPI_CTRL(port));
927 tmp &= ~READ_REQUEST_PRIORITY_MASK;
928 I915_WRITE(MIPI_CTRL(port), tmp |
929 READ_REQUEST_PRIORITY_HIGH);
930 } else if (IS_BROXTON(dev)) {
Deepak M56c48972015-12-09 20:14:04 +0530931 enum pipe pipe = intel_crtc->pipe;
932
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530933 tmp = I915_READ(MIPI_CTRL(port));
934 tmp &= ~BXT_PIPE_SELECT_MASK;
935
Deepak M56c48972015-12-09 20:14:04 +0530936 tmp |= BXT_PIPE_SELECT(pipe);
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530937 I915_WRITE(MIPI_CTRL(port), tmp);
938 }
Jani Nikula4e646492013-08-27 15:12:20 +0300939
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530940 /* XXX: why here, why like this? handling in irq handler?! */
941 I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
942 I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
943
944 I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
945
946 I915_WRITE(MIPI_DPI_RESOLUTION(port),
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300947 adjusted_mode->crtc_vdisplay << VERTICAL_ADDRESS_SHIFT |
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530948 mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
949 }
Jani Nikula4e646492013-08-27 15:12:20 +0300950
951 set_dsi_timings(encoder, adjusted_mode);
952
953 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
954 if (is_cmd_mode(intel_dsi)) {
955 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
956 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
957 } else {
958 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
Jani Nikula1e78aa02016-03-16 12:21:40 +0200959 val |= pixel_format_to_reg(intel_dsi->pixel_format);
Jani Nikula4e646492013-08-27 15:12:20 +0300960 }
Jani Nikula4e646492013-08-27 15:12:20 +0300961
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530962 tmp = 0;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530963 if (intel_dsi->eotp_pkt == 0)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530964 tmp |= EOT_DISABLE;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530965 if (intel_dsi->clock_stop)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530966 tmp |= CLOCKSTOP;
Jani Nikula4e646492013-08-27 15:12:20 +0300967
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530968 for_each_dsi_port(port, intel_dsi->ports) {
969 I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300970
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530971 /* timeouts for recovery. one frame IIUC. if counter expires,
972 * EOT and stop state. */
Shobhit Kumarcf4dbd22014-04-14 11:18:25 +0530973
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530974 /*
975 * In burst mode, value greater than one DPI line Time in byte
976 * clock (txbyteclkhs) To timeout this timer 1+ of the above
977 * said value is recommended.
978 *
979 * In non-burst mode, Value greater than one DPI frame time in
980 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
981 * said value is recommended.
982 *
983 * In DBI only mode, value greater than one DBI frame time in
984 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
985 * said value is recommended.
986 */
Jani Nikula4e646492013-08-27 15:12:20 +0300987
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530988 if (is_vid_mode(intel_dsi) &&
989 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
990 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300991 txbyteclkhs(adjusted_mode->crtc_htotal, bpp,
Ville Syrjälä124abe02015-09-08 13:40:45 +0300992 intel_dsi->lane_count,
993 intel_dsi->burst_mode_ratio) + 1);
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530994 } else {
995 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300996 txbyteclkhs(adjusted_mode->crtc_vtotal *
997 adjusted_mode->crtc_htotal,
Ville Syrjälä124abe02015-09-08 13:40:45 +0300998 bpp, intel_dsi->lane_count,
999 intel_dsi->burst_mode_ratio) + 1);
Gaurav K Singh24ee0e62014-12-05 14:24:21 +05301000 }
1001 I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
1002 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
1003 intel_dsi->turn_arnd_val);
1004 I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
1005 intel_dsi->rst_timer_val);
Jani Nikula4e646492013-08-27 15:12:20 +03001006
Gaurav K Singh24ee0e62014-12-05 14:24:21 +05301007 /* dphy stuff */
Jani Nikula4e646492013-08-27 15:12:20 +03001008
Gaurav K Singh24ee0e62014-12-05 14:24:21 +05301009 /* in terms of low power clock */
1010 I915_WRITE(MIPI_INIT_COUNT(port),
1011 txclkesc(intel_dsi->escape_clk_div, 100));
Jani Nikula4e646492013-08-27 15:12:20 +03001012
Shashank Sharmad2e08c02015-09-01 19:41:40 +05301013 if (IS_BROXTON(dev) && (!intel_dsi->dual_link)) {
1014 /*
1015 * BXT spec says write MIPI_INIT_COUNT for
1016 * both the ports, even if only one is
1017 * getting used. So write the other port
1018 * if not in dual link mode.
1019 */
1020 I915_WRITE(MIPI_INIT_COUNT(port ==
1021 PORT_A ? PORT_C : PORT_A),
1022 intel_dsi->init_count);
1023 }
Gaurav K Singh24ee0e62014-12-05 14:24:21 +05301024
1025 /* recovery disables */
Shobhit Kumar87c54d02015-02-03 12:17:35 +05301026 I915_WRITE(MIPI_EOT_DISABLE(port), tmp);
Gaurav K Singh24ee0e62014-12-05 14:24:21 +05301027
1028 /* in terms of low power clock */
1029 I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
1030
1031 /* in terms of txbyteclkhs. actual high to low switch +
1032 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
1033 *
1034 * XXX: write MIPI_STOP_STATE_STALL?
1035 */
1036 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
1037 intel_dsi->hs_to_lp_count);
1038
1039 /* XXX: low power clock equivalence in terms of byte clock.
1040 * the number of byte clocks occupied in one low power clock.
1041 * based on txbyteclkhs and txclkesc.
1042 * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
1043 * ) / 105.???
1044 */
1045 I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
1046
1047 /* the bw essential for transmitting 16 long packets containing
1048 * 252 bytes meant for dcs write memory command is programmed in
1049 * this register in terms of byte clocks. based on dsi transfer
1050 * rate and the number of lanes configured the time taken to
1051 * transmit 16 long packets in a dsi stream varies. */
1052 I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
1053
1054 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
1055 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
1056 intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
1057
1058 if (is_vid_mode(intel_dsi))
1059 /* Some panels might have resolution which is not a
1060 * multiple of 64 like 1366 x 768. Enable RANDOM
1061 * resolution support for such panels by default */
1062 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
1063 intel_dsi->video_frmt_cfg_bits |
1064 intel_dsi->video_mode_format |
1065 IP_TG_CONFIG |
1066 RANDOM_DPI_DISPLAY_RESOLUTION);
1067 }
Jani Nikula4e646492013-08-27 15:12:20 +03001068}
1069
1070static enum drm_connector_status
1071intel_dsi_detect(struct drm_connector *connector, bool force)
1072{
Jani Nikula36d21f42015-01-16 14:27:20 +02001073 return connector_status_connected;
Jani Nikula4e646492013-08-27 15:12:20 +03001074}
1075
1076static int intel_dsi_get_modes(struct drm_connector *connector)
1077{
1078 struct intel_connector *intel_connector = to_intel_connector(connector);
1079 struct drm_display_mode *mode;
1080
1081 DRM_DEBUG_KMS("\n");
1082
1083 if (!intel_connector->panel.fixed_mode) {
1084 DRM_DEBUG_KMS("no fixed mode\n");
1085 return 0;
1086 }
1087
1088 mode = drm_mode_duplicate(connector->dev,
1089 intel_connector->panel.fixed_mode);
1090 if (!mode) {
1091 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
1092 return 0;
1093 }
1094
1095 drm_mode_probed_add(connector, mode);
1096 return 1;
1097}
1098
Jani Nikula593e0622015-01-23 15:30:56 +02001099static void intel_dsi_connector_destroy(struct drm_connector *connector)
Jani Nikula4e646492013-08-27 15:12:20 +03001100{
1101 struct intel_connector *intel_connector = to_intel_connector(connector);
1102
1103 DRM_DEBUG_KMS("\n");
1104 intel_panel_fini(&intel_connector->panel);
Jani Nikula4e646492013-08-27 15:12:20 +03001105 drm_connector_cleanup(connector);
1106 kfree(connector);
1107}
1108
Jani Nikula593e0622015-01-23 15:30:56 +02001109static void intel_dsi_encoder_destroy(struct drm_encoder *encoder)
1110{
1111 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
1112
1113 if (intel_dsi->panel) {
1114 drm_panel_detach(intel_dsi->panel);
1115 /* XXX: Logically this call belongs in the panel driver. */
1116 drm_panel_remove(intel_dsi->panel);
1117 }
Shobhit Kumarfc45e822015-06-26 14:32:09 +05301118
1119 /* dispose of the gpios */
1120 if (intel_dsi->gpio_panel)
1121 gpiod_put(intel_dsi->gpio_panel);
1122
Jani Nikula593e0622015-01-23 15:30:56 +02001123 intel_encoder_destroy(encoder);
1124}
1125
Jani Nikula4e646492013-08-27 15:12:20 +03001126static const struct drm_encoder_funcs intel_dsi_funcs = {
Jani Nikula593e0622015-01-23 15:30:56 +02001127 .destroy = intel_dsi_encoder_destroy,
Jani Nikula4e646492013-08-27 15:12:20 +03001128};
1129
1130static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
1131 .get_modes = intel_dsi_get_modes,
1132 .mode_valid = intel_dsi_mode_valid,
1133 .best_encoder = intel_best_encoder,
1134};
1135
1136static const struct drm_connector_funcs intel_dsi_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02001137 .dpms = drm_atomic_helper_connector_dpms,
Jani Nikula4e646492013-08-27 15:12:20 +03001138 .detect = intel_dsi_detect,
Jani Nikula593e0622015-01-23 15:30:56 +02001139 .destroy = intel_dsi_connector_destroy,
Jani Nikula4e646492013-08-27 15:12:20 +03001140 .fill_modes = drm_helper_probe_single_connector_modes,
Matt Roper2545e4a2015-01-22 16:51:27 -08001141 .atomic_get_property = intel_connector_atomic_get_property,
Matt Roperc6f95f22015-01-22 16:50:32 -08001142 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02001143 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Jani Nikula4e646492013-08-27 15:12:20 +03001144};
1145
Damien Lespiau4328633d2014-05-28 12:30:56 +01001146void intel_dsi_init(struct drm_device *dev)
Jani Nikula4e646492013-08-27 15:12:20 +03001147{
1148 struct intel_dsi *intel_dsi;
1149 struct intel_encoder *intel_encoder;
1150 struct drm_encoder *encoder;
1151 struct intel_connector *intel_connector;
1152 struct drm_connector *connector;
Jani Nikula593e0622015-01-23 15:30:56 +02001153 struct drm_display_mode *scan, *fixed_mode = NULL;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +05301154 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula7e9804f2015-01-16 14:27:23 +02001155 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +03001156 unsigned int i;
1157
1158 DRM_DEBUG_KMS("\n");
1159
Shobhit Kumar3e6bd012014-05-27 19:33:59 +05301160 /* There is no detection method for MIPI so rely on VBT */
Jani Nikula7137aec2016-03-16 12:43:32 +02001161 if (!intel_bios_is_dsi_present(dev_priv, &port))
Damien Lespiau4328633d2014-05-28 12:30:56 +01001162 return;
Jani Nikula4e646492013-08-27 15:12:20 +03001163
Wayne Boyer666a4532015-12-09 12:29:35 -08001164 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +05301165 dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
Shashank Sharmac6c794a2016-03-22 12:01:50 +02001166 } else if (IS_BROXTON(dev)) {
1167 dev_priv->mipi_mmio_base = BXT_MIPI_BASE;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +05301168 } else {
1169 DRM_ERROR("Unsupported Mipi device to reg base");
Christoph Jaeger868d6652014-06-13 21:51:22 +02001170 return;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +05301171 }
1172
Jani Nikula4e646492013-08-27 15:12:20 +03001173 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
1174 if (!intel_dsi)
Damien Lespiau4328633d2014-05-28 12:30:56 +01001175 return;
Jani Nikula4e646492013-08-27 15:12:20 +03001176
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03001177 intel_connector = intel_connector_alloc();
Jani Nikula4e646492013-08-27 15:12:20 +03001178 if (!intel_connector) {
1179 kfree(intel_dsi);
Damien Lespiau4328633d2014-05-28 12:30:56 +01001180 return;
Jani Nikula4e646492013-08-27 15:12:20 +03001181 }
1182
1183 intel_encoder = &intel_dsi->base;
1184 encoder = &intel_encoder->base;
1185 intel_dsi->attached_connector = intel_connector;
1186
Jani Nikula4e646492013-08-27 15:12:20 +03001187 connector = &intel_connector->base;
1188
Ville Syrjälä13a3d912015-12-09 16:20:18 +02001189 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI,
1190 NULL);
Jani Nikula4e646492013-08-27 15:12:20 +03001191
Jani Nikula4e646492013-08-27 15:12:20 +03001192 intel_encoder->compute_config = intel_dsi_compute_config;
Jani Nikula4e646492013-08-27 15:12:20 +03001193 intel_encoder->pre_enable = intel_dsi_pre_enable;
Shobhit Kumar2634fd72014-04-09 13:59:31 +05301194 intel_encoder->enable = intel_dsi_enable_nop;
Imre Deakc315faf2014-05-27 19:00:09 +03001195 intel_encoder->disable = intel_dsi_pre_disable;
Jani Nikula4e646492013-08-27 15:12:20 +03001196 intel_encoder->post_disable = intel_dsi_post_disable;
1197 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
1198 intel_encoder->get_config = intel_dsi_get_config;
1199
1200 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak4932e2c2014-02-11 17:12:48 +02001201 intel_connector->unregister = intel_connector_unregister;
Jani Nikula4e646492013-08-27 15:12:20 +03001202
Jani Nikula2e85ab42016-03-18 17:05:44 +02001203 /*
1204 * On BYT/CHV, pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI
1205 * port C. BXT isn't limited like this.
1206 */
1207 if (IS_BROXTON(dev_priv))
1208 intel_encoder->crtc_mask = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C);
1209 else if (port == PORT_A)
Jani Nikula701d25b2016-03-18 17:05:43 +02001210 intel_encoder->crtc_mask = BIT(PIPE_A);
Jani Nikula7137aec2016-03-16 12:43:32 +02001211 else
Jani Nikula701d25b2016-03-18 17:05:43 +02001212 intel_encoder->crtc_mask = BIT(PIPE_B);
Jani Nikulae7d7cad2014-11-14 16:54:21 +02001213
Gaurav K Singh82425782015-08-03 15:45:32 +05301214 if (dev_priv->vbt.dsi.config->dual_link)
Jani Nikula701d25b2016-03-18 17:05:43 +02001215 intel_dsi->ports = BIT(PORT_A) | BIT(PORT_C);
Jani Nikula7137aec2016-03-16 12:43:32 +02001216 else
Jani Nikula701d25b2016-03-18 17:05:43 +02001217 intel_dsi->ports = BIT(port);
Gaurav K Singh82425782015-08-03 15:45:32 +05301218
Jani Nikula7e9804f2015-01-16 14:27:23 +02001219 /* Create a DSI host (and a device) for each port. */
1220 for_each_dsi_port(port, intel_dsi->ports) {
1221 struct intel_dsi_host *host;
1222
1223 host = intel_dsi_host_init(intel_dsi, port);
1224 if (!host)
1225 goto err;
1226
1227 intel_dsi->dsi_hosts[port] = host;
1228 }
1229
Jani Nikula593e0622015-01-23 15:30:56 +02001230 for (i = 0; i < ARRAY_SIZE(intel_dsi_drivers); i++) {
1231 intel_dsi->panel = intel_dsi_drivers[i].init(intel_dsi,
1232 intel_dsi_drivers[i].panel_id);
1233 if (intel_dsi->panel)
Jani Nikula4e646492013-08-27 15:12:20 +03001234 break;
1235 }
1236
Jani Nikula593e0622015-01-23 15:30:56 +02001237 if (!intel_dsi->panel) {
Jani Nikula4e646492013-08-27 15:12:20 +03001238 DRM_DEBUG_KMS("no device found\n");
1239 goto err;
1240 }
1241
Shobhit Kumarfc45e822015-06-26 14:32:09 +05301242 /*
1243 * In case of BYT with CRC PMIC, we need to use GPIO for
1244 * Panel control.
1245 */
1246 if (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) {
1247 intel_dsi->gpio_panel =
1248 gpiod_get(dev->dev, "panel", GPIOD_OUT_HIGH);
1249
1250 if (IS_ERR(intel_dsi->gpio_panel)) {
1251 DRM_ERROR("Failed to own gpio for panel control\n");
1252 intel_dsi->gpio_panel = NULL;
1253 }
1254 }
1255
Jani Nikula4e646492013-08-27 15:12:20 +03001256 intel_encoder->type = INTEL_OUTPUT_DSI;
Ville Syrjäläbc079e82014-03-03 16:15:28 +02001257 intel_encoder->cloneable = 0;
Jani Nikula4e646492013-08-27 15:12:20 +03001258 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
1259 DRM_MODE_CONNECTOR_DSI);
1260
1261 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
1262
1263 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
1264 connector->interlace_allowed = false;
1265 connector->doublescan_allowed = false;
1266
1267 intel_connector_attach_encoder(intel_connector, intel_encoder);
1268
Thomas Wood34ea3d32014-05-29 16:57:41 +01001269 drm_connector_register(connector);
Jani Nikula4e646492013-08-27 15:12:20 +03001270
Jani Nikula593e0622015-01-23 15:30:56 +02001271 drm_panel_attach(intel_dsi->panel, connector);
1272
1273 mutex_lock(&dev->mode_config.mutex);
1274 drm_panel_get_modes(intel_dsi->panel);
1275 list_for_each_entry(scan, &connector->probed_modes, head) {
1276 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
1277 fixed_mode = drm_mode_duplicate(dev, scan);
1278 break;
1279 }
1280 }
1281 mutex_unlock(&dev->mode_config.mutex);
1282
Jani Nikula4e646492013-08-27 15:12:20 +03001283 if (!fixed_mode) {
1284 DRM_DEBUG_KMS("no fixed mode\n");
1285 goto err;
1286 }
1287
Vandana Kannan4b6ed682014-02-11 14:26:36 +05301288 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
Shobhit Kumarb029e662015-06-26 14:32:10 +05301289 intel_panel_setup_backlight(connector, INVALID_PIPE);
Jani Nikula4e646492013-08-27 15:12:20 +03001290
Damien Lespiau4328633d2014-05-28 12:30:56 +01001291 return;
Jani Nikula4e646492013-08-27 15:12:20 +03001292
1293err:
1294 drm_encoder_cleanup(&intel_encoder->base);
1295 kfree(intel_dsi);
1296 kfree(intel_connector);
Jani Nikula4e646492013-08-27 15:12:20 +03001297}