iio: temperature: Add support for LTC2983
Nuno Sá
maintainerPATCH 1/2 iio: temperature: Add support for LTC2983
The LTC2983 is a Multi-Sensor High Accuracy Digital Temperature Measurement System. It measures a wide variety of temperature sensors and digitally outputs the result, in °C or °F, with 0.1°C accuracy and 0.001°C resolution. It can measure the temperature of all standard thermocouples (type B,E,J,K,N,S,R,T), standard 2-,3-,4-wire RTDs, thermistors and diodes.
--- .../testing/sysfs-bus-iio-temperature-ltc2983 | 43 + MAINTAINERS | 7 + drivers/iio/temperature/Kconfig | 10 + drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/ltc2983.c | 1327 +++++++++++++++++ 5 files changed, 1388 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 create mode 100644 drivers/iio/temperature/ltc2983.c
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +43 -0
@@ -0,0 +1,43 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_tempY_thermistor_raw +KernelVersion: +Contact: [email protected] +Description: + Reads the raw (unscaled no bias removal etc) temperature from + channel Y. The value is returned by a Thermistor sensor measurement. + Units after application of scale are degrees Celsius or Fahrenheit + depending on the device configuration. + +What: /sys/bus/iio/devices/iio:deviceX/in_tempY_thermocouple_raw +KernelVersion: +Contact: [email protected] +Description: + Reads the raw (unscaled no bias removal etc) temperature from + channel Y. The value is returned by a Thermocouple sensor measurement. + Units after application of scale are degrees Celsius or Fahrenheit + depending on the device configuration. + +What: /sys/bus/iio/devices/iio:deviceX/in_tempY_rtd_raw +KernelVersion: +Contact: [email protected] +Description: + Reads the raw (unscaled no bias removal etc) temperature from + channel Y. The value is returned by a RTD sensor measurement. + Units after application of scale are degrees Celsius or Fahrenheit + depending on the device configuration. + +What: /sys/bus/iio/devices/iio:deviceX/in_tempY_diode_raw +KernelVersion: +Contact: [email protected] +Description: + Reads the raw (unscaled no bias removal etc) temperature from + channel Y. The value is returned by a Diode sensor measurement. + Units after application of scale are degrees Celsius or Fahrenheit + depending on the device configuration. + +What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_direct_adc_raw +KernelVersion: +Contact: [email protected] +Description: + Reads the raw (unscaled no bias removal etc) voltage from + channel Y. The value is returned by a direct ADC measurement. + Units after application of scale are Volts.
MAINTAINERS +7 -0
@@ -9491,6 +9491,13 @@ S: Maintained F: Documentation/devicetree/bindings/iio/dac/ltc1660.txt F: drivers/iio/dac/ltc1660.c +LTC2983 IIO TEMPERATURE DRIVER +M: Nuno Sá <[email protected]> +W: http://ez.analog.com/community/linux-device-drivers +L: [email protected] +S: Supported +F: drivers/iio/temperature/ltc2983.c + LTC4261 HARDWARE MONITOR DRIVER M: Guenter Roeck <[email protected]> L: [email protected]
drivers/iio/temperature/Kconfig +10 -0
@@ -4,6 +4,16 @@ # menu "Temperature sensors" +config LTC2983 + tristate "Analog Devices Multi-Sensor Digital Temperature Measurement System" + depends on SPI + help + Say yes here to build support for the LTC2983 Multi-Sensor + high accuracy digital temperature measurement system. + + To compile this driver as a module, choose M here: the module + will be called ltc2983. + config MAXIM_THERMOCOUPLE tristate "Maxim thermocouple sensors" depends on SPI
drivers/iio/temperature/Makefile +1 -0
@@ -3,6 +3,7 @@ # Makefile for industrial I/O temperature drivers # +obj-$(CONFIG_LTC2983) += ltc2983.o obj-$(CONFIG_HID_SENSOR_TEMP) += hid-sensor-temperature.o obj-$(CONFIG_MAXIM_THERMOCOUPLE) += maxim_thermocouple.o obj-$(CONFIG_MAX31856) += max31856.o
drivers/iio/temperature/ltc2983.c new file +1327 -0
1,327 lines not on this page · raw message
Signature · 1 line
2.23.0
Nuno Sá
maintainerPATCH 2/2 dt-bindings: iio: Add ltc2983 documentation
Document the LTC2983 temperature sensor devicetree bindings.
--- .../bindings/iio/temperature/adi,ltc2983.yaml | 442 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 443 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +442 -0
@@ -0,0 +1,442 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/temperature/adi,ltc2983.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices LTC2983 Multi-sensor Temperature system + +maintainers: + - Nuno Sá <[email protected]> + +description: | + Analog Devices LTC2983 Multi-Sensor Digital Temperature Measurement System + https://www.analog.com/media/en/technical-documentation/data-sheets/2983fc.pdf + +properties: + compatible: + enum: + - adi,ltc2983 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + adi,temperature-celcius: + description: + If this property is present, the temperature is reported in Celsius. + type: boolean + maxItems: 1 + + adi,mux-delay-config: + description: + The LTC2983 performs 2 or 3 internal conversion cycles per temperature result. + Each conversion cycle is performed with different excitation and input multiplexer + configurations. Prior to each conversion, these excitation circuits and input + switch configurations are changed and an internal 1ms delay ensures settling prior + to the conversion cycle in most cases. An extra delay can be configured using this + property. The value written here is multiplied by 100us. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 255 + maxItems: 1 + + adi,filter-notch-freq: + description: + Set's the default setting of the digital filter. The default is simultaneous + 50/60Hz rejection. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0, 1, 2] + maxItems: 1 + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + +patternProperties: + "^thermocouple@([1-9]|1[0-9]|20)$": + type: object + description: Represents a thermocouple sensor which is connected to one of the device channels. + + properties: + reg: + description: | + The channel number. It can be connected to one of the 20 channels of the device. + Note that, for differential thermocouples, the minimum is 2. + minimum: 1 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the type of thermocouple connected to the device. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [1 2 3 4 5 6 7 8] + maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Look at table 14 of the + datasheet for how to set this value for thermocouples. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - minimum: 1 + - maximun: 15 + maxItems: 1 + + adi,cold-junction-handle: + description: | + Phandle which points to a sensor object responsible for measuring the + thermocouple cold junction temperature. + $ref: "/schemas/types.yaml#/definitions/phandle" + maxItems: 1 + + adi,custom-sensor: + description: | + This is a table, where each entry should be a pair of voltage(mv)-temperature(K). + The entries must be given in nv and uK so that, the original values must be + multiplied by 1000000. For more details look at table 69 and 70. + allOf: + - $ref: /schemas/types.yaml#/definitions/int64-array + minItems: 6 + maxItems: 128 + required: + - reg + - adi,sensor-type + +patternProperties: + "^diode@([1-9]|1[0-9]|20)$": + type: object + description: Represents a diode sensor which is connected to one of the device channels. + + properties: + reg: + description: + The channel number. It can be connected to one of the 20 channels of the device. + Note that, for differential diodes, the minimum is 2. + minimum: 1 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the sensor as a diode. + const: 28 + maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Look at table 17 of the + datasheet for how to set this value for diodes. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 3 4 5 6 7] + maxItems: 1 + + adi,excitation-current: + description: | + This property controls the magnitude of the excitation current applied + to the diode. Look at table 19 of the datasheet for more info. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 3] + maxItems: 1 + + adi,ideal-factor-value: + description: | + This property sets the diode ideality factor. The real value must be + multiplied by 1000000 to remove the fractional part. For more information + look at table 20 of the datasheet. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + maxItems: 1 + + required: + - reg + - adi,sensor-type + +patternProperties: + "^rtd@([2-9]|1[0-9]|20)$": + type: object + description: Represents a rtd sensor which is connected to one of the device channels. + + properties: + reg: + description: | + The channel number. It can be connected to one of the 20 channels of the device. + minimum: 2 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the type of RTD connected to the device. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [10 11 12 13 14 15 16 17] + maxItems: 1 + + adi,rsense-handle: + description: | + Phandle pointing to a rsense object associated with this RTD. + $ref: "/schemas/types.yaml#/definitions/phandle" + maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Look at table 28 of the + datasheet for how to set this value for RTD's. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 4 5 8 9 10 12 13 14] + maxItems: 1 + + adi,excitation-current: + description: | + This property controls the magnitude of the excitation current applied + to the RTD. Look at table 29 of the datasheet for more info. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [1 2 3 4 5 6 7 8] + maxItems: 1 + + adi,rtd-curve: + description: | + This property set the RTD curve used and the corresponding Callendar-Van + Dusen constants. Look at table 30 of the datasheet. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 3] + maxItems: 1 + + adi,custom-sensor: + description: | + This is a table, where each entry should be a pair of resistance(ohm)-temperature(K). + The entries added here are in uohm and uK. For more details values look at table 74 and 75. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint64-array + minItems: 6 + maxItems: 128 + required: + - reg + - adi,sensor-type + - adi,rsense-handle + +patternProperties: + "^thermistor@([1-9]|1[0-9]|20)$": + type: object + description: Represents a thermistor sensor which is connected to one of the device channels. + + properties: + reg: + description: | + The channel number. It can be connected to one of the 20 channels of the device. + Note that, for differential thermistors, the minimum is 2. + minimum: 1 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the type of thermistor connected to the device. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [19 20 21 22 23 24 25] + maxItems: 1 + + adi,rsense-handle: + description: | + Phandle pointing to a rsense object associated with this thermistor. + $ref: "/schemas/types.yaml#/definitions/phandle" + maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Look at table 52 of the + datasheet for how to set this value for thermistors. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 4] + maxItems: 1 + + adi,excitation-current: + description: | + This property controls the magnitude of the excitation current applied + to the thermistor. Look at table 53 of the datasheet for more info. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32-array + - enum: [1 2 3 4 5 6 7 8 9 10 11 12] + maxItems: 1 + + adi,custom-sensor: + description: | + This is a table, where each entry should be a pair of resistance(ohm)-temperature(K). + The entries added here are in uohm and uK only for custom thermistors. + For more details look at table 78 and 79. + Steinhart-Hart coefficients are also supported and can be programmed into the + device memory using this property. For Steinhart sensors, this table has a constant + size of 6 entries (defining the coefficients) and the values are given in the raw format. + Look at table 82 for more information. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint64-array + minItems: 6 + maxItems: 128 + required: + - reg + - adi,sensor-type + - adi,rsense-handle + +patternProperties: + "^adc@([1-9]|1[0-9]|20)$": + type: object + description: Represents a channel which is being used as a direct adc. + + properties: + reg: + description: | + The channel number. It can be connected to one of the 20 channels of the device. + Note that, for differential adc's, the minimum is 2. + minimum: 1 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the sensor as a direct adc. + const: 30 + maxItems: 1 + + adi,single-ended: + description: | + Boolean property which set's the adc as single-ended. + type: boolean + + required: + - reg + - adi,sensor-type + +patternProperties: + "^rsense@([2-9]|1[0-9]|20)$": + type: object + description: | + Represents a rsense which is connected to one of the device channels. + Rsense are used by thermistors and RTD's. + + properties: + reg: + description: | + The channel number. It can be connected to one of the 20 channels of the device. + minimum: 2 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the sensor as a rsense. + const: 29 + maxItems: 1 + + adi,rsense-val-micro-ohms: + description: | + Sets the value of the sense resistor. Look at table 20 of the datasheet + for information. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint64 + maxItems: 1 + + required: + - reg + - adi,sensor-type + - adi, rsense-val + +required: + - compatible + - reg + - interrupts + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + spi0 { + #address-cells = <1>; + #size-cells = <0>; + + sensor_ltc2983: ltc2983@0 { + compatible = "adi,ltc2983"; + reg = <0>; + + #address-cells = <1>; + #size-cells = <0>; + + adi,temperature-celcius; + interrupts = <20 IRQ_TYPE_EDGE_RISING>; + interrupt-parent = <&gpio>; + + thermocouple@18 { + reg = <18>; + adi,sensor-type = <8>; //Type B + adi,sensor-config = <1>; //Differential, open-circuit current + adi,cold-junction-handle = <&diode5>; + }; + + diode5: diode@5 { + reg = <5>; + adi,sensor-type = <28>; + }; + + rsense2: rsense@2 { + reg = <2>; + adi,sensor-type = <29>; + adi,rsense-val-micro-ohms = /bits/ 64 <1200000000>; //1.2Kohms + }; + + rtd@14 { + reg = <14>; + adi,sensor-type = <15>; //PT1000 + /*2-wire, internal gnd, no current rotation*/ + adi,sensor-config = <1>; + adi,excitation-current = <7>; //500uA + adi,rsense-handle = <&rsense2>; + }; + + adc@10 { + reg = <10>; + adi,sensor-type = <30>; + adi,single-ended; + }; + + thermistor@12 { + reg = <12>; + adi,sensor-type = <26>; //Steinhart + adi,rsense-handle = <&rsense2>; + adi,custom-sensor = /bits/ 64 <0x00F371EC 0x12345678 + 0x2C0F8733 0x10018C66 0xA0FEACCD + 0x90021D99>; //6 entries + }; + + thermocouple@20 { + reg = <20>; + adi,sensor-type = <9>; //custom thermocouple + adi,sensor-config = <8>; //single-ended + adi,custom-sensor = /bits/ 64 + <(-50220000) 0 + (-30200000) 99100000 + (-5300000) 135400000 + 0 273150000 + 40200000 361200000 + 55300000 522100000 + 88300000 720300000 + 132200000 811200000 + 188700000 922500000 + 460400000 1000000000>; //10 pairs + }; + + }; + }; +...
MAINTAINERS +1 -0
@@ -9497,6 +9497,7 @@ W: http://ez.analog.com/community/linux-device-drivers L: [email protected] S: Supported F: drivers/iio/temperature/ltc2983.c +F: Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml LTC4261 HARDWARE MONITOR DRIVER M: Guenter Roeck <[email protected]>
Signature · 1 line
2.23.0
Rob Herring
maintainerRe: [PATCH 2/2] dt-bindings: iio: Add ltc2983 documentation
Quoted 36 lines · Nuno S�
Document the LTC2983 temperature sensor devicetree bindings.
Signed-off-by Nuno S� <[email protected]>--- .../bindings/iio/temperature/adi,ltc2983.yaml | 442 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 443 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yamlDocumentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +21
-0@@ -0,0 +1,442 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/temperature/adi,ltc2983.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices LTC2983 Multi-sensor Temperature system + +maintainers: + - Nuno S� <[email protected]> + +description: | + Analog Devices LTC2983 Multi-Sensor Digital Temperature Measurement System + https://www.analog.com/media/en/technical-documentation/data-sheets/2983fc.pdf + +properties: + compatible: + enum: + - adi,ltc2983 + + reg:
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 31
Quoted 10 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +10
-0+ maxItems: 1 + + interrupts: + maxItems: 1 + + adi,temperature-celcius: + description: + If this property is present, the temperature is reported in Celsius. + type: boolean + maxItems: 1
It's a boolean, not an array so 'maxItems' doesn't make sense.
Running 'make dt_binding_check' should tell you this. You may need to update dt-schema install though.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 44
Quoted 13 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +13
-0+ + adi,mux-delay-config: + description: + The LTC2983 performs 2 or 3 internal conversion cycles per temperature result. + Each conversion cycle is performed with different excitation and input multiplexer + configurations. Prior to each conversion, these excitation circuits and input + switch configurations are changed and an internal 1ms delay ensures settling prior + to the conversion cycle in most cases. An extra delay can be configured using this + property. The value written here is multiplied by 100us. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 255 + maxItems: 1
Drop this.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 53
Quoted 9 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +9
-0+ + adi,filter-notch-freq: + description: + Set's the default setting of the digital filter. The default is simultaneous + 50/60Hz rejection. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0, 1, 2] + maxItems: 1
Drop this.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 64
Quoted 11 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +11
-0+ + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + +patternProperties: + "^thermocouple@([1-9]|1[0-9]|20)$": + type: object + description: Represents a thermocouple sensor which is connected to one of the device channels.
Wrap lines at 80 char.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 73
Quoted 9 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +9
-0+ + properties: + reg: + description: | + The channel number. It can be connected to one of the 20 channels of the device. + Note that, for differential thermocouples, the minimum is 2. + minimum: 1 + maximum: 20 + maxItems: 1
Drop this and pretty much everywhere else that is never an array.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 80
Quoted 7 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +7
-0+ + adi,sensor-type: + description: | + Identifies the type of thermocouple connected to the device. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [1 2 3 4 5 6 7 8]
Missing commas which may not even parse. Maybe be consistent with elsewhere and use minimum and maximum.
Quoted 85 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +85
-0+ maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Look at table 14 of the + datasheet for how to set this value for thermocouples. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - minimum: 1 + - maximun: 15 + maxItems: 1 + + adi,cold-junction-handle: + description: | + Phandle which points to a sensor object responsible for measuring the + thermocouple cold junction temperature. + $ref: "/schemas/types.yaml#/definitions/phandle" + maxItems: 1 + + adi,custom-sensor: + description: | + This is a table, where each entry should be a pair of voltage(mv)-temperature(K). + The entries must be given in nv and uK so that, the original values must be + multiplied by 1000000. For more details look at table 69 and 70. + allOf: + - $ref: /schemas/types.yaml#/definitions/int64-array + minItems: 6 + maxItems: 128 + required: + - reg + - adi,sensor-type + +patternProperties: + "^diode@([1-9]|1[0-9]|20)$": + type: object + description: Represents a diode sensor which is connected to one of the device channels. + + properties: + reg: + description: + The channel number. It can be connected to one of the 20 channels of the device. + Note that, for differential diodes, the minimum is 2. + minimum: 1 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the sensor as a diode. + const: 28 + maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Look at table 17 of the + datasheet for how to set this value for diodes. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 3 4 5 6 7] + maxItems: 1 + + adi,excitation-current: + description: | + This property controls the magnitude of the excitation current applied + to the diode. Look at table 19 of the datasheet for more info. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 3] + maxItems: 1 + + adi,ideal-factor-value: + description: | + This property sets the diode ideality factor. The real value must be + multiplied by 1000000 to remove the fractional part. For more information + look at table 20 of the datasheet. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + maxItems: 1 + + required: + - reg + - adi,sensor-type + +patternProperties: + "^rtd@([2-9]|1[0-9]|20)$":
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 175
Quoted 10 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +10
-0+ type: object + description: Represents a rtd sensor which is connected to one of the device channels. + + properties: + reg: + description: | + The channel number. It can be connected to one of the 20 channels of the device. + minimum: 2 + maximum: 20 + maxItems: 1
As this is pretty much the same for all child nodes, make a pattern that matches all child nodes and put this there rather than duplicating it. Then you only need 'minimum: 2' in the cases needing that.
Quoted 282 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +267
-0+ + adi,sensor-type: + description: | + Identifies the type of RTD connected to the device. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [10 11 12 13 14 15 16 17] + maxItems: 1 + + adi,rsense-handle: + description: | + Phandle pointing to a rsense object associated with this RTD. + $ref: "/schemas/types.yaml#/definitions/phandle" + maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Look at table 28 of the + datasheet for how to set this value for RTD's. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 4 5 8 9 10 12 13 14] + maxItems: 1 + + adi,excitation-current: + description: | + This property controls the magnitude of the excitation current applied + to the RTD. Look at table 29 of the datasheet for more info. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [1 2 3 4 5 6 7 8] + maxItems: 1 + + adi,rtd-curve: + description: | + This property set the RTD curve used and the corresponding Callendar-Van + Dusen constants. Look at table 30 of the datasheet. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 3] + maxItems: 1 + + adi,custom-sensor: + description: | + This is a table, where each entry should be a pair of resistance(ohm)-temperature(K). + The entries added here are in uohm and uK. For more details values look at table 74 and 75. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint64-array + minItems: 6 + maxItems: 128 + required: + - reg + - adi,sensor-type + - adi,rsense-handle + +patternProperties: + "^thermistor@([1-9]|1[0-9]|20)$": + type: object + description: Represents a thermistor sensor which is connected to one of the device channels. + + properties: + reg: + description: | + The channel number. It can be connected to one of the 20 channels of the device. + Note that, for differential thermistors, the minimum is 2. + minimum: 1 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the type of thermistor connected to the device. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [19 20 21 22 23 24 25] + maxItems: 1 + + adi,rsense-handle: + description: | + Phandle pointing to a rsense object associated with this thermistor. + $ref: "/schemas/types.yaml#/definitions/phandle" + maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Look at table 52 of the + datasheet for how to set this value for thermistors. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 4] + maxItems: 1 + + adi,excitation-current: + description: | + This property controls the magnitude of the excitation current applied + to the thermistor. Look at table 53 of the datasheet for more info. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32-array + - enum: [1 2 3 4 5 6 7 8 9 10 11 12] + maxItems: 1 + + adi,custom-sensor: + description: | + This is a table, where each entry should be a pair of resistance(ohm)-temperature(K). + The entries added here are in uohm and uK only for custom thermistors. + For more details look at table 78 and 79. + Steinhart-Hart coefficients are also supported and can be programmed into the + device memory using this property. For Steinhart sensors, this table has a constant + size of 6 entries (defining the coefficients) and the values are given in the raw format. + Look at table 82 for more information. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint64-array + minItems: 6 + maxItems: 128 + required: + - reg + - adi,sensor-type + - adi,rsense-handle + +patternProperties: + "^adc@([1-9]|1[0-9]|20)$": + type: object + description: Represents a channel which is being used as a direct adc. + + properties: + reg: + description: | + The channel number. It can be connected to one of the 20 channels of the device. + Note that, for differential adc's, the minimum is 2. + minimum: 1 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the sensor as a direct adc. + const: 30 + maxItems: 1 + + adi,single-ended: + description: | + Boolean property which set's the adc as single-ended. + type: boolean + + required: + - reg + - adi,sensor-type + +patternProperties: + "^rsense@([2-9]|1[0-9]|20)$": + type: object + description: | + Represents a rsense which is connected to one of the device channels. + Rsense are used by thermistors and RTD's. + + properties: + reg: + description: | + The channel number. It can be connected to one of the 20 channels of the device. + minimum: 2 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the sensor as a rsense. + const: 29 + maxItems: 1 + + adi,rsense-val-micro-ohms: + description: | + Sets the value of the sense resistor. Look at table 20 of the datasheet + for information. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint64 + maxItems: 1 + + required: + - reg + - adi,sensor-type + - adi, rsense-val + +required: + - compatible + - reg + - interrupts + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + spi0 { + #address-cells = <1>; + #size-cells = <0>; + + sensor_ltc2983: ltc2983@0 { + compatible = "adi,ltc2983"; + reg = <0>; + + #address-cells = <1>; + #size-cells = <0>; + + adi,temperature-celcius; + interrupts = <20 IRQ_TYPE_EDGE_RISING>; + interrupt-parent = <&gpio>; + + thermocouple@18 { + reg = <18>; + adi,sensor-type = <8>; //Type B + adi,sensor-config = <1>; //Differential, open-circuit current + adi,cold-junction-handle = <&diode5>; + }; + + diode5: diode@5 { + reg = <5>; + adi,sensor-type = <28>; + }; + + rsense2: rsense@2 { + reg = <2>; + adi,sensor-type = <29>; + adi,rsense-val-micro-ohms = /bits/ 64 <1200000000>; //1.2Kohms + }; + + rtd@14 { + reg = <14>; + adi,sensor-type = <15>; //PT1000 + /*2-wire, internal gnd, no current rotation*/ + adi,sensor-config = <1>; + adi,excitation-current = <7>; //500uA + adi,rsense-handle = <&rsense2>; + }; + + adc@10 { + reg = <10>; + adi,sensor-type = <30>; + adi,single-ended; + }; + + thermistor@12 { + reg = <12>; + adi,sensor-type = <26>; //Steinhart + adi,rsense-handle = <&rsense2>; + adi,custom-sensor = /bits/ 64 <0x00F371EC 0x12345678 + 0x2C0F8733 0x10018C66 0xA0FEACCD + 0x90021D99>; //6 entries + }; + + thermocouple@20 { + reg = <20>; + adi,sensor-type = <9>; //custom thermocouple + adi,sensor-config = <8>; //single-ended + adi,custom-sensor = /bits/ 64 + <(-50220000) 0 + (-30200000) 99100000 + (-5300000) 135400000 + 0 273150000 + 40200000 361200000 + 55300000 522100000 + 88300000 720300000 + 132200000 811200000 + 188700000 922500000 + 460400000 1000000000>; //10 pairs + }; + + }; + }; +...MAINTAINERS +1
-0@@ -9497,6 +9497,7 @@ W: http://ez.analog.com/community/linux-device-drivers L: [email protected] S: Supported F: drivers/iio/temperature/ltc2983.c +F: Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml LTC4261 HARDWARE MONITOR DRIVER M: Guenter Roeck <[email protected]>Signature · 1 line
2.23.0
Jonathan Cameron
maintainerRe: [PATCH 2/2] dt-bindings: iio: Add ltc2983 documentation
Quoted 50 lines · On Fri, 13 Sep 2019 15:36:21 +0100 Rob Herring <[email protected]> wrote:
Quoted 36 lines · Nuno Sá
Document the LTC2983 temperature sensor devicetree bindings.
Signed-off-by Nuno Sá <[email protected]>--- .../bindings/iio/temperature/adi,ltc2983.yaml | 442 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 443 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yamlDocumentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +21
-0@@ -0,0 +1,442 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/temperature/adi,ltc2983.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices LTC2983 Multi-sensor Temperature system + +maintainers: + - Nuno Sá <[email protected]> + +description: | + Analog Devices LTC2983 Multi-Sensor Digital Temperature Measurement System + https://www.analog.com/media/en/technical-documentation/data-sheets/2983fc.pdf + +properties: + compatible: + enum: + - adi,ltc2983 + + reg:Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 31
Quoted 10 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +10
-0+ maxItems: 1 + + interrupts: + maxItems: 1 + + adi,temperature-celcius: + description: + If this property is present, the temperature is reported in Celsius. + type: boolean + maxItems: 1It's a boolean, not an array so 'maxItems' doesn't make sense.
Quoted 12 lines
Running 'make
dt_binding_check' should tell you this. You may need to update dt-schema install though.Quoted 9 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +9
-0+ + adi,mux-delay-config: + description: + The LTC2983 performs 2 or 3 internal conversion cycles per temperature result. + Each conversion cycle is performed with different excitation and input multiplexer + configurations. Prior to each conversion, these excitation circuits and input + switch configurations are changed and an internal 1ms delay ensures settling prior + to the conversion cycle in most cases. An extra delay can be configured using this + property. The value written here is multiplied by 100us.
Make this adi,mux-delay-config-us and state it is rounded to nearest 100us.
Quoted 176 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 44
Quoted 4 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +4
-0+ allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 255 + maxItems: 1Drop this.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 53
Quoted 9 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +9
-0+ + adi,filter-notch-freq: + description: + Set's the default setting of the digital filter. The default is simultaneous + 50/60Hz rejection. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0, 1, 2] + maxItems: 1Drop this.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 64
Quoted 11 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +11
-0+ + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + +patternProperties: + "^thermocouple@([1-9]|1[0-9]|20)$": + type: object + description: Represents a thermocouple sensor which is connected to one of the device channels.Wrap lines at 80 char.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 73
Quoted 9 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +9
-0+ + properties: + reg: + description: | + The channel number. It can be connected to one of the 20 channels of the device. + Note that, for differential thermocouples, the minimum is 2. + minimum: 1 + maximum: 20 + maxItems: 1Drop this and pretty much everywhere else that is never an array.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 80
Quoted 7 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +7
-0+ + adi,sensor-type: + description: | + Identifies the type of thermocouple connected to the device. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [1 2 3 4 5 6 7 8]Missing commas which may not even parse. Maybe be consistent with elsewhere and use minimum and maximum.
Quoted 85 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +85
-0+ maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Look at table 14 of the + datasheet for how to set this value for thermocouples. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - minimum: 1 + - maximun: 15 + maxItems: 1 + + adi,cold-junction-handle: + description: | + Phandle which points to a sensor object responsible for measuring the + thermocouple cold junction temperature. + $ref: "/schemas/types.yaml#/definitions/phandle" + maxItems: 1 + + adi,custom-sensor: + description: | + This is a table, where each entry should be a pair of voltage(mv)-temperature(K). + The entries must be given in nv and uK so that, the original values must be + multiplied by 1000000. For more details look at table 69 and 70. + allOf: + - $ref: /schemas/types.yaml#/definitions/int64-array + minItems: 6 + maxItems: 128 + required: + - reg + - adi,sensor-type + +patternProperties: + "^diode@([1-9]|1[0-9]|20)$": + type: object + description: Represents a diode sensor which is connected to one of the device channels. + + properties: + reg: + description: + The channel number. It can be connected to one of the 20 channels of the device. + Note that, for differential diodes, the minimum is 2. + minimum: 1 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the sensor as a diode. + const: 28 + maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Look at table 17 of the + datasheet for how to set this value for diodes. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 3 4 5 6 7] + maxItems: 1 + + adi,excitation-current: + description: | + This property controls the magnitude of the excitation current applied + to the diode. Look at table 19 of the datasheet for more info. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 3] + maxItems: 1 + + adi,ideal-factor-value: + description: | + This property sets the diode ideality factor. The real value must be + multiplied by 1000000 to remove the fractional part. For more information + look at table 20 of the datasheet. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + maxItems: 1 + + required: + - reg + - adi,sensor-type + +patternProperties: + "^rtd@([2-9]|1[0-9]|20)$":Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 175
Quoted 10 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +10
-0+ type: object + description: Represents a rtd sensor which is connected to one of the device channels. + + properties: + reg: + description: | + The channel number. It can be connected to one of the 20 channels of the device. + minimum: 2 + maximum: 20 + maxItems: 1As this is pretty much the same for all child nodes, make a pattern that matches all child nodes and put this there rather than duplicating it. Then you only need 'minimum: 2' in the cases needing that.
Quoted 20 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +20
-0+ + adi,sensor-type: + description: | + Identifies the type of RTD connected to the device. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [10 11 12 13 14 15 16 17] + maxItems: 1 + + adi,rsense-handle: + description: | + Phandle pointing to a rsense object associated with this RTD. + $ref: "/schemas/types.yaml#/definitions/phandle" + maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Look at table 28 of the + datasheet for how to set this value for RTD's. + allOf:
Quoted 8 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 203
Quoted 8 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +8
-0+ - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 4 5 8 9 10 12 13 14] + maxItems: 1 + + adi,excitation-current: + description: | + This property controls the magnitude of the excitation current applied + to the RTD. Look at table 29 of the datasheet for more info.
Any way we can make this real units? Can list valid value here.
Quoted 255 lines
Quoted 254 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +239
-0+ allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [1 2 3 4 5 6 7 8] + maxItems: 1 + + adi,rtd-curve: + description: | + This property set the RTD curve used and the corresponding Callendar-Van + Dusen constants. Look at table 30 of the datasheet. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 3] + maxItems: 1 + + adi,custom-sensor: + description: | + This is a table, where each entry should be a pair of resistance(ohm)-temperature(K). + The entries added here are in uohm and uK. For more details values look at table 74 and 75. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint64-array + minItems: 6 + maxItems: 128 + required: + - reg + - adi,sensor-type + - adi,rsense-handle + +patternProperties: + "^thermistor@([1-9]|1[0-9]|20)$": + type: object + description: Represents a thermistor sensor which is connected to one of the device channels. + + properties: + reg: + description: | + The channel number. It can be connected to one of the 20 channels of the device. + Note that, for differential thermistors, the minimum is 2. + minimum: 1 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the type of thermistor connected to the device. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [19 20 21 22 23 24 25] + maxItems: 1 + + adi,rsense-handle: + description: | + Phandle pointing to a rsense object associated with this thermistor. + $ref: "/schemas/types.yaml#/definitions/phandle" + maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Look at table 52 of the + datasheet for how to set this value for thermistors. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 4] + maxItems: 1 + + adi,excitation-current: + description: | + This property controls the magnitude of the excitation current applied + to the thermistor. Look at table 53 of the datasheet for more info. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32-array + - enum: [1 2 3 4 5 6 7 8 9 10 11 12] + maxItems: 1 + + adi,custom-sensor: + description: | + This is a table, where each entry should be a pair of resistance(ohm)-temperature(K). + The entries added here are in uohm and uK only for custom thermistors. + For more details look at table 78 and 79. + Steinhart-Hart coefficients are also supported and can be programmed into the + device memory using this property. For Steinhart sensors, this table has a constant + size of 6 entries (defining the coefficients) and the values are given in the raw format. + Look at table 82 for more information. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint64-array + minItems: 6 + maxItems: 128 + required: + - reg + - adi,sensor-type + - adi,rsense-handle + +patternProperties: + "^adc@([1-9]|1[0-9]|20)$": + type: object + description: Represents a channel which is being used as a direct adc. + + properties: + reg: + description: | + The channel number. It can be connected to one of the 20 channels of the device. + Note that, for differential adc's, the minimum is 2. + minimum: 1 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the sensor as a direct adc. + const: 30 + maxItems: 1 + + adi,single-ended: + description: | + Boolean property which set's the adc as single-ended. + type: boolean + + required: + - reg + - adi,sensor-type + +patternProperties: + "^rsense@([2-9]|1[0-9]|20)$": + type: object + description: | + Represents a rsense which is connected to one of the device channels. + Rsense are used by thermistors and RTD's. + + properties: + reg: + description: | + The channel number. It can be connected to one of the 20 channels of the device. + minimum: 2 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the sensor as a rsense. + const: 29 + maxItems: 1 + + adi,rsense-val-micro-ohms: + description: | + Sets the value of the sense resistor. Look at table 20 of the datasheet + for information. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint64 + maxItems: 1 + + required: + - reg + - adi,sensor-type + - adi, rsense-val + +required: + - compatible + - reg + - interrupts + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + spi0 { + #address-cells = <1>; + #size-cells = <0>; + + sensor_ltc2983: ltc2983@0 { + compatible = "adi,ltc2983"; + reg = <0>; + + #address-cells = <1>; + #size-cells = <0>; + + adi,temperature-celcius; + interrupts = <20 IRQ_TYPE_EDGE_RISING>; + interrupt-parent = <&gpio>; + + thermocouple@18 { + reg = <18>; + adi,sensor-type = <8>; //Type B + adi,sensor-config = <1>; //Differential, open-circuit current + adi,cold-junction-handle = <&diode5>; + }; + + diode5: diode@5 { + reg = <5>; + adi,sensor-type = <28>; + }; + + rsense2: rsense@2 { + reg = <2>; + adi,sensor-type = <29>; + adi,rsense-val-micro-ohms = /bits/ 64 <1200000000>; //1.2Kohms + }; + + rtd@14 { + reg = <14>; + adi,sensor-type = <15>; //PT1000 + /*2-wire, internal gnd, no current rotation*/ + adi,sensor-config = <1>; + adi,excitation-current = <7>; //500uA + adi,rsense-handle = <&rsense2>; + }; + + adc@10 { + reg = <10>; + adi,sensor-type = <30>; + adi,single-ended; + }; + + thermistor@12 { + reg = <12>; + adi,sensor-type = <26>; //Steinhart + adi,rsense-handle = <&rsense2>; + adi,custom-sensor = /bits/ 64 <0x00F371EC 0x12345678 + 0x2C0F8733 0x10018C66 0xA0FEACCD + 0x90021D99>; //6 entries + }; + + thermocouple@20 { + reg = <20>; + adi,sensor-type = <9>; //custom thermocouple + adi,sensor-config = <8>; //single-ended + adi,custom-sensor = /bits/ 64 + <(-50220000) 0 + (-30200000) 99100000 + (-5300000) 135400000 + 0 273150000 + 40200000 361200000 + 55300000 522100000 + 88300000 720300000 + 132200000 811200000 + 188700000 922500000 + 460400000 1000000000>; //10 pairs + }; + + }; + }; +...MAINTAINERS +1
-0@@ -9497,6 +9497,7 @@ W: http://ez.analog.com/community/linux-device-drivers L: [email protected] S: Supported F: drivers/iio/temperature/ltc2983.c +F: Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml LTC4261 HARDWARE MONITOR DRIVER M: Guenter Roeck <[email protected]>Signature · 1 line
2.23.0
Sa, Nuno
maintainerRe: [PATCH 2/2] dt-bindings: iio: Add ltc2983 documentation
Hi Rob and Jonathan,
Some comments/questions inline.
Nuno Sá
Quoted 67 lines · Jonathan Cameron
Quoted 63 lines · On Fri, 13 Sep 2019 15:36:21 +0100 Rob Herring <[email protected]> wrote:
Quoted 57 lines · Nuno Sá
Document the LTC2983 temperature sensor devicetree bindings.
Signed-off-by Nuno Sá <[email protected]>--- .../bindings/iio/temperature/adi,ltc2983.yaml | 442 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 443 insertions(+) create mode 100644
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yamldiff --git a/Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.y aml b/Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.y aml
new file mode 100644
index 000000000000..2b468b3ed177
---/dev/null
+++
b/Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.y amlDocumentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +4
-0@@ -0,0 +1,442 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id:http://devicetree.org/schemas/iio/temperature/adi,ltc2983.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +8
-0+ +title: Analog Devices LTC2983 Multi-sensor Temperature system + +maintainers: + - Nuno Sá <[email protected]> + +description: | + Analog Devices LTC2983 Multi-Sensor Digital TemperatureMeasurement System
+
https://www.analog.com/media/en/technical-documentation/data-sheets/2983fc.pdfDocumentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +15
-0+ +properties: + compatible: + enum: + - adi,ltc2983 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + adi,temperature-celcius: + description: + If this property is present, the temperature is reportedin Celsius.
Review
Quoted 2 lines
(quoted diff) +2
-0+ type: boolean + maxItems: 1It's a boolean, not an array so 'maxItems' doesn't make sense.
Quoted 3 lines
Quoted 3 lines
Running 'make
dt_binding_check' should tell you this. You may need to
update dt-schema install though.
Rob, I'm having some issues with make dt_binding_check. I updated dt- schema and I get this when run it:
...
"ruamel.yaml.constructor.DuplicateKeyError: while constructing a mapping
in "<unicode string>", line 4, column 1
found duplicate key "patternProperties" with value "{}" (original
value: "{}")
in "<unicode string>", line 113, column 1"
If you want, I can paste the complete traceback in a following email. However I could use dt-doc-validate Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml directly by doing a manual change in dt-doc-validate . I changed the call testtree = dtschema.load(filename, line_number=line_number, duplicate_keys=False) to testtree = dtschema.load(filename, line_number=line_number, duplicate_keys=True). Is this something already known? I would not be surprised if it is some problem in my environment. However, I even tried this in a clean docker container based on ubuntu 18.04 and got the same behavior.
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +4
-0+ + adi,mux-delay-config: + description: + The LTC2983 performs 2 or 3 internal conversion cycles pertemperature result.
+ Each conversion cycle is performed with differentQuoted 8 lines
Quoted 8 lines
excitation and input multiplexer
+ configurations. Prior to each conversion, these excitation
circuits and input
+ switch configurations are changed and an internal 1ms
delay ensures settling prior
+ to the conversion cycle in most cases. An extra delay can
be configured using this
+ property. The value written here is multiplied by 100us.
Quoted 179 lines
Make this adi,mux-delay-config-us and state it is rounded to nearest 100us.
Quoted 176 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 44
Quoted 4 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +4
-0+ allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 255 + maxItems: 1Drop this.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 53
Quoted 10 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +4
-0+ + adi,filter-notch-freq: + description: + Set's the default setting of the digital filter. Thedefault is simultaneous
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +5
-0+ 50/60Hz rejection. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0, 1, 2] + maxItems: 1Drop this.
Quoted 11 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +11
-0+ + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + +patternProperties: + "^thermocouple@([1-9]|1[0-9]|20)$": + type: object + description: Represents a thermocouple sensor which isQuoted 1 line
connected to one of the device channels.
Wrap lines at 80 char.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 73
Quoted 11 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +5
-0+ + properties: + reg: + description: | + The channel number. It can be connected to one of the20 channels of the device.
+ Note that, for differential thermocouples, the minimum
is 2.Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +3
-0+ minimum: 1 + maximum: 20 + maxItems: 1Drop this and pretty much everywhere else that is never an array.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 80
Quoted 8 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +4
-0+ + adi,sensor-type: + description: | + Identifies the type of thermocouple connected to thedevice.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +3
-0+ allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [1 2 3 4 5 6 7 8]Missing commas which may not even parse. Maybe be consistent with elsewhere and use minimum and maximum.
Quoted 106 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +5
-0+ maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Lookat table 14 of the
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +10
-0+ datasheet for how to set this value for thermocouples. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - minimum: 1 + - maximun: 15 + maxItems: 1 + + adi,cold-junction-handle: + description: | + Phandle which points to a sensor object responsiblefor measuring the
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +7
-0+ thermocouple cold junction temperature. + $ref: "/schemas/types.yaml#/definitions/phandle" + maxItems: 1 + + adi,custom-sensor: + description: | + This is a table, where each entry should be a pair ofvoltage(mv)-temperature(K).
+ The entries must be given in nv and uK so that, the
original values must be
+ multiplied by 1000000. For more details look at table
69 and 70.Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +12
-0+ allOf: + - $ref: /schemas/types.yaml#/definitions/int64-array + minItems: 6 + maxItems: 128 + required: + - reg + - adi,sensor-type + +patternProperties: + "^diode@([1-9]|1[0-9]|20)$": + type: object + description: Represents a diode sensor which is connected toone of the device channels.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +5
-0+ + properties: + reg: + description: + The channel number. It can be connected to one of the20 channels of the device.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +14
-0+ Note that, for differential diodes, the minimum is 2. + minimum: 1 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the sensor as a diode. + const: 28 + maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Lookat table 17 of the
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +9
-0+ datasheet for how to set this value for diodes. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 3 4 5 6 7] + maxItems: 1 + + adi,excitation-current: + description: | + This property controls the magnitude of the excitationcurrent applied
+ to the diode. Look at table 19 of the datasheet for
more info.Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +8
-0+ allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 3] + maxItems: 1 + + adi,ideal-factor-value: + description: | + This property sets the diode ideality factor. The realvalue must be
+ multiplied by 1000000 to remove the fractional part.
For more informationDocumentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +13
-0+ look at table 20 of the datasheet. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + maxItems: 1 + + required: + - reg + - adi,sensor-type + +patternProperties: + "^rtd@([2-9]|1[0-9]|20)$": + type: object + description: Represents a rtd sensor which is connected toone of the device channels.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +5
-0+ + properties: + reg: + description: | + The channel number. It can be connected to one of the20 channels of the device.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml line 175
Quoted 3 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +3
-0+ minimum: 2 + maximum: 20 + maxItems: 1As this is pretty much the same for all child nodes, make a pattern that
matches all child nodes and put this there rather than duplicating it.
Then you only need 'minimum: 2' in the cases needing that.
I'm not sure I'm following your point here. So it's better to clarify it before sending a v2. Do you mean to add something like:
patternProperties:
"^(thermocouple|diode|rtd|thermistor|adc|rsense)@([1-9]|1[0-9]|20)$"
type: object
properties:
reg:
description: |
The channel number. It can be connected to one of the 20
channels of the device.
minimum: 1
maximum: 20And then, for instance, for a RTD I would have:
patternProperties:
"^rtd@([2-9]|1[0-9]|20)$"
...
properties:
reg:
minimum: 2
...Would this also make sense, or it's not really necessary?
patternProperties:
"^thermocouple@([1-9]|1[0-9]|20)$"
type: object
...
properties:
reg:
description: For differential thermocouples, the minimum is 2.
...Am I understanding it correctly?
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +12
-0+thermistor + adi,sensor-type: + description: | + Identifies the type of RTD connected to the device. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [10 11 12 13 14 15 16 17] + maxItems: 1 + + adi,rsense-handle: + description: | + Phandle pointing to a rsense object associated withthis RTD.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +6
-0+ $ref: "/schemas/types.yaml#/definitions/phandle" + maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Lookat table 28 of the
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +6
-0+ datasheet for how to set this value for RTD's. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 4 5 8 9 10 12 13 14] + maxItems: 1 +
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +3
-0+ adi,excitation-current: + description: | + This property controls the magnitude of the excitationcurrent applied
+ to the RTD. Look at table 29 of the datasheet for more
info.Any way we can make this real units? Can list valid value here.
For RTD's and diodes, it is possible to have it with real units. However, for thermistors it's not really doable since, for instance, for them we have an "Auto Range" setting. So, I just wanted to be consistent through all sensors having excitation-current configuration. Do you prefer to have it in real units where possible?
Quoted 284 lines
Quoted 284 lines
Quoted 284 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +8
-0+ allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [1 2 3 4 5 6 7 8] + maxItems: 1 + + adi,rtd-curve: + description: | + This property set the RTD curve used and thecorresponding Callendar-Van
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +9
-0+ Dusen constants. Look at table 30 of the datasheet. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 3] + maxItems: 1 + + adi,custom-sensor: + description: | + This is a table, where each entry should be a pair ofresistance(ohm)-temperature(K).
+ The entries added here are in uohm and uK. For more
details values look at table 74 and 75.Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +13
-0+ allOf: + - $ref: /schemas/types.yaml#/definitions/uint64-array + minItems: 6 + maxItems: 128 + required: + - reg + - adi,sensor-type + - adi,rsense-handle + +patternProperties: + "^thermistor@([1-9]|1[0-9]|20)$": + type: object + description: Represents a thermistor sensor which isconnected to one of the device channels.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +5
-0+ + properties: + reg: + description: | + The channel number. It can be connected to one of the20 channels of the device.
+ Note that, for differential thermistors, the minimum
is 2.Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +7
-0+ minimum: 1 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the type of thermistor connected to thedevice.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +8
-0+ allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [19 20 21 22 23 24 25] + maxItems: 1 + + adi,rsense-handle: + description: | + Phandle pointing to a rsense object associated withthis thermistor.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +6
-0+ $ref: "/schemas/types.yaml#/definitions/phandle" + maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Lookat table 52 of the
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +9
-0+ datasheet for how to set this value for thermistors. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 2 4] + maxItems: 1 + + adi,excitation-current: + description: | + This property controls the magnitude of the excitationcurrent applied
+ to the thermistor. Look at table 53 of the datasheet
for more info.Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +8
-0+ allOf: + - $ref: /schemas/types.yaml#/definitions/uint32-array + - enum: [1 2 3 4 5 6 7 8 9 10 11 12] + maxItems: 1 + + adi,custom-sensor: + description: | + This is a table, where each entry should be a pair ofresistance(ohm)-temperature(K).
+ The entries added here are in uohm and uK only for
custom thermistors.(quoted diff) +2
-0+ For more details look at table 78 and 79. + Steinhart-Hart coefficients are also supported and canbe programmed into the
+ device memory using this property. For Steinhart
sensors, this table has a constant
+ size of 6 entries (defining the coefficients) and the
values are given in the raw format.Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +14
-0+ Look at table 82 for more information. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint64-array + minItems: 6 + maxItems: 128 + required: + - reg + - adi,sensor-type + - adi,rsense-handle + +patternProperties: + "^adc@([1-9]|1[0-9]|20)$": + type: object + description: Represents a channel which is being used as adirect adc.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +5
-0+ + properties: + reg: + description: | + The channel number. It can be connected to one of the20 channels of the device.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +25
-0+ Note that, for differential adc's, the minimum is 2. + minimum: 1 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the sensor as a direct adc. + const: 30 + maxItems: 1 + + adi,single-ended: + description: | + Boolean property which set's the adc as single-ended. + type: boolean + + required: + - reg + - adi,sensor-type + +patternProperties: + "^rsense@([2-9]|1[0-9]|20)$": + type: object + description: | + Represents a rsense which is connected to one of thedevice channels.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +6
-0+ Rsense are used by thermistors and RTD's. + + properties: + reg: + description: | + The channel number. It can be connected to one of the20 channels of the device.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +13
-0+ minimum: 2 + maximum: 20 + maxItems: 1 + + adi,sensor-type: + description: | + Identifies the sensor as a rsense. + const: 29 + maxItems: 1 + + adi,rsense-val-micro-ohms: + description: | + Sets the value of the sense resistor. Look at table 20of the datasheet
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +37
-0+ for information. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint64 + maxItems: 1 + + required: + - reg + - adi,sensor-type + - adi, rsense-val + +required: + - compatible + - reg + - interrupts + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + spi0 { + #address-cells = <1>; + #size-cells = <0>; + + sensor_ltc2983: ltc2983@0 { + compatible = "adi,ltc2983"; + reg = <0>; + + #address-cells = <1>; + #size-cells = <0>; + + adi,temperature-celcius; + interrupts = <20 IRQ_TYPE_EDGE_RISING>; + interrupt-parent = <&gpio>; + + thermocouple@18 { + reg = <18>; + adi,sensor-type = <8>; //Type B + adi,sensor-config = <1>; //Differential,open-circuit current
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +12
-0+ adi,cold-junction-handle = <&diode5>; + }; + + diode5: diode@5 { + reg = <5>; + adi,sensor-type = <28>; + }; + + rsense2: rsense@2 { + reg = <2>; + adi,sensor-type = <29>; + adi,rsense-val-micro-ohms = /bits/ 64<1200000000>; //1.2Kohms
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +6
-0+ }; + + rtd@14 { + reg = <14>; + adi,sensor-type = <15>; //PT1000 + /*2-wire, internal gnd, no currentrotation*/
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +16
-0+ adi,sensor-config = <1>; + adi,excitation-current = <7>; //500uA + adi,rsense-handle = <&rsense2>; + }; + + adc@10 { + reg = <10>; + adi,sensor-type = <30>; + adi,single-ended; + }; + + thermistor@12 { + reg = <12>; + adi,sensor-type = <26>; //Steinhart + adi,rsense-handle = <&rsense2>; + adi,custom-sensor = /bits/ 64<
0x00F371EC0x12345678
+0x2C0F87330x10018C660xA0FEACCDDocumentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +6
-0+ 0x90021D99>; //6 entries + }; + + thermocouple@20 { + reg = <20>; + adi,sensor-type = <9>; //customthermocouple
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +12
-0+ adi,sensor-config = <8>; //single-ended + adi,custom-sensor = /bits/ 64 + <(-50220000) 0 + (-30200000) 99100000 + (-5300000) 135400000 + 0 273150000 + 40200000 361200000 + 55300000 522100000 + 88300000 720300000 + 132200000 811200000 + 188700000 922500000 + 460400000 1000000000>; //10pairs
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +5
-0+ }; + + }; + }; +...MAINTAINERS +0
-0@@ -9497,6 +9497,7 @@ W:http://ez.analog.com/community/linux-device-drivers
L: [email protected]
S: Supported
F:drivers/iio/temperature/ltc2983.c
+F:Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yamlLTC4261 HARDWARE MONITOR DRIVER
M: Guenter Roeck <[email protected]>Signature · 1 line
2.23.0
Rob Herring
maintainerRe: [PATCH 2/2] dt-bindings: iio: Add ltc2983 documentation
Quoted 82 lines · Nuno
Hi Rob and Jonathan,
Some comments/questions inline.
Nuno Sá
Quoted 67 lines · Jonathan Cameron
Quoted 63 lines · On Fri, 13 Sep 2019 15:36:21 +0100 Rob Herring <[email protected]> wrote:
Quoted 57 lines · Nuno Sá
Document the LTC2983 temperature sensor devicetree bindings.
Signed-off-by Nuno Sá <[email protected]>--- .../bindings/iio/temperature/adi,ltc2983.yaml | 442 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 443 insertions(+) create mode 100644
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yamldiff --git a/Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.y aml b/Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.y aml
new file mode 100644
index 000000000000..2b468b3ed177
---/dev/null
+++
b/Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.y amlDocumentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +4
-0@@ -0,0 +1,442 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id:http://devicetree.org/schemas/iio/temperature/adi,ltc2983.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +8
-0+ +title: Analog Devices LTC2983 Multi-sensor Temperature system + +maintainers: + - Nuno Sá <[email protected]> + +description: | + Analog Devices LTC2983 Multi-Sensor Digital TemperatureMeasurement System
+
https://www.analog.com/media/en/technical-documentation/data-sheets/2983fc.pdfDocumentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +15
-0+ +properties: + compatible: + enum: + - adi,ltc2983 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + adi,temperature-celcius: + description: + If this property is present, the temperature is reportedin Celsius.
Review
Quoted 2 lines
(quoted diff) +2
-0+ type: boolean + maxItems: 1It's a boolean, not an array so 'maxItems' doesn't make sense.
Quoted 3 lines
Quoted 3 lines
Running 'make
dt_binding_check' should tell you this. You may need to
update dt-schema install though.Rob, I'm having some issues with
make dt_binding_check. I updated dt- schema and I get this when run it:
Quoted 7 lines
...
"ruamel.yaml.constructor.DuplicateKeyError: while constructing a mapping
in "<unicode string>", line 4, column 1
found duplicate key "patternProperties" with value "{}" (original
value: "{}")
in "<unicode string>", line 113, column 1"
Simply drop all but the first 'patternProperties'. You can have multiple patterns under one.
Quoted 11 lines
If you want, I can paste the complete traceback in a following email. However I could use
dt-doc-validate Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yamldirectly by doing a manual change indt-doc-validate. I changed the calltesttree = dtschema.load(filename, line_number=line_number, duplicate_keys=False)totesttree = dtschema.load(filename, line_number=line_number, duplicate_keys=True). Is this something already known? I would not be surprised if it is some problem in my environment. However, I even tried this in a clean docker container based on ubuntu 18.04 and got the same behavior.
[...]
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +4
-0+patternProperties: + "^rtd@([2-9]|1[0-9]|20)$": + type: object + description: Represents a rtd sensor which is connected toone of the device channels.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +5
-0+ + properties: + reg: + description: | + The channel number. It can be connected to one of the20 channels of the device.
+ minimum: 2Quoted 8 lines
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ maximum: 20 + maxItems: 1As this is pretty much the same for all child nodes, make a pattern that
matches all child nodes and put this there rather than duplicating it.
Then you only need 'minimum: 2' in the cases needing that.
Quoted 5 lines
I'm not sure I'm following your point here. So it's better to clarify it before sending a v2. Do you mean to add something like:
patternProperties:
"^(thermocouple|diode|rtd|thermistor|adc|rsense)@([1-9]|1[0-9]|20)$"
Just ".*@([1-9]|1[0-9]|20)$" is fine.
Quoted 7 lines
type: object
properties:
reg:
description: |
The channel number. It can be connected to one of the 20
channels of the device.
Quoted 7 lines
minimum: 1 maximum: 20And then, for instance, for a RTD I would have:
patternProperties:
"^rtd@([2-9]|1[0-9]|20)$"
You've already defined the unit-address format above, so '^rtd@.*' would be sufficient here.
Quoted 10 lines
... properties: reg: minimum: 2 ...Would this also make sense, or it's not really necessary?
Yes, makes sense.
Quoted 10 lines
patternProperties:
"^thermocouple@([1-9]|1[0-9]|20)$"
type: object...
properties:
reg:
description: For differential thermocouples, the minimum is 2.
Why do you have a constraint in free form text here?
Quoted 39 lines
...Am I understanding it correctly?
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +12
-0+thermistor + adi,sensor-type: + description: | + Identifies the type of RTD connected to the device. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [10 11 12 13 14 15 16 17] + maxItems: 1 + + adi,rsense-handle: + description: | + Phandle pointing to a rsense object associated withthis RTD.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +6
-0+ $ref: "/schemas/types.yaml#/definitions/phandle" + maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration. Lookat table 28 of the
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +6
-0+ datasheet for how to set this value for RTD's. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 4 5 8 9 10 12 13 14] + maxItems: 1 +Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +3
-0+ adi,excitation-current: + description: | + This property controls the magnitude of the excitationcurrent applied
+ to the RTD. Look at table 29 of the datasheet for more
info.Any way we can make this real units? Can list valid value here.
Quoted 5 lines
For RTD's and diodes, it is possible to have it with real units. However, for thermistors it's not really doable since, for instance, for them we have an "Auto Range" setting. So, I just wanted to be consistent through all sensors having excitation-current configuration. Do you prefer to have it in real units where possible?
That's the preference if it makes sense. I have no idea what an RTD is to comment further.
Rob
Sa, Nuno
maintainerRe: [PATCH 2/2] dt-bindings: iio: Add ltc2983 documentation
Quoted 98 lines · Rob Herring
Quoted 88 lines · Nuno
Hi Rob and Jonathan,
Some comments/questions inline.
Nuno Sá
Quoted 72 lines · Jonathan Cameron
Quoted 69 lines · On Fri, 13 Sep 2019 15:36:21 +0100 Rob Herring <[email protected]> wrote:
Quoted 63 lines · Nuno Sá
Document the LTC2983 temperature sensor devicetree bindings.
Signed-off-by Nuno Sá <[email protected]>--- .../bindings/iio/temperature/adi,ltc2983.yaml | 442 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 443 insertions(+) create mode 100644
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yam
ldiff --git a/Documentation/devicetree/bindings/iio/temperature/adi,ltc29 83.y
aml b/Documentation/devicetree/bindings/iio/temperature/adi,ltc29 83.y
aml
new file mode 100644
index 000000000000..2b468b3ed177
---/dev/null
+++
b/Documentation/devicetree/bindings/iio/temperature/adi,ltc29 83.y
amlDocumentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +4
-0@@ -0,0 +1,442 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id:http://devicetree.org/schemas/iio/temperature/adi,ltc2983.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#(quoted diff) +2
-0+ +title: Analog Devices LTC2983 Multi-sensor Temperaturesystem
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +6
-0+ +maintainers: + - Nuno Sá <[email protected]> + +description: | + Analog Devices LTC2983 Multi-Sensor Digital TemperatureMeasurement System
+
https://www.analog.com/media/en/technical-documentation/data-sheets/2983fc.pdfDocumentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +15
-0+ +properties: + compatible: + enum: + - adi,ltc2983 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + adi,temperature-celcius: + description: + If this property is present, the temperature isreported
in Celsius.Review
Quoted 2 lines
(quoted diff) +2
-0+ type: boolean + maxItems: 1It's a boolean, not an array so 'maxItems' doesn't make sense.
Quoted 4 lines
Quoted 4 lines
Running 'make
dt_binding_check' should tell you this. You may need
to
update dt-schema install though.Rob, I'm having some issues with
make dt_binding_check. I updated dt-
schema and I get this when run it:Quoted 7 lines
...
"ruamel.yaml.constructor.DuplicateKeyError: while constructing a mapping
in "<unicode string>", line 4, column 1
found duplicate key "patternProperties" with value "{}" (original
value: "{}")
in "<unicode string>", line 113, column 1"
Quoted 3 lines
Simply drop all but the first 'patternProperties'. You can have multiple patterns under one.
Ok, got it.
Quoted 60 lines
Quoted 12 lines
If you want, I can paste the complete traceback in a following email.
However I could usedt-doc-validate Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yamldirectly by doing a manual change indt-doc-validate. I changed the
calltesttree = dtschema.load(filename, line_number=line_number, duplicate_keys=False)totesttree = dtschema.load(filename, line_number=line_number, duplicate_keys=True). Is this something already known? I would not be surprised if it is some problem in my environment. However, I even tried this in a clean docker container based on ubuntu 18.04 and got the same behavior.[...]
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +4
-0+patternProperties: + "^rtd@([2-9]|1[0-9]|20)$": + type: object + description: Represents a rtd sensor which is connectedto
one of the device channels.Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +5
-0+ + properties: + reg: + description: | + The channel number. It can be connected to one ofthe
20 channels of the device.Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +3
-0+ minimum: 2 + maximum: 20 + maxItems: 1Quoted 8 lines
Quoted 8 lines
As this is pretty much the same for all child nodes, make a pattern
that
matches all child nodes and put this there rather than duplicating
it.
Then you only need 'minimum: 2' in the cases needing that.Quoted 7 lines
I'm not sure I'm following your point here. So it's better to clarify
it before sending a v2. Do you mean to add something like:patternProperties:
"^(thermocouple|diode|rtd|thermistor|adc|rsense)@([1-9]|1[0-
9]|20)$"Just ".*@([1-9]|1[0-9]|20)$" is fine.
Quoted 10 lines
type: object
properties:
reg:
description: |
The channel number. It can be connected to one of the 20
channels of the device.minimum: 1 maximum: 20
Quoted 7 lines
Quoted 4 lines
And then, for instance, for a RTD I would have:
patternProperties:
"^rtd@([2-9]|1[0-9]|20)$"You've already defined the unit-address format above, so '^rtd@.*' would be sufficient here.
Ack.
Quoted 16 lines
Quoted 9 lines
... properties: reg: minimum: 2 ...Would this also make sense, or it's not really necessary?
Yes, makes sense.
Quoted 4 lines
patternProperties:
"^thermocouple@([1-9]|1[0-9]|20)$"
type: object
Quoted 8 lines
Quoted 6 lines
...
properties:
reg:
description: For differential thermocouples, the minimum is
2.Why do you have a constraint in free form text here?
There are sensors (like thermocouples) which can be configured as differential or single-ended. Depending on that the 'reg' minimum value is 1 or 2. The text was only giving a *note* on that. However I guess I can just drop it.
Quoted 51 lines
Quoted 43 lines
...Am I understanding it correctly?
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +4
-0+thermistor + adi,sensor-type: + description: | + Identifies the type of RTD connected to thedevice.
Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +8
-0+ allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [10 11 12 13 14 15 16 17] + maxItems: 1 + + adi,rsense-handle: + description: | + Phandle pointing to a rsense object associatedwith
this RTD.Documentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +6
-0+ $ref: "/schemas/types.yaml#/definitions/phandle" + maxItems: 1 + + adi,sensor-config: + description: | + Raw value which set's the sensor configuration.Look
at table 28 of theDocumentation/devicetree/bindings/iio/temperature/adi,ltc2983.yaml new file +8
-0+ datasheet for how to set this value for RTD's. + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - enum: [0 1 4 5 8 9 10 12 13 14] + maxItems: 1 + + adi,excitation-current: + description: |Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
+ This property controls the magnitude of the
excitation
current applied
+ to the RTD. Look at table 29 of the datasheet for
more
info.Any way we can make this real units? Can list valid value here.
Quoted 7 lines
For RTD's and diodes, it is possible to have it with real units. However, for thermistors it's not really doable since, for instance,
for them we have an "Auto Range" setting. So, I just wanted to be consistent through all sensors having excitation-current configuration.
Do you prefer to have it in real units where possible?
Quoted 3 lines
That's the preference if it makes sense. I have no idea what an RTD is
to comment further.
Ack. I will come up with some proposal for this on v2.
Quoted 1 line
Rob
Jonathan Cameron
maintainerQuoted 8 lines · On Mon, 9 Sep 2019 16:45:49 +0200 Nuno Sá <[email protected]> wrote:
The LTC2983 is a Multi-Sensor High Accuracy Digital Temperature Measurement System. It measures a wide variety of temperature sensors and digitally outputs the result, in °C or °F, with 0.1°C accuracy and 0.001°C resolution. It can measure the temperature of all standard thermocouples (type B,E,J,K,N,S,R,T), standard 2-,3-,4-wire RTDs, thermistors and diodes.
Signed-off-by Nuno Sá <[email protected]>
Some comments inline. Main concern is around the interface, rest is minor stuff.
Jonathan
Quoted 16 lines
--- .../testing/sysfs-bus-iio-temperature-ltc2983 | 43 + MAINTAINERS | 7 + drivers/iio/temperature/Kconfig | 10 + drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/ltc2983.c | 1327 +++++++++++++++++ 5 files changed, 1388 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 create mode 100644 drivers/iio/temperature/ltc2983.cDocumentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +0
-0
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 line 1
Quoted 1 line
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +1
-0@@ -0,0 +1,43 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_tempY_thermistor_raw
For each of these, I presume we know which type of device is attached at any time? Using the channel naming to convey this (and I assume the fact that different conversions need to be done in userspace?) is a bit messy. If we need to convey the channel type, then a separate in_tempY_mode attribute may make more sense. That would keep this ABI 'closer' to standard. Software that just logs an unprocessed value could just work for example.
I'm not sure I've totally understood what is going on here though.
Quoted 32 lines
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +32
-0+KernelVersion: +Contact: [email protected] +Description: + Reads the raw (unscaled no bias removal etc) temperature from + channel Y. The value is returned by a Thermistor sensor measurement. + Units after application of scale are degrees Celsius or Fahrenheit + depending on the device configuration. + +What: /sys/bus/iio/devices/iio:deviceX/in_tempY_thermocouple_raw +KernelVersion: +Contact: [email protected] +Description: + Reads the raw (unscaled no bias removal etc) temperature from + channel Y. The value is returned by a Thermocouple sensor measurement. + Units after application of scale are degrees Celsius or Fahrenheit + depending on the device configuration. + +What: /sys/bus/iio/devices/iio:deviceX/in_tempY_rtd_raw +KernelVersion: +Contact: [email protected] +Description: + Reads the raw (unscaled no bias removal etc) temperature from + channel Y. The value is returned by a RTD sensor measurement. + Units after application of scale are degrees Celsius or Fahrenheit + depending on the device configuration. + +What: /sys/bus/iio/devices/iio:deviceX/in_tempY_diode_raw +KernelVersion: +Contact: [email protected] +Description: + Reads the raw (unscaled no bias removal etc) temperature from + channel Y. The value is returned by a Diode sensor measurement.
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 line 43
Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +10
-0+ Units after application of scale are degrees Celsius or Fahrenheit + depending on the device configuration. + +What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_direct_adc_raw +KernelVersion: +Contact: [email protected] +Description: + Reads the raw (unscaled no bias removal etc) voltage from + channel Y. The value is returned by a direct ADC measurement. + Units after application of scale are Volts.
What is the extended name adding?
in_voltageY_raw already tells you it's the raw voltage from channel y.
Quoted 682 lines
MAINTAINERS +7
-0@@ -9491,6 +9491,13 @@ S: Maintained F: Documentation/devicetree/bindings/iio/dac/ltc1660.txt F: drivers/iio/dac/ltc1660.c +LTC2983 IIO TEMPERATURE DRIVER +M: Nuno Sá <[email protected]> +W: http://ez.analog.com/community/linux-device-drivers +L: [email protected] +S: Supported +F: drivers/iio/temperature/ltc2983.c + LTC4261 HARDWARE MONITOR DRIVER M: Guenter Roeck <[email protected]> L: [email protected]drivers/iio/temperature/Kconfig +10
-0@@ -4,6 +4,16 @@ # menu "Temperature sensors" +config LTC2983 + tristate "Analog Devices Multi-Sensor Digital Temperature Measurement System" + depends on SPI + help + Say yes here to build support for the LTC2983 Multi-Sensor + high accuracy digital temperature measurement system. + + To compile this driver as a module, choose M here: the module + will be called ltc2983. + config MAXIM_THERMOCOUPLE tristate "Maxim thermocouple sensors" depends on SPIdrivers/iio/temperature/Makefile +1
-0@@ -3,6 +3,7 @@ # Makefile for industrial I/O temperature drivers # +obj-$(CONFIG_LTC2983) += ltc2983.o obj-$(CONFIG_HID_SENSOR_TEMP) += hid-sensor-temperature.o obj-$(CONFIG_MAXIM_THERMOCOUPLE) += maxim_thermocouple.o obj-$(CONFIG_MAX31856) += max31856.odrivers/iio/temperature/ltc2983.c new file +625
-0@@ -0,0 +1,1327 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Analog Devices LTC2983 Multi-Sensor Digital Temperature Measurement System +* driver +* +* Copyright 2019 Analog Devices Inc. +*/ +#include <linux/bitfield.h> +#include <linux/completion.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/iio/iio.h> +#include <linux/interrupt.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/of_gpio.h> +#include <linux/regmap.h> +#include <linux/spi/spi.h> + +/* register map */ +#define LTC2983_STATUS_REG 0x0000 +#define LTC2983_TEMP_RES_START_REG 0x0010 +#define LTC2983_TEMP_RES_END_REG 0x005F +#define LTC2983_GLOBAL_CONFIG_REG 0x00F0 +#define LTC2983_MULT_CHANNEL_START_REG 0x00F4 +#define LTC2983_MULT_CHANNEL_END_REG 0x00F7 +#define LTC2983_MUX_CONFIG_REG 0x00FF +#define LTC2983_CHAN_ASSIGN_START_REG 0x0200 +#define LTC2983_CHAN_ASSIGN_END_REG 0x024F +#define LTC2983_CUST_SENS_TBL_START_REG 0x0250 +#define LTC2983_CUST_SENS_TBL_END_REG 0x03CF + +#define LTC2983_DIFFERENTIAL_CHAN_MIN 2 +#define LTC2983_MAX_CHANNELS_NR 20 +#define LTC2983_MIN_CHANNELS_NR 1 +#define LTC2983_SLEEP 0x97 +#define LTC2983_CUSTOM_STEINHART_SIZE 24 +#define LTC2983_CUSTOM_SENSOR_ENTRY_SZ 6 +#define LTC2983_CUSTOM_STEINHART_ENTRY_SZ 4 + +#define LTC2983_CHAN_START_ADDR (chan) \ + (((chan - 1) * 4) + LTC2983_CHAN_ASSIGN_START_REG) +#define LTC2983_CHAN_RES_ADDR (chan) \ + (((chan - 1) * 4) + LTC2983_TEMP_RES_START_REG) +#define LTC2983_THERMOCOUPLE_DIFF_MASK BIT(3) +#define LTC2983_THERMISTOR_DIFF_MASK BIT(2) +#define LTC2983_DIODE_DIFF_MASK BIT(2) +#define LTC2983_RTD_4_WIRE_MASK BIT(3) +#define LTC2983_RTD_ROTATION_MASK BIT(1) +#define LTC2983_RTD_KELVIN_R_SENSE_MASK GENMASK(3, 2) + +#define LTC2983_COMMON_HARD_FAULT_MASK GENMASK(31, 30) +#define LTC2983_COMMON_SOFT_FAULT_MASK GENMASK(27, 25) + +#define LTC2983_STATUS_START_MASK BIT(7) +#define LTC2983_STATUS_START (x) FIELD_PREP(LTC2983_STATUS_START_MASK, x) + +#define LTC2983_STATUS_CHAN_SEL_MASK GENMASK(4, 0) +#define LTC2983_STATUS_CHAN_SEL (x) \ + FIELD_PREP(LTC2983_STATUS_CHAN_SEL_MASK, x) + +#define LTC2983_TEMP_UNITS_MASK BIT(2) +#define LTC2983_TEMP_UNITS (x) FIELD_PREP(LTC2983_TEMP_UNITS_MASK, x) + +#define LTC2983_NOTCH_FREQ_MASK GENMASK(1, 0) +#define LTC2983_NOTCH_FREQ (x) FIELD_PREP(LTC2983_NOTCH_FREQ_MASK, x) + +#define LTC2983_RES_VALID_MASK BIT(24) +#define LTC2983_DATA_MASK GENMASK(23, 0) +#define LTC2983_DATA_SIGN_BIT 23 + +#define LTC2983_CHAN_TYPE_MASK GENMASK(31, 27) +#define LTC2983_CHAN_TYPE (x) FIELD_PREP(LTC2983_CHAN_TYPE_MASK, x) + +/* cold junction for thermocouples and rsense for rtd's and thermistor's */ +#define LTC2983_CHAN_ASSIGN_MASK GENMASK(26, 22) +#define LTC2983_CHAN_ASSIGN (x) FIELD_PREP(LTC2983_CHAN_ASSIGN_MASK, x) + +#define LTC2983_CUSTOM_LEN_MASK GENMASK(5, 0) +#define LTC2983_CUSTOM_LEN (x) FIELD_PREP(LTC2983_CUSTOM_LEN_MASK, x) + +#define LTC2983_CUSTOM_ADDR_MASK GENMASK(11, 6) +#define LTC2983_CUSTOM_ADDR (x) FIELD_PREP(LTC2983_CUSTOM_ADDR_MASK, x) + +#define LTC2983_THERMOCOUPLE_CFG_MASK GENMASK(21, 18) +#define LTC2983_THERMOCOUPLE_CFG (x) \ + FIELD_PREP(LTC2983_THERMOCOUPLE_CFG_MASK, x) +#define LTC2983_THERMOCOUPLE_HARD_FAULT_MASK GENMASK(31, 29) +#define LTC2983_THERMOCOUPLE_SOFT_FAULT_MASK GENMASK(28, 25) + +#define LTC2983_RTD_CFG_MASK GENMASK(21, 18) +#define LTC2983_RTD_CFG (x) FIELD_PREP(LTC2983_RTD_CFG_MASK, x) +#define LTC2983_RTD_EXC_CURRENT_MASK GENMASK(17, 14) +#define LTC2983_RTD_EXC_CURRENT (x) \ + FIELD_PREP(LTC2983_RTD_EXC_CURRENT_MASK, x) +#define LTC2983_RTD_CURVE_MASK GENMASK(13, 12) +#define LTC2983_RTD_CURVE (x) FIELD_PREP(LTC2983_RTD_CURVE_MASK, x) + +#define LTC2983_THERMISTOR_CFG_MASK GENMASK(21, 19) +#define LTC2983_THERMISTOR_CFG (x) \ + FIELD_PREP(LTC2983_THERMISTOR_CFG_MASK, x) +#define LTC2983_THERMISTOR_EXC_CURRENT_MASK GENMASK(18, 15) +#define LTC2983_THERMISTOR_EXC_CURRENT (x) \ + FIELD_PREP(LTC2983_THERMISTOR_EXC_CURRENT_MASK, x) + +#define LTC2983_DIODE_CFG_MASK GENMASK(26, 24) +#define LTC2983_DIODE_CFG (x) FIELD_PREP(LTC2983_DIODE_CFG_MASK, x) +#define LTC2983_DIODE_EXC_CURRENT_MASK GENMASK(23, 22) +#define LTC2983_DIODE_EXC_CURRENT (x) \ + FIELD_PREP(LTC2983_DIODE_EXC_CURRENT_MASK, x) +#define LTC2983_DIODE_IDEAL_FACTOR_MASK GENMASK(21, 0) +#define LTC2983_DIODE_IDEAL_FACTOR (x) \ + FIELD_PREP(LTC2983_DIODE_IDEAL_FACTOR_MASK, x) + +#define LTC2983_R_SENSE_VAL_MASK GENMASK(26, 0) +#define LTC2983_R_SENSE_VAL (x) FIELD_PREP(LTC2983_R_SENSE_VAL_MASK, x) + +#define LTC2983_ADC_SINGLE_ENDED_MASK BIT(26) +#define LTC2983_ADC_SINGLE_ENDED (x) \ + FIELD_PREP(LTC2983_ADC_SINGLE_ENDED_MASK, x) + +enum { +LTC2983_SENSOR_THERMOCOUPLE =1 , +LTC2983_SENSOR_THERMOCOUPLE_CUSTOM =9 , +LTC2983_SENSOR_RTD =10 , +LTC2983_SENSOR_RTD_CUSTOM =18 , +LTC2983_SENSOR_THERMISTOR =19 , +LTC2983_SENSOR_THERMISTOR_STEINHART =26 , +LTC2983_SENSOR_THERMISTOR_CUSTOM =27 , +LTC2983_SENSOR_DIODE =28 , +LTC2983_SENSOR_SENSE_RESISTOR =29 , +LTC2983_SENSOR_DIRECT_ADC =30 , +}; + +#define to_thermocouple (_sensor) \ + container_of(_sensor, struct ltc2983_thermocouple, sensor) + +#define to_rtd (_sensor) \ + container_of(_sensor, struct ltc2983_rtd, sensor) + +#define to_thermistor (_sensor) \ + container_of(_sensor, struct ltc2983_thermistor, sensor) + +#define to_diode (_sensor) \ + container_of(_sensor, struct ltc2983_diode, sensor) + +#define to_rsense (_sensor) \ + container_of(_sensor, struct ltc2983_rsense, sensor) + +#define to_adc (_sensor) \ + container_of(_sensor, struct ltc2983_adc, sensor) + +struct ltc2983_data { +struct regmap *regmap; +struct spi_device *spi; +struct mutex lock; +struct completion completion; +struct iio_chan_spec *iio_chan; +struct ltc2983_sensor **sensors; +u32 mux_delay_config; +u32 filter_notch_freq; +u16 custom_table_size; +u8 num_channels; +u8 iio_channels; +bool temp_farenheit; +bool reset; +}; + +struct ltc2983_sensor { +int (*fault_handler)(const struct ltc2983_data *st,const u32 result); +int (*assign_chan)(struct ltc2983_data *st, +const struct ltc2983_sensor *sensor); +const char *name; +/* specifies the sensor channel */ +u32 chan; +/* sensor type */ +u32 type; +}; + +struct ltc2983_custom_sensor { +/* raw table sensor data */ +u8 *table; +size_t size; +/* address offset */ +s8 offset; +bool is_steinhart; +}; + +struct ltc2983_thermocouple { +struct ltc2983_sensor sensor; +struct ltc2983_custom_sensor *custom; +u32 sensor_config; +u32 cold_junction_chan; +}; + +struct ltc2983_rtd { +struct ltc2983_sensor sensor; +struct ltc2983_custom_sensor *custom; +u32 sensor_config; +u32 r_sense_chan; +u32 excitation_current; +u32 rtd_curve; +}; + +struct ltc2983_thermistor { +struct ltc2983_sensor sensor; +struct ltc2983_custom_sensor *custom; +u32 sensor_config; +u32 r_sense_chan; +u32 excitation_current; +}; + +struct ltc2983_diode { +struct ltc2983_sensor sensor; +u32 sensor_config; +u32 excitation_current; +u32 ideal_factor_value; +}; + +struct ltc2983_rsense { +struct ltc2983_sensor sensor; +u32 r_sense_val; +}; + +struct ltc2983_adc { +struct ltc2983_sensor sensor; +bool single_ended; +}; + +/* +* Convert to Q format numbers. These number's are integers where +* the number of integer and fractional bits are specified. The resolution +* is given by 1/@resolution and tell us the number of fractional bits. For +* instance a resolution of 2^-10 means we have 10 fractional bits. +*/ +static u32 __convert_to_raw (const u64 val,const u32 resolution) +{ +u64 __res = val * resolution; + +/* all values are multiplied by 1000000 to remove the fraction */ +do_div (__res,1000000 ); + +return __res; +} + +static u32 __convert_to_raw_sign (const u64 val,const u32 resolution) +{ +s64 __res = -(s32 )val; + + __res =__convert_to_raw (__res, resolution); + +return (u32)-__res; +} + +static int __ltc2983_fault_handler (const struct ltc2983_data *st, +const u32 result,const u32 hard_mask, +const u32 soft_mask) +{ +const struct device *dev = &st->spi->dev; + +if (result & hard_mask) { +dev_err (dev,"Invalid conversion: Sensor HARD fault\n" ); +return -EIO ; + }else if (result & soft_mask) { +/* just print a warning */ +dev_warn (dev,"Suspicious conversion: Sensor SOFT fault\n" ); + } + +return 0 ; +} + +static int __ltc2983_chan_assign_common (const struct ltc2983_data *st, +const struct ltc2983_sensor *sensor, +u32 chan_val) +{ +u32 reg =LTC2983_CHAN_START_ADDR (sensor->chan); +__be32 __chan_val; + + chan_val |=LTC2983_CHAN_TYPE (sensor->type); +dev_dbg (&st->spi->dev,"Assign %s, reg:0x%04X, val:0x%08X\n" , + sensor->name, + reg, chan_val); + __chan_val =cpu_to_be32 (chan_val); +return regmap_bulk_write (st->regmap, reg, &__chan_val, +sizeof (__chan_val)); +} + +static int __ltc2983_chan_custom_sensor_assign (struct ltc2983_data *st, +struct ltc2983_custom_sensor *custom, +u32 *chan_val) +{ +u32 reg; +u8 mult = custom->is_steinhart ?LTC2983_CUSTOM_STEINHART_ENTRY_SZ : +LTC2983_CUSTOM_SENSOR_ENTRY_SZ ; +const struct device *dev = &st->spi->dev; +/* +* custom->size holds the raw size of the table. However, when +* configuring the sensor channel, we must write the number of +* entries of the table minus 1. For steinhart sensors 0 is written +* since the size is constant! +*/ +const u8 len = custom->is_steinhart ?0 : + (custom->size /LTC2983_CUSTOM_SENSOR_ENTRY_SZ ) -1 ; +/* +* Check if the offset was assigned already. It should be for steinhart +* sensors. When coming from sleep, it should be assigned for all. +*/ +if (custom->offset <0 ) { +/* +* This needs to be done again here because, from the moment +* when this test was done (successfully) for this custom +* sensor, a steinhart sensor might have been added changing +* custom_table_size... +*/ +if (st->custom_table_size + custom->size > + (LTC2983_CUST_SENS_TBL_END_REG - +LTC2983_CUST_SENS_TBL_START_REG ) +1 ) { +dev_err (dev, +"Not space left(%d) for new custom sensor(%zu)" , + st->custom_table_size, + custom->size); +return -EINVAL ; + } + + custom->offset = st->custom_table_size / +LTC2983_CUSTOM_SENSOR_ENTRY_SZ ; + st->custom_table_size += custom->size; + } + + reg = (custom->offset * mult) +LTC2983_CUST_SENS_TBL_START_REG ; + + *chan_val |=LTC2983_CUSTOM_LEN (len); + *chan_val |=LTC2983_CUSTOM_ADDR (custom->offset); +dev_dbg (dev,"Assign custom sensor, reg:0x%04X, off:%d, sz:%zu" , + reg, custom->offset, + custom->size); +/* write custom sensor table */ +return regmap_bulk_write (st->regmap, reg, custom->table, custom->size); +} + +static struct ltc2983_custom_sensor *__ltc2983_custom_sensor_new ( +struct ltc2983_data *st, +const struct device_node *np, +const bool is_steinhart, +const u32 resolution, +const bool has_signed) +{ +struct ltc2983_custom_sensor *new_custom; +u8 index, n_entries, tbl =0 ; +struct device *dev = &st->spi->dev; +/* +* For custom steinhart, the full u32 is taken. For all the others +* the MSB is discarded. +*/ +const u8 n_size = (is_steinhart == true) ?4 :3 ; + + n_entries =of_property_count_elems_of_size (np,"adi,custom-sensor" , +sizeof (u64)); +/* n_entries must be an even number */ +if (!n_entries || (n_entries %2 ) !=0 ) { +dev_err (dev,"Number of entries either 0 or not even\n" ); +return ERR_PTR (-EINVAL ); + } + + new_custom =devm_kzalloc (dev,sizeof (*new_custom),GFP_KERNEL ); +if (!new_custom) +return ERR_PTR (-ENOMEM ); + + new_custom->size = n_entries * n_size; +/* check Steinhart size */ +if (is_steinhart && new_custom->size !=LTC2983_CUSTOM_STEINHART_SIZE ) { +dev_err (dev,"Steinhart sensors size(%zu) must be 24" , + new_custom->size); +return ERR_PTR (-EINVAL ); + } +/* Check space on the table. */ +if (st->custom_table_size + new_custom->size > + (LTC2983_CUST_SENS_TBL_END_REG - +LTC2983_CUST_SENS_TBL_START_REG ) +1 ) { +dev_err (dev,"No space left(%d) for new custom sensor(%zu)" , + st->custom_table_size, new_custom->size); +return ERR_PTR (-EINVAL ); + } + +/* allocate the table */ + new_custom->table =devm_kzalloc (dev, new_custom->size,GFP_KERNEL ); +if (!new_custom->table) +return ERR_PTR (-ENOMEM ); + +for (index =0 ; index < n_entries; index++) { +u64 temp =0 , j; + +of_property_read_u64_index (np,"adi,custom-sensor" , index, + &temp); +/* +* Steinhart sensors are configured with raw values in the +* devicetree. For the other sensors we must convert the +* value to raw. The odd index's correspond to temperarures +* and always have 1/1024 of resolution. Temperatures also +* come in kelvin, so signed values is not possible +*/ +if (!is_steinhart) { +if ((index %2 ) !=0 ) + temp =__convert_to_raw (temp,1024 ); +else if (has_signed && (s64 )temp <0 ) + temp =__convert_to_raw_sign (temp, resolution); +else + temp =__convert_to_raw (temp, resolution); + } + +for (j =0 ; j < n_size; j++) + new_custom->table[tbl++] = + temp >> (8 * (n_size - j -1 )); + } + + new_custom->is_steinhart = is_steinhart; +/* +* This is done to first add all the steinhart sensors to the table, +* in order to maximize the table usage. If we mix adding steinhart +* with the other sensors, we might have to do some roundup to make +* sure that sensor_addr - 0x250(start address) is a multiple of 4 +* (for steinhart), and a multiple of 6 for all the other sensors. +* Since we have const 24 bytes for steinhart sensors and 24 is +* also a multiple of 6, we guarantee that the first non-steinhart +* sensor will sit in a correct address without the need of filling +* addresses. +*/ +if (is_steinhart) { + new_custom->offset = st->custom_table_size / +LTC2983_CUSTOM_STEINHART_ENTRY_SZ ; + st->custom_table_size += new_custom->size; + }else { +/* mark as unset. This is checked later on the assign phase */ + new_custom->offset =-1 ; + } + +return new_custom; +} + +static int ltc2983_thermocouple_fault_handler (const struct ltc2983_data *st, +const u32 result) +{ +return __ltc2983_fault_handler (st, result, +LTC2983_THERMOCOUPLE_HARD_FAULT_MASK , +LTC2983_THERMOCOUPLE_SOFT_FAULT_MASK ); +} + +static int ltc2983_common_fault_handler (const struct ltc2983_data *st, +const u32 result) +{ +return __ltc2983_fault_handler (st, result, +LTC2983_COMMON_HARD_FAULT_MASK , +LTC2983_COMMON_SOFT_FAULT_MASK ); +} + +static int ltc2983_thermocouple_assign_chan (struct ltc2983_data *st, +const struct ltc2983_sensor *sensor) +{ +struct ltc2983_thermocouple *thermo =to_thermocouple (sensor); +u32 chan_val; + + chan_val =LTC2983_CHAN_ASSIGN (thermo->cold_junction_chan); + chan_val |=LTC2983_THERMOCOUPLE_CFG (thermo->sensor_config); + +if (thermo->custom) { +int ret; + + ret =__ltc2983_chan_custom_sensor_assign (st, thermo->custom, + &chan_val); +if (ret) +return ret; + } +return __ltc2983_chan_assign_common (st, sensor, chan_val); +} + +static int ltc2983_rtd_assign_chan (struct ltc2983_data *st, +const struct ltc2983_sensor *sensor) +{ +struct ltc2983_rtd *rtd =to_rtd (sensor); +u32 chan_val; + + chan_val =LTC2983_CHAN_ASSIGN (rtd->r_sense_chan); + chan_val |=LTC2983_RTD_CFG (rtd->sensor_config); + chan_val |=LTC2983_RTD_EXC_CURRENT (rtd->excitation_current); + chan_val |=LTC2983_RTD_CURVE (rtd->rtd_curve); + +if (rtd->custom) { +int ret; + + ret =__ltc2983_chan_custom_sensor_assign (st, rtd->custom, + &chan_val); +if (ret) +return ret; + } +return __ltc2983_chan_assign_common (st, sensor, chan_val); +} + +static int ltc2983_thermistor_assign_chan (struct ltc2983_data *st, +const struct ltc2983_sensor *sensor) +{ +struct ltc2983_thermistor *thermistor =to_thermistor (sensor); +u32 chan_val; + + chan_val =LTC2983_CHAN_ASSIGN (thermistor->r_sense_chan); + chan_val |=LTC2983_THERMISTOR_CFG (thermistor->sensor_config); + chan_val |= +LTC2983_THERMISTOR_EXC_CURRENT (thermistor->excitation_current); + +if (thermistor->custom) { +int ret; + + ret =__ltc2983_chan_custom_sensor_assign (st, + thermistor->custom, + &chan_val); +if (ret) +return ret; + } +return __ltc2983_chan_assign_common (st, sensor, chan_val); +} + +static int ltc2983_diode_assign_chan (struct ltc2983_data *st, +const struct ltc2983_sensor *sensor) +{ +struct ltc2983_diode *diode =to_diode (sensor); +u32 chan_val; + + chan_val =LTC2983_DIODE_CFG (diode->sensor_config); + chan_val |=LTC2983_DIODE_EXC_CURRENT (diode->excitation_current); + chan_val |=LTC2983_DIODE_IDEAL_FACTOR (diode->ideal_factor_value); + +return __ltc2983_chan_assign_common (st, sensor, chan_val); +} + +static int ltc2983_r_sense_assign_chan (struct ltc2983_data *st, +const struct ltc2983_sensor *sensor) +{ +struct ltc2983_rsense *rsense =to_rsense (sensor); +u32 chan_val; + + chan_val =LTC2983_R_SENSE_VAL (rsense->r_sense_val); + +return __ltc2983_chan_assign_common (st, sensor, chan_val); +} + +static int ltc2983_adc_assign_chan (struct ltc2983_data *st, +const struct ltc2983_sensor *sensor) +{ +struct ltc2983_adc *adc =to_adc (sensor); +u32 chan_val; + + chan_val =LTC2983_ADC_SINGLE_ENDED (adc->single_ended); + +return __ltc2983_chan_assign_common (st, sensor, chan_val); +} + +static struct ltc2983_sensor *ltc2983_thermocouple_new ( +const struct device_node *child, +struct ltc2983_data *st, +const struct ltc2983_sensor *sensor) +{ +struct ltc2983_thermocouple *thermo; +struct device_node *phandle; + + thermo =devm_kzalloc (&st->spi->dev,sizeof (*thermo),GFP_KERNEL ); +if (!thermo) +return ERR_PTR (-ENOMEM ); + +of_property_read_u32 (child,"adi,sensor-config" , + &thermo->sensor_config); +/* validate channel index */ +if (!(thermo->sensor_config <C2983_THERMOCOUPLE_DIFF_MASK ) && + sensor->chan <LTC2983_DIFFERENTIAL_CHAN_MIN ) { +dev_err (&st->spi->dev, +"Invalid chann:%d for differential thermocouple" , + sensor->chan); +return ERR_PTR (-EINVAL ); + } + + phandle =of_parse_phandle (child,"adi,cold-junction-handle" ,0 ); +if (phandle) { +int ret; + + ret =of_property_read_u32 (phandle,"reg" , + &thermo->cold_junction_chan); +if (ret) { +/* +* This would be catched later but we can just return +* the error right away. +*/ +dev_err (&st->spi->dev,"Property reg must be given\n" ); +of_node_put (phandle); +return ERR_PTR (-EINVAL ); + } + } + +/* check custom sensor */ +if (sensor->type ==LTC2983_SENSOR_THERMOCOUPLE_CUSTOM ) { + thermo->custom =__ltc2983_custom_sensor_new (st, child, false, +16384 , true); +if (IS_ERR (thermo->custom)) { +of_node_put (phandle); +return ERR_CAST (thermo->custom); + } + } + +/* set common parameters */ + thermo->sensor.name ="thermocouple" ; + thermo->sensor.fault_handler = ltc2983_thermocouple_fault_handler; + thermo->sensor.assign_chan = ltc2983_thermocouple_assign_chan; + +of_node_put (phandle); +return &thermo->sensor; +} + +static struct ltc2983_sensor *ltc2983_rtd_new (const struct device_node *child, +struct ltc2983_data *st, +const struct ltc2983_sensor *sensor) +{ +struct ltc2983_rtd *rtd; +int ret =0 ; +struct device *dev = &st->spi->dev; +struct device_node *phandle; + + rtd =devm_kzalloc (dev,sizeof (*rtd),GFP_KERNEL ); +if (!rtd)
drivers/iio/temperature/ltc2983.c line 635
Quoted 10 lines
drivers/iio/temperature/ltc2983.c new file +10
-0+return ERR_PTR (-ENOMEM ); + + phandle =of_parse_phandle (child,"adi,rsense-handle" ,0 ); +if (!phandle) { +dev_err (dev,"Property adi,rsense-handle missing or invalid" ); +return ERR_PTR (-EINVAL ); + } + + ret =of_property_read_u32 (phandle,"reg" , + &rtd->r_sense_chan);
Doesn't look like that lines needs wrapping. Check for similar elsewhere.
Quoted 286 lines
drivers/iio/temperature/ltc2983.c new file +286
-0+if (ret) { +dev_err (dev,"Property reg must be given\n" ); + goto fail; + } + +of_property_read_u32 (child,"adi,sensor-config" , &rtd->sensor_config); +/* +* rtd channel indexes are a bit more complicated to validate. +* For 4wire RTD with rotation, the channel selection cannot be +* >=19 since the chann + 1 is used in this configuration. +* For 4wire RTDs with kelvin rsense, the rsense channel cannot be +* <=1 since chanel - 1 and channel - 2 are used. +*/ +if (rtd->sensor_config <C2983_RTD_4_WIRE_MASK ) { +/* 4-wire */ +u8 min =LTC2983_DIFFERENTIAL_CHAN_MIN , + max =LTC2983_MAX_CHANNELS_NR ; + +if (rtd->sensor_config <C2983_RTD_ROTATION_MASK ) + max =LTC2983_MAX_CHANNELS_NR -1 ; + +if (((rtd->sensor_config <C2983_RTD_KELVIN_R_SENSE_MASK ) + ==LTC2983_RTD_KELVIN_R_SENSE_MASK ) && + (rtd->r_sense_chan <= min)) { +/* kelvin rsense*/ +dev_err (dev, +"Invalid rsense chann:%d to use in kelvin rsense" , + rtd->r_sense_chan); + + ret = -EINVAL ; + goto fail; + } + +if (sensor->chan < min || sensor->chan > max) { +dev_err (dev,"Invalid chann:%d for the rtd config" , + sensor->chan); + + ret = -EINVAL ; + goto fail; + } + }else { +/* same as differential case */ +if (sensor->chan <LTC2983_DIFFERENTIAL_CHAN_MIN ) { +dev_err (&st->spi->dev, +"Invalid chann:%d for RTD" , sensor->chan); + + ret = -EINVAL ; + goto fail; + } + } + +/* check custom sensor */ +if (sensor->type ==LTC2983_SENSOR_RTD_CUSTOM ) { + rtd->custom =__ltc2983_custom_sensor_new (st, child, false, +2048 , false); +if (IS_ERR (rtd->custom)) { +of_node_put (phandle); +return ERR_CAST (rtd->custom); + } + } + +/* set common parameters */ + rtd->sensor.name ="rtd" ; + rtd->sensor.fault_handler = ltc2983_common_fault_handler; + rtd->sensor.assign_chan = ltc2983_rtd_assign_chan; + + ret =of_property_read_u32 (child,"adi,excitation-current" , + &rtd->excitation_current); +if (ret) +/* default to 1uA */ + rtd->excitation_current =1 ; + +of_property_read_u32 (child,"adi,rtd-curve" , &rtd->rtd_curve); + +of_node_put (phandle); +return &rtd->sensor; +fail: +of_node_put (phandle); +return ERR_PTR (ret); +} + +static struct ltc2983_sensor *ltc2983_thermistor_new ( +const struct device_node *child, +struct ltc2983_data *st, +const struct ltc2983_sensor *sensor) +{ +struct ltc2983_thermistor *thermistor; +struct device *dev = &st->spi->dev; +struct device_node *phandle; +int ret =0 ; + + thermistor =devm_kzalloc (dev,sizeof (*thermistor),GFP_KERNEL ); +if (!thermistor) +return ERR_PTR (-ENOMEM ); + + phandle =of_parse_phandle (child,"adi,rsense-handle" ,0 ); +if (!phandle) { +dev_err (dev,"Property adi,rsense-handle missing or invalid" ); +return ERR_PTR (-EINVAL ); + } + + ret =of_property_read_u32 (phandle,"reg" , + &thermistor->r_sense_chan); +if (ret) { +dev_err (dev,"rsense channel must be configured...\n" ); + goto fail; + } + +of_property_read_u32 (child,"adi,sensor-config" , + &thermistor->sensor_config); +/* validate channel index */ +if (!(thermistor->sensor_config <C2983_THERMISTOR_DIFF_MASK ) && + sensor->chan <LTC2983_DIFFERENTIAL_CHAN_MIN ) { +dev_err (&st->spi->dev, +"Invalid chann:%d for differential thermistor" , + sensor->chan); + ret = -EINVAL ; + goto fail; + } + +/* check custom sensor */ +if (sensor->type >=LTC2983_SENSOR_THERMISTOR_STEINHART ) { + thermistor->custom =__ltc2983_custom_sensor_new (st, child, + sensor->type ==LTC2983_SENSOR_THERMISTOR_STEINHART ? + true : false,64 , + false); +if (IS_ERR (thermistor->custom)) { +of_node_put (phandle); +return ERR_CAST (thermistor->custom); + } + } +/* set common parameters */ + thermistor->sensor.name ="thermistor" ; + thermistor->sensor.fault_handler = ltc2983_common_fault_handler; + thermistor->sensor.assign_chan = ltc2983_thermistor_assign_chan; + + ret =of_property_read_u32 (child,"adi,excitation-current" , + &thermistor->excitation_current); +if (ret) +/* default to auto-range */ + thermistor->excitation_current =0x0c ; + +of_node_put (phandle); +return &thermistor->sensor; +fail: +of_node_put (phandle); +return ERR_PTR (ret); +} + +static struct ltc2983_sensor *ltc2983_diode_new ( +const struct device_node *child, +const struct ltc2983_data *st, +const struct ltc2983_sensor *sensor) +{ +struct ltc2983_diode *diode; +u32 temp =0 ; + + diode =devm_kzalloc (&st->spi->dev,sizeof (*diode),GFP_KERNEL ); +if (!diode) +return ERR_PTR (-ENOMEM ); + +of_property_read_u32 (child,"adi,sensor-config" , &diode->sensor_config); +/* validate channel index */ +if (!(diode->sensor_config <C2983_DIODE_DIFF_MASK ) && + sensor->chan <LTC2983_DIFFERENTIAL_CHAN_MIN ) { +dev_err (&st->spi->dev, +"Invalid chann:%d for differential thermistor" , + sensor->chan); +return ERR_PTR (-EINVAL ); + } +/* set common parameters */ + diode->sensor.name ="diode" ; + diode->sensor.fault_handler = ltc2983_common_fault_handler; + diode->sensor.assign_chan = ltc2983_diode_assign_chan; + +of_property_read_u32 (child,"adi,excitation-current" , + &diode->excitation_current); + +of_property_read_u32 (child,"adi,ideal-factor-value" , &temp); + +/* 2^20 resolution */ + diode->ideal_factor_value =__convert_to_raw (temp,1048576 ); + +return &diode->sensor; +} + +static struct ltc2983_sensor *ltc2983_r_sense_new (struct device_node *child, +struct ltc2983_data *st, +const struct ltc2983_sensor *sensor) +{ +struct ltc2983_rsense *rsense; +int ret; +u64 temp; + + rsense =devm_kzalloc (&st->spi->dev,sizeof (*rsense),GFP_KERNEL ); +if (!rsense) +return ERR_PTR (-ENOMEM ); + +/* validate channel index */ +if (sensor->chan <LTC2983_DIFFERENTIAL_CHAN_MIN ) { +dev_err (&st->spi->dev,"Invalid chann:%d for r_sense" , + sensor->chan); +return ERR_PTR (-EINVAL ); + } +/* get raw value */ + ret =of_property_read_u64 (child,"adi,rsense-val-micro-ohms" , &temp); +if (ret) { +dev_err (&st->spi->dev,"Property adi,rsense-val-micro-ohms missing\n" ); +return ERR_PTR (-EINVAL ); + } + +/* 2^10 resolution */ + rsense->r_sense_val =__convert_to_raw (temp,1024 ); + +/* set common parameters */ + rsense->sensor.name ="r_sense" ; + rsense->sensor.assign_chan = ltc2983_r_sense_assign_chan; + +return &rsense->sensor; +} + +static struct ltc2983_sensor *ltc2983_adc_new (struct device_node *child, +struct ltc2983_data *st, +const struct ltc2983_sensor *sensor) +{ +struct ltc2983_adc *adc; + + adc =devm_kzalloc (&st->spi->dev,sizeof (*adc),GFP_KERNEL ); +if (!adc) +return ERR_PTR (-ENOMEM ); + +if (of_property_read_bool (child,"adi,single-ended" )) + adc->single_ended = true; + +if (!adc->single_ended && + sensor->chan <LTC2983_DIFFERENTIAL_CHAN_MIN ) { +dev_err (&st->spi->dev,"Invalid chan:%d for differential adc\n" , + sensor->chan); +return ERR_PTR (-EINVAL ); + } +/* set common parameters */ + adc->sensor.name ="direct_adc" ; + adc->sensor.assign_chan = ltc2983_adc_assign_chan; + adc->sensor.fault_handler = ltc2983_common_fault_handler; + +return &adc->sensor; +} + +static int ltc2983_chan_read (struct ltc2983_data *st, +const struct ltc2983_sensor *sensor,int *val) +{ +u32 start_conversion =0 ; +int ret; +unsigned long time; +__be32 temp; + +/* +* Do not allow channel readings if device is in sleep state. +* A read/write on the spi bus would bring the device prematurely +* out of sleep. +*/ +if (st->reset) +return -EPERM ; + + start_conversion =LTC2983_STATUS_START (true); + start_conversion |=LTC2983_STATUS_CHAN_SEL (sensor->chan); +dev_dbg (&st->spi->dev,"Start conversion on chan:%d, status:%02X\n" , + sensor->chan, start_conversion); +/* start conversion */ + ret =regmap_write (st->regmap,LTC2983_STATUS_REG , start_conversion); +if (ret) +return ret; + +reinit_completion (&st->completion); +/* +* wait for conversion to complete. +* 300 ms should be more than enough to complete the conversion. +* Depending on the sensor configuration, there are 2/3 conversions +* cycles of 82ms. +*/ + time =wait_for_completion_timeout (&st->completion, +msecs_to_jiffies (300 )); +if (!time) { +dev_warn (&st->spi->dev,"Conversion timed out\n" ); +return -ETIMEDOUT ; + }
drivers/iio/temperature/ltc2983.c line 931
Quoted 10 lines
drivers/iio/temperature/ltc2983.c new file +10
-0+ +/* read the converted data */ + ret =regmap_bulk_read (st->regmap,LTC2983_CHAN_RES_ADDR (sensor->chan), + &temp,sizeof (temp)); +if (ret) +return ret; + + *val =__be32_to_cpu (temp); +dev_dbg (&st->spi->dev,"Converted data: 0x%08X (addr:0x%04X)\n" , *val, +LTC2983_CHAN_RES_ADDR (sensor->chan));
Probably drop all the dev_dbg stuff unless it is providing information that isn't otherwise available (from reading channel etc, kprobe / ftrace).
Quoted 174 lines
drivers/iio/temperature/ltc2983.c new file +174
-0+ +if (!(LTC2983_RES_VALID_MASK & *val)) { +dev_err (&st->spi->dev,"Invalid conversion detected\n" ); +return -EIO ; + } + + ret = sensor->fault_handler (st, *val); +if (ret) +return ret; + + *val =sign_extend32 ((*val) <C2983_DATA_MASK ,LTC2983_DATA_SIGN_BIT ); +return 0 ; +} + +static int ltc2983_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val,int *val2,long mask) +{ +struct ltc2983_data *st =iio_priv (indio_dev); +int ret; + +/* sanity check */ +if (chan->address >= st->num_channels) { +dev_err (&st->spi->dev,"Invalid chan address:%ld" , + chan->address); +return -EINVAL ; + } +switch (mask) { +case IIO_CHAN_INFO_RAW : +mutex_lock (&st->lock); + ret =ltc2983_chan_read (st, st->sensors[chan->address], val); +mutex_unlock (&st->lock); +return ret ?:IIO_VAL_INT ; +case IIO_CHAN_INFO_SCALE : +switch (chan->type) { +case IIO_TEMP : + *val =1 ; +/* 2^10 */ + *val2 =1024 ; +return IIO_VAL_FRACTIONAL ; +case IIO_VOLTAGE : + *val =1 ; +/* 2^21 */ + *val2 =2097152 ; +return IIO_VAL_FRACTIONAL ; +default : +return -EINVAL ; + } + } + +return -EINVAL ; +} + +static int ltc2983_reg_access (struct iio_dev *indio_dev, +unsigned int reg, +unsigned int writeval, +unsigned int *readval) +{ +struct ltc2983_data *st =iio_priv (indio_dev); + +/* check comment in ltc2983_chan_read() */ +if (st->reset) +return -EPERM ; + +if (readval) +return regmap_read (st->regmap, reg, readval); +else +return regmap_write (st->regmap, reg, writeval); +} + +static irqreturn_t ltc2983_irq_handler (int irq,void *data) +{ +struct ltc2983_data *st = data; + +complete (&st->completion); +return IRQ_HANDLED ; +} + +#define LTC2983_CHAN (__type, index, __address, ext_name) ({ \ + struct iio_chan_spec __chan = { \ + .type = __type, \ + .indexed = 1, \ + .channel = index, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .address = __address, \ + .extend_name = ext_name, \ + }; \ + __chan; \ +}) + +static int ltc2983_parse_dt (struct ltc2983_data *st) +{ +struct device_node *child; +struct device *dev = &st->spi->dev; +int ret =0 , chan =0 , channel_avail_mask =0 ; + +if (!of_property_read_bool (dev->of_node,"adi,temperature-celcius" )) + st->temp_farenheit = true; + +of_property_read_u32 (dev->of_node,"adi,mux-delay-config" , + &st->mux_delay_config); + +of_property_read_u32 (dev->of_node,"adi,filter-notch-freq" , + &st->filter_notch_freq); + + st->num_channels =of_get_available_child_count (dev->of_node); + st->sensors =devm_kcalloc (dev, st->num_channels,sizeof (*st->sensors), +GFP_KERNEL ); +if (!st->sensors) +return -ENOMEM ; + + st->iio_channels = st->num_channels; +for_each_available_child_of_node (dev->of_node, child) { +struct ltc2983_sensor sensor; + + ret =of_property_read_u32 (child,"reg" , &sensor.chan); +if (ret) { +dev_err (dev,"reg property must given for child nodes\n" ); +return ret; + } + +/* check if we have a valid channel */ +if (sensor.chan <LTC2983_MIN_CHANNELS_NR || + sensor.chan >LTC2983_MAX_CHANNELS_NR ) { +dev_err (dev, +"chan:%d must be from 1 to 20\n" , sensor.chan); +return -EINVAL ; + }else if (channel_avail_mask &BIT (sensor.chan)) { +dev_err (dev,"chan:%d already in use\n" , sensor.chan); +return -EINVAL ; + } + + ret =of_property_read_u32 (child,"adi,sensor-type" , + &sensor.type); +if (ret) { +dev_err (dev, +"adi,sensor-type property must given for child nodes\n" ); +return ret; + } + +dev_dbg (dev,"Create new sensor, type %u, chann %u" , + sensor.type, + sensor.chan); + +if (sensor.type >=LTC2983_SENSOR_THERMOCOUPLE && + sensor.type <=LTC2983_SENSOR_THERMOCOUPLE_CUSTOM ) { + st->sensors[chan] =ltc2983_thermocouple_new (child, st, + &sensor); + }else if (sensor.type >=LTC2983_SENSOR_RTD && + sensor.type <=LTC2983_SENSOR_RTD_CUSTOM ) { + st->sensors[chan] =ltc2983_rtd_new (child, st, &sensor); + }else if (sensor.type >=LTC2983_SENSOR_THERMISTOR && + sensor.type <=LTC2983_SENSOR_THERMISTOR_CUSTOM ) { + st->sensors[chan] =ltc2983_thermistor_new (child, st, + &sensor); + }else if (sensor.type ==LTC2983_SENSOR_DIODE ) { + st->sensors[chan] =ltc2983_diode_new (child, st, + &sensor); + }else if (sensor.type ==LTC2983_SENSOR_SENSE_RESISTOR ) { + st->sensors[chan] =ltc2983_r_sense_new (child, st, + &sensor); +/* don't add rsense to iio */ + st->iio_channels--; + }else if (sensor.type ==LTC2983_SENSOR_DIRECT_ADC ) { + st->sensors[chan] =ltc2983_adc_new (child, st, &sensor); + }else { +dev_err (dev,"Unknown sensor type %d\n" , sensor.type); +return -EINVAL ; + } + +if (IS_ERR (st->sensors[chan])) { +dev_err (dev,"Failed to create sensor %ld" , +PTR_ERR (st->sensors[chan]));
drivers/iio/temperature/ltc2983.c line 1115
Quoted 10 lines
drivers/iio/temperature/ltc2983.c new file +10
-0+return PTR_ERR (st->sensors[chan]); + } +/* set generic sensor parameters */ + st->sensors[chan]->chan = sensor.chan; + st->sensors[chan]->type = sensor.type; + + channel_avail_mask |=BIT (sensor.chan); + chan++; + } +/* allocate iio_chan array */
This last block isn't really about parsing the DT, perhaps drop it out of here?
Quoted 13 lines
drivers/iio/temperature/ltc2983.c new file +13
-0+ st->iio_chan =devm_kzalloc (dev, + st->iio_channels *sizeof (*st->iio_chan), +GFP_KERNEL ); +if (!st->iio_chan) +return -ENOMEM ; + +return 0 ; +} + +static int ltc2983_setup (struct ltc2983_data *st,bool assign_iio) +{ +u32 iio_chan_t =0 , iio_chan_v =0 , chan, iio_idx =0 ; +u32 global_cfg =0 ;
drivers/iio/temperature/ltc2983.c line 1138
Quoted 10 lines
drivers/iio/temperature/ltc2983.c new file +10
-0+int ret; +unsigned long time; + +/* make sure the device is up */ + time =wait_for_completion_timeout (&st->completion, +msecs_to_jiffies (250 )); +if (!time) { +dev_err (&st->spi->dev,"Device startup timed out\n" ); +return -ETIMEDOUT ; + }
Blank line here, slightly helps readability be clearly separating the error handling path from normal flow.
drivers/iio/temperature/ltc2983.c line 1139
Quoted 1 line
drivers/iio/temperature/ltc2983.c new file +1
-0+/* set generic global cfg and mux delay */
Not sure this comment adds anything not obvious from the code. Comments like this are always at risk of 'rotting' over time, so better to not put them if they don't bring significant value.
drivers/iio/temperature/ltc2983.c line 1144
Quoted 5 lines
drivers/iio/temperature/ltc2983.c new file +5
-0+ global_cfg =LTC2983_NOTCH_FREQ (st->filter_notch_freq); + global_cfg |=LTC2983_TEMP_UNITS (st->temp_farenheit); +regmap_write (st->regmap,LTC2983_GLOBAL_CONFIG_REG , global_cfg); +regmap_write (st->regmap,LTC2983_MUX_CONFIG_REG , st->mux_delay_config); +/* setup channels */
This comment also not stating anything non obvious.
Quoted 44 lines
drivers/iio/temperature/ltc2983.c new file +44
-0+for (chan =0 ; chan < st->num_channels; chan++) { +u32 chan_type =0 , *iio_chan; + + ret = st->sensors[chan]->assign_chan (st, st->sensors[chan]); +if (ret) +return ret; +/* +* The assign_iio flag is necessary for when the device is +* coming out of sleep. In that case, we just need to +* re-configure the device channels. +* We also don't assign iio channels for rsense. +*/ +if (st->sensors[chan]->type ==LTC2983_SENSOR_SENSE_RESISTOR || + !assign_iio) +continue ; + +/* assign iio channel */ +if (st->sensors[chan]->type !=LTC2983_SENSOR_DIRECT_ADC ) { + chan_type =IIO_TEMP ; + iio_chan = &iio_chan_t; + }else { + chan_type =IIO_VOLTAGE ; + iio_chan = &iio_chan_v; + } + +/* +* add chan as the iio .address so that, we can directly +* reference the sensor given the iio_chan_spec +*/ + st->iio_chan[iio_idx++] =LTC2983_CHAN (chan_type, (*iio_chan)++, + chan, + st->sensors[chan]->name); + } + +return 0 ; +} + +static const struct regmap_range ltc2983_reg_ranges[] = { +regmap_reg_range (LTC2983_STATUS_REG ,LTC2983_STATUS_REG ), +regmap_reg_range (LTC2983_TEMP_RES_START_REG ,LTC2983_TEMP_RES_END_REG ), +regmap_reg_range (LTC2983_GLOBAL_CONFIG_REG ,LTC2983_GLOBAL_CONFIG_REG ), +regmap_reg_range (LTC2983_MULT_CHANNEL_START_REG , +LTC2983_MULT_CHANNEL_END_REG ), +regmap_reg_range (LTC2983_MUX_CONFIG_REG ,LTC2983_MUX_CONFIG_REG ),
drivers/iio/temperature/ltc2983.c line 1198
Quoted 10 lines
drivers/iio/temperature/ltc2983.c new file +10
-0+regmap_reg_range (LTC2983_CHAN_ASSIGN_START_REG , +LTC2983_CHAN_ASSIGN_END_REG ), +regmap_reg_range (LTC2983_CUST_SENS_TBL_START_REG , + LTC2983_CUST_SENS_TBL_END_REG), +}; + +static const struct regmap_access_table ltc2983_reg_table = { + .yes_ranges = ltc2983_reg_ranges, + .n_yes_ranges =ARRAY_SIZE (ltc2983_reg_ranges), +};
Blank line here.
Quoted 85 lines
drivers/iio/temperature/ltc2983.c new file +85
-0+/* +* The reg_bits are actually 12 but the device needs the first *complete* +* byte for the command (R/W). +*/ +static const struct regmap_config ltc2983_regmap_config = { + .reg_bits =24 , + .val_bits =8 , + .wr_table = <c2983_reg_table, + .rd_table = <c2983_reg_table, + .read_flag_mask =GENMASK (1 ,0 ), + .write_flag_mask =BIT (1 ), +}; + +static const struct iio_info ltc2983_iio_info = { + .read_raw = ltc2983_read_raw, + .debugfs_reg_access = ltc2983_reg_access, +}; + +static int ltc2983_probe (struct spi_device *spi) +{ +struct ltc2983_data *st; +struct iio_dev *indio_dev; +const char *name =spi_get_device_id (spi)->name; +int ret; + + indio_dev =devm_iio_device_alloc (&spi->dev,sizeof (*st)); +if (!indio_dev) +return -ENOMEM ; + + st =iio_priv (indio_dev); + + st->regmap =devm_regmap_init_spi (spi, <c2983_regmap_config); +if (IS_ERR (st->regmap)) { +dev_err (&spi->dev,"Failed to initialize regmap\n" ); +return PTR_ERR (st->regmap); + } + +mutex_init (&st->lock); +init_completion (&st->completion); + st->spi = spi; +spi_set_drvdata (spi, st); + + ret =ltc2983_parse_dt (st); +if (ret) +return ret; +/* +* let's request the irq now so it is used to sync the device +* startup in ltc2983_setup() +*/ + ret =devm_request_threaded_irq (&spi->dev, spi->irq,NULL , + ltc2983_irq_handler,IRQF_ONESHOT | +IRQF_TRIGGER_RISING , name, st); +if (ret) { +dev_err (&spi->dev,"failed to request an irq, %d" , ret); +return ret; + } + + ret =ltc2983_setup (st, true); +if (ret) +return ret; + + indio_dev->dev.parent = &spi->dev; + indio_dev->name = name; + indio_dev->num_channels = st->iio_channels; + indio_dev->channels = st->iio_chan; + indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->info = <c2983_iio_info; + +return devm_iio_device_register (&spi->dev, indio_dev); +} + +static int __maybe_unused ltc2983_resume (struct device *dev) +{ +struct ltc2983_data *st =spi_get_drvdata (to_spi_device (dev)); +int ret; + +mutex_lock (&st->lock); +/* dummy read to bring the device out of sleep */ +regmap_read (st->regmap,LTC2983_STATUS_REG , &ret); +/* we need to re-assign the channels */ + ret =ltc2983_setup (st, false); + st->reset = false; +mutex_unlock (&st->lock); + +return ret;
drivers/iio/temperature/ltc2983.c line 1293
Quoted 10 lines
drivers/iio/temperature/ltc2983.c new file +10
-0+} + +static int __maybe_unused ltc2983_suspend (struct device *dev) +{ +struct ltc2983_data *st =spi_get_drvdata (to_spi_device (dev)); +int ret; + +mutex_lock (&st->lock); + ret =regmap_write (st->regmap,LTC2983_STATUS_REG ,LTC2983_SLEEP ); + st->reset = true;
Naming seems a bit odd. The register field is called sleep, but we call it reset internally?
Quoted 34 lines
drivers/iio/temperature/ltc2983.c new file +34
-0+mutex_unlock (&st->lock); + +return ret; +} + +static SIMPLE_DEV_PM_OPS(ltc2983_pm_ops, ltc2983_suspend, ltc2983_resume); + +static const struct spi_device_id ltc2983_id_table[] = { + {"ltc2983" }, + {}, +}; +MODULE_DEVICE_TABLE (spi, ltc2983_id_table); + +static const struct of_device_id ltc2983_of_match[] = { + { .compatible ="adi,ltc2983" }, + {}, +}; +MODULE_DEVICE_TABLE (of, ltc2983_id_table); + +static struct spi_driver ltc2983_driver = { + .driver = { + .name ="ltc2983" , + .of_match_table = ltc2983_of_match, + .pm = <c2983_pm_ops, + }, + .probe = ltc2983_probe, + .id_table = ltc2983_id_table, +}; + +module_spi_driver (ltc2983_driver); + +MODULE_AUTHOR ("Nuno Sa <[email protected]>" ); +MODULE_DESCRIPTION ("Analog Devices LTC2983 SPI Temperature sensors" ); +MODULE_LICENSE ("GPL" );
Sa, Nuno
maintainerHi Jonathan,
Thanks for the review.
Comments inline.
Nuno Sá
Quoted 53 lines · Jonathan Cameron
Quoted 9 lines · On Mon, 9 Sep 2019 16:45:49 +0200 Nuno Sá <[email protected]> wrote:
The LTC2983 is a Multi-Sensor High Accuracy Digital Temperature Measurement System. It measures a wide variety of temperature sensors and
digitally outputs the result, in °C or °F, with 0.1°C accuracy and 0.001°C resolution. It can measure the temperature of all standard thermocouples (type B,E,J,K,N,S,R,T), standard 2-,3-,4-wire RTDs, thermistors and diodes.Signed-off-by Nuno Sá <[email protected]>Some comments inline. Main concern is around the interface, rest is minor
stuff.Jonathan
Quoted 21 lines
--- .../testing/sysfs-bus-iio-temperature-ltc2983 | 43 + MAINTAINERS | 7 + drivers/iio/temperature/Kconfig | 10 + drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/ltc2983.c | 1327 +++++++++++++++++ 5 files changed, 1388 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio- temperature-ltc2983 create mode 100644 drivers/iio/temperature/ltc2983.c(quoted diff) +0
-0ltc2983 b/Documentation/ABI/testing/sysfs-bus-iio-temperature- ltc2983
new file mode 100644
index 000000000000..3ad3440c0986Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +1
-0@@ -0,0 +1,43 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_tempY_thermQuoted 1 line
istor_rawFor each of these, I presume we know which type of device is attached at any time?
Using the channel naming to convey this (and I assume the fact that different
conversions need to be done in userspace?) is a bit messy. If we need
to convey the channel type, then a separatein_tempY_modeattribute may make more
sense. That would keep this ABI 'closer' to standard. Software that just logs
an unprocessed value could just work for example.
Quoted 2 lines
I'm not sure I've totally understood what is going on here though.
So, the extend_name does not really bring any functional advantage. It was just an easy way for someone to know which kind of sensor the channel was referring to. In terms of conversions, all the work is done by the part for all the different sensor's and the scale is the same for all of them. So, I can just drop the extended name and use standard ABI if you prefer?
Quoted 54 lines
Quoted 54 lines
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +4
-0+KernelVersion: +Contact: [email protected] +Description: + Reads the raw (unscaled no bias removal etc)temperature from
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +1
-0+ channel Y. The value is returned by a Thermistor sensormeasurement.
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +1
-0+ Units after application of scale are degrees Celsius orFahrenheit
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +3
-0+ depending on the device configuration. + +What: /sys/bus/iio/devices/iio:deviceX/in_tempY_therm
ocouple_rawDocumentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +4
-0+KernelVersion: +Contact: [email protected] +Description: + Reads the raw (unscaled no bias removal etc)temperature from
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +1
-0+ channel Y. The value is returned by a Thermocouplesensor measurement.
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +1
-0+ Units after application of scale are degrees Celsius orFahrenheit
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +3
-0+ depending on the device configuration. + +What: /sys/bus/iio/devices/iio:deviceX/in_tempY_rtd_raw
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +4
-0+KernelVersion: +Contact: [email protected] +Description: + Reads the raw (unscaled no bias removal etc)temperature from
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +1
-0+ channel Y. The value is returned by a RTD sensormeasurement.
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +1
-0+ Units after application of scale are degrees Celsius orFahrenheit
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +3
-0+ depending on the device configuration. + +What: /sys/bus/iio/devices/iio:deviceX/in_tempY_diode
_rawDocumentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +4
-0+KernelVersion: +Contact: [email protected] +Description: + Reads the raw (unscaled no bias removal etc)temperature from
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +1
-0+ channel Y. The value is returned by a Diode sensormeasurement.
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +1
-0+ Units after application of scale are degrees Celsius orFahrenheit
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +3
-0+ depending on the device configuration. + +What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_di
rect_adc_rawDocumentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +2
-0+KernelVersion: +Contact: [email protected]
Quoted 8 lines
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 line 43
Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +2
-0+Description: + Reads the raw (unscaled no bias removal etc) voltagefrom
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +1
-0+ channel Y. The value is returned by a direct ADCmeasurement.
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +1
-0+ Units after application of scale are Volts.What is the extended name adding?
The same as before. But here I see that it does not make sense having the extended name because if it's voltage then we know it's a direct adc reading. I will drop it.
Quoted 802 lines
in_voltageY_rawalready tells you it's the raw voltage from channel y.Quoted 799 lines
MAINTAINERS +7
-0@@ -9491,6 +9491,13 @@ S: Maintained F: Documentation/devicetree/bindings/iio/dac/ltc1660.txt F: drivers/iio/dac/ltc1660.c +LTC2983 IIO TEMPERATURE DRIVER +M: Nuno Sá <[email protected]> +W: http://ez.analog.com/community/linux-device-drivers +L: [email protected] +S: Supported +F: drivers/iio/temperature/ltc2983.c + LTC4261 HARDWARE MONITOR DRIVER M: Guenter Roeck <[email protected]> L: [email protected]drivers/iio/temperature/Kconfig +2
-0@@ -4,6 +4,16 @@ # menu "Temperature sensors" +config LTC2983 + tristate "Analog Devices Multi-Sensor Digital TemperatureMeasurement System"
drivers/iio/temperature/Kconfig +8
-0+ depends on SPI + help + Say yes here to build support for the LTC2983 Multi-Sensor + high accuracy digital temperature measurement system. + + To compile this driver as a module, choose M here: the module + will be called ltc2983. + config MAXIM_THERMOCOUPLE tristate "Maxim thermocouple sensors" depends on SPIdrivers/iio/temperature/Makefile +1
-0@@ -3,6 +3,7 @@ # Makefile for industrial I/O temperature drivers # +obj-$(CONFIG_LTC2983) += ltc2983.o obj-$(CONFIG_HID_SENSOR_TEMP) += hid-sensor-temperature.o obj-$(CONFIG_MAXIM_THERMOCOUPLE) += maxim_thermocouple.o obj-$(CONFIG_MAX31856) += max31856.odrivers/iio/temperature/ltc2983.c new file +3
-0@@ -0,0 +1,1327 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Analog Devices LTC2983 Multi-Sensor Digital Temperature Measurement System
+ * driver
+ *
+ * Copyright 2019 Analog Devices Inc.
+ */drivers/iio/temperature/ltc2983.c new file +35
-0+#include <linux/bitfield.h> +#include <linux/completion.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/iio/iio.h> +#include <linux/interrupt.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/of_gpio.h> +#include <linux/regmap.h> +#include <linux/spi/spi.h> + +/* register map */ +#define LTC2983_STATUS_REG 0x0000 +#define LTC2983_TEMP_RES_START_REG 0x0010 +#define LTC2983_TEMP_RES_END_REG 0x005F +#define LTC2983_GLOBAL_CONFIG_REG 0x00F0 +#define LTC2983_MULT_CHANNEL_START_REG 0x00F4 +#define LTC2983_MULT_CHANNEL_END_REG 0x00F7 +#define LTC2983_MUX_CONFIG_REG 0x00FF +#define LTC2983_CHAN_ASSIGN_START_REG 0x0200 +#define LTC2983_CHAN_ASSIGN_END_REG 0x024F +#define LTC2983_CUST_SENS_TBL_START_REG 0x0250 +#define LTC2983_CUST_SENS_TBL_END_REG 0x03CF + +#define LTC2983_DIFFERENTIAL_CHAN_MIN 2 +#define LTC2983_MAX_CHANNELS_NR 20 +#define LTC2983_MIN_CHANNELS_NR 1 +#define LTC2983_SLEEP 0x97 +#define LTC2983_CUSTOM_STEINHART_SIZE 24 +#define LTC2983_CUSTOM_SENSOR_ENTRY_SZ 6 +#define LTC2983_CUSTOM_STEINHART_ENTRY_SZ 4 + +#define LTC2983_CHAN_START_ADDR (chan) \ + (((chan - 1) * 4) +
LTC2983_CHAN_ASSIGN_START_REG)drivers/iio/temperature/ltc2983.c new file +14
-0+#define LTC2983_CHAN_RES_ADDR (chan) \ + (((chan - 1) * 4) + LTC2983_TEMP_RES_START_REG) +#define LTC2983_THERMOCOUPLE_DIFF_MASK BIT(3) +#define LTC2983_THERMISTOR_DIFF_MASK BIT(2) +#define LTC2983_DIODE_DIFF_MASK BIT(2) +#define LTC2983_RTD_4_WIRE_MASK BIT(3) +#define LTC2983_RTD_ROTATION_MASK BIT(1) +#define LTC2983_RTD_KELVIN_R_SENSE_MASK GENMASK(3, 2) + +#define LTC2983_COMMON_HARD_FAULT_MASK GENMASK(31, 30) +#define LTC2983_COMMON_SOFT_FAULT_MASK GENMASK(27, 25) + +#define LTC2983_STATUS_START_MASK BIT(7) +#define LTC2983_STATUS_START (x) FIELD_PREP(LTC2983_
STATUS_START_MASK, x)drivers/iio/temperature/ltc2983.c new file +4
-0+ +#define LTC2983_STATUS_CHAN_SEL_MASK GENMASK(4, 0) +#define LTC2983_STATUS_CHAN_SEL (x) \ + FIELD_PREP(LTC2983_STATUS_CHAN_SEL_MASK, x)
drivers/iio/temperature/ltc2983.c new file +3
-0+ +#define LTC2983_TEMP_UNITS_MASK BIT(2) +#define LTC2983_TEMP_UNITS (x) FIELD_PREP(LTC2983_TEMP
_UNITS_MASK, x)drivers/iio/temperature/ltc2983.c new file +3
-0+ +#define LTC2983_NOTCH_FREQ_MASK GENMASK(1, 0) +#define LTC2983_NOTCH_FREQ (x) FIELD_PREP(LTC2983_NOTC
H_FREQ_MASK, x)drivers/iio/temperature/ltc2983.c new file +7
-0+ +#define LTC2983_RES_VALID_MASK BIT(24) +#define LTC2983_DATA_MASK GENMASK(23, 0) +#define LTC2983_DATA_SIGN_BIT 23 + +#define LTC2983_CHAN_TYPE_MASK GENMASK(31, 27) +#define LTC2983_CHAN_TYPE (x) FIELD_PREP(LTC2983_CHAN
_TYPE_MASK, x)drivers/iio/temperature/ltc2983.c new file +2
-0+ +/* cold junction for thermocouples and rsense for rtd's and thermistor's */
drivers/iio/temperature/ltc2983.c new file +2
-0+#define LTC2983_CHAN_ASSIGN_MASK GENMASK(26, 22) +#define LTC2983_CHAN_ASSIGN (x) FIELD_PREP(LTC2983_CHAN
_ASSIGN_MASK, x)drivers/iio/temperature/ltc2983.c new file +3
-0+ +#define LTC2983_CUSTOM_LEN_MASK GENMASK(5, 0) +#define LTC2983_CUSTOM_LEN (x) FIELD_PREP(LTC2983_CUST
OM_LEN_MASK, x)drivers/iio/temperature/ltc2983.c new file +3
-0+ +#define LTC2983_CUSTOM_ADDR_MASK GENMASK(11, 6) +#define LTC2983_CUSTOM_ADDR (x) FIELD_PREP(LTC2983_CUST
OM_ADDR_MASK, x)drivers/iio/temperature/ltc2983.c new file +4
-0+ +#define LTC2983_THERMOCOUPLE_CFG_MASK GENMASK(21, 18) +#define LTC2983_THERMOCOUPLE_CFG (x) \ + FIELD_PREP(LTC2983_THERMOCOUPLE_CFG_MASK, x)
drivers/iio/temperature/ltc2983.c new file +5
-0+#define LTC2983_THERMOCOUPLE_HARD_FAULT_MASK GENMASK(31, 29) +#define LTC2983_THERMOCOUPLE_SOFT_FAULT_MASK GENMASK(28, 25) + +#define LTC2983_RTD_CFG_MASK GENMASK(21, 18) +#define LTC2983_RTD_CFG (x) FIELD_PREP(LTC2983_RTD_CFG_MASK, x)
drivers/iio/temperature/ltc2983.c new file +3
-0+#define LTC2983_RTD_EXC_CURRENT_MASK GENMASK(17, 14) +#define LTC2983_RTD_EXC_CURRENT (x) \ + FIELD_PREP(LTC2983_RTD_EXC_CURRENT_MASK, x)
drivers/iio/temperature/ltc2983.c new file +2
-0+#define LTC2983_RTD_CURVE_MASK GENMASK(13, 12) +#define LTC2983_RTD_CURVE (x) FIELD_PREP(LTC2983_RTD_
CURVE_MASK, x)drivers/iio/temperature/ltc2983.c new file +4
-0+ +#define LTC2983_THERMISTOR_CFG_MASK GENMASK(21, 19) +#define LTC2983_THERMISTOR_CFG (x) \ + FIELD_PREP(LTC2983_THERMISTOR_CFG_MASK,x)
drivers/iio/temperature/ltc2983.c new file +3
-0+#define LTC2983_THERMISTOR_EXC_CURRENT_MASK GENMASK(18, 15) +#define LTC2983_THERMISTOR_EXC_CURRENT (x) \ + FIELD_PREP(LTC2983_THERMISTOR_EXC_CURRENT_MASK,x)
drivers/iio/temperature/ltc2983.c new file +3
-0+ +#define LTC2983_DIODE_CFG_MASK GENMASK(26, 24) +#define LTC2983_DIODE_CFG (x) FIELD_PREP(LTC2983_DIOD
E_CFG_MASK, x)drivers/iio/temperature/ltc2983.c new file +3
-0+#define LTC2983_DIODE_EXC_CURRENT_MASK GENMASK(23, 22) +#define LTC2983_DIODE_EXC_CURRENT (x) \ + FIELD_PREP(LTC2983_DIODE_EXC_CURRENT_MASK, x)
drivers/iio/temperature/ltc2983.c new file +3
-0+#define LTC2983_DIODE_IDEAL_FACTOR_MASK GENMASK(21, 0) +#define LTC2983_DIODE_IDEAL_FACTOR (x) \ + FIELD_PREP(LTC2983_DIODE_IDEAL_FACTOR_MASK, x)
drivers/iio/temperature/ltc2983.c new file +3
-0+ +#define LTC2983_R_SENSE_VAL_MASK GENMASK(26, 0) +#define LTC2983_R_SENSE_VAL (x) FIELD_PREP(LTC2983_R_SE
NSE_VAL_MASK, x)drivers/iio/temperature/ltc2983.c new file +4
-0+ +#define LTC2983_ADC_SINGLE_ENDED_MASK BIT(26) +#define LTC2983_ADC_SINGLE_ENDED (x) \ + FIELD_PREP(LTC2983_ADC_SINGLE_ENDED_MASK, x)
drivers/iio/temperature/ltc2983.c new file +16
-0+ +enum { +LTC2983_SENSOR_THERMOCOUPLE =1 , +LTC2983_SENSOR_THERMOCOUPLE_CUSTOM =9 , +LTC2983_SENSOR_RTD =10 , +LTC2983_SENSOR_RTD_CUSTOM =18 , +LTC2983_SENSOR_THERMISTOR =19 , +LTC2983_SENSOR_THERMISTOR_STEINHART =26 , +LTC2983_SENSOR_THERMISTOR_CUSTOM =27 , +LTC2983_SENSOR_DIODE =28 , +LTC2983_SENSOR_SENSE_RESISTOR =29 , +LTC2983_SENSOR_DIRECT_ADC =30 , +}; + +#define to_thermocouple (_sensor) \ + container_of(_sensor, struct ltc2983_thermocouple,sensor)
drivers/iio/temperature/ltc2983.c new file +6
-0+ +#define to_rtd (_sensor) \ + container_of(_sensor, struct ltc2983_rtd, sensor) + +#define to_thermistor (_sensor) \ + container_of(_sensor, struct ltc2983_thermistor,sensor)
drivers/iio/temperature/ltc2983.c new file +28
-0+ +#define to_diode (_sensor) \ + container_of(_sensor, struct ltc2983_diode, sensor) + +#define to_rsense (_sensor) \ + container_of(_sensor, struct ltc2983_rsense, sensor) + +#define to_adc (_sensor) \ + container_of(_sensor, struct ltc2983_adc, sensor) + +struct ltc2983_data { +struct regmap *regmap; +struct spi_device *spi; +struct mutex lock; +struct completion completion; +struct iio_chan_spec *iio_chan; +struct ltc2983_sensor **sensors; +u32 mux_delay_config; +u32 filter_notch_freq; +u16 custom_table_size; +u8 num_channels; +u8 iio_channels; +bool temp_farenheit; +bool reset; +}; + +struct ltc2983_sensor { + int (*fault_handler)(const struct ltc2983_data *st, const u32result);
drivers/iio/temperature/ltc2983.c new file +62
-0+int (*assign_chan)(struct ltc2983_data *st, +const struct ltc2983_sensor *sensor); +const char *name; +/* specifies the sensor channel */ +u32 chan; +/* sensor type */ +u32 type; +}; + +struct ltc2983_custom_sensor { +/* raw table sensor data */ +u8 *table; +size_t size; +/* address offset */ +s8 offset; +bool is_steinhart; +}; + +struct ltc2983_thermocouple { +struct ltc2983_sensor sensor; +struct ltc2983_custom_sensor *custom; +u32 sensor_config; +u32 cold_junction_chan; +}; + +struct ltc2983_rtd { +struct ltc2983_sensor sensor; +struct ltc2983_custom_sensor *custom; +u32 sensor_config; +u32 r_sense_chan; +u32 excitation_current; +u32 rtd_curve; +}; + +struct ltc2983_thermistor { +struct ltc2983_sensor sensor; +struct ltc2983_custom_sensor *custom; +u32 sensor_config; +u32 r_sense_chan; +u32 excitation_current; +}; + +struct ltc2983_diode { +struct ltc2983_sensor sensor; +u32 sensor_config; +u32 excitation_current; +u32 ideal_factor_value; +}; + +struct ltc2983_rsense { +struct ltc2983_sensor sensor; +u32 r_sense_val; +}; + +struct ltc2983_adc { +struct ltc2983_sensor sensor; +bool single_ended; +}; + +/* +* Convert to Q format numbers. These number's are integers where +* the number of integer and fractional bits are specified. The resolution
+ * is given by 1/@resolution and tell us the number of fractional bits. For
+ * instance a resolution of 2^-10 means we have 10 fractional bits.
+ */drivers/iio/temperature/ltc2983.c new file +5
-0+static u32 __convert_to_raw (const u64 val,const u32 resolution) +{ +u64 __res = val * resolution; + +/* all values are multiplied by 1000000 to remove the fraction */
drivers/iio/temperature/ltc2983.c new file +6
-0+do_div (__res,1000000 ); + +return __res; +} + +static u32 __convert_to_raw_sign(const u64 val, const u32resolution)
drivers/iio/temperature/ltc2983.c new file +10
-0+{ +s64 __res = -(s32 )val; + + __res =__convert_to_raw (__res, resolution); + +return (u32)-__res; +} + +static int __ltc2983_fault_handler (const struct ltc2983_data *st, + const u32 result, const u32
hard_mask,drivers/iio/temperature/ltc2983.c new file +6
-0+ const u32 soft_mask) +{ +const struct device *dev = &st->spi->dev; + +if (result & hard_mask) { + dev_err(dev, "Invalid conversion: Sensor HARDfault\n");
drivers/iio/temperature/ltc2983.c new file +4
-0+return -EIO ; + }else if (result & soft_mask) { +/* just print a warning */ + dev_warn(dev, "Suspicious conversion: Sensor SOFTfault\n");
drivers/iio/temperature/ltc2983.c new file +6
-0+ } + +return 0 ; +} + +static int __ltc2983_chan_assign_common(const struct ltc2983_data*st,
drivers/iio/temperature/ltc2983.c new file +1
-0+ const struct ltc2983_sensor*sensor,
drivers/iio/temperature/ltc2983.c new file +15
-0+ u32 chan_val) +{ +u32 reg =LTC2983_CHAN_START_ADDR (sensor->chan); +__be32 __chan_val; + + chan_val |=LTC2983_CHAN_TYPE (sensor->type); +dev_dbg (&st->spi->dev,"Assign %s, reg:0x%04X, val:0x%08X\n" , + sensor->name, + reg, chan_val); + __chan_val =cpu_to_be32 (chan_val); +return regmap_bulk_write (st->regmap, reg, &__chan_val, +sizeof (__chan_val)); +} + +static int __ltc2983_chan_custom_sensor_assign(struct ltc2983_data*st,
drivers/iio/temperature/ltc2983.c new file +1
-0+struct ltc2983_custom_sensor *custom,
drivers/iio/temperature/ltc2983.c new file +4
-0+ u32 *chan_val) +{ +u32 reg; + u8 mult = custom->is_steinhart ?
LTC2983_CUSTOM_STEINHART_ENTRY_SZ:drivers/iio/temperature/ltc2983.c new file +6
-0+LTC2983_CUSTOM_SENSOR_ENTRY_SZ ; +const struct device *dev = &st->spi->dev; +/* +* custom->size holds the raw size of the table. However, when +* configuring the sensor channel, we must write the number of +* entries of the table minus 1. For steinhart sensors 0 is written
drivers/iio/temperature/ltc2983.c new file +6
-0+* since the size is constant! +*/ +const u8 len = custom->is_steinhart ?0 : + (custom->size /LTC2983_CUSTOM_SENSOR_ENTRY_SZ ) -1 ; +/* +* Check if the offset was assigned already. It should be for steinhart
drivers/iio/temperature/ltc2983.c new file +1
-0+* sensors. When coming from sleep, it should be assigned for all.
drivers/iio/temperature/ltc2983.c new file +4
-0+*/ +if (custom->offset <0 ) { +/* +* This needs to be done again here because, from the moment
drivers/iio/temperature/ltc2983.c new file +1
-0+* when this test was done (successfully) for this custom
drivers/iio/temperature/ltc2983.c new file +1
-0+* sensor, a steinhart sensor might have been added changing
drivers/iio/temperature/ltc2983.c new file +7
-0+* custom_table_size... +*/ +if (st->custom_table_size + custom->size > + (LTC2983_CUST_SENS_TBL_END_REG - +LTC2983_CUST_SENS_TBL_START_REG ) +1 ) { + dev_err(dev, + "Not space left(%d) for new customsensor(%zu)",
drivers/iio/temperature/ltc2983.c new file +1
-0+ st-Quoted 1 line
custom_table_size,drivers/iio/temperature/ltc2983.c new file +10
-0+ custom->size); +return -EINVAL ; + } + + custom->offset = st->custom_table_size / +LTC2983_CUSTOM_SENSOR_ENTRY_SZ ; + st->custom_table_size += custom->size; + } + + reg = (custom->offset * mult) +
LTC2983_CUST_SENS_TBL_START_REG;drivers/iio/temperature/ltc2983.c new file +4
-0+ + *chan_val |=LTC2983_CUSTOM_LEN (len); + *chan_val |=LTC2983_CUSTOM_ADDR (custom->offset); + dev_dbg(dev, "Assign custom sensor, reg:0x%04X, off:%d,sz:%zu",
drivers/iio/temperature/ltc2983.c new file +1
-0+ reg, custom-Quoted 1 line
offset,
drivers/iio/temperature/ltc2983.c new file +3
-0+ custom->size); +/* write custom sensor table */ + return regmap_bulk_write(st->regmap, reg, custom->table,
custom->size);drivers/iio/temperature/ltc2983.c new file +4
-0+} + +static struct ltc2983_custom_sensor *__ltc2983_custom_sensor_new ( + struct ltc2983_data*st,
drivers/iio/temperature/ltc2983.c new file +1
-0+ const struct
device_node*np,drivers/iio/temperature/ltc2983.c new file +1
-0+ const bool
is_steinhart,drivers/iio/temperature/ltc2983.c new file +8
-0+const u32 resolution, + const bool has_signed) +{ + struct ltc2983_custom_sensor *new_custom; +u8 index, n_entries, tbl =0 ; +struct device *dev = &st->spi->dev; +/* +* For custom steinhart, the full u32 is taken. For all the others
drivers/iio/temperature/ltc2983.c new file +5
-0+* the MSB is discarded. +*/ +const u8 n_size = (is_steinhart == true) ?4 :3 ; + + n_entries = of_property_count_elems_of_size(np, "adi,custom-sensor",
drivers/iio/temperature/ltc2983.c new file +4
-0+ sizeof(u64)); +/* n_entries must be an even number */ +if (!n_entries || (n_entries %2 ) !=0 ) { + dev_err(dev, "Number of entries either 0 or noteven\n");
drivers/iio/temperature/ltc2983.c new file +4
-0+return ERR_PTR (-EINVAL ); + } + + new_custom = devm_kzalloc(dev, sizeof(*new_custom),
GFP_KERNEL);drivers/iio/temperature/ltc2983.c new file +6
-0+if (!new_custom) +return ERR_PTR (-ENOMEM ); + + new_custom->size = n_entries * n_size; +/* check Steinhart size */ + if (is_steinhart && new_custom->size !=
LTC2983_CUSTOM_STEINHART_SIZE) {drivers/iio/temperature/ltc2983.c new file +2
-0+ dev_err(dev, "Steinhart sensors size(%zu) must be 24", + new_custom-Quoted 1 line
size);
drivers/iio/temperature/ltc2983.c new file +7
-0+return ERR_PTR (-EINVAL ); + } +/* Check space on the table. */ +if (st->custom_table_size + new_custom->size > + (LTC2983_CUST_SENS_TBL_END_REG - +LTC2983_CUST_SENS_TBL_START_REG ) +1 ) { + dev_err(dev, "No space left(%d) for new customsensor(%zu)",
drivers/iio/temperature/ltc2983.c new file +1
-0+ st->custom_table_size, new_custom-Quoted 1 line
size);
drivers/iio/temperature/ltc2983.c new file +5
-0+return ERR_PTR (-EINVAL ); + } + +/* allocate the table */ + new_custom->table = devm_kzalloc(dev, new_custom->size,
GFP_KERNEL);drivers/iio/temperature/ltc2983.c new file +7
-0+if (!new_custom->table) +return ERR_PTR (-ENOMEM ); + +for (index =0 ; index < n_entries; index++) { +u64 temp =0 , j; + + of_property_read_u64_index(np, "adi,custom-sensor",index,
drivers/iio/temperature/ltc2983.c new file +3
-0+ &temp); +/* +* Steinhart sensors are configured with raw values in the
drivers/iio/temperature/ltc2983.c new file +1
-0+* devicetree. For the other sensors we must convert the
drivers/iio/temperature/ltc2983.c new file +1
-0+* value to raw. The odd index's correspond to temperarures
drivers/iio/temperature/ltc2983.c new file +1
-0+* and always have 1/1024 of resolution. Temperatures also
drivers/iio/temperature/ltc2983.c new file +7
-0+* come in kelvin, so signed values is not possible +*/ +if (!is_steinhart) { +if ((index %2 ) !=0 ) + temp =__convert_to_raw (temp,1024 ); +else if (has_signed && (s64 )temp <0 ) + temp = __convert_to_raw_sign(temp,resolution);
drivers/iio/temperature/ltc2983.c new file +2
-0+else + temp = __convert_to_raw(temp,resolution);
drivers/iio/temperature/ltc2983.c new file +10
-0+ } + +for (j =0 ; j < n_size; j++) + new_custom->table[tbl++] = + temp >> (8 * (n_size - j -1 )); + } + + new_custom->is_steinhart = is_steinhart; +/* +* This is done to first add all the steinhart sensors to the table,
drivers/iio/temperature/ltc2983.c new file +1
-0+* in order to maximize the table usage. If we mix adding steinhart
drivers/iio/temperature/ltc2983.c new file +1
-0+* with the other sensors, we might have to do some roundup to make
drivers/iio/temperature/ltc2983.c new file +1
-0+* sure that sensor_addr - 0x250(start address) is a multiple of 4
drivers/iio/temperature/ltc2983.c new file +1
-0+* (for steinhart), and a multiple of 6 for all the other sensors.
drivers/iio/temperature/ltc2983.c new file +2
-0+* Since we have const 24 bytes for steinhart sensors and 24 is +* also a multiple of 6, we guarantee that the first non- steinhart
drivers/iio/temperature/ltc2983.c new file +1
-0+* sensor will sit in a correct address without the need of filling
drivers/iio/temperature/ltc2983.c new file +5
-0+* addresses. +*/ +if (is_steinhart) { + new_custom->offset = st->custom_table_size / +LTC2983_CUSTOM_STEINHART_ENTRY_ SZ;
drivers/iio/temperature/ltc2983.c new file +3
-0+ st->custom_table_size += new_custom->size; + }else { +/* mark as unset. This is checked later on the assign phase */
drivers/iio/temperature/ltc2983.c new file +7
-0+ new_custom->offset =-1 ; + } + +return new_custom; +} + +static int ltc2983_thermocouple_fault_handler(const struct
ltc2983_data*st,drivers/iio/temperature/ltc2983.c new file +4
-0+ const u32 result) +{ +return __ltc2983_fault_handler (st, result, + LTC2983_THERMOCOUPLE_HARD_FAULT_MASK,
drivers/iio/temperature/ltc2983.c new file +1
-0+LTC2983_THERMOCOUPLE_SOFT_FAULT_ MASK);
drivers/iio/temperature/ltc2983.c new file +3
-0+} + +static int ltc2983_common_fault_handler(const struct ltc2983_data*st,
drivers/iio/temperature/ltc2983.c new file +8
-0+ const u32 result) +{ +return __ltc2983_fault_handler (st, result, +LTC2983_COMMON_HARD_FAULT_MASK , +LTC2983_COMMON_SOFT_FAULT_MASK ); +} + +static int ltc2983_thermocouple_assign_chan(struct ltc2983_data*st,
drivers/iio/temperature/ltc2983.c new file +12
-0+ const struct ltc2983_sensor *sensor) +{ +struct ltc2983_thermocouple *thermo =to_thermocouple (sensor); +u32 chan_val; + + chan_val =LTC2983_CHAN_ASSIGN (thermo->cold_junction_chan); + chan_val |=LTC2983_THERMOCOUPLE_CFG (thermo->sensor_config); + +if (thermo->custom) { +int ret; + + ret = __ltc2983_chan_custom_sensor_assign(st, thermo-Quoted 1 line
custom,
drivers/iio/temperature/ltc2983.c new file +22
-0+ &chan_val); +if (ret) +return ret; + } +return __ltc2983_chan_assign_common (st, sensor, chan_val); +} + +static int ltc2983_rtd_assign_chan (struct ltc2983_data *st, +const struct ltc2983_sensor *sensor) +{ +struct ltc2983_rtd *rtd =to_rtd (sensor); +u32 chan_val; + + chan_val =LTC2983_CHAN_ASSIGN (rtd->r_sense_chan); + chan_val |=LTC2983_RTD_CFG (rtd->sensor_config); + chan_val |=LTC2983_RTD_EXC_CURRENT (rtd->excitation_current); + chan_val |=LTC2983_RTD_CURVE (rtd->rtd_curve); + +if (rtd->custom) { +int ret; + + ret = __ltc2983_chan_custom_sensor_assign(st, rtd-Quoted 1 line
custom,
drivers/iio/temperature/ltc2983.c new file +9
-0+ &chan_val); +if (ret) +return ret; + } +return __ltc2983_chan_assign_common (st, sensor, chan_val); +} + +static int ltc2983_thermistor_assign_chan (struct ltc2983_data *st, + const struct ltc2983_sensor*sensor)
drivers/iio/temperature/ltc2983.c new file +8
-0+{ +struct ltc2983_thermistor *thermistor =to_thermistor (sensor); +u32 chan_val; + + chan_val =LTC2983_CHAN_ASSIGN (thermistor->r_sense_chan); + chan_val |=LTC2983_THERMISTOR_CFG (thermistor->sensor_config); + chan_val |= + LTC2983_THERMISTOR_EXC_CURRENT(thermistor-Quoted 1 line
excitation_current);drivers/iio/temperature/ltc2983.c new file +6
-0+ +if (thermistor->custom) { +int ret; + + ret = __ltc2983_chan_custom_sensor_assign(st, + thermistor-Quoted 1 line
custom,
drivers/iio/temperature/ltc2983.c new file +9
-0+ &chan_val); +if (ret) +return ret; + } +return __ltc2983_chan_assign_common (st, sensor, chan_val); +} + +static int ltc2983_diode_assign_chan (struct ltc2983_data *st, + const struct ltc2983_sensor*sensor)
drivers/iio/temperature/ltc2983.c new file +6
-0+{ +struct ltc2983_diode *diode =to_diode (sensor); +u32 chan_val; + + chan_val =LTC2983_DIODE_CFG (diode->sensor_config); + chan_val |= LTC2983_DIODE_EXC_CURRENT(diode-Quoted 1 line
excitation_current);drivers/iio/temperature/ltc2983.c new file +1
-0+ chan_val |= LTC2983_DIODE_IDEAL_FACTOR(diode-Quoted 1 line
ideal_factor_value);drivers/iio/temperature/ltc2983.c new file +6
-0+ +return __ltc2983_chan_assign_common (st, sensor, chan_val); +} + +static int ltc2983_r_sense_assign_chan (struct ltc2983_data *st, + const struct ltc2983_sensor*sensor)
drivers/iio/temperature/ltc2983.c new file +22
-0+{ +struct ltc2983_rsense *rsense =to_rsense (sensor); +u32 chan_val; + + chan_val =LTC2983_R_SENSE_VAL (rsense->r_sense_val); + +return __ltc2983_chan_assign_common (st, sensor, chan_val); +} + +static int ltc2983_adc_assign_chan (struct ltc2983_data *st, +const struct ltc2983_sensor *sensor) +{ +struct ltc2983_adc *adc =to_adc (sensor); +u32 chan_val; + + chan_val =LTC2983_ADC_SINGLE_ENDED (adc->single_ended); + +return __ltc2983_chan_assign_common (st, sensor, chan_val); +} + +static struct ltc2983_sensor *ltc2983_thermocouple_new ( + const struct device_node*child,
drivers/iio/temperature/ltc2983.c new file +2
-0+struct ltc2983_data *st, + const struct ltc2983_sensor*sensor)
drivers/iio/temperature/ltc2983.c new file +5
-0+{ +struct ltc2983_thermocouple *thermo; +struct device_node *phandle; + + thermo = devm_kzalloc(&st->spi->dev, sizeof(*thermo),
GFP_KERNEL);drivers/iio/temperature/ltc2983.c new file +7
-0+if (!thermo) +return ERR_PTR (-ENOMEM ); + +of_property_read_u32 (child,"adi,sensor-config" , + &thermo->sensor_config); +/* validate channel index */ + if (!(thermo->sensor_config & LTC2983_THERMOCOUPLE_DIFF_MASK)&&
drivers/iio/temperature/ltc2983.c new file +3
-0+ sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { + dev_err(&st->spi->dev, + "Invalid chann:%d for differentialthermocouple",
drivers/iio/temperature/ltc2983.c new file +1
-0+ sensor-Quoted 1 line
chan);
drivers/iio/temperature/ltc2983.c new file +4
-0+return ERR_PTR (-EINVAL ); + } + + phandle = of_parse_phandle(child, "adi,cold-junction-handle",0);
drivers/iio/temperature/ltc2983.c new file +5
-0+if (phandle) { +int ret; + + ret = of_property_read_u32(phandle, "reg", + &thermo-Quoted 1 line
cold_junction_chan);drivers/iio/temperature/ltc2983.c new file +3
-0+if (ret) { +/* +* This would be catched later but we can just return
drivers/iio/temperature/ltc2983.c new file +3
-0+* the error right away. +*/ + dev_err(&st->spi->dev, "Property reg must begiven\n");
drivers/iio/temperature/ltc2983.c new file +8
-0+of_node_put (phandle); +return ERR_PTR (-EINVAL ); + } + } + +/* check custom sensor */ +if (sensor->type ==LTC2983_SENSOR_THERMOCOUPLE_CUSTOM ) { + thermo->custom = __ltc2983_custom_sensor_new(st, child,false,
drivers/iio/temperature/ltc2983.c new file +1
-0+ 16384,true);
drivers/iio/temperature/ltc2983.c new file +9
-0+if (IS_ERR (thermo->custom)) { +of_node_put (phandle); +return ERR_CAST (thermo->custom); + } + } + +/* set common parameters */ + thermo->sensor.name ="thermocouple" ; + thermo->sensor.fault_handler =
ltc2983_thermocouple_fault_handler;drivers/iio/temperature/ltc2983.c new file +7
-0+ thermo->sensor.assign_chan = ltc2983_thermocouple_assign_chan; + +of_node_put (phandle); +return &thermo->sensor; +} + +static struct ltc2983_sensor *ltc2983_rtd_new(const struct
device_node*child,drivers/iio/temperature/ltc2983.c new file +2
-0+struct ltc2983_data *st, + const struct ltc2983_sensor*sensor)
drivers/iio/temperature/ltc2983.c new file +13
-0+{ +struct ltc2983_rtd *rtd; +int ret =0 ; +struct device *dev = &st->spi->dev; +struct device_node *phandle; + + rtd =devm_kzalloc (dev,sizeof (*rtd),GFP_KERNEL ); +if (!rtd) +return ERR_PTR (-ENOMEM ); + + phandle =of_parse_phandle (child,"adi,rsense-handle" ,0 ); +if (!phandle) { + dev_err(dev, "Property adi,rsense-handle missing orinvalid");
Quoted 8 lines
drivers/iio/temperature/ltc2983.c line 635
Quoted 5 lines
drivers/iio/temperature/ltc2983.c new file +5
-0+return ERR_PTR (-EINVAL ); + } + + ret =of_property_read_u32 (phandle,"reg" , + &rtd->r_sense_chan);Doesn't look like that lines needs wrapping. Check for similar elsewhere.
ack.
Quoted 337 lines
Quoted 337 lines
drivers/iio/temperature/ltc2983.c new file +6
-0+if (ret) { +dev_err (dev,"Property reg must be given\n" ); + goto fail; + } + + of_property_read_u32(child, "adi,sensor-config", &rtd-Quoted 1 line
sensor_config);drivers/iio/temperature/ltc2983.c new file +5
-0+/* +* rtd channel indexes are a bit more complicated to validate. +* For 4wire RTD with rotation, the channel selection cannot be +* >=19 since the chann + 1 is used in this configuration. +* For 4wire RTDs with kelvin rsense, the rsense channel cannot be
drivers/iio/temperature/ltc2983.c new file +11
-0+* <=1 since chanel - 1 and channel - 2 are used. +*/ +if (rtd->sensor_config <C2983_RTD_4_WIRE_MASK ) { +/* 4-wire */ +u8 min =LTC2983_DIFFERENTIAL_CHAN_MIN , + max =LTC2983_MAX_CHANNELS_NR ; + +if (rtd->sensor_config <C2983_RTD_ROTATION_MASK ) + max =LTC2983_MAX_CHANNELS_NR -1 ; + + if (((rtd->sensor_config &
LTC2983_RTD_KELVIN_R_SENSE_MASK)drivers/iio/temperature/ltc2983.c new file +5
-0+ == LTC2983_RTD_KELVIN_R_SENSE_MASK) && + (rtd->r_sense_chan <= min)) { +/* kelvin rsense*/ + dev_err(dev, + "Invalid rsense chann:%d to use inkelvin rsense",
drivers/iio/temperature/ltc2983.c new file +1
-0+ rtd-Quoted 1 line
r_sense_chan);drivers/iio/temperature/ltc2983.c new file +7
-0+ + ret = -EINVAL ; + goto fail; + } + +if (sensor->chan < min || sensor->chan > max) { + dev_err(dev, "Invalid chann:%d for the rtdconfig",
drivers/iio/temperature/ltc2983.c new file +1
-0+ sensor-Quoted 1 line
chan);
drivers/iio/temperature/ltc2983.c new file +9
-0+ + ret = -EINVAL ; + goto fail; + } + }else { +/* same as differential case */ +if (sensor->chan <LTC2983_DIFFERENTIAL_CHAN_MIN ) { + dev_err(&st->spi->dev, + "Invalid chann:%d for RTD", sensor-Quoted 1 line
chan);
drivers/iio/temperature/ltc2983.c new file +9
-0+ + ret = -EINVAL ; + goto fail; + } + } + +/* check custom sensor */ +if (sensor->type ==LTC2983_SENSOR_RTD_CUSTOM ) { + rtd->custom = __ltc2983_custom_sensor_new(st, child,false,
drivers/iio/temperature/ltc2983.c new file +29
-0+ 2048, false); +if (IS_ERR (rtd->custom)) { +of_node_put (phandle); +return ERR_CAST (rtd->custom); + } + } + +/* set common parameters */ + rtd->sensor.name ="rtd" ; + rtd->sensor.fault_handler = ltc2983_common_fault_handler; + rtd->sensor.assign_chan = ltc2983_rtd_assign_chan; + + ret =of_property_read_u32 (child,"adi,excitation-current" , + &rtd->excitation_current); +if (ret) +/* default to 1uA */ + rtd->excitation_current =1 ; + +of_property_read_u32 (child,"adi,rtd-curve" , &rtd->rtd_curve); + +of_node_put (phandle); +return &rtd->sensor; +fail: +of_node_put (phandle); +return ERR_PTR (ret); +} + +static struct ltc2983_sensor *ltc2983_thermistor_new ( + const struct device_node*child,
drivers/iio/temperature/ltc2983.c new file +2
-0+struct ltc2983_data *st, + const struct ltc2983_sensor*sensor)
drivers/iio/temperature/ltc2983.c new file +7
-0+{ +struct ltc2983_thermistor *thermistor; +struct device *dev = &st->spi->dev; +struct device_node *phandle; +int ret =0 ; + + thermistor = devm_kzalloc(dev, sizeof(*thermistor),
GFP_KERNEL);drivers/iio/temperature/ltc2983.c new file +6
-0+if (!thermistor) +return ERR_PTR (-ENOMEM ); + + phandle =of_parse_phandle (child,"adi,rsense-handle" ,0 ); +if (!phandle) { + dev_err(dev, "Property adi,rsense-handle missing orinvalid");
drivers/iio/temperature/ltc2983.c new file +14
-0+return ERR_PTR (-EINVAL ); + } + + ret =of_property_read_u32 (phandle,"reg" , + &thermistor->r_sense_chan); +if (ret) { +dev_err (dev,"rsense channel must be configured...\n" ); + goto fail; + } + +of_property_read_u32 (child,"adi,sensor-config" , + &thermistor->sensor_config); +/* validate channel index */ + if (!(thermistor->sensor_config & LTC2983_THERMISTOR_DIFF_MASK)&&
drivers/iio/temperature/ltc2983.c new file +4
-0+ sensor->chan < LTC2983_DIFFERENTIAL_CHAN_MIN) { + dev_err(&st->spi->dev, + "Invalid chann:%d for differential thermistor", + sensor-Quoted 1 line
chan);
drivers/iio/temperature/ltc2983.c new file +7
-0+ ret = -EINVAL ; + goto fail; + } + +/* check custom sensor */ +if (sensor->type >=LTC2983_SENSOR_THERMISTOR_STEINHART ) { + thermistor->custom = __ltc2983_custom_sensor_new(st,child,
drivers/iio/temperature/ltc2983.c new file +1
-0+ sensor->type ==
LTC2983_SENSOR_THERMISTOR_STEINHART?drivers/iio/temperature/ltc2983.c new file +1
-0+ true : false,64,
drivers/iio/temperature/ltc2983.c new file +9
-0+ false); +if (IS_ERR (thermistor->custom)) { +of_node_put (phandle); +return ERR_CAST (thermistor->custom); + } + } +/* set common parameters */ + thermistor->sensor.name ="thermistor" ; + thermistor->sensor.fault_handler =
ltc2983_common_fault_handler;drivers/iio/temperature/ltc2983.c new file +1
-0+ thermistor->sensor.assign_chan =
ltc2983_thermistor_assign_chan;drivers/iio/temperature/ltc2983.c new file +16
-0+ + ret =of_property_read_u32 (child,"adi,excitation-current" , + &thermistor->excitation_current); +if (ret) +/* default to auto-range */ + thermistor->excitation_current =0x0c ; + +of_node_put (phandle); +return &thermistor->sensor; +fail: +of_node_put (phandle); +return ERR_PTR (ret); +} + +static struct ltc2983_sensor *ltc2983_diode_new ( + const struct device_node*child,
drivers/iio/temperature/ltc2983.c new file +2
-0+const struct ltc2983_data *st, + const struct ltc2983_sensor*sensor)
drivers/iio/temperature/ltc2983.c new file +5
-0+{ +struct ltc2983_diode *diode; +u32 temp =0 ; + + diode = devm_kzalloc(&st->spi->dev, sizeof(*diode),
GFP_KERNEL);drivers/iio/temperature/ltc2983.c new file +4
-0+if (!diode) +return ERR_PTR (-ENOMEM ); + + of_property_read_u32(child, "adi,sensor-config", &diode-Quoted 1 line
sensor_config);drivers/iio/temperature/ltc2983.c new file +6
-0+/* validate channel index */ +if (!(diode->sensor_config <C2983_DIODE_DIFF_MASK ) && + sensor->chan <LTC2983_DIFFERENTIAL_CHAN_MIN ) { + dev_err(&st->spi->dev, + "Invalid chann:%d for differential thermistor", + sensor-Quoted 1 line
chan);
drivers/iio/temperature/ltc2983.c new file +19
-0+return ERR_PTR (-EINVAL ); + } +/* set common parameters */ + diode->sensor.name ="diode" ; + diode->sensor.fault_handler = ltc2983_common_fault_handler; + diode->sensor.assign_chan = ltc2983_diode_assign_chan; + +of_property_read_u32 (child,"adi,excitation-current" , + &diode->excitation_current); + +of_property_read_u32 (child,"adi,ideal-factor-value" , &temp); + +/* 2^20 resolution */ + diode->ideal_factor_value =__convert_to_raw (temp,1048576 ); + +return &diode->sensor; +} + +static struct ltc2983_sensor *ltc2983_r_sense_new(struct
device_node*child,drivers/iio/temperature/ltc2983.c new file +2
-0+struct ltc2983_data *st, + const struct ltc2983_sensor*sensor)
drivers/iio/temperature/ltc2983.c new file +6
-0+{ +struct ltc2983_rsense *rsense; +int ret; +u64 temp; + + rsense = devm_kzalloc(&st->spi->dev, sizeof(*rsense),
GFP_KERNEL);drivers/iio/temperature/ltc2983.c new file +11
-0+if (!rsense) +return ERR_PTR (-ENOMEM ); + +/* validate channel index */ +if (sensor->chan <LTC2983_DIFFERENTIAL_CHAN_MIN ) { +dev_err (&st->spi->dev,"Invalid chann:%d for r_sense" , + sensor->chan); +return ERR_PTR (-EINVAL ); + } +/* get raw value */ + ret = of_property_read_u64(child, "adi,rsense-val-micro-ohms",&temp);
drivers/iio/temperature/ltc2983.c new file +2
-0+if (ret) { + dev_err(&st->spi->dev, "Property adi,rsense-val-micro-ohms missing\n");
drivers/iio/temperature/ltc2983.c new file +14
-0+return ERR_PTR (-EINVAL ); + } + +/* 2^10 resolution */ + rsense->r_sense_val =__convert_to_raw (temp,1024 ); + +/* set common parameters */ + rsense->sensor.name ="r_sense" ; + rsense->sensor.assign_chan = ltc2983_r_sense_assign_chan; + +return &rsense->sensor; +} + +static struct ltc2983_sensor *ltc2983_adc_new(struct device_node*child,
drivers/iio/temperature/ltc2983.c new file +2
-0+struct ltc2983_data *st, + const struct ltc2983_sensor*sensor)
drivers/iio/temperature/ltc2983.c new file +13
-0+{ +struct ltc2983_adc *adc; + + adc =devm_kzalloc (&st->spi->dev,sizeof (*adc),GFP_KERNEL ); +if (!adc) +return ERR_PTR (-ENOMEM ); + +if (of_property_read_bool (child,"adi,single-ended" )) + adc->single_ended = true; + +if (!adc->single_ended && + sensor->chan <LTC2983_DIFFERENTIAL_CHAN_MIN ) { + dev_err(&st->spi->dev, "Invalid chan:%d fordifferential adc\n",
drivers/iio/temperature/ltc2983.c new file +1
-0+ sensor-Quoted 1 line
chan);
drivers/iio/temperature/ltc2983.c new file +21
-0+return ERR_PTR (-EINVAL ); + } +/* set common parameters */ + adc->sensor.name ="direct_adc" ; + adc->sensor.assign_chan = ltc2983_adc_assign_chan; + adc->sensor.fault_handler = ltc2983_common_fault_handler; + +return &adc->sensor; +} + +static int ltc2983_chan_read (struct ltc2983_data *st, +const struct ltc2983_sensor *sensor,int *val) +{ +u32 start_conversion =0 ; +int ret; +unsigned long time; +__be32 temp; + +/* +* Do not allow channel readings if device is in sleep state. +* A read/write on the spi bus would bring the device prematurely
drivers/iio/temperature/ltc2983.c new file +8
-0+* out of sleep. +*/ +if (st->reset) +return -EPERM ; + + start_conversion =LTC2983_STATUS_START (true); + start_conversion |=LTC2983_STATUS_CHAN_SEL (sensor->chan); + dev_dbg(&st->spi->dev, "Start conversion on chan:%d,status:%02X\n",
drivers/iio/temperature/ltc2983.c new file +3
-0+ sensor->chan, start_conversion); +/* start conversion */ + ret = regmap_write(st->regmap, LTC2983_STATUS_REG,
start_conversion);drivers/iio/temperature/ltc2983.c new file +7
-0+if (ret) +return ret; + +reinit_completion (&st->completion); +/* +* wait for conversion to complete. +* 300 ms should be more than enough to complete the conversion.
drivers/iio/temperature/ltc2983.c new file +1
-0+* Depending on the sensor configuration, there are 2/3 conversions
drivers/iio/temperature/ltc2983.c new file +11
-0+* cycles of 82ms. +*/ + time =wait_for_completion_timeout (&st->completion, +msecs_to_jiffies (300 )); +if (!time) { +dev_warn (&st->spi->dev,"Conversion timed out\n" ); +return -ETIMEDOUT ; + } + +/* read the converted data */ + ret = regmap_bulk_read(st->regmap,
LTC2983_CHAN_RES_ADDR(sensor->chan),drivers/iio/temperature/ltc2983.c new file +6
-0+ &temp, sizeof(temp)); +if (ret) +return ret; + + *val =__be32_to_cpu (temp); + dev_dbg(&st->spi->dev, "Converted data: 0x%08X(addr:0x%04X)\n", *val,
drivers/iio/temperature/ltc2983.c new file +1
-0+ LTC2983_CHAN_RES_ADDR(sensor-
Quoted 6 lines
Quoted 1 line
Quoted 1 line
chan));
Probably drop all the
dev_dbgstuff unless it is providing information that
isn't otherwise available (from reading channel etc, kprobe / ftrace).
ack.
Quoted 199 lines
Quoted 199 lines
drivers/iio/temperature/ltc2983.c new file +3
-0+ +if (!(LTC2983_RES_VALID_MASK & *val)) { + dev_err(&st->spi->dev, "Invalid conversiondetected\n");
drivers/iio/temperature/ltc2983.c new file +8
-0+return -EIO ; + } + + ret = sensor->fault_handler (st, *val); +if (ret) +return ret; + + *val = sign_extend32((*val) & LTC2983_DATA_MASK,
LTC2983_DATA_SIGN_BIT);drivers/iio/temperature/ltc2983.c new file +20
-0+return 0 ; +} + +static int ltc2983_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val,int *val2,long mask) +{ +struct ltc2983_data *st =iio_priv (indio_dev); +int ret; + +/* sanity check */ +if (chan->address >= st->num_channels) { +dev_err (&st->spi->dev,"Invalid chan address:%ld" , + chan->address); +return -EINVAL ; + } +switch (mask) { +case IIO_CHAN_INFO_RAW : +mutex_lock (&st->lock); + ret = ltc2983_chan_read(st, st->sensors[chan->address],val);
drivers/iio/temperature/ltc2983.c new file +67
-0+mutex_unlock (&st->lock); +return ret ?:IIO_VAL_INT ; +case IIO_CHAN_INFO_SCALE : +switch (chan->type) { +case IIO_TEMP : + *val =1 ; +/* 2^10 */ + *val2 =1024 ; +return IIO_VAL_FRACTIONAL ; +case IIO_VOLTAGE : + *val =1 ; +/* 2^21 */ + *val2 =2097152 ; +return IIO_VAL_FRACTIONAL ; +default : +return -EINVAL ; + } + } + +return -EINVAL ; +} + +static int ltc2983_reg_access (struct iio_dev *indio_dev, +unsigned int reg, +unsigned int writeval, +unsigned int *readval) +{ +struct ltc2983_data *st =iio_priv (indio_dev); + +/* check comment in ltc2983_chan_read() */ +if (st->reset) +return -EPERM ; + +if (readval) +return regmap_read (st->regmap, reg, readval); +else +return regmap_write (st->regmap, reg, writeval); +} + +static irqreturn_t ltc2983_irq_handler (int irq,void *data) +{ +struct ltc2983_data *st = data; + +complete (&st->completion); +return IRQ_HANDLED ; +} + +#define LTC2983_CHAN (__type, index, __address, ext_name) ({ \ + struct iio_chan_spec __chan = { \ + .type = __type, \ + .indexed = 1, \ + .channel = index, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .address = __address, \ + .extend_name = ext_name, \ + }; \ + __chan; \ +}) + +static int ltc2983_parse_dt(struct ltc2983_data *st) +{ + struct device_node *child; + struct device *dev = &st->spi->dev; + int ret = 0, chan = 0, channel_avail_mask = 0; + + if (!of_property_read_bool(dev->of_node, "adi,temperature-celcius"))
drivers/iio/temperature/ltc2983.c new file +10
-0+ st->temp_farenheit = true; + +of_property_read_u32 (dev->of_node,"adi,mux-delay-config" , + &st->mux_delay_config); + +of_property_read_u32 (dev->of_node,"adi,filter-notch-freq" , + &st->filter_notch_freq); + + st->num_channels =of_get_available_child_count (dev->of_node); + st->sensors = devm_kcalloc(dev, st->num_channels, sizeof(*st-Quoted 1 line
sensors),
drivers/iio/temperature/ltc2983.c new file +11
-0+ GFP_KERNEL); +if (!st->sensors) +return -ENOMEM ; + + st->iio_channels = st->num_channels; +for_each_available_child_of_node (dev->of_node, child) { +struct ltc2983_sensor sensor; + + ret =of_property_read_u32 (child,"reg" , &sensor.chan); +if (ret) { + dev_err(dev, "reg property must given for childnodes\n");
drivers/iio/temperature/ltc2983.c new file +8
-0+return ret; + } + +/* check if we have a valid channel */ +if (sensor.chan <LTC2983_MIN_CHANNELS_NR || + sensor.chan >LTC2983_MAX_CHANNELS_NR ) { + dev_err(dev, + "chan:%d must be from 1 to 20\n",sensor.chan);
drivers/iio/temperature/ltc2983.c new file +3
-0+return -EINVAL ; + }else if (channel_avail_mask &BIT (sensor.chan)) { + dev_err(dev, "chan:%d already in use\n",sensor.chan);
drivers/iio/temperature/ltc2983.c new file +8
-0+return -EINVAL ; + } + + ret =of_property_read_u32 (child,"adi,sensor-type" , + &sensor.type); +if (ret) { + dev_err(dev, + "adi,sensor-type property must givenfor child nodes\n");
drivers/iio/temperature/ltc2983.c new file +5
-0+return ret; + } + + dev_dbg(dev, "Create new sensor, type %u, chann %u", + sensor.type,
drivers/iio/temperature/ltc2983.c new file +1
-0+ sensor.chan);
drivers/iio/temperature/ltc2983.c new file +3
-0+ +if (sensor.type >=LTC2983_SENSOR_THERMOCOUPLE && + sensor.type <=LTC2983_SENSOR_THERMOCOUPLE_CUSTOM ){
drivers/iio/temperature/ltc2983.c new file +1
-0+ st->sensors[chan] =ltc2983_thermocouple_new(child, st,
drivers/iio/temperature/ltc2983.c new file +1
-0+ &sensor);
drivers/iio/temperature/ltc2983.c new file +3
-0+ }else if (sensor.type >=LTC2983_SENSOR_RTD && + sensor.type <=LTC2983_SENSOR_RTD_CUSTOM ) { + st->sensors[chan] = ltc2983_rtd_new(child, st,&sensor);
drivers/iio/temperature/ltc2983.c new file +2
-0+ } else if (sensor.type >= LTC2983_SENSOR_THERMISTOR && + sensor.type <=
LTC2983_SENSOR_THERMISTOR_CUSTOM) {drivers/iio/temperature/ltc2983.c new file +1
-0+ st->sensors[chan] =ltc2983_thermistor_new(child, st,
drivers/iio/temperature/ltc2983.c new file +1
-0+ &sensor);
drivers/iio/temperature/ltc2983.c new file +2
-0+ }else if (sensor.type ==LTC2983_SENSOR_DIODE ) { + st->sensors[chan] = ltc2983_diode_new(child,st,
drivers/iio/temperature/ltc2983.c new file +2
-0+ &sensor); + } else if (sensor.type ==
LTC2983_SENSOR_SENSE_RESISTOR) {drivers/iio/temperature/ltc2983.c new file +1
-0+ st->sensors[chan] = ltc2983_r_sense_new(child,st,
drivers/iio/temperature/ltc2983.c new file +1
-0+ &sensor);
drivers/iio/temperature/ltc2983.c new file +4
-0+/* don't add rsense to iio */ + st->iio_channels--; + }else if (sensor.type ==LTC2983_SENSOR_DIRECT_ADC ) { + st->sensors[chan] = ltc2983_adc_new(child, st,&sensor);
drivers/iio/temperature/ltc2983.c new file +2
-0+ }else { + dev_err(dev, "Unknown sensor type %d\n",sensor.type);
drivers/iio/temperature/ltc2983.c new file +6
-0+return -EINVAL ; + } + +if (IS_ERR (st->sensors[chan])) { + dev_err(dev, "Failed to create sensor %ld", + PTR_ERR(st-Quoted 1 line
sensors[chan]));
Quoted 14 lines
drivers/iio/temperature/ltc2983.c line 1115
Quoted 10 lines
drivers/iio/temperature/ltc2983.c new file +10
-0+return PTR_ERR (st->sensors[chan]); + } +/* set generic sensor parameters */ + st->sensors[chan]->chan = sensor.chan; + st->sensors[chan]->type = sensor.type; + + channel_avail_mask |=BIT (sensor.chan); + chan++; + } +/* allocate iio_chan array */ This last block isn't really about parsing the DT, perhaps drop it out of
here?
Hmm that is true. I can just allocate the iio_chan array in the setup function.
Quoted 19 lines
Quoted 19 lines
drivers/iio/temperature/ltc2983.c new file +2
-0+ st->iio_chan = devm_kzalloc(dev, + st->iio_channels * sizeof(*st-Quoted 1 line
iio_chan),drivers/iio/temperature/ltc2983.c new file +16
-0+ GFP_KERNEL); +if (!st->iio_chan) +return -ENOMEM ; + +return 0 ; +} + +static int ltc2983_setup (struct ltc2983_data *st,bool assign_iio) +{ +u32 iio_chan_t =0 , iio_chan_v =0 , chan, iio_idx =0 ; +u32 global_cfg =0 ; +int ret; +unsigned long time; + +/* make sure the device is up */ + time = wait_for_completion_timeout(&st->completion,
Quoted 8 lines
drivers/iio/temperature/ltc2983.c line 1138
Quoted 5 lines
drivers/iio/temperature/ltc2983.c new file +5
-0+ msecs_to_jiffies(250)); +if (!time) { +dev_err (&st->spi->dev,"Device startup timed out\n" ); +return -ETIMEDOUT ; + }Blank line here, slightly helps readability be clearly separating the error handling path from normal flow.
ack.
Quoted 7 lines
drivers/iio/temperature/ltc2983.c line 1139
Quoted 1 line
drivers/iio/temperature/ltc2983.c new file +1
-0+/* set generic global cfg and mux delay */ Not sure this comment adds anything not obvious from the code. Comments
like this are always at risk of 'rotting' over time, so better to not put them if they don't bring significant value.
I will drop it.
Quoted 9 lines
drivers/iio/temperature/ltc2983.c line 1144
Quoted 7 lines
drivers/iio/temperature/ltc2983.c new file +3
-0+ global_cfg =LTC2983_NOTCH_FREQ (st->filter_notch_freq); + global_cfg |=LTC2983_TEMP_UNITS (st->temp_farenheit); + regmap_write(st->regmap, LTC2983_GLOBAL_CONFIG_REG,
global_cfg);drivers/iio/temperature/ltc2983.c new file +1
-0+ regmap_write(st->regmap, LTC2983_MUX_CONFIG_REG, st-Quoted 1 line
mux_delay_config);drivers/iio/temperature/ltc2983.c new file +1
-0+/* setup channels */ This comment also not stating anything non obvious.
I will drop it.
Quoted 58 lines
Quoted 58 lines
drivers/iio/temperature/ltc2983.c new file +4
-0+for (chan =0 ; chan < st->num_channels; chan++) { +u32 chan_type =0 , *iio_chan; + + ret = st->sensors[chan]->assign_chan(st, st-Quoted 1 line
sensors[chan]);
drivers/iio/temperature/ltc2983.c new file +4
-0+if (ret) +return ret; +/* +* The assign_iio flag is necessary for when the device is
drivers/iio/temperature/ltc2983.c new file +5
-0+* coming out of sleep. In that case, we just need to +* re-configure the device channels. +* We also don't assign iio channels for rsense. +*/ + if (st->sensors[chan]->type ==
LTC2983_SENSOR_SENSE_RESISTOR||drivers/iio/temperature/ltc2983.c new file +5
-0+ !assign_iio) +continue ; + +/* assign iio channel */ + if (st->sensors[chan]->type !=
LTC2983_SENSOR_DIRECT_ADC) {drivers/iio/temperature/ltc2983.c new file +9
-0+ chan_type =IIO_TEMP ; + iio_chan = &iio_chan_t; + }else { + chan_type =IIO_VOLTAGE ; + iio_chan = &iio_chan_v; + } + +/* +* add chan as the iio .address so that, we can directly
drivers/iio/temperature/ltc2983.c new file +3
-0+* reference the sensor given the iio_chan_spec +*/ + st->iio_chan[iio_idx++] = LTC2983_CHAN(chan_type,(*iio_chan)++,
drivers/iio/temperature/ltc2983.c new file +2
-0+ chan, + st-Quoted 1 line
sensors[chan]->name);
drivers/iio/temperature/ltc2983.c new file +8
-0+ } + +return 0 ; +} + +static const struct regmap_range ltc2983_reg_ranges[] = { +regmap_reg_range (LTC2983_STATUS_REG ,LTC2983_STATUS_REG ), + regmap_reg_range(LTC2983_TEMP_RES_START_REG,
LTC2983_TEMP_RES_END_REG),drivers/iio/temperature/ltc2983.c new file +1
-0+ regmap_reg_range(LTC2983_GLOBAL_CONFIG_REG,
LTC2983_GLOBAL_CONFIG_REG),drivers/iio/temperature/ltc2983.c new file +3
-0+regmap_reg_range (LTC2983_MULT_CHANNEL_START_REG , +LTC2983_MULT_CHANNEL_END_REG ), + regmap_reg_range(LTC2983_MUX_CONFIG_REG,
LTC2983_MUX_CONFIG_REG),drivers/iio/temperature/ltc2983.c new file +4
-0+regmap_reg_range (LTC2983_CHAN_ASSIGN_START_REG , +LTC2983_CHAN_ASSIGN_END_REG ), +regmap_reg_range (LTC2983_CUST_SENS_TBL_START_REG , + LTC2983_CUST_SENS_TBL_END_REG),
Quoted 8 lines
drivers/iio/temperature/ltc2983.c line 1198
Quoted 6 lines
drivers/iio/temperature/ltc2983.c new file +6
-0+}; + +static const struct regmap_access_table ltc2983_reg_table = { + .yes_ranges = ltc2983_reg_ranges, + .n_yes_ranges =ARRAY_SIZE (ltc2983_reg_ranges), +};Blank line here.
ack.
Quoted 95 lines
Quoted 95 lines
+/*
+ * Thereg_bitsare actually 12 but the device needs the first *complete*
+ * byte for the command (R/W).
+ */drivers/iio/temperature/ltc2983.c new file +47
-0+static const struct regmap_config ltc2983_regmap_config = { + .reg_bits =24 , + .val_bits =8 , + .wr_table = <c2983_reg_table, + .rd_table = <c2983_reg_table, + .read_flag_mask =GENMASK (1 ,0 ), + .write_flag_mask =BIT (1 ), +}; + +static const struct iio_info ltc2983_iio_info = { + .read_raw = ltc2983_read_raw, + .debugfs_reg_access = ltc2983_reg_access, +}; + +static int ltc2983_probe (struct spi_device *spi) +{ +struct ltc2983_data *st; +struct iio_dev *indio_dev; +const char *name =spi_get_device_id (spi)->name; +int ret; + + indio_dev =devm_iio_device_alloc (&spi->dev,sizeof (*st)); +if (!indio_dev) +return -ENOMEM ; + + st =iio_priv (indio_dev); + + st->regmap =devm_regmap_init_spi (spi, <c2983_regmap_config); +if (IS_ERR (st->regmap)) { +dev_err (&spi->dev,"Failed to initialize regmap\n" ); +return PTR_ERR (st->regmap); + } + +mutex_init (&st->lock); +init_completion (&st->completion); + st->spi = spi; +spi_set_drvdata (spi, st); + + ret =ltc2983_parse_dt (st); +if (ret) +return ret; +/* +* let's request the irq now so it is used to sync the device +* startup in ltc2983_setup() +*/ + ret = devm_request_threaded_irq(&spi->dev, spi->irq, NULL, + ltc2983_irq_handler,
IRQF_ONESHOT|drivers/iio/temperature/ltc2983.c new file +3
-0+ IRQF_TRIGGER_RISING, name, st); +if (ret) { + dev_err(&spi->dev, "failed to request an irq, %d",ret);
drivers/iio/temperature/ltc2983.c new file +38
-0+return ret; + } + + ret =ltc2983_setup (st, true); +if (ret) +return ret; + + indio_dev->dev.parent = &spi->dev; + indio_dev->name = name; + indio_dev->num_channels = st->iio_channels; + indio_dev->channels = st->iio_chan; + indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->info = <c2983_iio_info; + +return devm_iio_device_register (&spi->dev, indio_dev); +} + +static int __maybe_unused ltc2983_resume (struct device *dev) +{ +struct ltc2983_data *st =spi_get_drvdata (to_spi_device (dev)); +int ret; + +mutex_lock (&st->lock); +/* dummy read to bring the device out of sleep */ +regmap_read (st->regmap,LTC2983_STATUS_REG , &ret); +/* we need to re-assign the channels */ + ret =ltc2983_setup (st, false); + st->reset = false; +mutex_unlock (&st->lock); + +return ret; +} + +static int __maybe_unused ltc2983_suspend (struct device *dev) +{ +struct ltc2983_data *st =spi_get_drvdata (to_spi_device (dev)); +int ret; +
Quoted 8 lines
drivers/iio/temperature/ltc2983.c line 1293
Quoted 4 lines
drivers/iio/temperature/ltc2983.c new file +2
-0+mutex_lock (&st->lock); + ret = regmap_write(st->regmap, LTC2983_STATUS_REG,
LTC2983_SLEEP);drivers/iio/temperature/ltc2983.c new file +1
-0+ st->reset = true;Naming seems a bit odd. The register field is called sleep, but we call
it reset internally?
I agree. Something like suspend or sleep for the boolean would be ok?
Quoted 36 lines
Quoted 36 lines
drivers/iio/temperature/ltc2983.c new file +6
-0+mutex_unlock (&st->lock); + +return ret; +} + +static SIMPLE_DEV_PM_OPS(ltc2983_pm_ops, ltc2983_suspend,
ltc2983_resume);drivers/iio/temperature/ltc2983.c new file +27
-0+ +static const struct spi_device_id ltc2983_id_table[] = { + {"ltc2983" }, + {}, +}; +MODULE_DEVICE_TABLE (spi, ltc2983_id_table); + +static const struct of_device_id ltc2983_of_match[] = { + { .compatible ="adi,ltc2983" }, + {}, +}; +MODULE_DEVICE_TABLE (of, ltc2983_id_table); + +static struct spi_driver ltc2983_driver = { + .driver = { + .name ="ltc2983" , + .of_match_table = ltc2983_of_match, + .pm = <c2983_pm_ops, + }, + .probe = ltc2983_probe, + .id_table = ltc2983_id_table, +}; + +module_spi_driver (ltc2983_driver); + +MODULE_AUTHOR ("Nuno Sa <[email protected]>" ); +MODULE_DESCRIPTION("Analog Devices LTC2983 SPI Temperaturesensors");
+MODULE_LICENSE("GPL");
Jonathan Cameron
maintainerQuoted 61 lines · Nuno
Hi Jonathan,
Thanks for the review.
Comments inline.Nuno Sá
Quoted 53 lines · Jonathan Cameron
Quoted 9 lines · On Mon, 9 Sep 2019 16:45:49 +0200 Nuno Sá <[email protected]> wrote:
The LTC2983 is a Multi-Sensor High Accuracy Digital Temperature Measurement System. It measures a wide variety of temperature sensors and
digitally outputs the result, in °C or °F, with 0.1°C accuracy and 0.001°C resolution. It can measure the temperature of all standard thermocouples (type B,E,J,K,N,S,R,T), standard 2-,3-,4-wire RTDs, thermistors and diodes.Signed-off-by Nuno Sá <[email protected]>Some comments inline. Main concern is around the interface, rest is minor
stuff.Jonathan
Quoted 21 lines
--- .../testing/sysfs-bus-iio-temperature-ltc2983 | 43 + MAINTAINERS | 7 + drivers/iio/temperature/Kconfig | 10 + drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/ltc2983.c | 1327 +++++++++++++++++ 5 files changed, 1388 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio- temperature-ltc2983 create mode 100644 drivers/iio/temperature/ltc2983.c(quoted diff) +0
-0ltc2983 b/Documentation/ABI/testing/sysfs-bus-iio-temperature- ltc2983
new file mode 100644
index 000000000000..3ad3440c0986Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +1
-0@@ -0,0 +1,43 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_tempY_thermQuoted 1 line
istor_rawFor each of these, I presume we know which type of device is attached at any time?
Using the channel naming to convey this (and I assume the fact that different
conversions need to be done in userspace?) is a bit messy. If we need
to convey the channel type, then a separatein_tempY_modeattribute may make more
sense. That would keep this ABI 'closer' to standard. Software that just logs
an unprocessed value could just work for example.
Quoted 8 lines
Quoted 2 lines
I'm not sure I've totally understood what is going on here though.
So, the
extend_namedoes not really bring any functional advantage. It was just an easy way for someone to know which kind of sensor the channel was referring to. In terms of conversions, all the work is done by the part for all the different sensor's and the scale is the same for all of them. So, I can just drop the extended name and use standard ABI if you prefer?
Please do. It may make sense to add an additional attribute to provide the info on the type of sensor, but we don't want to do anything that will create new ABI in the basic read path.
...
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +6
-0+ +static int __maybe_unused ltc2983_suspend(struct device *dev) +{ + struct ltc2983_data *st = spi_get_drvdata(to_spi_device(dev)); + int ret; +Quoted 8 lines
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983
Quoted 4 lines
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +2
-0+ mutex_lock(&st->lock); + ret = regmap_write(st->regmap, LTC2983_STATUS_REG,
LTC2983_SLEEP);Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +1
-0+ st->reset = true;Naming seems a bit odd. The register field is called sleep, but we call
it reset internally?
Quoted 2 lines
I agree. Something like
suspendorsleepfor the boolean would be ok?
yes.
Quoted 37 lines
Quoted 36 lines
Quoted 36 lines
Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +6
-0+ mutex_unlock(&st->lock); + + return ret; +} + +static SIMPLE_DEV_PM_OPS(ltc2983_pm_ops, ltc2983_suspend,
ltc2983_resume);Documentation/ABI/testing/sysfs-bus-iio-temperature-ltc2983 new file +27
-0+ +static const struct spi_device_id ltc2983_id_table[] = { + { "ltc2983" }, + {}, +}; +MODULE_DEVICE_TABLE(spi, ltc2983_id_table); + +static const struct of_device_id ltc2983_of_match[] = { + { .compatible = "adi,ltc2983" }, + {}, +}; +MODULE_DEVICE_TABLE(of, ltc2983_id_table); + +static struct spi_driver ltc2983_driver = { + .driver = { + .name = "ltc2983", + .of_match_table = ltc2983_of_match, + .pm = <c2983_pm_ops, + }, + .probe = ltc2983_probe, + .id_table = ltc2983_id_table, +}; + +module_spi_driver(ltc2983_driver); + +MODULE_AUTHOR("Nuno Sa <[email protected]>"); +MODULE_DESCRIPTION("Analog Devices LTC2983 SPI Temperaturesensors");
+MODULE_LICENSE("GPL");
Sa, Nuno
maintainerQuoted 89 lines · Jonathan Cameron
Quoted 73 lines · Nuno
Hi Jonathan,
Thanks for the review.
Comments inline.Nuno Sá
Quoted 62 lines · Jonathan Cameron
Quoted 11 lines · On Mon, 9 Sep 2019 16:45:49 +0200 Nuno Sá <[email protected]> wrote:
The LTC2983 is a Multi-Sensor High Accuracy Digital Temperature Measurement System. It measures a wide variety of temperature sensors and
digitally outputs the result, in °C or °F, with 0.1°C accuracy and
0.001°C resolution. It can measure the temperature of all standard
thermocouples (type B,E,J,K,N,S,R,T), standard 2-,3-,4-wire RTDs,
thermistors and diodes.Quoted 1 line
Signed-off-by Nuno Sá <[email protected]>Some comments inline. Main concern is around the interface, rest is
minor
stuff.Jonathan
Quoted 23 lines
--- .../testing/sysfs-bus-iio-temperature-ltc2983 | 43 + MAINTAINERS | 7 + drivers/iio/temperature/Kconfig | 10 + drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/ltc2983.c | 1327 +++++++++++++++++ 5 files changed, 1388 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio- temperature-ltc2983 create mode 100644 drivers/iio/temperature/ltc2983.c(quoted diff) +0
-0temperature-
ltc2983 b/Documentation/ABI/testing/sysfs-bus-iio-temperature- ltc2983
new file mode 100644
index 000000000000..3ad3440c0986Documentation/ABI/testing/sysfs-bus-iio-temperature- new file +0
-0ltc2983
Documentation/ABI/testing/sysfs-bus-iio-temperature- new file +1
-0@@ -0,0 +1,43 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_tempY_thermQuoted 1 line
istor_rawFor each of these, I presume we know which type of device is attached
at any time?
Using the channel naming to convey this (and I assume the fact that
different
conversions need to be done in userspace?) is a bit messy. If we need
to convey the channel type, then a separatein_tempY_modeattribute
may make more
sense. That would keep this ABI 'closer' to standard. Software that
just logs
an unprocessed value could just work for example.Quoted 3 lines
I'm not sure I've totally understood what is going on here though.
Quoted 11 lines
So, the
extend_namedoes not really bring any functional advantage.
It was just an easy way for someone to know which kind of sensor the
channel was referring to. In terms of conversions, all the work is done
by the part for all the different sensor's and the scale is the same
for all of them. So, I can just drop the extended name and use standard
ABI if you prefer?
Quoted 4 lines
Please do. It may make sense to add an additional attribute to provide
the info on the type of sensor, but we don't want to do anything that will create new ABI in the basic read path.
There is already a v2 that I've sent last week which drops the extend_name. I guess we would need the type of sensor plus the channel number. Either way, I guess that can be added later if someone actually needs it.
Quoted 17 lines
...
Quoted 16 lines
Quoted 16 lines
Documentation/ABI/testing/sysfs-bus-iio-temperature-
Quoted 11 lines
Documentation/ABI/testing/sysfs-bus-iio-temperature- new file +4
-0+ +static int __maybe_unused ltc2983_suspend(struct device *dev) +{ + struct ltc2983_data *st =spi_get_drvdata(to_spi_device(dev));
Documentation/ABI/testing/sysfs-bus-iio-temperature- new file +4
-0+ int ret; + + mutex_lock(&st->lock); + ret = regmap_write(st->regmap, LTC2983_STATUS_REG,
LTC2983_SLEEP);Documentation/ABI/testing/sysfs-bus-iio-temperature- new file +1
-0+ st->reset = true;Naming seems a bit odd. The register field is called sleep, but we
call
it reset internally?
Quoted 5 lines
Quoted 3 lines
I agree. Something like
suspendorsleepfor the boolean would be
ok?yes.
Renamed to sleep.
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Documentation/ABI/testing/sysfs-bus-iio-temperature- new file +6
-0+ mutex_unlock(&st->lock); + + return ret; +} + +static SIMPLE_DEV_PM_OPS(ltc2983_pm_ops, ltc2983_suspend,
ltc2983_resume);Documentation/ABI/testing/sysfs-bus-iio-temperature- new file +27
-0+ +static const struct spi_device_id ltc2983_id_table[] = { + { "ltc2983" }, + {}, +}; +MODULE_DEVICE_TABLE(spi, ltc2983_id_table); + +static const struct of_device_id ltc2983_of_match[] = { + { .compatible = "adi,ltc2983" }, + {}, +}; +MODULE_DEVICE_TABLE(of, ltc2983_id_table); + +static struct spi_driver ltc2983_driver = { + .driver = { + .name = "ltc2983", + .of_match_table = ltc2983_of_match, + .pm = <c2983_pm_ops, + }, + .probe = ltc2983_probe, + .id_table = ltc2983_id_table, +}; + +module_spi_driver(ltc2983_driver); + +MODULE_AUTHOR("Nuno Sa <[email protected]>"); +MODULE_DESCRIPTION("Analog Devices LTC2983 SPI Temperaturesensors");
+MODULE_LICENSE("GPL");