public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: skip address detection if provided in board_info
@ 2010-10-11 23:10 jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA
       [not found] ` <1286838635-16474-1-git-send-email-jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
  0 siblings, 1 reply; 13+ messages in thread
From: jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA @ 2010-10-11 23:10 UTC (permalink / raw)
  To: i2c list, Feng Tang, Ben Dooks, Jean Delvare; +Cc: Jacob Pan

From: Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>

If the address of a given device is already provided by platform init
code, e.g. from system firmware, there is no need to call the driver's
detect() function for finding the matching address from the driver's
address list.

Avoiding such detection might save boot time.

Signed-off-by: Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
 drivers/i2c/i2c-core.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 6649176..e4f7feb 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1499,6 +1499,31 @@ static int i2c_detect_address(struct i2c_client *temp_client,
 	return 0;
 }
 
+static int i2c_scan_board_info(struct i2c_adapter *adapter, struct i2c_driver *driver)
+{
+	struct i2c_devinfo	*devinfo;
+	int ret = -ENODEV;
+
+	down_read(&__i2c_board_lock);
+	list_for_each_entry(devinfo, &__i2c_board_list, list) {
+		if (!strncmp(devinfo->board_info.type, driver->driver.name,
+				I2C_NAME_SIZE)) {
+			dev_info(&adapter->dev, "found i2c board info %s\n",
+				driver->driver.name);
+			if (devinfo->board_info.addr) {
+				ret = 0;
+				goto scan_exit;
+			}
+		}
+	}
+
+scan_exit:
+	up_read(&__i2c_board_lock);
+
+	return ret;
+}
+
+
 static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
 {
 	const unsigned short *address_list;
@@ -1506,6 +1531,13 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
 	int i, err = 0;
 	int adap_id = i2c_adapter_id(adapter);
 
+	/* There is no need to detect i2c address if board info is provided */
+	if (!i2c_scan_board_info(adapter, driver)) {
+		dev_info(&adapter->dev, "Skip address detection for %s\n",
+			driver->driver.name);
+		return 0;
+	}
+
 	address_list = driver->address_list;
 	if (!driver->detect || !address_list)
 		return 0;
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2010-10-13 17:04 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-11 23:10 [PATCH] i2c: skip address detection if provided in board_info jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA
     [not found] ` <1286838635-16474-1-git-send-email-jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2010-10-12  7:28   ` Jean Delvare
     [not found]     ` <20101012092822.6f4e4aa5-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2010-10-12  8:21       ` Feng Tang
2010-10-12  8:47         ` Jean Delvare
     [not found]           ` <20101012104707.3318511d-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2010-10-12  9:30             ` Feng Tang
2010-10-12 11:34               ` Jean Delvare
     [not found]                 ` <20101012133425.490e3c4c-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2010-10-12 18:01                   ` Jacob Pan
2010-10-13  7:26                     ` Jean Delvare
     [not found]                       ` <20101013092654.7e26fa00-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2010-10-13 15:54                         ` Jacob Pan
2010-10-13 16:07                           ` Jean Delvare
     [not found]                             ` <20101013180751.2d37c513-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2010-10-13 17:01                               ` Jacob Pan
2010-10-13 17:04                   ` Feng Tang
2010-10-13  9:29                     ` Jean Delvare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox