linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] hwmon: (pmbus) Add support for Infineon XDP710
@ 2024-04-25 15:36 Peter Yin
  2024-04-25 15:36 ` [PATCH v2 1/2] " Peter Yin
  2024-04-25 15:36 ` [PATCH v2 2/2] dt-bindings: hwmon: Add infineon xdp710 driver bindings Peter Yin
  0 siblings, 2 replies; 10+ messages in thread
From: Peter Yin @ 2024-04-25 15:36 UTC (permalink / raw)
  To: patrick, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Jean Delvare, Guenter Roeck, Jonathan Corbet, Delphine CC Chiu,
	Patrick Rudolph, Andre Werner, Bjorn Helgaas, Michal Simek,
	Lukas Wunner, devicetree, linux-kernel, linux-hwmon, linux-doc,
	linux-i2c

Add support for xdp710 device from Infineon vendor.
This is a Hot-Swap Controller.

Change log:
v1 -> v2
    - Merged patch 3 into patch 1.
    - Modified comments.
    - Fixed the microOhmRsense array.
    - Improved operational accuracy.

v1
    - Add support for xdp710 hot-swap device from Infineon vendor
---

Peter Yin (2):
  hwmon: (pmbus) Add support for Infineon XDP710
  dt-bindings: hwmon: Add infineon xdp710 driver bindings

 .../devicetree/bindings/trivial-devices.yaml  |   2 +
 Documentation/hwmon/index.rst                 |   1 +
 Documentation/hwmon/xdp710.rst                |  83 +++++++++++
 drivers/hwmon/pmbus/Kconfig                   |   9 ++
 drivers/hwmon/pmbus/Makefile                  |   1 +
 drivers/hwmon/pmbus/xdp710.c                  | 132 ++++++++++++++++++
 6 files changed, 228 insertions(+)
 create mode 100644 Documentation/hwmon/xdp710.rst
 create mode 100644 drivers/hwmon/pmbus/xdp710.c

-- 
2.25.1


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

* [PATCH v2 1/2] hwmon: (pmbus) Add support for Infineon XDP710
  2024-04-25 15:36 [PATCH v2 0/2] hwmon: (pmbus) Add support for Infineon XDP710 Peter Yin
@ 2024-04-25 15:36 ` Peter Yin
  2024-04-28 17:27   ` Guenter Roeck
  2024-04-25 15:36 ` [PATCH v2 2/2] dt-bindings: hwmon: Add infineon xdp710 driver bindings Peter Yin
  1 sibling, 1 reply; 10+ messages in thread
From: Peter Yin @ 2024-04-25 15:36 UTC (permalink / raw)
  To: patrick, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Jean Delvare, Guenter Roeck, Jonathan Corbet, Delphine CC Chiu,
	Patrick Rudolph, Bjorn Helgaas, Ninad Palsule, Fabio Estevam,
	Lukas Wunner, devicetree, linux-kernel, linux-hwmon, linux-doc,
	linux-i2c

Add support for Infineon XDP710.This is a Hot-Swap Controller.

Signed-off-by: Peter Yin <peteryin.openbmc@gmail.com>
---
 Documentation/hwmon/index.rst  |   1 +
 Documentation/hwmon/xdp710.rst |  83 +++++++++++++++++++++
 drivers/hwmon/pmbus/Kconfig    |   9 +++
 drivers/hwmon/pmbus/Makefile   |   1 +
 drivers/hwmon/pmbus/xdp710.c   | 132 +++++++++++++++++++++++++++++++++
 5 files changed, 226 insertions(+)
 create mode 100644 Documentation/hwmon/xdp710.rst
 create mode 100644 drivers/hwmon/pmbus/xdp710.c

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index 1ca7a4fe1f8f..b2546925fb15 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -250,6 +250,7 @@ Hardware Monitoring Kernel Drivers
    wm831x
    wm8350
    xgene-hwmon
+   xdp710
    xdpe12284
    xdpe152c4
    zl6100
diff --git a/Documentation/hwmon/xdp710.rst b/Documentation/hwmon/xdp710.rst
new file mode 100644
index 000000000000..083891f27818
--- /dev/null
+++ b/Documentation/hwmon/xdp710.rst
@@ -0,0 +1,83 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver xdp710
+====================
+
+Supported chips:
+
+  * Infineon XDP710
+
+    Prefix: 'xdp710'
+
+  * Datasheet
+
+    Publicly available at the Infineon website : https://www.infineon.com/dgdl/Infineon-XDP710-001-DataSheet-v01_00-EN.pdf?fileId=8ac78c8c8412f8d301848a5316290b97
+
+Author:
+
+	Peter Yin <peteryin.openbmc@gmail.com>
+
+Description
+-----------
+
+This driver implements support for Infineon XDP710 Hot-Swap Controller.
+
+Device compliant with:
+
+- PMBus rev 1.3 interface.
+
+Device supports direct and linear format for reading input voltage,
+output voltage, output current, input power and temperature.
+
+The driver exports the following attributes via the 'sysfs' files
+for input voltage:
+
+**in1_input**
+
+**in1_label**
+
+**in1_max**
+
+**in1_max_alarm**
+
+**in1_min**
+
+**in1_min_alarm**
+
+The driver provides the following attributes for output voltage:
+
+**in2_input**
+
+**in2_label**
+
+**in2_alarm**
+
+The driver provides the following attributes for output current:
+
+**curr1_input**
+
+**curr1_label**
+
+**curr1_alarm**
+
+**curr1_max**
+
+The driver provides the following attributes for input power:
+
+**power1_input**
+
+**power1_label**
+
+**power1_alarm**
+
+The driver provides the following attributes for temperature:
+
+**temp1_input**
+
+**temp1_max**
+
+**temp1_max_alarm**
+
+**temp1_crit**
+
+**temp1_crit_alarm**
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index 557ae0c414b0..c775128c2ea7 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -511,6 +511,15 @@ config SENSORS_UCD9200
 	  This driver can also be built as a module. If so, the module will
 	  be called ucd9200.
 
+config SENSORS_XDP710
+	tristate "Infineon XDP710 family"
+	help
+	  If you say yes here you get hardware monitoring support for Infineon
+	  XDP710.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called xdp710.
+
 config SENSORS_XDPE152
 	tristate "Infineon XDPE152 family"
 	help
diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
index f14ecf03ad77..4fe630793721 100644
--- a/drivers/hwmon/pmbus/Makefile
+++ b/drivers/hwmon/pmbus/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_SENSORS_TPS53679)	+= tps53679.o
 obj-$(CONFIG_SENSORS_TPS546D24)	+= tps546d24.o
 obj-$(CONFIG_SENSORS_UCD9000)	+= ucd9000.o
 obj-$(CONFIG_SENSORS_UCD9200)	+= ucd9200.o
+obj-$(CONFIG_SENSORS_XDP710)	+= xdp710.o
 obj-$(CONFIG_SENSORS_XDPE122)	+= xdpe12284.o
 obj-$(CONFIG_SENSORS_XDPE152)	+= xdpe152c4.o
 obj-$(CONFIG_SENSORS_ZL6100)	+= zl6100.o
diff --git a/drivers/hwmon/pmbus/xdp710.c b/drivers/hwmon/pmbus/xdp710.c
new file mode 100644
index 000000000000..a00f79cda5e5
--- /dev/null
+++ b/drivers/hwmon/pmbus/xdp710.c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Driver for Infineon XDP710 Hot-Swap Controller
+ */
+
+#include <linux/bitops.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include "pmbus.h"
+
+#define XDP710_REG_CFG		0xD3
+#define XDP710_V_SNS_CFG	0xD4
+#define XDP710_CS_RNG		0xD5
+
+/*
+ * The table to map configuration register values
+ * to sense resistor values
+ */
+const int microOhmRsense[] = {
+	200, 250, 300, 330, 400, 470, 500, 600,
+	670, 700, 750, 800, 900, 1000, 1100, 1200,
+	1250, 1300, 1400, 1500, 1600, 1700, 1800, 1900,
+	2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700,
+	2800, 3000, 3100, 3200, 3300, 3400, 3500, 3600,
+	3700, 3800, 3900, 4000, 4100, 4200, 4300, 4400,
+	4500, 4600, 4700, 4800, 4900, 5000, 5500, 6000,
+	6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000
+};
+
+static struct pmbus_driver_info xdp710_info = {
+	.pages = 1,
+	.format[PSC_VOLTAGE_IN] = direct,
+	.format[PSC_VOLTAGE_OUT] = direct,
+	.format[PSC_CURRENT_OUT] = direct,
+	.format[PSC_POWER] = direct,
+	.format[PSC_TEMPERATURE] = direct,
+	.m[PSC_VOLTAGE_IN] = 4653,
+	.b[PSC_VOLTAGE_IN] = 0,
+	.R[PSC_VOLTAGE_IN] = -2,
+	.m[PSC_VOLTAGE_OUT] = 4653,
+	.b[PSC_VOLTAGE_OUT] = 0,
+	.R[PSC_VOLTAGE_OUT] = -2,
+	.m[PSC_CURRENT_OUT] = 23165,
+	.b[PSC_CURRENT_OUT] = 0,
+	.R[PSC_CURRENT_OUT] = -2,
+	.m[PSC_POWER] = 4211,
+	.b[PSC_POWER] = 0,
+	.R[PSC_POWER] = -2,
+	.m[PSC_TEMPERATURE] = 52,
+	.b[PSC_TEMPERATURE] = 14321,
+	.R[PSC_TEMPERATURE] = -1,
+	.func[0] =
+		PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_PIN |
+		PMBUS_HAVE_TEMP | PMBUS_HAVE_IOUT |
+		PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP,
+};
+
+static int xdp710_probe(struct i2c_client *client)
+{
+	struct pmbus_driver_info *info;
+	u8 cs_rng;
+	u8 vtlm_rng;
+	int rsense;
+	int ret;
+	int m = 0;
+
+	info = devm_kmemdup(&client->dev, &xdp710_info, sizeof(*info),
+			    GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+
+	ret = i2c_smbus_read_word_data(client, XDP710_CS_RNG);
+	if (ret < 0) {
+		dev_err(&client->dev, "Can't get CS_RNG");
+		return ret;
+	}
+	cs_rng = (ret >> 6) & GENMASK(1, 0);
+
+	ret = i2c_smbus_read_word_data(client, XDP710_V_SNS_CFG);
+	if (ret < 0) {
+		dev_err(&client->dev, "Can't get V_SNS_CFG");
+		return ret;
+	}
+	vtlm_rng = ret & GENMASK(1, 0);
+
+	ret = i2c_smbus_read_word_data(client, XDP710_REG_CFG);
+	if (ret < 0) {
+		dev_err(&client->dev, "Can't get REG_CFG");
+		return ret;
+	}
+	ret &= GENMASK(5, 0);
+	rsense = microOhmRsense[ret];
+
+	info->m[PSC_VOLTAGE_IN] <<= vtlm_rng;
+	info->m[PSC_VOLTAGE_OUT] <<= vtlm_rng;
+
+	m = info->m[PSC_CURRENT_OUT];
+	info->m[PSC_CURRENT_OUT] = DIV_ROUND_CLOSEST(m * rsense >> cs_rng,
+						     1000);
+
+	m = info->m[PSC_POWER];
+	info->m[PSC_POWER] = DIV_ROUND_CLOSEST(m * rsense >> cs_rng, 1000);
+
+	return pmbus_do_probe(client, info);
+}
+
+static const struct of_device_id xdp710_of_match[] = {
+	{ .compatible = "infineon,xdp710" },
+	{}
+};
+
+static const struct i2c_device_id xdp710_id[] = {
+	{"xdp710", 0},
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, xdp710_id);
+
+static struct i2c_driver xdp710_driver = {
+	.driver = {
+		   .name = "xdp710",
+		   .of_match_table = xdp710_of_match,
+	},
+	.probe = xdp710_probe,
+	.id_table = xdp710_id,
+};
+module_i2c_driver(xdp710_driver);
+
+MODULE_AUTHOR("Peter Yin <peter.yin@quantatw.com>");
+MODULE_DESCRIPTION("PMBus driver for XDP710 HSC");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS(PMBUS);
-- 
2.25.1


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

* [PATCH v2 2/2] dt-bindings: hwmon: Add infineon xdp710 driver bindings
  2024-04-25 15:36 [PATCH v2 0/2] hwmon: (pmbus) Add support for Infineon XDP710 Peter Yin
  2024-04-25 15:36 ` [PATCH v2 1/2] " Peter Yin
@ 2024-04-25 15:36 ` Peter Yin
  2024-04-26  6:54   ` Krzysztof Kozlowski
  2024-04-28 17:23   ` Guenter Roeck
  1 sibling, 2 replies; 10+ messages in thread
From: Peter Yin @ 2024-04-25 15:36 UTC (permalink / raw)
  To: patrick, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Jean Delvare, Guenter Roeck, Jonathan Corbet, Delphine CC Chiu,
	Patrick Rudolph, Luca Ceresoli, Charles Hsu, Bjorn Helgaas,
	Lukas Wunner, devicetree, linux-kernel, linux-hwmon, linux-doc,
	linux-i2c

Add a device tree bindings for xdp710 device

Acked-by: "Rob Herring (Arm)" <robh@kernel.org>
Signed-off-by: Peter Yin <peteryin.openbmc@gmail.com>
---
 Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/trivial-devices.yaml b/Documentation/devicetree/bindings/trivial-devices.yaml
index e07be7bf8395..f982de168c4c 100644
--- a/Documentation/devicetree/bindings/trivial-devices.yaml
+++ b/Documentation/devicetree/bindings/trivial-devices.yaml
@@ -134,6 +134,8 @@ properties:
           - infineon,irps5401
             # Infineon TLV493D-A1B6 I2C 3D Magnetic Sensor
           - infineon,tlv493d-a1b6
+            # Infineon Hot-swap controller xdp710
+          - infineon,xdp710
             # Infineon Multi-phase Digital VR Controller xdpe11280
           - infineon,xdpe11280
             # Infineon Multi-phase Digital VR Controller xdpe12254
-- 
2.25.1


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

* Re: [PATCH v2 2/2] dt-bindings: hwmon: Add infineon xdp710 driver bindings
  2024-04-25 15:36 ` [PATCH v2 2/2] dt-bindings: hwmon: Add infineon xdp710 driver bindings Peter Yin
@ 2024-04-26  6:54   ` Krzysztof Kozlowski
  2024-04-26  7:12     ` Chia Hsing Yin
  2024-04-28 17:23   ` Guenter Roeck
  1 sibling, 1 reply; 10+ messages in thread
From: Krzysztof Kozlowski @ 2024-04-26  6:54 UTC (permalink / raw)
  To: Peter Yin, patrick, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Jean Delvare, Guenter Roeck, Jonathan Corbet,
	Delphine CC Chiu, Patrick Rudolph, Luca Ceresoli, Charles Hsu,
	Bjorn Helgaas, Lukas Wunner, devicetree, linux-kernel,
	linux-hwmon, linux-doc, linux-i2c

On 25/04/2024 17:36, Peter Yin wrote:
> Add a device tree bindings for xdp710 device
> 
> Acked-by: "Rob Herring (Arm)" <robh@kernel.org>

That's not the tag you received. Please do not modify the tags. Quotes
are not needed.

Best regards,
Krzysztof


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

* Re: [PATCH v2 2/2] dt-bindings: hwmon: Add infineon xdp710 driver bindings
  2024-04-26  6:54   ` Krzysztof Kozlowski
@ 2024-04-26  7:12     ` Chia Hsing Yin
  2024-04-26  8:20       ` Krzysztof Kozlowski
  0 siblings, 1 reply; 10+ messages in thread
From: Chia Hsing Yin @ 2024-04-26  7:12 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: patrick, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Jean Delvare, Guenter Roeck, Jonathan Corbet, Delphine CC Chiu,
	Patrick Rudolph, Luca Ceresoli, Charles Hsu, Bjorn Helgaas,
	Lukas Wunner, devicetree, linux-kernel, linux-hwmon, linux-doc,
	linux-i2c

I use b4 download and apply it, I think it is a tool issue, I can fix
in the next version.
Thank you for your feedback.

On Fri, Apr 26, 2024 at 2:55 PM Krzysztof Kozlowski <krzk@kernel.org> wrote:
>
> On 25/04/2024 17:36, Peter Yin wrote:
> > Add a device tree bindings for xdp710 device
> >
> > Acked-by: "Rob Herring (Arm)" <robh@kernel.org>
>
> That's not the tag you received. Please do not modify the tags. Quotes
> are not needed.
>
> Best regards,
> Krzysztof
>

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

* Re: [PATCH v2 2/2] dt-bindings: hwmon: Add infineon xdp710 driver bindings
  2024-04-26  7:12     ` Chia Hsing Yin
@ 2024-04-26  8:20       ` Krzysztof Kozlowski
  2024-04-26 20:38         ` Konstantin Ryabitsev
  0 siblings, 1 reply; 10+ messages in thread
From: Krzysztof Kozlowski @ 2024-04-26  8:20 UTC (permalink / raw)
  To: Chia Hsing Yin
  Cc: patrick, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Jean Delvare, Guenter Roeck, Jonathan Corbet, Delphine CC Chiu,
	Patrick Rudolph, Luca Ceresoli, Charles Hsu, Bjorn Helgaas,
	Lukas Wunner, devicetree, linux-kernel, linux-hwmon, linux-doc,
	linux-i2c

On 26/04/2024 09:12, Chia Hsing Yin wrote:
> I use b4 download and apply it, I think it is a tool issue, I can fix
> in the next version.

Just did it now:

b4 trailers -C -u -F '20240424095604.3425857-1-peteryin.openbmc@gmail.com>'
Calculating patch-ids from commits, this may take a moment...
Grabbing thread from
lore.kernel.org/all/20240424095604.3425857-1-peteryin.openbmc@gmail.com/t.mbox.gz
Looking for additional code-review trailers on lore.kernel.org
---
  dt-bindings: hwmon: Add infineon xdp710 driver bindings
    + Acked-by: Rob Herring (Arm) <robh@kernel.org> (✓ DKIM/kernel.org)


And no quotes...

Best regards,
Krzysztof


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

* Re: [PATCH v2 2/2] dt-bindings: hwmon: Add infineon xdp710 driver bindings
  2024-04-26  8:20       ` Krzysztof Kozlowski
@ 2024-04-26 20:38         ` Konstantin Ryabitsev
  2024-04-29  1:17           ` Peter Yin
  0 siblings, 1 reply; 10+ messages in thread
From: Konstantin Ryabitsev @ 2024-04-26 20:38 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Chia Hsing Yin, patrick, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Jean Delvare, Guenter Roeck, Jonathan Corbet,
	Delphine CC Chiu, Patrick Rudolph, Luca Ceresoli, Charles Hsu,
	Bjorn Helgaas, Lukas Wunner, devicetree, linux-kernel,
	linux-hwmon, linux-doc, linux-i2c

On Fri, Apr 26, 2024 at 10:20:58AM GMT, Krzysztof Kozlowski wrote:
> On 26/04/2024 09:12, Chia Hsing Yin wrote:
> > I use b4 download and apply it, I think it is a tool issue, I can fix
> > in the next version.
> 
> Just did it now:
> 
> b4 trailers -C -u -F '20240424095604.3425857-1-peteryin.openbmc@gmail.com>'
> Calculating patch-ids from commits, this may take a moment...
> Grabbing thread from
> lore.kernel.org/all/20240424095604.3425857-1-peteryin.openbmc@gmail.com/t.mbox.gz
> Looking for additional code-review trailers on lore.kernel.org
> ---
>   dt-bindings: hwmon: Add infineon xdp710 driver bindings
>     + Acked-by: Rob Herring (Arm) <robh@kernel.org> (✓ DKIM/kernel.org)
> 
> 
> And no quotes...

Yes, this was fixed in b4-0.12.4 and b4-0.13.

-K

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

* Re: [PATCH v2 2/2] dt-bindings: hwmon: Add infineon xdp710 driver bindings
  2024-04-25 15:36 ` [PATCH v2 2/2] dt-bindings: hwmon: Add infineon xdp710 driver bindings Peter Yin
  2024-04-26  6:54   ` Krzysztof Kozlowski
@ 2024-04-28 17:23   ` Guenter Roeck
  1 sibling, 0 replies; 10+ messages in thread
From: Guenter Roeck @ 2024-04-28 17:23 UTC (permalink / raw)
  To: Peter Yin
  Cc: patrick, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Jean Delvare, Jonathan Corbet, Delphine CC Chiu, Patrick Rudolph,
	Luca Ceresoli, Charles Hsu, Bjorn Helgaas, Lukas Wunner,
	devicetree, linux-kernel, linux-hwmon, linux-doc, linux-i2c

On Thu, Apr 25, 2024 at 11:36:02PM +0800, Peter Yin wrote:
> Add a device tree bindings for xdp710 device
> 
> Acked-by: "Rob Herring (Arm)" <robh@kernel.org>
> Signed-off-by: Peter Yin <peteryin.openbmc@gmail.com>

Applied, after fixing the tag.

Guenter

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

* Re: [PATCH v2 1/2] hwmon: (pmbus) Add support for Infineon XDP710
  2024-04-25 15:36 ` [PATCH v2 1/2] " Peter Yin
@ 2024-04-28 17:27   ` Guenter Roeck
  0 siblings, 0 replies; 10+ messages in thread
From: Guenter Roeck @ 2024-04-28 17:27 UTC (permalink / raw)
  To: Peter Yin
  Cc: patrick, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Jean Delvare, Jonathan Corbet, Delphine CC Chiu, Patrick Rudolph,
	Bjorn Helgaas, Ninad Palsule, Fabio Estevam, Lukas Wunner,
	devicetree, linux-kernel, linux-hwmon, linux-doc, linux-i2c

On Thu, Apr 25, 2024 at 11:36:01PM +0800, Peter Yin wrote:
> Add support for Infineon XDP710.This is a Hot-Swap Controller.
> 
> Signed-off-by: Peter Yin <peteryin.openbmc@gmail.com>

Applied, after "s/microOhmRsense/micro_ohm_rsense/g"

Guenter

> ---
>  Documentation/hwmon/index.rst  |   1 +
>  Documentation/hwmon/xdp710.rst |  83 +++++++++++++++++++++
>  drivers/hwmon/pmbus/Kconfig    |   9 +++
>  drivers/hwmon/pmbus/Makefile   |   1 +
>  drivers/hwmon/pmbus/xdp710.c   | 132 +++++++++++++++++++++++++++++++++
>  5 files changed, 226 insertions(+)
>  create mode 100644 Documentation/hwmon/xdp710.rst
>  create mode 100644 drivers/hwmon/pmbus/xdp710.c
> 
> diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
> index 1ca7a4fe1f8f..b2546925fb15 100644
> --- a/Documentation/hwmon/index.rst
> +++ b/Documentation/hwmon/index.rst
> @@ -250,6 +250,7 @@ Hardware Monitoring Kernel Drivers
>     wm831x
>     wm8350
>     xgene-hwmon
> +   xdp710
>     xdpe12284
>     xdpe152c4
>     zl6100
> diff --git a/Documentation/hwmon/xdp710.rst b/Documentation/hwmon/xdp710.rst
> new file mode 100644
> index 000000000000..083891f27818
> --- /dev/null
> +++ b/Documentation/hwmon/xdp710.rst
> @@ -0,0 +1,83 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +Kernel driver xdp710
> +====================
> +
> +Supported chips:
> +
> +  * Infineon XDP710
> +
> +    Prefix: 'xdp710'
> +
> +  * Datasheet
> +
> +    Publicly available at the Infineon website : https://www.infineon.com/dgdl/Infineon-XDP710-001-DataSheet-v01_00-EN.pdf?fileId=8ac78c8c8412f8d301848a5316290b97
> +
> +Author:
> +
> +	Peter Yin <peteryin.openbmc@gmail.com>
> +
> +Description
> +-----------
> +
> +This driver implements support for Infineon XDP710 Hot-Swap Controller.
> +
> +Device compliant with:
> +
> +- PMBus rev 1.3 interface.
> +
> +Device supports direct and linear format for reading input voltage,
> +output voltage, output current, input power and temperature.
> +
> +The driver exports the following attributes via the 'sysfs' files
> +for input voltage:
> +
> +**in1_input**
> +
> +**in1_label**
> +
> +**in1_max**
> +
> +**in1_max_alarm**
> +
> +**in1_min**
> +
> +**in1_min_alarm**
> +
> +The driver provides the following attributes for output voltage:
> +
> +**in2_input**
> +
> +**in2_label**
> +
> +**in2_alarm**
> +
> +The driver provides the following attributes for output current:
> +
> +**curr1_input**
> +
> +**curr1_label**
> +
> +**curr1_alarm**
> +
> +**curr1_max**
> +
> +The driver provides the following attributes for input power:
> +
> +**power1_input**
> +
> +**power1_label**
> +
> +**power1_alarm**
> +
> +The driver provides the following attributes for temperature:
> +
> +**temp1_input**
> +
> +**temp1_max**
> +
> +**temp1_max_alarm**
> +
> +**temp1_crit**
> +
> +**temp1_crit_alarm**
> diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
> index 557ae0c414b0..c775128c2ea7 100644
> --- a/drivers/hwmon/pmbus/Kconfig
> +++ b/drivers/hwmon/pmbus/Kconfig
> @@ -511,6 +511,15 @@ config SENSORS_UCD9200
>  	  This driver can also be built as a module. If so, the module will
>  	  be called ucd9200.
>  
> +config SENSORS_XDP710
> +	tristate "Infineon XDP710 family"
> +	help
> +	  If you say yes here you get hardware monitoring support for Infineon
> +	  XDP710.
> +
> +	  This driver can also be built as a module. If so, the module will
> +	  be called xdp710.
> +
>  config SENSORS_XDPE152
>  	tristate "Infineon XDPE152 family"
>  	help
> diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
> index f14ecf03ad77..4fe630793721 100644
> --- a/drivers/hwmon/pmbus/Makefile
> +++ b/drivers/hwmon/pmbus/Makefile
> @@ -51,6 +51,7 @@ obj-$(CONFIG_SENSORS_TPS53679)	+= tps53679.o
>  obj-$(CONFIG_SENSORS_TPS546D24)	+= tps546d24.o
>  obj-$(CONFIG_SENSORS_UCD9000)	+= ucd9000.o
>  obj-$(CONFIG_SENSORS_UCD9200)	+= ucd9200.o
> +obj-$(CONFIG_SENSORS_XDP710)	+= xdp710.o
>  obj-$(CONFIG_SENSORS_XDPE122)	+= xdpe12284.o
>  obj-$(CONFIG_SENSORS_XDPE152)	+= xdpe152c4.o
>  obj-$(CONFIG_SENSORS_ZL6100)	+= zl6100.o
> diff --git a/drivers/hwmon/pmbus/xdp710.c b/drivers/hwmon/pmbus/xdp710.c
> new file mode 100644
> index 000000000000..a00f79cda5e5
> --- /dev/null
> +++ b/drivers/hwmon/pmbus/xdp710.c
> @@ -0,0 +1,132 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Driver for Infineon XDP710 Hot-Swap Controller
> + */
> +
> +#include <linux/bitops.h>
> +#include <linux/i2c.h>
> +#include <linux/module.h>
> +#include <linux/of_device.h>
> +#include "pmbus.h"
> +
> +#define XDP710_REG_CFG		0xD3
> +#define XDP710_V_SNS_CFG	0xD4
> +#define XDP710_CS_RNG		0xD5
> +
> +/*
> + * The table to map configuration register values
> + * to sense resistor values
> + */
> +const int microOhmRsense[] = {
> +	200, 250, 300, 330, 400, 470, 500, 600,
> +	670, 700, 750, 800, 900, 1000, 1100, 1200,
> +	1250, 1300, 1400, 1500, 1600, 1700, 1800, 1900,
> +	2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700,
> +	2800, 3000, 3100, 3200, 3300, 3400, 3500, 3600,
> +	3700, 3800, 3900, 4000, 4100, 4200, 4300, 4400,
> +	4500, 4600, 4700, 4800, 4900, 5000, 5500, 6000,
> +	6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000
> +};
> +
> +static struct pmbus_driver_info xdp710_info = {
> +	.pages = 1,
> +	.format[PSC_VOLTAGE_IN] = direct,
> +	.format[PSC_VOLTAGE_OUT] = direct,
> +	.format[PSC_CURRENT_OUT] = direct,
> +	.format[PSC_POWER] = direct,
> +	.format[PSC_TEMPERATURE] = direct,
> +	.m[PSC_VOLTAGE_IN] = 4653,
> +	.b[PSC_VOLTAGE_IN] = 0,
> +	.R[PSC_VOLTAGE_IN] = -2,
> +	.m[PSC_VOLTAGE_OUT] = 4653,
> +	.b[PSC_VOLTAGE_OUT] = 0,
> +	.R[PSC_VOLTAGE_OUT] = -2,
> +	.m[PSC_CURRENT_OUT] = 23165,
> +	.b[PSC_CURRENT_OUT] = 0,
> +	.R[PSC_CURRENT_OUT] = -2,
> +	.m[PSC_POWER] = 4211,
> +	.b[PSC_POWER] = 0,
> +	.R[PSC_POWER] = -2,
> +	.m[PSC_TEMPERATURE] = 52,
> +	.b[PSC_TEMPERATURE] = 14321,
> +	.R[PSC_TEMPERATURE] = -1,
> +	.func[0] =
> +		PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_PIN |
> +		PMBUS_HAVE_TEMP | PMBUS_HAVE_IOUT |
> +		PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP,
> +};
> +
> +static int xdp710_probe(struct i2c_client *client)
> +{
> +	struct pmbus_driver_info *info;
> +	u8 cs_rng;
> +	u8 vtlm_rng;
> +	int rsense;
> +	int ret;
> +	int m = 0;
> +
> +	info = devm_kmemdup(&client->dev, &xdp710_info, sizeof(*info),
> +			    GFP_KERNEL);
> +	if (!info)
> +		return -ENOMEM;
> +
> +	ret = i2c_smbus_read_word_data(client, XDP710_CS_RNG);
> +	if (ret < 0) {
> +		dev_err(&client->dev, "Can't get CS_RNG");
> +		return ret;
> +	}
> +	cs_rng = (ret >> 6) & GENMASK(1, 0);
> +
> +	ret = i2c_smbus_read_word_data(client, XDP710_V_SNS_CFG);
> +	if (ret < 0) {
> +		dev_err(&client->dev, "Can't get V_SNS_CFG");
> +		return ret;
> +	}
> +	vtlm_rng = ret & GENMASK(1, 0);
> +
> +	ret = i2c_smbus_read_word_data(client, XDP710_REG_CFG);
> +	if (ret < 0) {
> +		dev_err(&client->dev, "Can't get REG_CFG");
> +		return ret;
> +	}
> +	ret &= GENMASK(5, 0);
> +	rsense = microOhmRsense[ret];
> +
> +	info->m[PSC_VOLTAGE_IN] <<= vtlm_rng;
> +	info->m[PSC_VOLTAGE_OUT] <<= vtlm_rng;
> +
> +	m = info->m[PSC_CURRENT_OUT];
> +	info->m[PSC_CURRENT_OUT] = DIV_ROUND_CLOSEST(m * rsense >> cs_rng,
> +						     1000);
> +
> +	m = info->m[PSC_POWER];
> +	info->m[PSC_POWER] = DIV_ROUND_CLOSEST(m * rsense >> cs_rng, 1000);
> +
> +	return pmbus_do_probe(client, info);
> +}
> +
> +static const struct of_device_id xdp710_of_match[] = {
> +	{ .compatible = "infineon,xdp710" },
> +	{}
> +};
> +
> +static const struct i2c_device_id xdp710_id[] = {
> +	{"xdp710", 0},
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(i2c, xdp710_id);
> +
> +static struct i2c_driver xdp710_driver = {
> +	.driver = {
> +		   .name = "xdp710",
> +		   .of_match_table = xdp710_of_match,
> +	},
> +	.probe = xdp710_probe,
> +	.id_table = xdp710_id,
> +};
> +module_i2c_driver(xdp710_driver);
> +
> +MODULE_AUTHOR("Peter Yin <peter.yin@quantatw.com>");
> +MODULE_DESCRIPTION("PMBus driver for XDP710 HSC");
> +MODULE_LICENSE("GPL");
> +MODULE_IMPORT_NS(PMBUS);

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

* Re: [PATCH v2 2/2] dt-bindings: hwmon: Add infineon xdp710 driver bindings
  2024-04-26 20:38         ` Konstantin Ryabitsev
@ 2024-04-29  1:17           ` Peter Yin
  0 siblings, 0 replies; 10+ messages in thread
From: Peter Yin @ 2024-04-29  1:17 UTC (permalink / raw)
  To: Konstantin Ryabitsev
  Cc: Krzysztof Kozlowski, patrick, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Jean Delvare, Guenter Roeck, Jonathan Corbet,
	Delphine CC Chiu, Patrick Rudolph, Luca Ceresoli, Charles Hsu,
	Bjorn Helgaas, Lukas Wunner, devicetree, linux-kernel,
	linux-hwmon, linux-doc, linux-i2c

Thank you for the information you provided.

On Sat, Apr 27, 2024 at 4:38 AM Konstantin Ryabitsev
<konstantin@linuxfoundation.org> wrote:
>
> On Fri, Apr 26, 2024 at 10:20:58AM GMT, Krzysztof Kozlowski wrote:
> > On 26/04/2024 09:12, Chia Hsing Yin wrote:
> > > I use b4 download and apply it, I think it is a tool issue, I can fix
> > > in the next version.
> >
> > Just did it now:
> >
> > b4 trailers -C -u -F '20240424095604.3425857-1-peteryin.openbmc@gmail.com>'
> > Calculating patch-ids from commits, this may take a moment...
> > Grabbing thread from
> > lore.kernel.org/all/20240424095604.3425857-1-peteryin.openbmc@gmail.com/t.mbox.gz
> > Looking for additional code-review trailers on lore.kernel.org
> > ---
> >   dt-bindings: hwmon: Add infineon xdp710 driver bindings
> >     + Acked-by: Rob Herring (Arm) <robh@kernel.org> (✓ DKIM/kernel.org)
> >
> >
> > And no quotes...
>
> Yes, this was fixed in b4-0.12.4 and b4-0.13.
>
> -K

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

end of thread, other threads:[~2024-04-29  1:17 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-25 15:36 [PATCH v2 0/2] hwmon: (pmbus) Add support for Infineon XDP710 Peter Yin
2024-04-25 15:36 ` [PATCH v2 1/2] " Peter Yin
2024-04-28 17:27   ` Guenter Roeck
2024-04-25 15:36 ` [PATCH v2 2/2] dt-bindings: hwmon: Add infineon xdp710 driver bindings Peter Yin
2024-04-26  6:54   ` Krzysztof Kozlowski
2024-04-26  7:12     ` Chia Hsing Yin
2024-04-26  8:20       ` Krzysztof Kozlowski
2024-04-26 20:38         ` Konstantin Ryabitsev
2024-04-29  1:17           ` Peter Yin
2024-04-28 17:23   ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).