diff mbox

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

Message ID 1452519005-17244-1-git-send-email-jani.nikula@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jani Nikula Jan. 11, 2016, 1:30 p.m. UTC
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

Cc: Jani Nikula <jani.nikula@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 | 58 ++++++++++++++++++++++++++++--
 1 file changed, 55 insertions(+), 3 deletions(-)

Comments

Jani Nikula Jan. 11, 2016, 1:32 p.m. UTC | #1
I screwed up something, the authorship for this one should have remained

From: vkorjani <vikas.korjani@intel.com>

Can be fixed while applying, will not resend now.

BR,
Jani.

On Mon, 11 Jan 2016, Jani Nikula <jani.nikula@intel.com> wrote:
> 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
>
> Cc: Jani Nikula <jani.nikula@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 | 58 ++++++++++++++++++++++++++++--
>  1 file changed, 55 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c b/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c
> index 1d43e6f37fc1..213d9ef2d712 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"
> @@ -229,9 +230,60 @@ static const u8 *mipi_exec_gpio(struct intel_dsi *intel_dsi, const u8 *data)
>  	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 i2c_adapter *adapter;
> +	int ret, i;
> +	u8 reg_offset, payload_size;
> +	struct i2c_msg msg;
> +	u8 *transmit_buffer;
> +	u8 flag, bus_number;
> +	u16 slave_add;
> +
> +	flag = *data++;
> +	data++; /* index, unused */
> +	bus_number = *data++;
> +	slave_add = *(u16 *)(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_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,
> @@ -240,7 +292,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,
>  };
>  
>  /*
Jani Nikula Jan. 11, 2016, 5:26 p.m. UTC | #2
Pushed the rest of the series *except* this patch. Thanks for the
review.

BR,
Jani.


On Mon, 11 Jan 2016, Jani Nikula <jani.nikula@intel.com> wrote:
> I screwed up something, the authorship for this one should have remained
>
> From: vkorjani <vikas.korjani@intel.com>
>
> Can be fixed while applying, will not resend now.
>
> BR,
> Jani.
>
> On Mon, 11 Jan 2016, Jani Nikula <jani.nikula@intel.com> wrote:
>> 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
>>
>> Cc: Jani Nikula <jani.nikula@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 | 58 ++++++++++++++++++++++++++++--
>>  1 file changed, 55 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c b/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c
>> index 1d43e6f37fc1..213d9ef2d712 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"
>> @@ -229,9 +230,60 @@ static const u8 *mipi_exec_gpio(struct intel_dsi *intel_dsi, const u8 *data)
>>  	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 i2c_adapter *adapter;
>> +	int ret, i;
>> +	u8 reg_offset, payload_size;
>> +	struct i2c_msg msg;
>> +	u8 *transmit_buffer;
>> +	u8 flag, bus_number;
>> +	u16 slave_add;
>> +
>> +	flag = *data++;
>> +	data++; /* index, unused */
>> +	bus_number = *data++;
>> +	slave_add = *(u16 *)(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_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,
>> @@ -240,7 +292,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,
>>  };
>>  
>>  /*
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c b/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c
index 1d43e6f37fc1..213d9ef2d712 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"
@@ -229,9 +230,60 @@  static const u8 *mipi_exec_gpio(struct intel_dsi *intel_dsi, const u8 *data)
 	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 i2c_adapter *adapter;
+	int ret, i;
+	u8 reg_offset, payload_size;
+	struct i2c_msg msg;
+	u8 *transmit_buffer;
+	u8 flag, bus_number;
+	u16 slave_add;
+
+	flag = *data++;
+	data++; /* index, unused */
+	bus_number = *data++;
+	slave_add = *(u16 *)(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_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,
@@ -240,7 +292,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,
 };
 
 /*