Skip to contentSkip to conversation

Add support for Intel CRPS PSU

PATCH Superseded Ninad Palsule 3 participants 13 messages Dec 12, 2024 – Dec 16, 2024

Subsystems (6)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Ninad Palsule

author maintainer
#0 lore raw

cover Add support for Intel CRPS PSU

Hello,

Please review the changes for Intel CRPS power supply driver. I need to add label in the pmbus core as new application like PSUSensor requires it.

Ninad Palsule (4):
hwmon: pmbus-core: Add label for fan and temp
hwmon: (pmbus/crps) Add Intel CRPS185 power supply
dt-bindings: hwmon: intel,crps185: Add to trivial
ARM: dts: aspeed: system1: Use crps PSU driver

 .../devicetree/bindings/trivial-devices.yaml  |   2 +
 Documentation/hwmon/crps.rst                  |  95 ++++++
 MAINTAINERS                                   |   7 +
 .../dts/aspeed/aspeed-bmc-ibm-system1.dts     |   8 +-
 drivers/hwmon/pmbus/Kconfig                   |   9 +
 drivers/hwmon/pmbus/Makefile                  |   1 +
 drivers/hwmon/pmbus/crps.c                    | 299 ++++++++++++++++++
 drivers/hwmon/pmbus/pmbus_core.c              |  14 +
 8 files changed, 431 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/hwmon/crps.rst
 create mode 100644 drivers/hwmon/pmbus/crps.c
Signature · 1 line
2.43.0
author maintainer
#9 lore raw

PATCH 3/4 dt-bindings: hwmon: intel,crps185: Add to trivial

Add INTEL Common Redundant Power Supply Versions crps185 bindings as trivial.

---
 Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/trivial-devices.yaml +2 -0
index 73a49d50c4ef..7d07b08b1459 100644
@@ -151,6 +151,8 @@ properties:
           - injoinic,ip5306
             # Inspur Power System power supply unit version 1
           - inspur,ipsps1
+            # Intel common redudant power supply crps185
+          - intel,crps185
             # Intersil ISL29028 Ambient Light and Proximity Sensor
           - isil,isl29028
             # Intersil ISL29030 Ambient Light and Proximity Sensor
Signature · 1 line
2.43.0
author maintainer
#6 lore raw

PATCH 2/4 hwmon: (pmbus/crps) Add Intel CRPS185 power supply

In reply to Ninad Palsule

Add the driver to monitor Intel common redundant power supply (crps185) with hwmon over pmbus.

---
 Documentation/hwmon/crps.rst |  95 +++++++++++
 MAINTAINERS                  |   7 +
 drivers/hwmon/pmbus/Kconfig  |   9 ++
 drivers/hwmon/pmbus/Makefile |   1 +
 drivers/hwmon/pmbus/crps.c   | 299 +++++++++++++++++++++++++++++++++++
 5 files changed, 411 insertions(+)
 create mode 100644 Documentation/hwmon/crps.rst
 create mode 100644 drivers/hwmon/pmbus/crps.c
Documentation/hwmon/crps.rst new file +95 -0
new file mode 100644
index 000000000000..81d5dfd68a46
@@ -0,0 +1,95 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver crps
+========================
+
+Supported chips:
+
+  * Intel CRPS185
+
+    Prefix: 'crps185'
+
+    Addresses scanned: -
+
+Authors:
+    Ninad Palsule <[email protected]>
+
+
+Description
+-----------
+
+This driver implements support for Common Redundant Power supply with PMBus
+support.
+
+The driver is a client driver to the core PMBus driver.
+Please see Documentation/hwmon/pmbus.rst for details on PMBus client drivers.
+
+
+Usage Notes
+-----------
+
+This driver does not auto-detect devices. You will have to instantiate the
+devices explicitly. Please see Documentation/i2c/instantiating-devices.rst for
+details.
+
+
+Sysfs entries
+-------------
+
+======================= ======================================================
+curr1_label		"iin"
+curr1_input		Measured input current
+curr1_max		Maximum input current
+curr1_max_alarm         Input maximum current high alarm
+curr1_crit              Critial high input current
+curr1_crit_alarm        Input critical current high alarm
+curr1_rated_max		Maximum rated input current
+
+curr2_label		"iout1"
+curr2_input		Measured output current
+curr2_max		Maximum output current
+curr2_max_alarm         Output maximum current high alarm
+curr2_crit	        Critial high output current
+curr2_crit_alarm        Output critical current high alarm
+curr2_rated_max		Maximum rated output current
+
+in1_label		"vin"
+in1_input		Measured input voltage
+in1_crit                Critical input over voltage
+in1_crit_alarm          Critical input over voltage alarm
+in1_max                 Maximum input over voltage
+in1_max_alarm           Maximum input over voltage alarm
+in1_rated_min		Minimum rated input voltage
+in1_rated_max		Maximum rated input voltage
+
+in2_label		"vout1"
+in2_input		Measured input voltage
+in2_crit                Critical input over voltage
+in2_crit_alarm          Critical input over voltage alarm
+in2_lcrit               Critical input under voltage fault
+in2_lcrit_alarm         Critical input under voltage fault alarm
+in2_max                 Maximum input over voltage
+in2_max_alarm           Maximum input over voltage alarm
+in2_min                 Minimum input under voltage warning
+in2_min_alarm           Minimum input under voltage warning alarm
+in2_rated_min		Minimum rated input voltage
+in2_rated_max		Maximum rated input voltage
+
+power1_label		"pin"
+power1_input		Measured input power
+power1_alarm		Input power high alarm
+power1_max  		Maximum input power
+power1_rated_max        Maximum rated input power
+
+temp[1-2]_input		Measured temperature
+temp[1-2]_crit 		Critical temperature
+temp[1-2]_crit_alarm    Critical temperature alarm
+temp[1-2]_max  		Maximum temperature
+temp[1-2]_max_alarm     Maximum temperature alarm
+temp[1-2]_rated_max     Maximum rated temperature
+
+fan1_alarm		Fan 1 warning.
+fan1_fault		Fan 1 fault.
+fan1_input		Fan 1 speed in RPM.
+fan1_target             Fan 1 target.
+======================= ======================================================
MAINTAINERS +7 -0
index 637ddd44245f..6b31d545f0f1 100644
@@ -6100,6 +6100,13 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/hid/hid-creative-sb0540.c
 
+CRPS COMMON REDUNDANT PSU DRIVER
+M:	Ninad Palsule <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/hwmon/crps.rst
+F:	drivers/hwmon/pmbus/crps.c
+
 CRYPTO API
 M:	Herbert Xu <[email protected]>
 M:	"David S. Miller" <[email protected]>
drivers/hwmon/pmbus/Kconfig +9 -0
index 22418a05ced0..56c4eb4b846e 100644
@@ -85,6 +85,15 @@ config SENSORS_BPA_RS600
 	  This driver can also be built as a module. If so, the module will
 	  be called bpa-rs600.
 
+config SENSORS_CRPS
+	tristate "Common Redundant Power Supply"
+	help
+	  If you say yes here you get hardware monitoring support for the Common
+	  Redundant Power Supply.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called crps.
+
 config SENSORS_DELTA_AHE50DC_FAN
 	tristate "Delta AHE-50DC fan control module"
 	help
drivers/hwmon/pmbus/Makefile +1 -0
index 3d3183f8d2a7..c7eb7739b7f8 100644
@@ -62,3 +62,4 @@ obj-$(CONFIG_SENSORS_XDPE122)	+= xdpe12284.o
 obj-$(CONFIG_SENSORS_XDPE152)	+= xdpe152c4.o
 obj-$(CONFIG_SENSORS_ZL6100)	+= zl6100.o
 obj-$(CONFIG_SENSORS_PIM4328)	+= pim4328.o
+obj-$(CONFIG_SENSORS_CRPS)	+= crps.o
drivers/hwmon/pmbus/crps.c new file +299 -0

299 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 1/4 hwmon: pmbus-core: Add label for fan and temp

In reply to Ninad Palsule

Adding label files for fan and temperature sensors in the power supply. The openbmc application dbus-sensor(psusensor) requires those files to consfigure those sensors.
Note that prefix for temp label is temp[A..C] used instead of temp[1..3] as dbus-sensor(psusensor) application calculate index based on last digit in the name so we do not want to make index double digit after appending page index.

---
 drivers/hwmon/pmbus/pmbus_core.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/hwmon/pmbus/pmbus_core.c +14 -0
index a7000314e5ad..149b3c5f3a4c 100644
@@ -2144,6 +2144,7 @@ static const struct pmbus_sensor_attr temp_attributes[] = {
 	{
 		.reg = PMBUS_READ_TEMPERATURE_1,
 		.class = PSC_TEMPERATURE,
+		.label = "tempA",
 		.paged = true,
 		.update = true,
 		.compare = true,
@@ -2156,6 +2157,7 @@ static const struct pmbus_sensor_attr temp_attributes[] = {
 	}, {
 		.reg = PMBUS_READ_TEMPERATURE_2,
 		.class = PSC_TEMPERATURE,
+		.label = "tempB",
 		.paged = true,
 		.update = true,
 		.compare = true,
@@ -2168,6 +2170,7 @@ static const struct pmbus_sensor_attr temp_attributes[] = {
 	}, {
 		.reg = PMBUS_READ_TEMPERATURE_3,
 		.class = PSC_TEMPERATURE,
+		.label = "tempC",
 		.paged = true,
 		.update = true,
 		.compare = true,
@@ -2282,6 +2285,17 @@ static int pmbus_add_fan_attributes(struct i2c_client *client,
 					     PSC_FAN, true, true, true) == NULL)
 				return -ENOMEM;
 
+			/*
+			 * Add fan label.
+			 * Assuming paged attributes while passing page index
+			 */
+			ret = pmbus_add_label(data, "fan", index, "fan",
+					      page + 1, 0xff);
+			if (ret) {
+				dev_err(data->dev, "Fan label add failed ret=%d\n", ret);
+				return ret;
+			}
+
 			/* Fan control */
 			if (pmbus_check_word_register(client, page,
 					pmbus_fan_command_registers[f])) {
Signature · 1 line
2.43.0
author maintainer
#12 lore raw

PATCH 4/4 ARM: dts: aspeed: system1: Use crps PSU driver

In reply to Ninad Palsule

The system1 uses Intel common redundant (crps185) power supplies so move to correct new crps driver.

---
 arch/arm/boot/dts/aspeed/aspeed-bmc-ibm-system1.dts | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm/boot/dts/aspeed/aspeed-bmc-ibm-system1.dts +4 -4
index 8f77bc9e860c..360b9ce3c850 100644
@@ -681,22 +681,22 @@ &i2c2 {
 	status = "okay";
 
 	power-supply@58 {
-		compatible = "ibm,cffps";
+		compatible = "intel,crps185";
 		reg = <0x58>;
 	};
 
 	power-supply@59 {
-		compatible = "ibm,cffps";
+		compatible = "intel,crps185";
 		reg = <0x59>;
 	};
 
 	power-supply@5a {
-		compatible = "ibm,cffps";
+		compatible = "intel,crps185";
 		reg = <0x5a>;
 	};
 
 	power-supply@5b {
-		compatible = "ibm,cffps";
+		compatible = "intel,crps185";
 		reg = <0x5b>;
 	};
 };
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH v1 1/4] hwmon: pmbus-core: Add label for fan and temp

In reply to Ninad Palsule
Quoted 9 lines · Ninad Palsule

Adding label files for fan and temperature sensors in the power supply. The openbmc application dbus-sensor(psusensor) requires those files to consfigure those sensors.
Note that prefix for temp label is temp[A..C] used instead of temp[1..3] as dbus-sensor(psusensor) application calculate index based on last digit in the name so we do not want to make index double digit after appending page index.

We are not going to fix userspace problems in the kernel.

Guenter

Quoted 50 lines
---
  drivers/hwmon/pmbus/pmbus_core.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
drivers/hwmon/pmbus/pmbus_core.c +14 -0
index a7000314e5ad..149b3c5f3a4c 100644
@@ -2144,6 +2144,7 @@ static const struct pmbus_sensor_attr temp_attributes[] = {
  	{
  		.reg = PMBUS_READ_TEMPERATURE_1,
  		.class = PSC_TEMPERATURE,
+		.label = "tempA",
  		.paged = true,
  		.update = true,
  		.compare = true,
@@ -2156,6 +2157,7 @@ static const struct pmbus_sensor_attr temp_attributes[] = {
  	}, {
  		.reg = PMBUS_READ_TEMPERATURE_2,
  		.class = PSC_TEMPERATURE,
+		.label = "tempB",
  		.paged = true,
  		.update = true,
  		.compare = true,
@@ -2168,6 +2170,7 @@ static const struct pmbus_sensor_attr temp_attributes[] = {
  	}, {
  		.reg = PMBUS_READ_TEMPERATURE_3,
  		.class = PSC_TEMPERATURE,
+		.label = "tempC",
  		.paged = true,
  		.update = true,
  		.compare = true,
@@ -2282,6 +2285,17 @@ static int pmbus_add_fan_attributes(struct i2c_client *client,
  					     PSC_FAN, true, true, true) == NULL)
  				return -ENOMEM;
 
+			/*
+			 * Add fan label.
+			 * Assuming paged attributes while passing page index
+			 */
+			ret = pmbus_add_label(data, "fan", index, "fan",
+					      page + 1, 0xff);
+			if (ret) {
+				dev_err(data->dev, "Fan label add failed ret=%d\n", ret);
+				return ret;
+			}
+
  			/* Fan control */
  			if (pmbus_check_word_register(client, page,
  					pmbus_fan_command_registers[f])) {
maintainer
#7 lore raw

Re: [PATCH v1 2/4] hwmon: (pmbus/crps) Add Intel CRPS185 power supply

In reply to Ninad Palsule
Quoted 6 lines · Ninad Palsule

Add the driver to monitor Intel common redundant power supply (crps185) with hwmon over pmbus.

---
  Documentation/hwmon/crps.rst |  95 +++++++++++

Documentation/hwmon/index.rst needs to be updated.

Quoted 14 lines
  MAINTAINERS                  |   7 +
  drivers/hwmon/pmbus/Kconfig  |   9 ++
  drivers/hwmon/pmbus/Makefile |   1 +
  drivers/hwmon/pmbus/crps.c   | 299 +++++++++++++++++++++++++++++++++++
  5 files changed, 411 insertions(+)

create mode 100644 Documentation/hwmon/crps.rst
create mode 100644 drivers/hwmon/pmbus/crps.c

Documentation/hwmon/crps.rst new file +0 -0
new file mode 100644
index 000000000000..81d5dfd68a46

Documentation/hwmon/crps.rst line 4

Quoted 4 lines
Documentation/hwmon/crps.rst new file +4 -0
@@ -0,0 +1,95 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver crps
+========================

I am quite sure that this triggers a documentation warning.

Documentation/hwmon/crps.rst line 17

Quoted 13 lines
Documentation/hwmon/crps.rst new file +13 -0
+
+Supported chips:
+
+  * Intel CRPS185
+
+    Prefix: 'crps185'
+
+    Addresses scanned: -
+
+Authors:
+    Ninad Palsule <[email protected]>
+
+

Is the documentation available somewhere ?
If yes, please add a reference. If not, add a comment explaining that it is not available to the public.

Documentation/hwmon/crps.rst line 21

Quoted 4 lines
Documentation/hwmon/crps.rst new file +4 -0
+Description
+-----------
+
+This driver implements support for Common Redundant Power supply with PMBus

For _Intel_ ...

Quoted 79 lines
Documentation/hwmon/crps.rst new file +74 -0
+support.
+
+The driver is a client driver to the core PMBus driver.
+Please see Documentation/hwmon/pmbus.rst for details on PMBus client drivers.
+
+
+Usage Notes
+-----------
+
+This driver does not auto-detect devices. You will have to instantiate the
+devices explicitly. Please see Documentation/i2c/instantiating-devices.rst for
+details.
+
+
+Sysfs entries
+-------------
+
+======================= ======================================================
+curr1_label		"iin"
+curr1_input		Measured input current
+curr1_max		Maximum input current
+curr1_max_alarm         Input maximum current high alarm
+curr1_crit              Critial high input current
+curr1_crit_alarm        Input critical current high alarm
+curr1_rated_max		Maximum rated input current
+
+curr2_label		"iout1"
+curr2_input		Measured output current
+curr2_max		Maximum output current
+curr2_max_alarm         Output maximum current high alarm
+curr2_crit	        Critial high output current
+curr2_crit_alarm        Output critical current high alarm
+curr2_rated_max		Maximum rated output current
+
+in1_label		"vin"
+in1_input		Measured input voltage
+in1_crit                Critical input over voltage
+in1_crit_alarm          Critical input over voltage alarm
+in1_max                 Maximum input over voltage
+in1_max_alarm           Maximum input over voltage alarm
+in1_rated_min		Minimum rated input voltage
+in1_rated_max		Maximum rated input voltage
+
+in2_label		"vout1"
+in2_input		Measured input voltage
+in2_crit                Critical input over voltage
+in2_crit_alarm          Critical input over voltage alarm
+in2_lcrit               Critical input under voltage fault
+in2_lcrit_alarm         Critical input under voltage fault alarm
+in2_max                 Maximum input over voltage
+in2_max_alarm           Maximum input over voltage alarm
+in2_min                 Minimum input under voltage warning
+in2_min_alarm           Minimum input under voltage warning alarm
+in2_rated_min		Minimum rated input voltage
+in2_rated_max		Maximum rated input voltage
+
+power1_label		"pin"
+power1_input		Measured input power
+power1_alarm		Input power high alarm
+power1_max  		Maximum input power
+power1_rated_max        Maximum rated input power
+
+temp[1-2]_input		Measured temperature
+temp[1-2]_crit 		Critical temperature
+temp[1-2]_crit_alarm    Critical temperature alarm
+temp[1-2]_max  		Maximum temperature
+temp[1-2]_max_alarm     Maximum temperature alarm
+temp[1-2]_rated_max     Maximum rated temperature
+
+fan1_alarm		Fan 1 warning.
+fan1_fault		Fan 1 fault.
+fan1_input		Fan 1 speed in RPM.
+fan1_target             Fan 1 target.
+======================= ======================================================
MAINTAINERS +0 -0
index 637ddd44245f..6b31d545f0f1 100644

MAINTAINERS L: [email protected] · line 6103

Quoted 4 lines
MAINTAINERS +1 -0
@@ -6100,6 +6100,13 @@ L:	[email protected]
  S:	Maintained
  F:	drivers/hid/hid-creative-sb0540.c
 
+CRPS COMMON REDUNDANT PSU DRIVER

This is _INTEL_ CRPS.

Quoted 14 lines
MAINTAINERS +6 -0
+M:	Ninad Palsule <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/hwmon/crps.rst
+F:	drivers/hwmon/pmbus/crps.c
+
  CRYPTO API
  M:	Herbert Xu <[email protected]>
  M:	"David S. Miller" <[email protected]>
drivers/hwmon/pmbus/Kconfig +0 -0
index 22418a05ced0..56c4eb4b846e 100644

drivers/hwmon/pmbus/Kconfig config SENSORS_BPA_RS600 · line 89

Quoted 5 lines
drivers/hwmon/pmbus/Kconfig +2 -0
@@ -85,6 +85,15 @@ config SENSORS_BPA_RS600
  	  This driver can also be built as a module. If so, the module will
  	  be called bpa-rs600.
 
+config SENSORS_CRPS
+	tristate "Common Redundant Power Supply"

Again, this is an Intel product.

Quoted 31 lines
drivers/hwmon/pmbus/Kconfig +7 -0
+	help
+	  If you say yes here you get hardware monitoring support for the Common
+	  Redundant Power Supply.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called crps.
+
  config SENSORS_DELTA_AHE50DC_FAN
  	tristate "Delta AHE-50DC fan control module"
  	help
drivers/hwmon/pmbus/Makefile +1 -0
index 3d3183f8d2a7..c7eb7739b7f8 100644
@@ -62,3 +62,4 @@ obj-$(CONFIG_SENSORS_XDPE122)	+= xdpe12284.o
  obj-$(CONFIG_SENSORS_XDPE152)	+= xdpe152c4.o
  obj-$(CONFIG_SENSORS_ZL6100)	+= zl6100.o
  obj-$(CONFIG_SENSORS_PIM4328)	+= pim4328.o
+obj-$(CONFIG_SENSORS_CRPS)	+= crps.o
drivers/hwmon/pmbus/crps.c new file +6 -0
new file mode 100644
index 000000000000..44d309f81803
@@ -0,0 +1,299 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2024 IBM Corp.
+ */
+
+#include <linux/debugfs.h>

drivers/hwmon/pmbus/crps.c line 16

Quoted 10 lines
drivers/hwmon/pmbus/crps.c new file +10 -0
+#include <linux/i2c.h>
+#include <linux/of.h>
+#include <linux/pmbus.h>
+
+#include "pmbus.h"
+
+/* Intel crps185 specific commands. */
+#define CRPS185_MFR_IOUT_MAX		0xA6
+#define CRPS185_MFR_POUT_MAX		0xA7
+

I fail to see the point in those defines, even more so since PMBUS_MFR_POUT_MAX and PMBUS_MFR_IOUT_MAX are used below.

drivers/hwmon/pmbus/crps.c line 24

Quoted 8 lines
drivers/hwmon/pmbus/crps.c new file +8 -0
+enum {
+	CRPS_DEBUGFS_PMBUS_REVISION = 0,
+	CRPS_DEBUGFS_MAX_POWER_OUT,
+	CRPS_DEBUGFS_MAX_CURRENT_OUT,
+	CRPS_DEBUGFS_NUM_ENTRIES
+};
+
+enum models { crps185 = 1, crps_unknown };

Pointless enum. The driver only supports a single power supply.

drivers/hwmon/pmbus/crps.c line 37

Quoted 13 lines
drivers/hwmon/pmbus/crps.c new file +13 -0
+
+struct crps {
+	enum models version;
+	struct i2c_client *client;
+
+	int debugfs_entries[CRPS_DEBUGFS_NUM_ENTRIES];
+};
+
+#define to_psu(x, y) container_of((x), struct crps, debugfs_entries[(y)])
+
+static struct pmbus_platform_data crps_pdata = {
+	.flags = PMBUS_SKIP_STATUS_CHECK,
+};

Did you confirm that it is needed ? If so, explain why it is needed.

Quoted 54 lines
drivers/hwmon/pmbus/crps.c new file +54 -0
+
+static const struct i2c_device_id crps_id[] = {
+	{ "intel_crps185", crps185 },
+	{}
+};
+MODULE_DEVICE_TABLE(i2c, crps_id);
+
+/*
+ * Convert linear format word to machine format. 11 LSB side bits are two's
+ * complement integer mantissa and 5 MSB side bits are two's complement
+ * exponent
+ */
+static int crps_convert_linear(int rc)
+{
+	s16 exponent;
+	s32 mantissa;
+	s64 val;
+
+	exponent = ((s16)rc) >> 11;
+	mantissa = ((s16)((rc & 0x7ff) << 5)) >> 5;
+
+	val = mantissa;
+	if (exponent >= 0)
+		val <<= exponent;
+	else
+		val >>= -exponent;
+
+	return (int)val;
+}
+
+static ssize_t crps_debugfs_read(struct file *file, char __user *buf,
+				 size_t count, loff_t *ppos)
+{
+	int rc;
+	int *idxp = file->private_data;
+	int idx = *idxp;
+	struct crps *psu = to_psu(idxp, idx);
+	char data[2 * I2C_SMBUS_BLOCK_MAX] = { 0 };
+
+	rc = pmbus_lock_interruptible(psu->client);
+	if (rc)
+		return rc;
+
+	rc = pmbus_set_page(psu->client, 0, 0xff);
+	if (rc)
+		goto unlock;
+
+	switch (idx) {
+	case CRPS_DEBUGFS_PMBUS_REVISION:
+		rc = i2c_smbus_read_byte_data(psu->client, PMBUS_REVISION);
+		if (rc >= 0) {
+			if (psu->version == crps185) {
+				if (rc == 0)
+					rc = sprintf(data, "%s", "1.0");

drivers/hwmon/pmbus/crps.c line 101

Quoted 10 lines
drivers/hwmon/pmbus/crps.c new file +10 -0
+				else if (rc == 0x11)
+					rc = sprintf(data, "%s", "1.1");
+				else if (rc == 0x22)
+					rc = sprintf(data, "%s", "1.2");
+				else
+					rc = snprintf(data, 3, "0x%02x", rc);
+			} else {
+				rc = snprintf(data, 3, "%02x", rc);
+			}
+		}

This attribute should be added into the PMBus core.

Quoted 5 lines
drivers/hwmon/pmbus/crps.c new file +5 -0
+		break;
+	case CRPS_DEBUGFS_MAX_POWER_OUT:
+		rc = i2c_smbus_read_word_data(psu->client, PMBUS_MFR_POUT_MAX);
+		if (rc >= 0) {
+			rc = crps_convert_linear(rc);

drivers/hwmon/pmbus/crps.c line 116

Quoted 10 lines
drivers/hwmon/pmbus/crps.c new file +10 -0
+			rc = snprintf(data, I2C_SMBUS_BLOCK_MAX, "%d", rc);
+		}
+		break;
+	case CRPS_DEBUGFS_MAX_CURRENT_OUT:
+		rc = i2c_smbus_read_word_data(psu->client, PMBUS_MFR_IOUT_MAX);
+		if (rc >= 0) {
+			rc = crps_convert_linear(rc);
+			rc = snprintf(data, I2C_SMBUS_BLOCK_MAX, "%d", rc);
+		}
+		break;

What is the point of those two attributes ? There are already standard sysfs attributes reporting those values.

Quoted 23 lines
drivers/hwmon/pmbus/crps.c new file +23 -0
+	default:
+		rc = -EINVAL;
+		break;
+	}
+
+unlock:
+	pmbus_unlock(psu->client);
+	if (rc < 0)
+		return rc;
+
+	data[rc] = '\n';
+	rc += 2;
+
+	return simple_read_from_buffer(buf, count, ppos, data, rc);
+}
+
+static const struct file_operations crps_debugfs_fops = {
+	.llseek = noop_llseek,
+	.read = crps_debugfs_read,
+	.open = simple_open,
+};
+
+static int crps_read_word_data(struct i2c_client *client, int page,

drivers/hwmon/pmbus/crps.c line 149

Quoted 10 lines
drivers/hwmon/pmbus/crps.c new file +10 -0
+				int phase, int reg)
+{
+	int rc;
+
+	switch (reg) {
+	case PMBUS_STATUS_WORD:
+		rc = pmbus_read_word_data(client, page, phase, reg);
+		if (rc < 0)
+			return rc;
+		break;

Why is this needed ?

Quoted 8 lines
drivers/hwmon/pmbus/crps.c new file +8 -0
+	case PMBUS_OT_WARN_LIMIT:
+		rc = pmbus_read_word_data(client, page, phase,
+					  PMBUS_MFR_MAX_TEMP_1);
+		if (rc < 0)
+			return rc;
+		break;
+	case PMBUS_IOUT_OC_WARN_LIMIT:
+		rc = pmbus_read_word_data(client, page, phase,

drivers/hwmon/pmbus/crps.c line 167

Quoted 10 lines
drivers/hwmon/pmbus/crps.c new file +10 -0
+					  CRPS185_MFR_IOUT_MAX);
+		if (rc < 0)
+			return rc;
+		break;
+	case PMBUS_POUT_OP_WARN_LIMIT:
+		rc = pmbus_read_word_data(client, page, phase,
+					  CRPS185_MFR_POUT_MAX);
+		if (rc < 0)
+			return rc;
+		break;

The above three values are more than odd. They duplicate the respective standard rated_max attributes as warning limits. Why ?

On top of that, on writes, the actual warning limits are overwritten. That makes even less sense.

Quoted 58 lines
drivers/hwmon/pmbus/crps.c new file +58 -0
+	default:
+		rc = -ENODATA;
+		break;
+	}
+
+	return rc;
+}
+
+static struct pmbus_driver_info crps_info[] = {
+	[crps185] = {
+		.pages = 1,
+		/* PSU uses default linear data format. */
+		.func[0] = PMBUS_HAVE_PIN | PMBUS_HAVE_IOUT |
+			PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_IIN |
+			PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT |
+			PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+			PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 |
+			PMBUS_HAVE_STATUS_TEMP |
+			PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12,
+		.read_word_data = crps_read_word_data,
+	},
+};
+
+#define to_psu(x, y) container_of((x), struct crps, debugfs_entries[(y)])
+
+static void crps_init_debugfs(struct crps *psu)
+{
+	struct i2c_client *client = psu->client;
+	struct dentry *debugfs;
+	int i;
+
+	/* Don't fail the probe if we can't create debugfs */
+	debugfs = pmbus_get_debugfs_dir(client);
+	if (!debugfs)
+		return;
+
+	for (i = 0; i < CRPS_DEBUGFS_NUM_ENTRIES; ++i)
+		psu->debugfs_entries[i] = i;
+
+	debugfs_create_file("pmbus_revision", 0444, debugfs,
+			    &psu->debugfs_entries[CRPS_DEBUGFS_PMBUS_REVISION],
+			    &crps_debugfs_fops);
+	debugfs_create_file("max_power_out", 0444, debugfs,
+			    &psu->debugfs_entries[CRPS_DEBUGFS_MAX_POWER_OUT],
+			    &crps_debugfs_fops);
+	debugfs_create_file("max_current_out", 0444, debugfs,
+			    &psu->debugfs_entries[CRPS_DEBUGFS_MAX_CURRENT_OUT],
+			    &crps_debugfs_fops);
+}
+
+static int crps_probe(struct i2c_client *client)
+{
+	int rc;
+	struct device *dev = &client->dev;
+	enum models vs = crps_unknown;
+	struct crps *psu;
+	const void *md = of_device_get_match_data(&client->dev);
+	const struct i2c_device_id *id = NULL;

drivers/hwmon/pmbus/crps.c line 235

Quoted 10 lines
drivers/hwmon/pmbus/crps.c new file +10 -0
+	char buf[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
+
+	if (md) {
+		vs = (uintptr_t)md;
+	} else {
+		id = i2c_match_id(crps_id, client);
+		if (id)
+			vs = (enum models)id->driver_data;
+	}
+

Consider using i2c_get_match_data().

drivers/hwmon/pmbus/crps.c line 239

Quoted 4 lines
drivers/hwmon/pmbus/crps.c new file +4 -0
+	if (!vs || vs >= crps_unknown) {
+		dev_err(dev, "Version %d not supported\n", vs);
+		return -EINVAL;
+	}

This is very much pointless. The driver would not be instantiated withut match.

drivers/hwmon/pmbus/crps.c line 244

Quoted 5 lines
drivers/hwmon/pmbus/crps.c new file +5 -0
+
+	rc = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf);
+	if (rc < 0) {
+		dev_err(dev, "Failed to read PMBUS_MFR_MODEL\n");
+		return rc;

dev_err_probe().

drivers/hwmon/pmbus/crps.c line 246

Quoted 2 lines
drivers/hwmon/pmbus/crps.c new file +2 -0
+	}
+	if (strncmp(buf, "03NK260", 7)) {

This should also check and ensure that rc == 7.

drivers/hwmon/pmbus/crps.c line 248

Quoted 2 lines
drivers/hwmon/pmbus/crps.c new file +2 -0
+		buf[rc] = '\0';
+		dev_err(dev, "Model '%s' not supported\n", buf);

dev_err_probe()

drivers/hwmon/pmbus/crps.c line 256

Quoted 8 lines
drivers/hwmon/pmbus/crps.c new file +8 -0
+		return -ENODEV;
+	}
+
+	client->dev.platform_data = &crps_pdata;
+	rc = pmbus_do_probe(client, &crps_info[vs]);
+	if (rc) {
+		dev_err(dev, "Failed to probe %d\n", rc);
+		return rc;

dev_err_probe().

Quoted 4 lines
drivers/hwmon/pmbus/crps.c new file +4 -0
+	}
+
+	/*
+	 * Don't fail the probe if there isn't enough memory for debugfs.

drivers/hwmon/pmbus/crps.c line 270

Quoted 10 lines
drivers/hwmon/pmbus/crps.c new file +10 -0
+	 */
+	psu = devm_kzalloc(&client->dev, sizeof(*psu), GFP_KERNEL);
+	if (!psu) {
+		dev_warn(dev, "Failed to allocate memory. debugfs are not supported.\n");
+		return 0;
+	}
+
+	psu->version = vs;
+	psu->client = client;
+

Drop all this. Add the PMBus version as standard debugfs attribute to the PMBus core if needed/wanted. The rest is already provided as standard sysfs attributes, and reporting the same value in debugfs files adds no value.

Quoted 17 lines
drivers/hwmon/pmbus/crps.c new file +17 -0
+	crps_init_debugfs(psu);
+
+	return 0;
+}
+
+static const struct of_device_id crps_of_match[] = {
+	{
+		.compatible = "intel,crps185",
+		.data = (void *)crps185
+	},
+	{}
+};
+MODULE_DEVICE_TABLE(of, crps_of_match);
+
+static struct i2c_driver crps_driver = {
+	.driver = {
+		.name = "crps",

drivers/hwmon/pmbus/crps.c line 297

Quoted 10 lines
drivers/hwmon/pmbus/crps.c new file +10 -0
+		.of_match_table = crps_of_match,
+	},
+	.probe = crps_probe,
+	.id_table = crps_id,
+};
+
+module_i2c_driver(crps_driver);
+
+MODULE_AUTHOR("Ninad Palsule");
+MODULE_DESCRIPTION("PMBus driver for Common Redundant power supplies");

Again, this is for _Intel_ power supplies.

Quoted 2 lines
drivers/hwmon/pmbus/crps.c new file +2 -0
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("PMBUS");
author maintainer
#3 lore raw

Re: [PATCH v1 1/4] hwmon: pmbus-core: Add label for fan and temp

In reply to Guenter Roeck

Hello Guenter,

Quoted 9 lines · Guenter Roeck
Quoted 8 lines · Ninad Palsule

Adding label files for fan and temperature sensors in the power supply. The openbmc application dbus-sensor(psusensor) requires those files to consfigure those sensors.
Note that prefix for temp label is temp[A..C] used instead of temp[1..3] as dbus-sensor(psusensor) application calculate index based on last digit in the name so we do not want to make index double digit after appending page index.

Quoted 6 lines
Quoted 1 line

We are not going to fix userspace problems in the kernel.

Guenter

Thanks for the quick review.

Sorry I am not clear on this. I feel that it is better to support labels for temperature

sensors and fans like other. Are you saying we should not support these labels or

I need update in the patch to support them better?

Please let me know.

Thanks & Regards,

Ninad Palsule

maintainer
#4 lore raw

Re: [PATCH v1 1/4] hwmon: pmbus-core: Add label for fan and temp

Quoted 19 lines · Ninad Palsule

Hello Guenter,

Quoted 9 lines · Guenter Roeck
Quoted 8 lines · Ninad Palsule

Adding label files for fan and temperature sensors in the power supply. The openbmc application dbus-sensor(psusensor) requires those files to consfigure those sensors.
Note that prefix for temp label is temp[A..C] used instead of temp[1..3] as dbus-sensor(psusensor) application calculate index based on last digit in the name so we do not want to make index double digit after appending page index.

Quoted 6 lines
Quoted 1 line

We are not going to fix userspace problems in the kernel.

Guenter

Quoted 8 lines

Thanks for the quick review.

Sorry I am not clear on this. I feel that it is better to support labels for temperature

sensors and fans like other. Are you saying we should not support these labels or

I need update in the patch to support them better?

There should be no such labels. Labels are supposed to have specific meanings, such as "this is the CPU temperature sensor", not vague meanings such as "tempA".

Guenter

author maintainer
#5 lore raw

Re: [PATCH v1 1/4] hwmon: pmbus-core: Add label for fan and temp

Hi Guenter,

Quoted 26 lines · Guenter Roeck
Quoted 25 lines · Ninad Palsule

Hello Guenter,

Quoted 9 lines · Guenter Roeck
Quoted 8 lines · Ninad Palsule

Adding label files for fan and temperature sensors in the power supply. The openbmc application dbus-sensor(psusensor) requires those files to consfigure those sensors.
Note that prefix for temp label is temp[A..C] used instead of temp[1..3] as dbus-sensor(psusensor) application calculate index based on last digit in the name so we do not want to make index double digit after appending page index.

Quoted 6 lines
Quoted 1 line

We are not going to fix userspace problems in the kernel.

Guenter

Thanks for the quick review.

Sorry I am not clear on this. I feel that it is better to support labels for temperature

sensors and fans like other. Are you saying we should not support these labels or

Quoted 7 lines
Quoted 2 lines

I need update in the patch to support them better?

There should be no such labels. Labels are supposed to have specific meanings, such as "this is the CPU temperature sensor", not vague meanings such as "tempA".

Guenter

Thanks for the quick response. I will remove these changes for now and will talk to you later about

better option.

Thanks & Regards,

Ninad Palsule

author maintainer
#8 lore raw

Re: [PATCH v1 2/4] hwmon: (pmbus/crps) Add Intel CRPS185 power supply

In reply to Guenter Roeck

Hi Guenter,

Thanks for the review!

Quoted 9 lines · Guenter Roeck
Quoted 6 lines · Ninad Palsule

Add the driver to monitor Intel common redundant power supply (crps185) with hwmon over pmbus.

---
  Documentation/hwmon/crps.rst |  95 +++++++++++

Documentation/hwmon/index.rst needs to be updated.

Added the entry. Sorry for that.

Quoted 9 lines
Quoted 9 lines

  MAINTAINERS                  |   7 + drivers/hwmon/pmbus/Kconfig  |   9 ++ drivers/hwmon/pmbus/Makefile |   1 + drivers/hwmon/pmbus/crps.c   | 299 +++++++++++++++++++++++++++++++++++

  5 files changed, 411 insertions(+)

  create mode 100644 Documentation/hwmon/crps.rst
  create mode 100644 drivers/hwmon/pmbus/crps.c

Quoted 12 lines

Documentation/hwmon/crps.rst line 4

Quoted 10 lines
Documentation/hwmon/crps.rst new file +4 -0
new file mode 100644
index 000000000000..81d5dfd68a46
@@ -0,0 +1,95 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver crps
+========================

I am quite sure that this triggers a documentation warning.

Fixed it.

Quoted 10 lines
Quoted 10 lines
Documentation/hwmon/crps.rst new file +9 -0
+
+Supported chips:
+
+  * Intel CRPS185
+
+    Prefix: 'crps185'
+
+    Addresses scanned: -
+
Quoted 8 lines

Documentation/hwmon/crps.rst line 17

Quoted 4 lines
Documentation/hwmon/crps.rst new file +4 -0
+Authors:
+    Ninad Palsule <[email protected]>
+
+

Is the documentation available somewhere ?
If yes, please add a reference. If not, add a comment explaining that it is not available to the public.

There is no public spec, added the comment

Quoted 8 lines
Quoted 6 lines
Documentation/hwmon/crps.rst new file +4 -0
+Description
+-----------
+
+This driver implements support for Common Redundant Power supply 

with PMBus

For _Intel_ ...

Updated.

Quoted 82 lines
Quoted 82 lines
Documentation/hwmon/crps.rst new file +4 -0
+support.
+
+The driver is a client driver to the core PMBus driver.
+Please see Documentation/hwmon/pmbus.rst for details on PMBus client 

drivers.

Documentation/hwmon/crps.rst new file +6 -0
+
+
+Usage Notes
+-----------
+
+This driver does not auto-detect devices. You will have to 

instantiate the
+devices explicitly. Please see
Documentation/i2c/instantiating-devices.rst for

Documentation/hwmon/crps.rst new file +7 -0
+details.
+
+
+Sysfs entries
+-------------
+
+======================= 

======================================================

Documentation/hwmon/crps.rst new file +56 -0
+curr1_label        "iin"
+curr1_input        Measured input current
+curr1_max        Maximum input current
+curr1_max_alarm         Input maximum current high alarm
+curr1_crit              Critial high input current
+curr1_crit_alarm        Input critical current high alarm
+curr1_rated_max        Maximum rated input current
+
+curr2_label        "iout1"
+curr2_input        Measured output current
+curr2_max        Maximum output current
+curr2_max_alarm         Output maximum current high alarm
+curr2_crit            Critial high output current
+curr2_crit_alarm        Output critical current high alarm
+curr2_rated_max        Maximum rated output current
+
+in1_label        "vin"
+in1_input        Measured input voltage
+in1_crit                Critical input over voltage
+in1_crit_alarm          Critical input over voltage alarm
+in1_max                 Maximum input over voltage
+in1_max_alarm           Maximum input over voltage alarm
+in1_rated_min        Minimum rated input voltage
+in1_rated_max        Maximum rated input voltage
+
+in2_label        "vout1"
+in2_input        Measured input voltage
+in2_crit                Critical input over voltage
+in2_crit_alarm          Critical input over voltage alarm
+in2_lcrit               Critical input under voltage fault
+in2_lcrit_alarm         Critical input under voltage fault alarm
+in2_max                 Maximum input over voltage
+in2_max_alarm           Maximum input over voltage alarm
+in2_min                 Minimum input under voltage warning
+in2_min_alarm           Minimum input under voltage warning alarm
+in2_rated_min        Minimum rated input voltage
+in2_rated_max        Maximum rated input voltage
+
+power1_label        "pin"
+power1_input        Measured input power
+power1_alarm        Input power high alarm
+power1_max          Maximum input power
+power1_rated_max        Maximum rated input power
+
+temp[1-2]_input        Measured temperature
+temp[1-2]_crit         Critical temperature
+temp[1-2]_crit_alarm    Critical temperature alarm
+temp[1-2]_max          Maximum temperature
+temp[1-2]_max_alarm     Maximum temperature alarm
+temp[1-2]_rated_max     Maximum rated temperature
+
+fan1_alarm        Fan 1 warning.
+fan1_fault        Fan 1 fault.
+fan1_input        Fan 1 speed in RPM.
+fan1_target             Fan 1 target.
+======================= 

======================================================

MAINTAINERS +0 -0
index 637ddd44245f..6b31d545f0f1 100644
Quoted 8 lines
Quoted 6 lines
MAINTAINERS +0 -0
@@ -6100,6 +6100,13 @@ L:    [email protected]

  S:    Maintained
  F:    drivers/hid/hid-creative-sb0540.c
  +CRPS COMMON REDUNDANT PSU DRIVER

This is _INTEL_ CRPS.

Updated.

Quoted 13 lines
Quoted 13 lines
MAINTAINERS +6 -0
+M:    Ninad Palsule <[email protected]>
+L:    [email protected]
+S:    Maintained
+F:    Documentation/hwmon/crps.rst
+F:    drivers/hwmon/pmbus/crps.c
+

  CRYPTO API
  M:    Herbert Xu <[email protected]>
  M:    "David S. Miller" <[email protected]>

drivers/hwmon/pmbus/Kconfig +0 -1
index 22418a05ced0..56c4eb4b846e 100644
--- a/drivers/hwmon/pmbus/Kconfig
Quoted 8 lines
Quoted 6 lines

+++ b/drivers/hwmon/pmbus/Kconfig

drivers/hwmon/pmbus/Kconfig +0 -0
@@ -85,6 +85,15 @@ config SENSORS_BPA_RS600

        This driver can also be built as a module. If so, the module will be called bpa-rs600.
  +config SENSORS_CRPS
+    tristate "Common Redundant Power Supply"

Again, this is an Intel product.

Fixed.

Quoted 38 lines
Quoted 38 lines

+    help
+      If you say yes here you get hardware monitoring support for the Common
+      Redundant Power Supply.

drivers/hwmon/pmbus/Kconfig +4 -0
+
+      This driver can also be built as a module. If so, the module will
+      be called crps.
+

  config SENSORS_DELTA_AHE50DC_FAN tristate "Delta AHE-50DC fan control module" help

drivers/hwmon/pmbus/Makefile +0 -0
index 3d3183f8d2a7..c7eb7739b7f8 100644
@@ -62,3 +62,4 @@ obj-$(CONFIG_SENSORS_XDPE122)    += xdpe12284.o

  obj-$(CONFIG_SENSORS_XDPE152)    += xdpe152c4.o
  obj-$(CONFIG_SENSORS_ZL6100)    += zl6100.o
  obj-$(CONFIG_SENSORS_PIM4328)    += pim4328.o

drivers/hwmon/pmbus/Makefile +1 -0
+obj-$(CONFIG_SENSORS_CRPS)    += crps.o
drivers/hwmon/pmbus/crps.c new file +11 -0
new file mode 100644
index 000000000000..44d309f81803
@@ -0,0 +1,299 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2024 IBM Corp.
+ */
+
+#include <linux/debugfs.h>
+#include <linux/i2c.h>
+#include <linux/of.h>
+#include <linux/pmbus.h>
+
+#include "pmbus.h"
Quoted 8 lines

drivers/hwmon/pmbus/crps.c line 16

Quoted 5 lines
drivers/hwmon/pmbus/crps.c new file +5 -0
+
+/* Intel crps185 specific commands. */
+#define CRPS185_MFR_IOUT_MAX        0xA6
+#define CRPS185_MFR_POUT_MAX        0xA7
+

I fail to see the point in those defines, even more so since PMBUS_MFR_POUT_MAX and PMBUS_MFR_IOUT_MAX are used below.

Removed these defines.

Quoted 11 lines

drivers/hwmon/pmbus/crps.c line 24

Quoted 9 lines
drivers/hwmon/pmbus/crps.c new file +8 -0
+enum {
+    CRPS_DEBUGFS_PMBUS_REVISION = 0,
+    CRPS_DEBUGFS_MAX_POWER_OUT,
+    CRPS_DEBUGFS_MAX_CURRENT_OUT,
+    CRPS_DEBUGFS_NUM_ENTRIES
+};
+
+enum models { crps185 = 1, crps_unknown };

Pointless enum. The driver only supports a single power supply.

Removed the enum.

Quoted 17 lines
Quoted 11 lines
drivers/hwmon/pmbus/crps.c new file +9 -0
+
+struct crps {
+    enum models version;
+    struct i2c_client *client;
+
+    int debugfs_entries[CRPS_DEBUGFS_NUM_ENTRIES];
+};
+
+#define to_psu(x, y) container_of((x), struct crps, 

debugfs_entries[(y)])

drivers/hwmon/pmbus/crps.c line 37

Quoted 4 lines
drivers/hwmon/pmbus/crps.c new file +4 -0
+
+static struct pmbus_platform_data crps_pdata = {
+    .flags = PMBUS_SKIP_STATUS_CHECK,
+};

Did you confirm that it is needed ? If so, explain why it is needed.

I removed it and still driver is working. I added it because spec did not mention about PMBUS_STATUS_CML

Quoted 60 lines
Quoted 60 lines
drivers/hwmon/pmbus/crps.c new file +9 -0
+
+static const struct i2c_device_id crps_id[] = {
+    { "intel_crps185", crps185 },
+    {}
+};
+MODULE_DEVICE_TABLE(i2c, crps_id);
+
+/*
+ * Convert linear format word to machine format. 11 LSB side bits 

are two's
+ * complement integer mantissa and 5 MSB side bits are two's complement
+ * exponent
+ */

drivers/hwmon/pmbus/crps.c new file +46 -0
+static int crps_convert_linear(int rc)
+{
+    s16 exponent;
+    s32 mantissa;
+    s64 val;
+
+    exponent = ((s16)rc) >> 11;
+    mantissa = ((s16)((rc & 0x7ff) << 5)) >> 5;
+
+    val = mantissa;
+    if (exponent >= 0)
+        val <<= exponent;
+    else
+        val >>= -exponent;
+
+    return (int)val;
+}
+
+static ssize_t crps_debugfs_read(struct file *file, char __user *buf,
+                 size_t count, loff_t *ppos)
+{
+    int rc;
+    int *idxp = file->private_data;
+    int idx = *idxp;
+    struct crps *psu = to_psu(idxp, idx);
+    char data[2 * I2C_SMBUS_BLOCK_MAX] = { 0 };
+
+    rc = pmbus_lock_interruptible(psu->client);
+    if (rc)
+        return rc;
+
+    rc = pmbus_set_page(psu->client, 0, 0xff);
+    if (rc)
+        goto unlock;
+
+    switch (idx) {
+    case CRPS_DEBUGFS_PMBUS_REVISION:
+        rc = i2c_smbus_read_byte_data(psu->client, PMBUS_REVISION);
+        if (rc >= 0) {
+            if (psu->version == crps185) {
+                if (rc == 0)
+                    rc = sprintf(data, "%s", "1.0");
+                else if (rc == 0x11)
+                    rc = sprintf(data, "%s", "1.1");
+                else if (rc == 0x22)
+                    rc = sprintf(data, "%s", "1.2");
Quoted 8 lines
Quoted 6 lines

+                else
+                    rc = snprintf(data, 3, "0x%02x", rc); +            } else {
+                rc = snprintf(data, 3, "%02x", rc); +            }
+        }

This attribute should be added into the PMBus core.

Moved the attribute in the core.

Quoted 17 lines
Quoted 16 lines

+        break;
+    case CRPS_DEBUGFS_MAX_POWER_OUT:
+        rc = i2c_smbus_read_word_data(psu->client, PMBUS_MFR_POUT_MAX); +        if (rc >= 0) {
+            rc = crps_convert_linear(rc);
+            rc = snprintf(data, I2C_SMBUS_BLOCK_MAX, "%d", rc); +        }
+        break;
+    case CRPS_DEBUGFS_MAX_CURRENT_OUT:
+        rc = i2c_smbus_read_word_data(psu->client, PMBUS_MFR_IOUT_MAX); +        if (rc >= 0) {
+            rc = crps_convert_linear(rc);
+            rc = snprintf(data, I2C_SMBUS_BLOCK_MAX, "%d", rc); +        }
+        break;

Quoted 2 lines

What is the point of those two attributes ? There are already standard sysfs attributes reporting those values.

Removed debugfs

Quoted 28 lines
Quoted 28 lines

+    default:
+        rc = -EINVAL;
+        break;
+    }

drivers/hwmon/pmbus/crps.c new file +23 -0
+
+unlock:
+    pmbus_unlock(psu->client);
+    if (rc < 0)
+        return rc;
+
+    data[rc] = '\n';
+    rc += 2;
+
+    return simple_read_from_buffer(buf, count, ppos, data, rc);
+}
+
+static const struct file_operations crps_debugfs_fops = {
+    .llseek = noop_llseek,
+    .read = crps_debugfs_read,
+    .open = simple_open,
+};
+
+static int crps_read_word_data(struct i2c_client *client, int page,
+                int phase, int reg)
+{
+    int rc;
+
Quoted 8 lines
Quoted 6 lines

+    switch (reg) {
+    case PMBUS_STATUS_WORD:
+        rc = pmbus_read_word_data(client, page, phase, reg); +        if (rc < 0)
+            return rc;
+        break;

Why is this needed ?

You are right, removed it.

Quoted 20 lines
Quoted 11 lines

+    case PMBUS_OT_WARN_LIMIT:
+        rc = pmbus_read_word_data(client, page, phase, +                      PMBUS_MFR_MAX_TEMP_1); +        if (rc < 0)
+            return rc;
+        break;
+    case PMBUS_IOUT_OC_WARN_LIMIT:
+        rc = pmbus_read_word_data(client, page, phase, +                      CRPS185_MFR_IOUT_MAX); +        if (rc < 0)

Quoted 8 lines

+            return rc;
+        break;
+    case PMBUS_POUT_OP_WARN_LIMIT:
+        rc = pmbus_read_word_data(client, page, phase, +                      CRPS185_MFR_POUT_MAX); +        if (rc < 0)
+            return rc;
+        break;

Quoted 2 lines

The above three values are more than odd. They duplicate the respective standard rated_max attributes as warning limits. Why ?

I realized that some of these registers exist. So removed it.

Quoted 3 lines

On top of that, on writes, the actual warning limits are overwritten. That makes even less sense.

I have removed read function so now we don't need write too.

Quoted 63 lines
Quoted 63 lines

+    default:
+        rc = -ENODATA;
+        break;
+    }

drivers/hwmon/pmbus/crps.c new file +20 -0
+
+    return rc;
+}
+
+static struct pmbus_driver_info crps_info[] = {
+    [crps185] = {
+        .pages = 1,
+        /* PSU uses default linear data format. */
+        .func[0] = PMBUS_HAVE_PIN | PMBUS_HAVE_IOUT |
+            PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_IIN |
+            PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT |
+            PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+            PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 |
+            PMBUS_HAVE_STATUS_TEMP |
+            PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12,
+        .read_word_data = crps_read_word_data,
+    },
+};
+
+#define to_psu(x, y) container_of((x), struct crps, 

debugfs_entries[(y)])

drivers/hwmon/pmbus/crps.c new file +37 -0
+
+static void crps_init_debugfs(struct crps *psu)
+{
+    struct i2c_client *client = psu->client;
+    struct dentry *debugfs;
+    int i;
+
+    /* Don't fail the probe if we can't create debugfs */
+    debugfs = pmbus_get_debugfs_dir(client);
+    if (!debugfs)
+        return;
+
+    for (i = 0; i < CRPS_DEBUGFS_NUM_ENTRIES; ++i)
+        psu->debugfs_entries[i] = i;
+
+    debugfs_create_file("pmbus_revision", 0444, debugfs,
+ &psu->debugfs_entries[CRPS_DEBUGFS_PMBUS_REVISION],
+                &crps_debugfs_fops);
+    debugfs_create_file("max_power_out", 0444, debugfs,
+ &psu->debugfs_entries[CRPS_DEBUGFS_MAX_POWER_OUT],
+                &crps_debugfs_fops);
+    debugfs_create_file("max_current_out", 0444, debugfs,
+ &psu->debugfs_entries[CRPS_DEBUGFS_MAX_CURRENT_OUT],
+                &crps_debugfs_fops);
+}
+
+static int crps_probe(struct i2c_client *client)
+{
+    int rc;
+    struct device *dev = &client->dev;
+    enum models vs = crps_unknown;
+    struct crps *psu;
+    const void *md = of_device_get_match_data(&client->dev);
+    const struct i2c_device_id *id = NULL;
+    char buf[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
+
+    if (md) {
Quoted 8 lines
Quoted 7 lines

+        vs = (uintptr_t)md;
+    } else {
+        id = i2c_match_id(crps_id, client);
+        if (id)
+            vs = (enum models)id->driver_data;
+    }
+

Consider using i2c_get_match_data().

Removed this code.

Quoted 7 lines
Quoted 5 lines

+    if (!vs || vs >= crps_unknown) {
+        dev_err(dev, "Version %d not supported\n", vs); +        return -EINVAL;
+    }

This is very much pointless. The driver would not be instantiated withut match.

Yes, removed it.

Quoted 8 lines
Quoted 6 lines

+
+    rc = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf); +    if (rc < 0) {
+        dev_err(dev, "Failed to read PMBUS_MFR_MODEL\n"); +        return rc;

dev_err_probe().

Changed to use this function.

Quoted 5 lines
Quoted 3 lines

+    }
+    if (strncmp(buf, "03NK260", 7)) {

This should also check and ensure that rc == 7.

Good idea, Added this check.

Quoted 5 lines
Quoted 3 lines

+        buf[rc] = '\0';
+        dev_err(dev, "Model '%s' not supported\n", buf);

dev_err_probe()

Changed the function

Quoted 11 lines
Quoted 9 lines

+        return -ENODEV;
+    }
+
+    client->dev.platform_data = &crps_pdata; +    rc = pmbus_do_probe(client, &crps_info[vs]); +    if (rc) {
+        dev_err(dev, "Failed to probe %d\n", rc); +        return rc;

dev_err_probe().

Changed this function.

Quoted 12 lines
Quoted 12 lines

+    }
+
+    /*
+     * Don't fail the probe if there isn't enough memory for debugfs. +     */
+    psu = devm_kzalloc(&client->dev, sizeof(*psu), GFP_KERNEL); +    if (!psu) {
+        dev_warn(dev, "Failed to allocate memory. debugfs are not supported.\n");
+        return 0;
+    }

Quoted 8 lines

drivers/hwmon/pmbus/crps.c line 270

Quoted 4 lines
drivers/hwmon/pmbus/crps.c new file +4 -0
+
+    psu->version = vs;
+    psu->client = client;
+

Drop all this. Add the PMBus version as standard debugfs attribute to the PMBus core if needed/wanted. The rest is already provided as standard sysfs attributes, and reporting the same value in debugfs files adds no value.

Yes, Removed debugfs.

Quoted 22 lines
Quoted 22 lines

+    crps_init_debugfs(psu);

drivers/hwmon/pmbus/crps.c new file +20 -0
+
+    return 0;
+}
+
+static const struct of_device_id crps_of_match[] = {
+    {
+        .compatible = "intel,crps185",
+        .data = (void *)crps185
+    },
+    {}
+};
+MODULE_DEVICE_TABLE(of, crps_of_match);
+
+static struct i2c_driver crps_driver = {
+    .driver = {
+        .name = "crps",
+        .of_match_table = crps_of_match,
+    },
+    .probe = crps_probe,
+    .id_table = crps_id,
Quoted 8 lines

drivers/hwmon/pmbus/crps.c line 297

Quoted 6 lines
drivers/hwmon/pmbus/crps.c new file +6 -0
+};
+
+module_i2c_driver(crps_driver);
+
+MODULE_AUTHOR("Ninad Palsule");
+MODULE_DESCRIPTION("PMBus driver for Common Redundant power supplies");

Again, this is for _Intel_ power supplies.

Yes, Added Intel

Thanks and Regards,

Ninad Palsule

Quoted 4 lines
Quoted 3 lines
drivers/hwmon/pmbus/crps.c new file +2 -0
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("PMBUS");
author maintainer
#11 lore raw

Re: [PATCH v1 3/4] dt-bindings: hwmon: intel,crps185: Add to trivial

In reply to Krzysztof Kozlowski

Hi Krzysztof,

Thanks for the review.

Quoted 10 lines · Krzysztof Kozlowski
Quoted 2 lines · Ninad Palsule

Add INTEL Common Redundant Power Supply Versions crps185 bindings as trivial.

becuse they are trivial or you don't care? Some broader context would be useful here.

Best regards,
Krzysztof

Yes, I care for it. I have updated the comment. It is trivial because device tree only need compatibility string.

Thanks & Regards,

Ninad Palsule

Quoted 1 line