xilinx: Add support for Xilinx Sysmon IP
Subsystems (4)
cover xilinx: Add support for Xilinx Sysmon IP
Hi,
the series is adding support for Xilinx Sysmon IP available on Versal SOCs. The series also contains thermal driver which is using Sysmon for providing temperature information.
As the part of it is also monitoring AI engine.
Thanks,
Michal
Anish Kadamathikuttiyil Karthikeyan Pillai (2):
iio: adc: versal-sysmon: Support AI Engine thermal monitoring
thermal: versal-thermal: Support thermal management in AI Engine
Salih Erim (4):
dt-bindings: iio: xilinx: Add Documentation for Sysmon
iio: versal-sysmon: add driver for Versal Sysmon
dt-bindings: thermal: versal: Add description for Versal Thermal
thermal: versal-thermal: Add Versal thermal driver
.../bindings/iio/adc/xlnx,versal-sysmon.yaml | 235 +++ .../bindings/thermal/xlnx,versal-thermal.yaml | 45 + MAINTAINERS | 13 + drivers/iio/adc/Kconfig | 15 + drivers/iio/adc/Makefile | 2 + drivers/iio/adc/versal-sysmon-core.c | 1379 +++++++++++++++++ drivers/iio/adc/versal-sysmon.c | 297 ++++ drivers/iio/adc/versal-sysmon.h | 278 ++++ drivers/thermal/Kconfig | 12 + drivers/thermal/Makefile | 1 + drivers/thermal/versal_thermal.c | 221 +++ include/linux/iio/adc/versal-sysmon-events.h | 56 + 12 files changed, 2554 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml create mode 100644 Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml create mode 100644 drivers/iio/adc/versal-sysmon-core.c create mode 100644 drivers/iio/adc/versal-sysmon.c create mode 100644 drivers/iio/adc/versal-sysmon.h create mode 100644 drivers/thermal/versal_thermal.c create mode 100644 include/linux/iio/adc/versal-sysmon-events.h
Signature · 1 line
2.43.0
PATCH 1/6 dt-bindings: iio: xilinx: Add Documentation for Sysmon
From: Salih Erim <[email protected]>
Add devicetree documentation for Xilinx Sysmon IP which is used for internal chip monitoring on Xilinx Versal SOCs.
---
.../bindings/iio/adc/xlnx,versal-sysmon.yaml | 235 ++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +235 -0
@@ -0,0 +1,235 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/xlnx,versal-sysmon.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Xilinx Versal Sysmon + +maintainers: + - Salih Erim <[email protected]> + +description: + The Xilinx Sysmon provides on-chip monitoring and control for the supply + voltages and temperatures across the chip. Since there are only 160 supply + voltage registers and 184 measurement points, there is no constant mapping + of supply voltage registers and the measurement points. User has to select + the voltages to monitor in design tool. Depending on the selection, a voltage + supply gets mapped to one of the supply registers. So, this mapping information + is provided via description which contain the information of name of + the supply enabled and the supply register it maps to. + +properties: + compatible: + items: + - const: xlnx,versal-sysmon + + reg: + maxItems: 1 + description: Sysmon Registers. + + interrupts: + maxItems: 1 + description: Interrupt line for Sysmon. + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + '#io-channel-cells': + const: 0 + + xlnx,hbm: + type: boolean + description: + Exists if node refers to a HBM (High Bandwidth Memory) SLR (Super Logic Region). + + xlnx,nodeid: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + PLM specified sysmon node id. + + xlnx,numaiechannels: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + maximum: 64 + description: + Total number of sysmon satellites close to AI Engine exposed as channels. + + xlnx,numchannels: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + maximum: 160 + description: + Number of supply channels enabled in the design. + +patternProperties: + "^supply@([0-9]{1,2}|1[0-5][0-9])$": + type: object + description: + Represents the supplies configured in the design. + + properties: + reg: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 159 + description: + The supply number associated with the voltage. + + xlnx,name: + $ref: /schemas/types.yaml#/definitions/string + description: + Name of the supply enabled + + xlnx,bipolar: + $ref: /schemas/types.yaml#/definitions/flag + description: + If the supply has a bipolar type and the output will be signed. + + required: + - reg + - xlnx,name + + additionalProperties: false + + "^temp@([1-9]|[1-5][0-9]|6[0-4])$": + type: object + description: + Represents the sysmon temperature satellites. + + properties: + reg: + minimum: 1 + maximum: 64 + description: + The sysmon temperature satellite number. + + xlnx,aie-temp: + $ref: /schemas/types.yaml#/definitions/flag + description: + If present it indicates the temperature satellite is in + close proximity with AI Engine + + xlnx,name: + $ref: /schemas/types.yaml#/definitions/string + description: + Name of temperature satellite exposed + + required: + - reg + - xlnx,name + + additionalProperties: false + +required: + - compatible + - reg + - xlnx,numchannels + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + sysmon@f1270000 { + compatible = "xlnx,versal-sysmon"; + reg = <0xf1270000 0x4000>; + interrupts = <0 0x90 IRQ_TYPE_LEVEL_HIGH>; + xlnx,numchannels = <8>; + xlnx,numaiechannels = <8>; + xlnx,nodeid = <0x18224055>; + #address-cells = <1>; + #size-cells = <0>; + supply@0 { + reg = <0>; + xlnx,name = "vccint"; + }; + + supply@31 { + reg = <31>; + xlnx,name = "vccsoc"; + }; + + supply@32 { + reg = <32>; + xlnx,bipolar; + xlnx,name = "vccram"; + }; + + supply@63 { + reg = <63>; + xlnx,bipolar; + xlnx,name = "vccaux"; + }; + + supply@64 { + reg = <64>; + xlnx,name = "vccbram"; + }; + + supply@95 { + reg = <95>; + xlnx,name = "gt_avaux"; + }; + + supply@96 { + reg = <96>; + xlnx,name = "gt_vccaux"; + }; + + supply@159 { + reg = <159>; + xlnx,name = "vccint_ir"; + }; + + temp@7 { + reg = <7>; + xlnx,aie-temp; + xlnx,name = "aie-temp-ch0"; + }; + + temp@8 { + reg = <8>; + xlnx,aie-temp; + xlnx,name = "aie-temp-ch1"; + }; + + temp@14 { + reg = <14>; + xlnx,aie-temp; + xlnx,name = "aie-temp-ch2"; + }; + + temp@15 { + reg = <15>; + xlnx,aie-temp; + xlnx,name = "aie-temp-ch3"; + }; + + temp@16 { + reg = <16>; + xlnx,aie-temp; + xlnx,name = "aie-temp-ch4"; + }; + + temp@30 { + reg = <30>; + xlnx,aie-temp; + xlnx,name = "aie-temp-ch5"; + }; + + temp@33 { + reg = <33>; + xlnx,aie-temp; + xlnx,name = "aie-temp-ch6"; + }; + + temp@34 { + reg = <34>; + xlnx,aie-temp; + xlnx,name = "aie-temp-ch7"; + }; + };
Signature · 1 line
2.43.0
Re: [PATCH 1/6] dt-bindings: iio: xilinx: Add Documentation for Sysmon
Quoted 72 lines · On Fri, 5 Sep 2025 10:41:44 +0200 Michal Simek <[email protected]> wrote:
From: Salih Erim <[email protected]>
Add devicetree documentation for Xilinx Sysmon IP which is used for internal chip monitoring on Xilinx Versal SOCs.
Co-developed-by Anand Ashok Dumbre <[email protected]>Signed-off-by Anand Ashok Dumbre <[email protected]>Co-developed-by Anish Kadamathikuttiyil Karthikeyan Pillai <[email protected]>Signed-off-by Salih Erim <[email protected]>Signed-off-by Michal Simek <[email protected]>---
.../bindings/iio/adc/xlnx,versal-sysmon.yaml | 235 ++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yamlDocumentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +49
-0@@ -0,0 +1,235 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/xlnx,versal-sysmon.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Xilinx Versal Sysmon + +maintainers: + - Salih Erim <[email protected]> + +description: + The Xilinx Sysmon provides on-chip monitoring and control for the supply + voltages and temperatures across the chip. Since there are only 160 supply + voltage registers and 184 measurement points, there is no constant mapping + of supply voltage registers and the measurement points. User has to select + the voltages to monitor in design tool. Depending on the selection, a voltage + supply gets mapped to one of the supply registers. So, this mapping information + is provided via description which contain the information of name of + the supply enabled and the supply register it maps to. + +properties: + compatible: + items: + - const: xlnx,versal-sysmon + + reg: + maxItems: 1 + description: Sysmon Registers. + + interrupts: + maxItems: 1 + description: Interrupt line for Sysmon. + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + '#io-channel-cells': + const: 0 + + xlnx,hbm: + type: boolean + description: + Exists if node refers to a HBM (High Bandwidth Memory) SLR (Super Logic Region). + + xlnx,nodeid:
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 59
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +10
-0+ $ref: /schemas/types.yaml#/definitions/uint32 + description: + PLM specified sysmon node id. + + xlnx,numaiechannels: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + maximum: 64 + description: + Total number of sysmon satellites close to AI Engine exposed as channels.
Feels like some use - would make this easier to parse. xlnx,num-aie-channels. Similar to the next one. How is this related to the number of child nodes?
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 66
Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +7
-0+ + xlnx,numchannels: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + maximum: 160 + description: + Number of supply channels enabled in the design.
Given you have subnodes called supplyxxx why is a count of those needed or is this not counting those?
Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +9
-0+ +patternProperties: + "^supply@([0-9]{1,2}|1[0-5][0-9])$": + type: object + description: + Represents the supplies configured in the design. + + properties: + reg:
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 85
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +10
-0+ $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 159 + description: + The supply number associated with the voltage. + + xlnx,name: + $ref: /schemas/types.yaml#/definitions/string + description: + Name of the supply enabled
Would the generic property "label" be useable here?
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 90
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +5
-0+ + xlnx,bipolar: + $ref: /schemas/types.yaml#/definitions/flag + description: + If the supply has a bipolar type and the output will be signed.
This is very generic. We have it described for ADC channels already in bindings/iio/adc/adc.yaml. Why can't we use that here?
That binding does rely on matching against 'channel' for node names though. Where a 'type of channel' has been relevant IIRC we've always added a separate property rather than using the child node name.
Quoted 14 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +14
-0+ + required: + - reg + - xlnx,name + + additionalProperties: false + + "^temp@([1-9]|[1-5][0-9]|6[0-4])$": + type: object + description: + Represents the sysmon temperature satellites. + + properties: + reg:
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 114
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +10
-0+ minimum: 1 + maximum: 64 + description: + The sysmon temperature satellite number. + + xlnx,aie-temp: + $ref: /schemas/types.yaml#/definitions/flag + description: + If present it indicates the temperature satellite is in + close proximity with AI Engine
This one seems unusual. I guess it makes a configuration difference of some type. I'll look at the code to see if that answers the question.
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 119
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +5
-0+ + xlnx,name: + $ref: /schemas/types.yaml#/definitions/string + description: + Name of temperature satellite exposed
As above. label tends to get used for things like this.
Quoted 13 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +13
-0+ + required: + - reg + - xlnx,name + + additionalProperties: false + +required: + - compatible + - reg + - xlnx,numchannels + +additionalProperties: false
Re: [PATCH 1/6] dt-bindings: iio: xilinx: Add Documentation for Sysmon
Quoted 80 lines · Jonathan Cameron
Quoted 77 lines · On Fri, 5 Sep 2025 10:41:44 +0200 Michal Simek <[email protected]> wrote:
From: Salih Erim <[email protected]>
Add devicetree documentation for Xilinx Sysmon IP which is used for internal chip monitoring on Xilinx Versal SOCs.
Co-developed-by Anand Ashok Dumbre <[email protected]>Signed-off-by Anand Ashok Dumbre <[email protected]>Co-developed-by Anish Kadamathikuttiyil Karthikeyan Pillai <[email protected]>Signed-off-by Salih Erim <[email protected]>Signed-off-by Michal Simek <[email protected]>---
.../bindings/iio/adc/xlnx,versal-sysmon.yaml | 235 ++++++++++++++++++ 1 file changed, 235 insertions(+)create mode 100644
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yamlDocumentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +54
-0@@ -0,0 +1,235 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/xlnx,versal-sysmon.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Xilinx Versal Sysmon + +maintainers: + - Salih Erim <[email protected]> + +description: + The Xilinx Sysmon provides on-chip monitoring and control for the supply + voltages and temperatures across the chip. Since there are only 160 supply + voltage registers and 184 measurement points, there is no constant mapping + of supply voltage registers and the measurement points. User has to select + the voltages to monitor in design tool. Depending on the selection, a voltage + supply gets mapped to one of the supply registers. So, this mapping information + is provided via description which contain the information of name of + the supply enabled and the supply register it maps to. + +properties: + compatible: + items: + - const: xlnx,versal-sysmon + + reg: + maxItems: 1 + description: Sysmon Registers. + + interrupts: + maxItems: 1 + description: Interrupt line for Sysmon. + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + '#io-channel-cells': + const: 0 + + xlnx,hbm: + type: boolean + description: + Exists if node refers to a HBM (High Bandwidth Memory) SLR (Super Logic Region). + + xlnx,nodeid: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + PLM specified sysmon node id. + + xlnx,numaiechannels:
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 59
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +5
-0+ $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + maximum: 64 + description: + Total number of sysmon satellites close to AI Engine exposed as channels.Feels like some use - would make this easier to parse. xlnx,num-aie-channels. Similar to the next one. How is this related to the number of child nodes?
it is number of childs below. They can be calculated to get this number.
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 66
Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +7
-0+ + xlnx,numchannels: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + maximum: 160 + description: + Number of supply channels enabled in the design.
Quoted 2 lines
Given you have subnodes called supplyxxx why is a count of those needed or is this not counting those?
possible.
Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +13
-0+ +patternProperties: + "^supply@([0-9]{1,2}|1[0-5][0-9])$": + type: object + description: + Represents the supplies configured in the design. + + properties: + reg: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 159 + description:
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 85
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +6
-0+ The supply number associated with the voltage. + + xlnx,name: + $ref: /schemas/types.yaml#/definitions/string + description: + Name of the supply enabledWould the generic property "label" be useable here?
label should be fine.
Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 90
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +5
-0+ + xlnx,bipolar: + $ref: /schemas/types.yaml#/definitions/flag + description: + If the supply has a bipolar type and the output will be signed.This is very generic. We have it described for ADC channels already in
bindings/iio/adc/adc.yaml. Why can't we use that here?
no issue with it.
And likely Documentation/devicetree/bindings/iio/adc/xlnx,zynqmp-ams.yaml should deprecated it and start to use new one.
Quoted 3 lines
That binding does rely on matching against 'channel' for node names though. Where a 'type of channel' has been relevant IIRC we've always added a separate property rather than using the child node name.
Is this related to supply/temp channel name?
I think one issue with the binding is that current schema allows to define supply@1 and also temp@1
but both of them have reg = <1> which is not allowed (duplicate unit-address).
Salih: What does this reg value means? Is it physical address where that sensor is placed?
Quoted 20 lines
Quoted 20 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +19
-0+ + required: + - reg + - xlnx,name + + additionalProperties: false + + "^temp@([1-9]|[1-5][0-9]|6[0-4])$": + type: object + description: + Represents the sysmon temperature satellites. + + properties: + reg: + minimum: 1 + maximum: 64 + description: + The sysmon temperature satellite number. +
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 114
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +5
-0+ xlnx,aie-temp: + $ref: /schemas/types.yaml#/definitions/flag + description: + If present it indicates the temperature satellite is in + close proximity with AI EngineThis one seems unusual. I guess it makes a configuration difference of some type. I'll look at the code to see if that answers the question.
it is supposed to be identify location of this sensor.
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 119
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +5
-0+ + xlnx,name: + $ref: /schemas/types.yaml#/definitions/string + description: + Name of temperature satellite exposedAs above. label tends to get used for things like this.
no issue with this.
Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +5
-0+ + required: + - reg + - xlnx,name +
Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 132
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +8
-0+ additionalProperties: false + +required: + - compatible + - reg + - xlnx,numchannels + +additionalProperties: false
Thanks,
Michal
Erim, Salih
maintainerRE: [PATCH 1/6] dt-bindings: iio: xilinx: Add Documentation for Sysmon
[AMD Official Use Only - AMD Internal Distribution Only]
Hi Michal and Jonathan,
Quoted 185 lines
-----Original Message-----
From: Simek, Michal <[email protected]>
Sent: Friday, September 5, 2025 1:30 PM
To: Jonathan Cameron <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Erim, Salih <[email protected]>; Anand Ashok Dumbre <[email protected]>; Kadamathikuttiyil Karthikeyan Pillai, Anish <[email protected]>; Andy Shevchenko <[email protected]>; Conor Dooley <[email protected]>; David Lechner <[email protected]>; Jonathan Cameron <[email protected]>; Krzysztof Kozlowski <[email protected]>; Nuno Sá <[email protected]>; Rob Herring <[email protected]>; open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS <[email protected]>; open list:IIO SUBSYSTEM AND DRIVERS <[email protected]>
Subject: Re: [PATCH 1/6] dt-bindings: iio: xilinx: Add Documentation for SysmonQuoted 76 lines · Jonathan Cameron
Quoted 73 lines · On Fri, 5 Sep 2025 10:41:44 +0200 Michal Simek <[email protected]> wrote:
From: Salih Erim <[email protected]>
Add devicetree documentation for Xilinx Sysmon IP which is used for internal chip monitoring on Xilinx Versal SOCs.
Co-developed-by Anand Ashok Dumbre <[email protected]>Signed-off-by Anand Ashok Dumbre <[email protected]>Co-developed-by Anish Kadamathikuttiyil Karthikeyan Pillai<[email protected]>
Signed-off-by: Anish Kadamathikuttiyil Karthikeyan Pillai <[email protected]>Signed-off-by Salih Erim <[email protected]>Signed-off-by Michal Simek <[email protected]>---
.../bindings/iio/adc/xlnx,versal-sysmon.yaml | 235 ++++++++++++++++++ 1 file changed, 235 insertions(+)create mode 100644
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yamldiff --git
a/Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yamlb/Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yamlnew file mode 100644
index 000000000000..a768395cade7Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya new file +45
-0+++ ml@@ -0,0 +1,235 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) %YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/xlnx,versal-sysmon.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Xilinx Versal Sysmon + +maintainers: + - Salih Erim <[email protected]> + +description: + The Xilinx Sysmon provides on-chip monitoring and control for the +supply + voltages and temperatures across the chip. Since there are only +160 supply + voltage registers and 184 measurement points, there is no constant +mapping + of supply voltage registers and the measurement points. User has +to select + the voltages to monitor in design tool. Depending on the +selection, a voltage + supply gets mapped to one of the supply registers. So, this +mapping information + is provided via description which contain the information of name of + the supply enabled and the supply register it maps to. + +properties: + compatible: + items: + - const: xlnx,versal-sysmon + + reg: + maxItems: 1 + description: Sysmon Registers. + + interrupts: + maxItems: 1 + description: Interrupt line for Sysmon. + + '#address-cells': + const: 1 + + '#size-cells': + const: 0Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya line 52
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya new file +8
-0+ + '#io-channel-cells': + const: 0 + + xlnx,hbm: + type: boolean + description: + Exists if node refers to a HBM (High Bandwidth Memory) SLR (Super LogicRegion).
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya new file +7
-0+ + xlnx,nodeid: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + PLM specified sysmon node id. + + xlnx,numaiechannels:Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya line 64
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya new file +5
-0+ $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + maximum: 64 + description: + Total number of sysmon satellites close to AI Engine exposed as channels.Feels like some use - would make this easier to parse. xlnx,num-aie-channels. Similar to the next one. How is this related to the number of child nodes?
it is number of childs below. They can be calculated to get this number.
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya line 71
Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya new file +7
-0+ + xlnx,numchannels: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + maximum: 160 + description: + Number of supply channels enabled in the design.Quoted 2 lines
Given you have subnodes called supplyxxx why is a count of those needed or is this not counting those?
possible.
Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya new file +13
-0+ +patternProperties: + "^supply@([0-9]{1,2}|1[0-5][0-9])$": + type: object + description: + Represents the supplies configured in the design. + + properties: + reg: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 159 + description:Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya line 90
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya new file +6
-0+ The supply number associated with the voltage. + + xlnx,name: + $ref: /schemas/types.yaml#/definitions/string + description: + Name of the supply enabledWould the generic property "label" be useable here?
label should be fine.
Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya line 95
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya new file +5
-0+ + xlnx,bipolar: + $ref: /schemas/types.yaml#/definitions/flag + description: + If the supply has a bipolar type and the output will be signed.This is very generic. We have it described for ADC channels already in
bindings/iio/adc/adc.yaml. Why can't we use that here?no issue with it.
And likelyDocumentation/devicetree/bindings/iio/adc/xlnx,zynqmp-ams.yamlshould deprecated it and start to use new one.Quoted 3 lines
That binding does rely on matching against 'channel' for node names though. Where a 'type of channel' has been relevant IIRC we've always added a separate property rather than using the child node name.
Quoted 8 lines
Is this related to supply/temp channel name?
I think one issue with the binding is that current schema allows to define supply@1 and also temp@1
but both of them have reg = <1> which is not allowed (duplicate unit-address).Salih: What does this reg value means? Is it physical address where that sensor is placed?
Reg is offset index to offset base of the memory addresses for each. Supplies and temp values are located in different offsets.
Quoted 58 lines
Quoted 21 lines
Quoted 21 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya new file +19
-0+ + required: + - reg + - xlnx,name + + additionalProperties: false + + "^temp@([1-9]|[1-5][0-9]|6[0-4])$": + type: object + description: + Represents the sysmon temperature satellites. + + properties: + reg: + minimum: 1 + maximum: 64 + description: + The sysmon temperature satellite number. +Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya line 119
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya new file +5
-0+ xlnx,aie-temp: + $ref: /schemas/types.yaml#/definitions/flag + description: + If present it indicates the temperature satellite is in + close proximity with AI EngineThis one seems unusual. I guess it makes a configuration difference of some type. I'll look at the code to see if that answers the question.
it is supposed to be identify location of this sensor.
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya line 124
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya new file +5
-0+ + xlnx,name: + $ref: /schemas/types.yaml#/definitions/string + description: + Name of temperature satellite exposedAs above. label tends to get used for things like this.
no issue with this.
Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya new file +5
-0+ + required: + - reg + - xlnx,name +Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya line 137
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.ya new file +8
-0+ additionalProperties: false + +required: + - compatible + - reg + - xlnx,numchannels + +additionalProperties: falseThanks,
Michal
David Lechner
reviewerRe: [PATCH 1/6] dt-bindings: iio: xilinx: Add Documentation for Sysmon
On 9/5/25 9:21 AM, Erim, Salih wrote:
...
Quoted 27 lines
Quoted 27 lines
Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 90
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +5
-0+ + xlnx,bipolar: + $ref: /schemas/types.yaml#/definitions/flag + description: + If the supply has a bipolar type and the output will be signed.This is very generic. We have it described for ADC channels already in
bindings/iio/adc/adc.yaml. Why can't we use that here?no issue with it.
And likelyDocumentation/devicetree/bindings/iio/adc/xlnx,zynqmp-ams.yamlshould deprecated it and start to use new one.Quoted 3 lines
That binding does rely on matching against 'channel' for node names though. Where a 'type of channel' has been relevant IIRC we've always added a separate property rather than using the child node name.
Is this related to supply/temp channel name?
I think one issue with the binding is that current schema allows to define supply@1 and also temp@1
but both of them have reg = <1> which is not allowed (duplicate unit-address).
Quoted 6 lines
Quoted 2 lines
Salih: What does this reg value means? Is it physical address where that sensor is placed?
Reg is offset index to offset base of the memory addresses for each. Supplies and temp values are located in different offsets.
Sounds like the .dts should looks like:
adc@f1270000 {
compatible = "xlnx,versal-sysmon";
reg = <0xf1270000 0x4000>;
...
supply-channels {
#size-cells = <0>;
#address-cells = <1>;
channel@0 {
reg = <0>;
label = "vccint";
};
...
};
temperature-channels {
#size-cells = <0>;
#address-cells = <1>;
channel@0 {
reg = <0>;
label = "aie-temp-ch0";
};
...
};
};Jonathan Cameron
maintainerRe: [PATCH 1/6] dt-bindings: iio: xilinx: Add Documentation for Sysmon
Quoted 61 lines · On Fri, 5 Sep 2025 15:44:20 -0500 David Lechner <[email protected]> wrote:
On 9/5/25 9:21 AM, Erim, Salih wrote:
...
Quoted 27 lines
Quoted 27 lines
Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 90
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +5
-0+ + xlnx,bipolar: + $ref: /schemas/types.yaml#/definitions/flag + description: + If the supply has a bipolar type and the output will be signed.This is very generic. We have it described for ADC channels already in
bindings/iio/adc/adc.yaml. Why can't we use that here?no issue with it.
And likelyDocumentation/devicetree/bindings/iio/adc/xlnx,zynqmp-ams.yamlshould deprecated it and start to use new one.Quoted 3 lines
That binding does rely on matching against 'channel' for node names though. Where a 'type of channel' has been relevant IIRC we've always added a separate property rather than using the child node name.
Is this related to supply/temp channel name?
I think one issue with the binding is that current schema allows to define supply@1 and also temp@1
but both of them have reg = <1> which is not allowed (duplicate unit-address).Quoted 6 lines
Quoted 2 lines
Salih: What does this reg value means? Is it physical address where that sensor is placed?
Reg is offset index to offset base of the memory addresses for each. Supplies and temp values are located in different offsets.
Sounds like the .dts should looks like:
adc@f1270000 { compatible = "xlnx,versal-sysmon"; reg = <0xf1270000 0x4000>; ... supply-channels { #size-cells = <0>; #address-cells = <1>; channel@0 { reg = <0>; label = "vccint"; }; ... }; temperature-channels { #size-cells = <0>; #address-cells = <1>;
Quoted 8 lines
channel@0 {
reg = <0>;
label = "aie-temp-ch0";
};
...
};
};This works for me. Alternative would be something similar to what we did for
dt-bindings: iio: adc: Add AD4170-4
Where there is an adi,sensor-type property in channels.
There they two types of channels were the same underlying hardware, it just provided a way to constrain the other properties in the channel nodes. That differs from here where, as I understand it (Salih?) they are different hardware blocks so 'reg' is an offset into a different set of registers.
DT maintainers, I think this discussion would benefit from your guidance!
Thanks,
Jonathan
Erim, Salih
maintainerRE: [PATCH 1/6] dt-bindings: iio: xilinx: Add Documentation for Sysmon
Hi David and Jonathan,
Quoted 17 lines
-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, September 7, 2025 11:51 AM
To: David Lechner <[email protected]>
Cc: Erim, Salih <[email protected]>; Simek, Michal <[email protected]>; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Anand Ashok Dumbre <[email protected]>; Kadamathikuttiyil Karthikeyan Pillai, Anish <[email protected]>; Andy Shevchenko <[email protected]>; Conor Dooley <[email protected]>; Krzysztof Kozlowski <[email protected]>; Nuno Sá <[email protected]>; Rob Herring <[email protected]>; open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS <[email protected]>; open list:IIO SUBSYSTEM AND DRIVERS <[email protected]>
Subject: Re: [PATCH 1/6] dt-bindings: iio: xilinx: Add Documentation for Sysmon
Quoted 78 lines
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 70 lines · On Fri, 5 Sep 2025 15:44:20 -0500 David Lechner <[email protected]> wrote:
On 9/5/25 9:21 AM, Erim, Salih wrote:
...
Quoted 28 lines
Quoted 28 lines
Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml line 90
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml new file +5
-0+ + xlnx,bipolar: + $ref: /schemas/types.yaml#/definitions/flag + description: + If the supply has a bipolar type and the output will be signed.This is very generic. We have it described for ADC channels already in
bindings/iio/adc/adc.yaml. Why can't we use that here?no issue with it.
And likelyDocumentation/devicetree/bindings/iio/adc/xlnx,zynqmp-ams.yamlshould deprecated it and start to use new one.Quoted 3 lines
That binding does rely on matching against 'channel' for node names though. Where a 'type of channel' has been relevant IIRC we've always added a separate property rather than using the child node name.
Is this related to supply/temp channel name?
I think one issue with the binding is that current schema allows to define
supply@1 and also temp@1
but both of them have reg = <1> which is not allowed (duplicate unit-address).Quoted 6 lines
Quoted 2 lines
Salih: What does this reg value means? Is it physical address where that sensor is placed?
Reg is offset index to offset base of the memory addresses for each. Supplies and temp values are located in different offsets.
Sounds like the .dts should looks like:
adc@f1270000 { compatible = "xlnx,versal-sysmon"; reg = <0xf1270000 0x4000>; ... supply-channels { #size-cells = <0>; #address-cells = <1>; channel@0 { reg = <0>; label = "vccint"; }; ... }; temperature-channels { #size-cells = <0>; #address-cells = <1>; channel@0 { reg = <0>; label = "aie-temp-ch0"; }; ... }; };
This seems to logical to me as well, only I am not sure if there are any restrictions.
Quoted 7 lines
This works for me. Alternative would be something similar to what we did for
dt-bindings: iio: adc: Add AD4170-4
Where there is an adi,sensor-type property in channels.
There they two types of channels were the same underlying hardware, it just provided a way to constrain the other properties in the channel nodes. That differs from here where, as I understand it (Salih?) they are different hardware blocks so 'reg' is an offset into a different set of registers.
Yes, there two types of channels, temperatures, and supplies(voltages) distributed across SoC Connected to same hardware block but sets of sensor value registers are separately located (base offsets). Reg is just offset to sensors memory addresses their base offsets.
I will check the AD4170 example how it manages.
Quoted 8 lines
DT maintainers, I think this discussion would benefit from your guidance!
Thanks,
Jonathan
Regards,
Salih.
PATCH 2/6 iio: versal-sysmon: add driver for Versal Sysmon
In reply to Michal SimekFrom: Salih Erim <[email protected]>
Sysmon Driver uses Linux IIO framework, which was used to abstract the supply voltages and temperatures across the chip as Voltage and Temperature Channels in the framework. Since there are only 160 supply voltage registers and 184 measurement points, there is no constant mapping of supply voltage registers and the measurement points. User has to select the voltages to monitor in design tool. Depending on the selection, a voltage supply gets mapped to one of the supply registers. So, this mapping information is provided to the driver via a device tree. Depending on the number of supplies enabled in the design, the device tree will contain the information of name of the supply enabled and the supply register it maps to.
---
MAINTAINERS | 7 + drivers/iio/adc/Kconfig | 15 + drivers/iio/adc/Makefile | 2 + drivers/iio/adc/versal-sysmon-core.c | 1334 ++++++++++++++++++ drivers/iio/adc/versal-sysmon.c | 264 ++++ drivers/iio/adc/versal-sysmon.h | 275 ++++ include/linux/iio/adc/versal-sysmon-events.h | 56 + 7 files changed, 1953 insertions(+) create mode 100644 drivers/iio/adc/versal-sysmon-core.c create mode 100644 drivers/iio/adc/versal-sysmon.c create mode 100644 drivers/iio/adc/versal-sysmon.h create mode 100644 include/linux/iio/adc/versal-sysmon-events.h
MAINTAINERS +7 -0
@@ -27602,6 +27602,13 @@ F: Documentation/misc-devices/xilinx_sdfec.rst F: drivers/misc/xilinx_sdfec.c F: include/uapi/misc/xilinx_sdfec.h +XILINX VERSAL SYSMON DRIVER +M: Salih Erim <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml +F: drivers/iio/adc/versal-sysmon* +F: include/linux/iio/adc/versal-sysmon-events.h + XILINX UARTLITE SERIAL DRIVER M: Peter Korsgaard <[email protected]> L: [email protected]
drivers/iio/adc/Kconfig +15 -0
@@ -1821,4 +1821,19 @@ config XILINX_AMS The driver can also be built as a module. If so, the module will be called xilinx-ams. +config VERSAL_SYSMON_CORE + tristate + +config VERSAL_SYSMON + tristate "Xilinx Sysmon driver for Versal" + depends on HAS_IOMEM + select VERSAL_SYSMON_CORE + help + Say yes here to have support for the Xilinx Sysmon. + The driver will enable users to monitor temperature and voltage on the + Xilinx Versal platform. + + The driver can also be build as a module. If so, the module will be called + versal-sysmon. + endmenu
drivers/iio/adc/Makefile +2 -0
@@ -159,3 +159,5 @@ obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o obj-$(CONFIG_XILINX_AMS) += xilinx-ams.o xilinx-xadc-y := xilinx-xadc-core.o xilinx-xadc-events.o obj-$(CONFIG_XILINX_XADC) += xilinx-xadc.o +obj-$(CONFIG_VERSAL_SYSMON_CORE) += versal-sysmon-core.o +obj-$(CONFIG_VERSAL_SYSMON) += versal-sysmon.o
drivers/iio/adc/versal-sysmon-core.c new file +1334 -0
1,334 lines not on this page · raw message
drivers/iio/adc/versal-sysmon.c new file +264 -0
264 lines not on this page · raw message
drivers/iio/adc/versal-sysmon.h new file +275 -0
275 lines not on this page · raw message
include/linux/iio/adc/versal-sysmon-events.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 2/6] iio: versal-sysmon: add driver for Versal Sysmon
Quoted 14 lines · On Fri, 5 Sep 2025 10:41:45 +0200 Michal Simek <[email protected]> wrote:
From: Salih Erim <[email protected]>
Sysmon Driver uses Linux IIO framework, which was used to abstract the supply voltages and temperatures across the chip as Voltage and Temperature Channels in the framework. Since there are only 160 supply voltage registers and 184 measurement points, there is no constant mapping of supply voltage registers and the measurement points. User has to select the voltages to monitor in design tool. Depending on the selection, a voltage supply gets mapped to one of the supply registers. So, this mapping information is provided to the driver via a device tree. Depending on the number of supplies enabled in the design, the device tree will contain the information of name of the supply enabled and the supply register it maps to.
Quoted 4 lines
Co-developed-by Anand Ashok Dumbre <[email protected]>Signed-off-by Anand Ashok Dumbre <[email protected]>Signed-off-by Salih Erim <[email protected]>Signed-off-by Michal Simek <[email protected]>
Various comments inline. Please generalize them to the rest of the code as some apply in a lot of places.
Thanks,
Jonathan
MAINTAINERS F: Documentation/misc-devices/xilinx_sdfec.rst · line 27608
Quoted 12 lines
MAINTAINERS +4
-0@@ -27602,6 +27602,13 @@ F: Documentation/misc-devices/xilinx_sdfec.rst F: drivers/misc/xilinx_sdfec.c F: include/uapi/misc/xilinx_sdfec.h +XILINX VERSAL SYSMON DRIVER +M: Salih Erim <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml
Bring this maintainers entry in when you add the first file (i.e. the dt binding patch). Then update it as new files are added in later patches.
Quoted 13 lines
MAINTAINERS +2
-0+F: drivers/iio/adc/versal-sysmon* +F: include/linux/iio/adc/versal-sysmon-events.hdrivers/iio/adc/versal-sysmon-core.c new file +3
-0+/** +* sysmon_millicelsius_to_q8p7() - converts value from IIO Framework to ADC Raw data +* @raw_data: Raw ADC value
drivers/iio/adc/versal-sysmon-core.c line 192
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +10
-0+* @val: The numerator of the fraction provided by the IIO Framework +* @val2: Denominator of the fraction provided by the IIO Framework +* +* The function takes in exponent and mantissa as val and val2 respectively +* of temperature value in milliDeg Celsius and returns raw adc value for the +* given temperature. +*/ +static void sysmon_millicelsius_to_q8p7 (u32 *raw_data,int val,int val2) +{ + (void )val2;
Don't bother - we don't care about unused parameters in the kernel.
drivers/iio/adc/versal-sysmon-core.c line 203
Quoted 11 lines
drivers/iio/adc/versal-sysmon-core.c new file +11
-0+ + *raw_data = (val <<SYSMON_FRACTIONAL_SHIFT ) /SYSMON_MILLI_SCALE ; +} + +static void sysmon_supply_rawtoprocessed (int raw_data,int *val,int *val2) +{ +int mantissa, format, exponent; + + mantissa = raw_data &SYSMON_MANTISSA_MASK ; + exponent =16 - ((raw_data &SYSMON_MODE_MASK ) >>SYSMON_MODE_SHIFT ); + format = (raw_data &SYSMON_FMT_MASK ) >>SYSMON_FMT_SHIFT ;
Feels like a FIELD_GET()#?
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +10
-0+static void sysmon_supply_processedtoraw (int val,int val2,u32 reg_val, +u32 *raw_data) +{ +int exponent = (reg_val &SYSMON_MODE_MASK ) >>SYSMON_MODE_SHIFT ; +int format = (reg_val &SYSMON_FMT_MASK ) >>SYSMON_FMT_SHIFT ; +int scale =1 << (16 - exponent); +int tmp; + + tmp = (val * scale) /SYSMON_MILLI_SCALE ; +
drivers/iio/adc/versal-sysmon-core.c line 234
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +10
-0+/* Set out of bound values to saturation levels */ +if (format) { +if (tmp >SYSMON_UPPER_SATURATION_SIGNED ) + tmp =0x7fff ; +else if (tmp <SYSMON_LOWER_SATURATION_SIGNED ) + tmp =0x8000 ; + + }else { +if (tmp >SYSMON_UPPER_SATURATION ) + tmp =0xffff ;
First MAX_U16 and secondly
tmp = min(tmp, MAX_U16);
or even better use clamp.
Quoted 6 lines
drivers/iio/adc/versal-sysmon-core.c new file +6
-0+else if (tmp <SYSMON_LOWER_SATURATION ) + tmp =0x0000 ; + } + + *raw_data = tmp &0xffff ; +}
drivers/iio/adc/versal-sysmon-core.c line 353
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +9
-0+static int sysmon_write_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int val,int val2,long mask) +{ +struct sysmon *sysmon =iio_priv (indio_dev); +u32 ret = -EINVAL ; +int i; + +mutex_lock (&sysmon->mutex);
guard()
drivers/iio/adc/versal-sysmon-core.c line 362
Quoted 9 lines
drivers/iio/adc/versal-sysmon-core.c new file +9
-0+switch (mask) { +case IIO_CHAN_INFO_OVERSAMPLING_RATIO : +if (val2 !=0 ) +break ; + +switch (chan->type) { +case IIO_TEMP : +for (i =0 ; i < sysmon->oversampling_num; i++) { +if (val == sysmon->oversampling_avail[i]) {
Possible flip logic of this and similar to keep indent manageable.
Quoted 27 lines
drivers/iio/adc/versal-sysmon-core.c new file +27
-0+ ret =sysmon_osr_write (sysmon, +IIO_TEMP , val); +if (!ret) + sysmon->temp_oversampling = val; + } + } +break ; + +case IIO_VOLTAGE : +for (i =0 ; i < sysmon->oversampling_num; i++) { +if (val == sysmon->oversampling_avail[i]) { + ret =sysmon_osr_write (sysmon, +IIO_VOLTAGE , val); +if (!ret) + sysmon->supply_oversampling = val; + } + } +break ; + +default : +break ; + } +break ; +default : +break ; + } +
drivers/iio/adc/versal-sysmon-core.c line 417
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +9
-0+mutex_unlock (&sysmon->mutex); +return ret; +} + +static int sysmon_get_event_mask (unsigned long address) +{ +if (address ==TEMP_EVENT ) +return BIT (SYSMON_BIT_TEMP ); +else if (address ==OT_EVENT )
Drop that else as we can't get here if returned in previous path anyway.
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +8
-0+return BIT (SYSMON_BIT_OT ); + +/* return supply */ +return BIT (address /32 ); +} +static int sysmon_read_event_value(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type,
drivers/iio/adc/versal-sysmon-core.c line 520
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +10
-0+enum iio_event_direction dir, + enum iio_event_info info, int *val, + int *val2) +{ + struct sysmon *sysmon = iio_priv(indio_dev); +u32 offset, reg_val; +u32 mask, shift; +u32 ret = -EINVAL ; + +mutex_lock (&sysmon->mutex);
guard and early returns will make this easier to read.
Quoted 35 lines
drivers/iio/adc/versal-sysmon-core.c new file +33
-0+if (chan->type ==IIO_TEMP ) { +if (info ==IIO_EV_INFO_VALUE ) { + offset =sysmon_temp_thresh_offset (chan->address, dir); +sysmon_read_reg (sysmon, offset, ®_val); +sysmon_q8p7_to_millicelsius (reg_val, val, val2); + ret =IIO_VAL_INT ; + }else if (info ==IIO_EV_INFO_HYSTERESIS ) { + mask = (chan->address ==OT_EVENT ) ?0x1 :0x2 ; + shift = mask -1 ; +sysmon_read_reg (sysmon,SYSMON_TEMP_EV_CFG , ®_val); + *val = (reg_val & mask) >> shift; + *val2 =0 ; + ret =IIO_VAL_INT ; + } + }else if (chan->type ==IIO_VOLTAGE ) { + offset =sysmon_supply_thresh_offset (chan->address, dir); +sysmon_read_reg (sysmon, offset, ®_val); +sysmon_supply_rawtoprocessed (reg_val, val, val2); + ret =IIO_VAL_INT ; + } + +mutex_unlock (&sysmon->mutex); +return ret; +} +/** +* sysmon_register_temp_ops - register temperature based event handler for a +* given region. +* @cb: callback function pointer. +* @data: private data to be passed to the callback. +* @region_id: id of the region for which the callback is to be set. +* @return: 0 for success and negative number in case of failure. +*/ +int sysmon_register_temp_ops(void (*cb)(void *data, struct regional_node *node),
drivers/iio/adc/versal-sysmon-core.c
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +10
-0+ void *data, enum sysmon_region region_id) +{ + struct sysmon *sysmon = g_sysmon; +struct region_info *region; +int ret =0 , found =0 ; + +if (!cb || !sysmon) +return -EINVAL ; + + ret =mutex_lock_interruptible (&sysmon->mutex);
as below. We have ACQUIRE() to deal this these in a similar fashion to guard().
drivers/iio/adc/versal-sysmon-core.c line 717
Quoted 13 lines
drivers/iio/adc/versal-sysmon-core.c new file +13
-0+if (ret) { +dev_err (sysmon->dev,"Failed to acquire a lock. Process was interrupted by fatal signals" ); +return ret; + } + +if (list_empty (&sysmon->region_list)) { +dev_err (sysmon->dev,"Failed to set a callback. HW node info missing in the device tree/ Not supported for this device" ); + ret = -EINVAL ; + goto exit; + } + +list_for_each_entry (region, &sysmon->region_list, list) { +if (region->id == region_id) {
Flip logic to reduce indent a little.
drivers/iio/adc/versal-sysmon-core.c line 720
Quoted 3 lines
drivers/iio/adc/versal-sysmon-core.c new file +3
-0+ found =1 ; +if (region->cb) { +dev_err (sysmon->dev,"Error callback already set. Unregister the existing callback to set a new one." );
at least wrap so the string starts as far to the left as is reasonable.
Quoted 26 lines
drivers/iio/adc/versal-sysmon-core.c new file +26
-0+ ret = -EINVAL ; + goto exit; + } + region->cb = cb; + region->data = data; +break ; + } + } + +if (!found) { +dev_err (sysmon->dev,"Error invalid region. Please select the correct region" ); + ret = -EINVAL ; + } + +exit: +mutex_unlock (&sysmon->mutex); +return ret; +} +EXPORT_SYMBOL (sysmon_register_temp_ops); + +/** +* sysmon_unregister_temp_ops - Unregister the callback for temperature +* notification. +* @region_id: id of the region for which the callback is to be set. +* @return: 0 for success and negative number in case of failure. +*/
drivers/iio/adc/versal-sysmon-core.c line 756
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +10
-0+int sysmon_unregister_temp_ops (enum sysmon_region region_id) +{ +struct sysmon *sysmon = g_sysmon; +struct region_info *region; +int ret =0 , found =0 ; + +if (!sysmon) +return -EINVAL ; + + ret =mutex_lock_interruptible (&sysmon->mutex);
The new ACQUIRE() stuff would probably clean this up.
Quoted 29 lines
drivers/iio/adc/versal-sysmon-core.c new file +29
-0+if (ret) { +dev_err (sysmon->dev,"Failed to acquire a lock. Process was interrupted by fatal signals" ); +return ret; + } + +if (list_empty (&sysmon->region_list)) { +dev_err (sysmon->dev,"Failed to set a callback. HW node info missing in the device tree/ Not supported for this device" ); + ret = -EINVAL ; + goto exit; + } + +list_for_each_entry (region, &sysmon->region_list, list) { +if (region->id == region_id) { + found =1 ; + region->cb =NULL ; + region->data =NULL ; +break ; + } + } + +if (!found) { +dev_err (sysmon->dev,"Error no such region. Please select the correct region" ); + ret = -EINVAL ; + } + +exit: +mutex_unlock (&sysmon->mutex); +return ret; +}
drivers/iio/adc/versal-sysmon-core.c line 837
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +9
-0+EXPORT_SYMBOL (sysmon_unregister_temp_ops); + +static void sysmon_push_event (struct iio_dev *indio_dev,u32 address) +{ +u32 i; +const struct iio_chan_spec *chan; + +for (i =0 ; i < indio_dev->num_channels; i++) { +if (indio_dev->channels[i].address == address) {
Flip logic
if (indio_dev->channels[i].address != address) continue; chan = ...
Quoted 8 lines
drivers/iio/adc/versal-sysmon-core.c new file +8
-0+ chan = &indio_dev->channels[i]; +iio_push_event (indio_dev, +IIO_UNMOD_EVENT_CODE (chan->type, + chan->channel, +IIO_EV_TYPE_THRESH , +IIO_EV_DIR_EITHER ), +iio_get_time_ns (indio_dev)); + }
drivers/iio/adc/versal-sysmon-core.c line 855
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +10
-0+ } +} + +int sysmon_create_avg_en_sysfs_entries (struct iio_dev *indio_dev) +{ +struct sysmon *sysmon =iio_priv (indio_dev); +int max_attrs_num, ret, i; +u8 supply_index; + +/* Allocate memory for temp. sat attribute list dynamically */
You are mixing and matching devm calls and non devm ones (manual iio_device_register() is before this). That is a bad idea for maintainabilty. Once you have to stop doing devm for some reason you can't start again later in probe without reordering the tear down to not be strict reverse order.
Quoted 69 lines
drivers/iio/adc/versal-sysmon-core.c new file +69
-0+ sysmon->temp_avg_en_attrs = +devm_kzalloc (&indio_dev->dev, +SYSMON_TEMP_SAT_COUNT * +sizeof (*sysmon->temp_avg_en_attrs),GFP_KERNEL ); +if (!sysmon->temp_avg_en_attrs) +return -ENOMEM ; + +/* Allocate memory for supply attribute list dynamically */ + sysmon->supply_avg_en_attrs = +devm_kzalloc (&indio_dev->dev, + sysmon->num_supply_chan * +sizeof (*sysmon->supply_avg_en_attrs),GFP_KERNEL ); +if (!sysmon->supply_avg_en_attrs) +return -ENOMEM ; + +/* +* Maximum attribute number is max temp. satellite number plus +* enabled supply channel number. +*/ + max_attrs_num =SYSMON_TEMP_SAT_COUNT + sysmon->num_supply_chan; + + sysmon->avg_attrs =devm_kzalloc (&indio_dev->dev, + (max_attrs_num +1 ) * +sizeof (*sysmon->avg_attrs),GFP_KERNEL ); +if (!sysmon->avg_attrs) +return -ENOMEM ; + +for (i =0 ; i <SYSMON_TEMP_SAT_COUNT ; i++) { +/* +* Temp. satellites are indexed from 1 to 64 on the register +* mapping, so the attr. sysfs entry will have appropriate +* postfix index number, plus one, accordingly. We are adding +* loop index number to attributes address because enable bit +* fields starts from 0. +*/ + sysmon->temp_avg_en_attrs[i].dev_attr.attr.name = +devm_kasprintf (&indio_dev->dev,GFP_KERNEL , +"averaging_en_tempsat%d" , (i +1 )); + sysmon->temp_avg_en_attrs[i].dev_attr.attr.mode =0644 ; + sysmon->temp_avg_en_attrs[i].dev_attr.show = tempsat_avg_en_show; + sysmon->temp_avg_en_attrs[i].dev_attr.store = tempsat_avg_en_store; + sysmon->temp_avg_en_attrs[i].address = i; + +/* Add all temp. sat averaging attrs to array of avg attributes */ + sysmon->avg_attrs[i] = + &sysmon->temp_avg_en_attrs[i].dev_attr.attr; + } + +for (i =0 ; i < sysmon->num_supply_chan; i++) { +/* +* Even each Sysmon device has max. 160 supply/voltage +* channels, they are enabled by dt discretely. There is no +* point of create attributes for all supply channels. We only +* create which is enabled by design and reflected in dt as +* supply channels. Supply index values are address of the +* IIO channel. +*/ + supply_index = indio_dev->channels[i].address; + sysmon->supply_avg_en_attrs[i].dev_attr.attr.name = +devm_kasprintf (&indio_dev->dev,GFP_KERNEL , +"averaging_en_supply%d" , supply_index); + sysmon->supply_avg_en_attrs[i].dev_attr.attr.mode =0644 ; + sysmon->supply_avg_en_attrs[i].dev_attr.show = supply_avg_en_show; + sysmon->supply_avg_en_attrs[i].dev_attr.store = supply_avg_en_store; + sysmon->supply_avg_en_attrs[i].address = supply_index; + + sysmon->avg_attrs[SYSMON_TEMP_SAT_COUNT + i] = + &sysmon->supply_avg_en_attrs[i].dev_attr.attr; + }
drivers/iio/adc/versal-sysmon-core.c line 934
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +10
-0+ +/* Null-terminate the attribute array */ + sysmon->avg_attrs[max_attrs_num +1 ] =NULL ; + +/* +* Assign all dynamically created attributes to averaging +* attributes group with "averaging" name. It will create +* a subfolder for this group under the IIO device folder. +*/ + sysmon->avg_attr_group.name ="averaging" ;
This almost certainly needs to be standard ABI, not custom. However to even start that discussion we need ABI documentation of what you want to do
in Documentation/ABI/testing/sysfs-bus-iio-*
drivers/iio/adc/versal-sysmon-core.c line 939
Quoted 5 lines
drivers/iio/adc/versal-sysmon-core.c new file +5
-0+ sysmon->avg_attr_group.attrs = sysmon->avg_attrs; + +/* Create the sysfs group for the attributes */ + ret =sysfs_create_group (&indio_dev->dev.kobj, + &sysmon->avg_attr_group);
This interface is both racey from a userspace point of view and more generally we have a bunch of ways to add extra stuff to IIO ABI and the directory bit is not a way we tend to do it.
Quoted 25 lines
drivers/iio/adc/versal-sysmon-core.c new file +24
-0+if (ret) { +dev_err (&indio_dev->dev, +"Failed to create averaging attribute group\n" ); +return ret; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (sysmon_create_avg_en_sysfs_entries); +static irqreturn_t sysmon_iio_irq (int irq,void *data) +{ +u32 isr, imr; +struct iio_dev *indio_dev = data; +struct sysmon *sysmon =iio_priv (indio_dev); + +spin_lock (&sysmon->lock); + +sysmon_read_reg (sysmon,SYSMON_ISR , &isr); +sysmon_read_reg (sysmon,SYSMON_IMR , &imr); + +/* only process alarm that are not masked */ + isr &= ~imr; + +/* clear interrupt */
drivers/iio/adc/versal-sysmon-core.c line 1117
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +10
-0+sysmon_write_reg (sysmon,SYSMON_ISR , isr); + +if (isr) { +sysmon_handle_events (indio_dev, isr); + +schedule_delayed_work (&sysmon->sysmon_unmask_work, +msecs_to_jiffies (SYSMON_UNMASK_WORK_DELAY_MS )); + } + +spin_unlock (&sysmon->lock);
Here guard() would be fine.
drivers/iio/adc/versal-sysmon-core.c line 1128
Quoted 11 lines
drivers/iio/adc/versal-sysmon-core.c new file +11
-0+ +return IRQ_HANDLED ; +} + +static void sysmon_events_worker (struct work_struct *work) +{ +u32 isr, imr; + struct sysmon *sysmon = container_of(work, struct sysmon, + sysmon_events_work.work); + +spin_lock (&sysmon->lock);
Perhaps scoped_guard()
Quoted 12 lines
drivers/iio/adc/versal-sysmon-core.c new file +12
-0+ +sysmon_read_reg (sysmon,SYSMON_ISR , &isr); +sysmon_read_reg (sysmon,SYSMON_IMR , &imr); + +/* only process alarm that are not masked */ + isr &= ~imr; + +/* clear interrupt */ +sysmon_write_reg (sysmon,SYSMON_ISR , isr); + +if (isr) { +sysmon_handle_events (sysmon->indio_dev, isr);
drivers/iio/adc/versal-sysmon-core.c line 1199
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +9
-0+schedule_delayed_work (&sysmon->sysmon_unmask_work, +msecs_to_jiffies (SYSMON_UNMASK_WORK_DELAY_MS )); + } +spin_unlock (&sysmon->lock); + +schedule_delayed_work (&sysmon->sysmon_events_work, +msecs_to_jiffies (SYSMON_EVENT_WORK_DELAY_MS )); +} +int sysmon_parse_dt (struct iio_dev *indio_dev,struct device *dev)
As below. Try to use property.h and avoid dt specific code. It's normally possible for almost everything.
Quoted 32 lines
drivers/iio/adc/versal-sysmon-core.c new file +32
-0+{ +struct sysmon *sysmon; +struct iio_chan_spec *sysmon_channels; +struct device_node *child_node =NULL , *np = dev->of_node; +int ret, i =0 ; +u32 num_supply_chan =0 ; +u32 reg =0 , num_temp_chan =0 ; +const char *name; +u32 chan_size =sizeof (struct iio_chan_spec ); +u32 temp_chan_size; + + sysmon =iio_priv (indio_dev); + ret =of_property_read_u32 (np,"xlnx,numchannels" , &num_supply_chan); +if (ret <0 ) +return ret; + + sysmon->num_supply_chan = num_supply_chan; + +INIT_LIST_HEAD (&sysmon->region_list); + +if (sysmon->irq >0 ) +get_hw_node_properties (dev, &sysmon->region_list); + +/* Initialize buffer for channel specification */ +if (sysmon->master_slr) { + temp_chan_size = (sizeof (temp_channels) +sizeof (temp_events)); + num_temp_chan =ARRAY_SIZE (temp_channels); + }else if (sysmon->hbm_slr) { + temp_chan_size = (sizeof (temp_hbm_channels)); + num_temp_chan =ARRAY_SIZE (temp_hbm_channels); + }else { + temp_chan_size =sizeof (temp_events);
drivers/iio/adc/versal-sysmon-core.c line 1241
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +10
-0+ num_temp_chan =0 ; + } + + sysmon_channels =devm_kzalloc (dev, (chan_size * num_supply_chan) + + temp_chan_size, +GFP_KERNEL ); +if (!sysmon_channels) +return -ENOMEM ; + +for_each_child_of_node (np, child_node) {
Look at scoped variants of this.
drivers/iio/adc/versal-sysmon-core.c line 1254
Quoted 13 lines
drivers/iio/adc/versal-sysmon-core.c new file +13
-0+ ret =of_property_read_u32 (child_node,"reg" , ®); +if (ret <0 ) { +of_node_put (child_node); +return ret; + } + + ret =of_property_read_string (child_node,"xlnx,name" , &name); +if (ret <0 ) { +of_node_put (child_node); +return ret; + } + + sysmon_channels[i].type =IIO_VOLTAGE ;
likely that something like
sysmon_channels[i] = (struct iio_chan_spec) {
.indexed = 1,
.address = reg,
...
};Will be easier to read here.
Quoted 53 lines
drivers/iio/adc/versal-sysmon-core.c new file +53
-0+ sysmon_channels[i].indexed =1 ; + sysmon_channels[i].address = reg; + sysmon_channels[i].channel = reg; + sysmon_channels[i].info_mask_separate = +BIT (IIO_CHAN_INFO_RAW ) |BIT (IIO_CHAN_INFO_PROCESSED ); + sysmon_channels[i].info_mask_shared_by_type = +BIT (IIO_CHAN_INFO_OVERSAMPLING_RATIO ); + sysmon_channels[i].info_mask_shared_by_type_available = +BIT (IIO_CHAN_INFO_OVERSAMPLING_RATIO ); + + sysmon_channels[i].event_spec = sysmon_supply_events; + sysmon_channels[i].num_event_specs =ARRAY_SIZE (sysmon_supply_events); + + sysmon_channels[i].scan_index = i; + sysmon_channels[i].scan_type.realbits =19 ; + sysmon_channels[i].scan_type.storagebits =32 ; + + sysmon_channels[i].scan_type.endianness =IIO_CPU ; + sysmon_channels[i].extend_name = name; + +if (of_property_read_bool (child_node,"xlnx,bipolar" )) + sysmon_channels[i].scan_type.sign ='s' ; +else + sysmon_channels[i].scan_type.sign ='u' ; + + i++; + } + +/* Append static temperature channels to the channel list */ + indio_dev->num_channels = num_supply_chan; + +if (sysmon->master_slr) { +memcpy (sysmon_channels + num_supply_chan, temp_channels, +sizeof (temp_channels)); + indio_dev->num_channels +=ARRAY_SIZE (temp_channels); + } + +if (sysmon->hbm_slr) { +memcpy (sysmon_channels + num_supply_chan, temp_hbm_channels, +sizeof (temp_hbm_channels)); + indio_dev->num_channels += num_temp_chan; + }else { +memcpy (sysmon_channels + num_supply_chan + num_temp_chan, + temp_events,sizeof (temp_events)); + indio_dev->num_channels +=ARRAY_SIZE (temp_events); + } + + indio_dev->channels = sysmon_channels; + +return 0 ; +} +EXPORT_SYMBOL (sysmon_parse_dt); +
drivers/iio/adc/versal-sysmon-core.c line 1317
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +10
-0+int sysmon_init_interrupt (struct sysmon *sysmon) +{ +u32 imr; +int ret; + +INIT_DELAYED_WORK (&sysmon->sysmon_unmask_work, + sysmon_unmask_worker); + +sysmon_read_reg (sysmon,SYSMON_IMR , &imr); + sysmon->temp_mask = imr &SYSMON_TEMP_MASK ;
Slight preference for FIELD_GET() as then we don't need to look at whether the bottom bits of SYSMON_TEMP_MASK are set.
Quoted 22 lines
drivers/iio/adc/versal-sysmon-core.c new file +17
-0+ +if (sysmon->irq >0 ) { + g_sysmon = sysmon; + ret =devm_request_irq (sysmon->dev, sysmon->irq, &sysmon_iio_irq, +0 ,"sysmon-irq" , sysmon->indio_dev); +if (ret <0 ) +return ret; + }else { +INIT_DELAYED_WORK (&sysmon->sysmon_events_work, + sysmon_events_worker); +schedule_delayed_work (&sysmon->sysmon_events_work, +msecs_to_jiffies (SYSMON_EVENT_WORK_DELAY_MS )); + } + +return 0 ; +} +EXPORT_SYMBOL (sysmon_init_interrupt);drivers/iio/adc/versal-sysmon.c new file +0
-0
drivers/iio/adc/versal-sysmon.c line 19
Quoted 8 lines
drivers/iio/adc/versal-sysmon.c new file +7
-0+ +#include <linux/bits.h> +#include <linux/moduleparam.h> +#include <linux/firmware/xlnx-zynqmp.h> +#include "versal-sysmon.h" + +static LIST_HEAD (sysmon_list_head);
Why do we need a list? Add a comment.
Quoted 31 lines
drivers/iio/adc/versal-sysmon.c new file +30
-0+ +static struct iio_map sysmon_therm_static_maps[] = { +IIO_MAP ("temp" ,"versal-thermal" ,"sysmon-temp-channel" ), + {} +}; + +static inline int sysmon_direct_read_reg (struct sysmon *sysmon,u32 offset,u32 *data) +{ + *data =readl (sysmon->base + offset); + +return 0 ; +} + +static inline void sysmon_direct_write_reg (struct sysmon *sysmon,u32 offset,u32 data) +{ +writel (data, sysmon->base + offset); +} + +static inline void sysmon_direct_update_reg (struct sysmon *sysmon,u32 offset, +u32 mask,u32 data) +{ +u32 val; + +sysmon_direct_read_reg (sysmon, offset, &val); +sysmon_direct_write_reg (sysmon, offset, (val & ~mask) | (mask & data)); +} + +/** +* sysmon_find_extreme_temp() - Finds extreme temperature +* value read from each device.
drivers/iio/adc/versal-sysmon.c line 65
Quoted 10 lines
drivers/iio/adc/versal-sysmon.c new file +10
-0+* @sysmon: Pointer to the sysmon instance +* @offset: Register offset address of temperature channels +* +* The function takes offset address of temperature channels +* returns extreme value (highest/lowest) of that channel +* +* @return: - The highest/lowest temperature found from +* current or historic min/max temperature of all devices. +*/ +static int sysmon_find_extreme_temp (struct sysmon *sysmon,int offset)
I would separate out this interface from the initial driver. Also rip out all infrastructure that isn't needed for other things. Then we can have a patch that clearly explains why this is needed.
Quoted 46 lines
drivers/iio/adc/versal-sysmon.c new file +46
-0+{ +u32 extreme_val =SYSMON_LOWER_SATURATION_SIGNED ; +bool is_min_channel = false, skip_hbm = true; +u32 regval; + +if (offset ==SYSMON_TEMP_MIN || offset ==SYSMON_TEMP_MIN_MIN ) { + is_min_channel = true; + extreme_val =SYSMON_UPPER_SATURATION_SIGNED ; + }else if (offset ==SYSMON_TEMP_HBM ) { + skip_hbm = false; + } + +list_for_each_entry (sysmon, &sysmon_list_head, list) { +if (skip_hbm && sysmon->hbm_slr) +/* Skip if HBM SLR and need non HBM reading */ +continue ; + +if (!skip_hbm && !sysmon->hbm_slr) +/* Skip if not HBM SLR and need a HBM reading */ +continue ; + +sysmon_read_reg (sysmon, offset, ®val); + +if (sysmon->hbm_slr) +return regval; + +if (!is_min_channel) { +/* Find the highest value */ +if (compare (regval, extreme_val)) + extreme_val = regval; + }else { +/* Find the lowest value */ +if (compare (extreme_val, regval)) + extreme_val = regval; + } + } + +return extreme_val; +} + +static int sysmon_probe (struct platform_device *pdev) +{ +struct sysmon *sysmon, *temp_sysmon; +struct iio_dev *indio_dev; +struct resource *mem; +bool exist = false;
drivers/iio/adc/versal-sysmon.c line 121
Quoted 10 lines
drivers/iio/adc/versal-sysmon.c new file +10
-0+int ret; + + indio_dev =devm_iio_device_alloc (&pdev->dev,sizeof (*sysmon)); +if (!indio_dev) +return -ENOMEM ; + + sysmon =iio_priv (indio_dev); + + sysmon->dev = &pdev->dev; + sysmon->indio_dev = indio_dev;
That usually means you have a design problem Why do you need to go from iio_priv() back to the containing structure. We intentionally do not have generic code to do that because it normally indicates the wrong data was passed somewhere and there are loops in references that should not exist.
drivers/iio/adc/versal-sysmon.c line 123
Quoted 2 lines
drivers/iio/adc/versal-sysmon.c new file +2
-0+ +mutex_init (&sysmon->mutex);
For new code
ret = devm_mutex_init() if (ret) return ret;
drivers/iio/adc/versal-sysmon.c line 127
Quoted 4 lines
drivers/iio/adc/versal-sysmon.c new file +4
-0+spin_lock_init (&sysmon->lock); + + indio_dev->dev.parent = &pdev->dev; + indio_dev->dev.of_node = pdev->dev.of_node;
You should I think need to set either of those by hand. The IIO core should do that for you.
Quoted 7 lines
drivers/iio/adc/versal-sysmon.c new file +7
-0+ indio_dev->name ="xlnx,versal-sysmon" ; +sysmon_set_iio_dev_info (indio_dev); + indio_dev->modes =INDIO_DIRECT_MODE ; + + sysmon->base =devm_platform_get_and_ioremap_resource (pdev,0 , &mem); +if (IS_ERR (sysmon->base)) +return PTR_ERR (sysmon->base);
drivers/iio/adc/versal-sysmon.c line 144
Quoted 10 lines
drivers/iio/adc/versal-sysmon.c new file +10
-0+ + sysmon->ops = &direct_access; + +INIT_LIST_HEAD (&sysmon->list); + +mutex_lock (&sysmon->mutex); + +if (list_empty (&sysmon_list_head)) { + sysmon->master_slr = true; + }else {
Bring declaratoin of exist into this scope. It sounds very general but isn't.
drivers/iio/adc/versal-sysmon.c line 154
Quoted 10 lines
drivers/iio/adc/versal-sysmon.c new file +10
-0+list_for_each_entry (temp_sysmon, &sysmon_list_head, list) { +if (temp_sysmon->master_slr) + exist = true; + } + sysmon->master_slr = !exist; + } + +mutex_unlock (&sysmon->mutex); + + sysmon->hbm_slr =of_property_read_bool (pdev->dev.of_node,"xlnx,hbm" );
Please use generic property accessors from property.h. That gives more flexibility for firmwares and in general means we don't introduce of specific new code into IIO that will get cut and paste into more drivers.
drivers/iio/adc/versal-sysmon.c line 157
Quoted 3 lines
drivers/iio/adc/versal-sysmon.c new file +3
-0+if (!sysmon->hbm_slr) { +sysmon_write_reg (sysmon,SYSMON_NPI_LOCK ,NPI_UNLOCK ); +sysmon_write_reg (sysmon,SYSMON_IDR ,0xffffffff );
GENMASK() is easier to read when it's writing all.
drivers/iio/adc/versal-sysmon.c line 162
Quoted 5 lines
drivers/iio/adc/versal-sysmon.c new file +5
-0+sysmon_write_reg (sysmon,SYSMON_ISR ,0xffffffff ); + sysmon->irq =platform_get_irq_optional (pdev,0 ); + } + + ret =sysmon_parse_dt (indio_dev, &pdev->dev);
parse_fw() given comment above about not doing DT specific handling.
drivers/iio/adc/versal-sysmon.c line 173
Quoted 11 lines
drivers/iio/adc/versal-sysmon.c new file +11
-0+if (ret) +return ret; + +if (!sysmon->hbm_slr) { + ret =sysmon_init_interrupt (sysmon); +if (ret) +return ret; + } + +/* +* Sysmon dev info is cleared initially.
Wrap at 80 chars.
Quoted 9 lines
drivers/iio/adc/versal-sysmon.c new file +9
-0+* temperature satellites and supply channels +* oversampling values will be 0. No need to +* assign them again. +*/ + sysmon->oversampling_avail = sysmon_oversampling_avail; + sysmon->oversampling_num =ARRAY_SIZE (sysmon_oversampling_avail); + + sysmon->temp_read = &sysmon_find_extreme_temp; +
drivers/iio/adc/versal-sysmon.c line 192
Quoted 10 lines
drivers/iio/adc/versal-sysmon.c new file +10
-0+platform_set_drvdata (pdev, indio_dev); + +if (sysmon->master_slr) { + ret =devm_iio_map_array_register (&pdev->dev, indio_dev, + sysmon_therm_static_maps); +if (ret <0 ) +return dev_err_probe (&pdev->dev, ret,"IIO map register failed\n" ); + } + + ret =iio_device_register (indio_dev);
I'd normally expect to find this last as it is where the userspace interface becomes visible.
Quoted 9 lines
drivers/iio/adc/versal-sysmon.c new file +9
-0+if (ret <0 ) + goto error_exit; + +/* Create the sysfs entries for the averaging enable bits */ + ret =sysmon_create_avg_en_sysfs_entries (indio_dev); +if (ret <0 ) + goto error_exit; + +mutex_lock (&sysmon->mutex);
drivers/iio/adc/versal-sysmon.c line 211
Quoted 10 lines
drivers/iio/adc/versal-sysmon.c new file +10
-0+list_add (&sysmon->list, &sysmon_list_head); +mutex_unlock (&sysmon->mutex); + +return 0 ; + +error_exit: +if (sysmon->irq <0 ) +cancel_delayed_work_sync (&sysmon->sysmon_events_work); + +cancel_delayed_work_sync (&sysmon->sysmon_unmask_work);
Look at whether you can register custom devm callbacks to clean this up and the list removal.
Quoted 10 lines
drivers/iio/adc/versal-sysmon.c new file +10
-0+return ret; +} + +static void sysmon_remove (struct platform_device *pdev) +{ +struct iio_dev *indio_dev =platform_get_drvdata (pdev); +struct sysmon *sysmon =iio_priv (indio_dev); + +/* cancel SSIT based events */ +if (sysmon->irq <0 )
drivers/iio/adc/versal-sysmon.c line 231
Quoted 10 lines
drivers/iio/adc/versal-sysmon.c new file +10
-0+cancel_delayed_work_sync (&sysmon->sysmon_events_work); + +cancel_delayed_work_sync (&sysmon->sysmon_unmask_work); + +mutex_lock (&sysmon->mutex); +list_del (&sysmon->list); +mutex_unlock (&sysmon->mutex); + +sysfs_remove_group (&indio_dev->dev.kobj, &sysmon->avg_attr_group); +/* Unregister the device */
Comment doesn't add anything not obvious from code.
drivers/iio/adc/versal-sysmon.c line 247
Quoted 7 lines
drivers/iio/adc/versal-sysmon.c new file +6
-0+iio_device_unregister (indio_dev); +} + +static const struct of_device_id sysmon_of_match_table[] = { + { .compatible ="xlnx,versal-sysmon" }, + {}
Trivial preference for
{ }I had to pick something when trying to standardize this formatting and I chose that one.
drivers/iio/adc/versal-sysmon.c line 254
Quoted 7 lines
drivers/iio/adc/versal-sysmon.c new file +7
-0+}; +MODULE_DEVICE_TABLE (of, sysmon_of_match_table); + +static struct platform_driver sysmon_driver = { + .probe = sysmon_probe, + .remove = sysmon_remove, + .resume = sysmon_resume,
I think I'd rather see this done with pm in the .driver That tends to be a lot more flexible unless I'm missing some reason this resume needs to be used here.
Quoted 34 lines
drivers/iio/adc/versal-sysmon.c new file +10
-0+ .driver = { + .name = "sysmon", + .of_match_table = sysmon_of_match_table, + }, +}; +module_platform_driver (sysmon_driver); + +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("Xilinx Versal SysMon Driver" ); +MODULE_AUTHOR ("Advanced Micro Devices, Inc" );drivers/iio/adc/versal-sysmon.h new file +18
-0@@ -0,0 +1,275 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* AMD SYSMON for Versal +* +* Copyright (C) 2019 - 2022, Xilinx, Inc. +* Copyright (C) 2022 - 2025, Advanced Micro Devices, Inc. +* +* Description: +* This driver is developed for SYSMON on Versal. The driver supports INDIO Mode +* and supports voltage and temperature monitoring via IIO sysfs interface. +*/ + +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/iio/buffer.h> +#include <linux/iio/driver.h> +#include <linux/iio/events.h>
drivers/iio/adc/versal-sysmon.h line 28
Quoted 10 lines
drivers/iio/adc/versal-sysmon.h new file +10
-0+#include <linux/iio/machine.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/adc/versal-sysmon-events.h> +#include <linux/iopoll.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/of_address.h>
Include only what is used in this header. The rest need to get pushed down to the files where they are needed.
drivers/iio/adc/versal-sysmon.h line 30
Quoted 2 lines
drivers/iio/adc/versal-sysmon.h new file +2
-0+ +/* Channel IDs for Temp Channels */
Combine these comments into one block and use the syntax below.
drivers/iio/adc/versal-sysmon.h line 36
Quoted 6 lines
drivers/iio/adc/versal-sysmon.h new file +6
-0+/* TEMP_MAX gives the current temperature for Production +* silicon. +* TEMP_MAX gives the current maximum temperature for ES1 +* silicon. +*/ +#define TEMP_MAX 160
Prefix constants like this that have very generic names.
drivers/iio/adc/versal-sysmon.h line 38
Quoted 2 lines
drivers/iio/adc/versal-sysmon.h new file +2
-0+ +/* TEMP_MIN is not applicable for Production silicon.
Multiline comment syntax
/*
* TEMP_MIN...
drivers/iio/adc/versal-sysmon.h line 40
Quoted 2 lines
drivers/iio/adc/versal-sysmon.h new file +2
-0+* TEMP_MIN gives the current minimum temperature for ES1 silicon. +*/
Do you need to support engineering samples upstream? As a general rule we don't bother unless there are a lot of them out there.
Quoted 35 lines
drivers/iio/adc/versal-sysmon.h new file +35
-0+#define TEMP_MIN 161 + +#define TEMP_MAX_MAX 162 +#define TEMP_MIN_MIN 163 +#define TEMP_EVENT 164 +#define OT_EVENT 165 +#define TEMP_HBM 166 + +/* Register Unlock Code */ +#define NPI_UNLOCK 0xF9E8D7C6 + +/* Register Offsets */ +#define SYSMON_NPI_LOCK 0x000C +#define SYSMON_ISR 0x0044 +#define SYSMON_CONFIG 0x0100 +#define SYSMON_TEMP_MASK 0x300 +#define SYSMON_IMR 0x0048 +#define SYSMON_IER 0x004C +#define SYSMON_IDR 0x0050 +#define SYSMON_ALARM_FLAG 0x1018 +#define SYSMON_TEMP_MAX 0x1030 +#define SYSMON_TEMP_MIN 0x1034 +#define SYSMON_SUPPLY_BASE 0x1040 +#define SYSMON_ALARM_REG 0x1940 +#define SYSMON_TEMP_TH_LOW 0x1970 +#define SYSMON_TEMP_TH_UP 0x1974 +#define SYSMON_OT_TH_LOW 0x1978 +#define SYSMON_OT_TH_UP 0x197C +#define SYSMON_SUPPLY_TH_LOW 0x1980 +#define SYSMON_SUPPLY_TH_UP 0x1C80 +#define SYSMON_TEMP_MAX_MAX 0x1F90 +#define SYSMON_TEMP_MIN_MIN 0x1F8C +#define SYSMON_TEMP_HBM 0x0000 +#define SYSMON_TEMP_EV_CFG 0x1F84 +#define SYSMON_NODE_OFFSET 0x1FAC
drivers/iio/adc/versal-sysmon.h line 85
Quoted 10 lines
drivers/iio/adc/versal-sysmon.h new file +10
-0+#define SYSMON_STATUS_RESET 0x1F94 +#define SYSMON_SUPPLY_EN_AVG_OFFSET 0x1958 +#define SYSMON_TEMP_SAT_EN_AVG_OFFSET 0x24B4 + +/* Average Sampling Rate macros */ +#define SYSMON_AVERAGE_FULL_SAMPLE_RATE 0/* Full sample rate */ +#define SYSMON_AVERAGE_2_SAMPLE_RATE 1/* Full sample rate/2 */ +#define SYSMON_AVERAGE_4_SAMPLE_RATE 2/* Full sample rate/4 */ +#define SYSMON_AVERAGE_8_SAMPLE_RATE 4/* Full sample rate/8 */ +#define SYSMON_AVERAGE_16_SAMPLE_RATE 8/* Full sample rate/16 */
That is an amusing mapping. Maybe the names can be tweaked to be self explanatory enough that the we don't need comments? This looks like classic oversampling, in which case just call them something related to that as it's the oversampling ratio.
Quoted 5 lines
drivers/iio/adc/versal-sysmon.h new file +5
-0+ +#define SYSMON_TEMP_SAT_IDX_FIRST 1 +#define SYSMON_TEMP_SAT_IDX_MAX 64 +#define SYSMON_TEMP_SAT_COUNT 64 +#define SYSMON_SUPPLY_IDX_MAX 159
drivers/iio/adc/versal-sysmon.h line 100
Quoted 10 lines
drivers/iio/adc/versal-sysmon.h new file +10
-0+ +#define SYSMON_SUPPLY_CONFIG_MASK GENMASK(17, 14) +#define SYSMON_SUPPLY_CONFIG_SHIFT 14 +#define SYSMON_TEMP_SAT_CONFIG_MASK GENMASK(27, 24) +#define SYSMON_TEMP_SAT_CONFIG_SHIFT 24 + +#define SYSMON_NO_OF_EVENTS 32 + +/* Supply Voltage Conversion macros */ +#define SYSMON_MANTISSA_MASK 0xFFFF
GENMASK() for all masks.
drivers/iio/adc/versal-sysmon.h line 107
Quoted 7 lines
drivers/iio/adc/versal-sysmon.h new file +7
-0+#define SYSMON_FMT_MASK 0x10000 +#define SYSMON_FMT_SHIFT 16 +#define SYSMON_MODE_MASK 0x60000 +#define SYSMON_MODE_SHIFT 17 +#define SYSMON_MANTISSA_SIGN_SHIFT 15 +#define SYSMON_UPPER_SATURATION_SIGNED 32767 +#define SYSMON_LOWER_SATURATION_SIGNED -32768
S16_MIN and S16_MAX from limits.h
drivers/iio/adc/versal-sysmon.h line 108
Quoted 1 line
drivers/iio/adc/versal-sysmon.h new file +1
-0+#define SYSMON_UPPER_SATURATION 65535
U16_MAX, U16_MIN
drivers/iio/adc/versal-sysmon.h line 111
Quoted 3 lines
drivers/iio/adc/versal-sysmon.h new file +3
-0+#define SYSMON_LOWER_SATURATION 0 + +#define SYSMON_MILLI_SCALE 1000
units.h
drivers/iio/adc/versal-sysmon.h line 117
Quoted 6 lines
drivers/iio/adc/versal-sysmon.h new file +6
-0+ +#define SYSMON_CHAN_TEMP_EVENT (_address, _ext, _events) { \ + .type = IIO_TEMP, \ + .indexed = 1, \ + .address = _address, \ + .channel = _address, \
Not really any point in setting address if you can always look up channel.
drivers/iio/adc/versal-sysmon.h line 122
Quoted 5 lines
drivers/iio/adc/versal-sysmon.h new file +5
-0+ .event_spec = _events, \ + .num_event_specs = ARRAY_SIZE(_events), \ + .scan_type = { \ + .sign = 's', \ + .realbits = 15, \
15 bit devices are unusual but fair enough if that's the case.
drivers/iio/adc/versal-sysmon.h line 126
Quoted 4 lines
drivers/iio/adc/versal-sysmon.h new file +4
-0+ .storagebits = 16, \ + .endianness = IIO_CPU, \ + }, \ + .extend_name = _ext, \
As below.
Quoted 9 lines
drivers/iio/adc/versal-sysmon.h new file +9
-0+ } + +#define SYSMON_CHAN_TEMP (_address, _ext) { \ + .type = IIO_TEMP, \ + .indexed = 1, \ + .address = _address, \ + .channel = _address, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_PROCESSED), \
drivers/iio/adc/versal-sysmon.h line 145
Quoted 10 lines
drivers/iio/adc/versal-sysmon.h new file +10
-0+ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .info_mask_shared_by_type_available = \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .scan_type = { \ + .sign = 's', \ + .realbits = 15, \ + .storagebits = 16, \ + .endianness = IIO_CPU, \ + }, \ + .extend_name = _ext, \
Don't set extend_name in a new driver. That makes a horrible mess of
the userspace ABI. Instead use the read_label() callback to provide a suitable string for each channel.
Quoted 11 lines
drivers/iio/adc/versal-sysmon.h new file +11
-0+ .datasheet_name = _ext,\ +} + +#define SYSMON_CHAN_TEMP_HBM (_address, _ext) { \ + .type = IIO_TEMP, \ + .indexed = 1, \ + .address = _address, \ + .channel = _address, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_PROCESSED), \ + .scan_type = { \
drivers/iio/adc/versal-sysmon.h line 166
Quoted 10 lines
drivers/iio/adc/versal-sysmon.h new file +10
-0+ .sign = 's', \ + .realbits = 15, \ + .storagebits = 16, \ + .endianness = IIO_CPU, \ + }, \ + .extend_name = _ext, \ + .datasheet_name = _ext, \ +} + +#define twoscomp (val) ((((val) ^ 0xFFFF) + 1) & 0x0000FFFF)
Not sure why this is needed yet, but generally no to this. Treat it as an s16 and I don't think you need to do anything other than negate if needed.
drivers/iio/adc/versal-sysmon.h line 168
Quoted 2 lines
drivers/iio/adc/versal-sysmon.h new file +2
-0+#define REG32_OFFSET (address) (4 * ((address) / 32)) +#define REG32_SHIFT (address) ((address) % 32)
SIZEOF(u32)*BITS_PER_BYTE.
drivers/iio/adc/versal-sysmon.h line 171
Quoted 3 lines
drivers/iio/adc/versal-sysmon.h new file +3
-0+ +#define compare (val, thresh) (((val) & 0x8000) || ((thresh) & 0x8000) ? \ + ((val) < (thresh)) : ((val) > (thresh))) \
This smells like you can just used signed comparison of s16s but I'm not quite sure what intent is.
Quoted 6 lines
drivers/iio/adc/versal-sysmon.h new file +6
-0+ +enum sysmon_alarm_bit { +SYSMON_BIT_ALARM0 =0 , +SYSMON_BIT_ALARM1 =1 , +SYSMON_BIT_ALARM2 =2 , +SYSMON_BIT_ALARM3 =3 ,
drivers/iio/adc/versal-sysmon.h line 187
Quoted 10 lines
drivers/iio/adc/versal-sysmon.h new file +10
-0+SYSMON_BIT_ALARM4 =4 , +SYSMON_BIT_ALARM5 =5 , +SYSMON_BIT_ALARM6 =6 , +SYSMON_BIT_ALARM7 =7 , +SYSMON_BIT_OT =8 , + SYSMON_BIT_TEMP = 9, +}; + +static const unsigned int sysmon_oversampling_avail[5 ] = { + SYSMON_AVERAGE_FULL_SAMPLE_RATE,
No oversampling is value 1, not 0. I'm not following how the mapping works for the otehrs.
Quoted 97 lines
drivers/iio/adc/versal-sysmon.h new file +88
-0+SYSMON_AVERAGE_2_SAMPLE_RATE , +SYSMON_AVERAGE_4_SAMPLE_RATE , +SYSMON_AVERAGE_8_SAMPLE_RATE , + SYSMON_AVERAGE_16_SAMPLE_RATE, +}; + +/** +* struct sysmon - Driver data for Sysmon +* @base: physical base address of device +* @dev: pointer to device struct +* @indio_dev: pointer to the iio device +* @client: pointer to the i2c client +* @mutex: to handle multiple user interaction +* @lock: to help manage interrupt registers correctly +* @irq: interrupt number of the sysmon +* @region_list: list of the regions of sysmon +* @list: list of sysmon instances +* @masked_temp: currently masked due to alarm +* @temp_mask: temperature based interrupt configuration +* @sysmon_unmask_work: re-enables event once the event condition disappears +* @sysmon_events_work: poll for events on SSIT slices +* @ops: read write operations for sysmon registers +* @pm_info: plm address of sysmon +* @master_slr: to keep master sysmon info +* @hbm_slr: flag if HBM slr is present +* @temp_oversampling: current oversampling ratio for temperature satellites +* @supply_oversampling: current oversampling ratio for supply nodes +* @oversampling_avail: list of available overampling ratios +* @oversampling_num: total number of available oversampling ratios +* @num_supply_chan: number of supply channels that are enabled +* @supply_avg_en_attrs: dynamic array of supply averaging enable attributes +* @temp_avg_en_attrs: dynamic array of temp. sat. averaging enable attributes +* @avg_attrs: dynamic array of pointers to averaging attributes +* @avg_attr_group: attribute group for averaging +* @temp_read: function pointer for the special temperature read +* +* This structure contains necessary state for Sysmon driver to operate +*/ +struct sysmon { +void __iomem *base; +struct device *dev; +struct iio_dev *indio_dev; +struct i2c_client *client; +/* kernel doc above */ +struct mutex mutex; +/* kernel doc above */ +spinlock_t lock; +int irq; +struct list_head region_list; +struct list_head list; +unsigned int masked_temp; +unsigned int temp_mask; +struct delayed_work sysmon_unmask_work; +struct delayed_work sysmon_events_work; +struct sysmon_ops *ops; +u32 pm_info; +bool master_slr; +bool hbm_slr; +unsigned int temp_oversampling; +unsigned int supply_oversampling; +const unsigned int *oversampling_avail; +unsigned int oversampling_num; +unsigned int num_supply_chan; +struct iio_dev_attr *supply_avg_en_attrs; +struct iio_dev_attr *temp_avg_en_attrs; +struct attribute **avg_attrs; +struct attribute_group avg_attr_group; +int (*temp_read)(struct sysmon *sysmon,int offset); +}; + +struct sysmon_ops { +int (*read_reg)(struct sysmon *sysmon,u32 offset,u32 *data); +void (*write_reg)(struct sysmon *sysmon,u32 offset,u32 data); +void (*update_reg)(struct sysmon *sysmon,u32 offset, +u32 mask,u32 data); +}; + +int sysmon_register_temp_ops (void (*cb)(void *data,struct regional_node *node), +void *data,enum sysmon_region region_id); +int sysmon_unregister_temp_ops (enum sysmon_region region_id); +struct list_head *sysmon_nodes_by_region (enum sysmon_region region_id); +int sysmon_get_node_value (int sat_id); +int sysmon_parse_dt (struct iio_dev *indio_dev,struct device *dev); +int sysmon_init_interrupt (struct sysmon *sysmon); +int sysmon_read_reg (struct sysmon *sysmon,u32 offset,u32 *data); +void sysmon_write_reg (struct sysmon *sysmon,u32 offset,u32 data); +void sysmon_set_iio_dev_info (struct iio_dev *indio_dev); +int sysmon_create_avg_en_sysfs_entries (struct iio_dev *indio_dev);include/linux/iio/adc/versal-sysmon-events.h new file +3
-0@@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Xilinx SYSMON hardware info
include/linux/iio/adc/versal-sysmon-events.h line 13
Quoted 10 lines
include/linux/iio/adc/versal-sysmon-events.h new file +10
-0+* +* Copyright (C) 2019 - 2022, Xilinx, Inc. +* Copyright (C) 2022 - 2025, Advanced Micro Devices, Inc. +* +*/ +#ifndef _VERSAL_SYSMON_EVENTS_H_ +#define _VERSAL_SYSMON_EVENTS_H_ + +#include <linux/types.h> +#include <linux/iio/types.h>
Follow include what you use principles. So here we need the list.h header, maybe others.
include/linux/iio/adc/versal-sysmon-events.h line 16
Quoted 3 lines
include/linux/iio/adc/versal-sysmon-events.h new file +3
-0+ +/* Sysmon region ids */ +enum sysmon_region {
sysmon is a heavily overloaded term. I'd prefix all the places you have sysmon to make them versal_symon_ VERSAL_SYSMON_ etc
Quoted 6 lines
include/linux/iio/adc/versal-sysmon-events.h new file +6
-0+SYSMON_AIE =0 , +SYSMON_PMC =1 , +SYSMON_XPIO =2 , +SYSMON_VNOC =3 , + SYSMON_CC = 4, +};
include/linux/iio/adc/versal-sysmon-events.h line 32
Quoted 10 lines
include/linux/iio/adc/versal-sysmon-events.h new file +10
-0+ +/** +* struct regional_node - regional node properties +* @sat_id: node_id +* @x: x co-ordinate of the node +* @y: y co-ordinate of the node +* @temp: raw sensor value +* @regional_node_list: list of nodes in the region +*/ +struct regional_node {
Probably namespace these as well to avoid a future potential name clash. So versal_symon_regional_node etc.
Quoted 24 lines
include/linux/iio/adc/versal-sysmon-events.h new file +24
-0+int sat_id; +int x; +int y; +u16 temp; + struct list_head regional_node_list; +}; + +/** +* struct region_info - information about a regions sensors +* @id: region id +* @cb: callback to be called when there is a region specific event +* @data: pointer to the callback data +* @node_list: head to the regional_nodes list +* @list: list of regions +*/ +struct region_info { +enum sysmon_region id; +void (*cb)(void *data,struct regional_node *node); +void *data; +struct list_head node_list; +struct list_head list; +}; + +#endif
Re: [PATCH 2/6] iio: versal-sysmon: add driver for Versal Sysmon
In reply to Michal SimekQuoted 7 lines · Michal Simek
Sysmon Driver uses Linux IIO framework, which was used to abstract the supply voltages and temperatures across the chip as Voltage and Temperature Channels in the framework. Since there are only 160 supply voltage registers and 184 measurement points, there is no constant mapping of supply voltage registers and the measurement points. User has to select the voltages to monitor in design tool. Depending on the selection, a
in the design
Quoted 5 lines
voltage supply gets mapped to one of the supply registers. So, this mapping information is provided to the driver via a device tree. Depending on the number of supplies enabled in the design, the device tree will contain the information of name of the supply enabled and the supply register it maps to.
...
drivers/iio/adc/Kconfig config XILINX_AMS · line 1836
Quoted 10 lines
drivers/iio/adc/Kconfig +10
-0+config VERSAL_SYSMON + tristate "Xilinx Sysmon driver for Versal" + depends on HAS_IOMEM + select VERSAL_SYSMON_CORE + help + Say yes here to have support for the Xilinx Sysmon. + The driver will enable users to monitor temperature and voltage on the + Xilinx Versal platform. + + The driver can also be build as a module. If so, the module will be called
built
Quoted 1 line
+ versal-sysmon.
...
Quoted 1 line
+#include <
linux/bits.h>
Quite a few headers are absent...
+ export.h
+ types.h
Quoted 1 line
+#include "
versal-sysmon.h"
...
Quoted 8 lines
drivers/iio/adc/versal-sysmon-core.c new file +8
-0+static u32 sysmon_temp_offset (int address) +{ +switch (address) { +case TEMP_MAX : +return SYSMON_TEMP_MAX ; +case TEMP_MIN : +return SYSMON_TEMP_MIN ; +case TEMP_MAX_MAX :
drivers/iio/adc/versal-sysmon-core.c line 116
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +9
-0+return SYSMON_TEMP_MAX_MAX ; +case TEMP_MIN_MIN : +return SYSMON_TEMP_MIN_MIN ; +case TEMP_HBM : +return SYSMON_TEMP_HBM ; +default : +return -EINVAL ; + } +return -EINVAL ;
Here and in many more, eliminate dead code.
Quoted 1 line
+}
...
drivers/iio/adc/versal-sysmon-core.c line 145
Quoted 8 lines
drivers/iio/adc/versal-sysmon-core.c new file +7
-0+static u32 sysmon_supply_thresh_offset (int address, +enum iio_event_direction dir) +{ +if (dir ==IIO_EV_DIR_RISING ) +return (address *4 ) +SYSMON_SUPPLY_TH_UP ; +else if (dir ==IIO_EV_DIR_FALLING ) +return (address *4 ) +SYSMON_SUPPLY_TH_LOW ;
Redundant 'else'.
Quoted 2 lines
(quoted diff) +2
-0+ return -EINVAL; +}
...
drivers/iio/adc/versal-sysmon-core.c line 161
Quoted 4 lines
drivers/iio/adc/versal-sysmon-core.c new file +4
-0+static void sysmon_hbm_to_millicelsius (int raw_data,int *val,int *val2) +{ + *val = ((raw_data >>SYSMON_HBM_TEMP_SHIFT ) &SYSMON_HBM_TEMP_MASK ) * +SYSMON_MILLI_SCALE ;
Can the whole driver be switched to FIELD_PREP()/FIELD_GET()/FIELD_MODIFY()?
Quoted 2 lines
(quoted diff) +2
-0+ *val2 = 0; +}
...
drivers/iio/adc/versal-sysmon-core.c line 192
Quoted 4 lines
drivers/iio/adc/versal-sysmon-core.c new file +3
-0+static void sysmon_millicelsius_to_q8p7 (u32 *raw_data,int val,int val2) +{ + (void )val2;
Unneeded.
Quoted 2 lines
(quoted diff) +2
-0+ *raw_data = (val << SYSMON_FRACTIONAL_SHIFT) / SYSMON_MILLI_SCALE; +}
...
Quoted 6 lines
drivers/iio/adc/versal-sysmon-core.c new file +6
-0+static void sysmon_supply_processedtoraw (int val,int val2,u32 reg_val, +u32 *raw_data) +{ +int exponent = (reg_val &SYSMON_MODE_MASK ) >>SYSMON_MODE_SHIFT ; +int format = (reg_val &SYSMON_FMT_MASK ) >>SYSMON_FMT_SHIFT ; +int scale =1 << (16 - exponent);
drivers/iio/adc/versal-sysmon-core.c line 230
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +10
-0+int tmp; + + tmp = (val * scale) /SYSMON_MILLI_SCALE ; + +/* Set out of bound values to saturation levels */ +if (format) { +if (tmp >SYSMON_UPPER_SATURATION_SIGNED ) + tmp =0x7fff ; +else if (tmp <SYSMON_LOWER_SATURATION_SIGNED ) + tmp =0x8000 ;
This looks like s16 limits, can you use them?
drivers/iio/adc/versal-sysmon-core.c line 236
Quoted 5 lines
drivers/iio/adc/versal-sysmon-core.c new file +5
-0+ }else { +if (tmp >SYSMON_UPPER_SATURATION ) + tmp =0xffff ; +else if (tmp <SYSMON_LOWER_SATURATION ) + tmp =0x0000 ;
u16 respectively.
Quoted 35 lines
drivers/iio/adc/versal-sysmon-core.c new file +32
-0+ } + + *raw_data = tmp &0xffff ; +} +u32 ret = -EINVAL ; +mutex_lock (&sysmon->mutex); +switch (mask) { +case IIO_CHAN_INFO_RAW : +switch (chan->type) { +case IIO_TEMP : + offset =sysmon_temp_offset (chan->address); + *val = sysmon->temp_read (sysmon, offset); + *val2 =0 ; + ret =IIO_VAL_INT ; +break ; + +case IIO_VOLTAGE : + offset =sysmon_supply_offset (chan->address); +sysmon_read_reg (sysmon, offset, ®val); + *val = (int )regval; + *val2 =0 ; + ret =IIO_VAL_INT ; +break ; + +default : +break ; + }> + +spin_unlock_irqrestore (&sysmon->lock, flags); +mutex_unlock (&sysmon->mutex); + +return 0 ; +}
...
Quoted 1 line
+#include <
linux/bits.h>
+ io.h
drivers/iio/adc/versal-sysmon.c line 19
Quoted 5 lines
drivers/iio/adc/versal-sysmon.c new file +5
-0+#include <linux/moduleparam.h> +#include <linux/firmware/xlnx-zynqmp.h> +#include "versal-sysmon.h" + +static LIST_HEAD (sysmon_list_head);
list.h?
drivers/iio/adc/versal-sysmon.c line 22
Quoted 2 lines
drivers/iio/adc/versal-sysmon.c new file +2
-0+static struct iio_map sysmon_therm_static_maps[] = { +IIO_MAP ("temp" ,"versal-thermal" ,"sysmon-temp-channel" ),
Where are the IIO_MAP() and struct iio_map defined?
drivers/iio/adc/versal-sysmon.c line 26
Quoted 4 lines
drivers/iio/adc/versal-sysmon.c new file +4
-0+ {} +}; + +static inline int sysmon_direct_read_reg (struct sysmon *sysmon,u32 offset,u32 *data)
+ types.h for uXX.
Quoted 5 lines
drivers/iio/adc/versal-sysmon.c new file +5
-0+{ + *data =readl (sysmon->base + offset); + +return 0 ; +}
...
Quoted 1 line
+
mutex_init(&sysmon->mutex);
devm?
...
drivers/iio/adc/versal-sysmon.c line 127
Quoted 2 lines
drivers/iio/adc/versal-sysmon.c new file +2
-0+ indio_dev->dev.parent = &pdev->dev; + indio_dev->dev.of_node = pdev->dev.of_node;
Drop these, IIO core does the same and even better.
...
Quoted 1 line
+
mutex_lock(&sysmon->mutex);
scoped_guard() from cleanup.h
drivers/iio/adc/versal-sysmon.c line 143
Quoted 2 lines
drivers/iio/adc/versal-sysmon.c new file +2
-0+if (list_empty (&sysmon_list_head)) { + sysmon->master_slr = true;
No need, just make a sane default and !exist will work in the other branch the same way. I believe it's
bool exist = false;
drivers/iio/adc/versal-sysmon.c line 147
Quoted 4 lines
drivers/iio/adc/versal-sysmon.c new file +4
-0+ }else { +list_for_each_entry (temp_sysmon, &sysmon_list_head, list) { +if (temp_sysmon->master_slr) + exist = true;
Why to continue?
Quoted 5 lines
drivers/iio/adc/versal-sysmon.c new file +5
-0+ } + sysmon->master_slr = !exist; + } + +mutex_unlock (&sysmon->mutex);
...
drivers/iio/adc/versal-sysmon.h line 23
Quoted 12 lines
drivers/iio/adc/versal-sysmon.h new file +11
-0+#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/iio/buffer.h> +#include <linux/iio/driver.h> +#include <linux/iio/events.h> +#include <linux/iio/machine.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/adc/versal-sysmon-events.h> +#include <linux/iopoll.h> +#include <linux/kernel.h>
Mustn't be used in new drivers.
drivers/iio/adc/versal-sysmon.h line 28
Quoted 5 lines
drivers/iio/adc/versal-sysmon.h new file +5
-0+#include <linux/list.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/of_address.h>
Huh?! Please, make sure you are following IWYU principle, please *drop* all of the headers that are *not* being used (by this header), there are a LOT of them to be dropped.
...
drivers/iio/adc/versal-sysmon.h line 36
Quoted 7 lines
drivers/iio/adc/versal-sysmon.h new file +7
-0+/* Channel IDs for Temp Channels */ +/* TEMP_MAX gives the current temperature for Production +* silicon. +* TEMP_MAX gives the current maximum temperature for ES1 +* silicon. +*/ +#define TEMP_MAX 160
Here and everywhere else, bad namings.
...
This is an unfinished review due to the following reasons (from more important to less):
- AMD is not the first day contributor, the code is awful, it missed a lot of reviews and updates regarding the last several years of the kernel development (IIO subsystem in particular). Please, avoid letting reviewers do *your* job.
- The patches are too long to review, it would be nicer to make them feature-by-feature, where each one is < 1000 LoCs.
- I started this a few days ago, but I'm busy at the moment, that's another reason.
--
With Best Regards,
Andy Shevchenko
Re: [PATCH 2/6] iio: versal-sysmon: add driver for Versal Sysmon
Hi Andy,
Quoted 286 lines · Andy Shevchenko
Quoted 7 lines · Michal Simek
Sysmon Driver uses Linux IIO framework, which was used to abstract the supply voltages and temperatures across the chip as Voltage and Temperature Channels in the framework. Since there are only 160 supply voltage registers and 184 measurement points, there is no constant mapping of supply voltage registers and the measurement points. User has to select the voltages to monitor in design tool. Depending on the selection, a
in the design
Quoted 5 lines
voltage supply gets mapped to one of the supply registers. So, this mapping information is provided to the driver via a device tree. Depending on the number of supplies enabled in the design, the device tree will contain the information of name of the supply enabled and the supply register it maps to.
...
drivers/iio/adc/Kconfig config XILINX_AMS · line 1836
Quoted 10 lines
drivers/iio/adc/Kconfig +10
-0+config VERSAL_SYSMON + tristate "Xilinx Sysmon driver for Versal" + depends on HAS_IOMEM + select VERSAL_SYSMON_CORE + help + Say yes here to have support for the Xilinx Sysmon. + The driver will enable users to monitor temperature and voltage on the + Xilinx Versal platform. + + The driver can also be build as a module. If so, the module will be calledbuilt
Quoted 1 line
+ versal-sysmon.
...
Quoted 1 line
+#include <
linux/bits.h>Quite a few headers are absent...
+
export.h
+types.hQuoted 1 line
+#include "
versal-sysmon.h"...
Quoted 8 lines
drivers/iio/adc/versal-sysmon-core.c new file +8
-0+static u32 sysmon_temp_offset (int address) +{ +switch (address) { +case TEMP_MAX : +return SYSMON_TEMP_MAX ; +case TEMP_MIN : +return SYSMON_TEMP_MIN ; +case TEMP_MAX_MAX :drivers/iio/adc/versal-sysmon-core.c line 116
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +9
-0+return SYSMON_TEMP_MAX_MAX ; +case TEMP_MIN_MIN : +return SYSMON_TEMP_MIN_MIN ; +case TEMP_HBM : +return SYSMON_TEMP_HBM ; +default : +return -EINVAL ; + } +return -EINVAL ;Here and in many more, eliminate dead code.
Quoted 1 line
+}
...
drivers/iio/adc/versal-sysmon-core.c line 145
Quoted 8 lines
drivers/iio/adc/versal-sysmon-core.c new file +7
-0+static u32 sysmon_supply_thresh_offset (int address, +enum iio_event_direction dir) +{ +if (dir ==IIO_EV_DIR_RISING ) +return (address *4 ) +SYSMON_SUPPLY_TH_UP ; +else if (dir ==IIO_EV_DIR_FALLING ) +return (address *4 ) +SYSMON_SUPPLY_TH_LOW ;Redundant 'else'.
Quoted 2 lines
(quoted diff) +2
-0+ return -EINVAL; +}...
drivers/iio/adc/versal-sysmon-core.c line 161
Quoted 4 lines
drivers/iio/adc/versal-sysmon-core.c new file +4
-0+static void sysmon_hbm_to_millicelsius (int raw_data,int *val,int *val2) +{ + *val = ((raw_data >>SYSMON_HBM_TEMP_SHIFT ) &SYSMON_HBM_TEMP_MASK ) * +SYSMON_MILLI_SCALE ;Can the whole driver be switched to FIELD_PREP()/FIELD_GET()/FIELD_MODIFY()?
Quoted 2 lines
(quoted diff) +2
-0+ *val2 = 0; +}...
drivers/iio/adc/versal-sysmon-core.c line 192
Quoted 4 lines
drivers/iio/adc/versal-sysmon-core.c new file +3
-0+static void sysmon_millicelsius_to_q8p7 (u32 *raw_data,int val,int val2) +{ + (void )val2;Unneeded.
Quoted 2 lines
(quoted diff) +2
-0+ *raw_data = (val << SYSMON_FRACTIONAL_SHIFT) / SYSMON_MILLI_SCALE; +}...
Quoted 6 lines
drivers/iio/adc/versal-sysmon-core.c new file +6
-0+static void sysmon_supply_processedtoraw (int val,int val2,u32 reg_val, +u32 *raw_data) +{ +int exponent = (reg_val &SYSMON_MODE_MASK ) >>SYSMON_MODE_SHIFT ; +int format = (reg_val &SYSMON_FMT_MASK ) >>SYSMON_FMT_SHIFT ; +int scale =1 << (16 - exponent);drivers/iio/adc/versal-sysmon-core.c line 230
Quoted 10 lines
drivers/iio/adc/versal-sysmon-core.c new file +10
-0+int tmp; + + tmp = (val * scale) /SYSMON_MILLI_SCALE ; + +/* Set out of bound values to saturation levels */ +if (format) { +if (tmp >SYSMON_UPPER_SATURATION_SIGNED ) + tmp =0x7fff ; +else if (tmp <SYSMON_LOWER_SATURATION_SIGNED ) + tmp =0x8000 ;This looks like s16 limits, can you use them?
drivers/iio/adc/versal-sysmon-core.c line 236
Quoted 5 lines
drivers/iio/adc/versal-sysmon-core.c new file +5
-0+ }else { +if (tmp >SYSMON_UPPER_SATURATION ) + tmp =0xffff ; +else if (tmp <SYSMON_LOWER_SATURATION ) + tmp =0x0000 ;u16 respectively.
Quoted 35 lines
drivers/iio/adc/versal-sysmon-core.c new file +32
-0+ } + + *raw_data = tmp &0xffff ; +} +u32 ret = -EINVAL ; +mutex_lock (&sysmon->mutex); +switch (mask) { +case IIO_CHAN_INFO_RAW : +switch (chan->type) { +case IIO_TEMP : + offset =sysmon_temp_offset (chan->address); + *val = sysmon->temp_read (sysmon, offset); + *val2 =0 ; + ret =IIO_VAL_INT ; +break ; + +case IIO_VOLTAGE : + offset =sysmon_supply_offset (chan->address); +sysmon_read_reg (sysmon, offset, ®val); + *val = (int )regval; + *val2 =0 ; + ret =IIO_VAL_INT ; +break ; + +default : +break ; + }> + +spin_unlock_irqrestore (&sysmon->lock, flags); +mutex_unlock (&sysmon->mutex); + +return 0 ; +}...
Quoted 1 line
+#include <
linux/bits.h>+
io.hdrivers/iio/adc/versal-sysmon.c line 19
Quoted 5 lines
drivers/iio/adc/versal-sysmon.c new file +5
-0+#include <linux/moduleparam.h> +#include <linux/firmware/xlnx-zynqmp.h> +#include "versal-sysmon.h" + +static LIST_HEAD (sysmon_list_head);
list.h?drivers/iio/adc/versal-sysmon.c line 22
Quoted 2 lines
drivers/iio/adc/versal-sysmon.c new file +2
-0+static struct iio_map sysmon_therm_static_maps[] = { +IIO_MAP ("temp" ,"versal-thermal" ,"sysmon-temp-channel" ),Where are the
IIO_MAP()and structiio_mapdefined?drivers/iio/adc/versal-sysmon.c line 26
Quoted 4 lines
drivers/iio/adc/versal-sysmon.c new file +4
-0+ {} +}; + +static inline int sysmon_direct_read_reg (struct sysmon *sysmon,u32 offset,u32 *data)+
types.hfor uXX.Quoted 5 lines
drivers/iio/adc/versal-sysmon.c new file +5
-0+{ + *data =readl (sysmon->base + offset); + +return 0 ; +}...
Quoted 1 line
+
mutex_init(&sysmon->mutex);devm?
...
drivers/iio/adc/versal-sysmon.c line 127
Quoted 2 lines
drivers/iio/adc/versal-sysmon.c new file +2
-0+ indio_dev->dev.parent = &pdev->dev; + indio_dev->dev.of_node = pdev->dev.of_node;Drop these, IIO core does the same and even better.
...
Quoted 1 line
+
mutex_lock(&sysmon->mutex);
scoped_guard()fromcleanup.hdrivers/iio/adc/versal-sysmon.c line 143
Quoted 2 lines
drivers/iio/adc/versal-sysmon.c new file +2
-0+if (list_empty (&sysmon_list_head)) { + sysmon->master_slr = true;No need, just make a sane default and !exist will work in the other branch the same way. I believe it's
bool exist = false;drivers/iio/adc/versal-sysmon.c line 147
Quoted 4 lines
drivers/iio/adc/versal-sysmon.c new file +4
-0+ }else { +list_for_each_entry (temp_sysmon, &sysmon_list_head, list) { +if (temp_sysmon->master_slr) + exist = true;Why to continue?
Quoted 5 lines
drivers/iio/adc/versal-sysmon.c new file +5
-0+ } + sysmon->master_slr = !exist; + } + +mutex_unlock (&sysmon->mutex);...
drivers/iio/adc/versal-sysmon.h line 23
Quoted 12 lines
drivers/iio/adc/versal-sysmon.h new file +11
-0+#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/iio/buffer.h> +#include <linux/iio/driver.h> +#include <linux/iio/events.h> +#include <linux/iio/machine.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/adc/versal-sysmon-events.h> +#include <linux/iopoll.h> +#include <linux/kernel.h> Mustn't be used in new drivers.
drivers/iio/adc/versal-sysmon.h line 28
Quoted 5 lines
drivers/iio/adc/versal-sysmon.h new file +5
-0+#include <linux/list.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/of_address.h> Huh?! Please, make sure you are following IWYU principle, please *drop* all of the headers that are *not* being used (by this header), there are a LOT of them to be dropped.
...
drivers/iio/adc/versal-sysmon.h line 36
Quoted 7 lines
drivers/iio/adc/versal-sysmon.h new file +7
-0+/* Channel IDs for Temp Channels */ +/* TEMP_MAX gives the current temperature for Production +* silicon. +* TEMP_MAX gives the current maximum temperature for ES1 +* silicon. +*/ +#define TEMP_MAX 160Here and everywhere else, bad namings.
Quoted 8 lines
...
This is an unfinished review due to the following reasons (from more important to less):
- AMD is not the first day contributor, the code is awful, it missed a lot of reviews and updates regarding the last several years of the kernel development (IIO subsystem in particular). Please, avoid letting reviewers do *your* job.
Sorry about this. Firstly we need to find a way to have DT binding correct which affect code too.
Quoted 2 lines
- The patches are too long to review, it would be nicer to make them feature-by-feature, where each one is < 1000 LoCs.
We will look at doing one more split. It is 2k LOC now. There is actually also i2c part of this which is not included.
Quoted 2 lines
- I started this a few days ago, but I'm busy at the moment, that's another reason.
Thanks for your review so far.
Thanks,
Michal
PATCH 3/6 iio: adc: versal-sysmon: Support AI Engine thermal monitoring
In reply to Michal SimekFrom: Anish Kadamathikuttiyil Karthikeyan Pillai <[email protected]>
To enhance the thermal monitoring of AI Engine, the sysmon satellites close to it are exposed as IIO channels.
The exposed IIO channel are mapped to allow consumer drivers to access specific sensor data through the IIO framework.
---
drivers/iio/adc/versal-sysmon-core.c | 135 ++++++++++++++++++--------- drivers/iio/adc/versal-sysmon.c | 35 ++++++- drivers/iio/adc/versal-sysmon.h | 3 + 3 files changed, 127 insertions(+), 46 deletions(-)
drivers/iio/adc/versal-sysmon-core.c +90 -45
@@ -272,7 +272,10 @@ static int sysmon_read_raw(struct iio_dev *indio_dev,case IIO_CHAN_INFO_RAW :switch (chan->type) {case IIO_TEMP : - offset =sysmon_temp_offset (chan->address); +if (chan->channel !=AIE_TEMP_CH ) + offset =sysmon_temp_offset (chan->address); +else + offset = chan->address; *val = sysmon->temp_read (sysmon, offset); *val2 =0 ; ret =IIO_VAL_INT ;
@@ -295,7 +298,10 @@ static int sysmon_read_raw(struct iio_dev *indio_dev,switch (chan->type) {case IIO_TEMP :/* In Deg C */ - offset =sysmon_temp_offset (chan->address); +if (chan->channel !=AIE_TEMP_CH ) + offset =sysmon_temp_offset (chan->address); +else + offset = chan->address; regval = sysmon->temp_read (sysmon, offset);if (!sysmon->hbm_slr)sysmon_q8p7_to_millicelsius (regval, val, val2);
@@ -1202,8 +1208,10 @@ int sysmon_parse_dt(struct iio_dev *indio_dev, struct device *dev)struct iio_chan_spec *sysmon_channels;struct device_node *child_node =NULL , *np = dev->of_node;int ret, i =0 ; +int aie_idx =0 ;u32 num_supply_chan =0 ;u32 reg =0 , num_temp_chan =0 ; +u32 num_aie_temp_chan =0 ;const char *name;u32 chan_size =sizeof (struct iio_chan_spec );u32 temp_chan_size;
@@ -1214,6 +1222,11 @@ int sysmon_parse_dt(struct iio_dev *indio_dev, struct device *dev)return ret; sysmon->num_supply_chan = num_supply_chan; + ret =of_property_read_u32 (np,"xlnx,numaiechannels" , &num_aie_temp_chan); +if (ret <0 ) + num_aie_temp_chan =0 ; + + sysmon->num_aie_temp_chan = num_aie_temp_chan;INIT_LIST_HEAD (&sysmon->region_list);
@@ -1233,69 +1246,101 @@ int sysmon_parse_dt(struct iio_dev *indio_dev, struct device *dev) } sysmon_channels =devm_kzalloc (dev, (chan_size * num_supply_chan) + + (chan_size * num_aie_temp_chan) + temp_chan_size,GFP_KERNEL );if (!sysmon_channels)return -ENOMEM ; +/* Configure the dynamic channels */ for_each_child_of_node (np, child_node) { - ret =of_property_read_u32 (child_node,"reg" , ®); -if (ret <0 ) { -of_node_put (child_node); -return ret; - } +if (of_property_present (child_node,"xlnx,aie-temp" )) { + ret =of_property_read_u32 (child_node,"reg" , ®); +if (ret <0 ) { +of_node_put (child_node); +return ret; + } + ret =of_property_read_string (child_node,"xlnx,name" , &name); +if (ret <0 ) { +of_node_put (child_node); +return ret; + } + sysmon_channels[num_supply_chan + aie_idx].type =IIO_TEMP ; + sysmon_channels[num_supply_chan + aie_idx].indexed =1 ; + sysmon_channels[num_supply_chan + aie_idx].address = +SYSMON_NODE_OFFSET + ((reg -1 ) *4 ); + sysmon_channels[num_supply_chan + aie_idx].channel =AIE_TEMP_CH ; + sysmon_channels[num_supply_chan + aie_idx].info_mask_separate = +BIT (IIO_CHAN_INFO_RAW ) |BIT (IIO_CHAN_INFO_PROCESSED ); + sysmon_channels[num_supply_chan + aie_idx].scan_index = aie_idx; + sysmon_channels[num_supply_chan + aie_idx].scan_type.realbits =15 ; + sysmon_channels[num_supply_chan + aie_idx].scan_type.storagebits = +16 ; + sysmon_channels[num_supply_chan + aie_idx].scan_type.endianness = +IIO_CPU ; + sysmon_channels[num_supply_chan + aie_idx].scan_type.sign ='s' ; + sysmon_channels[num_supply_chan + aie_idx].extend_name = name; + sysmon_channels[num_supply_chan + aie_idx].datasheet_name = name; + aie_idx++; + }else { + ret =of_property_read_u32 (child_node,"reg" , ®); +if (ret <0 ) { +of_node_put (child_node); +return ret; + } - ret =of_property_read_string (child_node,"xlnx,name" , &name); -if (ret <0 ) { -of_node_put (child_node); -return ret; - } + ret =of_property_read_string (child_node,"xlnx,name" , &name); +if (ret <0 ) { +of_node_put (child_node); +return ret; + } - sysmon_channels[i].type =IIO_VOLTAGE ; - sysmon_channels[i].indexed =1 ; - sysmon_channels[i].address = reg; - sysmon_channels[i].channel = reg; - sysmon_channels[i].info_mask_separate = -BIT (IIO_CHAN_INFO_RAW ) |BIT (IIO_CHAN_INFO_PROCESSED ); - sysmon_channels[i].info_mask_shared_by_type = -BIT (IIO_CHAN_INFO_OVERSAMPLING_RATIO ); - sysmon_channels[i].info_mask_shared_by_type_available = -BIT (IIO_CHAN_INFO_OVERSAMPLING_RATIO ); - - sysmon_channels[i].event_spec = sysmon_supply_events; - sysmon_channels[i].num_event_specs =ARRAY_SIZE (sysmon_supply_events); - - sysmon_channels[i].scan_index = i; - sysmon_channels[i].scan_type.realbits =19 ; - sysmon_channels[i].scan_type.storagebits =32 ; - - sysmon_channels[i].scan_type.endianness =IIO_CPU ; - sysmon_channels[i].extend_name = name; - -if (of_property_read_bool (child_node,"xlnx,bipolar" )) - sysmon_channels[i].scan_type.sign ='s' ; -else - sysmon_channels[i].scan_type.sign ='u' ; + sysmon_channels[i].type =IIO_VOLTAGE ; + sysmon_channels[i].indexed =1 ; + sysmon_channels[i].address = reg; + sysmon_channels[i].channel = reg; + sysmon_channels[i].info_mask_separate = +BIT (IIO_CHAN_INFO_RAW ) |BIT (IIO_CHAN_INFO_PROCESSED ); + sysmon_channels[i].info_mask_shared_by_type = +BIT (IIO_CHAN_INFO_OVERSAMPLING_RATIO ); + sysmon_channels[i].info_mask_shared_by_type_available = +BIT (IIO_CHAN_INFO_OVERSAMPLING_RATIO ); + + sysmon_channels[i].event_spec = sysmon_supply_events; + sysmon_channels[i].num_event_specs =ARRAY_SIZE (sysmon_supply_events); + + sysmon_channels[i].scan_index = i; + sysmon_channels[i].scan_type.realbits =19 ; + sysmon_channels[i].scan_type.storagebits =32 ; + + sysmon_channels[i].scan_type.endianness =IIO_CPU ; + sysmon_channels[i].extend_name = name; + +if (of_property_read_bool (child_node,"xlnx,bipolar" )) + sysmon_channels[i].scan_type.sign ='s' ; +else + sysmon_channels[i].scan_type.sign ='u' ; - i++; + i++; + } }/* Append static temperature channels to the channel list */ - indio_dev->num_channels = num_supply_chan; + indio_dev->num_channels = num_supply_chan + num_aie_temp_chan;if (sysmon->master_slr) { -memcpy (sysmon_channels + num_supply_chan, temp_channels, -sizeof (temp_channels)); +memcpy (sysmon_channels + num_supply_chan + num_aie_temp_chan, + temp_channels,sizeof (temp_channels)); indio_dev->num_channels +=ARRAY_SIZE (temp_channels); }if (sysmon->hbm_slr) { -memcpy (sysmon_channels + num_supply_chan, temp_hbm_channels, -sizeof (temp_hbm_channels)); +memcpy (sysmon_channels + num_supply_chan + num_aie_temp_chan, + temp_hbm_channels,sizeof (temp_hbm_channels)); indio_dev->num_channels += num_temp_chan; }else { -memcpy (sysmon_channels + num_supply_chan + num_temp_chan, - temp_events,sizeof (temp_events)); +memcpy (sysmon_channels + num_supply_chan + num_aie_temp_chan + + num_temp_chan, temp_events,sizeof (temp_events)); indio_dev->num_channels +=ARRAY_SIZE (temp_events); }
drivers/iio/adc/versal-sysmon.c +34 -1
@@ -108,8 +108,13 @@ static int sysmon_probe(struct platform_device *pdev)struct sysmon *sysmon, *temp_sysmon;struct iio_dev *indio_dev;struct resource *mem; +struct iio_map *all_maps; +const struct iio_chan_spec *chan;bool exist = false;int ret; +int maps_size =0 ; +int maps_idx =0 ; +int dyn_idx =0 ; indio_dev =devm_iio_device_alloc (&pdev->dev,sizeof (*sysmon));if (!indio_dev)
@@ -183,8 +188,36 @@ static int sysmon_probe(struct platform_device *pdev)platform_set_drvdata (pdev, indio_dev);if (sysmon->master_slr) { +/* Combine static and dynamic iio maps and register */ + maps_size =ARRAY_SIZE (sysmon_therm_static_maps) -1 + + sysmon->num_aie_temp_chan; + all_maps =devm_kzalloc (&pdev->dev, +sizeof (*all_maps) * (maps_size),GFP_KERNEL ); +if (!all_maps) +return -ENOMEM ; + +for (maps_idx =0 ; + maps_idx <ARRAY_SIZE (sysmon_therm_static_maps) -1 ; + maps_idx++) + all_maps[maps_idx] = + sysmon_therm_static_maps[maps_idx]; + +for (dyn_idx =0 ; dyn_idx < indio_dev->num_channels && maps_idx < maps_size; + dyn_idx++) { + chan = &indio_dev->channels[dyn_idx]; + +if (chan->channel ==AIE_TEMP_CH ) { + all_maps[maps_idx].adc_channel_label = + chan->extend_name; + all_maps[maps_idx].consumer_dev_name = +"versal-thermal" ; + all_maps[maps_idx].consumer_channel = + chan->extend_name; + maps_idx++; + } + } ret =devm_iio_map_array_register (&pdev->dev, indio_dev, - sysmon_therm_static_maps); + all_maps);if (ret <0 )return dev_err_probe (&pdev->dev, ret,"IIO map register failed\n" ); }
drivers/iio/adc/versal-sysmon.h +3 -0
@@ -45,6 +45,7 @@#define TEMP_EVENT 164#define OT_EVENT 165#define TEMP_HBM 166 +#define AIE_TEMP_CH 200/* Register Unlock Code */ #define NPI_UNLOCK 0xF9E8D7C6
@@ -215,6 +216,7 @@ static const unsigned int sysmon_oversampling_avail[5] = {* @oversampling_avail: list of available overampling ratios * @oversampling_num: total number of available oversampling ratios * @num_supply_chan: number of supply channels that are enabled +* @num_aie_temp_chan: number of aie temp channels that are enabled * @supply_avg_en_attrs: dynamic array of supply averaging enable attributes * @temp_avg_en_attrs: dynamic array of temp. sat. averaging enable attributes * @avg_attrs: dynamic array of pointers to averaging attributes
@@ -248,6 +250,7 @@ struct sysmon {const unsigned int *oversampling_avail;unsigned int oversampling_num;unsigned int num_supply_chan; +unsigned int num_aie_temp_chan;struct iio_dev_attr *supply_avg_en_attrs;struct iio_dev_attr *temp_avg_en_attrs;struct attribute **avg_attrs;
Signature · 1 line
2.43.0
PATCH 4/6 dt-bindings: thermal: versal: Add description for Versal Thermal
In reply to Michal SimekFrom: Salih Erim <[email protected]>
Add description of Versal Thermal which describes IO channels to be binded to thermal. Constant channel of "sysmon-temp-channel" used as mapped iio channel.
One temperature zone is used for the AI Engine temperature monitoring.
---
.../bindings/thermal/xlnx,versal-thermal.yaml | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml
Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml new file +45 -0
@@ -0,0 +1,45 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/thermal/xlnx,versal-thermal.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Xilinx Versal Thermal + +maintainers: + - Salih Erim <[email protected]> + +description: + Versal Thermal uses Versal Sysmon hardware for temperature reading. + It works as sensor interface to be defined in thermal zones. + +properties: + compatible: + const: xlnx,versal-thermal + + '#thermal-sensor-cells': + const: 1 + + io-channels: + maxItems: 1 + + io-channel-names: + const: sysmon-temp-channel + +required: + - compatible + - '#thermal-sensor-cells' + - io-channels + - io-channel-names + +additionalProperties: false + +examples: + - | + versal-thermal-sensor { + compatible = "xlnx,versal-thermal"; + #thermal-sensor-cells = <1>; + io-channels = <&sysmon0>; + io-channel-names = "sysmon-temp-channel"; + }; +...
Signature · 1 line
2.43.0
Re: [PATCH 4/6] dt-bindings: thermal: versal: Add description for Versal Thermal
Quoted 32 lines · Michal Simek
From: Salih Erim <[email protected]>
Add description of Versal Thermal which describes IO channels to be binded to thermal. Constant channel of "sysmon-temp-channel" used as mapped iio channel.
One temperature zone is used for the AI Engine temperature monitoring.
Signed-off-by Salih Erim <[email protected]>Co-developed-by Anish Kadamathikuttiyil Karthikeyan Pillai <[email protected]>Signed-off-by Michal Simek <[email protected]>---
.../bindings/thermal/xlnx,versal-thermal.yaml | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yamlDocumentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml new file +8
-0@@ -0,0 +1,45 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/thermal/xlnx,versal-thermal.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Xilinx Versal Thermal +
Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml line 18
Quoted 10 lines
Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml new file +10
-0+maintainers: + - Salih Erim <[email protected]> + +description: + Versal Thermal uses Versal Sysmon hardware for temperature reading. + It works as sensor interface to be defined in thermal zones. + +properties: + compatible: + const: xlnx,versal-thermal
BTW Michal, what's the story with using amd v xlnx for bindings? Planning to use amd for new devices and xlnx for stuff sold before the purchase or something like that?
Quoted 11 lines
Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml new file +11
-0+ + '#thermal-sensor-cells': + const: 1 + + io-channels: + maxItems: 1 + + io-channel-names: + const: sysmon-temp-channel + +required:
Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml line 39
Quoted 10 lines
Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml new file +10
-0+ - compatible + - '#thermal-sensor-cells' + - io-channels + - io-channel-names + +additionalProperties: false + +examples: + - | + versal-thermal-sensor {
Drop the versal from the node name here please.
With that,
Quoted 9 lines
Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml new file +6
-0+ compatible = "xlnx,versal-thermal"; + #thermal-sensor-cells = <1>; + io-channels = <&sysmon0>; + io-channel-names = "sysmon-temp-channel"; + }; +...Signature · 1 line
2.43.0
Re: [PATCH 4/6] dt-bindings: thermal: versal: Add description for Versal Thermal
Quoted 39 lines · Conor Dooley
Quoted 38 lines · Michal Simek
From: Salih Erim <[email protected]>
Add description of Versal Thermal which describes IO channels to be binded to thermal. Constant channel of "sysmon-temp-channel" used as mapped iio channel.
One temperature zone is used for the AI Engine temperature monitoring.
Signed-off-by Salih Erim <[email protected]>Co-developed-by Anish Kadamathikuttiyil Karthikeyan Pillai <[email protected]>Signed-off-by Michal Simek <[email protected]>---
.../bindings/thermal/xlnx,versal-thermal.yaml | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+)create mode 100644
Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yamlDocumentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml new file +14
-0@@ -0,0 +1,45 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/thermal/xlnx,versal-thermal.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Xilinx Versal Thermal + +maintainers: + - Salih Erim <[email protected]> + +description: + Versal Thermal uses Versal Sysmon hardware for temperature reading. + It works as sensor interface to be defined in thermal zones.
Quoted 8 lines
Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml line 18
Quoted 4 lines
Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml new file +4
-0+ +properties: + compatible: + const: xlnx,versal-thermalBTW Michal, what's the story with using amd v xlnx for bindings? Planning to use amd for new devices and xlnx for stuff sold before the purchase or something like that?
yes exactly that is the plan. Newly developed drivers or SOC will start to use amd prefixes instead of xlnx. This is the IP which is around for a while that's why xlnx is still used.
Quoted 17 lines
Quoted 17 lines
Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml new file +16
-0+ + '#thermal-sensor-cells': + const: 1 + + io-channels: + maxItems: 1 + + io-channel-names: + const: sysmon-temp-channel + +required: + - compatible + - '#thermal-sensor-cells' + - io-channels + - io-channel-names +
Quoted 8 lines
Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml line 39
Quoted 5 lines
Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml new file +5
-0+additionalProperties: false + +examples: + - | + versal-thermal-sensor {Drop the versal from the node name here please.
With that,
will do.
Quoted 1 line
Acked-by Conor Dooley <[email protected]>
Thanks,
Michal
PATCH 5/6 thermal: versal-thermal: Add Versal thermal driver
In reply to Michal SimekFrom: Salih Erim <[email protected]>
This patch adds the Versal thermal driver based on Versal Sysmon as thermal infrastructure sensor.
Sysmon devices use IIO framework to expose temperature information to system.
This driver connects to the sysmon temp channel by iio binding mapping defined on the sysmon driver.
This is initial work for defining thermal sensor driver and thermal infrastructure for Versal devices. Single thermal zone has to be defined and no cooling devices and maps are supported at this point.
Sysmon devices default temperature event thresholds can be used as temperature ranges.
Updates the maintainer file accordingly to this driver.
---
MAINTAINERS | 6 +++ drivers/thermal/Kconfig | 12 +++++ drivers/thermal/Makefile | 1 + drivers/thermal/versal_thermal.c | 87 ++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 drivers/thermal/versal_thermal.c
MAINTAINERS +6 -0
@@ -27609,6 +27609,12 @@ F: Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml F: drivers/iio/adc/versal-sysmon* F: include/linux/iio/adc/versal-sysmon-events.h +XILINX VERSAL THERMAL DRIVER +M: Salih Erim <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml +F: drivers/thermal/versal_thermal.c + XILINX UARTLITE SERIAL DRIVER M: Peter Korsgaard <[email protected]> L: [email protected]
drivers/thermal/Kconfig +12 -0
@@ -517,4 +517,16 @@ config LOONGSON2_THERMAL is higher than the high temperature threshold or lower than the low temperature threshold, the interrupt will occur. +config VERSAL_THERMAL + tristate "Versal thermal sensor driver" + depends on OF + depends on VERSAL_SYSMON + help + This adds support for Versal thermal driver as thermal zone sensor + The thermal driver is connected to Versal Sysmon for the temperature + channel via iio binding. The Sysmon channel is read via IIO framework + and the channel information is provided to driver. + The driver can also be build as a module. If so, the module will be called + versal_thermal + endif
drivers/thermal/Makefile +1 -0
@@ -68,3 +68,4 @@ obj-$(CONFIG_SPRD_THERMAL) += sprd_thermal.o obj-$(CONFIG_KHADAS_MCU_FAN_THERMAL) += khadas_mcu_fan.o obj-$(CONFIG_LOONGSON2_THERMAL) += loongson2_thermal.o obj-$(CONFIG_THERMAL_CORE_TESTING) += testing/ +obj-$(CONFIG_VERSAL_THERMAL) += versal_thermal.o
drivers/thermal/versal_thermal.c new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 6/6 thermal: versal-thermal: Support thermal management in AI Engine
In reply to Michal SimekFrom: Anish Kadamathikuttiyil Karthikeyan Pillai <[email protected]>
For AI Engine thermal monitoring, through the thermal framework, a new temperature zone is added. The temperature of versal sysmon satellites near to AI Engine is read from the mapped IIO channels. The maximum value of temperature from versal sysmon satellites near AI Engine will be reported.
In versal thermal driver iio channel names are read from versal sysmon temp child node. The reason is we cannot specify the iio-channel-names in versal thermal sensor node, as it can change from board to board and versal_thermal node which is not related to any hardware.
Passing NULL is not be supported by devm_ API for getting IIO channel names. So we moved from this approach to iio_channel_get approach.
---
drivers/thermal/versal_thermal.c | 146 +++++++++++++++++++++++++++++-- 1 file changed, 140 insertions(+), 6 deletions(-)
drivers/thermal/versal_thermal.c +140 -6
@@ -13,11 +13,17 @@#define SYSMON_TEMP_CH_NAME "sysmon-temp-channel"#define SYSMON_FRACTIONAL_DENOM 128 +#define SYSMON_STATIC_IIO_CH_COUNT 1 +#define SYSMON_AIE_TEMP_CH 200 +#define TEMP_MAX 160struct versal_thermal_info {struct device *dev;struct thermal_zone_device *tzd; +struct thermal_zone_device *tzd_aie;struct iio_channel *channel; +struct iio_channel **channel_aie; +u32 num_aie_channels; };static int temperature_sensor_get_temp (struct thermal_zone_device *tz,int *temp)
@@ -39,31 +45,158 @@ static int temperature_sensor_get_temp(struct thermal_zone_device *tz, int *tempreturn 0 ; } +static int temperature_sensor_get_temp_aie (struct thermal_zone_device *tz, +int *temp) +{ +struct versal_thermal_info *vti =thermal_zone_device_priv (tz); +int ret, val; +int max_temp =INT_MIN ; +u32 aie_ch_index; + +for (aie_ch_index =0 ; aie_ch_index < vti->num_aie_channels; + aie_ch_index++) { + ret =iio_read_channel_processed (vti->channel_aie[aie_ch_index], &val); +if (ret ==IIO_VAL_FRACTIONAL ) { +/* Convert raw value to temperature in millidegrees Celsius */ + *temp = val *1000 ; + *temp /=SYSMON_FRACTIONAL_DENOM ; + }else if (ret ==IIO_VAL_INT ) { + *temp = val; + }else { +dev_err (vti->dev,"iio_read_channel_processed failed aie ch%d, ret = %d\n" , + aie_ch_index, ret); +return ret; + } +if (*temp > max_temp) + max_temp = *temp; + } + *temp = max_temp; +return 0 ; +} +static const struct thermal_zone_device_ops thermal_zone_ops = { .get_temp = temperature_sensor_get_temp, }; +static const struct thermal_zone_device_ops thermal_zone_ops_aie = { + .get_temp = temperature_sensor_get_temp_aie, +}; + +static void versal_thermal_iio_chan_release (struct versal_thermal_info *vti) +{ +int aie_ch_index; + +if (!IS_ERR_OR_NULL (vti->channel)) +iio_channel_release (vti->channel); +for (aie_ch_index =0 ; aie_ch_index < vti->num_aie_channels; aie_ch_index++) +if (!IS_ERR_OR_NULL (vti->channel_aie[aie_ch_index])) +iio_channel_release (vti->channel_aie[aie_ch_index]); +} +static int versal_thermal_probe (struct platform_device *pdev) {struct versal_thermal_info *vti; +struct device_node *sysmon_node; +struct device_node *child_node =NULL ; +int aie_ch_index =0 ; +int ret =0 ; +u32 num_aie_channels =0 ; +const char **aie_temp_chan_names; +const char *aie_temp_chan_name; vti =devm_kzalloc (&pdev->dev,sizeof (struct versal_thermal_info ),GFP_KERNEL );if (!vti)return -ENOMEM ; - vti->channel =devm_iio_channel_get (&pdev->dev,SYSMON_TEMP_CH_NAME ); -if (IS_ERR (vti->channel)) -return dev_err_probe (&pdev->dev,PTR_ERR (vti->channel), -"IIO channel not found\n" ); - vti->dev = &pdev->dev; + vti->channel =iio_channel_get (NULL ,SYSMON_TEMP_CH_NAME ); +if (IS_ERR (vti->channel)) { + vti->num_aie_channels =0 ; +versal_thermal_iio_chan_release (vti); +return dev_err_probe (&pdev->dev,PTR_ERR (vti->channel), +"IIO channel %s not found\n" , +SYSMON_TEMP_CH_NAME ); + } + vti->tzd =devm_thermal_of_zone_register (&pdev->dev,0 , vti, &thermal_zone_ops);if (IS_ERR (vti->tzd))return dev_err_probe (&pdev->dev,PTR_ERR (vti->tzd),"Thermal zone sensor register failed\n" ); -return devm_thermal_add_hwmon_sysfs (&pdev->dev, vti->tzd); + ret =devm_thermal_add_hwmon_sysfs (&pdev->dev, vti->tzd); +if (ret) +return dev_err_probe (&pdev->dev, ret, +"Failed to add hwmon sysfs for sysmon temp\n" ); + + sysmon_node =of_find_node_by_name (NULL ,"sysmon" ); +if (sysmon_node) { + ret =of_property_read_u32 (sysmon_node,"xlnx,numaiechannels" , + &num_aie_channels); +if (ret <0 ) + num_aie_channels =0 ; + } + +if (num_aie_channels >0 ) { + aie_temp_chan_names =devm_kcalloc (&pdev->dev, num_aie_channels, +sizeof (*aie_temp_chan_names), +GFP_KERNEL ); +if (!aie_temp_chan_names) +return -ENOMEM ; + +for_each_child_of_node (sysmon_node, child_node) { +if (of_property_present (child_node,"xlnx,aie-temp" )) { + ret =of_property_read_string (child_node,"xlnx,name" , + &aie_temp_chan_name); +if (ret <0 ) { +of_node_put (child_node); +return ret; + } + aie_temp_chan_names[aie_ch_index] = aie_temp_chan_name; + aie_ch_index++; + } + } + +/* Allocate memory for the dynamic aie temperature channels */ + vti->channel_aie =devm_kcalloc (&pdev->dev, num_aie_channels, +sizeof (*vti->channel_aie),GFP_KERNEL ); +if (!vti->channel_aie) +return -ENOMEM ; + +for (aie_ch_index =0 ; aie_ch_index < num_aie_channels; aie_ch_index++) { + vti->channel_aie[aie_ch_index] = +iio_channel_get (NULL , aie_temp_chan_names[aie_ch_index]); +if (IS_ERR (vti->channel_aie[aie_ch_index])) { + vti->num_aie_channels = aie_ch_index +1 ; +versal_thermal_iio_chan_release (vti); +return dev_err_probe (&pdev->dev, +PTR_ERR (vti->channel_aie[aie_ch_index]), +"IIO AIE TEMP channel %s not found\n" , + aie_temp_chan_names[aie_ch_index]); + } + } + + vti->tzd_aie =devm_thermal_of_zone_register (&pdev->dev,1 , vti, + &thermal_zone_ops_aie); +if (IS_ERR (vti->tzd_aie)) +return dev_err_probe (&pdev->dev,PTR_ERR (vti->tzd_aie), +"Failed to register thermal zone aie temp\n" ); + + ret =devm_thermal_add_hwmon_sysfs (&pdev->dev, vti->tzd_aie); +if (ret) +return dev_err_probe (&pdev->dev, ret, +"Failed to add hwmon sysfs for aie temp\n" ); + } + vti->num_aie_channels = num_aie_channels; +platform_set_drvdata (pdev, vti); +return 0 ; +} + +static void versal_thermal_remove (struct platform_device *pdev) +{ +struct versal_thermal_info *vti =platform_get_drvdata (pdev); + +versal_thermal_iio_chan_release (vti); }static const struct of_device_id versal_thermal_of_match[] = {
@@ -78,6 +211,7 @@ static struct platform_driver versal_thermal_driver = { .of_match_table = versal_thermal_of_match, }, .probe = versal_thermal_probe, + .remove = versal_thermal_remove, };module_platform_driver (versal_thermal_driver);
Signature · 1 line
2.43.0
Re: [PATCH 6/6] thermal: versal-thermal: Support thermal management in AI Engine
Quoted 11 lines · Michal Simek
drivers/thermal/versal_thermal.c +9
-0+ vti->channel =iio_channel_get (NULL ,SYSMON_TEMP_CH_NAME ); +if (IS_ERR (vti->channel)) { + vti->num_aie_channels =0 ; +versal_thermal_iio_chan_release (vti); +return dev_err_probe (&pdev->dev,PTR_ERR (vti->channel), +"IIO channel %s not found\n" , +SYSMON_TEMP_CH_NAME ); + } + vti->tzd =devm_thermal_of_zone_register (&pdev->dev,0 , vti, &thermal_zone_ops);if (IS_ERR (vti->tzd))
drivers/thermal/versal_thermal.c static int temperature_sensor_get_temp(struct thermal_zone_device *tz, int *temp · line 132
Quoted 10 lines
drivers/thermal/versal_thermal.c +6
-1return dev_err_probe (&pdev->dev,PTR_ERR (vti->tzd),"Thermal zone sensor register failed\n" ); -return devm_thermal_add_hwmon_sysfs (&pdev->dev, vti->tzd); + ret =devm_thermal_add_hwmon_sysfs (&pdev->dev, vti->tzd); +if (ret) +return dev_err_probe (&pdev->dev, ret, +"Failed to add hwmon sysfs for sysmon temp\n" ); + + sysmon_node =of_find_node_by_name (NULL ,"sysmon" );
Undocumented ABI. Please don't do that. sysmon is not an approved name and for sure can be changed anytime to anything.
Phandles express relationships usually.
Quoted 57 lines
drivers/thermal/versal_thermal.c +57
-0+if (sysmon_node) { + ret =of_property_read_u32 (sysmon_node,"xlnx,numaiechannels" , + &num_aie_channels); +if (ret <0 ) + num_aie_channels =0 ; + } + +if (num_aie_channels >0 ) { + aie_temp_chan_names =devm_kcalloc (&pdev->dev, num_aie_channels, +sizeof (*aie_temp_chan_names), +GFP_KERNEL ); +if (!aie_temp_chan_names) +return -ENOMEM ; + +for_each_child_of_node (sysmon_node, child_node) { +if (of_property_present (child_node,"xlnx,aie-temp" )) { + ret =of_property_read_string (child_node,"xlnx,name" , + &aie_temp_chan_name); +if (ret <0 ) { +of_node_put (child_node); +return ret; + } + aie_temp_chan_names[aie_ch_index] = aie_temp_chan_name; + aie_ch_index++; + } + } + +/* Allocate memory for the dynamic aie temperature channels */ + vti->channel_aie =devm_kcalloc (&pdev->dev, num_aie_channels, +sizeof (*vti->channel_aie),GFP_KERNEL ); +if (!vti->channel_aie) +return -ENOMEM ; + +for (aie_ch_index =0 ; aie_ch_index < num_aie_channels; aie_ch_index++) { + vti->channel_aie[aie_ch_index] = +iio_channel_get (NULL , aie_temp_chan_names[aie_ch_index]); +if (IS_ERR (vti->channel_aie[aie_ch_index])) { + vti->num_aie_channels = aie_ch_index +1 ; +versal_thermal_iio_chan_release (vti); +return dev_err_probe (&pdev->dev, +PTR_ERR (vti->channel_aie[aie_ch_index]), +"IIO AIE TEMP channel %s not found\n" , + aie_temp_chan_names[aie_ch_index]); + } + } + + vti->tzd_aie =devm_thermal_of_zone_register (&pdev->dev,1 , vti, + &thermal_zone_ops_aie); +if (IS_ERR (vti->tzd_aie)) +return dev_err_probe (&pdev->dev,PTR_ERR (vti->tzd_aie), +"Failed to register thermal zone aie temp\n" ); + + ret =devm_thermal_add_hwmon_sysfs (&pdev->dev, vti->tzd_aie); +if (ret) +return dev_err_probe (&pdev->dev, ret, +"Failed to add hwmon sysfs for aie temp\n" ); + }
drivers/thermal/versal_thermal.c static int temperature_sensor_get_temp(struct thermal_zone_device *tz, int *temp · line 199
Quoted 10 lines
drivers/thermal/versal_thermal.c +10
-0+ vti->num_aie_channels = num_aie_channels; +platform_set_drvdata (pdev, vti); +return 0 ; +} + +static void versal_thermal_remove (struct platform_device *pdev) +{ +struct versal_thermal_info *vti =platform_get_drvdata (pdev); + +versal_thermal_iio_chan_release (vti);
Don't mix non-devm with devm. This should be a proper devm cleanup action.
Best regards,
Krzysztof