2 * Copyright © 2014 Intel Corporation
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:
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
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.
23 * Author: Shobhit Kumar <shobhit.kumar@intel.com>
28 #include <drm/drm_crtc.h>
29 #include <drm/drm_edid.h>
30 #include <drm/i915_drm.h>
31 #include <drm/drm_panel.h>
32 #include <linux/gpio/consumer.h>
33 #include <linux/slab.h>
34 #include <video/mipi_display.h>
35 #include <asm/intel-mid.h>
36 #include <video/mipi_display.h>
38 #include "intel_drv.h"
39 #include "intel_dsi.h"
42 struct drm_panel panel;
43 struct intel_dsi *intel_dsi;
46 static inline struct vbt_panel *to_vbt_panel(struct drm_panel *panel)
48 return container_of(panel, struct vbt_panel, panel);
51 #define MIPI_TRANSFER_MODE_SHIFT 0
52 #define MIPI_VIRTUAL_CHANNEL_SHIFT 1
53 #define MIPI_PORT_SHIFT 3
55 #define PREPARE_CNT_MAX 0x3F
56 #define EXIT_ZERO_CNT_MAX 0x3F
57 #define CLK_ZERO_CNT_MAX 0xFF
58 #define TRAIL_CNT_MAX 0x1F
60 #define NS_KHZ_RATIO 1000000
62 /* base offsets for gpio pads */
63 #define VLV_GPIO_NC_0_HV_DDI0_HPD 0x4130
64 #define VLV_GPIO_NC_1_HV_DDI0_DDC_SDA 0x4120
65 #define VLV_GPIO_NC_2_HV_DDI0_DDC_SCL 0x4110
66 #define VLV_GPIO_NC_3_PANEL0_VDDEN 0x4140
67 #define VLV_GPIO_NC_4_PANEL0_BKLTEN 0x4150
68 #define VLV_GPIO_NC_5_PANEL0_BKLTCTL 0x4160
69 #define VLV_GPIO_NC_6_HV_DDI1_HPD 0x4180
70 #define VLV_GPIO_NC_7_HV_DDI1_DDC_SDA 0x4190
71 #define VLV_GPIO_NC_8_HV_DDI1_DDC_SCL 0x4170
72 #define VLV_GPIO_NC_9_PANEL1_VDDEN 0x4100
73 #define VLV_GPIO_NC_10_PANEL1_BKLTEN 0x40E0
74 #define VLV_GPIO_NC_11_PANEL1_BKLTCTL 0x40F0
76 #define VLV_GPIO_PCONF0(base_offset) (base_offset)
77 #define VLV_GPIO_PAD_VAL(base_offset) ((base_offset) + 8)
84 static struct gpio_map vlv_gpio_table[] = {
85 { VLV_GPIO_NC_0_HV_DDI0_HPD },
86 { VLV_GPIO_NC_1_HV_DDI0_DDC_SDA },
87 { VLV_GPIO_NC_2_HV_DDI0_DDC_SCL },
88 { VLV_GPIO_NC_3_PANEL0_VDDEN },
89 { VLV_GPIO_NC_4_PANEL0_BKLTEN },
90 { VLV_GPIO_NC_5_PANEL0_BKLTCTL },
91 { VLV_GPIO_NC_6_HV_DDI1_HPD },
92 { VLV_GPIO_NC_7_HV_DDI1_DDC_SDA },
93 { VLV_GPIO_NC_8_HV_DDI1_DDC_SCL },
94 { VLV_GPIO_NC_9_PANEL1_VDDEN },
95 { VLV_GPIO_NC_10_PANEL1_BKLTEN },
96 { VLV_GPIO_NC_11_PANEL1_BKLTCTL },
99 #define CHV_GPIO_IDX_START_N 0
100 #define CHV_GPIO_IDX_START_E 73
101 #define CHV_GPIO_IDX_START_SW 100
102 #define CHV_GPIO_IDX_START_SE 198
104 #define CHV_VBT_MAX_PINS_PER_FMLY 15
106 #define CHV_GPIO_PAD_CFG0(f, i) (0x4400 + (f) * 0x400 + (i) * 8)
107 #define CHV_GPIO_GPIOEN (1 << 15)
108 #define CHV_GPIO_GPIOCFG_GPIO (0 << 8)
109 #define CHV_GPIO_GPIOCFG_GPO (1 << 8)
110 #define CHV_GPIO_GPIOCFG_GPI (2 << 8)
111 #define CHV_GPIO_GPIOCFG_HIZ (3 << 8)
112 #define CHV_GPIO_GPIOTXSTATE(state) ((!!(state)) << 1)
114 #define CHV_GPIO_PAD_CFG1(f, i) (0x4400 + (f) * 0x400 + (i) * 8 + 4)
115 #define CHV_GPIO_CFGLOCK (1 << 31)
117 static inline enum port intel_dsi_seq_port_to_port(u8 port)
119 return port ? PORT_C : PORT_A;
122 static const u8 *mipi_exec_send_packet(struct intel_dsi *intel_dsi,
125 struct mipi_dsi_device *dsi_device;
126 u8 type, flags, seq_port;
135 len = *((u16 *) data);
138 seq_port = (flags >> MIPI_PORT_SHIFT) & 3;
140 /* For DSI single link on Port A & C, the seq_port value which is
141 * parsed from Sequence Block#53 of VBT has been set to 0
142 * Now, read/write of packets for the DSI single link on Port A and
143 * Port C will based on the DVO port from VBT block 2.
145 if (intel_dsi->ports == (1 << PORT_C))
148 port = intel_dsi_seq_port_to_port(seq_port);
150 dsi_device = intel_dsi->dsi_hosts[port]->device;
152 DRM_DEBUG_KMS("no dsi device for port %c\n", port_name(port));
156 if ((flags >> MIPI_TRANSFER_MODE_SHIFT) & 1)
157 dsi_device->mode_flags &= ~MIPI_DSI_MODE_LPM;
159 dsi_device->mode_flags |= MIPI_DSI_MODE_LPM;
161 dsi_device->channel = (flags >> MIPI_VIRTUAL_CHANNEL_SHIFT) & 3;
164 case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
165 mipi_dsi_generic_write(dsi_device, NULL, 0);
167 case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
168 mipi_dsi_generic_write(dsi_device, data, 1);
170 case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
171 mipi_dsi_generic_write(dsi_device, data, 2);
173 case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
174 case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
175 case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
176 DRM_DEBUG_DRIVER("Generic Read not yet implemented or used\n");
178 case MIPI_DSI_GENERIC_LONG_WRITE:
179 mipi_dsi_generic_write(dsi_device, data, len);
181 case MIPI_DSI_DCS_SHORT_WRITE:
182 mipi_dsi_dcs_write_buffer(dsi_device, data, 1);
184 case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
185 mipi_dsi_dcs_write_buffer(dsi_device, data, 2);
187 case MIPI_DSI_DCS_READ:
188 DRM_DEBUG_DRIVER("DCS Read not yet implemented or used\n");
190 case MIPI_DSI_DCS_LONG_WRITE:
191 mipi_dsi_dcs_write_buffer(dsi_device, data, len);
195 wait_for_dsi_fifo_empty(intel_dsi, port);
203 static const u8 *mipi_exec_delay(struct intel_dsi *intel_dsi, const u8 *data)
205 u32 delay = *((const u32 *) data);
209 usleep_range(delay, delay + 10);
215 static void vlv_exec_gpio(struct drm_i915_private *dev_priv,
216 u8 gpio_source, u8 gpio_index, bool value)
218 struct gpio_map *map;
223 if (gpio_index >= ARRAY_SIZE(vlv_gpio_table)) {
224 DRM_DEBUG_KMS("unknown gpio index %u\n", gpio_index);
228 map = &vlv_gpio_table[gpio_index];
230 if (dev_priv->vbt.dsi.seq_version >= 3) {
231 /* XXX: this assumes vlv_gpio_table only has NC GPIOs. */
232 port = IOSF_PORT_GPIO_NC;
234 if (gpio_source == 0) {
235 port = IOSF_PORT_GPIO_NC;
236 } else if (gpio_source == 1) {
237 DRM_DEBUG_KMS("SC gpio not supported\n");
240 DRM_DEBUG_KMS("unknown gpio source %u\n", gpio_source);
245 pconf0 = VLV_GPIO_PCONF0(map->base_offset);
246 padval = VLV_GPIO_PAD_VAL(map->base_offset);
248 mutex_lock(&dev_priv->sb_lock);
250 /* FIXME: remove constant below */
251 vlv_iosf_sb_write(dev_priv, port, pconf0, 0x2000CC00);
256 vlv_iosf_sb_write(dev_priv, port, padval, tmp);
257 mutex_unlock(&dev_priv->sb_lock);
260 static void chv_exec_gpio(struct drm_i915_private *dev_priv,
261 u8 gpio_source, u8 gpio_index, bool value)
267 if (dev_priv->vbt.dsi.seq_version >= 3) {
268 if (gpio_index >= CHV_GPIO_IDX_START_SE) {
269 /* XXX: it's unclear whether 255->57 is part of SE. */
270 gpio_index -= CHV_GPIO_IDX_START_SE;
271 port = CHV_IOSF_PORT_GPIO_SE;
272 } else if (gpio_index >= CHV_GPIO_IDX_START_SW) {
273 gpio_index -= CHV_GPIO_IDX_START_SW;
274 port = CHV_IOSF_PORT_GPIO_SW;
275 } else if (gpio_index >= CHV_GPIO_IDX_START_E) {
276 gpio_index -= CHV_GPIO_IDX_START_E;
277 port = CHV_IOSF_PORT_GPIO_E;
279 port = CHV_IOSF_PORT_GPIO_N;
282 /* XXX: The spec is unclear about CHV GPIO on seq v2 */
283 if (gpio_source != 0) {
284 DRM_DEBUG_KMS("unknown gpio source %u\n", gpio_source);
288 if (gpio_index >= CHV_GPIO_IDX_START_E) {
289 DRM_DEBUG_KMS("invalid gpio index %u for GPIO N\n",
294 port = CHV_IOSF_PORT_GPIO_N;
297 family_num = gpio_index / CHV_VBT_MAX_PINS_PER_FMLY;
298 gpio_index = gpio_index % CHV_VBT_MAX_PINS_PER_FMLY;
300 cfg0 = CHV_GPIO_PAD_CFG0(family_num, gpio_index);
301 cfg1 = CHV_GPIO_PAD_CFG1(family_num, gpio_index);
303 mutex_lock(&dev_priv->sb_lock);
304 vlv_iosf_sb_write(dev_priv, port, cfg1, 0);
305 vlv_iosf_sb_write(dev_priv, port, cfg0,
306 CHV_GPIO_GPIOEN | CHV_GPIO_GPIOCFG_GPO |
307 CHV_GPIO_GPIOTXSTATE(value));
308 mutex_unlock(&dev_priv->sb_lock);
311 static void bxt_exec_gpio(struct drm_i915_private *dev_priv,
312 u8 gpio_source, u8 gpio_index, bool value)
314 /* XXX: this table is a quick ugly hack. */
315 static struct gpio_desc *bxt_gpio_table[U8_MAX + 1];
316 struct gpio_desc *gpio_desc = bxt_gpio_table[gpio_index];
319 gpio_desc = devm_gpiod_get_index(dev_priv->drm.dev,
321 value ? GPIOD_OUT_LOW :
324 if (IS_ERR_OR_NULL(gpio_desc)) {
325 DRM_ERROR("GPIO index %u request failed (%ld)\n",
326 gpio_index, PTR_ERR(gpio_desc));
330 bxt_gpio_table[gpio_index] = gpio_desc;
333 gpiod_set_value(gpio_desc, value);
336 static const u8 *mipi_exec_gpio(struct intel_dsi *intel_dsi, const u8 *data)
338 struct drm_device *dev = intel_dsi->base.base.dev;
339 struct drm_i915_private *dev_priv = to_i915(dev);
340 u8 gpio_source, gpio_index = 0, gpio_number;
345 if (dev_priv->vbt.dsi.seq_version >= 3)
346 gpio_index = *data++;
348 gpio_number = *data++;
350 /* gpio source in sequence v2 only */
351 if (dev_priv->vbt.dsi.seq_version == 2)
352 gpio_source = (*data >> 1) & 3;
359 if (IS_VALLEYVIEW(dev_priv))
360 vlv_exec_gpio(dev_priv, gpio_source, gpio_number, value);
361 else if (IS_CHERRYVIEW(dev_priv))
362 chv_exec_gpio(dev_priv, gpio_source, gpio_number, value);
364 bxt_exec_gpio(dev_priv, gpio_source, gpio_index, value);
369 static const u8 *mipi_exec_i2c(struct intel_dsi *intel_dsi, const u8 *data)
371 DRM_DEBUG_KMS("Skipping I2C element execution\n");
373 return data + *(data + 6) + 7;
376 static const u8 *mipi_exec_spi(struct intel_dsi *intel_dsi, const u8 *data)
378 DRM_DEBUG_KMS("Skipping SPI element execution\n");
380 return data + *(data + 5) + 6;
383 static const u8 *mipi_exec_pmic(struct intel_dsi *intel_dsi, const u8 *data)
385 DRM_DEBUG_KMS("Skipping PMIC element execution\n");
390 typedef const u8 * (*fn_mipi_elem_exec)(struct intel_dsi *intel_dsi,
392 static const fn_mipi_elem_exec exec_elem[] = {
393 [MIPI_SEQ_ELEM_SEND_PKT] = mipi_exec_send_packet,
394 [MIPI_SEQ_ELEM_DELAY] = mipi_exec_delay,
395 [MIPI_SEQ_ELEM_GPIO] = mipi_exec_gpio,
396 [MIPI_SEQ_ELEM_I2C] = mipi_exec_i2c,
397 [MIPI_SEQ_ELEM_SPI] = mipi_exec_spi,
398 [MIPI_SEQ_ELEM_PMIC] = mipi_exec_pmic,
402 * MIPI Sequence from VBT #53 parsing logic
403 * We have already separated each seqence during bios parsing
404 * Following is generic execution function for any sequence
407 static const char * const seq_name[] = {
408 [MIPI_SEQ_DEASSERT_RESET] = "MIPI_SEQ_DEASSERT_RESET",
409 [MIPI_SEQ_INIT_OTP] = "MIPI_SEQ_INIT_OTP",
410 [MIPI_SEQ_DISPLAY_ON] = "MIPI_SEQ_DISPLAY_ON",
411 [MIPI_SEQ_DISPLAY_OFF] = "MIPI_SEQ_DISPLAY_OFF",
412 [MIPI_SEQ_ASSERT_RESET] = "MIPI_SEQ_ASSERT_RESET",
413 [MIPI_SEQ_BACKLIGHT_ON] = "MIPI_SEQ_BACKLIGHT_ON",
414 [MIPI_SEQ_BACKLIGHT_OFF] = "MIPI_SEQ_BACKLIGHT_OFF",
415 [MIPI_SEQ_TEAR_ON] = "MIPI_SEQ_TEAR_ON",
416 [MIPI_SEQ_TEAR_OFF] = "MIPI_SEQ_TEAR_OFF",
417 [MIPI_SEQ_POWER_ON] = "MIPI_SEQ_POWER_ON",
418 [MIPI_SEQ_POWER_OFF] = "MIPI_SEQ_POWER_OFF",
421 static const char *sequence_name(enum mipi_seq seq_id)
423 if (seq_id < ARRAY_SIZE(seq_name) && seq_name[seq_id])
424 return seq_name[seq_id];
429 static void generic_exec_sequence(struct drm_panel *panel, enum mipi_seq seq_id)
431 struct vbt_panel *vbt_panel = to_vbt_panel(panel);
432 struct intel_dsi *intel_dsi = vbt_panel->intel_dsi;
433 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
435 fn_mipi_elem_exec mipi_elem_exec;
437 if (WARN_ON(seq_id >= ARRAY_SIZE(dev_priv->vbt.dsi.sequence)))
440 data = dev_priv->vbt.dsi.sequence[seq_id];
444 WARN_ON(*data != seq_id);
446 DRM_DEBUG_KMS("Starting MIPI sequence %d - %s\n",
447 seq_id, sequence_name(seq_id));
449 /* Skip Sequence Byte. */
452 /* Skip Size of Sequence. */
453 if (dev_priv->vbt.dsi.seq_version >= 3)
457 u8 operation_byte = *data++;
458 u8 operation_size = 0;
460 if (operation_byte == MIPI_SEQ_ELEM_END)
463 if (operation_byte < ARRAY_SIZE(exec_elem))
464 mipi_elem_exec = exec_elem[operation_byte];
466 mipi_elem_exec = NULL;
468 /* Size of Operation. */
469 if (dev_priv->vbt.dsi.seq_version >= 3)
470 operation_size = *data++;
472 if (mipi_elem_exec) {
473 const u8 *next = data + operation_size;
475 data = mipi_elem_exec(intel_dsi, data);
477 /* Consistency check if we have size. */
478 if (operation_size && data != next) {
479 DRM_ERROR("Inconsistent operation size\n");
482 } else if (operation_size) {
483 /* We have size, skip. */
484 DRM_DEBUG_KMS("Unsupported MIPI operation byte %u\n",
486 data += operation_size;
488 /* No size, can't skip without parsing. */
489 DRM_ERROR("Unsupported MIPI operation byte %u\n",
496 static int vbt_panel_prepare(struct drm_panel *panel)
498 generic_exec_sequence(panel, MIPI_SEQ_ASSERT_RESET);
499 generic_exec_sequence(panel, MIPI_SEQ_POWER_ON);
500 generic_exec_sequence(panel, MIPI_SEQ_DEASSERT_RESET);
501 generic_exec_sequence(panel, MIPI_SEQ_INIT_OTP);
506 static int vbt_panel_unprepare(struct drm_panel *panel)
508 generic_exec_sequence(panel, MIPI_SEQ_ASSERT_RESET);
509 generic_exec_sequence(panel, MIPI_SEQ_POWER_OFF);
514 static int vbt_panel_enable(struct drm_panel *panel)
516 generic_exec_sequence(panel, MIPI_SEQ_DISPLAY_ON);
517 generic_exec_sequence(panel, MIPI_SEQ_BACKLIGHT_ON);
522 static int vbt_panel_disable(struct drm_panel *panel)
524 generic_exec_sequence(panel, MIPI_SEQ_BACKLIGHT_OFF);
525 generic_exec_sequence(panel, MIPI_SEQ_DISPLAY_OFF);
530 static int vbt_panel_get_modes(struct drm_panel *panel)
532 struct vbt_panel *vbt_panel = to_vbt_panel(panel);
533 struct intel_dsi *intel_dsi = vbt_panel->intel_dsi;
534 struct drm_device *dev = intel_dsi->base.base.dev;
535 struct drm_i915_private *dev_priv = to_i915(dev);
536 struct drm_display_mode *mode;
538 if (!panel->connector)
541 mode = drm_mode_duplicate(dev, dev_priv->vbt.lfp_lvds_vbt_mode);
545 mode->type |= DRM_MODE_TYPE_PREFERRED;
547 drm_mode_probed_add(panel->connector, mode);
552 static const struct drm_panel_funcs vbt_panel_funcs = {
553 .disable = vbt_panel_disable,
554 .unprepare = vbt_panel_unprepare,
555 .prepare = vbt_panel_prepare,
556 .enable = vbt_panel_enable,
557 .get_modes = vbt_panel_get_modes,
560 struct drm_panel *vbt_panel_init(struct intel_dsi *intel_dsi, u16 panel_id)
562 struct drm_device *dev = intel_dsi->base.base.dev;
563 struct drm_i915_private *dev_priv = to_i915(dev);
564 struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;
565 struct mipi_pps_data *pps = dev_priv->vbt.dsi.pps;
566 struct drm_display_mode *mode = dev_priv->vbt.lfp_lvds_vbt_mode;
567 struct vbt_panel *vbt_panel;
569 u32 tlpx_ns, extra_byte_count, bitrate, tlpx_ui;
571 u32 prepare_cnt, exit_zero_cnt, clk_zero_cnt, trail_cnt;
572 u32 ths_prepare_ns, tclk_trail_ns;
573 u32 tclk_prepare_clkzero, ths_prepare_hszero;
574 u32 lp_to_hs_switch, hs_to_lp_switch;
575 u32 pclk, computed_ddr;
577 u16 burst_mode_ratio;
582 intel_dsi->eotp_pkt = mipi_config->eot_pkt_disabled ? 0 : 1;
583 intel_dsi->clock_stop = mipi_config->enable_clk_stop ? 1 : 0;
584 intel_dsi->lane_count = mipi_config->lane_cnt + 1;
585 intel_dsi->pixel_format =
586 pixel_format_from_register_bits(
587 mipi_config->videomode_color_format << 7);
588 bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
590 intel_dsi->dual_link = mipi_config->dual_link;
591 intel_dsi->pixel_overlap = mipi_config->pixel_overlap;
592 intel_dsi->operation_mode = mipi_config->is_cmd_mode;
593 intel_dsi->video_mode_format = mipi_config->video_transfer_mode;
594 intel_dsi->escape_clk_div = mipi_config->byte_clk_sel;
595 intel_dsi->lp_rx_timeout = mipi_config->lp_rx_timeout;
596 intel_dsi->turn_arnd_val = mipi_config->turn_around_timeout;
597 intel_dsi->rst_timer_val = mipi_config->device_reset_timer;
598 intel_dsi->init_count = mipi_config->master_init_timer;
599 intel_dsi->bw_timer = mipi_config->dbi_bw_timer;
600 intel_dsi->video_frmt_cfg_bits =
601 mipi_config->bta_enabled ? DISABLE_VIDEO_BTA : 0;
605 /* In dual link mode each port needs half of pixel clock */
606 if (intel_dsi->dual_link) {
609 /* we can enable pixel_overlap if needed by panel. In this
610 * case we need to increase the pixelclock for extra pixels
612 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
613 pclk += DIV_ROUND_UP(mode->vtotal *
614 intel_dsi->pixel_overlap *
620 * Target ddr frequency from VBT / non burst ddr freq
621 * multiply by 100 to preserve remainder
623 if (intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
624 if (mipi_config->target_burst_mode_freq) {
625 computed_ddr = (pclk * bpp) / intel_dsi->lane_count;
627 if (mipi_config->target_burst_mode_freq <
629 DRM_ERROR("Burst mode freq is less than computed\n");
633 burst_mode_ratio = DIV_ROUND_UP(
634 mipi_config->target_burst_mode_freq * 100,
637 pclk = DIV_ROUND_UP(pclk * burst_mode_ratio, 100);
639 DRM_ERROR("Burst mode target is not set\n");
643 burst_mode_ratio = 100;
645 intel_dsi->burst_mode_ratio = burst_mode_ratio;
646 intel_dsi->pclk = pclk;
648 bitrate = (pclk * bpp) / intel_dsi->lane_count;
650 switch (intel_dsi->escape_clk_div) {
666 switch (intel_dsi->lane_count) {
669 extra_byte_count = 2;
672 extra_byte_count = 4;
676 extra_byte_count = 3;
681 ui_num = NS_KHZ_RATIO;
684 tclk_prepare_clkzero = mipi_config->tclk_prepare_clkzero;
685 ths_prepare_hszero = mipi_config->ths_prepare_hszero;
689 * LP byte clock = TLPX/ (8UI)
691 intel_dsi->lp_byte_clk = DIV_ROUND_UP(tlpx_ns * ui_den, 8 * ui_num);
693 /* DDR clock period = 2 * UI
694 * UI(sec) = 1/(bitrate * 10^3) (bitrate is in KHZ)
695 * UI(nsec) = 10^6 / bitrate
696 * DDR clock period (nsec) = 2 * UI = (2 * 10^6)/ bitrate
697 * DDR clock count = ns_value / DDR clock period
699 * For GEMINILAKE dphy_param_reg will be programmed in terms of
700 * HS byte clock count for other platform in HS ddr clock count
702 mul = IS_GEMINILAKE(dev_priv) ? 8 : 2;
703 ths_prepare_ns = max(mipi_config->ths_prepare,
704 mipi_config->tclk_prepare);
707 prepare_cnt = DIV_ROUND_UP(ths_prepare_ns * ui_den, ui_num * mul);
709 /* exit zero count */
710 exit_zero_cnt = DIV_ROUND_UP(
711 (ths_prepare_hszero - ths_prepare_ns) * ui_den,
716 * Exit zero is unified val ths_zero and ths_exit
717 * minimum value for ths_exit = 110ns
718 * min (exit_zero_cnt * 2) = 110/UI
719 * exit_zero_cnt = 55/UI
721 if (exit_zero_cnt < (55 * ui_den / ui_num) && (55 * ui_den) % ui_num)
725 clk_zero_cnt = DIV_ROUND_UP(
726 (tclk_prepare_clkzero - ths_prepare_ns)
727 * ui_den, ui_num * mul);
730 tclk_trail_ns = max(mipi_config->tclk_trail, mipi_config->ths_trail);
731 trail_cnt = DIV_ROUND_UP(tclk_trail_ns * ui_den, ui_num * mul);
733 if (prepare_cnt > PREPARE_CNT_MAX ||
734 exit_zero_cnt > EXIT_ZERO_CNT_MAX ||
735 clk_zero_cnt > CLK_ZERO_CNT_MAX ||
736 trail_cnt > TRAIL_CNT_MAX)
737 DRM_DEBUG_DRIVER("Values crossing maximum limits, restricting to max values\n");
739 if (prepare_cnt > PREPARE_CNT_MAX)
740 prepare_cnt = PREPARE_CNT_MAX;
742 if (exit_zero_cnt > EXIT_ZERO_CNT_MAX)
743 exit_zero_cnt = EXIT_ZERO_CNT_MAX;
745 if (clk_zero_cnt > CLK_ZERO_CNT_MAX)
746 clk_zero_cnt = CLK_ZERO_CNT_MAX;
748 if (trail_cnt > TRAIL_CNT_MAX)
749 trail_cnt = TRAIL_CNT_MAX;
752 intel_dsi->dphy_reg = exit_zero_cnt << 24 | trail_cnt << 16 |
753 clk_zero_cnt << 8 | prepare_cnt;
756 * LP to HS switch count = 4TLPX + PREP_COUNT * 2 + EXIT_ZERO_COUNT * 2
757 * + 10UI + Extra Byte Count
759 * HS to LP switch count = THS-TRAIL + 2TLPX + Extra Byte Count
760 * Extra Byte Count is calculated according to number of lanes.
761 * High Low Switch Count is the Max of LP to HS and
762 * HS to LP switch count
765 tlpx_ui = DIV_ROUND_UP(tlpx_ns * ui_den, ui_num);
769 * The comment above does not match with the code */
770 lp_to_hs_switch = DIV_ROUND_UP(4 * tlpx_ui + prepare_cnt * 2 +
771 exit_zero_cnt * 2 + 10, 8);
773 hs_to_lp_switch = DIV_ROUND_UP(mipi_config->ths_trail + 2 * tlpx_ui, 8);
775 intel_dsi->hs_to_lp_count = max(lp_to_hs_switch, hs_to_lp_switch);
776 intel_dsi->hs_to_lp_count += extra_byte_count;
779 /* LP -> HS for clock lanes
780 * LP clk sync + LP11 + LP01 + tclk_prepare + tclk_zero +
782 * 2TPLX + 1TLPX + 1 TPLX(in ns) + prepare_cnt * 2 + clk_zero_cnt *
783 * 2(in UI) + extra byte count
784 * In byteclks = (4TLPX + prepare_cnt * 2 + clk_zero_cnt *2 (in UI)) /
785 * 8 + extra byte count
787 intel_dsi->clk_lp_to_hs_count =
789 4 * tlpx_ui + prepare_cnt * 2 +
793 intel_dsi->clk_lp_to_hs_count += extra_byte_count;
795 /* HS->LP for Clock Lanes
796 * Low Power clock synchronisations + 1Tx byteclk + tclk_trail +
798 * 2TLPX + 8UI + (trail_count*2)(in UI) + Extra byte count
799 * In byteclks = (2*TLpx(in UI) + trail_count*2 +8)(in UI)/8 +
802 intel_dsi->clk_hs_to_lp_count =
803 DIV_ROUND_UP(2 * tlpx_ui + trail_cnt * 2 + 8,
805 intel_dsi->clk_hs_to_lp_count += extra_byte_count;
807 DRM_DEBUG_KMS("Pclk %d\n", intel_dsi->pclk);
808 DRM_DEBUG_KMS("Pixel overlap %d\n", intel_dsi->pixel_overlap);
809 DRM_DEBUG_KMS("Lane count %d\n", intel_dsi->lane_count);
810 DRM_DEBUG_KMS("DPHY param reg 0x%x\n", intel_dsi->dphy_reg);
811 DRM_DEBUG_KMS("Video mode format %s\n",
812 intel_dsi->video_mode_format == VIDEO_MODE_NON_BURST_WITH_SYNC_PULSE ?
813 "non-burst with sync pulse" :
814 intel_dsi->video_mode_format == VIDEO_MODE_NON_BURST_WITH_SYNC_EVENTS ?
815 "non-burst with sync events" :
816 intel_dsi->video_mode_format == VIDEO_MODE_BURST ?
817 "burst" : "<unknown>");
818 DRM_DEBUG_KMS("Burst mode ratio %d\n", intel_dsi->burst_mode_ratio);
819 DRM_DEBUG_KMS("Reset timer %d\n", intel_dsi->rst_timer_val);
820 DRM_DEBUG_KMS("Eot %s\n", enableddisabled(intel_dsi->eotp_pkt));
821 DRM_DEBUG_KMS("Clockstop %s\n", enableddisabled(!intel_dsi->clock_stop));
822 DRM_DEBUG_KMS("Mode %s\n", intel_dsi->operation_mode ? "command" : "video");
823 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
824 DRM_DEBUG_KMS("Dual link: DSI_DUAL_LINK_FRONT_BACK\n");
825 else if (intel_dsi->dual_link == DSI_DUAL_LINK_PIXEL_ALT)
826 DRM_DEBUG_KMS("Dual link: DSI_DUAL_LINK_PIXEL_ALT\n");
828 DRM_DEBUG_KMS("Dual link: NONE\n");
829 DRM_DEBUG_KMS("Pixel Format %d\n", intel_dsi->pixel_format);
830 DRM_DEBUG_KMS("TLPX %d\n", intel_dsi->escape_clk_div);
831 DRM_DEBUG_KMS("LP RX Timeout 0x%x\n", intel_dsi->lp_rx_timeout);
832 DRM_DEBUG_KMS("Turnaround Timeout 0x%x\n", intel_dsi->turn_arnd_val);
833 DRM_DEBUG_KMS("Init Count 0x%x\n", intel_dsi->init_count);
834 DRM_DEBUG_KMS("HS to LP Count 0x%x\n", intel_dsi->hs_to_lp_count);
835 DRM_DEBUG_KMS("LP Byte Clock %d\n", intel_dsi->lp_byte_clk);
836 DRM_DEBUG_KMS("DBI BW Timer 0x%x\n", intel_dsi->bw_timer);
837 DRM_DEBUG_KMS("LP to HS Clock Count 0x%x\n", intel_dsi->clk_lp_to_hs_count);
838 DRM_DEBUG_KMS("HS to LP Clock Count 0x%x\n", intel_dsi->clk_hs_to_lp_count);
839 DRM_DEBUG_KMS("BTA %s\n",
840 enableddisabled(!(intel_dsi->video_frmt_cfg_bits & DISABLE_VIDEO_BTA)));
842 /* delays in VBT are in unit of 100us, so need to convert
844 * Delay (100us) * 100 /1000 = Delay / 10 (ms) */
845 intel_dsi->backlight_off_delay = pps->bl_disable_delay / 10;
846 intel_dsi->backlight_on_delay = pps->bl_enable_delay / 10;
847 intel_dsi->panel_on_delay = pps->panel_on_delay / 10;
848 intel_dsi->panel_off_delay = pps->panel_off_delay / 10;
849 intel_dsi->panel_pwr_cycle_delay = pps->panel_power_cycle_delay / 10;
851 /* This is cheating a bit with the cleanup. */
852 vbt_panel = devm_kzalloc(dev->dev, sizeof(*vbt_panel), GFP_KERNEL);
856 vbt_panel->intel_dsi = intel_dsi;
857 drm_panel_init(&vbt_panel->panel);
858 vbt_panel->panel.funcs = &vbt_panel_funcs;
859 drm_panel_add(&vbt_panel->panel);
861 /* a regular driver would get the device in probe */
862 for_each_dsi_port(port, intel_dsi->ports) {
863 mipi_dsi_attach(intel_dsi->dsi_hosts[port]->device);
866 return &vbt_panel->panel;