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>
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>
45 #include "intel_display_types.h"
46 #include "intel_dsi.h"
47 #include "intel_dsi_vbt.h"
48 #include "intel_gmbus_regs.h"
49 #include "intel_pps_regs.h"
51 #include "vlv_dsi_regs.h"
52 #include "vlv_sideband.h"
54 #define MIPI_TRANSFER_MODE_SHIFT 0
55 #define MIPI_VIRTUAL_CHANNEL_SHIFT 1
56 #define MIPI_PORT_SHIFT 3
58 /* base offsets for gpio pads */
59 #define VLV_GPIO_NC_0_HV_DDI0_HPD 0x4130
60 #define VLV_GPIO_NC_1_HV_DDI0_DDC_SDA 0x4120
61 #define VLV_GPIO_NC_2_HV_DDI0_DDC_SCL 0x4110
62 #define VLV_GPIO_NC_3_PANEL0_VDDEN 0x4140
63 #define VLV_GPIO_NC_4_PANEL0_BKLTEN 0x4150
64 #define VLV_GPIO_NC_5_PANEL0_BKLTCTL 0x4160
65 #define VLV_GPIO_NC_6_HV_DDI1_HPD 0x4180
66 #define VLV_GPIO_NC_7_HV_DDI1_DDC_SDA 0x4190
67 #define VLV_GPIO_NC_8_HV_DDI1_DDC_SCL 0x4170
68 #define VLV_GPIO_NC_9_PANEL1_VDDEN 0x4100
69 #define VLV_GPIO_NC_10_PANEL1_BKLTEN 0x40E0
70 #define VLV_GPIO_NC_11_PANEL1_BKLTCTL 0x40F0
72 #define VLV_GPIO_PCONF0(base_offset) (base_offset)
73 #define VLV_GPIO_PAD_VAL(base_offset) ((base_offset) + 8)
80 static struct gpio_map vlv_gpio_table[] = {
81 { VLV_GPIO_NC_0_HV_DDI0_HPD },
82 { VLV_GPIO_NC_1_HV_DDI0_DDC_SDA },
83 { VLV_GPIO_NC_2_HV_DDI0_DDC_SCL },
84 { VLV_GPIO_NC_3_PANEL0_VDDEN },
85 { VLV_GPIO_NC_4_PANEL0_BKLTEN },
86 { VLV_GPIO_NC_5_PANEL0_BKLTCTL },
87 { VLV_GPIO_NC_6_HV_DDI1_HPD },
88 { VLV_GPIO_NC_7_HV_DDI1_DDC_SDA },
89 { VLV_GPIO_NC_8_HV_DDI1_DDC_SCL },
90 { VLV_GPIO_NC_9_PANEL1_VDDEN },
91 { VLV_GPIO_NC_10_PANEL1_BKLTEN },
92 { VLV_GPIO_NC_11_PANEL1_BKLTCTL },
95 struct i2c_adapter_lookup {
97 struct intel_dsi *intel_dsi;
98 acpi_handle dev_handle;
101 #define CHV_GPIO_IDX_START_N 0
102 #define CHV_GPIO_IDX_START_E 73
103 #define CHV_GPIO_IDX_START_SW 100
104 #define CHV_GPIO_IDX_START_SE 198
106 #define CHV_VBT_MAX_PINS_PER_FMLY 15
108 #define CHV_GPIO_PAD_CFG0(f, i) (0x4400 + (f) * 0x400 + (i) * 8)
109 #define CHV_GPIO_GPIOEN (1 << 15)
110 #define CHV_GPIO_GPIOCFG_GPIO (0 << 8)
111 #define CHV_GPIO_GPIOCFG_GPO (1 << 8)
112 #define CHV_GPIO_GPIOCFG_GPI (2 << 8)
113 #define CHV_GPIO_GPIOCFG_HIZ (3 << 8)
114 #define CHV_GPIO_GPIOTXSTATE(state) ((!!(state)) << 1)
116 #define CHV_GPIO_PAD_CFG1(f, i) (0x4400 + (f) * 0x400 + (i) * 8 + 4)
117 #define CHV_GPIO_CFGLOCK (1 << 31)
119 /* ICL DSI Display GPIO Pins */
120 #define ICL_GPIO_DDSP_HPD_A 0
121 #define ICL_GPIO_L_VDDEN_1 1
122 #define ICL_GPIO_L_BKLTEN_1 2
123 #define ICL_GPIO_DDPA_CTRLCLK_1 3
124 #define ICL_GPIO_DDPA_CTRLDATA_1 4
125 #define ICL_GPIO_DDSP_HPD_B 5
126 #define ICL_GPIO_L_VDDEN_2 6
127 #define ICL_GPIO_L_BKLTEN_2 7
128 #define ICL_GPIO_DDPA_CTRLCLK_2 8
129 #define ICL_GPIO_DDPA_CTRLDATA_2 9
131 static enum port intel_dsi_seq_port_to_port(struct intel_dsi *intel_dsi,
135 * If single link DSI is being used on any port, the VBT sequence block
136 * send packet apparently always has 0 for the port. Just use the port
137 * we have configured, and ignore the sequence block port.
139 if (hweight8(intel_dsi->ports) == 1)
140 return ffs(intel_dsi->ports) - 1;
143 if (intel_dsi->ports & BIT(PORT_B))
145 else if (intel_dsi->ports & BIT(PORT_C))
152 static const u8 *mipi_exec_send_packet(struct intel_dsi *intel_dsi,
155 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
156 struct mipi_dsi_device *dsi_device;
157 u8 type, flags, seq_port;
161 drm_dbg_kms(&dev_priv->drm, "\n");
166 len = *((u16 *) data);
169 seq_port = (flags >> MIPI_PORT_SHIFT) & 3;
171 port = intel_dsi_seq_port_to_port(intel_dsi, seq_port);
173 if (drm_WARN_ON(&dev_priv->drm, !intel_dsi->dsi_hosts[port]))
176 dsi_device = intel_dsi->dsi_hosts[port]->device;
178 drm_dbg_kms(&dev_priv->drm, "no dsi device for port %c\n",
183 if ((flags >> MIPI_TRANSFER_MODE_SHIFT) & 1)
184 dsi_device->mode_flags &= ~MIPI_DSI_MODE_LPM;
186 dsi_device->mode_flags |= MIPI_DSI_MODE_LPM;
188 dsi_device->channel = (flags >> MIPI_VIRTUAL_CHANNEL_SHIFT) & 3;
191 case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
192 mipi_dsi_generic_write(dsi_device, NULL, 0);
194 case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
195 mipi_dsi_generic_write(dsi_device, data, 1);
197 case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
198 mipi_dsi_generic_write(dsi_device, data, 2);
200 case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
201 case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
202 case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
203 drm_dbg(&dev_priv->drm,
204 "Generic Read not yet implemented or used\n");
206 case MIPI_DSI_GENERIC_LONG_WRITE:
207 mipi_dsi_generic_write(dsi_device, data, len);
209 case MIPI_DSI_DCS_SHORT_WRITE:
210 mipi_dsi_dcs_write_buffer(dsi_device, data, 1);
212 case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
213 mipi_dsi_dcs_write_buffer(dsi_device, data, 2);
215 case MIPI_DSI_DCS_READ:
216 drm_dbg(&dev_priv->drm,
217 "DCS Read not yet implemented or used\n");
219 case MIPI_DSI_DCS_LONG_WRITE:
220 mipi_dsi_dcs_write_buffer(dsi_device, data, len);
224 if (DISPLAY_VER(dev_priv) < 11)
225 vlv_dsi_wait_for_fifo_empty(intel_dsi, port);
233 static const u8 *mipi_exec_delay(struct intel_dsi *intel_dsi, const u8 *data)
235 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev);
236 u32 delay = *((const u32 *) data);
238 drm_dbg_kms(&i915->drm, "\n");
240 usleep_range(delay, delay + 10);
246 static void vlv_exec_gpio(struct intel_connector *connector,
247 u8 gpio_source, u8 gpio_index, bool value)
249 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
250 struct gpio_map *map;
255 if (gpio_index >= ARRAY_SIZE(vlv_gpio_table)) {
256 drm_dbg_kms(&dev_priv->drm, "unknown gpio index %u\n",
261 map = &vlv_gpio_table[gpio_index];
263 if (connector->panel.vbt.dsi.seq_version >= 3) {
264 /* XXX: this assumes vlv_gpio_table only has NC GPIOs. */
265 port = IOSF_PORT_GPIO_NC;
267 if (gpio_source == 0) {
268 port = IOSF_PORT_GPIO_NC;
269 } else if (gpio_source == 1) {
270 drm_dbg_kms(&dev_priv->drm, "SC gpio not supported\n");
273 drm_dbg_kms(&dev_priv->drm,
274 "unknown gpio source %u\n", gpio_source);
279 pconf0 = VLV_GPIO_PCONF0(map->base_offset);
280 padval = VLV_GPIO_PAD_VAL(map->base_offset);
282 vlv_iosf_sb_get(dev_priv, BIT(VLV_IOSF_SB_GPIO));
284 /* FIXME: remove constant below */
285 vlv_iosf_sb_write(dev_priv, port, pconf0, 0x2000CC00);
290 vlv_iosf_sb_write(dev_priv, port, padval, tmp);
291 vlv_iosf_sb_put(dev_priv, BIT(VLV_IOSF_SB_GPIO));
294 static void chv_exec_gpio(struct intel_connector *connector,
295 u8 gpio_source, u8 gpio_index, bool value)
297 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
302 if (connector->panel.vbt.dsi.seq_version >= 3) {
303 if (gpio_index >= CHV_GPIO_IDX_START_SE) {
304 /* XXX: it's unclear whether 255->57 is part of SE. */
305 gpio_index -= CHV_GPIO_IDX_START_SE;
306 port = CHV_IOSF_PORT_GPIO_SE;
307 } else if (gpio_index >= CHV_GPIO_IDX_START_SW) {
308 gpio_index -= CHV_GPIO_IDX_START_SW;
309 port = CHV_IOSF_PORT_GPIO_SW;
310 } else if (gpio_index >= CHV_GPIO_IDX_START_E) {
311 gpio_index -= CHV_GPIO_IDX_START_E;
312 port = CHV_IOSF_PORT_GPIO_E;
314 port = CHV_IOSF_PORT_GPIO_N;
317 /* XXX: The spec is unclear about CHV GPIO on seq v2 */
318 if (gpio_source != 0) {
319 drm_dbg_kms(&dev_priv->drm,
320 "unknown gpio source %u\n", gpio_source);
324 if (gpio_index >= CHV_GPIO_IDX_START_E) {
325 drm_dbg_kms(&dev_priv->drm,
326 "invalid gpio index %u for GPIO N\n",
331 port = CHV_IOSF_PORT_GPIO_N;
334 family_num = gpio_index / CHV_VBT_MAX_PINS_PER_FMLY;
335 gpio_index = gpio_index % CHV_VBT_MAX_PINS_PER_FMLY;
337 cfg0 = CHV_GPIO_PAD_CFG0(family_num, gpio_index);
338 cfg1 = CHV_GPIO_PAD_CFG1(family_num, gpio_index);
340 vlv_iosf_sb_get(dev_priv, BIT(VLV_IOSF_SB_GPIO));
341 vlv_iosf_sb_write(dev_priv, port, cfg1, 0);
342 vlv_iosf_sb_write(dev_priv, port, cfg0,
343 CHV_GPIO_GPIOEN | CHV_GPIO_GPIOCFG_GPO |
344 CHV_GPIO_GPIOTXSTATE(value));
345 vlv_iosf_sb_put(dev_priv, BIT(VLV_IOSF_SB_GPIO));
348 static void bxt_exec_gpio(struct intel_connector *connector,
349 u8 gpio_source, u8 gpio_index, bool value)
351 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
352 /* XXX: this table is a quick ugly hack. */
353 static struct gpio_desc *bxt_gpio_table[U8_MAX + 1];
354 struct gpio_desc *gpio_desc = bxt_gpio_table[gpio_index];
357 gpio_desc = devm_gpiod_get_index(dev_priv->drm.dev,
359 value ? GPIOD_OUT_LOW :
362 if (IS_ERR_OR_NULL(gpio_desc)) {
363 drm_err(&dev_priv->drm,
364 "GPIO index %u request failed (%ld)\n",
365 gpio_index, PTR_ERR(gpio_desc));
369 bxt_gpio_table[gpio_index] = gpio_desc;
372 gpiod_set_value(gpio_desc, value);
375 static void icl_exec_gpio(struct intel_connector *connector,
376 u8 gpio_source, u8 gpio_index, bool value)
378 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
380 drm_dbg_kms(&dev_priv->drm, "Skipping ICL GPIO element execution\n");
396 static void icl_native_gpio_set_value(struct drm_i915_private *dev_priv,
397 int gpio, bool value)
401 if (drm_WARN_ON(&dev_priv->drm, DISPLAY_VER(dev_priv) == 11 && gpio >= MIPI_RESET_2))
407 index = gpio == MIPI_RESET_1 ? HPD_PORT_A : HPD_PORT_B;
410 * Disable HPD to set the pin to output, and set output
411 * value. The HPD pin should not be enabled for DSI anyway,
412 * assuming the board design and VBT are sane, and the pin isn't
413 * used by a non-DSI encoder.
415 * The locking protects against concurrent SHOTPLUG_CTL_DDI
416 * modifications in irq setup and handling.
418 spin_lock_irq(&dev_priv->irq_lock);
419 intel_de_rmw(dev_priv, SHOTPLUG_CTL_DDI,
420 SHOTPLUG_CTL_DDI_HPD_ENABLE(index) |
421 SHOTPLUG_CTL_DDI_HPD_OUTPUT_DATA(index),
422 value ? SHOTPLUG_CTL_DDI_HPD_OUTPUT_DATA(index) : 0);
423 spin_unlock_irq(&dev_priv->irq_lock);
427 index = gpio == MIPI_AVDD_EN_1 ? 0 : 1;
429 intel_de_rmw(dev_priv, PP_CONTROL(index), PANEL_POWER_ON,
430 value ? PANEL_POWER_ON : 0);
434 index = gpio == MIPI_BKLT_EN_1 ? 0 : 1;
436 intel_de_rmw(dev_priv, PP_CONTROL(index), EDP_BLC_ENABLE,
437 value ? EDP_BLC_ENABLE : 0);
441 index = gpio == MIPI_AVEE_EN_1 ? 1 : 2;
443 intel_de_rmw(dev_priv, GPIO(dev_priv, index),
445 GPIO_CLOCK_DIR_MASK | GPIO_CLOCK_DIR_OUT |
446 GPIO_CLOCK_VAL_MASK | (value ? GPIO_CLOCK_VAL_OUT : 0));
450 index = gpio == MIPI_VIO_EN_1 ? 1 : 2;
452 intel_de_rmw(dev_priv, GPIO(dev_priv, index),
454 GPIO_DATA_DIR_MASK | GPIO_DATA_DIR_OUT |
455 GPIO_DATA_VAL_MASK | (value ? GPIO_DATA_VAL_OUT : 0));
462 static const u8 *mipi_exec_gpio(struct intel_dsi *intel_dsi, const u8 *data)
464 struct drm_device *dev = intel_dsi->base.base.dev;
465 struct drm_i915_private *dev_priv = to_i915(dev);
466 struct intel_connector *connector = intel_dsi->attached_connector;
467 u8 gpio_source, gpio_index = 0, gpio_number;
469 bool native = DISPLAY_VER(dev_priv) >= 11;
471 if (connector->panel.vbt.dsi.seq_version >= 3)
472 gpio_index = *data++;
474 gpio_number = *data++;
476 /* gpio source in sequence v2 only */
477 if (connector->panel.vbt.dsi.seq_version == 2)
478 gpio_source = (*data >> 1) & 3;
482 if (connector->panel.vbt.dsi.seq_version >= 4 && *data & BIT(1))
488 drm_dbg_kms(&dev_priv->drm, "GPIO index %u, number %u, source %u, native %s, set to %s\n",
489 gpio_index, gpio_number, gpio_source, str_yes_no(native), str_on_off(value));
492 icl_native_gpio_set_value(dev_priv, gpio_number, value);
493 else if (DISPLAY_VER(dev_priv) >= 11)
494 icl_exec_gpio(connector, gpio_source, gpio_index, value);
495 else if (IS_VALLEYVIEW(dev_priv))
496 vlv_exec_gpio(connector, gpio_source, gpio_number, value);
497 else if (IS_CHERRYVIEW(dev_priv))
498 chv_exec_gpio(connector, gpio_source, gpio_number, value);
500 bxt_exec_gpio(connector, gpio_source, gpio_index, value);
506 static int i2c_adapter_lookup(struct acpi_resource *ares, void *data)
508 struct i2c_adapter_lookup *lookup = data;
509 struct intel_dsi *intel_dsi = lookup->intel_dsi;
510 struct acpi_resource_i2c_serialbus *sb;
511 struct i2c_adapter *adapter;
512 acpi_handle adapter_handle;
515 if (!i2c_acpi_get_i2c_resource(ares, &sb))
518 if (lookup->slave_addr != sb->slave_address)
521 status = acpi_get_handle(lookup->dev_handle,
522 sb->resource_source.string_ptr,
524 if (ACPI_FAILURE(status))
527 adapter = i2c_acpi_find_adapter_by_handle(adapter_handle);
529 intel_dsi->i2c_bus_num = adapter->nr;
534 static void i2c_acpi_find_adapter(struct intel_dsi *intel_dsi,
535 const u16 slave_addr)
537 struct drm_device *drm_dev = intel_dsi->base.base.dev;
538 struct acpi_device *adev = ACPI_COMPANION(drm_dev->dev);
539 struct i2c_adapter_lookup lookup = {
540 .slave_addr = slave_addr,
541 .intel_dsi = intel_dsi,
542 .dev_handle = acpi_device_handle(adev),
544 LIST_HEAD(resource_list);
546 acpi_dev_get_resources(adev, &resource_list, i2c_adapter_lookup, &lookup);
547 acpi_dev_free_resource_list(&resource_list);
550 static inline void i2c_acpi_find_adapter(struct intel_dsi *intel_dsi,
551 const u16 slave_addr)
556 static const u8 *mipi_exec_i2c(struct intel_dsi *intel_dsi, const u8 *data)
558 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev);
559 struct i2c_adapter *adapter;
562 u8 vbt_i2c_bus_num = *(data + 2);
563 u16 slave_addr = *(u16 *)(data + 3);
564 u8 reg_offset = *(data + 5);
565 u8 payload_size = *(data + 6);
568 if (intel_dsi->i2c_bus_num < 0) {
569 intel_dsi->i2c_bus_num = vbt_i2c_bus_num;
570 i2c_acpi_find_adapter(intel_dsi, slave_addr);
573 adapter = i2c_get_adapter(intel_dsi->i2c_bus_num);
575 drm_err(&i915->drm, "Cannot find a valid i2c bus for xfer\n");
579 payload_data = kzalloc(payload_size + 1, GFP_KERNEL);
583 payload_data[0] = reg_offset;
584 memcpy(&payload_data[1], (data + 7), payload_size);
586 msg.addr = slave_addr;
588 msg.len = payload_size + 1;
589 msg.buf = payload_data;
591 ret = i2c_transfer(adapter, &msg, 1);
594 "Failed to xfer payload of size (%u) to reg (%u)\n",
595 payload_size, reg_offset);
599 i2c_put_adapter(adapter);
601 return data + payload_size + 7;
604 static const u8 *mipi_exec_spi(struct intel_dsi *intel_dsi, const u8 *data)
606 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev);
608 drm_dbg_kms(&i915->drm, "Skipping SPI element execution\n");
610 return data + *(data + 5) + 6;
613 static const u8 *mipi_exec_pmic(struct intel_dsi *intel_dsi, const u8 *data)
615 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev);
616 #ifdef CONFIG_PMIC_OPREGION
617 u32 value, mask, reg_address;
621 /* byte 0 aka PMIC Flag is reserved */
622 i2c_address = get_unaligned_le16(data + 1);
623 reg_address = get_unaligned_le32(data + 3);
624 value = get_unaligned_le32(data + 7);
625 mask = get_unaligned_le32(data + 11);
627 ret = intel_soc_pmic_exec_mipi_pmic_seq_element(i2c_address,
631 drm_err(&i915->drm, "%s failed, error: %d\n", __func__, ret);
634 "Your hardware requires CONFIG_PMIC_OPREGION and it is not set\n");
640 typedef const u8 * (*fn_mipi_elem_exec)(struct intel_dsi *intel_dsi,
642 static const fn_mipi_elem_exec exec_elem[] = {
643 [MIPI_SEQ_ELEM_SEND_PKT] = mipi_exec_send_packet,
644 [MIPI_SEQ_ELEM_DELAY] = mipi_exec_delay,
645 [MIPI_SEQ_ELEM_GPIO] = mipi_exec_gpio,
646 [MIPI_SEQ_ELEM_I2C] = mipi_exec_i2c,
647 [MIPI_SEQ_ELEM_SPI] = mipi_exec_spi,
648 [MIPI_SEQ_ELEM_PMIC] = mipi_exec_pmic,
652 * MIPI Sequence from VBT #53 parsing logic
653 * We have already separated each seqence during bios parsing
654 * Following is generic execution function for any sequence
657 static const char * const seq_name[] = {
658 [MIPI_SEQ_DEASSERT_RESET] = "MIPI_SEQ_DEASSERT_RESET",
659 [MIPI_SEQ_INIT_OTP] = "MIPI_SEQ_INIT_OTP",
660 [MIPI_SEQ_DISPLAY_ON] = "MIPI_SEQ_DISPLAY_ON",
661 [MIPI_SEQ_DISPLAY_OFF] = "MIPI_SEQ_DISPLAY_OFF",
662 [MIPI_SEQ_ASSERT_RESET] = "MIPI_SEQ_ASSERT_RESET",
663 [MIPI_SEQ_BACKLIGHT_ON] = "MIPI_SEQ_BACKLIGHT_ON",
664 [MIPI_SEQ_BACKLIGHT_OFF] = "MIPI_SEQ_BACKLIGHT_OFF",
665 [MIPI_SEQ_TEAR_ON] = "MIPI_SEQ_TEAR_ON",
666 [MIPI_SEQ_TEAR_OFF] = "MIPI_SEQ_TEAR_OFF",
667 [MIPI_SEQ_POWER_ON] = "MIPI_SEQ_POWER_ON",
668 [MIPI_SEQ_POWER_OFF] = "MIPI_SEQ_POWER_OFF",
671 static const char *sequence_name(enum mipi_seq seq_id)
673 if (seq_id < ARRAY_SIZE(seq_name) && seq_name[seq_id])
674 return seq_name[seq_id];
679 static void intel_dsi_vbt_exec(struct intel_dsi *intel_dsi,
680 enum mipi_seq seq_id)
682 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
683 struct intel_connector *connector = intel_dsi->attached_connector;
685 fn_mipi_elem_exec mipi_elem_exec;
687 if (drm_WARN_ON(&dev_priv->drm,
688 seq_id >= ARRAY_SIZE(connector->panel.vbt.dsi.sequence)))
691 data = connector->panel.vbt.dsi.sequence[seq_id];
695 drm_WARN_ON(&dev_priv->drm, *data != seq_id);
697 drm_dbg_kms(&dev_priv->drm, "Starting MIPI sequence %d - %s\n",
698 seq_id, sequence_name(seq_id));
700 /* Skip Sequence Byte. */
703 /* Skip Size of Sequence. */
704 if (connector->panel.vbt.dsi.seq_version >= 3)
708 u8 operation_byte = *data++;
709 u8 operation_size = 0;
711 if (operation_byte == MIPI_SEQ_ELEM_END)
714 if (operation_byte < ARRAY_SIZE(exec_elem))
715 mipi_elem_exec = exec_elem[operation_byte];
717 mipi_elem_exec = NULL;
719 /* Size of Operation. */
720 if (connector->panel.vbt.dsi.seq_version >= 3)
721 operation_size = *data++;
723 if (mipi_elem_exec) {
724 const u8 *next = data + operation_size;
726 data = mipi_elem_exec(intel_dsi, data);
728 /* Consistency check if we have size. */
729 if (operation_size && data != next) {
730 drm_err(&dev_priv->drm,
731 "Inconsistent operation size\n");
734 } else if (operation_size) {
735 /* We have size, skip. */
736 drm_dbg_kms(&dev_priv->drm,
737 "Unsupported MIPI operation byte %u\n",
739 data += operation_size;
741 /* No size, can't skip without parsing. */
742 drm_err(&dev_priv->drm,
743 "Unsupported MIPI operation byte %u\n",
750 void intel_dsi_vbt_exec_sequence(struct intel_dsi *intel_dsi,
751 enum mipi_seq seq_id)
753 if (seq_id == MIPI_SEQ_POWER_ON && intel_dsi->gpio_panel)
754 gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1);
755 if (seq_id == MIPI_SEQ_BACKLIGHT_ON && intel_dsi->gpio_backlight)
756 gpiod_set_value_cansleep(intel_dsi->gpio_backlight, 1);
758 intel_dsi_vbt_exec(intel_dsi, seq_id);
760 if (seq_id == MIPI_SEQ_POWER_OFF && intel_dsi->gpio_panel)
761 gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0);
762 if (seq_id == MIPI_SEQ_BACKLIGHT_OFF && intel_dsi->gpio_backlight)
763 gpiod_set_value_cansleep(intel_dsi->gpio_backlight, 0);
766 void intel_dsi_log_params(struct intel_dsi *intel_dsi)
768 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev);
770 drm_dbg_kms(&i915->drm, "Pclk %d\n", intel_dsi->pclk);
771 drm_dbg_kms(&i915->drm, "Pixel overlap %d\n",
772 intel_dsi->pixel_overlap);
773 drm_dbg_kms(&i915->drm, "Lane count %d\n", intel_dsi->lane_count);
774 drm_dbg_kms(&i915->drm, "DPHY param reg 0x%x\n", intel_dsi->dphy_reg);
775 drm_dbg_kms(&i915->drm, "Video mode format %s\n",
776 intel_dsi->video_mode == NON_BURST_SYNC_PULSE ?
777 "non-burst with sync pulse" :
778 intel_dsi->video_mode == NON_BURST_SYNC_EVENTS ?
779 "non-burst with sync events" :
780 intel_dsi->video_mode == BURST_MODE ?
781 "burst" : "<unknown>");
782 drm_dbg_kms(&i915->drm, "Burst mode ratio %d\n",
783 intel_dsi->burst_mode_ratio);
784 drm_dbg_kms(&i915->drm, "Reset timer %d\n", intel_dsi->rst_timer_val);
785 drm_dbg_kms(&i915->drm, "Eot %s\n",
786 str_enabled_disabled(intel_dsi->eotp_pkt));
787 drm_dbg_kms(&i915->drm, "Clockstop %s\n",
788 str_enabled_disabled(!intel_dsi->clock_stop));
789 drm_dbg_kms(&i915->drm, "Mode %s\n",
790 intel_dsi->operation_mode ? "command" : "video");
791 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
792 drm_dbg_kms(&i915->drm,
793 "Dual link: DSI_DUAL_LINK_FRONT_BACK\n");
794 else if (intel_dsi->dual_link == DSI_DUAL_LINK_PIXEL_ALT)
795 drm_dbg_kms(&i915->drm,
796 "Dual link: DSI_DUAL_LINK_PIXEL_ALT\n");
798 drm_dbg_kms(&i915->drm, "Dual link: NONE\n");
799 drm_dbg_kms(&i915->drm, "Pixel Format %d\n", intel_dsi->pixel_format);
800 drm_dbg_kms(&i915->drm, "TLPX %d\n", intel_dsi->escape_clk_div);
801 drm_dbg_kms(&i915->drm, "LP RX Timeout 0x%x\n",
802 intel_dsi->lp_rx_timeout);
803 drm_dbg_kms(&i915->drm, "Turnaround Timeout 0x%x\n",
804 intel_dsi->turn_arnd_val);
805 drm_dbg_kms(&i915->drm, "Init Count 0x%x\n", intel_dsi->init_count);
806 drm_dbg_kms(&i915->drm, "HS to LP Count 0x%x\n",
807 intel_dsi->hs_to_lp_count);
808 drm_dbg_kms(&i915->drm, "LP Byte Clock %d\n", intel_dsi->lp_byte_clk);
809 drm_dbg_kms(&i915->drm, "DBI BW Timer 0x%x\n", intel_dsi->bw_timer);
810 drm_dbg_kms(&i915->drm, "LP to HS Clock Count 0x%x\n",
811 intel_dsi->clk_lp_to_hs_count);
812 drm_dbg_kms(&i915->drm, "HS to LP Clock Count 0x%x\n",
813 intel_dsi->clk_hs_to_lp_count);
814 drm_dbg_kms(&i915->drm, "BTA %s\n",
815 str_enabled_disabled(!(intel_dsi->video_frmt_cfg_bits & DISABLE_VIDEO_BTA)));
818 bool intel_dsi_vbt_init(struct intel_dsi *intel_dsi, u16 panel_id)
820 struct drm_device *dev = intel_dsi->base.base.dev;
821 struct drm_i915_private *dev_priv = to_i915(dev);
822 struct intel_connector *connector = intel_dsi->attached_connector;
823 struct mipi_config *mipi_config = connector->panel.vbt.dsi.config;
824 struct mipi_pps_data *pps = connector->panel.vbt.dsi.pps;
825 struct drm_display_mode *mode = connector->panel.vbt.lfp_lvds_vbt_mode;
826 u16 burst_mode_ratio;
829 drm_dbg_kms(&dev_priv->drm, "\n");
831 intel_dsi->eotp_pkt = mipi_config->eot_pkt_disabled ? 0 : 1;
832 intel_dsi->clock_stop = mipi_config->enable_clk_stop ? 1 : 0;
833 intel_dsi->lane_count = mipi_config->lane_cnt + 1;
834 intel_dsi->pixel_format =
835 pixel_format_from_register_bits(
836 mipi_config->videomode_color_format << 7);
838 intel_dsi->dual_link = mipi_config->dual_link;
839 intel_dsi->pixel_overlap = mipi_config->pixel_overlap;
840 intel_dsi->operation_mode = mipi_config->is_cmd_mode;
841 intel_dsi->video_mode = mipi_config->video_transfer_mode;
842 intel_dsi->escape_clk_div = mipi_config->byte_clk_sel;
843 intel_dsi->lp_rx_timeout = mipi_config->lp_rx_timeout;
844 intel_dsi->hs_tx_timeout = mipi_config->hs_tx_timeout;
845 intel_dsi->turn_arnd_val = mipi_config->turn_around_timeout;
846 intel_dsi->rst_timer_val = mipi_config->device_reset_timer;
847 intel_dsi->init_count = mipi_config->master_init_timer;
848 intel_dsi->bw_timer = mipi_config->dbi_bw_timer;
849 intel_dsi->video_frmt_cfg_bits =
850 mipi_config->bta_enabled ? DISABLE_VIDEO_BTA : 0;
851 intel_dsi->bgr_enabled = mipi_config->rgb_flip;
853 /* Starting point, adjusted depending on dual link and burst mode */
854 intel_dsi->pclk = mode->clock;
856 /* In dual link mode each port needs half of pixel clock */
857 if (intel_dsi->dual_link) {
858 intel_dsi->pclk /= 2;
860 /* we can enable pixel_overlap if needed by panel. In this
861 * case we need to increase the pixelclock for extra pixels
863 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
864 intel_dsi->pclk += DIV_ROUND_UP(mode->vtotal * intel_dsi->pixel_overlap * 60, 1000);
869 * Target ddr frequency from VBT / non burst ddr freq
870 * multiply by 100 to preserve remainder
872 if (intel_dsi->video_mode == BURST_MODE) {
873 if (mipi_config->target_burst_mode_freq) {
874 u32 bitrate = intel_dsi_bitrate(intel_dsi);
877 * Sometimes the VBT contains a slightly lower clock,
878 * then the bitrate we have calculated, in this case
879 * just replace it with the calculated bitrate.
881 if (mipi_config->target_burst_mode_freq < bitrate &&
882 intel_fuzzy_clock_check(
883 mipi_config->target_burst_mode_freq,
885 mipi_config->target_burst_mode_freq = bitrate;
887 if (mipi_config->target_burst_mode_freq < bitrate) {
888 drm_err(&dev_priv->drm,
889 "Burst mode freq is less than computed\n");
893 burst_mode_ratio = DIV_ROUND_UP(
894 mipi_config->target_burst_mode_freq * 100,
897 intel_dsi->pclk = DIV_ROUND_UP(intel_dsi->pclk * burst_mode_ratio, 100);
899 drm_err(&dev_priv->drm,
900 "Burst mode target is not set\n");
904 burst_mode_ratio = 100;
906 intel_dsi->burst_mode_ratio = burst_mode_ratio;
908 /* delays in VBT are in unit of 100us, so need to convert
910 * Delay (100us) * 100 /1000 = Delay / 10 (ms) */
911 intel_dsi->backlight_off_delay = pps->bl_disable_delay / 10;
912 intel_dsi->backlight_on_delay = pps->bl_enable_delay / 10;
913 intel_dsi->panel_on_delay = pps->panel_on_delay / 10;
914 intel_dsi->panel_off_delay = pps->panel_off_delay / 10;
915 intel_dsi->panel_pwr_cycle_delay = pps->panel_power_cycle_delay / 10;
917 intel_dsi->i2c_bus_num = -1;
919 /* a regular driver would get the device in probe */
920 for_each_dsi_port(port, intel_dsi->ports) {
921 mipi_dsi_attach(intel_dsi->dsi_hosts[port]->device);
928 * On some BYT/CHT devs some sequences are incomplete and we need to manually
929 * control some GPIOs. We need to add a GPIO lookup table before we get these.
930 * If the GOP did not initialize the panel (HDMI inserted) we may need to also
931 * change the pinmux for the SoC's PWM0 pin from GPIO to PWM.
933 static struct gpiod_lookup_table pmic_panel_gpio_table = {
934 /* Intel GFX is consumer */
935 .dev_id = "0000:00:02.0",
937 /* Panel EN/DISABLE */
938 GPIO_LOOKUP("gpio_crystalcove", 94, "panel", GPIO_ACTIVE_HIGH),
943 static struct gpiod_lookup_table soc_panel_gpio_table = {
944 .dev_id = "0000:00:02.0",
946 GPIO_LOOKUP("INT33FC:01", 10, "backlight", GPIO_ACTIVE_HIGH),
947 GPIO_LOOKUP("INT33FC:01", 11, "panel", GPIO_ACTIVE_HIGH),
952 static const struct pinctrl_map soc_pwm_pinctrl_map[] = {
953 PIN_MAP_MUX_GROUP("0000:00:02.0", "soc_pwm0", "INT33FC:00",
957 void intel_dsi_vbt_gpio_init(struct intel_dsi *intel_dsi, bool panel_is_on)
959 struct drm_device *dev = intel_dsi->base.base.dev;
960 struct drm_i915_private *dev_priv = to_i915(dev);
961 struct intel_connector *connector = intel_dsi->attached_connector;
962 struct mipi_config *mipi_config = connector->panel.vbt.dsi.config;
963 enum gpiod_flags flags = panel_is_on ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
964 bool want_backlight_gpio = false;
965 bool want_panel_gpio = false;
966 struct pinctrl *pinctrl;
969 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
970 mipi_config->pwm_blc == PPS_BLC_PMIC) {
971 gpiod_add_lookup_table(&pmic_panel_gpio_table);
972 want_panel_gpio = true;
975 if (IS_VALLEYVIEW(dev_priv) && mipi_config->pwm_blc == PPS_BLC_SOC) {
976 gpiod_add_lookup_table(&soc_panel_gpio_table);
977 want_panel_gpio = true;
978 want_backlight_gpio = true;
980 /* Ensure PWM0 pin is muxed as PWM instead of GPIO */
981 ret = pinctrl_register_mappings(soc_pwm_pinctrl_map,
982 ARRAY_SIZE(soc_pwm_pinctrl_map));
984 drm_err(&dev_priv->drm,
985 "Failed to register pwm0 pinmux mapping\n");
987 pinctrl = devm_pinctrl_get_select(dev->dev, "soc_pwm0");
989 drm_err(&dev_priv->drm,
990 "Failed to set pinmux to PWM\n");
993 if (want_panel_gpio) {
994 intel_dsi->gpio_panel = gpiod_get(dev->dev, "panel", flags);
995 if (IS_ERR(intel_dsi->gpio_panel)) {
996 drm_err(&dev_priv->drm,
997 "Failed to own gpio for panel control\n");
998 intel_dsi->gpio_panel = NULL;
1002 if (want_backlight_gpio) {
1003 intel_dsi->gpio_backlight =
1004 gpiod_get(dev->dev, "backlight", flags);
1005 if (IS_ERR(intel_dsi->gpio_backlight)) {
1006 drm_err(&dev_priv->drm,
1007 "Failed to own gpio for backlight control\n");
1008 intel_dsi->gpio_backlight = NULL;
1013 void intel_dsi_vbt_gpio_cleanup(struct intel_dsi *intel_dsi)
1015 struct drm_device *dev = intel_dsi->base.base.dev;
1016 struct drm_i915_private *dev_priv = to_i915(dev);
1017 struct intel_connector *connector = intel_dsi->attached_connector;
1018 struct mipi_config *mipi_config = connector->panel.vbt.dsi.config;
1020 if (intel_dsi->gpio_panel) {
1021 gpiod_put(intel_dsi->gpio_panel);
1022 intel_dsi->gpio_panel = NULL;
1025 if (intel_dsi->gpio_backlight) {
1026 gpiod_put(intel_dsi->gpio_backlight);
1027 intel_dsi->gpio_backlight = NULL;
1030 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1031 mipi_config->pwm_blc == PPS_BLC_PMIC)
1032 gpiod_remove_lookup_table(&pmic_panel_gpio_table);
1034 if (IS_VALLEYVIEW(dev_priv) && mipi_config->pwm_blc == PPS_BLC_SOC) {
1035 pinctrl_unregister_mappings(soc_pwm_pinctrl_map);
1036 gpiod_remove_lookup_table(&soc_panel_gpio_table);