[2/2] drm/i915: Adding the parsing logic for the i2c element

Submitted by Deepak M on March 11, 2016, 10:25 a.m.

Details

Message ID 1457691925-10655-2-git-send-email-m.deepak@intel.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Intel GFX

Not browsing as part of any series.

Commit Message

Deepak M March 11, 2016, 10:25 a.m.
From: vkorjani <vikas.korjani@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

v4 by Jani:
 - don't put the adapter if get fails
 - print an error message if all retries exhausted
 - use a for loop
 - fix warnings for unused variables

v5 by Jani:
 - rebase on the skip i2c element patch

v6: by Jani:
 - ignore the gmbus i2c elements (Ville)

v7: by Deepak
 - Use the i2c port number which is read from ACPI
   based on the resource id.

Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: vkorjani <vikas.korjani@intel.com>
Signed-off-by: Deepak M <m.deepak@intel.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 drivers/gpu/drm/i915/intel_dsi_panel_vbt.c | 84 ++++++++++++++++++++++++++++--
 1 file changed, 81 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c b/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c
index 7f145b4..5a7690d 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"
@@ -249,9 +250,86 @@  out:
 	return data;
 }
 
-static const u8 *mipi_exec_i2c_skip(struct intel_dsi *intel_dsi, const u8 *data)
+static const u8 *mipi_exec_i2c(struct intel_dsi *intel_dsi, const u8 *data)
 {
-	return data + *(data + 6) + 7;
+	struct drm_device *dev = intel_dsi->base.base.dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct i2c_adapter *adapter;
+	int ret, i;
+	u8 reg_offset, payload_size;
+	struct i2c_msg msg;
+	struct acpi_i2c_data_node *i2c_entry = NULL;
+	u8 *transmit_buffer;
+	u8 flag, resource_id, bus_number;
+	u16 slave_add;
+	u8 count = 0;
+
+	flag = *data++;
+	resource_id = *data++;
+	bus_number = *data++;
+	slave_add = *(u16 *)(data);
+	data += 2;
+	reg_offset = *data++;
+	payload_size = *data++;
+
+	if (resource_id == 0xff || bus_number == 0xff) {
+		DRM_DEBUG_KMS("ignoring gmbus (resource id %02x, bus %02x)\n",
+			      resource_id, bus_number);
+		goto out;
+	}
+
+	/* Parse the list and get the required i2c bus number */
+	list_for_each_entry(i2c_entry, &dev_priv->acpi_i2c_list,
+				head) {
+		if (count == resource_id) {
+			/* override the busnumber */
+			bus_number = i2c_entry->i2c_bus_number;
+			break;
+		}
+		count++;
+	}
+
+	/*
+	 * Since the i2c bus number indexing in BIOS starts from 1
+	 * decrementing the bus number which we are reading.
+	 */
+	bus_number--;
+
+	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_put;
+
+	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];
+
+	for (i = 0; i < 6; i++) {
+		ret = i2c_transfer(adapter, &msg, 1);
+		if (ret == 1)
+			goto out_free;
+		else if (ret == -EAGAIN) {
+			usleep_range(1000, 2500);
+		else
+			break;
+	}
+
+	DRM_ERROR("i2c transfer failed: %d\n", ret);
+out_free:
+	kfree(transmit_buffer);
+out_put:
+	i2c_put_adapter(adapter);
+out:
+	return data + payload_size;
 }
 
 typedef const u8 * (*fn_mipi_elem_exec)(struct intel_dsi *intel_dsi,
@@ -260,7 +338,7 @@  static const fn_mipi_elem_exec exec_elem[] = {
 	[MIPI_SEQ_ELEM_SEND_PKT] = mipi_exec_send_packet,
 	[MIPI_SEQ_ELEM_DELAY] = mipi_exec_delay,
 	[MIPI_SEQ_ELEM_GPIO] = mipi_exec_gpio,
-	[MIPI_SEQ_ELEM_I2C] = mipi_exec_i2c_skip,
+	[MIPI_SEQ_ELEM_I2C] = mipi_exec_i2c,
 };
 
 /*

Comments

Hi vkorjani,

[auto build test ERROR on drm-intel/for-linux-next]
[also build test ERROR on next-20160311]
[cannot apply to v4.5-rc7]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Deepak-M/drm-i915-Get-the-i2c-bus-number-from-the-ACPI/20160311-182912
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: i386-defconfig (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   drivers/gpu/drm/i915/intel_dsi_panel_vbt.c: In function 'mipi_exec_i2c':
>> drivers/gpu/drm/i915/intel_dsi_panel_vbt.c:322:3: error: expected '}' before 'else'
      else
      ^

vim +322 drivers/gpu/drm/i915/intel_dsi_panel_vbt.c

   316		for (i = 0; i < 6; i++) {
   317			ret = i2c_transfer(adapter, &msg, 1);
   318			if (ret == 1)
   319				goto out_free;
   320			else if (ret == -EAGAIN) {
   321				usleep_range(1000, 2500);
 > 322			else
   323				break;
   324		}
   325	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation