Skip to contentSkip to conversation

hwmon: (pmbus) Add support for MPS MP2949A

PATCH Superseded [email protected] 3 participants 5 messages Jun 22, 2021

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 hwmon: (pmbus) Add support for MPS MP2949A

From: "Ainux.Wang" <[email protected]>

Add support for MP2949A device from Monolithic Power Systems, Inc. (MPS). This is a triple-loop, digital, multi-phase controller.
This device:
- Supports up to three power rail.
- Provides 6 pulse-width modulations (PWMs), and can be configured up to 6-phase operation for Rail A , up to 2-phase operation for Rail B and up to 1-phase operation for Rail C.
- The PMBus registers are distributed into three pages: Page 0, Page 1, Page 2. Page 0 contains the registers for Rail A and most of the common settings for all of the rails. Page 1 contains register information for Rail B. Page 2 contains register information for Rail C.
- The MP2949A supports both 5mV VID step and 10mv VID step for IMVP8 and IMVP9.

v3:
- Added change log here.
- Errors in the document have been modified.
- Fixed PMBUS_VOUT_MODE to MP2949A_MFR_VR_CONFIG.
- Removed unnecessary vout_params and empty line.

v2:
- Reference has been added to Documentation/hwmon/index.rst.
- Droped 'vendor'.
- Removed change codes of the PMBus core and added mp2949a_identify() and mp2949a_read_byte_data() to this driver.

v1:
- Add support for MPS MP2949A.

---
 Documentation/hwmon/index.rst   |   1 +
 Documentation/hwmon/mp2949a.rst |  44 ++++++++++++
 drivers/hwmon/pmbus/Kconfig     |   9 +++
 drivers/hwmon/pmbus/Makefile    |   1 +
 drivers/hwmon/pmbus/mp2949a.c   | 118 ++++++++++++++++++++++++++++++++
 5 files changed, 173 insertions(+)
 create mode 100644 Documentation/hwmon/mp2949a.rst
 create mode 100644 drivers/hwmon/pmbus/mp2949a.c
Documentation/hwmon/index.rst +1 -0
index 9ed60fa84cbe..56aac3b1678d 100644
@@ -137,6 +137,7 @@ Hardware Monitoring Kernel Drivers
    mcp3021
    menf21bmc
    mlxreg-fan
+   mp2949a
    mp2975
    nct6683
    nct6775
Documentation/hwmon/mp2949a.rst new file +44 -0

44 lines not on this page · raw message

drivers/hwmon/pmbus/Kconfig +9 -0
index 37a5c39784fa..b1344b265976 100644
@@ -248,6 +248,15 @@ config SENSORS_MAX8688
 	  This driver can also be built as a module. If so, the module will
 	  be called max8688.
 
+config SENSORS_MP2949A
+	tristate "MPS MP2949A"
+	help
+	  If you say yes here you get hardware monitoring support for MPS
+	  MP2949A Triple Loop Digital Multi-Phase Controller.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called mp2949a.
+
 config SENSORS_MP2975
 	tristate "MPS MP2975"
 	help
drivers/hwmon/pmbus/Makefile +1 -0
index f8dcc27cd56a..bfb55ab12da1 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_SENSORS_MAX20751)	+= max20751.o
 obj-$(CONFIG_SENSORS_MAX31785)	+= max31785.o
 obj-$(CONFIG_SENSORS_MAX34440)	+= max34440.o
 obj-$(CONFIG_SENSORS_MAX8688)	+= max8688.o
+obj-$(CONFIG_SENSORS_MP2949A)	+= mp2949a.o
 obj-$(CONFIG_SENSORS_MP2975)	+= mp2975.o
 obj-$(CONFIG_SENSORS_PM6764TR)	+= pm6764tr.o
 obj-$(CONFIG_SENSORS_PXE1610)	+= pxe1610.o
drivers/hwmon/pmbus/mp2949a.c new file +118 -0

118 lines not on this page · raw message

Signature · 1 line
2.18.1
maintainer
#1 lore raw
Quoted 161 lines · On Tue, Jun 22, 2021 at 09:50:11AM +0800, [email protected] wrote:

From: "Ainux.Wang" <[email protected]>

Add support for MP2949A device from Monolithic Power Systems, Inc. (MPS). This is a triple-loop, digital, multi-phase controller.
This device:
- Supports up to three power rail.
- Provides 6 pulse-width modulations (PWMs), and can be configured up to 6-phase operation for Rail A , up to 2-phase operation for Rail B and up to 1-phase operation for Rail C.
- The PMBus registers are distributed into three pages: Page 0, Page 1, Page 2. Page 0 contains the registers for Rail A and most of the common settings for all of the rails. Page 1 contains register information for Rail B. Page 2 contains register information for Rail C.
- The MP2949A supports both 5mV VID step and 10mv VID step for IMVP8 and IMVP9.

v3:
- Added change log here.
- Errors in the document have been modified.
- Fixed PMBUS_VOUT_MODE to MP2949A_MFR_VR_CONFIG.
- Removed unnecessary vout_params and empty line.

v2:
- Reference has been added to Documentation/hwmon/index.rst.
- Droped 'vendor'.
- Removed change codes of the PMBus core and added mp2949a_identify() and mp2949a_read_byte_data() to this driver.

v1:
- Add support for MPS MP2949A.

---
 Documentation/hwmon/index.rst   |   1 +
 Documentation/hwmon/mp2949a.rst |  44 ++++++++++++
 drivers/hwmon/pmbus/Kconfig     |   9 +++
 drivers/hwmon/pmbus/Makefile    |   1 +
 drivers/hwmon/pmbus/mp2949a.c   | 118 ++++++++++++++++++++++++++++++++
 5 files changed, 173 insertions(+)
 create mode 100644 Documentation/hwmon/mp2949a.rst
 create mode 100644 drivers/hwmon/pmbus/mp2949a.c
Documentation/hwmon/index.rst +1 -0
index 9ed60fa84cbe..56aac3b1678d 100644
@@ -137,6 +137,7 @@ Hardware Monitoring Kernel Drivers
    mcp3021
    menf21bmc
    mlxreg-fan
+   mp2949a
    mp2975
    nct6683
    nct6775
Documentation/hwmon/mp2949a.rst new file +44 -0
new file mode 100644
index 000000000000..0235dec70f63
@@ -0,0 +1,44 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver mp2949a
+====================
+
+Supported chips:
+
+  * MPS MP2949A
+
+    Prefix: 'mp2949a'
+
+Author:
+
+	Ainux Wang <[email protected]>
+
+Description
+-----------
+
+This driver implements support for Monolithic Power Systems, Inc. (MPS)
+triple-loop, digital, multi-phase controller MP2949A.
+
+This device:
+
+- Supports up to three power rail.
+- Provides 6 pulse-width modulations (PWMs), and can be configured for
+  to 6-phase operation for Rail A , up to 2-phase operation for Rail B,
+  and up to 1-phase operation for Rail C.
+- The PMBus registers are distributed into three pages: Page 0, Page 1,
+  Page 2. Page 0 contains the registers for Rail A and most of the common
+  settings for all of the rails. Page 1 contains register information for
+  Rail B. Page 2 contains register information for Rail C.
+- The MP2949A supports both 5mV VID step and 10mv VID step for IMVP8 and
+  IMVP9.
+
+Device supports:
+
+- SVID interface.
+- PMBus rev 1.2 interface.
+
+Device supports direct format for reading output power.
+Device supports linear format for reading input voltage, output current,
+and temperature.
+Device supports VID for reading output voltage.
+The below VID modes are supported: VR12, VR13, IMVP8, IMVP9.
drivers/hwmon/pmbus/Kconfig +9 -0
index 37a5c39784fa..b1344b265976 100644
@@ -248,6 +248,15 @@ config SENSORS_MAX8688
 	  This driver can also be built as a module. If so, the module will
 	  be called max8688.
 
+config SENSORS_MP2949A
+	tristate "MPS MP2949A"
+	help
+	  If you say yes here you get hardware monitoring support for MPS
+	  MP2949A Triple Loop Digital Multi-Phase Controller.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called mp2949a.
+
 config SENSORS_MP2975
 	tristate "MPS MP2975"
 	help
drivers/hwmon/pmbus/Makefile +1 -0
index f8dcc27cd56a..bfb55ab12da1 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_SENSORS_MAX20751)	+= max20751.o
 obj-$(CONFIG_SENSORS_MAX31785)	+= max31785.o
 obj-$(CONFIG_SENSORS_MAX34440)	+= max34440.o
 obj-$(CONFIG_SENSORS_MAX8688)	+= max8688.o
+obj-$(CONFIG_SENSORS_MP2949A)	+= mp2949a.o
 obj-$(CONFIG_SENSORS_MP2975)	+= mp2975.o
 obj-$(CONFIG_SENSORS_PM6764TR)	+= pm6764tr.o
 obj-$(CONFIG_SENSORS_PXE1610)	+= pxe1610.o
drivers/hwmon/pmbus/mp2949a.c new file +19 -0
new file mode 100644
index 000000000000..744c88b8ebca
@@ -0,0 +1,118 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Hardware monitoring driver for Monolithic Power Systems MP2949A
+ *
+ * Copyright (c) 2021 Lemote Technologies. All rights reserved.
+ * Copyright (c) 2021 Ainux <[email protected]>
+ */
+
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include "pmbus.h"
+
+#define MP2949A_PAGE_NUM		3
+
+#define MP2949A_MFR_VR_CONFIG	0xE4
+

drivers/hwmon/pmbus/mp2949a.c line 29

Quoted 10 lines
drivers/hwmon/pmbus/mp2949a.c new file +10 -0
+static int mp2949a_read_byte_data(struct i2c_client *client, int page, int reg)
+{
+	switch (reg) {
+	case PMBUS_VOUT_MODE:
+		/*
+		 * This chip do not support the VOUT_MODE command.
+		 * There is not VOUT_MODE command in MP2949A datasheet P29~P31.
+		 * So there is a EINVAL in here.
+		 */
+		return -EINVAL;

This is not a reason to add this code. The PMBus core handles this situation. Please explain why this is needed. "The chip does not support this command" is not a reason.

Quoted 11 lines
drivers/hwmon/pmbus/mp2949a.c new file +11 -0
+	default:
+		return -ENODATA;
+	}
+}
+
+static int mp2949a_identify(struct i2c_client *client,
+			    struct pmbus_driver_info *info)
+{
+	int i, ret;
+
+	for (i = 0; i < MP2949A_PAGE_NUM; i++) {

drivers/hwmon/pmbus/mp2949a.c line 50

Quoted 10 lines
drivers/hwmon/pmbus/mp2949a.c new file +10 -0
+		ret = pmbus_read_byte_data(client, i, MP2949A_MFR_VR_CONFIG);
+		if (ret < 0)
+			return ret;
+
+		/*
+		 * Rail A bit 5, Rail B bit 4, Rail C bit 3.
+		 * 1'b1: 5mV  (vr12/imvp8)
+		 * 1'b0: 10mv (imvp9)
+		 */
+		info->vrm_version[i] = (ret & ~BIT(5-i)) ? vr12 : imvp9;

Space before and after '-'.
Also, why ~ ? This evaluates all bits except the target bit.

Quoted 71 lines
drivers/hwmon/pmbus/mp2949a.c new file +68 -0
+	}
+
+	return 0;
+}
+
+static struct pmbus_driver_info mp2949a_info = {
+	.pages = MP2949A_PAGE_NUM,
+	.format[PSC_VOLTAGE_IN] = linear,
+	.format[PSC_VOLTAGE_OUT] = vid,
+	.format[PSC_CURRENT_OUT] = linear,
+	.format[PSC_TEMPERATURE] = linear,
+	.format[PSC_POWER] = direct,
+	.m[PSC_POWER] = 1,
+	.b[PSC_POWER] = 0,
+	.R[PSC_POWER] = 0,
+	.func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+		PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+		PMBUS_HAVE_TEMP | PMBUS_HAVE_POUT,
+	.func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+		PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+		PMBUS_HAVE_POUT,
+	.func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+		PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+		PMBUS_HAVE_POUT,
+	.identify = mp2949a_identify,
+	.read_byte_data = mp2949a_read_byte_data,
+};
+
+static int mp2949a_probe(struct i2c_client *client,
+			  const struct i2c_device_id *id)
+{
+	struct pmbus_driver_info *info;
+
+	info = devm_kmemdup(&client->dev, &mp2949a_info, sizeof(*info),
+			    GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+
+	return pmbus_do_probe(client, info);
+}
+
+static const struct i2c_device_id mp2949a_id[] = {
+	{"mp2949a", 0},
+	{}
+};
+
+MODULE_DEVICE_TABLE(i2c, mp2949a_id);
+
+static const struct of_device_id mp2949a_of_match[] = {
+	{.compatible = "mps,mp2949a"},
+	{}
+};
+MODULE_DEVICE_TABLE(of, mp2949a_of_match);
+
+static struct i2c_driver mp2949a_driver = {
+	.driver = {
+		.name = "mp2949a",
+		.of_match_table = of_match_ptr(mp2949a_of_match),
+	},
+	.probe = mp2949a_probe,
+	.id_table = mp2949a_id,
+};
+
+module_i2c_driver(mp2949a_driver);
+
+MODULE_AUTHOR("Ainux <[email protected]>");
+MODULE_DESCRIPTION("PMBus driver for Monolithic Power Systems MP2949A");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.18.1
author
#2 lore raw

Hi, Guenter
Thanks for the review. I'll address it all in v4.
Best regards,
Ainux Wang.

Quoted 274 lines · Guenter Roeck
Quoted 161 lines · On Tue, Jun 22, 2021 at 09:50:11AM +0800, [email protected] wrote:

From: "Ainux.Wang" <[email protected]>

Add support for MP2949A device from Monolithic Power Systems, Inc. (MPS). This is a triple-loop, digital, multi-phase controller.
This device:
- Supports up to three power rail.
- Provides 6 pulse-width modulations (PWMs), and can be configured up to 6-phase operation for Rail A , up to 2-phase operation for Rail B and up to 1-phase operation for Rail C.
- The PMBus registers are distributed into three pages: Page 0, Page 1, Page 2. Page 0 contains the registers for Rail A and most of the common settings for all of the rails. Page 1 contains register information for Rail B. Page 2 contains register information for Rail C.
- The MP2949A supports both 5mV VID step and 10mv VID step for IMVP8 and IMVP9.

v3:
- Added change log here.
- Errors in the document have been modified.
- Fixed PMBUS_VOUT_MODE to MP2949A_MFR_VR_CONFIG.
- Removed unnecessary vout_params and empty line.

v2:
- Reference has been added to Documentation/hwmon/index.rst.
- Droped 'vendor'.
- Removed change codes of the PMBus core and added mp2949a_identify() and mp2949a_read_byte_data() to this driver.

v1:
- Add support for MPS MP2949A.

---
 Documentation/hwmon/index.rst   |   1 +
 Documentation/hwmon/mp2949a.rst |  44 ++++++++++++
 drivers/hwmon/pmbus/Kconfig     |   9 +++
 drivers/hwmon/pmbus/Makefile    |   1 +
 drivers/hwmon/pmbus/mp2949a.c   | 118 ++++++++++++++++++++++++++++++++
 5 files changed, 173 insertions(+)
 create mode 100644 Documentation/hwmon/mp2949a.rst
 create mode 100644 drivers/hwmon/pmbus/mp2949a.c
Documentation/hwmon/index.rst +1 -0
index 9ed60fa84cbe..56aac3b1678d 100644
@@ -137,6 +137,7 @@ Hardware Monitoring Kernel Drivers
    mcp3021
    menf21bmc
    mlxreg-fan
+   mp2949a
    mp2975
    nct6683
    nct6775
Documentation/hwmon/mp2949a.rst new file +44 -0
new file mode 100644
index 000000000000..0235dec70f63
@@ -0,0 +1,44 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver mp2949a
+====================
+
+Supported chips:
+
+  * MPS MP2949A
+
+    Prefix: 'mp2949a'
+
+Author:
+
+     Ainux Wang <[email protected]>
+
+Description
+-----------
+
+This driver implements support for Monolithic Power Systems, Inc. (MPS)
+triple-loop, digital, multi-phase controller MP2949A.
+
+This device:
+
+- Supports up to three power rail.
+- Provides 6 pulse-width modulations (PWMs), and can be configured for
+  to 6-phase operation for Rail A , up to 2-phase operation for Rail B,
+  and up to 1-phase operation for Rail C.
+- The PMBus registers are distributed into three pages: Page 0, Page 1,
+  Page 2. Page 0 contains the registers for Rail A and most of the common
+  settings for all of the rails. Page 1 contains register information for
+  Rail B. Page 2 contains register information for Rail C.
+- The MP2949A supports both 5mV VID step and 10mv VID step for IMVP8 and
+  IMVP9.
+
+Device supports:
+
+- SVID interface.
+- PMBus rev 1.2 interface.
+
+Device supports direct format for reading output power.
+Device supports linear format for reading input voltage, output current,
+and temperature.
+Device supports VID for reading output voltage.
+The below VID modes are supported: VR12, VR13, IMVP8, IMVP9.
drivers/hwmon/pmbus/Kconfig +9 -0
index 37a5c39784fa..b1344b265976 100644
@@ -248,6 +248,15 @@ config SENSORS_MAX8688
        This driver can also be built as a module. If so, the module will
        be called max8688.
 
+config SENSORS_MP2949A
+     tristate "MPS MP2949A"
+     help
+       If you say yes here you get hardware monitoring support for MPS
+       MP2949A Triple Loop Digital Multi-Phase Controller.
+
+       This driver can also be built as a module. If so, the module will
+       be called mp2949a.
+
 config SENSORS_MP2975
      tristate "MPS MP2975"
      help
drivers/hwmon/pmbus/Makefile +1 -0
index f8dcc27cd56a..bfb55ab12da1 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_SENSORS_MAX20751)      += max20751.o
 obj-$(CONFIG_SENSORS_MAX31785)       += max31785.o
 obj-$(CONFIG_SENSORS_MAX34440)       += max34440.o
 obj-$(CONFIG_SENSORS_MAX8688)        += max8688.o
+obj-$(CONFIG_SENSORS_MP2949A)        += mp2949a.o
 obj-$(CONFIG_SENSORS_MP2975) += mp2975.o
 obj-$(CONFIG_SENSORS_PM6764TR)       += pm6764tr.o
 obj-$(CONFIG_SENSORS_PXE1610)        += pxe1610.o
drivers/hwmon/pmbus/mp2949a.c new file +19 -0
new file mode 100644
index 000000000000..744c88b8ebca
@@ -0,0 +1,118 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Hardware monitoring driver for Monolithic Power Systems MP2949A
+ *
+ * Copyright (c) 2021 Lemote Technologies. All rights reserved.
+ * Copyright (c) 2021 Ainux <[email protected]>
+ */
+
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include "pmbus.h"
+
+#define MP2949A_PAGE_NUM             3
+
+#define MP2949A_MFR_VR_CONFIG        0xE4
+

drivers/hwmon/pmbus/mp2949a.c line 29

Quoted 10 lines
drivers/hwmon/pmbus/mp2949a.c new file +10 -0
+static int mp2949a_read_byte_data(struct i2c_client *client, int page, int reg)
+{
+     switch (reg) {
+     case PMBUS_VOUT_MODE:
+             /*
+              * This chip do not support the VOUT_MODE command.
+              * There is not VOUT_MODE command in MP2949A datasheet P29~P31.
+              * So there is a EINVAL in here.
+              */
+             return -EINVAL;

This is not a reason to add this code. The PMBus core handles this situation. Please explain why this is needed. "The chip does not support this command" is not a reason.

Quoted 11 lines
drivers/hwmon/pmbus/mp2949a.c new file +11 -0
+     default:
+             return -ENODATA;
+     }
+}
+
+static int mp2949a_identify(struct i2c_client *client,
+                         struct pmbus_driver_info *info)
+{
+     int i, ret;
+
+     for (i = 0; i < MP2949A_PAGE_NUM; i++) {

drivers/hwmon/pmbus/mp2949a.c line 50

Quoted 10 lines
drivers/hwmon/pmbus/mp2949a.c new file +10 -0
+             ret = pmbus_read_byte_data(client, i, MP2949A_MFR_VR_CONFIG);
+             if (ret < 0)
+                     return ret;
+
+             /*
+              * Rail A bit 5, Rail B bit 4, Rail C bit 3.
+              * 1'b1: 5mV  (vr12/imvp8)
+              * 1'b0: 10mv (imvp9)
+              */
+             info->vrm_version[i] = (ret & ~BIT(5-i)) ? vr12 : imvp9;

Space before and after '-'.
Also, why ~ ? This evaluates all bits except the target bit.

Quoted 71 lines
drivers/hwmon/pmbus/mp2949a.c new file +68 -1
+     }
+
+     return 0;
+}
+
+static struct pmbus_driver_info mp2949a_info = {
+     .pages = MP2949A_PAGE_NUM,
+     .format[PSC_VOLTAGE_IN] = linear,
+     .format[PSC_VOLTAGE_OUT] = vid,
+     .format[PSC_CURRENT_OUT] = linear,
+     .format[PSC_TEMPERATURE] = linear,
+     .format[PSC_POWER] = direct,
+     .m[PSC_POWER] = 1,
+     .b[PSC_POWER] = 0,
+     .R[PSC_POWER] = 0,
+     .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+             PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+             PMBUS_HAVE_TEMP | PMBUS_HAVE_POUT,
+     .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+             PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+             PMBUS_HAVE_POUT,
+     .func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+             PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+             PMBUS_HAVE_POUT,
+     .identify = mp2949a_identify,
+     .read_byte_data = mp2949a_read_byte_data,
+};
+
+static int mp2949a_probe(struct i2c_client *client,
+                       const struct i2c_device_id *id)
+{
+     struct pmbus_driver_info *info;
+
+     info = devm_kmemdup(&client->dev, &mp2949a_info, sizeof(*info),
+                         GFP_KERNEL);
+     if (!info)
+             return -ENOMEM;
+
+     return pmbus_do_probe(client, info);
+}
+
+static const struct i2c_device_id mp2949a_id[] = {
+     {"mp2949a", 0},
+     {}
+};
+
+MODULE_DEVICE_TABLE(i2c, mp2949a_id);
+
+static const struct of_device_id mp2949a_of_match[] = {
+     {.compatible = "mps,mp2949a"},
+     {}
+};
+MODULE_DEVICE_TABLE(of, mp2949a_of_match);
+
+static struct i2c_driver mp2949a_driver = {
+     .driver = {
+             .name = "mp2949a",
+             .of_match_table = of_match_ptr(mp2949a_of_match),
+     },
+     .probe = mp2949a_probe,
+     .id_table = mp2949a_id,
+};
+
+module_i2c_driver(mp2949a_driver);
+
+MODULE_AUTHOR("Ainux <[email protected]>");
+MODULE_DESCRIPTION("PMBus driver for Monolithic Power Systems MP2949A");
+MODULE_LICENSE("GPL");
--

2.18.1

#3 lore raw
In reply to [email protected]
Quoted 31 lines · <[email protected]> 于2021年6月22日周二 上午9:50写道:

From: "Ainux.Wang" <[email protected]>

Add support for MP2949A device from Monolithic Power Systems, Inc. (MPS). This is a triple-loop, digital, multi-phase controller.
This device:
- Supports up to three power rail.
- Provides 6 pulse-width modulations (PWMs), and can be configured up to 6-phase operation for Rail A , up to 2-phase operation for Rail B and up to 1-phase operation for Rail C.
- The PMBus registers are distributed into three pages: Page 0, Page 1, Page 2. Page 0 contains the registers for Rail A and most of the common settings for all of the rails. Page 1 contains register information for Rail B. Page 2 contains register information for Rail C.
- The MP2949A supports both 5mV VID step and 10mv VID step for IMVP8 and IMVP9.

v3:
- Added change log here.
- Errors in the document have been modified.
- Fixed PMBUS_VOUT_MODE to MP2949A_MFR_VR_CONFIG.
- Removed unnecessary vout_params and empty line.

v2:
- Reference has been added to Documentation/hwmon/index.rst.
- Droped 'vendor'.
- Removed change codes of the PMBus core and added mp2949a_identify() and mp2949a_read_byte_data() to this driver.

Quoted 3 lines

v1:
- Add support for MPS MP2949A.
---

Hi,Ainux

Change log goes here. just like:

...

---
v3:
- Added change log here.
- Errors in the document have been modified.
- Fixed PMBUS_VOUT_MODE to MP2949A_MFR_VR_CONFIG.
- Removed unnecessary vout_params and empty line.

v2:
- Reference has been added to Documentation/hwmon/index.rst.
- Droped 'vendor'.
- Removed change codes of the PMBus core and added mp2949a_identify() and mp2949a_read_byte_data() to this driver.

v1:
- Add support for MPS MP2949A.

Documentation/hwmon/index.rst | 1 +
...

Thanks,

Yanteng

Quoted 230 lines
 Documentation/hwmon/index.rst   |   1 +
 Documentation/hwmon/mp2949a.rst |  44 ++++++++++++
 drivers/hwmon/pmbus/Kconfig     |   9 +++
 drivers/hwmon/pmbus/Makefile    |   1 +
 drivers/hwmon/pmbus/mp2949a.c   | 118 ++++++++++++++++++++++++++++++++
 5 files changed, 173 insertions(+)
 create mode 100644 Documentation/hwmon/mp2949a.rst
 create mode 100644 drivers/hwmon/pmbus/mp2949a.c
Documentation/hwmon/index.rst +1 -0
index 9ed60fa84cbe..56aac3b1678d 100644
@@ -137,6 +137,7 @@ Hardware Monitoring Kernel Drivers
    mcp3021
    menf21bmc
    mlxreg-fan
+   mp2949a
    mp2975
    nct6683
    nct6775
Documentation/hwmon/mp2949a.rst new file +44 -0
new file mode 100644
index 000000000000..0235dec70f63
@@ -0,0 +1,44 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver mp2949a
+====================
+
+Supported chips:
+
+  * MPS MP2949A
+
+    Prefix: 'mp2949a'
+
+Author:
+
+       Ainux Wang <[email protected]>
+
+Description
+-----------
+
+This driver implements support for Monolithic Power Systems, Inc. (MPS)
+triple-loop, digital, multi-phase controller MP2949A.
+
+This device:
+
+- Supports up to three power rail.
+- Provides 6 pulse-width modulations (PWMs), and can be configured for
+  to 6-phase operation for Rail A , up to 2-phase operation for Rail B,
+  and up to 1-phase operation for Rail C.
+- The PMBus registers are distributed into three pages: Page 0, Page 1,
+  Page 2. Page 0 contains the registers for Rail A and most of the common
+  settings for all of the rails. Page 1 contains register information for
+  Rail B. Page 2 contains register information for Rail C.
+- The MP2949A supports both 5mV VID step and 10mv VID step for IMVP8 and
+  IMVP9.
+
+Device supports:
+
+- SVID interface.
+- PMBus rev 1.2 interface.
+
+Device supports direct format for reading output power.
+Device supports linear format for reading input voltage, output current,
+and temperature.
+Device supports VID for reading output voltage.
+The below VID modes are supported: VR12, VR13, IMVP8, IMVP9.
drivers/hwmon/pmbus/Kconfig +9 -0
index 37a5c39784fa..b1344b265976 100644
@@ -248,6 +248,15 @@ config SENSORS_MAX8688
          This driver can also be built as a module. If so, the module will
          be called max8688.
 
+config SENSORS_MP2949A
+       tristate "MPS MP2949A"
+       help
+         If you say yes here you get hardware monitoring support for MPS
+         MP2949A Triple Loop Digital Multi-Phase Controller.
+
+         This driver can also be built as a module. If so, the module will
+         be called mp2949a.
+
 config SENSORS_MP2975
        tristate "MPS MP2975"
        help
drivers/hwmon/pmbus/Makefile +1 -0
index f8dcc27cd56a..bfb55ab12da1 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_SENSORS_MAX20751)        += max20751.o
 obj-$(CONFIG_SENSORS_MAX31785) += max31785.o
 obj-$(CONFIG_SENSORS_MAX34440) += max34440.o
 obj-$(CONFIG_SENSORS_MAX8688)  += max8688.o
+obj-$(CONFIG_SENSORS_MP2949A)  += mp2949a.o
 obj-$(CONFIG_SENSORS_MP2975)   += mp2975.o
 obj-$(CONFIG_SENSORS_PM6764TR) += pm6764tr.o
 obj-$(CONFIG_SENSORS_PXE1610)  += pxe1610.o
drivers/hwmon/pmbus/mp2949a.c new file +118 -1
new file mode 100644
index 000000000000..744c88b8ebca
@@ -0,0 +1,118 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Hardware monitoring driver for Monolithic Power Systems MP2949A
+ *
+ * Copyright (c) 2021 Lemote Technologies. All rights reserved.
+ * Copyright (c) 2021 Ainux <[email protected]>
+ */
+
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include "pmbus.h"
+
+#define MP2949A_PAGE_NUM               3
+
+#define MP2949A_MFR_VR_CONFIG  0xE4
+
+static int mp2949a_read_byte_data(struct i2c_client *client, int page, int reg)
+{
+       switch (reg) {
+       case PMBUS_VOUT_MODE:
+               /*
+                * This chip do not support the VOUT_MODE command.
+                * There is not VOUT_MODE command in MP2949A datasheet P29~P31.
+                * So there is a EINVAL in here.
+                */
+               return -EINVAL;
+       default:
+               return -ENODATA;
+       }
+}
+
+static int mp2949a_identify(struct i2c_client *client,
+                           struct pmbus_driver_info *info)
+{
+       int i, ret;
+
+       for (i = 0; i < MP2949A_PAGE_NUM; i++) {
+               ret = pmbus_read_byte_data(client, i, MP2949A_MFR_VR_CONFIG);
+               if (ret < 0)
+                       return ret;
+
+               /*
+                * Rail A bit 5, Rail B bit 4, Rail C bit 3.
+                * 1'b1: 5mV  (vr12/imvp8)
+                * 1'b0: 10mv (imvp9)
+                */
+               info->vrm_version[i] = (ret & ~BIT(5-i)) ? vr12 : imvp9;
+       }
+
+       return 0;
+}
+
+static struct pmbus_driver_info mp2949a_info = {
+       .pages = MP2949A_PAGE_NUM,
+       .format[PSC_VOLTAGE_IN] = linear,
+       .format[PSC_VOLTAGE_OUT] = vid,
+       .format[PSC_CURRENT_OUT] = linear,
+       .format[PSC_TEMPERATURE] = linear,
+       .format[PSC_POWER] = direct,
+       .m[PSC_POWER] = 1,
+       .b[PSC_POWER] = 0,
+       .R[PSC_POWER] = 0,
+       .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+               PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+               PMBUS_HAVE_TEMP | PMBUS_HAVE_POUT,
+       .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+               PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+               PMBUS_HAVE_POUT,
+       .func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+               PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+               PMBUS_HAVE_POUT,
+       .identify = mp2949a_identify,
+       .read_byte_data = mp2949a_read_byte_data,
+};
+
+static int mp2949a_probe(struct i2c_client *client,
+                         const struct i2c_device_id *id)
+{
+       struct pmbus_driver_info *info;
+
+       info = devm_kmemdup(&client->dev, &mp2949a_info, sizeof(*info),
+                           GFP_KERNEL);
+       if (!info)
+               return -ENOMEM;
+
+       return pmbus_do_probe(client, info);
+}
+
+static const struct i2c_device_id mp2949a_id[] = {
+       {"mp2949a", 0},
+       {}
+};
+
+MODULE_DEVICE_TABLE(i2c, mp2949a_id);
+
+static const struct of_device_id mp2949a_of_match[] = {
+       {.compatible = "mps,mp2949a"},
+       {}
+};
+MODULE_DEVICE_TABLE(of, mp2949a_of_match);
+
+static struct i2c_driver mp2949a_driver = {
+       .driver = {
+               .name = "mp2949a",
+               .of_match_table = of_match_ptr(mp2949a_of_match),
+       },
+       .probe = mp2949a_probe,
+       .id_table = mp2949a_id,
+};
+
+module_i2c_driver(mp2949a_driver);
+
+MODULE_AUTHOR("Ainux <[email protected]>");
+MODULE_DESCRIPTION("PMBus driver for Monolithic Power Systems MP2949A");
+MODULE_LICENSE("GPL");
--

2.18.1

author
#4 lore raw

HI, Yanteng
Thanks for the review. I'll address it all in v4.
Best regards,
Ainux Wang.

Quoted 296 lines · teng sterling
Quoted 31 lines · <[email protected]> 于2021年6月22日周二 上午9:50写道:

From: "Ainux.Wang" <[email protected]>

Add support for MP2949A device from Monolithic Power Systems, Inc. (MPS). This is a triple-loop, digital, multi-phase controller.
This device:
- Supports up to three power rail.
- Provides 6 pulse-width modulations (PWMs), and can be configured up to 6-phase operation for Rail A , up to 2-phase operation for Rail B and up to 1-phase operation for Rail C.
- The PMBus registers are distributed into three pages: Page 0, Page 1, Page 2. Page 0 contains the registers for Rail A and most of the common settings for all of the rails. Page 1 contains register information for Rail B. Page 2 contains register information for Rail C.
- The MP2949A supports both 5mV VID step and 10mv VID step for IMVP8 and IMVP9.

v3:
- Added change log here.
- Errors in the document have been modified.
- Fixed PMBUS_VOUT_MODE to MP2949A_MFR_VR_CONFIG.
- Removed unnecessary vout_params and empty line.

v2:
- Reference has been added to Documentation/hwmon/index.rst.
- Droped 'vendor'.
- Removed change codes of the PMBus core and added mp2949a_identify() and mp2949a_read_byte_data() to this driver.

Quoted 3 lines

v1:
- Add support for MPS MP2949A.
---

Hi,Ainux

Change log goes here. just like:

...

---
v3:
- Added change log here.
- Errors in the document have been modified.
- Fixed PMBUS_VOUT_MODE to MP2949A_MFR_VR_CONFIG.
- Removed unnecessary vout_params and empty line.

v2:
- Reference has been added to Documentation/hwmon/index.rst.
- Droped 'vendor'.
- Removed change codes of the PMBus core and added mp2949a_identify() and mp2949a_read_byte_data() to this driver.

v1:
- Add support for MPS MP2949A.

Documentation/hwmon/index.rst | 1 +
...

Thanks,

Yanteng

Quoted 230 lines
 Documentation/hwmon/index.rst   |   1 +
 Documentation/hwmon/mp2949a.rst |  44 ++++++++++++
 drivers/hwmon/pmbus/Kconfig     |   9 +++
 drivers/hwmon/pmbus/Makefile    |   1 +
 drivers/hwmon/pmbus/mp2949a.c   | 118 ++++++++++++++++++++++++++++++++
 5 files changed, 173 insertions(+)
 create mode 100644 Documentation/hwmon/mp2949a.rst
 create mode 100644 drivers/hwmon/pmbus/mp2949a.c
Documentation/hwmon/index.rst +1 -0
index 9ed60fa84cbe..56aac3b1678d 100644
@@ -137,6 +137,7 @@ Hardware Monitoring Kernel Drivers
    mcp3021
    menf21bmc
    mlxreg-fan
+   mp2949a
    mp2975
    nct6683
    nct6775
Documentation/hwmon/mp2949a.rst new file +44 -0
new file mode 100644
index 000000000000..0235dec70f63
@@ -0,0 +1,44 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver mp2949a
+====================
+
+Supported chips:
+
+  * MPS MP2949A
+
+    Prefix: 'mp2949a'
+
+Author:
+
+       Ainux Wang <[email protected]>
+
+Description
+-----------
+
+This driver implements support for Monolithic Power Systems, Inc. (MPS)
+triple-loop, digital, multi-phase controller MP2949A.
+
+This device:
+
+- Supports up to three power rail.
+- Provides 6 pulse-width modulations (PWMs), and can be configured for
+  to 6-phase operation for Rail A , up to 2-phase operation for Rail B,
+  and up to 1-phase operation for Rail C.
+- The PMBus registers are distributed into three pages: Page 0, Page 1,
+  Page 2. Page 0 contains the registers for Rail A and most of the common
+  settings for all of the rails. Page 1 contains register information for
+  Rail B. Page 2 contains register information for Rail C.
+- The MP2949A supports both 5mV VID step and 10mv VID step for IMVP8 and
+  IMVP9.
+
+Device supports:
+
+- SVID interface.
+- PMBus rev 1.2 interface.
+
+Device supports direct format for reading output power.
+Device supports linear format for reading input voltage, output current,
+and temperature.
+Device supports VID for reading output voltage.
+The below VID modes are supported: VR12, VR13, IMVP8, IMVP9.
drivers/hwmon/pmbus/Kconfig +9 -0
index 37a5c39784fa..b1344b265976 100644
@@ -248,6 +248,15 @@ config SENSORS_MAX8688
          This driver can also be built as a module. If so, the module will
          be called max8688.
 
+config SENSORS_MP2949A
+       tristate "MPS MP2949A"
+       help
+         If you say yes here you get hardware monitoring support for MPS
+         MP2949A Triple Loop Digital Multi-Phase Controller.
+
+         This driver can also be built as a module. If so, the module will
+         be called mp2949a.
+
 config SENSORS_MP2975
        tristate "MPS MP2975"
        help
drivers/hwmon/pmbus/Makefile +1 -0
index f8dcc27cd56a..bfb55ab12da1 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_SENSORS_MAX20751)        += max20751.o
 obj-$(CONFIG_SENSORS_MAX31785) += max31785.o
 obj-$(CONFIG_SENSORS_MAX34440) += max34440.o
 obj-$(CONFIG_SENSORS_MAX8688)  += max8688.o
+obj-$(CONFIG_SENSORS_MP2949A)  += mp2949a.o
 obj-$(CONFIG_SENSORS_MP2975)   += mp2975.o
 obj-$(CONFIG_SENSORS_PM6764TR) += pm6764tr.o
 obj-$(CONFIG_SENSORS_PXE1610)  += pxe1610.o
drivers/hwmon/pmbus/mp2949a.c new file +118 -1
new file mode 100644
index 000000000000..744c88b8ebca
@@ -0,0 +1,118 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Hardware monitoring driver for Monolithic Power Systems MP2949A
+ *
+ * Copyright (c) 2021 Lemote Technologies. All rights reserved.
+ * Copyright (c) 2021 Ainux <[email protected]>
+ */
+
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include "pmbus.h"
+
+#define MP2949A_PAGE_NUM               3
+
+#define MP2949A_MFR_VR_CONFIG  0xE4
+
+static int mp2949a_read_byte_data(struct i2c_client *client, int page, int reg)
+{
+       switch (reg) {
+       case PMBUS_VOUT_MODE:
+               /*
+                * This chip do not support the VOUT_MODE command.
+                * There is not VOUT_MODE command in MP2949A datasheet P29~P31.
+                * So there is a EINVAL in here.
+                */
+               return -EINVAL;
+       default:
+               return -ENODATA;
+       }
+}
+
+static int mp2949a_identify(struct i2c_client *client,
+                           struct pmbus_driver_info *info)
+{
+       int i, ret;
+
+       for (i = 0; i < MP2949A_PAGE_NUM; i++) {
+               ret = pmbus_read_byte_data(client, i, MP2949A_MFR_VR_CONFIG);
+               if (ret < 0)
+                       return ret;
+
+               /*
+                * Rail A bit 5, Rail B bit 4, Rail C bit 3.
+                * 1'b1: 5mV  (vr12/imvp8)
+                * 1'b0: 10mv (imvp9)
+                */
+               info->vrm_version[i] = (ret & ~BIT(5-i)) ? vr12 : imvp9;
+       }
+
+       return 0;
+}
+
+static struct pmbus_driver_info mp2949a_info = {
+       .pages = MP2949A_PAGE_NUM,
+       .format[PSC_VOLTAGE_IN] = linear,
+       .format[PSC_VOLTAGE_OUT] = vid,
+       .format[PSC_CURRENT_OUT] = linear,
+       .format[PSC_TEMPERATURE] = linear,
+       .format[PSC_POWER] = direct,
+       .m[PSC_POWER] = 1,
+       .b[PSC_POWER] = 0,
+       .R[PSC_POWER] = 0,
+       .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+               PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+               PMBUS_HAVE_TEMP | PMBUS_HAVE_POUT,
+       .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+               PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+               PMBUS_HAVE_POUT,
+       .func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+               PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+               PMBUS_HAVE_POUT,
+       .identify = mp2949a_identify,
+       .read_byte_data = mp2949a_read_byte_data,
+};
+
+static int mp2949a_probe(struct i2c_client *client,
+                         const struct i2c_device_id *id)
+{
+       struct pmbus_driver_info *info;
+
+       info = devm_kmemdup(&client->dev, &mp2949a_info, sizeof(*info),
+                           GFP_KERNEL);
+       if (!info)
+               return -ENOMEM;
+
+       return pmbus_do_probe(client, info);
+}
+
+static const struct i2c_device_id mp2949a_id[] = {
+       {"mp2949a", 0},
+       {}
+};
+
+MODULE_DEVICE_TABLE(i2c, mp2949a_id);
+
+static const struct of_device_id mp2949a_of_match[] = {
+       {.compatible = "mps,mp2949a"},
+       {}
+};
+MODULE_DEVICE_TABLE(of, mp2949a_of_match);
+
+static struct i2c_driver mp2949a_driver = {
+       .driver = {
+               .name = "mp2949a",
+               .of_match_table = of_match_ptr(mp2949a_of_match),
+       },
+       .probe = mp2949a_probe,
+       .id_table = mp2949a_id,
+};
+
+module_i2c_driver(mp2949a_driver);
+
+MODULE_AUTHOR("Ainux <[email protected]>");
+MODULE_DESCRIPTION("PMBus driver for Monolithic Power Systems MP2949A");
+MODULE_LICENSE("GPL");
--

2.18.1