lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <3c89a559-2e2a-4f2b-842b-8130358d2a36@roeck-us.net>
Date: Mon, 10 Jun 2024 09:18:02 -0700
From: Guenter Roeck <linux@...ck-us.net>
To: Noah Wang <noahwang.wang@...look.com>, robh@...nel.org,
 krzk+dt@...nel.org, conor+dt@...nel.org, jdelvare@...e.com
Cc: corbet@....net, Delphine_CC_Chiu@...ynn.com, peteryin.openbmc@...il.com,
 javier.carrasco.cruz@...il.com, patrick.rudolph@...ements.com,
 bhelgaas@...gle.com, lukas@...ner.de, devicetree@...r.kernel.org,
 linux-kernel@...r.kernel.org, linux-hwmon@...r.kernel.org,
 linux-doc@...r.kernel.org, linux-i2c@...r.kernel.org
Subject: Re: [PATCH 4/4] hwmon: add MP9941 driver

On 6/7/24 02:05, Noah Wang wrote:
> Add support for MPS step-down converter mp9941. This driver exposes
> telemetry and limit value readings and writtings.
> 
> Signed-off-by: Noah Wang <noahwang.wang@...look.com>
> ---
>   Documentation/hwmon/index.rst  |   1 +
>   Documentation/hwmon/mp9941.rst |  92 +++++++++
>   MAINTAINERS                    |   7 +
>   drivers/hwmon/pmbus/Kconfig    |   9 +
>   drivers/hwmon/pmbus/Makefile   |   1 +
>   drivers/hwmon/pmbus/mp9941.c   | 328 +++++++++++++++++++++++++++++++++
>   6 files changed, 438 insertions(+)
>   create mode 100644 Documentation/hwmon/mp9941.rst
>   create mode 100644 drivers/hwmon/pmbus/mp9941.c
> 
> diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
> index 9d9d55b889f2..9ff8149d9a9d 100644
> --- a/Documentation/hwmon/index.rst
> +++ b/Documentation/hwmon/index.rst
> @@ -169,6 +169,7 @@ Hardware Monitoring Kernel Drivers
>      mp2993
>      mp5023
>      mp5990
> +   mp9941
>      mpq8785
>      nct6683
>      nct6775
> diff --git a/Documentation/hwmon/mp9941.rst b/Documentation/hwmon/mp9941.rst
> new file mode 100644
> index 000000000000..1274fa20e256
> --- /dev/null
> +++ b/Documentation/hwmon/mp9941.rst
> @@ -0,0 +1,92 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +Kernel driver mp9941
> +====================
> +
> +Supported chips:
> +
> +  * MPS mp9941
> +
> +    Prefix: 'mp9941'
> +
> +  * Datasheet
> +    https://scnbwymvp-my.sharepoint.com/:f:/g/personal/admin_scnbwy_com/Eth4kX1_J1hMsaASHiOYL4QBHU5a75r-tRfLKbHnJFdKLQ?e=vxj3DF
> +
> +Author:
> +
> +	Noah Wang <noahwang.wang@...look.com>
> +
> +Description
> +-----------
> +
> +This driver implements support for Monolithic Power Systems, Inc. (MPS)
> +MP9941 digital step-down converter.
> +
> +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**
> +
> +The driver provides the following attributes for output voltage:
> +
> +**in2_input**
> +
> +**in2_label**
> +
> +**in2_lcrit**
> +
> +**in2_lcrit_alarm**
> +
> +**in2_rated_max**
> +
> +**in2_rated_min**
> +
> +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**
> +
> +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**
> +
> +The driver provides the following attributes for temperature:
> +
> +**temp1_input**
> +
> +**temp1_crit**
> +
> +**temp1_crit_alarm**
> +
> +**temp1_max**
> +
> +**temp1_max_alarm**
> diff --git a/MAINTAINERS b/MAINTAINERS
> index f47f3e13b004..d4600533a3ee 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -15265,6 +15265,13 @@ F:	drivers/video/backlight/mp3309c.c
>   +F:	Documentation/hwmon/mp2993.rst
>   +F:	drivers/hwmon/pmbus/mp2993.c
>   
> ++MPS MP9941 DRIVER
> ++M:	Noah Wang <noahwang.wang@...look.com>
> ++L:	linux-hwmon@...r.kernel.org
> ++S:	Maintained
> ++F:	Documentation/hwmon/mp9941.rst
> ++F:	drivers/hwmon/pmbus/mp9941.c
> +
>   MR800 AVERMEDIA USB FM RADIO DRIVER
>   M:	Alexey Klimov <klimov.linux@...il.com>
>   L:	linux-media@...r.kernel.org
> diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
> index d875d31ce84c..7d32cfc19820 100644
> --- a/drivers/hwmon/pmbus/Kconfig
> +++ b/drivers/hwmon/pmbus/Kconfig
> @@ -380,6 +380,15 @@ config SENSORS_MP5990
>   	  This driver can also be built as a module. If so, the module will
>   	  be called mp5990.
>   
> +config SENSORS_MP9941
> +	tristate "MPS MP9941"
> +	help
> +	  If you say yes here you get hardware monitoring support for MPS
> +	  MP9941.
> +
> +	  This driver can also be built as a module. If so, the module will
> +	  be called mp9941.
> +
>   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 312d3f0c0540..6c7177fde355 100644
> --- a/drivers/hwmon/pmbus/Makefile
> +++ b/drivers/hwmon/pmbus/Makefile
> @@ -40,6 +40,7 @@ obj-$(CONFIG_SENSORS_MP2975)	+= mp2975.o
>   obj-$(CONFIG_SENSORS_MP2993)	+= mp2993.o
>   obj-$(CONFIG_SENSORS_MP5023)	+= mp5023.o
>   obj-$(CONFIG_SENSORS_MP5990)	+= mp5990.o
> +obj-$(CONFIG_SENSORS_MP9941)	+= mp9941.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/mp9941.c b/drivers/hwmon/pmbus/mp9941.c
> new file mode 100644
> index 000000000000..d24e98671e16
> --- /dev/null
> +++ b/drivers/hwmon/pmbus/mp9941.c
> @@ -0,0 +1,328 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Hardware monitoring driver for MPS Multi-phase Digital VR Controllers(MP9941)
> + */
> +
> +#include <linux/i2c.h>
> +#include <linux/module.h>
> +#include <linux/of_device.h>
> +#include "pmbus.h"
> +
> +/*
> + * Vender specific registers. The MFR_ICC_MAX(0x02) is used to
> + * config the iin scale. The MFR_RESO_SET(0xC7) is used to
> + * config the vout format. The MFR_VR_MULTI_CONFIG_R1(0x0D) is
> + * used to identify the vout vid step.
> + */
> +#define MFR_ICC_MAX	0x02
> +#define MFR_RESO_SET	0xC7
> +#define MFR_VR_MULTI_CONFIG_R1	0x0D
> +
> +#define MP9941_VIN_LIMIT_UINT	1
> +#define MP9941_VIN_LIMIT_DIV	8
> +#define MP9941_READ_VIN_UINT	1
> +#define MP9941_READ_VIN_DIV	32
> +
> +#define MP9941_PAGE_NUM	1
> +
> +#define MP9941_RAIL1_FUNC	(PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | \
> +							PMBUS_HAVE_IOUT | PMBUS_HAVE_POUT | \
> +							PMBUS_HAVE_TEMP | PMBUS_HAVE_PIN | \
> +							PMBUS_HAVE_IIN | \
> +							PMBUS_HAVE_STATUS_VOUT | \
> +							PMBUS_HAVE_STATUS_IOUT | \
> +							PMBUS_HAVE_STATUS_TEMP | \
> +							PMBUS_HAVE_STATUS_INPUT)
> +
> +struct mp9941_data {
> +	struct pmbus_driver_info info;
> +	int vid_resolution;
> +};
> +
> +#define to_mp9941_data(x) container_of(x, struct mp9941_data, info)
> +
> +static int mp2993_set_vout_format(struct i2c_client *client)
> +{
> +	int ret;
> +
> +	ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = i2c_smbus_read_word_data(client, MFR_RESO_SET);
> +	if (ret < 0)
> +		return ret;
> +
> +	/*
> +	 * page = 0, MFR_RESO_SET[7:6] defines the vout format
> +	 * 2'b11 set the vout format as direct
> +	 */
> +	ret = (ret & ~GENMASK(7, 6)) | FIELD_PREP(GENMASK(7, 6), 3);
> +
> +	ret = i2c_smbus_write_word_data(client, MFR_RESO_SET, ret);
> +	if (ret < 0)
> +		return ret;
> +

i2c_smbus_write_word_data() returns 0 or an error code. The above
is therefore not necessary.
	return i2c_smbus_write_word_data(client, MFR_RESO_SET, ret);
is sufficient. Same everythere else where the same pattern is used.

Thanks,
Guenter


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ