Linux Hardware Monitor development
 help / color / mirror / Atom feed
* [PATCH 7/8] hwmon: (pmbus/core) Optimize debugfs status attribute initialization
@ 2025-02-10  4:00 Guenter Roeck
  2025-02-10  4:00 ` [PATCH 8/8] hwmon: (pmbus/core) Report content of CAPABILITY register in debugfs Guenter Roeck
  2025-02-10  5:33 ` [PATCH 7/8] hwmon: (pmbus/core) Optimize debugfs status attribute initialization Tzung-Bi Shih
  0 siblings, 2 replies; 5+ messages in thread
From: Guenter Roeck @ 2025-02-10  4:00 UTC (permalink / raw)
  To: linux-hwmon; +Cc: Wolfram Sang, Guenter Roeck

Define debugfs attributes used to access status registers in a data
structure and loop through it instead of creating debugfs files
one by one. This reduces code size and simplifies adding additional
attributes if needed.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/pmbus/pmbus_core.c | 125 ++++++++-----------------------
 1 file changed, 32 insertions(+), 93 deletions(-)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 91dfb9ec9223..f4d4a91ff4aa 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -3501,6 +3501,7 @@ static void pmbus_remove_symlink(void *symlink)
 
 struct pmbus_debugfs_data {
 	u8 reg;
+	u32 flag;
 	const char *name;
 };
 
@@ -3513,6 +3514,19 @@ static const struct pmbus_debugfs_data pmbus_debugfs_block_data[] = {
 	{ .reg = PMBUS_MFR_SERIAL, .name = "mfr_serial" },
 };
 
+static const struct pmbus_debugfs_data pmbus_debugfs_status_data[] = {
+	{ .reg = PMBUS_STATUS_VOUT, .flag = PMBUS_HAVE_STATUS_VOUT, .name = "status%d_vout" },
+	{ .reg = PMBUS_STATUS_IOUT, .flag = PMBUS_HAVE_STATUS_IOUT, .name = "status%d_iout" },
+	{ .reg = PMBUS_STATUS_INPUT, .flag = PMBUS_HAVE_STATUS_INPUT, .name = "status%d_input" },
+	{ .reg = PMBUS_STATUS_TEMPERATURE, .flag = PMBUS_HAVE_STATUS_TEMP,
+	  .name = "status%d_temp" },
+	{ .reg = PMBUS_STATUS_FAN_12, .flag = PMBUS_HAVE_STATUS_FAN12, .name = "status%d_fan12" },
+	{ .reg = PMBUS_STATUS_FAN_34, .flag = PMBUS_HAVE_STATUS_FAN34, .name = "status%d_fan34" },
+	{ .reg = PMBUS_STATUS_CML, .name = "status%d_cml" },
+	{ .reg = PMBUS_STATUS_OTHER, .name = "status%d_other" },
+	{ .reg = PMBUS_STATUS_MFR_SPECIFIC, .name = "status%d_mfr" },
+};
+
 static void pmbus_init_debugfs(struct i2c_client *client,
 			       struct pmbus_data *data)
 {
@@ -3520,7 +3534,7 @@ static void pmbus_init_debugfs(struct i2c_client *client,
 	struct pmbus_debugfs_entry *entries;
 	const char *pathname, *symlink;
 	char name[PMBUS_NAME_SIZE];
-	int i, idx = 0;
+	int page, i, idx = 0;
 
 	/*
 	 * client->debugfs may be NULL or an ERR_PTR(). dentry_path_raw()
@@ -3594,107 +3608,32 @@ static void pmbus_init_debugfs(struct i2c_client *client,
 	}
 
 	/* Add page specific entries */
-	for (i = 0; i < data->info->pages; ++i) {
+	for (page = 0; page < data->info->pages; ++page) {
 		/* Check accessibility of status register if it's not page 0 */
-		if (!i || pmbus_check_status_register(client, i)) {
+		if (!page || pmbus_check_status_register(client, page)) {
 			/* No need to set reg as we have special read op. */
 			entries[idx].client = client;
-			entries[idx].page = i;
-			scnprintf(name, PMBUS_NAME_SIZE, "status%d", i);
+			entries[idx].page = page;
+			scnprintf(name, PMBUS_NAME_SIZE, "status%d", page);
 			debugfs_create_file(name, 0444, debugfs,
 					    &entries[idx++],
 					    &pmbus_debugfs_ops_status);
 		}
 
-		if (data->info->func[i] & PMBUS_HAVE_STATUS_VOUT) {
-			entries[idx].client = client;
-			entries[idx].page = i;
-			entries[idx].reg = PMBUS_STATUS_VOUT;
-			scnprintf(name, PMBUS_NAME_SIZE, "status%d_vout", i);
-			debugfs_create_file(name, 0444, debugfs,
-					    &entries[idx++],
-					    &pmbus_debugfs_ops);
-		}
+		for (i = 0; i < ARRAY_SIZE(pmbus_debugfs_status_data); i++) {
+			const struct pmbus_debugfs_data *d =
+					&pmbus_debugfs_status_data[i];
 
-		if (data->info->func[i] & PMBUS_HAVE_STATUS_IOUT) {
-			entries[idx].client = client;
-			entries[idx].page = i;
-			entries[idx].reg = PMBUS_STATUS_IOUT;
-			scnprintf(name, PMBUS_NAME_SIZE, "status%d_iout", i);
-			debugfs_create_file(name, 0444, debugfs,
-					    &entries[idx++],
-					    &pmbus_debugfs_ops);
-		}
-
-		if (data->info->func[i] & PMBUS_HAVE_STATUS_INPUT) {
-			entries[idx].client = client;
-			entries[idx].page = i;
-			entries[idx].reg = PMBUS_STATUS_INPUT;
-			scnprintf(name, PMBUS_NAME_SIZE, "status%d_input", i);
-			debugfs_create_file(name, 0444, debugfs,
-					    &entries[idx++],
-					    &pmbus_debugfs_ops);
-		}
-
-		if (data->info->func[i] & PMBUS_HAVE_STATUS_TEMP) {
-			entries[idx].client = client;
-			entries[idx].page = i;
-			entries[idx].reg = PMBUS_STATUS_TEMPERATURE;
-			scnprintf(name, PMBUS_NAME_SIZE, "status%d_temp", i);
-			debugfs_create_file(name, 0444, debugfs,
-					    &entries[idx++],
-					    &pmbus_debugfs_ops);
-		}
-
-		if (pmbus_check_byte_register(client, i, PMBUS_STATUS_CML)) {
-			entries[idx].client = client;
-			entries[idx].page = i;
-			entries[idx].reg = PMBUS_STATUS_CML;
-			scnprintf(name, PMBUS_NAME_SIZE, "status%d_cml", i);
-			debugfs_create_file(name, 0444, debugfs,
-					    &entries[idx++],
-					    &pmbus_debugfs_ops);
-		}
-
-		if (pmbus_check_byte_register(client, i, PMBUS_STATUS_OTHER)) {
-			entries[idx].client = client;
-			entries[idx].page = i;
-			entries[idx].reg = PMBUS_STATUS_OTHER;
-			scnprintf(name, PMBUS_NAME_SIZE, "status%d_other", i);
-			debugfs_create_file(name, 0444, debugfs,
-					    &entries[idx++],
-					    &pmbus_debugfs_ops);
-		}
-
-		if (pmbus_check_byte_register(client, i,
-					      PMBUS_STATUS_MFR_SPECIFIC)) {
-			entries[idx].client = client;
-			entries[idx].page = i;
-			entries[idx].reg = PMBUS_STATUS_MFR_SPECIFIC;
-			scnprintf(name, PMBUS_NAME_SIZE, "status%d_mfr", i);
-			debugfs_create_file(name, 0444, debugfs,
-					    &entries[idx++],
-					    &pmbus_debugfs_ops);
-		}
-
-		if (data->info->func[i] & PMBUS_HAVE_STATUS_FAN12) {
-			entries[idx].client = client;
-			entries[idx].page = i;
-			entries[idx].reg = PMBUS_STATUS_FAN_12;
-			scnprintf(name, PMBUS_NAME_SIZE, "status%d_fan12", i);
-			debugfs_create_file(name, 0444, debugfs,
-					    &entries[idx++],
-					    &pmbus_debugfs_ops);
-		}
-
-		if (data->info->func[i] & PMBUS_HAVE_STATUS_FAN34) {
-			entries[idx].client = client;
-			entries[idx].page = i;
-			entries[idx].reg = PMBUS_STATUS_FAN_34;
-			scnprintf(name, PMBUS_NAME_SIZE, "status%d_fan34", i);
-			debugfs_create_file(name, 0444, debugfs,
-					    &entries[idx++],
-					    &pmbus_debugfs_ops);
+			if ((data->info->func[page] & d->flag) ||
+			    (!d->flag && pmbus_check_byte_register(client, page, d->reg))) {
+				entries[idx].client = client;
+				entries[idx].page = page;
+				entries[idx].reg = d->reg;
+				scnprintf(name, PMBUS_NAME_SIZE, d->name, page);
+				debugfs_create_file(name, 0444, debugfs,
+						    &entries[idx++],
+						    &pmbus_debugfs_ops);
+			}
 		}
 	}
 }
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 8/8] hwmon: (pmbus/core) Report content of CAPABILITY register in debugfs
  2025-02-10  4:00 [PATCH 7/8] hwmon: (pmbus/core) Optimize debugfs status attribute initialization Guenter Roeck
@ 2025-02-10  4:00 ` Guenter Roeck
  2025-02-10  5:34   ` Tzung-Bi Shih
  2025-02-10  5:33 ` [PATCH 7/8] hwmon: (pmbus/core) Optimize debugfs status attribute initialization Tzung-Bi Shih
  1 sibling, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2025-02-10  4:00 UTC (permalink / raw)
  To: linux-hwmon; +Cc: Wolfram Sang, Guenter Roeck

Report the value of the CAPABILITY register in debugfs if supported.
Only check if the register is supported if PMBUS_NO_CAPABILITY
is not set.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/pmbus/pmbus_core.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index f4d4a91ff4aa..b2e3cd1ec941 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -3585,6 +3585,15 @@ static void pmbus_init_debugfs(struct i2c_client *client,
 	 * assume that values of the following registers are the same for all
 	 * pages and report values only for page 0.
 	 */
+	if (!(data->flags & PMBUS_NO_CAPABILITY) &&
+	    pmbus_check_byte_register(client, 0, PMBUS_CAPABILITY)) {
+		entries[idx].client = client;
+		entries[idx].page = 0;
+		entries[idx].reg = PMBUS_CAPABILITY;
+		debugfs_create_file("capability", 0444, debugfs,
+				    &entries[idx++],
+				    &pmbus_debugfs_ops);
+	}
 	if (pmbus_check_byte_register(client, 0, PMBUS_REVISION)) {
 		entries[idx].client = client;
 		entries[idx].page = 0;
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 7/8] hwmon: (pmbus/core) Optimize debugfs status attribute initialization
  2025-02-10  4:00 [PATCH 7/8] hwmon: (pmbus/core) Optimize debugfs status attribute initialization Guenter Roeck
  2025-02-10  4:00 ` [PATCH 8/8] hwmon: (pmbus/core) Report content of CAPABILITY register in debugfs Guenter Roeck
@ 2025-02-10  5:33 ` Tzung-Bi Shih
  1 sibling, 0 replies; 5+ messages in thread
From: Tzung-Bi Shih @ 2025-02-10  5:33 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: linux-hwmon, Wolfram Sang

On Sun, Feb 09, 2025 at 08:00:23PM -0800, Guenter Roeck wrote:
> Define debugfs attributes used to access status registers in a data
> structure and loop through it instead of creating debugfs files
> one by one. This reduces code size and simplifies adding additional
> attributes if needed.
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 8/8] hwmon: (pmbus/core) Report content of CAPABILITY register in debugfs
  2025-02-10  4:00 ` [PATCH 8/8] hwmon: (pmbus/core) Report content of CAPABILITY register in debugfs Guenter Roeck
@ 2025-02-10  5:34   ` Tzung-Bi Shih
  2025-02-10 16:02     ` Guenter Roeck
  0 siblings, 1 reply; 5+ messages in thread
From: Tzung-Bi Shih @ 2025-02-10  5:34 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: linux-hwmon, Wolfram Sang

On Sun, Feb 09, 2025 at 08:00:24PM -0800, Guenter Roeck wrote:
> @@ -3585,6 +3585,15 @@ static void pmbus_init_debugfs(struct i2c_client *client,
>  	 * assume that values of the following registers are the same for all
>  	 * pages and report values only for page 0.
>  	 */
> +	if (!(data->flags & PMBUS_NO_CAPABILITY) &&
> +	    pmbus_check_byte_register(client, 0, PMBUS_CAPABILITY)) {
> +		entries[idx].client = client;
> +		entries[idx].page = 0;
> +		entries[idx].reg = PMBUS_CAPABILITY;
> +		debugfs_create_file("capability", 0444, debugfs,
> +				    &entries[idx++],
> +				    &pmbus_debugfs_ops);
> +	}
>  	if (pmbus_check_byte_register(client, 0, PMBUS_REVISION)) {
>  		entries[idx].client = client;
>  		entries[idx].page = 0;

New device-specific entry.  The allocation size [1] should also change
accordingly: s/7/8/.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/hwmon/pmbus/pmbus_core.c?id=a64dcfb451e254085a7daee5fe51bf22959d52d3#n3537

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 8/8] hwmon: (pmbus/core) Report content of CAPABILITY register in debugfs
  2025-02-10  5:34   ` Tzung-Bi Shih
@ 2025-02-10 16:02     ` Guenter Roeck
  0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2025-02-10 16:02 UTC (permalink / raw)
  To: Tzung-Bi Shih; +Cc: linux-hwmon, Wolfram Sang

On 2/9/25 21:34, Tzung-Bi Shih wrote:
> On Sun, Feb 09, 2025 at 08:00:24PM -0800, Guenter Roeck wrote:
>> @@ -3585,6 +3585,15 @@ static void pmbus_init_debugfs(struct i2c_client *client,
>>   	 * assume that values of the following registers are the same for all
>>   	 * pages and report values only for page 0.
>>   	 */
>> +	if (!(data->flags & PMBUS_NO_CAPABILITY) &&
>> +	    pmbus_check_byte_register(client, 0, PMBUS_CAPABILITY)) {
>> +		entries[idx].client = client;
>> +		entries[idx].page = 0;
>> +		entries[idx].reg = PMBUS_CAPABILITY;
>> +		debugfs_create_file("capability", 0444, debugfs,
>> +				    &entries[idx++],
>> +				    &pmbus_debugfs_ops);
>> +	}
>>   	if (pmbus_check_byte_register(client, 0, PMBUS_REVISION)) {
>>   		entries[idx].client = client;
>>   		entries[idx].page = 0;
> 
> New device-specific entry.  The allocation size [1] should also change
> accordingly: s/7/8/.
> 
> [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/hwmon/pmbus/pmbus_core.c?id=a64dcfb451e254085a7daee5fe51bf22959d52d3#n3537


Good catch. Thanks!

Guenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-02-10 16:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-10  4:00 [PATCH 7/8] hwmon: (pmbus/core) Optimize debugfs status attribute initialization Guenter Roeck
2025-02-10  4:00 ` [PATCH 8/8] hwmon: (pmbus/core) Report content of CAPABILITY register in debugfs Guenter Roeck
2025-02-10  5:34   ` Tzung-Bi Shih
2025-02-10 16:02     ` Guenter Roeck
2025-02-10  5:33 ` [PATCH 7/8] hwmon: (pmbus/core) Optimize debugfs status attribute initialization Tzung-Bi Shih

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox