]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
i2c: core: Unify the firmware node type check
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Wed, 16 Apr 2025 07:01:32 +0000 (10:01 +0300)
committerWolfram Sang <wsa+renesas@sang-engineering.com>
Wed, 16 Apr 2025 16:05:47 +0000 (18:05 +0200)
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.

Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
drivers/i2c/i2c-core-base.c
drivers/i2c/i2c-core-slave.c

index c14ffd6190d3343c1e0888e6631d07a37088d4af..2b5236b726af390b087175ca67103291e21ce8bc 100644 (file)
@@ -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,16 +1055,18 @@ 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);
        device_unregister(&client->dev);
index faefe1dfa8e55b14d6179883937aa81cb72717b5..7ee6b992b835f5be0a7f2c15c075ab50af0628e2 100644 (file)
@@ -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,18 @@ 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)) {
+               struct fwnode_handle *child __free(fwnode_handle) = NULL;
                u32 reg;
 
-               for_each_child_of_node_scoped(dev->of_node, child) {
-                       of_property_read_u32(child, "reg", &reg);
+               fwnode_for_each_child_node(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;