adding support for Microchip PAC193X Power Monitor
Subsystems (4)
[email protected]
maintainerv3 cover adding support for Microchip PAC193X Power Monitor
From: Marius Cristea <[email protected]>
Adding support for Microchip PAC193X series of Power Monitor with Accumulator chip family. This driver covers the following part numbers:
- PAC1931, PAC1932, PAC1933 and PAC1934
This device is at the boundary between IIO and HWMON (if you are
looking just at the "shunt resistors, vsense, power, energy"). The device also has ADC internally that can measure voltages (up to 4 channels) and also currents (up to 4 channels). The current is measured as voltage across the shunt_resistor.
I have started with a simple driver (this one that is more appropriate to be a
HWMON) and willing to add more functionality later (like data buffering that is quite important for example if someone wants to profile power consumption of the processor itself, or a peripheral device, or a battery, this kind of functionality was requested by our customers).
Differences related to previous patch:
v3:
- this version was sent also to HWMON list
- fix review comments:
- drop redundant description from device tree bindings
- reorder "patternProperties:" to follow "properties:" in device tree bindings
- update comments to proper describe code
- use numbers instead of defines for clarity in some part of the code
- use the new "guard(mutex)"
- use "clamp()" instead of duplicating code
- remove extra layer of checking in some switch cases
- use "i2c_get_match_data()"
- replace while with for loops for the code to look cleaner
- reverse the logic to reduce indent.
- add comment related to channels numbering
- remove memory duplicate when creating dynamic channels
- add "devm_add_action_or_reset" to handle the "cancel_delayed_work_sync"
- remove "pac1934_remove()" function
v2:
- fix review comments:
- change the device tree bindings
- use label property
- fix coding style issues
- remove unused headers
- use get_unaligned_bexx instead of own functions
- change to use a system work queue
- use probe_new instead of old probe
v1:
- first version committed to review
Marius Cristea (2):
dt-bindings: iio: adc: adding support for PAC193X
iio: adc: adding support for PAC193x
.../ABI/testing/sysfs-bus-iio-adc-pac1934 | 15 + .../bindings/iio/adc/microchip,pac1934.yaml | 137 ++ MAINTAINERS | 7 + drivers/iio/adc/Kconfig | 12 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/pac1934.c | 1673 +++++++++++++++++ 6 files changed, 1845 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-adc-pac1934 create mode 100644 Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml create mode 100644 drivers/iio/adc/pac1934.c
base-commit: 5e99f692d4e32e3250ab18d511894ca797407aec
Signature · 1 line
2.34.1
[email protected]
maintainerPATCH v3 1/2 dt-bindings: iio: adc: adding support for PAC193X
From: Marius Cristea <[email protected]>
This is the device tree schema for iio driver for Microchip PAC193X series of Power Monitors with Accumulator.
--- .../bindings/iio/adc/microchip,pac1934.yaml | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +137 -0
@@ -0,0 +1,137 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/microchip,pac1934.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip PAC1934 Power Monitors with Accumulator + +maintainers: + - Marius Cristea <[email protected]> + +description: | + This device is part of the Microchip family of Power Monitors with Accumulator. + The datasheet for PAC1931, PAC1932, PAC1933 and PAC1934 can be found here: + https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/PAC1931-Family-Data-Sheet-DS20005850E.pdf + +properties: + compatible: + enum: + - microchip,pac1931 + - microchip,pac1932 + - microchip,pac1933 + - microchip,pac1934 + + reg: + maxItems: 1 + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + + interrupts: + maxItems: 1 + + microchip,slow-io: + type: boolean + description: | + A GPIO used to trigger a change is sampling rate (lowering the chip power consumption). + If configured in SLOW mode, if this pin is forced high, sampling rate is forced to eight + samples/second. When it is forced low, the sampling rate is 1024 samples/second unless + a different sample rate has been programmed. + +patternProperties: + "^channel@[1-4]+$": + type: object + $ref: adc.yaml + description: Represents the external channels which are connected to the ADC. + + properties: + reg: + items: + minimum: 1 + maximum: 4 + + shunt-resistor-micro-ohms: + description: | + Value in micro Ohms of the shunt resistor connected between + the SENSE+ and SENSE- inputs, across which the current is measured. Value + is needed to compute the scaling of the measured current. + + required: + - reg + - shunt-resistor-micro-ohms + + unevaluatedProperties: false + +required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + +allOf: + - if: + properties: + compatible: + contains: + const: interrupts + then: + properties: + microchip,slow-io: false + else: + if: + properties: + compatible: + contains: + const: microchip,slow-io + then: + properties: + interrupts: false + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + pac193x: power-monitor@10 { + compatible = "microchip,pac1934"; + reg = <0x10>; + + #address-cells = <1>; + #size-cells = <0>; + + channel@1 { + reg = <0x1>; + shunt-resistor-micro-ohms = <24900000>; + label = "CPU"; + }; + + channel@2 { + reg = <0x2>; + shunt-resistor-micro-ohms = <49900000>; + label = "GPU"; + }; + + channel@3 { + reg = <0x3>; + shunt-resistor-micro-ohms = <75000000>; + label = "MEM"; + bipolar; + }; + + channel@4 { + reg = <0x4>; + shunt-resistor-micro-ohms = <100000000>; + label = "NET"; + bipolar; + }; + }; + }; + +...
Signature · 1 line
2.34.1
Re: [PATCH v3 1/2] dt-bindings: iio: adc: adding support for PAC193X
Quoted 47 lines · On 15/11/2023 14:44, [email protected] wrote:
From: Marius Cristea <[email protected]>
This is the device tree schema for iio driver for Microchip PAC193X series of Power Monitors with Accumulator.
Signed-off-by Marius Cristea <[email protected]>--- .../bindings/iio/adc/microchip,pac1934.yaml | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yamlDocumentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +30
-0@@ -0,0 +1,137 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/microchip,pac1934.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip PAC1934 Power Monitors with Accumulator + +maintainers: + - Marius Cristea <[email protected]> + +description: | + This device is part of the Microchip family of Power Monitors with Accumulator. + The datasheet for PAC1931, PAC1932, PAC1933 and PAC1934 can be found here: + https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/PAC1931-Family-Data-Sheet-DS20005850E.pdf + +properties: + compatible: + enum: + - microchip,pac1931 + - microchip,pac1932 + - microchip,pac1933 + - microchip,pac1934 + + reg: + maxItems: 1 + + "#address-cells": + const: 1 +
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 40
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +10
-0+ "#size-cells": + const: 0 + + interrupts: + maxItems: 1 + + microchip,slow-io: + type: boolean + description: | + A GPIO used to trigger a change is sampling rate (lowering the chip power consumption).
Use Linux coding style wrapping (as described in Linux Coding style). I am not going to tell you numbers because I want you to read the document first.
This is boolean, not GPIO. I don't understand. "A GPIO", so any GPIO or some specific? How is this property related to GPIO?
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 41
Quoted 1 line
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +1
-0+ If configured in SLOW mode, if this pin is forced high, sampling rate is forced to eight
This pin? This is boolean, not a GPIO. GPIOs are phandles.
Quoted 29 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +29
-0+ samples/second. When it is forced low, the sampling rate is 1024 samples/second unless + a different sample rate has been programmed. + +patternProperties: + "^channel@[1-4]+$": + type: object + $ref: adc.yaml + description: Represents the external channels which are connected to the ADC. + + properties: + reg: + items: + minimum: 1 + maximum: 4 + + shunt-resistor-micro-ohms: + description: | + Value in micro Ohms of the shunt resistor connected between + the SENSE+ and SENSE- inputs, across which the current is measured. Value + is needed to compute the scaling of the measured current. + + required: + - reg + - shunt-resistor-micro-ohms + + unevaluatedProperties: false + +required: + - compatible
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 80
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +10
-0+ - reg + - "#address-cells" + - "#size-cells" + +allOf: + - if: + properties: + compatible: + contains: + const: interrupts
I don't understand what do you want to say here. I am also 100% sure you did not test it on a real case (maybe example passes but nothing more).
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 92
Quoted 12 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +12
-0+ then: + properties: + microchip,slow-io: false + else: + if: + properties: + compatible: + contains: + const: microchip,slow-io + then: + properties: + interrupts: false
Best regards,
Krzysztof
Re: [PATCH v3 1/2] dt-bindings: iio: adc: adding support for PAC193X
Quoted 63 lines · Krzysztof Kozlowski
Quoted 47 lines · On 15/11/2023 14:44, [email protected] wrote:
From: Marius Cristea <[email protected]>
This is the device tree schema for iio driver for Microchip PAC193X series of Power Monitors with Accumulator.
Signed-off-by Marius Cristea <[email protected]>--- .../bindings/iio/adc/microchip,pac1934.yaml | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yamlDocumentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +30
-0@@ -0,0 +1,137 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/microchip,pac1934.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip PAC1934 Power Monitors with Accumulator + +maintainers: + - Marius Cristea <[email protected]> + +description: | + This device is part of the Microchip family of Power Monitors with Accumulator. + The datasheet for PAC1931, PAC1932, PAC1933 and PAC1934 can be found here: + https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/PAC1931-Family-Data-Sheet-DS20005850E.pdf + +properties: + compatible: + enum: + - microchip,pac1931 + - microchip,pac1932 + - microchip,pac1933 + - microchip,pac1934 + + reg: + maxItems: 1 + + "#address-cells": + const: 1 +Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 40
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +10
-0+ "#size-cells": + const: 0 + + interrupts: + maxItems: 1 + + microchip,slow-io: + type: boolean + description: | + A GPIO used to trigger a change is sampling rate (lowering the chip power consumption).Use Linux coding style wrapping (as described in Linux Coding style). I am not going to tell you numbers because I want you to read the document first.
Quoted 7 lines
This is boolean, not GPIO. I don't understand. "A GPIO", so any GPIO or some specific? How is this property related to GPIO?
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 41
Quoted 1 line
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +1
-0+ If configured in SLOW mode, if this pin is forced high, sampling rate is forced to eightThis pin? This is boolean, not a GPIO. GPIOs are phandles.
I said it on the previous version, but this really seems like it should be something like "slow-io-gpios". I know Jonathan expressed some concerns about having to deal with it on the operating system side (as the pin is either an input & used for this slow-io control, or an output and used as an interrupt) but that is, in my opinion, a problem for the operating system & the binding should describe how the hardware works, even if that is not convenient. With this sort of property, a GPIO hog would be required to be set up (and the driver for that gpio controller bound etc before the pac driver loads) for correction functionality if this property was in the non-default state.
Quoted 35 lines
Quoted 35 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +35
-0+ samples/second. When it is forced low, the sampling rate is 1024 samples/second unless + a different sample rate has been programmed. + +patternProperties: + "^channel@[1-4]+$": + type: object + $ref: adc.yaml + description: Represents the external channels which are connected to the ADC. + + properties: + reg: + items: + minimum: 1 + maximum: 4 + + shunt-resistor-micro-ohms: + description: | + Value in micro Ohms of the shunt resistor connected between + the SENSE+ and SENSE- inputs, across which the current is measured. Value + is needed to compute the scaling of the measured current. + + required: + - reg + - shunt-resistor-micro-ohms + + unevaluatedProperties: false + +required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + +allOf: + - if:
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 80
Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +4
-0+ properties: + compatible: + contains: + const: interruptsI don't understand what do you want to say here. I am also 100% sure you did not test it on a real case (maybe example passes but nothing more).
As far as I understand, the same pin on the device is used for both an output or an input depending on the configuration. As an input, it is the "slow-io" control, and as an output it is an interrupt. I think Marius is trying to convey that either this pin can be in exclusively one state or another.
_However_ I am not sure that that is really the right thing to do - they might well be mutually exclusive modes, but I think the decision can be made at runtime, rather than at devicetree creation time. Say for example the GPIO controller this is connected to is capable of acting as an interrupt controller. Unless I am misunderstanding the runtime configurability of this hardware, I think it is possible to actually provide a "slow-io-gpios" and an interrupt property & let the operating system decide at runtime which mode it wants to work in.
I'm off travelling at the moment Marius, but I should be back in work on Monday if you want to have a chat about it & explain a bit more to me?
Cheers,
Conor.
Quoted 17 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 92
Quoted 13 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +12
-0+ then: + properties: + microchip,slow-io: false + else: + if: + properties: + compatible: + contains: + const: microchip,slow-io + then: + properties: + interrupts: falseBest regards,
Krzysztof
Re: [PATCH v3 1/2] dt-bindings: iio: adc: adding support for PAC193X
Quoted 26 lines · Conor Dooley
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 80
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +6
-0+allOf: + - if: + properties: + compatible: + contains: + const: interruptsI don't understand what do you want to say here. I am also 100% sure you did not test it on a real case (maybe example passes but nothing more).
As far as I understand, the same pin on the device is used for both an output or an input depending on the configuration. As an input, it is the "slow-io" control, and as an output it is an interrupt. I think Marius is trying to convey that either this pin can be in exclusively one state or another.
_However_ I am not sure that that is really the right thing to do - they might well be mutually exclusive modes, but I think the decision can be made at runtime, rather than at devicetree creation time. Say for example the GPIO controller this is connected to is capable of acting as an interrupt controller. Unless I am misunderstanding the runtime configurability of this hardware, I think it is possible to actually provide a "slow-io-gpios" and an interrupt property & let the operating system decide at runtime which mode it wants to work in.
Quoted 2 lines
I'm off travelling at the moment Marius, but I should be back in work on Monday if you want to have a chat about it & explain a bit more to me?
Sure, but which compatible contains "interrupts"?
Best regards,
Krzysztof
Re: [PATCH v3 1/2] dt-bindings: iio: adc: adding support for PAC193X
Quoted 28 lines · Krzysztof Kozlowski
Quoted 26 lines · Conor Dooley
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 80
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +6
-0+allOf: + - if: + properties: + compatible: + contains: + const: interruptsI don't understand what do you want to say here. I am also 100% sure you did not test it on a real case (maybe example passes but nothing more).
As far as I understand, the same pin on the device is used for both an output or an input depending on the configuration. As an input, it is the "slow-io" control, and as an output it is an interrupt. I think Marius is trying to convey that either this pin can be in exclusively one state or another.
_However_ I am not sure that that is really the right thing to do - they might well be mutually exclusive modes, but I think the decision can be made at runtime, rather than at devicetree creation time. Say for example the GPIO controller this is connected to is capable of acting as an interrupt controller. Unless I am misunderstanding the runtime configurability of this hardware, I think it is possible to actually provide a "slow-io-gpios" and an interrupt property & let the operating system decide at runtime which mode it wants to work in.
Quoted 4 lines
Quoted 2 lines
I'm off travelling at the moment Marius, but I should be back in work on Monday if you want to have a chat about it & explain a bit more to me?
Sure, but which compatible contains "interrupts"?
Yeah, I did notice that - I figured you understood that that was meant to not be a check on compatibles, but rather on regular old properties & the rationale for the mutual exclusion was what you were missing.
Jonathan Cameron
maintainerRe: [PATCH v3 1/2] dt-bindings: iio: adc: adding support for PAC193X
In reply to Conor DooleyQuoted 72 lines · On Thu, 16 Nov 2023 18:21:33 +0000 Conor Dooley <[email protected]> wrote:
Quoted 63 lines · Krzysztof Kozlowski
Quoted 47 lines · On 15/11/2023 14:44, [email protected] wrote:
From: Marius Cristea <[email protected]>
This is the device tree schema for iio driver for Microchip PAC193X series of Power Monitors with Accumulator.
Signed-off-by Marius Cristea <[email protected]>--- .../bindings/iio/adc/microchip,pac1934.yaml | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yamlDocumentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +30
-0@@ -0,0 +1,137 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/microchip,pac1934.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip PAC1934 Power Monitors with Accumulator + +maintainers: + - Marius Cristea <[email protected]> + +description: | + This device is part of the Microchip family of Power Monitors with Accumulator. + The datasheet for PAC1931, PAC1932, PAC1933 and PAC1934 can be found here: + https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/PAC1931-Family-Data-Sheet-DS20005850E.pdf + +properties: + compatible: + enum: + - microchip,pac1931 + - microchip,pac1932 + - microchip,pac1933 + - microchip,pac1934 + + reg: + maxItems: 1 + + "#address-cells": + const: 1 +Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 40
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +10
-0+ "#size-cells": + const: 0 + + interrupts: + maxItems: 1 + + microchip,slow-io: + type: boolean + description: | + A GPIO used to trigger a change is sampling rate (lowering the chip power consumption).Use Linux coding style wrapping (as described in Linux Coding style). I am not going to tell you numbers because I want you to read the document first.
Quoted 7 lines
This is boolean, not GPIO. I don't understand. "A GPIO", so any GPIO or some specific? How is this property related to GPIO?
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 41
Quoted 1 line
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +1
-0+ If configured in SLOW mode, if this pin is forced high, sampling rate is forced to eightThis pin? This is boolean, not a GPIO. GPIOs are phandles.
Quoted 10 lines
I said it on the previous version, but this really seems like it should be something like "slow-io-gpios". I know Jonathan expressed some concerns about having to deal with it on the operating system side (as the pin is either an input & used for this slow-io control, or an output and used as an interrupt) but that is, in my opinion, a problem for the operating system & the binding should describe how the hardware works, even if that is not convenient. With this sort of property, a GPIO hog would be required to be set up (and the driver for that gpio controller bound etc before the pac driver loads) for correction functionality if this property was in the non-default state.
I'd forgotten the discussion completely ;)
My main question was why bother with slow? You can do it without the GPIO anyway as there is a register bit for it.
I can conceive of various possible reasons, the evil one being that it's actually out of the host processors control. Is that what we care about here? If so it's nothing to do with a GPIO in the Linux sense at all and we can assume that it's not connected to an interrupt at the same time.
We 'might' need a control for that case that says configure the device for an external entity to use the slow pin.
It wouldn't be the first device to have that sort of thing, but normally they are sequencing pins that are wired up to some mechanical device or similar.
Quoted 51 lines
Quoted 36 lines
Quoted 36 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +35
-0+ samples/second. When it is forced low, the sampling rate is 1024 samples/second unless + a different sample rate has been programmed. + +patternProperties: + "^channel@[1-4]+$": + type: object + $ref: adc.yaml + description: Represents the external channels which are connected to the ADC. + + properties: + reg: + items: + minimum: 1 + maximum: 4 + + shunt-resistor-micro-ohms: + description: | + Value in micro Ohms of the shunt resistor connected between + the SENSE+ and SENSE- inputs, across which the current is measured. Value + is needed to compute the scaling of the measured current. + + required: + - reg + - shunt-resistor-micro-ohms + + unevaluatedProperties: false + +required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + +allOf: + - if:Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 80
Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +4
-0+ properties: + compatible: + contains: + const: interruptsI don't understand what do you want to say here. I am also 100% sure you did not test it on a real case (maybe example passes but nothing more).
As far as I understand, the same pin on the device is used for both an output or an input depending on the configuration. As an input, it is the "slow-io" control, and as an output it is an interrupt. I think Marius is trying to convey that either this pin can be in exclusively one state or another.
Quoted 8 lines
_However_ I am not sure that that is really the right thing to do - they might well be mutually exclusive modes, but I think the decision can be made at runtime, rather than at devicetree creation time. Say for example the GPIO controller this is connected to is capable of acting as an interrupt controller. Unless I am misunderstanding the runtime configurability of this hardware, I think it is possible to actually provide a "slow-io-gpios" and an interrupt property & let the operating system decide at runtime which mode it wants to work in.
I'll admit I've long forgotten what was going on here, but based just on this bit of text I agree. There is nothing 'stopping' us having a pin uses as either / or / both interrupt and gpio.
It'll be a bit messy to support in the driver as IIRC there are some sanity checks that limit combinations on IRQs and output GPIOS. Can't remember how bad the dance to navigate it safely is.
First version I'd just say pick one option if both are provided and don't support configuring it at runtime.
Jonathan
Quoted 24 lines
I'm off travelling at the moment Marius, but I should be back in work on Monday if you want to have a chat about it & explain a bit more to me?
Cheers,
Conor.Quoted 17 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 92
Quoted 13 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +12
-0+ then: + properties: + microchip,slow-io: false + else: + if: + properties: + compatible: + contains: + const: microchip,slow-io + then: + properties: + interrupts: falseBest regards,
Krzysztof
Re: [PATCH v3 1/2] dt-bindings: iio: adc: adding support for PAC193X
Quoted 66 lines · Jonathan Cameron
Quoted 51 lines · On Thu, 16 Nov 2023 18:21:33 +0000 Conor Dooley <[email protected]> wrote:
Quoted 35 lines · Krzysztof Kozlowski
Quoted 34 lines · On 15/11/2023 14:44, [email protected] wrote:
From: Marius Cristea <[email protected]>
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +32
-0+patternProperties: + "^channel@[1-4]+$": + type: object + $ref: adc.yaml + description: Represents the external channels which are connected to the ADC. + + properties: + reg: + items: + minimum: 1 + maximum: 4 + + shunt-resistor-micro-ohms: + description: | + Value in micro Ohms of the shunt resistor connected between + the SENSE+ and SENSE- inputs, across which the current is measured. Value + is needed to compute the scaling of the measured current. + + required: + - reg + - shunt-resistor-micro-ohms + + unevaluatedProperties: false + +required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + +allOf: + - if:Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 80
Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +4
-0+ properties: + compatible: + contains: + const: interruptsI don't understand what do you want to say here. I am also 100% sure you did not test it on a real case (maybe example passes but nothing more).
As far as I understand, the same pin on the device is used for both an output or an input depending on the configuration. As an input, it is the "slow-io" control, and as an output it is an interrupt. I think Marius is trying to convey that either this pin can be in exclusively one state or another.
Quoted 8 lines
_However_ I am not sure that that is really the right thing to do - they might well be mutually exclusive modes, but I think the decision can be made at runtime, rather than at devicetree creation time. Say for example the GPIO controller this is connected to is capable of acting as an interrupt controller. Unless I am misunderstanding the runtime configurability of this hardware, I think it is possible to actually provide a "slow-io-gpios" and an interrupt property & let the operating system decide at runtime which mode it wants to work in.
I'll admit I've long forgotten what was going on here, but based just on this bit of text I agree. There is nothing 'stopping' us having a pin uses as either / or / both interrupt and gpio.
Quoted 6 lines
It'll be a bit messy to support in the driver as IIRC there are some sanity checks that limit combinations on IRQs and output GPIOS. Can't remember how bad the dance to navigate it safely is.
First version I'd just say pick one option if both are provided and don't support configuring it at runtime.
Just to be clear, you are suggesting having the "microchip,slow-io-gpios" and "interrupts" properties in the binding, but the driver will just (for example) put that pin into alert mode always & leave it there?
If that is what you are suggesting, that seems pragmatic to me.
Cheers,
Conor.
Jonathan Cameron
maintainerRe: [PATCH v3 1/2] dt-bindings: iio: adc: adding support for PAC193X
Quoted 71 lines · On Sun, 26 Nov 2023 11:24:56 +0000 Conor Dooley <[email protected]> wrote:
Quoted 70 lines · Jonathan Cameron
Quoted 51 lines · On Thu, 16 Nov 2023 18:21:33 +0000 Conor Dooley <[email protected]> wrote:
Quoted 35 lines · Krzysztof Kozlowski
Quoted 34 lines · On 15/11/2023 14:44, [email protected] wrote:
From: Marius Cristea <[email protected]>
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +32
-0+patternProperties: + "^channel@[1-4]+$": + type: object + $ref: adc.yaml + description: Represents the external channels which are connected to the ADC. + + properties: + reg: + items: + minimum: 1 + maximum: 4 + + shunt-resistor-micro-ohms: + description: | + Value in micro Ohms of the shunt resistor connected between + the SENSE+ and SENSE- inputs, across which the current is measured. Value + is needed to compute the scaling of the measured current. + + required: + - reg + - shunt-resistor-micro-ohms + + unevaluatedProperties: false + +required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + +allOf: + - if:Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 80
Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +4
-0+ properties: + compatible: + contains: + const: interruptsI don't understand what do you want to say here. I am also 100% sure you did not test it on a real case (maybe example passes but nothing more).
As far as I understand, the same pin on the device is used for both an output or an input depending on the configuration. As an input, it is the "slow-io" control, and as an output it is an interrupt. I think Marius is trying to convey that either this pin can be in exclusively one state or another.
Quoted 8 lines
_However_ I am not sure that that is really the right thing to do - they might well be mutually exclusive modes, but I think the decision can be made at runtime, rather than at devicetree creation time. Say for example the GPIO controller this is connected to is capable of acting as an interrupt controller. Unless I am misunderstanding the runtime configurability of this hardware, I think it is possible to actually provide a "slow-io-gpios" and an interrupt property & let the operating system decide at runtime which mode it wants to work in.
I'll admit I've long forgotten what was going on here, but based just on this bit of text I agree. There is nothing 'stopping' us having a pin uses as either / or / both interrupt and gpio.
It'll be a bit messy to support in the driver as IIRC there are some sanity checks that limit combinations on IRQs and output GPIOS. Can't remember how bad the dance to navigate it safely is.
Quoted 7 lines
Quoted 2 lines
First version I'd just say pick one option if both are provided and don't support configuring it at runtime.
Just to be clear, you are suggesting having the "microchip,slow-io-gpios" and "interrupts" properties in the binding, but the driver will just (for example) put that pin into alert mode always & leave it there?
Yes.
Quoted 1 line
If that is what you are suggesting, that seems pragmatic to me.
If a use case to do something else comes along later, then we can be smarter, but I'd like to keep it simple initially at least.
Jonathan
Quoted 4 lines
Cheers,
Conor.
Re: [PATCH v3 1/2] dt-bindings: iio: adc: adding support for PAC193X
Quoted 80 lines · Jonathan Cameron
Quoted 70 lines · On Sun, 26 Nov 2023 11:24:56 +0000 Conor Dooley <[email protected]> wrote:
Quoted 69 lines · Jonathan Cameron
Quoted 50 lines · On Thu, 16 Nov 2023 18:21:33 +0000 Conor Dooley <[email protected]> wrote:
Quoted 34 lines · Krzysztof Kozlowski
Quoted 33 lines · On 15/11/2023 14:44, [email protected] wrote:
From: Marius Cristea <[email protected]>
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +32
-0+patternProperties: + "^channel@[1-4]+$": + type: object + $ref: adc.yaml + description: Represents the external channels which are connected to the ADC. + + properties: + reg: + items: + minimum: 1 + maximum: 4 + + shunt-resistor-micro-ohms: + description: | + Value in micro Ohms of the shunt resistor connected between + the SENSE+ and SENSE- inputs, across which the current is measured. Value + is needed to compute the scaling of the measured current. + + required: + - reg + - shunt-resistor-micro-ohms + + unevaluatedProperties: false + +required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + +allOf: + - if:Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml line 80
Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml new file +4
-0+ properties: + compatible: + contains: + const: interruptsI don't understand what do you want to say here. I am also 100% sure you did not test it on a real case (maybe example passes but nothing more).
As far as I understand, the same pin on the device is used for both an output or an input depending on the configuration. As an input, it is the "slow-io" control, and as an output it is an interrupt. I think Marius is trying to convey that either this pin can be in exclusively one state or another.
Quoted 8 lines
_However_ I am not sure that that is really the right thing to do - they might well be mutually exclusive modes, but I think the decision can be made at runtime, rather than at devicetree creation time. Say for example the GPIO controller this is connected to is capable of acting as an interrupt controller. Unless I am misunderstanding the runtime configurability of this hardware, I think it is possible to actually provide a "slow-io-gpios" and an interrupt property & let the operating system decide at runtime which mode it wants to work in.
I'll admit I've long forgotten what was going on here, but based just on this bit of text I agree. There is nothing 'stopping' us having a pin uses as either / or / both interrupt and gpio.
It'll be a bit messy to support in the driver as IIRC there are some sanity checks that limit combinations on IRQs and output GPIOS. Can't remember how bad the dance to navigate it safely is.
Quoted 7 lines
Quoted 2 lines
First version I'd just say pick one option if both are provided and don't support configuring it at runtime.
Just to be clear, you are suggesting having the "microchip,slow-io-gpios" and "interrupts" properties in the binding, but the driver will just (for example) put that pin into alert mode always & leave it there?
Quoted 6 lines
Yes.
Quoted 1 line
If that is what you are suggesting, that seems pragmatic to me.
If a use case to do something else comes along later, then we can be smarter, but I'd like to keep it simple initially at least.
Sounds good to me, thanks Jonathan. Seems like a good compromise of depicting the hardware accurately and not overcomplicating the driver implementation.
Marius, I completely forgot to get in touch with you about this - give me a shout on teams if there's anything outstanding that I can help you with.
[email protected]
maintainerPATCH v3 2/2 iio: adc: adding support for PAC193x
In reply to [email protected]From: Marius Cristea <[email protected]>
This is the iio driver for Microchip
PAC193X series of Power Monitor with Accumulator chip family.
--- .../ABI/testing/sysfs-bus-iio-adc-pac1934 | 15 + MAINTAINERS | 7 + drivers/iio/adc/Kconfig | 12 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/pac1934.c | 1673 +++++++++++++++++ 5 files changed, 1708 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-adc-pac1934 create mode 100644 drivers/iio/adc/pac1934.c
Documentation/ABI/testing/sysfs-bus-iio-adc-pac1934 new file +15 -0
@@ -0,0 +1,15 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_shunt_resistor_X +KernelVersion: 6.7 +Contact: [email protected] +Description: + The value of the shunt resistor may be known only at runtime and set + by a client application. This attribute allows to set its value + in micro-ohms. X is the IIO index of the device. The value is + used to calculate current, power and accumulated energy. + +What: /sys/bus/iio/devices/iio:deviceX/reset_accumulators +KernelVersion: 6.7 +Contact: [email protected] +Description: + Writing any value resets the accumulated power device's statistics + for all enabled channels.
MAINTAINERS +7 -0
@@ -14054,6 +14054,13 @@ F: Documentation/devicetree/bindings/nvmem/microchip,sama7g5-otpc.yaml F: drivers/nvmem/microchip-otpc.c F: include/dt-bindings/nvmem/microchip,sama7g5-otpc.h +MICROCHIP PAC1934 POWER/ENERGY MONITOR DRIVER +M: Marius Cristea <[email protected]> +L: [email protected] +S: Supported +F: Documentation/devicetree/bindings/iio/adc/microchip,pac1934.yaml +F: drivers/iio/adc/pac1934.c + MICROCHIP PCI1XXXX GP DRIVER M: Vaibhaav Ram T.L <[email protected]> M: Kumaravel Thiagarajan <[email protected]>
drivers/iio/adc/Kconfig +12 -0
@@ -903,6 +903,18 @@ config NPCM_ADC This driver can also be built as a module. If so, the module will be called npcm_adc. +config PAC1934 + tristate "Microchip Technology PAC1934 driver" + depends on I2C + depends on IIO + help + Say yes here to build support for Microchip Technology's PAC1931, + PAC1932, PAC1933, PAC1934 Single/Multi-Channel Power Monitor with + Accumulator. + + This driver can also be built as a module. If so, the module + will be called pac1934. + config PALMAS_GPADC tristate "TI Palmas General Purpose ADC" depends on MFD_PALMAS
drivers/iio/adc/Makefile +1 -0
@@ -83,6 +83,7 @@ obj-$(CONFIG_MP2629_ADC) += mp2629_adc.o obj-$(CONFIG_MXS_LRADC_ADC) += mxs-lradc-adc.o obj-$(CONFIG_NAU7802) += nau7802.o obj-$(CONFIG_NPCM_ADC) += npcm_adc.o +obj-$(CONFIG_PAC1934) += pac1934.o obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o obj-$(CONFIG_QCOM_SPMI_ADC5) += qcom-spmi-adc5.o obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o
drivers/iio/adc/pac1934.c new file +1673 -0
1,673 lines not on this page · raw message
Signature · 1 line
2.34.1
kernel test robot
build botRe: [PATCH v3 2/2] iio: adc: adding support for PAC193x
kernel test robot noticed the following build warnings:
Hi,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 5e99f692d4e32e3250ab18d511894ca797407aec]
url: https://github.com/intel-lab-lkp/linux/commits/marius-cristea-microchip-com/dt-bindings-iio-adc-adding-support-for-PAC193X/20231115-214733 base: 5e99f692d4e32e3250ab18d511894ca797407aec patch link: https://lore.kernel.org/r/20231115134453.6656-3-marius.cristea%40microchip.com patch subject: [PATCH v3 2/2] iio: adc: adding support for PAC193x config: arm64-allyesconfig (https://download.01.org/0day-ci/archive/20231121/[email protected]/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231121/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/iio/adc/pac1934.c:1239:3: warning: variable 'cnt' is incremented both in the loop header and in the loop body [-Wfor-loop-analysis]
1239 | cnt++;
| ^
drivers/iio/adc/pac1934.c:1236:44: note: incremented here
1236 | for (cnt = 0; cnt < info->phys_channels; cnt++) {
| ^1 warning generated.
vim +/cnt +1239 drivers/iio/adc/pac1934.c
1226
1227 static int pac1934_chip_configure(struct pac1934_chip_info *info)
1228 {
1229 int cnt, ret;
1230 struct i2c_client *client = info->client;
1231 u8 regs[PAC1934_CTRL_STATUS_INFO_LEN], idx, ctrl_reg;
1232 u32 wait_time;
1233
1234 cnt = 0;
1235 info->chip_reg_data.num_enabled_channels = 0;
1236 for (cnt = 0; cnt < info->phys_channels; cnt++) {
1237 if (info->active_channels[cnt])
1238 info->chip_reg_data.num_enabled_channels++;
> 1239 cnt++;
1240 }
1241
1242 /*
1243 * read whatever information was gathered before the driver was loaded
1244 * establish which channels are enabled/disabled and then establish the
1245 * information retrieval mode (using SKIP or no).
1246 * Read the chip ID values
1247 */
1248 ret = i2c_smbus_read_i2c_block_data(client, PAC1934_CTRL_STAT_REGS_ADDR,
1249 sizeof(regs),
1250 (u8 *)regs);
1251 if (ret < 0) {
1252 dev_err_probe(&client->dev, ret,
1253 "%s - cannot read regs from 0x%02X\n",
1254 __func__, PAC1934_CTRL_STAT_REGS_ADDR);
1255 return ret;
1256 }
1257
1258 /* write the CHANNEL_DIS and the NEG_PWR registers */
1259 regs[PAC1934_CHANNEL_DIS_REG_OFF] =
1260 FIELD_PREP(PAC1934_CHAN_DIS_CH1_OFF_MASK, !(info->active_channels[PAC1934_CH_1])) |
1261 FIELD_PREP(PAC1934_CHAN_DIS_CH2_OFF_MASK, !(info->active_channels[PAC1934_CH_2])) |
1262 FIELD_PREP(PAC1934_CHAN_DIS_CH3_OFF_MASK, !(info->active_channels[PAC1934_CH_3])) |
1263 FIELD_PREP(PAC1934_CHAN_DIS_CH4_OFF_MASK, !(info->active_channels[PAC1934_CH_4])) |
1264 FIELD_PREP(PAC1934_SMBUS_TIMEOUT_MASK, 0) |
1265 FIELD_PREP(PAC1934_SMBUS_BYTECOUNT_MASK, 0) |
1266 FIELD_PREP(PAC1934_SMBUS_NO_SKIP_MASK, 0);
1267
1268 regs[PAC1934_NEG_PWR_REG_OFF] =
1269 FIELD_PREP(PAC1934_NEG_PWR_CH1_BIDI_MASK, info->bi_dir[PAC1934_CH_1]) |
1270 FIELD_PREP(PAC1934_NEG_PWR_CH2_BIDI_MASK, info->bi_dir[PAC1934_CH_2]) |
1271 FIELD_PREP(PAC1934_NEG_PWR_CH3_BIDI_MASK, info->bi_dir[PAC1934_CH_3]) |
1272 FIELD_PREP(PAC1934_NEG_PWR_CH4_BIDI_MASK, info->bi_dir[PAC1934_CH_4]) |
1273 FIELD_PREP(PAC1934_NEG_PWR_CH1_BIDV_MASK, info->bi_dir[PAC1934_CH_1]) |
1274 FIELD_PREP(PAC1934_NEG_PWR_CH2_BIDV_MASK, info->bi_dir[PAC1934_CH_2]) |
1275 FIELD_PREP(PAC1934_NEG_PWR_CH3_BIDV_MASK, info->bi_dir[PAC1934_CH_3]) | 1276 FIELD_PREP(PAC1934_NEG_PWR_CH4_BIDV_MASK, info->bi_dir[PAC1934_CH_4]);
1277
1278 /* no SLOW triggered REFRESH, clear POR */
1279 regs[PAC1934_SLOW_REG_OFF] = 0;
1280
1281 ret = i2c_smbus_write_block_data(client, PAC1934_CTRL_STAT_REGS_ADDR, 3, (u8 *)regs);
1282 if (ret)
1283 return ret;
1284
1285 ctrl_reg = FIELD_PREP(PAC1934_CRTL_SAMPLE_RATE_MASK, info->crt_samp_spd_bitfield);
1286
1287 ret = i2c_smbus_write_byte_data(client, PAC1934_CTRL_REG_ADDR, ctrl_reg);
1288 if (ret)
1289 return ret;
1290
1291 /*
1292 * send a REFRESH to the chip, so the new settings take place
1293 * as well as resetting the accumulators
1294 */
1295 ret = i2c_smbus_write_byte(client, PAC1934_REFRESH_REG_ADDR);
1296 if (ret) {
1297 dev_err(&client->dev,
1298 "%s - cannot send 0x%02X\n",
1299 __func__, PAC1934_REFRESH_REG_ADDR);
1300 return ret;
1301 }
1302
1303 /*
1304 * get the current(in the chip) sampling speed and compute the
1305 * required timeout based on its value
1306 * the timeout is 1/sampling_speed
1307 */
1308 idx = regs[PAC1934_CTRL_ACT_REG_OFF] >> PAC1934_SAMPLE_RATE_SHIFT;
1309 wait_time = (1024 / samp_rate_map_tbl[idx]) * 1000;
1310
1311 /*
1312 * wait the maximum amount of time to be on the safe side
1313 * the maximum wait time is for 8sps
1314 */
1315 usleep_range(wait_time, wait_time + 100);
1316
1317 INIT_DELAYED_WORK(&info->work_chip_rfsh, pac1934_work_periodic_rfsh);
1318 /* Setup the latest moment for reading the regs before saturation */
1319 schedule_delayed_work(&info->work_chip_rfsh,
1320 msecs_to_jiffies(PAC1934_MAX_RFSH_LIMIT_MS));
1321
1322 devm_add_action_or_reset(&client->dev, pac1934_cancel_delayed_work,
1323 &info->work_chip_rfsh);
1324
1325 return 0;
1326 }
1327
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Jonathan Cameron
maintainerRe: [PATCH v3 2/2] iio: adc: adding support for PAC193x
In reply to [email protected]Quoted 22 lines · On Wed, 15 Nov 2023 15:44:53 +0200 <[email protected]> wrote:
From: Marius Cristea <[email protected]>
This is the iio driver for Microchip
PAC193X series of Power Monitor with Accumulator chip family.Signed-off-by Marius Cristea <[email protected]>--- .../ABI/testing/sysfs-bus-iio-adc-pac1934 | 15 + MAINTAINERS | 7 + drivers/iio/adc/Kconfig | 12 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/pac1934.c | 1673 +++++++++++++++++ 5 files changed, 1708 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-adc-pac1934 create mode 100644 drivers/iio/adc/pac1934.cDocumentation/ABI/testing/sysfs-bus-iio-adc-pac1934 new file +0
-0
Documentation/ABI/testing/sysfs-bus-iio-adc-pac1934 line 8
Quoted 8 lines
Documentation/ABI/testing/sysfs-bus-iio-adc-pac1934 new file +8
-0@@ -0,0 +1,15 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_shunt_resistor_X +KernelVersion: 6.7 +Contact: [email protected] +Description: + The value of the shunt resistor may be known only at runtime and set + by a client application. This attribute allows to set its value + in micro-ohms. X is the IIO index of the device. The value is + used to calculate current, power and accumulated energy.
Why the device being in the directory name and the shunt resistor name?
If you drop that, we need to move this abi to a more generic file because we can't have duplicate entries in the ABI directory. sysfs-bus-iio-power-mon or similar would do then remove the entries elsewhere.
Or does it mean channel index? In which case don't use X.
I'd love to make shunt resistor a DT problem... I guess that's a non starter because of potential calibrations etc?
Documentation/ABI/testing/sysfs-bus-iio-adc-pac1934 line 15
Quoted 7 lines
Documentation/ABI/testing/sysfs-bus-iio-adc-pac1934 new file +7
-0+ +What: /sys/bus/iio/devices/iio:deviceX/reset_accumulators +KernelVersion: 6.7 +Contact: [email protected] +Description: + Writing any value resets the accumulated power device's statistics + for all enabled channels.
Hmm. We have used channel enables for this before. Might be better to map to that though it's a bit inelegant to have a write of 1 to in_powerY_enable reset a bunch of other channels.
I'm not sure if we have an precedent that aligns perfectly with this. Closest is step counters were we do use enable, but then the reset only covers one clearly defined channel.
Having in_enable seems a bit odd as I assume some channels don't involve accumulation...
drivers/iio/adc/pac1934.c line 58
Quoted 13 lines
drivers/iio/adc/pac1934.c new file +6
-0@@ -0,0 +1,1673 @@ + +#define PAC1934_MAX_NUM_CHANNELS 4 +#define PAC1934_CH_1 0 +#define PAC1934_CH_2 1 +#define PAC1934_CH_3 2 +#define PAC1934_CH_4 3
The channel 1 extra naming doesn't actually seem relevant anywhere inside the driver other than maybe making relationship to datasheet clear. You might as well use the 0,1,23 values directly I think.
Quoted 1 line
+#define
PAC1934_MEAS_REG_LEN76
Can you compute these from register addresses and sizes? If so that will be self documenting and make it clear these are correct.
drivers/iio/adc/pac1934.c line 191
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +8
-0+#define PAC1934_CTRL_REG_LEN 12 + + +#define PAC1934_DEV_ATTR (name) (&iio_dev_attr_##name.dev_attr.attr) +/* +* Universal Unique Identifier (UUID), +* 033771E0-1705-47B4-9535-D1BBE14D9A09, is +* reserved to Microchip for the PAC1934 and must not be changed
No need to say it must not be changed. We can't change register addresses either and this is similar to those.
Quoted 3 lines
+ */
drivers/iio/adc/pac1934.c new file +2
-0+#define PAC1934_DSM_UUID "033771E0-1705-47B4-9535-D1BBE14D9A09" +
...
Quoted 6 lines
drivers/iio/adc/pac1934.c new file +6
-0+/** +* struct reg_data - data from the registers +* @meas_regs: snapshot of raw measurements registers +* @ctrl_regs: snapshot of control registers +* @energy_sec_acc: snapshot of energy values +* @vpower_acc: accumulated vpower values
drivers/iio/adc/pac1934.c line 279
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +10
-0+* @vpower: snapshot of vpower registers +* @vbus: snapshot of vbus registers +* @vbus_avg: averages of vbus registers +* @vsense: snapshot of vsense registers +* @vsense_avg: averages of vsense registers +* @num_enabled_channels: count of how many chip channels are currently enabled +*/ +struct reg_data { +u8 meas_regs[PAC1934_MEAS_REG_LEN ]; +u8 ctrl_regs[PAC1934_CTRL_REG_LEN ];
I guess the weird block read stuff where it skips addresses prevents using regmap and regcache to avoid hand spinning caching?
Quoted 32 lines
drivers/iio/adc/pac1934.c new file +32
-0+s64 energy_sec_acc[PAC1934_MAX_NUM_CHANNELS ]; +s64 vpower_acc[PAC1934_MAX_NUM_CHANNELS ]; +s32 vpower[PAC1934_MAX_NUM_CHANNELS ]; +s32 vbus[PAC1934_MAX_NUM_CHANNELS ]; +s32 vbus_avg[PAC1934_MAX_NUM_CHANNELS ]; +s32 vsense[PAC1934_MAX_NUM_CHANNELS ]; +s32 vsense_avg[PAC1934_MAX_NUM_CHANNELS ]; +u8 num_enabled_channels; +}; + +/** +* struct pac1934_chip_info - information about the chip +* @client: the i2c-client attached to the device +* @lock: synchronize access to driver's state members +* @work_chip_rfsh: work queue used for refresh commands +* @phys_channels: phys channels count +* @active_channels: array of values, true means that channel is active +* @bi_dir: array of bools, true means that channel is bidirectional +* @chip_variant: chip variant +* @chip_revision: chip revision +* @shunts: shunts +* @chip_reg_data: chip reg data +* @sample_rate_value: sampling frequency +* @labels: table with channels labels +* @pac1934_info: pac1934_info +* @crt_samp_spd_bitfield: the current sampling speed +* @jiffies_tstamp: chip's uptime +*/ +struct pac1934_chip_info { +struct i2c_client *client; +struct mutex lock;/* synchronize access to driver's state members */ +struct delayed_work work_chip_rfsh;
drivers/iio/adc/pac1934.c line 321
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +10
-0+u8 phys_channels; +bool active_channels[PAC1934_MAX_NUM_CHANNELS ]; +bool bi_dir[PAC1934_MAX_NUM_CHANNELS ]; +u8 chip_variant; +u8 chip_revision; +u32 shunts[PAC1934_MAX_NUM_CHANNELS ]; +struct reg_data chip_reg_data; +s32 sample_rate_value; +char *labels[PAC1934_MAX_NUM_CHANNELS ]; +struct iio_info pac1934_info;
I'd call it iio_info, or just info as the pac1934 bit is obvious from context.
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +10
-0+u8 crt_samp_spd_bitfield; +unsigned long jiffies_tstamp; +}; + +#define TO_PAC1934_CHIP_INFO (d) container_of(d, struct pac1934_chip_info, work_chip_rfsh) + +#define PAC1934_VPOWER_ACC_CHANNEL (_index, _si, _address) { \ + .type = IIO_ENERGY, \ + .address = (_address), \ + .indexed = 1, \
drivers/iio/adc/pac1934.c line 341
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +10
-0+ .channel = (_index), \ + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_dir = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .scan_index = (_si), \ + .scan_type = { \ + .sign = 'u', \ + .realbits = 48, \ + .storagebits = 48, \
IIO elements are always in naturally aligned power of 2. So that needs to be 64 bits. Standard userspace tooling expects this so we can't change it.
So needs to be
.storagebits = 64
You may have to repack data to meet this requirement. It's annoying but one of the costs we pay for a simple ABI.
I'd not add this stuff until you add the buffer support though. For now it's just noise.
Quoted 4 lines
drivers/iio/adc/pac1934.c new file +3
-0+ .endianness = IIO_CPU, \ + } \ +}
drivers/iio/adc/pac1934.c line 453
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +9
-0+ +/* Low-level I2c functions used to transfer up to 76 bytes at once */ +static int pac1934_i2c_read (struct i2c_client *client,u8 reg_addr,void *databuf,u8 len) +{ +int ret; +struct i2c_msg msgs[2 ] = { + { .addr = client->addr, + .len =1 , + .buf = (u8 *)®_addr,
odd indent.
{
.addr = client->addr,
.len = 1,
.buf
}, {
.addr = ..drivers/iio/adc/pac1934.c line 457
Quoted 4 lines
drivers/iio/adc/pac1934.c new file +4
-0+ }, + { .addr = client->addr, + .len = len, + .buf = databuf,
can you use i2c_smbus_read_i2c_block_data() here?
I'm rubbish at remembering all the smbus variants, so it might not fit, but it's close to this. You used it elsewhere so maybe this one got missed?
Quoted 8 lines
drivers/iio/adc/pac1934.c new file +8
-0+ .flags = I2C_M_RD + } + }; + + ret =i2c_transfer (client->adapter, msgs,ARRAY_SIZE (msgs)); +if (ret <0 ) +return ret; +
drivers/iio/adc/pac1934.c line 489
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +9
-0+return 0 ; +} + +static ssize_t shunt_value_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct iio_dev *indio_dev =dev_to_iio_dev (dev); +struct pac1934_chip_info *info =iio_priv (indio_dev); +int len =0 ; +int target = (int )(attr->attr.name[strlen (attr->attr.name) -1 ] -'0' ) -1 ;
There is an address field in the IIO_DEVICE_ATTR(). Use that (bit of container of magic to get to it)
drivers/iio/adc/pac1934.c line 493
Quoted 4 lines
drivers/iio/adc/pac1934.c new file +4
-0+ + len +=sprintf (buf,"%u\n" , info->shunts[target]); + +return len;
return sysfs_emit()
drivers/iio/adc/pac1934.c line 504
Quoted 11 lines
drivers/iio/adc/pac1934.c new file +11
-0+} + +static ssize_t shunt_value_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct iio_dev *indio_dev =dev_to_iio_dev (dev); +struct pac1934_chip_info *info =iio_priv (indio_dev); +int sh_val, target; + + target = (int )(attr->attr.name[strlen (attr->attr.name) -1 ] -'0' ) -1 ;
Again, address in the attribute for this. Not messy string mangling.
Quoted 11 lines
drivers/iio/adc/pac1934.c new file +11
-0+if (kstrtouint (buf,10 , &sh_val)) { +dev_err (dev,"Shunt value is not valid\n" ); +return -EINVAL ; + } + +scoped_guard (mutex, &info->lock) + info->shunts[target] = sh_val; + +return count; +} +
...
Quoted 9 lines
drivers/iio/adc/pac1934.c new file +9
-0+ +static int pac1934_send_refresh (struct pac1934_chip_info *info, +u8 refresh_cmd,u32 wait_time) +{ +/* this function only sends REFRESH or REFRESH_V */ +struct i2c_client *client = info->client; +int ret; +u8 bidir_reg; +bool revision_bug = false;
drivers/iio/adc/pac1934.c line 548
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +10
-0+ +if (info->chip_revision ==2 || info->chip_revision ==3 ) { +/* +* chip rev 2 and 3 bug workaround +* see: PAC1934 Family Data Sheet Errata DS80000836A.pdf +*/ + revision_bug = true; + + bidir_reg = + FIELD_PREP(PAC1934_NEG_PWR_CH1_BIDI_MASK, info->bi_dir[PAC1934_CH_1]) |
as mentioned above, just use [0], [1], [2], [3] as the CH_1 mapping doesn't make anything much clearer.
Quoted 8 lines
drivers/iio/adc/pac1934.c new file +8
-0+FIELD_PREP (PAC1934_NEG_PWR_CH2_BIDI_MASK , info->bi_dir[PAC1934_CH_2 ]) | +FIELD_PREP (PAC1934_NEG_PWR_CH3_BIDI_MASK , info->bi_dir[PAC1934_CH_3 ]) | +FIELD_PREP (PAC1934_NEG_PWR_CH4_BIDI_MASK , info->bi_dir[PAC1934_CH_4 ]) | +FIELD_PREP (PAC1934_NEG_PWR_CH1_BIDV_MASK , info->bi_dir[PAC1934_CH_1 ]) | +FIELD_PREP (PAC1934_NEG_PWR_CH2_BIDV_MASK , info->bi_dir[PAC1934_CH_2 ]) | +FIELD_PREP (PAC1934_NEG_PWR_CH3_BIDV_MASK , info->bi_dir[PAC1934_CH_3 ]) | +FIELD_PREP (PAC1934_NEG_PWR_CH4_BIDV_MASK , info->bi_dir[PAC1934_CH_4 ]); +
...
Quoted 15 lines
drivers/iio/adc/pac1934.c new file +14
-0+return ret; +} + +static int pac1934_retrieve_data (struct pac1934_chip_info *info, +u32 wait_time) +{ +int ret =0 ; + +/* +* check if the minimal elapsed time has passed and if so, +* re-read the chip, otherwise the cached info is just fine +*/ +if (time_after (jiffies, info->jiffies_tstamp + +msecs_to_jiffies (PAC1934_MIN_POLLING_TIME_MS ))) {
drivers/iio/adc/pac1934.c line 777
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +10
-0+ ret =pac1934_reg_snapshot (info, true,PAC1934_REFRESH_REG_ADDR , + wait_time); + +/* +* Re-schedule the work for the read registers on timeout +* (to prevent chip regs saturation) +*/ +cancel_delayed_work_sync (&info->work_chip_rfsh); +schedule_delayed_work (&info->work_chip_rfsh, +msecs_to_jiffies (PAC1934_MAX_RFSH_LIMIT_MS ));
Doesn't mod_delayed_work() cover this pair more cheaply?
Or is there are race I'm missing? I think it's safe for this usecase.
Quoted 28 lines
drivers/iio/adc/pac1934.c new file +28
-0+ } + +return ret; +} + +static int pac1934_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int *val, +int *val2,long mask) +{ +struct pac1934_chip_info *info =iio_priv (indio_dev); +s64 curr_energy; +int ret, channel = chan->channel -1 ; + + ret =pac1934_retrieve_data (info,PAC1934_MIN_UPDATE_WAIT_TIME_US ); +if (ret <0 ) +return ret; + +switch (mask) { +case IIO_CHAN_INFO_RAW : +switch (chan->type) { +case IIO_VOLTAGE : + *val = info->chip_reg_data.vbus[channel]; +return IIO_VAL_INT ; +case IIO_CURRENT : + *val = info->chip_reg_data.vsense[channel]; +return IIO_VAL_INT ; +case IIO_POWER : + *val = info->chip_reg_data.vpower[channel];
drivers/iio/adc/pac1934.c line 815
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +10
-0+return IIO_VAL_INT ; +case IIO_ENERGY : + curr_energy = info->chip_reg_data.energy_sec_acc[channel]; + *val = (u32 )curr_energy; + *val2 = (u32)(curr_energy >>32 ); +return IIO_VAL_INT_64 ; +default : +return -EINVAL ; + } +break ;
Not sure these break; at end of case can be reached.
Quoted 80 lines
drivers/iio/adc/pac1934.c new file +80
-0+case IIO_CHAN_INFO_AVERAGE_RAW : +switch (chan->type) { +case IIO_VOLTAGE : + *val = info->chip_reg_data.vbus_avg[channel]; +return IIO_VAL_INT ; +case IIO_CURRENT : + *val = info->chip_reg_data.vsense_avg[channel]; +return IIO_VAL_INT ; +default : +return -EINVAL ; + } +break ; +case IIO_CHAN_INFO_SCALE : +switch (chan->address) { +/* Voltages - scale for millivolts */ +case PAC1934_VBUS_1_ADDR : +case PAC1934_VBUS_2_ADDR : +case PAC1934_VBUS_3_ADDR : +case PAC1934_VBUS_4_ADDR : +case PAC1934_VBUS_AVG_1_ADDR : +case PAC1934_VBUS_AVG_2_ADDR : +case PAC1934_VBUS_AVG_3_ADDR : +case PAC1934_VBUS_AVG_4_ADDR : + *val =PAC1934_VOLTAGE_MILLIVOLTS_MAX ; +if (chan->scan_type.sign =='u' ) + *val2 =PAC1934_VOLTAGE_U_RES ; +else + *val2 =PAC1934_VOLTAGE_S_RES ; +return IIO_VAL_FRACTIONAL_LOG2 ; +/* +* Currents - scale for mA - depends on the +* channel's shunt value +* (100mV * 1000000) / (2^16 * shunt(uohm)) +*/ +case PAC1934_VSENSE_1_ADDR : +case PAC1934_VSENSE_2_ADDR : +case PAC1934_VSENSE_3_ADDR : +case PAC1934_VSENSE_4_ADDR : +case PAC1934_VSENSE_AVG_1_ADDR : +case PAC1934_VSENSE_AVG_2_ADDR : +case PAC1934_VSENSE_AVG_3_ADDR : +case PAC1934_VSENSE_AVG_4_ADDR : + *val =PAC1934_MAX_VSENSE_RSHIFTED_BY_16B ; +if (chan->scan_type.sign =='u' ) + *val2 = info->shunts[channel]; +else + *val2 = info->shunts[channel] >>1 ; +return IIO_VAL_FRACTIONAL ; +/* +* Power - uW - it will use the combined scale +* for current and voltage +* current(mA) * voltage(mV) = power (uW) +*/ +case PAC1934_VPOWER_1_ADDR : +case PAC1934_VPOWER_2_ADDR : +case PAC1934_VPOWER_3_ADDR : +case PAC1934_VPOWER_4_ADDR : + *val =PAC1934_MAX_VPOWER_RSHIFTED_BY_28B ; +if (chan->scan_type.sign =='u' ) + *val2 = info->shunts[channel]; +else + *val2 = info->shunts[channel] >>1 ; +return IIO_VAL_FRACTIONAL ; +case PAC1934_VPOWER_ACC_1_ADDR : +case PAC1934_VPOWER_ACC_2_ADDR : +case PAC1934_VPOWER_ACC_3_ADDR : +case PAC1934_VPOWER_ACC_4_ADDR : +/* +* expresses the 32 bit scale value +* here compute the scale for energy (miliWatt-second or miliJoule) +*/ + *val =PAC1934_SCALE_CONSTANT ; + +if (chan->scan_type.sign =='u' ) + *val2 = info->shunts[channel]; +else + *val2 = info->shunts[channel] >>1 ; +return IIO_VAL_FRACTIONAL ; +default : +return -EINVAL ;
drivers/iio/adc/pac1934.c line 905
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +10
-0+ } +break ; +case IIO_CHAN_INFO_SAMP_FREQ : + *val = info->sample_rate_value; +return IIO_VAL_INT ; +default : +return -EINVAL ; + } + +return -EINVAL ;
Shouldn't be able to get here.
Quoted 29 lines
drivers/iio/adc/pac1934.c new file +28
-0+} + +static bool pac1934_acpi_parse_channel_config (struct i2c_client *client, +struct pac1934_chip_info *info) +{ +acpi_handle handle; +union acpi_object *rez; +struct device *dev = &client->dev; +unsigned short bi_dir_mask; +int idx, i; +guid_t guid; +const struct acpi_device_id *id; + + handle =ACPI_HANDLE (&client->dev); + + id =acpi_match_device (dev->driver->acpi_match_table, dev); +if (!id) +return false; + +guid_parse (PAC1934_DSM_UUID , &guid); + + rez =acpi_evaluate_dsm (handle, &guid,0 ,PAC1934_ACPI_GET_NAMES_AND_MOHMS_VALS ,NULL ); +if (!rez) +return false; + +for (i =0 ; i < rez->package.count; i +=2 ) { + idx = i /2 ; + info->labels[idx] =
drivers/iio/adc/pac1934.c line 1115
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +10
-0+devm_kmemdup (&client->dev, rez->package.elements[i].string.pointer, + (size_t )rez->package.elements[i].string.length +1 , +GFP_KERNEL ); + info->labels[idx][rez->package.elements[i].string.length] ='\0' ; + info->shunts[idx] = + rez->package.elements[i +1 ].integer.value *1000 ; + info->active_channels[idx] = (info->shunts[idx] !=0 ); + } + +kfree (rez);
ACPI_FREE()? I think it's preferred as there is some ACPI tracking code for allocations that might be enabled.
...
drivers/iio/adc/pac1934.c line 1234
Quoted 12 lines
drivers/iio/adc/pac1934.c new file +11
-0+return true; +} + +static int pac1934_chip_configure (struct pac1934_chip_info *info) +{ +int cnt, ret; +struct i2c_client *client = info->client; +u8 regs[PAC1934_CTRL_STATUS_INFO_LEN ], idx, ctrl_reg; +u32 wait_time; + + cnt =0 ;
No need.
drivers/iio/adc/pac1934.c line 1239
Quoted 5 lines
drivers/iio/adc/pac1934.c new file +5
-0+ info->chip_reg_data.num_enabled_channels =0 ; +for (cnt =0 ; cnt < info->phys_channels; cnt++) { +if (info->active_channels[cnt]) + info->chip_reg_data.num_enabled_channels++; + cnt++;
? 0-day spotted this one.
Quoted 1 line
drivers/iio/adc/pac1934.c new file +1
-0+ }
...
drivers/iio/adc/pac1934.c line 1449
Quoted 2 lines
drivers/iio/adc/pac1934.c new file +2
-0+static IIO_DEVICE_ATTR(in_shunt_resistor_1, 0644, shunt_value_show, shunt_value_store, 0); +static IIO_DEVICE_ATTR(in_shunt_resistor_2, 0644, shunt_value_show, shunt_value_store, 0);
Put address as index.
Quoted 16 lines
drivers/iio/adc/pac1934.c new file +16
-0+static IIO_DEVICE_ATTR(in_shunt_resistor_3, 0644, shunt_value_show, shunt_value_store, 0); +static IIO_DEVICE_ATTR(in_shunt_resistor_4, 0644, shunt_value_show, shunt_value_store, 0); +static IIO_DEVICE_ATTR(reset_accumulators, 0200, NULL, reset_accumulators_store, 0); + +static struct attribute *pac1934_all_attributes[] = { +PAC1934_DEV_ATTR (in_shunt_resistor_1), +PAC1934_DEV_ATTR (in_shunt_resistor_2), +PAC1934_DEV_ATTR (in_shunt_resistor_3), +PAC1934_DEV_ATTR (in_shunt_resistor_4), +PAC1934_DEV_ATTR (reset_accumulators), +NULL +}; + +static int pac1934_prep_custom_attributes (struct pac1934_chip_info *info, +struct iio_dev *indio_dev) +{
drivers/iio/adc/pac1934.c line 1475
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +10
-0+int i, j, active_channels_count =0 ; +struct attribute **pac1934_custom_attributes; +struct attribute_group *pac1934_group; +struct i2c_client *client = info->client; + +for (i =0 ; i < info->phys_channels; i++) +if (info->active_channels[i]) + active_channels_count++; + + pac1934_group =devm_kzalloc (&client->dev,sizeof (*pac1934_group),GFP_KERNEL );
Can fail
drivers/iio/adc/pac1934.c line 1482
Quoted 7 lines
drivers/iio/adc/pac1934.c new file +7
-0+ + pac1934_custom_attributes =devm_kzalloc (&client->dev, + (PAC1934_CUSTOM_ATTR_FOR_CHANNEL * + active_channels_count + +PAC1934_SHARED_DEVATTRS_COUNT ) + *sizeof (*pac1934_group) +1 , +GFP_KERNEL );
as can this (in theory anyway and we should always handle that)
drivers/iio/adc/pac1934.c line 1488
Quoted 6 lines
drivers/iio/adc/pac1934.c new file +6
-0+ j =0 ; + +for (i =0 ; i < info->phys_channels; i++) { +if (info->active_channels[i]) { + pac1934_custom_attributes[PAC1934_CUSTOM_ATTR_FOR_CHANNEL * j] = + pac1934_all_attributes[PAC1934_CUSTOM_ATTR_FOR_CHANNEL * i];
Indent the second line one more table as this is very hard to read.
I'm not sure copying it from that table is worth doing. I'd just build the table here from the attributes.
Quoted 32 lines
drivers/iio/adc/pac1934.c new file +31
-0+ pac1934_custom_attributes[PAC1934_CUSTOM_ATTR_FOR_CHANNEL * j +1 ] = + pac1934_all_attributes[PAC1934_CUSTOM_ATTR_FOR_CHANNEL * i +1 ]; + j++; + } + } + +for (i =0 ; i <PAC1934_SHARED_DEVATTRS_COUNT ; i++) + pac1934_custom_attributes[PAC1934_CUSTOM_ATTR_FOR_CHANNEL * + active_channels_count + i] = + pac1934_all_attributes[PAC1934_CUSTOM_ATTR_FOR_CHANNEL * + info->phys_channels + i]; + + pac1934_group->attrs = pac1934_custom_attributes; + info->pac1934_info.attrs = pac1934_group; + +return 0 ; +} +static int pac1934_probe (struct i2c_client *client) +{ +struct pac1934_chip_info *info; +const struct pac1934_features *chip; +struct iio_dev *indio_dev; +int cnt, ret; +bool match = false; + + indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*info)); +if (!indio_dev) +return -ENOMEM ; + + info =iio_priv (indio_dev); +
drivers/iio/adc/pac1934.c line 1537
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +10
-0+i2c_set_clientdata (client, indio_dev); + info->client = client; + +/* +* load default settings - all channels disabled, +* uni directional flow +*/ +for (cnt =0 ; cnt <PAC1934_MAX_NUM_CHANNELS ; cnt++) { + info->active_channels[cnt] = false; + info->bi_dir[cnt] = false;
info is zero initialized. Could just not bother setting this as they are already 0. If you think it's useful documentation fine to leave it. Hopefully the compiler will elide it anyway.
Quoted 2 lines
drivers/iio/adc/pac1934.c new file +2
-0+ } +
...
drivers/iio/adc/pac1934.c line 1626
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +10
-0+} + +static const struct i2c_device_id pac1934_id[] = { + { .name ="pac1931" , .driver_data = (kernel_ulong_t)&pac1934_chip_config[PAC1931 ] }, + { .name ="pac1932" , .driver_data = (kernel_ulong_t)&pac1934_chip_config[PAC1932 ] }, + { .name ="pac1933" , .driver_data = (kernel_ulong_t)&pac1934_chip_config[PAC1933 ] }, + { .name ="pac1934" , .driver_data = (kernel_ulong_t)&pac1934_chip_config[PAC1934 ] }, + {} +}; +
No blank line here.
Quoted 14 lines
drivers/iio/adc/pac1934.c new file +14
-0+MODULE_DEVICE_TABLE (i2c, pac1934_id); + +static const struct of_device_id pac1934_of_match[] = { + { + .compatible ="microchip,pac1931" , + .data = &pac1934_chip_config[PAC1931 ] + }, + { + .compatible ="microchip,pac1932" , + .data = &pac1934_chip_config[PAC1932 ] + }, + { + .compatible ="microchip,pac1933" , + .data = &pac1934_chip_config[PAC1933 ]
drivers/iio/adc/pac1934.c line 1650
Quoted 10 lines
drivers/iio/adc/pac1934.c new file +10
-0+ }, + { + .compatible = "microchip,pac1934", + .data = &pac1934_chip_config[PAC1934] + }, + {} +}; +MODULE_DEVICE_TABLE (of, pac1934_of_match); + +/* using MCHP1930 to be compatible with WINDOWS ACPI */
Presumably BIOS rather than windows, but I guess the point is clear :)
Guenter Roeck
maintainerQuoted 12 lines · On Wed, Nov 15, 2023 at 03:44:51PM +0200, [email protected] wrote:
From: Marius Cristea <[email protected]>
Adding support for Microchip PAC193X series of Power Monitor with Accumulator chip family. This driver covers the following part numbers:
- PAC1931, PAC1932, PAC1933 and PAC1934This device is at the boundary between IIO and HWMON (if you are
looking just at the "shunt resistors, vsense, power, energy"). The device also has ADC internally that can measure voltages (up to 4 channels) and also currents (up to 4 channels). The current is measured as voltage across theshunt_resistor.
Quoted 6 lines
I have started with a simple driver (this one that is more appropriate to be a
HWMON) and willing to add more functionality later (like data buffering that is quite important for example if someone wants to profile power consumption of the processor itself, or a peripheral device, or a battery, this kind of functionality was requested by our customers).
I sdon't immediately see any typical hwmon properties such as limit registers or alarms. The hwmon subsystem also doesn't support data buffering. Given that, the iio implementation seems more appropriate to me. Anyone using the chip for hardware monitoring can use the iio->hwmon bridge.
Thanks,
Guenter