intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Mika Kahola <mika.kahola@intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: Deepak M <m.deepak@intel.com>,
	Jani Nikula <jani.nikula@intel.com>,
	vkorjani <vikas.korjani@intel.com>
Subject: [PATCH CI run 3/3] drm/i915: Adding the parsing logic for the i2c element
Date: Fri, 18 Nov 2016 09:46:41 +0200	[thread overview]
Message-ID: <1479455201-27917-4-git-send-email-mika.kahola@intel.com> (raw)
In-Reply-To: <1479455201-27917-1-git-send-email-mika.kahola@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.

v8: by Mika
 - rebase

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>
Signed-off-by: Mika Kahola <mika.kahola@intel.com>
---
 drivers/gpu/drm/i915/intel_dsi_panel_vbt.c | 78 +++++++++++++++++++++++++++++-
 1 file changed, 76 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c b/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c
index a4cbe68..7fe57c2 100644
--- a/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c
+++ b/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c
@@ -1004,9 +1004,83 @@ static const u8 *mipi_exec_gpio(struct intel_dsi *intel_dsi, const u8 *data)
 
 static const u8 *mipi_exec_i2c(struct intel_dsi *intel_dsi, const u8 *data)
 {
-	DRM_DEBUG_KMS("Skipping I2C element execution\n");
+	struct drm_i915_private *dev_priv = intel_dsi->base.base.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--;
 
-	return data + *(data + 6) + 7;
+	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;
 }
 
 static const u8 *mipi_exec_spi(struct intel_dsi *intel_dsi, const u8 *data)
-- 
2.7.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2016-11-18  7:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-18  7:46 [PATCH CI run 0/3] MIPI/DSI display support for APL Mika Kahola
2016-11-18  7:46 ` [PATCH CI run 1/3] drm/i915/bxt: add bxt dsi gpio element support Mika Kahola
2016-11-18  7:46 ` [PATCH CI run 2/3] drm/i915: Get the i2c bus number from the ACPI Mika Kahola
2016-11-18  7:46 ` Mika Kahola [this message]
2016-11-18  8:48 ` ✓ Fi.CI.BAT: success for MIPI/DSI display support for APL Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1479455201-27917-4-git-send-email-mika.kahola@intel.com \
    --to=mika.kahola@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@intel.com \
    --cc=m.deepak@intel.com \
    --cc=vikas.korjani@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).