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>
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 struct i2c_adapter_lookup {
60 struct intel_dsi *intel_dsi;
61 acpi_handle dev_handle;
64 #define CHV_GPIO_IDX_START_N 0
65 #define CHV_GPIO_IDX_START_E 73
66 #define CHV_GPIO_IDX_START_SW 100
67 #define CHV_GPIO_IDX_START_SE 198
69 /* ICL DSI Display GPIO Pins */
70 #define ICL_GPIO_DDSP_HPD_A 0
71 #define ICL_GPIO_L_VDDEN_1 1
72 #define ICL_GPIO_L_BKLTEN_1 2
73 #define ICL_GPIO_DDPA_CTRLCLK_1 3
74 #define ICL_GPIO_DDPA_CTRLDATA_1 4
75 #define ICL_GPIO_DDSP_HPD_B 5
76 #define ICL_GPIO_L_VDDEN_2 6
77 #define ICL_GPIO_L_BKLTEN_2 7
78 #define ICL_GPIO_DDPA_CTRLCLK_2 8
79 #define ICL_GPIO_DDPA_CTRLDATA_2 9
81 static enum port intel_dsi_seq_port_to_port(struct intel_dsi *intel_dsi,
85 * If single link DSI is being used on any port, the VBT sequence block
86 * send packet apparently always has 0 for the port. Just use the port
87 * we have configured, and ignore the sequence block port.
89 if (hweight8(intel_dsi->ports) == 1)
90 return ffs(intel_dsi->ports) - 1;
93 if (intel_dsi->ports & BIT(PORT_B))
95 if (intel_dsi->ports & BIT(PORT_C))
102 static const u8 *mipi_exec_send_packet(struct intel_dsi *intel_dsi,
105 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
106 struct mipi_dsi_device *dsi_device;
107 u8 type, flags, seq_port;
111 drm_dbg_kms(&dev_priv->drm, "\n");
116 len = *((u16 *) data);
119 seq_port = (flags >> MIPI_PORT_SHIFT) & 3;
121 port = intel_dsi_seq_port_to_port(intel_dsi, seq_port);
123 if (drm_WARN_ON(&dev_priv->drm, !intel_dsi->dsi_hosts[port]))
126 dsi_device = intel_dsi->dsi_hosts[port]->device;
128 drm_dbg_kms(&dev_priv->drm, "no dsi device for port %c\n",
133 if ((flags >> MIPI_TRANSFER_MODE_SHIFT) & 1)
134 dsi_device->mode_flags &= ~MIPI_DSI_MODE_LPM;
136 dsi_device->mode_flags |= MIPI_DSI_MODE_LPM;
138 dsi_device->channel = (flags >> MIPI_VIRTUAL_CHANNEL_SHIFT) & 3;
141 case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
142 mipi_dsi_generic_write(dsi_device, NULL, 0);
144 case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
145 mipi_dsi_generic_write(dsi_device, data, 1);
147 case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
148 mipi_dsi_generic_write(dsi_device, data, 2);
150 case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
151 case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
152 case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
153 drm_dbg(&dev_priv->drm,
154 "Generic Read not yet implemented or used\n");
156 case MIPI_DSI_GENERIC_LONG_WRITE:
157 mipi_dsi_generic_write(dsi_device, data, len);
159 case MIPI_DSI_DCS_SHORT_WRITE:
160 mipi_dsi_dcs_write_buffer(dsi_device, data, 1);
162 case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
163 mipi_dsi_dcs_write_buffer(dsi_device, data, 2);
165 case MIPI_DSI_DCS_READ:
166 drm_dbg(&dev_priv->drm,
167 "DCS Read not yet implemented or used\n");
169 case MIPI_DSI_DCS_LONG_WRITE:
170 mipi_dsi_dcs_write_buffer(dsi_device, data, len);
174 if (DISPLAY_VER(dev_priv) < 11)
175 vlv_dsi_wait_for_fifo_empty(intel_dsi, port);
183 static const u8 *mipi_exec_delay(struct intel_dsi *intel_dsi, const u8 *data)
185 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev);
186 u32 delay = *((const u32 *) data);
188 drm_dbg_kms(&i915->drm, "%d usecs\n", delay);
190 usleep_range(delay, delay + 10);
196 static void soc_gpio_set_value(struct intel_connector *connector, u8 gpio_index,
197 const char *con_id, u8 idx, bool value)
199 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
200 /* XXX: this table is a quick ugly hack. */
201 static struct gpio_desc *soc_gpio_table[U8_MAX + 1];
202 struct gpio_desc *gpio_desc = soc_gpio_table[gpio_index];
205 gpiod_set_value(gpio_desc, value);
207 gpio_desc = devm_gpiod_get_index(dev_priv->drm.dev, con_id, idx,
208 value ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW);
209 if (IS_ERR(gpio_desc)) {
210 drm_err(&dev_priv->drm,
211 "GPIO index %u request failed (%pe)\n",
212 gpio_index, gpio_desc);
216 soc_gpio_table[gpio_index] = gpio_desc;
220 static void soc_opaque_gpio_set_value(struct intel_connector *connector,
221 u8 gpio_index, const char *chip,
222 const char *con_id, u8 idx, bool value)
224 struct gpiod_lookup_table *lookup;
226 lookup = kzalloc(struct_size(lookup, table, 2), GFP_KERNEL);
230 lookup->dev_id = "0000:00:02.0";
232 GPIO_LOOKUP_IDX(chip, idx, con_id, idx, GPIO_ACTIVE_HIGH);
234 gpiod_add_lookup_table(lookup);
236 soc_gpio_set_value(connector, gpio_index, con_id, idx, value);
238 gpiod_remove_lookup_table(lookup);
242 static void vlv_gpio_set_value(struct intel_connector *connector,
243 u8 gpio_source, u8 gpio_index, bool value)
245 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
247 /* XXX: this assumes vlv_gpio_table only has NC GPIOs. */
248 if (connector->panel.vbt.dsi.seq_version < 3) {
249 if (gpio_source == 1) {
250 drm_dbg_kms(&dev_priv->drm, "SC gpio not supported\n");
253 if (gpio_source > 1) {
254 drm_dbg_kms(&dev_priv->drm,
255 "unknown gpio source %u\n", gpio_source);
260 soc_opaque_gpio_set_value(connector, gpio_index,
261 "INT33FC:01", "Panel N", gpio_index, value);
264 static void chv_gpio_set_value(struct intel_connector *connector,
265 u8 gpio_source, u8 gpio_index, bool value)
267 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
269 if (connector->panel.vbt.dsi.seq_version >= 3) {
270 if (gpio_index >= CHV_GPIO_IDX_START_SE) {
271 /* XXX: it's unclear whether 255->57 is part of SE. */
272 soc_opaque_gpio_set_value(connector, gpio_index, "INT33FF:03", "Panel SE",
273 gpio_index - CHV_GPIO_IDX_START_SE, value);
274 } else if (gpio_index >= CHV_GPIO_IDX_START_SW) {
275 soc_opaque_gpio_set_value(connector, gpio_index, "INT33FF:00", "Panel SW",
276 gpio_index - CHV_GPIO_IDX_START_SW, value);
277 } else if (gpio_index >= CHV_GPIO_IDX_START_E) {
278 soc_opaque_gpio_set_value(connector, gpio_index, "INT33FF:02", "Panel E",
279 gpio_index - CHV_GPIO_IDX_START_E, value);
281 soc_opaque_gpio_set_value(connector, gpio_index, "INT33FF:01", "Panel N",
282 gpio_index - CHV_GPIO_IDX_START_N, value);
285 /* XXX: The spec is unclear about CHV GPIO on seq v2 */
286 if (gpio_source != 0) {
287 drm_dbg_kms(&dev_priv->drm,
288 "unknown gpio source %u\n", gpio_source);
292 if (gpio_index >= CHV_GPIO_IDX_START_E) {
293 drm_dbg_kms(&dev_priv->drm,
294 "invalid gpio index %u for GPIO N\n",
299 soc_opaque_gpio_set_value(connector, gpio_index, "INT33FF:01", "Panel N",
300 gpio_index - CHV_GPIO_IDX_START_N, value);
304 static void bxt_gpio_set_value(struct intel_connector *connector,
305 u8 gpio_index, bool value)
307 soc_gpio_set_value(connector, gpio_index, NULL, gpio_index, value);
323 static void icl_native_gpio_set_value(struct drm_i915_private *dev_priv,
324 int gpio, bool value)
328 if (drm_WARN_ON(&dev_priv->drm, DISPLAY_VER(dev_priv) == 11 && gpio >= MIPI_RESET_2))
334 index = gpio == MIPI_RESET_1 ? HPD_PORT_A : HPD_PORT_B;
337 * Disable HPD to set the pin to output, and set output
338 * value. The HPD pin should not be enabled for DSI anyway,
339 * assuming the board design and VBT are sane, and the pin isn't
340 * used by a non-DSI encoder.
342 * The locking protects against concurrent SHOTPLUG_CTL_DDI
343 * modifications in irq setup and handling.
345 spin_lock_irq(&dev_priv->irq_lock);
346 intel_de_rmw(dev_priv, SHOTPLUG_CTL_DDI,
347 SHOTPLUG_CTL_DDI_HPD_ENABLE(index) |
348 SHOTPLUG_CTL_DDI_HPD_OUTPUT_DATA(index),
349 value ? SHOTPLUG_CTL_DDI_HPD_OUTPUT_DATA(index) : 0);
350 spin_unlock_irq(&dev_priv->irq_lock);
354 index = gpio == MIPI_AVDD_EN_1 ? 0 : 1;
356 intel_de_rmw(dev_priv, PP_CONTROL(index), PANEL_POWER_ON,
357 value ? PANEL_POWER_ON : 0);
361 index = gpio == MIPI_BKLT_EN_1 ? 0 : 1;
363 intel_de_rmw(dev_priv, PP_CONTROL(index), EDP_BLC_ENABLE,
364 value ? EDP_BLC_ENABLE : 0);
368 index = gpio == MIPI_AVEE_EN_1 ? 1 : 2;
370 intel_de_rmw(dev_priv, GPIO(dev_priv, index),
372 GPIO_CLOCK_DIR_MASK | GPIO_CLOCK_DIR_OUT |
373 GPIO_CLOCK_VAL_MASK | (value ? GPIO_CLOCK_VAL_OUT : 0));
377 index = gpio == MIPI_VIO_EN_1 ? 1 : 2;
379 intel_de_rmw(dev_priv, GPIO(dev_priv, index),
381 GPIO_DATA_DIR_MASK | GPIO_DATA_DIR_OUT |
382 GPIO_DATA_VAL_MASK | (value ? GPIO_DATA_VAL_OUT : 0));
389 static const u8 *mipi_exec_gpio(struct intel_dsi *intel_dsi, const u8 *data)
391 struct drm_device *dev = intel_dsi->base.base.dev;
392 struct drm_i915_private *i915 = to_i915(dev);
393 struct intel_connector *connector = intel_dsi->attached_connector;
394 u8 gpio_source = 0, gpio_index = 0, gpio_number;
397 bool native = DISPLAY_VER(i915) >= 11;
399 if (connector->panel.vbt.dsi.seq_version >= 3) {
402 gpio_index = data[0];
403 gpio_number = data[1];
404 value = data[2] & BIT(0);
406 if (connector->panel.vbt.dsi.seq_version >= 4 && data[2] & BIT(1))
411 gpio_number = data[0];
412 value = data[1] & BIT(0);
414 if (connector->panel.vbt.dsi.seq_version == 2)
415 gpio_source = (data[1] >> 1) & 3;
418 drm_dbg_kms(&i915->drm, "GPIO index %u, number %u, source %u, native %s, set to %s\n",
419 gpio_index, gpio_number, gpio_source, str_yes_no(native), str_on_off(value));
422 icl_native_gpio_set_value(i915, gpio_number, value);
423 else if (DISPLAY_VER(i915) >= 9)
424 bxt_gpio_set_value(connector, gpio_index, value);
425 else if (IS_VALLEYVIEW(i915))
426 vlv_gpio_set_value(connector, gpio_source, gpio_number, value);
427 else if (IS_CHERRYVIEW(i915))
428 chv_gpio_set_value(connector, gpio_source, gpio_number, value);
434 static int i2c_adapter_lookup(struct acpi_resource *ares, void *data)
436 struct i2c_adapter_lookup *lookup = data;
437 struct intel_dsi *intel_dsi = lookup->intel_dsi;
438 struct acpi_resource_i2c_serialbus *sb;
439 struct i2c_adapter *adapter;
440 acpi_handle adapter_handle;
443 if (!i2c_acpi_get_i2c_resource(ares, &sb))
446 if (lookup->slave_addr != sb->slave_address)
449 status = acpi_get_handle(lookup->dev_handle,
450 sb->resource_source.string_ptr,
452 if (ACPI_FAILURE(status))
455 adapter = i2c_acpi_find_adapter_by_handle(adapter_handle);
457 intel_dsi->i2c_bus_num = adapter->nr;
462 static void i2c_acpi_find_adapter(struct intel_dsi *intel_dsi,
463 const u16 slave_addr)
465 struct drm_device *drm_dev = intel_dsi->base.base.dev;
466 struct acpi_device *adev = ACPI_COMPANION(drm_dev->dev);
467 struct i2c_adapter_lookup lookup = {
468 .slave_addr = slave_addr,
469 .intel_dsi = intel_dsi,
470 .dev_handle = acpi_device_handle(adev),
472 LIST_HEAD(resource_list);
474 acpi_dev_get_resources(adev, &resource_list, i2c_adapter_lookup, &lookup);
475 acpi_dev_free_resource_list(&resource_list);
478 static inline void i2c_acpi_find_adapter(struct intel_dsi *intel_dsi,
479 const u16 slave_addr)
484 static const u8 *mipi_exec_i2c(struct intel_dsi *intel_dsi, const u8 *data)
486 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev);
487 struct i2c_adapter *adapter;
490 u8 vbt_i2c_bus_num = *(data + 2);
491 u16 slave_addr = *(u16 *)(data + 3);
492 u8 reg_offset = *(data + 5);
493 u8 payload_size = *(data + 6);
496 drm_dbg_kms(&i915->drm, "bus %d client-addr 0x%02x reg 0x%02x data %*ph\n",
497 vbt_i2c_bus_num, slave_addr, reg_offset, payload_size, data + 7);
499 if (intel_dsi->i2c_bus_num < 0) {
500 intel_dsi->i2c_bus_num = vbt_i2c_bus_num;
501 i2c_acpi_find_adapter(intel_dsi, slave_addr);
504 adapter = i2c_get_adapter(intel_dsi->i2c_bus_num);
506 drm_err(&i915->drm, "Cannot find a valid i2c bus for xfer\n");
510 payload_data = kzalloc(payload_size + 1, GFP_KERNEL);
514 payload_data[0] = reg_offset;
515 memcpy(&payload_data[1], (data + 7), payload_size);
517 msg.addr = slave_addr;
519 msg.len = payload_size + 1;
520 msg.buf = payload_data;
522 ret = i2c_transfer(adapter, &msg, 1);
525 "Failed to xfer payload of size (%u) to reg (%u)\n",
526 payload_size, reg_offset);
530 i2c_put_adapter(adapter);
532 return data + payload_size + 7;
535 static const u8 *mipi_exec_spi(struct intel_dsi *intel_dsi, const u8 *data)
537 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev);
539 drm_dbg_kms(&i915->drm, "Skipping SPI element execution\n");
541 return data + *(data + 5) + 6;
544 static const u8 *mipi_exec_pmic(struct intel_dsi *intel_dsi, const u8 *data)
546 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev);
547 #ifdef CONFIG_PMIC_OPREGION
548 u32 value, mask, reg_address;
552 /* byte 0 aka PMIC Flag is reserved */
553 i2c_address = get_unaligned_le16(data + 1);
554 reg_address = get_unaligned_le32(data + 3);
555 value = get_unaligned_le32(data + 7);
556 mask = get_unaligned_le32(data + 11);
558 ret = intel_soc_pmic_exec_mipi_pmic_seq_element(i2c_address,
562 drm_err(&i915->drm, "%s failed, error: %d\n", __func__, ret);
565 "Your hardware requires CONFIG_PMIC_OPREGION and it is not set\n");
571 typedef const u8 * (*fn_mipi_elem_exec)(struct intel_dsi *intel_dsi,
573 static const fn_mipi_elem_exec exec_elem[] = {
574 [MIPI_SEQ_ELEM_SEND_PKT] = mipi_exec_send_packet,
575 [MIPI_SEQ_ELEM_DELAY] = mipi_exec_delay,
576 [MIPI_SEQ_ELEM_GPIO] = mipi_exec_gpio,
577 [MIPI_SEQ_ELEM_I2C] = mipi_exec_i2c,
578 [MIPI_SEQ_ELEM_SPI] = mipi_exec_spi,
579 [MIPI_SEQ_ELEM_PMIC] = mipi_exec_pmic,
583 * MIPI Sequence from VBT #53 parsing logic
584 * We have already separated each seqence during bios parsing
585 * Following is generic execution function for any sequence
588 static const char * const seq_name[] = {
589 [MIPI_SEQ_END] = "MIPI_SEQ_END",
590 [MIPI_SEQ_DEASSERT_RESET] = "MIPI_SEQ_DEASSERT_RESET",
591 [MIPI_SEQ_INIT_OTP] = "MIPI_SEQ_INIT_OTP",
592 [MIPI_SEQ_DISPLAY_ON] = "MIPI_SEQ_DISPLAY_ON",
593 [MIPI_SEQ_DISPLAY_OFF] = "MIPI_SEQ_DISPLAY_OFF",
594 [MIPI_SEQ_ASSERT_RESET] = "MIPI_SEQ_ASSERT_RESET",
595 [MIPI_SEQ_BACKLIGHT_ON] = "MIPI_SEQ_BACKLIGHT_ON",
596 [MIPI_SEQ_BACKLIGHT_OFF] = "MIPI_SEQ_BACKLIGHT_OFF",
597 [MIPI_SEQ_TEAR_ON] = "MIPI_SEQ_TEAR_ON",
598 [MIPI_SEQ_TEAR_OFF] = "MIPI_SEQ_TEAR_OFF",
599 [MIPI_SEQ_POWER_ON] = "MIPI_SEQ_POWER_ON",
600 [MIPI_SEQ_POWER_OFF] = "MIPI_SEQ_POWER_OFF",
603 static const char *sequence_name(enum mipi_seq seq_id)
605 if (seq_id < ARRAY_SIZE(seq_name))
606 return seq_name[seq_id];
611 static void intel_dsi_vbt_exec(struct intel_dsi *intel_dsi,
612 enum mipi_seq seq_id)
614 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev);
615 struct intel_connector *connector = intel_dsi->attached_connector;
617 fn_mipi_elem_exec mipi_elem_exec;
619 if (drm_WARN_ON(&dev_priv->drm,
620 seq_id >= ARRAY_SIZE(connector->panel.vbt.dsi.sequence)))
623 data = connector->panel.vbt.dsi.sequence[seq_id];
627 drm_WARN_ON(&dev_priv->drm, *data != seq_id);
629 drm_dbg_kms(&dev_priv->drm, "Starting MIPI sequence %d - %s\n",
630 seq_id, sequence_name(seq_id));
632 /* Skip Sequence Byte. */
635 /* Skip Size of Sequence. */
636 if (connector->panel.vbt.dsi.seq_version >= 3)
639 while (*data != MIPI_SEQ_ELEM_END) {
640 u8 operation_byte = *data++;
641 u8 operation_size = 0;
643 if (operation_byte < ARRAY_SIZE(exec_elem))
644 mipi_elem_exec = exec_elem[operation_byte];
646 mipi_elem_exec = NULL;
648 /* Size of Operation. */
649 if (connector->panel.vbt.dsi.seq_version >= 3)
650 operation_size = *data++;
652 if (mipi_elem_exec) {
653 const u8 *next = data + operation_size;
655 data = mipi_elem_exec(intel_dsi, data);
657 /* Consistency check if we have size. */
658 if (operation_size && data != next) {
659 drm_err(&dev_priv->drm,
660 "Inconsistent operation size\n");
663 } else if (operation_size) {
664 /* We have size, skip. */
665 drm_dbg_kms(&dev_priv->drm,
666 "Unsupported MIPI operation byte %u\n",
668 data += operation_size;
670 /* No size, can't skip without parsing. */
671 drm_err(&dev_priv->drm,
672 "Unsupported MIPI operation byte %u\n",
679 void intel_dsi_vbt_exec_sequence(struct intel_dsi *intel_dsi,
680 enum mipi_seq seq_id)
682 if (seq_id == MIPI_SEQ_POWER_ON && intel_dsi->gpio_panel)
683 gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1);
684 if (seq_id == MIPI_SEQ_BACKLIGHT_ON && intel_dsi->gpio_backlight)
685 gpiod_set_value_cansleep(intel_dsi->gpio_backlight, 1);
687 intel_dsi_vbt_exec(intel_dsi, seq_id);
689 if (seq_id == MIPI_SEQ_POWER_OFF && intel_dsi->gpio_panel)
690 gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0);
691 if (seq_id == MIPI_SEQ_BACKLIGHT_OFF && intel_dsi->gpio_backlight)
692 gpiod_set_value_cansleep(intel_dsi->gpio_backlight, 0);
695 void intel_dsi_log_params(struct intel_dsi *intel_dsi)
697 struct drm_i915_private *i915 = to_i915(intel_dsi->base.base.dev);
699 drm_dbg_kms(&i915->drm, "Pclk %d\n", intel_dsi->pclk);
700 drm_dbg_kms(&i915->drm, "Pixel overlap %d\n",
701 intel_dsi->pixel_overlap);
702 drm_dbg_kms(&i915->drm, "Lane count %d\n", intel_dsi->lane_count);
703 drm_dbg_kms(&i915->drm, "DPHY param reg 0x%x\n", intel_dsi->dphy_reg);
704 drm_dbg_kms(&i915->drm, "Video mode format %s\n",
705 intel_dsi->video_mode == NON_BURST_SYNC_PULSE ?
706 "non-burst with sync pulse" :
707 intel_dsi->video_mode == NON_BURST_SYNC_EVENTS ?
708 "non-burst with sync events" :
709 intel_dsi->video_mode == BURST_MODE ?
710 "burst" : "<unknown>");
711 drm_dbg_kms(&i915->drm, "Burst mode ratio %d\n",
712 intel_dsi->burst_mode_ratio);
713 drm_dbg_kms(&i915->drm, "Reset timer %d\n", intel_dsi->rst_timer_val);
714 drm_dbg_kms(&i915->drm, "Eot %s\n",
715 str_enabled_disabled(intel_dsi->eotp_pkt));
716 drm_dbg_kms(&i915->drm, "Clockstop %s\n",
717 str_enabled_disabled(!intel_dsi->clock_stop));
718 drm_dbg_kms(&i915->drm, "Mode %s\n",
719 intel_dsi->operation_mode ? "command" : "video");
720 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK)
721 drm_dbg_kms(&i915->drm,
722 "Dual link: DSI_DUAL_LINK_FRONT_BACK\n");
723 else if (intel_dsi->dual_link == DSI_DUAL_LINK_PIXEL_ALT)
724 drm_dbg_kms(&i915->drm,
725 "Dual link: DSI_DUAL_LINK_PIXEL_ALT\n");
727 drm_dbg_kms(&i915->drm, "Dual link: NONE\n");
728 drm_dbg_kms(&i915->drm, "Pixel Format %d\n", intel_dsi->pixel_format);
729 drm_dbg_kms(&i915->drm, "TLPX %d\n", intel_dsi->escape_clk_div);
730 drm_dbg_kms(&i915->drm, "LP RX Timeout 0x%x\n",
731 intel_dsi->lp_rx_timeout);
732 drm_dbg_kms(&i915->drm, "Turnaround Timeout 0x%x\n",
733 intel_dsi->turn_arnd_val);
734 drm_dbg_kms(&i915->drm, "Init Count 0x%x\n", intel_dsi->init_count);
735 drm_dbg_kms(&i915->drm, "HS to LP Count 0x%x\n",
736 intel_dsi->hs_to_lp_count);
737 drm_dbg_kms(&i915->drm, "LP Byte Clock %d\n", intel_dsi->lp_byte_clk);
738 drm_dbg_kms(&i915->drm, "DBI BW Timer 0x%x\n", intel_dsi->bw_timer);
739 drm_dbg_kms(&i915->drm, "LP to HS Clock Count 0x%x\n",
740 intel_dsi->clk_lp_to_hs_count);
741 drm_dbg_kms(&i915->drm, "HS to LP Clock Count 0x%x\n",
742 intel_dsi->clk_hs_to_lp_count);
743 drm_dbg_kms(&i915->drm, "BTA %s\n",
744 str_enabled_disabled(!(intel_dsi->video_frmt_cfg_bits & DISABLE_VIDEO_BTA)));
747 bool intel_dsi_vbt_init(struct intel_dsi *intel_dsi, u16 panel_id)
749 struct drm_device *dev = intel_dsi->base.base.dev;
750 struct drm_i915_private *dev_priv = to_i915(dev);
751 struct intel_connector *connector = intel_dsi->attached_connector;
752 struct mipi_config *mipi_config = connector->panel.vbt.dsi.config;
753 struct mipi_pps_data *pps = connector->panel.vbt.dsi.pps;
754 struct drm_display_mode *mode = connector->panel.vbt.lfp_lvds_vbt_mode;
755 u16 burst_mode_ratio;
758 drm_dbg_kms(&dev_priv->drm, "\n");
760 intel_dsi->eotp_pkt = mipi_config->eot_pkt_disabled ? 0 : 1;
761 intel_dsi->clock_stop = mipi_config->enable_clk_stop ? 1 : 0;
762 intel_dsi->lane_count = mipi_config->lane_cnt + 1;
763 intel_dsi->pixel_format =
764 pixel_format_from_register_bits(
765 mipi_config->videomode_color_format << 7);
767 intel_dsi->dual_link = mipi_config->dual_link;
768 intel_dsi->pixel_overlap = mipi_config->pixel_overlap;
769 intel_dsi->operation_mode = mipi_config->is_cmd_mode;
770 intel_dsi->video_mode = mipi_config->video_transfer_mode;
771 intel_dsi->escape_clk_div = mipi_config->byte_clk_sel;
772 intel_dsi->lp_rx_timeout = mipi_config->lp_rx_timeout;
773 intel_dsi->hs_tx_timeout = mipi_config->hs_tx_timeout;
774 intel_dsi->turn_arnd_val = mipi_config->turn_around_timeout;
775 intel_dsi->rst_timer_val = mipi_config->device_reset_timer;
776 intel_dsi->init_count = mipi_config->master_init_timer;
777 intel_dsi->bw_timer = mipi_config->dbi_bw_timer;
778 intel_dsi->video_frmt_cfg_bits =
779 mipi_config->bta_enabled ? DISABLE_VIDEO_BTA : 0;
780 intel_dsi->bgr_enabled = mipi_config->rgb_flip;
782 /* Starting point, adjusted depending on dual link and burst mode */
783 intel_dsi->pclk = mode->clock;
785 /* In dual link mode each port needs half of pixel clock */
786 if (intel_dsi->dual_link) {
787 intel_dsi->pclk /= 2;
789 /* we can enable pixel_overlap if needed by panel. In this
790 * case we need to increase the pixelclock for extra pixels
792 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) {
793 intel_dsi->pclk += DIV_ROUND_UP(mode->vtotal * intel_dsi->pixel_overlap * 60, 1000);
798 * Target ddr frequency from VBT / non burst ddr freq
799 * multiply by 100 to preserve remainder
801 if (intel_dsi->video_mode == BURST_MODE) {
804 if (mipi_config->target_burst_mode_freq == 0) {
805 drm_err(&dev_priv->drm, "Burst mode target is not set\n");
809 bitrate = intel_dsi_bitrate(intel_dsi);
812 * Sometimes the VBT contains a slightly lower clock, then
813 * the bitrate we have calculated, in this case just replace it
814 * with the calculated bitrate.
816 if (mipi_config->target_burst_mode_freq < bitrate &&
817 intel_fuzzy_clock_check(mipi_config->target_burst_mode_freq,
819 mipi_config->target_burst_mode_freq = bitrate;
821 if (mipi_config->target_burst_mode_freq < bitrate) {
822 drm_err(&dev_priv->drm, "Burst mode freq is less than computed\n");
827 DIV_ROUND_UP(mipi_config->target_burst_mode_freq * 100, bitrate);
829 intel_dsi->pclk = DIV_ROUND_UP(intel_dsi->pclk * burst_mode_ratio, 100);
831 burst_mode_ratio = 100;
833 intel_dsi->burst_mode_ratio = burst_mode_ratio;
835 /* delays in VBT are in unit of 100us, so need to convert
837 * Delay (100us) * 100 /1000 = Delay / 10 (ms) */
838 intel_dsi->backlight_off_delay = pps->bl_disable_delay / 10;
839 intel_dsi->backlight_on_delay = pps->bl_enable_delay / 10;
840 intel_dsi->panel_on_delay = pps->panel_on_delay / 10;
841 intel_dsi->panel_off_delay = pps->panel_off_delay / 10;
842 intel_dsi->panel_pwr_cycle_delay = pps->panel_power_cycle_delay / 10;
844 intel_dsi->i2c_bus_num = -1;
846 /* a regular driver would get the device in probe */
847 for_each_dsi_port(port, intel_dsi->ports) {
848 mipi_dsi_attach(intel_dsi->dsi_hosts[port]->device);
855 * On some BYT/CHT devs some sequences are incomplete and we need to manually
856 * control some GPIOs. We need to add a GPIO lookup table before we get these.
857 * If the GOP did not initialize the panel (HDMI inserted) we may need to also
858 * change the pinmux for the SoC's PWM0 pin from GPIO to PWM.
860 static struct gpiod_lookup_table pmic_panel_gpio_table = {
861 /* Intel GFX is consumer */
862 .dev_id = "0000:00:02.0",
864 /* Panel EN/DISABLE */
865 GPIO_LOOKUP("gpio_crystalcove", 94, "panel", GPIO_ACTIVE_HIGH),
870 static struct gpiod_lookup_table soc_panel_gpio_table = {
871 .dev_id = "0000:00:02.0",
873 GPIO_LOOKUP("INT33FC:01", 10, "backlight", GPIO_ACTIVE_HIGH),
874 GPIO_LOOKUP("INT33FC:01", 11, "panel", GPIO_ACTIVE_HIGH),
879 static const struct pinctrl_map soc_pwm_pinctrl_map[] = {
880 PIN_MAP_MUX_GROUP("0000:00:02.0", "soc_pwm0", "INT33FC:00",
884 void intel_dsi_vbt_gpio_init(struct intel_dsi *intel_dsi, bool panel_is_on)
886 struct drm_device *dev = intel_dsi->base.base.dev;
887 struct drm_i915_private *dev_priv = to_i915(dev);
888 struct intel_connector *connector = intel_dsi->attached_connector;
889 struct mipi_config *mipi_config = connector->panel.vbt.dsi.config;
890 enum gpiod_flags flags = panel_is_on ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
891 struct gpiod_lookup_table *gpiod_lookup_table = NULL;
892 bool want_backlight_gpio = false;
893 bool want_panel_gpio = false;
894 struct pinctrl *pinctrl;
897 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
898 mipi_config->pwm_blc == PPS_BLC_PMIC) {
899 gpiod_lookup_table = &pmic_panel_gpio_table;
900 want_panel_gpio = true;
903 if (IS_VALLEYVIEW(dev_priv) && mipi_config->pwm_blc == PPS_BLC_SOC) {
904 gpiod_lookup_table = &soc_panel_gpio_table;
905 want_panel_gpio = true;
906 want_backlight_gpio = true;
908 /* Ensure PWM0 pin is muxed as PWM instead of GPIO */
909 ret = pinctrl_register_mappings(soc_pwm_pinctrl_map,
910 ARRAY_SIZE(soc_pwm_pinctrl_map));
912 drm_err(&dev_priv->drm,
913 "Failed to register pwm0 pinmux mapping\n");
915 pinctrl = devm_pinctrl_get_select(dev->dev, "soc_pwm0");
917 drm_err(&dev_priv->drm,
918 "Failed to set pinmux to PWM\n");
921 if (gpiod_lookup_table)
922 gpiod_add_lookup_table(gpiod_lookup_table);
924 if (want_panel_gpio) {
925 intel_dsi->gpio_panel = devm_gpiod_get(dev->dev, "panel", flags);
926 if (IS_ERR(intel_dsi->gpio_panel)) {
927 drm_err(&dev_priv->drm,
928 "Failed to own gpio for panel control\n");
929 intel_dsi->gpio_panel = NULL;
933 if (want_backlight_gpio) {
934 intel_dsi->gpio_backlight =
935 devm_gpiod_get(dev->dev, "backlight", flags);
936 if (IS_ERR(intel_dsi->gpio_backlight)) {
937 drm_err(&dev_priv->drm,
938 "Failed to own gpio for backlight control\n");
939 intel_dsi->gpio_backlight = NULL;
943 if (gpiod_lookup_table)
944 gpiod_remove_lookup_table(gpiod_lookup_table);