2023-11-03 08:03:51

by Peter Yin

[permalink] [raw]
Subject: [PATCH v1 0/2] hwmon: (pmbus) Add support for MPS Multi-phase mp5990

Add support for MPS Multi-phase mp5990 hsc controller

Change log:
v1: Add support for MPS Multi-phase mp5990 HSC.
---
Peter Yin (2):
dt-bindings: hwmon: Add mps mp5990 driver bindings
hwmon: (pmbus) Add support for MPS Multi-phase mp5990

.../devicetree/bindings/hwmon/mps,mp5990.yaml | 43 +++++++++
Documentation/hwmon/index.rst | 1 +
Documentation/hwmon/mp5990.rst | 84 +++++++++++++++++
drivers/hwmon/pmbus/Kconfig | 9 ++
drivers/hwmon/pmbus/Makefile | 1 +
drivers/hwmon/pmbus/mp5990.c | 90 +++++++++++++++++++
6 files changed, 228 insertions(+)
create mode 100644 Documentation/devicetree/bindings/hwmon/mps,mp5990.yaml
create mode 100644 Documentation/hwmon/mp5990.rst
create mode 100644 drivers/hwmon/pmbus/mp5990.c

--
2.25.1


2023-11-03 08:05:04

by Peter Yin

[permalink] [raw]
Subject: [PATCH v1 1/2] dt-bindings: hwmon: Add mps mp5990 driver bindings

Add a device tree bindings for mp5990 device.

Signed-off-by: Peter Yin <[email protected]>
---
.../devicetree/bindings/hwmon/mps,mp5990.yaml | 43 +++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 Documentation/devicetree/bindings/hwmon/mps,mp5990.yaml

diff --git a/Documentation/devicetree/bindings/hwmon/mps,mp5990.yaml b/Documentation/devicetree/bindings/hwmon/mps,mp5990.yaml
new file mode 100644
index 000000000000..7533d69f1922
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/mps,mp5990.yaml
@@ -0,0 +1,43 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/mps,mp5990.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices MP5990 HSC Controller
+
+maintainers:
+ - Peter Yin <[email protected]>
+
+description: |
+ Analog Devices MP5990 HSC Controller
+
+ Datasheets:
+ https://www.monolithicpower.com/en/mp5990.html
+
+properties:
+ compatible:
+ enum:
+ - mps,mp5990
+
+ reg:
+ description: I2C address of slave device.
+ maxItems: 1
+
+required:
+ - compatible
+ - reg
+
+additionalProperties: false
+
+examples:
+ - |
+ i2c {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ power-sensor@20 {
+ reg = <0x20>;
+ compatible = "mps,mp5990";
+ };
+ };
--
2.25.1

2023-11-03 08:06:26

by Peter Yin

[permalink] [raw]
Subject: [PATCH v1 2/2] hwmon: (pmbus) Add support for MPS Multi-phase mp5990

Add support for mp5990 device from Monolithic Power Systems, Inc. (MPS)
vendor. This is a Hot-Swap Controller.

Signed-off-by: Peter Yin <[email protected]>
---
Documentation/hwmon/index.rst | 1 +
Documentation/hwmon/mp5990.rst | 84 +++++++++++++++++++++++++++++++
drivers/hwmon/pmbus/Kconfig | 9 ++++
drivers/hwmon/pmbus/Makefile | 1 +
drivers/hwmon/pmbus/mp5990.c | 90 ++++++++++++++++++++++++++++++++++
5 files changed, 185 insertions(+)
create mode 100644 Documentation/hwmon/mp5990.rst
create mode 100644 drivers/hwmon/pmbus/mp5990.c

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index 042e1cf9501b..8c70e10fc795 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -157,6 +157,7 @@ Hardware Monitoring Kernel Drivers
mp2888
mp2975
mp5023
+ mp5990
nct6683
nct6775
nct7802
diff --git a/Documentation/hwmon/mp5990.rst b/Documentation/hwmon/mp5990.rst
new file mode 100644
index 000000000000..8fc4e388ff7b
--- /dev/null
+++ b/Documentation/hwmon/mp5990.rst
@@ -0,0 +1,84 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver mp5990
+====================
+
+Supported chips:
+
+ * MPS MP5990
+
+ Prefix: 'mp5990'
+
+ * Datasheet
+
+ Publicly available at the MPS website : https://www.monolithicpower.com/en/mp5990.html
+
+Author:
+
+ Peter Yin <[email protected]>
+
+Description
+-----------
+
+This driver implements support for Monolithic Power Systems, Inc. (MPS)
+MP5990 Hot-Swap Controller.
+
+Device complaint with:
+
+- PMBus rev 1.3 interface.
+
+Device supports direct 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 270b6336b76d..65a116f7744d 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -326,6 +326,15 @@ config SENSORS_MP5023
This driver can also be built as a module. If so, the module will
be called mp5023.

+config SENSORS_MP5990
+ tristate "MPS MP5990"
+ help
+ If you say yes here you get hardware monitoring support for MPS
+ MP5990.
+
+ This driver can also be built as a module. If so, the module will
+ be called mp5990.
+
config SENSORS_MPQ7932_REGULATOR
bool "Regulator support for MPQ7932"
depends on SENSORS_MPQ7932 && REGULATOR
diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
index 84ee960a6c2d..212d9ca0acc9 100644
--- a/drivers/hwmon/pmbus/Makefile
+++ b/drivers/hwmon/pmbus/Makefile
@@ -35,6 +35,7 @@ obj-$(CONFIG_SENSORS_MAX8688) += max8688.o
obj-$(CONFIG_SENSORS_MP2888) += mp2888.o
obj-$(CONFIG_SENSORS_MP2975) += mp2975.o
obj-$(CONFIG_SENSORS_MP5023) += mp5023.o
+obj-$(CONFIG_SENSORS_MP5990) += mp5990.o
obj-$(CONFIG_SENSORS_MPQ7932) += mpq7932.o
obj-$(CONFIG_SENSORS_PLI1209BC) += pli1209bc.o
obj-$(CONFIG_SENSORS_PM6764TR) += pm6764tr.o
diff --git a/drivers/hwmon/pmbus/mp5990.c b/drivers/hwmon/pmbus/mp5990.c
new file mode 100644
index 000000000000..c3b31af9f750
--- /dev/null
+++ b/drivers/hwmon/pmbus/mp5990.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Driver for MPS MP5990 Hot-Swap Controller
+ */
+
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/pmbus.h>
+#include "pmbus.h"
+
+static int mp5990_read_byte_data(struct i2c_client *client, int page, int reg)
+{
+ switch (reg) {
+ case PMBUS_VOUT_MODE:
+ /*
+ Enforce VOUT direct format, C4h reg BIT9
+ default val is not match vout format
+ */
+ return PB_VOUT_MODE_DIRECT;
+ default:
+ return -ENODATA;
+ }
+}
+
+static struct pmbus_driver_info mp5990_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] = 32,
+ .b[PSC_VOLTAGE_IN] = 0,
+ .R[PSC_VOLTAGE_IN] = 0,
+ .m[PSC_VOLTAGE_OUT] = 32,
+ .b[PSC_VOLTAGE_OUT] = 0,
+ .R[PSC_VOLTAGE_OUT] = 0,
+ .m[PSC_CURRENT_OUT] = 16,
+ .b[PSC_CURRENT_OUT] = 0,
+ .R[PSC_CURRENT_OUT] = 0,
+ .m[PSC_POWER] = 1,
+ .b[PSC_POWER] = 0,
+ .R[PSC_POWER] = 0,
+ .m[PSC_TEMPERATURE] = 1,
+ .b[PSC_TEMPERATURE] = 0,
+ .R[PSC_TEMPERATURE] = 0,
+ .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,
+ .read_byte_data = mp5990_read_byte_data,
+};
+
+static int mp5990_probe(struct i2c_client *client)
+{
+ int ret;
+
+ ret = i2c_smbus_write_byte_data(client, PMBUS_VOUT_MODE,
+ PB_VOUT_MODE_DIRECT);
+ if (ret < 0)
+ return ret;
+ return pmbus_do_probe(client, &mp5990_info);
+}
+
+static const struct of_device_id mp5990_of_match[] = {
+ { .compatible = "mps,mp5990" },
+ {}
+};
+
+static const struct i2c_device_id mp5990_id[] = {
+ {"mp5990", 0},
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, mp5990_id);
+
+static struct i2c_driver mp5990_driver = {
+ .driver = {
+ .name = "mp5990",
+ .of_match_table = of_match_ptr(mp5990_of_match),
+ },
+ .probe = mp5990_probe,
+ .id_table = mp5990_id,
+};
+module_i2c_driver(mp5990_driver);
+
+MODULE_AUTHOR("Peter Yin <[email protected]>");
+MODULE_DESCRIPTION("PMBus driver for MP5990 HSC");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS(PMBUS);
--
2.25.1

2023-11-03 12:44:59

by Conor Dooley

[permalink] [raw]
Subject: Re: [PATCH v1 1/2] dt-bindings: hwmon: Add mps mp5990 driver bindings

Hey,

On Fri, Nov 03, 2023 at 04:01:26PM +0800, Peter Yin wrote:
> Add a device tree bindings for mp5990 device.
>
> Signed-off-by: Peter Yin <[email protected]>
> ---
> .../devicetree/bindings/hwmon/mps,mp5990.yaml | 43 +++++++++++++++++++
> 1 file changed, 43 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/hwmon/mps,mp5990.yaml
>
> diff --git a/Documentation/devicetree/bindings/hwmon/mps,mp5990.yaml b/Documentation/devicetree/bindings/hwmon/mps,mp5990.yaml
> new file mode 100644
> index 000000000000..7533d69f1922
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/hwmon/mps,mp5990.yaml
> @@ -0,0 +1,43 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/hwmon/mps,mp5990.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Analog Devices MP5990 HSC Controller

Analog Devices? Also, could you write that out rather than using the
"HSC" acronym?

> +
> +maintainers:
> + - Peter Yin <[email protected]>
> +
> +description: |
> + Analog Devices MP5990 HSC Controller

Ditto here, Analog Devices?

> +
> + Datasheets:
> + https://www.monolithicpower.com/en/mp5990.html
> +
> +properties:
> + compatible:
> + enum:
> + - mps,mp5990

Do you expect this list to grow? If not, just use const: instead of
enum:

> +
> + reg:

> + description: I2C address of slave device.

Can drop this description.

Cheers,
Conor.

> + maxItems: 1
> +
> +required:
> + - compatible
> + - reg
> +
> +additionalProperties: false
> +
> +examples:
> + - |
> + i2c {
> + #address-cells = <1>;
> + #size-cells = <0>;
> +
> + power-sensor@20 {
> + reg = <0x20>;
> + compatible = "mps,mp5990";
> + };
> + };
> --
> 2.25.1
>


Attachments:
(No filename) (1.87 kB)
signature.asc (235.00 B)
Download all attachments

2023-11-03 14:36:31

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v1 2/2] hwmon: (pmbus) Add support for MPS Multi-phase mp5990

On 11/3/23 01:01, Peter Yin wrote:
> Add support for mp5990 device from Monolithic Power Systems, Inc. (MPS)
> vendor. This is a Hot-Swap Controller.
>
> Signed-off-by: Peter Yin <[email protected]>
> ---
> Documentation/hwmon/index.rst | 1 +
> Documentation/hwmon/mp5990.rst | 84 +++++++++++++++++++++++++++++++
> drivers/hwmon/pmbus/Kconfig | 9 ++++
> drivers/hwmon/pmbus/Makefile | 1 +
> drivers/hwmon/pmbus/mp5990.c | 90 ++++++++++++++++++++++++++++++++++
> 5 files changed, 185 insertions(+)
> create mode 100644 Documentation/hwmon/mp5990.rst
> create mode 100644 drivers/hwmon/pmbus/mp5990.c
>
> diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
> index 042e1cf9501b..8c70e10fc795 100644
> --- a/Documentation/hwmon/index.rst
> +++ b/Documentation/hwmon/index.rst
> @@ -157,6 +157,7 @@ Hardware Monitoring Kernel Drivers
> mp2888
> mp2975
> mp5023
> + mp5990
> nct6683
> nct6775
> nct7802
> diff --git a/Documentation/hwmon/mp5990.rst b/Documentation/hwmon/mp5990.rst
> new file mode 100644
> index 000000000000..8fc4e388ff7b
> --- /dev/null
> +++ b/Documentation/hwmon/mp5990.rst
> @@ -0,0 +1,84 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +Kernel driver mp5990
> +====================
> +
> +Supported chips:
> +
> + * MPS MP5990
> +
> + Prefix: 'mp5990'
> +
> + * Datasheet
> +
> + Publicly available at the MPS website : https://www.monolithicpower.com/en/mp5990.html
> +
> +Author:
> +
> + Peter Yin <[email protected]>
> +
> +Description
> +-----------
> +
> +This driver implements support for Monolithic Power Systems, Inc. (MPS)
> +MP5990 Hot-Swap Controller.
> +
> +Device complaint with:

compliant

> +
> +- PMBus rev 1.3 interface.
> +
> +Device supports direct 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 270b6336b76d..65a116f7744d 100644
> --- a/drivers/hwmon/pmbus/Kconfig
> +++ b/drivers/hwmon/pmbus/Kconfig
> @@ -326,6 +326,15 @@ config SENSORS_MP5023
> This driver can also be built as a module. If so, the module will
> be called mp5023.
>
> +config SENSORS_MP5990
> + tristate "MPS MP5990"
> + help
> + If you say yes here you get hardware monitoring support for MPS
> + MP5990.
> +
> + This driver can also be built as a module. If so, the module will
> + be called mp5990.
> +
> config SENSORS_MPQ7932_REGULATOR
> bool "Regulator support for MPQ7932"
> depends on SENSORS_MPQ7932 && REGULATOR
> diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
> index 84ee960a6c2d..212d9ca0acc9 100644
> --- a/drivers/hwmon/pmbus/Makefile
> +++ b/drivers/hwmon/pmbus/Makefile
> @@ -35,6 +35,7 @@ obj-$(CONFIG_SENSORS_MAX8688) += max8688.o
> obj-$(CONFIG_SENSORS_MP2888) += mp2888.o
> obj-$(CONFIG_SENSORS_MP2975) += mp2975.o
> obj-$(CONFIG_SENSORS_MP5023) += mp5023.o
> +obj-$(CONFIG_SENSORS_MP5990) += mp5990.o
> obj-$(CONFIG_SENSORS_MPQ7932) += mpq7932.o
> obj-$(CONFIG_SENSORS_PLI1209BC) += pli1209bc.o
> obj-$(CONFIG_SENSORS_PM6764TR) += pm6764tr.o
> diff --git a/drivers/hwmon/pmbus/mp5990.c b/drivers/hwmon/pmbus/mp5990.c
> new file mode 100644
> index 000000000000..c3b31af9f750
> --- /dev/null
> +++ b/drivers/hwmon/pmbus/mp5990.c
> @@ -0,0 +1,90 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Driver for MPS MP5990 Hot-Swap Controller
> + */
> +
> +#include <linux/i2c.h>
> +#include <linux/module.h>
> +#include <linux/of_device.h>
> +#include <linux/pmbus.h>
> +#include "pmbus.h"
> +
> +static int mp5990_read_byte_data(struct i2c_client *client, int page, int reg)
> +{
> + switch (reg) {
> + case PMBUS_VOUT_MODE:
> + /*
> + Enforce VOUT direct format, C4h reg BIT9
> + default val is not match vout format
> + */

/*
* Please use proper multi-line comments. Also, the problem here is that the
* chip does not support the VOUT_MODE command, which should be mentioned.
*
* On top of that, overwriting PMBUS_VOUT_MODE result from the chip is only
* necessary if the chip does not return an error when reading the value.
* If that is the case, it should be mentioned in the comment. The above
* does not explain why this would be needed, even if the command is not
* (officially) supported by the chip. What does it return that requires
* an overwrite ?
*/

> + return PB_VOUT_MODE_DIRECT;
> + default:
> + return -ENODATA;
> + }
> +}
> +
> +static struct pmbus_driver_info mp5990_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] = 32,
> + .b[PSC_VOLTAGE_IN] = 0,
> + .R[PSC_VOLTAGE_IN] = 0,
> + .m[PSC_VOLTAGE_OUT] = 32,
> + .b[PSC_VOLTAGE_OUT] = 0,
> + .R[PSC_VOLTAGE_OUT] = 0,
> + .m[PSC_CURRENT_OUT] = 16,
> + .b[PSC_CURRENT_OUT] = 0,
> + .R[PSC_CURRENT_OUT] = 0,
> + .m[PSC_POWER] = 1,
> + .b[PSC_POWER] = 0,
> + .R[PSC_POWER] = 0,
> + .m[PSC_TEMPERATURE] = 1,
> + .b[PSC_TEMPERATURE] = 0,
> + .R[PSC_TEMPERATURE] = 0,
> + .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,
> + .read_byte_data = mp5990_read_byte_data,
> +};
> +
> +static int mp5990_probe(struct i2c_client *client)
> +{
> + int ret;
> +
> + ret = i2c_smbus_write_byte_data(client, PMBUS_VOUT_MODE,
> + PB_VOUT_MODE_DIRECT);

According to the datasheet, the chip does not support the VOUT_MODE
command. Supposedly, direct vs. linear mode is selected with bit 9
of EFUSE_CFG. Even if the chip happens to "silently" support the command,
the official command should be used to select the chip mode.

Next question: Why use direct mode ? Linear mode is supported and would
be much more flexible.

> + if (ret < 0)
> + return ret;
> + return pmbus_do_probe(client, &mp5990_info);
> +}
> +
> +static const struct of_device_id mp5990_of_match[] = {
> + { .compatible = "mps,mp5990" },
> + {}
> +};
> +
> +static const struct i2c_device_id mp5990_id[] = {
> + {"mp5990", 0},
> + { }
> +};
> +MODULE_DEVICE_TABLE(i2c, mp5990_id);
> +
> +static struct i2c_driver mp5990_driver = {
> + .driver = {
> + .name = "mp5990",
> + .of_match_table = of_match_ptr(mp5990_of_match),

Using of_match_ptr() will result in a build failure if CONFIG_OF=n.

> + },
> + .probe = mp5990_probe,
> + .id_table = mp5990_id,
> +};
> +module_i2c_driver(mp5990_driver);
> +
> +MODULE_AUTHOR("Peter Yin <[email protected]>");
> +MODULE_DESCRIPTION("PMBus driver for MP5990 HSC");
> +MODULE_LICENSE("GPL");
> +MODULE_IMPORT_NS(PMBUS);

2023-11-06 08:06:38

by Peter Yin

[permalink] [raw]
Subject: Re: [PATCH v1 2/2] hwmon: (pmbus) Add support for MPS Multi-phase mp5990



Guenter Roeck 於 11/3/23 22:35 寫道:
> On 11/3/23 01:01, Peter Yin wrote:
>> Add support for mp5990 device from Monolithic Power Systems, Inc. (MPS)
>> vendor. This is a Hot-Swap Controller.
>>
>> Signed-off-by: Peter Yin <[email protected]>
>> ---
>>   Documentation/hwmon/index.rst  |  1 +
>>   Documentation/hwmon/mp5990.rst | 84 +++++++++++++++++++++++++++++++
>>   drivers/hwmon/pmbus/Kconfig    |  9 ++++
>>   drivers/hwmon/pmbus/Makefile   |  1 +
>>   drivers/hwmon/pmbus/mp5990.c   | 90 ++++++++++++++++++++++++++++++++++
>>   5 files changed, 185 insertions(+)
>>   create mode 100644 Documentation/hwmon/mp5990.rst
>>   create mode 100644 drivers/hwmon/pmbus/mp5990.c
>>
>> diff --git a/Documentation/hwmon/index.rst
>> b/Documentation/hwmon/index.rst
>> index 042e1cf9501b..8c70e10fc795 100644
>> --- a/Documentation/hwmon/index.rst
>> +++ b/Documentation/hwmon/index.rst
>> @@ -157,6 +157,7 @@ Hardware Monitoring Kernel Drivers
>>      mp2888
>>      mp2975
>>      mp5023
>> +   mp5990
>>      nct6683
>>      nct6775
>>      nct7802
>> diff --git a/Documentation/hwmon/mp5990.rst
>> b/Documentation/hwmon/mp5990.rst
>> new file mode 100644
>> index 000000000000..8fc4e388ff7b
>> --- /dev/null
>> +++ b/Documentation/hwmon/mp5990.rst
>> @@ -0,0 +1,84 @@
>> +.. SPDX-License-Identifier: GPL-2.0
>> +
>> +Kernel driver mp5990
>> +====================
>> +
>> +Supported chips:
>> +
>> +  * MPS MP5990
>> +
>> +    Prefix: 'mp5990'
>> +
>> +  * Datasheet
>> +
>> +    Publicly available at the MPS website :
>> https://www.monolithicpower.com/en/mp5990.html
>> +
>> +Author:
>> +
>> +    Peter Yin <[email protected]>
>> +
>> +Description
>> +-----------
>> +
>> +This driver implements support for Monolithic Power Systems, Inc. (MPS)
>> +MP5990 Hot-Swap Controller.
>> +
>> +Device complaint with:
>
> compliant
>
Thanks, I will fix it.
>> +
>> +- PMBus rev 1.3 interface.
>> +
>> +Device supports direct 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 270b6336b76d..65a116f7744d 100644
>> --- a/drivers/hwmon/pmbus/Kconfig
>> +++ b/drivers/hwmon/pmbus/Kconfig
>> @@ -326,6 +326,15 @@ config SENSORS_MP5023
>>         This driver can also be built as a module. If so, the module will
>>         be called mp5023.
>> +config SENSORS_MP5990
>> +    tristate "MPS MP5990"
>> +    help
>> +      If you say yes here you get hardware monitoring support for MPS
>> +      MP5990.
>> +
>> +      This driver can also be built as a module. If so, the module will
>> +      be called mp5990.
>> +
>>   config SENSORS_MPQ7932_REGULATOR
>>       bool "Regulator support for MPQ7932"
>>       depends on SENSORS_MPQ7932 && REGULATOR
>> diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
>> index 84ee960a6c2d..212d9ca0acc9 100644
>> --- a/drivers/hwmon/pmbus/Makefile
>> +++ b/drivers/hwmon/pmbus/Makefile
>> @@ -35,6 +35,7 @@ obj-$(CONFIG_SENSORS_MAX8688)    += max8688.o
>>   obj-$(CONFIG_SENSORS_MP2888)    += mp2888.o
>>   obj-$(CONFIG_SENSORS_MP2975)    += mp2975.o
>>   obj-$(CONFIG_SENSORS_MP5023)    += mp5023.o
>> +obj-$(CONFIG_SENSORS_MP5990)    += mp5990.o
>>   obj-$(CONFIG_SENSORS_MPQ7932)    += mpq7932.o
>>   obj-$(CONFIG_SENSORS_PLI1209BC)    += pli1209bc.o
>>   obj-$(CONFIG_SENSORS_PM6764TR)    += pm6764tr.o
>> diff --git a/drivers/hwmon/pmbus/mp5990.c b/drivers/hwmon/pmbus/mp5990.c
>> new file mode 100644
>> index 000000000000..c3b31af9f750
>> --- /dev/null
>> +++ b/drivers/hwmon/pmbus/mp5990.c
>> @@ -0,0 +1,90 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Driver for MPS MP5990 Hot-Swap Controller
>> + */
>> +
>> +#include <linux/i2c.h>
>> +#include <linux/module.h>
>> +#include <linux/of_device.h>
>> +#include <linux/pmbus.h>
>> +#include "pmbus.h"
>> +
>> +static int mp5990_read_byte_data(struct i2c_client *client, int page,
>> int reg)
>> +{
>> +    switch (reg) {
>> +    case PMBUS_VOUT_MODE:
>> +        /*
>> +          Enforce VOUT direct format, C4h reg BIT9
>> +          default val is not match vout format
>> +         */
>
> /*
>  * Please use proper multi-line comments. Also, the problem here is
> that the
>  * chip does not support the VOUT_MODE command, which should be mentioned.
>  *
>  * On top of that, overwriting PMBUS_VOUT_MODE result from the chip is
> only
>  * necessary if the chip does not return an error when reading the value.
>  * If that is the case, it should be mentioned in the comment. The above
>  * does not explain why this would be needed, even if the command is not
>  * (officially) supported by the chip. What does it return that requires
>  * an overwrite ?
>  */
>
The datasheet does not support the VOUT command, but the device responds
with a default value of 0x17. In the standard, 0x17 represents linear mode.
>> +        return PB_VOUT_MODE_DIRECT;
>> +    default:
>> +        return -ENODATA;
>> +    }
>> +}
>> +
>> +static struct pmbus_driver_info mp5990_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] = 32,
>> +    .b[PSC_VOLTAGE_IN] = 0,
>> +    .R[PSC_VOLTAGE_IN] = 0,
>> +    .m[PSC_VOLTAGE_OUT] = 32,
>> +    .b[PSC_VOLTAGE_OUT] = 0,
>> +    .R[PSC_VOLTAGE_OUT] = 0,
>> +    .m[PSC_CURRENT_OUT] = 16,
>> +    .b[PSC_CURRENT_OUT] = 0,
>> +    .R[PSC_CURRENT_OUT] = 0,
>> +    .m[PSC_POWER] = 1,
>> +    .b[PSC_POWER] = 0,
>> +    .R[PSC_POWER] = 0,
>> +    .m[PSC_TEMPERATURE] = 1,
>> +    .b[PSC_TEMPERATURE] = 0,
>> +    .R[PSC_TEMPERATURE] = 0,
>> +    .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,
>> +    .read_byte_data = mp5990_read_byte_data,
>> +};
>> +
>> +static int mp5990_probe(struct i2c_client *client)
>> +{
>> +    int ret;
>> +
>> +    ret = i2c_smbus_write_byte_data(client, PMBUS_VOUT_MODE,
>> +                    PB_VOUT_MODE_DIRECT);
>
> According to the datasheet, the chip does not support the VOUT_MODE
> command. Supposedly, direct vs. linear mode is selected with bit 9
> of EFUSE_CFG. Even if the chip happens to "silently" support the command,
> the official command should be used to select the chip mode.
>
> Next question: Why use direct mode ? Linear mode is supported and would
> be much more flexible.
>
The MP5990, the VOUT linear mode is linear11, not linear16. Therefore,
we should enforce the VOUT in the direct format.

>> +    if (ret < 0)
>> +        return ret;
>> +    return pmbus_do_probe(client, &mp5990_info);
>> +}
>> +
>> +static const struct of_device_id mp5990_of_match[] = {
>> +    { .compatible = "mps,mp5990" },
>> +    {}
>> +};
>> +
>> +static const struct i2c_device_id mp5990_id[] = {
>> +    {"mp5990", 0},
>> +    { }
>> +};
>> +MODULE_DEVICE_TABLE(i2c, mp5990_id);
>> +
>> +static struct i2c_driver mp5990_driver = {
>> +    .driver = {
>> +           .name = "mp5990",
>> +           .of_match_table = of_match_ptr(mp5990_of_match),
>
> Using of_match_ptr() will result in a build failure if CONFIG_OF=n.
>
Should I use .of_match_table = mp5990_of_match, ?

>> +    },
>> +    .probe = mp5990_probe,
>> +    .id_table = mp5990_id,
>> +};
>> +module_i2c_driver(mp5990_driver);
>> +
>> +MODULE_AUTHOR("Peter Yin <[email protected]>");
>> +MODULE_DESCRIPTION("PMBus driver for MP5990 HSC");
>> +MODULE_LICENSE("GPL");
>> +MODULE_IMPORT_NS(PMBUS);
>

2023-11-06 19:12:06

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v1 2/2] hwmon: (pmbus) Add support for MPS Multi-phase mp5990

On 11/6/23 00:02, PeterYin wrote:
>
[ ... ]
>>> +
>>> +static const struct of_device_id mp5990_of_match[] = {
>>> +    { .compatible = "mps,mp5990" },
>>> +    {}
>>> +};
>>> +
>>> +static const struct i2c_device_id mp5990_id[] = {
>>> +    {"mp5990", 0},
>>> +    { }
>>> +};
>>> +MODULE_DEVICE_TABLE(i2c, mp5990_id);
>>> +
>>> +static struct i2c_driver mp5990_driver = {
>>> +    .driver = {
>>> +           .name = "mp5990",
>>> +           .of_match_table = of_match_ptr(mp5990_of_match),
>>
>> Using of_match_ptr() will result in a build failure if CONFIG_OF=n.
>>
> Should I use .of_match_table = mp5990_of_match, ?
>

Yes.

Thanks,
Guenter

2023-11-07 01:27:47

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v1 2/2] hwmon: (pmbus) Add support for MPS Multi-phase mp5990

Hi Peter,

kernel test robot noticed the following build warnings:

[auto build test WARNING on groeck-staging/hwmon-next]
[also build test WARNING on linus/master v6.6 next-20231106]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Peter-Yin/dt-bindings-hwmon-Add-mps-mp5990-driver-bindings/20231103-160759
base: https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
patch link: https://lore.kernel.org/r/20231103080128.1204218-3-peteryin.openbmc%40gmail.com
patch subject: [PATCH v1 2/2] hwmon: (pmbus) Add support for MPS Multi-phase mp5990
config: xtensa-randconfig-001-20231107 (https://download.01.org/0day-ci/archive/20231107/[email protected]/config)
compiler: xtensa-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231107/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/hwmon/pmbus/mp5990.c:66:34: warning: 'mp5990_of_match' defined but not used [-Wunused-const-variable=]
66 | static const struct of_device_id mp5990_of_match[] = {
| ^~~~~~~~~~~~~~~


vim +/mp5990_of_match +66 drivers/hwmon/pmbus/mp5990.c

65
> 66 static const struct of_device_id mp5990_of_match[] = {
67 { .compatible = "mps,mp5990" },
68 {}
69 };
70

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki