Skip to content

Commit 73febd7

Browse files
Wolfram Sangwsakernel
authored andcommitted
i2c: create debugfs entry per adapter
Two drivers already implement custom debugfs handling for their i2c_adapter and more will come. So, let the core create a debugfs directory per adapter and pass that to drivers for their debugfs files. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Wolfram Sang <wsa@kernel.org>
1 parent f79ad78 commit 73febd7

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

drivers/i2c/i2c-core-base.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/acpi.h>
1717
#include <linux/clk/clk-conf.h>
1818
#include <linux/completion.h>
19+
#include <linux/debugfs.h>
1920
#include <linux/delay.h>
2021
#include <linux/err.h>
2122
#include <linux/errno.h>
@@ -67,6 +68,8 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver);
6768
static DEFINE_STATIC_KEY_FALSE(i2c_trace_msg_key);
6869
static bool is_registered;
6970

71+
static struct dentry *i2c_debugfs_root;
72+
7073
int i2c_transfer_trace_reg(void)
7174
{
7275
static_branch_inc(&i2c_trace_msg_key);
@@ -1524,6 +1527,8 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
15241527
goto out_list;
15251528
}
15261529

1530+
adap->debugfs = debugfs_create_dir(dev_name(&adap->dev), i2c_debugfs_root);
1531+
15271532
res = i2c_setup_smbus_alert(adap);
15281533
if (res)
15291534
goto out_reg;
@@ -1563,6 +1568,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
15631568
return 0;
15641569

15651570
out_reg:
1571+
debugfs_remove_recursive(adap->debugfs);
15661572
init_completion(&adap->dev_released);
15671573
device_unregister(&adap->dev);
15681574
wait_for_completion(&adap->dev_released);
@@ -1764,6 +1770,8 @@ void i2c_del_adapter(struct i2c_adapter *adap)
17641770

17651771
i2c_host_notify_irq_teardown(adap);
17661772

1773+
debugfs_remove_recursive(adap->debugfs);
1774+
17671775
/* wait until all references to the device are gone
17681776
*
17691777
* FIXME: This is old code and should ideally be replaced by an
@@ -2061,6 +2069,8 @@ static int __init i2c_init(void)
20612069

20622070
is_registered = true;
20632071

2072+
i2c_debugfs_root = debugfs_create_dir("i2c", NULL);
2073+
20642074
#ifdef CONFIG_I2C_COMPAT
20652075
i2c_adapter_compat_class = class_compat_register("i2c-adapter");
20662076
if (!i2c_adapter_compat_class) {
@@ -2099,6 +2109,7 @@ static void __exit i2c_exit(void)
20992109
#ifdef CONFIG_I2C_COMPAT
21002110
class_compat_unregister(i2c_adapter_compat_class);
21012111
#endif
2112+
debugfs_remove_recursive(i2c_debugfs_root);
21022113
bus_unregister(&i2c_bus_type);
21032114
tracepoint_synchronize_unregister();
21042115
}

include/linux/i2c.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ struct i2c_adapter {
746746

747747
struct irq_domain *host_notify_domain;
748748
struct regulator *bus_regulator;
749+
750+
struct dentry *debugfs;
749751
};
750752
#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
751753

0 commit comments

Comments
 (0)