Skip to contentSkip to conversation

Move OF i2c functions into i2c core

PATCH In review Rob Herring 3 participants 11 messages Aug 5, 2011 – Sep 2, 2011

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

cover Move OF i2c functions into i2c core

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

As suggested by Grant, this series moves OF i2c functions in of_i2c.c into i2c-core.c. This simplifies OF i2c drivers slightly. Combining the functions is necessary to avoid a module circular dependency between i2c-core.ko and of_i2c.ko.

Compile tested on ARM (DT/non-DT VExpress) and PowerPC (8xxx and 44x).

Rob

Rob Herring (3):
i2c: move of_i2c_register_devices call into core
i2c: move OF i2c related functions into i2c core
i2c-designware: add OF binding support

 Documentation/devicetree/bindings/i2c/dw-i2c.txt |   23 +++++
 arch/powerpc/platforms/44x/warp.c                |    1 -
 drivers/i2c/busses/i2c-cpm.c                     |    6 --
 drivers/i2c/busses/i2c-designware.c              |    8 ++
 drivers/i2c/busses/i2c-ibm_iic.c                 |    4 -
 drivers/i2c/busses/i2c-mpc.c                     |    2 -
 drivers/i2c/busses/i2c-pxa.c                     |    2 -
 drivers/i2c/busses/i2c-tegra.c                   |    3 -
 drivers/i2c/i2c-core.c                           |   87 +++++++++++++++++++-
 drivers/of/Makefile                              |    1 -
 drivers/of/of_i2c.c                              |   97 ----------------------
 include/linux/i2c.h                              |    4 +
 include/linux/of_i2c.h                           |   30 -------
 13 files changed, 121 insertions(+), 147 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/i2c/dw-i2c.txt
 delete mode 100644 drivers/of/of_i2c.c
 delete mode 100644 include/linux/of_i2c.h
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/3 i2c: move of_i2c_register_devices call into core

From: Rob Herring <[email protected]>

All callers of of_i2c_register_devices are immediately preceded by a call to i2c_add_adapter or i2c_add_numbered_adapter. Add call to of_i2c_register_devices and remove all other callers.

This causes a module dependency loop that is resolved by the next commit.

Cc Grant Likely <[email protected]>
Cc Jochen Friedrich <[email protected]>
Cc Jean Delvare <[email protected]>
Cc Ben Dooks <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
Cc Dirk Brandewie <[email protected]>
Cc Stephen Warren <[email protected]>
---
 drivers/i2c/busses/i2c-cpm.c     |    6 ------
 drivers/i2c/busses/i2c-ibm_iic.c |    4 ----
 drivers/i2c/busses/i2c-mpc.c     |    2 --
 drivers/i2c/busses/i2c-pxa.c     |    2 --
 drivers/i2c/busses/i2c-tegra.c   |    3 ---
 drivers/i2c/i2c-core.c           |    4 ++++
 6 files changed, 4 insertions(+), 17 deletions(-)
drivers/i2c/busses/i2c-cpm.c +0 -6
index b1d9cd2..7cbc82a 100644
@@ -42,7 +42,6 @@
 #include <linux/dma-mapping.h>
 #include <linux/of_device.h>
 #include <linux/of_platform.h>
-#include <linux/of_i2c.h>
 #include <sysdev/fsl_soc.h>
 #include <asm/cpm.h>
 
@@ -673,11 +672,6 @@ static int __devinit cpm_i2c_probe(struct platform_device *ofdev)
 	dev_dbg(&ofdev->dev, "hw routines for %s registered.\n",
 		cpm->adap.name);
 
-	/*
-	 * register OF I2C devices
-	 */
-	of_i2c_register_devices(&cpm->adap);
-
 	return 0;
 out_shut:
 	cpm_i2c_shutdown(cpm);
drivers/i2c/busses/i2c-ibm_iic.c +0 -4
index 3c110fb..5ba15ba 100644
@@ -42,7 +42,6 @@
 #include <linux/io.h>
 #include <linux/i2c.h>
 #include <linux/of_platform.h>
-#include <linux/of_i2c.h>
 
 #include "i2c-ibm_iic.h"
 
@@ -759,9 +758,6 @@ static int __devinit iic_probe(struct platform_device *ofdev)
 	dev_info(&ofdev->dev, "using %s mode\n",
 		 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)");
 
-	/* Now register all the child nodes */
-	of_i2c_register_devices(adap);
-
 	return 0;
 
 error_cleanup:
drivers/i2c/busses/i2c-mpc.c +0 -2
index 107397a..a433f59 100644
@@ -18,7 +18,6 @@
 #include <linux/sched.h>
 #include <linux/init.h>
 #include <linux/of_platform.h>
-#include <linux/of_i2c.h>
 #include <linux/slab.h>
 
 #include <linux/io.h>
@@ -637,7 +636,6 @@ static int __devinit fsl_i2c_probe(struct platform_device *op)
 		dev_err(i2c->dev, "failed to add adapter\n");
 		goto fail_add;
 	}
-	of_i2c_register_devices(&i2c->adap);
 
 	return result;
 
drivers/i2c/busses/i2c-pxa.c +0 -2
index d603646..c1c2885 100644
@@ -29,7 +29,6 @@
 #include <linux/errno.h>
 #include <linux/interrupt.h>
 #include <linux/i2c-pxa.h>
-#include <linux/of_i2c.h>
 #include <linux/platform_device.h>
 #include <linux/err.h>
 #include <linux/clk.h>
@@ -1147,7 +1146,6 @@ static int i2c_pxa_probe(struct platform_device *dev)
 		printk(KERN_INFO "I2C: Failed to add bus\n");
 		goto eadapt;
 	}
-	of_i2c_register_devices(&i2c->adap);
 
 	platform_set_drvdata(dev, i2c);
 
drivers/i2c/busses/i2c-tegra.c +0 -3
index 2440b74..9ec0a58 100644
@@ -26,7 +26,6 @@
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/i2c-tegra.h>
-#include <linux/of_i2c.h>
 
 #include <asm/unaligned.h>
 
@@ -653,8 +652,6 @@ static int tegra_i2c_probe(struct platform_device *pdev)
 		goto err_free_irq;
 	}
 
-	of_i2c_register_devices(&i2c_dev->adapter);
-
 	return 0;
 err_free_irq:
 	free_irq(i2c_dev->irq, i2c_dev);
drivers/i2c/i2c-core.c +4 -0
index 131079a..011e195 100644
@@ -32,6 +32,7 @@
 #include <linux/init.h>
 #include <linux/idr.h>
 #include <linux/mutex.h>
+#include <linux/of_i2c.h>
 #include <linux/of_device.h>
 #include <linux/completion.h>
 #include <linux/hardirq.h>
@@ -863,6 +864,9 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
 	if (adap->nr < __i2c_first_dynamic_bus_num)
 		i2c_scan_static_board_info(adap);
 
+	/* Register devices from the device tree */
+	of_i2c_register_devices(adap);
+
 	/* Notify drivers */
 	mutex_lock(&core_lock);
 	bus_for_each_drv(&i2c_bus_type, NULL, adap, __process_new_adapter);
Signature · 1 line
1.7.4.1
#5 lore raw

PATCH 2/3 i2c: move OF i2c related functions into i2c core

In reply to Rob Herring

From: Rob Herring <[email protected]>

This simplifies i2c drivers by removing calls to of_i2c_register_devices and resolves a module circular dependency between i2c-core and of_i2c.

---
 arch/powerpc/platforms/44x/warp.c |    1 -
 drivers/i2c/i2c-core.c            |   85 +++++++++++++++++++++++++++++++-
 drivers/of/Makefile               |    1 -
 drivers/of/of_i2c.c               |   97 -------------------------------------
 include/linux/i2c.h               |    4 ++
 include/linux/of_i2c.h            |   30 -----------
 6 files changed, 87 insertions(+), 131 deletions(-)
 delete mode 100644 drivers/of/of_i2c.c
 delete mode 100644 include/linux/of_i2c.h
arch/powerpc/platforms/44x/warp.c +0 -1
index 8f77139..9327ccf 100644
@@ -16,7 +16,6 @@
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 #include <linux/of_gpio.h>
-#include <linux/of_i2c.h>
 #include <linux/slab.h>
 
 #include <asm/machdep.h>
drivers/i2c/i2c-core.c +83 -2

103 lines not on this page · raw message

drivers/of/Makefile +0 -1
index dccb117..faa007c 100644
@@ -5,7 +5,6 @@ obj-$(CONFIG_OF_ADDRESS)  += address.o
 obj-$(CONFIG_OF_IRQ)    += irq.o
 obj-$(CONFIG_OF_DEVICE) += device.o platform.o
 obj-$(CONFIG_OF_GPIO)   += gpio.o
-obj-$(CONFIG_OF_I2C)	+= of_i2c.o
 obj-$(CONFIG_OF_NET)	+= of_net.o
 obj-$(CONFIG_OF_SPI)	+= of_spi.o
 obj-$(CONFIG_OF_MDIO)	+= of_mdio.o
drivers/of/of_i2c.c deleted +0 -97

97 lines not on this page · raw message

include/linux/i2c.h +4 -0
index a6c652e..830397b 100644
@@ -468,6 +468,10 @@ static inline int i2c_adapter_id(struct i2c_adapter *adap)
 {
 	return adap->nr;
 }
+
+/* must call put_device() when done with returned i2c_client device */
+extern struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
+
 #endif /* I2C */
 #endif /* __KERNEL__ */
 
include/linux/of_i2c.h deleted +0 -30
deleted file mode 100644
index 0efe8d4..0000000
@@ -1,30 +0,0 @@
-/*
- * Generic I2C API implementation for PowerPC.
- *
- * Copyright (c) 2008 Jochen Friedrich <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef __LINUX_OF_I2C_H
-#define __LINUX_OF_I2C_H
-
-#if defined(CONFIG_OF_I2C) || defined(CONFIG_OF_I2C_MODULE)
-#include <linux/i2c.h>
-
-extern void of_i2c_register_devices(struct i2c_adapter *adap);
-
-/* must call put_device() when done with returned i2c_client device */
-extern struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
-
-#else
-static inline void of_i2c_register_devices(struct i2c_adapter *adap)
-{
-	return;
-}
-#endif /* CONFIG_OF_I2C */
-
-#endif /* __LINUX_OF_I2C_H */
Signature · 1 line
1.7.4.1
#9 lore raw

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

In reply to Rob Herring

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

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

---
 Documentation/devicetree/bindings/i2c/dw-i2c.txt |   23 ++++++++++++++++++++++
 drivers/i2c/busses/i2c-designware.c              |    8 +++++++
 2 files changed, 31 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 +8 -0
index b7a51c4..0223b98 100644
@@ -769,6 +769,7 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev)
 			sizeof(adap->name));
 	adap->algo = &i2c_dw_algo;
 	adap->dev.parent = &pdev->dev;
+	adap->dev.of_node = pdev->dev.of_node;
 
 	adap->nr = pdev->id;
 	r = i2c_add_numbered_adapter(adap);
@@ -819,6 +820,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 +834,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
#2 lore raw

Re: [PATCH 1/3] i2c: move of_i2c_register_devices call into core

In reply to Rob Herring
Quoted 7 lines · Rob Herring

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

All callers of of_i2c_register_devices are immediately preceded by a call to i2c_add_adapter or i2c_add_numbered_adapter. Add call to of_i2c_register_devices and remove all other callers.

This causes a module dependency loop that is resolved by the next commit.

Wrong way around. Don't break bisectability. I'll leave it up to Ben and Jean on weather or not they want to move this code. I intend to do the same thing for spi/gpio, but I maintain those subsystems so I get to choose. i2c is not up to me.

g.

Quoted 152 lines
Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc Jochen Friedrich <[email protected]>
Cc Jean Delvare <[email protected]>
Cc Ben Dooks <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
Cc Dirk Brandewie <[email protected]>
Cc Stephen Warren <[email protected]>
Cc linuxppc-dev-uLR06cmDAlY/[email protected]
---
 drivers/i2c/busses/i2c-cpm.c     |    6 ------
 drivers/i2c/busses/i2c-ibm_iic.c |    4 ----
 drivers/i2c/busses/i2c-mpc.c     |    2 --
 drivers/i2c/busses/i2c-pxa.c     |    2 --
 drivers/i2c/busses/i2c-tegra.c   |    3 ---
 drivers/i2c/i2c-core.c           |    4 ++++
 6 files changed, 4 insertions(+), 17 deletions(-)
drivers/i2c/busses/i2c-cpm.c +0 -6
index b1d9cd2..7cbc82a 100644
@@ -42,7 +42,6 @@
 #include <linux/dma-mapping.h>
 #include <linux/of_device.h>
 #include <linux/of_platform.h>
-#include <linux/of_i2c.h>
 #include <sysdev/fsl_soc.h>
 #include <asm/cpm.h>
 
@@ -673,11 +672,6 @@ static int __devinit cpm_i2c_probe(struct platform_device *ofdev)
 	dev_dbg(&ofdev->dev, "hw routines for %s registered.\n",
 		cpm->adap.name);
 
-	/*
-	 * register OF I2C devices
-	 */
-	of_i2c_register_devices(&cpm->adap);
-
 	return 0;
 out_shut:
 	cpm_i2c_shutdown(cpm);
drivers/i2c/busses/i2c-ibm_iic.c +0 -4
index 3c110fb..5ba15ba 100644
@@ -42,7 +42,6 @@
 #include <linux/io.h>
 #include <linux/i2c.h>
 #include <linux/of_platform.h>
-#include <linux/of_i2c.h>
 
 #include "i2c-ibm_iic.h"
 
@@ -759,9 +758,6 @@ static int __devinit iic_probe(struct platform_device *ofdev)
 	dev_info(&ofdev->dev, "using %s mode\n",
 		 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)");
 
-	/* Now register all the child nodes */
-	of_i2c_register_devices(adap);
-
 	return 0;
 
 error_cleanup:
drivers/i2c/busses/i2c-mpc.c +0 -2
index 107397a..a433f59 100644
@@ -18,7 +18,6 @@
 #include <linux/sched.h>
 #include <linux/init.h>
 #include <linux/of_platform.h>
-#include <linux/of_i2c.h>
 #include <linux/slab.h>
 
 #include <linux/io.h>
@@ -637,7 +636,6 @@ static int __devinit fsl_i2c_probe(struct platform_device *op)
 		dev_err(i2c->dev, "failed to add adapter\n");
 		goto fail_add;
 	}
-	of_i2c_register_devices(&i2c->adap);
 
 	return result;
 
drivers/i2c/busses/i2c-pxa.c +0 -2
index d603646..c1c2885 100644
@@ -29,7 +29,6 @@
 #include <linux/errno.h>
 #include <linux/interrupt.h>
 #include <linux/i2c-pxa.h>
-#include <linux/of_i2c.h>
 #include <linux/platform_device.h>
 #include <linux/err.h>
 #include <linux/clk.h>
@@ -1147,7 +1146,6 @@ static int i2c_pxa_probe(struct platform_device *dev)
 		printk(KERN_INFO "I2C: Failed to add bus\n");
 		goto eadapt;
 	}
-	of_i2c_register_devices(&i2c->adap);
 
 	platform_set_drvdata(dev, i2c);
 
drivers/i2c/busses/i2c-tegra.c +0 -3
index 2440b74..9ec0a58 100644
@@ -26,7 +26,6 @@
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/i2c-tegra.h>
-#include <linux/of_i2c.h>
 
 #include <asm/unaligned.h>
 
@@ -653,8 +652,6 @@ static int tegra_i2c_probe(struct platform_device *pdev)
 		goto err_free_irq;
 	}
 
-	of_i2c_register_devices(&i2c_dev->adapter);
-
 	return 0;
 err_free_irq:
 	free_irq(i2c_dev->irq, i2c_dev);
drivers/i2c/i2c-core.c +4 -0
index 131079a..011e195 100644
@@ -32,6 +32,7 @@
 #include <linux/init.h>
 #include <linux/idr.h>
 #include <linux/mutex.h>
+#include <linux/of_i2c.h>
 #include <linux/of_device.h>
 #include <linux/completion.h>
 #include <linux/hardirq.h>
@@ -863,6 +864,9 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
 	if (adap->nr < __i2c_first_dynamic_bus_num)
 		i2c_scan_static_board_info(adap);
 
+	/* Register devices from the device tree */
+	of_i2c_register_devices(adap);
+
 	/* Notify drivers */
 	mutex_lock(&core_lock);
 	bus_for_each_drv(&i2c_bus_type, NULL, adap, __process_new_adapter);
Signature · 1 line
1.7.4.1
#6 lore raw

Re: [PATCH 2/3] i2c: move OF i2c related functions into i2c core

In reply to Rob Herring
Quoted 58 lines · Rob Herring

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

This simplifies i2c drivers by removing calls to of_i2c_register_devices and resolves a module circular dependency between i2c-core and of_i2c.

Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc Jean Delvare <[email protected]>
Cc Ben Dooks <[email protected]>
---
 arch/powerpc/platforms/44x/warp.c |    1 -
 drivers/i2c/i2c-core.c            |   85 +++++++++++++++++++++++++++++++-
 drivers/of/Makefile               |    1 -
 drivers/of/of_i2c.c               |   97 -------------------------------------
 include/linux/i2c.h               |    4 ++
 include/linux/of_i2c.h            |   30 -----------
 6 files changed, 87 insertions(+), 131 deletions(-)
 delete mode 100644 drivers/of/of_i2c.c
 delete mode 100644 include/linux/of_i2c.h
arch/powerpc/platforms/44x/warp.c +0 -1
index 8f77139..9327ccf 100644
@@ -16,7 +16,6 @@
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 #include <linux/of_gpio.h>
-#include <linux/of_i2c.h>
 #include <linux/slab.h>
 
 #include <asm/machdep.h>
drivers/i2c/i2c-core.c +4 -2
index 011e195..478c7f2 100644
@@ -22,7 +22,10 @@
    SMBus 2.0 support by Mark Studebaker <mdsxyz123-/[email protected]> and
    Jean Delvare <[email protected]>
    Mux support by Rodolfo Giometti <giometti-AVVDYK/kqiJWk0Htik3J/[email protected]> and
-   Michael Lawnick <[email protected]> */
+   Michael Lawnick <[email protected]>
+   OF support by Jochen Friedrich <[email protected]> and
+   Jon Smirl <[email protected]>
+   */
 
 #include <linux/module.h>
 #include <linux/kernel.h>
@@ -32,7 +35,6 @@
 #include <linux/init.h>
 #include <linux/idr.h>
 #include <linux/mutex.h>
-#include <linux/of_i2c.h>
 #include <linux/of_device.h>
 #include <linux/completion.h>
 #include <linux/hardirq.h>

drivers/i2c/i2c-core.c static void i2c_scan_static_board_info(struct i2c_adapter *adapter) · line 795

Quoted 4 lines
drivers/i2c/i2c-core.c +1 -0
@@ -790,6 +792,85 @@ static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
 	up_read(&__i2c_board_lock);
 }
 
+#ifdef CONFIG_OF_I2C

I think this becomes simply "#ifdef CONFIG_OF" since CONFIG_I2C is implied at this point.

include/linux/i2c.h static inline int i2c_adapter_id(struct i2c_adapter *adap) · line 474

Quoted 12 lines
include/linux/i2c.h +4 -0
index a6c652e..830397b 100644
@@ -468,6 +468,10 @@ static inline int i2c_adapter_id(struct i2c_adapter *adap)
 {
 	return adap->nr;
 }
+
+/* must call put_device() when done with returned i2c_client device */
+extern struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
+

This shouldn't be defined if !CONFIG_OF

#7 lore raw

Re: [PATCH 2/3] i2c: move OF i2c related functions into i2c core

Grant,

Quoted 62 lines · Grant Likely
Quoted 61 lines · Rob Herring

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

This simplifies i2c drivers by removing calls to of_i2c_register_devices and resolves a module circular dependency between i2c-core and of_i2c.

Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc Jean Delvare <[email protected]>
Cc Ben Dooks <[email protected]>
---
 arch/powerpc/platforms/44x/warp.c |    1 -
 drivers/i2c/i2c-core.c            |   85 +++++++++++++++++++++++++++++++-
 drivers/of/Makefile               |    1 -
 drivers/of/of_i2c.c               |   97 -------------------------------------
 include/linux/i2c.h               |    4 ++
 include/linux/of_i2c.h            |   30 -----------
 6 files changed, 87 insertions(+), 131 deletions(-)
 delete mode 100644 drivers/of/of_i2c.c
 delete mode 100644 include/linux/of_i2c.h
arch/powerpc/platforms/44x/warp.c +0 -1
index 8f77139..9327ccf 100644
@@ -16,7 +16,6 @@
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 #include <linux/of_gpio.h>
-#include <linux/of_i2c.h>
 #include <linux/slab.h>
 
 #include <asm/machdep.h>
drivers/i2c/i2c-core.c +4 -2
index 011e195..478c7f2 100644
@@ -22,7 +22,10 @@
    SMBus 2.0 support by Mark Studebaker <mdsxyz123-/[email protected]> and
    Jean Delvare <[email protected]>
    Mux support by Rodolfo Giometti <giometti-AVVDYK/kqiJWk0Htik3J/[email protected]> and
-   Michael Lawnick <[email protected]> */
+   Michael Lawnick <[email protected]>
+   OF support by Jochen Friedrich <[email protected]> and
+   Jon Smirl <[email protected]>
+   */
 
 #include <linux/module.h>
 #include <linux/kernel.h>
@@ -32,7 +35,6 @@
 #include <linux/init.h>
 #include <linux/idr.h>
 #include <linux/mutex.h>
-#include <linux/of_i2c.h>
 #include <linux/of_device.h>
 #include <linux/completion.h>
 #include <linux/hardirq.h>
@@ -790,6 +792,85 @@ static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
 	up_read(&__i2c_board_lock);
 }
 
Quoted 3 lines

drivers/i2c/i2c-core.c static void i2c_scan_static_board_info(struct i2c_adapter *adapter) · line 795

Quoted 1 line
drivers/i2c/i2c-core.c +1 -0
+#ifdef CONFIG_OF_I2C

I think this becomes simply "#ifdef CONFIG_OF" since CONFIG_I2C is implied at this point.

I was going to remove CONFIG_OF_I2C altogether, but it depends on !SPARC so I thought it should be kept.

Quoted 15 lines

include/linux/i2c.h static inline int i2c_adapter_id(struct i2c_adapter *adap) · line 474

Quoted 13 lines
include/linux/i2c.h +4 -0
index a6c652e..830397b 100644
@@ -468,6 +468,10 @@ static inline int i2c_adapter_id(struct i2c_adapter *adap)
 {
 	return adap->nr;
 }
+
+/* must call put_device() when done with returned i2c_client device */
+extern struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
+

This shouldn't be defined if !CONFIG_OF

There is no empty version today and externs don't need to be ifdef'ed in that case.

Rob

#3 lore raw

Re: [PATCH 1/3] i2c: move of_i2c_register_devices call into core

In reply to Grant Likely

Grant,

Quoted 7 lines · Grant Likely
Quoted 6 lines · Rob Herring

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

All callers of of_i2c_register_devices are immediately preceded by a call to i2c_add_adapter or i2c_add_numbered_adapter. Add call to of_i2c_register_devices and remove all other callers.

Quoted 7 lines
Quoted 1 line

This causes a module dependency loop that is resolved by the next commit.

Wrong way around. Don't break bisectability. I'll leave it up to Ben and Jean on weather or not they want to move this code. I intend to do the same thing for spi/gpio, but I maintain those subsystems so I get to choose. i2c is not up to me.

Well, I know, but it's only broken for bisect in the case of both being modules. So it's only run-time brokenness. That's better than the 3 months it was broken before. I couldn't come up with a better way. The choices I thought of were:

-temporarily exporting and adding of_i2c_register_devices to i2c.h and then removing it. I'm not a fan of adding that churn.
-just combining it all into 1 patch.
-reverse the order and leave i2c device registration broken for 1 commit. Thinking some more about it, perhaps that is a bit better than broken module loading. Guess it depends if you are doing modules or built-in.

Rob

Quoted 154 lines

g.

Quoted 152 lines
Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc Jochen Friedrich <[email protected]>
Cc Jean Delvare <[email protected]>
Cc Ben Dooks <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
Cc Dirk Brandewie <[email protected]>
Cc Stephen Warren <[email protected]>
Cc linuxppc-dev-uLR06cmDAlY/[email protected]
---
 drivers/i2c/busses/i2c-cpm.c     |    6 ------
 drivers/i2c/busses/i2c-ibm_iic.c |    4 ----
 drivers/i2c/busses/i2c-mpc.c     |    2 --
 drivers/i2c/busses/i2c-pxa.c     |    2 --
 drivers/i2c/busses/i2c-tegra.c   |    3 ---
 drivers/i2c/i2c-core.c           |    4 ++++
 6 files changed, 4 insertions(+), 17 deletions(-)
drivers/i2c/busses/i2c-cpm.c +0 -6
index b1d9cd2..7cbc82a 100644
@@ -42,7 +42,6 @@
 #include <linux/dma-mapping.h>
 #include <linux/of_device.h>
 #include <linux/of_platform.h>
-#include <linux/of_i2c.h>
 #include <sysdev/fsl_soc.h>
 #include <asm/cpm.h>
 
@@ -673,11 +672,6 @@ static int __devinit cpm_i2c_probe(struct platform_device *ofdev)
 	dev_dbg(&ofdev->dev, "hw routines for %s registered.\n",
 		cpm->adap.name);
 
-	/*
-	 * register OF I2C devices
-	 */
-	of_i2c_register_devices(&cpm->adap);
-
 	return 0;
 out_shut:
 	cpm_i2c_shutdown(cpm);
drivers/i2c/busses/i2c-ibm_iic.c +0 -4
index 3c110fb..5ba15ba 100644
@@ -42,7 +42,6 @@
 #include <linux/io.h>
 #include <linux/i2c.h>
 #include <linux/of_platform.h>
-#include <linux/of_i2c.h>
 
 #include "i2c-ibm_iic.h"
 
@@ -759,9 +758,6 @@ static int __devinit iic_probe(struct platform_device *ofdev)
 	dev_info(&ofdev->dev, "using %s mode\n",
 		 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)");
 
-	/* Now register all the child nodes */
-	of_i2c_register_devices(adap);
-
 	return 0;
 
 error_cleanup:
drivers/i2c/busses/i2c-mpc.c +0 -2
index 107397a..a433f59 100644
@@ -18,7 +18,6 @@
 #include <linux/sched.h>
 #include <linux/init.h>
 #include <linux/of_platform.h>
-#include <linux/of_i2c.h>
 #include <linux/slab.h>
 
 #include <linux/io.h>
@@ -637,7 +636,6 @@ static int __devinit fsl_i2c_probe(struct platform_device *op)
 		dev_err(i2c->dev, "failed to add adapter\n");
 		goto fail_add;
 	}
-	of_i2c_register_devices(&i2c->adap);
 
 	return result;
 
drivers/i2c/busses/i2c-pxa.c +0 -2
index d603646..c1c2885 100644
@@ -29,7 +29,6 @@
 #include <linux/errno.h>
 #include <linux/interrupt.h>
 #include <linux/i2c-pxa.h>
-#include <linux/of_i2c.h>
 #include <linux/platform_device.h>
 #include <linux/err.h>
 #include <linux/clk.h>
@@ -1147,7 +1146,6 @@ static int i2c_pxa_probe(struct platform_device *dev)
 		printk(KERN_INFO "I2C: Failed to add bus\n");
 		goto eadapt;
 	}
-	of_i2c_register_devices(&i2c->adap);
 
 	platform_set_drvdata(dev, i2c);
 
drivers/i2c/busses/i2c-tegra.c +0 -3
index 2440b74..9ec0a58 100644
@@ -26,7 +26,6 @@
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/i2c-tegra.h>
-#include <linux/of_i2c.h>
 
 #include <asm/unaligned.h>
 
@@ -653,8 +652,6 @@ static int tegra_i2c_probe(struct platform_device *pdev)
 		goto err_free_irq;
 	}
 
-	of_i2c_register_devices(&i2c_dev->adapter);
-
 	return 0;
 err_free_irq:
 	free_irq(i2c_dev->irq, i2c_dev);
drivers/i2c/i2c-core.c +4 -0
index 131079a..011e195 100644
@@ -32,6 +32,7 @@
 #include <linux/init.h>
 #include <linux/idr.h>
 #include <linux/mutex.h>
+#include <linux/of_i2c.h>
 #include <linux/of_device.h>
 #include <linux/completion.h>
 #include <linux/hardirq.h>
@@ -863,6 +864,9 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
 	if (adap->nr < __i2c_first_dynamic_bus_num)
 		i2c_scan_static_board_info(adap);
 
+	/* Register devices from the device tree */
+	of_i2c_register_devices(adap);
+
 	/* Notify drivers */
 	mutex_lock(&core_lock);
 	bus_for_each_drv(&i2c_bus_type, NULL, adap, __process_new_adapter);
Signature · 1 line
1.7.4.1
#8 lore raw

Re: [PATCH 2/3] i2c: move OF i2c related functions into i2c core

In reply to Rob Herring
Quoted 65 lines · Rob Herring

Grant,

Quoted 62 lines · Grant Likely
Quoted 61 lines · Rob Herring

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

This simplifies i2c drivers by removing calls to of_i2c_register_devices and resolves a module circular dependency between i2c-core and of_i2c.

Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc Jean Delvare <[email protected]>
Cc Ben Dooks <[email protected]>

---
 arch/powerpc/platforms/44x/warp.c |    1 - drivers/i2c/i2c-core.c            |   85 +++++++++++++++++++++++++++++++-

 drivers/of/Makefile               |    1 -
 drivers/of/of_i2c.c               |   97 -------------------------------------
 include/linux/i2c.h               |    4 ++
 include/linux/of_i2c.h            |   30 -----------
 6 files changed, 87 insertions(+), 131 deletions(-)

 delete mode 100644 drivers/of/of_i2c.c
 delete mode 100644 include/linux/of_i2c.h

arch/powerpc/platforms/44x/warp.c +0 -1
index 8f77139..9327ccf 100644
@@ -16,7 +16,6 @@
  #include <linux/interrupt.h>
  #include <linux/delay.h>
  #include <linux/of_gpio.h>
-#include <linux/of_i2c.h>
  #include <linux/slab.h>
 
  #include <asm/machdep.h>
drivers/i2c/i2c-core.c +0 -0
index 011e195..478c7f2 100644
@@ -22,7 +22,10 @@

    SMBus 2.0 support by Mark Studebaker <mdsxyz123-/[email protected]> and Jean Delvare <[email protected]>
    Mux support by Rodolfo Giometti <giometti-AVVDYK/kqiJWk0Htik3J/[email protected]> and
-   Michael Lawnick <[email protected]> */
+   Michael Lawnick <[email protected]>
+   OF support by Jochen Friedrich <[email protected]> and
+   Jon Smirl <[email protected]>
+   */

 #include <linux/module.h>
 #include <linux/kernel.h>

drivers/i2c/i2c-core.c +0 -1
@@ -32,7 +35,6 @@
  #include <linux/init.h>
  #include <linux/idr.h>
  #include <linux/mutex.h>
-#include <linux/of_i2c.h>
  #include <linux/of_device.h>
  #include <linux/completion.h>
  #include <linux/hardirq.h>
@@ -790,6 +792,85 @@ static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
      up_read(&__i2c_board_lock);
  }
 
Quoted 6 lines
Quoted 3 lines

drivers/i2c/i2c-core.c static void i2c_scan_static_board_info(struct i2c_adapter *adapter) · line 795

Quoted 1 line
drivers/i2c/i2c-core.c +1 -0
+#ifdef CONFIG_OF_I2C

I think this becomes simply "#ifdef CONFIG_OF" since CONFIG_I2C is implied at this point.

I was going to remove CONFIG_OF_I2C altogether, but it depends on !SPARC so I thought it should be kept.

Good point. I keep forgetting that SPARC has different behaviour.

g.

#10 lore raw

Re: [PATCH 3/3] i2c-designware: add OF binding support

In reply to Rob Herring

Ben,

Quoted 11 lines · Rob Herring

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

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

---

Any comments on this? If not, will you apply to your tree?

Rob

Quoted 67 lines
 Documentation/devicetree/bindings/i2c/dw-i2c.txt |   23 ++++++++++++++++++++++
 drivers/i2c/busses/i2c-designware.c              |    8 +++++++
 2 files changed, 31 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 +8 -0
index b7a51c4..0223b98 100644
@@ -769,6 +769,7 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev)
 			sizeof(adap->name));
 	adap->algo = &i2c_dw_algo;
 	adap->dev.parent = &pdev->dev;
+	adap->dev.of_node = pdev->dev.of_node;
 
 	adap->nr = pdev->id;
 	r = i2c_add_numbered_adapter(adap);
@@ -819,6 +820,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 +834,7 @@ static struct platform_driver dw_i2c_driver = {
 	.driver		= {
 		.name	= "i2c_designware",
 		.owner	= THIS_MODULE,
+		.of_match_table = dw_i2c_of_match,
 	},
 };
 
#4 lore raw

Re: [PATCH 1/3] i2c: move of_i2c_register_devices call into core

In reply to Rob Herring

Hi Rob, Grant,

Quoted 17 lines · Rob Herring

Grant,

Quoted 7 lines · Grant Likely
Quoted 6 lines · Rob Herring

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

All callers of of_i2c_register_devices are immediately preceded by a call to i2c_add_adapter or i2c_add_numbered_adapter. Add call to of_i2c_register_devices and remove all other callers.

Quoted 6 lines
Quoted 1 line

This causes a module dependency loop that is resolved by the next commit.

Wrong way around. Don't break bisectability. I'll leave it up to Ben and Jean on weather or not they want to move this code. I intend to do the same thing for spi/gpio, but I maintain those subsystems so I get to choose. i2c is not up to me.

Quoted 8 lines

Well, I know, but it's only broken for bisect in the case of both being modules. So it's only run-time brokenness. That's better than the 3 months it was broken before. I couldn't come up with a better way. The choices I thought of were:

-temporarily exporting and adding of_i2c_register_devices to i2c.h and then removing it. I'm not a fan of adding that churn.
-just combining it all into 1 patch.

That would have been the right thing to do, yes. The two patches are not so large, so the resulting merged patch would still be reasonable. There's no point in splitting patches if they can't be applied in sequence, bisected, and rejected, reverted or backported individually; which is clearly not the case here.

But anyway, I don't buy the whole thing. We currently have a nice separation between OF and the underlying bus types. Breaking it all just for the sake of saving one call in 4 drivers (out of ~70 in the current kernel tree) doesn't seem worth it, at all. It would make things harder to maintain, too (I definitely do not want to maintain OF-specific code).

If you are really worried about the extra call to of_i2c_register_devices(), then maybe the of_i2c implementation is incorrect, and you should rework it to build on top of i2c_register_board_info() rather than i2c_new_device().

Quoted 4 lines

-reverse the order and leave i2c device registration broken for 1 commit. Thinking some more about it, perhaps that is a bit better than broken module loading. Guess it depends if you are doing modules or built-in.

Signature · 1 line
Jean Delvare