Skip to contentSkip to conversation

add support for MCP998X

PATCH Superseded [email protected] 6 participants 14 messages Jun 13, 2025 – Jul 29, 2025

Subsystems (2)

v3 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v3 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.

Current version of driver does not support interrupts, events and data buffering.

Differences related to previous patch:
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:
- inital version.

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

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

base-commit: 0c86e33819785fe50616b6ee3fb35c1e4be406d5

Signature · 1 line
2.48.1
#1 lore raw

PATCH v3 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 Automotive Temperature Monitor Family.

---
 .../iio/temperature/microchip,mcp9982.yaml    | 211 ++++++++++++++++++
 1 file changed, 211 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml
Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml new file +211 -0
new file mode 100644
index 000000000000..ec939d463612
@@ -0,0 +1,211 @@
+# 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 Multichannel Automotive
+       Temperature Monitor Family
+
+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:
+    minItems: 2
+    maxItems: 2
+
+  interrupt-names:
+    description:
+      -alert-therm is used to handle a HIGH or LOW limit.
+      -therm-addr is used to handle a THERM limit on chips
+      without "D" in the name.
+      -sys-shutdown is used to handle a THERM limit on chips
+      with "D" in the name.
+    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,beta1:
+    description:
+      Set beta compensation value for external channel 1.
+      <0> 0.050
+      <1> 0.066
+      <2> 0.087
+      <3> 0.114
+      <4> 0.150
+      <5> 0.197
+      <6> 0.260
+      <7> 0.342
+      <8> 0.449
+      <9> 0.591
+      <10> 0.778
+      <11> 1.024
+      <12> 1.348
+      <13> 1.773
+      <14> 2.333
+      <15> Diode_Mode
+      <16> Auto
+      - Diode_Mode is used when measuring a discrete thermal diode
+      or a CPU diode that functions like a discrete thermal diode.
+      - Auto enables beta auto-detection. The chip monitors
+      external diode/transistor and determines the optimum
+      setting.
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 16
+
+  microchip,beta2:
+    description:
+      Set beta compensation value for external channel 2.
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 16
+
+  microchip,resistance-comp-ch1-2-enable:
+    description:
+      Enable resistance error correction(REC) for external channels 1 and 2.
+      The chip internal hardware counterbalances the parasitic resistance in
+      series with the external diodes. The compensation can be activated or
+      disabled in hardware for both channels 1 and 2 at the same time.
+    type: boolean
+
+  microchip,resistance-comp-ch3-4-enable:
+    description:
+      Enable resistance error correction(REC) for external channels 3 and 4.
+      The chip internal hardware counterbalances the parasitic resistance in
+      series with the external diodes. The compensation can be activated or
+      disabled in hardware for both channels 3 and 4 at the same time.
+    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:
+          minimum: 1
+          maximum: 4
+
+      microchip,ideality-factor:
+        description:
+          Each channel has an ideality factor.
+          Beta compensation and resistance error correction automatically
+          correct for most ideality errors. So ideality factor does not need
+          to be adjusted in general.
+        $ref: /schemas/types.yaml#/definitions/uint32
+        default: 18
+
+      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
+
+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,resistance-comp-ch1-2-enable;
+            microchip,resistance-comp-ch3-4-enable;
+            microchip,beta1 = <16>;
+            microchip,beta2 = <16>;
+            vdd-supply = <&vdd>;
+
+            channel@1 {
+                reg = <1>;
+                label = "CPU Temperature";
+            };
+
+            channel@2 {
+                reg = <2>;
+                label = "GPU Temperature";
+            };
+        };
+    };
+
+...
Signature · 1 line
2.48.1
#2 lore raw

Re: [PATCH v3 1/2] dt-bindings: iio: temperature: add support for MCP998X

Quoted 98 lines · On Fri, Jun 13, 2025 at 04:02:06PM +0300, [email protected] wrote:

From: Victor Duicu <[email protected]>

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

---
 .../iio/temperature/microchip,mcp9982.yaml    | 211 ++++++++++++++++++
 1 file changed, 211 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml
Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml new file +81 -0
new file mode 100644
index 000000000000..ec939d463612
@@ -0,0 +1,211 @@
+# 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 Multichannel Automotive
+       Temperature Monitor Family
+
+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:
+    minItems: 2
+    maxItems: 2
+
+  interrupt-names:
+    description:
+      -alert-therm is used to handle a HIGH or LOW limit.
+      -therm-addr is used to handle a THERM limit on chips
+      without "D" in the name.
+      -sys-shutdown is used to handle a THERM limit on chips
+      with "D" in the name.
+    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,beta1:
+    description:
+      Set beta compensation value for external channel 1.
+      <0> 0.050
+      <1> 0.066
+      <2> 0.087
+      <3> 0.114
+      <4> 0.150
+      <5> 0.197
+      <6> 0.260
+      <7> 0.342
+      <8> 0.449
+      <9> 0.591
+      <10> 0.778
+      <11> 1.024
+      <12> 1.348
+      <13> 1.773

Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml line 91

Quoted 10 lines
Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml new file +10 -0
+      <14> 2.333
+      <15> Diode_Mode
+      <16> Auto
+      - Diode_Mode is used when measuring a discrete thermal diode
+      or a CPU diode that functions like a discrete thermal diode.
+      - Auto enables beta auto-detection. The chip monitors
+      external diode/transistor and determines the optimum
+      setting.
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 16

Missing max/min constraints on the property.

Quoted 4 lines
Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml new file +4 -0
+
+  microchip,beta2:
+    description:
+      Set beta compensation value for external channel 2.

Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml line 105

Quoted 10 lines
Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml new file +10 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 16
+
+  microchip,resistance-comp-ch1-2-enable:
+    description:
+      Enable resistance error correction(REC) for external channels 1 and 2.
+      The chip internal hardware counterbalances the parasitic resistance in
+      series with the external diodes. The compensation can be activated or
+      disabled in hardware for both channels 1 and 2 at the same time.
+    type: boolean

On the previous version I objected to this wording for the property, where it is being used as an enable, and instead said that it should indicate the presence of the parasitic resistance. Did I miss some sort of new justification for it still talking about being an enable?

Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml line 113

Quoted 7 lines
Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml new file +7 -0
+  microchip,resistance-comp-ch3-4-enable:
+    description:
+      Enable resistance error correction(REC) for external channels 3 and 4.
+      The chip internal hardware counterbalances the parasitic resistance in
+      series with the external diodes. The compensation can be activated or
+      disabled in hardware for both channels 3 and 4 at the same time.
+    type: boolean

Cheers,
Conor.

#3 lore raw

Re: [PATCH v3 1/2] dt-bindings: iio: temperature: add support for MCP998X

Quoted 4 lines · Conor Dooley
Quoted 2 lines · On Fri, Jun 13, 2025 at 04:02:06PM +0300, [email protected] wrote:

From: Victor Duicu <[email protected]>

Hi Conor,

Quoted 36 lines
Quoted 36 lines

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

---
 .../iio/temperature/microchip,mcp9982.yaml    | 211
++++++++++++++++++

 1 file changed, 211 insertions(+)

 create mode 100644 Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982 .yaml

diff --git a/Documentation/devicetree/bindings/iio/temperature/microchip,mcp99 82.yaml b/Documentation/devicetree/bindings/iio/temperature/microchip,mcp99 82.yaml
new file mode 100644
index 000000000000..ec939d463612
--- /dev/null
+++
b/Documentation/devicetree/bindings/iio/temperature/microchip,mcp99 82.yaml

Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml new file +5 -0
@@ -0,0 +1,211 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
 
+
+  microchip,resistance-comp-ch1-2-enable:
+    description:
+      Enable resistance error correction(REC) for external

channels 1 and 2.
+      The chip internal hardware counterbalances the parasitic resistance in
+      series with the external diodes. The compensation can be activated or
+      disabled in hardware for both channels 1 and 2 at the same

Quoted 9 lines
Quoted 2 lines

time.
+    type: boolean

On the previous version I objected to this wording for the property, where it is being used as an enable, and instead said that it should indicate the presence of the parasitic resistance. Did I miss some sort
of new justification for it still talking about being an enable?

My apologies, I forgot to modify the name of the variable. I will change the variables to something like:

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.

Quoted 13 lines
Quoted 12 lines

+  microchip,resistance-comp-ch3-4-enable:
+    description:
+      Enable resistance error correction(REC) for external channels 3 and 4.
+      The chip internal hardware counterbalances the parasitic resistance in
+      series with the external diodes. The compensation can be activated or
+      disabled in hardware for both channels 3 and 4 at the same time.
+    type: boolean

With Kind Regards,
Victor Duicu

Quoted 2 lines

Cheers,
Conor.

#4 lore raw

Re: [PATCH v3 1/2] dt-bindings: iio: temperature: add support for MCP998X

In reply to [email protected]

Hi everyone,

I am writing this message to ask your opinions regarding the placement of temperature range property from the MCP998X/XD family in the devicetree.

The reason why I am bringing back this topic is due to a limitation of the chips. When the moving average filter is enabled, the old readings are kept and new readings are added to the average. This is a problem when changing the range of temperatures. The raw temperature values change based on the range so the mixed values will give erroneous results during averaging.

One possible workaround for this behavior is to set the temperature range before runtime, to not allow the user to change it.

Initially, in the first patch, I have placed the property microchip,extended-temp-range in the devicetree.
At that point I mistakenly did not include Conor, Krzysztof and Rob in the discussion and I would like to ask for comments.

Below is the discussion between me and Jonathan from patch v1:

Quoted 22 lines
Quoted 13 lines
Quoted 10 lines
Quoted 9 lines
(quoted diff) +4 -1
+
+  microchip,extended-temp-range:
+    description: |
+      Set the chip to work in the extended temperature range
-64

degrees C to 191.875 degrees C.
+ Omit this tag to set the default range 0 degrees C to
127.875 degrees C
+ type: boolean

Quoted 2 lines

I'm curious. Why does this belong in the DT binding?

Quoted 8 lines

Regarding microchip,extended-temp-range, my perspective is that the user knows beforehand which specific range of temperatures he needs.
For example, if the device to be measured is a freezer, the user would
be interested in temperatures below 0 degrees C. If we monitor a CPU,
the user would be interested in temperatures above 0 degrees C.

Quoted 2 lines

Maybe - though also easy to control from userspace by making the offset writeable.

Thank you,
Victor Duicu

Quoted 251 lines · On Fri, 2025-06-13 at 16:02 +0300, [email protected] wrote:

From: Victor Duicu <[email protected]>

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

---
 .../iio/temperature/microchip,mcp9982.yaml    | 211
++++++++++++++++++

 1 file changed, 211 insertions(+)

 create mode 100644 Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.y aml

diff --git a/Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982 .yaml b/Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982 .yaml
new file mode 100644
index 000000000000..ec939d463612
--- /dev/null
+++
b/Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982 .yaml

Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml new file +4 -0
@@ -0,0 +1,211 @@
+# 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#

Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml new file +9 -0
+
+title: Microchip MCP998X/33 and MCP998XD/33D Multichannel Automotive
+       Temperature Monitor Family
+
+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

Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml new file +44 -0
+
+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:
+    minItems: 2
+    maxItems: 2
+
+  interrupt-names:
+    description:
+      -alert-therm is used to handle a HIGH or LOW limit.
+      -therm-addr is used to handle a THERM limit on chips
+      without "D" in the name.
+      -sys-shutdown is used to handle a THERM limit on chips
+      with "D" in the name.
+    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

Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml new file +38 -0
+
+  microchip,beta1:
+    description:
+      Set beta compensation value for external channel 1.
+      <0> 0.050
+      <1> 0.066
+      <2> 0.087
+      <3> 0.114
+      <4> 0.150
+      <5> 0.197
+      <6> 0.260
+      <7> 0.342
+      <8> 0.449
+      <9> 0.591
+      <10> 0.778
+      <11> 1.024
+      <12> 1.348
+      <13> 1.773
+      <14> 2.333
+      <15> Diode_Mode
+      <16> Auto
+      - Diode_Mode is used when measuring a discrete thermal diode
+      or a CPU diode that functions like a discrete thermal diode.
+      - Auto enables beta auto-detection. The chip monitors
+      external diode/transistor and determines the optimum
+      setting.
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 16
+
+  microchip,beta2:
+    description:
+      Set beta compensation value for external channel 2.
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 16
+
+  microchip,resistance-comp-ch1-2-enable:
+    description:
+      Enable resistance error correction(REC) for external channels

1 and 2.
+      The chip internal hardware counterbalances the parasitic resistance in
+      series with the external diodes. The compensation can be activated or
+      disabled in hardware for both channels 1 and 2 at the same time.
+    type: boolean
+
+  microchip,resistance-comp-ch3-4-enable:
+    description:
+      Enable resistance error correction(REC) for external channels 3 and 4.
+      The chip internal hardware counterbalances the parasitic resistance in
+      series with the external diodes. The compensation can be activated or
+      disabled in hardware for both channels 3 and 4 at the same time.
+    type: boolean

Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml new file +21 -0
+
+
+  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:
+          minimum: 1
+          maximum: 4
+
+      microchip,ideality-factor:
+        description:
+          Each channel has an ideality factor.
+          Beta compensation and resistance error correction

automatically
+          correct for most ideality errors. So ideality factor does not need
+          to be adjusted in general.
+        $ref: /schemas/types.yaml#/definitions/uint32
+        default: 18

Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982.yaml new file +73 -0
+
+      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
+
+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,resistance-comp-ch1-2-enable;
+            microchip,resistance-comp-ch3-4-enable;
+            microchip,beta1 = <16>;
+            microchip,beta2 = <16>;
+            vdd-supply = <&vdd>;
+
+            channel@1 {
+                reg = <1>;
+                label = "CPU Temperature";
+            };
+
+            channel@2 {
+                reg = <2>;
+                label = "GPU Temperature";
+            };
+        };
+    };
+
+...
reviewer
#5 lore raw

Re: [PATCH v3 1/2] dt-bindings: iio: temperature: add support for MCP998X

Quoted 13 lines · On 7/28/25 8:01 AM, [email protected] wrote:

Hi everyone,

I am writing this message to ask your opinions regarding the placement of temperature range property from the MCP998X/XD family in the devicetree.

The reason why I am bringing back this topic is due to a limitation of the chips. When the moving average filter is enabled, the old readings are kept and new readings are added to the average. This is a problem when changing the range of temperatures. The raw temperature values change based on the range so the mixed values will give erroneous results during averaging.

Quoted 2 lines

One possible workaround for this behavior is to set the temperature range before runtime, to not allow the user to change it.

It looks like it is just a an average of the last 8 samples at most. So if there isn't a way to reset the chip memory that holds those 8 samples, we could just read 8 samples and throw away the values before giving data to userspace any time we start sampling.

Even without changing the temperature range, we would still have old values and possibly the same issue of stale data possibly influencing the measurements any time we stop sampling and start again. So I'm not seeing that this temperature range setting should be a special case. It still sounds like something better suited to be set at runtime.

Quoted 6 lines

Initially, in the first patch, I have placed the property microchip,extended-temp-range in the devicetree.
At that point I mistakenly did not include Conor, Krzysztof and Rob in the discussion and I would like to ask for comments.

#6 lore raw

PATCH v3 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                       |   7 +
 drivers/iio/temperature/Kconfig   |  10 +
 drivers/iio/temperature/Makefile  |   1 +
 drivers/iio/temperature/mcp9982.c | 778 ++++++++++++++++++++++++++++++
 4 files changed, 796 insertions(+)
 create mode 100644 drivers/iio/temperature/mcp9982.c
MAINTAINERS +7 -0
index 86a2045ba62e..63573c517603 100644
@@ -15887,6 +15887,13 @@ 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
+F:	drivers/iio/temperature/mcp9982.c
+
 MICROCHIP MMC/SD/SDIO MCI DRIVER
 M:	Aubin Constans <[email protected]>
 S:	Maintained
drivers/iio/temperature/Kconfig +10 -0
index 1244d8e17d50..e72b49f95f86 100644
@@ -182,4 +182,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 +778 -0

778 lines not on this page · raw message

Signature · 1 line
2.48.1
#7 lore raw

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

Quoted 5 lines · On Fri, Jun 13, 2025 at 4:02 PM <[email protected]> wrote:

From: Victor Duicu <[email protected]>

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

...

MAINTAINERS S: Maintained · line 15895

Quoted 6 lines
MAINTAINERS +6 -0
+MICROCHIP MCP9982 TEMPERATURE DRIVER
+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

So, with the first patch only the dangling file will be present without record in MAINTAINERS. Please, make sure that your DT schema file is in MAINTAINERS.

Quoted 3 lines
drivers/iio/temperature/Kconfig +3 -0
+config MCP9982
+       tristate "Microchip Technology MCP9982 driver"
+       depends on I2C

...

Quoted 1 line

+#include <asm/div64.h>

This needs to be linux/math64.h instead. The rule of thumb: prefer linux/foo over asm/foo (with some exceptions, that are not the case here).

...

Quoted 1 line

+#define MCP9982_INT_VALUE_ADDR(index) (2 * (index))

Maybe also ' + 0'? But I'm fine with this as well.

Quoted 1 line

+#define MCP9982_FRAC_VALUE_ADDR(index) (2 * (index) + 1)

...

Quoted 1 line

+#define MCP9982_EXT_IDEAL_ADDR(index) ((index) + 54)

What does 54 mean? What is the magic behind?

...

drivers/iio/temperature/mcp9982.c line 74

Quoted 2 lines
drivers/iio/temperature/mcp9982.c new file +2 -0
+#define MCP9982_CHAN(index, si, __address) ({                                          \
+       struct iio_chan_spec __chan = {                                                 \

Why not compound literal?

Quoted 21 lines
drivers/iio/temperature/mcp9982.c new file +21 -0
+               .type = IIO_TEMP,                                                       \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),                           \
+               .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_SAMP_FREQ) |     \
+               BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) |                      \
+               BIT(IIO_CHAN_INFO_OFFSET),                                              \
+               .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) |               \
+               BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) |                      \
+               BIT(IIO_CHAN_INFO_HYSTERESIS) |                                         \
+               BIT(IIO_CHAN_INFO_OFFSET),                                              \
+               .channel = index,                                                       \
+               .address = __address,                                                   \
+               .scan_index = si,                                                       \
+               .scan_type = {                                                          \
+                       .sign = 'u',                                                    \
+                       .realbits = 8,                                                  \
+                       .storagebits = 8,                                               \
+               },                                                                      \
+               .indexed = 1,                                                           \
+       };                                                                              \
+       __chan;                                                                         \
+})

...

Quoted 1 line

+static const unsigned int mcp9982_window_size[3] = {1, 4, 8};

Add surrounding spaces inside {}.

...

Quoted 2 lines

+/*
+ * (Sampling_Frequency * 1000000) / (Window_Size * 2)

This comment needs more elaboration, i.e. units in use for frequency and perhaps window size.

drivers/iio/temperature/mcp9982.c line 209

Quoted 9 lines

+ */

drivers/iio/temperature/mcp9982.c new file +8 -0
+static unsigned int mcp9982_calc_all_3db_values(void)
+{
+       u32 denominator, remainder;
+       unsigned int i, j;
+       u64 numerator;
+
+       for (i = 0; i < ARRAY_SIZE(mcp9982_window_size); i++)
+               for (j = 0; j <  ARRAY_SIZE(mcp9982_sampl_fr); j++) {

Have you considered making mcp9982_sampl_fr to be struct u64_fract? Also using here on stack something like

struct u64_fract tmp;

drivers/iio/temperature/mcp9982.c line 215

Quoted 6 lines
drivers/iio/temperature/mcp9982.c new file +6 -0
+                       numerator = MICRO * mcp9982_sampl_fr[j][0];
+                       denominator = 2 * mcp9982_window_size[i] * mcp9982_sampl_fr[j][1];
+                       remainder = do_div(numerator, denominator);
+                       remainder = do_div(numerator, MICRO);
+                       mcp9982_3db_values_map_tbl[j][i][0] = numerator;
+                       mcp9982_3db_values_map_tbl[j][i][1] = remainder;

The proposed changes will clarify the meaning of [0] and [1] in such a table.

Quoted 3 lines
drivers/iio/temperature/mcp9982.c new file +3 -0
+               }
+       return 0;
+}

...

Quoted 9 lines
drivers/iio/temperature/mcp9982.c new file +9 -0
+struct mcp9982_priv {
+       struct regmap *regmap;
+       u8 num_channels;
+       bool extended_temp_range;
+       bool recd34_enable;
+       bool recd12_enable;
+       unsigned int beta_values[2];
+       /*
+        * Synchronize access to private members, and ensure

drivers/iio/temperature/mcp9982.c line 315

Quoted 10 lines
drivers/iio/temperature/mcp9982.c new file +9 -0
+        * atomicity of consecutive regmap operations.
+        */
+       struct mutex lock;
+       struct iio_chan_spec *iio_chan;
+       const char *labels[MCP9982_MAX_NUM_CHANNELS];
+       unsigned int ideality_value[4];
+       unsigned int sampl_idx;
+       const char *dev_name;
 
+       bool apdd_enable;

Wouldn't it be slightly better to group all booleans (and move u8 here)?

Quoted 1 line

+};

...

drivers/iio/temperature/mcp9982.c line 333

Quoted 7 lines
drivers/iio/temperature/mcp9982.c new file +7 -0
+               if (strchr(priv->dev_name, 'd')) {
+                       *vals = mcp9982_conv_rate[4];
+                       *length = (ARRAY_SIZE(mcp9982_conv_rate) - 4) * 2;
+               } else {
+                       *vals = mcp9982_conv_rate[0];
+                       *length = ARRAY_SIZE(mcp9982_conv_rate) * 2;
+               }

So, the length can be multiplied only once here...

...

drivers/iio/temperature/mcp9982.c line 385

Quoted 7 lines
drivers/iio/temperature/mcp9982.c new file +6 -0
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               *val = mcp9982_conv_rate[priv->sampl_idx][0];
+               *val2 = mcp9982_conv_rate[priv->sampl_idx][1];
+               return IIO_VAL_INT_PLUS_MICRO;
+       case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
 
+

Why this blank line?

Quoted 5 lines
drivers/iio/temperature/mcp9982.c new file +5 -0
+               ret = regmap_read(priv->regmap, MCP9982_RUNNING_AVG_ADDR, &tmp_reg);
+               if (ret)
+                       return ret;
+               /*
+                * In Filter Selection Register values 1 and 2

drivers/iio/temperature/mcp9982.c line 400

Quoted 10 lines
drivers/iio/temperature/mcp9982.c new file +10 -0
+                * are mapped to the same setting.
+                */
+               switch (tmp_reg) {
+               case 0:
+                       idx = 0;
+                       break;
+               case 1:
+               case 2:
+                       idx = 1;
+                       break;

Instead of comment this can be regrouped like

case 0:
case 1:
idx = tmp_reg;
break;
case 2:
idx = 1;
break;
default:
...

Quoted 8 lines
drivers/iio/temperature/mcp9982.c new file +8 -0
+               default:
+                       idx = 2;
+                       break;
+               }
+
+               *val = mcp9982_3db_values_map_tbl[priv->sampl_idx][idx][0];
+               *val2 = mcp9982_3db_values_map_tbl[priv->sampl_idx][idx][1];
+               return IIO_VAL_INT_PLUS_MICRO;

...

Quoted 7 lines
drivers/iio/temperature/mcp9982.c new file +7 -0
+static int mcp9982_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
+                            int val, int val2, long mask)
+{
+       struct mcp9982_priv *priv = iio_priv(indio_dev);
+       int ret;
+       unsigned int i;
+       unsigned int start = 0;

drivers/iio/temperature/mcp9982.c line 470

Quoted 10 lines
drivers/iio/temperature/mcp9982.c new file +9 -0
+
+       guard(mutex)(&priv->lock);
+       switch (mask) {
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               /*
+                * For MCP998XD and MCP9933D sampling frequency can't
+                * be set lower than 1.
+                */
 
+               if (strchr(priv->dev_name, 'd'))

Why not simply have this in an additional field of chip_info structure?

Quoted 25 lines
drivers/iio/temperature/mcp9982.c new file +25 -0
+                       start = 4;
+               for (i = start; i < ARRAY_SIZE(mcp9982_conv_rate); i++)
+                       if (val == mcp9982_conv_rate[i][0] && val2 == mcp9982_conv_rate[i][1])
+                               break;
+
+               if (i == ARRAY_SIZE(mcp9982_conv_rate))
+                       return -EINVAL;
+
+               ret = regmap_write(priv->regmap, MCP9982_CONV_ADDR, i);
+               if (ret)
+                       return ret;
+
+               priv->sampl_idx = i;
+               return 0;
+       case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
+               for (i = 0; i < ARRAY_SIZE(mcp9982_3db_values_map_tbl[priv->sampl_idx]); i++)
+                       if (val == mcp9982_3db_values_map_tbl[priv->sampl_idx][i][0] &&
+                           val2 == mcp9982_3db_values_map_tbl[priv->sampl_idx][i][1])
+                               break;
+
+               if (i == ARRAY_SIZE(mcp9982_3db_values_map_tbl[priv->sampl_idx]))
+                       return -EINVAL;
+
+               /*
+                * In mcp9982_3db_values_map_tbl the second index maps:

drivers/iio/temperature/mcp9982.c line 504

Quoted 10 lines
drivers/iio/temperature/mcp9982.c new file +9 -0
+                * 0 for filter off
+                * 1 for filter at level 1
+                * 2 for filter at level 2
+                */
+               if (i == 2)
+                       i = 3;
 
+               ret = regmap_write(priv->regmap, MCP9982_RUNNING_AVG_ADDR, i);
+
+               return ret;

Why not

  return regmap_write(...);

?

drivers/iio/temperature/mcp9982.c line 510

Quoted 6 lines
drivers/iio/temperature/mcp9982.c new file +6 -0
+       case IIO_CHAN_INFO_HYSTERESIS:
+               if (val < 0 || val > 255)
+                       return -EINVAL;
+
+               ret = regmap_write(priv->regmap, MCP9982_HYS_ADDR, val);
+               return ret;

Ditto.

drivers/iio/temperature/mcp9982.c line 517

Quoted 8 lines
drivers/iio/temperature/mcp9982.c new file +7 -0
+       case IIO_CHAN_INFO_OFFSET:
+               if (val != 0 && val != -64)
+                       return -EINVAL;
+               priv->extended_temp_range = !(val == 0);
 
+               ret = regmap_assign_bits(priv->regmap, MCP9982_CFG_ADDR, MCP9982_CFG_RANGE,
+                                        priv->extended_temp_range);
+               return ret;

Ditto.

Quoted 4 lines
drivers/iio/temperature/mcp9982.c new file +4 -0
+       default:
+               return -EINVAL;
+       }
+}

...

Quoted 8 lines
drivers/iio/temperature/mcp9982.c new file +8 -0
+static int mcp9982_init(struct mcp9982_priv *priv)
+{
+       int ret;
+       unsigned int i;
+       u8 val;
+
+       /*
+        * For chips with "D" in the name

drivers/iio/temperature/mcp9982.c line 547

Quoted 10 lines
drivers/iio/temperature/mcp9982.c new file +9 -0
+        * set the below parameters to default to
+        * ensure that hardware shutdown feature
+        * can't be overridden.
+        */
+       if (strchr(priv->dev_name, 'd')) {
+               priv->recd12_enable = true;
+               priv->recd34_enable = true;
 
+               for (i = 0; i < 2; i++)
+                       priv->beta_values[i] = 16;

memset32() ?

drivers/iio/temperature/mcp9982.c line 549

Quoted 2 lines
drivers/iio/temperature/mcp9982.c new file +2 -0
+               for (i = 0; i < 4; i++)
+                       priv->ideality_value[i] = 18;

Ditto.

Quoted 31 lines
drivers/iio/temperature/mcp9982.c new file +31 -0
+       }
+
+       /*
+        * Set default values in registers.
+        * APDD, RECD12 and RECD34 are active on 0.
+        */
+       val = FIELD_PREP(MCP9982_CFG_MSKAL, 1) | FIELD_PREP(MCP9982_CFG_RS, 1) |
+             FIELD_PREP(MCP9982_CFG_ATTHM, 1) |
+             FIELD_PREP(MCP9982_CFG_RECD12, !priv->recd12_enable) |
+             FIELD_PREP(MCP9982_CFG_RECD34, !priv->recd34_enable) |
+             FIELD_PREP(MCP9982_CFG_RANGE, 0) | FIELD_PREP(MCP9982_CFG_DA_ENA, 0) |
+             FIELD_PREP(MCP9982_CFG_APDD, !priv->apdd_enable);
+
+       ret = regmap_write(priv->regmap, MCP9982_CFG_ADDR, val);
+       if (ret)
+               return ret;
+       priv->extended_temp_range = false;
+
+       ret = regmap_write(priv->regmap, MCP9982_CONV_ADDR, 6);
+       if (ret)
+               return ret;
+       priv->sampl_idx = 6;
+
+       ret = regmap_write(priv->regmap, MCP9982_HYS_ADDR, 10);
+       if (ret)
+               return ret;
+
+       ret = regmap_write(priv->regmap, MCP9982_CONSEC_ALRT_ADDR, 112);
+       if (ret)
+               return ret;
+

drivers/iio/temperature/mcp9982.c line 590

Quoted 10 lines
drivers/iio/temperature/mcp9982.c new file +10 -0
+       ret = regmap_write(priv->regmap, MCP9982_RUNNING_AVG_ADDR, 0);
+       if (ret)
+               return ret;
+
+       ret = regmap_write(priv->regmap, MCP9982_HOTTEST_CFG_ADDR, 0);
+       if (ret)
+               return ret;
+
+       /* Set beta compensation for channels 1 and 2 */
+       for (i = 0; i < 2; i++) {

ARRAY_SIZE()

drivers/iio/temperature/mcp9982.c line 597

Quoted 7 lines
drivers/iio/temperature/mcp9982.c new file +7 -0
+               ret = regmap_write(priv->regmap, MCP9982_EXT_BETA_CFG_ADDR(i),
+                                  priv->beta_values[i]);
+               if (ret)
+                       return ret;
+       }
+       /* Set ideality factor for all external channels */
+       for (i = 0; i < 4; i++) {

Ditto.

Quoted 8 lines
drivers/iio/temperature/mcp9982.c new file +8 -0
+               ret = regmap_write(priv->regmap, MCP9982_EXT_IDEAL_ADDR(i),
+                                  priv->ideality_value[i]);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}

...

drivers/iio/temperature/mcp9982.c line 622

Quoted 2 lines
drivers/iio/temperature/mcp9982.c new file +2 -0
+       priv->beta_values[0] = 16;
+       priv->beta_values[1] = 16;

memset32() ?

Quoted 4 lines
drivers/iio/temperature/mcp9982.c new file +4 -0
+       device_property_read_u32(dev, "microchip,beta1", &priv->beta_values[0]);
+       device_property_read_u32(dev, "microchip,beta2", &priv->beta_values[1]);
+       if (priv->beta_values[0] > 16 || priv->beta_values[1] > 16)
+               return -EINVAL;

...

drivers/iio/temperature/mcp9982.c line 631

Quoted 2 lines
drivers/iio/temperature/mcp9982.c new file +2 -0
+       if (priv->num_channels > device_nr_channels)
+               return dev_err_probe(dev, -EINVAL, "More channels than the chip supports\n");

Hmm... Perhaps -E2BIG?

...

Quoted 4 lines
drivers/iio/temperature/mcp9982.c new file +4 -0
+       priv->labels[0] = "internal diode";
+       iio_idx++;
+       device_for_each_child_node_scoped(dev, child) {
+               fwnode_property_read_u32(child, "reg", &reg_nr);

drivers/iio/temperature/mcp9982.c line 652

Quoted 10 lines
drivers/iio/temperature/mcp9982.c new file +10 -0
+               if (!reg_nr || reg_nr >= device_nr_channels)
+                       return dev_err_probe(dev, -EINVAL,
+                                    "The index of the channels does not match the chip\n");
+
+               priv->ideality_value[reg_nr - 1] = 18;
+               if (fwnode_property_present(child, "microchip,ideality-factor")) {
+                       fwnode_property_read_u32(child, "microchip,ideality-factor",
+                                                &priv->ideality_value[reg_nr - 1]);
+                       if (priv->ideality_value[reg_nr - 1] > 63)
+                               return dev_err_probe(dev, -EINVAL,

-EOVERFLOW?

Quoted 9 lines
drivers/iio/temperature/mcp9982.c new file +9 -0
+                                    "The ideality value is higher than maximum\n");
+               }
+
+               fwnode_property_read_string(child, "label",
+                                           &priv->labels[reg_nr]);
+
+               priv->iio_chan[iio_idx++] = MCP9982_CHAN(reg_nr, reg_nr,
+                                                        MCP9982_INT_VALUE_ADDR(reg_nr));
+       }
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw

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

Quoted 11 lines · Andy Shevchenko

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 5 lines · On Fri, Jun 13, 2025 at 4:02 PM <[email protected]> wrote:

From: Victor Duicu <[email protected]>

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

...

Hi Andy,

Quoted 14 lines
Quoted 9 lines
MAINTAINERS +5 -0
+MICROCHIP MCP9982 TEMPERATURE DRIVER
+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

So, with the first patch only the dangling file will be present without record in MAINTAINERS. Please, make sure that your DT schema file is in MAINTAINERS.

Are you referring here to the file sysfs-bus-iio-temperature-mcp9982? This file was in v2 where there were a few custom attributes. In v3 I removed them, so the driver currently doesn't have custom attributes. Should I had added it to the files in MAINTAINERS?

Isn't the yaml file sufficient to describe the devicetree? Should I also add a dts file?
...

Quoted 9 lines
Quoted 6 lines

+#define MCP9982_CHAN(index, si, __address) ({                                          \
+       struct iio_chan_spec __chan =
{                                                 \

Why not compound literal?

In v2 I used compound literal, but Jonathan suggested to add the struct in the macro. After describing the reasoning, we agreed to code it like this.

[1]:https://lore.kernel.org/linux-iio/20250607182813.64230171@jic23-huawei/

Quoted 38 lines
Quoted 38 lines

+               .type =
IIO_TEMP,                                                       \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),                           \
+               .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_SAMP_FREQ) |     \
+               BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) |                      \
+
BIT(IIO_CHAN_INFO_OFFSET),
     \
+               .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) |               \
+               BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) |                      \
+               BIT(IIO_CHAN_INFO_HYSTERESIS)
|                                         \
+
BIT(IIO_CHAN_INFO_OFFSET),
     \
+               .channel =
index,                                                       \
+               .address =
__address,                                                   \
+               .scan_index =
si,                                                       \
+               .scan_type =
{                                                          \
+                       .sign =
'u',                                                    \
+                       .realbits =
8,                                                  \
+                       .storagebits =
8,                                               \
+
},
     \
+               .indexed =

Quoted 10 lines
Quoted 8 lines

1,                                                           \
+
};
             \
+
__chan;
             \
+})

With Best Regards,
Victor Duicu

Quoted 3 lines

--
With Best Regards,
Andy Shevchenko

#9 lore raw

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

Quoted 2 lines · On Thu, Jun 19, 2025 at 10:22 AM <[email protected]> wrote:
Quoted 1 line · Andy Shevchenko

On Fri, Jun 13, 2025 at 4:02 PM <[email protected]> wrote:

...

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
MAINTAINERS +4 -0
+MICROCHIP MCP9982 TEMPERATURE DRIVER
+M:     Victor Duicu <[email protected]>
+L:     [email protected]
+S:     Supported
Quoted 8 lines
Quoted 4 lines

+F:
Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982 .yaml
+F: drivers/iio/temperature/mcp9982.c

So, with the first patch only the dangling file will be present without record in MAINTAINERS. Please, make sure that your DT schema file is in MAINTAINERS.

Quoted 4 lines

Are you referring here to the file sysfs-bus-iio-temperature-mcp9982? This file was in v2 where there were a few custom attributes. In v3 I removed them, so the driver currently doesn't have custom attributes. Should I had added it to the files in MAINTAINERS?

You should have added the file to the MAINTAINERS in the same patch it appears. Not in some arbitrary change afterwards.

Quoted 2 lines

Isn't the yaml file sufficient to describe the devicetree? Should I also add a dts file?

No, this is not the point.

...

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

+#define MCP9982_CHAN(index, si, __address)
({ \
+ struct iio_chan_spec __chan =
{ \

Why not compound literal?

In v2 I used compound literal, but Jonathan suggested to add the struct in the macro. After describing the reasoning, we agreed to code it like this.

Neither of the versions has a compound literal.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
};
             \
+
__chan;
             \

+})

https://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#10 lore raw

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

Quoted 19 lines · On Thu, 19 Jun 2025 11:29:30 +0300 Andy Shevchenko <[email protected]>…
Quoted 2 lines · On Thu, Jun 19, 2025 at 10:22 AM <[email protected]> wrote:
Quoted 1 line · Andy Shevchenko

On Fri, Jun 13, 2025 at 4:02 PM <[email protected]> wrote:

...

Quoted 13 lines
Quoted 12 lines
Quoted 8 lines
MAINTAINERS +5 -0
+MICROCHIP MCP9982 TEMPERATURE DRIVER
+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

So, with the first patch only the dangling file will be present without record in MAINTAINERS. Please, make sure that your DT schema file is in MAINTAINERS.

Quoted 8 lines
Quoted 4 lines

Are you referring here to the file sysfs-bus-iio-temperature-mcp9982? This file was in v2 where there were a few custom attributes. In v3 I removed them, so the driver currently doesn't have custom attributes. Should I had added it to the files in MAINTAINERS?

You should have added the file to the MAINTAINERS in the same patch it appears. Not in some arbitrary change afterwards.

Perhaps the confusion here is that Andy is talking about 2 lines above, not the immediate line above this feedback. So the one with the dt-binding file. If Victor was reading it as being about the .c file then this whole cross discussion makes more sense!

Jonathan

#11 lore raw

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

Quoted 5 lines · Jonathan Cameron
Quoted 3 lines · On Thu, 19 Jun 2025 11:29:30 +0300 Andy Shevchenko <[email protected]>…
Quoted 2 lines · On Thu, Jun 19, 2025 at 10:22 AM <[email protected]> wrote:
Quoted 1 line · Andy Shevchenko

On Fri, Jun 13, 2025 at 4:02 PM <[email protected]> wrote:

...

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 4 lines
Quoted 4 lines
MAINTAINERS +4 -0
+MICROCHIP MCP9982 TEMPERATURE DRIVER
+M:     Victor Duicu <[email protected]>
+L:     [email protected]
+S:     Supported
Quoted 8 lines
Quoted 4 lines

+F:
Documentation/devicetree/bindings/iio/temperature/microchip,mcp9982 .yaml
+F: drivers/iio/temperature/mcp9982.c

So, with the first patch only the dangling file will be present without record in MAINTAINERS. Please, make sure that your DT schema file is in MAINTAINERS.

Are you referring here to the file sysfs-bus-iio-temperature-mcp9982? This file was in v2 where there were a few custom attributes. In v3 I removed them, so the driver currently doesn't have custom attributes. Should I had added it to the files in MAINTAINERS?

Quoted 7 lines
Quoted 2 lines

You should have added the file to the MAINTAINERS in the same patch it appears. Not in some arbitrary change afterwards.

Perhaps the confusion here is that Andy is talking about 2 lines above, not the immediate line above this feedback. So the one with the dt-binding file. If Victor was reading it as being about the .c file then this whole cross discussion makes more sense!

Yep, sorry for the confusion. My point is that the first patch in the series added a file, it should start a MAINTAINERS at the same time.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#12 lore raw

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

In reply to [email protected]
Quoted 6 lines · On Fri, 13 Jun 2025 16:02:07 +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.

Hi Victor,

Some comments from me to add to what Andy called out. Hopefully I've avoided too much duplication!

Thanks,

Jonathan

Quoted 6 lines
drivers/iio/temperature/mcp9982.c new file +0 -0
new file mode 100644
index 000000000000..b1ae77c6e691

drivers/iio/temperature/mcp9982.c line 104

Quoted 9 lines
drivers/iio/temperature/mcp9982.c new file +8 -0
@@ -0,0 +1,778 @@
 
+/**
+ * struct mcp9982_features - features of a mcp9982 instance
+ * @name:		chip's name
+ * @phys_channels:	number of physical channels supported by the chip
+ */
+struct mcp9982_features {
+	const char	*name;
+	u8		phys_channels;

As below. Add a few more fields for the stuff you were getting from string matching.

drivers/iio/temperature/mcp9982.c line 197

Quoted 3 lines
drivers/iio/temperature/mcp9982.c new file +2 -0
+};
 
+static const unsigned int mcp9982_window_size[3] = {1, 4, 8};

{ 1, 4, 8, };
is style preference for IIO code and consistent with the rest of this driver.

drivers/iio/temperature/mcp9982.c line 201

Quoted 4 lines
drivers/iio/temperature/mcp9982.c new file +4 -0
+
+/*
+ * (Sampling_Frequency * 1000000) / (Window_Size * 2)
+ */

Single line comment syntax

drivers/iio/temperature/mcp9982.c line 208

Quoted 7 lines
drivers/iio/temperature/mcp9982.c new file +7 -0
+static unsigned int mcp9982_calc_all_3db_values(void)
+{
+	u32 denominator, remainder;
+	unsigned int i, j;
+	u64 numerator;
+
+	for (i = 0; i < ARRAY_SIZE(mcp9982_window_size); i++)

Coding style is a little ambiguous around what is a single statement vs multi statements but here I think {} for the outer loop would help readability a tiny bit.

Quoted 27 lines
drivers/iio/temperature/mcp9982.c new file +26 -0
+		for (j = 0; j <  ARRAY_SIZE(mcp9982_sampl_fr); j++) {
+			numerator = MICRO * mcp9982_sampl_fr[j][0];
+			denominator = 2 * mcp9982_window_size[i] * mcp9982_sampl_fr[j][1];
+			remainder = do_div(numerator, denominator);
+			remainder = do_div(numerator, MICRO);
+			mcp9982_3db_values_map_tbl[j][i][0] = numerator;
+			mcp9982_3db_values_map_tbl[j][i][1] = remainder;
+		}
+	return 0;
+}
 
+/**
+ * struct mcp9992_priv - information about chip parameters
+ * @regmap:			device register map
+ * @num_channels		number of physical channels
+ * @extended_temp_range		use extended temperature range or not
+ * @recd34_enable		state of REC on channels 3 and 4
+ * @recd12_enable		state of REC on channels 1 and 2
+ * @beta_values			beta compensation value for external channel 1 and 2
+ * @lock			synchronize access to driver's state members
+ * @iio_chan			specifications of channels
+ * @labels			labels of the channels
+ * @ideality_value		ideality factor value for each external channel
+ * @sampl_idx			index representing the current sampling frequency
+ * @dev_name			name of the device
+ * @apdd_enable			state of anti-parallel diode mode
+ */

drivers/iio/temperature/mcp9982.c line 307

Quoted 10 lines
drivers/iio/temperature/mcp9982.c new file +10 -0
+struct mcp9982_priv {
+	struct regmap *regmap;
+	u8 num_channels;
+	bool extended_temp_range;
+	bool recd34_enable;
+	bool recd12_enable;
+	unsigned int beta_values[2];
+	/*
+	 * Synchronize access to private members, and ensure
+	 * atomicity of consecutive regmap operations.

wrap at 80

drivers/iio/temperature/mcp9982.c line 314

Quoted 7 lines
drivers/iio/temperature/mcp9982.c new file +7 -0
+	 */
+	struct mutex lock;
+	struct iio_chan_spec *iio_chan;
+	const char *labels[MCP9982_MAX_NUM_CHANNELS];
+	unsigned int ideality_value[4];
+	unsigned int sampl_idx;
+	const char *dev_name;

I'd store a pointer to chip in here rather than just the name. Particularly as there are other flags to add to it.

Quoted 16 lines
drivers/iio/temperature/mcp9982.c new file +14 -0
+	bool apdd_enable;
+};
 
 
+static int mcp9982_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
+			    int *val, int *val2, long mask)
+{
+	unsigned int index, idx, tmp_reg;
+	struct mcp9982_priv *priv = iio_priv(indio_dev);
+	int ret;
+
+	ret = regmap_write(priv->regmap, MCP9982_ONE_SHOT_ADDR, 1);
+	if (ret)
+		return ret;
+
+	guard(mutex)(&priv->lock);

drivers/iio/temperature/mcp9982.c line 371

Quoted 10 lines
drivers/iio/temperature/mcp9982.c new file +10 -0
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = regmap_read(priv->regmap, MCP9982_INT_VALUE_ADDR(chan->channel), val);
+		if (ret)
+			return ret;
+
+		/* The extended temperature range is offset by 64 degrees C */
+		if (priv->extended_temp_range)
+			*val -= 64;

Why is this here and in offset below? Userspace should be doing the maths for us.

Quoted 37 lines
drivers/iio/temperature/mcp9982.c new file +37 -0
+
+		ret = regmap_read(priv->regmap, MCP9982_FRAC_VALUE_ADDR(chan->channel), val2);
+		if (ret)
+			return ret;
+
+		/* Only the 3 MSB in fractional registers are used */
+		*val2 = mcp9982_fractional_values[*val2 >> 5];
+		return IIO_VAL_INT_PLUS_MICRO;
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		*val = mcp9982_conv_rate[priv->sampl_idx][0];
+		*val2 = mcp9982_conv_rate[priv->sampl_idx][1];
+		return IIO_VAL_INT_PLUS_MICRO;
+	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
+
+		ret = regmap_read(priv->regmap, MCP9982_RUNNING_AVG_ADDR, &tmp_reg);
+		if (ret)
+			return ret;
+		/*
+		 * In Filter Selection Register values 1 and 2
+		 * are mapped to the same setting.
+		 */
+		switch (tmp_reg) {
+		case 0:
+			idx = 0;
+			break;
+		case 1:
+		case 2:
+			idx = 1;
+			break;
+		default:
+			idx = 2;
+			break;
+		}
+
+		*val = mcp9982_3db_values_map_tbl[priv->sampl_idx][idx][0];
+		*val2 = mcp9982_3db_values_map_tbl[priv->sampl_idx][idx][1];
+		return IIO_VAL_INT_PLUS_MICRO;

drivers/iio/temperature/mcp9982.c line 418

Quoted 10 lines
drivers/iio/temperature/mcp9982.c new file +10 -0
+	case IIO_CHAN_INFO_HYSTERESIS:
+		ret = regmap_read(priv->regmap, MCP9982_HYS_ADDR, &index);
+		if (ret)
+			return ret;
+
+		*val = index;
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_OFFSET:
+		if (priv->extended_temp_range)
+			*val = -64;

As above. I'd expect to only see this -64 here - not in _RAW as well.

Quoted 14 lines
drivers/iio/temperature/mcp9982.c new file +13 -0
+		else
+			*val = 0;
+		return IIO_VAL_INT;
+	default:
+		return -EINVAL;
+	}
+}
 
+static int mcp9982_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan,
+			     int val, int val2, long mask)
+{
+	struct mcp9982_priv *priv = iio_priv(indio_dev);
+	int ret;
+	unsigned int i;

drivers/iio/temperature/mcp9982.c line 470

Quoted 10 lines
drivers/iio/temperature/mcp9982.c new file +10 -0
+	unsigned int start = 0;
+
+	guard(mutex)(&priv->lock);
+	switch (mask) {
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		/*
+		 * For MCP998XD and MCP9933D sampling frequency can't
+		 * be set lower than 1.
+		 */
+		if (strchr(priv->dev_name, 'd'))

Encode this in the features structure as a specific field.
In general don't use string matching for this stuff as it ends up fragile when new device support is added over time and people don't notice this hiding in here.

Quoted 14 lines
drivers/iio/temperature/mcp9982.c new file +14 -0
+			start = 4;
+		for (i = start; i < ARRAY_SIZE(mcp9982_conv_rate); i++)
+			if (val == mcp9982_conv_rate[i][0] && val2 == mcp9982_conv_rate[i][1])
+				break;
+
+		if (i == ARRAY_SIZE(mcp9982_conv_rate))
+			return -EINVAL;
+
+		ret = regmap_write(priv->regmap, MCP9982_CONV_ADDR, i);
+		if (ret)
+			return ret;
+
+		priv->sampl_idx = i;
+		return 0;

drivers/iio/temperature/mcp9982.c line 538

Quoted 10 lines
drivers/iio/temperature/mcp9982.c new file +8 -0
 
 
+static int mcp9982_init(struct mcp9982_priv *priv)
+{
+	int ret;
+	unsigned int i;
+	u8 val;
+
+	/*
+	 * For chips with "D" in the name

Very short wrap. Aim for 80 chars.

drivers/iio/temperature/mcp9982.c line 543

Quoted 5 lines
drivers/iio/temperature/mcp9982.c new file +5 -0
+	 * set the below parameters to default to
+	 * ensure that hardware shutdown feature
+	 * can't be overridden.
+	 */
+	if (strchr(priv->dev_name, 'd')) {

As above. Don't match on strings - store the thing as a flag in the per device type features structure.

Quoted 66 lines
drivers/iio/temperature/mcp9982.c new file +65 -0
+		priv->recd12_enable = true;
+		priv->recd34_enable = true;
+		for (i = 0; i < 2; i++)
+			priv->beta_values[i] = 16;
+		for (i = 0; i < 4; i++)
+			priv->ideality_value[i] = 18;
+	}
+
+	/*
+	 * Set default values in registers.
+	 * APDD, RECD12 and RECD34 are active on 0.
+	 */
+	val = FIELD_PREP(MCP9982_CFG_MSKAL, 1) | FIELD_PREP(MCP9982_CFG_RS, 1) |
+	      FIELD_PREP(MCP9982_CFG_ATTHM, 1) |
+	      FIELD_PREP(MCP9982_CFG_RECD12, !priv->recd12_enable) |
+	      FIELD_PREP(MCP9982_CFG_RECD34, !priv->recd34_enable) |
+	      FIELD_PREP(MCP9982_CFG_RANGE, 0) | FIELD_PREP(MCP9982_CFG_DA_ENA, 0) |
+	      FIELD_PREP(MCP9982_CFG_APDD, !priv->apdd_enable);
+
+	ret = regmap_write(priv->regmap, MCP9982_CFG_ADDR, val);
+	if (ret)
+		return ret;
+	priv->extended_temp_range = false;
+
+	ret = regmap_write(priv->regmap, MCP9982_CONV_ADDR, 6);
+	if (ret)
+		return ret;
+	priv->sampl_idx = 6;
+
+	ret = regmap_write(priv->regmap, MCP9982_HYS_ADDR, 10);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(priv->regmap, MCP9982_CONSEC_ALRT_ADDR, 112);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(priv->regmap, MCP9982_RUNNING_AVG_ADDR, 0);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(priv->regmap, MCP9982_HOTTEST_CFG_ADDR, 0);
+	if (ret)
+		return ret;
+
+	/* Set beta compensation for channels 1 and 2 */
+	for (i = 0; i < 2; i++) {
+		ret = regmap_write(priv->regmap, MCP9982_EXT_BETA_CFG_ADDR(i),
+				   priv->beta_values[i]);
+		if (ret)
+			return ret;
+	}
+	/* Set ideality factor for all external channels */
+	for (i = 0; i < 4; i++) {
+		ret = regmap_write(priv->regmap, MCP9982_EXT_IDEAL_ADDR(i),
+				   priv->ideality_value[i]);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
 
+
+static const struct i2c_device_id mcp9982_id[] = {
+	{ .name = "mcp9933", .driver_data = (kernel_ulong_t)&mcp9933_chip_config },

drivers/iio/temperature/mcp9982.c

Quoted 10 lines
drivers/iio/temperature/mcp9982.c new file +10 -0
+	{ .name = "mcp9933d", .driver_data = (kernel_ulong_t)&mcp9933d_chip_config },
+	{ .name = "mcp9982", .driver_data = (kernel_ulong_t)&mcp9982_chip_config },
+	{ .name = "mcp9982d", .driver_data = (kernel_ulong_t)&mcp9982d_chip_config },
+	{ .name = "mcp9983", .driver_data = (kernel_ulong_t)&mcp9983_chip_config },
+	{ .name = "mcp9983d", .driver_data = (kernel_ulong_t)&mcp9983d_chip_config },
+	{ .name = "mcp9984", .driver_data = (kernel_ulong_t)&mcp9984_chip_config },
+	{ .name = "mcp9984d", .driver_data = (kernel_ulong_t)&mcp9984d_chip_config },
+	{ .name = "mcp9985", .driver_data = (kernel_ulong_t)&mcp9985_chip_config },
+	{ .name = "mcp9985d", .driver_data = (kernel_ulong_t)&mcp9985d_chip_config },
+	{ }

David mentioned the other day that there is an effort to remove the need for the kernel_ulong_t here but it relies on

	{ "mcp9985d", &mcp9984d_chip_config },

style entries.

https://lore.kernel.org/all/[email protected]/

I wasn't aware of that effort but seems sensible to me!

Quoted 2 lines
drivers/iio/temperature/mcp9982.c new file +2 -0
+};
+MODULE_DEVICE_TABLE(i2c, mcp9982_id);
maintainer
#13 lore raw

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

Quoted 17 lines
Quoted 5 lines
drivers/iio/temperature/mcp9982.c new file +3 -0
+
+static const struct i2c_device_id mcp9982_id[] = {
+	{ .name = "mcp9933", .driver_data = (kernel_ulong_t)&mcp9933_chip_config },

drivers/iio/temperature/mcp9982.c line 726

Quoted 10 lines
drivers/iio/temperature/mcp9982.c new file +10 -0
+	{ .name = "mcp9933d", .driver_data = (kernel_ulong_t)&mcp9933d_chip_config },
+	{ .name = "mcp9982", .driver_data = (kernel_ulong_t)&mcp9982_chip_config },
+	{ .name = "mcp9982d", .driver_data = (kernel_ulong_t)&mcp9982d_chip_config },
+	{ .name = "mcp9983", .driver_data = (kernel_ulong_t)&mcp9983_chip_config },
+	{ .name = "mcp9983d", .driver_data = (kernel_ulong_t)&mcp9983d_chip_config },
+	{ .name = "mcp9984", .driver_data = (kernel_ulong_t)&mcp9984_chip_config },
+	{ .name = "mcp9984d", .driver_data = (kernel_ulong_t)&mcp9984d_chip_config },
+	{ .name = "mcp9985", .driver_data = (kernel_ulong_t)&mcp9985_chip_config },
+	{ .name = "mcp9985d", .driver_data = (kernel_ulong_t)&mcp9985d_chip_config },
+	{ }  

David mentioned the other day that there is an effort to remove the need for the kernel_ulong_t here but it relies on

Quoted 2 lines
	{ "mcp9985d", &mcp9984d_chip_config },

style entries.

Oops. Still need the cast.

Quoted 10 lines

https://lore.kernel.org/all/[email protected]/

I wasn't aware of that effort but seems sensible to me!

Quoted 2 lines
drivers/iio/temperature/mcp9982.c new file +2 -0
+};
+MODULE_DEVICE_TABLE(i2c, mcp9982_id);