Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1370139 > unrolled thread

[PATCH v6 14/24] of/unittest: convert to use an explicit i2c mux core

Started byPeter Rosin <peda@lysator.liu.se>
First post2016-04-03 11:00 +0200
Last post2016-04-05 09:50 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v6 14/24] of/unittest: convert to use an explicit i2c mux core Peter Rosin <peda@lysator.liu.se> - 2016-04-03 11:00 +0200
    Re: [PATCH v6 14/24] of/unittest: convert to use an explicit i2c mux  core Rob Herring <robh@kernel.org> - 2016-04-04 07:20 +0200
      Re: [PATCH v6 14/24] of/unittest: convert to use an explicit i2c  mux core Peter Rosin <peda@lysator.liu.se> - 2016-04-05 09:50 +0200

#1370139 — [PATCH v6 14/24] of/unittest: convert to use an explicit i2c mux core

FromPeter Rosin <peda@lysator.liu.se>
Date2016-04-03 11:00 +0200
Subject[PATCH v6 14/24] of/unittest: convert to use an explicit i2c mux core
Message-ID<rjM31-Ns-21@gated-at.bofh.it>
From: Peter Rosin <peda@axentia.se>

Allocate an explicit i2c mux core to handle parent and child adapters
etc. Update the select op to be in terms of the i2c mux core instead
of the child adapter.

Signed-off-by: Peter Rosin <peda@axentia.se>
---
 drivers/of/unittest.c | 40 +++++++++++++++-------------------------
 1 file changed, 15 insertions(+), 25 deletions(-)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index e986e6ee52e0..84a65b711e8c 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1692,13 +1692,7 @@ static struct i2c_driver unittest_i2c_dev_driver = {
 
 #if IS_BUILTIN(CONFIG_I2C_MUX)
 
-struct unittest_i2c_mux_data {
-	int nchans;
-	struct i2c_adapter *adap[];
-};
-
-static int unittest_i2c_mux_select_chan(struct i2c_adapter *adap,
-			       void *client, u32 chan)
+static int unittest_i2c_mux_select_chan(struct i2c_mux_core *muxc, u32 chan)
 {
 	return 0;
 }
@@ -1706,11 +1700,11 @@ static int unittest_i2c_mux_select_chan(struct i2c_adapter *adap,
 static int unittest_i2c_mux_probe(struct i2c_client *client,
 		const struct i2c_device_id *id)
 {
-	int ret, i, nchans, size;
+	int ret, i, nchans;
 	struct device *dev = &client->dev;
 	struct i2c_adapter *adap = to_i2c_adapter(dev->parent);
 	struct device_node *np = client->dev.of_node, *child;
-	struct unittest_i2c_mux_data *stm;
+	struct i2c_mux_core *muxc;
 	u32 reg, max_reg;
 
 	dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
@@ -1734,25 +1728,23 @@ static int unittest_i2c_mux_probe(struct i2c_client *client,
 		return -EINVAL;
 	}
 
-	size = offsetof(struct unittest_i2c_mux_data, adap[nchans]);
-	stm = devm_kzalloc(dev, size, GFP_KERNEL);
-	if (!stm) {
-		dev_err(dev, "Out of memory\n");
+	muxc = i2c_mux_alloc(adap, dev, 0, 0,
+			     unittest_i2c_mux_select_chan, NULL);
+	if (!muxc)
 		return -ENOMEM;
-	}
-	stm->nchans = nchans;
+	ret = i2c_mux_reserve_adapters(muxc, nchans);
+	if (ret)
+		return ret;
 	for (i = 0; i < nchans; i++) {
-		stm->adap[i] = i2c_add_mux_adapter(adap, dev, client,
-				0, i, 0, unittest_i2c_mux_select_chan, NULL);
-		if (!stm->adap[i]) {
+		ret = i2c_mux_add_adapter(muxc, 0, i, 0);
+		if (ret) {
 			dev_err(dev, "Failed to register mux #%d\n", i);
-			for (i--; i >= 0; i--)
-				i2c_del_mux_adapter(stm->adap[i]);
+			i2c_mux_del_adapters(muxc);
 			return -ENODEV;
 		}
 	}
 
-	i2c_set_clientdata(client, stm);
+	i2c_set_clientdata(client, muxc);
 
 	return 0;
 };
@@ -1761,12 +1753,10 @@ static int unittest_i2c_mux_remove(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
 	struct device_node *np = client->dev.of_node;
-	struct unittest_i2c_mux_data *stm = i2c_get_clientdata(client);
-	int i;
+	struct i2c_mux_core *muxc = i2c_get_clientdata(client);
 
 	dev_dbg(dev, "%s for node @%s\n", __func__, np->full_name);
-	for (i = stm->nchans - 1; i >= 0; i--)
-		i2c_del_mux_adapter(stm->adap[i]);
+	i2c_mux_del_adapters(muxc);
 	return 0;
 }
 
-- 
2.1.4

[toc] | [next] | [standalone]


#1370358 — Re: [PATCH v6 14/24] of/unittest: convert to use an explicit i2c mux core

FromRob Herring <robh@kernel.org>
Date2016-04-04 07:20 +0200
SubjectRe: [PATCH v6 14/24] of/unittest: convert to use an explicit i2c mux core
Message-ID<rk55F-6H0-29@gated-at.bofh.it>
In reply to#1370139
On Sun, Apr 03, 2016 at 10:52:44AM +0200, Peter Rosin wrote:
> From: Peter Rosin <peda@axentia.se>
> 
> Allocate an explicit i2c mux core to handle parent and child adapters
> etc. Update the select op to be in terms of the i2c mux core instead
> of the child adapter.
> 
> Signed-off-by: Peter Rosin <peda@axentia.se>
> ---
>  drivers/of/unittest.c | 40 +++++++++++++++-------------------------
>  1 file changed, 15 insertions(+), 25 deletions(-)

I assume you ran the unittest...

Acked-by: Rob Herring <robh@kernel.org>

[toc] | [prev] | [next] | [standalone]


#1371287 — Re: [PATCH v6 14/24] of/unittest: convert to use an explicit i2c mux core

FromPeter Rosin <peda@lysator.liu.se>
Date2016-04-05 09:50 +0200
SubjectRe: [PATCH v6 14/24] of/unittest: convert to use an explicit i2c mux core
Message-ID<rktUm-8dF-27@gated-at.bofh.it>
In reply to#1370358
On 2016-04-04 07:16, Rob Herring wrote:
> On Sun, Apr 03, 2016 at 10:52:44AM +0200, Peter Rosin wrote:
>> From: Peter Rosin <peda@axentia.se>
>>
>> Allocate an explicit i2c mux core to handle parent and child adapters
>> etc. Update the select op to be in terms of the i2c mux core instead
>> of the child adapter.
>>
>> Signed-off-by: Peter Rosin <peda@axentia.se>
>> ---
>>  drivers/of/unittest.c | 40 +++++++++++++++-------------------------
>>  1 file changed, 15 insertions(+), 25 deletions(-)
> 
> I assume you ran the unittest...

It's one of the few drivers I do have hardware for, so yes, I did
indeed test it!

> Acked-by: Rob Herring <robh@kernel.org>

Thanks!

Cheers,
Peter

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web