blob: 803e87a5a22f8782da986f44af3e4bf466a5c4c0 [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>
34#include "i915_drv.h"
35#include "intel_drv.h"
36#include "intel_dsi.h"
37#include "intel_dsi_cmd.h"
38
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
Jani Nikula7e9804f2015-01-16 14:27:23 +020063static void write_data(struct drm_i915_private *dev_priv, u32 reg,
64 const u8 *data, u32 len)
65{
66 u32 i, j;
67
68 for (i = 0; i < len; i += 4) {
69 u32 val = 0;
70
71 for (j = 0; j < min_t(u32, len - i, 4); j++)
72 val |= *data++ << 8 * j;
73
74 I915_WRITE(reg, val);
75 }
76}
77
78static void read_data(struct drm_i915_private *dev_priv, u32 reg,
79 u8 *data, u32 len)
80{
81 u32 i, j;
82
83 for (i = 0; i < len; i += 4) {
84 u32 val = I915_READ(reg);
85
86 for (j = 0; j < min_t(u32, len - i, 4); j++)
87 *data++ = val >> 8 * j;
88 }
89}
90
91static ssize_t intel_dsi_host_transfer(struct mipi_dsi_host *host,
92 const struct mipi_dsi_msg *msg)
93{
94 struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host);
95 struct drm_device *dev = intel_dsi_host->intel_dsi->base.base.dev;
96 struct drm_i915_private *dev_priv = dev->dev_private;
97 enum port port = intel_dsi_host->port;
98 struct mipi_dsi_packet packet;
99 ssize_t ret;
100 const u8 *header, *data;
101 u32 data_reg, data_mask, ctrl_reg, ctrl_mask;
102
103 ret = mipi_dsi_create_packet(&packet, msg);
104 if (ret < 0)
105 return ret;
106
107 header = packet.header;
108 data = packet.payload;
109
110 if (msg->flags & MIPI_DSI_MSG_USE_LPM) {
111 data_reg = MIPI_LP_GEN_DATA(port);
112 data_mask = LP_DATA_FIFO_FULL;
113 ctrl_reg = MIPI_LP_GEN_CTRL(port);
114 ctrl_mask = LP_CTRL_FIFO_FULL;
115 } else {
116 data_reg = MIPI_HS_GEN_DATA(port);
117 data_mask = HS_DATA_FIFO_FULL;
118 ctrl_reg = MIPI_HS_GEN_CTRL(port);
119 ctrl_mask = HS_CTRL_FIFO_FULL;
120 }
121
122 /* note: this is never true for reads */
123 if (packet.payload_length) {
124
125 if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & data_mask) == 0, 50))
126 DRM_ERROR("Timeout waiting for HS/LP DATA FIFO !full\n");
127
128 write_data(dev_priv, data_reg, packet.payload,
129 packet.payload_length);
130 }
131
132 if (msg->rx_len) {
133 I915_WRITE(MIPI_INTR_STAT(port), GEN_READ_DATA_AVAIL);
134 }
135
136 if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & ctrl_mask) == 0, 50)) {
137 DRM_ERROR("Timeout waiting for HS/LP CTRL FIFO !full\n");
138 }
139
140 I915_WRITE(ctrl_reg, header[2] << 16 | header[1] << 8 | header[0]);
141
142 /* ->rx_len is set only for reads */
143 if (msg->rx_len) {
144 data_mask = GEN_READ_DATA_AVAIL;
145 if (wait_for((I915_READ(MIPI_INTR_STAT(port)) & data_mask) == data_mask, 50))
146 DRM_ERROR("Timeout waiting for read data.\n");
147
148 read_data(dev_priv, data_reg, msg->rx_buf, msg->rx_len);
149 }
150
151 /* XXX: fix for reads and writes */
152 return 4 + packet.payload_length;
153}
154
155static int intel_dsi_host_attach(struct mipi_dsi_host *host,
156 struct mipi_dsi_device *dsi)
157{
158 return 0;
159}
160
161static int intel_dsi_host_detach(struct mipi_dsi_host *host,
162 struct mipi_dsi_device *dsi)
163{
164 return 0;
165}
166
167static const struct mipi_dsi_host_ops intel_dsi_host_ops = {
168 .attach = intel_dsi_host_attach,
169 .detach = intel_dsi_host_detach,
170 .transfer = intel_dsi_host_transfer,
171};
172
173static struct intel_dsi_host *intel_dsi_host_init(struct intel_dsi *intel_dsi,
174 enum port port)
175{
176 struct intel_dsi_host *host;
177 struct mipi_dsi_device *device;
178
179 host = kzalloc(sizeof(*host), GFP_KERNEL);
180 if (!host)
181 return NULL;
182
183 host->base.ops = &intel_dsi_host_ops;
184 host->intel_dsi = intel_dsi;
185 host->port = port;
186
187 /*
188 * We should call mipi_dsi_host_register(&host->base) here, but we don't
189 * have a host->dev, and we don't have OF stuff either. So just use the
190 * dsi framework as a library and hope for the best. Create the dsi
191 * devices by ourselves here too. Need to be careful though, because we
192 * don't initialize any of the driver model devices here.
193 */
194 device = kzalloc(sizeof(*device), GFP_KERNEL);
195 if (!device) {
196 kfree(host);
197 return NULL;
198 }
199
200 device->host = &host->base;
201 host->device = device;
202
203 return host;
204}
205
Shobhit Kumare9fe51c2013-12-10 12:14:55 +0530206static void band_gap_reset(struct drm_i915_private *dev_priv)
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +0300207{
208 mutex_lock(&dev_priv->dpio_lock);
209
Shobhit Kumare9fe51c2013-12-10 12:14:55 +0530210 vlv_flisdsi_write(dev_priv, 0x08, 0x0001);
211 vlv_flisdsi_write(dev_priv, 0x0F, 0x0005);
212 vlv_flisdsi_write(dev_priv, 0x0F, 0x0025);
213 udelay(150);
214 vlv_flisdsi_write(dev_priv, 0x0F, 0x0000);
215 vlv_flisdsi_write(dev_priv, 0x08, 0x0000);
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +0300216
217 mutex_unlock(&dev_priv->dpio_lock);
Shobhit Kumar4ce8c9a2013-08-27 15:12:24 +0300218}
219
Jani Nikula4e646492013-08-27 15:12:20 +0300220static inline bool is_vid_mode(struct intel_dsi *intel_dsi)
221{
Shobhit Kumardfba2e22014-04-14 11:18:24 +0530222 return intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE;
Jani Nikula4e646492013-08-27 15:12:20 +0300223}
224
225static inline bool is_cmd_mode(struct intel_dsi *intel_dsi)
226{
Shobhit Kumardfba2e22014-04-14 11:18:24 +0530227 return intel_dsi->operation_mode == INTEL_DSI_COMMAND_MODE;
Jani Nikula4e646492013-08-27 15:12:20 +0300228}
229
230static void intel_dsi_hot_plug(struct intel_encoder *encoder)
231{
232 DRM_DEBUG_KMS("\n");
233}
234
235static bool intel_dsi_compute_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200236 struct intel_crtc_state *config)
Jani Nikula4e646492013-08-27 15:12:20 +0300237{
238 struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi,
239 base);
240 struct intel_connector *intel_connector = intel_dsi->attached_connector;
241 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200242 struct drm_display_mode *adjusted_mode = &config->base.adjusted_mode;
Jani Nikula4e646492013-08-27 15:12:20 +0300243
244 DRM_DEBUG_KMS("\n");
245
246 if (fixed_mode)
247 intel_fixed_panel_mode(fixed_mode, adjusted_mode);
248
Shobhit Kumarf573de52014-07-30 20:32:37 +0530249 /* DSI uses short packets for sync events, so clear mode flags for DSI */
250 adjusted_mode->flags = 0;
251
Jani Nikula4e646492013-08-27 15:12:20 +0300252 return true;
253}
254
Gaurav K Singh5505a242014-12-04 10:58:47 +0530255static void intel_dsi_port_enable(struct intel_encoder *encoder)
256{
257 struct drm_device *dev = encoder->base.dev;
258 struct drm_i915_private *dev_priv = dev->dev_private;
259 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
260 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Gaurav K Singh369602d2014-12-05 14:09:28 +0530261 enum port port;
Gaurav K Singh5505a242014-12-04 10:58:47 +0530262 u32 temp;
263
Gaurav K Singha9da9bc2014-12-05 14:13:41 +0530264 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
265 temp = I915_READ(VLV_CHICKEN_3);
266 temp &= ~PIXEL_OVERLAP_CNT_MASK |
267 intel_dsi->pixel_overlap <<
268 PIXEL_OVERLAP_CNT_SHIFT;
269 I915_WRITE(VLV_CHICKEN_3, temp);
270 }
271
Gaurav K Singh369602d2014-12-05 14:09:28 +0530272 for_each_dsi_port(port, intel_dsi->ports) {
273 temp = I915_READ(MIPI_PORT_CTRL(port));
274 temp &= ~LANE_CONFIGURATION_MASK;
275 temp &= ~DUAL_LINK_MODE_MASK;
276
277 if (intel_dsi->ports == ((1 << PORT_A) | (1 << PORT_C))) {
278 temp |= (intel_dsi->dual_link - 1)
279 << DUAL_LINK_MODE_SHIFT;
280 temp |= intel_crtc->pipe ?
281 LANE_CONFIGURATION_DUAL_LINK_B :
282 LANE_CONFIGURATION_DUAL_LINK_A;
283 }
284 /* assert ip_tg_enable signal */
285 I915_WRITE(MIPI_PORT_CTRL(port), temp | DPI_ENABLE);
286 POSTING_READ(MIPI_PORT_CTRL(port));
287 }
Gaurav K Singh5505a242014-12-04 10:58:47 +0530288}
289
290static void intel_dsi_port_disable(struct intel_encoder *encoder)
291{
292 struct drm_device *dev = encoder->base.dev;
293 struct drm_i915_private *dev_priv = dev->dev_private;
Gaurav K Singh369602d2014-12-05 14:09:28 +0530294 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
295 enum port port;
Gaurav K Singh5505a242014-12-04 10:58:47 +0530296 u32 temp;
297
Gaurav K Singh369602d2014-12-05 14:09:28 +0530298 for_each_dsi_port(port, intel_dsi->ports) {
299 /* de-assert ip_tg_enable signal */
300 temp = I915_READ(MIPI_PORT_CTRL(port));
301 I915_WRITE(MIPI_PORT_CTRL(port), temp & ~DPI_ENABLE);
302 POSTING_READ(MIPI_PORT_CTRL(port));
303 }
Gaurav K Singh5505a242014-12-04 10:58:47 +0530304}
305
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530306static void intel_dsi_device_ready(struct intel_encoder *encoder)
307{
308 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530309 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
310 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530311 u32 val;
312
313 DRM_DEBUG_KMS("\n");
314
Shobhit Kumar2095f9f2014-04-09 13:59:30 +0530315 mutex_lock(&dev_priv->dpio_lock);
316 /* program rcomp for compliance, reduce from 50 ohms to 45 ohms
317 * needed everytime after power gate */
318 vlv_flisdsi_write(dev_priv, 0x04, 0x0004);
319 mutex_unlock(&dev_priv->dpio_lock);
320
321 /* bandgap reset is needed after everytime we do power gate */
322 band_gap_reset(dev_priv);
323
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530324 for_each_dsi_port(port, intel_dsi->ports) {
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530325
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530326 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER);
327 usleep_range(2500, 3000);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530328
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530329 val = I915_READ(MIPI_PORT_CTRL(port));
Gaurav K Singhbf344e82014-12-07 16:13:54 +0530330
331 /* Enable MIPI PHY transparent latch
332 * Common bit for both MIPI Port A & MIPI Port C
333 * No similar bit in MIPI Port C reg
334 */
335 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD);
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530336 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530337
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530338 I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT);
339 usleep_range(2500, 3000);
340
341 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY);
342 usleep_range(2500, 3000);
343 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530344}
Jani Nikula4e646492013-08-27 15:12:20 +0300345
346static void intel_dsi_enable(struct intel_encoder *encoder)
347{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530348 struct drm_device *dev = encoder->base.dev;
349 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300350 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikula4934b652015-01-22 15:01:35 +0200351 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300352
353 DRM_DEBUG_KMS("\n");
354
Jani Nikula4934b652015-01-22 15:01:35 +0200355 if (is_cmd_mode(intel_dsi)) {
356 for_each_dsi_port(port, intel_dsi->ports)
357 I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4);
358 } else {
Jani Nikula4e646492013-08-27 15:12:20 +0300359 msleep(20); /* XXX */
Jani Nikulaf03e4172015-01-16 14:27:16 +0200360 for_each_dsi_port(port, intel_dsi->ports)
361 dpi_send_cmd(intel_dsi, TURN_ON, DPI_LP_MODE_EN, port);
Jani Nikula4e646492013-08-27 15:12:20 +0300362 msleep(100);
363
Jani Nikula593e0622015-01-23 15:30:56 +0200364 drm_panel_enable(intel_dsi->panel);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530365
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200366 for_each_dsi_port(port, intel_dsi->ports)
367 wait_for_dsi_fifo_empty(intel_dsi, port);
Shobhit Kumar13813082014-07-12 17:17:22 +0530368
Gaurav K Singh5505a242014-12-04 10:58:47 +0530369 intel_dsi_port_enable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300370 }
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530371}
Jani Nikula4e646492013-08-27 15:12:20 +0300372
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530373static void intel_dsi_pre_enable(struct intel_encoder *encoder)
374{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530375 struct drm_device *dev = encoder->base.dev;
376 struct drm_i915_private *dev_priv = dev->dev_private;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530377 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530378 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
379 enum pipe pipe = intel_crtc->pipe;
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200380 enum port port;
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530381 u32 tmp;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530382
383 DRM_DEBUG_KMS("\n");
384
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530385 /* Disable DPOunit clock gating, can stall pipe
386 * and we need DPLL REFA always enabled */
387 tmp = I915_READ(DPLL(pipe));
388 tmp |= DPLL_REFA_CLK_ENABLE_VLV;
389 I915_WRITE(DPLL(pipe), tmp);
390
Shobhit Kumarf573de52014-07-30 20:32:37 +0530391 /* update the hw state for DPLL */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200392 intel_crtc->config->dpll_hw_state.dpll = DPLL_INTEGRATED_CLOCK_VLV |
Daniel Vetter7f3de832014-07-30 22:34:27 +0200393 DPLL_REFA_CLK_ENABLE_VLV;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530394
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530395 tmp = I915_READ(DSPCLK_GATE_D);
396 tmp |= DPOUNIT_CLOCK_GATE_DISABLE;
397 I915_WRITE(DSPCLK_GATE_D, tmp);
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530398
399 /* put device in ready state */
400 intel_dsi_device_ready(encoder);
401
Shobhit Kumardf38e652014-04-14 11:18:26 +0530402 msleep(intel_dsi->panel_on_delay);
403
Jani Nikula593e0622015-01-23 15:30:56 +0200404 drm_panel_prepare(intel_dsi->panel);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530405
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200406 for_each_dsi_port(port, intel_dsi->ports)
407 wait_for_dsi_fifo_empty(intel_dsi, port);
Shobhit Kumar13813082014-07-12 17:17:22 +0530408
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530409 /* Enable port in pre-enable phase itself because as per hw team
410 * recommendation, port should be enabled befor plane & pipe */
411 intel_dsi_enable(encoder);
412}
413
414static void intel_dsi_enable_nop(struct intel_encoder *encoder)
415{
416 DRM_DEBUG_KMS("\n");
417
418 /* for DSI port enable has to be done before pipe
419 * and plane enable, so port enable is done in
420 * pre_enable phase itself unlike other encoders
421 */
Jani Nikula4e646492013-08-27 15:12:20 +0300422}
423
Imre Deakc315faf2014-05-27 19:00:09 +0300424static void intel_dsi_pre_disable(struct intel_encoder *encoder)
425{
426 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Jani Nikulaf03e4172015-01-16 14:27:16 +0200427 enum port port;
Imre Deakc315faf2014-05-27 19:00:09 +0300428
429 DRM_DEBUG_KMS("\n");
430
431 if (is_vid_mode(intel_dsi)) {
432 /* Send Shutdown command to the panel in LP mode */
Jani Nikulaf03e4172015-01-16 14:27:16 +0200433 for_each_dsi_port(port, intel_dsi->ports)
434 dpi_send_cmd(intel_dsi, SHUTDOWN, DPI_LP_MODE_EN, port);
Imre Deakc315faf2014-05-27 19:00:09 +0300435 msleep(10);
436 }
437}
438
Jani Nikula4e646492013-08-27 15:12:20 +0300439static void intel_dsi_disable(struct intel_encoder *encoder)
440{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530441 struct drm_device *dev = encoder->base.dev;
442 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula4e646492013-08-27 15:12:20 +0300443 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530444 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300445 u32 temp;
446
447 DRM_DEBUG_KMS("\n");
448
Jani Nikula4e646492013-08-27 15:12:20 +0300449 if (is_vid_mode(intel_dsi)) {
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200450 for_each_dsi_port(port, intel_dsi->ports)
451 wait_for_dsi_fifo_empty(intel_dsi, port);
Shobhit Kumar13813082014-07-12 17:17:22 +0530452
Gaurav K Singh5505a242014-12-04 10:58:47 +0530453 intel_dsi_port_disable(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300454 msleep(2);
455 }
456
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530457 for_each_dsi_port(port, intel_dsi->ports) {
458 /* Panel commands can be sent when clock is in LP11 */
459 I915_WRITE(MIPI_DEVICE_READY(port), 0x0);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530460
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530461 temp = I915_READ(MIPI_CTRL(port));
462 temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
463 I915_WRITE(MIPI_CTRL(port), temp |
464 intel_dsi->escape_clk_div <<
465 ESCAPE_CLOCK_DIVIDER_SHIFT);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530466
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530467 I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530468
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530469 temp = I915_READ(MIPI_DSI_FUNC_PRG(port));
470 temp &= ~VID_MODE_FORMAT_MASK;
471 I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp);
Shobhit Kumar339023e2014-04-09 13:59:34 +0530472
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530473 I915_WRITE(MIPI_DEVICE_READY(port), 0x1);
474 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530475 /* if disable packets are sent before sending shutdown packet then in
476 * some next enable sequence send turn on packet error is observed */
Jani Nikula593e0622015-01-23 15:30:56 +0200477 drm_panel_disable(intel_dsi->panel);
Shobhit Kumar13813082014-07-12 17:17:22 +0530478
Jani Nikula7f6a6a42015-01-16 14:27:19 +0200479 for_each_dsi_port(port, intel_dsi->ports)
480 wait_for_dsi_fifo_empty(intel_dsi, port);
Jani Nikula4e646492013-08-27 15:12:20 +0300481}
482
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530483static void intel_dsi_clear_device_ready(struct intel_encoder *encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300484{
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530485 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530486 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
487 enum port port;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530488 u32 val;
489
Jani Nikula4e646492013-08-27 15:12:20 +0300490 DRM_DEBUG_KMS("\n");
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530491 for_each_dsi_port(port, intel_dsi->ports) {
ymohanmabe4fc042013-08-27 23:40:56 +0300492
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530493 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
494 ULPS_STATE_ENTER);
495 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530496
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530497 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
498 ULPS_STATE_EXIT);
499 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530500
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530501 I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY |
502 ULPS_STATE_ENTER);
503 usleep_range(2000, 2500);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530504
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530505 /* Wait till Clock lanes are in LP-00 state for MIPI Port A
506 * only. MIPI Port C has no similar bit for checking
507 */
508 if (wait_for(((I915_READ(MIPI_PORT_CTRL(PORT_A)) & AFE_LATCHOUT)
509 == 0x00000), 30))
510 DRM_ERROR("DSI LP not going Low\n");
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530511
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530512 val = I915_READ(MIPI_PORT_CTRL(port));
513 /* Disable MIPI PHY transparent latch
514 * Common bit for both MIPI Port A & MIPI Port C
515 */
516 I915_WRITE(MIPI_PORT_CTRL(PORT_A), val & ~LP_OUTPUT_HOLD);
517 usleep_range(1000, 1500);
Shobhit Kumaraceb3652014-07-03 16:35:41 +0530518
Gaurav K Singh384f02a2014-12-05 14:22:44 +0530519 I915_WRITE(MIPI_DEVICE_READY(port), 0x00);
520 usleep_range(2000, 2500);
521 }
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530522
ymohanmabe4fc042013-08-27 23:40:56 +0300523 vlv_disable_dsi_pll(encoder);
Jani Nikula4e646492013-08-27 15:12:20 +0300524}
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530525
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530526static void intel_dsi_post_disable(struct intel_encoder *encoder)
527{
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530528 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530529 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530530 u32 val;
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530531
532 DRM_DEBUG_KMS("\n");
533
Imre Deakc315faf2014-05-27 19:00:09 +0300534 intel_dsi_disable(encoder);
535
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530536 intel_dsi_clear_device_ready(encoder);
537
Shobhit Kumar20e5bf62014-04-09 13:59:32 +0530538 val = I915_READ(DSPCLK_GATE_D);
539 val &= ~DPOUNIT_CLOCK_GATE_DISABLE;
540 I915_WRITE(DSPCLK_GATE_D, val);
541
Jani Nikula593e0622015-01-23 15:30:56 +0200542 drm_panel_unprepare(intel_dsi->panel);
Shobhit Kumardf38e652014-04-14 11:18:26 +0530543
544 msleep(intel_dsi->panel_off_delay);
545 msleep(intel_dsi->panel_pwr_cycle_delay);
Shobhit Kumar1dbd7cb2013-12-11 17:52:05 +0530546}
Jani Nikula4e646492013-08-27 15:12:20 +0300547
548static bool intel_dsi_get_hw_state(struct intel_encoder *encoder,
549 enum pipe *pipe)
550{
551 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530552 struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
553 struct drm_device *dev = encoder->base.dev;
Imre Deak6d129be2014-03-05 16:20:54 +0200554 enum intel_display_power_domain power_domain;
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530555 u32 dpi_enabled, func;
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200556 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300557
558 DRM_DEBUG_KMS("\n");
559
Imre Deak6d129be2014-03-05 16:20:54 +0200560 power_domain = intel_display_port_power_domain(encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200561 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200562 return false;
563
Jani Nikula4e646492013-08-27 15:12:20 +0300564 /* XXX: this only works for one DSI output */
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530565 for_each_dsi_port(port, intel_dsi->ports) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200566 func = I915_READ(MIPI_DSI_FUNC_PRG(port));
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530567 dpi_enabled = I915_READ(MIPI_PORT_CTRL(port)) &
568 DPI_ENABLE;
Jani Nikula4e646492013-08-27 15:12:20 +0300569
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530570 /* Due to some hardware limitations on BYT, MIPI Port C DPI
571 * Enable bit does not get set. To check whether DSI Port C
572 * was enabled in BIOS, check the Pipe B enable bit
573 */
574 if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) &&
575 (port == PORT_C))
576 dpi_enabled = I915_READ(PIPECONF(PIPE_B)) &
577 PIPECONF_ENABLE;
578
579 if (dpi_enabled || (func & CMD_MODE_DATA_WIDTH_MASK)) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200580 if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) {
Gaurav K Singhc0beefd2014-12-09 10:59:20 +0530581 *pipe = port == PORT_A ? PIPE_A : PIPE_B;
Jani Nikula4e646492013-08-27 15:12:20 +0300582 return true;
583 }
584 }
585 }
586
587 return false;
588}
589
590static void intel_dsi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200591 struct intel_crtc_state *pipe_config)
Jani Nikula4e646492013-08-27 15:12:20 +0300592{
Shobhit Kumarf573de52014-07-30 20:32:37 +0530593 u32 pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300594 DRM_DEBUG_KMS("\n");
595
Shobhit Kumarf573de52014-07-30 20:32:37 +0530596 /*
597 * DPLL_MD is not used in case of DSI, reading will get some default value
598 * set dpll_md = 0
599 */
600 pipe_config->dpll_hw_state.dpll_md = 0;
601
602 pclk = vlv_get_dsi_pclk(encoder, pipe_config->pipe_bpp);
603 if (!pclk)
604 return;
605
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200606 pipe_config->base.adjusted_mode.crtc_clock = pclk;
Shobhit Kumarf573de52014-07-30 20:32:37 +0530607 pipe_config->port_clock = pclk;
Jani Nikula4e646492013-08-27 15:12:20 +0300608}
609
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000610static enum drm_mode_status
611intel_dsi_mode_valid(struct drm_connector *connector,
612 struct drm_display_mode *mode)
Jani Nikula4e646492013-08-27 15:12:20 +0300613{
614 struct intel_connector *intel_connector = to_intel_connector(connector);
615 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
Jani Nikula4e646492013-08-27 15:12:20 +0300616
617 DRM_DEBUG_KMS("\n");
618
619 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
620 DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n");
621 return MODE_NO_DBLESCAN;
622 }
623
624 if (fixed_mode) {
625 if (mode->hdisplay > fixed_mode->hdisplay)
626 return MODE_PANEL;
627 if (mode->vdisplay > fixed_mode->vdisplay)
628 return MODE_PANEL;
629 }
630
Jani Nikula36d21f42015-01-16 14:27:20 +0200631 return MODE_OK;
Jani Nikula4e646492013-08-27 15:12:20 +0300632}
633
634/* return txclkesc cycles in terms of divider and duration in us */
635static u16 txclkesc(u32 divider, unsigned int us)
636{
637 switch (divider) {
638 case ESCAPE_CLOCK_DIVIDER_1:
639 default:
640 return 20 * us;
641 case ESCAPE_CLOCK_DIVIDER_2:
642 return 10 * us;
643 case ESCAPE_CLOCK_DIVIDER_4:
644 return 5 * us;
645 }
646}
647
648/* return pixels in terms of txbyteclkhs */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530649static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count,
650 u16 burst_mode_ratio)
Jani Nikula4e646492013-08-27 15:12:20 +0300651{
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530652 return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200653 8 * 100), lane_count);
Jani Nikula4e646492013-08-27 15:12:20 +0300654}
655
656static void set_dsi_timings(struct drm_encoder *encoder,
657 const struct drm_display_mode *mode)
658{
659 struct drm_device *dev = encoder->dev;
660 struct drm_i915_private *dev_priv = dev->dev_private;
661 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
662 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530663 enum port port;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200664 unsigned int bpp = intel_crtc->config->pipe_bpp;
Jani Nikula4e646492013-08-27 15:12:20 +0300665 unsigned int lane_count = intel_dsi->lane_count;
666
667 u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp;
668
669 hactive = mode->hdisplay;
670 hfp = mode->hsync_start - mode->hdisplay;
671 hsync = mode->hsync_end - mode->hsync_start;
672 hbp = mode->htotal - mode->hsync_end;
673
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530674 if (intel_dsi->dual_link) {
675 hactive /= 2;
676 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
677 hactive += intel_dsi->pixel_overlap;
678 hfp /= 2;
679 hsync /= 2;
680 hbp /= 2;
681 }
682
Jani Nikula4e646492013-08-27 15:12:20 +0300683 vfp = mode->vsync_start - mode->vdisplay;
684 vsync = mode->vsync_end - mode->vsync_start;
685 vbp = mode->vtotal - mode->vsync_end;
686
687 /* horizontal values are in terms of high speed byte clock */
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530688 hactive = txbyteclkhs(hactive, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200689 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530690 hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio);
691 hsync = txbyteclkhs(hsync, bpp, lane_count,
Daniel Vetter7f3de832014-07-30 22:34:27 +0200692 intel_dsi->burst_mode_ratio);
Shobhit Kumar7f0c8602014-07-30 20:34:57 +0530693 hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio);
Jani Nikula4e646492013-08-27 15:12:20 +0300694
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530695 for_each_dsi_port(port, intel_dsi->ports) {
696 I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive);
697 I915_WRITE(MIPI_HFP_COUNT(port), hfp);
Jani Nikula4e646492013-08-27 15:12:20 +0300698
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530699 /* meaningful for video mode non-burst sync pulse mode only,
700 * can be zero for non-burst sync events and burst modes */
701 I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync);
702 I915_WRITE(MIPI_HBP_COUNT(port), hbp);
Jani Nikula4e646492013-08-27 15:12:20 +0300703
Gaurav K Singhaa102d22014-12-04 10:58:54 +0530704 /* vertical values are in terms of lines */
705 I915_WRITE(MIPI_VFP_COUNT(port), vfp);
706 I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync);
707 I915_WRITE(MIPI_VBP_COUNT(port), vbp);
708 }
Jani Nikula4e646492013-08-27 15:12:20 +0300709}
710
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200711static void intel_dsi_prepare(struct intel_encoder *intel_encoder)
Jani Nikula4e646492013-08-27 15:12:20 +0300712{
713 struct drm_encoder *encoder = &intel_encoder->base;
714 struct drm_device *dev = encoder->dev;
715 struct drm_i915_private *dev_priv = dev->dev_private;
716 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
717 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
718 struct drm_display_mode *adjusted_mode =
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200719 &intel_crtc->config->base.adjusted_mode;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530720 enum port port;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200721 unsigned int bpp = intel_crtc->config->pipe_bpp;
Jani Nikula4e646492013-08-27 15:12:20 +0300722 u32 val, tmp;
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530723 u16 mode_hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300724
Jani Nikulae7d7cad2014-11-14 16:54:21 +0200725 DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe));
Jani Nikula4e646492013-08-27 15:12:20 +0300726
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530727 mode_hdisplay = adjusted_mode->hdisplay;
Jani Nikula4e646492013-08-27 15:12:20 +0300728
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530729 if (intel_dsi->dual_link) {
730 mode_hdisplay /= 2;
731 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
732 mode_hdisplay += intel_dsi->pixel_overlap;
733 }
Jani Nikula4e646492013-08-27 15:12:20 +0300734
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530735 for_each_dsi_port(port, intel_dsi->ports) {
736 /* escape clock divider, 20MHz, shared for A and C.
737 * device ready must be off when doing this! txclkesc? */
738 tmp = I915_READ(MIPI_CTRL(PORT_A));
739 tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
740 I915_WRITE(MIPI_CTRL(PORT_A), tmp | ESCAPE_CLOCK_DIVIDER_1);
Jani Nikula4e646492013-08-27 15:12:20 +0300741
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530742 /* read request priority is per pipe */
743 tmp = I915_READ(MIPI_CTRL(port));
744 tmp &= ~READ_REQUEST_PRIORITY_MASK;
745 I915_WRITE(MIPI_CTRL(port), tmp | READ_REQUEST_PRIORITY_HIGH);
Jani Nikula4e646492013-08-27 15:12:20 +0300746
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530747 /* XXX: why here, why like this? handling in irq handler?! */
748 I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff);
749 I915_WRITE(MIPI_INTR_EN(port), 0xffffffff);
750
751 I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg);
752
753 I915_WRITE(MIPI_DPI_RESOLUTION(port),
754 adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT |
755 mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT);
756 }
Jani Nikula4e646492013-08-27 15:12:20 +0300757
758 set_dsi_timings(encoder, adjusted_mode);
759
760 val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT;
761 if (is_cmd_mode(intel_dsi)) {
762 val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT;
763 val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */
764 } else {
765 val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT;
766
767 /* XXX: cross-check bpp vs. pixel format? */
768 val |= intel_dsi->pixel_format;
769 }
Jani Nikula4e646492013-08-27 15:12:20 +0300770
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530771 tmp = 0;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530772 if (intel_dsi->eotp_pkt == 0)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530773 tmp |= EOT_DISABLE;
Shobhit Kumarf1c79f12014-04-09 13:59:33 +0530774 if (intel_dsi->clock_stop)
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530775 tmp |= CLOCKSTOP;
Jani Nikula4e646492013-08-27 15:12:20 +0300776
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530777 for_each_dsi_port(port, intel_dsi->ports) {
778 I915_WRITE(MIPI_DSI_FUNC_PRG(port), val);
Jani Nikula4e646492013-08-27 15:12:20 +0300779
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530780 /* timeouts for recovery. one frame IIUC. if counter expires,
781 * EOT and stop state. */
Shobhit Kumarcf4dbd22014-04-14 11:18:25 +0530782
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530783 /*
784 * In burst mode, value greater than one DPI line Time in byte
785 * clock (txbyteclkhs) To timeout this timer 1+ of the above
786 * said value is recommended.
787 *
788 * In non-burst mode, Value greater than one DPI frame time in
789 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
790 * said value is recommended.
791 *
792 * In DBI only mode, value greater than one DBI frame time in
793 * byte clock(txbyteclkhs) To timeout this timer 1+ of the above
794 * said value is recommended.
795 */
Jani Nikula4e646492013-08-27 15:12:20 +0300796
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530797 if (is_vid_mode(intel_dsi) &&
798 intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
799 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
800 txbyteclkhs(adjusted_mode->htotal, bpp,
801 intel_dsi->lane_count,
802 intel_dsi->burst_mode_ratio) + 1);
803 } else {
804 I915_WRITE(MIPI_HS_TX_TIMEOUT(port),
805 txbyteclkhs(adjusted_mode->vtotal *
806 adjusted_mode->htotal,
807 bpp, intel_dsi->lane_count,
808 intel_dsi->burst_mode_ratio) + 1);
809 }
810 I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout);
811 I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port),
812 intel_dsi->turn_arnd_val);
813 I915_WRITE(MIPI_DEVICE_RESET_TIMER(port),
814 intel_dsi->rst_timer_val);
Jani Nikula4e646492013-08-27 15:12:20 +0300815
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530816 /* dphy stuff */
Jani Nikula4e646492013-08-27 15:12:20 +0300817
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530818 /* in terms of low power clock */
819 I915_WRITE(MIPI_INIT_COUNT(port),
820 txclkesc(intel_dsi->escape_clk_div, 100));
Jani Nikula4e646492013-08-27 15:12:20 +0300821
Gaurav K Singh24ee0e62014-12-05 14:24:21 +0530822
823 /* recovery disables */
824 I915_WRITE(MIPI_EOT_DISABLE(port), val);
825
826 /* in terms of low power clock */
827 I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count);
828
829 /* in terms of txbyteclkhs. actual high to low switch +
830 * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK.
831 *
832 * XXX: write MIPI_STOP_STATE_STALL?
833 */
834 I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port),
835 intel_dsi->hs_to_lp_count);
836
837 /* XXX: low power clock equivalence in terms of byte clock.
838 * the number of byte clocks occupied in one low power clock.
839 * based on txbyteclkhs and txclkesc.
840 * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL
841 * ) / 105.???
842 */
843 I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk);
844
845 /* the bw essential for transmitting 16 long packets containing
846 * 252 bytes meant for dcs write memory command is programmed in
847 * this register in terms of byte clocks. based on dsi transfer
848 * rate and the number of lanes configured the time taken to
849 * transmit 16 long packets in a dsi stream varies. */
850 I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer);
851
852 I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port),
853 intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT |
854 intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT);
855
856 if (is_vid_mode(intel_dsi))
857 /* Some panels might have resolution which is not a
858 * multiple of 64 like 1366 x 768. Enable RANDOM
859 * resolution support for such panels by default */
860 I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port),
861 intel_dsi->video_frmt_cfg_bits |
862 intel_dsi->video_mode_format |
863 IP_TG_CONFIG |
864 RANDOM_DPI_DISPLAY_RESOLUTION);
865 }
Jani Nikula4e646492013-08-27 15:12:20 +0300866}
867
Daniel Vetter07e4fb92014-04-24 23:54:59 +0200868static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder)
869{
870 DRM_DEBUG_KMS("\n");
871
872 intel_dsi_prepare(encoder);
873
874 vlv_enable_dsi_pll(encoder);
875}
876
Jani Nikula4e646492013-08-27 15:12:20 +0300877static enum drm_connector_status
878intel_dsi_detect(struct drm_connector *connector, bool force)
879{
Jani Nikula36d21f42015-01-16 14:27:20 +0200880 return connector_status_connected;
Jani Nikula4e646492013-08-27 15:12:20 +0300881}
882
883static int intel_dsi_get_modes(struct drm_connector *connector)
884{
885 struct intel_connector *intel_connector = to_intel_connector(connector);
886 struct drm_display_mode *mode;
887
888 DRM_DEBUG_KMS("\n");
889
890 if (!intel_connector->panel.fixed_mode) {
891 DRM_DEBUG_KMS("no fixed mode\n");
892 return 0;
893 }
894
895 mode = drm_mode_duplicate(connector->dev,
896 intel_connector->panel.fixed_mode);
897 if (!mode) {
898 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
899 return 0;
900 }
901
902 drm_mode_probed_add(connector, mode);
903 return 1;
904}
905
Jani Nikula593e0622015-01-23 15:30:56 +0200906static void intel_dsi_connector_destroy(struct drm_connector *connector)
Jani Nikula4e646492013-08-27 15:12:20 +0300907{
908 struct intel_connector *intel_connector = to_intel_connector(connector);
909
910 DRM_DEBUG_KMS("\n");
911 intel_panel_fini(&intel_connector->panel);
Jani Nikula4e646492013-08-27 15:12:20 +0300912 drm_connector_cleanup(connector);
913 kfree(connector);
914}
915
Jani Nikula593e0622015-01-23 15:30:56 +0200916static void intel_dsi_encoder_destroy(struct drm_encoder *encoder)
917{
918 struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder);
919
920 if (intel_dsi->panel) {
921 drm_panel_detach(intel_dsi->panel);
922 /* XXX: Logically this call belongs in the panel driver. */
923 drm_panel_remove(intel_dsi->panel);
924 }
925 intel_encoder_destroy(encoder);
926}
927
Jani Nikula4e646492013-08-27 15:12:20 +0300928static const struct drm_encoder_funcs intel_dsi_funcs = {
Jani Nikula593e0622015-01-23 15:30:56 +0200929 .destroy = intel_dsi_encoder_destroy,
Jani Nikula4e646492013-08-27 15:12:20 +0300930};
931
932static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = {
933 .get_modes = intel_dsi_get_modes,
934 .mode_valid = intel_dsi_mode_valid,
935 .best_encoder = intel_best_encoder,
936};
937
938static const struct drm_connector_funcs intel_dsi_connector_funcs = {
939 .dpms = intel_connector_dpms,
940 .detect = intel_dsi_detect,
Jani Nikula593e0622015-01-23 15:30:56 +0200941 .destroy = intel_dsi_connector_destroy,
Jani Nikula4e646492013-08-27 15:12:20 +0300942 .fill_modes = drm_helper_probe_single_connector_modes,
Matt Roper2545e4a2015-01-22 16:51:27 -0800943 .atomic_get_property = intel_connector_atomic_get_property,
Matt Roperc6f95f22015-01-22 16:50:32 -0800944 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Jani Nikula4e646492013-08-27 15:12:20 +0300945};
946
Damien Lespiau4328633d2014-05-28 12:30:56 +0100947void intel_dsi_init(struct drm_device *dev)
Jani Nikula4e646492013-08-27 15:12:20 +0300948{
949 struct intel_dsi *intel_dsi;
950 struct intel_encoder *intel_encoder;
951 struct drm_encoder *encoder;
952 struct intel_connector *intel_connector;
953 struct drm_connector *connector;
Jani Nikula593e0622015-01-23 15:30:56 +0200954 struct drm_display_mode *scan, *fixed_mode = NULL;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530955 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula7e9804f2015-01-16 14:27:23 +0200956 enum port port;
Jani Nikula4e646492013-08-27 15:12:20 +0300957 unsigned int i;
958
959 DRM_DEBUG_KMS("\n");
960
Shobhit Kumar3e6bd012014-05-27 19:33:59 +0530961 /* There is no detection method for MIPI so rely on VBT */
962 if (!dev_priv->vbt.has_mipi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100963 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300964
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530965 if (IS_VALLEYVIEW(dev)) {
966 dev_priv->mipi_mmio_base = VLV_MIPI_BASE;
967 } else {
968 DRM_ERROR("Unsupported Mipi device to reg base");
Christoph Jaeger868d6652014-06-13 21:51:22 +0200969 return;
Shashank Sharmab6fdd0f2014-05-19 20:54:03 +0530970 }
971
Jani Nikula4e646492013-08-27 15:12:20 +0300972 intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL);
973 if (!intel_dsi)
Damien Lespiau4328633d2014-05-28 12:30:56 +0100974 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300975
976 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
977 if (!intel_connector) {
978 kfree(intel_dsi);
Damien Lespiau4328633d2014-05-28 12:30:56 +0100979 return;
Jani Nikula4e646492013-08-27 15:12:20 +0300980 }
981
982 intel_encoder = &intel_dsi->base;
983 encoder = &intel_encoder->base;
984 intel_dsi->attached_connector = intel_connector;
985
Jani Nikula4e646492013-08-27 15:12:20 +0300986 connector = &intel_connector->base;
987
988 drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI);
989
990 /* XXX: very likely not all of these are needed */
991 intel_encoder->hot_plug = intel_dsi_hot_plug;
992 intel_encoder->compute_config = intel_dsi_compute_config;
993 intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable;
994 intel_encoder->pre_enable = intel_dsi_pre_enable;
Shobhit Kumar2634fd72014-04-09 13:59:31 +0530995 intel_encoder->enable = intel_dsi_enable_nop;
Imre Deakc315faf2014-05-27 19:00:09 +0300996 intel_encoder->disable = intel_dsi_pre_disable;
Jani Nikula4e646492013-08-27 15:12:20 +0300997 intel_encoder->post_disable = intel_dsi_post_disable;
998 intel_encoder->get_hw_state = intel_dsi_get_hw_state;
999 intel_encoder->get_config = intel_dsi_get_config;
1000
1001 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak4932e2c2014-02-11 17:12:48 +02001002 intel_connector->unregister = intel_connector_unregister;
Jani Nikula4e646492013-08-27 15:12:20 +03001003
Jani Nikulae7d7cad2014-11-14 16:54:21 +02001004 /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */
Jani Nikula7e9804f2015-01-16 14:27:23 +02001005 if (dev_priv->vbt.dsi.config->dual_link) {
1006 /* XXX: does dual link work on either pipe? */
1007 intel_encoder->crtc_mask = (1 << PIPE_A);
1008 intel_dsi->ports = ((1 << PORT_A) | (1 << PORT_C));
1009 } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +02001010 intel_encoder->crtc_mask = (1 << PIPE_A);
Jani Nikula17af40a2014-11-14 16:54:22 +02001011 intel_dsi->ports = (1 << PORT_A);
1012 } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) {
Jani Nikulae7d7cad2014-11-14 16:54:21 +02001013 intel_encoder->crtc_mask = (1 << PIPE_B);
Jani Nikula17af40a2014-11-14 16:54:22 +02001014 intel_dsi->ports = (1 << PORT_C);
1015 }
Jani Nikulae7d7cad2014-11-14 16:54:21 +02001016
Jani Nikula7e9804f2015-01-16 14:27:23 +02001017 /* Create a DSI host (and a device) for each port. */
1018 for_each_dsi_port(port, intel_dsi->ports) {
1019 struct intel_dsi_host *host;
1020
1021 host = intel_dsi_host_init(intel_dsi, port);
1022 if (!host)
1023 goto err;
1024
1025 intel_dsi->dsi_hosts[port] = host;
1026 }
1027
Jani Nikula593e0622015-01-23 15:30:56 +02001028 for (i = 0; i < ARRAY_SIZE(intel_dsi_drivers); i++) {
1029 intel_dsi->panel = intel_dsi_drivers[i].init(intel_dsi,
1030 intel_dsi_drivers[i].panel_id);
1031 if (intel_dsi->panel)
Jani Nikula4e646492013-08-27 15:12:20 +03001032 break;
1033 }
1034
Jani Nikula593e0622015-01-23 15:30:56 +02001035 if (!intel_dsi->panel) {
Jani Nikula4e646492013-08-27 15:12:20 +03001036 DRM_DEBUG_KMS("no device found\n");
1037 goto err;
1038 }
1039
1040 intel_encoder->type = INTEL_OUTPUT_DSI;
Ville Syrjäläbc079e82014-03-03 16:15:28 +02001041 intel_encoder->cloneable = 0;
Jani Nikula4e646492013-08-27 15:12:20 +03001042 drm_connector_init(dev, connector, &intel_dsi_connector_funcs,
1043 DRM_MODE_CONNECTOR_DSI);
1044
1045 drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs);
1046
1047 connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/
1048 connector->interlace_allowed = false;
1049 connector->doublescan_allowed = false;
1050
1051 intel_connector_attach_encoder(intel_connector, intel_encoder);
1052
Thomas Wood34ea3d32014-05-29 16:57:41 +01001053 drm_connector_register(connector);
Jani Nikula4e646492013-08-27 15:12:20 +03001054
Jani Nikula593e0622015-01-23 15:30:56 +02001055 drm_panel_attach(intel_dsi->panel, connector);
1056
1057 mutex_lock(&dev->mode_config.mutex);
1058 drm_panel_get_modes(intel_dsi->panel);
1059 list_for_each_entry(scan, &connector->probed_modes, head) {
1060 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
1061 fixed_mode = drm_mode_duplicate(dev, scan);
1062 break;
1063 }
1064 }
1065 mutex_unlock(&dev->mode_config.mutex);
1066
Jani Nikula4e646492013-08-27 15:12:20 +03001067 if (!fixed_mode) {
1068 DRM_DEBUG_KMS("no fixed mode\n");
1069 goto err;
1070 }
1071
Vandana Kannan4b6ed682014-02-11 14:26:36 +05301072 intel_panel_init(&intel_connector->panel, fixed_mode, NULL);
Jani Nikula4e646492013-08-27 15:12:20 +03001073
Damien Lespiau4328633d2014-05-28 12:30:56 +01001074 return;
Jani Nikula4e646492013-08-27 15:12:20 +03001075
1076err:
1077 drm_encoder_cleanup(&intel_encoder->base);
1078 kfree(intel_dsi);
1079 kfree(intel_connector);
Jani Nikula4e646492013-08-27 15:12:20 +03001080}