Re: [v3,1/2] hwmon: add MP2891 driver

From: Christophe JAILLET
Date: Sat Jun 01 2024 - 04:41:06 EST


Le 31/05/2024 à 09:26, Noah Wang a écrit :
Add support for MPS VR controller mp2891. This driver exposes
telemetry and limit value readings and writings.

Signed-off-by: Noah Wang <noahwang.wang@xxxxxxxxxxx>
---

Hi,

below a few nitpicks, if it make sense to you.

...

+++ b/drivers/hwmon/pmbus/mp2891.c
@@ -0,0 +1,608 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Hardware monitoring driver for MPS Multi-phase Digital VR Controllers(MP2891)
+ */
+
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/bitfield.h>

It is usually prefered to have includes sorted.

+#include "pmbus.h"
+

...

+static struct pmbus_driver_info mp2891_info = {

I think this could be const.

+ .pages = MP2891_PAGE_NUM,
+ .format[PSC_VOLTAGE_IN] = direct,
+ .format[PSC_CURRENT_IN] = direct,
+ .format[PSC_CURRENT_OUT] = direct,
+ .format[PSC_TEMPERATURE] = direct,
+ .format[PSC_POWER] = direct,
+ .format[PSC_VOLTAGE_OUT] = direct,
+
+ /* set vin scale 31.25mV/Lsb */
+ .m[PSC_VOLTAGE_IN] = 32,
+ .R[PSC_VOLTAGE_IN] = 0,
+ .b[PSC_VOLTAGE_IN] = 0,
+
+ /* set temp scale 1000m°C/Lsb */
+ .m[PSC_TEMPERATURE] = 1,
+ .R[PSC_TEMPERATURE] = 0,
+ .b[PSC_TEMPERATURE] = 0,
+
+ .m[PSC_CURRENT_IN] = 1,
+ .R[PSC_CURRENT_IN] = 0,
+ .b[PSC_CURRENT_IN] = 0,
+
+ .m[PSC_CURRENT_OUT] = 1,
+ .R[PSC_CURRENT_OUT] = 0,
+ .b[PSC_CURRENT_OUT] = 0,
+
+ .m[PSC_POWER] = 1,
+ .R[PSC_POWER] = 0,
+ .b[PSC_POWER] = 0,
+
+ .m[PSC_VOLTAGE_OUT] = 1,
+ .R[PSC_VOLTAGE_OUT] = 3,
+ .b[PSC_VOLTAGE_OUT] = 0,
+
+ .func[0] = MP2891_RAIL1_FUNC,
+ .func[1] = MP2891_RAIL2_FUNC,
+ .read_word_data = mp2891_read_word_data,
+ .write_word_data = mp2891_write_word_data,
+ .read_byte_data = mp2891_read_byte_data,
+ .identify = mp2891_identify,
+};
+
+static int mp2891_probe(struct i2c_client *client)
+{
+ struct pmbus_driver_info *info;
+ struct mp2891_data *data;
+
+ data = devm_kzalloc(&client->dev, sizeof(struct mp2891_data), GFP_KERNEL);

sizeof(*data)?

+ if (!data)
+ return -ENOMEM;
+
+ memcpy(&data->info, &mp2891_info, sizeof(*info));
+ info = &data->info;

'info' is not really useful. It could either be dropped, or initialised 1 line above, so that it can be used in the memcpy().

CJ

+
+ return pmbus_do_probe(client, info);
+}

...