Commit | Line | Data |
---|---|---|
2ab8b458 SK |
1 | /* |
2 | * Copyright © 2014 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: Shobhit Kumar <shobhit.kumar@intel.com> | |
24 | * | |
25 | */ | |
26 | ||
27 | #include <drm/drmP.h> | |
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> |
2ab8b458 SK |
32 | #include <linux/slab.h> |
33 | #include <video/mipi_display.h> | |
34 | #include <asm/intel-mid.h> | |
35 | #include <video/mipi_display.h> | |
36 | #include "i915_drv.h" | |
37 | #include "intel_drv.h" | |
38 | #include "intel_dsi.h" | |
2ab8b458 | 39 | |
593e0622 JN |
40 | struct vbt_panel { |
41 | struct drm_panel panel; | |
42 | struct intel_dsi *intel_dsi; | |
43 | }; | |
44 | ||
45 | static inline struct vbt_panel *to_vbt_panel(struct drm_panel *panel) | |
46 | { | |
47 | return container_of(panel, struct vbt_panel, panel); | |
48 | } | |
49 | ||
2ab8b458 SK |
50 | #define MIPI_TRANSFER_MODE_SHIFT 0 |
51 | #define MIPI_VIRTUAL_CHANNEL_SHIFT 1 | |
52 | #define MIPI_PORT_SHIFT 3 | |
53 | ||
54 | #define PREPARE_CNT_MAX 0x3F | |
55 | #define EXIT_ZERO_CNT_MAX 0x3F | |
56 | #define CLK_ZERO_CNT_MAX 0xFF | |
57 | #define TRAIL_CNT_MAX 0x1F | |
58 | ||
59 | #define NS_KHZ_RATIO 1000000 | |
60 | ||
61 | #define GPI0_NC_0_HV_DDI0_HPD 0x4130 | |
62 | #define GPIO_NC_0_HV_DDI0_PAD 0x4138 | |
63 | #define GPIO_NC_1_HV_DDI0_DDC_SDA 0x4120 | |
64 | #define GPIO_NC_1_HV_DDI0_DDC_SDA_PAD 0x4128 | |
65 | #define GPIO_NC_2_HV_DDI0_DDC_SCL 0x4110 | |
66 | #define GPIO_NC_2_HV_DDI0_DDC_SCL_PAD 0x4118 | |
67 | #define GPIO_NC_3_PANEL0_VDDEN 0x4140 | |
68 | #define GPIO_NC_3_PANEL0_VDDEN_PAD 0x4148 | |
69 | #define GPIO_NC_4_PANEL0_BLKEN 0x4150 | |
70 | #define GPIO_NC_4_PANEL0_BLKEN_PAD 0x4158 | |
71 | #define GPIO_NC_5_PANEL0_BLKCTL 0x4160 | |
72 | #define GPIO_NC_5_PANEL0_BLKCTL_PAD 0x4168 | |
73 | #define GPIO_NC_6_PCONF0 0x4180 | |
74 | #define GPIO_NC_6_PAD 0x4188 | |
75 | #define GPIO_NC_7_PCONF0 0x4190 | |
76 | #define GPIO_NC_7_PAD 0x4198 | |
77 | #define GPIO_NC_8_PCONF0 0x4170 | |
78 | #define GPIO_NC_8_PAD 0x4178 | |
79 | #define GPIO_NC_9_PCONF0 0x4100 | |
80 | #define GPIO_NC_9_PAD 0x4108 | |
81 | #define GPIO_NC_10_PCONF0 0x40E0 | |
82 | #define GPIO_NC_10_PAD 0x40E8 | |
83 | #define GPIO_NC_11_PCONF0 0x40F0 | |
84 | #define GPIO_NC_11_PAD 0x40F8 | |
85 | ||
86 | struct gpio_table { | |
87 | u16 function_reg; | |
88 | u16 pad_reg; | |
89 | u8 init; | |
90 | }; | |
91 | ||
92 | static struct gpio_table gtable[] = { | |
93 | { GPI0_NC_0_HV_DDI0_HPD, GPIO_NC_0_HV_DDI0_PAD, 0 }, | |
94 | { GPIO_NC_1_HV_DDI0_DDC_SDA, GPIO_NC_1_HV_DDI0_DDC_SDA_PAD, 0 }, | |
95 | { GPIO_NC_2_HV_DDI0_DDC_SCL, GPIO_NC_2_HV_DDI0_DDC_SCL_PAD, 0 }, | |
96 | { GPIO_NC_3_PANEL0_VDDEN, GPIO_NC_3_PANEL0_VDDEN_PAD, 0 }, | |
97 | { GPIO_NC_4_PANEL0_BLKEN, GPIO_NC_4_PANEL0_BLKEN_PAD, 0 }, | |
98 | { GPIO_NC_5_PANEL0_BLKCTL, GPIO_NC_5_PANEL0_BLKCTL_PAD, 0 }, | |
99 | { GPIO_NC_6_PCONF0, GPIO_NC_6_PAD, 0 }, | |
100 | { GPIO_NC_7_PCONF0, GPIO_NC_7_PAD, 0 }, | |
101 | { GPIO_NC_8_PCONF0, GPIO_NC_8_PAD, 0 }, | |
102 | { GPIO_NC_9_PCONF0, GPIO_NC_9_PAD, 0 }, | |
103 | { GPIO_NC_10_PCONF0, GPIO_NC_10_PAD, 0}, | |
104 | { GPIO_NC_11_PCONF0, GPIO_NC_11_PAD, 0} | |
105 | }; | |
106 | ||
8f4d2683 GS |
107 | static inline enum port intel_dsi_seq_port_to_port(u8 port) |
108 | { | |
109 | return port ? PORT_C : PORT_A; | |
110 | } | |
111 | ||
5b48ca0f JN |
112 | static const u8 *mipi_exec_send_packet(struct intel_dsi *intel_dsi, |
113 | const u8 *data) | |
2ab8b458 | 114 | { |
759d10c2 JN |
115 | struct mipi_dsi_device *dsi_device; |
116 | u8 type, flags, seq_port; | |
2ab8b458 | 117 | u16 len; |
8f4d2683 | 118 | enum port port; |
2ab8b458 | 119 | |
759d10c2 JN |
120 | flags = *data++; |
121 | type = *data++; | |
122 | ||
123 | len = *((u16 *) data); | |
124 | data += 2; | |
125 | ||
126 | seq_port = (flags >> MIPI_PORT_SHIFT) & 3; | |
2ab8b458 | 127 | |
f915084e GS |
128 | /* For DSI single link on Port A & C, the seq_port value which is |
129 | * parsed from Sequence Block#53 of VBT has been set to 0 | |
130 | * Now, read/write of packets for the DSI single link on Port A and | |
131 | * Port C will based on the DVO port from VBT block 2. | |
132 | */ | |
133 | if (intel_dsi->ports == (1 << PORT_C)) | |
134 | port = PORT_C; | |
135 | else | |
136 | port = intel_dsi_seq_port_to_port(seq_port); | |
2ab8b458 | 137 | |
759d10c2 JN |
138 | dsi_device = intel_dsi->dsi_hosts[port]->device; |
139 | if (!dsi_device) { | |
140 | DRM_DEBUG_KMS("no dsi device for port %c\n", port_name(port)); | |
141 | goto out; | |
142 | } | |
2ab8b458 | 143 | |
759d10c2 JN |
144 | if ((flags >> MIPI_TRANSFER_MODE_SHIFT) & 1) |
145 | dsi_device->mode_flags &= ~MIPI_DSI_MODE_LPM; | |
146 | else | |
147 | dsi_device->mode_flags |= MIPI_DSI_MODE_LPM; | |
148 | ||
149 | dsi_device->channel = (flags >> MIPI_VIRTUAL_CHANNEL_SHIFT) & 3; | |
2ab8b458 SK |
150 | |
151 | switch (type) { | |
152 | case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM: | |
759d10c2 | 153 | mipi_dsi_generic_write(dsi_device, NULL, 0); |
2ab8b458 SK |
154 | break; |
155 | case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM: | |
759d10c2 | 156 | mipi_dsi_generic_write(dsi_device, data, 1); |
2ab8b458 SK |
157 | break; |
158 | case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM: | |
759d10c2 | 159 | mipi_dsi_generic_write(dsi_device, data, 2); |
2ab8b458 SK |
160 | break; |
161 | case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM: | |
162 | case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM: | |
163 | case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM: | |
164 | DRM_DEBUG_DRIVER("Generic Read not yet implemented or used\n"); | |
165 | break; | |
166 | case MIPI_DSI_GENERIC_LONG_WRITE: | |
759d10c2 | 167 | mipi_dsi_generic_write(dsi_device, data, len); |
2ab8b458 SK |
168 | break; |
169 | case MIPI_DSI_DCS_SHORT_WRITE: | |
759d10c2 | 170 | mipi_dsi_dcs_write_buffer(dsi_device, data, 1); |
2ab8b458 SK |
171 | break; |
172 | case MIPI_DSI_DCS_SHORT_WRITE_PARAM: | |
759d10c2 | 173 | mipi_dsi_dcs_write_buffer(dsi_device, data, 2); |
2ab8b458 SK |
174 | break; |
175 | case MIPI_DSI_DCS_READ: | |
176 | DRM_DEBUG_DRIVER("DCS Read not yet implemented or used\n"); | |
177 | break; | |
178 | case MIPI_DSI_DCS_LONG_WRITE: | |
759d10c2 | 179 | mipi_dsi_dcs_write_buffer(dsi_device, data, len); |
2ab8b458 | 180 | break; |
b5fbcd98 | 181 | } |
2ab8b458 | 182 | |
759d10c2 | 183 | out: |
2ab8b458 SK |
184 | data += len; |
185 | ||
186 | return data; | |
187 | } | |
188 | ||
5b48ca0f | 189 | static const u8 *mipi_exec_delay(struct intel_dsi *intel_dsi, const u8 *data) |
2ab8b458 | 190 | { |
5b48ca0f | 191 | u32 delay = *((const u32 *) data); |
2ab8b458 SK |
192 | |
193 | usleep_range(delay, delay + 10); | |
194 | data += 4; | |
195 | ||
196 | return data; | |
197 | } | |
198 | ||
5b48ca0f | 199 | static const u8 *mipi_exec_gpio(struct intel_dsi *intel_dsi, const u8 *data) |
2ab8b458 | 200 | { |
1d96a4a8 | 201 | u8 gpio_source, gpio_index, action, port; |
2ab8b458 SK |
202 | u16 function, pad; |
203 | u32 val; | |
204 | struct drm_device *dev = intel_dsi->base.base.dev; | |
205 | struct drm_i915_private *dev_priv = dev->dev_private; | |
206 | ||
96afef1d JN |
207 | if (dev_priv->vbt.dsi.seq_version >= 3) |
208 | data++; | |
209 | ||
e37788fd | 210 | gpio_index = *data++; |
2ab8b458 | 211 | |
1d96a4a8 JN |
212 | /* gpio source in sequence v2 only */ |
213 | if (dev_priv->vbt.dsi.seq_version == 2) | |
214 | gpio_source = (*data >> 1) & 3; | |
215 | else | |
216 | gpio_source = 0; | |
217 | ||
2ab8b458 | 218 | /* pull up/down */ |
4e1c63e3 | 219 | action = *data++ & 1; |
2ab8b458 | 220 | |
e37788fd JN |
221 | if (gpio_index >= ARRAY_SIZE(gtable)) { |
222 | DRM_DEBUG_KMS("unknown gpio index %u\n", gpio_index); | |
5d2d0a12 JN |
223 | goto out; |
224 | } | |
225 | ||
96afef1d JN |
226 | if (!IS_VALLEYVIEW(dev_priv)) { |
227 | DRM_DEBUG_KMS("GPIO element not supported on this platform\n"); | |
228 | goto out; | |
229 | } | |
230 | ||
231 | if (dev_priv->vbt.dsi.seq_version >= 3) { | |
232 | DRM_DEBUG_KMS("GPIO element v3 not supported\n"); | |
233 | goto out; | |
1d96a4a8 JN |
234 | } else { |
235 | if (gpio_source == 0) { | |
236 | port = IOSF_PORT_GPIO_NC; | |
237 | } else if (gpio_source == 1) { | |
238 | port = IOSF_PORT_GPIO_SC; | |
239 | } else { | |
240 | DRM_DEBUG_KMS("unknown gpio source %u\n", gpio_source); | |
241 | goto out; | |
242 | } | |
96afef1d JN |
243 | } |
244 | ||
e37788fd JN |
245 | function = gtable[gpio_index].function_reg; |
246 | pad = gtable[gpio_index].pad_reg; | |
2ab8b458 | 247 | |
a580516d | 248 | mutex_lock(&dev_priv->sb_lock); |
e37788fd | 249 | if (!gtable[gpio_index].init) { |
2ab8b458 SK |
250 | /* program the function */ |
251 | /* FIXME: remove constant below */ | |
1d96a4a8 | 252 | vlv_iosf_sb_write(dev_priv, port, function, 0x2000CC00); |
e37788fd | 253 | gtable[gpio_index].init = 1; |
2ab8b458 SK |
254 | } |
255 | ||
256 | val = 0x4 | action; | |
257 | ||
258 | /* pull up/down */ | |
1d96a4a8 | 259 | vlv_iosf_sb_write(dev_priv, port, pad, val); |
a580516d | 260 | mutex_unlock(&dev_priv->sb_lock); |
2ab8b458 | 261 | |
5d2d0a12 | 262 | out: |
2ab8b458 SK |
263 | return data; |
264 | } | |
265 | ||
29bbdcb0 JN |
266 | static const u8 *mipi_exec_i2c_skip(struct intel_dsi *intel_dsi, const u8 *data) |
267 | { | |
268 | return data + *(data + 6) + 7; | |
269 | } | |
270 | ||
5b48ca0f JN |
271 | typedef const u8 * (*fn_mipi_elem_exec)(struct intel_dsi *intel_dsi, |
272 | const u8 *data); | |
2ab8b458 | 273 | static const fn_mipi_elem_exec exec_elem[] = { |
28c72840 JN |
274 | [MIPI_SEQ_ELEM_SEND_PKT] = mipi_exec_send_packet, |
275 | [MIPI_SEQ_ELEM_DELAY] = mipi_exec_delay, | |
276 | [MIPI_SEQ_ELEM_GPIO] = mipi_exec_gpio, | |
29bbdcb0 | 277 | [MIPI_SEQ_ELEM_I2C] = mipi_exec_i2c_skip, |
2ab8b458 SK |
278 | }; |
279 | ||
280 | /* | |
281 | * MIPI Sequence from VBT #53 parsing logic | |
282 | * We have already separated each seqence during bios parsing | |
283 | * Following is generic execution function for any sequence | |
284 | */ | |
285 | ||
286 | static const char * const seq_name[] = { | |
5cda0d20 JN |
287 | [MIPI_SEQ_ASSERT_RESET] = "MIPI_SEQ_ASSERT_RESET", |
288 | [MIPI_SEQ_INIT_OTP] = "MIPI_SEQ_INIT_OTP", | |
289 | [MIPI_SEQ_DISPLAY_ON] = "MIPI_SEQ_DISPLAY_ON", | |
290 | [MIPI_SEQ_DISPLAY_OFF] = "MIPI_SEQ_DISPLAY_OFF", | |
291 | [MIPI_SEQ_DEASSERT_RESET] = "MIPI_SEQ_DEASSERT_RESET", | |
bc95ce7f JN |
292 | [MIPI_SEQ_BACKLIGHT_ON] = "MIPI_SEQ_BACKLIGHT_ON", |
293 | [MIPI_SEQ_BACKLIGHT_OFF] = "MIPI_SEQ_BACKLIGHT_OFF", | |
294 | [MIPI_SEQ_TEAR_ON] = "MIPI_SEQ_TEAR_ON", | |
295 | [MIPI_SEQ_TEAR_OFF] = "MIPI_SEQ_TEAR_OFF", | |
296 | [MIPI_SEQ_POWER_ON] = "MIPI_SEQ_POWER_ON", | |
297 | [MIPI_SEQ_POWER_OFF] = "MIPI_SEQ_POWER_OFF", | |
2ab8b458 SK |
298 | }; |
299 | ||
5cda0d20 JN |
300 | static const char *sequence_name(enum mipi_seq seq_id) |
301 | { | |
302 | if (seq_id < ARRAY_SIZE(seq_name) && seq_name[seq_id]) | |
303 | return seq_name[seq_id]; | |
304 | else | |
305 | return "(unknown)"; | |
306 | } | |
307 | ||
c67fed85 | 308 | static void generic_exec_sequence(struct drm_panel *panel, enum mipi_seq seq_id) |
2ab8b458 | 309 | { |
c67fed85 JN |
310 | struct vbt_panel *vbt_panel = to_vbt_panel(panel); |
311 | struct intel_dsi *intel_dsi = vbt_panel->intel_dsi; | |
2a33d934 | 312 | struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev); |
c67fed85 | 313 | const u8 *data; |
2ab8b458 | 314 | fn_mipi_elem_exec mipi_elem_exec; |
2ab8b458 | 315 | |
c67fed85 | 316 | if (WARN_ON(seq_id >= ARRAY_SIZE(dev_priv->vbt.dsi.sequence))) |
2ab8b458 SK |
317 | return; |
318 | ||
c67fed85 JN |
319 | data = dev_priv->vbt.dsi.sequence[seq_id]; |
320 | if (!data) { | |
321 | DRM_DEBUG_KMS("MIPI sequence %d - %s not available\n", | |
322 | seq_id, sequence_name(seq_id)); | |
323 | return; | |
324 | } | |
2ab8b458 | 325 | |
c67fed85 JN |
326 | WARN_ON(*data != seq_id); |
327 | ||
328 | DRM_DEBUG_KMS("Starting MIPI sequence %d - %s\n", | |
329 | seq_id, sequence_name(seq_id)); | |
330 | ||
331 | /* Skip Sequence Byte. */ | |
2ab8b458 SK |
332 | data++; |
333 | ||
2a33d934 JN |
334 | /* Skip Size of Sequence. */ |
335 | if (dev_priv->vbt.dsi.seq_version >= 3) | |
336 | data += 4; | |
337 | ||
2ab8b458 | 338 | while (1) { |
28c72840 | 339 | u8 operation_byte = *data++; |
40795782 JN |
340 | u8 operation_size = 0; |
341 | ||
342 | if (operation_byte == MIPI_SEQ_ELEM_END) | |
343 | break; | |
344 | ||
345 | if (operation_byte < ARRAY_SIZE(exec_elem)) | |
346 | mipi_elem_exec = exec_elem[operation_byte]; | |
347 | else | |
348 | mipi_elem_exec = NULL; | |
349 | ||
350 | /* Size of Operation. */ | |
351 | if (dev_priv->vbt.dsi.seq_version >= 3) | |
352 | operation_size = *data++; | |
353 | ||
354 | if (mipi_elem_exec) { | |
355 | data = mipi_elem_exec(intel_dsi, data); | |
356 | } else if (operation_size) { | |
357 | /* We have size, skip. */ | |
358 | DRM_DEBUG_KMS("Unsupported MIPI operation byte %u\n", | |
359 | operation_byte); | |
360 | data += operation_size; | |
361 | } else { | |
362 | /* No size, can't skip without parsing. */ | |
28c72840 JN |
363 | DRM_ERROR("Unsupported MIPI operation byte %u\n", |
364 | operation_byte); | |
2ab8b458 SK |
365 | return; |
366 | } | |
2ab8b458 SK |
367 | } |
368 | } | |
369 | ||
593e0622 JN |
370 | static int vbt_panel_prepare(struct drm_panel *panel) |
371 | { | |
c67fed85 JN |
372 | generic_exec_sequence(panel, MIPI_SEQ_ASSERT_RESET); |
373 | generic_exec_sequence(panel, MIPI_SEQ_INIT_OTP); | |
593e0622 JN |
374 | |
375 | return 0; | |
376 | } | |
377 | ||
378 | static int vbt_panel_unprepare(struct drm_panel *panel) | |
379 | { | |
c67fed85 | 380 | generic_exec_sequence(panel, MIPI_SEQ_DEASSERT_RESET); |
593e0622 JN |
381 | |
382 | return 0; | |
383 | } | |
384 | ||
385 | static int vbt_panel_enable(struct drm_panel *panel) | |
386 | { | |
c67fed85 | 387 | generic_exec_sequence(panel, MIPI_SEQ_DISPLAY_ON); |
593e0622 JN |
388 | |
389 | return 0; | |
390 | } | |
391 | ||
392 | static int vbt_panel_disable(struct drm_panel *panel) | |
393 | { | |
c67fed85 | 394 | generic_exec_sequence(panel, MIPI_SEQ_DISPLAY_OFF); |
593e0622 JN |
395 | |
396 | return 0; | |
397 | } | |
398 | ||
399 | static int vbt_panel_get_modes(struct drm_panel *panel) | |
400 | { | |
401 | struct vbt_panel *vbt_panel = to_vbt_panel(panel); | |
402 | struct intel_dsi *intel_dsi = vbt_panel->intel_dsi; | |
403 | struct drm_device *dev = intel_dsi->base.base.dev; | |
404 | struct drm_i915_private *dev_priv = dev->dev_private; | |
405 | struct drm_display_mode *mode; | |
406 | ||
407 | if (!panel->connector) | |
408 | return 0; | |
409 | ||
410 | mode = drm_mode_duplicate(dev, dev_priv->vbt.lfp_lvds_vbt_mode); | |
411 | if (!mode) | |
412 | return 0; | |
413 | ||
414 | mode->type |= DRM_MODE_TYPE_PREFERRED; | |
415 | ||
416 | drm_mode_probed_add(panel->connector, mode); | |
417 | ||
418 | return 1; | |
419 | } | |
420 | ||
421 | static const struct drm_panel_funcs vbt_panel_funcs = { | |
422 | .disable = vbt_panel_disable, | |
423 | .unprepare = vbt_panel_unprepare, | |
424 | .prepare = vbt_panel_prepare, | |
425 | .enable = vbt_panel_enable, | |
426 | .get_modes = vbt_panel_get_modes, | |
427 | }; | |
428 | ||
1e78aa01 JN |
429 | /* XXX: This should be done when parsing the VBT in intel_bios.c */ |
430 | static enum mipi_dsi_pixel_format pixel_format_from_vbt(u32 fmt) | |
431 | { | |
432 | /* It just so happens the VBT matches register contents. */ | |
433 | switch (fmt) { | |
434 | case VID_MODE_FORMAT_RGB888: | |
435 | return MIPI_DSI_FMT_RGB888; | |
436 | case VID_MODE_FORMAT_RGB666: | |
437 | return MIPI_DSI_FMT_RGB666; | |
438 | case VID_MODE_FORMAT_RGB666_PACKED: | |
439 | return MIPI_DSI_FMT_RGB666_PACKED; | |
440 | case VID_MODE_FORMAT_RGB565: | |
441 | return MIPI_DSI_FMT_RGB565; | |
442 | default: | |
443 | MISSING_CASE(fmt); | |
444 | return MIPI_DSI_FMT_RGB666; | |
445 | } | |
446 | } | |
447 | ||
593e0622 | 448 | struct drm_panel *vbt_panel_init(struct intel_dsi *intel_dsi, u16 panel_id) |
2ab8b458 | 449 | { |
2ab8b458 SK |
450 | struct drm_device *dev = intel_dsi->base.base.dev; |
451 | struct drm_i915_private *dev_priv = dev->dev_private; | |
452 | struct mipi_config *mipi_config = dev_priv->vbt.dsi.config; | |
453 | struct mipi_pps_data *pps = dev_priv->vbt.dsi.pps; | |
454 | struct drm_display_mode *mode = dev_priv->vbt.lfp_lvds_vbt_mode; | |
593e0622 | 455 | struct vbt_panel *vbt_panel; |
1e78aa01 | 456 | u32 bpp; |
2ab8b458 SK |
457 | u32 tlpx_ns, extra_byte_count, bitrate, tlpx_ui; |
458 | u32 ui_num, ui_den; | |
459 | u32 prepare_cnt, exit_zero_cnt, clk_zero_cnt, trail_cnt; | |
460 | u32 ths_prepare_ns, tclk_trail_ns; | |
461 | u32 tclk_prepare_clkzero, ths_prepare_hszero; | |
462 | u32 lp_to_hs_switch, hs_to_lp_switch; | |
7f0c8605 SK |
463 | u32 pclk, computed_ddr; |
464 | u16 burst_mode_ratio; | |
759d10c2 | 465 | enum port port; |
2ab8b458 SK |
466 | |
467 | DRM_DEBUG_KMS("\n"); | |
468 | ||
469 | intel_dsi->eotp_pkt = mipi_config->eot_pkt_disabled ? 0 : 1; | |
470 | intel_dsi->clock_stop = mipi_config->enable_clk_stop ? 1 : 0; | |
471 | intel_dsi->lane_count = mipi_config->lane_cnt + 1; | |
1e78aa01 JN |
472 | intel_dsi->pixel_format = pixel_format_from_vbt(mipi_config->videomode_color_format << 7); |
473 | bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); | |
474 | ||
369602d3 | 475 | intel_dsi->dual_link = mipi_config->dual_link; |
a9da9bce | 476 | intel_dsi->pixel_overlap = mipi_config->pixel_overlap; |
2ab8b458 SK |
477 | intel_dsi->operation_mode = mipi_config->is_cmd_mode; |
478 | intel_dsi->video_mode_format = mipi_config->video_transfer_mode; | |
479 | intel_dsi->escape_clk_div = mipi_config->byte_clk_sel; | |
480 | intel_dsi->lp_rx_timeout = mipi_config->lp_rx_timeout; | |
481 | intel_dsi->turn_arnd_val = mipi_config->turn_around_timeout; | |
482 | intel_dsi->rst_timer_val = mipi_config->device_reset_timer; | |
483 | intel_dsi->init_count = mipi_config->master_init_timer; | |
484 | intel_dsi->bw_timer = mipi_config->dbi_bw_timer; | |
b5fbcd98 SK |
485 | intel_dsi->video_frmt_cfg_bits = |
486 | mipi_config->bta_enabled ? DISABLE_VIDEO_BTA : 0; | |
2ab8b458 | 487 | |
7f0c8605 SK |
488 | pclk = mode->clock; |
489 | ||
a9da9bce GS |
490 | /* In dual link mode each port needs half of pixel clock */ |
491 | if (intel_dsi->dual_link) { | |
492 | pclk = pclk / 2; | |
493 | ||
494 | /* we can enable pixel_overlap if needed by panel. In this | |
495 | * case we need to increase the pixelclock for extra pixels | |
496 | */ | |
497 | if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) { | |
498 | pclk += DIV_ROUND_UP(mode->vtotal * | |
499 | intel_dsi->pixel_overlap * | |
500 | 60, 1000); | |
501 | } | |
502 | } | |
503 | ||
7f0c8605 SK |
504 | /* Burst Mode Ratio |
505 | * Target ddr frequency from VBT / non burst ddr freq | |
506 | * multiply by 100 to preserve remainder | |
507 | */ | |
508 | if (intel_dsi->video_mode_format == VIDEO_MODE_BURST) { | |
509 | if (mipi_config->target_burst_mode_freq) { | |
1e78aa01 | 510 | computed_ddr = (pclk * bpp) / intel_dsi->lane_count; |
7f0c8605 SK |
511 | |
512 | if (mipi_config->target_burst_mode_freq < | |
513 | computed_ddr) { | |
514 | DRM_ERROR("Burst mode freq is less than computed\n"); | |
593e0622 | 515 | return NULL; |
7f0c8605 SK |
516 | } |
517 | ||
518 | burst_mode_ratio = DIV_ROUND_UP( | |
519 | mipi_config->target_burst_mode_freq * 100, | |
520 | computed_ddr); | |
521 | ||
522 | pclk = DIV_ROUND_UP(pclk * burst_mode_ratio, 100); | |
523 | } else { | |
524 | DRM_ERROR("Burst mode target is not set\n"); | |
593e0622 | 525 | return NULL; |
7f0c8605 SK |
526 | } |
527 | } else | |
528 | burst_mode_ratio = 100; | |
529 | ||
530 | intel_dsi->burst_mode_ratio = burst_mode_ratio; | |
531 | intel_dsi->pclk = pclk; | |
532 | ||
1e78aa01 | 533 | bitrate = (pclk * bpp) / intel_dsi->lane_count; |
7f0c8605 | 534 | |
2ab8b458 SK |
535 | switch (intel_dsi->escape_clk_div) { |
536 | case 0: | |
537 | tlpx_ns = 50; | |
538 | break; | |
539 | case 1: | |
540 | tlpx_ns = 100; | |
541 | break; | |
542 | ||
543 | case 2: | |
544 | tlpx_ns = 200; | |
545 | break; | |
546 | default: | |
547 | tlpx_ns = 50; | |
548 | break; | |
549 | } | |
550 | ||
551 | switch (intel_dsi->lane_count) { | |
552 | case 1: | |
553 | case 2: | |
554 | extra_byte_count = 2; | |
555 | break; | |
556 | case 3: | |
557 | extra_byte_count = 4; | |
558 | break; | |
559 | case 4: | |
560 | default: | |
561 | extra_byte_count = 3; | |
562 | break; | |
563 | } | |
564 | ||
565 | /* | |
566 | * ui(s) = 1/f [f in hz] | |
567 | * ui(ns) = 10^9 / (f*10^6) [f in Mhz] -> 10^3/f(Mhz) | |
568 | */ | |
569 | ||
570 | /* in Kbps */ | |
571 | ui_num = NS_KHZ_RATIO; | |
572 | ui_den = bitrate; | |
573 | ||
574 | tclk_prepare_clkzero = mipi_config->tclk_prepare_clkzero; | |
575 | ths_prepare_hszero = mipi_config->ths_prepare_hszero; | |
576 | ||
577 | /* | |
578 | * B060 | |
579 | * LP byte clock = TLPX/ (8UI) | |
580 | */ | |
581 | intel_dsi->lp_byte_clk = DIV_ROUND_UP(tlpx_ns * ui_den, 8 * ui_num); | |
582 | ||
583 | /* count values in UI = (ns value) * (bitrate / (2 * 10^6)) | |
584 | * | |
585 | * Since txddrclkhs_i is 2xUI, all the count values programmed in | |
586 | * DPHY param register are divided by 2 | |
587 | * | |
588 | * prepare count | |
589 | */ | |
b5fbcd98 SK |
590 | ths_prepare_ns = max(mipi_config->ths_prepare, |
591 | mipi_config->tclk_prepare); | |
2ab8b458 SK |
592 | prepare_cnt = DIV_ROUND_UP(ths_prepare_ns * ui_den, ui_num * 2); |
593 | ||
594 | /* exit zero count */ | |
595 | exit_zero_cnt = DIV_ROUND_UP( | |
596 | (ths_prepare_hszero - ths_prepare_ns) * ui_den, | |
597 | ui_num * 2 | |
598 | ); | |
599 | ||
600 | /* | |
601 | * Exit zero is unified val ths_zero and ths_exit | |
602 | * minimum value for ths_exit = 110ns | |
603 | * min (exit_zero_cnt * 2) = 110/UI | |
604 | * exit_zero_cnt = 55/UI | |
605 | */ | |
606 | if (exit_zero_cnt < (55 * ui_den / ui_num)) | |
607 | if ((55 * ui_den) % ui_num) | |
608 | exit_zero_cnt += 1; | |
609 | ||
610 | /* clk zero count */ | |
611 | clk_zero_cnt = DIV_ROUND_UP( | |
612 | (tclk_prepare_clkzero - ths_prepare_ns) | |
613 | * ui_den, 2 * ui_num); | |
614 | ||
615 | /* trail count */ | |
616 | tclk_trail_ns = max(mipi_config->tclk_trail, mipi_config->ths_trail); | |
617 | trail_cnt = DIV_ROUND_UP(tclk_trail_ns * ui_den, 2 * ui_num); | |
618 | ||
619 | if (prepare_cnt > PREPARE_CNT_MAX || | |
620 | exit_zero_cnt > EXIT_ZERO_CNT_MAX || | |
621 | clk_zero_cnt > CLK_ZERO_CNT_MAX || | |
622 | trail_cnt > TRAIL_CNT_MAX) | |
623 | DRM_DEBUG_DRIVER("Values crossing maximum limits, restricting to max values\n"); | |
624 | ||
625 | if (prepare_cnt > PREPARE_CNT_MAX) | |
626 | prepare_cnt = PREPARE_CNT_MAX; | |
627 | ||
628 | if (exit_zero_cnt > EXIT_ZERO_CNT_MAX) | |
629 | exit_zero_cnt = EXIT_ZERO_CNT_MAX; | |
630 | ||
631 | if (clk_zero_cnt > CLK_ZERO_CNT_MAX) | |
632 | clk_zero_cnt = CLK_ZERO_CNT_MAX; | |
633 | ||
634 | if (trail_cnt > TRAIL_CNT_MAX) | |
635 | trail_cnt = TRAIL_CNT_MAX; | |
636 | ||
637 | /* B080 */ | |
638 | intel_dsi->dphy_reg = exit_zero_cnt << 24 | trail_cnt << 16 | | |
639 | clk_zero_cnt << 8 | prepare_cnt; | |
640 | ||
641 | /* | |
642 | * LP to HS switch count = 4TLPX + PREP_COUNT * 2 + EXIT_ZERO_COUNT * 2 | |
643 | * + 10UI + Extra Byte Count | |
644 | * | |
645 | * HS to LP switch count = THS-TRAIL + 2TLPX + Extra Byte Count | |
646 | * Extra Byte Count is calculated according to number of lanes. | |
647 | * High Low Switch Count is the Max of LP to HS and | |
648 | * HS to LP switch count | |
649 | * | |
650 | */ | |
651 | tlpx_ui = DIV_ROUND_UP(tlpx_ns * ui_den, ui_num); | |
652 | ||
653 | /* B044 */ | |
654 | /* FIXME: | |
655 | * The comment above does not match with the code */ | |
656 | lp_to_hs_switch = DIV_ROUND_UP(4 * tlpx_ui + prepare_cnt * 2 + | |
657 | exit_zero_cnt * 2 + 10, 8); | |
658 | ||
659 | hs_to_lp_switch = DIV_ROUND_UP(mipi_config->ths_trail + 2 * tlpx_ui, 8); | |
660 | ||
661 | intel_dsi->hs_to_lp_count = max(lp_to_hs_switch, hs_to_lp_switch); | |
662 | intel_dsi->hs_to_lp_count += extra_byte_count; | |
663 | ||
664 | /* B088 */ | |
665 | /* LP -> HS for clock lanes | |
666 | * LP clk sync + LP11 + LP01 + tclk_prepare + tclk_zero + | |
667 | * extra byte count | |
668 | * 2TPLX + 1TLPX + 1 TPLX(in ns) + prepare_cnt * 2 + clk_zero_cnt * | |
669 | * 2(in UI) + extra byte count | |
670 | * In byteclks = (4TLPX + prepare_cnt * 2 + clk_zero_cnt *2 (in UI)) / | |
671 | * 8 + extra byte count | |
672 | */ | |
673 | intel_dsi->clk_lp_to_hs_count = | |
674 | DIV_ROUND_UP( | |
675 | 4 * tlpx_ui + prepare_cnt * 2 + | |
676 | clk_zero_cnt * 2, | |
677 | 8); | |
678 | ||
679 | intel_dsi->clk_lp_to_hs_count += extra_byte_count; | |
680 | ||
681 | /* HS->LP for Clock Lanes | |
682 | * Low Power clock synchronisations + 1Tx byteclk + tclk_trail + | |
683 | * Extra byte count | |
684 | * 2TLPX + 8UI + (trail_count*2)(in UI) + Extra byte count | |
685 | * In byteclks = (2*TLpx(in UI) + trail_count*2 +8)(in UI)/8 + | |
686 | * Extra byte count | |
687 | */ | |
688 | intel_dsi->clk_hs_to_lp_count = | |
689 | DIV_ROUND_UP(2 * tlpx_ui + trail_cnt * 2 + 8, | |
690 | 8); | |
691 | intel_dsi->clk_hs_to_lp_count += extra_byte_count; | |
692 | ||
693 | DRM_DEBUG_KMS("Eot %s\n", intel_dsi->eotp_pkt ? "enabled" : "disabled"); | |
694 | DRM_DEBUG_KMS("Clockstop %s\n", intel_dsi->clock_stop ? | |
695 | "disabled" : "enabled"); | |
696 | DRM_DEBUG_KMS("Mode %s\n", intel_dsi->operation_mode ? "command" : "video"); | |
a9da9bce GS |
697 | if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) |
698 | DRM_DEBUG_KMS("Dual link: DSI_DUAL_LINK_FRONT_BACK\n"); | |
699 | else if (intel_dsi->dual_link == DSI_DUAL_LINK_PIXEL_ALT) | |
700 | DRM_DEBUG_KMS("Dual link: DSI_DUAL_LINK_PIXEL_ALT\n"); | |
701 | else | |
702 | DRM_DEBUG_KMS("Dual link: NONE\n"); | |
2ab8b458 SK |
703 | DRM_DEBUG_KMS("Pixel Format %d\n", intel_dsi->pixel_format); |
704 | DRM_DEBUG_KMS("TLPX %d\n", intel_dsi->escape_clk_div); | |
705 | DRM_DEBUG_KMS("LP RX Timeout 0x%x\n", intel_dsi->lp_rx_timeout); | |
706 | DRM_DEBUG_KMS("Turnaround Timeout 0x%x\n", intel_dsi->turn_arnd_val); | |
707 | DRM_DEBUG_KMS("Init Count 0x%x\n", intel_dsi->init_count); | |
708 | DRM_DEBUG_KMS("HS to LP Count 0x%x\n", intel_dsi->hs_to_lp_count); | |
709 | DRM_DEBUG_KMS("LP Byte Clock %d\n", intel_dsi->lp_byte_clk); | |
710 | DRM_DEBUG_KMS("DBI BW Timer 0x%x\n", intel_dsi->bw_timer); | |
711 | DRM_DEBUG_KMS("LP to HS Clock Count 0x%x\n", intel_dsi->clk_lp_to_hs_count); | |
712 | DRM_DEBUG_KMS("HS to LP Clock Count 0x%x\n", intel_dsi->clk_hs_to_lp_count); | |
713 | DRM_DEBUG_KMS("BTA %s\n", | |
714 | intel_dsi->video_frmt_cfg_bits & DISABLE_VIDEO_BTA ? | |
715 | "disabled" : "enabled"); | |
716 | ||
717 | /* delays in VBT are in unit of 100us, so need to convert | |
718 | * here in ms | |
719 | * Delay (100us) * 100 /1000 = Delay / 10 (ms) */ | |
720 | intel_dsi->backlight_off_delay = pps->bl_disable_delay / 10; | |
721 | intel_dsi->backlight_on_delay = pps->bl_enable_delay / 10; | |
722 | intel_dsi->panel_on_delay = pps->panel_on_delay / 10; | |
723 | intel_dsi->panel_off_delay = pps->panel_off_delay / 10; | |
724 | intel_dsi->panel_pwr_cycle_delay = pps->panel_power_cycle_delay / 10; | |
725 | ||
593e0622 JN |
726 | /* This is cheating a bit with the cleanup. */ |
727 | vbt_panel = devm_kzalloc(dev->dev, sizeof(*vbt_panel), GFP_KERNEL); | |
62ab420f IY |
728 | if (!vbt_panel) |
729 | return NULL; | |
2ab8b458 | 730 | |
593e0622 JN |
731 | vbt_panel->intel_dsi = intel_dsi; |
732 | drm_panel_init(&vbt_panel->panel); | |
733 | vbt_panel->panel.funcs = &vbt_panel_funcs; | |
734 | drm_panel_add(&vbt_panel->panel); | |
2ab8b458 | 735 | |
759d10c2 JN |
736 | /* a regular driver would get the device in probe */ |
737 | for_each_dsi_port(port, intel_dsi->ports) { | |
738 | mipi_dsi_attach(intel_dsi->dsi_hosts[port]->device); | |
739 | } | |
740 | ||
593e0622 | 741 | return &vbt_panel->panel; |
2ab8b458 | 742 | } |