]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
hwmon: (pmbus) add driver for MPS MP9945
authorCosmo Chou <chou.cosmo@gmail.com>
Thu, 9 Oct 2025 20:54:58 +0000 (04:54 +0800)
committerGuenter Roeck <linux@roeck-us.net>
Wed, 15 Oct 2025 18:02:43 +0000 (11:02 -0700)
Add support for mp9945 device from Monolithic Power Systems, Inc.
(MPS) vendor. This is a single phase digital step down converter.

Signed-off-by: Cosmo Chou <chou.cosmo@gmail.com>
Link: https://lore.kernel.org/r/20251009205458.396368-2-chou.cosmo@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Documentation/hwmon/index.rst
Documentation/hwmon/mp9945.rst [new file with mode: 0644]
MAINTAINERS
drivers/hwmon/pmbus/Kconfig
drivers/hwmon/pmbus/Makefile
drivers/hwmon/pmbus/mp9945.c [new file with mode: 0644]

index bebe0e731be7af815f434072e2194beb25d45cbd..45a26927e64f0072faf7397b0840a9bc5116ced7 100644 (file)
@@ -186,6 +186,7 @@ Hardware Monitoring Kernel Drivers
    mp5920
    mp5990
    mp9941
+   mp9945
    mpq8785
    nct6683
    nct6775
diff --git a/Documentation/hwmon/mp9945.rst b/Documentation/hwmon/mp9945.rst
new file mode 100644 (file)
index 0000000..f406f96
--- /dev/null
@@ -0,0 +1,117 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver mp9945
+=====================
+
+Supported chips:
+
+  * MPS mp9945
+
+    Prefix: 'mp9945'
+
+Author:
+
+       Cosmo Chou <chou.cosmo@gmail.com>
+
+Description
+-----------
+
+This driver implements support for Monolithic Power Systems, Inc. (MPS)
+MP9945 Digital Single-phase Controller.
+
+Device compliant with:
+
+- PMBus rev 1.3 interface.
+
+The driver exports the following attributes via the 'sysfs' files
+for input voltage:
+
+**in1_input**
+
+**in1_label**
+
+**in1_crit**
+
+**in1_crit_alarm**
+
+**in1_lcrit**
+
+**in1_lcrit_alarm**
+
+**in1_max**
+
+**in1_max_alarm**
+
+**in1_min**
+
+**in1_min_alarm**
+
+The driver provides the following attributes for output voltage:
+
+**in2_input**
+
+**in2_label**
+
+**in2_crit**
+
+**in2_crit_alarm**
+
+**in2_lcrit**
+
+**in2_lcrit_alarm**
+
+**in2_min**
+
+**in2_min_alarm**
+
+The driver provides the following attributes for input current:
+
+**curr1_input**
+
+**curr1_label**
+
+**curr1_max**
+
+**curr1_max_alarm**
+
+The driver provides the following attributes for output current:
+
+**curr2_input**
+
+**curr2_label**
+
+**curr2_crit**
+
+**curr2_crit_alarm**
+
+**curr2_max**
+
+**curr2_max_alarm**
+
+The driver provides the following attributes for input power:
+
+**power1_input**
+
+**power1_label**
+
+The driver provides the following attributes for output power:
+
+**power2_input**
+
+**power2_label**
+
+**power2_max**
+
+**power2_max_alarm**
+
+The driver provides the following attributes for temperature:
+
+**temp1_input**
+
+**temp1_crit**
+
+**temp1_crit_alarm**
+
+**temp1_max**
+
+**temp1_max_alarm**
index 953bf1d29a812936d55cf83fe983e255dc18c5a2..4a6e00df8a389d8690d614026abe9cb5b197e7b0 100644 (file)
@@ -17499,6 +17499,13 @@ S:     Maintained
 F:     Documentation/hwmon/mp9941.rst
 F:     drivers/hwmon/pmbus/mp9941.c
 
+MPS MP9945 DRIVER
+M:     Cosmo Chou <chou.cosmo@gmail.com>
+L:     linux-hwmon@vger.kernel.org
+S:     Maintained
+F:     Documentation/hwmon/mp9945.rst
+F:     drivers/hwmon/pmbus/mp9945.c
+
 MR800 AVERMEDIA USB FM RADIO DRIVER
 M:     Alexey Klimov <alexey.klimov@linaro.org>
 L:     linux-media@vger.kernel.org
index fdcef5dfa5a8c4eac484e872de5ae6ef0503fe9b..f3fb94cebf1ad37f5943969892e5a4e947bd3b3f 100644 (file)
@@ -490,6 +490,15 @@ config SENSORS_MP9941
          This driver can also be built as a module. If so, the module will
          be called mp9941.
 
+config SENSORS_MP9945
+       tristate "MPS MP9945"
+       help
+         If you say yes here you get hardware monitoring support for MPS
+         MP9945.
+
+         This driver can also be built as a module. If so, the module will
+         be called mp9945.
+
 config SENSORS_MPQ7932_REGULATOR
        bool "Regulator support for MPQ7932"
        depends on SENSORS_MPQ7932 && REGULATOR
index 43fbc546fb5d5d1e83f061639354be9e99a7fb56..349a89b6d92eb739f8549dc3371b87e81c5d2c88 100644 (file)
@@ -49,6 +49,7 @@ obj-$(CONFIG_SENSORS_MP5023)  += mp5023.o
 obj-$(CONFIG_SENSORS_MP5920)   += mp5920.o
 obj-$(CONFIG_SENSORS_MP5990)   += mp5990.o
 obj-$(CONFIG_SENSORS_MP9941)   += mp9941.o
+obj-$(CONFIG_SENSORS_MP9945)   += mp9945.o
 obj-$(CONFIG_SENSORS_MPQ7932)  += mpq7932.o
 obj-$(CONFIG_SENSORS_MPQ8785)  += mpq8785.o
 obj-$(CONFIG_SENSORS_PLI1209BC)        += pli1209bc.o
diff --git a/drivers/hwmon/pmbus/mp9945.c b/drivers/hwmon/pmbus/mp9945.c
new file mode 100644 (file)
index 0000000..34822e0
--- /dev/null
@@ -0,0 +1,243 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Hardware monitoring driver for MPS Single-phase Digital VR Controllers(MP9945)
+ */
+
+#include <linux/bitfield.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include "pmbus.h"
+
+#define MFR_VR_MULTI_CONFIG_R1 0x08
+#define MFR_SVID_CFG_R1                0xBD
+
+/* VOUT_MODE register values */
+#define VOUT_MODE_LINEAR16     0x17
+#define VOUT_MODE_VID          0x21
+#define VOUT_MODE_DIRECT       0x40
+
+#define MP9945_PAGE_NUM                1
+
+#define MP9945_RAIL1_FUNC      (PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | \
+                               PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | \
+                               PMBUS_HAVE_PIN | PMBUS_HAVE_POUT | \
+                               PMBUS_HAVE_TEMP | \
+                               PMBUS_HAVE_STATUS_VOUT | \
+                               PMBUS_HAVE_STATUS_IOUT | \
+                               PMBUS_HAVE_STATUS_TEMP | \
+                               PMBUS_HAVE_STATUS_INPUT)
+
+enum mp9945_vout_mode {
+       MP9945_VOUT_MODE_VID,
+       MP9945_VOUT_MODE_DIRECT,
+       MP9945_VOUT_MODE_LINEAR16,
+};
+
+struct mp9945_data {
+       struct pmbus_driver_info info;
+       enum mp9945_vout_mode vout_mode;
+       int vid_resolution;
+       int vid_offset;
+};
+
+#define to_mp9945_data(x) container_of(x, struct mp9945_data, info)
+
+static int mp9945_read_vout(struct i2c_client *client, struct mp9945_data *data)
+{
+       int ret;
+
+       ret = i2c_smbus_read_word_data(client, PMBUS_READ_VOUT);
+       if (ret < 0)
+               return ret;
+
+       ret &= GENMASK(11, 0);
+
+       switch (data->vout_mode) {
+       case MP9945_VOUT_MODE_VID:
+               if (ret > 0)
+                       ret = (ret + data->vid_offset) * data->vid_resolution;
+               break;
+       case MP9945_VOUT_MODE_DIRECT:
+               break;
+       case MP9945_VOUT_MODE_LINEAR16:
+               /* LSB: 1000 * 2^-9 (mV) */
+               ret = DIV_ROUND_CLOSEST(ret * 125, 64);
+               break;
+       default:
+               return -ENODEV;
+       }
+
+       return ret;
+}
+
+static int mp9945_read_byte_data(struct i2c_client *client, int page, int reg)
+{
+       int ret;
+
+       ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
+       if (ret < 0)
+               return ret;
+
+       switch (reg) {
+       case PMBUS_VOUT_MODE:
+               /*
+                * Override VOUT_MODE to DIRECT as the driver handles custom
+                * VOUT format conversions internally.
+                */
+               return PB_VOUT_MODE_DIRECT;
+       default:
+               return -ENODATA;
+       }
+}
+
+static int mp9945_read_word_data(struct i2c_client *client, int page, int phase,
+                                int reg)
+{
+       const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+       struct mp9945_data *data = to_mp9945_data(info);
+       int ret;
+
+       ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
+       if (ret < 0)
+               return ret;
+
+       switch (reg) {
+       case PMBUS_READ_VOUT:
+               ret = mp9945_read_vout(client, data);
+               break;
+       case PMBUS_VOUT_OV_FAULT_LIMIT:
+       case PMBUS_VOUT_UV_FAULT_LIMIT:
+               ret = i2c_smbus_read_word_data(client, reg);
+               if (ret < 0)
+                       return ret;
+
+               /* LSB: 1.95 (mV) */
+               ret = DIV_ROUND_CLOSEST((ret & GENMASK(11, 0)) * 39, 20);
+               break;
+       case PMBUS_VOUT_UV_WARN_LIMIT:
+               ret = i2c_smbus_read_word_data(client, reg);
+               if (ret < 0)
+                       return ret;
+
+               ret &= GENMASK(9, 0);
+               if (ret > 0)
+                       ret = (ret + data->vid_offset) * data->vid_resolution;
+               break;
+       default:
+               ret = -ENODATA;
+               break;
+       }
+
+       return ret;
+}
+
+static int mp9945_identify(struct i2c_client *client,
+                          struct pmbus_driver_info *info)
+{
+       struct mp9945_data *data = to_mp9945_data(info);
+       int ret;
+
+       ret = i2c_smbus_read_byte_data(client, PMBUS_VOUT_MODE);
+       if (ret < 0)
+               return ret;
+
+       switch (ret) {
+       case VOUT_MODE_LINEAR16:
+               data->vout_mode = MP9945_VOUT_MODE_LINEAR16;
+               break;
+       case VOUT_MODE_VID:
+               data->vout_mode = MP9945_VOUT_MODE_VID;
+               break;
+       case VOUT_MODE_DIRECT:
+               data->vout_mode = MP9945_VOUT_MODE_DIRECT;
+               break;
+       default:
+               return -ENODEV;
+       }
+
+       ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 3);
+       if (ret < 0)
+               return ret;
+
+       ret = i2c_smbus_read_word_data(client, MFR_VR_MULTI_CONFIG_R1);
+       if (ret < 0)
+               return ret;
+
+       data->vid_resolution = (FIELD_GET(BIT(2), ret)) ? 5 : 10;
+
+       ret = i2c_smbus_read_word_data(client, MFR_SVID_CFG_R1);
+       if (ret < 0)
+               return ret;
+
+       data->vid_offset = (FIELD_GET(BIT(15), ret)) ? 19 : 49;
+
+       return i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
+}
+
+static struct pmbus_driver_info mp9945_info = {
+       .pages = MP9945_PAGE_NUM,
+       .format[PSC_VOLTAGE_IN] = linear,
+       .format[PSC_VOLTAGE_OUT] = direct,
+       .format[PSC_CURRENT_IN] = linear,
+       .format[PSC_CURRENT_OUT] = linear,
+       .format[PSC_POWER] = linear,
+       .format[PSC_TEMPERATURE] = linear,
+       .m[PSC_VOLTAGE_OUT] = 1,
+       .R[PSC_VOLTAGE_OUT] = 3,
+       .b[PSC_VOLTAGE_OUT] = 0,
+       .func[0] = MP9945_RAIL1_FUNC,
+       .read_word_data = mp9945_read_word_data,
+       .read_byte_data = mp9945_read_byte_data,
+       .identify = mp9945_identify,
+};
+
+static int mp9945_probe(struct i2c_client *client)
+{
+       struct mp9945_data *data;
+       int ret;
+
+       data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
+       if (!data)
+               return -ENOMEM;
+
+       memcpy(&data->info, &mp9945_info, sizeof(mp9945_info));
+
+       /*
+        * Set page 0 before probe. The core reads paged registers which are
+        * only on page 0 for this device.
+        */
+       ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
+       if (ret < 0)
+               return ret;
+
+       return pmbus_do_probe(client, &data->info);
+}
+
+static const struct i2c_device_id mp9945_id[] = {
+       {"mp9945"},
+       {}
+};
+MODULE_DEVICE_TABLE(i2c, mp9945_id);
+
+static const struct of_device_id __maybe_unused mp9945_of_match[] = {
+       {.compatible = "mps,mp9945"},
+       {}
+};
+MODULE_DEVICE_TABLE(of, mp9945_of_match);
+
+static struct i2c_driver mp9945_driver = {
+       .driver = {
+               .name = "mp9945",
+               .of_match_table = of_match_ptr(mp9945_of_match),
+       },
+       .probe = mp9945_probe,
+       .id_table = mp9945_id,
+};
+
+module_i2c_driver(mp9945_driver);
+
+MODULE_AUTHOR("Cosmo Chou <chou.cosmo@gmail.com>");
+MODULE_DESCRIPTION("PMBus driver for MPS MP9945");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("PMBUS");