* [PATCH v1 0/6] i2c: core: Move client towards fwnode
@ 2025-03-12 18:48 Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 1/6] i2c: core: Drop duplicate check before calling OF APIs Andy Shevchenko
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Andy Shevchenko @ 2025-03-12 18:48 UTC (permalink / raw)
To: Wolfram Sang, linux-i2c, linux-kernel; +Cc: 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.
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 | 58 ++++++++++++++++++-------------------
include/linux/i2c.h | 2 +-
2 files changed, 30 insertions(+), 30 deletions(-)
--
2.47.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v1 1/6] i2c: core: Drop duplicate check before calling OF APIs
2025-03-12 18:48 [PATCH v1 0/6] i2c: core: Move client towards fwnode Andy Shevchenko
@ 2025-03-12 18:48 ` Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 2/6] i2c: core: Unify the firmware node type check Andy Shevchenko
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2025-03-12 18:48 UTC (permalink / raw)
To: Wolfram Sang, linux-i2c, linux-kernel; +Cc: Andy Shevchenko
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.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/i2c/i2c-core-base.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 7ad1ad5c8c3f..c14ffd6190d3 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -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);
--
2.47.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 2/6] i2c: core: Unify the firmware node type check
2025-03-12 18:48 [PATCH v1 0/6] i2c: core: Move client towards fwnode Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 1/6] i2c: core: Drop duplicate check before calling OF APIs Andy Shevchenko
@ 2025-03-12 18:48 ` Andy Shevchenko
2025-03-21 18:55 ` Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 3/6] i2c: core: Switch to fwnode APIs to get IRQ Andy Shevchenko
` (3 subsequent siblings)
5 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2025-03-12 18:48 UTC (permalink / raw)
To: Wolfram Sang, linux-i2c, linux-kernel; +Cc: 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.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/i2c/i2c-core-base.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index c14ffd6190d3..edab56e5d5e5 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -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);
--
2.47.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 3/6] i2c: core: Switch to fwnode APIs to get IRQ
2025-03-12 18:48 [PATCH v1 0/6] i2c: core: Move client towards fwnode Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 1/6] i2c: core: Drop duplicate check before calling OF APIs Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 2/6] i2c: core: Unify the firmware node type check Andy Shevchenko
@ 2025-03-12 18:48 ` Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 4/6] i2c: core: Reuse fwnode variable where it makes sense Andy Shevchenko
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2025-03-12 18:48 UTC (permalink / raw)
To: Wolfram Sang, linux-i2c, linux-kernel; +Cc: 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.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/i2c/i2c-core-base.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index edab56e5d5e5..f0420cc0df26 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -510,9 +510,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 +547,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;
--
2.47.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 4/6] i2c: core: Reuse fwnode variable where it makes sense
2025-03-12 18:48 [PATCH v1 0/6] i2c: core: Move client towards fwnode Andy Shevchenko
` (2 preceding siblings ...)
2025-03-12 18:48 ` [PATCH v1 3/6] i2c: core: Switch to fwnode APIs to get IRQ Andy Shevchenko
@ 2025-03-12 18:48 ` Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 5/6] i2c: core: Do not dereference fwnode in struct device Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 6/6] i2c: core: Deprecate of_node in struct i2c_board_info Andy Shevchenko
5 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2025-03-12 18:48 UTC (permalink / raw)
To: Wolfram Sang, linux-i2c, linux-kernel; +Cc: 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.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/i2c/i2c-core-base.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index f0420cc0df26..1236061a78c3 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -568,7 +568,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;
@@ -1062,10 +1062,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);
--
2.47.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 5/6] i2c: core: Do not dereference fwnode in struct device
2025-03-12 18:48 [PATCH v1 0/6] i2c: core: Move client towards fwnode Andy Shevchenko
` (3 preceding siblings ...)
2025-03-12 18:48 ` [PATCH v1 4/6] i2c: core: Reuse fwnode variable where it makes sense Andy Shevchenko
@ 2025-03-12 18:48 ` Andy Shevchenko
2025-03-21 18:57 ` Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 6/6] i2c: core: Deprecate of_node in struct i2c_board_info Andy Shevchenko
5 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2025-03-12 18:48 UTC (permalink / raw)
To: Wolfram Sang, linux-i2c, linux-kernel; +Cc: 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.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/i2c/i2c-core-base.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 1236061a78c3..dba6c5ce9d42 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -962,6 +962,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;
@@ -1002,18 +1003,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;
}
}
@@ -1032,8 +1034,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",
@@ -1061,11 +1063,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);
--
2.47.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 6/6] i2c: core: Deprecate of_node in struct i2c_board_info
2025-03-12 18:48 [PATCH v1 0/6] i2c: core: Move client towards fwnode Andy Shevchenko
` (4 preceding siblings ...)
2025-03-12 18:48 ` [PATCH v1 5/6] i2c: core: Do not dereference fwnode in struct device Andy Shevchenko
@ 2025-03-12 18:48 ` Andy Shevchenko
5 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2025-03-12 18:48 UTC (permalink / raw)
To: Wolfram Sang, linux-i2c, linux-kernel; +Cc: 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.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/i2c.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 2e4903b7f7bc..cc1437f29823 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -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
--
2.47.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v1 2/6] i2c: core: Unify the firmware node type check
2025-03-12 18:48 ` [PATCH v1 2/6] i2c: core: Unify the firmware node type check Andy Shevchenko
@ 2025-03-21 18:55 ` Andy Shevchenko
0 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2025-03-21 18:55 UTC (permalink / raw)
To: Wolfram Sang, linux-i2c, linux-kernel
On Wed, Mar 12, 2025 at 08:48:49PM +0200, Andy Shevchenko wrote:
> 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 ++++++++------
The i2c-core-slave.c can be also modified to follow the same approach.
I'll do that way in v2.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v1 5/6] i2c: core: Do not dereference fwnode in struct device
2025-03-12 18:48 ` [PATCH v1 5/6] i2c: core: Do not dereference fwnode in struct device Andy Shevchenko
@ 2025-03-21 18:57 ` Andy Shevchenko
0 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2025-03-21 18:57 UTC (permalink / raw)
To: Wolfram Sang, linux-i2c, linux-kernel
On Wed, Mar 12, 2025 at 08:48:52PM +0200, Andy Shevchenko wrote:
> 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 ++++++++++--------
This missed i2c-core-of.c changes.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-03-21 18:58 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-12 18:48 [PATCH v1 0/6] i2c: core: Move client towards fwnode Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 1/6] i2c: core: Drop duplicate check before calling OF APIs Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 2/6] i2c: core: Unify the firmware node type check Andy Shevchenko
2025-03-21 18:55 ` Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 3/6] i2c: core: Switch to fwnode APIs to get IRQ Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 4/6] i2c: core: Reuse fwnode variable where it makes sense Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 5/6] i2c: core: Do not dereference fwnode in struct device Andy Shevchenko
2025-03-21 18:57 ` Andy Shevchenko
2025-03-12 18:48 ` [PATCH v1 6/6] i2c: core: Deprecate of_node in struct i2c_board_info Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox