Skip to contentSkip to conversation

i2c: core: Move client towards fwnode

PATCH Superseded Andy Shevchenko 3 participants 13 messages Apr 7, 2025

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover i2c: core: Move client towards fwnode

The struct i2c_board_info has of_node and fwnode members. This is quite confusing as they are of the same semantics and it's tend to have an issue if user assigns both. Luckily there is only a single driver that does this and fix was sent today. Nevertheless the series moves the client handling code to use fwnode and deprecates the of_node member in the respective documentation.

Tomi, can you test this series + the patch we discussed earlier so it works as expected?

In v2:
- covered i2c-core-slave.c where it makes sense
- covered i2c-core-of.c where it makes sense
- rebased on top of the latest code base

Andy Shevchenko (6):
i2c: core: Drop duplicate check before calling OF APIs
i2c: core: Unify the firmware node type check
i2c: core: Switch to fwnode APIs to get IRQ
i2c: core: Reuse fwnode variable where it makes sense
i2c: core: Do not dereference fwnode in struct device
i2c: core: Deprecate of_node in struct i2c_board_info

 drivers/i2c/i2c-core-base.c  | 59 ++++++++++++++++++------------------
 drivers/i2c/i2c-core-of.c    |  1 -
 drivers/i2c/i2c-core-slave.c | 11 ++++---
 include/linux/i2c.h          |  2 +-
 4 files changed, 37 insertions(+), 36 deletions(-)
Signature · 1 line
2.47.2
#1 lore raw

PATCH v2 1/6 i2c: core: Drop duplicate check before calling OF APIs

OF APIs are usually NULL-aware and returns an error in case when device node is not present or supported. We already have a check for the returned value, no need to check for the parameter.

---
 drivers/i2c/i2c-core-base.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)
drivers/i2c/i2c-core-base.c +7 -11
index 7ad1ad5c8c3f..c14ffd6190d3 100644
@@ -1209,11 +1209,9 @@ struct i2c_client *i2c_new_ancillary_device(struct i2c_client *client,
 	u32 addr = default_addr;
 	int i;
 
-	if (np) {
-		i = of_property_match_string(np, "reg-names", name);
-		if (i >= 0)
-			of_property_read_u32_index(np, "reg", i, &addr);
-	}
+	i = of_property_match_string(np, "reg-names", name);
+	if (i >= 0)
+		of_property_read_u32_index(np, "reg", i, &addr);
 
 	dev_dbg(&client->adapter->dev, "Address for %s : 0x%x\n", name, addr);
 	return i2c_new_dummy_device(client->adapter, addr);
@@ -1651,12 +1649,10 @@ int i2c_add_adapter(struct i2c_adapter *adapter)
 	struct device *dev = &adapter->dev;
 	int id;
 
-	if (dev->of_node) {
-		id = of_alias_get_id(dev->of_node, "i2c");
-		if (id >= 0) {
-			adapter->nr = id;
-			return __i2c_add_numbered_adapter(adapter);
-		}
+	id = of_alias_get_id(dev->of_node, "i2c");
+	if (id >= 0) {
+		adapter->nr = id;
+		return __i2c_add_numbered_adapter(adapter);
 	}
 
 	mutex_lock(&core_lock);
Signature · 1 line
2.47.2
#2 lore raw

PATCH v2 2/6 i2c: core: Unify the firmware node type check

In reply to Andy Shevchenko

OF and ACPI currently are using asymmetrical APIs to check for the firmware node type. Unify them by using is_*_node() against struct fwnode_handle pointer.

---
 drivers/i2c/i2c-core-base.c  | 14 ++++++++------
 drivers/i2c/i2c-core-slave.c | 11 +++++++----
 2 files changed, 15 insertions(+), 10 deletions(-)
drivers/i2c/i2c-core-base.c +8 -6
index c14ffd6190d3..edab56e5d5e5 100644
@@ -490,6 +490,7 @@ static int i2c_smbus_host_notify_to_irq(const struct i2c_client *client)
 
 static int i2c_device_probe(struct device *dev)
 {
+	struct fwnode_handle	*fwnode = dev_fwnode(dev);
 	struct i2c_client	*client = i2c_verify_client(dev);
 	struct i2c_driver	*driver;
 	bool do_power_on;
@@ -508,11 +509,11 @@ static int i2c_device_probe(struct device *dev)
 			/* Keep adapter active when Host Notify is required */
 			pm_runtime_get_sync(&client->adapter->dev);
 			irq = i2c_smbus_host_notify_to_irq(client);
-		} else if (dev->of_node) {
+		} else if (is_of_node(fwnode)) {
 			irq = of_irq_get_byname(dev->of_node, "irq");
 			if (irq == -EINVAL || irq == -ENODATA)
 				irq = of_irq_get(dev->of_node, 0);
-		} else if (ACPI_COMPANION(dev)) {
+		} else if (is_acpi_device_node(fwnode)) {
 			bool wake_capable;
 
 			irq = i2c_acpi_get_irq(client, &wake_capable);
@@ -1054,15 +1055,16 @@ EXPORT_SYMBOL_GPL(i2c_new_client_device);
  */
 void i2c_unregister_device(struct i2c_client *client)
 {
+	struct fwnode_handle *fwnode;
+
 	if (IS_ERR_OR_NULL(client))
 		return;
 
-	if (client->dev.of_node) {
+	fwnode = dev_fwnode(&client->dev);
+	if (is_of_node(fwnode)) {
 		of_node_clear_flag(client->dev.of_node, OF_POPULATED);
 		of_node_put(client->dev.of_node);
-	}
-
-	if (ACPI_COMPANION(&client->dev))
+	} else if (is_acpi_device_node(fwnode))
 		acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev));
 
 	device_remove_software_node(&client->dev);
drivers/i2c/i2c-core-slave.c +7 -4
index faefe1dfa8e5..3c5cb61b8c39 100644
@@ -11,6 +11,7 @@
 #include <linux/err.h>
 #include <linux/i2c.h>
 #include <linux/of.h>
+#include <linux/property.h>
 
 #include "i2c-core.h"
 
@@ -108,15 +109,17 @@ EXPORT_SYMBOL_GPL(i2c_slave_event);
  */
 bool i2c_detect_slave_mode(struct device *dev)
 {
-	if (IS_BUILTIN(CONFIG_OF) && dev->of_node) {
+	struct fwnode_handle *fwnode = dev_fwnode(dev);
+
+	if (is_of_node(fwnode)) {
 		u32 reg;
 
-		for_each_child_of_node_scoped(dev->of_node, child) {
-			of_property_read_u32(child, "reg", &reg);
+		for_each_child_node_scoped(fwnode, child) {
+			fwnode_property_read_u32(child, "reg", &reg);
 			if (reg & I2C_OWN_SLAVE_ADDRESS)
 				return true;
 		}
-	} else if (IS_BUILTIN(CONFIG_ACPI) && ACPI_HANDLE(dev)) {
+	} else if (is_acpi_device_node(fwnode)) {
 		dev_dbg(dev, "ACPI slave is not supported yet\n");
 	}
 	return false;
Signature · 1 line
2.47.2
#3 lore raw

Re: [PATCH v2 2/6] i2c: core: Unify the firmware node type check

kernel test robot noticed the following build errors:

Hi Andy,

kernel test robot noticed the following build errors:

[auto build test ERROR on wsa/i2c/for-next]
[also build test ERROR on linus/master v6.15-rc1 next-20250407] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/i2c-core-Drop-duplicate-check-before-calling-OF-APIs/20250407-180528
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
patch link:    https://lore.kernel.org/r/20250407095852.215809-3-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v2 2/6] i2c: core: Unify the firmware node type check
config: arc-randconfig-002-20250407 (https://download.01.org/0day-ci/archive/20250407/[email protected]/config)
compiler: arc-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250407/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

drivers/i2c/i2c-core-slave.c: In function 'i2c_detect_slave_mode':

>> drivers/i2c/i2c-core-slave.c:117:17: error: implicit declaration of function 'for_each_child_node_scoped'; did you mean 'for_each_child_of_node_scoped'? [-Wimplicit-function-declaration]
     117 |                 for_each_child_node_scoped(fwnode, child) {
         |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~
         |                 for_each_child_of_node_scoped
>> drivers/i2c/i2c-core-slave.c:117:52: error: 'child' undeclared (first use in this function)
     117 |                 for_each_child_node_scoped(fwnode, child) {
         |                                                    ^~~~~
   drivers/i2c/i2c-core-slave.c:117:52: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/i2c/i2c-core-slave.c:117:58: error: expected ';' before '{' token
     117 |                 for_each_child_node_scoped(fwnode, child) {
         |                                                          ^~
         |                                                          ;
>> drivers/i2c/i2c-core-slave.c:115:21: warning: unused variable 'reg' [-Wunused-variable]
     115 |                 u32 reg;
         |                     ^~~

vim +117 drivers/i2c/i2c-core-slave.c

    97	
    98	/**
    99	 * i2c_detect_slave_mode - detect operation mode
   100	 * @dev: The device owning the bus
   101	 *
   102	 * This checks the device nodes for an I2C slave by checking the address
   103	 * used in the reg property. If the address match the I2C_OWN_SLAVE_ADDRESS
   104	 * flag this means the device is configured to act as a I2C slave and it will
   105	 * be listening at that address.
   106	 *
   107	 * Returns true if an I2C own slave address is detected, otherwise returns
   108	 * false.
   109	 */
   110	bool i2c_detect_slave_mode(struct device *dev)
   111	{
   112		struct fwnode_handle *fwnode = dev_fwnode(dev);
   113	
   114		if (is_of_node(fwnode)) {
 > 115			u32 reg;
   116	
 > 117			for_each_child_node_scoped(fwnode, child) {
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw

Re: [PATCH v2 2/6] i2c: core: Unify the firmware node type check

Quoted 18 lines · kernel test robot

Hi Andy,

kernel test robot noticed the following build errors:

[auto build test ERROR on wsa/i2c/for-next]
[also build test ERROR on linus/master v6.15-rc1 next-20250407] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/i2c-core-Drop-duplicate-check-before-calling-OF-APIs/20250407-180528
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
patch link:    https://lore.kernel.org/r/20250407095852.215809-3-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v2 2/6] i2c: core: Unify the firmware node type check
config: arc-randconfig-002-20250407 (https://download.01.org/0day-ci/archive/20250407/[email protected]/config)
compiler: arc-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250407/[email protected]/reproduce)
Quoted 7 lines

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

Ah, I should compile-test the slave part as well...
Will be fixed in v3. Since v3 is required, Tomi, I'm going to add the media patch to its end.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

Re: [PATCH v2 2/6] i2c: core: Unify the firmware node type check

In reply to Andy Shevchenko
kernel test robot noticed the following build errors:

Hi Andy,

kernel test robot noticed the following build errors:

[auto build test ERROR on wsa/i2c/for-next]
[also build test ERROR on linus/master v6.15-rc1 next-20250407] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/i2c-core-Drop-duplicate-check-before-calling-OF-APIs/20250407-180528
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
patch link:    https://lore.kernel.org/r/20250407095852.215809-3-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v2 2/6] i2c: core: Unify the firmware node type check
config: arm-randconfig-002-20250407 (https://download.01.org/0day-ci/archive/20250407/[email protected]/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 92c93f5286b9ff33f27ff694d2dc33da1c07afdd)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250407/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/i2c/i2c-core-slave.c:117:3: error: call to undeclared function 'for_each_child_node_scoped'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     117 |                 for_each_child_node_scoped(fwnode, child) {
         |                 ^
>> drivers/i2c/i2c-core-slave.c:117:44: error: expected ';' after expression
     117 |                 for_each_child_node_scoped(fwnode, child) {
         |                                                          ^
         |                                                          ;
>> drivers/i2c/i2c-core-slave.c:117:38: error: use of undeclared identifier 'child'; did you mean 'ihold'?
     117 |                 for_each_child_node_scoped(fwnode, child) {
         |                                                    ^~~~~
         |                                                    ihold
   include/linux/fs.h:2758:13: note: 'ihold' declared here
    2758 | extern void ihold(struct inode * inode);
         |             ^
   drivers/i2c/i2c-core-slave.c:118:29: error: use of undeclared identifier 'child'; did you mean 'ihold'?
     118 |                         fwnode_property_read_u32(child, "reg", &reg);
         |                                                  ^~~~~
         |                                                  ihold
   include/linux/fs.h:2758:13: note: 'ihold' declared here
    2758 | extern void ihold(struct inode * inode);
         |             ^

4 errors generated.

vim +/for_each_child_node_scoped +117 drivers/i2c/i2c-core-slave.c

    97	
    98	/**
    99	 * i2c_detect_slave_mode - detect operation mode
   100	 * @dev: The device owning the bus
   101	 *
   102	 * This checks the device nodes for an I2C slave by checking the address
   103	 * used in the reg property. If the address match the I2C_OWN_SLAVE_ADDRESS
   104	 * flag this means the device is configured to act as a I2C slave and it will
   105	 * be listening at that address.
   106	 *
   107	 * Returns true if an I2C own slave address is detected, otherwise returns
   108	 * false.
   109	 */
   110	bool i2c_detect_slave_mode(struct device *dev)
   111	{
   112		struct fwnode_handle *fwnode = dev_fwnode(dev);
   113	
   114		if (is_of_node(fwnode)) {
   115			u32 reg;
   116	
 > 117			for_each_child_node_scoped(fwnode, child) {
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#6 lore raw

PATCH v2 3/6 i2c: core: Switch to fwnode APIs to get IRQ

In reply to Andy Shevchenko

Switch to fwnode APIs to get IRQ. In particular this enables a support of the separate wakeup IRQ. The rest is converted just for the sake of consistency and fwnode reuse.

---
 drivers/i2c/i2c-core-base.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/i2c/i2c-core-base.c +3 -4
index edab56e5d5e5..196b29e5924b 100644
@@ -33,7 +33,6 @@
 #include <linux/mutex.h>
 #include <linux/of_device.h>
 #include <linux/of.h>
-#include <linux/of_irq.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/pinctrl/devinfo.h>
 #include <linux/pm_domain.h>
@@ -510,9 +509,9 @@ static int i2c_device_probe(struct device *dev)
 			pm_runtime_get_sync(&client->adapter->dev);
 			irq = i2c_smbus_host_notify_to_irq(client);
 		} else if (is_of_node(fwnode)) {
-			irq = of_irq_get_byname(dev->of_node, "irq");
+			irq = fwnode_irq_get_byname(fwnode, "irq");
 			if (irq == -EINVAL || irq == -ENODATA)
-				irq = of_irq_get(dev->of_node, 0);
+				irq = fwnode_irq_get(fwnode, 0);
 		} else if (is_acpi_device_node(fwnode)) {
 			bool wake_capable;
 
@@ -547,7 +546,7 @@ static int i2c_device_probe(struct device *dev)
 	if (client->flags & I2C_CLIENT_WAKE) {
 		int wakeirq;
 
-		wakeirq = of_irq_get_byname(dev->of_node, "wakeup");
+		wakeirq = fwnode_irq_get_byname(fwnode, "wakeup");
 		if (wakeirq == -EPROBE_DEFER) {
 			status = wakeirq;
 			goto put_sync_adapter;
Signature · 1 line
2.47.2
#7 lore raw

Re: [PATCH v2 3/6] i2c: core: Switch to fwnode APIs to get IRQ

kernel test robot noticed the following build errors:

Hi Andy,

kernel test robot noticed the following build errors:

[auto build test ERROR on wsa/i2c/for-next]
[also build test ERROR on linus/master v6.15-rc1 next-20250407] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/i2c-core-Drop-duplicate-check-before-calling-OF-APIs/20250407-180528
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
patch link:    https://lore.kernel.org/r/20250407095852.215809-4-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v2 3/6] i2c: core: Switch to fwnode APIs to get IRQ
config: i386-buildonly-randconfig-002-20250407 (https://download.01.org/0day-ci/archive/20250407/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250407/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

drivers/i2c/i2c-core-base.c: In function 'i2c_dev_irq_from_resources':

>> drivers/i2c/i2c-core-base.c:911:32: error: implicit declaration of function 'irq_get_irq_data'; did you mean 'irq_set_irq_wake'? [-Werror=implicit-function-declaration]
     911 |                         irqd = irq_get_irq_data(r->start);
         |                                ^~~~~~~~~~~~~~~~
         |                                irq_set_irq_wake
>> drivers/i2c/i2c-core-base.c:911:30: warning: assignment to 'struct irq_data *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     911 |                         irqd = irq_get_irq_data(r->start);
         |                              ^
>> drivers/i2c/i2c-core-base.c:915:25: error: implicit declaration of function 'irqd_set_trigger_type' [-Werror=implicit-function-declaration]
     915 |                         irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/i2c/i2c-core-base.c: In function 'i2c_host_notify_irq_map':
>> drivers/i2c/i2c-core-base.c:1458:9: error: implicit declaration of function 'irq_set_chip_and_handler' [-Werror=implicit-function-declaration]
    1458 |         irq_set_chip_and_handler(virq, &dummy_irq_chip, handle_simple_irq);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/i2c/i2c-core-base.c:1458:41: error: 'dummy_irq_chip' undeclared (first use in this function)
    1458 |         irq_set_chip_and_handler(virq, &dummy_irq_chip, handle_simple_irq);
         |                                         ^~~~~~~~~~~~~~
   drivers/i2c/i2c-core-base.c:1458:41: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/i2c/i2c-core-base.c:1458:57: error: 'handle_simple_irq' undeclared (first use in this function)
    1458 |         irq_set_chip_and_handler(virq, &dummy_irq_chip, handle_simple_irq);
         |                                                         ^~~~~~~~~~~~~~~~~
   drivers/i2c/i2c-core-base.c: In function 'i2c_handle_smbus_host_notify':
>> drivers/i2c/i2c-core-base.c:1508:9: error: implicit declaration of function 'generic_handle_irq_safe' [-Werror=implicit-function-declaration]
    1508 |         generic_handle_irq_safe(irq);
         |         ^~~~~~~~~~~~~~~~~~~~~~~

cc1: some warnings being treated as errors

vim +911 drivers/i2c/i2c-core-base.c

70762abb9f89d97 drivers/i2c/i2c-core.c      Jarkko Nikula   2013-11-14  897  
1d7534b6adcd3e4 drivers/i2c/i2c-core-base.c Charles Keepax  2019-06-27  898  int i2c_dev_irq_from_resources(const struct resource *resources,
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  899  			       unsigned int num_resources)
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  900  {
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  901  	struct irq_data *irqd;
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  902  	int i;
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  903  
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  904  	for (i = 0; i < num_resources; i++) {
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  905  		const struct resource *r = &resources[i];
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  906  
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  907  		if (resource_type(r) != IORESOURCE_IRQ)
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  908  			continue;
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  909  
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  910  		if (r->flags & IORESOURCE_BITS) {
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01 @911  			irqd = irq_get_irq_data(r->start);
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  912  			if (!irqd)
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  913  				break;
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  914  
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01 @915  			irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  916  		}
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  917  
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  918  		return r->start;
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  919  	}
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  920  
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  921  	return 0;
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  922  }
4124c4eba40256b drivers/i2c/i2c-core.c      Dmitry Torokhov 2017-03-01  923  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#8 lore raw

PATCH v2 4/6 i2c: core: Reuse fwnode variable where it makes sense

In reply to Andy Shevchenko

Reuse fwnode variable where it makes sense. This avoids unneeded duplication hidden in some macros and unifies the code for different types of fwnode.

---
 drivers/i2c/i2c-core-base.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/i2c/i2c-core-base.c +3 -3
index 196b29e5924b..a0d3aec6c00e 100644
@@ -567,7 +567,7 @@ static int i2c_device_probe(struct device *dev)
 
 	dev_dbg(dev, "probe\n");
 
-	status = of_clk_set_defaults(dev->of_node, false);
+	status = of_clk_set_defaults(to_of_node(fwnode), false);
 	if (status < 0)
 		goto err_clear_wakeup_irq;
 
@@ -1061,10 +1061,10 @@ void i2c_unregister_device(struct i2c_client *client)
 
 	fwnode = dev_fwnode(&client->dev);
 	if (is_of_node(fwnode)) {
-		of_node_clear_flag(client->dev.of_node, OF_POPULATED);
+		of_node_clear_flag(to_of_node(fwnode), OF_POPULATED);
 		of_node_put(client->dev.of_node);
 	} else if (is_acpi_device_node(fwnode))
-		acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev));
+		acpi_device_clear_enumerated(to_acpi_device_node(fwnode));
 
 	device_remove_software_node(&client->dev);
 	device_unregister(&client->dev);
Signature · 1 line
2.47.2
#9 lore raw

PATCH v2 5/6 i2c: core: Do not dereference fwnode in struct device

In reply to Andy Shevchenko

In order to make the underneath API easier to change in the future, prevent users from dereferencing fwnode from struct device. Instead, use the specific device_set_node() API for that.

---
 drivers/i2c/i2c-core-base.c | 18 ++++++++++--------
 drivers/i2c/i2c-core-of.c   |  1 -
 2 files changed, 10 insertions(+), 9 deletions(-)
drivers/i2c/i2c-core-base.c +10 -8
index a0d3aec6c00e..c0df67619364 100644
@@ -961,6 +961,7 @@ static void i2c_unlock_addr(struct i2c_adapter *adap, unsigned short addr,
 struct i2c_client *
 i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
 {
+	struct fwnode_handle *fwnode;
 	struct i2c_client *client;
 	bool need_put = false;
 	int status;
@@ -1001,18 +1002,19 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf
 	client->dev.parent = &client->adapter->dev;
 	client->dev.bus = &i2c_bus_type;
 	client->dev.type = &i2c_client_type;
-	client->dev.of_node = of_node_get(info->of_node);
-	client->dev.fwnode = info->fwnode;
 
 	device_enable_async_suspend(&client->dev);
 
+	fwnode = info->fwnode ?: of_fwnode_handle(info->of_node);
+	device_set_node(&client->dev, fwnode_handle_get(fwnode));
+
 	if (info->swnode) {
 		status = device_add_software_node(&client->dev, info->swnode);
 		if (status) {
 			dev_err(&adap->dev,
 				"Failed to add software node to client %s: %d\n",
 				client->name, status);
-			goto out_err_put_of_node;
+			goto out_err_put_fwnode;
 		}
 	}
 
@@ -1031,8 +1033,8 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf
 out_remove_swnode:
 	device_remove_software_node(&client->dev);
 	need_put = true;
-out_err_put_of_node:
-	of_node_put(info->of_node);
+out_err_put_fwnode:
+	fwnode_handle_put(fwnode);
 out_err:
 	dev_err(&adap->dev,
 		"Failed to register i2c client %s at 0x%02x (%d)\n",
@@ -1060,11 +1062,11 @@ void i2c_unregister_device(struct i2c_client *client)
 		return;
 
 	fwnode = dev_fwnode(&client->dev);
-	if (is_of_node(fwnode)) {
+	if (is_of_node(fwnode))
 		of_node_clear_flag(to_of_node(fwnode), OF_POPULATED);
-		of_node_put(client->dev.of_node);
-	} else if (is_acpi_device_node(fwnode))
+	else if (is_acpi_device_node(fwnode))
 		acpi_device_clear_enumerated(to_acpi_device_node(fwnode));
+	fwnode_handle_put(fwnode);
 
 	device_remove_software_node(&client->dev);
 	device_unregister(&client->dev);
drivers/i2c/i2c-core-of.c +0 -1
index 02feee6c9ba9..eb7fb202355f 100644
@@ -49,7 +49,6 @@ int of_i2c_get_board_info(struct device *dev, struct device_node *node,
 	}
 
 	info->addr = addr;
-	info->of_node = node;
 	info->fwnode = of_fwnode_handle(node);
 
 	if (of_property_read_bool(node, "host-notify"))
Signature · 1 line
2.47.2
#10 lore raw

PATCH v2 6/6 i2c: core: Deprecate of_node in struct i2c_board_info

In reply to Andy Shevchenko

Two members of the same or similar semantics is quite confusing to begin with. Moreover, the fwnode covers all possible firmware descriptions that Linux kernel supports. Deprecate of_node in struct i2c_board_info, so users will be warned and in the future remote it completely.

---
 include/linux/i2c.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/i2c.h +1 -1
index 2e4903b7f7bc..cc1437f29823 100644
@@ -405,7 +405,7 @@ static inline bool i2c_detect_slave_mode(struct device *dev) { return false; }
  * @addr: stored in i2c_client.addr
  * @dev_name: Overrides the default <busnr>-<addr> dev_name if set
  * @platform_data: stored in i2c_client.dev.platform_data
- * @of_node: pointer to OpenFirmware device node
+ * @of_node: **DEPRECATED** - use @fwnode for this
  * @fwnode: device node supplied by the platform firmware
  * @swnode: software node for the device
  * @resources: resources associated with the device
Signature · 1 line
2.47.2
Tested-by on the v2 series
#11 lore raw
In reply to Andy Shevchenko

Hi Andy,

Quoted 9 lines · Andy Shevchenko

The struct i2c_board_info has of_node and fwnode members. This is quite confusing as they are of the same semantics and it's tend to have an issue if user assigns both. Luckily there is only a single driver that does this and fix was sent today. Nevertheless the series moves the client handling code to use fwnode and deprecates the of_node member in the respective documentation.

Tomi, can you test this series + the patch we discussed earlier so it works as expected?

I tested this series, and then tested this series + "[PATCH v1 1/1] media: i2c: ds90ub960: Remove of_node assignment". I didn't see anything amiss in either case.

I assume the ds90ub960 patch is the "single driver that does this and fix was sent today"? If so, I think that patch could have been included in this series as well, there's hardly a chance of conflicts with the one liner. And if applied separately, we probably need to apply the ub960 patch one kernel version later than this series.

Tomi

Quoted 20 lines

In v2:
- covered i2c-core-slave.c where it makes sense
- covered i2c-core-of.c where it makes sense
- rebased on top of the latest code base

Andy Shevchenko (6):
i2c: core: Drop duplicate check before calling OF APIs
i2c: core: Unify the firmware node type check
i2c: core: Switch to fwnode APIs to get IRQ
i2c: core: Reuse fwnode variable where it makes sense
i2c: core: Do not dereference fwnode in struct device
i2c: core: Deprecate of_node in struct i2c_board_info

  drivers/i2c/i2c-core-base.c  | 59 ++++++++++++++++++------------------
  drivers/i2c/i2c-core-of.c    |  1 -
  drivers/i2c/i2c-core-slave.c | 11 ++++---
  include/linux/i2c.h          |  2 +-
  4 files changed, 37 insertions(+), 36 deletions(-)
#12 lore raw
Quoted 8 lines · Tomi Valkeinen
Quoted 7 lines · Andy Shevchenko

The struct i2c_board_info has of_node and fwnode members. This is quite confusing as they are of the same semantics and it's tend to have an issue if user assigns both. Luckily there is only a single driver that does this and fix was sent today. Nevertheless the series moves the client handling code to use fwnode and deprecates the of_node member in the respective documentation.

Quoted 8 lines
Quoted 2 lines

Tomi, can you test this series + the patch we discussed earlier so it works as expected?

I tested this series, and then tested this series + "[PATCH v1 1/1] media:
i2c: ds90ub960: Remove of_node assignment". I didn't see anything amiss in either case.

Thank you very much for the testing!

Quoted 5 lines

I assume the ds90ub960 patch is the "single driver that does this and fix was sent today"? If so, I think that patch could have been included in this series as well, there's hardly a chance of conflicts with the one liner. And if applied separately, we probably need to apply the ub960 patch one kernel version later than this series.

Yeah, I forgot to update the cover letter to point to that one out. I agree on everything you said above. But let's wait a bit for Wolfram to comment on / apply this first. It would be nice to have it in, so we prevent new ambiguous users from appearing.

Signature · 2 lines
With Best Regards,
Andy Shevchenko