linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v8 0/4] hwmon: Add max31760 fan speed controller
@ 2022-09-09 13:37 Ibrahim Tilki
  2022-09-09 13:37 ` [PATCH v8 1/4] drivers: hwmon: Add max31760 fan speed controller driver Ibrahim Tilki
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Ibrahim Tilki @ 2022-09-09 13:37 UTC (permalink / raw)
  To: jdelvare, linux
  Cc: Ibrahim Tilki, linux-hwmon, robh+dt, krzysztof.kozlowski+dt,
	devicetree, linux-kernel

changes in v8:
  - use sizeof(*)
  - use DEFINE_SIMPLE_DEV_PM_OPS
  - remove __maybe_unused
  - remove of_match_ptr
  - dt-bindings: style fixes

changes in v7:
  - make max31760_read_string static

changes in v6:
  - update description of hwmon documentation
  - add hwmon documentation to index.rst

changes in v5:
  - add dt-bindings documentation
  - add maintainer

changes in v4:
  - use sysfs_emit instead of sprintf
  - use kstrtou8 for pwm
  - use closest match for pwm1_auto_point_temp_hyst

changes in v3:
  - add regmap cache
  - remove pwm1_auto_point[1-48]_{temp,temp_hyst} attributes
  - add pwm1_auto_point_temp_hyst attribute

changes in v2:
  - remove pulse_per_rev variable in tach_to_rpm
  - remove temperature max_hyst and crit_hyst
  - strict value checking for fan_enable and pwm_enable
  - do not clamp pwm value for Look-up table
  - add sysfs_attr_init call
  - add documentation


Ibrahim Tilki (4):
  drivers: hwmon: Add max31760 fan speed controller driver
  docs: hwmon: add max31760 documentation
  dt-bindings: hwmon: Add bindings for max31760
  MAINTAINERS: Add maintainer for hwmon/max31760

 .../bindings/hwmon/adi,max31760.yaml          |  44 ++
 Documentation/hwmon/index.rst                 |   1 +
 Documentation/hwmon/max31760.rst              |  77 +++
 MAINTAINERS                                   |   9 +
 drivers/hwmon/Kconfig                         |  12 +
 drivers/hwmon/Makefile                        |   1 +
 drivers/hwmon/max31760.c                      | 596 ++++++++++++++++++
 7 files changed, 740 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/adi,max31760.yaml
 create mode 100644 Documentation/hwmon/max31760.rst
 create mode 100644 drivers/hwmon/max31760.c

-- 
2.36.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v8 1/4] drivers: hwmon: Add max31760 fan speed controller driver
  2022-09-09 13:37 [PATCH v8 0/4] hwmon: Add max31760 fan speed controller Ibrahim Tilki
@ 2022-09-09 13:37 ` Ibrahim Tilki
  2022-09-09 17:43   ` Guenter Roeck
  2022-09-09 13:37 ` [PATCH v8 2/4] docs: hwmon: add max31760 documentation Ibrahim Tilki
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 16+ messages in thread
From: Ibrahim Tilki @ 2022-09-09 13:37 UTC (permalink / raw)
  To: jdelvare, linux
  Cc: Ibrahim Tilki, linux-hwmon, robh+dt, krzysztof.kozlowski+dt,
	devicetree, linux-kernel, Nurettin Bolucu

MAX31760 is a precision fan speed controller with nonvolatile lookup table.
Device has one internal and one external temperature sensor support.
Controls two fans and measures their speeds. Generates hardware alerts when
programmable max and critical temperatures are exceeded.

Signed-off-by: Ibrahim Tilki <Ibrahim.Tilki@analog.com>
Reviewed-by: Nurettin Bolucu <Nurettin.Bolucu@analog.com>
---
 drivers/hwmon/Kconfig    |  12 +
 drivers/hwmon/Makefile   |   1 +
 drivers/hwmon/max31760.c | 596 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 609 insertions(+)
 create mode 100644 drivers/hwmon/max31760.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index e70d9614b..46ae3c4c4 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1066,6 +1066,18 @@ config SENSORS_MAX31730
 	  This driver can also be built as a module. If so, the module
 	  will be called max31730.
 
+config SENSORS_MAX31760
+	tristate "MAX31760 fan speed controller"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  Support for the Analog Devices MAX31760 Precision Fan-Speed
+	  Controller. MAX31760 integrates temperature sensing along with
+	  precision PWM fan control.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called max31760.
+
 config SENSORS_MAX6620
 	tristate "Maxim MAX6620 fan controller"
 	depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 007e829d1..1c0fa4dd8 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -140,6 +140,7 @@ obj-$(CONFIG_SENSORS_MAX1668)	+= max1668.o
 obj-$(CONFIG_SENSORS_MAX197)	+= max197.o
 obj-$(CONFIG_SENSORS_MAX31722)	+= max31722.o
 obj-$(CONFIG_SENSORS_MAX31730)	+= max31730.o
+obj-$(CONFIG_SENSORS_MAX31760)  += max31760.o
 obj-$(CONFIG_SENSORS_MAX6620)	+= max6620.o
 obj-$(CONFIG_SENSORS_MAX6621)	+= max6621.o
 obj-$(CONFIG_SENSORS_MAX6639)	+= max6639.o
diff --git a/drivers/hwmon/max31760.c b/drivers/hwmon/max31760.c
new file mode 100644
index 000000000..ab6764787
--- /dev/null
+++ b/drivers/hwmon/max31760.c
@@ -0,0 +1,596 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/bitfield.h>
+#include <linux/bits.h>
+#include <linux/err.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+#include <linux/util_macros.h>
+
+#define REG_CR1		0x00
+#define CR1_HYST	BIT(5)
+#define CR1_DRV		GENMASK(4, 3)
+#define CR1_TEMP_SRC	GENMASK(1, 0)
+#define REG_CR2		0x01
+#define CR2_STBY	BIT(7)
+#define CR2_ALERTS	BIT(6)
+#define CR2_DFC		BIT(0)
+#define REG_CR3		0x02
+#define REG_PWMR	0x50
+#define REG_PWMV	0x51
+#define REG_STATUS	0x5A
+#define STATUS_ALARM_CRIT(ch)	BIT(2 + 2 * (ch))
+#define STATUS_ALARM_MAX(ch)	BIT(3 + 2 * (ch))
+#define STATUS_RDFA		BIT(6)
+
+#define REG_TACH(ch)		(0x52 + (ch) * 2)
+#define REG_TEMP_INPUT(ch)	(0x56 + (ch) * 2)
+#define REG_TEMP_MAX(ch)	(0x06 + (ch) * 2)
+#define REG_TEMP_CRIT(ch)	(0x0A + (ch) * 2)
+
+#define TEMP11_FROM_REG(reg)	((reg) / 32 * 125)
+#define TEMP11_TO_REG(val)	(DIV_ROUND_CLOSEST(clamp_val((val), -128000, \
+							     127875), 125) * 32)
+
+#define LUT_SIZE	48
+
+#define REG_LUT(index)		(0x20 + (index))
+
+struct max31760_state {
+	struct regmap *regmap;
+
+	struct lut_attribute {
+		char name[24];
+		struct sensor_device_attribute sda;
+	} lut[LUT_SIZE];
+
+	struct attribute *attrs[LUT_SIZE + 2];
+	struct attribute_group group;
+	const struct attribute_group *groups[2];
+};
+
+static bool max31760_volatile_reg(struct device *dev, unsigned int reg)
+{
+	return reg > 0x50;
+}
+
+static const struct regmap_config regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = 0x5B,
+	.cache_type = REGCACHE_RBTREE,
+	.volatile_reg = max31760_volatile_reg,
+};
+
+static const int max31760_pwm_freq[] = {33, 150, 1500, 25000};
+
+static int tach_to_rpm(u16 tach)
+{
+	if (tach == 0)
+		tach = 1;
+
+	return 60 * 100000 / tach / 2;
+}
+
+static int max31760_read(struct device *dev, enum hwmon_sensor_types type,
+			 u32 attr, int channel, long *val)
+{
+	struct max31760_state *state = dev_get_drvdata(dev);
+	unsigned int regval;
+	unsigned int reg_temp;
+	s16 temp;
+	u8 reg[2];
+	int ret;
+
+	switch (type) {
+	case hwmon_temp:
+		switch (attr) {
+		case hwmon_temp_fault:
+			ret = regmap_read(state->regmap, REG_STATUS, &regval);
+			if (ret)
+				return ret;
+
+			*val = FIELD_GET(STATUS_RDFA, regval);
+
+			return 0;
+		case hwmon_temp_max_alarm:
+			ret = regmap_read(state->regmap, REG_STATUS, &regval);
+			if (ret)
+				return ret;
+
+			if (channel)
+				*val = FIELD_GET(STATUS_ALARM_MAX(1), regval);
+			else
+				*val = FIELD_GET(STATUS_ALARM_MAX(0), regval);
+
+			return 0;
+		case hwmon_temp_crit_alarm:
+			ret = regmap_read(state->regmap, REG_STATUS, &regval);
+			if (ret)
+				return ret;
+
+			if (channel)
+				*val = FIELD_GET(STATUS_ALARM_CRIT(1), regval);
+			else
+				*val = FIELD_GET(STATUS_ALARM_CRIT(0), regval);
+
+			return 0;
+		case hwmon_temp_input:
+			reg_temp = REG_TEMP_INPUT(channel);
+			break;
+		case hwmon_temp_max:
+			reg_temp = REG_TEMP_MAX(channel);
+			break;
+		case hwmon_temp_crit:
+			reg_temp = REG_TEMP_CRIT(channel);
+			break;
+		default:
+			return -EOPNOTSUPP;
+		}
+
+		ret = regmap_bulk_read(state->regmap, reg_temp, reg, 2);
+		if (ret)
+			return ret;
+
+		temp = (reg[0] << 8) | reg[1];
+
+		*val = TEMP11_FROM_REG(temp);
+
+		return 0;
+	case hwmon_fan:
+		switch (attr) {
+		case hwmon_fan_input:
+			ret = regmap_bulk_read(state->regmap, REG_TACH(channel), reg, 2);
+			if (ret)
+				return ret;
+
+			*val = tach_to_rpm(reg[0] * 256 + reg[1]);
+
+			return 0;
+		case hwmon_fan_fault:
+			ret = regmap_read(state->regmap, REG_STATUS, &regval);
+			if (ret)
+				return ret;
+
+			if (channel)
+				*val = FIELD_GET(BIT(1), regval);
+			else
+				*val = FIELD_GET(BIT(0), regval);
+
+			return 0;
+		case hwmon_fan_enable:
+			ret = regmap_read(state->regmap, REG_CR3, &regval);
+			if (ret)
+				return ret;
+
+			if (channel)
+				*val = FIELD_GET(BIT(1), regval);
+			else
+				*val = FIELD_GET(BIT(0), regval);
+
+			return 0;
+		default:
+			return -EOPNOTSUPP;
+		}
+	case hwmon_pwm:
+		switch (attr) {
+		case hwmon_pwm_input:
+			ret = regmap_read(state->regmap, REG_PWMV, &regval);
+			if (ret)
+				return ret;
+
+			*val = regval;
+
+			return 0;
+		case hwmon_pwm_freq:
+			ret = regmap_read(state->regmap, REG_CR1, &regval);
+			if (ret)
+				return ret;
+
+			regval = FIELD_GET(CR1_DRV, regval);
+			if (regval >= ARRAY_SIZE(max31760_pwm_freq))
+				return -EINVAL;
+
+			*val = max31760_pwm_freq[regval];
+
+			return 0;
+		case hwmon_pwm_enable:
+			ret = regmap_read(state->regmap, REG_CR2, &regval);
+			if (ret)
+				return ret;
+
+			*val = 2 - FIELD_GET(CR2_DFC, regval);
+
+			return 0;
+		case hwmon_pwm_auto_channels_temp:
+			ret = regmap_read(state->regmap, REG_CR1, &regval);
+			if (ret)
+				return ret;
+
+			switch (FIELD_GET(CR1_TEMP_SRC, regval)) {
+			case 0:
+				*val = 2;
+				break;
+			case 1:
+				*val = 1;
+				break;
+			case 2:
+			case 3:
+				*val = 3;
+				break;
+			default:
+				return -EINVAL;
+			}
+
+			return 0;
+		default:
+			return -EOPNOTSUPP;
+		}
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int max31760_write(struct device *dev, enum hwmon_sensor_types type,
+			  u32 attr, int channel, long val)
+{
+	struct max31760_state *state = dev_get_drvdata(dev);
+	unsigned int pwm_index;
+	unsigned int reg_temp;
+	int temp;
+	u8 reg_val[2];
+
+	switch (type) {
+	case hwmon_temp:
+		switch (attr) {
+		case hwmon_temp_max:
+			reg_temp = REG_TEMP_MAX(channel);
+			break;
+		case hwmon_temp_crit:
+			reg_temp = REG_TEMP_CRIT(channel);
+			break;
+		default:
+			return -EOPNOTSUPP;
+		}
+
+		temp = TEMP11_TO_REG(val);
+		reg_val[0] = temp >> 8;
+		reg_val[1] = temp & 0xFF;
+
+		return regmap_bulk_write(state->regmap, reg_temp, reg_val, 2);
+	case hwmon_fan:
+		switch (attr) {
+		case hwmon_fan_enable:
+			if (val == 0)
+				return regmap_clear_bits(state->regmap, REG_CR3, BIT(channel));
+
+			if (val == 1)
+				return regmap_set_bits(state->regmap, REG_CR3, BIT(channel));
+
+			return -EOPNOTSUPP;
+		default:
+			return -EOPNOTSUPP;
+		}
+	case hwmon_pwm:
+		switch (attr) {
+		case hwmon_pwm_input:
+			if (val < 0 || val > 255)
+				return -EINVAL;
+
+			return regmap_write(state->regmap, REG_PWMR, val);
+		case hwmon_pwm_enable:
+			if (val == 1)
+				return regmap_set_bits(state->regmap, REG_CR2, CR2_DFC);
+
+			if (val == 2)
+				return regmap_clear_bits(state->regmap, REG_CR2, CR2_DFC);
+
+			return -EOPNOTSUPP;
+		case hwmon_pwm_freq:
+			pwm_index = find_closest(val, max31760_pwm_freq,
+						 ARRAY_SIZE(max31760_pwm_freq));
+
+			return regmap_update_bits(state->regmap,
+						  REG_CR1, CR1_DRV,
+						  FIELD_PREP(CR1_DRV, pwm_index));
+		case hwmon_pwm_auto_channels_temp:
+			switch (val) {
+			case 1:
+				break;
+			case 2:
+				val = 0;
+				break;
+			case 3:
+				val = 2;
+				break;
+			default:
+				return -EINVAL;
+			}
+
+			return regmap_update_bits(state->regmap, REG_CR1, CR1_TEMP_SRC, val);
+		default:
+			return -EOPNOTSUPP;
+		}
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static const struct hwmon_channel_info *max31760_info[] = {
+	HWMON_CHANNEL_INFO(chip,
+			   HWMON_C_REGISTER_TZ),
+	HWMON_CHANNEL_INFO(fan,
+			   HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE,
+			   HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_ENABLE),
+	HWMON_CHANNEL_INFO(temp,
+			   HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_CRIT | HWMON_T_FAULT |
+			   HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | HWMON_T_LABEL,
+			   HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_CRIT |
+			   HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | HWMON_T_LABEL),
+	HWMON_CHANNEL_INFO(pwm,
+			   HWMON_PWM_ENABLE | HWMON_PWM_FREQ | HWMON_PWM_INPUT |
+			   HWMON_PWM_AUTO_CHANNELS_TEMP),
+	NULL
+};
+
+static umode_t max31760_is_visible(const void *data,
+				   enum hwmon_sensor_types type,
+				   u32 attr, int channel)
+{
+	switch (type) {
+	case hwmon_temp:
+		switch (attr) {
+		case hwmon_temp_input:
+		case hwmon_temp_max_alarm:
+		case hwmon_temp_crit_alarm:
+		case hwmon_temp_fault:
+		case hwmon_temp_label:
+			return 0444;
+		case hwmon_temp_max:
+		case hwmon_temp_crit:
+			return 0644;
+		default:
+			return 0;
+		}
+	case hwmon_fan:
+		switch (attr) {
+		case hwmon_fan_input:
+		case hwmon_fan_fault:
+			return 0444;
+		case hwmon_fan_enable:
+			return 0644;
+		default:
+			return 0;
+		}
+	case hwmon_pwm:
+		switch (attr) {
+		case hwmon_pwm_enable:
+		case hwmon_pwm_input:
+		case hwmon_pwm_freq:
+		case hwmon_pwm_auto_channels_temp:
+			return 0644;
+		default:
+			return 0;
+		}
+	default:
+		return 0;
+	}
+}
+
+static int max31760_read_string(struct device *dev,
+				enum hwmon_sensor_types type,
+				u32 attr, int channel, const char **str)
+{
+	switch (type) {
+	case hwmon_temp:
+		if (attr != hwmon_temp_label)
+			return -EOPNOTSUPP;
+
+		*str = channel ? "local" : "remote";
+
+		return 0;
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static const struct hwmon_ops max31760_hwmon_ops = {
+	.is_visible = max31760_is_visible,
+	.read = max31760_read,
+	.write = max31760_write,
+	.read_string = max31760_read_string
+};
+
+static const struct hwmon_chip_info max31760_chip_info = {
+	.ops = &max31760_hwmon_ops,
+	.info = max31760_info,
+};
+
+static ssize_t lut_show(struct device *dev,
+			struct device_attribute *devattr, char *buf)
+{
+	struct sensor_device_attribute *sda = to_sensor_dev_attr(devattr);
+	struct max31760_state *state = dev_get_drvdata(dev);
+	int ret;
+	unsigned int regval;
+
+	ret = regmap_read(state->regmap, REG_LUT(sda->index), &regval);
+	if (ret)
+		return ret;
+
+	return sysfs_emit(buf, "%d\n", regval);
+}
+
+static ssize_t lut_store(struct device *dev,
+			 struct device_attribute *devattr,
+			 const char *buf, size_t count)
+{
+	struct sensor_device_attribute *sda = to_sensor_dev_attr(devattr);
+	struct max31760_state *state = dev_get_drvdata(dev);
+	int ret;
+	u8 pwm;
+
+	ret = kstrtou8(buf, 10, &pwm);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(state->regmap, REG_LUT(sda->index), pwm);
+	if (ret)
+		return ret;
+
+	return count;
+}
+
+static ssize_t pwm1_auto_point_temp_hyst_show(struct device *dev,
+					      struct device_attribute *attr,
+					      char *buf)
+{
+	struct max31760_state *state = dev_get_drvdata(dev);
+	unsigned int regval;
+	int ret;
+
+	ret = regmap_read(state->regmap, REG_CR1, &regval);
+	if (ret)
+		return ret;
+
+	return sysfs_emit(buf, "%d\n", (1 + (int)FIELD_GET(CR1_HYST, regval)) * 2000);
+}
+
+static ssize_t pwm1_auto_point_temp_hyst_store(struct device *dev,
+					       struct device_attribute *attr,
+					       const char *buf,
+					       size_t count)
+{
+	struct max31760_state *state = dev_get_drvdata(dev);
+	unsigned int hyst;
+	int ret;
+
+	ret = kstrtou32(buf, 10, &hyst);
+	if (ret)
+		return ret;
+
+	if (hyst < 3000)
+		ret = regmap_clear_bits(state->regmap, REG_CR1, CR1_HYST);
+	else
+		ret = regmap_set_bits(state->regmap, REG_CR1, CR1_HYST);
+
+	if (ret)
+		return ret;
+
+	return count;
+}
+
+static DEVICE_ATTR_RW(pwm1_auto_point_temp_hyst);
+
+static void max31760_create_lut_nodes(struct max31760_state *state)
+{
+	int i;
+	struct sensor_device_attribute *sda;
+	struct lut_attribute *lut;
+
+	for (i = 0; i < LUT_SIZE; ++i) {
+		lut = &state->lut[i];
+		sda = &lut->sda;
+
+		snprintf(lut->name, sizeof(lut->name),
+			 "pwm1_auto_point%d_pwm", i + 1);
+
+		sda->dev_attr.attr.mode = 0644;
+		sda->index = i;
+		sda->dev_attr.show = lut_show;
+		sda->dev_attr.store = lut_store;
+		sda->dev_attr.attr.name = lut->name;
+
+		sysfs_attr_init(&sda->dev_attr.attr);
+
+		state->attrs[i] = &sda->dev_attr.attr;
+	}
+
+	state->attrs[i] = &dev_attr_pwm1_auto_point_temp_hyst.attr;
+
+	state->group.attrs = state->attrs;
+	state->groups[0] = &state->group;
+}
+
+static int max31760_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct max31760_state *state;
+	struct device *hwmon_dev;
+	int ret;
+
+	state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL);
+	if (!state)
+		return -ENOMEM;
+
+	state->regmap = devm_regmap_init_i2c(client, &regmap_config);
+	if (IS_ERR(state->regmap))
+		return dev_err_probe(dev,
+				     PTR_ERR(state->regmap),
+				     "regmap initialization failed\n");
+
+	dev_set_drvdata(dev, state);
+
+	/* Set alert output to comparator mode */
+	ret = regmap_set_bits(state->regmap, REG_CR2, CR2_ALERTS);
+	if (ret)
+		return dev_err_probe(dev, ret, "cannot write register\n");
+
+	max31760_create_lut_nodes(state);
+
+	hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
+							 state,
+							 &max31760_chip_info,
+							 state->groups);
+
+	return PTR_ERR_OR_ZERO(hwmon_dev);
+}
+
+static const struct of_device_id max31760_of_match[] = {
+	{.compatible = "adi,max31760"},
+	{ }
+};
+MODULE_DEVICE_TABLE(of, max31760_of_match);
+
+static const struct i2c_device_id max31760_id[] = {
+	{"max31760"},
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, max31760_id);
+
+static int max31760_suspend(struct device *dev)
+{
+	struct max31760_state *state = dev_get_drvdata(dev);
+
+	return regmap_set_bits(state->regmap, REG_CR2, CR2_STBY);
+}
+
+static int max31760_resume(struct device *dev)
+{
+	struct max31760_state *state = dev_get_drvdata(dev);
+
+	return regmap_clear_bits(state->regmap, REG_CR2, CR2_STBY);
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(max31760_pm_ops, max31760_suspend,
+				max31760_resume);
+
+static struct i2c_driver max31760_driver = {
+	.class		= I2C_CLASS_HWMON,
+	.driver = {
+		.name	= "max31760",
+		.of_match_table = max31760_of_match,
+		.pm = pm_ptr(&max31760_pm_ops)
+	},
+	.probe_new	= max31760_probe,
+	.id_table	= max31760_id
+};
+module_i2c_driver(max31760_driver);
+
+MODULE_AUTHOR("Ibrahim Tilki <Ibrahim.Tilki@analog.com>");
+MODULE_DESCRIPTION("Analog Devices MAX31760 Fan Speed Controller");
+MODULE_SOFTDEP("pre: regmap_i2c");
+MODULE_VERSION("1.0");
+MODULE_LICENSE("GPL");
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v8 2/4] docs: hwmon: add max31760 documentation
  2022-09-09 13:37 [PATCH v8 0/4] hwmon: Add max31760 fan speed controller Ibrahim Tilki
  2022-09-09 13:37 ` [PATCH v8 1/4] drivers: hwmon: Add max31760 fan speed controller driver Ibrahim Tilki
@ 2022-09-09 13:37 ` Ibrahim Tilki
  2022-09-09 13:37 ` [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760 Ibrahim Tilki
  2022-09-09 13:37 ` [PATCH v8 4/4] MAINTAINERS: Add maintainer for hwmon/max31760 Ibrahim Tilki
  3 siblings, 0 replies; 16+ messages in thread
From: Ibrahim Tilki @ 2022-09-09 13:37 UTC (permalink / raw)
  To: jdelvare, linux
  Cc: Ibrahim Tilki, linux-hwmon, robh+dt, krzysztof.kozlowski+dt,
	devicetree, linux-kernel

Adding documentation for max31760 fan speed controller

Signed-off-by: Ibrahim Tilki <Ibrahim.Tilki@analog.com>
---
 Documentation/hwmon/index.rst    |  1 +
 Documentation/hwmon/max31760.rst | 77 ++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+)
 create mode 100644 Documentation/hwmon/max31760.rst

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index f7113b0f8..dba260013 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -133,6 +133,7 @@ Hardware Monitoring Kernel Drivers
    max20751
    max31722
    max31730
+   max31760
    max31785
    max31790
    max34440
diff --git a/Documentation/hwmon/max31760.rst b/Documentation/hwmon/max31760.rst
new file mode 100644
index 000000000..b1b55fb84
--- /dev/null
+++ b/Documentation/hwmon/max31760.rst
@@ -0,0 +1,77 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver max31760
+======================
+
+Supported chips:
+  * Analog Devices MAX31760
+
+    Prefix: 'max31760'
+
+    Addresses scanned: none
+
+    Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX31760.pdf
+
+
+Author: Ibrahim Tilki <Ibrahim.Tilki@analog.com>
+
+Description
+-----------
+
+The MAX31760 integrates temperature sensing along with precision PWM fan
+control. It accurately measures its local die temperature and the remote
+temperature of a discrete diode-connected transistor, such as a 2N3906,
+or a thermal diode commonly found on CPUs, graphics processor units (GPUs),
+and other ASICs. Multiple temperature thresholds, such as local
+high/overtemperature (OT) and remote high/overtemperature, can be set by an
+I2C-compatible interface. Fan speed is controlled based on the temperature
+reading as an index to a 48-byte lookup table (LUT) containing
+user-programmed PWM values. The flexible LUT-based architecture enables
+the user to program a smooth nonlinear fan speed vs. temperature transfer
+function to minimize acoustic fan noise. Two tachometer inputs allow
+measuring the speeds of two fans independently. When the local or remote
+OT threshold is exceeded, the SHDN pin is asserted low and can be used to
+shut down the system. A dedicated ALERT pin reports that either a local or
+remote high-temperature threshold has been exceeded.
+
+Temperature measurement range: from -55°C to 125°C
+
+Temperature Resolution: 11 Bits, ±0.125°C
+
+Please refer how to instantiate this driver: Documentation/i2c/instantiating-devices.rst
+
+Lookup table for auto fan control
+---------------------------------
+
+========= =================================
+LUT Index Name
+========= =================================
+1         PWM value for T < +18°C
+2         PWM value for +18°C ≤ T < +20°C
+3         PWM value for +20°C ≤ T < +22°C
+...       ...
+47        PWM value for +108°C ≤ T < +110°C
+48        PWM value for T ≥ +110°C
+========= =================================
+
+Sysfs entries
+-------------
+
+=============================== =================================================================================
+fan[1-2]_input                  Fan speed (in RPM)
+fan[1-2]_enable                 Enable fan readings and fan fault alarms
+fan[1-2]_fault                  Fan fault status
+temp[1-2]_label                 "Remote" and "Local" temperature channel labels
+temp[1-2]_input                 Temperature sensor readings (in millidegrees Celsius)
+temp1_fault                     Remote temperature sensor fault status
+temp[1-2]_max                   Temperature max value. Asserts "ALERT" pin when exceeded
+temp[1-2]_max_alarm             Temperature max alarm status
+temp[1-2]_crit                  Temperature critical value. Asserts "SHDN" pin when exceeded
+temp[1-2]_crit_alarm            Temperature critical alarm status
+pwm1                            PWM value for direct fan control
+pwm1_enable                     1: direct fan control, 2: temperature based auto fan control
+pwm1_freq                       PWM frequency in hertz
+pwm1_auto_channels_temp         Temperature source for auto fan control. 1: temp1, 2: temp2, 3: max(temp1, temp2)
+pwm1_auto_point[1-48]_pwm       PWM value for LUT point
+pwm1_auto_point_temp_hyst       Temperature hysteresis for auto fan control. Can be either 2000mC or 4000mC
+=============================== =================================================================================
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760
  2022-09-09 13:37 [PATCH v8 0/4] hwmon: Add max31760 fan speed controller Ibrahim Tilki
  2022-09-09 13:37 ` [PATCH v8 1/4] drivers: hwmon: Add max31760 fan speed controller driver Ibrahim Tilki
  2022-09-09 13:37 ` [PATCH v8 2/4] docs: hwmon: add max31760 documentation Ibrahim Tilki
@ 2022-09-09 13:37 ` Ibrahim Tilki
  2022-09-09 14:49   ` Krzysztof Kozlowski
  2022-09-09 16:26   ` Rob Herring
  2022-09-09 13:37 ` [PATCH v8 4/4] MAINTAINERS: Add maintainer for hwmon/max31760 Ibrahim Tilki
  3 siblings, 2 replies; 16+ messages in thread
From: Ibrahim Tilki @ 2022-09-09 13:37 UTC (permalink / raw)
  To: jdelvare, linux
  Cc: Ibrahim Tilki, linux-hwmon, robh+dt, krzysztof.kozlowski+dt,
	devicetree, linux-kernel

Adding bindings for Analog Devices MAX31760 Fan-Speed Controller

Signed-off-by: Ibrahim Tilki <Ibrahim.Tilki@analog.com>
---
 .../bindings/hwmon/adi,max31760.yaml          | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/adi,max31760.yaml

diff --git a/Documentation/devicetree/bindings/hwmon/adi,max31760.yaml b/Documentation/devicetree/bindings/hwmon/adi,max31760.yaml
new file mode 100644
index 000000000..c9318e4b3
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/adi,max31760.yaml
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/adi,max31760.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices MAX31760 Fan-Speed Controller
+
+maintainers:
+  - Ibrahim Tilki <Ibrahim.Tilki@analog.com>
+
+description: |
+  Analog Devices MAX31760 Fan-Speed Controller
+  https://datasheets.maximintegrated.com/en/ds/MAX31760.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,max31760
+
+  reg:
+    description: I2C address of slave device.
+    maxItems: 1
+    items:
+      minimum: 0x50
+      maximum: 0x57
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        fan-controller@50 {
+            reg = <0x50>;
+            compatible = "adi,max31760";
+        };
+    };
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v8 4/4] MAINTAINERS: Add maintainer for hwmon/max31760
  2022-09-09 13:37 [PATCH v8 0/4] hwmon: Add max31760 fan speed controller Ibrahim Tilki
                   ` (2 preceding siblings ...)
  2022-09-09 13:37 ` [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760 Ibrahim Tilki
@ 2022-09-09 13:37 ` Ibrahim Tilki
  3 siblings, 0 replies; 16+ messages in thread
From: Ibrahim Tilki @ 2022-09-09 13:37 UTC (permalink / raw)
  To: jdelvare, linux
  Cc: Ibrahim Tilki, linux-hwmon, robh+dt, krzysztof.kozlowski+dt,
	devicetree, linux-kernel

Add maintainer for hwmon/max31760 driver

Signed-off-by: Ibrahim Tilki <Ibrahim.Tilki@analog.com>
---
 MAINTAINERS | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index f1390b827..78ab41c92 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1334,6 +1334,15 @@ F:	drivers/iio/amplifiers/hmc425a.c
 F:	drivers/staging/iio/*/ad*
 X:	drivers/iio/*/adjd*
 
+ANALOG DEVICES INC MAX31760 DRIVER
+M:	Ibrahim Tilki <Ibrahim.Tilki@analog.com>
+S:	Maintained
+W:	http://wiki.analog.com/
+W:	https://ez.analog.com/linux-software-drivers
+F:	Documentation/devicetree/bindings/hwmon/adi,max31760.yaml
+F:	Documentation/hwmon/max31760.rst
+F:	drivers/hwmon/max31760.c
+
 ANALOGBITS PLL LIBRARIES
 M:	Paul Walmsley <paul.walmsley@sifive.com>
 S:	Supported
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760
  2022-09-09 13:37 ` [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760 Ibrahim Tilki
@ 2022-09-09 14:49   ` Krzysztof Kozlowski
  2022-09-09 14:52     ` Guenter Roeck
  2022-09-09 16:26   ` Rob Herring
  1 sibling, 1 reply; 16+ messages in thread
From: Krzysztof Kozlowski @ 2022-09-09 14:49 UTC (permalink / raw)
  To: Ibrahim Tilki, jdelvare, linux
  Cc: linux-hwmon, robh+dt, krzysztof.kozlowski+dt, devicetree, linux-kernel

On 09/09/2022 15:37, Ibrahim Tilki wrote:
> Adding bindings for Analog Devices MAX31760 Fan-Speed Controller
> 
> Signed-off-by: Ibrahim Tilki <Ibrahim.Tilki@analog.com>
> ---


Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Please wait with applying for Rob's bot to check it.

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760
  2022-09-09 14:49   ` Krzysztof Kozlowski
@ 2022-09-09 14:52     ` Guenter Roeck
  2022-09-09 14:56       ` Krzysztof Kozlowski
  0 siblings, 1 reply; 16+ messages in thread
From: Guenter Roeck @ 2022-09-09 14:52 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Ibrahim Tilki, jdelvare
  Cc: linux-hwmon, robh+dt, krzysztof.kozlowski+dt, devicetree, linux-kernel

Hi Krzysztof,

On 9/9/22 07:49, Krzysztof Kozlowski wrote:
> On 09/09/2022 15:37, Ibrahim Tilki wrote:
>> Adding bindings for Analog Devices MAX31760 Fan-Speed Controller
>>
>> Signed-off-by: Ibrahim Tilki <Ibrahim.Tilki@analog.com>
>> ---
> 
> 
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> 
> Please wait with applying for Rob's bot to check it.
> 

I don't think I see those results unless there is a failure.
Is there a link where I can look up the results ?

Thanks,
Guenter

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760
  2022-09-09 14:52     ` Guenter Roeck
@ 2022-09-09 14:56       ` Krzysztof Kozlowski
  2022-09-09 15:04         ` Guenter Roeck
  0 siblings, 1 reply; 16+ messages in thread
From: Krzysztof Kozlowski @ 2022-09-09 14:56 UTC (permalink / raw)
  To: Guenter Roeck, Ibrahim Tilki, jdelvare
  Cc: linux-hwmon, robh+dt, krzysztof.kozlowski+dt, devicetree, linux-kernel

On 09/09/2022 16:52, Guenter Roeck wrote:
> Hi Krzysztof,
> 
> On 9/9/22 07:49, Krzysztof Kozlowski wrote:
>> On 09/09/2022 15:37, Ibrahim Tilki wrote:
>>> Adding bindings for Analog Devices MAX31760 Fan-Speed Controller
>>>
>>> Signed-off-by: Ibrahim Tilki <Ibrahim.Tilki@analog.com>
>>> ---
>>
>>
>> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>>
>> Please wait with applying for Rob's bot to check it.
>>
> 
> I don't think I see those results unless there is a failure.

That's correct.

> Is there a link where I can look up the results ?

It will pop-up on Patchwork:
https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20220909133718.388213-4-Ibrahim.Tilki@analog.com/

Like for example here:
https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20220908184925.2714098-3-sireeshkodali1@gmail.com/


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760
  2022-09-09 14:56       ` Krzysztof Kozlowski
@ 2022-09-09 15:04         ` Guenter Roeck
  2022-09-09 16:42           ` Krzysztof Kozlowski
  0 siblings, 1 reply; 16+ messages in thread
From: Guenter Roeck @ 2022-09-09 15:04 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Ibrahim Tilki, jdelvare
  Cc: linux-hwmon, robh+dt, krzysztof.kozlowski+dt, devicetree, linux-kernel

On 9/9/22 07:56, Krzysztof Kozlowski wrote:
> On 09/09/2022 16:52, Guenter Roeck wrote:
>> Hi Krzysztof,
>>
>> On 9/9/22 07:49, Krzysztof Kozlowski wrote:
>>> On 09/09/2022 15:37, Ibrahim Tilki wrote:
>>>> Adding bindings for Analog Devices MAX31760 Fan-Speed Controller
>>>>
>>>> Signed-off-by: Ibrahim Tilki <Ibrahim.Tilki@analog.com>
>>>> ---
>>>
>>>
>>> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>>>
>>> Please wait with applying for Rob's bot to check it.
>>>
>>
>> I don't think I see those results unless there is a failure.
> 
> That's correct.
> 
>> Is there a link where I can look up the results ?
> 
> It will pop-up on Patchwork:
> https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20220909133718.388213-4-Ibrahim.Tilki@analog.com/
> 
> Like for example here:
> https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20220908184925.2714098-3-sireeshkodali1@gmail.com/
> 
Thanks!

Guenter


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760
  2022-09-09 13:37 ` [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760 Ibrahim Tilki
  2022-09-09 14:49   ` Krzysztof Kozlowski
@ 2022-09-09 16:26   ` Rob Herring
  2022-09-09 16:47     ` Rob Herring
  1 sibling, 1 reply; 16+ messages in thread
From: Rob Herring @ 2022-09-09 16:26 UTC (permalink / raw)
  To: Ibrahim Tilki
  Cc: jdelvare, linux-kernel, krzysztof.kozlowski+dt, linux, robh+dt,
	linux-hwmon, devicetree

On Fri, 09 Sep 2022 16:37:17 +0300, Ibrahim Tilki wrote:
> Adding bindings for Analog Devices MAX31760 Fan-Speed Controller
> 
> Signed-off-by: Ibrahim Tilki <Ibrahim.Tilki@analog.com>
> ---
>  .../bindings/hwmon/adi,max31760.yaml          | 44 +++++++++++++++++++
>  1 file changed, 44 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/hwmon/adi,max31760.yaml
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
./Documentation/devicetree/bindings/hwmon/adi,max31760.yaml: error checking schema file
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/hwmon/adi,max31760.yaml: ignoring, error in schema: properties: reg
Documentation/devicetree/bindings/hwmon/adi,max31760.example.dtb:0:0: /example-0/i2c/fan-controller@50: failed to match any schema with compatible: ['adi,max31760']

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/

This check can fail if there are any dependencies. The base for a patch
series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760
  2022-09-09 15:04         ` Guenter Roeck
@ 2022-09-09 16:42           ` Krzysztof Kozlowski
  0 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2022-09-09 16:42 UTC (permalink / raw)
  To: Guenter Roeck, Ibrahim Tilki, jdelvare
  Cc: linux-hwmon, robh+dt, krzysztof.kozlowski+dt, devicetree, linux-kernel

On 09/09/2022 17:04, Guenter Roeck wrote:
> On 9/9/22 07:56, Krzysztof Kozlowski wrote:
>> On 09/09/2022 16:52, Guenter Roeck wrote:
>>> Hi Krzysztof,
>>>
>>> On 9/9/22 07:49, Krzysztof Kozlowski wrote:
>>>> On 09/09/2022 15:37, Ibrahim Tilki wrote:
>>>>> Adding bindings for Analog Devices MAX31760 Fan-Speed Controller
>>>>>
>>>>> Signed-off-by: Ibrahim Tilki <Ibrahim.Tilki@analog.com>
>>>>> ---
>>>>
>>>>
>>>> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>>>>
>>>> Please wait with applying for Rob's bot to check it.
>>>>
>>>
>>> I don't think I see those results unless there is a failure.
>>
>> That's correct.
>>
>>> Is there a link where I can look up the results ?
>>
>> It will pop-up on Patchwork:
>> https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20220909133718.388213-4-Ibrahim.Tilki@analog.com/

And there is a failure - the bindings were not tested before sending. :(

The error is visible when testing locally, although syntax in general
looks fine.

Un-reviewed.

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760
  2022-09-09 16:26   ` Rob Herring
@ 2022-09-09 16:47     ` Rob Herring
  2022-09-09 16:59       ` Krzysztof Kozlowski
  2022-09-09 17:48       ` Tilki, Ibrahim
  0 siblings, 2 replies; 16+ messages in thread
From: Rob Herring @ 2022-09-09 16:47 UTC (permalink / raw)
  To: Ibrahim Tilki
  Cc: jdelvare, linux-kernel, krzysztof.kozlowski+dt, linux,
	linux-hwmon, devicetree

On Fri, Sep 09, 2022 at 11:26:29AM -0500, Rob Herring wrote:
> On Fri, 09 Sep 2022 16:37:17 +0300, Ibrahim Tilki wrote:
> > Adding bindings for Analog Devices MAX31760 Fan-Speed Controller
> > 
> > Signed-off-by: Ibrahim Tilki <Ibrahim.Tilki@analog.com>
> > ---
> >  .../bindings/hwmon/adi,max31760.yaml          | 44 +++++++++++++++++++
> >  1 file changed, 44 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/hwmon/adi,max31760.yaml
> > 
> 
> My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
> on your patch (DT_CHECKER_FLAGS is new in v5.13):
> 
> yamllint warnings/errors:
> 
> dtschema/dtc warnings/errors:
> ./Documentation/devicetree/bindings/hwmon/adi,max31760.yaml: error checking schema file

Not sure why the error is useless ATM. I'm checking that.

The problem is that 'reg' is a matrix and you need to either fully 
define it or use the simplified form for a single cell:

reg:
  minimum: 0x50
  maximum: 0x57

The full, expanded form is:

reg:
  items:
    - items:
        - minimum: 0x50
          maximum: 0x57

> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/hwmon/adi,max31760.yaml: ignoring, error in schema: properties: reg

> Documentation/devicetree/bindings/hwmon/adi,max31760.example.dtb:0:0: /example-0/i2c/fan-controller@50: failed to match any schema with compatible: ['adi,max31760']

This will go away when the schema passes checks.

Rob

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760
  2022-09-09 16:47     ` Rob Herring
@ 2022-09-09 16:59       ` Krzysztof Kozlowski
  2022-09-09 17:48       ` Tilki, Ibrahim
  1 sibling, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2022-09-09 16:59 UTC (permalink / raw)
  To: Rob Herring, Ibrahim Tilki
  Cc: jdelvare, linux-kernel, krzysztof.kozlowski+dt, linux,
	linux-hwmon, devicetree

On 09/09/2022 18:47, Rob Herring wrote:
> On Fri, Sep 09, 2022 at 11:26:29AM -0500, Rob Herring wrote:
>> On Fri, 09 Sep 2022 16:37:17 +0300, Ibrahim Tilki wrote:
>>> Adding bindings for Analog Devices MAX31760 Fan-Speed Controller
>>>
>>> Signed-off-by: Ibrahim Tilki <Ibrahim.Tilki@analog.com>
>>> ---
>>>  .../bindings/hwmon/adi,max31760.yaml          | 44 +++++++++++++++++++
>>>  1 file changed, 44 insertions(+)
>>>  create mode 100644 Documentation/devicetree/bindings/hwmon/adi,max31760.yaml
>>>
>>
>> My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
>> on your patch (DT_CHECKER_FLAGS is new in v5.13):
>>
>> yamllint warnings/errors:
>>
>> dtschema/dtc warnings/errors:
>> ./Documentation/devicetree/bindings/hwmon/adi,max31760.yaml: error checking schema file
> 
> Not sure why the error is useless ATM. I'm checking that.
> 
> The problem is that 'reg' is a matrix and you need to either fully 
> define it or use the simplified form for a single cell:
> 
> reg:
>   minimum: 0x50
>   maximum: 0x57

I think this was in v7, so I understand that schema in that case expects
the third option from anyOf - #/single?

https://github.com/devicetree-org/dt-schema/blob/main/dtschema/meta-schemas/cell.yaml#L62

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v8 1/4] drivers: hwmon: Add max31760 fan speed controller driver
  2022-09-09 13:37 ` [PATCH v8 1/4] drivers: hwmon: Add max31760 fan speed controller driver Ibrahim Tilki
@ 2022-09-09 17:43   ` Guenter Roeck
  0 siblings, 0 replies; 16+ messages in thread
From: Guenter Roeck @ 2022-09-09 17:43 UTC (permalink / raw)
  To: Ibrahim Tilki, jdelvare
  Cc: linux-hwmon, robh+dt, krzysztof.kozlowski+dt, devicetree,
	linux-kernel, Nurettin Bolucu

On 9/9/22 06:37, Ibrahim Tilki wrote:
> MAX31760 is a precision fan speed controller with nonvolatile lookup table.
> Device has one internal and one external temperature sensor support.
> Controls two fans and measures their speeds. Generates hardware alerts when
> programmable max and critical temperatures are exceeded.
> 
> Signed-off-by: Ibrahim Tilki <Ibrahim.Tilki@analog.com>
> Reviewed-by: Nurettin Bolucu <Nurettin.Bolucu@analog.com>

Since you'll have to resend this anyway to address the devicetree
failures:

[ ... ]

> +
> +static int max31760_write(struct device *dev, enum hwmon_sensor_types type,
> +			  u32 attr, int channel, long val)
> +{
> +	struct max31760_state *state = dev_get_drvdata(dev);
> +	unsigned int pwm_index;
> +	unsigned int reg_temp;
> +	int temp;
> +	u8 reg_val[2];
> +
> +	switch (type) {
> +	case hwmon_temp:
> +		switch (attr) {
> +		case hwmon_temp_max:
> +			reg_temp = REG_TEMP_MAX(channel);
> +			break;
> +		case hwmon_temp_crit:
> +			reg_temp = REG_TEMP_CRIT(channel);
> +			break;
> +		default:
> +			return -EOPNOTSUPP;
> +		}
> +
> +		temp = TEMP11_TO_REG(val);
> +		reg_val[0] = temp >> 8;
> +		reg_val[1] = temp & 0xFF;
> +
> +		return regmap_bulk_write(state->regmap, reg_temp, reg_val, 2);
> +	case hwmon_fan:
> +		switch (attr) {
> +		case hwmon_fan_enable:
> +			if (val == 0)
> +				return regmap_clear_bits(state->regmap, REG_CR3, BIT(channel));
> +
> +			if (val == 1)
> +				return regmap_set_bits(state->regmap, REG_CR3, BIT(channel));
> +
> +			return -EOPNOTSUPP;

This should return -EINVAL.

> +		default:
> +			return -EOPNOTSUPP;
> +		}
> +	case hwmon_pwm:
> +		switch (attr) {
> +		case hwmon_pwm_input:
> +			if (val < 0 || val > 255)
> +				return -EINVAL;
> +
> +			return regmap_write(state->regmap, REG_PWMR, val);
> +		case hwmon_pwm_enable:
> +			if (val == 1)
> +				return regmap_set_bits(state->regmap, REG_CR2, CR2_DFC);
> +
> +			if (val == 2)
> +				return regmap_clear_bits(state->regmap, REG_CR2, CR2_DFC);
> +
> +			return -EOPNOTSUPP;

This should return -EINVAL (the _operation_ is supported, after all,
but the written value is invalid).

Thanks,
Guenter

^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760
  2022-09-09 16:47     ` Rob Herring
  2022-09-09 16:59       ` Krzysztof Kozlowski
@ 2022-09-09 17:48       ` Tilki, Ibrahim
  2022-09-10  8:10         ` Krzysztof Kozlowski
  1 sibling, 1 reply; 16+ messages in thread
From: Tilki, Ibrahim @ 2022-09-09 17:48 UTC (permalink / raw)
  To: Rob Herring
  Cc: jdelvare, linux-kernel, krzysztof.kozlowski+dt, linux,
	linux-hwmon, devicetree

> On Fri, Sep 09, 2022 at 11:26:29AM -0500, Rob Herring wrote:
> > On Fri, 09 Sep 2022 16:37:17 +0300, Ibrahim Tilki wrote:
> > > Adding bindings for Analog Devices MAX31760 Fan-Speed Controller
> > > 
> > > Signed-off-by: Ibrahim Tilki <Ibrahim.Tilki@analog.com>
> > > ---
> > >  .../bindings/hwmon/adi,max31760.yaml          | 44 +++++++++++++++++++
> > >  1 file changed, 44 insertions(+)
> > >  create mode 100644 
> > > Documentation/devicetree/bindings/hwmon/adi,max31760.yaml
> > > 
> > 
> > My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
> > on your patch (DT_CHECKER_FLAGS is new in v5.13):
> > 
> > yamllint warnings/errors:
> > 
> > dtschema/dtc warnings/errors:
> > ./Documentation/devicetree/bindings/hwmon/adi,max31760.yaml: error 
> > checking schema file
> 
> Not sure why the error is useless ATM. I'm checking that.
> 
> The problem is that 'reg' is a matrix and you need to either fully define it or use the simplified form for a single cell:
> 
> reg:
>   minimum: 0x50
>   maximum: 0x57
> 
> The full, expanded form is:
> 
> reg:
>   items:
>     - items:
>         - minimum: 0x50
>           maximum: 0x57
> 

Actually it passes the check when I remove maxItems property:

  reg:
    description: I2C address of slave device.
    items:
      minimum: 0x50
      maximum: 0x57

I cannot find a way to specify both maxItems and min-max limits.
Which one should I drop? Line below is from the output of dt_bindigs_check:

hint: "maxItems" is not needed with an "items" list

Regards,
Ibrahim

> > /builds/robherring/dt-review-ci/linux/Documentation/devicetree/binding
> > s/hwmon/adi,max31760.yaml: ignoring, error in schema: properties: reg
> 
> > Documentation/devicetree/bindings/hwmon/adi,max31760.example.dtb:0:0: 
> > /example-0/i2c/fan-controller@50: failed to match any schema with 
> > compatible: ['adi,max31760']
> 
> This will go away when the schema passes checks.
> 
> Rob

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760
  2022-09-09 17:48       ` Tilki, Ibrahim
@ 2022-09-10  8:10         ` Krzysztof Kozlowski
  0 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2022-09-10  8:10 UTC (permalink / raw)
  To: Tilki, Ibrahim, Rob Herring
  Cc: jdelvare, linux-kernel, krzysztof.kozlowski+dt, linux,
	linux-hwmon, devicetree

On 09/09/2022 19:48, Tilki, Ibrahim wrote:
ded form is:
>>
>> reg:
>>   items:
>>     - items:
>>         - minimum: 0x50
>>           maximum: 0x57
>>
> 
> Actually it passes the check when I remove maxItems property:
> 
>   reg:
>     description: I2C address of slave device.
>     items:
>       minimum: 0x50
>       maximum: 0x57
> 
> I cannot find a way to specify both maxItems and min-max limits.
> Which one should I drop? Line below is from the output of dt_bindigs_check:
> 
> hint: "maxItems" is not needed with an "items" list

Use Rob's first syntax:

reg:
  minimum: 0x50
  maximum: 0x57

(this will expect only one item)


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2022-09-10  8:11 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-09 13:37 [PATCH v8 0/4] hwmon: Add max31760 fan speed controller Ibrahim Tilki
2022-09-09 13:37 ` [PATCH v8 1/4] drivers: hwmon: Add max31760 fan speed controller driver Ibrahim Tilki
2022-09-09 17:43   ` Guenter Roeck
2022-09-09 13:37 ` [PATCH v8 2/4] docs: hwmon: add max31760 documentation Ibrahim Tilki
2022-09-09 13:37 ` [PATCH v8 3/4] dt-bindings: hwmon: Add bindings for max31760 Ibrahim Tilki
2022-09-09 14:49   ` Krzysztof Kozlowski
2022-09-09 14:52     ` Guenter Roeck
2022-09-09 14:56       ` Krzysztof Kozlowski
2022-09-09 15:04         ` Guenter Roeck
2022-09-09 16:42           ` Krzysztof Kozlowski
2022-09-09 16:26   ` Rob Herring
2022-09-09 16:47     ` Rob Herring
2022-09-09 16:59       ` Krzysztof Kozlowski
2022-09-09 17:48       ` Tilki, Ibrahim
2022-09-10  8:10         ` Krzysztof Kozlowski
2022-09-09 13:37 ` [PATCH v8 4/4] MAINTAINERS: Add maintainer for hwmon/max31760 Ibrahim Tilki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).