Skip to contentSkip to conversation

i2c: Fallback to of_node of parent

PATCH In review Florian Meier 2 participants 5 messages Nov 16, 2013 – Nov 25, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: Fallback to of_node of parent

Many busses (e.g. tegra, omap, bcm2835)
need to set the of_node of the adapter
device to the one of the parent device, i.e.

adap->dev.of_node = pdev->dev.of_node;

As suggested by Stephen Warren, this could also be done in the i2c core and it is a common mistake to forget this line:

I2C: BCM2835: Linking platform nodes to adapter nodes
i2c: Fix device tree binding for i2c-cbus-gpio

---
 drivers/i2c/i2c-core.c |    3 +++
 1 file changed, 3 insertions(+)
drivers/i2c/i2c-core.c +3 -0
index 430c001..c8e33a5 100644
@@ -1310,6 +1310,9 @@ int i2c_add_adapter(struct i2c_adapter *adapter)
 	struct device *dev = &adapter->dev;
 	int id;
 
+	if (!dev->of_node && dev->parent)
+		dev->of_node = dev->parent->of_node;
+
 	if (dev->of_node) {
 		id = of_alias_get_id(dev->of_node, "i2c");
 		if (id >= 0) {
Signature · 1 line
1.7.9.5
#1 lore raw

drivers/i2c/i2c-core.c int i2c_add_adapter(struct i2c_adapter *adapter) · line 1315

Quoted 4 lines
drivers/i2c/i2c-core.c +3 -0
+	if (!dev->of_node && dev->parent)
+		dev->of_node = dev->parent->of_node;
+

That is not enough. Current drivers could then have the assignment removed and even more important, this behaviour should be documented.

Regards,

Wolfram

#2 lore raw

Ok, I will try to find all relevant lines.
Where is the best place to document this?

Greetings,
Florian

2013/11/16 Wolfram Sang <wsa-z923LK4zBo2bacvFa/[email protected]>:

Quoted 12 lines

drivers/i2c/i2c-core.c int i2c_add_adapter(struct i2c_adapter *adapter) · line 1315

Quoted 4 lines
drivers/i2c/i2c-core.c +3 -0
+     if (!dev->of_node && dev->parent)
+             dev->of_node = dev->parent->of_node;
+

That is not enough. Current drivers could then have the assignment removed and even more important, this behaviour should be documented.

Regards,

Wolfram

#3 lore raw

I have looked through all bus drivers and in most cases they have a corresponding line that could be removed.

Although, this patch would break i2c-powermac, because it relies on the fact that of_node stays NULL.

Any idea how to handle that?

Greetings,
Florian

Quoted 19 lines · Florian Meier

Ok, I will try to find all relevant lines.
Where is the best place to document this?

Greetings,
Florian

2013/11/16 Wolfram Sang <wsa-z923LK4zBo2bacvFa/[email protected]>:

Quoted 12 lines

drivers/i2c/i2c-core.c int i2c_add_adapter(struct i2c_adapter *adapter) · line 1315

Quoted 4 lines
drivers/i2c/i2c-core.c +3 -0
+     if (!dev->of_node && dev->parent)
+             dev->of_node = dev->parent->of_node;
+

That is not enough. Current drivers could then have the assignment removed and even more important, this behaviour should be documented.

Regards,

Wolfram

#4 lore raw
Quoted 7 lines · Florian Meier

I have looked through all bus drivers and in most cases they have a corresponding line that could be removed.

Although, this patch would break i2c-powermac, because it relies on the fact that of_node stays NULL.

Any idea how to handle that?

You are right, yet I don't have the time to look into that. If you have an idea, please go ahead.