* [PATCH v4 0/3] hwmon: add initial NXP MC34VR500 PMIC monitoring support @ 2023-01-18 12:30 Mario Kicherer 2023-01-18 12:30 ` [PATCH v4 1/3] dt-bindings: hwmon: add nxp,mc34vr500 Mario Kicherer ` (2 more replies) 0 siblings, 3 replies; 8+ messages in thread From: Mario Kicherer @ 2023-01-18 12:30 UTC (permalink / raw) To: linux-hwmon Cc: jdelvare, linux, robh+dt, krzysztof.kozlowski+dt, corbet, linux-doc, devicetree, Mario Kicherer Add initial monitoring support for the MC34VR500 PMIC. In its current state, input voltage and temperature alarms are reported to hwmon. Changes since v3: - added specific #includes - use INTSENSE0 instead of INTSTAT0 register to query alarm status - abort probe if hwmon_device_register fails - fixed interrupt clear and unmask - added device tree match id - removed client from struct mc34vr500_data - fixed commit messages - fixed filename and node name in dtbinding 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 Mario Kicherer (3): dt-bindings: hwmon: add nxp,mc34vr500 docs: hwmon: add docs for the NXP MC34VR500 PMIC hwmon: add initial NXP MC34VR500 PMIC monitoring support .../bindings/hwmon/nxp,mc34vr500.yaml | 36 +++ Documentation/hwmon/mc34vr500.rst | 30 ++ drivers/hwmon/Kconfig | 7 + drivers/hwmon/Makefile | 1 + drivers/hwmon/mc34vr500.c | 262 ++++++++++++++++++ 5 files changed, 336 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 -- 2.34.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v4 1/3] dt-bindings: hwmon: add nxp,mc34vr500 2023-01-18 12:30 [PATCH v4 0/3] hwmon: add initial NXP MC34VR500 PMIC monitoring support Mario Kicherer @ 2023-01-18 12:30 ` Mario Kicherer 2023-01-19 11:42 ` Krzysztof Kozlowski 2023-01-24 13:56 ` Guenter Roeck 2023-01-18 12:30 ` [PATCH v4 2/3] docs: hwmon: add docs for the NXP MC34VR500 PMIC Mario Kicherer 2023-01-18 12:30 ` [PATCH v4 3/3] hwmon: add initial NXP MC34VR500 PMIC monitoring support Mario Kicherer 2 siblings, 2 replies; 8+ messages in thread From: Mario Kicherer @ 2023-01-18 12:30 UTC (permalink / raw) To: linux-hwmon Cc: jdelvare, linux, robh+dt, krzysztof.kozlowski+dt, corbet, linux-doc, devicetree, Mario Kicherer Add dt-bindings for the NXP MC34VR500 PMIC. Signed-off-by: Mario Kicherer <dev@kicherer.org> --- .../bindings/hwmon/nxp,mc34vr500.yaml | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml diff --git a/Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml b/Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml new file mode 100644 index 000000000000..306f67315835 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml @@ -0,0 +1,36 @@ +# SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/nxp,mc34vr500.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP MC34VR500 hwmon sensor + +maintainers: + - Mario Kicherer <dev@kicherer.org> + +properties: + compatible: + enum: + - nxp,mc34vr500 + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + pmic@8 { + compatible = "nxp,mc34vr500"; + reg = <0x08>; + }; + }; -- 2.34.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v4 1/3] dt-bindings: hwmon: add nxp,mc34vr500 2023-01-18 12:30 ` [PATCH v4 1/3] dt-bindings: hwmon: add nxp,mc34vr500 Mario Kicherer @ 2023-01-19 11:42 ` Krzysztof Kozlowski 2023-01-24 13:56 ` Guenter Roeck 1 sibling, 0 replies; 8+ messages in thread From: Krzysztof Kozlowski @ 2023-01-19 11:42 UTC (permalink / raw) To: Mario Kicherer, linux-hwmon Cc: jdelvare, linux, robh+dt, krzysztof.kozlowski+dt, corbet, linux-doc, devicetree On 18/01/2023 13:30, Mario Kicherer wrote: > Add dt-bindings for the NXP MC34VR500 PMIC. > > Signed-off-by: Mario Kicherer <dev@kicherer.org> > --- > .../bindings/hwmon/nxp,mc34vr500.yaml | 36 +++++++++++++++++++ > 1 file changed, 36 insertions(+) > create mode 100644 Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml > Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Best regards, Krzysztof ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 1/3] dt-bindings: hwmon: add nxp,mc34vr500 2023-01-18 12:30 ` [PATCH v4 1/3] dt-bindings: hwmon: add nxp,mc34vr500 Mario Kicherer 2023-01-19 11:42 ` Krzysztof Kozlowski @ 2023-01-24 13:56 ` Guenter Roeck 1 sibling, 0 replies; 8+ messages in thread From: Guenter Roeck @ 2023-01-24 13:56 UTC (permalink / raw) To: Mario Kicherer Cc: linux-hwmon, jdelvare, robh+dt, krzysztof.kozlowski+dt, corbet, linux-doc, devicetree On Wed, Jan 18, 2023 at 01:30:17PM +0100, Mario Kicherer wrote: > Add dt-bindings for the NXP MC34VR500 PMIC. > > Signed-off-by: Mario Kicherer <dev@kicherer.org> > Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Applied th hwmon-next. Thanks, Guenter > --- > .../bindings/hwmon/nxp,mc34vr500.yaml | 36 +++++++++++++++++++ > 1 file changed, 36 insertions(+) > create mode 100644 Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml > > diff --git a/Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml b/Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml > new file mode 100644 > index 000000000000..306f67315835 > --- /dev/null > +++ b/Documentation/devicetree/bindings/hwmon/nxp,mc34vr500.yaml > @@ -0,0 +1,36 @@ > +# SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause > +%YAML 1.2 > +--- > +$id: http://devicetree.org/schemas/hwmon/nxp,mc34vr500.yaml# > +$schema: http://devicetree.org/meta-schemas/core.yaml# > + > +title: NXP MC34VR500 hwmon sensor > + > +maintainers: > + - Mario Kicherer <dev@kicherer.org> > + > +properties: > + compatible: > + enum: > + - nxp,mc34vr500 > + > + reg: > + maxItems: 1 > + > +required: > + - compatible > + - reg > + > +additionalProperties: false > + > +examples: > + - | > + i2c { > + #address-cells = <1>; > + #size-cells = <0>; > + > + pmic@8 { > + compatible = "nxp,mc34vr500"; > + reg = <0x08>; > + }; > + }; ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v4 2/3] docs: hwmon: add docs for the NXP MC34VR500 PMIC 2023-01-18 12:30 [PATCH v4 0/3] hwmon: add initial NXP MC34VR500 PMIC monitoring support Mario Kicherer 2023-01-18 12:30 ` [PATCH v4 1/3] dt-bindings: hwmon: add nxp,mc34vr500 Mario Kicherer @ 2023-01-18 12:30 ` Mario Kicherer 2023-01-24 13:59 ` Guenter Roeck 2023-01-18 12:30 ` [PATCH v4 3/3] hwmon: add initial NXP MC34VR500 PMIC monitoring support Mario Kicherer 2 siblings, 1 reply; 8+ messages in thread From: Mario Kicherer @ 2023-01-18 12:30 UTC (permalink / raw) To: linux-hwmon Cc: jdelvare, linux, robh+dt, krzysztof.kozlowski+dt, corbet, linux-doc, devicetree, Mario Kicherer [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain; charset=y, Size: 1403 bytes --] Add documentation for the NXP MC34VR500 PMIC. Signed-off-by: Mario Kicherer <dev@kicherer.org> --- Documentation/hwmon/mc34vr500.rst | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Documentation/hwmon/mc34vr500.rst diff --git a/Documentation/hwmon/mc34vr500.rst b/Documentation/hwmon/mc34vr500.rst new file mode 100644 index 000000000000..c9e3b44fb04f --- /dev/null +++ b/Documentation/hwmon/mc34vr500.rst @@ -0,0 +1,30 @@ +Kernel driver mc34vr500 +======================= + +Supported Chips: + + * NXP MC34VR500 + + Prefix: 'mc34vr500' + + Datasheet: https://www.nxp.com/docs/en/data-sheet/MC34VR500.pdf + +Author: Mario Kicherer <dev@kicherer.org> + +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 -> in0_min_alarm +>110°c -> temp1_max_alarm +>120°c -> temp1_crit_alarm +>130°c -> temp1_emergency_alarm -- 2.34.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v4 2/3] docs: hwmon: add docs for the NXP MC34VR500 PMIC 2023-01-18 12:30 ` [PATCH v4 2/3] docs: hwmon: add docs for the NXP MC34VR500 PMIC Mario Kicherer @ 2023-01-24 13:59 ` Guenter Roeck 0 siblings, 0 replies; 8+ messages in thread From: Guenter Roeck @ 2023-01-24 13:59 UTC (permalink / raw) To: Mario Kicherer Cc: linux-hwmon, jdelvare, robh+dt, krzysztof.kozlowski+dt, corbet, linux-doc, devicetree On Wed, Jan 18, 2023 at 01:30:18PM +0100, Mario Kicherer wrote: > Add documentation for the NXP MC34VR500 PMIC. > > Signed-off-by: Mario Kicherer <dev@kicherer.org> Checkpatch notes that the SPDX license identifier is missing. I copied the one from the source (SPDX-License-Identifier: GPL-2.0-or-later). If this is not what you want, please let me know and/or resubmit with the desired license identifier. Thanks, Guenter > --- > Documentation/hwmon/mc34vr500.rst | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > create mode 100644 Documentation/hwmon/mc34vr500.rst > > diff --git a/Documentation/hwmon/mc34vr500.rst b/Documentation/hwmon/mc34vr500.rst > new file mode 100644 > index 000000000000..c9e3b44fb04f > --- /dev/null > +++ b/Documentation/hwmon/mc34vr500.rst > @@ -0,0 +1,30 @@ > +Kernel driver mc34vr500 > +======================= > + > +Supported Chips: > + > + * NXP MC34VR500 > + > + Prefix: 'mc34vr500' > + > + Datasheet: https://www.nxp.com/docs/en/data-sheet/MC34VR500.pdf > + > +Author: Mario Kicherer <dev@kicherer.org> > + > +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 -> in0_min_alarm > +>110°c -> temp1_max_alarm > +>120°c -> temp1_crit_alarm > +>130°c -> temp1_emergency_alarm ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v4 3/3] hwmon: add initial NXP MC34VR500 PMIC monitoring support 2023-01-18 12:30 [PATCH v4 0/3] hwmon: add initial NXP MC34VR500 PMIC monitoring support Mario Kicherer 2023-01-18 12:30 ` [PATCH v4 1/3] dt-bindings: hwmon: add nxp,mc34vr500 Mario Kicherer 2023-01-18 12:30 ` [PATCH v4 2/3] docs: hwmon: add docs for the NXP MC34VR500 PMIC Mario Kicherer @ 2023-01-18 12:30 ` Mario Kicherer 2023-01-24 14:00 ` Guenter Roeck 2 siblings, 1 reply; 8+ messages in thread From: Mario Kicherer @ 2023-01-18 12:30 UTC (permalink / raw) To: linux-hwmon Cc: jdelvare, linux, robh+dt, krzysztof.kozlowski+dt, corbet, linux-doc, devicetree, Mario Kicherer Add initial monitoring support for the MC34VR500 PMIC. In its current state, input voltage and temperature alarms are reported to hwmon. Datasheet: - https://www.nxp.com/docs/en/data-sheet/MC34VR500.pdf Signed-off-by: Mario Kicherer <dev@kicherer.org> --- drivers/hwmon/Kconfig | 7 + drivers/hwmon/Makefile | 1 + drivers/hwmon/mc34vr500.c | 262 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 270 insertions(+) create mode 100644 drivers/hwmon/mc34vr500.c diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 3176c33af6c6..69d4c1609494 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -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 diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index e2e4e87b282f..4bef13d16c66 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -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 diff --git a/drivers/hwmon/mc34vr500.c b/drivers/hwmon/mc34vr500.c new file mode 100644 index 000000000000..b14daa999a2e --- /dev/null +++ b/drivers/hwmon/mc34vr500.c @@ -0,0 +1,262 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * An hwmon driver for the NXP MC34VR500 PMIC + * + * Author: Mario Kicherer <dev@kicherer.org> + */ + +#include <linux/bits.h> +#include <linux/dev_printk.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/errno.h> +#include <linux/hwmon.h> +#include <linux/i2c.h> +#include <linux/interrupt.h> +#include <linux/irqreturn.h> +#include <linux/module.h> +#include <linux/of.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 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, ®); + 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); + + /* write 1 to clear */ + regmap_write(data->regmap, MC34VR500_INTSTAT0, LOWVINS_BIT | + THERM110S_BIT | THERM120S_BIT | THERM130S_BIT); + } + + 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_INTSENSE0, ®); + if (ret < 0) + return ret; + + *val = !!(reg & index); + + 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; + + ret = regmap_read(regmap, MC34VR500_DEVICEID, ®); + 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); + if (IS_ERR(hwmon_dev)) + return PTR_ERR(hwmon_dev); + + 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; + + /* write 1 to clear interrupts */ + ret = regmap_write(regmap, MC34VR500_INTSTAT0, LOWVINS_BIT | + THERM110S_BIT | THERM120S_BIT | + THERM130S_BIT); + if (ret) + return ret; + + /* unmask interrupts */ + ret = regmap_write(regmap, MC34VR500_INTMASK0, + ~(LOWVINS_BIT | THERM110S_BIT | + THERM120S_BIT | THERM130S_BIT)); + if (ret) + return ret; + } + + return 0; +} + +static const struct i2c_device_id mc34vr500_id[] = { + { "mc34vr500", 0 }, +}; + +MODULE_DEVICE_TABLE(i2c, mc34vr500_id); + +static const struct of_device_id __maybe_unused mc34vr500_of_match[] = { + { .compatible = "nxp,mc34vr500" }, +}; +MODULE_DEVICE_TABLE(of, mc34vr500_of_match); + +static struct i2c_driver mc34vr500_driver = { + .driver = { + .name = "mc34vr500", + .of_match_table = of_match_ptr(mc34vr500_of_match), + }, + .probe_new = mc34vr500_probe, + .id_table = mc34vr500_id, +}; + +module_i2c_driver(mc34vr500_driver); + +MODULE_AUTHOR("Mario Kicherer <dev@kicherer.org>"); + +MODULE_DESCRIPTION("MC34VR500 driver"); +MODULE_LICENSE("GPL"); -- 2.34.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v4 3/3] hwmon: add initial NXP MC34VR500 PMIC monitoring support 2023-01-18 12:30 ` [PATCH v4 3/3] hwmon: add initial NXP MC34VR500 PMIC monitoring support Mario Kicherer @ 2023-01-24 14:00 ` Guenter Roeck 0 siblings, 0 replies; 8+ messages in thread From: Guenter Roeck @ 2023-01-24 14:00 UTC (permalink / raw) To: Mario Kicherer Cc: linux-hwmon, jdelvare, robh+dt, krzysztof.kozlowski+dt, corbet, linux-doc, devicetree On Wed, Jan 18, 2023 at 01:30:19PM +0100, Mario Kicherer wrote: > Add initial monitoring support for the MC34VR500 PMIC. In its current > state, input voltage and temperature alarms are reported to hwmon. > > Datasheet: > - https://www.nxp.com/docs/en/data-sheet/MC34VR500.pdf > > Signed-off-by: Mario Kicherer <dev@kicherer.org> Applied to hwmon-next. Thanks, Guenter > --- > drivers/hwmon/Kconfig | 7 + > drivers/hwmon/Makefile | 1 + > drivers/hwmon/mc34vr500.c | 262 ++++++++++++++++++++++++++++++++++++++ > 3 files changed, 270 insertions(+) > create mode 100644 drivers/hwmon/mc34vr500.c > > diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig > index 3176c33af6c6..69d4c1609494 100644 > --- a/drivers/hwmon/Kconfig > +++ b/drivers/hwmon/Kconfig > @@ -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 > diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile > index e2e4e87b282f..4bef13d16c66 100644 > --- a/drivers/hwmon/Makefile > +++ b/drivers/hwmon/Makefile > @@ -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 > diff --git a/drivers/hwmon/mc34vr500.c b/drivers/hwmon/mc34vr500.c > new file mode 100644 > index 000000000000..b14daa999a2e > --- /dev/null > +++ b/drivers/hwmon/mc34vr500.c > @@ -0,0 +1,262 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * An hwmon driver for the NXP MC34VR500 PMIC > + * > + * Author: Mario Kicherer <dev@kicherer.org> > + */ > + > +#include <linux/bits.h> > +#include <linux/dev_printk.h> > +#include <linux/device.h> > +#include <linux/err.h> > +#include <linux/errno.h> > +#include <linux/hwmon.h> > +#include <linux/i2c.h> > +#include <linux/interrupt.h> > +#include <linux/irqreturn.h> > +#include <linux/module.h> > +#include <linux/of.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 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, ®); > + 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); > + > + /* write 1 to clear */ > + regmap_write(data->regmap, MC34VR500_INTSTAT0, LOWVINS_BIT | > + THERM110S_BIT | THERM120S_BIT | THERM130S_BIT); > + } > + > + 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_INTSENSE0, ®); > + if (ret < 0) > + return ret; > + > + *val = !!(reg & index); > + > + 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; > + > + ret = regmap_read(regmap, MC34VR500_DEVICEID, ®); > + 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); > + if (IS_ERR(hwmon_dev)) > + return PTR_ERR(hwmon_dev); > + > + 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; > + > + /* write 1 to clear interrupts */ > + ret = regmap_write(regmap, MC34VR500_INTSTAT0, LOWVINS_BIT | > + THERM110S_BIT | THERM120S_BIT | > + THERM130S_BIT); > + if (ret) > + return ret; > + > + /* unmask interrupts */ > + ret = regmap_write(regmap, MC34VR500_INTMASK0, > + ~(LOWVINS_BIT | THERM110S_BIT | > + THERM120S_BIT | THERM130S_BIT)); > + if (ret) > + return ret; > + } > + > + return 0; > +} > + > +static const struct i2c_device_id mc34vr500_id[] = { > + { "mc34vr500", 0 }, > +}; > + > +MODULE_DEVICE_TABLE(i2c, mc34vr500_id); > + > +static const struct of_device_id __maybe_unused mc34vr500_of_match[] = { > + { .compatible = "nxp,mc34vr500" }, > +}; > +MODULE_DEVICE_TABLE(of, mc34vr500_of_match); > + > +static struct i2c_driver mc34vr500_driver = { > + .driver = { > + .name = "mc34vr500", > + .of_match_table = of_match_ptr(mc34vr500_of_match), > + }, > + .probe_new = mc34vr500_probe, > + .id_table = mc34vr500_id, > +}; > + > +module_i2c_driver(mc34vr500_driver); > + > +MODULE_AUTHOR("Mario Kicherer <dev@kicherer.org>"); > + > +MODULE_DESCRIPTION("MC34VR500 driver"); > +MODULE_LICENSE("GPL"); ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-01-24 14:01 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-01-18 12:30 [PATCH v4 0/3] hwmon: add initial NXP MC34VR500 PMIC monitoring support Mario Kicherer 2023-01-18 12:30 ` [PATCH v4 1/3] dt-bindings: hwmon: add nxp,mc34vr500 Mario Kicherer 2023-01-19 11:42 ` Krzysztof Kozlowski 2023-01-24 13:56 ` Guenter Roeck 2023-01-18 12:30 ` [PATCH v4 2/3] docs: hwmon: add docs for the NXP MC34VR500 PMIC Mario Kicherer 2023-01-24 13:59 ` Guenter Roeck 2023-01-18 12:30 ` [PATCH v4 3/3] hwmon: add initial NXP MC34VR500 PMIC monitoring support Mario Kicherer 2023-01-24 14:00 ` Guenter Roeck
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).