diff mbox

i2c: Fallback to of_node of parent

Message ID 528791EF.9060505@koalo.de
State Changes Requested
Headers show

Commit Message

Florian Meier Nov. 16, 2013, 3:40 p.m. UTC
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

Signed-off-by: Florian Meier <florian.meier@koalo.de>
Suggested-by: Stephen Warren <swarren@wwwdotorg.org>
---
 drivers/i2c/i2c-core.c |    3 +++
 1 file changed, 3 insertions(+)

Comments

Wolfram Sang Nov. 16, 2013, 4:06 p.m. UTC | #1
> +	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
Florian Meier Nov. 16, 2013, 4:11 p.m. UTC | #2
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@the-dreams.de>:
>
>> +     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
>
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Florian Meier Nov. 16, 2013, 4:59 p.m. UTC | #3
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

On 16.11.2013 17:11, Florian Meier wrote:
> 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@the-dreams.de>:
>>
>>> +     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
>>

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfram Sang Nov. 25, 2013, 8:46 a.m. UTC | #4
On Sat, Nov 16, 2013 at 05:59:15PM +0100, Florian Meier wrote:
> 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.
diff mbox

Patch

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 430c001..c8e33a5 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -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) {