diff mbox

[3/3] i2c: Export i2c_init_adapter() for use by drivers in early initialisation

Message ID 1465462435-5240-3-git-send-email-chris@chris-wilson.co.uk
State New
Headers show

Commit Message

Chris Wilson June 9, 2016, 8:53 a.m. UTC
Some drivers require use of their i2c adapter long before they can add
the adapter to userspace (i.e. before they establish and expose their
objects in the sysfs kobject tree). Currently i2c_add_adapter()
registers the adapter with userspace, which causes a conflict in the
ordering of the driver's initialisation. Exporting i2c_init_adapter()
allows for the i2c adapter to be used early in the initialisation in
order to detect whether the device the adapter is attached to is even
present. The drivers still need to call i2c_add_adapter() (or
i2c_add_number_adapter()) as per normal to complete their registration.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
Cc: linux-i2c@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
---
 drivers/i2c/i2c-core.c | 16 +++++++++++++++-
 include/linux/i2c.h    |  1 +
 2 files changed, 16 insertions(+), 1 deletion(-)

Comments

Wolfram Sang Aug. 23, 2016, 9:33 p.m. UTC | #1
On Thu, Jun 09, 2016 at 09:53:55AM +0100, Chris Wilson wrote:
> Some drivers require use of their i2c adapter long before they can add
> the adapter to userspace (i.e. before they establish and expose their
> objects in the sysfs kobject tree). Currently i2c_add_adapter()
> registers the adapter with userspace, which causes a conflict in the
> ordering of the driver's initialisation. Exporting i2c_init_adapter()
> allows for the i2c adapter to be used early in the initialisation in
> order to detect whether the device the adapter is attached to is even
> present. The drivers still need to call i2c_add_adapter() (or
> i2c_add_number_adapter()) as per normal to complete their registration.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Cc: Wolfram Sang <wsa@the-dreams.de>
> Cc: linux-i2c@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Cc: dri-devel@lists.freedesktop.org

Do you have a patch for some i2c driver making use of this change?
diff mbox

Patch

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 91ff70d31ec8..0a3bdb048d65 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1511,7 +1511,20 @@  static int __process_new_adapter(struct device_driver *d, void *data)
 	return i2c_do_add_adapter(to_i2c_driver(d), data);
 }
 
-static int i2c_init_adapter(struct i2c_adapter *adap)
+/**
+ * i2c_init_adapter - initialise i2c adapter for internal use
+ * @adapter: the adapter to initialise
+ * Context: any
+ *
+ * This routine is used to initialise an I2C adapter for internal use
+ * prior to registering it with third parties (including userspace). The
+ * driver should still call i2c_add_adapter() or i2c_add_numbered_adapter()
+ * when it is ready to expose the adapter to userspace.
+ *
+ * Returns: 0 on success, or a negative error value if the adapter is not
+ * fully specified for use.
+ */
+int i2c_init_adapter(struct i2c_adapter *adap)
 {
 	/* Only initialise the adapter once. */
 	if (list_empty(&adap->userspace_clients))
@@ -1546,6 +1559,7 @@  static int i2c_init_adapter(struct i2c_adapter *adap)
 
 	return 0;
 }
+EXPORT_SYMBOL(i2c_init_adapter);
 
 static int i2c_register_adapter(struct i2c_adapter *adap)
 {
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 96a25ae14494..72c76c5efba5 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -639,6 +639,7 @@  i2c_unlock_adapter(struct i2c_adapter *adapter)
 /* administration...
  */
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+extern int i2c_init_adapter(struct i2c_adapter *);
 extern int i2c_add_adapter(struct i2c_adapter *);
 extern void i2c_del_adapter(struct i2c_adapter *);
 extern int i2c_add_numbered_adapter(struct i2c_adapter *);