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.
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>
33 #include <linux/string_helpers.h>
35 #include <asm/unaligned.h>
37 #include <drm/drm_crtc.h>
38 #include <drm/drm_edid.h>
40 #include <video/mipi_display.h>
44 #include "intel_display_types.h"
45 #include "intel_dsi.h"
46 #include "intel_dsi_vbt.h"
48 #include "vlv_dsi_regs.h"
49 #include "vlv_sideband.h"
51 #define MIPI_TRANSFER_MODE_SHIFT 0
52 #define MIPI_VIRTUAL_CHANNEL_SHIFT 1
53 #define MIPI_PORT_SHIFT 3
55 /* base offsets for gpio pads */
56 #define VLV_GPIO_NC_0_HV_DDI0_HPD 0x4130
57 #define VLV_GPIO_NC_1_HV_DDI0_DDC_SDA 0x4120
58 #define VLV_GPIO_NC_2_HV_DDI0_DDC_SCL 0x4110
59 #define VLV_GPIO_NC_3_PANEL0_VDDEN 0x4140
60 #define VLV_GPIO_NC_4_PANEL0_BKLTEN 0x4150
61 #define VLV_GPIO_NC_5_PANEL0_BKLTCTL 0x4160
62 #define VLV_GPIO_NC_6_HV_DDI1_HPD 0x4180
63 #define VLV_GPIO_NC_7_HV_DDI1_DDC_SDA 0x4190
64 #define VLV_GPIO_NC_8_HV_DDI1_DDC_SCL 0x4170
65 #define VLV_GPIO_NC_9_PANEL1_VDDEN 0x4100
66 #define VLV_GPIO_NC_10_PANEL1_BKLTEN 0x40E0
67 #define VLV_GPIO_NC_11_PANEL1_BKLTCTL 0x40F0
69 #define VLV_GPIO_PCONF0(base_offset) (base_offset)
70 #define VLV_GPIO_PAD_VAL(base_offset) ((base_offset) + 8)
77 static struct gpio_map vlv_gpio_table[] = {
78 { VLV_GPIO_NC_0_HV_DDI0_HPD },
79 { VLV_GPIO_NC_1_HV_DDI0_DDC_SDA },
80 { VLV_GPIO_NC_2_HV_DDI0_DDC_SCL },
81 { VLV_GPIO_NC_3_PANEL0_VDDEN },
82 { VLV_GPIO_NC_4_PANEL0_BKLTEN },
83 { VLV_GPIO_NC_5_PANEL0_BKLTCTL },
84 { VLV_GPIO_NC_6_HV_DDI1_HPD },
85 { VLV_GPIO_NC_7_HV_DDI1_DDC_SDA },
86 { VLV_GPIO_NC_8_HV_DDI1_DDC_SCL },
87 { VLV_GPIO_NC_9_PANEL1_VDDEN },
88 { VLV_GPIO_NC_10_PANEL1_BKLTEN },
89 { VLV_GPIO_NC_11_PANEL1_BKLTCTL },
92 struct i2c_adapter_lookup {
94 struct intel_dsi *intel_dsi;
95 acpi_handle dev_handle;
98 #define CHV_GPIO_IDX_START_N 0
99 #define CHV_GPIO_IDX_START_E 73
100 #define CHV_GPIO_IDX_START_SW 100
101 #define CHV_GPIO_IDX_START_SE 198
103 #define CHV_VBT_MAX_PINS_PER_FMLY 15
105 #define CHV_GPIO_PAD_CFG0(f, i) (0x4400 + (f) * 0x400 + (i) * 8)
106 #define CHV_GPIO_GPIOEN (1 << 15)
107 #define CHV_GPIO_GPIOCFG_GPIO (0 << 8)
108 #define CHV_GPIO_GPIOCFG_GPO (1 << 8)
109 #define CHV_GPIO_GPIOCFG_GPI (2 << 8)
110 #define CHV_GPIO_GPIOCFG_HIZ (3 << 8)
111 #define CHV_GPIO_GPIOTXSTATE(state) ((!!(state)) << 1)
113 #define CHV_GPIO_PAD_CFG1(f, i) (0x4400 + (f) * 0x400 + (i) * 8 + 4)
114 #define CHV_GPIO_CFGLOCK (1 << 31)
116 /* ICL DSI Display GPIO Pins */
117 #define ICL_GPIO_DDSP_HPD_A 0
118 #define ICL_GPIO_L_VDDEN_1 1
119 #define ICL_GPIO_L_BKLTEN_1 2
120 #define ICL_GPIO_DDPA_CTRLCLK_1 3
121 #define ICL_GPIO_DDPA_CTRLDATA_1 4
122 #define ICL_GPIO_DDSP_HPD_B 5
123 #define ICL_GPIO_L_VDDEN_2 6
124 #define ICL_GPIO_L_BKLTEN_2 7
125 #define ICL_GPIO_DDPA_CTRLCLK_2 8
126 #define ICL_GPIO_DDPA_CTRLDATA_2 9
128 static enum port intel_dsi_seq_port_to_port(struct intel_dsi *intel_dsi,
132 * If single link DSI is being used on any port, the VBT sequence block
133 * send packet apparently always has 0 for the port. Just use the port
134 * we have configured, and ignore the sequence block port.
136 if (hweight8(intel_dsi->ports) == 1)
137 return ffs(intel_dsi->ports) - 1;
140 if (intel_dsi->ports & PORT_B)
142 else if (intel_dsi->ports & PORT_C)
149 static const u8 *mipi_exec_send_packet(struct intel_dsi *intel_dsi,
152 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
153 struct mipi_dsi_device *dsi_device;
154 u8 type, flags, seq_port;
158 drm_dbg_kms(&dev_priv->drm, "\n");
163 len = *((u16 *) data);
166 seq_port = (flags >> MIPI_PORT_SHIFT) & 3;
168 port = intel_dsi_seq_port_to_port(intel_dsi, seq_port);
170 if (drm_WARN_ON(&dev_priv->drm, !intel_dsi->dsi_hosts[port]))
173 dsi_device = intel_dsi->dsi_hosts[port]->device;
175 drm_dbg_kms(&dev_priv->drm, "no dsi device for port %c\n",
180 if ((flags >> MIPI_TRANSFER_MODE_SHIFT) & 1)
181 dsi_device->mode_flags &= ~MIPI_DSI_MODE_LPM;
183 dsi_device->mode_flags |= MIPI_DSI_MODE_LPM;
185 dsi_device->channel = (flags >> MIPI_VIRTUAL_CHANNEL_SHIFT) & 3;
188 case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
189 mipi_dsi_generic_write(dsi_device, NULL, 0);
191 case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
192 mipi_dsi_generic_write(dsi_device, data, 1);
194 case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
195 mipi_dsi_generic_write(dsi_device, data, 2);
197 case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
198 case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
199 case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
200 drm_dbg(&dev_priv->drm,
201 "Generic Read not yet implemented or used\n");
203 case MIPI_DSI_GENERIC_LONG_WRITE:
204 mipi_dsi_generic_write(dsi_device, data, len);
206 case MIPI_DSI_DCS_SHORT_WRITE:
207 mipi_dsi_dcs_write_buffer(dsi_device, data, 1);
209 case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
210 mipi_dsi_dcs_write_buffer(dsi_device, data, 2);
212 case MIPI_DSI_DCS_READ:
213 drm_dbg(&dev_priv->drm,
214 "DCS Read not yet implemented or used\n");
216 case MIPI_DSI_DCS_LONG_WRITE:
217 mipi_dsi_dcs_write_buffer(dsi_device, data, len);
221 if (DISPLAY_VER(dev_priv) < 11)
222 vlv_dsi_wait_for_fifo_empty(intel_dsi, port);
230 static const u8 *mipi_exec_delay(struct intel_dsi *intel_dsi, const u8 *data)
232 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev);
233 u32 delay = *((const u32 *) data);
235 drm_dbg_kms(&i915->drm, "\n");
237 usleep_range(delay, delay + 10);
243 static void vlv_exec_gpio(struct drm_i915_private *dev_priv,
244 u8 gpio_source, u8 gpio_index, bool value)
246 struct gpio_map *map;
251 if (gpio_index >= ARRAY_SIZE(vlv_gpio_table)) {
252 drm_dbg_kms(&dev_priv->drm, "unknown gpio index %u\n",
257 map = &vlv_gpio_table[gpio_index];
259 if (dev_priv->vbt.dsi.seq_version >= 3) {
260 /* XXX: this assumes vlv_gpio_table only has NC GPIOs. */
261 port = IOSF_PORT_GPIO_NC;
263 if (gpio_source == 0) {
264 port = IOSF_PORT_GPIO_NC;
265 } else if (gpio_source == 1) {
266 drm_dbg_kms(&dev_priv->drm, "SC gpio not supported\n");
269 drm_dbg_kms(&dev_priv->drm,
270 "unknown gpio source %u\n", gpio_source);
275 pconf0 = VLV_GPIO_PCONF0(map->base_offset);
276 padval = VLV_GPIO_PAD_VAL(map->base_offset);
278 vlv_iosf_sb_get(dev_priv, BIT(VLV_IOSF_SB_GPIO));
280 /* FIXME: remove constant below */
281 vlv_iosf_sb_write(dev_priv, port, pconf0, 0x2000CC00);
286 vlv_iosf_sb_write(dev_priv, port, padval, tmp);
287 vlv_iosf_sb_put(dev_priv, BIT(VLV_IOSF_SB_GPIO));
290 static void chv_exec_gpio(struct drm_i915_private *dev_priv,
291 u8 gpio_source, u8 gpio_index, bool value)
297 if (dev_priv->vbt.dsi.seq_version >= 3) {
298 if (gpio_index >= CHV_GPIO_IDX_START_SE) {
299 /* XXX: it's unclear whether 255->57 is part of SE. */
300 gpio_index -= CHV_GPIO_IDX_START_SE;
301 port = CHV_IOSF_PORT_GPIO_SE;
302 } else if (gpio_index >= CHV_GPIO_IDX_START_SW) {
303 gpio_index -= CHV_GPIO_IDX_START_SW;
304 port = CHV_IOSF_PORT_GPIO_SW;
305 } else if (gpio_index >= CHV_GPIO_IDX_START_E) {
306 gpio_index -= CHV_GPIO_IDX_START_E;
307 port = CHV_IOSF_PORT_GPIO_E;
309 port = CHV_IOSF_PORT_GPIO_N;
312 /* XXX: The spec is unclear about CHV GPIO on seq v2 */
313 if (gpio_source != 0) {
314 drm_dbg_kms(&dev_priv->drm,
315 "unknown gpio source %u\n", gpio_source);
319 if (gpio_index >= CHV_GPIO_IDX_START_E) {
320 drm_dbg_kms(&dev_priv->drm,
321 "invalid gpio index %u for GPIO N\n",
326 port = CHV_IOSF_PORT_GPIO_N;
329 family_num = gpio_index / CHV_VBT_MAX_PINS_PER_FMLY;
330 gpio_index = gpio_index % CHV_VBT_MAX_PINS_PER_FMLY;
332 cfg0 = CHV_GPIO_PAD_CFG0(family_num, gpio_index);
333 cfg1 = CHV_GPIO_PAD_CFG1(family_num, gpio_index);
335 vlv_iosf_sb_get(dev_priv, BIT(VLV_IOSF_SB_GPIO));
336 vlv_iosf_sb_write(dev_priv, port, cfg1, 0);
337 vlv_iosf_sb_write(dev_priv, port, cfg0,
338 CHV_GPIO_GPIOEN | CHV_GPIO_GPIOCFG_GPO |
339 CHV_GPIO_GPIOTXSTATE(value));
340 vlv_iosf_sb_put(dev_priv, BIT(VLV_IOSF_SB_GPIO));
343 static void bxt_exec_gpio(struct drm_i915_private *dev_priv,
344 u8 gpio_source, u8 gpio_index, bool value)
346 /* XXX: this table is a quick ugly hack. */
347 static struct gpio_desc *bxt_gpio_table[U8_MAX + 1];
348 struct gpio_desc *gpio_desc = bxt_gpio_table[gpio_index];
351 gpio_desc = devm_gpiod_get_index(dev_priv->drm.dev,
353 value ? GPIOD_OUT_LOW :
356 if (IS_ERR_OR_NULL(gpio_desc)) {
357 drm_err(&dev_priv->drm,
358 "GPIO index %u request failed (%ld)\n",
359 gpio_index, PTR_ERR(gpio_desc));
363 bxt_gpio_table[gpio_index] = gpio_desc;
366 gpiod_set_value(gpio_desc, value);
369 static void icl_exec_gpio(struct drm_i915_private *dev_priv,
370 u8 gpio_source, u8 gpio_index, bool value)
372 drm_dbg_kms(&dev_priv->drm, "Skipping ICL GPIO element execution\n");
375 static const u8 *mipi_exec_gpio(struct intel_dsi *intel_dsi, const u8 *data)
377 struct drm_device *dev = intel_dsi->base.base.dev;
378 struct drm_i915_private *dev_priv = to_i915(dev);
379 u8 gpio_source, gpio_index = 0, gpio_number;
382 drm_dbg_kms(&dev_priv->drm, "\n");
384 if (dev_priv->vbt.dsi.seq_version >= 3)
385 gpio_index = *data++;
387 gpio_number = *data++;
389 /* gpio source in sequence v2 only */
390 if (dev_priv->vbt.dsi.seq_version == 2)
391 gpio_source = (*data >> 1) & 3;
398 if (DISPLAY_VER(dev_priv) >= 11)
399 icl_exec_gpio(dev_priv, gpio_source, gpio_index, value);
400 else if (IS_VALLEYVIEW(dev_priv))
401 vlv_exec_gpio(dev_priv, gpio_source, gpio_number, value);
402 else if (IS_CHERRYVIEW(dev_priv))
403 chv_exec_gpio(dev_priv, gpio_source, gpio_number, value);
405 bxt_exec_gpio(dev_priv, gpio_source, gpio_index, value);
411 static int i2c_adapter_lookup(struct acpi_resource *ares, void *data)
413 struct i2c_adapter_lookup *lookup = data;
414 struct intel_dsi *intel_dsi = lookup->intel_dsi;
415 struct acpi_resource_i2c_serialbus *sb;
416 struct i2c_adapter *adapter;
417 acpi_handle adapter_handle;
420 if (!i2c_acpi_get_i2c_resource(ares, &sb))
423 if (lookup->slave_addr != sb->slave_address)
426 status = acpi_get_handle(lookup->dev_handle,
427 sb->resource_source.string_ptr,
429 if (ACPI_FAILURE(status))
432 adapter = i2c_acpi_find_adapter_by_handle(adapter_handle);
434 intel_dsi->i2c_bus_num = adapter->nr;
439 static void i2c_acpi_find_adapter(struct intel_dsi *intel_dsi,
440 const u16 slave_addr)
442 struct drm_device *drm_dev = intel_dsi->base.base.dev;
443 struct acpi_device *adev = ACPI_COMPANION(drm_dev->dev);
444 struct i2c_adapter_lookup lookup = {
445 .slave_addr = slave_addr,
446 .intel_dsi = intel_dsi,
447 .dev_handle = acpi_device_handle(adev),
449 LIST_HEAD(resource_list);
451 acpi_dev_get_resources(adev, &resource_list, i2c_adapter_lookup, &lookup);
452 acpi_dev_free_resource_list(&resource_list);
455 static inline void i2c_acpi_find_adapter(struct intel_dsi *intel_dsi,
456 const u16 slave_addr)
461 static const u8 *mipi_exec_i2c(struct intel_dsi *intel_dsi, const u8 *data)
463 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev);
464 struct i2c_adapter *adapter;
467 u8 vbt_i2c_bus_num = *(data + 2);
468 u16 slave_addr = *(u16 *)(data + 3);
469 u8 reg_offset = *(data + 5);
470 u8 payload_size = *(data + 6);
473 if (intel_dsi->i2c_bus_num < 0) {
474 intel_dsi->i2c_bus_num = vbt_i2c_bus_num;
475 i2c_acpi_find_adapter(intel_dsi, slave_addr);
478 adapter = i2c_get_adapter(intel_dsi->i2c_bus_num);
480 drm_err(&i915->drm, "Cannot find a valid i2c bus for xfer\n");
484 payload_data = kzalloc(payload_size + 1, GFP_KERNEL);
488 payload_data[0] = reg_offset;
489 memcpy(&payload_data[1], (data + 7), payload_size);
491 msg.addr = slave_addr;
493 msg.len = payload_size + 1;
494 msg.buf = payload_data;
496 ret = i2c_transfer(adapter, &msg, 1);
499 "Failed to xfer payload of size (%u) to reg (%u)\n",
500 payload_size, reg_offset);
504 i2c_put_adapter(adapter);
506 return data + payload_size + 7;
509 static const u8 *mipi_exec_spi(struct intel_dsi *intel_dsi, const u8 *data)
511 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev);
513 drm_dbg_kms(&i915->drm, "Skipping SPI element execution\n");
515 return data + *(data + 5) + 6;
518 static const u8 *mipi_exec_pmic(struct intel_dsi *intel_dsi, const u8 *data)
520 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev);
521 #ifdef CONFIG_PMIC_OPREGION
522 u32 value, mask, reg_address;
526 /* byte 0 aka PMIC Flag is reserved */
527 i2c_address = get_unaligned_le16(data + 1);
528 reg_address = get_unaligned_le32(data + 3);
529 value = get_unaligned_le32(data + 7);
530 mask = get_unaligned_le32(data + 11);
532 ret = intel_soc_pmic_exec_mipi_pmic_seq_element(i2c_address,
536 drm_err(&i915->drm, "%s failed, error: %d\n", __func__, ret);
539 "Your hardware requires CONFIG_PMIC_OPREGION and it is not set\n");
545 typedef const u8 * (*fn_mipi_elem_exec)(struct intel_dsi *intel_dsi,
547 static const fn_mipi_elem_exec exec_elem[] = {
548 [MIPI_SEQ_ELEM_SEND_PKT] = mipi_exec_send_packet,
549 [MIPI_SEQ_ELEM_DELAY] = mipi_exec_delay,
550 [MIPI_SEQ_ELEM_GPIO] = mipi_exec_gpio,
551 [MIPI_SEQ_ELEM_I2C] = mipi_exec_i2c,
552 [MIPI_SEQ_ELEM_SPI] = mipi_exec_spi,
553 [MIPI_SEQ_ELEM_PMIC] = mipi_exec_pmic,
557 * MIPI Sequence from VBT #53 parsing logic
558 * We have already separated each seqence during bios parsing
559 * Following is generic execution function for any sequence
562 static const char * const seq_name[] = {
563 [MIPI_SEQ_DEASSERT_RESET] = "MIPI_SEQ_DEASSERT_RESET",
564 [MIPI_SEQ_INIT_OTP] = "MIPI_SEQ_INIT_OTP",
565 [MIPI_SEQ_DISPLAY_ON] = "MIPI_SEQ_DISPLAY_ON",
566 [MIPI_SEQ_DISPLAY_OFF] = "MIPI_SEQ_DISPLAY_OFF",
567 [MIPI_SEQ_ASSERT_RESET] = "MIPI_SEQ_ASSERT_RESET",
568 [MIPI_SEQ_BACKLIGHT_ON] = "MIPI_SEQ_BACKLIGHT_ON",
569 [MIPI_SEQ_BACKLIGHT_OFF] = "MIPI_SEQ_BACKLIGHT_OFF",
570 [MIPI_SEQ_TEAR_ON] = "MIPI_SEQ_TEAR_ON",
571 [MIPI_SEQ_TEAR_OFF] = "MIPI_SEQ_TEAR_OFF",
572 [MIPI_SEQ_POWER_ON] = "MIPI_SEQ_POWER_ON",
573 [MIPI_SEQ_POWER_OFF] = "MIPI_SEQ_POWER_OFF",
576 static const char *sequence_name(enum mipi_seq seq_id)
578 if (seq_id < ARRAY_SIZE(seq_name) && seq_name[seq_id])
579 return seq_name[seq_id];
584 static void intel_dsi_vbt_exec(struct intel_dsi *intel_dsi,
585 enum mipi_seq seq_id)
587 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
589 fn_mipi_elem_exec mipi_elem_exec;
591 if (drm_WARN_ON(&dev_priv->drm,
592 seq_id >= ARRAY_SIZE(dev_priv->vbt.dsi.sequence)))
595 data = dev_priv->vbt.dsi.sequence[seq_id];
599 drm_WARN_ON(&dev_priv->drm, *data != seq_id);
601 drm_dbg_kms(&dev_priv->drm, "Starting MIPI sequence %d - %s\n",
602 seq_id, sequence_name(seq_id));
604 /* Skip Sequence Byte. */
607 /* Skip Size of Sequence. */
608 if (dev_priv->vbt.dsi.seq_version >= 3)
612 u8 operation_byte = *data++;
613 u8 operation_size = 0;
615 if (operation_byte == MIPI_SEQ_ELEM_END)
618 if (operation_byte < ARRAY_SIZE(exec_elem))
619 mipi_elem_exec = exec_elem[operation_byte];
621 mipi_elem_exec = NULL;
623 /* Size of Operation. */
624 if (dev_priv->vbt.dsi.seq_version >= 3)
625 operation_size = *data++;
627 if (mipi_elem_exec) {
628 const u8 *next = data + operation_size;
630 data = mipi_elem_exec(intel_dsi, data);
632 /* Consistency check if we have size. */
633 if (operation_size && data != next) {
634 drm_err(&dev_priv->drm,
635 "Inconsistent operation size\n");
638 } else if (operation_size) {
639 /* We have size, skip. */
640 drm_dbg_kms(&dev_priv->drm,
641 "Unsupported MIPI operation byte %u\n",
643 data += operation_size;
645 /* No size, can't skip without parsing. */
646 drm_err(&dev_priv->drm,
647 "Unsupported MIPI operation byte %u\n",
654 void intel_dsi_vbt_exec_sequence(struct intel_dsi *intel_dsi,
655 enum mipi_seq seq_id)
657 if (seq_id == MIPI_SEQ_POWER_ON && intel_dsi->gpio_panel)
658 gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1);
659 if (seq_id == MIPI_SEQ_BACKLIGHT_ON && intel_dsi->gpio_backlight)
660 gpiod_set_value_cansleep(intel_dsi->gpio_backlight, 1);
662 intel_dsi_vbt_exec(intel_dsi, seq_id);
664 if (seq_id == MIPI_SEQ_POWER_OFF && intel_dsi->gpio_panel)
665 gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0);
666 if (seq_id == MIPI_SEQ_BACKLIGHT_OFF && intel_dsi->gpio_backlight)
667 gpiod_set_value_cansleep(intel_dsi->gpio_backlight, 0);
670 void intel_dsi_msleep(struct intel_dsi *intel_dsi, int msec)
672 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
674 /* For v3 VBTs in vid-mode the delays are part of the VBT sequences */
675 if (is_vid_mode(intel_dsi) && dev_priv->vbt.dsi.seq_version >= 3)
681 void intel_dsi_log_params(struct intel_dsi *intel_dsi)
683 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev);
685 drm_dbg_kms(&i915->drm, "Pclk %d\n", intel_dsi->pclk);
686 drm_dbg_kms(&i915->drm, "Pixel overlap %d\n",
687 intel_dsi->pixel_overlap);
688 drm_dbg_kms(&i915->drm, "Lane count %d\n", intel_dsi->lane_count);
689 drm_dbg_kms(&i915->drm, "DPHY param reg 0x%x\n", intel_dsi->dphy_reg);
690 drm_dbg_kms(&i915->drm, "Video mode format %s\n",
691 intel_dsi->video_mode == NON_BURST_SYNC_PULSE ?
692 "non-burst with sync pulse" :
693 intel_dsi->video_mode == NON_BURST_SYNC_EVENTS ?
694 "non-burst with sync events" :
695 intel_dsi->video_mode == BURST_MODE ?
696 "burst" : "<unknown>");
697 drm_dbg_kms(&i915->drm, "Burst mode ratio %d\n",
698 intel_dsi->burst_mode_ratio);
699 drm_dbg_kms(&i915->drm, "Reset timer %d\n", intel_dsi->rst_timer_val);
700 drm_dbg_kms(&i915->drm, "Eot %s\n",
701 str_enabled_disabled(intel_dsi->eotp_pkt));
702 drm_dbg_kms(&i915->drm, "Clockstop %s\n",
703 str_enabled_disabled(!intel_dsi->clock_stop));
704 drm_dbg_kms(&i915->drm, "Mode %s\n",
705 intel_dsi->operation_mode ? "command" : "video");
706 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
707 drm_dbg_kms(&i915->drm,
708 "Dual link: DSI_DUAL_LINK_FRONT_BACK\n");
709 else if (intel_dsi->dual_link == DSI_DUAL_LINK_PIXEL_ALT)
710 drm_dbg_kms(&i915->drm,
711 "Dual link: DSI_DUAL_LINK_PIXEL_ALT\n");
713 drm_dbg_kms(&i915->drm, "Dual link: NONE\n");
714 drm_dbg_kms(&i915->drm, "Pixel Format %d\n", intel_dsi->pixel_format);
715 drm_dbg_kms(&i915->drm, "TLPX %d\n", intel_dsi->escape_clk_div);
716 drm_dbg_kms(&i915->drm, "LP RX Timeout 0x%x\n",
717 intel_dsi->lp_rx_timeout);
718 drm_dbg_kms(&i915->drm, "Turnaround Timeout 0x%x\n",
719 intel_dsi->turn_arnd_val);
720 drm_dbg_kms(&i915->drm, "Init Count 0x%x\n", intel_dsi->init_count);
721 drm_dbg_kms(&i915->drm, "HS to LP Count 0x%x\n",
722 intel_dsi->hs_to_lp_count);
723 drm_dbg_kms(&i915->drm, "LP Byte Clock %d\n", intel_dsi->lp_byte_clk);
724 drm_dbg_kms(&i915->drm, "DBI BW Timer 0x%x\n", intel_dsi->bw_timer);
725 drm_dbg_kms(&i915->drm, "LP to HS Clock Count 0x%x\n",
726 intel_dsi->clk_lp_to_hs_count);
727 drm_dbg_kms(&i915->drm, "HS to LP Clock Count 0x%x\n",
728 intel_dsi->clk_hs_to_lp_count);
729 drm_dbg_kms(&i915->drm, "BTA %s\n",
730 str_enabled_disabled(!(intel_dsi->video_frmt_cfg_bits & DISABLE_VIDEO_BTA)));
733 bool intel_dsi_vbt_init(struct intel_dsi *intel_dsi, u16 panel_id)
735 struct drm_device *dev = intel_dsi->base.base.dev;
736 struct drm_i915_private *dev_priv = to_i915(dev);
737 struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;
738 struct mipi_pps_data *pps = dev_priv->vbt.dsi.pps;
739 struct drm_display_mode *mode = dev_priv->vbt.lfp_lvds_vbt_mode;
740 u16 burst_mode_ratio;
743 drm_dbg_kms(&dev_priv->drm, "\n");
745 intel_dsi->eotp_pkt = mipi_config->eot_pkt_disabled ? 0 : 1;
746 intel_dsi->clock_stop = mipi_config->enable_clk_stop ? 1 : 0;
747 intel_dsi->lane_count = mipi_config->lane_cnt + 1;
748 intel_dsi->pixel_format =
749 pixel_format_from_register_bits(
750 mipi_config->videomode_color_format << 7);
752 intel_dsi->dual_link = mipi_config->dual_link;
753 intel_dsi->pixel_overlap = mipi_config->pixel_overlap;
754 intel_dsi->operation_mode = mipi_config->is_cmd_mode;
755 intel_dsi->video_mode = mipi_config->video_transfer_mode;
756 intel_dsi->escape_clk_div = mipi_config->byte_clk_sel;
757 intel_dsi->lp_rx_timeout = mipi_config->lp_rx_timeout;
758 intel_dsi->hs_tx_timeout = mipi_config->hs_tx_timeout;
759 intel_dsi->turn_arnd_val = mipi_config->turn_around_timeout;
760 intel_dsi->rst_timer_val = mipi_config->device_reset_timer;
761 intel_dsi->init_count = mipi_config->master_init_timer;
762 intel_dsi->bw_timer = mipi_config->dbi_bw_timer;
763 intel_dsi->video_frmt_cfg_bits =
764 mipi_config->bta_enabled ? DISABLE_VIDEO_BTA : 0;
765 intel_dsi->bgr_enabled = mipi_config->rgb_flip;
767 /* Starting point, adjusted depending on dual link and burst mode */
768 intel_dsi->pclk = mode->clock;
770 /* In dual link mode each port needs half of pixel clock */
771 if (intel_dsi->dual_link) {
772 intel_dsi->pclk /= 2;
774 /* we can enable pixel_overlap if needed by panel. In this
775 * case we need to increase the pixelclock for extra pixels
777 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
778 intel_dsi->pclk += DIV_ROUND_UP(mode->vtotal * intel_dsi->pixel_overlap * 60, 1000);
783 * Target ddr frequency from VBT / non burst ddr freq
784 * multiply by 100 to preserve remainder
786 if (intel_dsi->video_mode == BURST_MODE) {
787 if (mipi_config->target_burst_mode_freq) {
788 u32 bitrate = intel_dsi_bitrate(intel_dsi);
791 * Sometimes the VBT contains a slightly lower clock,
792 * then the bitrate we have calculated, in this case
793 * just replace it with the calculated bitrate.
795 if (mipi_config->target_burst_mode_freq < bitrate &&
796 intel_fuzzy_clock_check(
797 mipi_config->target_burst_mode_freq,
799 mipi_config->target_burst_mode_freq = bitrate;
801 if (mipi_config->target_burst_mode_freq < bitrate) {
802 drm_err(&dev_priv->drm,
803 "Burst mode freq is less than computed\n");
807 burst_mode_ratio = DIV_ROUND_UP(
808 mipi_config->target_burst_mode_freq * 100,
811 intel_dsi->pclk = DIV_ROUND_UP(intel_dsi->pclk * burst_mode_ratio, 100);
813 drm_err(&dev_priv->drm,
814 "Burst mode target is not set\n");
818 burst_mode_ratio = 100;
820 intel_dsi->burst_mode_ratio = burst_mode_ratio;
822 /* delays in VBT are in unit of 100us, so need to convert
824 * Delay (100us) * 100 /1000 = Delay / 10 (ms) */
825 intel_dsi->backlight_off_delay = pps->bl_disable_delay / 10;
826 intel_dsi->backlight_on_delay = pps->bl_enable_delay / 10;
827 intel_dsi->panel_on_delay = pps->panel_on_delay / 10;
828 intel_dsi->panel_off_delay = pps->panel_off_delay / 10;
829 intel_dsi->panel_pwr_cycle_delay = pps->panel_power_cycle_delay / 10;
831 intel_dsi->i2c_bus_num = -1;
833 /* a regular driver would get the device in probe */
834 for_each_dsi_port(port, intel_dsi->ports) {
835 mipi_dsi_attach(intel_dsi->dsi_hosts[port]->device);
842 * On some BYT/CHT devs some sequences are incomplete and we need to manually
843 * control some GPIOs. We need to add a GPIO lookup table before we get these.
844 * If the GOP did not initialize the panel (HDMI inserted) we may need to also
845 * change the pinmux for the SoC's PWM0 pin from GPIO to PWM.
847 static struct gpiod_lookup_table pmic_panel_gpio_table = {
848 /* Intel GFX is consumer */
849 .dev_id = "0000:00:02.0",
851 /* Panel EN/DISABLE */
852 GPIO_LOOKUP("gpio_crystalcove", 94, "panel", GPIO_ACTIVE_HIGH),
857 static struct gpiod_lookup_table soc_panel_gpio_table = {
858 .dev_id = "0000:00:02.0",
860 GPIO_LOOKUP("INT33FC:01", 10, "backlight", GPIO_ACTIVE_HIGH),
861 GPIO_LOOKUP("INT33FC:01", 11, "panel", GPIO_ACTIVE_HIGH),
866 static const struct pinctrl_map soc_pwm_pinctrl_map[] = {
867 PIN_MAP_MUX_GROUP("0000:00:02.0", "soc_pwm0", "INT33FC:00",
871 void intel_dsi_vbt_gpio_init(struct intel_dsi *intel_dsi, bool panel_is_on)
873 struct drm_device *dev = intel_dsi->base.base.dev;
874 struct drm_i915_private *dev_priv = to_i915(dev);
875 struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;
876 enum gpiod_flags flags = panel_is_on ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
877 bool want_backlight_gpio = false;
878 bool want_panel_gpio = false;
879 struct pinctrl *pinctrl;
882 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
883 mipi_config->pwm_blc == PPS_BLC_PMIC) {
884 gpiod_add_lookup_table(&pmic_panel_gpio_table);
885 want_panel_gpio = true;
888 if (IS_VALLEYVIEW(dev_priv) && mipi_config->pwm_blc == PPS_BLC_SOC) {
889 gpiod_add_lookup_table(&soc_panel_gpio_table);
890 want_panel_gpio = true;
891 want_backlight_gpio = true;
893 /* Ensure PWM0 pin is muxed as PWM instead of GPIO */
894 ret = pinctrl_register_mappings(soc_pwm_pinctrl_map,
895 ARRAY_SIZE(soc_pwm_pinctrl_map));
897 drm_err(&dev_priv->drm,
898 "Failed to register pwm0 pinmux mapping\n");
900 pinctrl = devm_pinctrl_get_select(dev->dev, "soc_pwm0");
902 drm_err(&dev_priv->drm,
903 "Failed to set pinmux to PWM\n");
906 if (want_panel_gpio) {
907 intel_dsi->gpio_panel = gpiod_get(dev->dev, "panel", flags);
908 if (IS_ERR(intel_dsi->gpio_panel)) {
909 drm_err(&dev_priv->drm,
910 "Failed to own gpio for panel control\n");
911 intel_dsi->gpio_panel = NULL;
915 if (want_backlight_gpio) {
916 intel_dsi->gpio_backlight =
917 gpiod_get(dev->dev, "backlight", flags);
918 if (IS_ERR(intel_dsi->gpio_backlight)) {
919 drm_err(&dev_priv->drm,
920 "Failed to own gpio for backlight control\n");
921 intel_dsi->gpio_backlight = NULL;
926 void intel_dsi_vbt_gpio_cleanup(struct intel_dsi *intel_dsi)
928 struct drm_device *dev = intel_dsi->base.base.dev;
929 struct drm_i915_private *dev_priv = to_i915(dev);
930 struct mipi_config *mipi_config = dev_priv->vbt.dsi.config;
932 if (intel_dsi->gpio_panel) {
933 gpiod_put(intel_dsi->gpio_panel);
934 intel_dsi->gpio_panel = NULL;
937 if (intel_dsi->gpio_backlight) {
938 gpiod_put(intel_dsi->gpio_backlight);
939 intel_dsi->gpio_backlight = NULL;
942 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
943 mipi_config->pwm_blc == PPS_BLC_PMIC)
944 gpiod_remove_lookup_table(&pmic_panel_gpio_table);
946 if (IS_VALLEYVIEW(dev_priv) && mipi_config->pwm_blc == PPS_BLC_SOC) {
947 pinctrl_unregister_mappings(soc_pwm_pinctrl_map);
948 gpiod_remove_lookup_table(&soc_panel_gpio_table);