[PATCH 1/3] i2c: Split adapter initialisation from registers

From: Chris Wilson
Date: Thu Jun 09 2016 - 04:54:46 EST


In order to handle devices that need to use the adapter prior to it
being registered with the system, we first need to split out the
initialisation of the adapter out of i2c_register_adapter.

Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
Cc: Ville SyrjÃlà <ville.syrjala@xxxxxxxxxxxxxxx>
Cc: Wolfram Sang <wsa@xxxxxxxxxxxxx>
Cc: linux-i2c@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: dri-devel@xxxxxxxxxxxxxxxxxxxxx
---
drivers/i2c/i2c-core.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index af11b658984d..743c38a63da1 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1511,16 +1511,8 @@ static int __process_new_adapter(struct device_driver *d, void *data)
return i2c_do_add_adapter(to_i2c_driver(d), data);
}

-static int i2c_register_adapter(struct i2c_adapter *adap)
+static int i2c_init_adapter(struct i2c_adapter *adap)
{
- int res = 0;
-
- /* Can't register until after driver model init */
- if (WARN_ON(!is_registered)) {
- res = -EAGAIN;
- goto out_list;
- }
-
/* Sanity checks */
if (unlikely(adap->name[0] == '\0')) {
pr_err("i2c-core: Attempt to register an adapter with "
@@ -1548,6 +1540,23 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
if (adap->timeout == 0)
adap->timeout = HZ;

+ return 0;
+}
+
+static int i2c_register_adapter(struct i2c_adapter *adap)
+{
+ int res = 0;
+
+ /* Can't register until after driver model init */
+ if (WARN_ON(!is_registered)) {
+ res = -EAGAIN;
+ goto out_list;
+ }
+
+ res = i2c_init_adapter(adap);
+ if (res)
+ goto out_list;
+
dev_set_name(&adap->dev, "i2c-%d", adap->nr);
adap->dev.bus = &i2c_bus_type;
adap->dev.type = &i2c_adapter_type;
--
2.8.1