1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <drm/drm_crtc.h>
28#include <drm/drm_edid.h>
29#include <drm/i915_drm.h>
30#include <linux/gpio/consumer.h>
31#include <linux/mfd/intel_soc_pmic.h>
32#include <linux/slab.h>
33#include <video/mipi_display.h>
34#include <asm/intel-mid.h>
35#include <asm/unaligned.h>
36#include "i915_drv.h"
37#include "intel_drv.h"
38#include "intel_dsi.h"
39
40#define MIPI_TRANSFER_MODE_SHIFT 0
41#define MIPI_VIRTUAL_CHANNEL_SHIFT 1
42#define MIPI_PORT_SHIFT 3
43
44#define PREPARE_CNT_MAX 0x3F
45#define EXIT_ZERO_CNT_MAX 0x3F
46#define CLK_ZERO_CNT_MAX 0xFF
47#define TRAIL_CNT_MAX 0x1F
48
49#define NS_KHZ_RATIO 1000000
50
51
52#define VLV_GPIO_NC_0_HV_DDI0_HPD 0x4130
53#define VLV_GPIO_NC_1_HV_DDI0_DDC_SDA 0x4120
54#define VLV_GPIO_NC_2_HV_DDI0_DDC_SCL 0x4110
55#define VLV_GPIO_NC_3_PANEL0_VDDEN 0x4140
56#define VLV_GPIO_NC_4_PANEL0_BKLTEN 0x4150
57#define VLV_GPIO_NC_5_PANEL0_BKLTCTL 0x4160
58#define VLV_GPIO_NC_6_HV_DDI1_HPD 0x4180
59#define VLV_GPIO_NC_7_HV_DDI1_DDC_SDA 0x4190
60#define VLV_GPIO_NC_8_HV_DDI1_DDC_SCL 0x4170
61#define VLV_GPIO_NC_9_PANEL1_VDDEN 0x4100
62#define VLV_GPIO_NC_10_PANEL1_BKLTEN 0x40E0
63#define VLV_GPIO_NC_11_PANEL1_BKLTCTL 0x40F0
64
65#define VLV_GPIO_PCONF0(base_offset) (base_offset)
66#define VLV_GPIO_PAD_VAL(base_offset) ((base_offset) + 8)
67
68struct gpio_map {
69 u16 base_offset;
70 bool init;
71};
72
73static struct gpio_map vlv_gpio_table[] = {
74 { VLV_GPIO_NC_0_HV_DDI0_HPD },
75 { VLV_GPIO_NC_1_HV_DDI0_DDC_SDA },
76 { VLV_GPIO_NC_2_HV_DDI0_DDC_SCL },
77 { VLV_GPIO_NC_3_PANEL0_VDDEN },
78 { VLV_GPIO_NC_4_PANEL0_BKLTEN },
79 { VLV_GPIO_NC_5_PANEL0_BKLTCTL },
80 { VLV_GPIO_NC_6_HV_DDI1_HPD },
81 { VLV_GPIO_NC_7_HV_DDI1_DDC_SDA },
82 { VLV_GPIO_NC_8_HV_DDI1_DDC_SCL },
83 { VLV_GPIO_NC_9_PANEL1_VDDEN },
84 { VLV_GPIO_NC_10_PANEL1_BKLTEN },
85 { VLV_GPIO_NC_11_PANEL1_BKLTCTL },
86};
87
88#define CHV_GPIO_IDX_START_N 0
89#define CHV_GPIO_IDX_START_E 73
90#define CHV_GPIO_IDX_START_SW 100
91#define CHV_GPIO_IDX_START_SE 198
92
93#define CHV_VBT_MAX_PINS_PER_FMLY 15
94
95#define CHV_GPIO_PAD_CFG0(f, i) (0x4400 + (f) * 0x400 + (i) * 8)
96#define CHV_GPIO_GPIOEN (1 << 15)
97#define CHV_GPIO_GPIOCFG_GPIO (0 << 8)
98#define CHV_GPIO_GPIOCFG_GPO (1 << 8)
99#define CHV_GPIO_GPIOCFG_GPI (2 << 8)
100#define CHV_GPIO_GPIOCFG_HIZ (3 << 8)
101#define CHV_GPIO_GPIOTXSTATE(state) ((!!(state)) << 1)
102
103#define CHV_GPIO_PAD_CFG1(f, i) (0x4400 + (f) * 0x400 + (i) * 8 + 4)
104#define CHV_GPIO_CFGLOCK (1 << 31)
105
106
107#define ICL_GPIO_DDSP_HPD_A 0
108#define ICL_GPIO_L_VDDEN_1 1
109#define ICL_GPIO_L_BKLTEN_1 2
110#define ICL_GPIO_DDPA_CTRLCLK_1 3
111#define ICL_GPIO_DDPA_CTRLDATA_1 4
112#define ICL_GPIO_DDSP_HPD_B 5
113#define ICL_GPIO_L_VDDEN_2 6
114#define ICL_GPIO_L_BKLTEN_2 7
115#define ICL_GPIO_DDPA_CTRLCLK_2 8
116#define ICL_GPIO_DDPA_CTRLDATA_2 9
117
118static inline enum port intel_dsi_seq_port_to_port(u8 port)
119{
120 return port ? PORT_C : PORT_A;
121}
122
123static const u8 *mipi_exec_send_packet(struct intel_dsi *intel_dsi,
124 const u8 *data)
125{
126 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
127 struct mipi_dsi_device *dsi_device;
128 u8 type, flags, seq_port;
129 u16 len;
130 enum port port;
131
132 DRM_DEBUG_KMS("\n");
133
134 flags = *data++;
135 type = *data++;
136
137 len = *((u16 *) data);
138 data += 2;
139
140 seq_port = (flags >> MIPI_PORT_SHIFT) & 3;
141
142
143
144
145
146
147 if (intel_dsi->ports == (1 << PORT_C))
148 port = PORT_C;
149 else
150 port = intel_dsi_seq_port_to_port(seq_port);
151
152 dsi_device = intel_dsi->dsi_hosts[port]->device;
153 if (!dsi_device) {
154 DRM_DEBUG_KMS("no dsi device for port %c\n", port_name(port));
155 goto out;
156 }
157
158 if ((flags >> MIPI_TRANSFER_MODE_SHIFT) & 1)
159 dsi_device->mode_flags &= ~MIPI_DSI_MODE_LPM;
160 else
161 dsi_device->mode_flags |= MIPI_DSI_MODE_LPM;
162
163 dsi_device->channel = (flags >> MIPI_VIRTUAL_CHANNEL_SHIFT) & 3;
164
165 switch (type) {
166 case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
167 mipi_dsi_generic_write(dsi_device, NULL, 0);
168 break;
169 case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
170 mipi_dsi_generic_write(dsi_device, data, 1);
171 break;
172 case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
173 mipi_dsi_generic_write(dsi_device, data, 2);
174 break;
175 case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
176 case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
177 case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
178 DRM_DEBUG_DRIVER("Generic Read not yet implemented or used\n");
179 break;
180 case MIPI_DSI_GENERIC_LONG_WRITE:
181 mipi_dsi_generic_write(dsi_device, data, len);
182 break;
183 case MIPI_DSI_DCS_SHORT_WRITE:
184 mipi_dsi_dcs_write_buffer(dsi_device, data, 1);
185 break;
186 case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
187 mipi_dsi_dcs_write_buffer(dsi_device, data, 2);
188 break;
189 case MIPI_DSI_DCS_READ:
190 DRM_DEBUG_DRIVER("DCS Read not yet implemented or used\n");
191 break;
192 case MIPI_DSI_DCS_LONG_WRITE:
193 mipi_dsi_dcs_write_buffer(dsi_device, data, len);
194 break;
195 }
196
197 if (INTEL_GEN(dev_priv) < 11)
198 vlv_dsi_wait_for_fifo_empty(intel_dsi, port);
199
200out:
201 data += len;
202
203 return data;
204}
205
206static const u8 *mipi_exec_delay(struct intel_dsi *intel_dsi, const u8 *data)
207{
208 u32 delay = *((const u32 *) data);
209
210 DRM_DEBUG_KMS("\n");
211
212 usleep_range(delay, delay + 10);
213 data += 4;
214
215 return data;
216}
217
218static void vlv_exec_gpio(struct drm_i915_private *dev_priv,
219 u8 gpio_source, u8 gpio_index, bool value)
220{
221 struct gpio_map *map;
222 u16 pconf0, padval;
223 u32 tmp;
224 u8 port;
225
226 if (gpio_index >= ARRAY_SIZE(vlv_gpio_table)) {
227 DRM_DEBUG_KMS("unknown gpio index %u\n", gpio_index);
228 return;
229 }
230
231 map = &vlv_gpio_table[gpio_index];
232
233 if (dev_priv->vbt.dsi.seq_version >= 3) {
234
235 port = IOSF_PORT_GPIO_NC;
236 } else {
237 if (gpio_source == 0) {
238 port = IOSF_PORT_GPIO_NC;
239 } else if (gpio_source == 1) {
240 DRM_DEBUG_KMS("SC gpio not supported\n");
241 return;
242 } else {
243 DRM_DEBUG_KMS("unknown gpio source %u\n", gpio_source);
244 return;
245 }
246 }
247
248 pconf0 = VLV_GPIO_PCONF0(map->base_offset);
249 padval = VLV_GPIO_PAD_VAL(map->base_offset);
250
251 mutex_lock(&dev_priv->sb_lock);
252 if (!map->init) {
253
254 vlv_iosf_sb_write(dev_priv, port, pconf0, 0x2000CC00);
255 map->init = true;
256 }
257
258 tmp = 0x4 | value;
259 vlv_iosf_sb_write(dev_priv, port, padval, tmp);
260 mutex_unlock(&dev_priv->sb_lock);
261}
262
263static void chv_exec_gpio(struct drm_i915_private *dev_priv,
264 u8 gpio_source, u8 gpio_index, bool value)
265{
266 u16 cfg0, cfg1;
267 u16 family_num;
268 u8 port;
269
270 if (dev_priv->vbt.dsi.seq_version >= 3) {
271 if (gpio_index >= CHV_GPIO_IDX_START_SE) {
272
273 gpio_index -= CHV_GPIO_IDX_START_SE;
274 port = CHV_IOSF_PORT_GPIO_SE;
275 } else if (gpio_index >= CHV_GPIO_IDX_START_SW) {
276 gpio_index -= CHV_GPIO_IDX_START_SW;
277 port = CHV_IOSF_PORT_GPIO_SW;
278 } else if (gpio_index >= CHV_GPIO_IDX_START_E) {
279 gpio_index -= CHV_GPIO_IDX_START_E;
280 port = CHV_IOSF_PORT_GPIO_E;
281 } else {
282 port = CHV_IOSF_PORT_GPIO_N;
283 }
284 } else {
285
286 if (gpio_source != 0) {
287 DRM_DEBUG_KMS("unknown gpio source %u\n", gpio_source);
288 return;
289 }
290
291 if (gpio_index >= CHV_GPIO_IDX_START_E) {
292 DRM_DEBUG_KMS("invalid gpio index %u for GPIO N\n",
293 gpio_index);
294 return;
295 }
296
297 port = CHV_IOSF_PORT_GPIO_N;
298 }
299
300 family_num = gpio_index / CHV_VBT_MAX_PINS_PER_FMLY;
301 gpio_index = gpio_index % CHV_VBT_MAX_PINS_PER_FMLY;
302
303 cfg0 = CHV_GPIO_PAD_CFG0(family_num, gpio_index);
304 cfg1 = CHV_GPIO_PAD_CFG1(family_num, gpio_index);
305
306 mutex_lock(&dev_priv->sb_lock);
307 vlv_iosf_sb_write(dev_priv, port, cfg1, 0);
308 vlv_iosf_sb_write(dev_priv, port, cfg0,
309 CHV_GPIO_GPIOEN | CHV_GPIO_GPIOCFG_GPO |
310 CHV_GPIO_GPIOTXSTATE(value));
311 mutex_unlock(&dev_priv->sb_lock);
312}
313
314static void bxt_exec_gpio(struct drm_i915_private *dev_priv,
315 u8 gpio_source, u8 gpio_index, bool value)
316{
317
318 static struct gpio_desc *bxt_gpio_table[U8_MAX + 1];
319 struct gpio_desc *gpio_desc = bxt_gpio_table[gpio_index];
320
321 if (!gpio_desc) {
322 gpio_desc = devm_gpiod_get_index(dev_priv->drm.dev,
323 NULL, gpio_index,
324 value ? GPIOD_OUT_LOW :
325 GPIOD_OUT_HIGH);
326
327 if (IS_ERR_OR_NULL(gpio_desc)) {
328 DRM_ERROR("GPIO index %u request failed (%ld)\n",
329 gpio_index, PTR_ERR(gpio_desc));
330 return;
331 }
332
333 bxt_gpio_table[gpio_index] = gpio_desc;
334 }
335
336 gpiod_set_value(gpio_desc, value);
337}
338
339static void icl_exec_gpio(struct drm_i915_private *dev_priv,
340 u8 gpio_source, u8 gpio_index, bool value)
341{
342 DRM_DEBUG_KMS("Skipping ICL GPIO element execution\n");
343}
344
345static const u8 *mipi_exec_gpio(struct intel_dsi *intel_dsi, const u8 *data)
346{
347 struct drm_device *dev = intel_dsi->base.base.dev;
348 struct drm_i915_private *dev_priv = to_i915(dev);
349 u8 gpio_source, gpio_index = 0, gpio_number;
350 bool value;
351
352 DRM_DEBUG_KMS("\n");
353
354 if (dev_priv->vbt.dsi.seq_version >= 3)
355 gpio_index = *data++;
356
357 gpio_number = *data++;
358
359
360 if (dev_priv->vbt.dsi.seq_version == 2)
361 gpio_source = (*data >> 1) & 3;
362 else
363 gpio_source = 0;
364
365
366 value = *data++ & 1;
367
368 if (INTEL_GEN(dev_priv) >= 11)
369 icl_exec_gpio(dev_priv, gpio_source, gpio_index, value);
370 else if (IS_VALLEYVIEW(dev_priv))
371 vlv_exec_gpio(dev_priv, gpio_source, gpio_number, value);
372 else if (IS_CHERRYVIEW(dev_priv))
373 chv_exec_gpio(dev_priv, gpio_source, gpio_number, value);
374 else
375 bxt_exec_gpio(dev_priv, gpio_source, gpio_index, value);
376
377 return data;
378}
379
380static const u8 *mipi_exec_i2c(struct intel_dsi *intel_dsi, const u8 *data)
381{
382 DRM_DEBUG_KMS("Skipping I2C element execution\n");
383
384 return data + *(data + 6) + 7;
385}
386
387static const u8 *mipi_exec_spi(struct intel_dsi *intel_dsi, const u8 *data)
388{
389 DRM_DEBUG_KMS("Skipping SPI element execution\n");
390
391 return data + *(data + 5) + 6;
392}
393
394static const u8 *mipi_exec_pmic(struct intel_dsi *intel_dsi, const u8 *data)
395{
396#ifdef CONFIG_PMIC_OPREGION
397 u32 value, mask, reg_address;
398 u16 i2c_address;
399 int ret;
400
401
402 i2c_address = get_unaligned_le16(data + 1);
403 reg_address = get_unaligned_le32(data + 3);
404 value = get_unaligned_le32(data + 7);
405 mask = get_unaligned_le32(data + 11);
406
407 ret = intel_soc_pmic_exec_mipi_pmic_seq_element(i2c_address,
408 reg_address,
409 value, mask);
410 if (ret)
411 DRM_ERROR("%s failed, error: %d\n", __func__, ret);
412#else
413 DRM_ERROR("Your hardware requires CONFIG_PMIC_OPREGION and it is not set\n");
414#endif
415
416 return data + 15;
417}
418
419typedef const u8 * (*fn_mipi_elem_exec)(struct intel_dsi *intel_dsi,
420 const u8 *data);
421static const fn_mipi_elem_exec exec_elem[] = {
422 [MIPI_SEQ_ELEM_SEND_PKT] = mipi_exec_send_packet,
423 [MIPI_SEQ_ELEM_DELAY] = mipi_exec_delay,
424 [MIPI_SEQ_ELEM_GPIO] = mipi_exec_gpio,
425 [MIPI_SEQ_ELEM_I2C] = mipi_exec_i2c,
426 [MIPI_SEQ_ELEM_SPI] = mipi_exec_spi,
427 [MIPI_SEQ_ELEM_PMIC] = mipi_exec_pmic,
428};
429
430
431
432
433
434
435
436static const char * const seq_name[] = {
437 [MIPI_SEQ_DEASSERT_RESET] = "MIPI_SEQ_DEASSERT_RESET",
438 [MIPI_SEQ_INIT_OTP] = "MIPI_SEQ_INIT_OTP",
439 [MIPI_SEQ_DISPLAY_ON] = "MIPI_SEQ_DISPLAY_ON",
440 [MIPI_SEQ_DISPLAY_OFF] = "MIPI_SEQ_DISPLAY_OFF",
441 [MIPI_SEQ_ASSERT_RESET] = "MIPI_SEQ_ASSERT_RESET",
442 [MIPI_SEQ_BACKLIGHT_ON] = "MIPI_SEQ_BACKLIGHT_ON",
443 [MIPI_SEQ_BACKLIGHT_OFF] = "MIPI_SEQ_BACKLIGHT_OFF",
444 [MIPI_SEQ_TEAR_ON] = "MIPI_SEQ_TEAR_ON",
445 [MIPI_SEQ_TEAR_OFF] = "MIPI_SEQ_TEAR_OFF",
446 [MIPI_SEQ_POWER_ON] = "MIPI_SEQ_POWER_ON",
447 [MIPI_SEQ_POWER_OFF] = "MIPI_SEQ_POWER_OFF",
448};
449
450static const char *sequence_name(enum mipi_seq seq_id)
451{
452 if (seq_id < ARRAY_SIZE(seq_name) && seq_name[seq_id])
453 return seq_name[seq_id];
454 else
455 return "(unknown)";
456}
457
458void intel_dsi_vbt_exec_sequence(struct intel_dsi *intel_dsi,
459 enum mipi_seq seq_id)
460{
461 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
462 const u8 *data;
463 fn_mipi_elem_exec mipi_elem_exec;
464
465 if (WARN_ON(seq_id >= ARRAY_SIZE(dev_priv->vbt.dsi.sequence)))
466 return;
467
468 data = dev_priv->vbt.dsi.sequence[seq_id];
469 if (!data)
470 return;
471
472 WARN_ON(*data != seq_id);
473
474 DRM_DEBUG_KMS("Starting MIPI sequence %d - %s\n",
475 seq_id, sequence_name(seq_id));
476
477
478 data++;
479
480
481 if (dev_priv->vbt.dsi.seq_version >= 3)
482 data += 4;
483
484 while (1) {
485 u8 operation_byte = *data++;
486 u8 operation_size = 0;
487
488 if (operation_byte == MIPI_SEQ_ELEM_END)
489 break;
490
491 if (operation_byte < ARRAY_SIZE(exec_elem))
492 mipi_elem_exec = exec_elem[operation_byte];
493 else
494 mipi_elem_exec = NULL;
495
496
497 if (dev_priv->vbt.dsi.seq_version >= 3)
498 operation_size = *data++;
499
500 if (mipi_elem_exec) {
501 const u8 *next = data + operation_size;
502
503 data = mipi_elem_exec(intel_dsi, data);
504
505
506 if (operation_size && data != next) {
507 DRM_ERROR("Inconsistent operation size\n");
508 return;
509 }
510 } else if (operation_size) {
511
512 DRM_DEBUG_KMS("Unsupported MIPI operation byte %u\n",
513 operation_byte);
514 data += operation_size;
515 } else {
516
517 DRM_ERROR("Unsupported MIPI operation byte %u\n",
518 operation_byte);
519 return;
520 }
521 }
522}
523
524void intel_dsi_msleep(struct intel_dsi *intel_dsi, int msec)
525{
526 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
527
528
529 if (is_vid_mode(intel_dsi) && dev_priv->vbt.dsi.seq_version >= 3)
530 return;
531
532 msleep(msec);
533}
534
535#define ICL_PREPARE_CNT_MAX 0x7
536#define ICL_CLK_ZERO_CNT_MAX 0xf
537#define ICL_TRAIL_CNT_MAX 0x7
538#define ICL_TCLK_PRE_CNT_MAX 0x3
539#define ICL_TCLK_POST_CNT_MAX 0x7
540#define ICL_HS_ZERO_CNT_MAX 0xf
541#define ICL_EXIT_ZERO_CNT_MAX 0x7
542
543static void icl_dphy_param_init(struct intel_dsi *intel_dsi)
544{
545 struct drm_device *dev = intel_dsi->base.base.dev;
546 struct drm_i915_private *dev_priv = to_i915(dev);
547 struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;
548 u32 tlpx_ns;
549 u32 prepare_cnt, exit_zero_cnt, clk_zero_cnt, trail_cnt;
550 u32 ths_prepare_ns, tclk_trail_ns;
551 u32 hs_zero_cnt;
552 u32 tclk_pre_cnt, tclk_post_cnt;
553
554 tlpx_ns = intel_dsi_tlpx_ns(intel_dsi);
555
556 tclk_trail_ns = max(mipi_config->tclk_trail, mipi_config->ths_trail);
557 ths_prepare_ns = max(mipi_config->ths_prepare,
558 mipi_config->tclk_prepare);
559
560
561
562
563
564
565
566
567 prepare_cnt = DIV_ROUND_UP(ths_prepare_ns * 4, tlpx_ns);
568 if (prepare_cnt > ICL_PREPARE_CNT_MAX) {
569 DRM_DEBUG_KMS("prepare_cnt out of range (%d)\n", prepare_cnt);
570 prepare_cnt = ICL_PREPARE_CNT_MAX;
571 }
572
573
574 clk_zero_cnt = DIV_ROUND_UP(mipi_config->tclk_prepare_clkzero -
575 ths_prepare_ns, tlpx_ns);
576 if (clk_zero_cnt > ICL_CLK_ZERO_CNT_MAX) {
577 DRM_DEBUG_KMS("clk_zero_cnt out of range (%d)\n", clk_zero_cnt);
578 clk_zero_cnt = ICL_CLK_ZERO_CNT_MAX;
579 }
580
581
582 trail_cnt = DIV_ROUND_UP(tclk_trail_ns, tlpx_ns);
583 if (trail_cnt > ICL_TRAIL_CNT_MAX) {
584 DRM_DEBUG_KMS("trail_cnt out of range (%d)\n", trail_cnt);
585 trail_cnt = ICL_TRAIL_CNT_MAX;
586 }
587
588
589 tclk_pre_cnt = DIV_ROUND_UP(mipi_config->tclk_pre, tlpx_ns);
590 if (tclk_pre_cnt > ICL_TCLK_PRE_CNT_MAX) {
591 DRM_DEBUG_KMS("tclk_pre_cnt out of range (%d)\n", tclk_pre_cnt);
592 tclk_pre_cnt = ICL_TCLK_PRE_CNT_MAX;
593 }
594
595
596 tclk_post_cnt = DIV_ROUND_UP(mipi_config->tclk_post, tlpx_ns);
597 if (tclk_post_cnt > ICL_TCLK_POST_CNT_MAX) {
598 DRM_DEBUG_KMS("tclk_post_cnt out of range (%d)\n", tclk_post_cnt);
599 tclk_post_cnt = ICL_TCLK_POST_CNT_MAX;
600 }
601
602
603 hs_zero_cnt = DIV_ROUND_UP(mipi_config->ths_prepare_hszero -
604 ths_prepare_ns, tlpx_ns);
605 if (hs_zero_cnt > ICL_HS_ZERO_CNT_MAX) {
606 DRM_DEBUG_KMS("hs_zero_cnt out of range (%d)\n", hs_zero_cnt);
607 hs_zero_cnt = ICL_HS_ZERO_CNT_MAX;
608 }
609
610
611 exit_zero_cnt = DIV_ROUND_UP(mipi_config->ths_exit, tlpx_ns);
612 if (exit_zero_cnt > ICL_EXIT_ZERO_CNT_MAX) {
613 DRM_DEBUG_KMS("exit_zero_cnt out of range (%d)\n", exit_zero_cnt);
614 exit_zero_cnt = ICL_EXIT_ZERO_CNT_MAX;
615 }
616
617
618 intel_dsi->dphy_reg = (CLK_PREPARE_OVERRIDE |
619 CLK_PREPARE(prepare_cnt) |
620 CLK_ZERO_OVERRIDE |
621 CLK_ZERO(clk_zero_cnt) |
622 CLK_PRE_OVERRIDE |
623 CLK_PRE(tclk_pre_cnt) |
624 CLK_POST_OVERRIDE |
625 CLK_POST(tclk_post_cnt) |
626 CLK_TRAIL_OVERRIDE |
627 CLK_TRAIL(trail_cnt));
628
629
630 intel_dsi->dphy_data_lane_reg = (HS_PREPARE_OVERRIDE |
631 HS_PREPARE(prepare_cnt) |
632 HS_ZERO_OVERRIDE |
633 HS_ZERO(hs_zero_cnt) |
634 HS_TRAIL_OVERRIDE |
635 HS_TRAIL(trail_cnt) |
636 HS_EXIT_OVERRIDE |
637 HS_EXIT(exit_zero_cnt));
638}
639
640static void vlv_dphy_param_init(struct intel_dsi *intel_dsi)
641{
642 struct drm_device *dev = intel_dsi->base.base.dev;
643 struct drm_i915_private *dev_priv = to_i915(dev);
644 struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;
645 u32 tlpx_ns, extra_byte_count, tlpx_ui;
646 u32 ui_num, ui_den;
647 u32 prepare_cnt, exit_zero_cnt, clk_zero_cnt, trail_cnt;
648 u32 ths_prepare_ns, tclk_trail_ns;
649 u32 tclk_prepare_clkzero, ths_prepare_hszero;
650 u32 lp_to_hs_switch, hs_to_lp_switch;
651 u32 mul;
652
653 tlpx_ns = intel_dsi_tlpx_ns(intel_dsi);
654
655 switch (intel_dsi->lane_count) {
656 case 1:
657 case 2:
658 extra_byte_count = 2;
659 break;
660 case 3:
661 extra_byte_count = 4;
662 break;
663 case 4:
664 default:
665 extra_byte_count = 3;
666 break;
667 }
668
669
670 ui_num = NS_KHZ_RATIO;
671 ui_den = intel_dsi_bitrate(intel_dsi);
672
673 tclk_prepare_clkzero = mipi_config->tclk_prepare_clkzero;
674 ths_prepare_hszero = mipi_config->ths_prepare_hszero;
675
676
677
678
679
680 intel_dsi->lp_byte_clk = DIV_ROUND_UP(tlpx_ns * ui_den, 8 * ui_num);
681
682
683
684
685
686
687
688
689
690
691 mul = IS_GEMINILAKE(dev_priv) ? 8 : 2;
692 ths_prepare_ns = max(mipi_config->ths_prepare,
693 mipi_config->tclk_prepare);
694
695
696 prepare_cnt = DIV_ROUND_UP(ths_prepare_ns * ui_den, ui_num * mul);
697
698 if (prepare_cnt > PREPARE_CNT_MAX) {
699 DRM_DEBUG_KMS("prepare count too high %u\n", prepare_cnt);
700 prepare_cnt = PREPARE_CNT_MAX;
701 }
702
703
704 exit_zero_cnt = DIV_ROUND_UP(
705 (ths_prepare_hszero - ths_prepare_ns) * ui_den,
706 ui_num * mul
707 );
708
709
710
711
712
713
714
715 if (exit_zero_cnt < (55 * ui_den / ui_num) && (55 * ui_den) % ui_num)
716 exit_zero_cnt += 1;
717
718 if (exit_zero_cnt > EXIT_ZERO_CNT_MAX) {
719 DRM_DEBUG_KMS("exit zero count too high %u\n", exit_zero_cnt);
720 exit_zero_cnt = EXIT_ZERO_CNT_MAX;
721 }
722
723
724 clk_zero_cnt = DIV_ROUND_UP(
725 (tclk_prepare_clkzero - ths_prepare_ns)
726 * ui_den, ui_num * mul);
727
728 if (clk_zero_cnt > CLK_ZERO_CNT_MAX) {
729 DRM_DEBUG_KMS("clock zero count too high %u\n", clk_zero_cnt);
730 clk_zero_cnt = CLK_ZERO_CNT_MAX;
731 }
732
733
734 tclk_trail_ns = max(mipi_config->tclk_trail, mipi_config->ths_trail);
735 trail_cnt = DIV_ROUND_UP(tclk_trail_ns * ui_den, ui_num * mul);
736
737 if (trail_cnt > TRAIL_CNT_MAX) {
738 DRM_DEBUG_KMS("trail count too high %u\n", trail_cnt);
739 trail_cnt = TRAIL_CNT_MAX;
740 }
741
742
743 intel_dsi->dphy_reg = exit_zero_cnt << 24 | trail_cnt << 16 |
744 clk_zero_cnt << 8 | prepare_cnt;
745
746
747
748
749
750
751
752
753
754
755
756 tlpx_ui = DIV_ROUND_UP(tlpx_ns * ui_den, ui_num);
757
758
759
760
761 lp_to_hs_switch = DIV_ROUND_UP(4 * tlpx_ui + prepare_cnt * mul +
762 exit_zero_cnt * mul + 10, 8);
763
764 hs_to_lp_switch = DIV_ROUND_UP(mipi_config->ths_trail + 2 * tlpx_ui, 8);
765
766 intel_dsi->hs_to_lp_count = max(lp_to_hs_switch, hs_to_lp_switch);
767 intel_dsi->hs_to_lp_count += extra_byte_count;
768
769
770
771
772
773
774
775
776
777
778 intel_dsi->clk_lp_to_hs_count =
779 DIV_ROUND_UP(
780 4 * tlpx_ui + prepare_cnt * 2 +
781 clk_zero_cnt * 2,
782 8);
783
784 intel_dsi->clk_lp_to_hs_count += extra_byte_count;
785
786
787
788
789
790
791
792
793 intel_dsi->clk_hs_to_lp_count =
794 DIV_ROUND_UP(2 * tlpx_ui + trail_cnt * 2 + 8,
795 8);
796 intel_dsi->clk_hs_to_lp_count += extra_byte_count;
797}
798
799bool intel_dsi_vbt_init(struct intel_dsi *intel_dsi, u16 panel_id)
800{
801 struct drm_device *dev = intel_dsi->base.base.dev;
802 struct drm_i915_private *dev_priv = to_i915(dev);
803 struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;
804 struct mipi_pps_data *pps = dev_priv->vbt.dsi.pps;
805 struct drm_display_mode *mode = dev_priv->vbt.lfp_lvds_vbt_mode;
806 u16 burst_mode_ratio;
807 enum port port;
808
809 DRM_DEBUG_KMS("\n");
810
811 intel_dsi->eotp_pkt = mipi_config->eot_pkt_disabled ? 0 : 1;
812 intel_dsi->clock_stop = mipi_config->enable_clk_stop ? 1 : 0;
813 intel_dsi->lane_count = mipi_config->lane_cnt + 1;
814 intel_dsi->pixel_format =
815 pixel_format_from_register_bits(
816 mipi_config->videomode_color_format << 7);
817
818 intel_dsi->dual_link = mipi_config->dual_link;
819 intel_dsi->pixel_overlap = mipi_config->pixel_overlap;
820 intel_dsi->operation_mode = mipi_config->is_cmd_mode;
821 intel_dsi->video_mode_format = mipi_config->video_transfer_mode;
822 intel_dsi->escape_clk_div = mipi_config->byte_clk_sel;
823 intel_dsi->lp_rx_timeout = mipi_config->lp_rx_timeout;
824 intel_dsi->hs_tx_timeout = mipi_config->hs_tx_timeout;
825 intel_dsi->turn_arnd_val = mipi_config->turn_around_timeout;
826 intel_dsi->rst_timer_val = mipi_config->device_reset_timer;
827 intel_dsi->init_count = mipi_config->master_init_timer;
828 intel_dsi->bw_timer = mipi_config->dbi_bw_timer;
829 intel_dsi->video_frmt_cfg_bits =
830 mipi_config->bta_enabled ? DISABLE_VIDEO_BTA : 0;
831 intel_dsi->bgr_enabled = mipi_config->rgb_flip;
832
833
834 intel_dsi->pclk = mode->clock;
835
836
837 if (intel_dsi->dual_link) {
838 intel_dsi->pclk /= 2;
839
840
841
842
843 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
844 intel_dsi->pclk += DIV_ROUND_UP(mode->vtotal * intel_dsi->pixel_overlap * 60, 1000);
845 }
846 }
847
848
849
850
851
852 if (intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
853 if (mipi_config->target_burst_mode_freq) {
854 u32 bitrate = intel_dsi_bitrate(intel_dsi);
855
856
857
858
859
860
861 if (mipi_config->target_burst_mode_freq < bitrate &&
862 intel_fuzzy_clock_check(
863 mipi_config->target_burst_mode_freq,
864 bitrate))
865 mipi_config->target_burst_mode_freq = bitrate;
866
867 if (mipi_config->target_burst_mode_freq < bitrate) {
868 DRM_ERROR("Burst mode freq is less than computed\n");
869 return false;
870 }
871
872 burst_mode_ratio = DIV_ROUND_UP(
873 mipi_config->target_burst_mode_freq * 100,
874 bitrate);
875
876 intel_dsi->pclk = DIV_ROUND_UP(intel_dsi->pclk * burst_mode_ratio, 100);
877 } else {
878 DRM_ERROR("Burst mode target is not set\n");
879 return false;
880 }
881 } else
882 burst_mode_ratio = 100;
883
884 intel_dsi->burst_mode_ratio = burst_mode_ratio;
885
886 if (INTEL_GEN(dev_priv) >= 11)
887 icl_dphy_param_init(intel_dsi);
888 else
889 vlv_dphy_param_init(intel_dsi);
890
891 DRM_DEBUG_KMS("Pclk %d\n", intel_dsi->pclk);
892 DRM_DEBUG_KMS("Pixel overlap %d\n", intel_dsi->pixel_overlap);
893 DRM_DEBUG_KMS("Lane count %d\n", intel_dsi->lane_count);
894 DRM_DEBUG_KMS("DPHY param reg 0x%x\n", intel_dsi->dphy_reg);
895 DRM_DEBUG_KMS("Video mode format %s\n",
896 intel_dsi->video_mode_format == VIDEO_MODE_NON_BURST_WITH_SYNC_PULSE ?
897 "non-burst with sync pulse" :
898 intel_dsi->video_mode_format == VIDEO_MODE_NON_BURST_WITH_SYNC_EVENTS ?
899 "non-burst with sync events" :
900 intel_dsi->video_mode_format == VIDEO_MODE_BURST ?
901 "burst" : "<unknown>");
902 DRM_DEBUG_KMS("Burst mode ratio %d\n", intel_dsi->burst_mode_ratio);
903 DRM_DEBUG_KMS("Reset timer %d\n", intel_dsi->rst_timer_val);
904 DRM_DEBUG_KMS("Eot %s\n", enableddisabled(intel_dsi->eotp_pkt));
905 DRM_DEBUG_KMS("Clockstop %s\n", enableddisabled(!intel_dsi->clock_stop));
906 DRM_DEBUG_KMS("Mode %s\n", intel_dsi->operation_mode ? "command" : "video");
907 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
908 DRM_DEBUG_KMS("Dual link: DSI_DUAL_LINK_FRONT_BACK\n");
909 else if (intel_dsi->dual_link == DSI_DUAL_LINK_PIXEL_ALT)
910 DRM_DEBUG_KMS("Dual link: DSI_DUAL_LINK_PIXEL_ALT\n");
911 else
912 DRM_DEBUG_KMS("Dual link: NONE\n");
913 DRM_DEBUG_KMS("Pixel Format %d\n", intel_dsi->pixel_format);
914 DRM_DEBUG_KMS("TLPX %d\n", intel_dsi->escape_clk_div);
915 DRM_DEBUG_KMS("LP RX Timeout 0x%x\n", intel_dsi->lp_rx_timeout);
916 DRM_DEBUG_KMS("Turnaround Timeout 0x%x\n", intel_dsi->turn_arnd_val);
917 DRM_DEBUG_KMS("Init Count 0x%x\n", intel_dsi->init_count);
918 DRM_DEBUG_KMS("HS to LP Count 0x%x\n", intel_dsi->hs_to_lp_count);
919 DRM_DEBUG_KMS("LP Byte Clock %d\n", intel_dsi->lp_byte_clk);
920 DRM_DEBUG_KMS("DBI BW Timer 0x%x\n", intel_dsi->bw_timer);
921 DRM_DEBUG_KMS("LP to HS Clock Count 0x%x\n", intel_dsi->clk_lp_to_hs_count);
922 DRM_DEBUG_KMS("HS to LP Clock Count 0x%x\n", intel_dsi->clk_hs_to_lp_count);
923 DRM_DEBUG_KMS("BTA %s\n",
924 enableddisabled(!(intel_dsi->video_frmt_cfg_bits & DISABLE_VIDEO_BTA)));
925
926
927
928
929 intel_dsi->backlight_off_delay = pps->bl_disable_delay / 10;
930 intel_dsi->backlight_on_delay = pps->bl_enable_delay / 10;
931 intel_dsi->panel_on_delay = pps->panel_on_delay / 10;
932 intel_dsi->panel_off_delay = pps->panel_off_delay / 10;
933 intel_dsi->panel_pwr_cycle_delay = pps->panel_power_cycle_delay / 10;
934
935
936 for_each_dsi_port(port, intel_dsi->ports) {
937 mipi_dsi_attach(intel_dsi->dsi_hosts[port]->device);
938 }
939
940 return true;
941}
942