Skip to contentSkip to conversation

i2c-designware: add OF binding support

PATCH Superseded Rob Herring 3 participants 6 messages Aug 3, 2011 – Aug 4, 2011 4 messages not in the archive

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c-designware: add OF binding support

From: Rob Herring <rob.herring-bsGFqQB8/[email protected]>

Add of_match_table and DT style i2c registration to designware i2c driver.

Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc devicetree-discuss-uLR06cmDAlY/[email protected]
Cc Ben Dooks <[email protected]>
---
 Documentation/devicetree/bindings/i2c/dw-i2c.txt |   23 ++++++++++++++++++++++
 drivers/i2c/busses/i2c-designware.c              |   13 ++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/i2c/dw-i2c.txt
Documentation/devicetree/bindings/i2c/dw-i2c.txt new file +23 -0
new file mode 100644
index 0000000..cbcb404
@@ -0,0 +1,23 @@
+* Synopsys DesignWare I2C
+
+Required properties :
+
+ - compatible : should be "snps,designware-i2c"
+ - reg : Offset and length of the register set for the device
+ - interrupts : <IRQ> where IRQ is the interrupt number.
+
+Recommended properties :
+
+ - clock-frequency : desired I2C bus clock frequency in Hz.
+
+Example :
+
+	i2c@f0000 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "snps,designware-i2c";
+		reg = <0xf0000 0x1000>;
+		interrupts = <11>;
+		clock-frequency = <400000>;
+	};
+
drivers/i2c/busses/i2c-designware.c +13 -0
index b7a51c4..2911a49 100644
@@ -37,6 +37,7 @@
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/slab.h>
+#include <linux/of_i2c.h>
 
 /*
  * Registers offset
@@ -770,12 +771,17 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev)
 	adap->algo = &i2c_dw_algo;
 	adap->dev.parent = &pdev->dev;
 
+#ifdef CONFIG_OF
+	r = i2c_add_adapter(adap);
+#else
 	adap->nr = pdev->id;
 	r = i2c_add_numbered_adapter(adap);
+#endif
 	if (r) {
 		dev_err(&pdev->dev, "failure adding adapter\n");
 		goto err_free_irq;
 	}
+	of_i2c_register_devices(adap);
 
 	return 0;
 
@@ -819,6 +825,12 @@ static int __devexit dw_i2c_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct of_device_id dw_i2c_of_match[] = {
+	{ .compatible = "snps,designware-i2c", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, dw_i2c_of_match);
+
 /* work with hotplug and coldplug */
 MODULE_ALIAS("platform:i2c_designware");
 
@@ -827,6 +839,7 @@ static struct platform_driver dw_i2c_driver = {
 	.driver		= {
 		.name	= "i2c_designware",
 		.owner	= THIS_MODULE,
+		.of_match_table = dw_i2c_of_match,
 	},
 };
 
Signature · 1 line
1.7.4.1
Acked-by
#2 lore raw
In reply to a message not in the archive
Quoted 58 lines · Rob Herring

From: Rob Herring <rob.herring-bsGFqQB8/[email protected]>

Add of_match_table and DT style i2c registration to designware i2c driver.

Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc devicetree-discuss-uLR06cmDAlY/[email protected]
Cc Ben Dooks <[email protected]>

---
 Documentation/devicetree/bindings/i2c/dw-i2c.txt |   23 ++++++++++++++++++++++ drivers/i2c/busses/i2c-designware.c              |   13 ++++++++++++

 2 files changed, 36 insertions(+), 0 deletions(-)

 create mode 100644 Documentation/devicetree/bindings/i2c/dw-i2c.txt

Documentation/devicetree/bindings/i2c/dw-i2c.txt new file +23 -0
new file mode 100644
index 0000000..cbcb404
@@ -0,0 +1,23 @@
+* Synopsys DesignWare I2C
+
+Required properties :
+
+ - compatible : should be "snps,designware-i2c"
+ - reg : Offset and length of the register set for the device
+ - interrupts : <IRQ> where IRQ is the interrupt number.
+
+Recommended properties :
+
+ - clock-frequency : desired I2C bus clock frequency in Hz.
+
+Example :
+
+       i2c@f0000 {
+               #address-cells = <1>;
+               #size-cells = <0>;
+               compatible = "snps,designware-i2c";
+               reg = <0xf0000 0x1000>;
+               interrupts = <11>;
+               clock-frequency = <400000>;
+       };
+
drivers/i2c/busses/i2c-designware.c +1 -0
index b7a51c4..2911a49 100644
@@ -37,6 +37,7 @@
  #include <linux/platform_device.h>
  #include <linux/io.h>
  #include <linux/slab.h>
+#include <linux/of_i2c.h>
 
  /*
  * Registers offset

drivers/i2c/busses/i2c-designware.c static int __devinit dw_i2c_probe(struct platform_device *pdev) · line 779

Quoted 9 lines
drivers/i2c/busses/i2c-designware.c +4 -0
@@ -770,12 +771,17 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev)
        adap->algo = &i2c_dw_algo;
        adap->dev.parent = &pdev->dev;
 
+#ifdef CONFIG_OF
+       r = i2c_add_adapter(adap);
+#else
        adap->nr = pdev->id;
        r = i2c_add_numbered_adapter(adap);
+#endif

Unnecessary. i2c_add_numbered_adapter will dynamically assign a bus number now if nr is -1.

Otherwise, the patch looks good. You can add the following after removing the above hunk. Besides, the way this is changed with an #ifdef will break non-dt users in the same kernel. You know better than to do that! :-)

g.

#3 lore raw
In reply to a message not in the archive
Quoted 35 lines · Rob Herring

From: Rob Herring <rob.herring-bsGFqQB8/[email protected]>

Add of_match_table and DT style i2c registration to designware i2c driver.

Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc devicetree-discuss-uLR06cmDAlY/[email protected]
Cc Ben Dooks <[email protected]>
---
 Documentation/devicetree/bindings/i2c/dw-i2c.txt |   23 ++++++++++++++++++++++
 drivers/i2c/busses/i2c-designware.c              |   13 ++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/i2c/dw-i2c.txt
Documentation/devicetree/bindings/i2c/dw-i2c.txt new file +13 -0
new file mode 100644
index 0000000..cbcb404
@@ -0,0 +1,23 @@
+* Synopsys DesignWare I2C
+
+Required properties :
+
+ - compatible : should be "snps,designware-i2c"
+ - reg : Offset and length of the register set for the device
+ - interrupts : <IRQ> where IRQ is the interrupt number.
+
+Recommended properties :
+
+ - clock-frequency : desired I2C bus clock frequency in Hz.
+
+Example :

Documentation/devicetree/bindings/i2c/dw-i2c.txt line 23

Quoted 10 lines
Documentation/devicetree/bindings/i2c/dw-i2c.txt new file +10 -0
+
+	i2c@f0000 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "snps,designware-i2c";
+		reg = <0xf0000 0x1000>;
+		interrupts = <11>;
+		clock-frequency = <400000>;
+	};
+

looks good to me.

Quoted 13 lines
drivers/i2c/busses/i2c-designware.c +1 -0
index b7a51c4..2911a49 100644
@@ -37,6 +37,7 @@
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/slab.h>
+#include <linux/of_i2c.h>
 
 /*
  * Registers offset

drivers/i2c/busses/i2c-designware.c static int __devinit dw_i2c_probe(struct platform_device *pdev) · line 779

Quoted 9 lines
drivers/i2c/busses/i2c-designware.c +4 -0
@@ -770,12 +771,17 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev)
 	adap->algo = &i2c_dw_algo;
 	adap->dev.parent = &pdev->dev;
 
+#ifdef CONFIG_OF
+	r = i2c_add_adapter(adap);
+#else
 	adap->nr = pdev->id;
 	r = i2c_add_numbered_adapter(adap);
+#endif

I would say that doing the #ifdef CONFIG_OF is dangerous here when we are in a mixed OF/platform enviromnent as we're depending on compile time selection.

I'm also wondering whether we have an of helper macro which takes a pdev and gives you an adapter number either given on pdev->id or -1 for the case when we're using the OF bindings.

It might be worth talking to Grant about setting pdev->id to -1 if we are using an OF device.

drivers/i2c/busses/i2c-designware.c static int __devinit dw_i2c_probe(struct platform_device *pdev) · line 784

Quoted 5 lines
drivers/i2c/busses/i2c-designware.c +1 -0
 	if (r) {
 		dev_err(&pdev->dev, "failure adding adapter\n");
 		goto err_free_irq;
 	}
+	of_i2c_register_devices(adap);

If we did that, we could add a of_i2c_register_adapter() call which would take the platform device and then do the of_i2c_register_devices() and do these steps.

Quoted 16 lines
drivers/i2c/busses/i2c-designware.c +6 -0
 	return 0;
 
@@ -819,6 +825,12 @@ static int __devexit dw_i2c_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct of_device_id dw_i2c_of_match[] = {
+	{ .compatible = "snps,designware-i2c", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, dw_i2c_of_match);
+
 /* work with hotplug and coldplug */
 MODULE_ALIAS("platform:i2c_designware");
 

drivers/i2c/busses/i2c-designware.c static struct platform_driver dw_i2c_driver = { · line 842

Quoted 4 lines
drivers/i2c/busses/i2c-designware.c +1 -0
@@ -827,6 +839,7 @@ static struct platform_driver dw_i2c_driver = {
 	.driver		= {
 		.name	= "i2c_designware",
 		.owner	= THIS_MODULE,
+		.of_match_table = dw_i2c_of_match,

If my patch for of_match_ptr() is accepted, it will be needed here otherwise you will need to do something about remvoing the of table above if not config of.

Signature · 3 lines
Ben Dooks, [email protected], http://www.fluff.org/ben/

Large Hadron Colada: A large Pina Colada that makes the universe disappear.
#5 lore raw
In reply to a message not in the archive

Ben,

Quoted 76 lines · Ben Dooks
Quoted 35 lines · Rob Herring

From: Rob Herring <rob.herring-bsGFqQB8/[email protected]>

Add of_match_table and DT style i2c registration to designware i2c driver.

Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc devicetree-discuss-uLR06cmDAlY/[email protected]
Cc Ben Dooks <[email protected]>
---
 Documentation/devicetree/bindings/i2c/dw-i2c.txt |   23 ++++++++++++++++++++++
 drivers/i2c/busses/i2c-designware.c              |   13 ++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/i2c/dw-i2c.txt
Documentation/devicetree/bindings/i2c/dw-i2c.txt new file +13 -0
new file mode 100644
index 0000000..cbcb404
@@ -0,0 +1,23 @@
+* Synopsys DesignWare I2C
+
+Required properties :
+
+ - compatible : should be "snps,designware-i2c"
+ - reg : Offset and length of the register set for the device
+ - interrupts : <IRQ> where IRQ is the interrupt number.
+
+Recommended properties :
+
+ - clock-frequency : desired I2C bus clock frequency in Hz.
+
+Example :

Documentation/devicetree/bindings/i2c/dw-i2c.txt line 23

Quoted 10 lines
Documentation/devicetree/bindings/i2c/dw-i2c.txt new file +10 -0
+
+	i2c@f0000 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "snps,designware-i2c";
+		reg = <0xf0000 0x1000>;
+		interrupts = <11>;
+		clock-frequency = <400000>;
+	};
+

looks good to me.

Quoted 13 lines
drivers/i2c/busses/i2c-designware.c +1 -0
index b7a51c4..2911a49 100644
@@ -37,6 +37,7 @@
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/slab.h>
+#include <linux/of_i2c.h>
 
 /*
  * Registers offset

drivers/i2c/busses/i2c-designware.c static int __devinit dw_i2c_probe(struct platform_device *pdev) · line 779

Quoted 9 lines
drivers/i2c/busses/i2c-designware.c +4 -0
@@ -770,12 +771,17 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev)
 	adap->algo = &i2c_dw_algo;
 	adap->dev.parent = &pdev->dev;
 
+#ifdef CONFIG_OF
+	r = i2c_add_adapter(adap);
+#else
 	adap->nr = pdev->id;
 	r = i2c_add_numbered_adapter(adap);
+#endif

I would say that doing the #ifdef CONFIG_OF is dangerous here when we are in a mixed OF/platform enviromnent as we're depending on compile time selection.

Quoted 7 lines

I'm also wondering whether we have an of helper macro which takes a pdev and gives you an adapter number either given on pdev->id or -1 for the case when we're using the OF bindings.

It might be worth talking to Grant about setting pdev->id to -1 if we are using an OF device.

As Grant said, that's already done and this hunk is not needed.

Quoted 10 lines

drivers/i2c/busses/i2c-designware.c static int __devinit dw_i2c_probe(struct platform_device *pdev) · line 784

Quoted 5 lines
drivers/i2c/busses/i2c-designware.c +1 -0
 	if (r) {
 		dev_err(&pdev->dev, "failure adding adapter\n");
 		goto err_free_irq;
 	}
+	of_i2c_register_devices(adap);

If we did that, we could add a of_i2c_register_adapter() call which would take the platform device and then do the of_i2c_register_devices() and do these steps.

Better yet, how about putting of_i2c_register_devices into i2c_register_adapter? Everywhere that calls of_i2c_register_devices is preceded by a call to i2c_add_numbered_adapter or i2c_add_adapter. It seems logical to put it with i2c_scan_static_board_info. I'll prepare a patch to add that and remove all the other callers unless you think that's a bad idea.

Quoted 15 lines
Quoted 15 lines
drivers/i2c/busses/i2c-designware.c +6 -0
 	return 0;
 
@@ -819,6 +825,12 @@ static int __devexit dw_i2c_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct of_device_id dw_i2c_of_match[] = {
+	{ .compatible = "snps,designware-i2c", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, dw_i2c_of_match);
+
 /* work with hotplug and coldplug */
 MODULE_ALIAS("platform:i2c_designware");
 
Quoted 9 lines

drivers/i2c/busses/i2c-designware.c static struct platform_driver dw_i2c_driver = { · line 842

Quoted 5 lines
drivers/i2c/busses/i2c-designware.c +1 -0
@@ -827,6 +839,7 @@ static struct platform_driver dw_i2c_driver = {
 	.driver		= {
 		.name	= "i2c_designware",
 		.owner	= THIS_MODULE,
+		.of_match_table = dw_i2c_of_match,

If my patch for of_match_ptr() is accepted, it will be needed here otherwise you will need to do something about remvoing the of table above if not config of.

There's really not much harm with having the table. If you match the device in the non-DT way, the table is not used. Drivers should never directly access the table either, but use the helpers to get their data.

Rob

#7 lore raw
In reply to a message not in the archive
Quoted 100 lines · Rob Herring

Ben,

Quoted 76 lines · Ben Dooks
Quoted 35 lines · Rob Herring

From: Rob Herring <rob.herring-bsGFqQB8/[email protected]>

Add of_match_table and DT style i2c registration to designware i2c driver.

Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc devicetree-discuss-uLR06cmDAlY/[email protected]
Cc Ben Dooks <[email protected]>
---
 Documentation/devicetree/bindings/i2c/dw-i2c.txt |   23 ++++++++++++++++++++++
 drivers/i2c/busses/i2c-designware.c              |   13 ++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/i2c/dw-i2c.txt
Documentation/devicetree/bindings/i2c/dw-i2c.txt new file +13 -0
new file mode 100644
index 0000000..cbcb404
@@ -0,0 +1,23 @@
+* Synopsys DesignWare I2C
+
+Required properties :
+
+ - compatible : should be "snps,designware-i2c"
+ - reg : Offset and length of the register set for the device
+ - interrupts : <IRQ> where IRQ is the interrupt number.
+
+Recommended properties :
+
+ - clock-frequency : desired I2C bus clock frequency in Hz.
+
+Example :

Documentation/devicetree/bindings/i2c/dw-i2c.txt line 23

Quoted 10 lines
Documentation/devicetree/bindings/i2c/dw-i2c.txt new file +10 -0
+
+	i2c@f0000 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "snps,designware-i2c";
+		reg = <0xf0000 0x1000>;
+		interrupts = <11>;
+		clock-frequency = <400000>;
+	};
+

looks good to me.

Quoted 13 lines
drivers/i2c/busses/i2c-designware.c +1 -0
index b7a51c4..2911a49 100644
@@ -37,6 +37,7 @@
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/slab.h>
+#include <linux/of_i2c.h>
 
 /*
  * Registers offset

drivers/i2c/busses/i2c-designware.c static int __devinit dw_i2c_probe(struct platform_device *pdev) · line 779

Quoted 9 lines
drivers/i2c/busses/i2c-designware.c +4 -0
@@ -770,12 +771,17 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev)
 	adap->algo = &i2c_dw_algo;
 	adap->dev.parent = &pdev->dev;
 
+#ifdef CONFIG_OF
+	r = i2c_add_adapter(adap);
+#else
 	adap->nr = pdev->id;
 	r = i2c_add_numbered_adapter(adap);
+#endif

I would say that doing the #ifdef CONFIG_OF is dangerous here when we are in a mixed OF/platform enviromnent as we're depending on compile time selection.

Quoted 7 lines

I'm also wondering whether we have an of helper macro which takes a pdev and gives you an adapter number either given on pdev->id or -1 for the case when we're using the OF bindings.

It might be worth talking to Grant about setting pdev->id to -1 if we are using an OF device.

As Grant said, that's already done and this hunk is not needed.

Quoted 10 lines

drivers/i2c/busses/i2c-designware.c static int __devinit dw_i2c_probe(struct platform_device *pdev) · line 784

Quoted 5 lines
drivers/i2c/busses/i2c-designware.c +1 -0
 	if (r) {
 		dev_err(&pdev->dev, "failure adding adapter\n");
 		goto err_free_irq;
 	}
+	of_i2c_register_devices(adap);

If we did that, we could add a of_i2c_register_adapter() call which would take the platform device and then do the of_i2c_register_devices() and do these steps.

Quoted 7 lines

Better yet, how about putting of_i2c_register_devices into i2c_register_adapter? Everywhere that calls of_i2c_register_devices is preceded by a call to i2c_add_numbered_adapter or i2c_add_adapter. It seems logical to put it with i2c_scan_static_board_info. I'll prepare a patch to add that and remove all the other callers unless you think that's a bad idea.

Nevermind. That would be undoing this commit:

of/i2c: Fix module load order issue caused by of_i2c.c

Commit 959e85f7, "i2c: add OF-style registration and binding" caused a module dependency loop where of_i2c.c calls functions in i2c-core, and i2c-core calls of_i2c_register_devices() in of_i2c. This means that when i2c support is built as a module when CONFIG_OF is set, then neither i2c_core nor of_i2c are able to be loaded.

This patch fixes the problem by moving the of_i2c_register_devices() calls back into the device drivers. Device drivers already specifically request the core code to parse the device tree for devices anyway by setting the of_node pointer, so it isn't a big deal to also call the registration function. The drivers just become slightly more verbose.

Rob

Quoted 32 lines
Quoted 15 lines
Quoted 15 lines
drivers/i2c/busses/i2c-designware.c +6 -0
 	return 0;
 
@@ -819,6 +825,12 @@ static int __devexit dw_i2c_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct of_device_id dw_i2c_of_match[] = {
+	{ .compatible = "snps,designware-i2c", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, dw_i2c_of_match);
+
 /* work with hotplug and coldplug */
 MODULE_ALIAS("platform:i2c_designware");
 
Quoted 9 lines

drivers/i2c/busses/i2c-designware.c static struct platform_driver dw_i2c_driver = { · line 842

Quoted 5 lines
drivers/i2c/busses/i2c-designware.c +1 -0
@@ -827,6 +839,7 @@ static struct platform_driver dw_i2c_driver = {
 	.driver		= {
 		.name	= "i2c_designware",
 		.owner	= THIS_MODULE,
+		.of_match_table = dw_i2c_of_match,

If my patch for of_match_ptr() is accepted, it will be needed here otherwise you will need to do something about remvoing the of table above if not config of.

There's really not much harm with having the table. If you match the device in the non-DT way, the table is not used. Drivers should never directly access the table either, but use the helpers to get their data.

Rob

#9 lore raw
In reply to a message not in the archive
Quoted 109 lines · Rob Herring
Quoted 100 lines · Rob Herring

Ben,

Quoted 76 lines · Ben Dooks
Quoted 35 lines · Rob Herring

From: Rob Herring <rob.herring-bsGFqQB8/[email protected]>

Add of_match_table and DT style i2c registration to designware i2c driver.

Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc devicetree-discuss-uLR06cmDAlY/[email protected]
Cc Ben Dooks <[email protected]>

---
 Documentation/devicetree/bindings/i2c/dw-i2c.txt |   23 ++++++++++++++++++++++ drivers/i2c/busses/i2c-designware.c              |   13 ++++++++++++

 2 files changed, 36 insertions(+), 0 deletions(-)

 create mode 100644 Documentation/devicetree/bindings/i2c/dw-i2c.txt

Documentation/devicetree/bindings/i2c/dw-i2c.txt new file +13 -0
new file mode 100644
index 0000000..cbcb404
@@ -0,0 +1,23 @@
+* Synopsys DesignWare I2C
+
+Required properties :
+
+ - compatible : should be "snps,designware-i2c"
+ - reg : Offset and length of the register set for the device
+ - interrupts : <IRQ> where IRQ is the interrupt number.
+
+Recommended properties :
+
+ - clock-frequency : desired I2C bus clock frequency in Hz.
+
+Example :

Documentation/devicetree/bindings/i2c/dw-i2c.txt line 23

Quoted 10 lines
Documentation/devicetree/bindings/i2c/dw-i2c.txt new file +10 -0
+
+   i2c@f0000 {
+           #address-cells = <1>;
+           #size-cells = <0>;
+           compatible = "snps,designware-i2c";
+           reg = <0xf0000 0x1000>;
+           interrupts = <11>;
+           clock-frequency = <400000>;
+   };
+

looks good to me.

Quoted 13 lines
drivers/i2c/busses/i2c-designware.c +1 -0
index b7a51c4..2911a49 100644
@@ -37,6 +37,7 @@
  #include <linux/platform_device.h>
  #include <linux/io.h>
  #include <linux/slab.h>
+#include <linux/of_i2c.h>
 
  /*
   * Registers offset

drivers/i2c/busses/i2c-designware.c static int __devinit dw_i2c_probe(struct platform_device *pdev) · line 779

Quoted 9 lines
drivers/i2c/busses/i2c-designware.c +4 -0
@@ -770,12 +771,17 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev)
     adap->algo = &i2c_dw_algo;
     adap->dev.parent = &pdev->dev;
 
+#ifdef CONFIG_OF
+   r = i2c_add_adapter(adap);
+#else
     adap->nr = pdev->id;
     r = i2c_add_numbered_adapter(adap);
+#endif

I would say that doing the #ifdef CONFIG_OF is dangerous here when we are in a mixed OF/platform enviromnent as we're depending on compile time selection.

Quoted 7 lines

I'm also wondering whether we have an of helper macro which takes a pdev and gives you an adapter number either given on pdev->id or -1 for the case when we're using the OF bindings.

It might be worth talking to Grant about setting pdev->id to -1 if we are using an OF device.

As Grant said, that's already done and this hunk is not needed.

Quoted 10 lines

drivers/i2c/busses/i2c-designware.c static int __devinit dw_i2c_probe(struct platform_device *pdev) · line 784

Quoted 5 lines
drivers/i2c/busses/i2c-designware.c +1 -0
     if (r) {
             dev_err(&pdev->dev, "failure adding adapter\n");
             goto err_free_irq;
     }
+   of_i2c_register_devices(adap);

If we did that, we could add a of_i2c_register_adapter() call which would take the platform device and then do the of_i2c_register_devices() and do these steps.

Quoted 7 lines

Better yet, how about putting of_i2c_register_devices into i2c_register_adapter? Everywhere that calls of_i2c_register_devices is preceded by a call to i2c_add_numbered_adapter or i2c_add_adapter. It seems logical to put it with i2c_scan_static_board_info. I'll prepare a patch to add that and remove all the other callers unless you think that's a bad idea.

Quoted 3 lines

Nevermind. That would be undoing this commit:

   of/i2c: Fix module load order issue caused by of_i2c.c

The other alternative would be to move the i2c dt parsing code into drivers/i2c. I'm already planning to do that for spi and gpio dt parsing code.

g.