diff mbox series

[v2,2/2] hwmon: add MP5920 driver

Message ID 20240627090113.391730-3-xzeol@yahoo.com (mailing list archive)
State Changes Requested
Headers show
Series Add MPS MP5920 Host-Swap controller | expand

Commit Message

Alex Vdovydchenko June 27, 2024, 9:01 a.m. UTC
Add support for MPS Hot-Swap controller mp5920. This driver exposes
telemetry and limit value readings and writings.

Signed-off-by: Alex Vdovydchenko <xzeol@yahoo.com>
---
 Documentation/hwmon/index.rst  |  1 +
 Documentation/hwmon/mp5920.rst | 91 +++++++++++++++++++++++++++++++++
 drivers/hwmon/pmbus/Kconfig    |  9 ++++
 drivers/hwmon/pmbus/Makefile   |  1 +
 drivers/hwmon/pmbus/mp5920.c   | 93 ++++++++++++++++++++++++++++++++++
 5 files changed, 195 insertions(+)
 create mode 100644 Documentation/hwmon/mp5920.rst
 create mode 100644 drivers/hwmon/pmbus/mp5920.c

Comments

kernel test robot June 28, 2024, 5:29 a.m. UTC | #1
Hi Alex,

kernel test robot noticed the following build errors:

[auto build test ERROR on groeck-staging/hwmon-next]
[also build test ERROR on next-20240627]
[cannot apply to robh/for-next krzk-dt/for-next linus/master v6.10-rc5]
[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/Alex-Vdovydchenko/dt-bindings-hwmon-Add-MPS-mp5920/20240628-021125
base:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
patch link:    https://lore.kernel.org/r/20240627090113.391730-3-xzeol%40yahoo.com
patch subject: [PATCH v2 2/2] hwmon: add MP5920 driver
config: loongarch-allmodconfig (https://download.01.org/0day-ci/archive/20240628/202406281339.YzOThRyw-lkp@intel.com/config)
compiler: loongarch64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240628/202406281339.YzOThRyw-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202406281339.YzOThRyw-lkp@intel.com/

All error/warnings (new ones prefixed by >>):

>> drivers/hwmon/pmbus/mp5920.c:26:9: error: 'pages' undeclared here (not in a function); did you mean 'page'?
      26 |         pages = 1,
         |         ^~~~~
         |         page
>> drivers/hwmon/pmbus/mp5920.c:27:9: error: 'format' undeclared here (not in a function)
      27 |         format[PSC_VOLTAGE_IN] = direct,
         |         ^~~~~~
>> drivers/hwmon/pmbus/mp5920.c:32:9: error: 'm' undeclared here (not in a function); did you mean 'tm'?
      32 |         m[PSC_VOLTAGE_IN] = 2266,
         |         ^
         |         tm
>> drivers/hwmon/pmbus/mp5920.c:33:9: error: 'b' undeclared here (not in a function); did you mean 'mb'?
      33 |         b[PSC_VOLTAGE_IN] = 0,
         |         ^
         |         mb
>> drivers/hwmon/pmbus/mp5920.c:34:9: error: 'R' undeclared here (not in a function)
      34 |         R[PSC_VOLTAGE_IN] = -1,
         |         ^
>> drivers/hwmon/pmbus/mp5920.c:44:9: warning: excess elements in struct initializer
      44 |         m[PSC_TEMPERATURE] = 1067,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:44:9: note: (near initialization for 'mp5920_info')
   drivers/hwmon/pmbus/mp5920.c:45:9: warning: excess elements in struct initializer
      45 |         b[PSC_TEMPERATURE] = 20500,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:45:9: note: (near initialization for 'mp5920_info')
   drivers/hwmon/pmbus/mp5920.c:46:9: warning: excess elements in struct initializer
      46 |         R[PSC_TEMPERATURE] = -2,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:46:9: note: (near initialization for 'mp5920_info')
>> drivers/hwmon/pmbus/mp5920.c:47:9: error: 'func' undeclared here (not in a function)
      47 |         func[0] = PMBUS_HAVE_VIN  | PMBUS_HAVE_VOUT |
         |         ^~~~
   drivers/hwmon/pmbus/mp5920.c:47:9: warning: excess elements in struct initializer
   drivers/hwmon/pmbus/mp5920.c:47:9: note: (near initialization for 'mp5920_info')


vim +26 drivers/hwmon/pmbus/mp5920.c

    24	
    25	static struct pmbus_driver_info mp5920_info = {
  > 26		pages = 1,
  > 27		format[PSC_VOLTAGE_IN] = direct,
    28		format[PSC_VOLTAGE_OUT] = direct,
    29		format[PSC_CURRENT_OUT] = direct,
    30		format[PSC_POWER] = direct,
    31		format[PSC_TEMPERATURE] = direct,
  > 32		m[PSC_VOLTAGE_IN] = 2266,
  > 33		b[PSC_VOLTAGE_IN] = 0,
  > 34		R[PSC_VOLTAGE_IN] = -1,
    35		m[PSC_VOLTAGE_OUT] = 2266,
    36		b[PSC_VOLTAGE_OUT] = 0,
    37		R[PSC_VOLTAGE_OUT] = -1,
    38		m[PSC_CURRENT_OUT] = 546,
    39		b[PSC_CURRENT_OUT] = 0,
    40		R[PSC_CURRENT_OUT] = -2,
    41		m[PSC_POWER] = 5840,
    42		b[PSC_POWER] = 0,
    43		R[PSC_POWER] = -3,
  > 44		m[PSC_TEMPERATURE] = 1067,
    45		b[PSC_TEMPERATURE] = 20500,
    46		R[PSC_TEMPERATURE] = -2,
  > 47		func[0] = PMBUS_HAVE_VIN  | PMBUS_HAVE_VOUT |
    48			PMBUS_HAVE_IOUT | PMBUS_HAVE_POUT |
    49			PMBUS_HAVE_TEMP,
    50	};
    51
kernel test robot June 28, 2024, 7:21 a.m. UTC | #2
Hi Alex,

kernel test robot noticed the following build errors:

[auto build test ERROR on groeck-staging/hwmon-next]
[also build test ERROR on next-20240627]
[cannot apply to robh/for-next krzk-dt/for-next linus/master v6.10-rc5]
[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/Alex-Vdovydchenko/dt-bindings-hwmon-Add-MPS-mp5920/20240628-021125
base:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
patch link:    https://lore.kernel.org/r/20240627090113.391730-3-xzeol%40yahoo.com
patch subject: [PATCH v2 2/2] hwmon: add MP5920 driver
config: arm64-allmodconfig (https://download.01.org/0day-ci/archive/20240628/202406281512.NAdadCZX-lkp@intel.com/config)
compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 326ba38a991250a8587a399a260b0f7af2c9166a)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240628/202406281512.NAdadCZX-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202406281512.NAdadCZX-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from drivers/hwmon/pmbus/mp5920.c:18:
   In file included from include/linux/i2c.h:13:
   In file included from include/linux/acpi.h:39:
   In file included from include/acpi/acpi_io.h:7:
   In file included from arch/arm64/include/asm/acpi.h:14:
   In file included from include/linux/memblock.h:12:
   In file included from include/linux/mm.h:2253:
   include/linux/vmstat.h:500:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     500 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     501 |                            item];
         |                            ~~~~
   include/linux/vmstat.h:507:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     507 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     508 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   include/linux/vmstat.h:514:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     514 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
   include/linux/vmstat.h:519:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     519 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     520 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   include/linux/vmstat.h:528:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     528 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     529 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hwmon/pmbus/mp5920.c:26:2: error: use of undeclared identifier 'pages'
      26 |         pages = 1,
         |         ^
>> drivers/hwmon/pmbus/mp5920.c:27:2: error: use of undeclared identifier 'format'
      27 |         format[PSC_VOLTAGE_IN] = direct,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:28:2: error: use of undeclared identifier 'format'
      28 |         format[PSC_VOLTAGE_OUT] = direct,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:29:2: error: use of undeclared identifier 'format'
      29 |         format[PSC_CURRENT_OUT] = direct,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:30:2: error: use of undeclared identifier 'format'
      30 |         format[PSC_POWER] = direct,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:31:2: error: use of undeclared identifier 'format'
      31 |         format[PSC_TEMPERATURE] = direct,
         |         ^
>> drivers/hwmon/pmbus/mp5920.c:32:2: error: use of undeclared identifier 'm'
      32 |         m[PSC_VOLTAGE_IN] = 2266,
         |         ^
>> drivers/hwmon/pmbus/mp5920.c:33:2: error: use of undeclared identifier 'b'
      33 |         b[PSC_VOLTAGE_IN] = 0,
         |         ^
>> drivers/hwmon/pmbus/mp5920.c:34:2: error: use of undeclared identifier 'R'
      34 |         R[PSC_VOLTAGE_IN] = -1,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:35:2: error: use of undeclared identifier 'm'
      35 |         m[PSC_VOLTAGE_OUT] = 2266,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:36:2: error: use of undeclared identifier 'b'
      36 |         b[PSC_VOLTAGE_OUT] = 0,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:37:2: error: use of undeclared identifier 'R'
      37 |         R[PSC_VOLTAGE_OUT] = -1,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:38:2: error: use of undeclared identifier 'm'
      38 |         m[PSC_CURRENT_OUT] = 546,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:39:2: error: use of undeclared identifier 'b'
      39 |         b[PSC_CURRENT_OUT] = 0,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:40:2: error: use of undeclared identifier 'R'
      40 |         R[PSC_CURRENT_OUT] = -2,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:41:2: error: use of undeclared identifier 'm'
      41 |         m[PSC_POWER] = 5840,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:42:2: error: use of undeclared identifier 'b'
      42 |         b[PSC_POWER] = 0,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:43:2: error: use of undeclared identifier 'R'
      43 |         R[PSC_POWER] = -3,
         |         ^
   drivers/hwmon/pmbus/mp5920.c:44:2: error: use of undeclared identifier 'm'
      44 |         m[PSC_TEMPERATURE] = 1067,
         |         ^
   fatal error: too many errors emitted, stopping now [-ferror-limit=]
   5 warnings and 20 errors generated.


vim +/pages +26 drivers/hwmon/pmbus/mp5920.c

    24	
    25	static struct pmbus_driver_info mp5920_info = {
  > 26		pages = 1,
  > 27		format[PSC_VOLTAGE_IN] = direct,
    28		format[PSC_VOLTAGE_OUT] = direct,
    29		format[PSC_CURRENT_OUT] = direct,
    30		format[PSC_POWER] = direct,
    31		format[PSC_TEMPERATURE] = direct,
  > 32		m[PSC_VOLTAGE_IN] = 2266,
  > 33		b[PSC_VOLTAGE_IN] = 0,
  > 34		R[PSC_VOLTAGE_IN] = -1,
    35		m[PSC_VOLTAGE_OUT] = 2266,
    36		b[PSC_VOLTAGE_OUT] = 0,
    37		R[PSC_VOLTAGE_OUT] = -1,
    38		m[PSC_CURRENT_OUT] = 546,
    39		b[PSC_CURRENT_OUT] = 0,
    40		R[PSC_CURRENT_OUT] = -2,
    41		m[PSC_POWER] = 5840,
    42		b[PSC_POWER] = 0,
    43		R[PSC_POWER] = -3,
    44		m[PSC_TEMPERATURE] = 1067,
    45		b[PSC_TEMPERATURE] = 20500,
    46		R[PSC_TEMPERATURE] = -2,
    47		func[0] = PMBUS_HAVE_VIN  | PMBUS_HAVE_VOUT |
    48			PMBUS_HAVE_IOUT | PMBUS_HAVE_POUT |
    49			PMBUS_HAVE_TEMP,
    50	};
    51
diff mbox series

Patch

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index e92a3d5c7..9eba7e402 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -168,6 +168,7 @@  Hardware Monitoring Kernel Drivers
    mp2975
    mp2993
    mp5023
+   mp5920
    mp5990
    mp9941
    mpq8785
diff --git a/Documentation/hwmon/mp5920.rst b/Documentation/hwmon/mp5920.rst
new file mode 100644
--- /dev/null
+++ b/Documentation/hwmon/mp5920.rst
@@ -0,0 +1,91 @@ 
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver mp5920
+====================
+
+Supported chips:
+
+  * MPS MP5920
+
+    Prefix: 'mp5920'
+
+  * Datasheet
+
+    Publicly available at the MPS website : https://www.monolithicpower.com/en/mp5920.html
+
+Authors:
+
+	Tony Ao <tony_ao@wiwynn.com>
+	Alex Vdovydchenko <xzeol@yahoo.com>
+
+Description
+-----------
+
+This driver implements support for Monolithic Power Systems, Inc. (MPS)
+MP5920 Hot-Swap Controller.
+
+Device compliant with:
+
+- PMBus rev 1.3 interface.
+
+Device supports direct and linear format for reading input voltage,
+output voltage, output current, input power and temperature.
+
+The driver exports the following attributes via the 'sysfs' files
+for input voltage:
+
+**in1_input**
+
+**in1_label**
+
+**in1_rated_max**
+
+**in1_rated_min**
+
+**in1_crit**
+
+**in1_alarm**
+
+The driver provides the following attributes for output voltage:
+
+**in2_input**
+
+**in2_label**
+
+**in2_rated_max**
+
+**in2_rated_min**
+
+**in2_alarm**
+
+The driver provides the following attributes for output current:
+
+**curr1_input**
+
+**curr1_label**
+
+**curr1_crit**
+
+**curr1_alarm**
+
+**curr1_rated_max**
+
+The driver provides the following attributes for input power:
+
+**power1_input**
+
+**power1_label**
+
+**power1_max**
+
+**power1_rated_max**
+
+The driver provides the following attributes for temperature:
+
+**temp1_input**
+
+**temp1_max**
+
+**temp1_crit**
+
+**temp1_alarm**
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -371,6 +371,15 @@  config SENSORS_MP5023
 	  This driver can also be built as a module. If so, the module will
 	  be called mp5023.
 
+config SENSORS_MP5920
+	tristate "MPS MP5920"
+	help
+	  If you say yes here you get hardware monitoring support for Monolithic
+	  MP5920.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called mp5920.
+
 config SENSORS_MP5990
 	tristate "MPS MP5990"
 	help
diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
--- a/drivers/hwmon/pmbus/Makefile
+++ b/drivers/hwmon/pmbus/Makefile
@@ -39,6 +39,7 @@  obj-$(CONFIG_SENSORS_MP2888)	+= mp2888.o
 obj-$(CONFIG_SENSORS_MP2975)	+= mp2975.o
 obj-$(CONFIG_SENSORS_MP2993)	+= mp2993.o
 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_MPQ7932)	+= mpq7932.o
diff --git a/drivers/hwmon/pmbus/mp5920.c b/drivers/hwmon/pmbus/mp5920.c
new file mode 100644
--- /dev/null
+++ b/drivers/hwmon/pmbus/mp5920.c
@@ -0,0 +1,95 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Hardware monitoring driver for MP5920 and compatible chips.
+ *
+ * Copyright (c) 2019 Facebook Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/jiffies.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include "pmbus.h"
+
+static struct pmbus_driver_info mp5920_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] = 2266,
+	b[PSC_VOLTAGE_IN] = 0,
+	R[PSC_VOLTAGE_IN] = -1,
+	m[PSC_VOLTAGE_OUT] = 2266,
+	b[PSC_VOLTAGE_OUT] = 0,
+	R[PSC_VOLTAGE_OUT] = -1,
+	m[PSC_CURRENT_OUT] = 546,
+	b[PSC_CURRENT_OUT] = 0,
+	R[PSC_CURRENT_OUT] = -2,
+	m[PSC_POWER] = 5840,
+	b[PSC_POWER] = 0,
+	R[PSC_POWER] = -3,
+	m[PSC_TEMPERATURE] = 1067,
+	b[PSC_TEMPERATURE] = 20500,
+	R[PSC_TEMPERATURE] = -2,
+	func[0] = PMBUS_HAVE_VIN  | PMBUS_HAVE_VOUT |
+		PMBUS_HAVE_IOUT | PMBUS_HAVE_POUT |
+		PMBUS_HAVE_TEMP,
+};
+
+static int mp5920_probe(struct i2c_client *client)
+{
+	struct device *dev =  &client->dev;
+	int chip_id;
+
+	if (!i2c_check_functionality(client->adapter,
+				     I2C_FUNC_SMBUS_READ_WORD_DATA))
+		return -ENODEV;
+
+	chip_id = i2c_smbus_read_word_data(client, PMBUS_MFR_ID);
+	if (chip_id < 0) {
+		dev_err(dev, "Failed to read MFR ID");
+		return chip_id;
+	}
+
+	return pmbus_do_probe(client, &mp5920_info);
+}
+
+static const struct of_device_id mp5920_of_match[] = {
+	{ .compatible = "mps,mp5920" },
+	{}
+};
+
+static const struct i2c_device_id mp5920_id[] = {
+	{"mp5920", 0},
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, mp5920_id);
+
+static struct i2c_driver mp5920_driver = {
+	.driver = {
+		.name = "mp5920",
+		.of_match_table = mp5920_of_match,
+	},
+	.probe = mp5920_probe,
+	.id_table = mp5920_id,
+};
+module_i2c_driver(mp5920_driver);
+
+MODULE_AUTHOR("Tony Ao <tony_ao@wiwynn.com>");
+MODULE_AUTHOR("Alex Vdovydchenko <xzeol@yahoo.com>");
+MODULE_DESCRIPTION("PMBus driver for MP5920 HSC");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS(PMBUS);