* [PATCH 0/2] Adding MAX20754 support
@ 2022-07-07 15:29 Atif Ofluoglu
2022-07-07 15:29 ` [PATCH 1/2] hwmon: (pmbus/max20754) Add support for MAX20754 Atif Ofluoglu
2022-07-07 15:29 ` [PATCH 2/2] Added documentation for Maxim Integrated max20754 hwmon userspace sysfs Atif Ofluoglu
0 siblings, 2 replies; 6+ messages in thread
From: Atif Ofluoglu @ 2022-07-07 15:29 UTC (permalink / raw)
To: linux; +Cc: jdelvare, linux-hwmon, linux-kernel, Atif Ofluoglu
From: Atif Ofluoglu <atif.ofluoglu@analog.com>
Adding support for Maxim MAX20754 Dual-Output, Configurable Multiphase Power-Supply Controller with PMBus Interface.
The driver is tested on MAX20754 evalution kit hardware.
Atif Ofluoglu (2):
hwmon: (pmbus/max20754) Add support for MAX20754
Added documentation for Maxim Integrated max20754 hwmon userspace
sysfs.
Documentation/hwmon/max20754.rst | 122 ++++++++++
drivers/hwmon/pmbus/Kconfig | 9 +
drivers/hwmon/pmbus/Makefile | 1 +
drivers/hwmon/pmbus/max20754.c | 390 +++++++++++++++++++++++++++++++
4 files changed, 522 insertions(+)
create mode 100644 Documentation/hwmon/max20754.rst
create mode 100644 drivers/hwmon/pmbus/max20754.c
--
2.25.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] hwmon: (pmbus/max20754) Add support for MAX20754
2022-07-07 15:29 [PATCH 0/2] Adding MAX20754 support Atif Ofluoglu
@ 2022-07-07 15:29 ` Atif Ofluoglu
2022-07-07 18:56 ` kernel test robot
2022-07-13 14:16 ` Guenter Roeck
2022-07-07 15:29 ` [PATCH 2/2] Added documentation for Maxim Integrated max20754 hwmon userspace sysfs Atif Ofluoglu
1 sibling, 2 replies; 6+ messages in thread
From: Atif Ofluoglu @ 2022-07-07 15:29 UTC (permalink / raw)
To: linux; +Cc: jdelvare, linux-hwmon, linux-kernel, Atif Ofluoglu, Atif Ofluoglu
From: Atif Ofluoglu <atif.ofluoglu@analog.com>
Signed-off-by: Atif Ofluoglu <Atif.Ofluoglu@analog.com>
---
drivers/hwmon/pmbus/Kconfig | 9 +
drivers/hwmon/pmbus/Makefile | 1 +
drivers/hwmon/pmbus/max20754.c | 390 +++++++++++++++++++++++++++++++++
3 files changed, 400 insertions(+)
create mode 100644 drivers/hwmon/pmbus/max20754.c
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index dfae76db65ae..f259b8739766 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -254,6 +254,15 @@ config SENSORS_MAX20751
This driver can also be built as a module. If so, the module will
be called max20751.
+config SENSORS_MAX20754
+ tristate "Maxim MAX20754"
+ help
+ If you say yes here you get hardware monitoring support for Maxim
+ MAX20754.
+
+ This driver can also be built as a module. If so, the module will
+ be called max20754.
+
config SENSORS_MAX31785
tristate "Maxim MAX31785 and compatibles"
help
diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
index 4678fba5012c..b8b1d8a84b3b 100644
--- a/drivers/hwmon/pmbus/Makefile
+++ b/drivers/hwmon/pmbus/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_SENSORS_MAX16064) += max16064.o
obj-$(CONFIG_SENSORS_MAX16601) += max16601.o
obj-$(CONFIG_SENSORS_MAX20730) += max20730.o
obj-$(CONFIG_SENSORS_MAX20751) += max20751.o
+obj-$(CONFIG_SENSORS_MAX20751) += max20754.o
obj-$(CONFIG_SENSORS_MAX31785) += max31785.o
obj-$(CONFIG_SENSORS_MAX34440) += max34440.o
obj-$(CONFIG_SENSORS_MAX8688) += max8688.o
diff --git a/drivers/hwmon/pmbus/max20754.c b/drivers/hwmon/pmbus/max20754.c
new file mode 100644
index 000000000000..5e29e8f8009b
--- /dev/null
+++ b/drivers/hwmon/pmbus/max20754.c
@@ -0,0 +1,390 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Maxim MAX20754 Dual-Output, Configurable Multiphase
+ * Power-Supply Controller with PMBus Interface
+ * and Internal Buck Converter Driver
+ *
+ * Author: Atif Emre Ofluoglu <atif.ofluoglu@analog.com>
+ * Copyright (C) 2022 Analog Devices
+ *
+ * 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.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include "pmbus.h"
+
+enum chips { max20754 };
+
+#define MAX20754_NUM_PHASES 6
+#define MAX20754_LINEAR_EXPONENT -10
+
+struct max20754_data {
+ enum chips id;
+ struct pmbus_driver_info info;
+ struct i2c_client *rail2;
+ bool smbus_i2c_block_read;
+};
+
+#define to_max20754_data(x) container_of(x, struct max20754_data, info)
+
+enum max20754_reg_index {
+ operation_index,
+ on_off_config_index,
+ vout_command_index,
+ num_regs,
+};
+
+static const u8 max20754_regs[num_regs][2] = {
+ [operation_index] = {PMBUS_OPERATION, 1},
+ [on_off_config_index] = {PMBUS_ON_OFF_CONFIG, 1},
+ [vout_command_index] = {PMBUS_VOUT_COMMAND, 2},
+};
+
+static u16 val_to_linear16(int val)
+{
+ return ((u16)val * 1000LL) >> -MAX20754_LINEAR_EXPONENT;
+}
+
+static long linear16_to_val(s64 val)
+{
+ if (val == 0)
+ return 0;
+
+ val <<= -MAX20754_LINEAR_EXPONENT;
+ val = DIV_ROUND_CLOSEST_ULL(val, 1000);
+ val = clamp_val(val, 0, 0xffff);
+ return val;
+}
+
+static int max20754_read_block_data(struct i2c_client *client, int reg,
+ u8 length, u8 *values)
+{
+ const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+ struct max20754_data *data = to_max20754_data(info);
+ int ret;
+
+ if (data->smbus_i2c_block_read) {
+ ret = i2c_smbus_read_i2c_block_data(client, reg, length, values);
+ if (ret < 1)
+ return ret;
+ ret = ret - 1;
+ memcpy(values, &values[1], ret);
+ } else {
+ ret = i2c_smbus_read_block_data(client, reg, values);
+ }
+
+ return ret;
+}
+
+static int max20754_read_word(struct i2c_client *client, int page, int phase,
+ int reg)
+{
+ const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+ struct max20754_data *data = to_max20754_data(info);
+
+ if (reg > 0xFF)
+ return -ENXIO;
+
+ if (reg == PMBUS_MFR_VOUT_MAX)
+ reg = PMBUS_VOUT_MAX;
+
+ switch (page) {
+ case 0: /* RAIL1 */
+ return i2c_smbus_read_word_data(client, reg);
+ case 1: /* RAIL2 */
+ return i2c_smbus_read_word_data(data->rail2, reg);
+ default:
+ return -ENODATA;
+ }
+
+ return -ENODATA;
+}
+
+static int max20754_write_word(struct i2c_client *client, int page, int reg, u16 value)
+{
+ const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+ struct max20754_data *data = to_max20754_data(info);
+
+ switch (reg) {
+ case PMBUS_OPERATION:
+ if (value >= 0x90 && value <= 0x93)
+ return -EOPNOTSUPP;
+ break;
+ case PMBUS_MFR_VOUT_MAX:
+ reg = PMBUS_VOUT_MAX;
+ break;
+ default:
+ break;
+ }
+
+ switch (page) {
+ case 0: /* RAIL1 */
+ return i2c_smbus_write_word_data(client, reg, value);
+ case 1: /* RAIL2 */
+ return i2c_smbus_write_word_data(data->rail2, reg, value);
+ default:
+ return -EOPNOTSUPP;
+ }
+ return -ENODATA;
+}
+
+static int max20754_read_byte(struct i2c_client *client, int page, int reg)
+{
+ const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+ struct max20754_data *data = to_max20754_data(info);
+ int vout_mode;
+
+ if (reg == PMBUS_VOUT_MODE) {
+ vout_mode = i2c_smbus_read_byte_data(client, reg);
+ if (vout_mode != 0x2C)
+ vout_mode = 0x16;
+ return vout_mode;
+ }
+
+ switch (page) {
+ case 0: /* RAIL1 */
+ return i2c_smbus_read_byte_data(client, reg);
+ case 1: /* RAIL2 */
+ return i2c_smbus_read_byte_data(data->rail2, reg);
+ default:
+ return -ENODATA;
+ }
+ return -ENODATA;
+}
+
+static int max20754_write_byte(struct i2c_client *client, int page, u8 reg)
+{
+ const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+ struct max20754_data *data = to_max20754_data(info);
+
+ if (reg == PMBUS_CLEAR_FAULTS) {
+ switch (page) {
+ case 0:
+ return i2c_smbus_write_byte(client, reg);
+ case 1:
+ return i2c_smbus_write_byte(data->rail2, reg);
+ default:
+ return -ENODATA;
+ }
+ }
+ return -ENODATA;
+}
+
+static int max20754_identify(struct i2c_client *client,
+ struct pmbus_driver_info *info)
+{
+ struct device *dev = &client->dev;
+ u8 buf[9] = {0};
+ int ret;
+
+ ret = max20754_read_block_data(client,
+ PMBUS_IC_DEVICE_ID, 9,
+ buf);
+
+ if (ret < 0 || ret < 8)
+ return -ENODEV;
+
+ /*
+ * PMBUS_IC_DEVICE_ID is expected to return "MAX20754"
+ */
+
+ if (strncmp(buf, "MAX20754", 8)) {
+ buf[ret] = '\0';
+ dev_err(dev, "Unsupported chip '%s'\n", buf);
+ return -ENODEV;
+ }
+
+ return 0;
+}
+
+static ssize_t max20754_register_store(struct device *dev,
+ struct device_attribute *attr, const char *buf,
+ size_t count)
+{
+ struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
+ struct i2c_client *client = to_i2c_client(dev->parent);
+ const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+ struct max20754_data *data = to_max20754_data(info);
+
+ u8 cmd = max20754_regs[sattr->index][0];
+ u8 reg_size = max20754_regs[sattr->index][1];
+ u8 rail_number = sattr->nr;
+ long val = 0;
+ int ret;
+
+ ret = kstrtol(buf, 10, &val);
+ if (ret)
+ return ret;
+
+ if (rail_number == 1)
+ client = data->rail2;
+
+ if (cmd == PMBUS_VOUT_COMMAND)
+ val = linear16_to_val(val);
+
+ switch (reg_size) {
+ case 1:
+ ret = i2c_smbus_write_byte_data(client, cmd, val);
+ break;
+ case 2:
+ ret = i2c_smbus_write_word_data(client, cmd, val);
+ break;
+ default:
+ break;
+ }
+
+ if (ret < 0)
+ return ret;
+
+ return count;
+}
+
+static ssize_t max20754_register_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
+ struct i2c_client *client = to_i2c_client(dev->parent);
+
+ int ret_val = 0;
+ u8 cmd = max20754_regs[sattr->index][0];
+ u8 reg_size = max20754_regs[sattr->index][1];
+ u8 rail_number = sattr->nr;
+
+ switch (reg_size) {
+ case 1:
+ ret_val = max20754_read_byte(client, rail_number, cmd);
+ break;
+ case 2:
+ ret_val = max20754_read_word(client, rail_number, 0, cmd);
+ break;
+ default:
+ break;
+ }
+
+ if (ret_val < 0)
+ return -ENODATA;
+
+ if (cmd == PMBUS_VOUT_COMMAND)
+ ret_val = val_to_linear16(ret_val);
+
+ return sprintf(buf, "%d\n", ret_val);
+}
+
+#define MAX20754_REGISTER_ATTR_RW(__name, __reg_index, __size) \
+ SENSOR_DEVICE_ATTR_2_RW(__name, max20754_register, __size, __reg_index)
+
+static MAX20754_REGISTER_ATTR_RW(operation, operation_index, 0);
+static MAX20754_REGISTER_ATTR_RW(on_off_config, on_off_config_index, 0);
+
+static MAX20754_REGISTER_ATTR_RW(vout1_command, vout_command_index, 0);
+static MAX20754_REGISTER_ATTR_RW(vout2_command, vout_command_index, 1);
+
+static struct attribute *max20754_attrs[] = {
+ &sensor_dev_attr_operation.dev_attr.attr,
+ &sensor_dev_attr_on_off_config.dev_attr.attr,
+ &sensor_dev_attr_vout1_command.dev_attr.attr,
+ &sensor_dev_attr_vout2_command.dev_attr.attr,
+ NULL
+};
+ATTRIBUTE_GROUPS(max20754);
+
+static struct pmbus_driver_info max20754_info = {
+ .pages = 2,
+ .format[PSC_VOLTAGE_IN] = linear,
+ .format[PSC_VOLTAGE_OUT] = linear,
+ .vrm_version[0] = vr12,
+ .format[PSC_TEMPERATURE] = linear,
+ .format[PSC_CURRENT_OUT] = linear,
+ .format[PSC_POWER] = linear,
+ .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
+ PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+ PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP,
+ .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_INPUT |
+ PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
+ PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP,
+ .identify = max20754_identify,
+ .read_byte_data = max20754_read_byte,
+ .read_word_data = max20754_read_word,
+ .write_byte = max20754_write_byte,
+ .write_word_data = max20754_write_word,
+};
+
+static void max20754_remove(void *_data)
+{
+ struct max20754_data *data = _data;
+
+ i2c_unregister_device(data->rail2);
+}
+
+static int max20754_probe(struct i2c_client *client)
+{
+ struct device *dev = &client->dev;
+ struct max20754_data *data;
+ bool i2c_block_data_ok = false;
+ int ret = 0;
+
+ ret = i2c_check_functionality(client->adapter,
+ I2C_FUNC_SMBUS_READ_BYTE_DATA |
+ I2C_FUNC_SMBUS_READ_BLOCK_DATA);
+
+ if (!ret) {
+ ret = i2c_check_functionality(client->adapter,
+ I2C_FUNC_SMBUS_READ_BYTE_DATA |
+ I2C_FUNC_SMBUS_I2C_BLOCK);
+ if (!ret)
+ return -ENODEV;
+
+ i2c_block_data_ok = true;
+ }
+
+ data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+
+ data->rail2 = i2c_new_dummy_device(client->adapter, client->addr + 1);
+ if (IS_ERR(data->rail2)) {
+ dev_err(dev, "Failed to register rail2 client\n");
+ return PTR_ERR(data->rail2);
+ }
+ ret = devm_add_action_or_reset(dev, max20754_remove, data);
+ if (ret)
+ return ret;
+
+ data->info = max20754_info;
+ data->info.groups = max20754_groups;
+ data->smbus_i2c_block_read = i2c_block_data_ok;
+
+ return pmbus_do_probe(client, &data->info);
+}
+
+static const struct i2c_device_id max20754_id[] = {
+ {"max20754", max20754},
+ {}
+};
+
+MODULE_DEVICE_TABLE(i2c, max20754_id);
+
+static struct i2c_driver max20754_driver = {
+ .driver = {
+ .name = "max20754",
+ },
+ .probe_new = max20754_probe,
+ .remove = pmbus_do_remove,
+ .id_table = max20754_id,
+};
+
+module_i2c_driver(max20754_driver);
+
+MODULE_AUTHOR("Atif Emre Ofluoglu <atif.ofluoglu@analog.com>");
+MODULE_DESCRIPTION("PMBus driver for Maxim MAX20754");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS(PMBUS);
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] Added documentation for Maxim Integrated max20754 hwmon userspace sysfs.
2022-07-07 15:29 [PATCH 0/2] Adding MAX20754 support Atif Ofluoglu
2022-07-07 15:29 ` [PATCH 1/2] hwmon: (pmbus/max20754) Add support for MAX20754 Atif Ofluoglu
@ 2022-07-07 15:29 ` Atif Ofluoglu
2022-07-08 6:41 ` kernel test robot
1 sibling, 1 reply; 6+ messages in thread
From: Atif Ofluoglu @ 2022-07-07 15:29 UTC (permalink / raw)
To: linux; +Cc: jdelvare, linux-hwmon, linux-kernel, Atif Ofluoglu
From: Atif Ofluoglu <atif.ofluoglu@analog.com>
Signed-off-by: Atif Ofluoglu <atif.ofluoglu@analog.com>
---
Documentation/hwmon/max20754.rst | 122 +++++++++++++++++++++++++++++++
1 file changed, 122 insertions(+)
create mode 100644 Documentation/hwmon/max20754.rst
diff --git a/Documentation/hwmon/max20754.rst b/Documentation/hwmon/max20754.rst
new file mode 100644
index 000000000000..30cb1356cabf
--- /dev/null
+++ b/Documentation/hwmon/max20754.rst
@@ -0,0 +1,122 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver MAX20754
+======================
+
+Supported chips:
+
+ * Maxim MAX20754
+
+ Prefix: 'max20754'
+
+ Addresses scanned: -
+
+ Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX20754.pdf
+ Application Note:
+
+Author: Atif Emre Ofluoglu <Atif.Ofluoglu@analog.com>
+
+
+Description
+-----------
+
+This driver supports MAX20754 Dual-Output, Configurable Multiphase
+Power-Supply Controller with PMBus Interface and Internal Buck Converter.
+
+The driver is a client driver to the core PMBus driver.
+Please see Documentation/hwmon/pmbus.rst for details on PMBus client drivers.
+
+
+Usage Notes
+-----------
+
+This driver does not auto-detect devices. You will have to instantiate the
+devices explicitly. Please see Documentation/i2c/instantiating-devices.rst for
+details.
+
+
+Platform data support
+---------------------
+
+The driver supports standard PMBus driver platform data.
+
+
+Sysfs entries
+-------------
+
+The following attributes are supported.
+
+=============================== ===============================================
+in1_input Measured voltage on Supply Voltage.
+in1_label "vin1"
+in1_alarm Input voltage under-voltage alarm
+
+in2_label "vout1"
+in2_input Measured voltage on RAIL1.
+in2_min Minimum output voltage.
+in2_max Maximum output voltage.
+in2_lcrit Critical minimum output voltage.
+in2_crit Critical maximum output voltage.
+in2_lcrit_alarm Output voltage critical low alarm.
+in2_crit_alarm Output voltage critical high alarm.
+in2_min_alarm Output voltage low alarm.
+in2_max_alarm Output voltage high alarm.
+in2_rated_max Maximum rated output voltage
+in2_rated_min Minimum rated output voltage
+
+in3_label "vout2"
+in3_input Measured voltage on RAIL2.
+in3_min Minimum output voltage.
+in3_max Maximum output voltage.
+in3_lcrit Critical minimum output voltage.
+in3_crit Critical maximum output voltage.
+in3_lcrit_alarm Output voltage critical low alarm.
+in3_crit_alarm Output voltage critical high alarm.
+in3_min_alarm Output voltage low alarm.
+in3_max_alarm Output voltage high alarm.
+in3_rated_max Maximum rated output voltage
+in3_rated_min Minimum rated output voltage
+
+curr1_input Measured output current on RAIL1.
+curr1_label "iout1"
+curr1_max Maximum output current.
+curr1_max_alarm Output current high alarm.
+curr1_crit Critical maximum current
+curr1_crit_alarm Current critical high alarm
+
+curr2_input Measured output current on RAIL2.
+curr2_label "iout2"
+curr2_max Maximum output current.
+curr2_max_alarm Output current high alarm.
+curr2_crit Critical maximum current
+curr2_crit_alarm Current critical high alarm
+
+temp1_input Measured Temperature value of Die Core
+temp1_crit Maximum Temperature value of Die Core
+temp1_crit_alarm Maximum Temperature Alarm of Die Core
+temp1_max Over Temperature Warning value of Die Core
+temp1_max_alarm Over Temperature Warning value of Die Core
+temp1_min Under Temperature value of Die Core
+temp1_min_alarm Under Temperature Alarm of Die Core
+
+temp1_input Measured Temperature value of Temperature Sense 1
+temp1_crit Maximum Temperature value of Temperature Sense 1
+temp1_crit_alarm Maximum Temperature Alarm of Temperature Sense 1
+temp1_max Over Temperature Warning value of Temperature Sense 1
+temp1_max_alarm Over Temperature Warning value of Temperature Sense 1
+temp1_min Under Temperature value of Temperature Sense 1
+temp1_min_alarm Under Temperature Alarm of Temperature Sense 1
+
+temp1_input Measured Temperature value of Temperature Sense 1
+temp1_crit Maximum Temperature value of Temperature Sense 1
+temp1_crit_alarm Maximum Temperature Alarm of Temperature Sense 1
+temp1_max Over Temperature Warning value ofTemperature Sense 1
+temp1_max_alarm Over Temperature Warning Temperature Sense 1
+temp1_min Under Temperature value of Temperature Sense 1
+temp1_min_alarm Under Temperature Alarm of Temperature Sense 1
+
+vout1_command Determine Voltage read format of RAIL1
+vout2_command Determine Voltage read format of RAIL2
+
+on_off_config Configures Power On/Off behavior.
+operation Configures Power Supply Operation Mode.
\ No newline at end of file
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] hwmon: (pmbus/max20754) Add support for MAX20754
2022-07-07 15:29 ` [PATCH 1/2] hwmon: (pmbus/max20754) Add support for MAX20754 Atif Ofluoglu
@ 2022-07-07 18:56 ` kernel test robot
2022-07-13 14:16 ` Guenter Roeck
1 sibling, 0 replies; 6+ messages in thread
From: kernel test robot @ 2022-07-07 18:56 UTC (permalink / raw)
To: Atif Ofluoglu, linux
Cc: kbuild-all, jdelvare, linux-hwmon, linux-kernel, Atif Ofluoglu
Hi Atif,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on groeck-staging/hwmon-next]
[also build test ERROR on linus/master v5.19-rc5 next-20220707]
[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/Atif-Ofluoglu/Adding-MAX20754-support/20220707-233249
base: https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
config: arc-randconfig-r043-20220707 (https://download.01.org/0day-ci/archive/20220708/202207080255.fBmFH9Ry-lkp@intel.com/config)
compiler: arceb-elf-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/52ef0855bc74f95cd6c170b5475a3e957d7e1028
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Atif-Ofluoglu/Adding-MAX20754-support/20220707-233249
git checkout 52ef0855bc74f95cd6c170b5475a3e957d7e1028
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash drivers/hwmon/pmbus/
If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
>> drivers/hwmon/pmbus/max20754.c:381:19: error: 'pmbus_do_remove' undeclared here (not in a function); did you mean 'pmbus_do_probe'?
381 | .remove = pmbus_do_remove,
| ^~~~~~~~~~~~~~~
| pmbus_do_probe
vim +381 drivers/hwmon/pmbus/max20754.c
375
376 static struct i2c_driver max20754_driver = {
377 .driver = {
378 .name = "max20754",
379 },
380 .probe_new = max20754_probe,
> 381 .remove = pmbus_do_remove,
382 .id_table = max20754_id,
383 };
384
--
0-DAY CI Kernel Test Service
https://01.org/lkp
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] Added documentation for Maxim Integrated max20754 hwmon userspace sysfs.
2022-07-07 15:29 ` [PATCH 2/2] Added documentation for Maxim Integrated max20754 hwmon userspace sysfs Atif Ofluoglu
@ 2022-07-08 6:41 ` kernel test robot
0 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2022-07-08 6:41 UTC (permalink / raw)
To: Atif Ofluoglu, linux
Cc: kbuild-all, jdelvare, linux-hwmon, linux-kernel, Atif Ofluoglu
Hi Atif,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on groeck-staging/hwmon-next]
[also build test WARNING on linus/master v5.19-rc5 next-20220707]
[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/Atif-Ofluoglu/Adding-MAX20754-support/20220707-233249
base: https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
reproduce: make htmldocs
If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
>> Documentation/hwmon/max20754.rst: WARNING: document isn't included in any toctree
>> Documentation/hwmon/max20754.rst:49: WARNING: Malformed table.
--
0-DAY CI Kernel Test Service
https://01.org/lkp
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] hwmon: (pmbus/max20754) Add support for MAX20754
2022-07-07 15:29 ` [PATCH 1/2] hwmon: (pmbus/max20754) Add support for MAX20754 Atif Ofluoglu
2022-07-07 18:56 ` kernel test robot
@ 2022-07-13 14:16 ` Guenter Roeck
1 sibling, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2022-07-13 14:16 UTC (permalink / raw)
To: Atif Ofluoglu; +Cc: jdelvare, linux-hwmon, linux-kernel
On Thu, Jul 07, 2022 at 03:29:17PM +0000, Atif Ofluoglu wrote:
> From: Atif Ofluoglu <atif.ofluoglu@analog.com>
>
> Signed-off-by: Atif Ofluoglu <Atif.Ofluoglu@analog.com>
Please use lowercase for the e-mail address to avoid confusing
checkpatch.
> ---
> drivers/hwmon/pmbus/Kconfig | 9 +
> drivers/hwmon/pmbus/Makefile | 1 +
> drivers/hwmon/pmbus/max20754.c | 390 +++++++++++++++++++++++++++++++++
> 3 files changed, 400 insertions(+)
> create mode 100644 drivers/hwmon/pmbus/max20754.c
>
> diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
> index dfae76db65ae..f259b8739766 100644
> --- a/drivers/hwmon/pmbus/Kconfig
> +++ b/drivers/hwmon/pmbus/Kconfig
> @@ -254,6 +254,15 @@ config SENSORS_MAX20751
> This driver can also be built as a module. If so, the module will
> be called max20751.
>
> +config SENSORS_MAX20754
> + tristate "Maxim MAX20754"
> + help
> + If you say yes here you get hardware monitoring support for Maxim
> + MAX20754.
> +
> + This driver can also be built as a module. If so, the module will
> + be called max20754.
> +
> config SENSORS_MAX31785
> tristate "Maxim MAX31785 and compatibles"
> help
> diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
> index 4678fba5012c..b8b1d8a84b3b 100644
> --- a/drivers/hwmon/pmbus/Makefile
> +++ b/drivers/hwmon/pmbus/Makefile
> @@ -27,6 +27,7 @@ obj-$(CONFIG_SENSORS_MAX16064) += max16064.o
> obj-$(CONFIG_SENSORS_MAX16601) += max16601.o
> obj-$(CONFIG_SENSORS_MAX20730) += max20730.o
> obj-$(CONFIG_SENSORS_MAX20751) += max20751.o
> +obj-$(CONFIG_SENSORS_MAX20751) += max20754.o
> obj-$(CONFIG_SENSORS_MAX31785) += max31785.o
> obj-$(CONFIG_SENSORS_MAX34440) += max34440.o
> obj-$(CONFIG_SENSORS_MAX8688) += max8688.o
> diff --git a/drivers/hwmon/pmbus/max20754.c b/drivers/hwmon/pmbus/max20754.c
> new file mode 100644
> index 000000000000..5e29e8f8009b
> --- /dev/null
> +++ b/drivers/hwmon/pmbus/max20754.c
> @@ -0,0 +1,390 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Maxim MAX20754 Dual-Output, Configurable Multiphase
> + * Power-Supply Controller with PMBus Interface
> + * and Internal Buck Converter Driver
> + *
> + * Author: Atif Emre Ofluoglu <atif.ofluoglu@analog.com>
> + * Copyright (C) 2022 Analog Devices
> + *
> + * 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.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/err.h>
> +#include <linux/i2c.h>
> +#include <linux/hwmon.h>
Alphabetic include file order, please.
> +#include <linux/hwmon-sysfs.h>
Not needed.
> +#include "pmbus.h"
> +
> +enum chips { max20754 };
Not needed unless you plan to add another chip to the driver later on,
and then it should be added with the patch introducing that chip.
> +
> +#define MAX20754_NUM_PHASES 6
> +#define MAX20754_LINEAR_EXPONENT -10
#define<space>NAME<tab>value, please. Also, (-10)
> +
> +struct max20754_data {
> + enum chips id;
> + struct pmbus_driver_info info;
> + struct i2c_client *rail2;
> + bool smbus_i2c_block_read;
> +};
> +
> +#define to_max20754_data(x) container_of(x, struct max20754_data, info)
> +
> +enum max20754_reg_index {
> + operation_index,
> + on_off_config_index,
> + vout_command_index,
> + num_regs,
> +};
> +
> +static const u8 max20754_regs[num_regs][2] = {
> + [operation_index] = {PMBUS_OPERATION, 1},
> + [on_off_config_index] = {PMBUS_ON_OFF_CONFIG, 1},
> + [vout_command_index] = {PMBUS_VOUT_COMMAND, 2},
> +};
> +
> +static u16 val_to_linear16(int val)
> +{
> + return ((u16)val * 1000LL) >> -MAX20754_LINEAR_EXPONENT;
Double negation whenever MAX20754_LINEAR_EXPONENT ? What is the point
of that ?
> +}
> +
> +static long linear16_to_val(s64 val)
> +{
> + if (val == 0)
> + return 0;
Why is that needed ?
> +
> + val <<= -MAX20754_LINEAR_EXPONENT;
> + val = DIV_ROUND_CLOSEST_ULL(val, 1000);
> + val = clamp_val(val, 0, 0xffff);
> + return val;
> +}
> +
> +static int max20754_read_block_data(struct i2c_client *client, int reg,
> + u8 length, u8 *values)
> +{
> + const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
> + struct max20754_data *data = to_max20754_data(info);
> + int ret;
> +
> + if (data->smbus_i2c_block_read) {
> + ret = i2c_smbus_read_i2c_block_data(client, reg, length, values);
> + if (ret < 1)
> + return ret;
> + ret = ret - 1;
> + memcpy(values, &values[1], ret);
> + } else {
> + ret = i2c_smbus_read_block_data(client, reg, values);
> + }
> +
> + return ret;
> +}
> +
> +static int max20754_read_word(struct i2c_client *client, int page, int phase,
> + int reg)
> +{
> + const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
> + struct max20754_data *data = to_max20754_data(info);
> +
> + if (reg > 0xFF)
> + return -ENXIO;
> +
> + if (reg == PMBUS_MFR_VOUT_MAX)
> + reg = PMBUS_VOUT_MAX;
> +
I don't think this makes sense. MFR_VOUT_MAX is the _rated_
maximum output voltage, while VOUT_MAX is the _configured_ maximum
output voltage. Those are distinctly diffferent.
> + switch (page) {
> + case 0: /* RAIL1 */
> + return i2c_smbus_read_word_data(client, reg);
> + case 1: /* RAIL2 */
> + return i2c_smbus_read_word_data(data->rail2, reg);
> + default:
> + return -ENODATA;
> + }
> +
> + return -ENODATA;
> +}
> +
> +static int max20754_write_word(struct i2c_client *client, int page, int reg, u16 value)
> +{
> + const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
> + struct max20754_data *data = to_max20754_data(info);
> +
> + switch (reg) {
> + case PMBUS_OPERATION:
> + if (value >= 0x90 && value <= 0x93)
> + return -EOPNOTSUPP;
> + break;
> + case PMBUS_MFR_VOUT_MAX:
> + reg = PMBUS_VOUT_MAX;
> + break;
> + default:
> + break;
> + }
> +
> + switch (page) {
> + case 0: /* RAIL1 */
> + return i2c_smbus_write_word_data(client, reg, value);
> + case 1: /* RAIL2 */
> + return i2c_smbus_write_word_data(data->rail2, reg, value);
> + default:
> + return -EOPNOTSUPP;
> + }
> + return -ENODATA;
> +}
> +
> +static int max20754_read_byte(struct i2c_client *client, int page, int reg)
> +{
> + const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
> + struct max20754_data *data = to_max20754_data(info);
> + int vout_mode;
> +
> + if (reg == PMBUS_VOUT_MODE) {
> + vout_mode = i2c_smbus_read_byte_data(client, reg);
> + if (vout_mode != 0x2C)
> + vout_mode = 0x16;
This ignores errors.
> + return vout_mode;
Needs explanation.
> + }
> +
> + switch (page) {
> + case 0: /* RAIL1 */
> + return i2c_smbus_read_byte_data(client, reg);
> + case 1: /* RAIL2 */
> + return i2c_smbus_read_byte_data(data->rail2, reg);
> + default:
> + return -ENODATA;
> + }
> + return -ENODATA;
> +}
> +
> +static int max20754_write_byte(struct i2c_client *client, int page, u8 reg)
> +{
> + const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
> + struct max20754_data *data = to_max20754_data(info);
> +
> + if (reg == PMBUS_CLEAR_FAULTS) {
> + switch (page) {
> + case 0:
> + return i2c_smbus_write_byte(client, reg);
> + case 1:
> + return i2c_smbus_write_byte(data->rail2, reg);
> + default:
> + return -ENODATA;
> + }
> + }
> + return -ENODATA;
> +}
> +
> +static int max20754_identify(struct i2c_client *client,
> + struct pmbus_driver_info *info)
> +{
> + struct device *dev = &client->dev;
> + u8 buf[9] = {0};
> + int ret;
> +
> + ret = max20754_read_block_data(client,
> + PMBUS_IC_DEVICE_ID, 9,
> + buf);
> +
> + if (ret < 0 || ret < 8)
> + return -ENODEV;
> +
> + /*
> + * PMBUS_IC_DEVICE_ID is expected to return "MAX20754"
> + */
> +
> + if (strncmp(buf, "MAX20754", 8)) {
> + buf[ret] = '\0';
> + dev_err(dev, "Unsupported chip '%s'\n", buf);
> + return -ENODEV;
> + }
> +
> + return 0;
> +}
The above can and should be handled in the probe function.
With this, the smbus_i2c_block_read boolean in struct max20754_data
is no longer necessary.
> +
> +static ssize_t max20754_register_store(struct device *dev,
> + struct device_attribute *attr, const char *buf,
> + size_t count)
> +{
> + struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
> + struct i2c_client *client = to_i2c_client(dev->parent);
> + const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
> + struct max20754_data *data = to_max20754_data(info);
> +
> + u8 cmd = max20754_regs[sattr->index][0];
> + u8 reg_size = max20754_regs[sattr->index][1];
> + u8 rail_number = sattr->nr;
> + long val = 0;
Unnecessary initialization.
> + int ret;
> +
> + ret = kstrtol(buf, 10, &val);
> + if (ret)
> + return ret;
> +
> + if (rail_number == 1)
> + client = data->rail2;
> +
> + if (cmd == PMBUS_VOUT_COMMAND)
> + val = linear16_to_val(val);
> +
> + switch (reg_size) {
> + case 1:
> + ret = i2c_smbus_write_byte_data(client, cmd, val);
> + break;
> + case 2:
> + ret = i2c_smbus_write_word_data(client, cmd, val);
> + break;
> + default:
> + break;
> + }
> +
> + if (ret < 0)
> + return ret;
> +
> + return count;
> +}
> +
> +static ssize_t max20754_register_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
> + struct i2c_client *client = to_i2c_client(dev->parent);
> +
> + int ret_val = 0;
Why ret_val instead of ret like everywhere else ?
> + u8 cmd = max20754_regs[sattr->index][0];
> + u8 reg_size = max20754_regs[sattr->index][1];
> + u8 rail_number = sattr->nr;
> +
> + switch (reg_size) {
> + case 1:
> + ret_val = max20754_read_byte(client, rail_number, cmd);
> + break;
> + case 2:
> + ret_val = max20754_read_word(client, rail_number, 0, cmd);
> + break;
> + default:
> + break;
> + }
> +
> + if (ret_val < 0)
> + return -ENODATA;
> +
> + if (cmd == PMBUS_VOUT_COMMAND)
> + ret_val = val_to_linear16(ret_val);
> +
> + return sprintf(buf, "%d\n", ret_val);
> +}
> +
> +#define MAX20754_REGISTER_ATTR_RW(__name, __reg_index, __size) \
> + SENSOR_DEVICE_ATTR_2_RW(__name, max20754_register, __size, __reg_index)
> +
> +static MAX20754_REGISTER_ATTR_RW(operation, operation_index, 0);
> +static MAX20754_REGISTER_ATTR_RW(on_off_config, on_off_config_index, 0);
> +
> +static MAX20754_REGISTER_ATTR_RW(vout1_command, vout_command_index, 0);
> +static MAX20754_REGISTER_ATTR_RW(vout2_command, vout_command_index, 1);
> +
The above attributes are not acceptable. Register as regulator(s) if you
want to control output voltage and operation.
> +static struct attribute *max20754_attrs[] = {
> + &sensor_dev_attr_operation.dev_attr.attr,
> + &sensor_dev_attr_on_off_config.dev_attr.attr,
> + &sensor_dev_attr_vout1_command.dev_attr.attr,
> + &sensor_dev_attr_vout2_command.dev_attr.attr,
> + NULL
> +};
> +ATTRIBUTE_GROUPS(max20754);
> +
> +static struct pmbus_driver_info max20754_info = {
> + .pages = 2,
> + .format[PSC_VOLTAGE_IN] = linear,
> + .format[PSC_VOLTAGE_OUT] = linear,
> + .vrm_version[0] = vr12,
> + .format[PSC_TEMPERATURE] = linear,
> + .format[PSC_CURRENT_OUT] = linear,
> + .format[PSC_POWER] = linear,
> + .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
> + PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
> + PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP,
> + .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_INPUT |
> + PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
> + PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP,
> + .identify = max20754_identify,
> + .read_byte_data = max20754_read_byte,
> + .read_word_data = max20754_read_word,
> + .write_byte = max20754_write_byte,
> + .write_word_data = max20754_write_word,
> +};
> +
> +static void max20754_remove(void *_data)
> +{
> + struct max20754_data *data = _data;
> +
> + i2c_unregister_device(data->rail2);
> +}
> +
> +static int max20754_probe(struct i2c_client *client)
> +{
> + struct device *dev = &client->dev;
> + struct max20754_data *data;
> + bool i2c_block_data_ok = false;
> + int ret = 0;
Unnecessary assignment.
> +
> + ret = i2c_check_functionality(client->adapter,
> + I2C_FUNC_SMBUS_READ_BYTE_DATA |
> + I2C_FUNC_SMBUS_READ_BLOCK_DATA);
> +
Unnecessary empty line. Also, assigning the return value to a variable
isn't really necessary.
if (!i2c_check_functionality(...)) {
...
> + if (!ret)
> + ret = i2c_check_functionality(client->adapter,
> + I2C_FUNC_SMBUS_READ_BYTE_DATA |
> + I2C_FUNC_SMBUS_I2C_BLOCK);
> + if (!ret)
> + return -ENODEV;
if (!i2c_check_functionality(...))
return -ENODEV;
> +
> + i2c_block_data_ok = true;
> + }
> +
> + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + data->rail2 = i2c_new_dummy_device(client->adapter, client->addr + 1);
> + if (IS_ERR(data->rail2)) {
> + dev_err(dev, "Failed to register rail2 client\n");
> + return PTR_ERR(data->rail2);
> + }
> + ret = devm_add_action_or_reset(dev, max20754_remove, data);
> + if (ret)
> + return ret;
> +
> + data->info = max20754_info;
> + data->info.groups = max20754_groups;
> + data->smbus_i2c_block_read = i2c_block_data_ok;
> +
> + return pmbus_do_probe(client, &data->info);
> +}
> +
> +static const struct i2c_device_id max20754_id[] = {
> + {"max20754", max20754},
> + {}
> +};
> +
> +MODULE_DEVICE_TABLE(i2c, max20754_id);
> +
> +static struct i2c_driver max20754_driver = {
> + .driver = {
> + .name = "max20754",
> + },
> + .probe_new = max20754_probe,
> + .remove = pmbus_do_remove,
Please rebase to latest kernel. pmbus_do_remove() no longer exists.
> + .id_table = max20754_id,
> +};
> +
> +module_i2c_driver(max20754_driver);
> +
> +MODULE_AUTHOR("Atif Emre Ofluoglu <atif.ofluoglu@analog.com>");
> +MODULE_DESCRIPTION("PMBus driver for Maxim MAX20754");
> +MODULE_LICENSE("GPL");
> +MODULE_IMPORT_NS(PMBUS);
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-07-13 14:16 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-07 15:29 [PATCH 0/2] Adding MAX20754 support Atif Ofluoglu
2022-07-07 15:29 ` [PATCH 1/2] hwmon: (pmbus/max20754) Add support for MAX20754 Atif Ofluoglu
2022-07-07 18:56 ` kernel test robot
2022-07-13 14:16 ` Guenter Roeck
2022-07-07 15:29 ` [PATCH 2/2] Added documentation for Maxim Integrated max20754 hwmon userspace sysfs Atif Ofluoglu
2022-07-08 6:41 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox