Skip to contentSkip to conversation

drm/i915: Get the i2c bus number from the ACPI

PATCH In review Deepak M 3 participants 6 messages Mar 11, 2016 – Apr 19, 2016

Subsystems (2)
lore
Share & tools
lore
#1 lore raw

✗ Fi.CI.BAT: failure for series starting with [1/2] drm/i915: Get the i2c bus number from the ACPI

In reply to Deepak M
== Series Details ==

== Series Details ==

Series: series starting with [1/2] drm/i915: Get the i2c bus number from the ACPI
URL : https://patchwork.freedesktop.org/series/4348/
State : failure

== Summary ==

  CC [M]  drivers/gpu/drm/i915/intel_dp_link_training.o
  CC [M]  drivers/gpu/drm/i915/intel_dp_mst.o
  CC [M]  drivers/gpu/drm/i915/intel_dp.o
  CC [M]  drivers/gpu/drm/i915/intel_dsi.o
  CC [M]  drivers/gpu/drm/i915/intel_dsi_panel_vbt.o
  CC [M]  drivers/gpu/drm/i915/intel_dsi_pll.o
  CC [M]  drivers/gpu/drm/i915/intel_dvo.o
  CC [M]  drivers/gpu/drm/i915/intel_hdmi.o
  CC [M]  drivers/gpu/drm/i915/intel_i2c.o
  CC [M]  drivers/gpu/drm/i915/intel_lvds.o
  CC [M]  drivers/gpu/drm/i915/intel_panel.o
  CC [M]  drivers/gpu/drm/i915/intel_sdvo.o
  CC [M]  drivers/gpu/drm/i915/intel_tv.o
  CC [M]  drivers/gpu/drm/i915/i915_vgpu.o
  CC [M]  drivers/gpu/drm/i915/i915_dma.o

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
^
scripts/Makefile.build:258: recipe for target 'drivers/gpu/drm/i915/intel_dsi_panel_vbt.o' failed make[4]: *** [drivers/gpu/drm/i915/intel_dsi_panel_vbt.o] Error 1
make[4]: *** Waiting for unfinished jobs....
scripts/Makefile.build:407: recipe for target 'drivers/gpu/drm/i915' failed make[3]: *** [drivers/gpu/drm/i915] Error 2
scripts/Makefile.build:407: recipe for target 'drivers/gpu/drm' failed
make[2]: *** [drivers/gpu/drm] Error 2
scripts/Makefile.build:407: recipe for target 'drivers/gpu' failed
make[1]: *** [drivers/gpu] Error 2
Makefile:950: recipe for target 'drivers' failed
make: *** [drivers] Error 2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Deepak M

author
#0 lore raw

PATCH 1/2 drm/i915: Get the i2c bus number from the ACPI

Currently for executing the i2c MIPI sequence, we are relaying on the i2c bus bunmber which is specified in the VBT. But there are cases where different Fab versions of the board will drive the same chip with different i2c port, in which case the i2c bus number from the VBT cant be relied on. To overcome this the i2c bus number is read from the BIOS acpi table; BIOS can detect the Fab version in runtime and will store the correct i2c bus number in the ACPI table.

v2 by Deepak:
- Reading the i2c from the ACPI and storing them in list

Cc Jani Nikula <[email protected]>
Cc Ville Syrjälä <[email protected]>
---
 drivers/gpu/drm/i915/i915_dma.c   |  2 ++
 drivers/gpu/drm/i915/i915_drv.h   | 11 ++++++++
 drivers/gpu/drm/i915/intel_acpi.c | 59 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
drivers/gpu/drm/i915/i915_dma.c +2 -0
index 4aa3db6..57be99b 100644
@@ -387,6 +387,8 @@ static int i915_load_modeset_init(struct drm_device *dev)
 
 	intel_register_dsm_handler();
 
+	intel_acpi_find_i2c(dev_priv);
+
 	ret = vga_switcheroo_register_client(dev->pdev, &i915_switcheroo_ops, false);
 	if (ret)
 		goto cleanup_vga_client;
drivers/gpu/drm/i915/i915_drv.h +11 -0
index f37ac12..5c6279d 100644
@@ -41,6 +41,7 @@
 #include "intel_lrc.h"
 #include "i915_gem_gtt.h"
 #include "i915_gem_render_state.h"
+#include <linux/acpi.h>
 #include <linux/io-mapping.h>
 #include <linux/i2c.h>
 #include <linux/i2c-algo-bit.h>
@@ -1739,6 +1740,12 @@ struct intel_wm_config {
 	bool sprites_scaled;
 };
 
+struct acpi_i2c_data_node {
+	struct list_head head;
+	int i2c_bus_number;
+	int i2c_slave_address;
+};
+
 struct drm_i915_private {
 	struct drm_device *dev;
 	struct kmem_cache *objects;
@@ -1823,6 +1830,8 @@ struct drm_i915_private {
 	/* backlight registers and fields in struct intel_panel */
 	struct mutex backlight_lock;
 
+	struct list_head acpi_i2c_list;
+
 	/* LVDS info */
 	bool no_aux_handshake;
 
@@ -1892,6 +1901,7 @@ struct drm_i915_private {
 
 	struct i915_workarounds workarounds;
 
+
 	/* Reclocking support */
 	bool render_reclock_avail;
 
@@ -3439,6 +3449,7 @@ intel_opregion_notify_adapter(struct drm_device *dev, pci_power_t state)
 #ifdef CONFIG_ACPI
 extern void intel_register_dsm_handler(void);
 extern void intel_unregister_dsm_handler(void);
+extern acpi_status intel_acpi_find_i2c(struct drm_i915_private *dev_priv);
 #else
 static inline void intel_register_dsm_handler(void) { return; }
 static inline void intel_unregister_dsm_handler(void) { return; }
drivers/gpu/drm/i915/intel_acpi.c +59 -0

65 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#3 lore raw

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

From: vkorjani <[email protected]>

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.

---
 drivers/gpu/drm/i915/intel_dsi_panel_vbt.c | 84 ++++++++++++++++++++++++++++--
 1 file changed, 81 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/intel_dsi_panel_vbt.c +81 -3
index 7f145b4..5a7690d 100644
@@ -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,
 };
 
 /*
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#2 lore raw

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

In reply to Patchwork

From: vkorjani <[email protected]>

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.

---
 drivers/gpu/drm/i915/intel_dsi_panel_vbt.c | 84 ++++++++++++++++++++++++++++--
 1 file changed, 81 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/intel_dsi_panel_vbt.c +81 -3
index 7f145b4..be92cf3 100644
@@ -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,
 };
 
 /*
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

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

In reply to Deepak M
reproduce:

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

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

author
#5 lore raw
In reply to Deepak M

Waiting for review comments.

Quoted 164 lines

-----Original Message-----
From: Deepak, M
Sent: Friday, March 11, 2016 3:55 PM
To: [email protected]
Cc: Deepak, M <[email protected]>; Nikula, Jani <[email protected]>; Ville Syrjälä <[email protected]>
Subject: [PATCH 1/2] drm/i915: Get the i2c bus number from the ACPI

Currently for executing the i2c MIPI sequence, we are relaying on the i2c bus number which is specified in the VBT. But there are cases where different Fab versions of the board will drive the same chip with different i2c port, in which case the i2c bus number from the VBT cant be relied on. To overcome this the i2c bus number is read from the BIOS acpi table; BIOS can detect the Fab version in runtime and will store the correct i2c bus number in the ACPI table.

v2 by Deepak:
- Reading the i2c from the ACPI and storing them in list

Cc Jani Nikula <[email protected]>
Cc Ville Syrjälä <[email protected]>
---
 drivers/gpu/drm/i915/i915_dma.c   |  2 ++
 drivers/gpu/drm/i915/i915_drv.h   | 11 ++++++++
 drivers/gpu/drm/i915/intel_acpi.c | 59
+++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_dma.c index 4aa3db6..57be99b 100644

drivers/gpu/drm/i915/i915_dma.c +2 -0
@@ -387,6 +387,8 @@ static int i915_load_modeset_init(struct drm_device
 *dev)
 
 	intel_register_dsm_handler();
 
+	intel_acpi_find_i2c(dev_priv);
+
 	ret = vga_switcheroo_register_client(dev->pdev,
 &i915_switcheroo_ops, false);
drivers/gpu/drm/i915/i915_dma.c +0 -0
 	if (ret)
 		goto cleanup_vga_client;
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h index f37ac12..5c6279d 100644

drivers/gpu/drm/i915/i915_drv.h +10 -0
@@ -41,6 +41,7 @@
 #include "intel_lrc.h"
 #include "i915_gem_gtt.h"
 #include "i915_gem_render_state.h"
+#include <linux/acpi.h>
 #include <linux/io-mapping.h>
 #include <linux/i2c.h>
 #include <linux/i2c-algo-bit.h>
@@ -1739,6 +1740,12 @@ struct intel_wm_config {
 	bool sprites_scaled;
 };
 
+struct acpi_i2c_data_node {
+	struct list_head head;
+	int i2c_bus_number;
+	int i2c_slave_address;
+};
+
 struct drm_i915_private {
 	struct drm_device *dev;
 	struct kmem_cache *objects;
@@ -1823,6 +1830,8 @@ struct drm_i915_private {
 	/* backlight registers and fields in struct intel_panel */
 	struct mutex backlight_lock;
 
+	struct list_head acpi_i2c_list;
+
 	/* LVDS info */
 	bool no_aux_handshake;
 
@@ -1892,6 +1901,7 @@ struct drm_i915_private {
 
 	struct i915_workarounds workarounds;
 
+
 	/* Reclocking support */
 	bool render_reclock_avail;
 
@@ -3439,6 +3449,7 @@ intel_opregion_notify_adapter(struct drm_device
 *dev, pci_power_t state)  #ifdef CONFIG_ACPI  extern void

intel_register_dsm_handler(void); extern void
intel_unregister_dsm_handler(void);

drivers/gpu/drm/i915/i915_drv.h +2 -0
+extern acpi_status intel_acpi_find_i2c(struct drm_i915_private
+*dev_priv);
 #else
 static inline void intel_register_dsm_handler(void) { return; }  static inline

void intel_unregister_dsm_handler(void) { return; } diff --git a/drivers/gpu/drm/i915/intel_acpi.c b/drivers/gpu/drm/i915/intel_acpi.c index eb638a1..afe42ab 100644

drivers/gpu/drm/i915/intel_acpi.c +57 -1
@@ -110,6 +110,65 @@ static void intel_dsm_platform_mux_info(void)
 	ACPI_FREE(pkg);
 }
 
+static int i2c_acpi_get_name(struct acpi_resource *ares, void *data) {
+	struct drm_i915_private *dev_priv = data;
+	struct acpi_resource_i2c_serialbus *sb;
+	unsigned int val;
+	char *resource;
+	int error;
+
+
+	if (ares->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
+		sb = &ares->data.i2c_serial_bus;
+
+		if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_I2C) {
+			struct acpi_i2c_data_node *i2c_entry = NULL;
+
+			resource = sb->resource_source.string_ptr;
+			resource = strstr(resource, "I2C");
+			error = kstrtouint(resource+3, 0, &val);
+			if (error)
+				return error;
+
+			i2c_entry = kzalloc(sizeof(struct
 acpi_i2c_data_node),
+					GFP_NOWAIT);
+			i2c_entry->i2c_bus_number = val;
+			i2c_entry->i2c_slave_address = sb->slave_address;
+
+			list_add_tail(&i2c_entry->head,
+					&dev_priv->acpi_i2c_list);
+		}
+	}
+
+	return 1;
+}
+
+acpi_status intel_acpi_find_i2c(struct drm_i915_private *dev_priv) {
+	struct pci_dev *pdev = dev_priv->dev->pdev;
+	struct list_head resource_list;
+	struct acpi_device *adev;
+	acpi_handle dhandle;
+
+	dhandle = ACPI_HANDLE(&pdev->dev);
+	if (!dhandle)
+		return false;
+
+	if (acpi_bus_get_device(dhandle, &adev))
+		return AE_OK;
+	if (acpi_bus_get_status(adev) || !adev->status.present)
+		return AE_OK;
+
+	INIT_LIST_HEAD(&resource_list);
+	INIT_LIST_HEAD(&dev_priv->acpi_i2c_list);
+	acpi_dev_get_resources(adev, &resource_list,
+			i2c_acpi_get_name, dev_priv);
+	acpi_dev_free_resource_list(&resource_list);
+
+	return AE_OK;
+}
+
 static bool intel_dsm_pci_probe(struct pci_dev *pdev)  {
 	acpi_handle dhandle;
--
Quoted 1 line

1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx