linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] hwmon: (pmbus): Infineon IR36021 driver
@ 2021-02-28 23:07 Chris Packham
  2021-02-28 23:07 ` [PATCH 1/2] dt-bindings: trivial-devices: Add infineon,ir36021 Chris Packham
  2021-02-28 23:07 ` [PATCH 2/2] hwmon: (pmbus): Add driver for Infineon IR36021 Chris Packham
  0 siblings, 2 replies; 4+ messages in thread
From: Chris Packham @ 2021-02-28 23:07 UTC (permalink / raw)
  To: robh+dt, jdelvare, linux
  Cc: devicetree, linux-hwmon, linux-kernel, Chris Packham

This adds a basic driver for the IR36021. This chip as both a PMBUS and I2C
interface that is available simultaenously. This driver is just the PMBUS
interface.

Chris Packham (2):
  dt-bindings: trivial-devices: Add infineon,ir36021
  hwmon: (pmbus): Add driver for Infineon IR36021

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

-- 
2.30.0


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

* [PATCH 1/2] dt-bindings: trivial-devices: Add infineon,ir36021
  2021-02-28 23:07 [PATCH 0/2] hwmon: (pmbus): Infineon IR36021 driver Chris Packham
@ 2021-02-28 23:07 ` Chris Packham
  2021-02-28 23:07 ` [PATCH 2/2] hwmon: (pmbus): Add driver for Infineon IR36021 Chris Packham
  1 sibling, 0 replies; 4+ messages in thread
From: Chris Packham @ 2021-02-28 23:07 UTC (permalink / raw)
  To: robh+dt, jdelvare, linux
  Cc: devicetree, linux-hwmon, linux-kernel, Chris Packham, Jiri Kosina

Add infineon,ir36021 to trivial-devices.yaml.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
 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 a327130d1faa..19bc4c301f5b 100644
--- a/Documentation/devicetree/bindings/trivial-devices.yaml
+++ b/Documentation/devicetree/bindings/trivial-devices.yaml
@@ -102,6 +102,8 @@ properties:
           - mps,mp2975
             # G751: Digital Temperature Sensor and Thermal Watchdog with Two-Wire Interface
           - gmt,g751
+            # Infineon IR36021 digital POL buck controller
+          - infineon,ir36021
             # Infineon IR38064 Voltage Regulator
           - infineon,ir38064
             # Infineon SLB9635 (Soft-) I2C TPM (old protocol, max 100khz)
-- 
2.30.0


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

* [PATCH 2/2] hwmon: (pmbus): Add driver for Infineon IR36021
  2021-02-28 23:07 [PATCH 0/2] hwmon: (pmbus): Infineon IR36021 driver Chris Packham
  2021-02-28 23:07 ` [PATCH 1/2] dt-bindings: trivial-devices: Add infineon,ir36021 Chris Packham
@ 2021-02-28 23:07 ` Chris Packham
  2021-03-01  3:06   ` Guenter Roeck
  1 sibling, 1 reply; 4+ messages in thread
From: Chris Packham @ 2021-02-28 23:07 UTC (permalink / raw)
  To: robh+dt, jdelvare, linux
  Cc: devicetree, linux-hwmon, linux-kernel, Chris Packham,
	Jonathan Corbet, linux-doc

The IR36021 is a dual‐loop digital multi‐phase buck controller.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
 Documentation/hwmon/index.rst   |  1 +
 Documentation/hwmon/ir36021.rst | 62 +++++++++++++++++++++++++
 drivers/hwmon/pmbus/Kconfig     |  9 ++++
 drivers/hwmon/pmbus/Makefile    |  1 +
 drivers/hwmon/pmbus/ir36021.c   | 81 +++++++++++++++++++++++++++++++++
 5 files changed, 154 insertions(+)
 create mode 100644 Documentation/hwmon/ir36021.rst
 create mode 100644 drivers/hwmon/pmbus/ir36021.c

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index 8d5a2df1ecb6..b34894403c2b 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -77,6 +77,7 @@ Hardware Monitoring Kernel Drivers
    intel-m10-bmc-hwmon
    ir35221
    ir38064
+   ir36021
    isl68137
    it87
    jc42
diff --git a/Documentation/hwmon/ir36021.rst b/Documentation/hwmon/ir36021.rst
new file mode 100644
index 000000000000..36ef8d518b81
--- /dev/null
+++ b/Documentation/hwmon/ir36021.rst
@@ -0,0 +1,62 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver ir36021
+=====================
+
+Supported chips:
+
+  * Infineon IR36021
+
+    Prefix: ir36021
+    Addresses scanned: -
+
+    Datasheet: Publicly available at the Infineon website
+      https://www.infineon.com/dgdl/ir36021.pdf?fileId=5546d462533600a4015355d0aa2d1775
+
+Authors:
+      - Chris Packham <chris.packham@alliedtelesis.co.nz>
+
+Description
+-----------
+
+The IR36021 is a dual‐loop digital multi‐phase buck controller designed for
+point of load applications.
+
+Usage Notes
+-----------
+
+This driver does not probe for PMBus devices. You will have to instantiate
+devices explicitly.
+
+Sysfs attributes
+----------------
+
+======================= ===========================
+curr1_label             "iin"
+curr1_input             Measured input current
+curr1_alarm             Input fault alarm
+
+curr2_label             "iout1"
+curr2_input             Measured output current
+curr2_alarm             Output over-current alarm
+
+in1_label               "vin"
+in1_input               Measured input voltage
+in1_alarm               Input under-voltage alarm
+
+in2_label               "vout1"
+in2_input               Measured output voltage
+in2_alarm               Output over-voltage alarm
+
+power1_label            "pin"
+power1_input            Measured input power
+power1_alarm            Input under-voltage alarm
+
+power2_label            "pout1"
+power2_input            Measured output power
+
+temp1_input             Measured temperature
+temp1_alarm             Temperature alarm
+
+temp2_input             Measured other loop temperature
+temp2_alarm             Temperature alarm
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index 32d2fc850621..ee8c27b3b83d 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -84,6 +84,15 @@ config SENSORS_IR35221
 	  This driver can also be built as a module. If so, the module will
 	  be called ir35221.
 
+config SENSORS_IR36021
+	tristate "Infineon IR36021"
+	help
+	  If you say yes here you get hardware monitoring support for Infineon
+	  IR36021.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called ir36021.
+
 config SENSORS_IR38064
 	tristate "Infineon IR38064"
 	help
diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
index 6a4ba0fdc1db..685a6bc2b15f 100644
--- a/drivers/hwmon/pmbus/Makefile
+++ b/drivers/hwmon/pmbus/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_SENSORS_BEL_PFE)	+= bel-pfe.o
 obj-$(CONFIG_SENSORS_IBM_CFFPS)	+= ibm-cffps.o
 obj-$(CONFIG_SENSORS_INSPUR_IPSPS) += inspur-ipsps.o
 obj-$(CONFIG_SENSORS_IR35221)	+= ir35221.o
+obj-$(CONFIG_SENSORS_IR36021)	+= ir36021.o
 obj-$(CONFIG_SENSORS_IR38064)	+= ir38064.o
 obj-$(CONFIG_SENSORS_IRPS5401)	+= irps5401.o
 obj-$(CONFIG_SENSORS_ISL68137)	+= isl68137.o
diff --git a/drivers/hwmon/pmbus/ir36021.c b/drivers/hwmon/pmbus/ir36021.c
new file mode 100644
index 000000000000..99b5c7311afd
--- /dev/null
+++ b/drivers/hwmon/pmbus/ir36021.c
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Hardware monitoring driver for Infineon IR36021
+ *
+ * Copyright (c) 2021 Allied Telesis
+ */
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include "pmbus.h"
+
+static struct pmbus_driver_info ir36021_info = {
+	.pages = 1,
+	.format[PSC_VOLTAGE_IN] = linear,
+	.format[PSC_VOLTAGE_OUT] = linear,
+	.format[PSC_CURRENT_IN] = linear,
+	.format[PSC_CURRENT_OUT] = linear,
+	.format[PSC_POWER] = linear,
+	.format[PSC_TEMPERATURE] = linear,
+	.func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT
+		| PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT
+		| PMBUS_HAVE_PIN | PMBUS_HAVE_POUT
+		| PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2
+		| PMBUS_HAVE_STATUS_TEMP,
+};
+
+static int ir36021_probe(struct i2c_client *client,
+			 const struct i2c_device_id *id)
+{
+	u8 buf[I2C_SMBUS_BLOCK_MAX];
+	int ret;
+
+	if (!i2c_check_functionality(client->adapter,
+				     I2C_FUNC_SMBUS_READ_BYTE_DATA
+				     | I2C_FUNC_SMBUS_READ_WORD_DATA
+				     | I2C_FUNC_SMBUS_READ_BLOCK_DATA))
+		return -ENODEV;
+
+	ret = i2c_smbus_read_i2c_block_data(client, PMBUS_MFR_MODEL, 2, buf);
+	if (ret < 0) {
+		dev_err(&client->dev, "Failed to read PMBUS_MFR_MODEL\n");
+		return ret;
+	}
+	if (ret != 2 || !(buf[0] == 0x01 || buf[1] == 0x2d)) {
+		dev_err(&client->dev, "MFR_MODEL unrecognised\n");
+		return -ENODEV;
+	}
+
+	return pmbus_do_probe(client, id, &ir36021_info);
+}
+
+static const struct i2c_device_id ir36021_id[] = {
+	{ "ir36021", 0 },
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, ir36021_id);
+
+static const struct of_device_id __maybe_unused ir36021_of_id[] = {
+	{ .compatible = "infineon,ir36021" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, ir36021_of_id);
+
+static struct i2c_driver ir36021_driver = {
+	.class = I2C_CLASS_HWMON,
+	.driver = {
+		.name = "ir36021",
+		.of_match_table = of_match_ptr(ir36021_of_id),
+	},
+	.probe = ir36021_probe,
+	.remove = pmbus_do_remove,
+	.id_table = ir36021_id,
+};
+
+module_i2c_driver(ir36021_driver);
+
+MODULE_AUTHOR("Chris Packham <chris.packham@alliedtelesis.co.nz>");
+MODULE_DESCRIPTION("PMBus driver for Infineon IR36021");
+MODULE_LICENSE("GPL");
-- 
2.30.0


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

* Re: [PATCH 2/2] hwmon: (pmbus): Add driver for Infineon IR36021
  2021-02-28 23:07 ` [PATCH 2/2] hwmon: (pmbus): Add driver for Infineon IR36021 Chris Packham
@ 2021-03-01  3:06   ` Guenter Roeck
  0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2021-03-01  3:06 UTC (permalink / raw)
  To: Chris Packham, robh+dt, jdelvare
  Cc: devicetree, linux-hwmon, linux-kernel, Jonathan Corbet, linux-doc

Hi Chris,

On 2/28/21 3:07 PM, Chris Packham wrote:
> The IR36021 is a dual‐loop digital multi‐phase buck controller.
> 
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
>  Documentation/hwmon/index.rst   |  1 +
>  Documentation/hwmon/ir36021.rst | 62 +++++++++++++++++++++++++
>  drivers/hwmon/pmbus/Kconfig     |  9 ++++
>  drivers/hwmon/pmbus/Makefile    |  1 +
>  drivers/hwmon/pmbus/ir36021.c   | 81 +++++++++++++++++++++++++++++++++
>  5 files changed, 154 insertions(+)
>  create mode 100644 Documentation/hwmon/ir36021.rst
>  create mode 100644 drivers/hwmon/pmbus/ir36021.c
> 
> diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
> index 8d5a2df1ecb6..b34894403c2b 100644
> --- a/Documentation/hwmon/index.rst
> +++ b/Documentation/hwmon/index.rst
> @@ -77,6 +77,7 @@ Hardware Monitoring Kernel Drivers
>     intel-m10-bmc-hwmon
>     ir35221
>     ir38064
> +   ir36021
>     isl68137
>     it87
>     jc42
> diff --git a/Documentation/hwmon/ir36021.rst b/Documentation/hwmon/ir36021.rst
> new file mode 100644
> index 000000000000..36ef8d518b81
> --- /dev/null
> +++ b/Documentation/hwmon/ir36021.rst
> @@ -0,0 +1,62 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +Kernel driver ir36021
> +=====================
> +
> +Supported chips:
> +
> +  * Infineon IR36021
> +
> +    Prefix: ir36021
> +    Addresses scanned: -
> +
> +    Datasheet: Publicly available at the Infineon website
> +      https://www.infineon.com/dgdl/ir36021.pdf?fileId=5546d462533600a4015355d0aa2d1775
> +
> +Authors:
> +      - Chris Packham <chris.packham@alliedtelesis.co.nz>
> +
> +Description
> +-----------
> +
> +The IR36021 is a dual‐loop digital multi‐phase buck controller designed for
> +point of load applications.
> +
> +Usage Notes
> +-----------
> +
> +This driver does not probe for PMBus devices. You will have to instantiate
> +devices explicitly.
> +
> +Sysfs attributes
> +----------------
> +
> +======================= ===========================
> +curr1_label             "iin"
> +curr1_input             Measured input current
> +curr1_alarm             Input fault alarm
> +
> +curr2_label             "iout1"
> +curr2_input             Measured output current
> +curr2_alarm             Output over-current alarm
> +
> +in1_label               "vin"
> +in1_input               Measured input voltage
> +in1_alarm               Input under-voltage alarm
> +
> +in2_label               "vout1"
> +in2_input               Measured output voltage
> +in2_alarm               Output over-voltage alarm
> +
> +power1_label            "pin"
> +power1_input            Measured input power
> +power1_alarm            Input under-voltage alarm
> +
> +power2_label            "pout1"
> +power2_input            Measured output power
> +
> +temp1_input             Measured temperature
> +temp1_alarm             Temperature alarm
> +
> +temp2_input             Measured other loop temperature
> +temp2_alarm             Temperature alarm
> diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
> index 32d2fc850621..ee8c27b3b83d 100644
> --- a/drivers/hwmon/pmbus/Kconfig
> +++ b/drivers/hwmon/pmbus/Kconfig
> @@ -84,6 +84,15 @@ config SENSORS_IR35221
>  	  This driver can also be built as a module. If so, the module will
>  	  be called ir35221.
>  
> +config SENSORS_IR36021
> +	tristate "Infineon IR36021"
> +	help
> +	  If you say yes here you get hardware monitoring support for Infineon
> +	  IR36021.
> +
> +	  This driver can also be built as a module. If so, the module will
> +	  be called ir36021.
> +
>  config SENSORS_IR38064
>  	tristate "Infineon IR38064"
>  	help
> diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
> index 6a4ba0fdc1db..685a6bc2b15f 100644
> --- a/drivers/hwmon/pmbus/Makefile
> +++ b/drivers/hwmon/pmbus/Makefile
> @@ -11,6 +11,7 @@ obj-$(CONFIG_SENSORS_BEL_PFE)	+= bel-pfe.o
>  obj-$(CONFIG_SENSORS_IBM_CFFPS)	+= ibm-cffps.o
>  obj-$(CONFIG_SENSORS_INSPUR_IPSPS) += inspur-ipsps.o
>  obj-$(CONFIG_SENSORS_IR35221)	+= ir35221.o
> +obj-$(CONFIG_SENSORS_IR36021)	+= ir36021.o
>  obj-$(CONFIG_SENSORS_IR38064)	+= ir38064.o
>  obj-$(CONFIG_SENSORS_IRPS5401)	+= irps5401.o
>  obj-$(CONFIG_SENSORS_ISL68137)	+= isl68137.o
> diff --git a/drivers/hwmon/pmbus/ir36021.c b/drivers/hwmon/pmbus/ir36021.c
> new file mode 100644
> index 000000000000..99b5c7311afd
> --- /dev/null
> +++ b/drivers/hwmon/pmbus/ir36021.c
> @@ -0,0 +1,81 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Hardware monitoring driver for Infineon IR36021
> + *
> + * Copyright (c) 2021 Allied Telesis
> + */
> +#include <linux/err.h>
> +#include <linux/i2c.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include "pmbus.h"
> +
> +static struct pmbus_driver_info ir36021_info = {
> +	.pages = 1,
> +	.format[PSC_VOLTAGE_IN] = linear,
> +	.format[PSC_VOLTAGE_OUT] = linear,
> +	.format[PSC_CURRENT_IN] = linear,
> +	.format[PSC_CURRENT_OUT] = linear,
> +	.format[PSC_POWER] = linear,
> +	.format[PSC_TEMPERATURE] = linear,
> +	.func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT
> +		| PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT
> +		| PMBUS_HAVE_PIN | PMBUS_HAVE_POUT
> +		| PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2
> +		| PMBUS_HAVE_STATUS_TEMP,
> +};
> +
> +static int ir36021_probe(struct i2c_client *client,
> +			 const struct i2c_device_id *id)
> +{
> +	u8 buf[I2C_SMBUS_BLOCK_MAX];
> +	int ret;
> +
> +	if (!i2c_check_functionality(client->adapter,
> +				     I2C_FUNC_SMBUS_READ_BYTE_DATA
> +				     | I2C_FUNC_SMBUS_READ_WORD_DATA
> +				     | I2C_FUNC_SMBUS_READ_BLOCK_DATA))
> +		return -ENODEV;
> +
> +	ret = i2c_smbus_read_i2c_block_data(client, PMBUS_MFR_MODEL, 2, buf);
> +	if (ret < 0) {
> +		dev_err(&client->dev, "Failed to read PMBUS_MFR_MODEL\n");
> +		return ret;
> +	}
> +	if (ret != 2 || !(buf[0] == 0x01 || buf[1] == 0x2d)) {

Please use
			buf[0] != 0x01 || buf[1] != 0x2d

I am not a friend of double negations and find it confusing.

> +		dev_err(&client->dev, "MFR_MODEL unrecognised\n");
> +		return -ENODEV;
> +	}
> +
> +	return pmbus_do_probe(client, id, &ir36021_info);

Please rebase to the latest upstream kernel (parameter change).

> +}
> +
> +static const struct i2c_device_id ir36021_id[] = {
> +	{ "ir36021", 0 },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(i2c, ir36021_id);
> +
> +static const struct of_device_id __maybe_unused ir36021_of_id[] = {
> +	{ .compatible = "infineon,ir36021" },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, ir36021_of_id);
> +
> +static struct i2c_driver ir36021_driver = {
> +	.class = I2C_CLASS_HWMON,
> +	.driver = {
> +		.name = "ir36021",
> +		.of_match_table = of_match_ptr(ir36021_of_id),
> +	},
> +	.probe = ir36021_probe,

Please use the .probe_new callback.

> +	.remove = pmbus_do_remove,

pmbus_do_remove is no longer needed (and does not exist anymore).

Thanks,
Guenter

> +	.id_table = ir36021_id,
> +};
> +
> +module_i2c_driver(ir36021_driver);
> +
> +MODULE_AUTHOR("Chris Packham <chris.packham@alliedtelesis.co.nz>");
> +MODULE_DESCRIPTION("PMBus driver for Infineon IR36021");
> +MODULE_LICENSE("GPL");
> 


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

end of thread, other threads:[~2021-03-01  3:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-28 23:07 [PATCH 0/2] hwmon: (pmbus): Infineon IR36021 driver Chris Packham
2021-02-28 23:07 ` [PATCH 1/2] dt-bindings: trivial-devices: Add infineon,ir36021 Chris Packham
2021-02-28 23:07 ` [PATCH 2/2] hwmon: (pmbus): Add driver for Infineon IR36021 Chris Packham
2021-03-01  3:06   ` 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).