Skip to contentSkip to conversation

add initial NXP MC34VR500 PMIC monitoring support

PATCH Superseded Mario Kicherer 4 participants 10 messages Jan 17, 2023 – Jan 18, 2023

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover add initial NXP MC34VR500 PMIC monitoring support

This patch adds initial monitoring support for the MC34VR500 PMIC. In its current form, input voltage and temperature alarms are reported to hwmon.

Changes since v2:
- split documentation and dt-bindings patch

Changes since v1:
- included required #defines directly in the C file
- removed separate header file
- removed #defines for unimplemented sensors
- removed error log output
- use hwmon_device_register_with_info API
- cleaned probe function
- added documentation for chip and dt bindings

Mario Kicherer (3):
hwmon: add initial NXP MC34VR500 PMIC monitoring support
dt-bindings: hwmon: add nxp,mc34vr500
docs: hwmon: add docs for the NXP MC34VR500 PMIC

 .../bindings/hwmon/nxp,mc34vr500.yaml         |  36 +++
 Documentation/hwmon/mc34vr500.rst             |  32 +++
 drivers/hwmon/Kconfig                         |   7 +
 drivers/hwmon/Makefile                        |   1 +
 drivers/hwmon/mc34vr500.c                     | 245 ++++++++++++++++++
 5 files changed, 321 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml
 create mode 100644 Documentation/hwmon/mc34vr500.rst
 create mode 100644 drivers/hwmon/mc34vr500.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/3 hwmon: add initial NXP MC34VR500 PMIC monitoring support

This patch adds initial monitoring support for the MC34VR500 PMIC. In its current form, input voltage and temperature alarms are reported to hwmon.

Datasheet:
- https://www.nxp.com/docs/en/data-sheet/MC34VR500.pdf

Changes since v1:
- included required #defines directly in the C file
- removed separate header file
- removed #defines for unimplemented sensors
- removed error log output
- use hwmon_device_register_with_info API
- cleaned probe function

---
 drivers/hwmon/Kconfig     |   7 ++
 drivers/hwmon/Makefile    |   1 +
 drivers/hwmon/mc34vr500.c | 245 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 253 insertions(+)
 create mode 100644 drivers/hwmon/mc34vr500.c
drivers/hwmon/Kconfig +7 -0
index 3176c33af6c6..69d4c1609494 100644
@@ -1166,6 +1166,13 @@ config SENSORS_MAX31790
 	  This driver can also be built as a module. If so, the module
 	  will be called max31790.
 
+config SENSORS_MC34VR500
+	tristate "NXP MC34VR500 hardware monitoring driver"
+	depends on I2C
+	help
+	  If you say yes here you get support for the temperature and input
+	  voltage sensors of the NXP MC34VR500.
+
 config SENSORS_MCP3021
 	tristate "Microchip MCP3021 and compatibles"
 	depends on I2C
drivers/hwmon/Makefile +1 -0
index e2e4e87b282f..4bef13d16c66 100644
@@ -149,6 +149,7 @@ obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
 obj-$(CONFIG_SENSORS_MAX6697)	+= max6697.o
 obj-$(CONFIG_SENSORS_MAX31790)	+= max31790.o
 obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
+obj-$(CONFIG_SENSORS_MC34VR500)	+= mc34vr500.o
 obj-$(CONFIG_SENSORS_MCP3021)	+= mcp3021.o
 obj-$(CONFIG_SENSORS_TC654)	+= tc654.o
 obj-$(CONFIG_SENSORS_TPS23861)	+= tps23861.o
drivers/hwmon/mc34vr500.c new file +245 -0

245 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH v3 1/3] hwmon: add initial NXP MC34VR500 PMIC monitoring support

Quoted 58 lines · Mario Kicherer

This patch adds initial monitoring support for the MC34VR500 PMIC. In its current form, input voltage and temperature alarms are reported to hwmon.

Datasheet:
- https://www.nxp.com/docs/en/data-sheet/MC34VR500.pdf

Changes since v1:
- included required #defines directly in the C file
- removed separate header file
- removed #defines for unimplemented sensors
- removed error log output
- use hwmon_device_register_with_info API
- cleaned probe function

---
 drivers/hwmon/Kconfig     |   7 ++
 drivers/hwmon/Makefile    |   1 +
 drivers/hwmon/mc34vr500.c | 245 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 253 insertions(+)
 create mode 100644 drivers/hwmon/mc34vr500.c
drivers/hwmon/Kconfig +7 -0
index 3176c33af6c6..69d4c1609494 100644
@@ -1166,6 +1166,13 @@ config SENSORS_MAX31790
 	  This driver can also be built as a module. If so, the module
 	  will be called max31790.
 
+config SENSORS_MC34VR500
+	tristate "NXP MC34VR500 hardware monitoring driver"
+	depends on I2C
+	help
+	  If you say yes here you get support for the temperature and input
+	  voltage sensors of the NXP MC34VR500.
+
 config SENSORS_MCP3021
 	tristate "Microchip MCP3021 and compatibles"
 	depends on I2C
drivers/hwmon/Makefile +1 -0
index e2e4e87b282f..4bef13d16c66 100644
@@ -149,6 +149,7 @@ obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
 obj-$(CONFIG_SENSORS_MAX6697)	+= max6697.o
 obj-$(CONFIG_SENSORS_MAX31790)	+= max31790.o
 obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
+obj-$(CONFIG_SENSORS_MC34VR500)	+= mc34vr500.o
 obj-$(CONFIG_SENSORS_MCP3021)	+= mcp3021.o
 obj-$(CONFIG_SENSORS_TC654)	+= tc654.o
 obj-$(CONFIG_SENSORS_TPS23861)	+= tps23861.o
drivers/hwmon/mc34vr500.c new file +0 -0
new file mode 100644
index 000000000000..211dc44af42e

drivers/hwmon/mc34vr500.c line 9

Quoted 9 lines
drivers/hwmon/mc34vr500.c new file +9 -0
@@ -0,0 +1,245 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * An hwmon driver for the NXP MC34VR500 PMIC
+ *
+ * Author: Mario Kicherer <[email protected]>
+ */
+
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>

No longer necessary.

drivers/hwmon/mc34vr500.c line 11

Quoted 2 lines
drivers/hwmon/mc34vr500.c new file +2 -0
+#include <linux/i2c.h>
+#include <linux/regmap.h>

You are sparse with include files. The point is not to include as few as possible, but to include everything that declares functions or defines used in the code. I identified some below, but there may be more missing.

drivers/hwmon/mc34vr500.c line 22

Quoted 11 lines
drivers/hwmon/mc34vr500.c new file +11 -0
+
+#define MC34VR500_I2C_ADDR		0x08
+#define MC34VR500_DEVICEID_VALUE	0x14
+
+/* INTSENSE0 */
+#define ENS_BIT		BIT(0)
+#define LOWVINS_BIT	BIT(1)
+#define THERM110S_BIT	BIT(2)
+#define THERM120S_BIT	BIT(3)
+#define THERM125S_BIT	BIT(4)
+#define THERM130S_BIT	BIT(5)

#include <linux/bits.h>

drivers/hwmon/mc34vr500.c line 34

Quoted 12 lines
drivers/hwmon/mc34vr500.c new file +12 -0
+
+#define MC34VR500_DEVICEID	0x00
+
+#define MC34VR500_SILICONREVID	0x03
+#define MC34VR500_FABID		0x04
+#define MC34VR500_INTSTAT0	0x05
+#define MC34VR500_INTMASK0	0x06
+#define MC34VR500_INTSENSE0	0x07
+
+struct mc34vr500_data {
+	struct device *hwmon_dev;
+	struct i2c_client *client;

Unused

drivers/hwmon/mc34vr500.c line 38

Quoted 4 lines
drivers/hwmon/mc34vr500.c new file +4 -0
+	struct regmap *regmap;
+};
+
+static irqreturn_t mc34vr500_process_interrupt(int irq, void *userdata)

#include <linux/irqreturn.h>

Quoted 60 lines
drivers/hwmon/mc34vr500.c new file +60 -0
+{
+	struct mc34vr500_data *data = (struct mc34vr500_data *)userdata;
+	unsigned int reg;
+	int ret;
+
+	ret = regmap_read(data->regmap, MC34VR500_INTSTAT0, &reg);
+	if (ret < 0)
+		return IRQ_HANDLED;
+
+	if (reg) {
+		if (reg & LOWVINS_BIT)
+			hwmon_notify_event(data->hwmon_dev, hwmon_in,
+					   hwmon_in_min_alarm, 0);
+
+		if (reg & THERM110S_BIT)
+			hwmon_notify_event(data->hwmon_dev, hwmon_temp,
+					   hwmon_temp_max_alarm, 0);
+
+		if (reg & THERM120S_BIT)
+			hwmon_notify_event(data->hwmon_dev, hwmon_temp,
+					   hwmon_temp_crit_alarm, 0);
+
+		if (reg & THERM130S_BIT)
+			hwmon_notify_event(data->hwmon_dev, hwmon_temp,
+					   hwmon_temp_emergency_alarm, 0);
+	}
+
+	return IRQ_HANDLED;
+}
+
+static umode_t mc34vr500_is_visible(const void *data,
+				    enum hwmon_sensor_types type,
+				    u32 attr, int channel)
+{
+	switch (attr) {
+	case hwmon_in_min_alarm:
+	case hwmon_temp_max_alarm:
+	case hwmon_temp_crit_alarm:
+	case hwmon_temp_emergency_alarm:
+		return 0444;
+	default:
+		break;
+	}
+
+	return 0;
+}
+
+static int mc34vr500_alarm_read(struct mc34vr500_data *data, int index,
+				long *val)
+{
+	unsigned int reg;
+	int ret;
+
+	ret = regmap_read(data->regmap, MC34VR500_INTSTAT0, &reg);
+	if (ret < 0)
+		return ret;
+
+	*val = !!(reg & index);
+
+	/* write 1 to clear */

drivers/hwmon/mc34vr500.c line 108

Quoted 10 lines
drivers/hwmon/mc34vr500.c new file +10 -0
+	reg = index;
+	regmap_write(data->regmap, MC34VR500_INTSTAT0, reg);
+
+	return 0;
+}
+
+static int mc34vr500_read(struct device *dev, enum hwmon_sensor_types type,
+			  u32 attr, int channel, long *val)
+{
+	struct mc34vr500_data *data = dev_get_drvdata(dev);

#include <linux/device.h>

drivers/hwmon/mc34vr500.c line 116

Quoted 8 lines
drivers/hwmon/mc34vr500.c new file +8 -0
+
+	switch (type) {
+	case hwmon_in:
+		switch (attr) {
+		case hwmon_in_min_alarm:
+			return mc34vr500_alarm_read(data, LOWVINS_BIT, val);
+		default:
+			return -EOPNOTSUPP;

#include <linux/errno.h>

Quoted 66 lines
drivers/hwmon/mc34vr500.c new file +66 -0
+		}
+	case hwmon_temp:
+		switch (attr) {
+		case hwmon_temp_max_alarm:
+			return mc34vr500_alarm_read(data, THERM110S_BIT, val);
+		case hwmon_temp_crit_alarm:
+			return mc34vr500_alarm_read(data, THERM120S_BIT, val);
+		case hwmon_temp_emergency_alarm:
+			return mc34vr500_alarm_read(data, THERM130S_BIT, val);
+		default:
+			return -EOPNOTSUPP;
+		}
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static const struct hwmon_channel_info *mc34vr500_info[] = {
+	HWMON_CHANNEL_INFO(in, HWMON_I_MIN_ALARM),
+	HWMON_CHANNEL_INFO(temp, HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM
+			   | HWMON_T_EMERGENCY_ALARM),
+	NULL,
+};
+
+static const struct hwmon_ops mc34vr500_hwmon_ops = {
+	.is_visible = mc34vr500_is_visible,
+	.read = mc34vr500_read,
+};
+
+static const struct hwmon_chip_info mc34vr500_chip_info = {
+	.ops = &mc34vr500_hwmon_ops,
+	.info = mc34vr500_info,
+};
+
+static const struct regmap_config mc34vr500_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = MC34VR500_INTSENSE0,
+};
+
+static int mc34vr500_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct mc34vr500_data *data;
+	struct device *hwmon_dev;
+	int ret;
+	unsigned int reg, revid, fabid;
+	struct regmap *regmap;
+
+	regmap = devm_regmap_init_i2c(client, &mc34vr500_regmap_config);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	data = devm_kzalloc(dev, sizeof(struct mc34vr500_data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->regmap = regmap;
+	data->client = client;
+
+	ret = regmap_read(regmap, MC34VR500_DEVICEID, &reg);
+	if (ret < 0)
+		return ret;
+
+	if (reg != MC34VR500_DEVICEID_VALUE)
+		return -ENODEV;

drivers/hwmon/mc34vr500.c line 192

Quoted 10 lines
drivers/hwmon/mc34vr500.c new file +10 -0
+
+	ret = regmap_read(regmap, MC34VR500_SILICONREVID, &revid);
+	if (ret < 0)
+		return ret;
+
+	ret = regmap_read(regmap, MC34VR500_FABID, &fabid);
+	if (ret < 0)
+		return ret;
+
+	dev_dbg(dev, "mc34vr500: revid 0x%x fabid 0x%x\n", revid, fabid);

#include <linux/dev_printk.h>

drivers/hwmon/mc34vr500.c line 200

Quoted 8 lines
drivers/hwmon/mc34vr500.c new file +8 -0
+
+	hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
+							 data,
+							 &mc34vr500_chip_info,
+							 NULL);
+	data->hwmon_dev = hwmon_dev;
+
+	if (client->irq) {

This would still request and enable interrupts after registering the hwmon device failed for whatever reason. If an interrupt then occurs before the probe function actually fails, hwmon_notify_event() would be called with a bad hwmon device pointer and crash.

The return value from devm_hwmon_device_register_with_info() needs to be checked before the interrupt is enabled.

drivers/hwmon/mc34vr500.c line 206

Quoted 6 lines
drivers/hwmon/mc34vr500.c new file +6 -0
+		ret = devm_request_threaded_irq(dev, client->irq, NULL,
+						mc34vr500_process_interrupt,
+						IRQF_TRIGGER_RISING |
+						IRQF_ONESHOT |
+						IRQF_SHARED,
+						dev_name(dev), data);

#include <linux/interrupt.h>

drivers/hwmon/mc34vr500.c line 217

Quoted 11 lines
drivers/hwmon/mc34vr500.c new file +11 -0
+		if (ret)
+			return ret;
+
+		/* clear interrupts */
+		ret = regmap_write(regmap, MC34VR500_INTSTAT0, 0);
+		if (ret)
+			return ret;
+
+		/* unmask interrupts */
+		ret = regmap_write(regmap, MC34VR500_INTMASK0,
+				   ~(LOWVINS_BIT | THERM110S_BIT));

Why not enable the other handled thermal event bits ?

drivers/hwmon/mc34vr500.c line 222

Quoted 5 lines
drivers/hwmon/mc34vr500.c new file +5 -0
+		if (ret)
+			return ret;
+	}
+
+	return PTR_ERR_OR_ZERO(hwmon_dev);

Then this can just return 0. Also

#include <linux/err.h>

for both PTR_ERR_OR_ZERO() and PTR_ERR().

drivers/hwmon/mc34vr500.c line 229

Quoted 7 lines
drivers/hwmon/mc34vr500.c new file +7 -0
+}
+
+static const struct i2c_device_id mc34vr500_id[] = {
+	{ "mc34vr500", 0 },
+	{ }
+};
+

Drop this empty line

drivers/hwmon/mc34vr500.c line 230

Quoted 1 line
drivers/hwmon/mc34vr500.c new file +1 -0
+MODULE_DEVICE_TABLE(i2c, mc34vr500_id);

#include <linux/module.h>

drivers/hwmon/mc34vr500.c line 231

Quoted 1 line
drivers/hwmon/mc34vr500.c new file +1 -0
+

What happened with nxp,mc34vr500 ? You'll need the devicetree match to instantiate the device in devicetree systems.

Quoted 17 lines
drivers/hwmon/mc34vr500.c new file +14 -0
+static struct i2c_driver mc34vr500_driver = {
+	.driver = {
+		   .name = "mc34vr500",
+		    },
+	.probe_new = mc34vr500_probe,
+	.id_table = mc34vr500_id,
+};
+
+module_i2c_driver(mc34vr500_driver);
+
+MODULE_AUTHOR("Mario Kicherer <[email protected]>");
+
+MODULE_DESCRIPTION("MC34VR500 driver");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.34.1
maintainer
#3 lore raw

Re: [PATCH v3 1/3] hwmon: add initial NXP MC34VR500 PMIC monitoring support

In reply to Mario Kicherer
Quoted 1 line · Mario Kicherer

This patch adds initial monitoring support for the MC34VR500 PMIC. In its

I forgot:

Documentation/process/submitting-patches.rst

Describe your changes
---------------------
...
Describe your changes in imperative mood, e.g. "make xyzzy do frotz" instead of "[This patch] makes xyzzy do frotz" or "[I] changed xyzzy to do frotz", as if you are giving orders to the codebase to change its behaviour.

Guenter

Quoted 305 lines

current form, input voltage and temperature alarms are reported to hwmon.

Datasheet:
- https://www.nxp.com/docs/en/data-sheet/MC34VR500.pdf

Changes since v1:
- included required #defines directly in the C file
- removed separate header file
- removed #defines for unimplemented sensors
- removed error log output
- use hwmon_device_register_with_info API
- cleaned probe function

---
 drivers/hwmon/Kconfig     |   7 ++
 drivers/hwmon/Makefile    |   1 +
 drivers/hwmon/mc34vr500.c | 245 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 253 insertions(+)
 create mode 100644 drivers/hwmon/mc34vr500.c
drivers/hwmon/Kconfig +7 -0
index 3176c33af6c6..69d4c1609494 100644
@@ -1166,6 +1166,13 @@ config SENSORS_MAX31790
 	  This driver can also be built as a module. If so, the module
 	  will be called max31790.
 
+config SENSORS_MC34VR500
+	tristate "NXP MC34VR500 hardware monitoring driver"
+	depends on I2C
+	help
+	  If you say yes here you get support for the temperature and input
+	  voltage sensors of the NXP MC34VR500.
+
 config SENSORS_MCP3021
 	tristate "Microchip MCP3021 and compatibles"
 	depends on I2C
drivers/hwmon/Makefile +1 -0
index e2e4e87b282f..4bef13d16c66 100644
@@ -149,6 +149,7 @@ obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
 obj-$(CONFIG_SENSORS_MAX6697)	+= max6697.o
 obj-$(CONFIG_SENSORS_MAX31790)	+= max31790.o
 obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
+obj-$(CONFIG_SENSORS_MC34VR500)	+= mc34vr500.o
 obj-$(CONFIG_SENSORS_MCP3021)	+= mcp3021.o
 obj-$(CONFIG_SENSORS_TC654)	+= tc654.o
 obj-$(CONFIG_SENSORS_TPS23861)	+= tps23861.o
drivers/hwmon/mc34vr500.c new file +245 -0
new file mode 100644
index 000000000000..211dc44af42e
@@ -0,0 +1,245 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * An hwmon driver for the NXP MC34VR500 PMIC
+ *
+ * Author: Mario Kicherer <[email protected]>
+ */
+
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+
+#define MC34VR500_I2C_ADDR		0x08
+#define MC34VR500_DEVICEID_VALUE	0x14
+
+/* INTSENSE0 */
+#define ENS_BIT		BIT(0)
+#define LOWVINS_BIT	BIT(1)
+#define THERM110S_BIT	BIT(2)
+#define THERM120S_BIT	BIT(3)
+#define THERM125S_BIT	BIT(4)
+#define THERM130S_BIT	BIT(5)
+
+#define MC34VR500_DEVICEID	0x00
+
+#define MC34VR500_SILICONREVID	0x03
+#define MC34VR500_FABID		0x04
+#define MC34VR500_INTSTAT0	0x05
+#define MC34VR500_INTMASK0	0x06
+#define MC34VR500_INTSENSE0	0x07
+
+struct mc34vr500_data {
+	struct device *hwmon_dev;
+	struct i2c_client *client;
+	struct regmap *regmap;
+};
+
+static irqreturn_t mc34vr500_process_interrupt(int irq, void *userdata)
+{
+	struct mc34vr500_data *data = (struct mc34vr500_data *)userdata;
+	unsigned int reg;
+	int ret;
+
+	ret = regmap_read(data->regmap, MC34VR500_INTSTAT0, &reg);
+	if (ret < 0)
+		return IRQ_HANDLED;
+
+	if (reg) {
+		if (reg & LOWVINS_BIT)
+			hwmon_notify_event(data->hwmon_dev, hwmon_in,
+					   hwmon_in_min_alarm, 0);
+
+		if (reg & THERM110S_BIT)
+			hwmon_notify_event(data->hwmon_dev, hwmon_temp,
+					   hwmon_temp_max_alarm, 0);
+
+		if (reg & THERM120S_BIT)
+			hwmon_notify_event(data->hwmon_dev, hwmon_temp,
+					   hwmon_temp_crit_alarm, 0);
+
+		if (reg & THERM130S_BIT)
+			hwmon_notify_event(data->hwmon_dev, hwmon_temp,
+					   hwmon_temp_emergency_alarm, 0);
+	}
+
+	return IRQ_HANDLED;
+}
+
+static umode_t mc34vr500_is_visible(const void *data,
+				    enum hwmon_sensor_types type,
+				    u32 attr, int channel)
+{
+	switch (attr) {
+	case hwmon_in_min_alarm:
+	case hwmon_temp_max_alarm:
+	case hwmon_temp_crit_alarm:
+	case hwmon_temp_emergency_alarm:
+		return 0444;
+	default:
+		break;
+	}
+
+	return 0;
+}
+
+static int mc34vr500_alarm_read(struct mc34vr500_data *data, int index,
+				long *val)
+{
+	unsigned int reg;
+	int ret;
+
+	ret = regmap_read(data->regmap, MC34VR500_INTSTAT0, &reg);
+	if (ret < 0)
+		return ret;
+
+	*val = !!(reg & index);
+
+	/* write 1 to clear */
+	reg = index;
+	regmap_write(data->regmap, MC34VR500_INTSTAT0, reg);
+
+	return 0;
+}
+
+static int mc34vr500_read(struct device *dev, enum hwmon_sensor_types type,
+			  u32 attr, int channel, long *val)
+{
+	struct mc34vr500_data *data = dev_get_drvdata(dev);
+
+	switch (type) {
+	case hwmon_in:
+		switch (attr) {
+		case hwmon_in_min_alarm:
+			return mc34vr500_alarm_read(data, LOWVINS_BIT, val);
+		default:
+			return -EOPNOTSUPP;
+		}
+	case hwmon_temp:
+		switch (attr) {
+		case hwmon_temp_max_alarm:
+			return mc34vr500_alarm_read(data, THERM110S_BIT, val);
+		case hwmon_temp_crit_alarm:
+			return mc34vr500_alarm_read(data, THERM120S_BIT, val);
+		case hwmon_temp_emergency_alarm:
+			return mc34vr500_alarm_read(data, THERM130S_BIT, val);
+		default:
+			return -EOPNOTSUPP;
+		}
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static const struct hwmon_channel_info *mc34vr500_info[] = {
+	HWMON_CHANNEL_INFO(in, HWMON_I_MIN_ALARM),
+	HWMON_CHANNEL_INFO(temp, HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM
+			   | HWMON_T_EMERGENCY_ALARM),
+	NULL,
+};
+
+static const struct hwmon_ops mc34vr500_hwmon_ops = {
+	.is_visible = mc34vr500_is_visible,
+	.read = mc34vr500_read,
+};
+
+static const struct hwmon_chip_info mc34vr500_chip_info = {
+	.ops = &mc34vr500_hwmon_ops,
+	.info = mc34vr500_info,
+};
+
+static const struct regmap_config mc34vr500_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = MC34VR500_INTSENSE0,
+};
+
+static int mc34vr500_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct mc34vr500_data *data;
+	struct device *hwmon_dev;
+	int ret;
+	unsigned int reg, revid, fabid;
+	struct regmap *regmap;
+
+	regmap = devm_regmap_init_i2c(client, &mc34vr500_regmap_config);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	data = devm_kzalloc(dev, sizeof(struct mc34vr500_data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->regmap = regmap;
+	data->client = client;
+
+	ret = regmap_read(regmap, MC34VR500_DEVICEID, &reg);
+	if (ret < 0)
+		return ret;
+
+	if (reg != MC34VR500_DEVICEID_VALUE)
+		return -ENODEV;
+
+	ret = regmap_read(regmap, MC34VR500_SILICONREVID, &revid);
+	if (ret < 0)
+		return ret;
+
+	ret = regmap_read(regmap, MC34VR500_FABID, &fabid);
+	if (ret < 0)
+		return ret;
+
+	dev_dbg(dev, "mc34vr500: revid 0x%x fabid 0x%x\n", revid, fabid);
+
+	hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
+							 data,
+							 &mc34vr500_chip_info,
+							 NULL);
+	data->hwmon_dev = hwmon_dev;
+
+	if (client->irq) {
+		ret = devm_request_threaded_irq(dev, client->irq, NULL,
+						mc34vr500_process_interrupt,
+						IRQF_TRIGGER_RISING |
+						IRQF_ONESHOT |
+						IRQF_SHARED,
+						dev_name(dev), data);
+		if (ret)
+			return ret;
+
+		/* clear interrupts */
+		ret = regmap_write(regmap, MC34VR500_INTSTAT0, 0);
+		if (ret)
+			return ret;
+
+		/* unmask interrupts */
+		ret = regmap_write(regmap, MC34VR500_INTMASK0,
+				   ~(LOWVINS_BIT | THERM110S_BIT));
+		if (ret)
+			return ret;
+	}
+
+	return PTR_ERR_OR_ZERO(hwmon_dev);
+}
+
+static const struct i2c_device_id mc34vr500_id[] = {
+	{ "mc34vr500", 0 },
+	{ }
+};
+
+MODULE_DEVICE_TABLE(i2c, mc34vr500_id);
+
+static struct i2c_driver mc34vr500_driver = {
+	.driver = {
+		   .name = "mc34vr500",
+		    },
+	.probe_new = mc34vr500_probe,
+	.id_table = mc34vr500_id,
+};
+
+module_i2c_driver(mc34vr500_driver);
+
+MODULE_AUTHOR("Mario Kicherer <[email protected]>");
+
+MODULE_DESCRIPTION("MC34VR500 driver");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.34.1
#4 lore raw

PATCH v3 2/3 dt-bindings: hwmon: add nxp,mc34vr500

In reply to Mario Kicherer

This patch adds dt-bindings for the NXP MC34VR500 PMIC.

---
 .../bindings/hwmon/nxp,mc34vr500.yaml         | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml
Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml new file +36 -0
new file mode 100644
index 000000000000..dfbd6125e84a
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/mc34vr500.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NXP MC34VR500 hwmon sensor
+
+maintainers:
+  - Mario Kicherer <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - nxp,mc34vr500
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      mc34vr500@8 {
+        compatible = "nxp,mc34vr500";
+        reg = <0x08>;
+      };
+    };
Signature · 1 line
2.34.1
maintainer
#5 lore raw

Re: [PATCH v3 2/3] dt-bindings: hwmon: add nxp,mc34vr500

Quoted 1 line · Mario Kicherer

This patch adds dt-bindings for the NXP MC34VR500 PMIC.

As with the other patches, use imperative mood.

Guenter

Quoted 52 lines
---
 .../bindings/hwmon/nxp,mc34vr500.yaml         | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml
Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml new file +36 -0
new file mode 100644
index 000000000000..dfbd6125e84a
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/mc34vr500.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NXP MC34VR500 hwmon sensor
+
+maintainers:
+  - Mario Kicherer <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - nxp,mc34vr500
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      mc34vr500@8 {
+        compatible = "nxp,mc34vr500";
+        reg = <0x08>;
+      };
+    };
Signature · 1 line
2.34.1
maintainer
#6 lore raw

Re: [PATCH v3 2/3] dt-bindings: hwmon: add nxp,mc34vr500

In reply to Mario Kicherer
Quoted 8 lines · Mario Kicherer

This patch adds dt-bindings for the NXP MC34VR500 PMIC.

---
 .../bindings/hwmon/nxp,mc34vr500.yaml         | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.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/nxp,mc34vr500.yaml: $id: relative path/filename doesn't match actual path or filename
expected: http://devicetree.org/schemas/hwmon/nxp,mc34vr500.yaml#

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

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 after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

#7 lore raw

Re: [PATCH v3 2/3] dt-bindings: hwmon: add nxp,mc34vr500

In reply to Mario Kicherer
Quoted 4 lines · Mario Kicherer

This patch adds dt-bindings for the NXP MC34VR500 PMIC.

---

Except being untested one more comment:

Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml line 32

Quoted 7 lines
Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml new file +7 -0
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      mc34vr500@8 {

Node names should be generic.
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

Best regards,
Krzysztof

#8 lore raw

PATCH v3 3/3 docs: hwmon: add docs for the NXP MC34VR500 PMIC

In reply to Mario Kicherer

This patch adds documentation for the NXP MC34VR500 PMIC.

---
 Documentation/hwmon/mc34vr500.rst | 32 +++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 Documentation/hwmon/mc34vr500.rst
Documentation/hwmon/mc34vr500.rst new file +32 -0
new file mode 100644
index 000000000000..5a8e0cbf4dbf
@@ -0,0 +1,32 @@
+Kernel driver mc34vr500
+=======================
+
+Supported Chips:
+
+  * NXP MC34VR500
+
+    Prefix: 'mc34vr500'
+
+    Addresses scanned: I2C 0x08
+
+    Datasheet: https://www.nxp.com/docs/en/data-sheet/MC34VR500.pdf
+
+Author: Mario Kicherer <[email protected]>
+
+Description
+-----------
+
+This driver implements initial support for the NXP MC34VR500 PMIC. The MC34VR500
+monitors the temperature, input voltage and output currents and provides
+corresponding alarms. For the temperature, the chip can send interrupts if
+the temperature rises above one of the following values: 110°, 120°, 125° and
+130° Celsius. For the input voltage, an interrupt is sent when the voltage
+drops below 2.8V.
+
+Currently, this driver only implements the input voltage and temperature
+alarms. The interrupts are mapped as follows:
+
+<= 2.8V  -> in_min_alarm
+>110°c   -> temp_max_alarm
+>120°c   -> temp_crit_alarm
+>130°c   -> temp_emergency_alarm
Signature · 1 line
2.34.1
maintainer
#9 lore raw

Re: [PATCH v3 3/3] docs: hwmon: add docs for the NXP MC34VR500 PMIC

Quoted 1 line · Mario Kicherer

This patch adds documentation for the NXP MC34VR500 PMIC.

"Add documentation".

See Documentation/process/submitting-patches.rst,
"Describe your changes".

Quoted 13 lines
---
 Documentation/hwmon/mc34vr500.rst | 32 +++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 Documentation/hwmon/mc34vr500.rst
Documentation/hwmon/mc34vr500.rst new file +0 -0
new file mode 100644
index 000000000000..5a8e0cbf4dbf

Documentation/hwmon/mc34vr500.rst line 10

Quoted 10 lines
Documentation/hwmon/mc34vr500.rst new file +10 -0
@@ -0,0 +1,32 @@
+Kernel driver mc34vr500
+=======================
+
+Supported Chips:
+
+  * NXP MC34VR500
+
+    Prefix: 'mc34vr500'
+
+    Addresses scanned: I2C 0x08

No, since there is no detect function.

Quoted 9 lines
Documentation/hwmon/mc34vr500.rst new file +9 -0
+
+    Datasheet: https://www.nxp.com/docs/en/data-sheet/MC34VR500.pdf
+
+Author: Mario Kicherer <[email protected]>
+
+Description
+-----------
+
+This driver implements initial support for the NXP MC34VR500 PMIC. The MC34VR500

Documentation/hwmon/mc34vr500.rst line 29

Quoted 10 lines
Documentation/hwmon/mc34vr500.rst new file +10 -0
+monitors the temperature, input voltage and output currents and provides
+corresponding alarms. For the temperature, the chip can send interrupts if
+the temperature rises above one of the following values: 110°, 120°, 125° and
+130° Celsius. For the input voltage, an interrupt is sent when the voltage
+drops below 2.8V.
+
+Currently, this driver only implements the input voltage and temperature
+alarms. The interrupts are mapped as follows:
+
+<= 2.8V  -> in_min_alarm

in0_min_alarm

Documentation/hwmon/mc34vr500.rst line 32

Quoted 3 lines
Documentation/hwmon/mc34vr500.rst new file +3 -0
+>110°c   -> temp_max_alarm
+>120°c   -> temp_crit_alarm
+>130°c   -> temp_emergency_alarm

temp1_xxx

Quoted 3 lines
Signature · 1 line
2.34.1