LTC4286 and LTC4287 driver support
Subsystems (5)
Delphine CC Chiu
maintainerv4 cover LTC4286 and LTC4287 driver support
v4 - Add LTC4286 and LTC4287 binding document
- Add LTC4286 and LTC4287 driver
Delphine CC Chiu (2):
dt-bindings: hwmon: Add lltc ltc4286 driver bindings
hwmon: pmbus: Add ltc4286 driver
.../bindings/hwmon/lltc,ltc4286.yaml | 51 +++++ Documentation/hwmon/index.rst | 1 + Documentation/hwmon/ltc4286.rst | 95 ++++++++++ MAINTAINERS | 10 + drivers/hwmon/pmbus/Kconfig | 10 + drivers/hwmon/pmbus/Makefile | 1 + drivers/hwmon/pmbus/ltc4286.c | 177 ++++++++++++++++++ 7 files changed, 345 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/lltc,ltc4286.yaml create mode 100644 Documentation/hwmon/ltc4286.rst create mode 100644 drivers/hwmon/pmbus/ltc4286.c
Signature · 1 line
2.25.1
Delphine CC Chiu
maintainerPATCH v4 1/2 dt-bindings: hwmon: Add lltc ltc4286 driver bindings
Add a device tree bindings for ltc4286 device.
Changelog:
v4 - Revise some inappropriate writing in yaml file v3 - Revise adi,vrange-select-25p6 to adi,vrange-low-enable v2 - Revise vrange_select_25p6 to adi,vrange-select-25p6
- Add type for adi,vrange-select-25p6
- Revise rsense-micro-ohms to shunt-resistor-micro-ohms
--- .../bindings/hwmon/lltc,ltc4286.yaml | 51 +++++++++++++++++++ MAINTAINERS | 10 ++++ 2 files changed, 61 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/lltc,ltc4286.yaml
Documentation/devicetree/bindings/hwmon/lltc,ltc4286.yaml new file +51 -0
@@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/lltc,ltc4286.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LTC4286 power monitors + +maintainers: + - Delphine CC Chiu <[email protected]> + +properties: + compatible: + enum: + - lltc,ltc4286 + - lltc,ltc4287 + + reg: + maxItems: 1 + + adi,vrange-low-enable: + description: + This property is a bool parameter to represent the + voltage range is 25.6 volts or 102.4 volts for this chip. + The default is 102.4 volts. + type: boolean + + shunt-resistor-micro-ohms: + description: + Resistor value micro-ohms. + +required: + - compatible + - reg + - shunt-resistor-micro-ohms + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + power-monitor@40 { + compatible = "lltc,ltc4286"; + reg = <0x40>; + adi,vrange-low-enable; + shunt-resistor-micro-ohms = <300>; + }; + };
MAINTAINERS +10 -0
@@ -12609,6 +12609,16 @@ S: Maintained F: Documentation/hwmon/ltc4261.rst F: drivers/hwmon/ltc4261.c +LTC4286 HARDWARE MONITOR DRIVER +M: Delphine CC Chiu <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/hwmon/lltc,ltc4286.yaml +F: Documentation/devicetree/bindings/hwmon/ltc4286.rst +F: drivers/hwmon/pmbus/Kconfig +F: drivers/hwmon/pmbus/Makefile +F: drivers/hwmon/pmbus/ltc4286.c + LTC4306 I2C MULTIPLEXER DRIVER M: Michael Hennerich <[email protected]> L: [email protected]
Signature · 1 line
2.25.1
Re: [PATCH v4 1/2] dt-bindings: hwmon: Add lltc ltc4286 driver bindings
Quoted 10 lines · Delphine CC Chiu
Add a device tree bindings for ltc4286 device.
Signed-off-by Delphine CC Chiu <[email protected]>Changelog:
v4 - Revise some inappropriate writing in yaml file v3 - Revise adi,vrange-select-25p6 to adi,vrange-low-enable v2 - Revisevrange_select_25p6to adi,vrange-select-25p6
- Add type for adi,vrange-select-25p6
- Revise rsense-micro-ohms to shunt-resistor-micro-ohms
Your changelog should be below the --- line. You also omitted the tag I left on the previous version. With the changelog fixed:
Cheers,
Conor.
Quoted 88 lines
--- .../bindings/hwmon/lltc,ltc4286.yaml | 51 +++++++++++++++++++ MAINTAINERS | 10 ++++ 2 files changed, 61 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/lltc,ltc4286.yamlDocumentation/devicetree/bindings/hwmon/lltc,ltc4286.yaml new file +51
-0@@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/lltc,ltc4286.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LTC4286 power monitors + +maintainers: + - Delphine CC Chiu <[email protected]> + +properties: + compatible: + enum: + - lltc,ltc4286 + - lltc,ltc4287 + + reg: + maxItems: 1 + + adi,vrange-low-enable: + description: + This property is a bool parameter to represent the + voltage range is 25.6 volts or 102.4 volts for this chip. + The default is 102.4 volts. + type: boolean + + shunt-resistor-micro-ohms: + description: + Resistor value micro-ohms. + +required: + - compatible + - reg + - shunt-resistor-micro-ohms + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + power-monitor@40 { + compatible = "lltc,ltc4286"; + reg = <0x40>; + adi,vrange-low-enable; + shunt-resistor-micro-ohms = <300>; + }; + };MAINTAINERS +10
-0@@ -12609,6 +12609,16 @@ S: Maintained F: Documentation/hwmon/ltc4261.rst F: drivers/hwmon/ltc4261.c +LTC4286 HARDWARE MONITOR DRIVER +M: Delphine CC Chiu <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/hwmon/lltc,ltc4286.yaml +F: Documentation/devicetree/bindings/hwmon/ltc4286.rst +F: drivers/hwmon/pmbus/Kconfig +F: drivers/hwmon/pmbus/Makefile +F: drivers/hwmon/pmbus/ltc4286.c + LTC4306 I2C MULTIPLEXER DRIVER M: Michael Hennerich <[email protected]> L: [email protected]Signature · 1 line
2.25.1
Delphine_CC_Chiu/WYHQ/Wiwynn
maintainerRE: [PATCH v4 1/2] dt-bindings: hwmon: Add lltc ltc4286 driver bindings
Quoted 18 lines
-----Original Message-----
From: Conor Dooley <[email protected]>
Sent: Friday, November 10, 2023 1:10 AM
To: Delphine_CC_Chiu/WYHQ/Wiwynn <[email protected]>
Cc: [email protected]; Jean Delvare <[email protected]>; Guenter Roeck <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 1/2] dt-bindings: hwmon: Add lltc ltc4286 driver bindingsQuoted 4 lines · Delphine CC Chiu
Add a device tree bindings for ltc4286 device.
Signed-off-by Delphine CC Chiu <[email protected]>
Quoted 8 lines
Quoted 6 lines
Changelog:
v4 - Revise some inappropriate writing in yaml file v3 - Revise adi,vrange-select-25p6 to adi,vrange-low-enable v2 - Revisevrange_select_25p6to adi,vrange-select-25p6
- Add type for adi,vrange-select-25p6
- Revise rsense-micro-ohms to shunt-resistor-micro-ohmsYour changelog should be below the --- line.
We will add --- line on our changelog.
Quoted 1 line
You also omitted the tag I left on the previous version.
Could you point out the exact places that we omit? Thanks.
Quoted 96 lines
With the changelog fixed:
Reviewed-by Conor Dooley <[email protected]>Cheers,
Conor.Quoted 2 lines
--- .../bindings/hwmon/lltc,ltc4286.yaml | 51+++++++++++++++++++
Quoted 87 lines
MAINTAINERS | 10 ++++ 2 files changed, 61 insertions(+) create mode 100644
Documentation/devicetree/bindings/hwmon/lltc,ltc4286.yamlDocumentation/devicetree/bindings/hwmon/lltc,ltc4286.yaml new file +50
-0@@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) %YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/lltc,ltc4286.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LTC4286 power monitors + +maintainers: + - Delphine CC Chiu <[email protected]> + +properties: + compatible: + enum: + - lltc,ltc4286 + - lltc,ltc4287 + + reg: + maxItems: 1 + + adi,vrange-low-enable: + description: + This property is a bool parameter to represent the + voltage range is 25.6 volts or 102.4 volts for this chip. + The default is 102.4 volts. + type: boolean + + shunt-resistor-micro-ohms: + description: + Resistor value micro-ohms. + +required: + - compatible + - reg + - shunt-resistor-micro-ohms + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + power-monitor@40 { + compatible = "lltc,ltc4286"; + reg = <0x40>; + adi,vrange-low-enable; + shunt-resistor-micro-ohms = <300>; + }; + };MAINTAINERS index renamed from MAINTAINERS +0
-0
0b275b8d6bd2..5d439cd64ecb100644MAINTAINERS +10
-1@@ -12609,6 +12609,16 @@ S: Maintained F: Documentation/hwmon/ltc4261.rst F: drivers/hwmon/ltc4261.c +LTC4286 HARDWARE MONITOR DRIVER +M: Delphine CC Chiu <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/hwmon/lltc,ltc4286.yaml +F: Documentation/devicetree/bindings/hwmon/ltc4286.rst +F: drivers/hwmon/pmbus/Kconfig +F: drivers/hwmon/pmbus/Makefile +F: drivers/hwmon/pmbus/ltc4286.c + LTC4306 I2C MULTIPLEXER DRIVER M: Michael Hennerich <[email protected]> L: [email protected] --2.25.1
Re: [PATCH v4 1/2] dt-bindings: hwmon: Add lltc ltc4286 driver bindings
Quoted 25 lines · Delphine_CC_Chiu/WYHQ/Wiwynn
Quoted 25 lines
-----Original Message-----
From: Conor Dooley <[email protected]>
Sent: Friday, November 10, 2023 1:10 AM
To: Delphine_CC_Chiu/WYHQ/Wiwynn <[email protected]>
Cc: [email protected]; Jean Delvare <[email protected]>; Guenter Roeck <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 1/2] dt-bindings: hwmon: Add lltc ltc4286 driver bindingsQuoted 10 lines · Delphine CC Chiu
Add a device tree bindings for ltc4286 device.
Signed-off-by Delphine CC Chiu <[email protected]>Changelog:
v4 - Revise some inappropriate writing in yaml file v3 - Revise adi,vrange-select-25p6 to adi,vrange-low-enable v2 - Revisevrange_select_25p6to adi,vrange-select-25p6
- Add type for adi,vrange-select-25p6
- Revise rsense-micro-ohms to shunt-resistor-micro-ohms
Quoted 7 lines
Quoted 1 line
Your changelog should be below the --- line.
We will add --- line on our changelog.
Quoted 1 line
You also omitted the tag I left on the previous version.
Could you point out the exact places that we omit?
Open the previous email and read it fully. Did you or did you not get a tag?
Quoted 4 lines
Thanks.
Quoted 2 lines
With the changelog fixed:
Reviewed-by Conor Dooley <[email protected]>
Best regards,
Krzysztof
Delphine_CC_Chiu/WYHQ/Wiwynn
maintainerRE: [PATCH v4 1/2] dt-bindings: hwmon: Add lltc ltc4286 driver bindings
Quoted 47 lines
-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Wednesday, November 15, 2023 8:18 PM
To: Delphine_CC_Chiu/WYHQ/Wiwynn <[email protected]>; Conor Dooley <[email protected]>
Cc: [email protected]; Jean Delvare <[email protected]>; Guenter Roeck <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 1/2] dt-bindings: hwmon: Add lltc ltc4286 driver bindingsSecurity Reminder: Please be aware that this email is sent by an external
sender.Quoted 4 lines · Delphine_CC_Chiu/WYHQ/Wiwynn
Quoted 4 lines
-----Original Message-----
From: Conor Dooley <[email protected]>
Sent: Friday, November 10, 2023 1:10 AM
To: Delphine_CC_Chiu/WYHQ/WiwynnQuoted 24 lines
Quoted 23 lines
Cc: [email protected]; Jean Delvare <[email protected]>; Guenter Roeck <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 1/2] dt-bindings: hwmon: Add lltc ltc4286 driver bindingsQuoted 10 lines · Delphine CC Chiu
Add a device tree bindings for ltc4286 device.
Signed-off-by Delphine CC Chiu <[email protected]>Changelog:
v4 - Revise some inappropriate writing in yaml file v3 - Revise adi,vrange-select-25p6 to adi,vrange-low-enable v2 - Revisevrange_select_25p6to adi,vrange-select-25p6
- Add type for adi,vrange-select-25p6
- Revise rsense-micro-ohms to shunt-resistor-micro-ohmsYour changelog should be below the --- line.
Quoted 7 lines
Quoted 5 lines
We will add --- line on our changelog.
Quoted 1 line
You also omitted the tag I left on the previous version.
Could you point out the exact places that we omit?
Open the previous email and read it fully. Did you or did you not get a tag?
We realize the meaning of tag after survey.
We will add tag in commit message.
Thanks.
Quoted 7 lines
Quoted 5 lines
Thanks.
Quoted 2 lines
With the changelog fixed:
Reviewed-by Conor Dooley <[email protected]>Best regards,
Krzysztof
Delphine CC Chiu
maintainerPATCH v4 2/2 hwmon: pmbus: Add ltc4286 driver
In reply to Delphine CC ChiuAdd a driver to support ltc4286 chip
Changelog:
v4 - Add empty line before "config SENSORS_LTC4286" in Kconfig
- Add ltc4286 to Documentation/hwmon/index.rst
- Revise comment typo
- Use devm_kmemdup instead of memcpy
- Check MBR value before writting into
v3 - Use dev_err_probe() instead of dev_err()
- The VRANGE_SELECT bit only be written if it actually changed
- Avoid the info pointer being overwritten
- Check the MBR value range to avoid overflow
- Revise ltc4286.rst to corrcet description
v2 - Revise Linear Technologies LTC4286 to
Analog Devices LTC4286 in Kconfig
- Add more description for this driver in Kconfig
- Add some comments for MBR setting in ltc4286.c
- Add ltc4286.rst
--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/ltc4286.rst | 95 +++++++++++++++++ drivers/hwmon/pmbus/Kconfig | 10 ++ drivers/hwmon/pmbus/Makefile | 1 + drivers/hwmon/pmbus/ltc4286.c | 177 ++++++++++++++++++++++++++++++++ 5 files changed, 284 insertions(+) create mode 100644 Documentation/hwmon/ltc4286.rst create mode 100644 drivers/hwmon/pmbus/ltc4286.c
Documentation/hwmon/index.rst +1 -0
@@ -128,6 +128,7 @@ Hardware Monitoring Kernel Drivers ltc4245 ltc4260 ltc4261 + ltc4286 max127 max15301 max16064
Documentation/hwmon/ltc4286.rst new file +95 -0
95 lines not on this page · raw message
drivers/hwmon/pmbus/Kconfig +10 -0
@@ -227,6 +227,16 @@ config SENSORS_LTC3815 This driver can also be built as a module. If so, the module will be called ltc3815. +config SENSORS_LTC4286 + bool "Analog Devices LTC4286" + help + LTC4286 is an integrated solution for hot swap applications that + allows a board to be safely inserted and removed from a live + backplane. + This chip could be used to monitor voltage, current, ...etc. + If you say yes here you get hardware monitoring support for Analog + Devices LTC4286. + config SENSORS_MAX15301 tristate "Maxim MAX15301" help
drivers/hwmon/pmbus/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_SENSORS_LM25066) += lm25066.o obj-$(CONFIG_SENSORS_LT7182S) += lt7182s.o obj-$(CONFIG_SENSORS_LTC2978) += ltc2978.o obj-$(CONFIG_SENSORS_LTC3815) += ltc3815.o +obj-$(CONFIG_SENSORS_LTC4286) += ltc4286.o obj-$(CONFIG_SENSORS_MAX15301) += max15301.o obj-$(CONFIG_SENSORS_MAX16064) += max16064.o obj-$(CONFIG_SENSORS_MAX16601) += max16601.o
drivers/hwmon/pmbus/ltc4286.c new file +177 -0
177 lines not on this page · raw message
Signature · 1 line
2.25.1
Guenter Roeck
maintainerRe: [PATCH v4 2/2] hwmon: pmbus: Add ltc4286 driver
Quoted 235 lines · Delphine CC Chiu
Add a driver to support ltc4286 chip
Signed-off-by Delphine CC Chiu <[email protected]>Changelog:
v4 - Add empty line before "configSENSORS_LTC4286" inKconfig
- Add ltc4286 toDocumentation/hwmon/index.rst
- Revise comment typo
- Usedevm_kmemdupinstead of memcpy
- Check MBR value before writting into
v3 - Usedev_err_probe()instead ofdev_err()
- TheVRANGE_SELECTbit only be written if it actually changed
- Avoid the info pointer being overwritten
- Check the MBR value range to avoid overflow
- Reviseltc4286.rstto corrcet description
v2 - Revise Linear Technologies LTC4286 to
Analog Devices LTC4286 inKconfig
- Add more description for this driver inKconfig
- Add some comments for MBR setting inltc4286.c
- Addltc4286.rst--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/ltc4286.rst | 95 +++++++++++++++++ drivers/hwmon/pmbus/Kconfig | 10 ++ drivers/hwmon/pmbus/Makefile | 1 + drivers/hwmon/pmbus/ltc4286.c | 177 ++++++++++++++++++++++++++++++++ 5 files changed, 284 insertions(+)create mode 100644
Documentation/hwmon/ltc4286.rstcreate mode 100644drivers/hwmon/pmbus/ltc4286.cDocumentation/hwmon/index.rst +1
-0@@ -128,6 +128,7 @@ Hardware Monitoring Kernel Drivers ltc4245 ltc4260 ltc4261 + ltc4286 max127 max15301 max16064Documentation/hwmon/ltc4286.rst new file +95
-0@@ -0,0 +1,95 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver ltc4286 +===================== + +Supported chips: + + * Analog Devices LTC4286 + + Prefix: 'ltc4286' + + Addresses scanned: - + + Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ltc4286.pdf + + * Analog Devices LTC4287 + + Prefix: 'ltc4287' + + Addresses scanned: - + + Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ltc4287.pdf + +Author: Delphine CC Chiu <[email protected]> + + +Description +----------- + +This driver supports hardware monitoring for Analog Devices LTC4286 +and LTC4287 Hot-Swap Controller and Digital Power Monitors. + +LTC4286 and LTC4287 are hot-swap controllers that allow a circuit board +to be removed from or inserted into a live backplane. They also feature +current and voltage readback via an integrated 12 bit analog-to-digital +converter (ADC), accessed using a PMBus interface. + +The driver is a client driver to the core PMBus driver. Please see +Documentation/hwmon/pmbus.rst for details on PMBus client drivers. + + +Usage Notes +----------- + +This driver does not auto-detect devices. You will have to instantiate the +devices explicitly. Please see Documentation/i2c/instantiating-devices.rst for +details. + +The shunt value in micro-ohms can be set via device tree at compile-time. Please +refer to the Documentation/devicetree/bindings/hwmon/lltc,ltc4286.yaml for bindings +if the device tree is used. + + +Platform data support +--------------------- + +The driver supports standard PMBus driver platform data. Please see +Documentation/hwmon/pmbus.rst for details. + + +Sysfs entries +------------- + +The following attributes are supported. Limits are read-write, history reset +attributes are write-only, all other attributes are read-only. + +======================= ======================================================= +in1_label "vin" +in1_input Measured voltage. +in1_alarm Input voltage alarm. +in1_min Minimum input voltage. +in1_max Maximum input voltage. + +in2_label "vout1" +in2_input Measured voltage. +in2_alarm Output voltage alarm. +in2_min Minimum output voltage. +in2_max Maximum output voltage. + +curr1_label "iout1" +curr1_input Measured current. +curr1_alarm Output current alarm. +curr1_max Maximum current. + +power1_label "pin" +power1_input Input power. +power1_alarm Input power alarm. +power1_max Maximum poewr. + +temp1_input Chip temperature. +temp1_min Minimum chip temperature. +temp1_max Maximum chip temperature. +temp1_crit Critical chip temperature. +temp1_alarm Chip temperature alarm. +======================= =======================================================drivers/hwmon/pmbus/Kconfig +10
-0@@ -227,6 +227,16 @@ config SENSORS_LTC3815 This driver can also be built as a module. If so, the module will be called ltc3815. +config SENSORS_LTC4286 + bool "Analog Devices LTC4286" + help + LTC4286 is an integrated solution for hot swap applications that + allows a board to be safely inserted and removed from a live + backplane. + This chip could be used to monitor voltage, current, ...etc. + If you say yes here you get hardware monitoring support for Analog + Devices LTC4286. + config SENSORS_MAX15301 tristate "Maxim MAX15301" helpdrivers/hwmon/pmbus/Makefile +1
-0@@ -24,6 +24,7 @@ obj-$(CONFIG_SENSORS_LM25066) += lm25066.o obj-$(CONFIG_SENSORS_LT7182S) += lt7182s.o obj-$(CONFIG_SENSORS_LTC2978) += ltc2978.o obj-$(CONFIG_SENSORS_LTC3815) += ltc3815.o +obj-$(CONFIG_SENSORS_LTC4286) += ltc4286.o obj-$(CONFIG_SENSORS_MAX15301) += max15301.o obj-$(CONFIG_SENSORS_MAX16064) += max16064.o obj-$(CONFIG_SENSORS_MAX16601) += max16601.odrivers/hwmon/pmbus/ltc4286.c new file +53
-0@@ -0,0 +1,177 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/pmbus.h> +#include "pmbus.h" + +/* LTC4286 register */ +#define LTC4286_MFR_CONFIG1 0xF2 + +/* LTC4286 configuration */ +#define VRANGE_SELECT_BIT BIT(1) + +#define LTC4286_MFR_ID_SIZE 3 +#define VRANGE_25P6 0 + +/* +* Initialize the MBR as default settings which is referred to LTC4286 datasheet +* (March 22, 2022 version) table 3 page 16 +*/ +static struct pmbus_driver_info ltc4286_info = { + .pages =1 , + .format[PSC_VOLTAGE_IN ] = direct, + .format[PSC_VOLTAGE_OUT ] = direct, + .format[PSC_CURRENT_OUT ] = direct, + .format[PSC_POWER ] = direct, + .format[PSC_TEMPERATURE ] = direct, + .m[PSC_VOLTAGE_IN ] =32 , + .b[PSC_VOLTAGE_IN ] =0 , + .R[PSC_VOLTAGE_IN ] =1 , + .m[PSC_VOLTAGE_OUT ] =32 , + .b[PSC_VOLTAGE_OUT ] =0 , + .R[PSC_VOLTAGE_OUT ] =1 , + .m[PSC_CURRENT_OUT ] =1024 , + .b[PSC_CURRENT_OUT ] =0 , +/* +* The rsense value used in MBR formula in LTC4286 datasheet should be ohm unit. +* However, the rsense value that user input is micro ohm. +* Thus, the MBR setting which involves rsense should be shifted by 6 digits. +*/ + .R[PSC_CURRENT_OUT ] =3 -6 , + .m[PSC_POWER ] =1 , + .b[PSC_POWER ] =0 , +/* +* The rsense value used in MBR formula in LTC4286 datasheet should be ohm unit. +* However, the rsense value that user input is micro ohm. +* Thus, the MBR setting which involves rsense should be shifted by 6 digits. +*/ + .R[PSC_POWER ] =4 -6 , + .m[PSC_TEMPERATURE ] =1 ,
drivers/hwmon/pmbus/ltc4286.c line 63
Quoted 10 lines
drivers/hwmon/pmbus/ltc4286.c new file +10
-0+ .b[PSC_TEMPERATURE] = 273, + .R[PSC_TEMPERATURE] = 0, + .func[0 ] =PMBUS_HAVE_VIN |PMBUS_HAVE_VOUT |PMBUS_HAVE_IOUT | +PMBUS_HAVE_PIN |PMBUS_HAVE_TEMP |PMBUS_HAVE_STATUS_VOUT | + PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_STATUS_TEMP, +}; + +static const struct i2c_device_id ltc4286_id[] = { {"ltc4286" ,0 }, + {"ltc4287" ,1 }, + {} };
Please fix that formatting and use the more common style.
static const struct i2c_device_id ltc4286_id[] = {
{ "ltc4286", 0 },
{ "ltc4287", 1 },
{}
};Quoted 42 lines
drivers/hwmon/pmbus/ltc4286.c new file +42
-0+MODULE_DEVICE_TABLE (i2c, ltc4286_id); + +static int ltc4286_probe (struct i2c_client *client) +{ +int ret; +int temp_setting; +const struct i2c_device_id *mid; +u8 block_buffer[I2C_SMBUS_BLOCK_MAX +1 ]; +struct pmbus_driver_info *info; +u32 rsense; + + ret =i2c_smbus_read_block_data (client,PMBUS_MFR_ID , block_buffer); +if (ret <0 ) { +return dev_err_probe (&client->dev, ret, +"Failed to read manufacturer id\n" ); + } + +/* +* Refer to ltc4286 datasheet page 20 +* the manufacturer id is LTC +*/ +if (ret !=LTC4286_MFR_ID_SIZE || +strncmp (block_buffer,"LTC" ,LTC4286_MFR_ID_SIZE )) { +return dev_err_probe (&client->dev, ret, +"Manufacturer id mismatch\n" ); + } + + ret =i2c_smbus_read_block_data (client,PMBUS_MFR_MODEL , block_buffer); +if (ret <0 ) { +return dev_err_probe (&client->dev, ret, +"Failed to read manufacturer model\n" ); + } + +for (mid = ltc4286_id; mid->name[0 ]; mid++) { +if (!strncasecmp (mid->name, block_buffer,strlen (mid->name))) +break ; + } +if (!mid->name[0 ]) +return dev_err_probe (&client->dev, -ENODEV , +"Unsupported device\n" ); + + ret = of_property_read_u32(client->dev.of_node,
drivers/hwmon/pmbus/ltc4286.c line 115
Quoted 10 lines
drivers/hwmon/pmbus/ltc4286.c new file +10
-0+ "shunt-resistor-micro-ohms", &rsense); +if (ret <0 ) +return ret; + +if (rsense ==0 ) +return -EINVAL ; + +if (rsense >INT_MAX ) +return -ERANGE ; +
This is not "Math result not representable". See below.
Quoted 16 lines
drivers/hwmon/pmbus/ltc4286.c new file +16
-0+ info =devm_kmemdup (&client->dev, <c4286_info,sizeof (*info), +GFP_KERNEL ); +if (!info) +return -ENOMEM ; + +/* Default of VRANGE_SELECT = 1, 102.4V */ +if (device_property_read_bool (&client->dev,"adi,vrange-low-enable" )) { +/* Setup MFR1 CONFIG register bit 1 VRANGE_SELECT */ + ret =i2c_smbus_read_word_data (client,LTC4286_MFR_CONFIG1 ); +if (ret <0 ) +return dev_err_probe ( + &client->dev, ret, +"Failed to read manufacturer configuration one\n" ); + + ret &= ~VRANGE_SELECT_BIT ;/* VRANGE_SELECT = 0, 25.6V */ + ret = i2c_smbus_write_word_data(client, LTC4286_MFR_CONFIG1,
drivers/hwmon/pmbus/ltc4286.c line 141
Quoted 10 lines
drivers/hwmon/pmbus/ltc4286.c new file +10
-0+ ret); +if (ret <0 ) +return dev_err_probe (&client->dev, ret, +"Failed to set vrange\n" ); + + info->m[PSC_VOLTAGE_IN ] =128 ; + info->m[PSC_VOLTAGE_OUT ] =128 ; + + temp_setting =4 * rsense; +if (temp_setting >INT_MAX )
This will still overflow for values of rsense larger than INT_MAX / 4. temp_setting is an int, and its value will never be > INT_MAX.
drivers/hwmon/pmbus/ltc4286.c line 143
Quoted 2 lines
drivers/hwmon/pmbus/ltc4286.c new file +2
-0+return dev_err_probe (&client->dev, -ERANGE , +"Power coefficient overflow\n" );
ERANGE is "Math result not representable", which is not the case here. This (and the above above) error needs to be -EINVAL.
drivers/hwmon/pmbus/ltc4286.c line 146
Quoted 3 lines
drivers/hwmon/pmbus/ltc4286.c new file +3
-0+ info->m[PSC_POWER ] = temp_setting; + }else { + info->m[PSC_POWER ] = rsense;
I told you before, the default range needs to be set. The range may have been changed by the BIOS/ROMMON, or someone could have changed it manually with i2cset or some other application, or some other operating system was loaded earlier which did its own setting.
I do understand by now that you don't want to do that, but I won't accept the driver without it, sorry.
drivers/hwmon/pmbus/ltc4286.c line 152
Quoted 6 lines
drivers/hwmon/pmbus/ltc4286.c new file +6
-0+ } + + temp_setting =1024 * rsense; +if (temp_setting >INT_MAX ) +return dev_err_probe (&client->dev, -ERANGE , +"Current coefficient overflow\n" );
Same comments as above for both overflow detection and error code. This also means that rsense must _always_ be <= INT_MAX / 1024. I would suggest to check that once after reading rsense instead of having three different checks in different places.
Also, having an error message here but not with the initial check against 0 and INT_MAX is inconsistent. I'd suggest no error message, but if you want to have error messages please make it consistent.
Quoted 25 lines
drivers/hwmon/pmbus/ltc4286.c new file +25
-0+ info->m[PSC_CURRENT_OUT ] = temp_setting; + +return pmbus_do_probe (client, info); +} + +static const struct of_device_id ltc4286_of_match[] = { + { .compatible ="lltc,ltc4286" }, + { .compatible ="lltc,ltc4287" }, + {} +}; + +static struct i2c_driver ltc4286_driver = { + .driver = { + .name ="ltc4286" , + .of_match_table = ltc4286_of_match, + }, + .probe = ltc4286_probe, + .id_table = ltc4286_id, +}; + +module_i2c_driver (ltc4286_driver); + +MODULE_AUTHOR ("Delphine CC Chiu <[email protected]>" ); +MODULE_DESCRIPTION ("PMBUS driver for LTC4286 and compatibles" ); +MODULE_LICENSE ("GPL" );
Guenter Roeck
maintainerRe: [PATCH v4 2/2] hwmon: pmbus: Add ltc4286 driver
Quoted 6 lines · Guenter Roeck
Quoted 3 lines · Delphine CC Chiu
+ info->m[PSC_POWER] =
temp_setting;
+ } else {
+ info->m[PSC_POWER] = rsense;
Quoted 8 lines
I told you before, the default range needs to be set. The range may have been changed by the BIOS/ROMMON, or someone could have changed it manually with i2cset or some other application, or some other operating system was loaded earlier which did its own setting.
I do understand by now that you don't want to do that, but I won't accept the driver without it, sorry.
As a follow-up on this, it turns out that LTC4287 supports an external EEPROM to store its configuration as well as "STORE_USER_ALL" and "RESTORE_USER_ALL" PMBus commands. It is therefore very well possible and even likely that the voltage range (together with other configurable parameters) was set during system production.
With that in mind, it seems to me that not only the default (property not present) case has to be handled, but that a boolean property to reflect the voltage range is insufficient. I think what is needed instead is a property which specifies the requested range and which, if not present, explicitly means "use whatever is currently programmed into the chip".
Thanks,
Guenter
Delphine_CC_Chiu/WYHQ/Wiwynn
maintainerRE: [PATCH v4 2/2] hwmon: pmbus: Add ltc4286 driver
In reply to Guenter RoeckQuoted 282 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Friday, November 10, 2023 1:28 AM
To: Delphine_CC_Chiu/WYHQ/Wiwynn <[email protected]>; [email protected]; Jean Delvare <[email protected]>; Jonathan Corbet <[email protected]>
Cc: Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 2/2] hwmon: pmbus: Add ltc4286 driverSecurity Reminder: Please be aware that this email is sent by an external
sender.Quoted 20 lines · Delphine CC Chiu
Add a driver to support ltc4286 chip
Signed-off-by Delphine CC Chiu <[email protected]>Changelog:
v4 - Add empty line before "configSENSORS_LTC4286" inKconfig
- Add ltc4286 toDocumentation/hwmon/index.rst
- Revise comment typo
- Usedevm_kmemdupinstead of memcpy
- Check MBR value before writting into
v3 - Usedev_err_probe()instead ofdev_err()
- TheVRANGE_SELECTbit only be written if it actually changed
- Avoid the info pointer being overwritten
- Check the MBR value range to avoid overflow
- Reviseltc4286.rstto corrcet description
v2 - Revise Linear Technologies LTC4286 to
Analog Devices LTC4286 inKconfig
- Add more description for this driver inKconfig
- Add some comments for MBR setting inltc4286.c
- Addltc4286.rstQuoted 6 lines
--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/ltc4286.rst | 95 +++++++++++++++++ drivers/hwmon/pmbus/Kconfig | 10 ++ drivers/hwmon/pmbus/Makefile | 1 + drivers/hwmon/pmbus/ltc4286.c | 177++++++++++++++++++++++++++++++++
Quoted 68 lines
5 files changed, 284 insertions(+)create mode 100644
Documentation/hwmon/ltc4286.rstcreate mode 100644drivers/hwmon/pmbus/ltc4286.c(quoted diff) +0
-0
b/Documentation/hwmon/index.rstindex72f4e6065bae..080827cc4c34100644Documentation/hwmon/index.rst +1
-0@@ -128,6 +128,7 @@ Hardware Monitoring Kernel Drivers ltc4245 ltc4260 ltc4261 + ltc4286 max127 max15301 max16064(quoted diff) +0
-0
b/Documentation/hwmon/ltc4286.rstnew file mode 100644 index 000000000000..2cd149676d86Documentation/hwmon/ltc4286.rst new file +45
-0@@ -0,0 +1,95 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver ltc4286 +===================== + +Supported chips: + + * Analog Devices LTC4286 + + Prefix: 'ltc4286' + + Addresses scanned: - + + Datasheet: + https://www.analog.com/media/en/technical-documentation/data-sheets/ + ltc4286.pdf + + * Analog Devices LTC4287 + + Prefix: 'ltc4287' + + Addresses scanned: - + + Datasheet: + https://www.analog.com/media/en/technical-documentation/data-sheets/ + ltc4287.pdf + +Author: Delphine CC Chiu <[email protected]> + + +Description +----------- + +This driver supports hardware monitoring for Analog Devices LTC4286 +and LTC4287 Hot-Swap Controller and Digital Power Monitors. + +LTC4286 and LTC4287 are hot-swap controllers that allow a circuit +board to be removed from or inserted into a live backplane. They also +feature current and voltage readback via an integrated 12 bit +analog-to-digital converter (ADC), accessed using a PMBus interface. + +The driver is a client driver to the core PMBus driver. Please see +Documentation/hwmon/pmbus.rst for details on PMBus client drivers. + +Documentation/hwmon/ltc4286.rst line 55
Quoted 10 lines
Documentation/hwmon/ltc4286.rst new file +10
-0+Usage Notes +----------- + +This driver does not auto-detect devices. You will have to +instantiate the devices explicitly. Please see +Documentation/i2c/instantiating-devices.rst for details. + +The shunt value in micro-ohms can be set via device tree at +compile-time. Please refer to the +Documentation/devicetree/bindings/hwmon/lltc,ltc4286.yaml for bindingsif the device tree is used.
Quoted 6 lines
Documentation/hwmon/ltc4286.rst new file +6
-0+ + +Platform data support +--------------------- + +The driver supports standard PMBus driver platform data. Please seeDocumentation/hwmon/ltc4286.rst
Quoted 10 lines
Documentation/hwmon/ltc4286.rst new file +10
-0+Documentation/hwmon/pmbus.rst for details. + + +Sysfs entries +------------- + +The following attributes are supported. Limits are read-write, +history reset attributes are write-only, all other attributes are read-only. + +==============================================================================
Quoted 51 lines
Documentation/hwmon/ltc4286.rst new file +29
-0+in1_label "vin" +in1_input Measured voltage. +in1_alarm Input voltage alarm. +in1_min Minimum input voltage. +in1_max Maximum input voltage. + +in2_label "vout1" +in2_input Measured voltage. +in2_alarm Output voltage alarm. +in2_min Minimum output voltage. +in2_max Maximum output voltage. + +curr1_label "iout1" +curr1_input Measured current. +curr1_alarm Output current alarm. +curr1_max Maximum current. + +power1_label "pin" +power1_input Input power. +power1_alarm Input power alarm. +power1_max Maximum poewr. + +temp1_input Chip temperature. +temp1_min Minimum chip temperature. +temp1_max Maximum chip temperature. +temp1_crit Critical chip temperature. +temp1_alarm Chip temperature alarm. +======================= +=======================================================drivers/hwmon/pmbus/Kconfig +10
-0@@ -227,6 +227,16 @@ config SENSORS_LTC3815 This driver can also be built as a module. If so, the module will be called ltc3815. +config SENSORS_LTC4286 + bool "Analog Devices LTC4286" + help + LTC4286 is an integrated solution for hot swap applications that + allows a board to be safely inserted and removed from a live + backplane. + This chip could be used to monitor voltage, current, ...etc. + If you say yes here you get hardware monitoring support for Analog + Devices LTC4286. + config SENSORS_MAX15301 tristate "Maxim MAX15301" help(quoted diff) +0
-0Quoted 1 line
b/drivers/hwmon/pmbus/Makefile index
84ee960a6c2d..94e28f6d6a61100644
drivers/hwmon/pmbus/Makefile obj-$(CONFIG_SENSORS_LM25066) +=
Quoted 3 lines
drivers/hwmon/pmbus/Makefile +0
-0@@ -24,6 +24,7 @@ obj-$(CONFIG_SENSORS_LM25066) +=lm25066.o
Quoted 43 lines
drivers/hwmon/pmbus/Makefile +1
-0obj-$(CONFIG_SENSORS_LT7182S) += lt7182s.o obj-$(CONFIG_SENSORS_LTC2978) += ltc2978.o obj-$(CONFIG_SENSORS_LTC3815) += ltc3815.o +obj-$(CONFIG_SENSORS_LTC4286) += ltc4286.o obj-$(CONFIG_SENSORS_MAX15301) += max15301.o obj-$(CONFIG_SENSORS_MAX16064) += max16064.o obj-$(CONFIG_SENSORS_MAX16601) += max16601.o(quoted diff) +0
-0
b/drivers/hwmon/pmbus/ltc4286.cnew file mode 100644 index 000000000000..e6690b38349adrivers/hwmon/pmbus/ltc4286.c new file +30
-0@@ -0,0 +1,177 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/pmbus.h> +#include "pmbus.h" + +/* LTC4286 register */ +#define LTC4286_MFR_CONFIG1 0xF2 + +/* LTC4286 configuration */ +#define VRANGE_SELECT_BIT BIT(1) + +#define LTC4286_MFR_ID_SIZE 3 +#define VRANGE_25P6 0 + +/* +* Initialize the MBR as default settings which is referred to +LTC4286 datasheet +* (March 22, 2022 version) table 3 page 16 */ static struct +pmbus_driver_info ltc4286_info = { + .pages =1 , + .format[PSC_VOLTAGE_IN ] = direct, + .format[PSC_VOLTAGE_OUT ] = direct, + .format[PSC_CURRENT_OUT ] = direct, + .format[PSC_POWER ] = direct, + .format[PSC_TEMPERATURE ] = direct,drivers/hwmon/pmbus/ltc4286.c line 40
Quoted 10 lines
drivers/hwmon/pmbus/ltc4286.c new file +10
-0+ .m[PSC_VOLTAGE_IN] = 32, + .b[PSC_VOLTAGE_IN] = 0, + .R[PSC_VOLTAGE_IN] = 1, + .m[PSC_VOLTAGE_OUT] = 32, + .b[PSC_VOLTAGE_OUT] = 0, + .R[PSC_VOLTAGE_OUT] = 1, + .m[PSC_CURRENT_OUT] = 1024, + .b[PSC_CURRENT_OUT] = 0, +/* +* The rsense value used in MBR formula in LTC4286 datasheet should be ohm unit.
drivers/hwmon/pmbus/ltc4286.c line 42
Quoted 2 lines
drivers/hwmon/pmbus/ltc4286.c new file +2
-0+* However, the rsense value that user input is micro ohm. +* Thus, the MBR setting which involves rsense should be shifted by 6 digits.
drivers/hwmon/pmbus/ltc4286.c
Quoted 6 lines
drivers/hwmon/pmbus/ltc4286.c new file +6
-0+*/ + .R[PSC_CURRENT_OUT] = 3 - 6, + .m[PSC_POWER] = 1, + .b[PSC_POWER] = 0, +/* +* The rsense value used in MBR formula in LTC4286 datasheet should be ohm unit.
drivers/hwmon/pmbus/ltc4286.c line 50
Quoted 2 lines
drivers/hwmon/pmbus/ltc4286.c new file +2
-0+* However, the rsense value that user input is micro ohm. +* Thus, the MBR setting which involves rsense should be shifted by 6 digits.
drivers/hwmon/pmbus/ltc4286.c
Quoted 6 lines
drivers/hwmon/pmbus/ltc4286.c new file +6
-0+*/ + .R[PSC_POWER] = 4 - 6, + .m[PSC_TEMPERATURE] = 1, + .b[PSC_TEMPERATURE] = 273, + .R[PSC_TEMPERATURE] = 0, + .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT |
PMBUS_HAVE_IOUT|drivers/hwmon/pmbus/ltc4286.c line 57
Quoted 1 line
drivers/hwmon/pmbus/ltc4286.c new file +1
-0+ PMBUS_HAVE_PIN | PMBUS_HAVE_TEMP |
PMBUS_HAVE_STATUS_VOUT|drivers/hwmon/pmbus/ltc4286.c line 58
Quoted 1 line
drivers/hwmon/pmbus/ltc4286.c new file +1
-0+ PMBUS_HAVE_STATUS_IOUT |
PMBUS_HAVE_STATUS_TEMP, };drivers/hwmon/pmbus/ltc4286.c line 63
Quoted 4 lines
drivers/hwmon/pmbus/ltc4286.c new file +4
-0+ +static const struct i2c_device_id ltc4286_id[] = { {"ltc4286" ,0 }, + {"ltc4287" ,1 }, + {} };Please fix that formatting and use the more common style.
Quoted 5 lines
static const struct i2c_device_id ltc4286_id[] = {
{ "ltc4286", 0 },
{ "ltc4287", 1 },
{}
};We will revise to
static const struct i2c_device_id ltc4286_id[] = {
{ "ltc4286", 0 },
{ "ltc4287", 1 },
{}
};Quoted 49 lines
drivers/hwmon/pmbus/ltc4286.c
Quoted 12 lines
drivers/hwmon/pmbus/ltc4286.c new file +11
-0+MODULE_DEVICE_TABLE (i2c, ltc4286_id); + +static int ltc4286_probe (struct i2c_client *client) { +int ret; +int temp_setting; +const struct i2c_device_id *mid; +u8 block_buffer[I2C_SMBUS_BLOCK_MAX +1 ]; +struct pmbus_driver_info *info; +u32 rsense; + + ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID,
block_buffer);drivers/hwmon/pmbus/ltc4286.c
Quoted 3 lines
drivers/hwmon/pmbus/ltc4286.c new file +3
-0+if (ret <0 ) { + return dev_err_probe(&client->dev, ret, + "Failed to read manufacturerid\n");
drivers/hwmon/pmbus/ltc4286.c
Quoted 13 lines
drivers/hwmon/pmbus/ltc4286.c new file +13
-0+ } + +/* +* Refer to ltc4286 datasheet page 20 +* the manufacturer id is LTC +*/ +if (ret !=LTC4286_MFR_ID_SIZE || +strncmp (block_buffer,"LTC" ,LTC4286_MFR_ID_SIZE )) { +return dev_err_probe (&client->dev, ret, +"Manufacturer id mismatch\n" ); + } + + ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL,
block_buffer);drivers/hwmon/pmbus/ltc4286.c
Quoted 3 lines
drivers/hwmon/pmbus/ltc4286.c new file +3
-0+if (ret <0 ) { + return dev_err_probe(&client->dev, ret, + "Failed to read manufacturermodel\n");
drivers/hwmon/pmbus/ltc4286.c
Quoted 4 lines
drivers/hwmon/pmbus/ltc4286.c new file +4
-0+ } + + for (mid = ltc4286_id; mid->name[0]; mid++) { + if (!strncasecmp(mid->name, block_buffer,
strlen(mid->name)))drivers/hwmon/pmbus/ltc4286.c
Quoted 8 lines
drivers/hwmon/pmbus/ltc4286.c new file +8
-0+break ; + } +if (!mid->name[0 ]) +return dev_err_probe (&client->dev, -ENODEV , +"Unsupported device\n" ); + + ret = of_property_read_u32(client->dev.of_node, + "shunt-resistor-micro-ohms",&rsense);
Quoted 11 lines
drivers/hwmon/pmbus/ltc4286.c line 115
Quoted 9 lines
drivers/hwmon/pmbus/ltc4286.c new file +9
-0+if (ret <0 ) +return ret; + +if (rsense ==0 ) +return -EINVAL ; + +if (rsense >INT_MAX ) +return -ERANGE ; +This is not "Math result not representable". See below.
We will revise as below
/* Check for the latter MBR value won't overflow */ if (rsense > (INT_MAX / 1024))
return -EINVAL;
Quoted 45 lines
drivers/hwmon/pmbus/ltc4286.c
Quoted 8 lines
drivers/hwmon/pmbus/ltc4286.c new file +7
-0+ info =devm_kmemdup (&client->dev, <c4286_info,sizeof (*info), +GFP_KERNEL ); +if (!info) +return -ENOMEM ; + +/* Default of VRANGE_SELECT = 1, 102.4V */ +if (device_property_read_bool (&client->dev,"adi,vrange-low-enable" )){
drivers/hwmon/pmbus/ltc4286.c line 122
Quoted 2 lines
drivers/hwmon/pmbus/ltc4286.c new file +2
-0+/* Setup MFR1 CONFIG register bit 1 VRANGE_SELECT */ + ret = i2c_smbus_read_word_data(client,
LTC4286_MFR_CONFIG1);drivers/hwmon/pmbus/ltc4286.c
Quoted 7 lines
drivers/hwmon/pmbus/ltc4286.c new file +7
-0+ if (ret < 0) + return dev_err_probe( + &client->dev, ret, + "Failed to read manufacturer + configuration one\n"); + + ret &= ~VRANGE_SELECT_BIT; /* VRANGE_SELECT = 0,25.6V */
drivers/hwmon/pmbus/ltc4286.c line 130
Quoted 1 line
drivers/hwmon/pmbus/ltc4286.c new file +1
-0+ ret = i2c_smbus_write_word_data(client,
LTC4286_MFR_CONFIG1,drivers/hwmon/pmbus/ltc4286.c
Quoted 4 lines
drivers/hwmon/pmbus/ltc4286.c new file +4
-0+ ret); +if (ret <0 ) + return dev_err_probe(&client->dev, ret, + "Failed to setvrange\n");
drivers/hwmon/pmbus/ltc4286.c line 141
Quoted 6 lines
drivers/hwmon/pmbus/ltc4286.c new file +6
-0+ + info->m[PSC_VOLTAGE_IN ] =128 ; + info->m[PSC_VOLTAGE_OUT ] =128 ; + + temp_setting =4 * rsense; +if (temp_setting >INT_MAX )This will still overflow for values of rsense larger than
INT_MAX/ 4.temp_settingis an int, and its value will never be >INT_MAX.drivers/hwmon/pmbus/ltc4286.c line 143
Quoted 3 lines
drivers/hwmon/pmbus/ltc4286.c new file +3
-0+return dev_err_probe (&client->dev, -ERANGE , +"Power coefficient + overflow\n");ERANGE is "Math result not representable", which is not the case here. This (and the above above) error needs to be
-EINVAL.
Quoted 8 lines
drivers/hwmon/pmbus/ltc4286.c line 146
Quoted 3 lines
drivers/hwmon/pmbus/ltc4286.c new file +3
-0+ info->m[PSC_POWER ] = temp_setting; + }else { + info->m[PSC_POWER ] = rsense;I told you before, the default range needs to be set. The range may have been changed by the BIOS/ROMMON, or someone could have changed it manually with i2cset or some other application, or some other operating system was loaded earlier which did its own setting.
After consulting with our hardware engineer, we will set default rsense value as 300.
Quoted 11 lines
I do understand by now that you don't want to do that, but I won't accept the driver without it, sorry.
drivers/hwmon/pmbus/ltc4286.c line 152
Quoted 6 lines
drivers/hwmon/pmbus/ltc4286.c new file +6
-0+ } + + temp_setting =1024 * rsense; +if (temp_setting >INT_MAX ) +return dev_err_probe (&client->dev, -ERANGE , +"Current coefficient overflow\n" );
Quoted 8 lines
Same comments as above for both overflow detection and error code. This also means that rsense must _always_ be <=
INT_MAX/ 1024. I would suggest to check that once after reading rsense instead of having three different checks in different places.Also, having an error message here but not with the initial check against 0 and
INT_MAXis inconsistent. I'd suggest no error message, but if you want to have error messages please make it consistent.
OK, we will check the rsense right after reading it.
Quoted 26 lines
Quoted 13 lines
drivers/hwmon/pmbus/ltc4286.c new file +12
-0+ info->m[PSC_CURRENT_OUT ] = temp_setting; + +return pmbus_do_probe (client, info); } + +static const struct of_device_id ltc4286_of_match[] = { + { .compatible ="lltc,ltc4286" }, + { .compatible ="lltc,ltc4287" }, + {} +}; + +static struct i2c_driver ltc4286_driver = { + .driver = {drivers/hwmon/pmbus/ltc4286.c
Quoted 10 lines
drivers/hwmon/pmbus/ltc4286.c new file +10
-0+ .name = "ltc4286", + .of_match_table = ltc4286_of_match, + }, + .probe = ltc4286_probe, + .id_table = ltc4286_id, +}; + +module_i2c_driver (ltc4286_driver); + +MODULE_AUTHOR("Delphine CC Chiu<[email protected]>");
Quoted 2 lines
drivers/hwmon/pmbus/ltc4286.c new file +2
-0+MODULE_DESCRIPTION ("PMBUS driver for LTC4286 and compatibles" ); +MODULE_LICENSE ("GPL" );