[Intel-gfx] [MIPI SEQ PARSING v3 01/13] drm/i915: Adding the parsing logic for the i2c element
Deepak M
m.deepak at intel.com
Mon Nov 30 14:47:04 PST 2015
From: vkorjani <vikas.korjani at intel.com>
New sequence element for i2c is been added in the
mipi sequence block of the VBT. This patch parses
and executes the i2c sequence.
v2: Add i2c_put_adapter call(Jani), rebase
v3: corrected the retry loop(Jani), rebase
Cc: Jani Nikula <jani.nikula at intel.com>
Signed-off-by: vkorjani <vikas.korjani at intel.com>
Signed-off-by: Deepak M <m.deepak at intel.com>
---
drivers/gpu/drm/i915/intel_bios.c | 6 +++
drivers/gpu/drm/i915/intel_bios.h | 1 +
drivers/gpu/drm/i915/intel_dsi_panel_vbt.c | 60 ++++++++++++++++++++++++++++++
3 files changed, 67 insertions(+)
diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
index ce82f9c..6756a1c 100644
--- a/drivers/gpu/drm/i915/intel_bios.c
+++ b/drivers/gpu/drm/i915/intel_bios.c
@@ -718,6 +718,12 @@ static u8 *goto_next_sequence(u8 *data, int *size)
data += 3;
break;
+ case MIPI_SEQ_ELEM_I2C:
+ /* skip by this element payload size */
+ data += 7;
+ len = *data;
+ data += len + 1;
+ break;
default:
DRM_ERROR("Unknown element\n");
return NULL;
diff --git a/drivers/gpu/drm/i915/intel_bios.h b/drivers/gpu/drm/i915/intel_bios.h
index 7ec8c9a..4ec73f5 100644
--- a/drivers/gpu/drm/i915/intel_bios.h
+++ b/drivers/gpu/drm/i915/intel_bios.h
@@ -954,6 +954,7 @@ enum mipi_seq_element {
MIPI_SEQ_ELEM_SEND_PKT,
MIPI_SEQ_ELEM_DELAY,
MIPI_SEQ_ELEM_GPIO,
+ MIPI_SEQ_ELEM_I2C,
MIPI_SEQ_ELEM_STATUS,
MIPI_SEQ_ELEM_MAX
};
diff --git a/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c b/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c
index a5e99ac..92d619a 100644
--- a/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c
+++ b/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c
@@ -31,6 +31,7 @@
#include <drm/drm_panel.h>
#include <linux/slab.h>
#include <video/mipi_display.h>
+#include <linux/i2c.h>
#include <asm/intel-mid.h>
#include <video/mipi_display.h>
#include "i915_drv.h"
@@ -104,6 +105,64 @@ static struct gpio_table gtable[] = {
{ GPIO_NC_11_PCONF0, GPIO_NC_11_PAD, 0}
};
+static const u8 *mipi_exec_i2c(struct intel_dsi *intel_dsi, const u8 *data)
+{
+ struct i2c_adapter *adapter;
+ int ret;
+ u8 reg_offset, payload_size, retries = 5;
+ struct i2c_msg msg;
+ u8 *transmit_buffer = NULL;
+ u8 flag = *data++;
+ u8 index = *data++;
+ u8 bus_number = *data++;
+ u16 slave_add = *(u16 *)(data);
+
+ data = data + 2;
+ reg_offset = *data++;
+ payload_size = *data++;
+
+ adapter = i2c_get_adapter(bus_number);
+
+ if (!adapter) {
+ DRM_ERROR("i2c_get_adapter(%u)\n", bus_number);
+ goto out;
+ }
+
+ transmit_buffer = kmalloc(1 + payload_size, GFP_TEMPORARY);
+
+ if (!transmit_buffer)
+ goto out;
+
+ transmit_buffer[0] = reg_offset;
+ memcpy(&transmit_buffer[1], data, payload_size);
+
+ msg.addr = slave_add;
+ msg.flags = 0;
+ msg.len = payload_size + 1;
+ msg.buf = &transmit_buffer[0];
+
+ do {
+ ret = i2c_transfer(adapter, &msg, 1);
+ if (ret == 1)
+ goto out;
+ else if (ret == -EAGAIN)
+ usleep_range(1000, 2500);
+ else {
+ DRM_ERROR("i2c transfer failed, error code:%d\n", ret);
+ goto out;
+ }
+ } while (retries--);
+
+ if (retries == 0)
+ DRM_ERROR("i2c transfer failed, error code:%d\n", ret);
+out:
+ kfree(transmit_buffer);
+ i2c_put_adapter(adapter);
+
+ data = data + payload_size;
+ return data;
+}
+
static inline enum port intel_dsi_seq_port_to_port(u8 port)
{
return port ? PORT_C : PORT_A;
@@ -236,6 +295,7 @@ static const fn_mipi_elem_exec exec_elem[] = {
mipi_exec_send_packet,
mipi_exec_delay,
mipi_exec_gpio,
+ mipi_exec_i2c,
NULL, /* status read; later */
};
--
1.9.1
More information about the Intel-gfx
mailing list