Skip to contentSkip to conversation

hwmon: Add driver for Astera Labs PT5161L retimer

PATCH Superseded Cosmo Chou 3 participants 12 messages Feb 5, 2024 – Feb 6, 2024

Subsystems (3)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Cosmo Chou

author
#0 lore raw

v5 cover hwmon: Add driver for Astera Labs PT5161L retimer

This driver implements support for temperature monitoring of Astera Labs PT5161L series PCIe retimer chips.

v5:
- Fix warning and check messages of 'checkpatch --strict'
- Without resubmitting the applied patches

v4:
- Rebased

v3:
- Revise pt5161l.rst
- Revise the style of comments
- Remove unused pec_enable
- Add back safe access wide registers
- fix build warning

v2:
- Add "asteralabs,pt5161l" to trivial-devices.yaml
- Change naming PT516XX/pt516xx to PT5161L/pt5161l
- Separated debugfs files for health status
- Revise the style of comments
- Remove unused defines
- Remove including unused header files
- Remove unnecessary debugging messages
- Revise the data parsing for a big-endian system
- Use read_block_data instead of accessing wide registers
- Remove the debugfs files when the device is unloaded
- Add acpi_match_table

Cosmo Chou (1):
hwmon: Add driver for Astera Labs PT5161L retimer

 Documentation/hwmon/index.rst   |   1 +
 Documentation/hwmon/pt5161l.rst |  42 ++
 MAINTAINERS                     |   7 +
 drivers/hwmon/Kconfig           |  10 +
 drivers/hwmon/Makefile          |   1 +
 drivers/hwmon/pt5161l.c         | 673 ++++++++++++++++++++++++++++++++
 6 files changed, 734 insertions(+)
 create mode 100644 Documentation/hwmon/pt5161l.rst
 create mode 100644 drivers/hwmon/pt5161l.c
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v5 1/1 hwmon: Add driver for Astera Labs PT5161L retimer

This driver implements support for temperature monitoring of Astera Labs PT5161L series PCIe retimer chips.

This driver implementation originates from the CSDK available at

The communication protocol utilized is based on the I2C/SMBus standard.

---
 Documentation/hwmon/index.rst   |   1 +
 Documentation/hwmon/pt5161l.rst |  42 ++
 MAINTAINERS                     |   7 +
 drivers/hwmon/Kconfig           |  10 +
 drivers/hwmon/Makefile          |   1 +
 drivers/hwmon/pt5161l.c         | 673 ++++++++++++++++++++++++++++++++
 6 files changed, 734 insertions(+)
 create mode 100644 Documentation/hwmon/pt5161l.rst
 create mode 100644 drivers/hwmon/pt5161l.c
Documentation/hwmon/index.rst +1 -0
index c7ed1f73ac06..9f5f215fcb2d 100644
@@ -185,6 +185,7 @@ Hardware Monitoring Kernel Drivers
    pmbus
    powerz
    powr1220
+   pt5161l
    pxe1610
    pwm-fan
    q54sj108a2
Documentation/hwmon/pt5161l.rst new file +42 -0

42 lines not on this page · raw message

MAINTAINERS +7 -0
index 960512bec428..a656b98971ca 100644
@@ -17679,6 +17679,13 @@ F:	fs/pstore/
 F:	include/linux/pstore*
 K:	\b(pstore|ramoops)
 
+PT5161L HARDWARE MONITOR DRIVER
+M:	Cosmo Chou <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/hwmon/pt5161l.rst
+F:	drivers/hwmon/pt5161l.c
+
 PTP HARDWARE CLOCK SUPPORT
 M:	Richard Cochran <[email protected]>
 L:	[email protected]
drivers/hwmon/Kconfig +10 -0
index a608264da87d..c8d86a695f66 100644
@@ -1714,6 +1714,16 @@ source "drivers/hwmon/peci/Kconfig"
 
 source "drivers/hwmon/pmbus/Kconfig"
 
+config SENSORS_PT5161L
+	tristate "Astera Labs PT5161L PCIe retimer hardware monitoring"
+	depends on I2C
+	help
+	  If you say yes here you get support for temperature monitoring
+	  on the Astera Labs PT5161L PCIe retimer.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called pt5161l.
+
 config SENSORS_PWM_FAN
 	tristate "PWM fan"
 	depends on (PWM && OF) || COMPILE_TEST
drivers/hwmon/Makefile +1 -0
index 47be39af5c03..0554d3ccb09a 100644
@@ -180,6 +180,7 @@ obj-$(CONFIG_SENSORS_PC87427)	+= pc87427.o
 obj-$(CONFIG_SENSORS_PCF8591)	+= pcf8591.o
 obj-$(CONFIG_SENSORS_POWERZ)	+= powerz.o
 obj-$(CONFIG_SENSORS_POWR1220)  += powr1220.o
+obj-$(CONFIG_SENSORS_PT5161L)	+= pt5161l.o
 obj-$(CONFIG_SENSORS_PWM_FAN)	+= pwm-fan.o
 obj-$(CONFIG_SENSORS_RASPBERRYPI_HWMON)	+= raspberrypi-hwmon.o
 obj-$(CONFIG_SENSORS_SBTSI)	+= sbtsi_temp.o
drivers/hwmon/pt5161l.c new file +673 -0

673 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw
Quoted 13 lines · Cosmo Chou

This driver implements support for temperature monitoring of Astera Labs PT5161L series PCIe retimer chips.

This driver implementation originates from the CSDK available at

The communication protocol utilized is based on the I2C/SMBus standard.

---
 Documentation/hwmon/index.rst   |   1 +
 Documentation/hwmon/pt5161l.rst |  42 ++
 MAINTAINERS                     |   7 +
 drivers/hwmon/Kconfig           |  10 +

....

drivers/hwmon/pt5161l.c line 600

Quoted 8 lines
drivers/hwmon/pt5161l.c new file +8 -0
+
+static int pt5161l_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct device *hwmon_dev;
+	struct pt5161l_data *data;
+
+	data = devm_kzalloc(dev, sizeof(struct pt5161l_data), GFP_KERNEL);

sizeof(*)

Quoted 17 lines
drivers/hwmon/pt5161l.c new file +17 -0
+	if (!data)
+		return -ENOMEM;
+
+	data->client = client;
+	mutex_init(&data->lock);
+	pt5161l_init_dev(data);
+	dev_set_drvdata(dev, data);
+
+	hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
+							 data,
+							 &pt5161l_chip_info,
+							 NULL);
+
+	pt5161l_init_debugfs(data);
+
+	return PTR_ERR_OR_ZERO(hwmon_dev);
+}

drivers/hwmon/pt5161l.c line 627

Quoted 10 lines
drivers/hwmon/pt5161l.c new file +10 -0
+
+static void pt5161l_remove(struct i2c_client *client)
+{
+	struct pt5161l_data *data = i2c_get_clientdata(client);
+
+	debugfs_remove_recursive(data->debugfs);
+}
+
+static const struct of_device_id __maybe_unused pt5161l_of_match[] = {
+	{ .compatible = "asteralabs,pt5161l" },

Please run scripts/checkpatch.pl and fix reported warnings. Some warnings can be ignored, but the code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.

Quoted 21 lines
drivers/hwmon/pt5161l.c new file +21 -0
+	{},
+};
+MODULE_DEVICE_TABLE(of, pt5161l_of_match);
+
+static const struct acpi_device_id __maybe_unused pt5161l_acpi_match[] = {
+	{ "PT5161L", 0 },
+	{},
+};
+MODULE_DEVICE_TABLE(acpi, pt5161l_acpi_match);
+
+static const struct i2c_device_id pt5161l_id[] = {
+	{ "pt5161l", 0 },
+	{}
+};
+MODULE_DEVICE_TABLE(i2c, pt5161l_id);
+
+static struct i2c_driver pt5161l_driver = {
+	.class = I2C_CLASS_HWMON,
+	.driver = {
+		.name = "pt5161l",
+		.of_match_table = of_match_ptr(pt5161l_of_match),

drivers/hwmon/pt5161l.c line 658

Quoted 10 lines
drivers/hwmon/pt5161l.c new file +10 -0
+		.acpi_match_table = ACPI_PTR(pt5161l_acpi_match),
+	},
+	.probe = pt5161l_probe,
+	.remove = pt5161l_remove,
+	.id_table = pt5161l_id,
+};
+
+static int __init pt5161l_init(void)
+{
+	pt5161l_debugfs_dir = debugfs_create_dir("pt5161l", NULL);

Drivers don't need initcalls. For sure any debugfs should not be handled here but in probe.

Best regards,
Krzysztof

maintainer
#3 lore raw
Quoted 10 lines · Krzysztof Kozlowski
Quoted 9 lines · Cosmo Chou

This driver implements support for temperature monitoring of Astera Labs PT5161L series PCIe retimer chips.

This driver implementation originates from the CSDK available at

The communication protocol utilized is based on the I2C/SMBus standard.

---

[ ... ]

Quoted 8 lines

drivers/hwmon/pt5161l.c line 658

Quoted 4 lines
drivers/hwmon/pt5161l.c new file +4 -0
+
+static int __init pt5161l_init(void)
+{
+	pt5161l_debugfs_dir = debugfs_create_dir("pt5161l", NULL);

Drivers don't need initcalls. For sure any debugfs should not be handled here but in probe.

Lots of hwmon drivers have init functions, for basic chip detection of Super-I/O chips (example: drivers/hwmon/nct6775-platform.c) and to create a parent debugfs subdirectory for the driver. The probe function then adds subdirecties per chip instantiation. Example for pmbus, in drivers/hwmon/pmbus/pmbus_core.c:

static int __init pmbus_core_init(void)

{
        pmbus_debugfs_dir = debugfs_create_dir("pmbus", NULL);
        if (IS_ERR(pmbus_debugfs_dir))
                pmbus_debugfs_dir = NULL;

        return 0;
}

static void __exit pmbus_core_exit(void)

{
        debugfs_remove_recursive(pmbus_debugfs_dir);
}

Are you saying this is all wrong ? What alternative would you suggest ?

Thanks,
Guenter

maintainer
#6 lore raw
In reply to Cosmo Chou
Quoted 9 lines · Cosmo Chou

This driver implements support for temperature monitoring of Astera Labs PT5161L series PCIe retimer chips.

This driver implementation originates from the CSDK available at

The communication protocol utilized is based on the I2C/SMBus standard.

---

[ ... ]

Quoted 8 lines
drivers/hwmon/pt5161l.c new file +8 -0
+static ssize_t pt5161l_debugfs_read_fw_ver(struct file *file, char __user *buf,
+					   size_t count, loff_t *ppos)
+{
+	struct pt5161l_data *data = file->private_data;
+	int ret;
+	char ver[32];
+
+	mutex_lock(&data->lock);

drivers/hwmon/pt5161l.c line 513

Quoted 10 lines
drivers/hwmon/pt5161l.c new file +10 -0
+	ret = pt5161l_fwsts_check(data);
+	mutex_unlock(&data->lock);
+	if (ret)
+		return ret;
+
+	ret = snprintf(ver, sizeof(ver), "%u.%u.%u\n", data->fw_ver.major,
+		       data->fw_ver.minor, data->fw_ver.build);
+	if (ret < 0)
+		return ret;
+

You almost got me here ;-). snprintf() never returns a negative error code, so checking for it is not necessary.

drivers/hwmon/pt5161l.c line 514

Quoted 1 line
drivers/hwmon/pt5161l.c new file +1 -0
+	return simple_read_from_buffer(buf, count, ppos, ver, ret + 1);

Number of bytes written plus 1 ? Why ?

Thanks,
Guenter

author
#7 lore raw
Quoted 26 lines · Guenter Roeck
Quoted 9 lines · Cosmo Chou

This driver implements support for temperature monitoring of Astera Labs PT5161L series PCIe retimer chips.

This driver implementation originates from the CSDK available at

The communication protocol utilized is based on the I2C/SMBus standard.

---

[ ... ]

Quoted 13 lines
drivers/hwmon/pt5161l.c new file +13 -0
+static ssize_t pt5161l_debugfs_read_fw_ver(struct file *file, char __user *buf,
+                                        size_t count, loff_t *ppos)
+{
+     struct pt5161l_data *data = file->private_data;
+     int ret;
+     char ver[32];
+
+     mutex_lock(&data->lock);
+     ret = pt5161l_fwsts_check(data);
+     mutex_unlock(&data->lock);
+     if (ret)
+             return ret;
+
Quoted 9 lines

drivers/hwmon/pt5161l.c line 513

Quoted 5 lines
drivers/hwmon/pt5161l.c new file +5 -0
+     ret = snprintf(ver, sizeof(ver), "%u.%u.%u\n", data->fw_ver.major,
+                    data->fw_ver.minor, data->fw_ver.build);
+     if (ret < 0)
+             return ret;
+

You almost got me here ;-). snprintf() never returns a negative error code, so checking for it is not necessary.

Oh! You're right.

Quoted 3 lines
Quoted 1 line

+ return simple_read_from_buffer(buf, count, ppos, ver, ret + 1);

Number of bytes written plus 1 ? Why ?

It's just to include the string terminator '\0'.

Quoted 3 lines

Thanks,
Guenter

maintainer
#8 lore raw
Quoted 36 lines · Cosmo Chou
Quoted 26 lines · Guenter Roeck
Quoted 9 lines · Cosmo Chou

This driver implements support for temperature monitoring of Astera Labs PT5161L series PCIe retimer chips.

This driver implementation originates from the CSDK available at

The communication protocol utilized is based on the I2C/SMBus standard.

---

[ ... ]

Quoted 13 lines
drivers/hwmon/pt5161l.c new file +13 -0
+static ssize_t pt5161l_debugfs_read_fw_ver(struct file *file, char __user *buf,
+                                        size_t count, loff_t *ppos)
+{
+     struct pt5161l_data *data = file->private_data;
+     int ret;
+     char ver[32];
+
+     mutex_lock(&data->lock);
+     ret = pt5161l_fwsts_check(data);
+     mutex_unlock(&data->lock);
+     if (ret)
+             return ret;
+
Quoted 9 lines

drivers/hwmon/pt5161l.c line 513

Quoted 5 lines
drivers/hwmon/pt5161l.c new file +5 -0
+     ret = snprintf(ver, sizeof(ver), "%u.%u.%u\n", data->fw_ver.major,
+                    data->fw_ver.minor, data->fw_ver.build);
+     if (ret < 0)
+             return ret;
+

You almost got me here ;-). snprintf() never returns a negative error code, so checking for it is not necessary.

Quoted 7 lines

Oh! You're right.

Quoted 3 lines
Quoted 1 line

+ return simple_read_from_buffer(buf, count, ppos, ver, ret + 1);

Number of bytes written plus 1 ? Why ?

It's just to include the string terminator '\0'.

If that was needed, it would be risky. snprintf() truncates the output if the buffer is not large enough. You might want to consider using scnprintf() instead. But then I am not sure if that is needed in the first place. Almost all code I checked doesn't do that, and it seems to be likely that the few drivers who do that are simply wrong. Can you explain why the string terminator needs to be added to the output ?

Thanks,
Guenter

author
#9 lore raw
Quoted 53 lines · Guenter Roeck
Quoted 36 lines · Cosmo Chou
Quoted 26 lines · Guenter Roeck
Quoted 9 lines · Cosmo Chou

This driver implements support for temperature monitoring of Astera Labs PT5161L series PCIe retimer chips.

This driver implementation originates from the CSDK available at

The communication protocol utilized is based on the I2C/SMBus standard.

---

[ ... ]

Quoted 13 lines
drivers/hwmon/pt5161l.c new file +13 -0
+static ssize_t pt5161l_debugfs_read_fw_ver(struct file *file, char __user *buf,
+                                        size_t count, loff_t *ppos)
+{
+     struct pt5161l_data *data = file->private_data;
+     int ret;
+     char ver[32];
+
+     mutex_lock(&data->lock);
+     ret = pt5161l_fwsts_check(data);
+     mutex_unlock(&data->lock);
+     if (ret)
+             return ret;
+
Quoted 9 lines

drivers/hwmon/pt5161l.c line 513

Quoted 5 lines
drivers/hwmon/pt5161l.c new file +5 -0
+     ret = snprintf(ver, sizeof(ver), "%u.%u.%u\n", data->fw_ver.major,
+                    data->fw_ver.minor, data->fw_ver.build);
+     if (ret < 0)
+             return ret;
+

You almost got me here ;-). snprintf() never returns a negative error code, so checking for it is not necessary.

Quoted 7 lines

Oh! You're right.

Quoted 3 lines
Quoted 1 line

+ return simple_read_from_buffer(buf, count, ppos, ver, ret + 1);

Number of bytes written plus 1 ? Why ?

It's just to include the string terminator '\0'.

If that was needed, it would be risky. snprintf() truncates the output if the buffer is not large enough. You might want to consider using scnprintf() instead. But then I am not sure if that is needed in the first place. Almost all code I checked doesn't do that, and it seems to be likely that the few drivers who do that are simply wrong. Can you explain why the string terminator needs to be added to the output ?

Quoted 3 lines

Thanks,
Guenter

It's just in case someone reads and prints this, but with a dirty buffer and doesn't handle the terminator.

maintainer
#10 lore raw
Quoted 54 lines · Cosmo Chou
Quoted 53 lines · Guenter Roeck
Quoted 36 lines · Cosmo Chou
Quoted 26 lines · Guenter Roeck
Quoted 9 lines · Cosmo Chou

This driver implements support for temperature monitoring of Astera Labs PT5161L series PCIe retimer chips.

This driver implementation originates from the CSDK available at

The communication protocol utilized is based on the I2C/SMBus standard.

---

[ ... ]

Quoted 13 lines
drivers/hwmon/pt5161l.c new file +13 -0
+static ssize_t pt5161l_debugfs_read_fw_ver(struct file *file, char __user *buf,
+                                        size_t count, loff_t *ppos)
+{
+     struct pt5161l_data *data = file->private_data;
+     int ret;
+     char ver[32];
+
+     mutex_lock(&data->lock);
+     ret = pt5161l_fwsts_check(data);
+     mutex_unlock(&data->lock);
+     if (ret)
+             return ret;
+
Quoted 9 lines

drivers/hwmon/pt5161l.c line 513

Quoted 5 lines
drivers/hwmon/pt5161l.c new file +5 -0
+     ret = snprintf(ver, sizeof(ver), "%u.%u.%u\n", data->fw_ver.major,
+                    data->fw_ver.minor, data->fw_ver.build);
+     if (ret < 0)
+             return ret;
+

You almost got me here ;-). snprintf() never returns a negative error code, so checking for it is not necessary.

Quoted 7 lines

Oh! You're right.

Quoted 3 lines
Quoted 1 line

+ return simple_read_from_buffer(buf, count, ppos, ver, ret + 1);

Number of bytes written plus 1 ? Why ?

It's just to include the string terminator '\0'.

If that was needed, it would be risky. snprintf() truncates the output if the buffer is not large enough. You might want to consider using scnprintf() instead. But then I am not sure if that is needed in the first place. Almost all code I checked doesn't do that, and it seems to be likely that the few drivers who do that are simply wrong. Can you explain why the string terminator needs to be added to the output ?

Quoted 5 lines
Quoted 3 lines

Thanks,
Guenter

It's just in case someone reads and prints this, but with a dirty buffer and doesn't handle the terminator.

That needs a better reason. It is not conceivable that 99% of drivers don't do this but this one would need it for some reason. I am not going to accept this unless you can show that debugfs files are supposed to include a terminating '\0' in the response. This is like claiming that printf() should include a terminating '\0' in the output just in case the output is read by a broken application which needs to see the terminator.

Guenter

author
#11 lore raw
Quoted 70 lines · Guenter Roeck
Quoted 54 lines · Cosmo Chou
Quoted 53 lines · Guenter Roeck
Quoted 36 lines · Cosmo Chou
Quoted 26 lines · Guenter Roeck
Quoted 9 lines · Cosmo Chou

This driver implements support for temperature monitoring of Astera Labs PT5161L series PCIe retimer chips.

This driver implementation originates from the CSDK available at

The communication protocol utilized is based on the I2C/SMBus standard.

---

[ ... ]

Quoted 13 lines
drivers/hwmon/pt5161l.c new file +13 -0
+static ssize_t pt5161l_debugfs_read_fw_ver(struct file *file, char __user *buf,
+                                        size_t count, loff_t *ppos)
+{
+     struct pt5161l_data *data = file->private_data;
+     int ret;
+     char ver[32];
+
+     mutex_lock(&data->lock);
+     ret = pt5161l_fwsts_check(data);
+     mutex_unlock(&data->lock);
+     if (ret)
+             return ret;
+
Quoted 9 lines

drivers/hwmon/pt5161l.c line 513

Quoted 5 lines
drivers/hwmon/pt5161l.c new file +5 -0
+     ret = snprintf(ver, sizeof(ver), "%u.%u.%u\n", data->fw_ver.major,
+                    data->fw_ver.minor, data->fw_ver.build);
+     if (ret < 0)
+             return ret;
+

You almost got me here ;-). snprintf() never returns a negative error code, so checking for it is not necessary.

Quoted 7 lines

Oh! You're right.

Quoted 3 lines
Quoted 1 line

+ return simple_read_from_buffer(buf, count, ppos, ver, ret + 1);

Number of bytes written plus 1 ? Why ?

It's just to include the string terminator '\0'.

If that was needed, it would be risky. snprintf() truncates the output if the buffer is not large enough. You might want to consider using scnprintf() instead. But then I am not sure if that is needed in the first place. Almost all code I checked doesn't do that, and it seems to be likely that the few drivers who do that are simply wrong. Can you explain why the string terminator needs to be added to the output ?

Quoted 5 lines
Quoted 3 lines

Thanks,
Guenter

It's just in case someone reads and prints this, but with a dirty buffer and doesn't handle the terminator.

That needs a better reason. It is not conceivable that 99% of drivers don't do this but this one would need it for some reason. I am not going to accept this unless you can show that debugfs files are supposed to include a terminating '\0' in the response. This is like claiming that printf() should include a terminating '\0' in the output just in case the output is read by a broken application which needs to see the terminator.

Quoted 2 lines

Guenter

Agree. Users should handle this by themselves. I'll revise it to align the behavior.

Thanks
Cosmo

#4 lore raw
In reply to Guenter Roeck
Quoted 22 lines · Guenter Roeck
Quoted 10 lines · Krzysztof Kozlowski
Quoted 9 lines · Cosmo Chou

This driver implements support for temperature monitoring of Astera Labs PT5161L series PCIe retimer chips.

This driver implementation originates from the CSDK available at

The communication protocol utilized is based on the I2C/SMBus standard.

---

[ ... ]

Quoted 8 lines

drivers/hwmon/pt5161l.c line 658

Quoted 4 lines
drivers/hwmon/pt5161l.c new file +4 -0
+
+static int __init pt5161l_init(void)
+{
+	pt5161l_debugfs_dir = debugfs_create_dir("pt5161l", NULL);

Drivers don't need initcalls. For sure any debugfs should not be handled here but in probe.

Quoted 5 lines

Lots of hwmon drivers have init functions, for basic chip detection of Super-I/O chips (example: drivers/hwmon/nct6775-platform.c) and to create a parent debugfs subdirectory for the driver. The probe function then adds subdirecties per chip instantiation. Example for pmbus, in drivers/hwmon/pmbus/pmbus_core.c:

Core bus components are a bit different...

Quoted 10 lines

static int __init pmbus_core_init(void)

{
        pmbus_debugfs_dir = debugfs_create_dir("pmbus", NULL);
        if (IS_ERR(pmbus_debugfs_dir))
                pmbus_debugfs_dir = NULL;

        return 0;
}
Quoted 6 lines

static void __exit pmbus_core_exit(void)

{
        debugfs_remove_recursive(pmbus_debugfs_dir);
}

Are you saying this is all wrong ? What alternative would you suggest ?

Just create parent directory in probe and only keep remove in __exit. But you are right that might not be much better approach.

Best regards,
Krzysztof

maintainer
#5 lore raw
Quoted 46 lines · Krzysztof Kozlowski
Quoted 22 lines · Guenter Roeck
Quoted 10 lines · Krzysztof Kozlowski
Quoted 9 lines · Cosmo Chou

This driver implements support for temperature monitoring of Astera Labs PT5161L series PCIe retimer chips.

This driver implementation originates from the CSDK available at

The communication protocol utilized is based on the I2C/SMBus standard.

---

[ ... ]

Quoted 8 lines

drivers/hwmon/pt5161l.c line 658

Quoted 4 lines
drivers/hwmon/pt5161l.c new file +4 -0
+
+static int __init pt5161l_init(void)
+{
+	pt5161l_debugfs_dir = debugfs_create_dir("pt5161l", NULL);

Drivers don't need initcalls. For sure any debugfs should not be handled here but in probe.

Quoted 5 lines

Lots of hwmon drivers have init functions, for basic chip detection of Super-I/O chips (example: drivers/hwmon/nct6775-platform.c) and to create a parent debugfs subdirectory for the driver. The probe function then adds subdirecties per chip instantiation. Example for pmbus, in drivers/hwmon/pmbus/pmbus_core.c:

Core bus components are a bit different...

Quoted 15 lines

static int __init pmbus_core_init(void)

{
         pmbus_debugfs_dir = debugfs_create_dir("pmbus", NULL);
         if (IS_ERR(pmbus_debugfs_dir))
                 pmbus_debugfs_dir = NULL;

         return 0;
}

static void __exit pmbus_core_exit(void)

{
         debugfs_remove_recursive(pmbus_debugfs_dir);
}
Quoted 5 lines
Quoted 1 line

Are you saying this is all wrong ? What alternative would you suggest ?

Just create parent directory in probe and only keep remove in __exit. But you are right that might not be much better approach.

That would just add more code and increase complexity since it would require a mutex to protect against parallel probes. On the plus side, it would only create the driver root directory if necessary, that is, if there is an actual device. I am not sure if that would be worth the increased complexity.

That makes me wonder, though, if an API function such as

	struct dentry *hwmon_debugfs_get_root(char *name);

would make sense. That would move the complexity to the hwmon core and unify its handling. I'll think about that. For the time being, I'll accept the code as-is.

Thanks,
Guenter