blob: fcd746c55abd7736a47494748ede563f88eda5f2 [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{
271 struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
272 base);
273 struct intel_connector *intel_connector = intel_dsi->attached_connector;
274 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Jani Nikulaa65347b2015-11-27 12:21:46 +0200275 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Jani Nikula4e646492013-08-27 15:12:20 +0300276
277 DRM_DEBUG_KMS("\n");
278
Jani Nikulaa65347b2015-11-27 12:21:46 +0200279 pipe_config->has_dsi_encoder = true;
280
Jani Nikula4e646492013-08-27 15:12:20 +0300281 if (fixed_mode)
282 intel_fixed_panel_mode(fixed_mode, adjusted_mode);
283
Shobhit Kumarf573de52014-07-30 20:32:37 +0530284 /* DSI uses short packets for sync events, so clear mode flags for DSI */
285 adjusted_mode->flags = 0;
286
Jani Nikula4e646492013-08-27 15:12:20 +0300287 return true;
288}
289
Shashank Sharma37ab0812015-09-01 19:41:42 +0530290static void bxt_dsi_device_ready(struct intel_encoder *encoder)
Gaurav K Singh5505a242014-12-04 10:58:47 +0530291{
Shashank Sharma37ab0812015-09-01 19:41:42 +0530292 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh5505a242014-12-04 10:58:47 +0530293 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Gaurav K Singh369602d2014-12-05 14:09:28 +0530294 enum port port;
Shashank Sharma37ab0812015-09-01 19:41:42 +0530295 u32 val;
Gaurav K Singh5505a242014-12-04 10:58:47 +0530296
Shashank Sharma37ab0812015-09-01 19:41:42 +0530297 DRM_DEBUG_KMS("\n");
Gaurav K Singha9da9bc2014-12-05 14:13:41 +0530298
Shashank Sharma37ab0812015-09-01 19:41:42 +0530299 /* Exit Low power state in 4 steps*/
Gaurav K Singh369602d2014-12-05 14:09:28 +0530300 for_each_dsi_port(port, intel_dsi->ports) {
Gaurav K Singh369602d2014-12-05 14:09:28 +0530301
Shashank Sharma37ab0812015-09-01 19:41:42 +0530302 /* 1. Enable MIPI PHY transparent latch */
303 val = I915_READ(BXT_MIPI_PORT_CTRL(port));
304 I915_WRITE(BXT_MIPI_PORT_CTRL(port), val | LP_OUTPUT_HOLD);
305 usleep_range(2000, 2500);
306
307 /* 2. Enter ULPS */
308 val = I915_READ(MIPI_DEVICE_READY(port));
309 val &= ~ULPS_STATE_MASK;
310 val |= (ULPS_STATE_ENTER | DEVICE_READY);
311 I915_WRITE(MIPI_DEVICE_READY(port), val);
312 usleep_range(2, 3);
313
314 /* 3. Exit ULPS */
315 val = I915_READ(MIPI_DEVICE_READY(port));
316 val &= ~ULPS_STATE_MASK;
317 val |= (ULPS_STATE_EXIT | DEVICE_READY);
318 I915_WRITE(MIPI_DEVICE_READY(port), val);
319 usleep_range(1000, 1500);
320
321 /* Clear ULPS and set device ready */
322 val = I915_READ(MIPI_DEVICE_READY(port));
323 val &= ~ULPS_STATE_MASK;
324 val |= DEVICE_READY;
325 I915_WRITE(MIPI_DEVICE_READY(port), val);
Gaurav K Singh369602d2014-12-05 14:09:28 +0530326 }
Gaurav K Singh5505a242014-12-04 10:58:47 +0530327}
328
Shashank Sharma37ab0812015-09-01 19:41:42 +0530329static void vlv_dsi_device_ready(struct intel_encoder *encoder)
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530330{
331 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530332 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
333 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530334 u32 val;
335
336 DRM_DEBUG_KMS("\n");
337
Ville Syrjäläa5805162015-05-26 20:42:30 +0300338 mutex_lock(&dev_priv->sb_lock);
Shobhit Kumar2095f9f2014-04-09 13:59:30 +0530339 /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
340 * needed everytime after power gate */
341 vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
Ville Syrjäläa5805162015-05-26 20:42:30 +0300342 mutex_unlock(&dev_priv->sb_lock);
Shobhit Kumar2095f9f2014-04-09 13:59:30 +0530343
344 /* bandgap reset is needed after everytime we do power gate */
345 band_gap_reset(dev_priv);
346
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530347 for_each_dsi_port(port, intel_dsi->ports) {
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530348
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530349 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
350 usleep_range(2500, 3000);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530351
Gaurav K Singhbf344e82014-12-07 16:13:54 +0530352 /* Enable MIPI PHY transparent latch
353 * Common bit for both MIPI Port A & MIPI Port C
354 * No similar bit in MIPI Port C reg
355 */
Shobhit Kumar4ba7d932015-02-05 17:08:45 +0530356 val = I915_READ(MIPI_PORT_CTRL(PORT_A));
Gaurav K Singhbf344e82014-12-07 16:13:54 +0530357 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD);
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530358 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530359
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530360 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
361 usleep_range(2500, 3000);
362
363 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
364 usleep_range(2500, 3000);
365 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530366}
Jani Nikula4e646492013-08-27 15:12:20 +0300367
Shashank Sharma37ab0812015-09-01 19:41:42 +0530368static void intel_dsi_device_ready(struct intel_encoder *encoder)
369{
370 struct drm_device *dev = encoder->base.dev;
371
Wayne Boyer666a4532015-12-09 12:29:35 -0800372 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Shashank Sharma37ab0812015-09-01 19:41:42 +0530373 vlv_dsi_device_ready(encoder);
374 else if (IS_BROXTON(dev))
375 bxt_dsi_device_ready(encoder);
376}
377
378static void intel_dsi_port_enable(struct intel_encoder *encoder)
379{
380 struct drm_device *dev = encoder->base.dev;
381 struct drm_i915_private *dev_priv = dev->dev_private;
382 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
383 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
384 enum port port;
Shashank Sharma37ab0812015-09-01 19:41:42 +0530385
386 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200387 u32 temp;
388
Shashank Sharma37ab0812015-09-01 19:41:42 +0530389 temp = I915_READ(VLV_CHICKEN_3);
390 temp &= ~PIXEL_OVERLAP_CNT_MASK |
391 intel_dsi->pixel_overlap <<
392 PIXEL_OVERLAP_CNT_SHIFT;
393 I915_WRITE(VLV_CHICKEN_3, temp);
394 }
395
396 for_each_dsi_port(port, intel_dsi->ports) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200397 i915_reg_t port_ctrl = IS_BROXTON(dev) ?
398 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
399 u32 temp;
Shashank Sharma37ab0812015-09-01 19:41:42 +0530400
401 temp = I915_READ(port_ctrl);
402
403 temp &= ~LANE_CONFIGURATION_MASK;
404 temp &= ~DUAL_LINK_MODE_MASK;
405
406 if (intel_dsi->ports == ((1 << PORT_A) | (1 << PORT_C))) {
407 temp |= (intel_dsi->dual_link - 1)
408 << DUAL_LINK_MODE_SHIFT;
409 temp |= intel_crtc->pipe ?
410 LANE_CONFIGURATION_DUAL_LINK_B :
411 LANE_CONFIGURATION_DUAL_LINK_A;
412 }
413 /* assert ip_tg_enable signal */
414 I915_WRITE(port_ctrl, temp | DPI_ENABLE);
415 POSTING_READ(port_ctrl);
416 }
417}
418
419static void intel_dsi_port_disable(struct intel_encoder *encoder)
420{
421 struct drm_device *dev = encoder->base.dev;
422 struct drm_i915_private *dev_priv = dev->dev_private;
423 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
424 enum port port;
Shashank Sharma37ab0812015-09-01 19:41:42 +0530425
426 for_each_dsi_port(port, intel_dsi->ports) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200427 i915_reg_t port_ctrl = IS_BROXTON(dev) ?
428 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
429 u32 temp;
430
Shashank Sharma37ab0812015-09-01 19:41:42 +0530431 /* de-assert ip_tg_enable signal */
Shashank Sharmab389a452015-09-01 19:41:44 +0530432 temp = I915_READ(port_ctrl);
433 I915_WRITE(port_ctrl, temp & ~DPI_ENABLE);
434 POSTING_READ(port_ctrl);
Shashank Sharma37ab0812015-09-01 19:41:42 +0530435 }
436}
437
Jani Nikula4e646492013-08-27 15:12:20 +0300438static void intel_dsi_enable(struct intel_encoder *encoder)
439{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530440 struct drm_device *dev = encoder->base.dev;
441 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300442 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikula4934b652015-01-22 15:01:35 +0200443 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300444
445 DRM_DEBUG_KMS("\n");
446
Jani Nikula4934b652015-01-22 15:01:35 +0200447 if (is_cmd_mode(intel_dsi)) {
448 for_each_dsi_port(port, intel_dsi->ports)
449 I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
450 } else {
Jani Nikula4e646492013-08-27 15:12:20 +0300451 msleep(20); /* XXX */
Jani Nikulaf03e4172015-01-16 14:27:16 +0200452 for_each_dsi_port(port, intel_dsi->ports)
Jani Nikulaa2581a92015-01-16 14:27:26 +0200453 dpi_send_cmd(intel_dsi, TURN_ON, false, port);
Jani Nikula4e646492013-08-27 15:12:20 +0300454 msleep(100);
455
Jani Nikula593e0622015-01-23 15:30:56 +0200456 drm_panel_enable(intel_dsi->panel);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530457
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200458 for_each_dsi_port(port, intel_dsi->ports)
459 wait_for_dsi_fifo_empty(intel_dsi, port);
Shobhit Kumar13813082014-07-12 17:17:22 +0530460
Gaurav K Singh5505a242014-12-04 10:58:47 +0530461 intel_dsi_port_enable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300462 }
Shobhit Kumarb029e662015-06-26 14:32:10 +0530463
464 intel_panel_enable_backlight(intel_dsi->attached_connector);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530465}
Jani Nikula4e646492013-08-27 15:12:20 +0300466
Jani Nikulae3488e72015-11-27 12:21:44 +0200467static void intel_dsi_prepare(struct intel_encoder *intel_encoder);
468
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530469static void intel_dsi_pre_enable(struct intel_encoder *encoder)
470{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530471 struct drm_device *dev = encoder->base.dev;
472 struct drm_i915_private *dev_priv = dev->dev_private;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530473 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530474 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
475 enum pipe pipe = intel_crtc->pipe;
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200476 enum port port;
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530477 u32 tmp;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530478
479 DRM_DEBUG_KMS("\n");
480
Jani Nikulae3488e72015-11-27 12:21:44 +0200481 intel_enable_dsi_pll(encoder);
Ramalingam C58d4d322016-02-03 18:20:46 +0530482 intel_dsi_prepare(encoder);
Jani Nikulae3488e72015-11-27 12:21:44 +0200483
Shobhit Kumarfc45e822015-06-26 14:32:09 +0530484 /* Panel Enable over CRC PMIC */
485 if (intel_dsi->gpio_panel)
486 gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1);
487
488 msleep(intel_dsi->panel_on_delay);
489
Wayne Boyer666a4532015-12-09 12:29:35 -0800490 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Shashank Sharma37ab0812015-09-01 19:41:42 +0530491 /*
492 * Disable DPOunit clock gating, can stall pipe
493 * and we need DPLL REFA always enabled
494 */
495 tmp = I915_READ(DPLL(pipe));
496 tmp |= DPLL_REF_CLK_ENABLE_VLV;
497 I915_WRITE(DPLL(pipe), tmp);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530498
Shashank Sharma37ab0812015-09-01 19:41:42 +0530499 /* update the hw state for DPLL */
500 intel_crtc->config->dpll_hw_state.dpll =
501 DPLL_INTEGRATED_REF_CLK_VLV |
502 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530503
Shashank Sharma37ab0812015-09-01 19:41:42 +0530504 tmp = I915_READ(DSPCLK_GATE_D);
505 tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
506 I915_WRITE(DSPCLK_GATE_D, tmp);
507 }
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530508
509 /* put device in ready state */
510 intel_dsi_device_ready(encoder);
511
Jani Nikula593e0622015-01-23 15:30:56 +0200512 drm_panel_prepare(intel_dsi->panel);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530513
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200514 for_each_dsi_port(port, intel_dsi->ports)
515 wait_for_dsi_fifo_empty(intel_dsi, port);
Shobhit Kumar13813082014-07-12 17:17:22 +0530516
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530517 /* Enable port in pre-enable phase itself because as per hw team
518 * recommendation, port should be enabled befor plane & pipe */
519 intel_dsi_enable(encoder);
520}
521
522static void intel_dsi_enable_nop(struct intel_encoder *encoder)
523{
524 DRM_DEBUG_KMS("\n");
525
526 /* for DSI port enable has to be done before pipe
527 * and plane enable, so port enable is done in
528 * pre_enable phase itself unlike other encoders
529 */
Jani Nikula4e646492013-08-27 15:12:20 +0300530}
531
Imre Deakc315faf2014-05-27 19:00:09 +0300532static void intel_dsi_pre_disable(struct intel_encoder *encoder)
533{
534 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikulaf03e4172015-01-16 14:27:16 +0200535 enum port port;
Imre Deakc315faf2014-05-27 19:00:09 +0300536
537 DRM_DEBUG_KMS("\n");
538
Shobhit Kumarb029e662015-06-26 14:32:10 +0530539 intel_panel_disable_backlight(intel_dsi->attached_connector);
540
Imre Deakc315faf2014-05-27 19:00:09 +0300541 if (is_vid_mode(intel_dsi)) {
542 /* Send Shutdown command to the panel in LP mode */
Jani Nikulaf03e4172015-01-16 14:27:16 +0200543 for_each_dsi_port(port, intel_dsi->ports)
Jani Nikulaa2581a92015-01-16 14:27:26 +0200544 dpi_send_cmd(intel_dsi, SHUTDOWN, false, port);
Imre Deakc315faf2014-05-27 19:00:09 +0300545 msleep(10);
546 }
547}
548
Jani Nikula4e646492013-08-27 15:12:20 +0300549static void intel_dsi_disable(struct intel_encoder *encoder)
550{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530551 struct drm_device *dev = encoder->base.dev;
552 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300553 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530554 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300555 u32 temp;
556
557 DRM_DEBUG_KMS("\n");
558
Jani Nikula4e646492013-08-27 15:12:20 +0300559 if (is_vid_mode(intel_dsi)) {
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200560 for_each_dsi_port(port, intel_dsi->ports)
561 wait_for_dsi_fifo_empty(intel_dsi, port);
Shobhit Kumar13813082014-07-12 17:17:22 +0530562
Gaurav K Singh5505a242014-12-04 10:58:47 +0530563 intel_dsi_port_disable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300564 msleep(2);
565 }
566
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530567 for_each_dsi_port(port, intel_dsi->ports) {
568 /* Panel commands can be sent when clock is in LP11 */
569 I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530570
Shashank Sharmab389a452015-09-01 19:41:44 +0530571 intel_dsi_reset_clocks(encoder, port);
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530572 I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530573
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530574 temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
575 temp &= ~VID_MODE_FORMAT_MASK;
576 I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530577
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530578 I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
579 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530580 /* if disable packets are sent before sending shutdown packet then in
581 * some next enable sequence send turn on packet error is observed */
Jani Nikula593e0622015-01-23 15:30:56 +0200582 drm_panel_disable(intel_dsi->panel);
Shobhit Kumar13813082014-07-12 17:17:22 +0530583
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200584 for_each_dsi_port(port, intel_dsi->ports)
585 wait_for_dsi_fifo_empty(intel_dsi, port);
Jani Nikula4e646492013-08-27 15:12:20 +0300586}
587
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530588static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300589{
Shashank Sharmab389a452015-09-01 19:41:44 +0530590 struct drm_device *dev = encoder->base.dev;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530591 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530592 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
593 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530594
Jani Nikula4e646492013-08-27 15:12:20 +0300595 DRM_DEBUG_KMS("\n");
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530596 for_each_dsi_port(port, intel_dsi->ports) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200597 /* Common bit for both MIPI Port A & MIPI Port C on VLV/CHV */
598 i915_reg_t port_ctrl = IS_BROXTON(dev) ?
599 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(PORT_A);
600 u32 val;
ymohanmabe4fc042013-08-27 23:40:56 +0300601
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530602 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
603 ULPS_STATE_ENTER);
604 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530605
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530606 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
607 ULPS_STATE_EXIT);
608 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530609
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530610 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
611 ULPS_STATE_ENTER);
612 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530613
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530614 /* Wait till Clock lanes are in LP-00 state for MIPI Port A
615 * only. MIPI Port C has no similar bit for checking
616 */
Shashank Sharmab389a452015-09-01 19:41:44 +0530617 if (wait_for(((I915_READ(port_ctrl) & AFE_LATCHOUT)
618 == 0x00000), 30))
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530619 DRM_ERROR("DSI LP not going Low\n");
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530620
Shashank Sharmab389a452015-09-01 19:41:44 +0530621 /* Disable MIPI PHY transparent latch */
622 val = I915_READ(port_ctrl);
623 I915_WRITE(port_ctrl, val & ~LP_OUTPUT_HOLD);
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530624 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530625
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530626 I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
627 usleep_range(2000, 2500);
628 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530629
Shashank Sharmafe88fc62015-09-01 19:41:39 +0530630 intel_disable_dsi_pll(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300631}
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530632
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530633static void intel_dsi_post_disable(struct intel_encoder *encoder)
634{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530635 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530636 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530637 u32 val;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530638
639 DRM_DEBUG_KMS("\n");
640
Imre Deakc315faf2014-05-27 19:00:09 +0300641 intel_dsi_disable(encoder);
642
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530643 intel_dsi_clear_device_ready(encoder);
644
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530645 val = I915_READ(DSPCLK_GATE_D);
646 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
647 I915_WRITE(DSPCLK_GATE_D, val);
648
Jani Nikula593e0622015-01-23 15:30:56 +0200649 drm_panel_unprepare(intel_dsi->panel);
Shobhit Kumardf38e652014-04-14 11:18:26 +0530650
651 msleep(intel_dsi->panel_off_delay);
652 msleep(intel_dsi->panel_pwr_cycle_delay);
Shobhit Kumarfc45e822015-06-26 14:32:09 +0530653
654 /* Panel Disable over CRC PMIC */
655 if (intel_dsi->gpio_panel)
656 gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530657}
Jani Nikula4e646492013-08-27 15:12:20 +0300658
659static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
660 enum pipe *pipe)
661{
662 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530663 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
664 struct drm_device *dev = encoder->base.dev;
Imre Deak6d129be2014-03-05 16:20:54 +0200665 enum intel_display_power_domain power_domain;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200666 enum port port;
Imre Deak3f3f42b2016-02-12 18:55:19 +0200667 bool ret;
Jani Nikula4e646492013-08-27 15:12:20 +0300668
669 DRM_DEBUG_KMS("\n");
670
Imre Deak6d129be2014-03-05 16:20:54 +0200671 power_domain = intel_display_port_power_domain(encoder);
Imre Deak3f3f42b2016-02-12 18:55:19 +0200672 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200673 return false;
674
Imre Deak3f3f42b2016-02-12 18:55:19 +0200675 ret = false;
676
Jani Nikula4e646492013-08-27 15:12:20 +0300677 /* XXX: this only works for one DSI output */
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530678 for_each_dsi_port(port, intel_dsi->ports) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200679 i915_reg_t ctrl_reg = IS_BROXTON(dev) ?
680 BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port);
681 u32 dpi_enabled, func;
682
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200683 func = I915_READ(MIPI_DSI_FUNC_PRG(port));
Shashank Sharmabaeac682015-09-01 19:41:45 +0530684 dpi_enabled = I915_READ(ctrl_reg) & DPI_ENABLE;
Jani Nikula4e646492013-08-27 15:12:20 +0300685
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530686 /* Due to some hardware limitations on BYT, MIPI Port C DPI
687 * Enable bit does not get set. To check whether DSI Port C
688 * was enabled in BIOS, check the Pipe B enable bit
689 */
Wayne Boyer666a4532015-12-09 12:29:35 -0800690 if (IS_VALLEYVIEW(dev) && port == PORT_C)
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530691 dpi_enabled = I915_READ(PIPECONF(PIPE_B)) &
692 PIPECONF_ENABLE;
693
694 if (dpi_enabled || (func & CMD_MODE_DATA_WIDTH_MASK)) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200695 if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530696 *pipe = port == PORT_A ? PIPE_A : PIPE_B;
Imre Deak3f3f42b2016-02-12 18:55:19 +0200697 ret = true;
698
699 goto out;
Jani Nikula4e646492013-08-27 15:12:20 +0300700 }
701 }
702 }
Imre Deak3f3f42b2016-02-12 18:55:19 +0200703out:
704 intel_display_power_put(dev_priv, power_domain);
Jani Nikula4e646492013-08-27 15:12:20 +0300705
Imre Deak3f3f42b2016-02-12 18:55:19 +0200706 return ret;
Jani Nikula4e646492013-08-27 15:12:20 +0300707}
708
709static void intel_dsi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200710 struct intel_crtc_state *pipe_config)
Jani Nikula4e646492013-08-27 15:12:20 +0300711{
Jani Nikulad7d85d82016-01-08 12:45:39 +0200712 u32 pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300713 DRM_DEBUG_KMS("\n");
714
Jani Nikulaa65347b2015-11-27 12:21:46 +0200715 pipe_config->has_dsi_encoder = true;
716
Shobhit Kumarf573de52014-07-30 20:32:37 +0530717 /*
718 * DPLL_MD is not used in case of DSI, reading will get some default value
719 * set dpll_md = 0
720 */
721 pipe_config->dpll_hw_state.dpll_md = 0;
722
Jani Nikulad7d85d82016-01-08 12:45:39 +0200723 pclk = intel_dsi_get_pclk(encoder, pipe_config->pipe_bpp);
Shobhit Kumarf573de52014-07-30 20:32:37 +0530724 if (!pclk)
725 return;
726
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200727 pipe_config->base.adjusted_mode.crtc_clock = pclk;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530728 pipe_config->port_clock = pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300729}
730
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000731static enum drm_mode_status
732intel_dsi_mode_valid(struct drm_connector *connector,
733 struct drm_display_mode *mode)
Jani Nikula4e646492013-08-27 15:12:20 +0300734{
735 struct intel_connector *intel_connector = to_intel_connector(connector);
736 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Mika Kahola759a1e92015-08-18 14:37:01 +0300737 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
Jani Nikula4e646492013-08-27 15:12:20 +0300738
739 DRM_DEBUG_KMS("\n");
740
741 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
742 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
743 return MODE_NO_DBLESCAN;
744 }
745
746 if (fixed_mode) {
747 if (mode->hdisplay > fixed_mode->hdisplay)
748 return MODE_PANEL;
749 if (mode->vdisplay > fixed_mode->vdisplay)
750 return MODE_PANEL;
Mika Kahola759a1e92015-08-18 14:37:01 +0300751 if (fixed_mode->clock > max_dotclk)
752 return MODE_CLOCK_HIGH;
Jani Nikula4e646492013-08-27 15:12:20 +0300753 }
754
Jani Nikula36d21f42015-01-16 14:27:20 +0200755 return MODE_OK;
Jani Nikula4e646492013-08-27 15:12:20 +0300756}
757
758/* return txclkesc cycles in terms of divider and duration in us */
759static u16 txclkesc(u32 divider, unsigned int us)
760{
761 switch (divider) {
762 case ESCAPE_CLOCK_DIVIDER_1:
763 default:
764 return 20 * us;
765 case ESCAPE_CLOCK_DIVIDER_2:
766 return 10 * us;
767 case ESCAPE_CLOCK_DIVIDER_4:
768 return 5 * us;
769 }
770}
771
772/* return pixels in terms of txbyteclkhs */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530773static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
774 u16 burst_mode_ratio)
Jani Nikula4e646492013-08-27 15:12:20 +0300775{
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530776 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200777 8 * 100), lane_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300778}
779
780static void set_dsi_timings(struct drm_encoder *encoder,
Ville Syrjälä5e7234c2015-09-25 16:37:43 +0300781 const struct drm_display_mode *adjusted_mode)
Jani Nikula4e646492013-08-27 15:12:20 +0300782{
783 struct drm_device *dev = encoder->dev;
784 struct drm_i915_private *dev_priv = dev->dev_private;
785 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
786 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530787 enum port port;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200788 unsigned int bpp = intel_crtc->config->pipe_bpp;
Jani Nikula4e646492013-08-27 15:12:20 +0300789 unsigned int lane_count = intel_dsi->lane_count;
790
791 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
792
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300793 hactive = adjusted_mode->crtc_hdisplay;
794 hfp = adjusted_mode->crtc_hsync_start - adjusted_mode->crtc_hdisplay;
795 hsync = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
796 hbp = adjusted_mode->crtc_htotal - adjusted_mode->crtc_hsync_end;
Jani Nikula4e646492013-08-27 15:12:20 +0300797
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530798 if (intel_dsi->dual_link) {
799 hactive /= 2;
800 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
801 hactive += intel_dsi->pixel_overlap;
802 hfp /= 2;
803 hsync /= 2;
804 hbp /= 2;
805 }
806
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300807 vfp = adjusted_mode->crtc_vsync_start - adjusted_mode->crtc_vdisplay;
808 vsync = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
809 vbp = adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vsync_end;
Jani Nikula4e646492013-08-27 15:12:20 +0300810
811 /* horizontal values are in terms of high speed byte clock */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530812 hactive = txbyteclkhs(hactive, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200813 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530814 hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
815 hsync = txbyteclkhs(hsync, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200816 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530817 hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
Jani Nikula4e646492013-08-27 15:12:20 +0300818
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530819 for_each_dsi_port(port, intel_dsi->ports) {
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530820 if (IS_BROXTON(dev)) {
821 /*
822 * Program hdisplay and vdisplay on MIPI transcoder.
823 * This is different from calculated hactive and
824 * vactive, as they are calculated per channel basis,
825 * whereas these values should be based on resolution.
826 */
827 I915_WRITE(BXT_MIPI_TRANS_HACTIVE(port),
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300828 adjusted_mode->crtc_hdisplay);
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530829 I915_WRITE(BXT_MIPI_TRANS_VACTIVE(port),
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300830 adjusted_mode->crtc_vdisplay);
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530831 I915_WRITE(BXT_MIPI_TRANS_VTOTAL(port),
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300832 adjusted_mode->crtc_vtotal);
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530833 }
834
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530835 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
836 I915_WRITE(MIPI_HFP_COUNT(port), hfp);
Jani Nikula4e646492013-08-27 15:12:20 +0300837
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530838 /* meaningful for video mode non-burst sync pulse mode only,
839 * can be zero for non-burst sync events and burst modes */
840 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
841 I915_WRITE(MIPI_HBP_COUNT(port), hbp);
Jani Nikula4e646492013-08-27 15:12:20 +0300842
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530843 /* vertical values are in terms of lines */
844 I915_WRITE(MIPI_VFP_COUNT(port), vfp);
845 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
846 I915_WRITE(MIPI_VBP_COUNT(port), vbp);
847 }
Jani Nikula4e646492013-08-27 15:12:20 +0300848}
849
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200850static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300851{
852 struct drm_encoder *encoder = &intel_encoder->base;
853 struct drm_device *dev = encoder->dev;
854 struct drm_i915_private *dev_priv = dev->dev_private;
855 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
856 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +0300857 const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530858 enum port port;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200859 unsigned int bpp = intel_crtc->config->pipe_bpp;
Jani Nikula4e646492013-08-27 15:12:20 +0300860 u32 val, tmp;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530861 u16 mode_hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300862
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200863 DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
Jani Nikula4e646492013-08-27 15:12:20 +0300864
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300865 mode_hdisplay = adjusted_mode->crtc_hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300866
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530867 if (intel_dsi->dual_link) {
868 mode_hdisplay /= 2;
869 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
870 mode_hdisplay += intel_dsi->pixel_overlap;
871 }
Jani Nikula4e646492013-08-27 15:12:20 +0300872
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530873 for_each_dsi_port(port, intel_dsi->ports) {
Wayne Boyer666a4532015-12-09 12:29:35 -0800874 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530875 /*
876 * escape clock divider, 20MHz, shared for A and C.
877 * device ready must be off when doing this! txclkesc?
878 */
879 tmp = I915_READ(MIPI_CTRL(PORT_A));
880 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
881 I915_WRITE(MIPI_CTRL(PORT_A), tmp |
882 ESCAPE_CLOCK_DIVIDER_1);
Jani Nikula4e646492013-08-27 15:12:20 +0300883
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530884 /* read request priority is per pipe */
885 tmp = I915_READ(MIPI_CTRL(port));
886 tmp &= ~READ_REQUEST_PRIORITY_MASK;
887 I915_WRITE(MIPI_CTRL(port), tmp |
888 READ_REQUEST_PRIORITY_HIGH);
889 } else if (IS_BROXTON(dev)) {
Deepak M56c48972015-12-09 20:14:04 +0530890 enum pipe pipe = intel_crtc->pipe;
891
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530892 tmp = I915_READ(MIPI_CTRL(port));
893 tmp &= ~BXT_PIPE_SELECT_MASK;
894
Deepak M56c48972015-12-09 20:14:04 +0530895 tmp |= BXT_PIPE_SELECT(pipe);
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530896 I915_WRITE(MIPI_CTRL(port), tmp);
897 }
Jani Nikula4e646492013-08-27 15:12:20 +0300898
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530899 /* XXX: why here, why like this? handling in irq handler?! */
900 I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
901 I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
902
903 I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
904
905 I915_WRITE(MIPI_DPI_RESOLUTION(port),
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300906 adjusted_mode->crtc_vdisplay << VERTICAL_ADDRESS_SHIFT |
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530907 mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
908 }
Jani Nikula4e646492013-08-27 15:12:20 +0300909
910 set_dsi_timings(encoder, adjusted_mode);
911
912 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
913 if (is_cmd_mode(intel_dsi)) {
914 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
915 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
916 } else {
917 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
918
919 /* XXX: cross-check bpp vs. pixel format? */
920 val |= intel_dsi->pixel_format;
921 }
Jani Nikula4e646492013-08-27 15:12:20 +0300922
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530923 tmp = 0;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530924 if (intel_dsi->eotp_pkt == 0)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530925 tmp |= EOT_DISABLE;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530926 if (intel_dsi->clock_stop)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530927 tmp |= CLOCKSTOP;
Jani Nikula4e646492013-08-27 15:12:20 +0300928
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530929 for_each_dsi_port(port, intel_dsi->ports) {
930 I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300931
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530932 /* timeouts for recovery. one frame IIUC. if counter expires,
933 * EOT and stop state. */
Shobhit Kumarcf4dbd22014-04-14 11:18:25 +0530934
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530935 /*
936 * In burst mode, value greater than one DPI line Time in byte
937 * clock (txbyteclkhs) To timeout this timer 1+ of the above
938 * said value is recommended.
939 *
940 * In non-burst mode, Value greater than one DPI frame time in
941 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
942 * said value is recommended.
943 *
944 * In DBI only mode, value greater than one DBI frame time in
945 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
946 * said value is recommended.
947 */
Jani Nikula4e646492013-08-27 15:12:20 +0300948
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530949 if (is_vid_mode(intel_dsi) &&
950 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
951 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300952 txbyteclkhs(adjusted_mode->crtc_htotal, bpp,
Ville Syrjälä124abe02015-09-08 13:40:45 +0300953 intel_dsi->lane_count,
954 intel_dsi->burst_mode_ratio) + 1);
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530955 } else {
956 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
Ville Syrjäläaad941d2015-09-25 16:38:56 +0300957 txbyteclkhs(adjusted_mode->crtc_vtotal *
958 adjusted_mode->crtc_htotal,
Ville Syrjälä124abe02015-09-08 13:40:45 +0300959 bpp, intel_dsi->lane_count,
960 intel_dsi->burst_mode_ratio) + 1);
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530961 }
962 I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
963 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
964 intel_dsi->turn_arnd_val);
965 I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
966 intel_dsi->rst_timer_val);
Jani Nikula4e646492013-08-27 15:12:20 +0300967
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530968 /* dphy stuff */
Jani Nikula4e646492013-08-27 15:12:20 +0300969
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530970 /* in terms of low power clock */
971 I915_WRITE(MIPI_INIT_COUNT(port),
972 txclkesc(intel_dsi->escape_clk_div, 100));
Jani Nikula4e646492013-08-27 15:12:20 +0300973
Shashank Sharmad2e08c02015-09-01 19:41:40 +0530974 if (IS_BROXTON(dev) && (!intel_dsi->dual_link)) {
975 /*
976 * BXT spec says write MIPI_INIT_COUNT for
977 * both the ports, even if only one is
978 * getting used. So write the other port
979 * if not in dual link mode.
980 */
981 I915_WRITE(MIPI_INIT_COUNT(port ==
982 PORT_A ? PORT_C : PORT_A),
983 intel_dsi->init_count);
984 }
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530985
986 /* recovery disables */
Shobhit Kumar87c54d02015-02-03 12:17:35 +0530987 I915_WRITE(MIPI_EOT_DISABLE(port), tmp);
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530988
989 /* in terms of low power clock */
990 I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
991
992 /* in terms of txbyteclkhs. actual high to low switch +
993 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
994 *
995 * XXX: write MIPI_STOP_STATE_STALL?
996 */
997 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
998 intel_dsi->hs_to_lp_count);
999
1000 /* XXX: low power clock equivalence in terms of byte clock.
1001 * the number of byte clocks occupied in one low power clock.
1002 * based on txbyteclkhs and txclkesc.
1003 * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
1004 * ) / 105.???
1005 */
1006 I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
1007
1008 /* the bw essential for transmitting 16 long packets containing
1009 * 252 bytes meant for dcs write memory command is programmed in
1010 * this register in terms of byte clocks. based on dsi transfer
1011 * rate and the number of lanes configured the time taken to
1012 * transmit 16 long packets in a dsi stream varies. */
1013 I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
1014
1015 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
1016 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
1017 intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
1018
1019 if (is_vid_mode(intel_dsi))
1020 /* Some panels might have resolution which is not a
1021 * multiple of 64 like 1366 x 768. Enable RANDOM
1022 * resolution support for such panels by default */
1023 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
1024 intel_dsi->video_frmt_cfg_bits |
1025 intel_dsi->video_mode_format |
1026 IP_TG_CONFIG |
1027 RANDOM_DPI_DISPLAY_RESOLUTION);
1028 }
Jani Nikula4e646492013-08-27 15:12:20 +03001029}
1030
1031static enum drm_connector_status
1032intel_dsi_detect(struct drm_connector *connector, bool force)
1033{
Jani Nikula36d21f42015-01-16 14:27:20 +02001034 return connector_status_connected;
Jani Nikula4e646492013-08-27 15:12:20 +03001035}
1036
1037static int intel_dsi_get_modes(struct drm_connector *connector)
1038{
1039 struct intel_connector *intel_connector = to_intel_connector(connector);
1040 struct drm_display_mode *mode;
1041
1042 DRM_DEBUG_KMS("\n");
1043
1044 if (!intel_connector->panel.fixed_mode) {
1045 DRM_DEBUG_KMS("no fixed mode\n");
1046 return 0;
1047 }
1048
1049 mode = drm_mode_duplicate(connector->dev,
1050 intel_connector->panel.fixed_mode);
1051 if (!mode) {
1052 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
1053 return 0;
1054 }
1055
1056 drm_mode_probed_add(connector, mode);
1057 return 1;
1058}
1059
Jani Nikula593e0622015-01-23 15:30:56 +02001060static void intel_dsi_connector_destroy(struct drm_connector *connector)
Jani Nikula4e646492013-08-27 15:12:20 +03001061{
1062 struct intel_connector *intel_connector = to_intel_connector(connector);
1063
1064 DRM_DEBUG_KMS("\n");
1065 intel_panel_fini(&intel_connector->panel);
Jani Nikula4e646492013-08-27 15:12:20 +03001066 drm_connector_cleanup(connector);
1067 kfree(connector);
1068}
1069
Jani Nikula593e0622015-01-23 15:30:56 +02001070static void intel_dsi_encoder_destroy(struct drm_encoder *encoder)
1071{
1072 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
1073
1074 if (intel_dsi->panel) {
1075 drm_panel_detach(intel_dsi->panel);
1076 /* XXX: Logically this call belongs in the panel driver. */
1077 drm_panel_remove(intel_dsi->panel);
1078 }
Shobhit Kumarfc45e822015-06-26 14:32:09 +05301079
1080 /* dispose of the gpios */
1081 if (intel_dsi->gpio_panel)
1082 gpiod_put(intel_dsi->gpio_panel);
1083
Jani Nikula593e0622015-01-23 15:30:56 +02001084 intel_encoder_destroy(encoder);
1085}
1086
Jani Nikula4e646492013-08-27 15:12:20 +03001087static const struct drm_encoder_funcs intel_dsi_funcs = {
Jani Nikula593e0622015-01-23 15:30:56 +02001088 .destroy = intel_dsi_encoder_destroy,
Jani Nikula4e646492013-08-27 15:12:20 +03001089};
1090
1091static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
1092 .get_modes = intel_dsi_get_modes,
1093 .mode_valid = intel_dsi_mode_valid,
1094 .best_encoder = intel_best_encoder,
1095};
1096
1097static const struct drm_connector_funcs intel_dsi_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02001098 .dpms = drm_atomic_helper_connector_dpms,
Jani Nikula4e646492013-08-27 15:12:20 +03001099 .detect = intel_dsi_detect,
Jani Nikula593e0622015-01-23 15:30:56 +02001100 .destroy = intel_dsi_connector_destroy,
Jani Nikula4e646492013-08-27 15:12:20 +03001101 .fill_modes = drm_helper_probe_single_connector_modes,
Matt Roper2545e4a2015-01-22 16:51:27 -08001102 .atomic_get_property = intel_connector_atomic_get_property,
Matt Roperc6f95f22015-01-22 16:50:32 -08001103 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02001104 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Jani Nikula4e646492013-08-27 15:12:20 +03001105};
1106
Damien Lespiau4328633d2014-05-28 12:30:56 +01001107void intel_dsi_init(struct drm_device *dev)
Jani Nikula4e646492013-08-27 15:12:20 +03001108{
1109 struct intel_dsi *intel_dsi;
1110 struct intel_encoder *intel_encoder;
1111 struct drm_encoder *encoder;
1112 struct intel_connector *intel_connector;
1113 struct drm_connector *connector;
Jani Nikula593e0622015-01-23 15:30:56 +02001114 struct drm_display_mode *scan, *fixed_mode = NULL;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +05301115 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula7e9804f2015-01-16 14:27:23 +02001116 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +03001117 unsigned int i;
1118
1119 DRM_DEBUG_KMS("\n");
1120
Shobhit Kumar3e6bd012014-05-27 19:33:59 +05301121 /* There is no detection method for MIPI so rely on VBT */
1122 if (!dev_priv->vbt.has_mipi)
Damien Lespiau4328633d2014-05-28 12:30:56 +01001123 return;
Jani Nikula4e646492013-08-27 15:12:20 +03001124
Wayne Boyer666a4532015-12-09 12:29:35 -08001125 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +05301126 dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
1127 } else {
1128 DRM_ERROR("Unsupported Mipi device to reg base");
Christoph Jaeger868d6652014-06-13 21:51:22 +02001129 return;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +05301130 }
1131
Jani Nikula4e646492013-08-27 15:12:20 +03001132 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
1133 if (!intel_dsi)
Damien Lespiau4328633d2014-05-28 12:30:56 +01001134 return;
Jani Nikula4e646492013-08-27 15:12:20 +03001135
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03001136 intel_connector = intel_connector_alloc();
Jani Nikula4e646492013-08-27 15:12:20 +03001137 if (!intel_connector) {
1138 kfree(intel_dsi);
Damien Lespiau4328633d2014-05-28 12:30:56 +01001139 return;
Jani Nikula4e646492013-08-27 15:12:20 +03001140 }
1141
1142 intel_encoder = &intel_dsi->base;
1143 encoder = &intel_encoder->base;
1144 intel_dsi->attached_connector = intel_connector;
1145
Jani Nikula4e646492013-08-27 15:12:20 +03001146 connector = &intel_connector->base;
1147
Ville Syrjälä13a3d912015-12-09 16:20:18 +02001148 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI,
1149 NULL);
Jani Nikula4e646492013-08-27 15:12:20 +03001150
Jani Nikula4e646492013-08-27 15:12:20 +03001151 intel_encoder->compute_config = intel_dsi_compute_config;
Jani Nikula4e646492013-08-27 15:12:20 +03001152 intel_encoder->pre_enable = intel_dsi_pre_enable;
Shobhit Kumar2634fd72014-04-09 13:59:31 +05301153 intel_encoder->enable = intel_dsi_enable_nop;
Imre Deakc315faf2014-05-27 19:00:09 +03001154 intel_encoder->disable = intel_dsi_pre_disable;
Jani Nikula4e646492013-08-27 15:12:20 +03001155 intel_encoder->post_disable = intel_dsi_post_disable;
1156 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
1157 intel_encoder->get_config = intel_dsi_get_config;
1158
1159 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak4932e2c2014-02-11 17:12:48 +02001160 intel_connector->unregister = intel_connector_unregister;
Jani Nikula4e646492013-08-27 15:12:20 +03001161
Jani Nikulae7d7cad2014-11-14 16:54:21 +02001162 /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
Gaurav K Singh82425782015-08-03 15:45:32 +05301163 if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +02001164 intel_encoder->crtc_mask = (1 << PIPE_A);
Jani Nikula17af40a2014-11-14 16:54:22 +02001165 intel_dsi->ports = (1 << PORT_A);
1166 } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +02001167 intel_encoder->crtc_mask = (1 << PIPE_B);
Jani Nikula17af40a2014-11-14 16:54:22 +02001168 intel_dsi->ports = (1 << PORT_C);
1169 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +02001170
Gaurav K Singh82425782015-08-03 15:45:32 +05301171 if (dev_priv->vbt.dsi.config->dual_link)
1172 intel_dsi->ports = ((1 << PORT_A) | (1 << PORT_C));
1173
Jani Nikula7e9804f2015-01-16 14:27:23 +02001174 /* Create a DSI host (and a device) for each port. */
1175 for_each_dsi_port(port, intel_dsi->ports) {
1176 struct intel_dsi_host *host;
1177
1178 host = intel_dsi_host_init(intel_dsi, port);
1179 if (!host)
1180 goto err;
1181
1182 intel_dsi->dsi_hosts[port] = host;
1183 }
1184
Jani Nikula593e0622015-01-23 15:30:56 +02001185 for (i = 0; i < ARRAY_SIZE(intel_dsi_drivers); i++) {
1186 intel_dsi->panel = intel_dsi_drivers[i].init(intel_dsi,
1187 intel_dsi_drivers[i].panel_id);
1188 if (intel_dsi->panel)
Jani Nikula4e646492013-08-27 15:12:20 +03001189 break;
1190 }
1191
Jani Nikula593e0622015-01-23 15:30:56 +02001192 if (!intel_dsi->panel) {
Jani Nikula4e646492013-08-27 15:12:20 +03001193 DRM_DEBUG_KMS("no device found\n");
1194 goto err;
1195 }
1196
Shobhit Kumarfc45e822015-06-26 14:32:09 +05301197 /*
1198 * In case of BYT with CRC PMIC, we need to use GPIO for
1199 * Panel control.
1200 */
1201 if (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) {
1202 intel_dsi->gpio_panel =
1203 gpiod_get(dev->dev, "panel", GPIOD_OUT_HIGH);
1204
1205 if (IS_ERR(intel_dsi->gpio_panel)) {
1206 DRM_ERROR("Failed to own gpio for panel control\n");
1207 intel_dsi->gpio_panel = NULL;
1208 }
1209 }
1210
Jani Nikula4e646492013-08-27 15:12:20 +03001211 intel_encoder->type = INTEL_OUTPUT_DSI;
Ville Syrjäläbc079e82014-03-03 16:15:28 +02001212 intel_encoder->cloneable = 0;
Jani Nikula4e646492013-08-27 15:12:20 +03001213 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
1214 DRM_MODE_CONNECTOR_DSI);
1215
1216 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
1217
1218 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
1219 connector->interlace_allowed = false;
1220 connector->doublescan_allowed = false;
1221
1222 intel_connector_attach_encoder(intel_connector, intel_encoder);
1223
Thomas Wood34ea3d32014-05-29 16:57:41 +01001224 drm_connector_register(connector);
Jani Nikula4e646492013-08-27 15:12:20 +03001225
Jani Nikula593e0622015-01-23 15:30:56 +02001226 drm_panel_attach(intel_dsi->panel, connector);
1227
1228 mutex_lock(&dev->mode_config.mutex);
1229 drm_panel_get_modes(intel_dsi->panel);
1230 list_for_each_entry(scan, &connector->probed_modes, head) {
1231 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
1232 fixed_mode = drm_mode_duplicate(dev, scan);
1233 break;
1234 }
1235 }
1236 mutex_unlock(&dev->mode_config.mutex);
1237
Jani Nikula4e646492013-08-27 15:12:20 +03001238 if (!fixed_mode) {
1239 DRM_DEBUG_KMS("no fixed mode\n");
1240 goto err;
1241 }
1242
Vandana Kannan4b6ed682014-02-11 14:26:36 +05301243 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
Shobhit Kumarb029e662015-06-26 14:32:10 +05301244 intel_panel_setup_backlight(connector, INVALID_PIPE);
Jani Nikula4e646492013-08-27 15:12:20 +03001245
Damien Lespiau4328633d2014-05-28 12:30:56 +01001246 return;
Jani Nikula4e646492013-08-27 15:12:20 +03001247
1248err:
1249 drm_encoder_cleanup(&intel_encoder->base);
1250 kfree(intel_dsi);
1251 kfree(intel_connector);
Jani Nikula4e646492013-08-27 15:12:20 +03001252}