]>
Commit | Line | Data |
---|---|---|
4e646495 JN |
1 | /* |
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> | |
c6f95f27 | 27 | #include <drm/drm_atomic_helper.h> |
4e646495 JN |
28 | #include <drm/drm_crtc.h> |
29 | #include <drm/drm_edid.h> | |
30 | #include <drm/i915_drm.h> | |
593e0622 | 31 | #include <drm/drm_panel.h> |
7e9804fd | 32 | #include <drm/drm_mipi_dsi.h> |
4e646495 | 33 | #include <linux/slab.h> |
fc45e821 | 34 | #include <linux/gpio/consumer.h> |
4e646495 JN |
35 | #include "i915_drv.h" |
36 | #include "intel_drv.h" | |
37 | #include "intel_dsi.h" | |
4e646495 | 38 | |
593e0622 JN |
39 | static const struct { |
40 | u16 panel_id; | |
41 | struct drm_panel * (*init)(struct intel_dsi *intel_dsi, u16 panel_id); | |
42 | } intel_dsi_drivers[] = { | |
2ab8b458 SK |
43 | { |
44 | .panel_id = MIPI_DSI_GENERIC_PANEL_ID, | |
593e0622 | 45 | .init = vbt_panel_init, |
2ab8b458 | 46 | }, |
4e646495 JN |
47 | }; |
48 | ||
43367ec9 R |
49 | enum mipi_dsi_pixel_format pixel_format_from_register_bits(u32 fmt) |
50 | { | |
51 | /* It just so happens the VBT matches register contents. */ | |
52 | switch (fmt) { | |
53 | case VID_MODE_FORMAT_RGB888: | |
54 | return MIPI_DSI_FMT_RGB888; | |
55 | case VID_MODE_FORMAT_RGB666: | |
56 | return MIPI_DSI_FMT_RGB666; | |
57 | case VID_MODE_FORMAT_RGB666_PACKED: | |
58 | return MIPI_DSI_FMT_RGB666_PACKED; | |
59 | case VID_MODE_FORMAT_RGB565: | |
60 | return MIPI_DSI_FMT_RGB565; | |
61 | default: | |
62 | MISSING_CASE(fmt); | |
63 | return MIPI_DSI_FMT_RGB666; | |
64 | } | |
65 | } | |
66 | ||
7f6a6a4a | 67 | static void wait_for_dsi_fifo_empty(struct intel_dsi *intel_dsi, enum port port) |
3b1808bf JN |
68 | { |
69 | struct drm_encoder *encoder = &intel_dsi->base.base; | |
70 | struct drm_device *dev = encoder->dev; | |
71 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3b1808bf JN |
72 | u32 mask; |
73 | ||
74 | mask = LP_CTRL_FIFO_EMPTY | HS_CTRL_FIFO_EMPTY | | |
75 | LP_DATA_FIFO_EMPTY | HS_DATA_FIFO_EMPTY; | |
76 | ||
77 | if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & mask) == mask, 100)) | |
78 | DRM_ERROR("DPI FIFOs are not empty\n"); | |
79 | } | |
80 | ||
f0f59a00 VS |
81 | static void write_data(struct drm_i915_private *dev_priv, |
82 | i915_reg_t reg, | |
7e9804fd JN |
83 | const u8 *data, u32 len) |
84 | { | |
85 | u32 i, j; | |
86 | ||
87 | for (i = 0; i < len; i += 4) { | |
88 | u32 val = 0; | |
89 | ||
90 | for (j = 0; j < min_t(u32, len - i, 4); j++) | |
91 | val |= *data++ << 8 * j; | |
92 | ||
93 | I915_WRITE(reg, val); | |
94 | } | |
95 | } | |
96 | ||
f0f59a00 VS |
97 | static void read_data(struct drm_i915_private *dev_priv, |
98 | i915_reg_t reg, | |
7e9804fd JN |
99 | u8 *data, u32 len) |
100 | { | |
101 | u32 i, j; | |
102 | ||
103 | for (i = 0; i < len; i += 4) { | |
104 | u32 val = I915_READ(reg); | |
105 | ||
106 | for (j = 0; j < min_t(u32, len - i, 4); j++) | |
107 | *data++ = val >> 8 * j; | |
108 | } | |
109 | } | |
110 | ||
111 | static ssize_t intel_dsi_host_transfer(struct mipi_dsi_host *host, | |
112 | const struct mipi_dsi_msg *msg) | |
113 | { | |
114 | struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host); | |
115 | struct drm_device *dev = intel_dsi_host->intel_dsi->base.base.dev; | |
116 | struct drm_i915_private *dev_priv = dev->dev_private; | |
117 | enum port port = intel_dsi_host->port; | |
118 | struct mipi_dsi_packet packet; | |
119 | ssize_t ret; | |
120 | const u8 *header, *data; | |
f0f59a00 VS |
121 | i915_reg_t data_reg, ctrl_reg; |
122 | u32 data_mask, ctrl_mask; | |
7e9804fd JN |
123 | |
124 | ret = mipi_dsi_create_packet(&packet, msg); | |
125 | if (ret < 0) | |
126 | return ret; | |
127 | ||
128 | header = packet.header; | |
129 | data = packet.payload; | |
130 | ||
131 | if (msg->flags & MIPI_DSI_MSG_USE_LPM) { | |
132 | data_reg = MIPI_LP_GEN_DATA(port); | |
133 | data_mask = LP_DATA_FIFO_FULL; | |
134 | ctrl_reg = MIPI_LP_GEN_CTRL(port); | |
135 | ctrl_mask = LP_CTRL_FIFO_FULL; | |
136 | } else { | |
137 | data_reg = MIPI_HS_GEN_DATA(port); | |
138 | data_mask = HS_DATA_FIFO_FULL; | |
139 | ctrl_reg = MIPI_HS_GEN_CTRL(port); | |
140 | ctrl_mask = HS_CTRL_FIFO_FULL; | |
141 | } | |
142 | ||
143 | /* note: this is never true for reads */ | |
144 | if (packet.payload_length) { | |
145 | ||
146 | if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & data_mask) == 0, 50)) | |
147 | DRM_ERROR("Timeout waiting for HS/LP DATA FIFO !full\n"); | |
148 | ||
149 | write_data(dev_priv, data_reg, packet.payload, | |
150 | packet.payload_length); | |
151 | } | |
152 | ||
153 | if (msg->rx_len) { | |
154 | I915_WRITE(MIPI_INTR_STAT(port), GEN_READ_DATA_AVAIL); | |
155 | } | |
156 | ||
157 | if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & ctrl_mask) == 0, 50)) { | |
158 | DRM_ERROR("Timeout waiting for HS/LP CTRL FIFO !full\n"); | |
159 | } | |
160 | ||
161 | I915_WRITE(ctrl_reg, header[2] << 16 | header[1] << 8 | header[0]); | |
162 | ||
163 | /* ->rx_len is set only for reads */ | |
164 | if (msg->rx_len) { | |
165 | data_mask = GEN_READ_DATA_AVAIL; | |
166 | if (wait_for((I915_READ(MIPI_INTR_STAT(port)) & data_mask) == data_mask, 50)) | |
167 | DRM_ERROR("Timeout waiting for read data.\n"); | |
168 | ||
169 | read_data(dev_priv, data_reg, msg->rx_buf, msg->rx_len); | |
170 | } | |
171 | ||
172 | /* XXX: fix for reads and writes */ | |
173 | return 4 + packet.payload_length; | |
174 | } | |
175 | ||
176 | static int intel_dsi_host_attach(struct mipi_dsi_host *host, | |
177 | struct mipi_dsi_device *dsi) | |
178 | { | |
179 | return 0; | |
180 | } | |
181 | ||
182 | static int intel_dsi_host_detach(struct mipi_dsi_host *host, | |
183 | struct mipi_dsi_device *dsi) | |
184 | { | |
185 | return 0; | |
186 | } | |
187 | ||
188 | static const struct mipi_dsi_host_ops intel_dsi_host_ops = { | |
189 | .attach = intel_dsi_host_attach, | |
190 | .detach = intel_dsi_host_detach, | |
191 | .transfer = intel_dsi_host_transfer, | |
192 | }; | |
193 | ||
194 | static struct intel_dsi_host *intel_dsi_host_init(struct intel_dsi *intel_dsi, | |
195 | enum port port) | |
196 | { | |
197 | struct intel_dsi_host *host; | |
198 | struct mipi_dsi_device *device; | |
199 | ||
200 | host = kzalloc(sizeof(*host), GFP_KERNEL); | |
201 | if (!host) | |
202 | return NULL; | |
203 | ||
204 | host->base.ops = &intel_dsi_host_ops; | |
205 | host->intel_dsi = intel_dsi; | |
206 | host->port = port; | |
207 | ||
208 | /* | |
209 | * We should call mipi_dsi_host_register(&host->base) here, but we don't | |
210 | * have a host->dev, and we don't have OF stuff either. So just use the | |
211 | * dsi framework as a library and hope for the best. Create the dsi | |
212 | * devices by ourselves here too. Need to be careful though, because we | |
213 | * don't initialize any of the driver model devices here. | |
214 | */ | |
215 | device = kzalloc(sizeof(*device), GFP_KERNEL); | |
216 | if (!device) { | |
217 | kfree(host); | |
218 | return NULL; | |
219 | } | |
220 | ||
221 | device->host = &host->base; | |
222 | host->device = device; | |
223 | ||
224 | return host; | |
225 | } | |
226 | ||
a2581a9e JN |
227 | /* |
228 | * send a video mode command | |
229 | * | |
230 | * XXX: commands with data in MIPI_DPI_DATA? | |
231 | */ | |
232 | static int dpi_send_cmd(struct intel_dsi *intel_dsi, u32 cmd, bool hs, | |
233 | enum port port) | |
234 | { | |
235 | struct drm_encoder *encoder = &intel_dsi->base.base; | |
236 | struct drm_device *dev = encoder->dev; | |
237 | struct drm_i915_private *dev_priv = dev->dev_private; | |
238 | u32 mask; | |
239 | ||
240 | /* XXX: pipe, hs */ | |
241 | if (hs) | |
242 | cmd &= ~DPI_LP_MODE; | |
243 | else | |
244 | cmd |= DPI_LP_MODE; | |
245 | ||
246 | /* clear bit */ | |
247 | I915_WRITE(MIPI_INTR_STAT(port), SPL_PKT_SENT_INTERRUPT); | |
248 | ||
249 | /* XXX: old code skips write if control unchanged */ | |
250 | if (cmd == I915_READ(MIPI_DPI_CONTROL(port))) | |
251 | DRM_ERROR("Same special packet %02x twice in a row.\n", cmd); | |
252 | ||
253 | I915_WRITE(MIPI_DPI_CONTROL(port), cmd); | |
254 | ||
255 | mask = SPL_PKT_SENT_INTERRUPT; | |
256 | if (wait_for((I915_READ(MIPI_INTR_STAT(port)) & mask) == mask, 100)) | |
257 | DRM_ERROR("Video mode command 0x%08x send failed.\n", cmd); | |
258 | ||
259 | return 0; | |
260 | } | |
261 | ||
e9fe51c6 | 262 | static void band_gap_reset(struct drm_i915_private *dev_priv) |
4ce8c9a7 | 263 | { |
a580516d | 264 | mutex_lock(&dev_priv->sb_lock); |
4ce8c9a7 | 265 | |
e9fe51c6 SK |
266 | vlv_flisdsi_write(dev_priv, 0x08, 0x0001); |
267 | vlv_flisdsi_write(dev_priv, 0x0F, 0x0005); | |
268 | vlv_flisdsi_write(dev_priv, 0x0F, 0x0025); | |
269 | udelay(150); | |
270 | vlv_flisdsi_write(dev_priv, 0x0F, 0x0000); | |
271 | vlv_flisdsi_write(dev_priv, 0x08, 0x0000); | |
4ce8c9a7 | 272 | |
a580516d | 273 | mutex_unlock(&dev_priv->sb_lock); |
4ce8c9a7 SK |
274 | } |
275 | ||
4e646495 JN |
276 | static inline bool is_vid_mode(struct intel_dsi *intel_dsi) |
277 | { | |
dfba2e2d | 278 | return intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE; |
4e646495 JN |
279 | } |
280 | ||
281 | static inline bool is_cmd_mode(struct intel_dsi *intel_dsi) | |
282 | { | |
dfba2e2d | 283 | return intel_dsi->operation_mode == INTEL_DSI_COMMAND_MODE; |
4e646495 JN |
284 | } |
285 | ||
4e646495 | 286 | static bool intel_dsi_compute_config(struct intel_encoder *encoder, |
a65347ba | 287 | struct intel_crtc_state *pipe_config) |
4e646495 | 288 | { |
4d1de975 | 289 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
4e646495 JN |
290 | struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi, |
291 | base); | |
292 | struct intel_connector *intel_connector = intel_dsi->attached_connector; | |
f4ee265f VS |
293 | struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc); |
294 | const struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode; | |
a65347ba | 295 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
47eacbab | 296 | int ret; |
4e646495 JN |
297 | |
298 | DRM_DEBUG_KMS("\n"); | |
299 | ||
a65347ba JN |
300 | pipe_config->has_dsi_encoder = true; |
301 | ||
f4ee265f | 302 | if (fixed_mode) { |
4e646495 JN |
303 | intel_fixed_panel_mode(fixed_mode, adjusted_mode); |
304 | ||
f4ee265f VS |
305 | if (HAS_GMCH_DISPLAY(dev_priv)) |
306 | intel_gmch_panel_fitting(crtc, pipe_config, | |
307 | intel_connector->panel.fitting_mode); | |
308 | else | |
309 | intel_pch_panel_fitting(crtc, pipe_config, | |
310 | intel_connector->panel.fitting_mode); | |
311 | } | |
312 | ||
f573de5a SK |
313 | /* DSI uses short packets for sync events, so clear mode flags for DSI */ |
314 | adjusted_mode->flags = 0; | |
315 | ||
4d1de975 JN |
316 | if (IS_BROXTON(dev_priv)) { |
317 | /* Dual link goes to DSI transcoder A. */ | |
318 | if (intel_dsi->ports == BIT(PORT_C)) | |
319 | pipe_config->cpu_transcoder = TRANSCODER_DSI_C; | |
320 | else | |
321 | pipe_config->cpu_transcoder = TRANSCODER_DSI_A; | |
322 | } | |
323 | ||
47eacbab VS |
324 | ret = intel_compute_dsi_pll(encoder, pipe_config); |
325 | if (ret) | |
326 | return false; | |
327 | ||
cd2d34d9 VS |
328 | pipe_config->clock_set = true; |
329 | ||
4e646495 JN |
330 | return true; |
331 | } | |
332 | ||
37ab0810 | 333 | static void bxt_dsi_device_ready(struct intel_encoder *encoder) |
5505a244 | 334 | { |
37ab0810 | 335 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
5505a244 | 336 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
369602d3 | 337 | enum port port; |
37ab0810 | 338 | u32 val; |
5505a244 | 339 | |
37ab0810 | 340 | DRM_DEBUG_KMS("\n"); |
a9da9bce | 341 | |
37ab0810 | 342 | /* Exit Low power state in 4 steps*/ |
369602d3 | 343 | for_each_dsi_port(port, intel_dsi->ports) { |
5505a244 | 344 | |
37ab0810 SS |
345 | /* 1. Enable MIPI PHY transparent latch */ |
346 | val = I915_READ(BXT_MIPI_PORT_CTRL(port)); | |
347 | I915_WRITE(BXT_MIPI_PORT_CTRL(port), val | LP_OUTPUT_HOLD); | |
348 | usleep_range(2000, 2500); | |
349 | ||
350 | /* 2. Enter ULPS */ | |
351 | val = I915_READ(MIPI_DEVICE_READY(port)); | |
352 | val &= ~ULPS_STATE_MASK; | |
353 | val |= (ULPS_STATE_ENTER | DEVICE_READY); | |
354 | I915_WRITE(MIPI_DEVICE_READY(port), val); | |
355 | usleep_range(2, 3); | |
356 | ||
357 | /* 3. Exit ULPS */ | |
358 | val = I915_READ(MIPI_DEVICE_READY(port)); | |
359 | val &= ~ULPS_STATE_MASK; | |
360 | val |= (ULPS_STATE_EXIT | DEVICE_READY); | |
361 | I915_WRITE(MIPI_DEVICE_READY(port), val); | |
362 | usleep_range(1000, 1500); | |
5505a244 | 363 | |
37ab0810 SS |
364 | /* Clear ULPS and set device ready */ |
365 | val = I915_READ(MIPI_DEVICE_READY(port)); | |
366 | val &= ~ULPS_STATE_MASK; | |
367 | val |= DEVICE_READY; | |
368 | I915_WRITE(MIPI_DEVICE_READY(port), val); | |
369602d3 | 369 | } |
5505a244 GS |
370 | } |
371 | ||
37ab0810 | 372 | static void vlv_dsi_device_ready(struct intel_encoder *encoder) |
4e646495 | 373 | { |
1dbd7cb2 | 374 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
24ee0e64 GS |
375 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
376 | enum port port; | |
1dbd7cb2 SK |
377 | u32 val; |
378 | ||
4e646495 | 379 | DRM_DEBUG_KMS("\n"); |
4e646495 | 380 | |
a580516d | 381 | mutex_lock(&dev_priv->sb_lock); |
2095f9fc SK |
382 | /* program rcomp for compliance, reduce from 50 ohms to 45 ohms |
383 | * needed everytime after power gate */ | |
384 | vlv_flisdsi_write(dev_priv, 0x04, 0x0004); | |
a580516d | 385 | mutex_unlock(&dev_priv->sb_lock); |
2095f9fc SK |
386 | |
387 | /* bandgap reset is needed after everytime we do power gate */ | |
388 | band_gap_reset(dev_priv); | |
389 | ||
24ee0e64 | 390 | for_each_dsi_port(port, intel_dsi->ports) { |
aceb365c | 391 | |
24ee0e64 GS |
392 | I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER); |
393 | usleep_range(2500, 3000); | |
aceb365c | 394 | |
bf344e80 GS |
395 | /* Enable MIPI PHY transparent latch |
396 | * Common bit for both MIPI Port A & MIPI Port C | |
397 | * No similar bit in MIPI Port C reg | |
398 | */ | |
4ba7d93a | 399 | val = I915_READ(MIPI_PORT_CTRL(PORT_A)); |
bf344e80 | 400 | I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD); |
24ee0e64 | 401 | usleep_range(1000, 1500); |
aceb365c | 402 | |
24ee0e64 GS |
403 | I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT); |
404 | usleep_range(2500, 3000); | |
405 | ||
406 | I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY); | |
407 | usleep_range(2500, 3000); | |
408 | } | |
1dbd7cb2 | 409 | } |
1dbd7cb2 | 410 | |
37ab0810 SS |
411 | static void intel_dsi_device_ready(struct intel_encoder *encoder) |
412 | { | |
413 | struct drm_device *dev = encoder->base.dev; | |
414 | ||
666a4537 | 415 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
37ab0810 SS |
416 | vlv_dsi_device_ready(encoder); |
417 | else if (IS_BROXTON(dev)) | |
418 | bxt_dsi_device_ready(encoder); | |
419 | } | |
420 | ||
421 | static void intel_dsi_port_enable(struct intel_encoder *encoder) | |
422 | { | |
423 | struct drm_device *dev = encoder->base.dev; | |
424 | struct drm_i915_private *dev_priv = dev->dev_private; | |
425 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); | |
426 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); | |
427 | enum port port; | |
37ab0810 SS |
428 | |
429 | if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) { | |
f0f59a00 VS |
430 | u32 temp; |
431 | ||
37ab0810 SS |
432 | temp = I915_READ(VLV_CHICKEN_3); |
433 | temp &= ~PIXEL_OVERLAP_CNT_MASK | | |
434 | intel_dsi->pixel_overlap << | |
435 | PIXEL_OVERLAP_CNT_SHIFT; | |
436 | I915_WRITE(VLV_CHICKEN_3, temp); | |
437 | } | |
438 | ||
439 | for_each_dsi_port(port, intel_dsi->ports) { | |
f0f59a00 VS |
440 | i915_reg_t port_ctrl = IS_BROXTON(dev) ? |
441 | BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port); | |
442 | u32 temp; | |
37ab0810 SS |
443 | |
444 | temp = I915_READ(port_ctrl); | |
445 | ||
446 | temp &= ~LANE_CONFIGURATION_MASK; | |
447 | temp &= ~DUAL_LINK_MODE_MASK; | |
448 | ||
701d25b4 | 449 | if (intel_dsi->ports == (BIT(PORT_A) | BIT(PORT_C))) { |
37ab0810 SS |
450 | temp |= (intel_dsi->dual_link - 1) |
451 | << DUAL_LINK_MODE_SHIFT; | |
452 | temp |= intel_crtc->pipe ? | |
453 | LANE_CONFIGURATION_DUAL_LINK_B : | |
454 | LANE_CONFIGURATION_DUAL_LINK_A; | |
455 | } | |
456 | /* assert ip_tg_enable signal */ | |
457 | I915_WRITE(port_ctrl, temp | DPI_ENABLE); | |
458 | POSTING_READ(port_ctrl); | |
459 | } | |
460 | } | |
461 | ||
462 | static void intel_dsi_port_disable(struct intel_encoder *encoder) | |
463 | { | |
464 | struct drm_device *dev = encoder->base.dev; | |
465 | struct drm_i915_private *dev_priv = dev->dev_private; | |
466 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); | |
467 | enum port port; | |
37ab0810 SS |
468 | |
469 | for_each_dsi_port(port, intel_dsi->ports) { | |
f0f59a00 VS |
470 | i915_reg_t port_ctrl = IS_BROXTON(dev) ? |
471 | BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port); | |
472 | u32 temp; | |
473 | ||
37ab0810 | 474 | /* de-assert ip_tg_enable signal */ |
b389a45c SS |
475 | temp = I915_READ(port_ctrl); |
476 | I915_WRITE(port_ctrl, temp & ~DPI_ENABLE); | |
477 | POSTING_READ(port_ctrl); | |
37ab0810 SS |
478 | } |
479 | } | |
480 | ||
1dbd7cb2 SK |
481 | static void intel_dsi_enable(struct intel_encoder *encoder) |
482 | { | |
483 | struct drm_device *dev = encoder->base.dev; | |
484 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1dbd7cb2 | 485 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
4934b656 | 486 | enum port port; |
1dbd7cb2 SK |
487 | |
488 | DRM_DEBUG_KMS("\n"); | |
b9f5e07d | 489 | |
4934b656 JN |
490 | if (is_cmd_mode(intel_dsi)) { |
491 | for_each_dsi_port(port, intel_dsi->ports) | |
492 | I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4); | |
493 | } else { | |
4e646495 | 494 | msleep(20); /* XXX */ |
f03e4179 | 495 | for_each_dsi_port(port, intel_dsi->ports) |
a2581a9e | 496 | dpi_send_cmd(intel_dsi, TURN_ON, false, port); |
4e646495 JN |
497 | msleep(100); |
498 | ||
593e0622 | 499 | drm_panel_enable(intel_dsi->panel); |
2634fd7f | 500 | |
7f6a6a4a JN |
501 | for_each_dsi_port(port, intel_dsi->ports) |
502 | wait_for_dsi_fifo_empty(intel_dsi, port); | |
1381308b | 503 | |
5505a244 | 504 | intel_dsi_port_enable(encoder); |
4e646495 | 505 | } |
b029e66f SK |
506 | |
507 | intel_panel_enable_backlight(intel_dsi->attached_connector); | |
2634fd7f SK |
508 | } |
509 | ||
e3488e75 JN |
510 | static void intel_dsi_prepare(struct intel_encoder *intel_encoder); |
511 | ||
2634fd7f SK |
512 | static void intel_dsi_pre_enable(struct intel_encoder *encoder) |
513 | { | |
20e5bf66 SK |
514 | struct drm_device *dev = encoder->base.dev; |
515 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2634fd7f | 516 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
47eacbab | 517 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
7f6a6a4a | 518 | enum port port; |
2634fd7f SK |
519 | |
520 | DRM_DEBUG_KMS("\n"); | |
521 | ||
f00b5689 VS |
522 | /* |
523 | * The BIOS may leave the PLL in a wonky state where it doesn't | |
524 | * lock. It needs to be fully powered down to fix it. | |
525 | */ | |
526 | intel_disable_dsi_pll(encoder); | |
47eacbab | 527 | intel_enable_dsi_pll(encoder, crtc->config); |
f00b5689 | 528 | |
58d4d32f | 529 | intel_dsi_prepare(encoder); |
e3488e75 | 530 | |
fc45e821 SK |
531 | /* Panel Enable over CRC PMIC */ |
532 | if (intel_dsi->gpio_panel) | |
533 | gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1); | |
534 | ||
535 | msleep(intel_dsi->panel_on_delay); | |
536 | ||
d1877c0f VS |
537 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
538 | u32 val; | |
539 | ||
cd2d34d9 | 540 | /* Disable DPOunit clock gating, can stall pipe */ |
d1877c0f VS |
541 | val = I915_READ(DSPCLK_GATE_D); |
542 | val |= DPOUNIT_CLOCK_GATE_DISABLE; | |
543 | I915_WRITE(DSPCLK_GATE_D, val); | |
37ab0810 | 544 | } |
2634fd7f SK |
545 | |
546 | /* put device in ready state */ | |
547 | intel_dsi_device_ready(encoder); | |
4e646495 | 548 | |
593e0622 | 549 | drm_panel_prepare(intel_dsi->panel); |
20e5bf66 | 550 | |
7f6a6a4a JN |
551 | for_each_dsi_port(port, intel_dsi->ports) |
552 | wait_for_dsi_fifo_empty(intel_dsi, port); | |
1381308b | 553 | |
2634fd7f SK |
554 | /* Enable port in pre-enable phase itself because as per hw team |
555 | * recommendation, port should be enabled befor plane & pipe */ | |
556 | intel_dsi_enable(encoder); | |
557 | } | |
558 | ||
559 | static void intel_dsi_enable_nop(struct intel_encoder *encoder) | |
560 | { | |
561 | DRM_DEBUG_KMS("\n"); | |
562 | ||
563 | /* for DSI port enable has to be done before pipe | |
564 | * and plane enable, so port enable is done in | |
565 | * pre_enable phase itself unlike other encoders | |
566 | */ | |
4e646495 JN |
567 | } |
568 | ||
c315faf8 ID |
569 | static void intel_dsi_pre_disable(struct intel_encoder *encoder) |
570 | { | |
571 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); | |
f03e4179 | 572 | enum port port; |
c315faf8 ID |
573 | |
574 | DRM_DEBUG_KMS("\n"); | |
575 | ||
b029e66f SK |
576 | intel_panel_disable_backlight(intel_dsi->attached_connector); |
577 | ||
c315faf8 ID |
578 | if (is_vid_mode(intel_dsi)) { |
579 | /* Send Shutdown command to the panel in LP mode */ | |
f03e4179 | 580 | for_each_dsi_port(port, intel_dsi->ports) |
a2581a9e | 581 | dpi_send_cmd(intel_dsi, SHUTDOWN, false, port); |
c315faf8 ID |
582 | msleep(10); |
583 | } | |
584 | } | |
585 | ||
4e646495 JN |
586 | static void intel_dsi_disable(struct intel_encoder *encoder) |
587 | { | |
1dbd7cb2 SK |
588 | struct drm_device *dev = encoder->base.dev; |
589 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4e646495 | 590 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
384f02a2 | 591 | enum port port; |
4e646495 JN |
592 | u32 temp; |
593 | ||
594 | DRM_DEBUG_KMS("\n"); | |
595 | ||
4e646495 | 596 | if (is_vid_mode(intel_dsi)) { |
7f6a6a4a JN |
597 | for_each_dsi_port(port, intel_dsi->ports) |
598 | wait_for_dsi_fifo_empty(intel_dsi, port); | |
1381308b | 599 | |
5505a244 | 600 | intel_dsi_port_disable(encoder); |
4e646495 JN |
601 | msleep(2); |
602 | } | |
603 | ||
384f02a2 GS |
604 | for_each_dsi_port(port, intel_dsi->ports) { |
605 | /* Panel commands can be sent when clock is in LP11 */ | |
606 | I915_WRITE(MIPI_DEVICE_READY(port), 0x0); | |
339023ec | 607 | |
b389a45c | 608 | intel_dsi_reset_clocks(encoder, port); |
384f02a2 | 609 | I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP); |
339023ec | 610 | |
384f02a2 GS |
611 | temp = I915_READ(MIPI_DSI_FUNC_PRG(port)); |
612 | temp &= ~VID_MODE_FORMAT_MASK; | |
613 | I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp); | |
339023ec | 614 | |
384f02a2 GS |
615 | I915_WRITE(MIPI_DEVICE_READY(port), 0x1); |
616 | } | |
1dbd7cb2 SK |
617 | /* if disable packets are sent before sending shutdown packet then in |
618 | * some next enable sequence send turn on packet error is observed */ | |
593e0622 | 619 | drm_panel_disable(intel_dsi->panel); |
1381308b | 620 | |
7f6a6a4a JN |
621 | for_each_dsi_port(port, intel_dsi->ports) |
622 | wait_for_dsi_fifo_empty(intel_dsi, port); | |
4e646495 JN |
623 | } |
624 | ||
1dbd7cb2 | 625 | static void intel_dsi_clear_device_ready(struct intel_encoder *encoder) |
4e646495 | 626 | { |
b389a45c | 627 | struct drm_device *dev = encoder->base.dev; |
1dbd7cb2 | 628 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
384f02a2 GS |
629 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
630 | enum port port; | |
1dbd7cb2 | 631 | |
4e646495 | 632 | DRM_DEBUG_KMS("\n"); |
384f02a2 | 633 | for_each_dsi_port(port, intel_dsi->ports) { |
f0f59a00 VS |
634 | /* Common bit for both MIPI Port A & MIPI Port C on VLV/CHV */ |
635 | i915_reg_t port_ctrl = IS_BROXTON(dev) ? | |
636 | BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(PORT_A); | |
637 | u32 val; | |
be4fc046 | 638 | |
384f02a2 GS |
639 | I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | |
640 | ULPS_STATE_ENTER); | |
641 | usleep_range(2000, 2500); | |
642 | ||
643 | I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | | |
644 | ULPS_STATE_EXIT); | |
645 | usleep_range(2000, 2500); | |
646 | ||
647 | I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | | |
648 | ULPS_STATE_ENTER); | |
649 | usleep_range(2000, 2500); | |
650 | ||
651 | /* Wait till Clock lanes are in LP-00 state for MIPI Port A | |
652 | * only. MIPI Port C has no similar bit for checking | |
653 | */ | |
b389a45c SS |
654 | if (wait_for(((I915_READ(port_ctrl) & AFE_LATCHOUT) |
655 | == 0x00000), 30)) | |
384f02a2 GS |
656 | DRM_ERROR("DSI LP not going Low\n"); |
657 | ||
b389a45c SS |
658 | /* Disable MIPI PHY transparent latch */ |
659 | val = I915_READ(port_ctrl); | |
660 | I915_WRITE(port_ctrl, val & ~LP_OUTPUT_HOLD); | |
384f02a2 GS |
661 | usleep_range(1000, 1500); |
662 | ||
663 | I915_WRITE(MIPI_DEVICE_READY(port), 0x00); | |
664 | usleep_range(2000, 2500); | |
665 | } | |
1dbd7cb2 | 666 | |
fe88fc68 | 667 | intel_disable_dsi_pll(encoder); |
4e646495 | 668 | } |
20e5bf66 | 669 | |
1dbd7cb2 SK |
670 | static void intel_dsi_post_disable(struct intel_encoder *encoder) |
671 | { | |
20e5bf66 | 672 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
1dbd7cb2 SK |
673 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
674 | ||
675 | DRM_DEBUG_KMS("\n"); | |
676 | ||
c315faf8 ID |
677 | intel_dsi_disable(encoder); |
678 | ||
1dbd7cb2 SK |
679 | intel_dsi_clear_device_ready(encoder); |
680 | ||
d1877c0f | 681 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
d6e3af54 US |
682 | u32 val; |
683 | ||
684 | val = I915_READ(DSPCLK_GATE_D); | |
685 | val &= ~DPOUNIT_CLOCK_GATE_DISABLE; | |
686 | I915_WRITE(DSPCLK_GATE_D, val); | |
687 | } | |
20e5bf66 | 688 | |
593e0622 | 689 | drm_panel_unprepare(intel_dsi->panel); |
df38e655 SK |
690 | |
691 | msleep(intel_dsi->panel_off_delay); | |
fc45e821 SK |
692 | |
693 | /* Panel Disable over CRC PMIC */ | |
694 | if (intel_dsi->gpio_panel) | |
695 | gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0); | |
1d5c65ed VS |
696 | |
697 | /* | |
698 | * FIXME As we do with eDP, just make a note of the time here | |
699 | * and perform the wait before the next panel power on. | |
700 | */ | |
701 | msleep(intel_dsi->panel_pwr_cycle_delay); | |
1dbd7cb2 | 702 | } |
4e646495 JN |
703 | |
704 | static bool intel_dsi_get_hw_state(struct intel_encoder *encoder, | |
705 | enum pipe *pipe) | |
706 | { | |
707 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; | |
c0beefd2 GS |
708 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
709 | struct drm_device *dev = encoder->base.dev; | |
6d129bea | 710 | enum intel_display_power_domain power_domain; |
e7d7cad0 | 711 | enum port port; |
1dcec2f3 | 712 | bool active = false; |
4e646495 JN |
713 | |
714 | DRM_DEBUG_KMS("\n"); | |
715 | ||
6d129bea | 716 | power_domain = intel_display_port_power_domain(encoder); |
3f3f42b8 | 717 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
6d129bea ID |
718 | return false; |
719 | ||
db18b6a6 ID |
720 | /* |
721 | * On Broxton the PLL needs to be enabled with a valid divider | |
722 | * configuration, otherwise accessing DSI registers will hang the | |
723 | * machine. See BSpec North Display Engine registers/MIPI[BXT]. | |
724 | */ | |
725 | if (IS_BROXTON(dev_priv) && !intel_dsi_pll_is_enabled(dev_priv)) | |
726 | goto out_put_power; | |
727 | ||
4e646495 | 728 | /* XXX: this only works for one DSI output */ |
c0beefd2 | 729 | for_each_dsi_port(port, intel_dsi->ports) { |
f0f59a00 VS |
730 | i915_reg_t ctrl_reg = IS_BROXTON(dev) ? |
731 | BXT_MIPI_PORT_CTRL(port) : MIPI_PORT_CTRL(port); | |
1dcec2f3 | 732 | bool enabled = I915_READ(ctrl_reg) & DPI_ENABLE; |
c0beefd2 | 733 | |
e6f57789 JN |
734 | /* |
735 | * Due to some hardware limitations on VLV/CHV, the DPI enable | |
736 | * bit in port C control register does not get set. As a | |
737 | * workaround, check pipe B conf instead. | |
c0beefd2 | 738 | */ |
e6f57789 | 739 | if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && port == PORT_C) |
1dcec2f3 | 740 | enabled = I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE; |
4e646495 | 741 | |
1dcec2f3 JN |
742 | /* Try command mode if video mode not enabled */ |
743 | if (!enabled) { | |
744 | u32 tmp = I915_READ(MIPI_DSI_FUNC_PRG(port)); | |
745 | enabled = tmp & CMD_MODE_DATA_WIDTH_MASK; | |
4e646495 | 746 | } |
1dcec2f3 JN |
747 | |
748 | if (!enabled) | |
749 | continue; | |
750 | ||
751 | if (!(I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY)) | |
752 | continue; | |
753 | ||
6b93e9c8 JN |
754 | if (IS_BROXTON(dev_priv)) { |
755 | u32 tmp = I915_READ(MIPI_CTRL(port)); | |
756 | tmp &= BXT_PIPE_SELECT_MASK; | |
757 | tmp >>= BXT_PIPE_SELECT_SHIFT; | |
758 | ||
759 | if (WARN_ON(tmp > PIPE_C)) | |
760 | continue; | |
761 | ||
762 | *pipe = tmp; | |
763 | } else { | |
764 | *pipe = port == PORT_A ? PIPE_A : PIPE_B; | |
765 | } | |
766 | ||
1dcec2f3 JN |
767 | active = true; |
768 | break; | |
4e646495 | 769 | } |
1dcec2f3 | 770 | |
db18b6a6 | 771 | out_put_power: |
3f3f42b8 | 772 | intel_display_power_put(dev_priv, power_domain); |
4e646495 | 773 | |
1dcec2f3 | 774 | return active; |
4e646495 JN |
775 | } |
776 | ||
6f0e7535 R |
777 | static void bxt_dsi_get_pipe_config(struct intel_encoder *encoder, |
778 | struct intel_crtc_state *pipe_config) | |
779 | { | |
780 | struct drm_device *dev = encoder->base.dev; | |
781 | struct drm_i915_private *dev_priv = dev->dev_private; | |
782 | struct drm_display_mode *adjusted_mode = | |
783 | &pipe_config->base.adjusted_mode; | |
784 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); | |
785 | unsigned int bpp, fmt; | |
786 | enum port port; | |
787 | u16 vfp, vsync, vbp; | |
788 | ||
789 | /* | |
790 | * Atleast one port is active as encoder->get_config called only if | |
791 | * encoder->get_hw_state() returns true. | |
792 | */ | |
793 | for_each_dsi_port(port, intel_dsi->ports) { | |
794 | if (I915_READ(BXT_MIPI_PORT_CTRL(port)) & DPI_ENABLE) | |
795 | break; | |
796 | } | |
797 | ||
798 | fmt = I915_READ(MIPI_DSI_FUNC_PRG(port)) & VID_MODE_FORMAT_MASK; | |
799 | pipe_config->pipe_bpp = | |
800 | mipi_dsi_pixel_format_to_bpp( | |
801 | pixel_format_from_register_bits(fmt)); | |
802 | bpp = pipe_config->pipe_bpp; | |
803 | ||
804 | /* In terms of pixels */ | |
805 | adjusted_mode->crtc_hdisplay = | |
806 | I915_READ(BXT_MIPI_TRANS_HACTIVE(port)); | |
807 | adjusted_mode->crtc_vdisplay = | |
808 | I915_READ(BXT_MIPI_TRANS_VACTIVE(port)); | |
809 | adjusted_mode->crtc_vtotal = | |
810 | I915_READ(BXT_MIPI_TRANS_VTOTAL(port)); | |
811 | ||
812 | /* | |
813 | * TODO: Retrieve hfp, hsync and hbp. Adjust them for dual link and | |
814 | * calculate hsync_start, hsync_end, htotal and hblank_end | |
815 | */ | |
816 | ||
817 | /* vertical values are in terms of lines */ | |
818 | vfp = I915_READ(MIPI_VFP_COUNT(port)); | |
819 | vsync = I915_READ(MIPI_VSYNC_PADDING_COUNT(port)); | |
820 | vbp = I915_READ(MIPI_VBP_COUNT(port)); | |
821 | ||
822 | adjusted_mode->crtc_hblank_start = adjusted_mode->crtc_hdisplay; | |
823 | ||
824 | adjusted_mode->crtc_vsync_start = | |
825 | vfp + adjusted_mode->crtc_vdisplay; | |
826 | adjusted_mode->crtc_vsync_end = | |
827 | vsync + adjusted_mode->crtc_vsync_start; | |
828 | adjusted_mode->crtc_vblank_start = adjusted_mode->crtc_vdisplay; | |
829 | adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vtotal; | |
830 | } | |
831 | ||
832 | ||
4e646495 | 833 | static void intel_dsi_get_config(struct intel_encoder *encoder, |
5cec258b | 834 | struct intel_crtc_state *pipe_config) |
4e646495 | 835 | { |
6f0e7535 | 836 | struct drm_device *dev = encoder->base.dev; |
d7d85d85 | 837 | u32 pclk; |
4e646495 JN |
838 | DRM_DEBUG_KMS("\n"); |
839 | ||
a65347ba JN |
840 | pipe_config->has_dsi_encoder = true; |
841 | ||
6f0e7535 R |
842 | if (IS_BROXTON(dev)) |
843 | bxt_dsi_get_pipe_config(encoder, pipe_config); | |
844 | ||
47eacbab VS |
845 | pclk = intel_dsi_get_pclk(encoder, pipe_config->pipe_bpp, |
846 | pipe_config); | |
f573de5a SK |
847 | if (!pclk) |
848 | return; | |
849 | ||
2d112de7 | 850 | pipe_config->base.adjusted_mode.crtc_clock = pclk; |
f573de5a | 851 | pipe_config->port_clock = pclk; |
4e646495 JN |
852 | } |
853 | ||
c19de8eb DL |
854 | static enum drm_mode_status |
855 | intel_dsi_mode_valid(struct drm_connector *connector, | |
856 | struct drm_display_mode *mode) | |
4e646495 JN |
857 | { |
858 | struct intel_connector *intel_connector = to_intel_connector(connector); | |
f4ee265f | 859 | const struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode; |
759a1e98 | 860 | int max_dotclk = to_i915(connector->dev)->max_dotclk_freq; |
4e646495 JN |
861 | |
862 | DRM_DEBUG_KMS("\n"); | |
863 | ||
864 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) { | |
865 | DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n"); | |
866 | return MODE_NO_DBLESCAN; | |
867 | } | |
868 | ||
869 | if (fixed_mode) { | |
870 | if (mode->hdisplay > fixed_mode->hdisplay) | |
871 | return MODE_PANEL; | |
872 | if (mode->vdisplay > fixed_mode->vdisplay) | |
873 | return MODE_PANEL; | |
759a1e98 MK |
874 | if (fixed_mode->clock > max_dotclk) |
875 | return MODE_CLOCK_HIGH; | |
4e646495 JN |
876 | } |
877 | ||
36d21f4c | 878 | return MODE_OK; |
4e646495 JN |
879 | } |
880 | ||
881 | /* return txclkesc cycles in terms of divider and duration in us */ | |
882 | static u16 txclkesc(u32 divider, unsigned int us) | |
883 | { | |
884 | switch (divider) { | |
885 | case ESCAPE_CLOCK_DIVIDER_1: | |
886 | default: | |
887 | return 20 * us; | |
888 | case ESCAPE_CLOCK_DIVIDER_2: | |
889 | return 10 * us; | |
890 | case ESCAPE_CLOCK_DIVIDER_4: | |
891 | return 5 * us; | |
892 | } | |
893 | } | |
894 | ||
895 | /* return pixels in terms of txbyteclkhs */ | |
7f0c8605 SK |
896 | static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count, |
897 | u16 burst_mode_ratio) | |
4e646495 | 898 | { |
7f0c8605 | 899 | return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio, |
7f3de833 | 900 | 8 * 100), lane_count); |
4e646495 JN |
901 | } |
902 | ||
903 | static void set_dsi_timings(struct drm_encoder *encoder, | |
5e7234c9 | 904 | const struct drm_display_mode *adjusted_mode) |
4e646495 JN |
905 | { |
906 | struct drm_device *dev = encoder->dev; | |
907 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4e646495 | 908 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); |
aa102d28 | 909 | enum port port; |
1e78aa01 | 910 | unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); |
4e646495 JN |
911 | unsigned int lane_count = intel_dsi->lane_count; |
912 | ||
913 | u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp; | |
914 | ||
aad941d5 VS |
915 | hactive = adjusted_mode->crtc_hdisplay; |
916 | hfp = adjusted_mode->crtc_hsync_start - adjusted_mode->crtc_hdisplay; | |
917 | hsync = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start; | |
918 | hbp = adjusted_mode->crtc_htotal - adjusted_mode->crtc_hsync_end; | |
4e646495 | 919 | |
aa102d28 GS |
920 | if (intel_dsi->dual_link) { |
921 | hactive /= 2; | |
922 | if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) | |
923 | hactive += intel_dsi->pixel_overlap; | |
924 | hfp /= 2; | |
925 | hsync /= 2; | |
926 | hbp /= 2; | |
927 | } | |
928 | ||
aad941d5 VS |
929 | vfp = adjusted_mode->crtc_vsync_start - adjusted_mode->crtc_vdisplay; |
930 | vsync = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start; | |
931 | vbp = adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vsync_end; | |
4e646495 JN |
932 | |
933 | /* horizontal values are in terms of high speed byte clock */ | |
7f0c8605 | 934 | hactive = txbyteclkhs(hactive, bpp, lane_count, |
7f3de833 | 935 | intel_dsi->burst_mode_ratio); |
7f0c8605 SK |
936 | hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio); |
937 | hsync = txbyteclkhs(hsync, bpp, lane_count, | |
7f3de833 | 938 | intel_dsi->burst_mode_ratio); |
7f0c8605 | 939 | hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio); |
4e646495 | 940 | |
aa102d28 | 941 | for_each_dsi_port(port, intel_dsi->ports) { |
d2e08c0f SS |
942 | if (IS_BROXTON(dev)) { |
943 | /* | |
944 | * Program hdisplay and vdisplay on MIPI transcoder. | |
945 | * This is different from calculated hactive and | |
946 | * vactive, as they are calculated per channel basis, | |
947 | * whereas these values should be based on resolution. | |
948 | */ | |
949 | I915_WRITE(BXT_MIPI_TRANS_HACTIVE(port), | |
aad941d5 | 950 | adjusted_mode->crtc_hdisplay); |
d2e08c0f | 951 | I915_WRITE(BXT_MIPI_TRANS_VACTIVE(port), |
aad941d5 | 952 | adjusted_mode->crtc_vdisplay); |
d2e08c0f | 953 | I915_WRITE(BXT_MIPI_TRANS_VTOTAL(port), |
aad941d5 | 954 | adjusted_mode->crtc_vtotal); |
d2e08c0f SS |
955 | } |
956 | ||
aa102d28 GS |
957 | I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive); |
958 | I915_WRITE(MIPI_HFP_COUNT(port), hfp); | |
959 | ||
960 | /* meaningful for video mode non-burst sync pulse mode only, | |
961 | * can be zero for non-burst sync events and burst modes */ | |
962 | I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync); | |
963 | I915_WRITE(MIPI_HBP_COUNT(port), hbp); | |
964 | ||
965 | /* vertical values are in terms of lines */ | |
966 | I915_WRITE(MIPI_VFP_COUNT(port), vfp); | |
967 | I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync); | |
968 | I915_WRITE(MIPI_VBP_COUNT(port), vbp); | |
969 | } | |
4e646495 JN |
970 | } |
971 | ||
1e78aa01 JN |
972 | static u32 pixel_format_to_reg(enum mipi_dsi_pixel_format fmt) |
973 | { | |
974 | switch (fmt) { | |
975 | case MIPI_DSI_FMT_RGB888: | |
976 | return VID_MODE_FORMAT_RGB888; | |
977 | case MIPI_DSI_FMT_RGB666: | |
978 | return VID_MODE_FORMAT_RGB666; | |
979 | case MIPI_DSI_FMT_RGB666_PACKED: | |
980 | return VID_MODE_FORMAT_RGB666_PACKED; | |
981 | case MIPI_DSI_FMT_RGB565: | |
982 | return VID_MODE_FORMAT_RGB565; | |
983 | default: | |
984 | MISSING_CASE(fmt); | |
985 | return VID_MODE_FORMAT_RGB666; | |
986 | } | |
987 | } | |
988 | ||
07e4fb9e | 989 | static void intel_dsi_prepare(struct intel_encoder *intel_encoder) |
4e646495 JN |
990 | { |
991 | struct drm_encoder *encoder = &intel_encoder->base; | |
992 | struct drm_device *dev = encoder->dev; | |
993 | struct drm_i915_private *dev_priv = dev->dev_private; | |
994 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); | |
995 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); | |
7c5f93b0 | 996 | const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode; |
24ee0e64 | 997 | enum port port; |
1e78aa01 | 998 | unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); |
4e646495 | 999 | u32 val, tmp; |
24ee0e64 | 1000 | u16 mode_hdisplay; |
4e646495 | 1001 | |
e7d7cad0 | 1002 | DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe)); |
4e646495 | 1003 | |
aad941d5 | 1004 | mode_hdisplay = adjusted_mode->crtc_hdisplay; |
4e646495 | 1005 | |
24ee0e64 GS |
1006 | if (intel_dsi->dual_link) { |
1007 | mode_hdisplay /= 2; | |
1008 | if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) | |
1009 | mode_hdisplay += intel_dsi->pixel_overlap; | |
1010 | } | |
4e646495 | 1011 | |
24ee0e64 | 1012 | for_each_dsi_port(port, intel_dsi->ports) { |
666a4537 | 1013 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
d2e08c0f SS |
1014 | /* |
1015 | * escape clock divider, 20MHz, shared for A and C. | |
1016 | * device ready must be off when doing this! txclkesc? | |
1017 | */ | |
1018 | tmp = I915_READ(MIPI_CTRL(PORT_A)); | |
1019 | tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK; | |
1020 | I915_WRITE(MIPI_CTRL(PORT_A), tmp | | |
1021 | ESCAPE_CLOCK_DIVIDER_1); | |
1022 | ||
1023 | /* read request priority is per pipe */ | |
1024 | tmp = I915_READ(MIPI_CTRL(port)); | |
1025 | tmp &= ~READ_REQUEST_PRIORITY_MASK; | |
1026 | I915_WRITE(MIPI_CTRL(port), tmp | | |
1027 | READ_REQUEST_PRIORITY_HIGH); | |
1028 | } else if (IS_BROXTON(dev)) { | |
56c48978 D |
1029 | enum pipe pipe = intel_crtc->pipe; |
1030 | ||
d2e08c0f SS |
1031 | tmp = I915_READ(MIPI_CTRL(port)); |
1032 | tmp &= ~BXT_PIPE_SELECT_MASK; | |
1033 | ||
56c48978 | 1034 | tmp |= BXT_PIPE_SELECT(pipe); |
d2e08c0f SS |
1035 | I915_WRITE(MIPI_CTRL(port), tmp); |
1036 | } | |
24ee0e64 GS |
1037 | |
1038 | /* XXX: why here, why like this? handling in irq handler?! */ | |
1039 | I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff); | |
1040 | I915_WRITE(MIPI_INTR_EN(port), 0xffffffff); | |
1041 | ||
1042 | I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg); | |
1043 | ||
1044 | I915_WRITE(MIPI_DPI_RESOLUTION(port), | |
aad941d5 | 1045 | adjusted_mode->crtc_vdisplay << VERTICAL_ADDRESS_SHIFT | |
24ee0e64 GS |
1046 | mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT); |
1047 | } | |
4e646495 JN |
1048 | |
1049 | set_dsi_timings(encoder, adjusted_mode); | |
1050 | ||
1051 | val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT; | |
1052 | if (is_cmd_mode(intel_dsi)) { | |
1053 | val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT; | |
1054 | val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */ | |
1055 | } else { | |
1056 | val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT; | |
1e78aa01 | 1057 | val |= pixel_format_to_reg(intel_dsi->pixel_format); |
4e646495 | 1058 | } |
4e646495 | 1059 | |
24ee0e64 GS |
1060 | tmp = 0; |
1061 | if (intel_dsi->eotp_pkt == 0) | |
1062 | tmp |= EOT_DISABLE; | |
1063 | if (intel_dsi->clock_stop) | |
1064 | tmp |= CLOCKSTOP; | |
4e646495 | 1065 | |
24ee0e64 GS |
1066 | for_each_dsi_port(port, intel_dsi->ports) { |
1067 | I915_WRITE(MIPI_DSI_FUNC_PRG(port), val); | |
1068 | ||
1069 | /* timeouts for recovery. one frame IIUC. if counter expires, | |
1070 | * EOT and stop state. */ | |
1071 | ||
1072 | /* | |
1073 | * In burst mode, value greater than one DPI line Time in byte | |
1074 | * clock (txbyteclkhs) To timeout this timer 1+ of the above | |
1075 | * said value is recommended. | |
1076 | * | |
1077 | * In non-burst mode, Value greater than one DPI frame time in | |
1078 | * byte clock(txbyteclkhs) To timeout this timer 1+ of the above | |
1079 | * said value is recommended. | |
1080 | * | |
1081 | * In DBI only mode, value greater than one DBI frame time in | |
1082 | * byte clock(txbyteclkhs) To timeout this timer 1+ of the above | |
1083 | * said value is recommended. | |
1084 | */ | |
4e646495 | 1085 | |
24ee0e64 GS |
1086 | if (is_vid_mode(intel_dsi) && |
1087 | intel_dsi->video_mode_format == VIDEO_MODE_BURST) { | |
1088 | I915_WRITE(MIPI_HS_TX_TIMEOUT(port), | |
aad941d5 | 1089 | txbyteclkhs(adjusted_mode->crtc_htotal, bpp, |
124abe07 VS |
1090 | intel_dsi->lane_count, |
1091 | intel_dsi->burst_mode_ratio) + 1); | |
24ee0e64 GS |
1092 | } else { |
1093 | I915_WRITE(MIPI_HS_TX_TIMEOUT(port), | |
aad941d5 VS |
1094 | txbyteclkhs(adjusted_mode->crtc_vtotal * |
1095 | adjusted_mode->crtc_htotal, | |
124abe07 VS |
1096 | bpp, intel_dsi->lane_count, |
1097 | intel_dsi->burst_mode_ratio) + 1); | |
24ee0e64 GS |
1098 | } |
1099 | I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout); | |
1100 | I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port), | |
1101 | intel_dsi->turn_arnd_val); | |
1102 | I915_WRITE(MIPI_DEVICE_RESET_TIMER(port), | |
1103 | intel_dsi->rst_timer_val); | |
f1c79f16 | 1104 | |
24ee0e64 | 1105 | /* dphy stuff */ |
f1c79f16 | 1106 | |
24ee0e64 GS |
1107 | /* in terms of low power clock */ |
1108 | I915_WRITE(MIPI_INIT_COUNT(port), | |
1109 | txclkesc(intel_dsi->escape_clk_div, 100)); | |
4e646495 | 1110 | |
d2e08c0f SS |
1111 | if (IS_BROXTON(dev) && (!intel_dsi->dual_link)) { |
1112 | /* | |
1113 | * BXT spec says write MIPI_INIT_COUNT for | |
1114 | * both the ports, even if only one is | |
1115 | * getting used. So write the other port | |
1116 | * if not in dual link mode. | |
1117 | */ | |
1118 | I915_WRITE(MIPI_INIT_COUNT(port == | |
1119 | PORT_A ? PORT_C : PORT_A), | |
1120 | intel_dsi->init_count); | |
1121 | } | |
4e646495 | 1122 | |
24ee0e64 | 1123 | /* recovery disables */ |
87c54d0e | 1124 | I915_WRITE(MIPI_EOT_DISABLE(port), tmp); |
cf4dbd2e | 1125 | |
24ee0e64 GS |
1126 | /* in terms of low power clock */ |
1127 | I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count); | |
4e646495 | 1128 | |
24ee0e64 GS |
1129 | /* in terms of txbyteclkhs. actual high to low switch + |
1130 | * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK. | |
1131 | * | |
1132 | * XXX: write MIPI_STOP_STATE_STALL? | |
1133 | */ | |
1134 | I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port), | |
1135 | intel_dsi->hs_to_lp_count); | |
1136 | ||
1137 | /* XXX: low power clock equivalence in terms of byte clock. | |
1138 | * the number of byte clocks occupied in one low power clock. | |
1139 | * based on txbyteclkhs and txclkesc. | |
1140 | * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL | |
1141 | * ) / 105.??? | |
1142 | */ | |
1143 | I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk); | |
1144 | ||
1145 | /* the bw essential for transmitting 16 long packets containing | |
1146 | * 252 bytes meant for dcs write memory command is programmed in | |
1147 | * this register in terms of byte clocks. based on dsi transfer | |
1148 | * rate and the number of lanes configured the time taken to | |
1149 | * transmit 16 long packets in a dsi stream varies. */ | |
1150 | I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer); | |
1151 | ||
1152 | I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port), | |
1153 | intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT | | |
1154 | intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT); | |
1155 | ||
1156 | if (is_vid_mode(intel_dsi)) | |
1157 | /* Some panels might have resolution which is not a | |
1158 | * multiple of 64 like 1366 x 768. Enable RANDOM | |
1159 | * resolution support for such panels by default */ | |
1160 | I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port), | |
1161 | intel_dsi->video_frmt_cfg_bits | | |
1162 | intel_dsi->video_mode_format | | |
1163 | IP_TG_CONFIG | | |
1164 | RANDOM_DPI_DISPLAY_RESOLUTION); | |
1165 | } | |
4e646495 JN |
1166 | } |
1167 | ||
1168 | static enum drm_connector_status | |
1169 | intel_dsi_detect(struct drm_connector *connector, bool force) | |
1170 | { | |
36d21f4c | 1171 | return connector_status_connected; |
4e646495 JN |
1172 | } |
1173 | ||
1174 | static int intel_dsi_get_modes(struct drm_connector *connector) | |
1175 | { | |
1176 | struct intel_connector *intel_connector = to_intel_connector(connector); | |
1177 | struct drm_display_mode *mode; | |
1178 | ||
1179 | DRM_DEBUG_KMS("\n"); | |
1180 | ||
1181 | if (!intel_connector->panel.fixed_mode) { | |
1182 | DRM_DEBUG_KMS("no fixed mode\n"); | |
1183 | return 0; | |
1184 | } | |
1185 | ||
1186 | mode = drm_mode_duplicate(connector->dev, | |
1187 | intel_connector->panel.fixed_mode); | |
1188 | if (!mode) { | |
1189 | DRM_DEBUG_KMS("drm_mode_duplicate failed\n"); | |
1190 | return 0; | |
1191 | } | |
1192 | ||
1193 | drm_mode_probed_add(connector, mode); | |
1194 | return 1; | |
1195 | } | |
1196 | ||
f4ee265f VS |
1197 | static int intel_dsi_set_property(struct drm_connector *connector, |
1198 | struct drm_property *property, | |
1199 | uint64_t val) | |
1200 | { | |
1201 | struct drm_device *dev = connector->dev; | |
1202 | struct intel_connector *intel_connector = to_intel_connector(connector); | |
1203 | struct drm_crtc *crtc; | |
1204 | int ret; | |
1205 | ||
1206 | ret = drm_object_property_set_value(&connector->base, property, val); | |
1207 | if (ret) | |
1208 | return ret; | |
1209 | ||
1210 | if (property == dev->mode_config.scaling_mode_property) { | |
1211 | if (val == DRM_MODE_SCALE_NONE) { | |
1212 | DRM_DEBUG_KMS("no scaling not supported\n"); | |
1213 | return -EINVAL; | |
1214 | } | |
234126c6 VS |
1215 | if (HAS_GMCH_DISPLAY(dev) && |
1216 | val == DRM_MODE_SCALE_CENTER) { | |
1217 | DRM_DEBUG_KMS("centering not supported\n"); | |
1218 | return -EINVAL; | |
1219 | } | |
f4ee265f VS |
1220 | |
1221 | if (intel_connector->panel.fitting_mode == val) | |
1222 | return 0; | |
1223 | ||
1224 | intel_connector->panel.fitting_mode = val; | |
1225 | } | |
1226 | ||
1227 | crtc = intel_attached_encoder(connector)->base.crtc; | |
1228 | if (crtc && crtc->state->enable) { | |
1229 | /* | |
1230 | * If the CRTC is enabled, the display will be changed | |
1231 | * according to the new panel fitting mode. | |
1232 | */ | |
1233 | intel_crtc_restore_mode(crtc); | |
1234 | } | |
1235 | ||
1236 | return 0; | |
1237 | } | |
1238 | ||
593e0622 | 1239 | static void intel_dsi_connector_destroy(struct drm_connector *connector) |
4e646495 JN |
1240 | { |
1241 | struct intel_connector *intel_connector = to_intel_connector(connector); | |
1242 | ||
1243 | DRM_DEBUG_KMS("\n"); | |
1244 | intel_panel_fini(&intel_connector->panel); | |
4e646495 JN |
1245 | drm_connector_cleanup(connector); |
1246 | kfree(connector); | |
1247 | } | |
1248 | ||
593e0622 JN |
1249 | static void intel_dsi_encoder_destroy(struct drm_encoder *encoder) |
1250 | { | |
1251 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); | |
1252 | ||
1253 | if (intel_dsi->panel) { | |
1254 | drm_panel_detach(intel_dsi->panel); | |
1255 | /* XXX: Logically this call belongs in the panel driver. */ | |
1256 | drm_panel_remove(intel_dsi->panel); | |
1257 | } | |
fc45e821 SK |
1258 | |
1259 | /* dispose of the gpios */ | |
1260 | if (intel_dsi->gpio_panel) | |
1261 | gpiod_put(intel_dsi->gpio_panel); | |
1262 | ||
593e0622 JN |
1263 | intel_encoder_destroy(encoder); |
1264 | } | |
1265 | ||
4e646495 | 1266 | static const struct drm_encoder_funcs intel_dsi_funcs = { |
593e0622 | 1267 | .destroy = intel_dsi_encoder_destroy, |
4e646495 JN |
1268 | }; |
1269 | ||
1270 | static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = { | |
1271 | .get_modes = intel_dsi_get_modes, | |
1272 | .mode_valid = intel_dsi_mode_valid, | |
1273 | .best_encoder = intel_best_encoder, | |
1274 | }; | |
1275 | ||
1276 | static const struct drm_connector_funcs intel_dsi_connector_funcs = { | |
4d688a2a | 1277 | .dpms = drm_atomic_helper_connector_dpms, |
4e646495 | 1278 | .detect = intel_dsi_detect, |
593e0622 | 1279 | .destroy = intel_dsi_connector_destroy, |
4e646495 | 1280 | .fill_modes = drm_helper_probe_single_connector_modes, |
f4ee265f | 1281 | .set_property = intel_dsi_set_property, |
2545e4a6 | 1282 | .atomic_get_property = intel_connector_atomic_get_property, |
c6f95f27 | 1283 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
98969725 | 1284 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
4e646495 JN |
1285 | }; |
1286 | ||
f4ee265f VS |
1287 | static void intel_dsi_add_properties(struct intel_connector *connector) |
1288 | { | |
1289 | struct drm_device *dev = connector->base.dev; | |
1290 | ||
1291 | if (connector->panel.fixed_mode) { | |
1292 | drm_mode_create_scaling_mode_property(dev); | |
1293 | drm_object_attach_property(&connector->base.base, | |
1294 | dev->mode_config.scaling_mode_property, | |
1295 | DRM_MODE_SCALE_ASPECT); | |
1296 | connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT; | |
1297 | } | |
1298 | } | |
1299 | ||
4328633d | 1300 | void intel_dsi_init(struct drm_device *dev) |
4e646495 JN |
1301 | { |
1302 | struct intel_dsi *intel_dsi; | |
1303 | struct intel_encoder *intel_encoder; | |
1304 | struct drm_encoder *encoder; | |
1305 | struct intel_connector *intel_connector; | |
1306 | struct drm_connector *connector; | |
593e0622 | 1307 | struct drm_display_mode *scan, *fixed_mode = NULL; |
b6fdd0f2 | 1308 | struct drm_i915_private *dev_priv = dev->dev_private; |
7e9804fd | 1309 | enum port port; |
4e646495 JN |
1310 | unsigned int i; |
1311 | ||
1312 | DRM_DEBUG_KMS("\n"); | |
1313 | ||
3e6bd011 | 1314 | /* There is no detection method for MIPI so rely on VBT */ |
7137aec1 | 1315 | if (!intel_bios_is_dsi_present(dev_priv, &port)) |
4328633d | 1316 | return; |
3e6bd011 | 1317 | |
666a4537 | 1318 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
868d665b | 1319 | dev_priv->mipi_mmio_base = VLV_MIPI_BASE; |
c6c794a2 SS |
1320 | } else if (IS_BROXTON(dev)) { |
1321 | dev_priv->mipi_mmio_base = BXT_MIPI_BASE; | |
868d665b CJ |
1322 | } else { |
1323 | DRM_ERROR("Unsupported Mipi device to reg base"); | |
1324 | return; | |
1325 | } | |
3e6bd011 | 1326 | |
4e646495 JN |
1327 | intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL); |
1328 | if (!intel_dsi) | |
4328633d | 1329 | return; |
4e646495 | 1330 | |
08d9bc92 | 1331 | intel_connector = intel_connector_alloc(); |
4e646495 JN |
1332 | if (!intel_connector) { |
1333 | kfree(intel_dsi); | |
4328633d | 1334 | return; |
4e646495 JN |
1335 | } |
1336 | ||
1337 | intel_encoder = &intel_dsi->base; | |
1338 | encoder = &intel_encoder->base; | |
1339 | intel_dsi->attached_connector = intel_connector; | |
1340 | ||
1341 | connector = &intel_connector->base; | |
1342 | ||
13a3d91f VS |
1343 | drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI, |
1344 | NULL); | |
4e646495 | 1345 | |
4e646495 | 1346 | intel_encoder->compute_config = intel_dsi_compute_config; |
4e646495 | 1347 | intel_encoder->pre_enable = intel_dsi_pre_enable; |
2634fd7f | 1348 | intel_encoder->enable = intel_dsi_enable_nop; |
c315faf8 | 1349 | intel_encoder->disable = intel_dsi_pre_disable; |
4e646495 JN |
1350 | intel_encoder->post_disable = intel_dsi_post_disable; |
1351 | intel_encoder->get_hw_state = intel_dsi_get_hw_state; | |
1352 | intel_encoder->get_config = intel_dsi_get_config; | |
1353 | ||
1354 | intel_connector->get_hw_state = intel_connector_get_hw_state; | |
4932e2c3 | 1355 | intel_connector->unregister = intel_connector_unregister; |
4e646495 | 1356 | |
2e85ab4f JN |
1357 | /* |
1358 | * On BYT/CHV, pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI | |
1359 | * port C. BXT isn't limited like this. | |
1360 | */ | |
1361 | if (IS_BROXTON(dev_priv)) | |
1362 | intel_encoder->crtc_mask = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C); | |
1363 | else if (port == PORT_A) | |
701d25b4 | 1364 | intel_encoder->crtc_mask = BIT(PIPE_A); |
7137aec1 | 1365 | else |
701d25b4 | 1366 | intel_encoder->crtc_mask = BIT(PIPE_B); |
e7d7cad0 | 1367 | |
82425785 | 1368 | if (dev_priv->vbt.dsi.config->dual_link) |
701d25b4 | 1369 | intel_dsi->ports = BIT(PORT_A) | BIT(PORT_C); |
7137aec1 | 1370 | else |
701d25b4 | 1371 | intel_dsi->ports = BIT(port); |
82425785 | 1372 | |
7e9804fd JN |
1373 | /* Create a DSI host (and a device) for each port. */ |
1374 | for_each_dsi_port(port, intel_dsi->ports) { | |
1375 | struct intel_dsi_host *host; | |
1376 | ||
1377 | host = intel_dsi_host_init(intel_dsi, port); | |
1378 | if (!host) | |
1379 | goto err; | |
1380 | ||
1381 | intel_dsi->dsi_hosts[port] = host; | |
1382 | } | |
1383 | ||
593e0622 JN |
1384 | for (i = 0; i < ARRAY_SIZE(intel_dsi_drivers); i++) { |
1385 | intel_dsi->panel = intel_dsi_drivers[i].init(intel_dsi, | |
1386 | intel_dsi_drivers[i].panel_id); | |
1387 | if (intel_dsi->panel) | |
4e646495 JN |
1388 | break; |
1389 | } | |
1390 | ||
593e0622 | 1391 | if (!intel_dsi->panel) { |
4e646495 JN |
1392 | DRM_DEBUG_KMS("no device found\n"); |
1393 | goto err; | |
1394 | } | |
1395 | ||
fc45e821 SK |
1396 | /* |
1397 | * In case of BYT with CRC PMIC, we need to use GPIO for | |
1398 | * Panel control. | |
1399 | */ | |
1400 | if (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) { | |
1401 | intel_dsi->gpio_panel = | |
1402 | gpiod_get(dev->dev, "panel", GPIOD_OUT_HIGH); | |
1403 | ||
1404 | if (IS_ERR(intel_dsi->gpio_panel)) { | |
1405 | DRM_ERROR("Failed to own gpio for panel control\n"); | |
1406 | intel_dsi->gpio_panel = NULL; | |
1407 | } | |
1408 | } | |
1409 | ||
4e646495 | 1410 | intel_encoder->type = INTEL_OUTPUT_DSI; |
bc079e8b | 1411 | intel_encoder->cloneable = 0; |
4e646495 JN |
1412 | drm_connector_init(dev, connector, &intel_dsi_connector_funcs, |
1413 | DRM_MODE_CONNECTOR_DSI); | |
1414 | ||
1415 | drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs); | |
1416 | ||
1417 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/ | |
1418 | connector->interlace_allowed = false; | |
1419 | connector->doublescan_allowed = false; | |
1420 | ||
1421 | intel_connector_attach_encoder(intel_connector, intel_encoder); | |
1422 | ||
593e0622 JN |
1423 | drm_panel_attach(intel_dsi->panel, connector); |
1424 | ||
1425 | mutex_lock(&dev->mode_config.mutex); | |
1426 | drm_panel_get_modes(intel_dsi->panel); | |
1427 | list_for_each_entry(scan, &connector->probed_modes, head) { | |
1428 | if ((scan->type & DRM_MODE_TYPE_PREFERRED)) { | |
1429 | fixed_mode = drm_mode_duplicate(dev, scan); | |
1430 | break; | |
1431 | } | |
1432 | } | |
1433 | mutex_unlock(&dev->mode_config.mutex); | |
1434 | ||
4e646495 JN |
1435 | if (!fixed_mode) { |
1436 | DRM_DEBUG_KMS("no fixed mode\n"); | |
1437 | goto err; | |
1438 | } | |
1439 | ||
4b6ed685 | 1440 | intel_panel_init(&intel_connector->panel, fixed_mode, NULL); |
f4ee265f VS |
1441 | |
1442 | intel_dsi_add_properties(intel_connector); | |
1443 | ||
1444 | drm_connector_register(connector); | |
1445 | ||
b029e66f | 1446 | intel_panel_setup_backlight(connector, INVALID_PIPE); |
4e646495 | 1447 | |
4328633d | 1448 | return; |
4e646495 JN |
1449 | |
1450 | err: | |
1451 | drm_encoder_cleanup(&intel_encoder->base); | |
1452 | kfree(intel_dsi); | |
1453 | kfree(intel_connector); | |
4e646495 | 1454 | } |