Skip to contentSkip to conversation

add support for MCP998X

PATCH Superseded [email protected] 4 participants 7 messages Sep 30, 2025 – Oct 4, 2025

Subsystems (2)

v6 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v6 cover add support for MCP998X

From: Victor Duicu <[email protected]>

Add support for Microchip MCP998X/33 and MCP998XD/33D Multichannel Automotive Temperature Monitor Family.

The chips in the family have different numbers of external channels, ranging from 1 (MCP9982) to 4 channels (MCP9985). Reading diodes in anti-parallel connection is supported by MCP9984/85/33 and MCP9984D/85D/33D. Dedicated hardware shutdown circuitry is present only in MCP998XD and MCP9933D.

This driver was submitted in the IIO subsystem because the chips could use interrupts to handle threshold events. Each chip supports 3 user programmable limits per channel. The family is also capable of detecting hottest diode and diode faults.
These features will be added in future patches.

Differences related to previous patch:
v6:
- in yaml first condition list part numbers instead of regular expression. Add ^ to regular expression.
- edit coding style and comments.
- use hex values in defines.
- remove MCP9982_TEMP_MEM_BLOCK_LOW and MCP9982_TEMP_MEM_BLOCK_HIGH.
- in MCP9982_CHAN() place macro parameters in ().
- move all variable definitions at the start of functions.
- in mcp9982_parse_fw_config() initialise iio_idx to 0.
- remove bit flags.
- in MCP9982_CHAN remove outer ().
- remove variable start in mcp9982_write_raw().
- replace constant in .max_register.
- use get_unaligned_be16 in mcp9982_read_raw().

v5:
- in yaml edit description of interrupts.
- add min and maxItems to reg.
- remove ideality parameter.
- use pattern recognition in conditionals.
- group conditions based on the chip.
- correct microchip,parasitic-res-on-channel3-4 to true.
- in driver include bitops.h.
- change name of some variables.
- rename mcp9982_parse_of_config() to mcp9982_parse_fw_config().
- implement bulk reading of temp registers.
- lock ideality parameter to default value.
- implement bit flags.
- add compound literal to MCP9982_CHAN.
- remove hysteresis parameter.
- edit comments.
- change values from int to bool in mcp9982_features.
- remove mcp9982_calc_all_3db_values() and hardcode values. When filter is OFF the 3db value is equal to frequency.
- add .max_register to regmap_config.
- remove devm_kcalloc().
- in mcp9982_read_avail() add an else branch to hw_thermal_shutdown check.
- in mcp9982_read_raw use USEC_PER_MSEC and set regmap_read_poll_timeout to never timeout.
Replace switch with bitmap_weight.
- in mcp9982_read_label() remove unnecessary if.
- in mcp9982_write_raw() remove duplicated code.
- in mcp9982_init add error messages when APDD and RECD are incorrectly set.
- in mcp9982_parse_fw_config() add default for reg_nr.

v4:
- lock beta parameters to default value of beta-autodetect. Remove beta parameters and checks from devicetree.
- lock temperature range to extended.
This change avoids the issue of the average filter using raw values with different scales when changing the range.
- change driver to wait an amount of time before reading a raw value to ensure it is valid.
- change driver to stop calculating the physical temp when reading in_tempx_raw. Reading from in_tempx_raw will return the raw value. The physical temp will be calculated with in_tempx_raw, scale and offset parameters.
- add scale parameter to channel definition.
- initialise chips with "D" to work in Run state and those without in Standby state.
- when activating the low pass filter for chips without "D", set the power state to RUN to ensure fresh values for the average.
- add minimum and maximum to microchip,beta1 and microchip,beta2 in yaml.
- rename microchip,resistance-comp-ch1-2-enable and microchip,resistance-comp-ch3-4-enable to microchip,parasitic-res-on-channel1-2
and microchip,parasitic-res-on-channel3-4
and edit description in yaml.
- add conditional logic to check if the chip supports APDD and force default values where necessary in yaml.
- edit comments and coding style.
- replace asm/div64.h with linux/math64.h.
- add delay.h to includes.
- redefine mcp9982_sampl_fr with new structure division.
- in mcp9982_priv remove dev_name,extended_temp_range and beta_values. Add run_state, wait_before_read, time_limit and pointer to chip structure to remove all instances of matching strings. Reorder parameters for memory optimization.
- in mcp9982_features add flags to know if the chip has thermal shutdown circuitry and supports APDD.
- in mcp9982_read_avail() rework verification of chip type in sampling frequency case.
- in mcp9982_read_raw() rework switch in low pass filter case.
- in mcp9982_parse_of_config() replace generic -EINVAL code with -E2BIG and -EOVERFLOW.

v3:
- move beta parameters to devicetree.
- change the name of the interrupts and add
check to match them to the device in yaml.
- remove label for device and remove "0x" from
channel registers in example in yaml.
- edit comments in yaml and driver.
- add minItems to interrupts in yaml.
- rename microchip,recd12 and microchip,recd34 to microchip,resistance-comp-ch1-2-enable
and microchip,resistance-comp-ch3-4-enable.
- rename microchip,apdd-state to microchip,enable-anti-parallel.
- add static to mcp9982_3db_values_map_tbl to fix kernel test robot warning.
- in mcp9982_init() add check to ensure that hardware shutdown feature can't be overridden.
- replace div_u64_rem with do_div and add
asm/div64.h to includes.
- remove unused includes.
- add iio_chan_spec in the macro definition of MCP9982_CHAN.
- remove MCP9982_EXT_BETA_ENBL.
- in mcp9982_init() replace regmap_assign_bits
with regmap_write when setting beta compensation.
- remove custom attribute enable_extended_temp_range and map it to IIO_CHAN_INFO_OFFSET.
- add unsigned to int variables that allow it.
- reorder parameters in mcp9982_priv, change some
from int to bool, add const to labels and add dev_name.
- add check for chips with "D" in the name to not allow sampling frequencies lower than 1 to
prevent overriding of hardware shutdown.
- remove mcp9982_attributes.
- move mcp9982_calc_all_3db_values() to before mcp9982_init().
- use MICRO instead of number constant.
- in mcp9982_write_raw replace ">=" with "==".
- rename index2 to idx in mcp9982_read_raw().
- remove i2c_set_clientdata() in mcp9982_probe().
- since there are no more custom ABI attributes
the testing file was removed.

v2:
- move hysteresis, extended temperature range and beta parameters from devicetree into user space.
- edit comments in yaml and driver.
- remove "|" in descpriptions, remove "+" from PatternProperties in yaml.
- add default to microchip,ideality-factor, delete blank lines and wrap to 80 chars in yaml.
- remove variables with upper case.
- add check for microchip,apdd-state and microchip,recd34 in yaml.
- improve coding style in driver code.
- add includes for all functions used.
- rename MCP9982_INT_HIGH_BYTE_ADDR to MCP9982_INT_VALUE_ADDR and MCP9982_INT_LOW_BYTE_ADDR to MCP9982_FRAC_VALUE_ADDR.
- remove custom attribute running_average_window and running_average_window_available and map them to a low pass filter.
- update sysfs-bus-iio-temperature-mcp9982 to reflect current driver attributes and point to next kernel version (6.17).
- use compound literal to define driver channels.
- replace device_property_read_string() with i2c_get_match_data() to read chip name from devicetree.
- remove MCP9982_DEV_ATTR and mcp9982_prep_custom_attributes().
- remove client, chip_name, iio_info from mcp9982_priv.
- replace sprintf() with sysfs_emit().
- remove error messages which are triggered by keyboard input.
- replace devm_kzalloc() with devm_kcalloc(), array mcp9982_chip_config[] with individual structures, device_property_present() with device_property_read_bool().
- reordered parameters in mcp9982_features and mcp9982_priv to optimize memory allocation.
- remove .endianness from channel properties.
- change name of some parameters in mcp9982_priv.
- add check for reg value 0 from devicetree (channel 0 is for internal temperature and can't be disabled).

v1:
- initial version.

Victor Duicu (2):
dt-bindings: iio: temperature: add support for MCP998X
iio: temperature: add support for MCP998X

 .../iio/temperature/microchip,mcp9982.yaml    | 190 ++++
 MAINTAINERS                                   |   7 +
 drivers/iio/temperature/Kconfig               |  10 +
 drivers/iio/temperature/Makefile              |   1 +
 drivers/iio/temperature/mcp9982.c             | 862 ++++++++++++++++++
 5 files changed, 1070 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml
 create mode 100644 drivers/iio/temperature/mcp9982.c

base-commit: 561285d048053fec8a3d6d1e3ddc60df11c393a0

Signature · 1 line
2.48.1
#1 lore raw

PATCH v6 1/2 dt-bindings: iio: temperature: add support for MCP998X

From: Victor Duicu <[email protected]>

This is the devicetree schema for Microchip MCP998X/33 and MCP998XD/33D Multichannel Automotive Temperature Monitor Family.

---
 .../iio/temperature/microchip,mcp9982.yaml    | 190 ++++++++++++++++++
 MAINTAINERS                                   |   6 +
 2 files changed, 196 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml
Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml new file +190 -0
new file mode 100644
index 000000000000..f0e0564c333f
@@ -0,0 +1,190 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/temperature/microchip,mcp9982.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Microchip MCP998X/33 and MCP998XD/33D Temperature Monitor
+
+maintainers:
+  - Victor Duicu <[email protected]>
+
+description: |
+  The MCP998X/33 and MCP998XD/33D family is a high-accuracy 2-wire
+  multichannel automotive temperature monitor.
+  The datasheet can be found here:
+    https://ww1.microchip.com/downloads/aemDocuments/documents/MSLD/ProductDocuments/DataSheets/MCP998X-Family-Data-Sheet-DS20006827.pdf
+
+properties:
+  compatible:
+    enum:
+      - microchip,mcp9933
+      - microchip,mcp9933d
+      - microchip,mcp9982
+      - microchip,mcp9982d
+      - microchip,mcp9983
+      - microchip,mcp9983d
+      - microchip,mcp9984
+      - microchip,mcp9984d
+      - microchip,mcp9985
+      - microchip,mcp9985d
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    items:
+      - description: Signal coming from ALERT/THERM pin.
+      - description: Signal coming from THERM/ADDR pin.
+      - description: Signal coming from SYS_SHDN pin.
+
+  interrupt-names:
+    items:
+      - const: alert-therm
+      - const: therm-addr
+      - const: sys-shutdown
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+  microchip,enable-anti-parallel:
+    description:
+      Enable anti-parallel diode mode operation.
+      MCP9984/84D/85/85D and MCP9933/33D support reading two external diodes
+      in anti-parallel connection on the same set of pins.
+    type: boolean
+
+  microchip,parasitic-res-on-channel1-2:
+    description:
+      Indicates that the chip and the diodes/transistors are sufficiently far
+      apart that a parasitic resistance is added to the wires, which can affect
+      the measurements. Due to the anti-parallel diode connections, channels
+      1 and 2 are affected together.
+    type: boolean
+
+  microchip,parasitic-res-on-channel3-4:
+    description:
+      Indicates that the chip and the diodes/transistors are sufficiently far
+      apart that a parasitic resistance is added to the wires, which can affect
+      the measurements. Due to the anti-parallel diode connections, channels
+      3 and 4 are affected together.
+    type: boolean
+
+  vdd-supply: true
+
+patternProperties:
+  "^channel@[1-4]$":
+    description:
+      Represents the external temperature channels to which
+      a remote diode is connected.
+    type: object
+
+    properties:
+      reg:
+        items:
+          minItems: 1
+          maxItems: 4
+
+      label:
+        description: Unique name to identify which channel this is.
+
+    required:
+      - reg
+
+    additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - microchip,mcp9982d
+              - microchip,mcp9983d
+              - microchip,mcp9984d
+              - microchip,mcp9985d
+              - microchip,mcp9933d
+    then:
+      properties:
+        interrupts-names:
+          items:
+            - const: alert-therm
+            - const: sys-shutdown
+    else:
+      properties:
+        interrupts-names:
+          items:
+            - const: alert-therm
+            - const: therm-addr
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            pattern: '^microchip,mcp998(2|3)$'
+    then:
+      properties:
+        microchip,enable-anti-parallel: false
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            pattern: '^microchip,mcp998(2|3)d$'
+    then:
+      properties:
+        microchip,enable-anti-parallel: false
+        microchip,parasitic-res-on-channel1-2: true
+        microchip,parasitic-res-on-channel3-4: true
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            pattern: '^microchip,mcp99(33|8[4-5])d$'
+    then:
+      properties:
+        microchip,parasitic-res-on-channel1-2: true
+        microchip,parasitic-res-on-channel3-4: true
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        temperature-sensor@4c {
+            compatible = "microchip,mcp9985";
+            reg = <0x4c>;
+
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            microchip,enable-anti-parallel;
+            microchip,parasitic-res-on-channel1-2;
+            microchip,parasitic-res-on-channel3-4;
+            vdd-supply = <&vdd>;
+
+            channel@1 {
+                reg = <1>;
+                label = "Interior Temperature";
+            };
+
+            channel@2 {
+                reg = <2>;
+                label = "GPU Temperature";
+            };
+        };
+    };
+
+...
MAINTAINERS +6 -0
index f090c2f6e63a..a1981c2f659b 100644
@@ -16662,6 +16662,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/iio/adc/microchip,mcp3911.yaml
 F:	drivers/iio/adc/mcp3911.c
 
+MICROCHIP MCP9982 TEMPERATURE DRIVER
+M:	Victor Duicu <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml
+
 MICROCHIP MMC/SD/SDIO MCI DRIVER
 M:	Aubin Constans <[email protected]>
 S:	Maintained
Signature · 1 line
2.48.1
#2 lore raw

PATCH v6 2/2 iio: temperature: add support for MCP998X

In reply to [email protected]

From: Victor Duicu <[email protected]>

This is the driver for Microchip MCP998X/33 and MCP998XD/33D Multichannel Automotive Temperature Monitor Family.

---
 MAINTAINERS                       |   1 +
 drivers/iio/temperature/Kconfig   |  10 +
 drivers/iio/temperature/Makefile  |   1 +
 drivers/iio/temperature/mcp9982.c | 862 ++++++++++++++++++++++++++++++
 4 files changed, 874 insertions(+)
 create mode 100644 drivers/iio/temperature/mcp9982.c
MAINTAINERS +1 -0
index a1981c2f659b..1fb2aad63800 100644
@@ -16667,6 +16667,7 @@ M:	Victor Duicu <[email protected]>
 L:	[email protected]
 S:	Supported
 F:	Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml
+F:	drivers/iio/temperature/mcp9982.c
 
 MICROCHIP MMC/SD/SDIO MCI DRIVER
 M:	Aubin Constans <[email protected]>
drivers/iio/temperature/Kconfig +10 -0
index 9328b2250ace..d1751db6bf6f 100644
@@ -184,4 +184,14 @@ config MCP9600
 	  This driver can also be built as a module. If so, the module
 	  will be called mcp9600.
 
+config MCP9982
+       tristate "Microchip Technology MCP9982 driver"
+       depends on I2C
+       help
+         Say yes here to build support for Microchip Technology's MCP998X/33
+         and MCP998XD/33D Multichannel Automotive Temperature Monitor Family.
+
+         This driver can also be built as a module. If so, the module
+         will be called mcp9982.
+
 endmenu
drivers/iio/temperature/Makefile +1 -0
index 07d6e65709f7..83f5f4bb4ff3 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_MAX30208) += max30208.o
 obj-$(CONFIG_MAX31856) += max31856.o
 obj-$(CONFIG_MAX31865) += max31865.o
 obj-$(CONFIG_MCP9600) += mcp9600.o
+obj-$(CONFIG_MCP9982) += mcp9982.o
 obj-$(CONFIG_MLX90614) += mlx90614.o
 obj-$(CONFIG_MLX90632) += mlx90632.o
 obj-$(CONFIG_MLX90632) += mlx90635.o
drivers/iio/temperature/mcp9982.c new file +862 -0

862 lines not on this page · raw message

Signature · 1 line
2.48.1
#3 lore raw

Re: [PATCH v6 2/2] iio: temperature: add support for MCP998X

kernel test robot noticed the following build errors:

Hi,

kernel test robot noticed the following build errors:

[auto build test ERROR on 561285d048053fec8a3d6d1e3ddc60df11c393a0]

url:    https://github.com/intel-lab-lkp/linux/commits/victor-duicu-microchip-com/dt-bindings-iio-temperature-add-support-for-MCP998X/20250930-213443
base:   561285d048053fec8a3d6d1e3ddc60df11c393a0
patch link:    https://lore.kernel.org/r/20250930133131.13797-3-victor.duicu%40microchip.com
patch subject: [PATCH v6 2/2] iio: temperature: add support for MCP998X
config: i386-randconfig-013-20251002 (https://download.01.org/0day-ci/archive/20251002/[email protected]/config)
compiler: gcc-12 (Debian 12.4.0-5) 12.4.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251002/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/iio/temperature/mcp9982.c: In function 'mcp9982_read_raw':

>> drivers/iio/temperature/mcp9982.c:467:24: error: implicit declaration of function 'get_unaligned_be16' [-Werror=implicit-function-declaration]
     467 |                 *val = get_unaligned_be16(bulk_read + 1);
         |                        ^~~~~~~~~~~~~~~~~~

cc1: some warnings being treated as errors

vim +/get_unaligned_be16 +467 drivers/iio/temperature/mcp9982.c

416
417 static int mcp9982_read_raw(struct iio_dev *indio_dev,
418 struct iio_chan_spec const *chan, int *val,
419 int *val2, long mask)
420 {
421 unsigned int tmp_reg, reg_status;
422 struct mcp9982_priv *priv = iio_priv(indio_dev);
423 unsigned long *src;
424 int ret;
425 u8 bulk_read[3];
426
427 if (priv->run_state) {
428 /*
429 * When working in Run mode, after modifying a parameter (like sampling
430 * frequency) we have to wait a delay before reading the new values.
431 * We can't determine when the conversion is done based on the BUSY bit.
432 */
433 if (priv->wait_before_read) {
434 if (!time_after(jiffies, priv->time_limit))
435 mdelay(jiffies_to_msecs(priv->time_limit - jiffies));
436 priv->wait_before_read = false;
437 }
438 } else {
439 ret = regmap_write(priv->regmap, MCP9982_ONE_SHOT_ADDR, 1);
440 if (ret)
441 return ret;
442 /*
443 * In Standby state after writing in OneShot register wait for
444 * the start of conversion and then poll the BUSY bit.
445 */
446 mdelay(125);
447 ret = regmap_read_poll_timeout(priv->regmap, MCP9982_STATUS_ADDR,

   448						       reg_status, !(reg_status & MCP9982_STATUS_BUSY),
   449						       mcp9982_delay_ms[priv->sampl_idx] * USEC_PER_MSEC,
   450						       0);
   451			if (ret)
   452				return ret;
   453		}
   454		guard(mutex)(&priv->lock);
   455	
   456		switch (mask) {
   457		case IIO_CHAN_INFO_RAW:
   458			/*
   459			 * The Block Read Protocol first returns the number of user readable
   460			 * bytes, held in bulk_read[0], followed by the data.
   461			 */
   462			ret = regmap_bulk_read(priv->regmap, MCP9982_TEMP_MEM_BLOCK_ADDR(chan->channel),
   463					       &bulk_read, sizeof(bulk_read));
   464			if (ret)
   465				return ret;
   466	
 > 467			*val = get_unaligned_be16(bulk_read + 1);

468
469 return IIO_VAL_INT;
470 case IIO_CHAN_INFO_SCALE:
471 *val = 0;
472 *val2 = MCP9982_SCALE;
473 return IIO_VAL_INT_PLUS_NANO;
474 case IIO_CHAN_INFO_SAMP_FREQ:
475 *val = mcp9982_conv_rate[priv->sampl_idx][0];
476 *val2 = mcp9982_conv_rate[priv->sampl_idx][1];
477 return IIO_VAL_INT_PLUS_MICRO;
478 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
479 ret = regmap_read(priv->regmap, MCP9982_RUNNING_AVG_ADDR, &tmp_reg);
480 if (ret)
481 return ret;
482 *src = tmp_reg;
483 *val = mcp9982_3db_values_map_tbl[priv->sampl_idx][bitmap_weight(src, 2)][0];
484 *val2 = mcp9982_3db_values_map_tbl[priv->sampl_idx][bitmap_weight(src, 2)][1];
485 return IIO_VAL_INT_PLUS_MICRO;
486 case IIO_CHAN_INFO_OFFSET:
487 *val = MCP9982_OFFSET;
488 return IIO_VAL_INT;
489 default:
490 return -EINVAL;
491 }
492 }
493

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#4 lore raw

Re: [PATCH v6 2/2] iio: temperature: add support for MCP998X

In reply to [email protected]
Quoted 6 lines · On Tue, 30 Sep 2025 16:31:31 +0300 <[email protected]> wrote:

From: Victor Duicu <[email protected]>

This is the driver for Microchip MCP998X/33 and MCP998XD/33D Multichannel Automotive Temperature Monitor Family.

Other than the request for a stronger set of reasoning for IIO rather than hwmon this looks good to me.

We have plenty of time given where we are in the cycle to resolve that question.

Thanks,

Jonathan

maintainer
#5 lore raw
In reply to [email protected]
Quoted 5 lines · On Tue, 30 Sep 2025 16:31:29 +0300 <[email protected]> wrote:

From: Victor Duicu <[email protected]>

Add support for Microchip MCP998X/33 and MCP998XD/33D Multichannel Automotive Temperature Monitor Family.

Quoted 8 lines

The chips in the family have different numbers of external channels, ranging from 1 (MCP9982) to 4 channels (MCP9985). Reading diodes in anti-parallel connection is supported by MCP9984/85/33 and MCP9984D/85D/33D. Dedicated hardware shutdown circuitry is present only in MCP998XD and MCP9933D.

This driver was submitted in the IIO subsystem because the chips could use interrupts to handle threshold events.

This reasoning isn't particularly strong as hwmon has support for events etc. This device is also 'slow' so I'm not immediately seeing a strong reason why IIO is the right choice.

After some recent feedback from Guenter I'm keen to get a clearer set of reasoning when I take a temperature monitoring chip into IIO.

Also asking that we +CC Guenter for his input on devices where the decision isn't clear cut.
So +CC Guenter (and Jean as the other hwmon maintainer).

Apologies if I didn't explicitly request Guenter be +CC on earlier versions.

Thanks,

Jonathan

Quoted 188 lines

Each chip supports 3 user.
programmable limits per channel. The family is also capable of detecting hottest diode and diode faults.
These features will be added in future patches.

Differences related to previous patch:
v6:
- in yaml first condition list part numbers instead of regular expression. Add ^ to regular expression.
- edit coding style and comments.
- use hex values in defines.
- remove MCP9982_TEMP_MEM_BLOCK_LOW and MCP9982_TEMP_MEM_BLOCK_HIGH.
- in MCP9982_CHAN() place macro parameters in ().
- move all variable definitions at the start of functions.
- in mcp9982_parse_fw_config() initialise iio_idx to 0.
- remove bit flags.
- in MCP9982_CHAN remove outer ().
- remove variable start in mcp9982_write_raw().
- replace constant in .max_register.
- use get_unaligned_be16 in mcp9982_read_raw().

v5:
- in yaml edit description of interrupts.
- add min and maxItems to reg.
- remove ideality parameter.
- use pattern recognition in conditionals.
- group conditions based on the chip.
- correct microchip,parasitic-res-on-channel3-4 to true.
- in driver include bitops.h.
- change name of some variables.
- rename mcp9982_parse_of_config() to mcp9982_parse_fw_config().
- implement bulk reading of temp registers.
- lock ideality parameter to default value.
- implement bit flags.
- add compound literal to MCP9982_CHAN.
- remove hysteresis parameter.
- edit comments.
- change values from int to bool in mcp9982_features.
- remove mcp9982_calc_all_3db_values() and hardcode values. When filter is OFF the 3db value is equal to frequency.
- add .max_register to regmap_config.
- remove devm_kcalloc().
- in mcp9982_read_avail() add an else branch to hw_thermal_shutdown check.
- in mcp9982_read_raw use USEC_PER_MSEC and set regmap_read_poll_timeout to never timeout.
Replace switch with bitmap_weight.
- in mcp9982_read_label() remove unnecessary if.
- in mcp9982_write_raw() remove duplicated code.
- in mcp9982_init add error messages when APDD and RECD are incorrectly set.
- in mcp9982_parse_fw_config() add default for reg_nr.

v4:
- lock beta parameters to default value of beta-autodetect. Remove beta parameters and checks from devicetree.
- lock temperature range to extended.
This change avoids the issue of the average filter using raw values with different scales when changing the range.
- change driver to wait an amount of time before reading a raw value to ensure it is valid.
- change driver to stop calculating the physical temp when reading in_tempx_raw. Reading from in_tempx_raw will return the raw value. The physical temp will be calculated with in_tempx_raw, scale and offset parameters.
- add scale parameter to channel definition.
- initialise chips with "D" to work in Run state and those without in Standby state.
- when activating the low pass filter for chips without "D", set the power state to RUN to ensure fresh values for the average.
- add minimum and maximum to microchip,beta1 and microchip,beta2 in yaml.
- rename microchip,resistance-comp-ch1-2-enable and microchip,resistance-comp-ch3-4-enable to microchip,parasitic-res-on-channel1-2
and microchip,parasitic-res-on-channel3-4
and edit description in yaml.
- add conditional logic to check if the chip supports APDD and force default values where necessary in yaml.
- edit comments and coding style.
- replace asm/div64.h with linux/math64.h.
- add delay.h to includes.
- redefine mcp9982_sampl_fr with new structure division.
- in mcp9982_priv remove dev_name,extended_temp_range and beta_values. Add run_state, wait_before_read, time_limit and pointer to chip structure to remove all instances of matching strings. Reorder parameters for memory optimization.
- in mcp9982_features add flags to know if the chip has thermal shutdown circuitry and supports APDD.
- in mcp9982_read_avail() rework verification of chip type in sampling frequency case.
- in mcp9982_read_raw() rework switch in low pass filter case.
- in mcp9982_parse_of_config() replace generic -EINVAL code with -E2BIG and -EOVERFLOW.

v3:
- move beta parameters to devicetree.
- change the name of the interrupts and add
check to match them to the device in yaml.
- remove label for device and remove "0x" from
channel registers in example in yaml.
- edit comments in yaml and driver.
- add minItems to interrupts in yaml.
- rename microchip,recd12 and microchip,recd34 to microchip,resistance-comp-ch1-2-enable
and microchip,resistance-comp-ch3-4-enable.
- rename microchip,apdd-state to microchip,enable-anti-parallel.
- add static to mcp9982_3db_values_map_tbl to fix kernel test robot warning.
- in mcp9982_init() add check to ensure that hardware shutdown feature can't be overridden.
- replace div_u64_rem with do_div and add
asm/div64.h to includes.
- remove unused includes.
- add iio_chan_spec in the macro definition of MCP9982_CHAN.
- remove MCP9982_EXT_BETA_ENBL.
- in mcp9982_init() replace regmap_assign_bits
with regmap_write when setting beta compensation.
- remove custom attribute enable_extended_temp_range and map it to IIO_CHAN_INFO_OFFSET.
- add unsigned to int variables that allow it.
- reorder parameters in mcp9982_priv, change some
from int to bool, add const to labels and add dev_name.
- add check for chips with "D" in the name to not allow sampling frequencies lower than 1 to
prevent overriding of hardware shutdown.
- remove mcp9982_attributes.
- move mcp9982_calc_all_3db_values() to before mcp9982_init().
- use MICRO instead of number constant.
- in mcp9982_write_raw replace ">=" with "==".
- rename index2 to idx in mcp9982_read_raw().
- remove i2c_set_clientdata() in mcp9982_probe().
- since there are no more custom ABI attributes
the testing file was removed.

v2:
- move hysteresis, extended temperature range and beta parameters from devicetree into user space.
- edit comments in yaml and driver.
- remove "|" in descpriptions, remove "+" from PatternProperties in yaml.
- add default to microchip,ideality-factor, delete blank lines and wrap to 80 chars in yaml.
- remove variables with upper case.
- add check for microchip,apdd-state and microchip,recd34 in yaml.
- improve coding style in driver code.
- add includes for all functions used.
- rename MCP9982_INT_HIGH_BYTE_ADDR to MCP9982_INT_VALUE_ADDR and MCP9982_INT_LOW_BYTE_ADDR to MCP9982_FRAC_VALUE_ADDR.
- remove custom attribute running_average_window and running_average_window_available and map them to a low pass filter.
- update sysfs-bus-iio-temperature-mcp9982 to reflect current driver attributes and point to next kernel version (6.17).
- use compound literal to define driver channels.
- replace device_property_read_string() with i2c_get_match_data() to read chip name from devicetree.
- remove MCP9982_DEV_ATTR and mcp9982_prep_custom_attributes().
- remove client, chip_name, iio_info from mcp9982_priv.
- replace sprintf() with sysfs_emit().
- remove error messages which are triggered by keyboard input.
- replace devm_kzalloc() with devm_kcalloc(), array mcp9982_chip_config[] with individual structures, device_property_present() with device_property_read_bool().
- reordered parameters in mcp9982_features and mcp9982_priv to optimize memory allocation.
- remove .endianness from channel properties.
- change name of some parameters in mcp9982_priv.
- add check for reg value 0 from devicetree (channel 0 is for internal temperature and can't be disabled).

v1:
- initial version.

Victor Duicu (2):
dt-bindings: iio: temperature: add support for MCP998X
iio: temperature: add support for MCP998X

 .../iio/temperature/microchip,mcp9982.yaml    | 190 ++++
 MAINTAINERS                                   |   7 +
 drivers/iio/temperature/Kconfig               |  10 +
 drivers/iio/temperature/Makefile              |   1 +
 drivers/iio/temperature/mcp9982.c             | 862 ++++++++++++++++++
 5 files changed, 1070 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml
 create mode 100644 drivers/iio/temperature/mcp9982.c

base-commit: 561285d048053fec8a3d6d1e3ddc60df11c393a0

#6 lore raw
Quoted 14 lines · Jonathan Cameron
Quoted 11 lines · On Tue, 30 Sep 2025 16:31:29 +0300 <[email protected]> wrote:

From: Victor Duicu <[email protected]>

Add support for Microchip MCP998X/33 and MCP998XD/33D Multichannel Automotive Temperature Monitor Family.

The chips in the family have different numbers of external channels, ranging from 1 (MCP9982) to 4 channels (MCP9985). Reading diodes in anti-parallel connection is supported by MCP9984/85/33 and MCP9984D/85D/33D. Dedicated hardware shutdown circuitry is present only in MCP998XD and MCP9933D.

Quoted 7 lines
Quoted 2 lines

This driver was submitted in the IIO subsystem because the chips could use interrupts to handle threshold events.

This reasoning isn't particularly strong as hwmon has support for events etc. This device is also 'slow' so I'm not immediately seeing a strong reason why IIO is the right choice.

Correct. hwmon supports both events and udev events.

Quoted 5 lines

After some recent feedback from Guenter I'm keen to get a clearer set of reasoning when I take a temperature monitoring chip into IIO.

Also asking that we +CC Guenter for his input on devices where the decision isn't clear cut.

IMO this _is_ (or should be) clear cut: This is a hardware monitoring device. It should be a hardware monitoring driver. FWIW, writing one should be straightforward (including interrupt/event support).

Guenter