All of lore.kernel.org
 help / color / mirror / Atom feed
* i2c: introduce i2c helper i2c_find_client_by_name()
@ 2013-06-06 18:33 ` Bin Gao
  0 siblings, 0 replies; 32+ messages in thread
From: Bin Gao @ 2013-06-06 18:33 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: linux-kernel

i2c: introduce i2c helper i2c_find_client_by_name()

There is a requirement to get the i2c_client pointer dynamically without
knowing the bus and slave address. But we do know the client name,
i.e. the name in the i2c_board_info. This patch is to fit this requirement.

A good example is that an ISP(Imaging Signal Processor) driver needs
register i2c camera sensor devices via v4l2, so it has to unregister
all i2c clients that were previously registered by calling
i2c_register_board_info(), and then re-register. For this case we
can use this helper to get i2c_client by passing the client name.

Signed-off-by: Bin Gao <bin.gao@linux.intel.com>
---
 drivers/i2c/i2c-core.c |   17 +++++++++++++++++
 include/linux/i2c.h    |    1 +
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 48e31ed..17683de6 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -2326,6 +2326,23 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
 }
 EXPORT_SYMBOL(i2c_smbus_xfer);
 
+static int match_name(struct device *dev, void *data)
+{
+	const char *name = data;
+	struct i2c_client *client = to_i2c_client(dev);
+
+	return !strncmp(client->name, name, strlen(client->name));
+}
+
+struct i2c_client *i2c_find_client_by_name(char *name)
+{
+	struct device *dev;
+
+	dev = bus_find_device(&i2c_bus_type, NULL, name, match_name);
+	return dev ? to_i2c_client(dev) : NULL;
+}
+EXPORT_SYMBOL_GPL(i2c_find_client_by_name);
+
 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
 MODULE_DESCRIPTION("I2C-Bus main module");
 MODULE_LICENSE("GPL");
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index e988fa9..7d8bf02 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -509,6 +509,7 @@ extern void i2c_clients_command(struct i2c_adapter *adap,
 extern struct i2c_adapter *i2c_get_adapter(int nr);
 extern void i2c_put_adapter(struct i2c_adapter *adap);
 
+extern struct i2c_client *i2c_find_client_by_name(char *name);
 
 /* Return the functionality mask */
 static inline u32 i2c_get_functionality(struct i2c_adapter *adap)
-- 
1.7.4.4


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

end of thread, other threads:[~2013-07-12 11:56 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-06 18:33 i2c: introduce i2c helper i2c_find_client_by_name() Bin Gao
2013-06-06 18:33 ` Bin Gao
2013-06-06 20:32 ` Andy Shevchenko
2013-06-06 20:32   ` Andy Shevchenko
2013-06-06 21:26   ` Bin Gao
2013-06-06 21:26     ` Bin Gao
2013-06-09 19:53     ` Andy Shevchenko
2013-06-09 19:53       ` Andy Shevchenko
2013-06-11 17:11       ` Bin Gao
2013-06-14  7:29         ` Andy Shevchenko
2013-06-14  7:29           ` Andy Shevchenko
2013-06-14 19:00           ` Bin Gao
2013-06-14 19:00             ` Bin Gao
2013-06-19 10:13             ` Wolfram Sang
2013-06-19 10:13               ` Wolfram Sang
2013-06-22  0:27               ` Bin Gao
2013-06-22  0:27                 ` Bin Gao
2013-06-23 12:43                 ` Wolfram Sang
2013-06-23 12:43                   ` Wolfram Sang
2013-07-05 19:55 ` Mark Brown
2013-07-12 10:54   ` Andy Shevchenko
2013-07-12 10:54     ` Andy Shevchenko
2013-07-12 11:00     ` Wolfram Sang
2013-07-12 11:00       ` Wolfram Sang
2013-07-12 11:02       ` Laurent Pinchart
2013-07-12 11:02         ` Laurent Pinchart
2013-07-12 11:29       ` Andy Shevchenko
2013-07-12 11:29         ` Andy Shevchenko
2013-07-12 11:35         ` Laurent Pinchart
2013-07-12 11:35           ` Laurent Pinchart
2013-07-12 11:56           ` Andy Shevchenko
2013-07-12 11:56             ` Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.