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>
27 #include <linux/gpio/consumer.h>
28 #include <linux/gpio/machine.h>
29 #include <linux/mfd/intel_soc_pmic.h>
30 #include <linux/pinctrl/consumer.h>
31 #include <linux/pinctrl/machine.h>
32 #include <linux/slab.h>
34 #include <asm/intel-mid.h>
35 #include <asm/unaligned.h>
37 #include <drm/drm_crtc.h>
38 #include <drm/drm_edid.h>
39 #include <drm/i915_drm.h>
41 #include <video/mipi_display.h>
44 #include "intel_display_types.h"
45 #include "intel_dsi.h"
46 #include "intel_sideband.h"
48 #define MIPI_TRANSFER_MODE_SHIFT 0
49 #define MIPI_VIRTUAL_CHANNEL_SHIFT 1
50 #define MIPI_PORT_SHIFT 3
52 /* base offsets for gpio pads */
53 #define VLV_GPIO_NC_0_HV_DDI0_HPD 0x4130
54 #define VLV_GPIO_NC_1_HV_DDI0_DDC_SDA 0x4120
55 #define VLV_GPIO_NC_2_HV_DDI0_DDC_SCL 0x4110
56 #define VLV_GPIO_NC_3_PANEL0_VDDEN 0x4140
57 #define VLV_GPIO_NC_4_PANEL0_BKLTEN 0x4150
58 #define VLV_GPIO_NC_5_PANEL0_BKLTCTL 0x4160
59 #define VLV_GPIO_NC_6_HV_DDI1_HPD 0x4180
60 #define VLV_GPIO_NC_7_HV_DDI1_DDC_SDA 0x4190
61 #define VLV_GPIO_NC_8_HV_DDI1_DDC_SCL 0x4170
62 #define VLV_GPIO_NC_9_PANEL1_VDDEN 0x4100
63 #define VLV_GPIO_NC_10_PANEL1_BKLTEN 0x40E0
64 #define VLV_GPIO_NC_11_PANEL1_BKLTCTL 0x40F0
66 #define VLV_GPIO_PCONF0(base_offset) (base_offset)
67 #define VLV_GPIO_PAD_VAL(base_offset) ((base_offset) + 8)
74 static struct gpio_map vlv_gpio_table[] = {
75 { VLV_GPIO_NC_0_HV_DDI0_HPD },
76 { VLV_GPIO_NC_1_HV_DDI0_DDC_SDA },
77 { VLV_GPIO_NC_2_HV_DDI0_DDC_SCL },
78 { VLV_GPIO_NC_3_PANEL0_VDDEN },
79 { VLV_GPIO_NC_4_PANEL0_BKLTEN },
80 { VLV_GPIO_NC_5_PANEL0_BKLTCTL },
81 { VLV_GPIO_NC_6_HV_DDI1_HPD },
82 { VLV_GPIO_NC_7_HV_DDI1_DDC_SDA },
83 { VLV_GPIO_NC_8_HV_DDI1_DDC_SCL },
84 { VLV_GPIO_NC_9_PANEL1_VDDEN },
85 { VLV_GPIO_NC_10_PANEL1_BKLTEN },
86 { VLV_GPIO_NC_11_PANEL1_BKLTCTL },
89 #define CHV_GPIO_IDX_START_N 0
90 #define CHV_GPIO_IDX_START_E 73
91 #define CHV_GPIO_IDX_START_SW 100
92 #define CHV_GPIO_IDX_START_SE 198
94 #define CHV_VBT_MAX_PINS_PER_FMLY 15
96 #define CHV_GPIO_PAD_CFG0(f, i) (0x4400 + (f) * 0x400 + (i) * 8)
97 #define CHV_GPIO_GPIOEN (1 << 15)
98 #define CHV_GPIO_GPIOCFG_GPIO (0 << 8)
99 #define CHV_GPIO_GPIOCFG_GPO (1 << 8)
100 #define CHV_GPIO_GPIOCFG_GPI (2 << 8)
101 #define CHV_GPIO_GPIOCFG_HIZ (3 << 8)
102 #define CHV_GPIO_GPIOTXSTATE(state) ((!!(state)) << 1)
104 #define CHV_GPIO_PAD_CFG1(f, i) (0x4400 + (f) * 0x400 + (i) * 8 + 4)
105 #define CHV_GPIO_CFGLOCK (1 << 31)
107 /* ICL DSI Display GPIO Pins */
108 #define ICL_GPIO_DDSP_HPD_A 0
109 #define ICL_GPIO_L_VDDEN_1 1
110 #define ICL_GPIO_L_BKLTEN_1 2
111 #define ICL_GPIO_DDPA_CTRLCLK_1 3
112 #define ICL_GPIO_DDPA_CTRLDATA_1 4
113 #define ICL_GPIO_DDSP_HPD_B 5
114 #define ICL_GPIO_L_VDDEN_2 6
115 #define ICL_GPIO_L_BKLTEN_2 7
116 #define ICL_GPIO_DDPA_CTRLCLK_2 8
117 #define ICL_GPIO_DDPA_CTRLDATA_2 9
119 static inline enum port intel_dsi_seq_port_to_port(u8 port)
121 return port ? PORT_C : PORT_A;
124 static const u8 *mipi_exec_send_packet(struct intel_dsi *intel_dsi,
127 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
128 struct mipi_dsi_device *dsi_device;
129 u8 type, flags, seq_port;
138 len = *((u16 *) data);
141 seq_port = (flags >> MIPI_PORT_SHIFT) & 3;
143 /* For DSI single link on Port A & C, the seq_port value which is
144 * parsed from Sequence Block#53 of VBT has been set to 0
145 * Now, read/write of packets for the DSI single link on Port A and
146 * Port C will based on the DVO port from VBT block 2.
148 if (intel_dsi->ports == (1 << PORT_C))
151 port = intel_dsi_seq_port_to_port(seq_port);
153 dsi_device = intel_dsi->dsi_hosts[port]->device;
155 DRM_DEBUG_KMS("no dsi device for port %c\n", port_name(port));
159 if ((flags >> MIPI_TRANSFER_MODE_SHIFT) & 1)
160 dsi_device->mode_flags &= ~MIPI_DSI_MODE_LPM;
162 dsi_device->mode_flags |= MIPI_DSI_MODE_LPM;
164 dsi_device->channel = (flags >> MIPI_VIRTUAL_CHANNEL_SHIFT) & 3;
167 case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
168 mipi_dsi_generic_write(dsi_device, NULL, 0);
170 case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
171 mipi_dsi_generic_write(dsi_device, data, 1);
173 case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
174 mipi_dsi_generic_write(dsi_device, data, 2);
176 case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
177 case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
178 case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
179 DRM_DEBUG_DRIVER("Generic Read not yet implemented or used\n");
181 case MIPI_DSI_GENERIC_LONG_WRITE:
182 mipi_dsi_generic_write(dsi_device, data, len);
184 case MIPI_DSI_DCS_SHORT_WRITE:
185 mipi_dsi_dcs_write_buffer(dsi_device, data, 1);
187 case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
188 mipi_dsi_dcs_write_buffer(dsi_device, data, 2);
190 case MIPI_DSI_DCS_READ:
191 DRM_DEBUG_DRIVER("DCS Read not yet implemented or used\n");
193 case MIPI_DSI_DCS_LONG_WRITE:
194 mipi_dsi_dcs_write_buffer(dsi_device, data, len);
198 if (INTEL_GEN(dev_priv) < 11)
199 vlv_dsi_wait_for_fifo_empty(intel_dsi, port);
207 static const u8 *mipi_exec_delay(struct intel_dsi *intel_dsi, const u8 *data)
209 u32 delay = *((const u32 *) data);
213 usleep_range(delay, delay + 10);
219 static void vlv_exec_gpio(struct drm_i915_private *dev_priv,
220 u8 gpio_source, u8 gpio_index, bool value)
222 struct gpio_map *map;
227 if (gpio_index >= ARRAY_SIZE(vlv_gpio_table)) {
228 DRM_DEBUG_KMS("unknown gpio index %u\n", gpio_index);
232 map = &vlv_gpio_table[gpio_index];
234 if (dev_priv->vbt.dsi.seq_version >= 3) {
235 /* XXX: this assumes vlv_gpio_table only has NC GPIOs. */
236 port = IOSF_PORT_GPIO_NC;
238 if (gpio_source == 0) {
239 port = IOSF_PORT_GPIO_NC;
240 } else if (gpio_source == 1) {
241 DRM_DEBUG_KMS("SC gpio not supported\n");
244 DRM_DEBUG_KMS("unknown gpio source %u\n", gpio_source);
249 pconf0 = VLV_GPIO_PCONF0(map->base_offset);
250 padval = VLV_GPIO_PAD_VAL(map->base_offset);
252 vlv_iosf_sb_get(dev_priv, BIT(VLV_IOSF_SB_GPIO));
254 /* FIXME: remove constant below */
255 vlv_iosf_sb_write(dev_priv, port, pconf0, 0x2000CC00);
260 vlv_iosf_sb_write(dev_priv, port, padval, tmp);
261 vlv_iosf_sb_put(dev_priv, BIT(VLV_IOSF_SB_GPIO));
264 static void chv_exec_gpio(struct drm_i915_private *dev_priv,
265 u8 gpio_source, u8 gpio_index, bool value)
271 if (dev_priv->vbt.dsi.seq_version >= 3) {
272 if (gpio_index >= CHV_GPIO_IDX_START_SE) {
273 /* XXX: it's unclear whether 255->57 is part of SE. */
274 gpio_index -= CHV_GPIO_IDX_START_SE;
275 port = CHV_IOSF_PORT_GPIO_SE;
276 } else if (gpio_index >= CHV_GPIO_IDX_START_SW) {
277 gpio_index -= CHV_GPIO_IDX_START_SW;
278 port = CHV_IOSF_PORT_GPIO_SW;
279 } else if (gpio_index >= CHV_GPIO_IDX_START_E) {
280 gpio_index -= CHV_GPIO_IDX_START_E;
281 port = CHV_IOSF_PORT_GPIO_E;
283 port = CHV_IOSF_PORT_GPIO_N;
286 /* XXX: The spec is unclear about CHV GPIO on seq v2 */
287 if (gpio_source != 0) {
288 DRM_DEBUG_KMS("unknown gpio source %u\n", gpio_source);
292 if (gpio_index >= CHV_GPIO_IDX_START_E) {
293 DRM_DEBUG_KMS("invalid gpio index %u for GPIO N\n",
298 port = CHV_IOSF_PORT_GPIO_N;
301 family_num = gpio_index / CHV_VBT_MAX_PINS_PER_FMLY;
302 gpio_index = gpio_index % CHV_VBT_MAX_PINS_PER_FMLY;
304 cfg0 = CHV_GPIO_PAD_CFG0(family_num, gpio_index);
305 cfg1 = CHV_GPIO_PAD_CFG1(family_num, gpio_index);
307 vlv_iosf_sb_get(dev_priv, BIT(VLV_IOSF_SB_GPIO));
308 vlv_iosf_sb_write(dev_priv, port, cfg1, 0);
309 vlv_iosf_sb_write(dev_priv, port, cfg0,
310 CHV_GPIO_GPIOEN | CHV_GPIO_GPIOCFG_GPO |
311 CHV_GPIO_GPIOTXSTATE(value));
312 vlv_iosf_sb_put(dev_priv, BIT(VLV_IOSF_SB_GPIO));
315 static void bxt_exec_gpio(struct drm_i915_private *dev_priv,
316 u8 gpio_source, u8 gpio_index, bool value)
318 /* XXX: this table is a quick ugly hack. */
319 static struct gpio_desc *bxt_gpio_table[U8_MAX + 1];
320 struct gpio_desc *gpio_desc = bxt_gpio_table[gpio_index];
323 gpio_desc = devm_gpiod_get_index(dev_priv->drm.dev,
325 value ? GPIOD_OUT_LOW :
328 if (IS_ERR_OR_NULL(gpio_desc)) {
329 DRM_ERROR("GPIO index %u request failed (%ld)\n",
330 gpio_index, PTR_ERR(gpio_desc));
334 bxt_gpio_table[gpio_index] = gpio_desc;
337 gpiod_set_value(gpio_desc, value);
340 static void icl_exec_gpio(struct drm_i915_private *dev_priv,
341 u8 gpio_source, u8 gpio_index, bool value)
343 DRM_DEBUG_KMS("Skipping ICL GPIO element execution\n");
346 static const u8 *mipi_exec_gpio(struct intel_dsi *intel_dsi, const u8 *data)
348 struct drm_device *dev = intel_dsi->base.base.dev;
349 struct drm_i915_private *dev_priv = to_i915(dev);
350 u8 gpio_source, gpio_index = 0, gpio_number;
355 if (dev_priv->vbt.dsi.seq_version >= 3)
356 gpio_index = *data++;
358 gpio_number = *data++;
360 /* gpio source in sequence v2 only */
361 if (dev_priv->vbt.dsi.seq_version == 2)
362 gpio_source = (*data >> 1) & 3;
369 if (INTEL_GEN(dev_priv) >= 11)
370 icl_exec_gpio(dev_priv, gpio_source, gpio_index, value);
371 else if (IS_VALLEYVIEW(dev_priv))
372 vlv_exec_gpio(dev_priv, gpio_source, gpio_number, value);
373 else if (IS_CHERRYVIEW(dev_priv))
374 chv_exec_gpio(dev_priv, gpio_source, gpio_number, value);
376 bxt_exec_gpio(dev_priv, gpio_source, gpio_index, value);
381 static const u8 *mipi_exec_i2c(struct intel_dsi *intel_dsi, const u8 *data)
383 DRM_DEBUG_KMS("Skipping I2C element execution\n");
385 return data + *(data + 6) + 7;
388 static const u8 *mipi_exec_spi(struct intel_dsi *intel_dsi, const u8 *data)
390 DRM_DEBUG_KMS("Skipping SPI element execution\n");
392 return data + *(data + 5) + 6;
395 static const u8 *mipi_exec_pmic(struct intel_dsi *intel_dsi, const u8 *data)
397 #ifdef CONFIG_PMIC_OPREGION
398 u32 value, mask, reg_address;
402 /* byte 0 aka PMIC Flag is reserved */
403 i2c_address = get_unaligned_le16(data + 1);
404 reg_address = get_unaligned_le32(data + 3);
405 value = get_unaligned_le32(data + 7);
406 mask = get_unaligned_le32(data + 11);
408 ret = intel_soc_pmic_exec_mipi_pmic_seq_element(i2c_address,
412 DRM_ERROR("%s failed, error: %d\n", __func__, ret);
414 DRM_ERROR("Your hardware requires CONFIG_PMIC_OPREGION and it is not set\n");
420 typedef const u8 * (*fn_mipi_elem_exec)(struct intel_dsi *intel_dsi,
422 static const fn_mipi_elem_exec exec_elem[] = {
423 [MIPI_SEQ_ELEM_SEND_PKT] = mipi_exec_send_packet,
424 [MIPI_SEQ_ELEM_DELAY] = mipi_exec_delay,
425 [MIPI_SEQ_ELEM_GPIO] = mipi_exec_gpio,
426 [MIPI_SEQ_ELEM_I2C] = mipi_exec_i2c,
427 [MIPI_SEQ_ELEM_SPI] = mipi_exec_spi,
428 [MIPI_SEQ_ELEM_PMIC] = mipi_exec_pmic,
432 * MIPI Sequence from VBT #53 parsing logic
433 * We have already separated each seqence during bios parsing
434 * Following is generic execution function for any sequence
437 static const char * const seq_name[] = {
438 [MIPI_SEQ_DEASSERT_RESET] = "MIPI_SEQ_DEASSERT_RESET",
439 [MIPI_SEQ_INIT_OTP] = "MIPI_SEQ_INIT_OTP",
440 [MIPI_SEQ_DISPLAY_ON] = "MIPI_SEQ_DISPLAY_ON",
441 [MIPI_SEQ_DISPLAY_OFF] = "MIPI_SEQ_DISPLAY_OFF",
442 [MIPI_SEQ_ASSERT_RESET] = "MIPI_SEQ_ASSERT_RESET",
443 [MIPI_SEQ_BACKLIGHT_ON] = "MIPI_SEQ_BACKLIGHT_ON",
444 [MIPI_SEQ_BACKLIGHT_OFF] = "MIPI_SEQ_BACKLIGHT_OFF",
445 [MIPI_SEQ_TEAR_ON] = "MIPI_SEQ_TEAR_ON",
446 [MIPI_SEQ_TEAR_OFF] = "MIPI_SEQ_TEAR_OFF",
447 [MIPI_SEQ_POWER_ON] = "MIPI_SEQ_POWER_ON",
448 [MIPI_SEQ_POWER_OFF] = "MIPI_SEQ_POWER_OFF",
451 static const char *sequence_name(enum mipi_seq seq_id)
453 if (seq_id < ARRAY_SIZE(seq_name) && seq_name[seq_id])
454 return seq_name[seq_id];
459 static void intel_dsi_vbt_exec(struct intel_dsi *intel_dsi,
460 enum mipi_seq seq_id)
462 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
464 fn_mipi_elem_exec mipi_elem_exec;
466 if (WARN_ON(seq_id >= ARRAY_SIZE(dev_priv->vbt.dsi.sequence)))
469 data = dev_priv->vbt.dsi.sequence[seq_id];
473 WARN_ON(*data != seq_id);
475 DRM_DEBUG_KMS("Starting MIPI sequence %d - %s\n",
476 seq_id, sequence_name(seq_id));
478 /* Skip Sequence Byte. */
481 /* Skip Size of Sequence. */
482 if (dev_priv->vbt.dsi.seq_version >= 3)
486 u8 operation_byte = *data++;
487 u8 operation_size = 0;
489 if (operation_byte == MIPI_SEQ_ELEM_END)
492 if (operation_byte < ARRAY_SIZE(exec_elem))
493 mipi_elem_exec = exec_elem[operation_byte];
495 mipi_elem_exec = NULL;
497 /* Size of Operation. */
498 if (dev_priv->vbt.dsi.seq_version >= 3)
499 operation_size = *data++;
501 if (mipi_elem_exec) {
502 const u8 *next = data + operation_size;
504 data = mipi_elem_exec(intel_dsi, data);
506 /* Consistency check if we have size. */
507 if (operation_size && data != next) {
508 DRM_ERROR("Inconsistent operation size\n");
511 } else if (operation_size) {
512 /* We have size, skip. */
513 DRM_DEBUG_KMS("Unsupported MIPI operation byte %u\n",
515 data += operation_size;
517 /* No size, can't skip without parsing. */
518 DRM_ERROR("Unsupported MIPI operation byte %u\n",
525 void intel_dsi_vbt_exec_sequence(struct intel_dsi *intel_dsi,
526 enum mipi_seq seq_id)
528 if (seq_id == MIPI_SEQ_POWER_ON && intel_dsi->gpio_panel)
529 gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1);
530 if (seq_id == MIPI_SEQ_BACKLIGHT_ON && intel_dsi->gpio_backlight)
531 gpiod_set_value_cansleep(intel_dsi->gpio_backlight, 1);
533 intel_dsi_vbt_exec(intel_dsi, seq_id);
535 if (seq_id == MIPI_SEQ_POWER_OFF && intel_dsi->gpio_panel)
536 gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0);
537 if (seq_id == MIPI_SEQ_BACKLIGHT_OFF && intel_dsi->gpio_backlight)
538 gpiod_set_value_cansleep(intel_dsi->gpio_backlight, 0);
541 void intel_dsi_msleep(struct intel_dsi *intel_dsi, int msec)
543 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
545 /* For v3 VBTs in vid-mode the delays are part of the VBT sequences */
546 if (is_vid_mode(intel_dsi) && dev_priv->vbt.dsi.seq_version >= 3)
552 void intel_dsi_log_params(struct intel_dsi *intel_dsi)
554 DRM_DEBUG_KMS("Pclk %d\n", intel_dsi->pclk);
555 DRM_DEBUG_KMS("Pixel overlap %d\n", intel_dsi->pixel_overlap);
556 DRM_DEBUG_KMS("Lane count %d\n", intel_dsi->lane_count);
557 DRM_DEBUG_KMS("DPHY param reg 0x%x\n", intel_dsi->dphy_reg);
558 DRM_DEBUG_KMS("Video mode format %s\n",
559 intel_dsi->video_mode_format == VIDEO_MODE_NON_BURST_WITH_SYNC_PULSE ?
560 "non-burst with sync pulse" :
561 intel_dsi->video_mode_format == VIDEO_MODE_NON_BURST_WITH_SYNC_EVENTS ?
562 "non-burst with sync events" :
563 intel_dsi->video_mode_format == VIDEO_MODE_BURST ?
564 "burst" : "<unknown>");
565 DRM_DEBUG_KMS("Burst mode ratio %d\n", intel_dsi->burst_mode_ratio);
566 DRM_DEBUG_KMS("Reset timer %d\n", intel_dsi->rst_timer_val);
567 DRM_DEBUG_KMS("Eot %s\n", enableddisabled(intel_dsi->eotp_pkt));
568 DRM_DEBUG_KMS("Clockstop %s\n", enableddisabled(!intel_dsi->clock_stop));
569 DRM_DEBUG_KMS("Mode %s\n", intel_dsi->operation_mode ? "command" : "video");
570 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
571 DRM_DEBUG_KMS("Dual link: DSI_DUAL_LINK_FRONT_BACK\n");
572 else if (intel_dsi->dual_link == DSI_DUAL_LINK_PIXEL_ALT)
573 DRM_DEBUG_KMS("Dual link: DSI_DUAL_LINK_PIXEL_ALT\n");
575 DRM_DEBUG_KMS("Dual link: NONE\n");
576 DRM_DEBUG_KMS("Pixel Format %d\n", intel_dsi->pixel_format);
577 DRM_DEBUG_KMS("TLPX %d\n", intel_dsi->escape_clk_div);
578 DRM_DEBUG_KMS("LP RX Timeout 0x%x\n", intel_dsi->lp_rx_timeout);
579 DRM_DEBUG_KMS("Turnaround Timeout 0x%x\n", intel_dsi->turn_arnd_val);
580 DRM_DEBUG_KMS("Init Count 0x%x\n", intel_dsi->init_count);
581 DRM_DEBUG_KMS("HS to LP Count 0x%x\n", intel_dsi->hs_to_lp_count);
582 DRM_DEBUG_KMS("LP Byte Clock %d\n", intel_dsi->lp_byte_clk);
583 DRM_DEBUG_KMS("DBI BW Timer 0x%x\n", intel_dsi->bw_timer);
584 DRM_DEBUG_KMS("LP to HS Clock Count 0x%x\n", intel_dsi->clk_lp_to_hs_count);
585 DRM_DEBUG_KMS("HS to LP Clock Count 0x%x\n", intel_dsi->clk_hs_to_lp_count);
586 DRM_DEBUG_KMS("BTA %s\n",
587 enableddisabled(!(intel_dsi->video_frmt_cfg_bits & DISABLE_VIDEO_BTA)));
590 bool intel_dsi_vbt_init(struct intel_dsi *intel_dsi, u16 panel_id)
592 struct drm_device *dev = intel_dsi->base.base.dev;
593 struct drm_i915_private *dev_priv = to_i915(dev);
594 struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;
595 struct mipi_pps_data *pps = dev_priv->vbt.dsi.pps;
596 struct drm_display_mode *mode = dev_priv->vbt.lfp_lvds_vbt_mode;
597 u16 burst_mode_ratio;
602 intel_dsi->eotp_pkt = mipi_config->eot_pkt_disabled ? 0 : 1;
603 intel_dsi->clock_stop = mipi_config->enable_clk_stop ? 1 : 0;
604 intel_dsi->lane_count = mipi_config->lane_cnt + 1;
605 intel_dsi->pixel_format =
606 pixel_format_from_register_bits(
607 mipi_config->videomode_color_format << 7);
609 intel_dsi->dual_link = mipi_config->dual_link;
610 intel_dsi->pixel_overlap = mipi_config->pixel_overlap;
611 intel_dsi->operation_mode = mipi_config->is_cmd_mode;
612 intel_dsi->video_mode_format = mipi_config->video_transfer_mode;
613 intel_dsi->escape_clk_div = mipi_config->byte_clk_sel;
614 intel_dsi->lp_rx_timeout = mipi_config->lp_rx_timeout;
615 intel_dsi->hs_tx_timeout = mipi_config->hs_tx_timeout;
616 intel_dsi->turn_arnd_val = mipi_config->turn_around_timeout;
617 intel_dsi->rst_timer_val = mipi_config->device_reset_timer;
618 intel_dsi->init_count = mipi_config->master_init_timer;
619 intel_dsi->bw_timer = mipi_config->dbi_bw_timer;
620 intel_dsi->video_frmt_cfg_bits =
621 mipi_config->bta_enabled ? DISABLE_VIDEO_BTA : 0;
622 intel_dsi->bgr_enabled = mipi_config->rgb_flip;
624 /* Starting point, adjusted depending on dual link and burst mode */
625 intel_dsi->pclk = mode->clock;
627 /* In dual link mode each port needs half of pixel clock */
628 if (intel_dsi->dual_link) {
629 intel_dsi->pclk /= 2;
631 /* we can enable pixel_overlap if needed by panel. In this
632 * case we need to increase the pixelclock for extra pixels
634 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
635 intel_dsi->pclk += DIV_ROUND_UP(mode->vtotal * intel_dsi->pixel_overlap * 60, 1000);
640 * Target ddr frequency from VBT / non burst ddr freq
641 * multiply by 100 to preserve remainder
643 if (intel_dsi->video_mode_format == VIDEO_MODE_BURST) {
644 if (mipi_config->target_burst_mode_freq) {
645 u32 bitrate = intel_dsi_bitrate(intel_dsi);
648 * Sometimes the VBT contains a slightly lower clock,
649 * then the bitrate we have calculated, in this case
650 * just replace it with the calculated bitrate.
652 if (mipi_config->target_burst_mode_freq < bitrate &&
653 intel_fuzzy_clock_check(
654 mipi_config->target_burst_mode_freq,
656 mipi_config->target_burst_mode_freq = bitrate;
658 if (mipi_config->target_burst_mode_freq < bitrate) {
659 DRM_ERROR("Burst mode freq is less than computed\n");
663 burst_mode_ratio = DIV_ROUND_UP(
664 mipi_config->target_burst_mode_freq * 100,
667 intel_dsi->pclk = DIV_ROUND_UP(intel_dsi->pclk * burst_mode_ratio, 100);
669 DRM_ERROR("Burst mode target is not set\n");
673 burst_mode_ratio = 100;
675 intel_dsi->burst_mode_ratio = burst_mode_ratio;
677 /* delays in VBT are in unit of 100us, so need to convert
679 * Delay (100us) * 100 /1000 = Delay / 10 (ms) */
680 intel_dsi->backlight_off_delay = pps->bl_disable_delay / 10;
681 intel_dsi->backlight_on_delay = pps->bl_enable_delay / 10;
682 intel_dsi->panel_on_delay = pps->panel_on_delay / 10;
683 intel_dsi->panel_off_delay = pps->panel_off_delay / 10;
684 intel_dsi->panel_pwr_cycle_delay = pps->panel_power_cycle_delay / 10;
686 /* a regular driver would get the device in probe */
687 for_each_dsi_port(port, intel_dsi->ports) {
688 mipi_dsi_attach(intel_dsi->dsi_hosts[port]->device);
695 * On some BYT/CHT devs some sequences are incomplete and we need to manually
696 * control some GPIOs. We need to add a GPIO lookup table before we get these.
697 * If the GOP did not initialize the panel (HDMI inserted) we may need to also
698 * change the pinmux for the SoC's PWM0 pin from GPIO to PWM.
700 static struct gpiod_lookup_table pmic_panel_gpio_table = {
701 /* Intel GFX is consumer */
702 .dev_id = "0000:00:02.0",
704 /* Panel EN/DISABLE */
705 GPIO_LOOKUP("gpio_crystalcove", 94, "panel", GPIO_ACTIVE_HIGH),
710 static struct gpiod_lookup_table soc_panel_gpio_table = {
711 .dev_id = "0000:00:02.0",
713 GPIO_LOOKUP("INT33FC:01", 10, "backlight", GPIO_ACTIVE_HIGH),
714 GPIO_LOOKUP("INT33FC:01", 11, "panel", GPIO_ACTIVE_HIGH),
719 static const struct pinctrl_map soc_pwm_pinctrl_map[] = {
720 PIN_MAP_MUX_GROUP("0000:00:02.0", "soc_pwm0", "INT33FC:00",
724 void intel_dsi_vbt_gpio_init(struct intel_dsi *intel_dsi, bool panel_is_on)
726 struct drm_device *dev = intel_dsi->base.base.dev;
727 struct drm_i915_private *dev_priv = to_i915(dev);
728 struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;
729 enum gpiod_flags flags = panel_is_on ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
730 bool want_backlight_gpio = false;
731 bool want_panel_gpio = false;
732 struct pinctrl *pinctrl;
735 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
736 mipi_config->pwm_blc == PPS_BLC_PMIC) {
737 gpiod_add_lookup_table(&pmic_panel_gpio_table);
738 want_panel_gpio = true;
741 if (IS_VALLEYVIEW(dev_priv) && mipi_config->pwm_blc == PPS_BLC_SOC) {
742 gpiod_add_lookup_table(&soc_panel_gpio_table);
743 want_panel_gpio = true;
744 want_backlight_gpio = true;
746 /* Ensure PWM0 pin is muxed as PWM instead of GPIO */
747 ret = pinctrl_register_mappings(soc_pwm_pinctrl_map,
748 ARRAY_SIZE(soc_pwm_pinctrl_map));
750 DRM_ERROR("Failed to register pwm0 pinmux mapping\n");
752 pinctrl = devm_pinctrl_get_select(dev->dev, "soc_pwm0");
754 DRM_ERROR("Failed to set pinmux to PWM\n");
757 if (want_panel_gpio) {
758 intel_dsi->gpio_panel = gpiod_get(dev->dev, "panel", flags);
759 if (IS_ERR(intel_dsi->gpio_panel)) {
760 DRM_ERROR("Failed to own gpio for panel control\n");
761 intel_dsi->gpio_panel = NULL;
765 if (want_backlight_gpio) {
766 intel_dsi->gpio_backlight =
767 gpiod_get(dev->dev, "backlight", flags);
768 if (IS_ERR(intel_dsi->gpio_backlight)) {
769 DRM_ERROR("Failed to own gpio for backlight control\n");
770 intel_dsi->gpio_backlight = NULL;
775 void intel_dsi_vbt_gpio_cleanup(struct intel_dsi *intel_dsi)
777 struct drm_device *dev = intel_dsi->base.base.dev;
778 struct drm_i915_private *dev_priv = to_i915(dev);
779 struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;
781 if (intel_dsi->gpio_panel) {
782 gpiod_put(intel_dsi->gpio_panel);
783 intel_dsi->gpio_panel = NULL;
786 if (intel_dsi->gpio_backlight) {
787 gpiod_put(intel_dsi->gpio_backlight);
788 intel_dsi->gpio_backlight = NULL;
791 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
792 mipi_config->pwm_blc == PPS_BLC_PMIC)
793 gpiod_remove_lookup_table(&pmic_panel_gpio_table);
795 if (IS_VALLEYVIEW(dev_priv) && mipi_config->pwm_blc == PPS_BLC_SOC) {
796 pinctrl_unregister_mappings(soc_pwm_pinctrl_map);
797 gpiod_remove_lookup_table(&soc_panel_gpio_table);