hwmon: max31827: Add PEC support
Subsystems (3)
PATCH 1/3 hwmon: max31827: Add PEC support
Removed regmap and used my functions to read, write and update bits. In these functions i2c_smbus_ helper functions are used. These check if there were any PEC errors during read. In the write function, if PEC is enabled, I check for PEC Error bit, to see if there were any errors.
--- Documentation/hwmon/max31827.rst | 14 +- drivers/hwmon/max31827.c | 219 +++++++++++++++++++++++-------- 2 files changed, 171 insertions(+), 62 deletions(-)
Documentation/hwmon/max31827.rst +10 -4
@@ -131,7 +131,13 @@ The Fault Queue bits select how many consecutive temperature faults must occur before overtemperature or undertemperature faults are indicated in the corresponding status bits. -Notes ------ - -PEC is not implemented. +PEC (packet error checking) can be enabled from the "pec" device attribute. +If PEC is enabled, a PEC byte is appended to the end of each message transfer. +This is a CRC-8 byte that is calculated on all of the message bytes (including +the address/read/write byte). The last device to transmit a data byte also +transmits the PEC byte. The master transmits the PEC byte after a write +transaction, and the MAX31827 transmits the PEC byte after a read transaction. + +The read PEC error is handled inside the i2c_smbus_read_word_swapped() function. +To check if the write had any PEC error a read is performed on the configuration +register, to check the PEC Error bit.
drivers/hwmon/max31827.c +161 -58
397 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 2/3 bindings: hwmon: Add adi,adaq4224_temp as compatible string
In the device ada4224 the max31827 temperature sensor will be used, so the default values corresponding to adaq4224_temp are the same for max31827.
--- Documentation/devicetree/bindings/hwmon/adi,max31827.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml +4 -1
@@ -20,6 +20,7 @@ properties: - const: adi,max31827 - items: - enum: + - adi,adaq4224_temp - adi,max31828 - adi,max31829 - const: adi,max31827
@@ -81,7 +82,9 @@ allOf: properties: compatible: contains: - const: adi,max31827 + enum: + - adi,max31827 + - adi,adaq4224_temp then: properties:
Signature · 1 line
2.34.1
Guenter Roeck
maintainerRe: [PATCH 2/3] bindings: hwmon: Add adi,adaq4224_temp as compatible string
Quoted 4 lines · Daniel Matyas
In the device ada4224 the max31827 temperature sensor will be used, so the default values corresponding to
adaq4224_tempare the same for max31827.
I don't know what that device is, but if the max31827 is used it should be instantiated as max31827.
Guenter
Quoted 28 lines
Signed-off-by Daniel Matyas <[email protected]>--- Documentation/devicetree/bindings/hwmon/adi,max31827.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/hwmon/adi,max31827.yaml +4
-1@@ -20,6 +20,7 @@ properties: - const: adi,max31827 - items: - enum: + - adi,adaq4224_temp - adi,max31828 - adi,max31829 - const: adi,max31827@@ -81,7 +82,9 @@ allOf: properties: compatible: contains: - const: adi,max31827 + enum: + - adi,max31827 + - adi,adaq4224_temp then: properties:
Re: [PATCH 2/3] bindings: hwmon: Add adi,adaq4224_temp as compatible string
Quoted 8 lines · Guenter Roeck
Quoted 4 lines · Daniel Matyas
In the device ada4224 the max31827 temperature sensor will be used, so the default values corresponding to
adaq4224_tempare the same for max31827.I don't know what that device is, but if the max31827 is used it should be instantiated as max31827.
An improved commit message would be rather helpful here, as google did not turn up any information on what this new device is. Taking the patch on face value, a couple comments below.
Quoted 5 lines
Quoted 5 lines
Signed-off-by Daniel Matyas <[email protected]>--- Documentation/devicetree/bindings/hwmon/adi,max31827.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 9 lines
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml properties: · line 23
Quoted 9 lines
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml +1
-0@@ -20,6 +20,7 @@ properties: - const: adi,max31827 - items: - enum: + - adi,adaq4224_temp
No underscores in the compatible please.
Quoted 11 lines
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml allOf: · line 87
Quoted 11 lines
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml +3
-1- adi,max31828 - adi,max31829 - const: adi,max31827@@ -81,7 +82,9 @@ allOf: properties: compatible: contains: - const: adi,max31827 + enum: + - adi,max31827 + - adi,adaq4224_temp
This doesn't do anything afaict, since the binding doesn't allow "adi,adaq4224_temp" without "adi,max31827".
Quoted 3 lines
Quoted 2 lines
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml +0
-0then: properties:
Re: [PATCH 2/3] bindings: hwmon: Add adi,adaq4224_temp as compatible string
In reply to Daniel MatyasQuoted 5 lines · Daniel Matyas
In the device ada4224 the max31827 temperature sensor will be used, so the default values corresponding to
adaq4224_tempare the same for max31827.Signed-off-by Daniel Matyas <[email protected]>
Please use subject prefixes matching the subsystem. You can get them for example with git log --oneline -- DIRECTORY_OR_FILE on the directory your patch is touching.
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml properties: · line 23
Quoted 13 lines
--- Documentation/devicetree/bindings/hwmon/adi,max31827.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/hwmon/adi,max31827.yaml +1
-0@@ -20,6 +20,7 @@ properties: - const: adi,max31827 - items: - enum: + - adi,adaq4224_temp
Underscores are not allowed
Best regards,
Krzysztof
Guenter Roeck
maintainerRe: [PATCH 2/3] bindings: hwmon: Add adi,adaq4224_temp as compatible string
Quoted 15 lines · Krzysztof Kozlowski
Quoted 5 lines · Daniel Matyas
In the device ada4224 the max31827 temperature sensor will be used, so the default values corresponding to
adaq4224_tempare the same for max31827.Signed-off-by Daniel Matyas <[email protected]>Please use subject prefixes matching the subsystem. You can get them for example with
git log --oneline -- DIRECTORY_OR_FILEon the directory your patch is touching.Quoted 4 lines
--- Documentation/devicetree/bindings/hwmon/adi,max31827.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 12 lines
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml properties: · line 23
Quoted 9 lines
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml +1
-0@@ -20,6 +20,7 @@ properties: - const: adi,max31827 - items: - enum: + - adi,adaq4224_tempUnderscores are not allowed
That isn't the main problem with this patch.
https://github.com/analogdevicesinc/linux/tree/dev_adaq4224_dts
suggests that it may be a development system which utilizes the max31827. From there, we can see that there is a devicetree description of a board with that name which uses
temperature1: temperature@5f {
compatible = "adi,adaq4224_temp";
reg = <0x5f>;
vref-supply = <&vio>;
adi,comp-int;
adi,alarm-pol = <0>;
adi,fault-q = <1>;
adi,timeout-enable;
};That doesn't make sense to me. I don't know why they don't just reference max31827. I am most definitely not going to accept a driver change just to map adi,adaq4224_temp (or adi,adaq4224-temp) to the actually used temperature sensor chip. If we start accepting that, we'd end up with no end of "<vendor>,<board_name>-{temp,voltage,current,power,...}"
compatibles.
Looking more into the above mentioned repository/branch, an earlier version of the dts file did reference adi,max31827 for that chip. It also looks like there may be an adaq4224 ADC (per drivers/iio/adc/ad4630.c), but that would be a SPI chip. It seems highly unlikely that a SPI ADC would have a separate I2C interface connected to a temperature sensor. Confusing.
There is also some indication that this may some IP to be loaded into an FPGA. which utilizes an FPGA implementation of max31827 (or maybe connects to one). If that is the case, it should still be referenced as max31827.
All that wasted time because of "let's provide as little as possible information about what we are actually doing" :-(.
Guenter
RE: [PATCH 2/3] bindings: hwmon: Add adi,adaq4224_temp as compatible string
Quoted 94 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Friday, December 15, 2023 6:03 PM
To: Krzysztof Kozlowski <[email protected]>; Matyas, Daniel <[email protected]>
Cc: Jean Delvare <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 2/3] bindings: hwmon: Add adi,adaq4224_temp as compatible string[External]
Quoted 3 lines · Krzysztof Kozlowski
Quoted 2 lines · Daniel Matyas
In the device ada4224 the max31827 temperature sensor will be used, so the default values corresponding to
adaq4224_tempare the samefor
Quoted 10 lines
Quoted 3 lines
max31827.
Signed-off-by Daniel Matyas <[email protected]>Please use subject prefixes matching the subsystem. You can get them for example with
git log --oneline -- DIRECTORY_OR_FILEon the directory your patch is touching.Quoted 2 lines
--- Documentation/devicetree/bindings/hwmon/adi,max31827.yaml | 5++++-
Quoted 8 lines
Quoted 8 lines
1 file changed, 4 insertions(+), 1 deletion(-)diff --git
a/Documentation/devicetree/bindings/hwmon/adi,max31827.yamlb/Documentation/devicetree/bindings/hwmon/adi,max31827.yamlindexf60e06ab7d0a..9f3b0839aa46100644
---a/Documentation/devicetree/bindings/hwmon/adi,max31827.yaml
+++
b/Documentation/devicetree/bindings/hwmon/adi,max31827.yamlQuoted 8 lines
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml properties: · line 23
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml +1
-0@@ -20,6 +20,7 @@ properties: - const: adi,max31827 - items: - enum: + - adi,adaq4224_tempUnderscores are not allowed
That isn't the main problem with this patch.
https://urldefense.com/v3/__https://github.com/analogdevicesinc/linux/
tree/dev_adaq4224_dts__;!!A3Ni8CS0y2Y!_2D1w1DD5sjJrNyArZYZ3QW9nS8URmP6X0n6R7q1sBnDB1HPL6jROhD_w9u3fJixt2hDDNtO6VpgLM1Jka
Q$
suggests that it may be a development system which utilizes the max31827.
From there, we can see that there is a devicetree description of a board
with that name which usestemperature1: temperature@5f { compatible = "adi,adaq4224_temp"; reg = <0x5f>; vref-supply = <&vio>; adi,comp-int; adi,alarm-pol = <0>; adi,fault-q = <1>; adi,timeout-enable; };That doesn't make sense to me. I don't know why they don't just reference max31827.
I am most definitely not going to accept a driver change just to map adi,adaq4224_temp (or adi,adaq4224-temp) to the actually used temperature sensor chip. If we start accepting that, we'd end up with no end of "<vendor>,<board_name>-{temp,voltage,current,power,...}" compatibles.Looking more into the above mentioned repository/branch, an earlier version of the dts file did reference adi,max31827 for that chip. It also looks like there may be an adaq4224 ADC (per
drivers/iio/adc/ad4630.c), but that would be a SPI chip. It seems highly unlikely that a SPI ADC would have a separate I2C interface connected to a temperature sensor. Confusing.There is also some indication that this may some IP to be loaded into an FPGA.
which utilizes an FPGA implementation of max31827 (or maybe connects to one).
If that is the case, it should still be referenced as max31827.
Quoted 4 lines
All that wasted time because of "let's provide as little as possible information about what we are actually doing" :-(.
Guenter
I asked around to get some more clarification on the matter. There will be a new chip released, named adaq4224. This chip will have the max31827 implemented in the silicon, so the driver used to get temperature information would be max31827.c. The chip will have spi and i2c communication too. The other driver you mentioned, the ad4630.c will communicate through spi.
Because the chip has a different name, I was asked to add a new label for the max31827, so that it will be clear for the user, that the max31827 is part of the chip.
In ad4630.c the indio_dev->name is changed. Would it be ok, if I did something similar? Is there something similar in hwmon? Maybe dev->init_name?
Daniel
Guenter Roeck
maintainerRe: [PATCH 2/3] bindings: hwmon: Add adi,adaq4224_temp as compatible string
Quoted 94 lines · Daniel
Quoted 94 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Friday, December 15, 2023 6:03 PM
To: Krzysztof Kozlowski <[email protected]>; Matyas, Daniel <[email protected]>
Cc: Jean Delvare <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 2/3] bindings: hwmon: Add adi,adaq4224_temp as compatible string[External]
Quoted 3 lines · Krzysztof Kozlowski
Quoted 2 lines · Daniel Matyas
In the device ada4224 the max31827 temperature sensor will be used, so the default values corresponding to
adaq4224_tempare the samefor
Quoted 10 lines
Quoted 3 lines
max31827.
Signed-off-by Daniel Matyas <[email protected]>Please use subject prefixes matching the subsystem. You can get them for example with
git log --oneline -- DIRECTORY_OR_FILEon the directory your patch is touching.Quoted 2 lines
--- Documentation/devicetree/bindings/hwmon/adi,max31827.yaml | 5++++-
Quoted 8 lines
Quoted 8 lines
1 file changed, 4 insertions(+), 1 deletion(-)diff --git
a/Documentation/devicetree/bindings/hwmon/adi,max31827.yamlb/Documentation/devicetree/bindings/hwmon/adi,max31827.yamlindexf60e06ab7d0a..9f3b0839aa46100644
---a/Documentation/devicetree/bindings/hwmon/adi,max31827.yaml
+++
b/Documentation/devicetree/bindings/hwmon/adi,max31827.yamlQuoted 8 lines
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml properties: · line 23
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml +1
-0@@ -20,6 +20,7 @@ properties: - const: adi,max31827 - items: - enum: + - adi,adaq4224_tempUnderscores are not allowed
That isn't the main problem with this patch.
https://urldefense.com/v3/__https://github.com/analogdevicesinc/linux/
tree/dev_adaq4224_dts__;!!A3Ni8CS0y2Y!_2D1w1DD5sjJrNyArZYZ3QW9nS8URmP6X0n6R7q1sBnDB1HPL6jROhD_w9u3fJixt2hDDNtO6VpgLM1Jka
Q$
suggests that it may be a development system which utilizes the max31827.
From there, we can see that there is a devicetree description of a board
with that name which usestemperature1: temperature@5f { compatible = "adi,adaq4224_temp"; reg = <0x5f>; vref-supply = <&vio>; adi,comp-int; adi,alarm-pol = <0>; adi,fault-q = <1>; adi,timeout-enable; };That doesn't make sense to me. I don't know why they don't just reference max31827.
I am most definitely not going to accept a driver change just to map adi,adaq4224_temp (or adi,adaq4224-temp) to the actually used temperature sensor chip. If we start accepting that, we'd end up with no end of "<vendor>,<board_name>-{temp,voltage,current,power,...}" compatibles.Looking more into the above mentioned repository/branch, an earlier version of the dts file did reference adi,max31827 for that chip. It also looks like there may be an adaq4224 ADC (per
drivers/iio/adc/ad4630.c), but that would be a SPI chip. It seems highly unlikely that a SPI ADC would have a separate I2C interface connected to a temperature sensor. Confusing.There is also some indication that this may some IP to be loaded into an FPGA.
which utilizes an FPGA implementation of max31827 (or maybe connects to one).
If that is the case, it should still be referenced as max31827.
Quoted 9 lines
Quoted 4 lines
All that wasted time because of "let's provide as little as possible information about what we are actually doing" :-(.
Guenter
I asked around to get some more clarification on the matter. There will be a new chip released, named adaq4224. This chip will have the max31827 implemented in the silicon, so the driver used to get temperature information would be
max31827.c. The chip will have spi and i2c communication too. The other driver you mentioned, thead4630.cwill communicate through spi.Because the chip has a different name, I was asked to add a new label for the max31827, so that it will be clear for the user, that the max31827 is part of the chip.
It is still a max31827 core. If there is no difference in programming to max31827, it can possibly be reflected in devicetree as "adi,adaq4224-temp", in addition to "adi,max31827". This would not require a change in the driver code as "adi,max31827" would still be mandatory.
But I don't think changing the driver or device name for this purpose would be appropriate. We don't do that for any of the other hwmon drivers, and I really don't want to open a floodgate. The lm75 driver supports more than 20 chips from various different vendors, but it is still the lm75 driver. The jc42 driver supports many chips from different vendors, but the driver only has a single "jedec,jc-42.4-temp" binding, and devices are instantiated as "jc42". I don't see why this one should be handled differently.
Guenter
Re: [PATCH 2/3] bindings: hwmon: Add adi,adaq4224_temp as compatible string
Quoted 102 lines · Guenter Roeck
Quoted 101 lines · Daniel
Quoted 94 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Friday, December 15, 2023 6:03 PM
To: Krzysztof Kozlowski <[email protected]>; Matyas, Daniel <[email protected]>
Cc: Jean Delvare <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 2/3] bindings: hwmon: Add adi,adaq4224_temp as compatible string[External]
Quoted 3 lines · Krzysztof Kozlowski
Quoted 2 lines · Daniel Matyas
In the device ada4224 the max31827 temperature sensor will be used, so the default values corresponding to
adaq4224_tempare the samefor
Quoted 10 lines
Quoted 3 lines
max31827.
Signed-off-by Daniel Matyas <[email protected]>Please use subject prefixes matching the subsystem. You can get them for example with
git log --oneline -- DIRECTORY_OR_FILEon the directory your patch is touching.Quoted 2 lines
--- Documentation/devicetree/bindings/hwmon/adi,max31827.yaml | 5++++-
Quoted 8 lines
Quoted 8 lines
1 file changed, 4 insertions(+), 1 deletion(-)diff --git
a/Documentation/devicetree/bindings/hwmon/adi,max31827.yamlb/Documentation/devicetree/bindings/hwmon/adi,max31827.yamlindexf60e06ab7d0a..9f3b0839aa46100644
---a/Documentation/devicetree/bindings/hwmon/adi,max31827.yaml
+++
b/Documentation/devicetree/bindings/hwmon/adi,max31827.yamlQuoted 8 lines
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml properties: · line 23
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/adi,max31827.yaml +1
-0@@ -20,6 +20,7 @@ properties: - const: adi,max31827 - items: - enum: + - adi,adaq4224_tempUnderscores are not allowed
That isn't the main problem with this patch.
https://urldefense.com/v3/__https://github.com/analogdevicesinc/linux/
tree/dev_adaq4224_dts__;!!A3Ni8CS0y2Y!_2D1w1DD5sjJrNyArZYZ3QW9nS8URmP6X0n6R7q1sBnDB1HPL6jROhD_w9u3fJixt2hDDNtO6VpgLM1Jka
Q$
suggests that it may be a development system which utilizes the max31827.
From there, we can see that there is a devicetree description of a board
with that name which usestemperature1: temperature@5f { compatible = "adi,adaq4224_temp"; reg = <0x5f>; vref-supply = <&vio>; adi,comp-int; adi,alarm-pol = <0>; adi,fault-q = <1>; adi,timeout-enable; };That doesn't make sense to me. I don't know why they don't just reference max31827.
I am most definitely not going to accept a driver change just to map adi,adaq4224_temp (or adi,adaq4224-temp) to the actually used temperature sensor chip. If we start accepting that, we'd end up with no end of "<vendor>,<board_name>-{temp,voltage,current,power,...}" compatibles.Looking more into the above mentioned repository/branch, an earlier version of the dts file did reference adi,max31827 for that chip. It also looks like there may be an adaq4224 ADC (per
drivers/iio/adc/ad4630.c), but that would be a SPI chip. It seems highly unlikely that a SPI ADC would have a separate I2C interface connected to a temperature sensor. Confusing.There is also some indication that this may some IP to be loaded into an FPGA.
which utilizes an FPGA implementation of max31827 (or maybe connects to one).
If that is the case, it should still be referenced as max31827.Quoted 4 lines
All that wasted time because of "let's provide as little as possible information about what we are actually doing" :-(.
Guenter
I asked around to get some more clarification on the matter. There will be a new chip released, named adaq4224. This chip will have the max31827 implemented in the silicon, so the driver used to get temperature information would be
max31827.c. The chip will have spi and i2c communication too. The other driver you mentioned, thead4630.cwill communicate through spi.
Quoted 8 lines
Quoted 2 lines
Because the chip has a different name, I was asked to add a new label for the max31827, so that it will be clear for the user, that the max31827 is part of the chip.
It is still a max31827 core. If there is no difference in programming to max31827, it can possibly be reflected in devicetree as "adi,adaq4224-temp", in addition to "adi,max31827". This would not require a change in the driver code as "adi,max31827" would still be mandatory.
I am inclined to agree, but it is very hard to review these bindings when only partial functionality of the hardware is submitted. Then subtract any documentation of the device from the picture and clearly reviewing becomes quite challenging.
PATCH 3/3 hwmon: max31827: Compatible for adaq4224
In reply to Daniel MatyasCompatible string "adi,adaq4224_temp" is accepted in device tree. When this string is seen in the device tree, the name of the device changes to "adaq4224_temp" and the default configuration of max31827 is loaded.
This modification was requested by the costumer, so that whenever one analyzes the available devices, one can know for sure, that max31827 is part of the adaq4224.
--- drivers/hwmon/max31827.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/hwmon/max31827.c +11 -1
@@ -48,7 +48,7 @@#define MAX31827_M_DGR_TO_16_BIT (x) (((x) << 4) / 1000)#define MAX31827_DEVICE_ENABLE (x) ((x) ? 0xA : 0x0) -enum chips { max31827 =1 , max31828, max31829 }; +enum chips { max31827 =1 , max31828, max31829, adaq4224_temp };enum max31827_cnv {MAX31827_CNV_1_DIV_64_HZ =1 ,
@@ -592,6 +592,7 @@ static const struct i2c_device_id max31827_i2c_ids[] = { { "max31827", max31827 }, { "max31828", max31828 }, { "max31829", max31829 }, + { "adaq4224_temp", adaq4224_temp }, { } };MODULE_DEVICE_TABLE (i2c, max31827_i2c_ids);
@@ -620,6 +621,9 @@ static int max31827_init_client(struct max31827_state *st) res |=FIELD_PREP (MAX31827_CONFIGURATION_TIMEOUT_MASK , !prop); type = (enum chips )(uintptr_t )device_get_match_data (dev); +if (type == adaq4224_temp) { + dev->driver->name ="adaq4224_temp" ; + }if (fwnode_property_present (fwnode,"adi,alarm-pol" )) { ret =fwnode_property_read_u32 (fwnode,"adi,alarm-pol" , &data);
@@ -633,6 +637,7 @@ static int max31827_init_client(struct max31827_state *st)*/ switch (type) {case max31827: +case adaq4224_temp:case max31828: res |=FIELD_PREP (MAX31827_CONFIGURATION_ALRM_POL_MASK ,MAX31827_ALRM_POL_LOW );
@@ -669,6 +674,7 @@ static int max31827_init_client(struct max31827_state *st)*/ switch (type) {case max31827: +case adaq4224_temp: res |=FIELD_PREP (MAX31827_CONFIGURATION_FLT_Q_MASK ,MAX31827_FLT_Q_1 );break ;
@@ -750,6 +756,10 @@ static const struct of_device_id max31827_of_match[] = { .compatible = "adi,max31829", .data = (void *)max31829 }, + { + .compatible = "adi,adaq4224_temp", + .data = (void *)adaq4224_temp + }, { } };MODULE_DEVICE_TABLE (of, max31827_of_match);
Signature · 1 line
2.34.1
Guenter Roeck
maintainerRe: [PATCH 3/3] hwmon: max31827: Compatible for adaq4224
Quoted 6 lines · Daniel Matyas
Compatible string "adi,adaq4224_temp" is accepted in device tree. When this string is seen in the device tree, the name of the device changes to "
adaq4224_temp" and the default configuration of max31827 is loaded.This modification was requested by the costumer, so that whenever one
customer
Quoted 3 lines
analyzes the available devices, one can know for sure, that max31827 is part of the adaq4224.
There is (officially) no such chip. I have no idea if this is a new chip or something else, and I have no idea how it relates to max31827. Either case, the "_temp" in the chip name doesn't make sense to me.
Quoted 27 lines
Signed-off-by Daniel Matyas <[email protected]>--- drivers/hwmon/max31827.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/hwmon/max31827.c +2
-1@@ -48,7 +48,7 @@#define MAX31827_M_DGR_TO_16_BIT (x) (((x) << 4) / 1000)#define MAX31827_DEVICE_ENABLE (x) ((x) ? 0xA : 0x0) -enum chips { max31827 =1 , max31828, max31829 }; +enum chips { max31827 =1 , max31828, max31829, adaq4224_temp };enum max31827_cnv {MAX31827_CNV_1_DIV_64_HZ =1 ,@@ -592,6 +592,7 @@ static const struct i2c_device_id max31827_i2c_ids[] = { { "max31827", max31827 }, { "max31828", max31828 }, { "max31829", max31829 }, + { "adaq4224_temp", adaq4224_temp }, { } };MODULE_DEVICE_TABLE (i2c, max31827_i2c_ids);
drivers/hwmon/max31827.c static int max31827_init_client(struct max31827_state *st) · line 627
Quoted 7 lines
drivers/hwmon/max31827.c +3
-0@@ -620,6 +621,9 @@ static int max31827_init_client(struct max31827_state *st) res |=FIELD_PREP (MAX31827_CONFIGURATION_TIMEOUT_MASK , !prop); type = (enum chips )(uintptr_t )device_get_match_data (dev); +if (type == adaq4224_temp) { + dev->driver->name ="adaq4224_temp" ; + }
No, sorry, we don't make such changes. The driver has a fixed name which is independent of the device connected to it.
Guenter
Guenter Roeck
maintainerQuoted 6 lines · Daniel Matyas
Removed regmap and used my functions to read, write and update bits. In these functions
i2c_smbus_helper functions are used. These check if there were any PEC errors during read. In the write function, if PEC is enabled, I check for PEC Error bit, to see if there were any errors.Signed-off-by Daniel Matyas <[email protected]>
The "PEC" attribute needs to be attached to the I2C device. See lm90.c or pmbus_core.c for examples.
The changes, if indeed needed, do not warant dropping regmap. You will need to explain why the reg_read and reg_write callbacks provideed by regmap can not be used.
On top of that, it is not clear why regmap can't be used in the first place. It seems that the major change is that one needs to read the configuration register after a write to see if there was a PEC error. It is not immediately obvious why that additional read (if indeed necessary) would require regmap support to be dropped.
Regarding "if indeed necessary": There needs to be a comment explaining that the device will return ACK even after a packet with bad PEC is received.
Quoted 67 lines
--- Documentation/hwmon/max31827.rst | 14 +- drivers/hwmon/max31827.c | 219 +++++++++++++++++++++++-------- 2 files changed, 171 insertions(+), 62 deletions(-)Documentation/hwmon/max31827.rst +10
-4@@ -131,7 +131,13 @@ The Fault Queue bits select how many consecutive temperature faults must occur before overtemperature or undertemperature faults are indicated in the corresponding status bits. -Notes ------ - -PEC is not implemented. +PEC (packet error checking) can be enabled from the "pec" device attribute. +If PEC is enabled, a PEC byte is appended to the end of each message transfer. +This is a CRC-8 byte that is calculated on all of the message bytes (including +the address/read/write byte). The last device to transmit a data byte also +transmits the PEC byte. The master transmits the PEC byte after a write +transaction, and the MAX31827 transmits the PEC byte after a read transaction. + +The read PEC error is handled inside the i2c_smbus_read_word_swapped() function. +To check if the write had any PEC error a read is performed on the configuration +register, to check the PEC Error bit.drivers/hwmon/max31827.c +4
-2@@ -11,8 +11,8 @@#include <linux/hwmon.h> #include <linux/i2c.h> #include <linux/mutex.h> -#include <linux/regmap.h> #include <linux/regulator/consumer.h> +#include <linux/hwmon-sysfs.h> #include <linux/of_device.h> #define MAX31827_T_REG 0x0@@ -24,11 +24,13 @@#define MAX31827_CONFIGURATION_1SHOT_MASK BIT(0)#define MAX31827_CONFIGURATION_CNV_RATE_MASK GENMASK(3, 1) +#define MAX31827_CONFIGURATION_PEC_EN_MASK BIT(4)#define MAX31827_CONFIGURATION_TIMEOUT_MASK BIT(5)#define MAX31827_CONFIGURATION_RESOLUTION_MASK GENMASK(7, 6)#define MAX31827_CONFIGURATION_ALRM_POL_MASK BIT(8)#define MAX31827_CONFIGURATION_COMP_INT_MASK BIT(9)#define MAX31827_CONFIGURATION_FLT_Q_MASK GENMASK(11, 10) +#define MAX31827_CONFIGURATION_PEC_ERR_MASK BIT(13)#define MAX31827_CONFIGURATION_U_TEMP_STAT_MASK BIT(14)#define MAX31827_CONFIGURATION_O_TEMP_STAT_MASK BIT(15)@@ -94,23 +96,67 @@ struct max31827_state {* Prevent simultaneous access to the i2c client. */ struct mutex lock; -struct regmap *regmap;bool enable;unsigned int resolution;unsigned int update_interval; +struct i2c_client *client; };
drivers/hwmon/max31827.c struct max31827_state { · line 109
Quoted 10 lines
drivers/hwmon/max31827.c +5
-5-static const struct regmap_config max31827_regmap = { - .reg_bits =8 , - .val_bits =16 , - .max_register =0xA , -}; +static int max31827_reg_read (struct i2c_client *client,u8 reg,u16 *val) +{ +u16 tmp =i2c_smbus_read_word_swapped (client, reg); + +if (tmp <0 )
An u16 variable will never be negative.
drivers/hwmon/max31827.c struct max31827_state { · line 114
Quoted 5 lines
drivers/hwmon/max31827.c +5
-0+return tmp; + + *val = tmp; +return 0 ; +}
If regmap can indeed not be used, it is unnecessary to provide a pointer to the return value. Instead, just like with smbus calls, the error return and the return value can be combined. Adding this function just to separate error from return value adds zero value (and, as can be seen from the above, actually adds an opportunity to introduce bugs).
drivers/hwmon/max31827.c struct max31827_state { · line 125
Quoted 11 lines
drivers/hwmon/max31827.c +11
-0+ +static int max31827_reg_write (struct i2c_client *client,u8 reg,u16 val) +{ +u16 cfg; +int ret; + + ret =i2c_smbus_write_word_swapped (client, reg, val); +if (ret) +return ret; + +// If PEC is not enabled, return with success
Do not mix comment styles. The rest of the driver doesn't use C++ comments. Besides, the comment does not add any value.
drivers/hwmon/max31827.c struct max31827_state { · line 135
Quoted 10 lines
drivers/hwmon/max31827.c +10
-0+if (!(client->flags &I2C_CLIENT_PEC )) +return 0 ; + + ret =max31827_reg_read (client,MAX31827_CONFIGURATION_REG , &cfg); +if (ret) +return ret; + +if (cfg &MAX31827_CONFIGURATION_PEC_ERR_MASK ) +return -EBADMSG ; +
EBADMSG is "Not a data message". I don't think that is appropriate here.
I would very much prefer
if (client->flags & I2C_CLIENT_PEC) {
...
}Quoted 16 lines
drivers/hwmon/max31827.c +16
-0+return 0 ; +} + +static int max31827_update_bits (struct i2c_client *client,u8 reg, +u16 mask,u16 val) +{ +u16 tmp; +int ret; + + ret =max31827_reg_read (client, reg, &tmp); +if (ret) +return ret; + + tmp = (tmp & ~mask) | (val & mask); + ret =max31827_reg_write (client, reg, tmp); +
drivers/hwmon/max31827.c struct max31827_state { · line 159
Quoted 10 lines
drivers/hwmon/max31827.c +4
-2+return ret; +}static int shutdown_write (struct max31827_state *st,unsigned int reg,unsigned int mask,unsigned int val) { -unsigned int cfg; -unsigned int cnv_rate; +u16 cfg; +u16 cnv_rate;
I really do not see the point of those changes. u16 is more expensive than unsigned int on many architectures. If retained, you'll have to explain why this is needed and beneficial.
Quoted 277 lines
drivers/hwmon/max31827.c +101
-40int ret;/* @@ -125,34 +171,34 @@ static int shutdown_write(struct max31827_state *st, unsigned int reg,if (!st->enable) {if (!mask) - ret =regmap_write (st->regmap, reg, val); + ret =max31827_reg_write (st->client, reg, val);else - ret =regmap_update_bits (st->regmap, reg, mask, val); + ret =max31827_update_bits (st->client, reg, mask, val); goto unlock; } - ret =regmap_read (st->regmap,MAX31827_CONFIGURATION_REG , &cfg); + ret =max31827_reg_read (st->client,MAX31827_CONFIGURATION_REG , &cfg);if (ret) goto unlock; cnv_rate =MAX31827_CONFIGURATION_CNV_RATE_MASK & cfg; cfg = cfg & ~(MAX31827_CONFIGURATION_1SHOT_MASK |MAX31827_CONFIGURATION_CNV_RATE_MASK ); - ret =regmap_write (st->regmap,MAX31827_CONFIGURATION_REG , cfg); + ret =max31827_reg_write (st->client,MAX31827_CONFIGURATION_REG , cfg);if (ret) goto unlock;if (!mask) - ret =regmap_write (st->regmap, reg, val); + ret =max31827_reg_write (st->client, reg, val);else - ret =regmap_update_bits (st->regmap, reg, mask, val); + ret =max31827_update_bits (st->client, reg, mask, val);if (ret) goto unlock; - ret =regmap_update_bits (st->regmap,MAX31827_CONFIGURATION_REG , -MAX31827_CONFIGURATION_CNV_RATE_MASK , - cnv_rate); + ret =max31827_update_bits (st->client,MAX31827_CONFIGURATION_REG , +MAX31827_CONFIGURATION_CNV_RATE_MASK , + cnv_rate); unlock:mutex_unlock (&st->lock);@@ -198,15 +244,16 @@ static int max31827_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { struct max31827_state *st = dev_get_drvdata(dev); -unsigned int uval; +u16 uval;int ret =0 ;switch (type) {case hwmon_temp:switch (attr) {case hwmon_temp_enable: - ret =regmap_read (st->regmap, -MAX31827_CONFIGURATION_REG , &uval); + ret =max31827_reg_read (st->client, +MAX31827_CONFIGURATION_REG , + &uval);if (ret)break ;@@ -226,10 +273,10 @@ static int max31827_read(struct device *dev, enum hwmon_sensor_types type,* be changed during the conversion process. */ - ret =regmap_update_bits (st->regmap, -MAX31827_CONFIGURATION_REG , -MAX31827_CONFIGURATION_1SHOT_MASK , -1 ); + ret =max31827_update_bits (st->client, +MAX31827_CONFIGURATION_REG , +MAX31827_CONFIGURATION_1SHOT_MASK , +1 );if (ret) {mutex_unlock (&st->lock);return ret;@@ -246,7 +293,8 @@ static int max31827_read(struct device *dev, enum hwmon_sensor_types type, st->update_interval == 125)usleep_range (15000 ,20000 ); - ret =regmap_read (st->regmap,MAX31827_T_REG , &uval); + ret =max31827_reg_read (st->client,MAX31827_T_REG , + &uval);mutex_unlock (&st->lock);@@ -257,23 +305,26 @@ static int max31827_read(struct device *dev, enum hwmon_sensor_types type,break ;case hwmon_temp_max: - ret =regmap_read (st->regmap,MAX31827_TH_REG , &uval); + ret =max31827_reg_read (st->client,MAX31827_TH_REG , + &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_max_hyst: - ret =regmap_read (st->regmap,MAX31827_TH_HYST_REG , - &uval); + ret =max31827_reg_read (st->client, +MAX31827_TH_HYST_REG , + &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_max_alarm: - ret =regmap_read (st->regmap, -MAX31827_CONFIGURATION_REG , &uval); + ret =max31827_reg_read (st->client, +MAX31827_CONFIGURATION_REG , + &uval);if (ret)break ;@@ -281,23 +332,25 @@ static int max31827_read(struct device *dev, enum hwmon_sensor_types type, uval);break ;case hwmon_temp_min: - ret =regmap_read (st->regmap,MAX31827_TL_REG , &uval); + ret =max31827_reg_read (st->client,MAX31827_TL_REG , + &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_min_hyst: - ret =regmap_read (st->regmap,MAX31827_TL_HYST_REG , - &uval); + ret =max31827_reg_read (st->client,MAX31827_TL_HYST_REG , + &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_min_alarm: - ret =regmap_read (st->regmap, -MAX31827_CONFIGURATION_REG , &uval); + ret =max31827_reg_read (st->client, +MAX31827_CONFIGURATION_REG , + &uval);if (ret)break ;@@ -313,8 +366,9 @@ static int max31827_read(struct device *dev, enum hwmon_sensor_types type,case hwmon_chip:if (attr == hwmon_chip_update_interval) { - ret =regmap_read (st->regmap, -MAX31827_CONFIGURATION_REG , &uval); + ret =max31827_reg_read (st->client, +MAX31827_CONFIGURATION_REG , + &uval);if (ret)break ;@@ -355,11 +409,11 @@ static int max31827_write(struct device *dev, enum hwmon_sensor_types type, st->enable = val; - ret =regmap_update_bits (st->regmap, -MAX31827_CONFIGURATION_REG , -MAX31827_CONFIGURATION_1SHOT_MASK | -MAX31827_CONFIGURATION_CNV_RATE_MASK , -MAX31827_DEVICE_ENABLE (val)); + ret =max31827_update_bits (st->client, +MAX31827_CONFIGURATION_REG , +MAX31827_CONFIGURATION_1SHOT_MASK | +MAX31827_CONFIGURATION_CNV_RATE_MASK , +MAX31827_DEVICE_ENABLE (val));mutex_unlock (&st->lock);@@ -402,10 +456,10 @@ static int max31827_write(struct device *dev, enum hwmon_sensor_types type, res =FIELD_PREP (MAX31827_CONFIGURATION_CNV_RATE_MASK , res); - ret =regmap_update_bits (st->regmap, -MAX31827_CONFIGURATION_REG , -MAX31827_CONFIGURATION_CNV_RATE_MASK , - res); + ret =max31827_update_bits (st->client, +MAX31827_CONFIGURATION_REG , +MAX31827_CONFIGURATION_CNV_RATE_MASK , + res);if (ret)return ret;@@ -425,10 +479,10 @@ static ssize_t temp1_resolution_show(struct device *dev, char *buf) {struct max31827_state *st =dev_get_drvdata (dev); -unsigned int val; +u16 val;int ret; - ret =regmap_read (st->regmap,MAX31827_CONFIGURATION_REG , &val); + ret =max31827_reg_read (st->client,MAX31827_CONFIGURATION_REG , &val);if (ret)return ret;@@ -473,10 +527,63 @@ static ssize_t temp1_resolution_store(struct device *dev,return ret ? ret : count; } +static ssize_t pec_show (struct device *dev,struct device_attribute *devattr, +char *buf) +{ +struct max31827_state *st =dev_get_drvdata (dev); +struct i2c_client *client = st->client; + +return scnprintf (buf,PAGE_SIZE ,"%d\n" , !!(client->flags &I2C_CLIENT_PEC )); +} + +static ssize_t pec_store (struct device *dev,struct device_attribute *devattr, +const char *buf,size_t count) +{ +struct max31827_state *st =dev_get_drvdata (dev); +struct i2c_client *client = st->client; +unsigned int val; +u16 val2; +int err; + + err =kstrtouint (buf,10 , &val); +if (err <0 ) +return err; + + val2 =FIELD_PREP (MAX31827_CONFIGURATION_PEC_EN_MASK , val); + +if (err) +return err; + +switch (val) { +case 0 : + client->flags &= ~I2C_CLIENT_PEC ; + err =max31827_update_bits (client,MAX31827_CONFIGURATION_REG , +MAX31827_CONFIGURATION_PEC_EN_MASK , + val2); +if (err) +return err; +break ; +case 1 : + err =max31827_update_bits (client,MAX31827_CONFIGURATION_REG , +MAX31827_CONFIGURATION_PEC_EN_MASK , + val2); +if (err) +return err; + client->flags |=I2C_CLIENT_PEC ; +break ; +default : +return -EINVAL ; + } + +return count; +} +static DEVICE_ATTR_RW (temp1_resolution); +static DEVICE_ATTR_RW (pec);static struct attribute *max31827_attrs[] = { &dev_attr_temp1_resolution.attr, + &dev_attr_pec.attr,NULL };ATTRIBUTE_GROUPS (max31827);
drivers/hwmon/max31827.c static const struct i2c_device_id max31827_i2c_ids[] = { · line 601
Quoted 8 lines
drivers/hwmon/max31827.c +2
-2@@ -489,9 +596,9 @@ static const struct i2c_device_id max31827_i2c_ids[] = { };MODULE_DEVICE_TABLE (i2c, max31827_i2c_ids); -static int max31827_init_client (struct max31827_state *st, -struct device *dev) +static int max31827_init_client (struct max31827_state *st) { +struct device *dev = &st->client->dev;
Now we are absolutely down to personal preference changes. I am not at all inclined to accept such changes, sorry.
Including such changes means I'll have to put extra scrutiny on your patch submissions in the future to ensure that you don't try to sneak in similar changes, which I find quite frustrating. Is that really necessary ?
Guenter
Quoted 32 lines
drivers/hwmon/max31827.c +3
-7struct fwnode_handle *fwnode;unsigned int res =0 ;u32 data, lsb_idx;@@ -575,7 +682,7 @@ static int max31827_init_client(struct max31827_state *st, } } -return regmap_write (st->regmap,MAX31827_CONFIGURATION_REG , res); +return max31827_reg_write (st->client,MAX31827_CONFIGURATION_REG , res); }static const struct hwmon_channel_info *max31827_info[] = {@@ -613,17 +720,13 @@ static int max31827_probe(struct i2c_client *client)return -ENOMEM ;mutex_init (&st->lock); - - st->regmap =devm_regmap_init_i2c (client, &max31827_regmap); -if (IS_ERR (st->regmap)) -return dev_err_probe (dev,PTR_ERR (st->regmap), -"Failed to allocate regmap.\n" ); + st->client = client; err =devm_regulator_get_enable (dev,"vref" );if (err)return dev_err_probe (dev, err,"failed to enable regulator\n" ); - err =max31827_init_client (st, dev); + err =max31827_init_client (st);if (err)return err;
Quoted 22 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Thursday, December 14, 2023 6:10 PM
To: Matyas, Daniel <[email protected]>
Cc: Jean Delvare <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 1/3] hwmon: max31827: Add PEC support[External]
Quoted 5 lines · Daniel Matyas
Removed regmap and used my functions to read, write and update bits. In these functions
i2c_smbus_helper functions are used. These check if there were any PEC errors during read. In the write function, if PEC is enabled, I check for PEC Error bit, to see if there were any errors.
Quoted 5 lines
Quoted 1 line
Signed-off-by Daniel Matyas <[email protected]>The "PEC" attribute needs to be attached to the I2C device. See
lm90.corpmbus_core.cfor examples.
I added pec_show() and pec_store() functions and created the pec file within the max31827_groups. I did not set the flags, because I want them to be set only in pec_store. By default the PEC flag should not be set.
Quoted 10 lines
The changes, if indeed needed, do not warant dropping regmap. You will need to explain why the
reg_readandreg_writecallbacks provideed by regmap can not be used.On top of that, it is not clear why regmap can't be used in the first place. It seems that the major change is that one needs to read the configuration register after a write to see if there was a PEC error. It is not immediately obvious why that additional read (if indeed necessary) would require regmap support to be dropped.
So I am not sure about this, but it seems to me, that regmap_write is not sending a PEC byte and regmap_read is not checking the PEC byte by default. My rationale was: i2c_smbus_write_word_data() is using the i2c_xfer function, which has as argument the client->flags. So, if I2C_CLIENT_PEC is set in client->flags, that would be transmitted by i2c_xfer. I am not convinced about this, but lm90 and pmbus_core are not using regmap, so I went ahead and replaced it.
If what I am thinking is wrong, please correct me.
Quoted 534 lines
Regarding "if indeed necessary": There needs to be a comment explaining that the device will return ACK even after a packet with bad PEC is received.
Quoted 3 lines
--- Documentation/hwmon/max31827.rst | 14 +- drivers/hwmon/max31827.c | 219 +++++++++++++++++++++++--------
Documentation/hwmon/max31827.rst The Fault Queue bits select how many
Quoted 8 lines
2 files changed, 171 insertions(+), 62 deletions(-)Documentation/hwmon/max31827.rst +0
-0@@ -131,7 +131,13 @@ The Fault Queue bits select how manyconsecutive temperature faults must occur
Documentation/hwmon/max31827.rst The Fault Queue bits select how many · line 131
Quoted 1 line
Documentation/hwmon/max31827.rst +0
-0before overtemperature or undertemperature faults are indicated inthe
Documentation/hwmon/max31827.rst The Fault Queue bits select how many consecutive temperature faults must occur
Quoted 7 lines
Documentation/hwmon/max31827.rst +1
-4corresponding status bits. -Notes ------ - -PEC is not implemented. +PEC (packet error checking) can be enabled from the "pec" deviceattribute.
Documentation/hwmon/max31827.rst The Fault Queue bits select how many · line 135
Quoted 1 line
Documentation/hwmon/max31827.rst +1
-0+If PEC is enabled, a PEC byte is appended to the end of each messagetransfer.
Documentation/hwmon/max31827.rst The Fault Queue bits select how many · line 139
Quoted 4 lines
Documentation/hwmon/max31827.rst +4
-0+This is a CRC-8 byte that is calculated on all of the message bytes +(including the address/read/write byte). The last device to transmit +a data byte also transmits the PEC byte. The master transmits the PEC +byte after a write transaction, and the MAX31827 transmits the PECbyte after a read transaction.
Documentation/hwmon/max31827.rst The Fault Queue bits select how many · line 141
Quoted 2 lines
Documentation/hwmon/max31827.rst +2
-0+ +The read PEC error is handled inside the
i2c_smbus_read_word_swapped()function.drivers/hwmon/max31827.c
Quoted 4 lines
Documentation/hwmon/max31827.rst +2
-0+To check if the write had any PEC error a read is performed on the +configuration register, to check the PEC Error bit.drivers/hwmon/max31827.c +0
-0index
Quoted 14 lines
71ad3934dfb6..db93492193bd100644drivers/hwmon/max31827.c +1
-1@@ -11,8 +11,8 @@#include <linux/hwmon.h> #include <linux/i2c.h> #include <linux/mutex.h> -#include <linux/regmap.h> #include <linux/regulator/consumer.h> +#include <linux/hwmon-sysfs.h> #include <linux/of_device.h> #define MAX31827_T_REG 0x0drivers/hwmon/max31827.c line 26
Quoted 3 lines
drivers/hwmon/max31827.c +0
-0@@ -24,11 +24,13 @@#define MAX31827_CONFIGURATION_1SHOT_MASK BIT(0)#define MAX31827_CONFIGURATION_CNV_RATE_MASK GENMASK(3, 1)drivers/hwmon/max31827.c
Quoted 3 lines
drivers/hwmon/max31827.c +1
-0+#define MAX31827_CONFIGURATION_PEC_EN_MASK BIT(4)#define MAX31827_CONFIGURATION_TIMEOUT_MASK BIT(5)#define MAX31827_CONFIGURATION_RESOLUTION_MASK GENMASK(7, 6)Quoted 18 lines
drivers/hwmon/max31827.c +2
-1#define MAX31827_CONFIGURATION_ALRM_POL_MASK BIT(8)#define MAX31827_CONFIGURATION_COMP_INT_MASK BIT(9)#define MAX31827_CONFIGURATION_FLT_Q_MASK GENMASK(11, 10) +#define MAX31827_CONFIGURATION_PEC_ERR_MASK BIT(13)#define MAX31827_CONFIGURATION_U_TEMP_STAT_MASK BIT(14)#define MAX31827_CONFIGURATION_O_TEMP_STAT_MASK BIT(15)@@ -94,23 +96,67 @@ struct max31827_state {* Prevent simultaneous access to the i2c client. */ struct mutex lock; -struct regmap *regmap;bool enable;unsigned int resolution;unsigned int update_interval; +struct i2c_client *client; };drivers/hwmon/max31827.c struct max31827_state { · line 109
Quoted 10 lines
drivers/hwmon/max31827.c +5
-5-static const struct regmap_config max31827_regmap = { - .reg_bits =8 , - .val_bits =16 , - .max_register =0xA , -}; +static int max31827_reg_read (struct i2c_client *client,u8 reg,u16 +*val) { +u16 tmp =i2c_smbus_read_word_swapped (client, reg); + +if (tmp <0 )An u16 variable will never be negative.
drivers/hwmon/max31827.c struct max31827_state { · line 114
Quoted 5 lines
drivers/hwmon/max31827.c +5
-0+return tmp; + + *val = tmp; +return 0 ; +}If regmap can indeed not be used, it is unnecessary to provide a pointer to the return value. Instead, just like with smbus calls, the error return and the return value can be combined. Adding this function just to separate error from return value adds zero value (and, as can be seen from the above, actually adds an opportunity to introduce bugs).
drivers/hwmon/max31827.c struct max31827_state { · line 125
Quoted 11 lines
drivers/hwmon/max31827.c +11
-0+ +static int max31827_reg_write (struct i2c_client *client,u8 reg,u16 +val) { +u16 cfg; +int ret; + + ret =i2c_smbus_write_word_swapped (client, reg, val); +if (ret) +return ret; + +// If PEC is not enabled, return with success Do not mix comment styles. The rest of the driver doesn't use C++ comments.
Besides, the comment does not add any value.drivers/hwmon/max31827.c struct max31827_state {
Quoted 4 lines
drivers/hwmon/max31827.c +4
-0+if (!(client->flags &I2C_CLIENT_PEC )) +return 0 ; + + ret = max31827_reg_read(client,
MAX31827_CONFIGURATION_REG, &cfg);drivers/hwmon/max31827.c struct max31827_state { · line 135
Quoted 6 lines
drivers/hwmon/max31827.c +6
-0+if (ret) +return ret; + +if (cfg &MAX31827_CONFIGURATION_PEC_ERR_MASK ) +return -EBADMSG ; +EBADMSG is "Not a data message". I don't think that is appropriate here.
I would very much prefer
if (client->flags & I2C_CLIENT_PEC) { ... }Quoted 16 lines
drivers/hwmon/max31827.c +16
-0+return 0 ; +} + +static int max31827_update_bits (struct i2c_client *client,u8 reg, +u16 mask,u16 val) +{ +u16 tmp; +int ret; + + ret =max31827_reg_read (client, reg, &tmp); +if (ret) +return ret; + + tmp = (tmp & ~mask) | (val & mask); + ret =max31827_reg_write (client, reg, tmp); +drivers/hwmon/max31827.c struct max31827_state { · line 159
Quoted 10 lines
drivers/hwmon/max31827.c +4
-2+return ret; +}static int shutdown_write (struct max31827_state *st,unsigned int reg,unsigned int mask,unsigned int val) { -unsigned int cfg; -unsigned int cnv_rate; +u16 cfg; +u16 cnv_rate;I really do not see the point of those changes. u16 is more expensive than unsigned int on many architectures. If retained, you'll have to explain why this is needed and beneficial.
drivers/hwmon/max31827.c static int shutdown_write(struct
Quoted 4 lines
drivers/hwmon/max31827.c +0
-0int ret;/* @@ -125,34 +171,34 @@ static int shutdown_write(struct
max31827_statedrivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 8 lines
drivers/hwmon/max31827.c +1
-2*st, unsigned int reg, if (!st->enable) {if (!mask) - ret =regmap_write (st->regmap, reg, val); + ret =max31827_reg_write (st->client, reg, val);else - ret = regmap_update_bits(st->regmap, reg, mask,val);
drivers/hwmon/max31827.c static int shutdown_write(struct · line 177
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_update_bits(st->client, reg,mask, val);
drivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-1goto unlock; } - ret = regmap_read(st->regmap,
MAX31827_CONFIGURATION_REG, &cfg);drivers/hwmon/max31827.c static int shutdown_write(struct · line 181
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 8 lines
drivers/hwmon/max31827.c +1
-1+&cfg);if (ret) goto unlock; cnv_rate =MAX31827_CONFIGURATION_CNV_RATE_MASK & cfg; cfg = cfg & ~(MAX31827_CONFIGURATION_1SHOT_MASK |MAX31827_CONFIGURATION_CNV_RATE_MASK ); - ret = regmap_write(st->regmap,
MAX31827_CONFIGURATION_REG, cfg);drivers/hwmon/max31827.c static int shutdown_write(struct · line 189
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_write(st->client,
MAX31827_CONFIGURATION_REG,Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+cfg);if (ret) goto unlock;if (!mask)drivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 10 lines
drivers/hwmon/max31827.c +2
-3- ret =regmap_write (st->regmap, reg, val); + ret =max31827_reg_write (st->client, reg, val); else - ret =regmap_update_bits (st->regmap, reg, mask, val); + ret =max31827_update_bits (st->client, reg, mask, val);if (ret) goto unlock; - ret = regmap_update_bits(st->regmap,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int shutdown_write(struct · line 155
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int shutdown_write(struct · line 202
Quoted 2 lines
drivers/hwmon/max31827.c +1
-1- cnv_rate); + ret = max31827_update_bits(st->client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int shutdown_write(struct · line 203
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ cnv_rate); unlock:mutex_unlock (&st->lock);@@ -198,15 +244,16 @@ static int max31827_read(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 13 lines
drivers/hwmon/max31827.c +1
-3u32 attr, int channel, long *val) { struct max31827_state *st = dev_get_drvdata(dev); -unsigned int uval; +u16 uval;int ret =0 ;switch (type) {case hwmon_temp:switch (attr) {case hwmon_temp_enable: - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 255
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ &uval);if (ret)break ;@@ -226,10 +273,10 @@ static int max31827_read(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 273
Quoted 1 line
drivers/hwmon/max31827.c +0
-0* be changed during the conversion process.
drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-2*/ - ret = regmap_update_bits(st->regmap, -
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 231
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_1SHOT_MASK,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 3 lines
drivers/hwmon/max31827.c +2
-1- 1); + ret = max31827_update_bits(st->client, +
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 278
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_1SHOT_MASK,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ 1);if (ret) {mutex_unlock (&st->lock);return ret;@@ -246,7 +293,8 @@ static int max31827_read(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-1st->update_interval == 125)usleep_range (15000 ,20000 ); - ret = regmap_read(st->regmap,
MAX31827_T_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 296
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_T_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 261
Quoted 10 lines
drivers/hwmon/max31827.c +1
-1+ &uval);mutex_unlock (&st->lock);@@ -257,23 +305,26 @@ static int max31827_read(struct device *dev,enum hwmon_sensor_types type, break;case hwmon_temp_max: - ret = regmap_read(st->regmap,
MAX31827_TH_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 309
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_TH_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type, · line 275
Quoted 8 lines
drivers/hwmon/max31827.c +1
-1+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_max_hyst: - ret = regmap_read(st->regmap,
MAX31827_TH_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 3 lines
drivers/hwmon/max31827.c +2
-1- &uval); + ret = max31827_reg_read(st->client, +MAX31827_TH_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 9 lines
drivers/hwmon/max31827.c +1
-2+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_max_alarm: - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 327
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ &uval);if (ret)break ;@@ -281,23 +332,25 @@ static int max31827_read(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type, · line 299
Quoted 4 lines
drivers/hwmon/max31827.c +0
-1uval);break ;case hwmon_temp_min: - ret = regmap_read(st->regmap,
MAX31827_TL_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 335
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_TL_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type, · line 299
Quoted 8 lines
drivers/hwmon/max31827.c +1
-1+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_min_hyst: - ret = regmap_read(st->regmap,
MAX31827_TL_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 343
Quoted 2 lines
drivers/hwmon/max31827.c +1
-1- &uval); + ret = max31827_reg_read(st->client,
MAX31827_TL_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 9 lines
drivers/hwmon/max31827.c +1
-2+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_min_alarm: - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 352
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ &uval);if (ret)break ;@@ -313,8 +366,9 @@ static int max31827_read(struct device *dev,enum
drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 6 lines
drivers/hwmon/max31827.c +0
-2hwmon_sensor_types type, case hwmon_chip: if (attr == hwmon_chip_update_interval) { - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 371
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 360
Quoted 11 lines
drivers/hwmon/max31827.c +1
-2+ &uval);if (ret)break ;@@ -355,11 +409,11 @@ static int max31827_write(struct device *dev,enum hwmon_sensor_types type, st->enable = val; - ret = regmap_update_bits(st->regmap, -
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 361
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_1SHOT_MASK|drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 362
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 363
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_DEVICE_ENABLE(val));drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 414
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_update_bits(st->client, +
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 415
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_1SHOT_MASK|drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 416
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 417
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_DEVICE_ENABLE(val));drivers/hwmon/max31827.c static int max31827_write(struct device *dev,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-0mutex_unlock (&st->lock);@@ -402,10 +456,10 @@ static int max31827_write(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 456
Quoted 1 line
drivers/hwmon/max31827.c +0
-0res =FIELD_PREP(MAX31827_CONFIGURATION_CNV_RATE_MASK,
drivers/hwmon/max31827.c static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-2res); - ret = regmap_update_bits(st->regmap, -
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 407
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
Quoted 3 lines
drivers/hwmon/max31827.c +2
-1- res); + ret = max31827_update_bits(st->client, +
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 461
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static ssize_t temp1_resolution_show(struct
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ res);if (ret)return ret;@@ -425,10 +479,10 @@ static ssize_t temp1_resolution_show(structdevice *dev,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_show(struct device *dev,
Quoted 8 lines
drivers/hwmon/max31827.c +1
-2char *buf) {struct max31827_state *st =dev_get_drvdata (dev); -unsigned int val; +u16 val;int ret; - ret = regmap_read(st->regmap,
MAX31827_CONFIGURATION_REG, &val);drivers/hwmon/max31827.c static ssize_t temp1_resolution_show(struct · line 485
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+&val);if (ret)return ret;@@ -473,10 +527,63 @@ static ssize_t temp1_resolution_store(structdevice *dev,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 4 lines
drivers/hwmon/max31827.c +1
-0return ret ? ret : count; } +static ssize_t pec_show(struct device *dev, struct device_attribute*devattr,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 9 lines
drivers/hwmon/max31827.c +9
-0+ char *buf) +{ +struct max31827_state *st =dev_get_drvdata (dev); +struct i2c_client *client = st->client; + +return scnprintf (buf,PAGE_SIZE ,"%d\n" , !!(client->flags & +I2C_CLIENT_PEC )); } + +static ssize_t pec_store(struct device *dev, struct device_attribute*devattr,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 13 lines
drivers/hwmon/max31827.c +13
-0+ const char *buf, size_t count) +{ +struct max31827_state *st =dev_get_drvdata (dev); +struct i2c_client *client = st->client; +unsigned int val; +u16 val2; +int err; + + err =kstrtouint (buf,10 , &val); +if (err <0 ) +return err; + + val2 = FIELD_PREP(MAX31827_CONFIGURATION_PEC_EN_MASK,val);
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 8 lines
drivers/hwmon/max31827.c +8
-0+ +if (err) +return err; + +switch (val) { +case 0 : + client->flags &= ~I2C_CLIENT_PEC ; + err = max31827_update_bits(client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct · line 561
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_PEC_EN_MASK,drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 6 lines
drivers/hwmon/max31827.c +6
-0+ val2); +if (err) +return err; +break ; +case 1 : + err = max31827_update_bits(client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct · line 568
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_PEC_EN_MASK,drivers/hwmon/max31827.c static const struct i2c_device_id
Quoted 22 lines
drivers/hwmon/max31827.c +14
-0+ val2); +if (err) +return err; + client->flags |=I2C_CLIENT_PEC ; +break ; +default : +return -EINVAL ; + } + +return count; +} +static DEVICE_ATTR_RW (temp1_resolution); +static DEVICE_ATTR_RW (pec);static struct attribute *max31827_attrs[] = { &dev_attr_temp1_resolution.attr, + &dev_attr_pec.attr,NULL };ATTRIBUTE_GROUPS (max31827);@@ -489,9 +596,9 @@ static const struct i2c_device_idmax31827_i2c_ids[] = {
drivers/hwmon/max31827.c static const struct i2c_device_id max31827_i2c_ids[] = { · line 601
Quoted 8 lines
drivers/hwmon/max31827.c +2
-2};MODULE_DEVICE_TABLE (i2c, max31827_i2c_ids); -static int max31827_init_client (struct max31827_state *st, -struct device *dev) +static int max31827_init_client (struct max31827_state *st) { +struct device *dev = &st->client->dev;Now we are absolutely down to personal preference changes. I am not at all inclined to accept such changes, sorry.
Quoted 6 lines
Including such changes means I'll have to put extra scrutiny on your patch submissions in the future to ensure that you don't try to sneak in similar changes, which I find quite frustrating. Is that really necessary ?
Guenter
Sorry for this! I thought, if I am adding client to the private structure I might as well delete the second parameter of init_client, because I can easily retrieve the device structure from client. I added this line so that the changes to the code are kept to a minimum.
Quoted 39 lines
drivers/hwmon/max31827.c static int max31827_init_client(struct
Quoted 4 lines
drivers/hwmon/max31827.c +0
-0struct fwnode_handle *fwnode;unsigned int res =0 ;u32 data, lsb_idx;@@ -575,7 +682,7 @@ static int max31827_init_client(struct
max31827_state*st,drivers/hwmon/max31827.c static int max31827_init_client(struct · line 578
Quoted 4 lines
drivers/hwmon/max31827.c +0
-1} } - return regmap_write(st->regmap,
MAX31827_CONFIGURATION_REG, res);drivers/hwmon/max31827.c static int max31827_init_client(struct · line 685
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ return max31827_reg_write(st->client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_init_client(struct
Quoted 5 lines
drivers/hwmon/max31827.c +1
-1+res); } static const struct hwmon_channel_info *max31827_info[] = { @@ -613,17 +720,13 @@ static int max31827_probe(struct i2c_client*client)
drivers/hwmon/max31827.c
Quoted 5 lines
return
-ENOMEM;mutex_init(&st->lock);drivers/hwmon/max31827.c +0
-2- - st->regmap = devm_regmap_init_i2c(client,
&max31827_regmap);drivers/hwmon/max31827.c static int max31827_probe(struct i2c_client *client)
Quoted 8 lines
drivers/hwmon/max31827.c +1
-3-if (IS_ERR (st->regmap)) -return dev_err_probe (dev,PTR_ERR (st->regmap), -"Failed to allocate regmap.\n" ); + st->client = client; err =devm_regulator_get_enable (dev,"vref" );if (err) return dev_err_probe(dev, err, "failed to enableregulator\n");
Quoted 6 lines
drivers/hwmon/max31827.c +1
-1- err =max31827_init_client (st, dev); + err =max31827_init_client (st);if (err)return err;
Guenter Roeck
maintainerQuoted 22 lines · Daniel
Quoted 22 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Thursday, December 14, 2023 6:10 PM
To: Matyas, Daniel <[email protected]>
Cc: Jean Delvare <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 1/3] hwmon: max31827: Add PEC support[External]
Quoted 5 lines · Daniel Matyas
Removed regmap and used my functions to read, write and update bits. In these functions
i2c_smbus_helper functions are used. These check if there were any PEC errors during read. In the write function, if PEC is enabled, I check for PEC Error bit, to see if there were any errors.
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Daniel Matyas <[email protected]>The "PEC" attribute needs to be attached to the I2C device. See
lm90.corpmbus_core.cfor examples.I added
pec_show()andpec_store()functions and created the pec file within themax31827_groups. I did not set the flags, because I want them to be set only inpec_store. By default the PEC flag should not be set.
That is not the point. Again,
Quoted 2 lines
Quoted 2 lines
The "PEC" attribute needs to be attached to the I2C device. See
lm90.corpmbus_core.cfor examples.
That is not about regmap, it is about the location of the "pec" attribute.
Quoted 11 lines
Quoted 10 lines
The changes, if indeed needed, do not warant dropping regmap. You will need to explain why the
reg_readandreg_writecallbacks provideed by regmap can not be used.On top of that, it is not clear why regmap can't be used in the first place. It seems that the major change is that one needs to read the configuration register after a write to see if there was a PEC error. It is not immediately obvious why that additional read (if indeed necessary) would require regmap support to be dropped.
Quoted 4 lines
So I am not sure about this, but it seems to me, that
regmap_writeis not sending a PEC byte andregmap_readis not checking the PEC byte by default. My rationale was:i2c_smbus_write_word_data()is using thei2c_xferfunction, which has as argument theclient->flags. So, ifI2C_CLIENT_PECis set inclient->flags, that would be transmitted byi2c_xfer. I am not convinced about this, but lm90 andpmbus_coreare not using regmap, so I went ahead and replaced it.If what I am thinking is wrong, please correct me.
regmap uses smbus functions to access the chip if the underlying i2c driver supports SMBus word operations. I fail to see the difference to your code. Sure, max31827_reg_write() executes another read after the write, but that is again a 16-bit operation and might we well be implemented as another regmap operation to read the status register.
It would be possible to replace the regmap i2c code, use raw regmap code instead, and provide ->read and ->write callbacks in struct regmap_config, but I am not convinced that this would be beneficial.
Either case, sorry, I can not follow your line of argument.
Quoted 534 lines
Quoted 534 lines
Regarding "if indeed necessary": There needs to be a comment explaining that the device will return ACK even after a packet with bad PEC is received.
Quoted 3 lines
--- Documentation/hwmon/max31827.rst | 14 +- drivers/hwmon/max31827.c | 219 +++++++++++++++++++++++--------
Documentation/hwmon/max31827.rst The Fault Queue bits select how many
Quoted 8 lines
2 files changed, 171 insertions(+), 62 deletions(-)Documentation/hwmon/max31827.rst +0
-0@@ -131,7 +131,13 @@ The Fault Queue bits select how manyconsecutive temperature faults must occur
Documentation/hwmon/max31827.rst The Fault Queue bits select how many · line 131
Quoted 1 line
Documentation/hwmon/max31827.rst +0
-0before overtemperature or undertemperature faults are indicated inthe
Documentation/hwmon/max31827.rst The Fault Queue bits select how many consecutive temperature faults must occur
Quoted 7 lines
Documentation/hwmon/max31827.rst +1
-4corresponding status bits. -Notes ------ - -PEC is not implemented. +PEC (packet error checking) can be enabled from the "pec" deviceattribute.
Documentation/hwmon/max31827.rst The Fault Queue bits select how many · line 135
Quoted 1 line
Documentation/hwmon/max31827.rst +1
-0+If PEC is enabled, a PEC byte is appended to the end of each messagetransfer.
Documentation/hwmon/max31827.rst The Fault Queue bits select how many · line 139
Quoted 4 lines
Documentation/hwmon/max31827.rst +4
-0+This is a CRC-8 byte that is calculated on all of the message bytes +(including the address/read/write byte). The last device to transmit +a data byte also transmits the PEC byte. The master transmits the PEC +byte after a write transaction, and the MAX31827 transmits the PECbyte after a read transaction.
Documentation/hwmon/max31827.rst The Fault Queue bits select how many · line 141
Quoted 2 lines
Documentation/hwmon/max31827.rst +2
-0+ +The read PEC error is handled inside the
i2c_smbus_read_word_swapped()function.drivers/hwmon/max31827.c
Quoted 4 lines
Documentation/hwmon/max31827.rst +2
-0+To check if the write had any PEC error a read is performed on the +configuration register, to check the PEC Error bit.drivers/hwmon/max31827.c +0
-0index
Quoted 14 lines
71ad3934dfb6..db93492193bd100644drivers/hwmon/max31827.c +1
-1@@ -11,8 +11,8 @@#include <linux/hwmon.h> #include <linux/i2c.h> #include <linux/mutex.h> -#include <linux/regmap.h> #include <linux/regulator/consumer.h> +#include <linux/hwmon-sysfs.h> #include <linux/of_device.h> #define MAX31827_T_REG 0x0drivers/hwmon/max31827.c line 26
Quoted 3 lines
drivers/hwmon/max31827.c +0
-0@@ -24,11 +24,13 @@#define MAX31827_CONFIGURATION_1SHOT_MASK BIT(0)#define MAX31827_CONFIGURATION_CNV_RATE_MASK GENMASK(3, 1)drivers/hwmon/max31827.c
Quoted 3 lines
drivers/hwmon/max31827.c +1
-0+#define MAX31827_CONFIGURATION_PEC_EN_MASK BIT(4)#define MAX31827_CONFIGURATION_TIMEOUT_MASK BIT(5)#define MAX31827_CONFIGURATION_RESOLUTION_MASK GENMASK(7, 6)Quoted 18 lines
drivers/hwmon/max31827.c +2
-1#define MAX31827_CONFIGURATION_ALRM_POL_MASK BIT(8)#define MAX31827_CONFIGURATION_COMP_INT_MASK BIT(9)#define MAX31827_CONFIGURATION_FLT_Q_MASK GENMASK(11, 10) +#define MAX31827_CONFIGURATION_PEC_ERR_MASK BIT(13)#define MAX31827_CONFIGURATION_U_TEMP_STAT_MASK BIT(14)#define MAX31827_CONFIGURATION_O_TEMP_STAT_MASK BIT(15)@@ -94,23 +96,67 @@ struct max31827_state {* Prevent simultaneous access to the i2c client. */ struct mutex lock; -struct regmap *regmap;bool enable;unsigned int resolution;unsigned int update_interval; +struct i2c_client *client; };drivers/hwmon/max31827.c struct max31827_state { · line 109
Quoted 10 lines
drivers/hwmon/max31827.c +5
-5-static const struct regmap_config max31827_regmap = { - .reg_bits =8 , - .val_bits =16 , - .max_register =0xA , -}; +static int max31827_reg_read (struct i2c_client *client,u8 reg,u16 +*val) { +u16 tmp =i2c_smbus_read_word_swapped (client, reg); + +if (tmp <0 )An u16 variable will never be negative.
drivers/hwmon/max31827.c struct max31827_state { · line 114
Quoted 5 lines
drivers/hwmon/max31827.c +5
-0+return tmp; + + *val = tmp; +return 0 ; +}If regmap can indeed not be used, it is unnecessary to provide a pointer to the return value. Instead, just like with smbus calls, the error return and the return value can be combined. Adding this function just to separate error from return value adds zero value (and, as can be seen from the above, actually adds an opportunity to introduce bugs).
drivers/hwmon/max31827.c struct max31827_state { · line 125
Quoted 11 lines
drivers/hwmon/max31827.c +11
-0+ +static int max31827_reg_write (struct i2c_client *client,u8 reg,u16 +val) { +u16 cfg; +int ret; + + ret =i2c_smbus_write_word_swapped (client, reg, val); +if (ret) +return ret; + +// If PEC is not enabled, return with success Do not mix comment styles. The rest of the driver doesn't use C++ comments.
Besides, the comment does not add any value.drivers/hwmon/max31827.c struct max31827_state {
Quoted 4 lines
drivers/hwmon/max31827.c +4
-0+if (!(client->flags &I2C_CLIENT_PEC )) +return 0 ; + + ret = max31827_reg_read(client,
MAX31827_CONFIGURATION_REG, &cfg);drivers/hwmon/max31827.c struct max31827_state { · line 135
Quoted 6 lines
drivers/hwmon/max31827.c +6
-0+if (ret) +return ret; + +if (cfg &MAX31827_CONFIGURATION_PEC_ERR_MASK ) +return -EBADMSG ; +EBADMSG is "Not a data message". I don't think that is appropriate here.
I would very much prefer
if (client->flags & I2C_CLIENT_PEC) { ... }Quoted 16 lines
drivers/hwmon/max31827.c +16
-0+return 0 ; +} + +static int max31827_update_bits (struct i2c_client *client,u8 reg, +u16 mask,u16 val) +{ +u16 tmp; +int ret; + + ret =max31827_reg_read (client, reg, &tmp); +if (ret) +return ret; + + tmp = (tmp & ~mask) | (val & mask); + ret =max31827_reg_write (client, reg, tmp); +drivers/hwmon/max31827.c struct max31827_state { · line 159
Quoted 10 lines
drivers/hwmon/max31827.c +4
-2+return ret; +}static int shutdown_write (struct max31827_state *st,unsigned int reg,unsigned int mask,unsigned int val) { -unsigned int cfg; -unsigned int cnv_rate; +u16 cfg; +u16 cnv_rate;I really do not see the point of those changes. u16 is more expensive than unsigned int on many architectures. If retained, you'll have to explain why this is needed and beneficial.
drivers/hwmon/max31827.c static int shutdown_write(struct
Quoted 4 lines
drivers/hwmon/max31827.c +0
-0int ret;/* @@ -125,34 +171,34 @@ static int shutdown_write(struct
max31827_statedrivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 8 lines
drivers/hwmon/max31827.c +1
-2*st, unsigned int reg, if (!st->enable) {if (!mask) - ret =regmap_write (st->regmap, reg, val); + ret =max31827_reg_write (st->client, reg, val);else - ret = regmap_update_bits(st->regmap, reg, mask,val);
drivers/hwmon/max31827.c static int shutdown_write(struct · line 177
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_update_bits(st->client, reg,mask, val);
drivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-1goto unlock; } - ret = regmap_read(st->regmap,
MAX31827_CONFIGURATION_REG, &cfg);drivers/hwmon/max31827.c static int shutdown_write(struct · line 181
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 8 lines
drivers/hwmon/max31827.c +1
-1+&cfg);if (ret) goto unlock; cnv_rate =MAX31827_CONFIGURATION_CNV_RATE_MASK & cfg; cfg = cfg & ~(MAX31827_CONFIGURATION_1SHOT_MASK |MAX31827_CONFIGURATION_CNV_RATE_MASK ); - ret = regmap_write(st->regmap,
MAX31827_CONFIGURATION_REG, cfg);drivers/hwmon/max31827.c static int shutdown_write(struct · line 189
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_write(st->client,
MAX31827_CONFIGURATION_REG,Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+cfg);if (ret) goto unlock;if (!mask)drivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 10 lines
drivers/hwmon/max31827.c +2
-3- ret =regmap_write (st->regmap, reg, val); + ret =max31827_reg_write (st->client, reg, val); else - ret =regmap_update_bits (st->regmap, reg, mask, val); + ret =max31827_update_bits (st->client, reg, mask, val);if (ret) goto unlock; - ret = regmap_update_bits(st->regmap,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int shutdown_write(struct · line 155
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int shutdown_write(struct · line 202
Quoted 2 lines
drivers/hwmon/max31827.c +1
-1- cnv_rate); + ret = max31827_update_bits(st->client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int shutdown_write(struct · line 203
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ cnv_rate); unlock:mutex_unlock (&st->lock);@@ -198,15 +244,16 @@ static int max31827_read(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 13 lines
drivers/hwmon/max31827.c +1
-3u32 attr, int channel, long *val) { struct max31827_state *st = dev_get_drvdata(dev); -unsigned int uval; +u16 uval;int ret =0 ;switch (type) {case hwmon_temp:switch (attr) {case hwmon_temp_enable: - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 255
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ &uval);if (ret)break ;@@ -226,10 +273,10 @@ static int max31827_read(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 273
Quoted 1 line
drivers/hwmon/max31827.c +0
-0* be changed during the conversion process.
drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-2*/ - ret = regmap_update_bits(st->regmap, -
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 231
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_1SHOT_MASK,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 3 lines
drivers/hwmon/max31827.c +2
-1- 1); + ret = max31827_update_bits(st->client, +
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 278
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_1SHOT_MASK,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ 1);if (ret) {mutex_unlock (&st->lock);return ret;@@ -246,7 +293,8 @@ static int max31827_read(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-1st->update_interval == 125)usleep_range (15000 ,20000 ); - ret = regmap_read(st->regmap,
MAX31827_T_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 296
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_T_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 261
Quoted 10 lines
drivers/hwmon/max31827.c +1
-1+ &uval);mutex_unlock (&st->lock);@@ -257,23 +305,26 @@ static int max31827_read(struct device *dev,enum hwmon_sensor_types type, break;case hwmon_temp_max: - ret = regmap_read(st->regmap,
MAX31827_TH_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 309
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_TH_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type, · line 275
Quoted 8 lines
drivers/hwmon/max31827.c +1
-1+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_max_hyst: - ret = regmap_read(st->regmap,
MAX31827_TH_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 3 lines
drivers/hwmon/max31827.c +2
-1- &uval); + ret = max31827_reg_read(st->client, +MAX31827_TH_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 9 lines
drivers/hwmon/max31827.c +1
-2+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_max_alarm: - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 327
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ &uval);if (ret)break ;@@ -281,23 +332,25 @@ static int max31827_read(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type, · line 299
Quoted 4 lines
drivers/hwmon/max31827.c +0
-1uval);break ;case hwmon_temp_min: - ret = regmap_read(st->regmap,
MAX31827_TL_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 335
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_TL_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type, · line 299
Quoted 8 lines
drivers/hwmon/max31827.c +1
-1+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_min_hyst: - ret = regmap_read(st->regmap,
MAX31827_TL_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 343
Quoted 2 lines
drivers/hwmon/max31827.c +1
-1- &uval); + ret = max31827_reg_read(st->client,
MAX31827_TL_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 9 lines
drivers/hwmon/max31827.c +1
-2+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_min_alarm: - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 352
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ &uval);if (ret)break ;@@ -313,8 +366,9 @@ static int max31827_read(struct device *dev,enum
drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 6 lines
drivers/hwmon/max31827.c +0
-2hwmon_sensor_types type, case hwmon_chip: if (attr == hwmon_chip_update_interval) { - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 371
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 360
Quoted 11 lines
drivers/hwmon/max31827.c +1
-2+ &uval);if (ret)break ;@@ -355,11 +409,11 @@ static int max31827_write(struct device *dev,enum hwmon_sensor_types type, st->enable = val; - ret = regmap_update_bits(st->regmap, -
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 361
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_1SHOT_MASK|drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 362
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 363
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_DEVICE_ENABLE(val));drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 414
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_update_bits(st->client, +
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 415
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_1SHOT_MASK|drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 416
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 417
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_DEVICE_ENABLE(val));drivers/hwmon/max31827.c static int max31827_write(struct device *dev,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-0mutex_unlock (&st->lock);@@ -402,10 +456,10 @@ static int max31827_write(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 456
Quoted 1 line
drivers/hwmon/max31827.c +0
-0res =FIELD_PREP(MAX31827_CONFIGURATION_CNV_RATE_MASK,
drivers/hwmon/max31827.c static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-2res); - ret = regmap_update_bits(st->regmap, -
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 407
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
Quoted 3 lines
drivers/hwmon/max31827.c +2
-1- res); + ret = max31827_update_bits(st->client, +
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 461
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static ssize_t temp1_resolution_show(struct
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ res);if (ret)return ret;@@ -425,10 +479,10 @@ static ssize_t temp1_resolution_show(structdevice *dev,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_show(struct device *dev,
Quoted 8 lines
drivers/hwmon/max31827.c +1
-2char *buf) {struct max31827_state *st =dev_get_drvdata (dev); -unsigned int val; +u16 val;int ret; - ret = regmap_read(st->regmap,
MAX31827_CONFIGURATION_REG, &val);drivers/hwmon/max31827.c static ssize_t temp1_resolution_show(struct · line 485
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+&val);if (ret)return ret;@@ -473,10 +527,63 @@ static ssize_t temp1_resolution_store(structdevice *dev,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 4 lines
drivers/hwmon/max31827.c +1
-0return ret ? ret : count; } +static ssize_t pec_show(struct device *dev, struct device_attribute*devattr,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 9 lines
drivers/hwmon/max31827.c +9
-0+ char *buf) +{ +struct max31827_state *st =dev_get_drvdata (dev); +struct i2c_client *client = st->client; + +return scnprintf (buf,PAGE_SIZE ,"%d\n" , !!(client->flags & +I2C_CLIENT_PEC )); } + +static ssize_t pec_store(struct device *dev, struct device_attribute*devattr,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 13 lines
drivers/hwmon/max31827.c +13
-0+ const char *buf, size_t count) +{ +struct max31827_state *st =dev_get_drvdata (dev); +struct i2c_client *client = st->client; +unsigned int val; +u16 val2; +int err; + + err =kstrtouint (buf,10 , &val); +if (err <0 ) +return err; + + val2 = FIELD_PREP(MAX31827_CONFIGURATION_PEC_EN_MASK,val);
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 8 lines
drivers/hwmon/max31827.c +8
-0+ +if (err) +return err; + +switch (val) { +case 0 : + client->flags &= ~I2C_CLIENT_PEC ; + err = max31827_update_bits(client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct · line 561
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_PEC_EN_MASK,drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 6 lines
drivers/hwmon/max31827.c +6
-0+ val2); +if (err) +return err; +break ; +case 1 : + err = max31827_update_bits(client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct · line 568
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_PEC_EN_MASK,drivers/hwmon/max31827.c static const struct i2c_device_id
Quoted 22 lines
drivers/hwmon/max31827.c +14
-0+ val2); +if (err) +return err; + client->flags |=I2C_CLIENT_PEC ; +break ; +default : +return -EINVAL ; + } + +return count; +} +static DEVICE_ATTR_RW (temp1_resolution); +static DEVICE_ATTR_RW (pec);static struct attribute *max31827_attrs[] = { &dev_attr_temp1_resolution.attr, + &dev_attr_pec.attr,NULL };ATTRIBUTE_GROUPS (max31827);@@ -489,9 +596,9 @@ static const struct i2c_device_idmax31827_i2c_ids[] = {
drivers/hwmon/max31827.c static const struct i2c_device_id max31827_i2c_ids[] = { · line 601
Quoted 8 lines
drivers/hwmon/max31827.c +2
-2};MODULE_DEVICE_TABLE (i2c, max31827_i2c_ids); -static int max31827_init_client (struct max31827_state *st, -struct device *dev) +static int max31827_init_client (struct max31827_state *st) { +struct device *dev = &st->client->dev;Now we are absolutely down to personal preference changes. I am not at all inclined to accept such changes, sorry.
Quoted 9 lines
Quoted 6 lines
Including such changes means I'll have to put extra scrutiny on your patch submissions in the future to ensure that you don't try to sneak in similar changes, which I find quite frustrating. Is that really necessary ?
Guenter
Sorry for this! I thought, if I am adding client to the private structure I might as well delete the second parameter of
init_client, because I can easily retrieve the device structure from client. I added this line so that the changes to the code are kept to a minimum.
You are making unnecessary changes (several unsigned int -> u16 plus this one), and claim this would be "so that the changes to the code are kept to a minimum". Really ? How does making unnecessary changes keep the changes to the code to a minimum ?
Guenter
Quoted 54 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Saturday, December 16, 2023 3:33 AM
To: Matyas, Daniel <[email protected]>
Cc: Jean Delvare <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 1/3] hwmon: max31827: Add PEC support[External]
Quoted 4 lines · Daniel
Quoted 4 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of GuenterRoeck
Quoted 10 lines
Quoted 10 lines
Sent: Thursday, December 14, 2023 6:10 PM
To: Matyas, Daniel <[email protected]>
Cc: Jean Delvare <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 1/3] hwmon: max31827: Add PEC supportQuoted 4 lines
Quoted 4 lines
[External]
Quoted 1 line · Daniel Matyas
Removed regmap and used my functions to read, write and update
bits.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
In these functions
i2c_smbus_helper functions are used. These check if there were any PEC errors during read. In the write function, if PEC is enabled, I check for PEC Error bit, to see if there were anyerrors.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Signed-off-by Daniel Matyas <[email protected]>The "PEC" attribute needs to be attached to the I2C device. See
lm90.corpmbus_core.cfor examples.I added
pec_show()andpec_store()functions and created the pec filewithin the
max31827_groups.Quoted 1 line
I did not set the flags, because I want them to be set only in
pec_store.By default the PEC flag should not be set.
Quoted 1 line
Quoted 7 lines
That is not the point. Again,
Quoted 2 lines
Quoted 2 lines
The "PEC" attribute needs to be attached to the I2C device. See
lm90.corpmbus_core.cfor examples.That is not about regmap, it is about the location of the "pec" attribute.
I understand that this is not about regmap. Still, I would argue, that when I am registering the device with groups, the "pec" attribute is attached.
Quoted 611 lines
Quoted 5 lines
Quoted 5 lines
The changes, if indeed needed, do not warant dropping regmap. You will need to explain why the
reg_readandreg_writecallbacks provideed by regmap can not be used.On top of that, it is not clear why regmap can't be used in the first
place.
Quoted 7 lines
Quoted 5 lines
It seems that the major change is that one needs to read the configuration register after a write to see if there was a PEC error. It is not immediately obvious why that additional read (if indeed necessary) would require regmap support to be dropped.
So I am not sure about this, but it seems to me, that
regmap_writeis notsending a PEC byte and
regmap_readis not checking the PEC byte by default. My rationale was:i2c_smbus_write_word_data()is using thei2c_xferfunction, which has as argument theclient->flags. So, ifI2C_CLIENT_PECis set inclient->flags, that would be transmitted byi2c_xfer. I am not convinced about this, but lm90 andpmbus_coreare not using regmap, so I went ahead and replaced it.Quoted 3 lines
If what I am thinking is wrong, please correct me.
regmap uses smbus functions to access the chip if the underlying i2c driver supports SMBus word operations. I fail to see the difference to your code.
Sure,max31827_reg_write()executes another read after the write, but that is again a 16-bit operation and might we well be implemented as another regmap operation to read the status register.It would be possible to replace the regmap i2c code, use raw regmap code instead, and provide ->read and ->write callbacks in struct
regmap_config, but I am not convinced that this would be beneficial.Either case, sorry, I can not follow your line of argument.
Quoted 7 lines
Quoted 7 lines
Regarding "if indeed necessary": There needs to be a comment explaining that the device will return ACK even after a packet with bad PEC is received.
Quoted 3 lines
--- Documentation/hwmon/max31827.rst | 14 +- drivers/hwmon/max31827.c | 219 +++++++++++++++++++++++-----
Quoted 30 lines
Quoted 30 lines
---
Documentation/hwmon/max31827.rst The Fault Queue bits select how many
Quoted 8 lines
2 files changed, 171 insertions(+), 62 deletions(-)Documentation/hwmon/max31827.rst +0
-0@@ -131,7 +131,13 @@ The Fault Queue bits select how manyconsecutive temperature faults must occur
Quoted 2 lines
Documentation/hwmon/max31827.rst +0
-0before overtemperature or undertemperature faults are indicatedin
the
Documentation/hwmon/max31827.rst The Fault Queue bits select how many consecutive temperature faults must occur
Quoted 7 lines
corresponding status bits.
Documentation/hwmon/max31827.rst +1
-4-Notes ------ - -PEC is not implemented. +PEC (packet error checking) can be enabled from the "pec" deviceattribute.
Documentation/hwmon/max31827.rst
Quoted 2 lines
Documentation/hwmon/max31827.rst +2
-0+If PEC is enabled, a PEC byte is appended to the end of each +messagetransfer.
Documentation/hwmon/max31827.rst
Quoted 5 lines
Documentation/hwmon/max31827.rst +5
-0+This is a CRC-8 byte that is calculated on all of the message bytes +(including the address/read/write byte). The last device to +transmit a data byte also transmits the PEC byte. The master +transmits the PEC byte after a write transaction, and the MAX31827 +transmits the PECbyte after a read transaction.
Quoted 7 lines
Quoted 7 lines
Documentation/hwmon/max31827.rst
Quoted 2 lines
Documentation/hwmon/max31827.rst +2
-0+ +The read PEC error is handled inside the
i2c_smbus_read_word_swapped()function.Review
Quoted 4 lines
Documentation/hwmon/max31827.rst +2
-0+To check if the write had any PEC error a read is performed on the +configuration register, to check the PEC Error bit.(quoted diff) +0
-0
b/drivers/hwmon/max31827.cQuoted 19 lines
Quoted 19 lines
index
Quoted 14 lines
71ad3934dfb6..db93492193bd100644drivers/hwmon/max31827.c +1
-1@@ -11,8 +11,8 @@#include <linux/hwmon.h> #include <linux/i2c.h> #include <linux/mutex.h> -#include <linux/regmap.h> #include <linux/regulator/consumer.h> +#include <linux/hwmon-sysfs.h> #include <linux/of_device.h> #define MAX31827_T_REG 0x0drivers/hwmon/max31827.c line 26
Quoted 3 lines
drivers/hwmon/max31827.c +0
-0@@ -24,11 +24,13 @@#define MAX31827_CONFIGURATION_1SHOT_MASK BIT(0)#define MAX31827_CONFIGURATION_CNV_RATE_MASK GENMASK(3, 1)Quoted 7 lines
Quoted 7 lines
drivers/hwmon/max31827.c
Quoted 3 lines
drivers/hwmon/max31827.c +1
-0+#define MAX31827_CONFIGURATION_PEC_EN_MASK BIT(4)#define MAX31827_CONFIGURATION_TIMEOUT_MASK BIT(5)#define MAX31827_CONFIGURATION_RESOLUTION_MASK GENMASK(7, 6)Quoted 3 lines
drivers/hwmon/max31827.c +0
-0#define MAX31827_CONFIGURATION_ALRM_POL_MASK BIT(8)#define MAX31827_CONFIGURATION_COMP_INT_MASK BIT(9)#define MAX31827_CONFIGURATION_FLT_Q_MASK GENMASK(11, 10)Quoted 2 lines
Quoted 2 lines
drivers/hwmon/max31827.c line 34
Quoted 2 lines
drivers/hwmon/max31827.c +1
-0+#define MAX31827_CONFIGURATION_PEC_ERR_MASK BIT(13)#define MAX31827_CONFIGURATION_U_TEMP_STAT_MASK BIT(14)Quoted 1 line
Quoted 1 line
drivers/hwmon/max31827.c line 35
Quoted 1 line
drivers/hwmon/max31827.c +0
-0#define MAX31827_CONFIGURATION_O_TEMP_STAT_MASK BIT(15)Quoted 25 lines
Quoted 25 lines
Quoted 12 lines
drivers/hwmon/max31827.c +1
-1@@ -94,23 +96,67 @@ struct max31827_state {* Prevent simultaneous access to the i2c client. */ struct mutex lock; -struct regmap *regmap;bool enable;unsigned int resolution;unsigned int update_interval; +struct i2c_client *client; };drivers/hwmon/max31827.c struct max31827_state { · line 109
Quoted 10 lines
drivers/hwmon/max31827.c +5
-5-static const struct regmap_config max31827_regmap = { - .reg_bits =8 , - .val_bits =16 , - .max_register =0xA , -}; +static int max31827_reg_read (struct i2c_client *client,u8 reg,u16 +*val) { +u16 tmp =i2c_smbus_read_word_swapped (client, reg); + +if (tmp <0 )An u16 variable will never be negative.
Quoted 11 lines
Quoted 11 lines
drivers/hwmon/max31827.c struct max31827_state { · line 114
Quoted 5 lines
drivers/hwmon/max31827.c +5
-0+return tmp; + + *val = tmp; +return 0 ; +}If regmap can indeed not be used, it is unnecessary to provide a pointer to the return value. Instead, just like with smbus calls, the error return and the return value can be combined. Adding this function just to separate error from return value adds zero value (and, as can be seen from the above, actually adds an opportunity to
introduce bugs).
Quoted 23 lines
Quoted 23 lines
drivers/hwmon/max31827.c struct max31827_state { · line 125
Quoted 13 lines
drivers/hwmon/max31827.c +12
-0+ +static int max31827_reg_write (struct i2c_client *client,u8 reg, +u16 +val) { +u16 cfg; +int ret; + + ret =i2c_smbus_write_word_swapped (client, reg, val); +if (ret) +return ret; + +// If PEC is not enabled, return with success Do not mix comment styles. The rest of the driver doesn't use C++ comments.
Besides, the comment does not add any value.drivers/hwmon/max31827.c struct max31827_state {
Quoted 4 lines
drivers/hwmon/max31827.c +4
-0+if (!(client->flags &I2C_CLIENT_PEC )) +return 0 ; + + ret = max31827_reg_read(client,
MAX31827_CONFIGURATION_REG, &cfg);Quoted 8 lines
Quoted 8 lines
drivers/hwmon/max31827.c struct max31827_state { · line 135
Quoted 6 lines
drivers/hwmon/max31827.c +6
-0+if (ret) +return ret; + +if (cfg &MAX31827_CONFIGURATION_PEC_ERR_MASK ) +return -EBADMSG ; +EBADMSG is "Not a data message". I don't think that is appropriate
here.
Quoted 25 lines
Quoted 25 lines
I would very much prefer
if (client->flags & I2C_CLIENT_PEC) { ... }Quoted 19 lines
drivers/hwmon/max31827.c +18
-0+return 0 ; +} + +static int max31827_update_bits (struct i2c_client *client,u8 reg, +u16 mask,u16 val) +{ +u16 tmp; +int ret; + + ret =max31827_reg_read (client, reg, &tmp); +if (ret) +return ret; + + tmp = (tmp & ~mask) | (val & mask); + ret =max31827_reg_write (client, reg, tmp); + +return ret; +}Quoted 1 line
Quoted 1 line
drivers/hwmon/max31827.c struct max31827_state { · line 156
Quoted 1 line
drivers/hwmon/max31827.c +0
-0static int shutdown_write(struct max31827_state *st, unsigned intreg,
Quoted 66 lines
Quoted 66 lines
drivers/hwmon/max31827.c struct max31827_state { · line 159
Quoted 6 lines
drivers/hwmon/max31827.c +2
-2unsigned int mask, unsigned int val) { -unsigned int cfg; -unsigned int cnv_rate; +u16 cfg; +u16 cnv_rate;I really do not see the point of those changes. u16 is more expensive than unsigned int on many architectures. If retained, you'll have to explain why this is needed and beneficial.
drivers/hwmon/max31827.c static int shutdown_write(struct
Quoted 4 lines
drivers/hwmon/max31827.c +0
-0int ret;/* @@ -125,34 +171,34 @@ static int shutdown_write(struct
max31827_statedrivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 8 lines
drivers/hwmon/max31827.c +1
-2*st, unsigned int reg, if (!st->enable) {if (!mask) - ret =regmap_write (st->regmap, reg, val); + ret =max31827_reg_write (st->client, reg, val);else - ret = regmap_update_bits(st->regmap, reg, mask,val);
drivers/hwmon/max31827.c static int shutdown_write(struct · line 177
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_update_bits(st->client, reg,mask, val);
drivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-1goto unlock; } - ret = regmap_read(st->regmap,
MAX31827_CONFIGURATION_REG, &cfg);drivers/hwmon/max31827.c static int shutdown_write(struct · line 181
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 8 lines
drivers/hwmon/max31827.c +1
-1+&cfg);if (ret) goto unlock; cnv_rate =MAX31827_CONFIGURATION_CNV_RATE_MASK & cfg; cfg = cfg & ~(MAX31827_CONFIGURATION_1SHOT_MASK |MAX31827_CONFIGURATION_CNV_RATE_MASK ); - ret = regmap_write(st->regmap,
MAX31827_CONFIGURATION_REG, cfg);drivers/hwmon/max31827.c static int shutdown_write(struct · line 189
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_write(st->client,
MAX31827_CONFIGURATION_REG,Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+cfg);if (ret) goto unlock;if (!mask)drivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 10 lines
drivers/hwmon/max31827.c +2
-3- ret =regmap_write (st->regmap, reg, val); + ret =max31827_reg_write (st->client, reg, val); else - ret =regmap_update_bits (st->regmap, reg, mask, val); + ret =max31827_update_bits (st->client, reg, mask, val);if (ret) goto unlock; - ret = regmap_update_bits(st->regmap,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int shutdown_write(struct · line 155
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int shutdown_write(struct · line 202
Quoted 2 lines
drivers/hwmon/max31827.c +1
-1- cnv_rate); + ret = max31827_update_bits(st->client,
MAX31827_CONFIGURATION_REG,Quoted 7 lines
Quoted 7 lines
drivers/hwmon/max31827.c static int shutdown_write(struct · line 203
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_read(struct device
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ cnv_rate); unlock:mutex_unlock (&st->lock);@@ -198,15 +244,16 @@ static int max31827_read(struct device*dev,
Quoted 15 lines
Quoted 15 lines
enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 13 lines
drivers/hwmon/max31827.c +1
-3u32 attr, int channel, long *val) { struct max31827_state *st = dev_get_drvdata(dev); -unsigned int uval; +u16 uval;int ret =0 ;switch (type) {case hwmon_temp:switch (attr) {case hwmon_temp_enable: - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);Quoted 8 lines
Quoted 8 lines
drivers/hwmon/max31827.c static int max31827_read(struct device · line 255
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ &uval);if (ret)break ;@@ -226,10 +273,10 @@ static int max31827_read(struct device*dev,
Quoted 27 lines
Quoted 27 lines
enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device · line 273
Quoted 1 line
drivers/hwmon/max31827.c +0
-0* be changed during the conversion process.
drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-2*/ - ret = regmap_update_bits(st->regmap, -
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device · line 231
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_1SHOT_MASK,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 3 lines
drivers/hwmon/max31827.c +2
-1- 1); + ret = max31827_update_bits(st->client, +
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device · line 278
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_1SHOT_MASK,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ 1);if (ret) {mutex_unlock (&st->lock);return ret;@@ -246,7 +293,8 @@ static int max31827_read(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-1st->update_interval == 125)usleep_range (15000 ,20000 ); - ret = regmap_read(st->regmap,
MAX31827_T_REG, &uval);Quoted 7 lines
Quoted 7 lines
drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 296
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_T_REG,drivers/hwmon/max31827.c static int max31827_read(struct device
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ &uval);mutex_unlock (&st->lock);@@ -257,23 +305,26 @@ static int max31827_read(struct device*dev,
Quoted 31 lines
Quoted 31 lines
drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type, · line 275
Quoted 5 lines
drivers/hwmon/max31827.c +0
-1enum hwmon_sensor_types type, break;case hwmon_temp_max: - ret = regmap_read(st->regmap,
MAX31827_TH_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device · line 309
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_TH_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type, · line 275
Quoted 8 lines
drivers/hwmon/max31827.c +1
-1+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_max_hyst: - ret = regmap_read(st->regmap,
MAX31827_TH_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 3 lines
drivers/hwmon/max31827.c +2
-1- &uval); + ret = max31827_reg_read(st->client, +MAX31827_TH_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 9 lines
drivers/hwmon/max31827.c +1
-2+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_max_alarm: - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);Quoted 8 lines
Quoted 8 lines
drivers/hwmon/max31827.c static int max31827_read(struct device · line 327
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ &uval);if (ret)break ;@@ -281,23 +332,25 @@ static int max31827_read(struct device*dev,
Quoted 46 lines
Quoted 46 lines
enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type, · line 299
Quoted 4 lines
drivers/hwmon/max31827.c +0
-1uval);break ;case hwmon_temp_min: - ret = regmap_read(st->regmap,
MAX31827_TL_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device · line 335
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_TL_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type, · line 299
Quoted 8 lines
drivers/hwmon/max31827.c +1
-1+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_min_hyst: - ret = regmap_read(st->regmap,
MAX31827_TL_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device · line 343
Quoted 2 lines
drivers/hwmon/max31827.c +1
-1- &uval); + ret = max31827_reg_read(st->client,
MAX31827_TL_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 9 lines
drivers/hwmon/max31827.c +1
-2+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_min_alarm: - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device · line 352
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ &uval);if (ret)break ;@@ -313,8 +366,9 @@ static int max31827_read(struct device *dev,enum
drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 6 lines
drivers/hwmon/max31827.c +0
-2hwmon_sensor_types type, case hwmon_chip: if (attr == hwmon_chip_update_interval) { - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);Quoted 8 lines
Quoted 8 lines
drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 371
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ &uval);if (ret)break ;@@ -355,11 +409,11 @@ static int max31827_write(struct device*dev,
Quoted 18 lines
Quoted 18 lines
drivers/hwmon/max31827.c static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
Quoted 6 lines
drivers/hwmon/max31827.c +0
-2enum hwmon_sensor_types type, st->enable = val; - ret = regmap_update_bits(st->regmap, -
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device · line 361
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_1SHOT_MASK|drivers/hwmon/max31827.c static int max31827_write(struct device · line 362
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_write(struct device · line 363
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_DEVICE_ENABLE(val));drivers/hwmon/max31827.c static int max31827_write(struct device · line 414
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_update_bits(st->client, +
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device · line 415
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_1SHOT_MASK|Quoted 8 lines
Quoted 8 lines
drivers/hwmon/max31827.c static int max31827_write(struct device · line 416
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_write(struct device · line 417
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_DEVICE_ENABLE(val));drivers/hwmon/max31827.c static int max31827_write(struct device
Quoted 4 lines
drivers/hwmon/max31827.c +0
-0mutex_unlock (&st->lock);@@ -402,10 +456,10 @@ static int max31827_write(struct device*dev,
Quoted 14 lines
Quoted 14 lines
enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_write(struct device · line 456
Quoted 1 line
drivers/hwmon/max31827.c +0
-0res =FIELD_PREP(MAX31827_CONFIGURATION_CNV_RATE_MASK,
drivers/hwmon/max31827.c static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-2res); - ret = regmap_update_bits(st->regmap, -
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device · line 407
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
Quoted 3 lines
drivers/hwmon/max31827.c +2
-1- res); + ret = max31827_update_bits(st->client, +
MAX31827_CONFIGURATION_REG,Quoted 7 lines
Quoted 7 lines
drivers/hwmon/max31827.c static int max31827_write(struct device · line 461
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static ssize_t
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ res);if (ret)return ret;@@ -425,10 +479,10 @@ static ssize_ttemp1_resolution_show(struct
Quoted 10 lines
Quoted 10 lines
device *dev,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_show(struct device *dev,
Quoted 8 lines
drivers/hwmon/max31827.c +1
-2char *buf) {struct max31827_state *st =dev_get_drvdata (dev); -unsigned int val; +u16 val;int ret; - ret = regmap_read(st->regmap,
MAX31827_CONFIGURATION_REG, &val);Quoted 7 lines
Quoted 7 lines
drivers/hwmon/max31827.c static ssize_t · line 485
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static ssize_t
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+&val);if (ret)return ret;@@ -473,10 +527,63 @@ static ssize_ttemp1_resolution_store(struct
Quoted 86 lines
Quoted 86 lines
device *dev,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 4 lines
drivers/hwmon/max31827.c +1
-0return ret ? ret : count; } +static ssize_t pec_show(struct device *dev, struct device_attribute*devattr,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 10 lines
drivers/hwmon/max31827.c +10
-0+ char *buf) +{ +struct max31827_state *st =dev_get_drvdata (dev); +struct i2c_client *client = st->client; + +return scnprintf (buf,PAGE_SIZE ,"%d\n" , !!(client->flags & +I2C_CLIENT_PEC )); } + +static ssize_t pec_store (struct device *dev,struct +device_attribute*devattr,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 13 lines
drivers/hwmon/max31827.c +13
-0+ const char *buf, size_t count) +{ +struct max31827_state *st =dev_get_drvdata (dev); +struct i2c_client *client = st->client; +unsigned int val; +u16 val2; +int err; + + err =kstrtouint (buf,10 , &val); +if (err <0 ) +return err; + + val2 = FIELD_PREP(MAX31827_CONFIGURATION_PEC_EN_MASK,val);
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 8 lines
drivers/hwmon/max31827.c +8
-0+ +if (err) +return err; + +switch (val) { +case 0 : + client->flags &= ~I2C_CLIENT_PEC ; + err = max31827_update_bits(client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static ssize_t · line 562
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_PEC_EN_MASK,drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 6 lines
drivers/hwmon/max31827.c +6
-0+ val2); +if (err) +return err; +break ; +case 1 : + err = max31827_update_bits(client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static ssize_t · line 569
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_PEC_EN_MASK,drivers/hwmon/max31827.c static const struct i2c_device_id
Quoted 22 lines
drivers/hwmon/max31827.c +14
-0+ val2); +if (err) +return err; + client->flags |=I2C_CLIENT_PEC ; +break ; +default : +return -EINVAL ; + } + +return count; +} +static DEVICE_ATTR_RW (temp1_resolution); +static DEVICE_ATTR_RW (pec);static struct attribute *max31827_attrs[] = { &dev_attr_temp1_resolution.attr, + &dev_attr_pec.attr,NULL };ATTRIBUTE_GROUPS (max31827);@@ -489,9 +596,9 @@ static const struct i2c_device_idmax31827_i2c_ids[] = {
drivers/hwmon/max31827.c static const struct i2c_device_id max31827_i2c_ids[] = { · line 601
Quoted 8 lines
drivers/hwmon/max31827.c +2
-2};MODULE_DEVICE_TABLE (i2c, max31827_i2c_ids); -static int max31827_init_client (struct max31827_state *st, -struct device *dev) +static int max31827_init_client (struct max31827_state *st) { +struct device *dev = &st->client->dev;Now we are absolutely down to personal preference changes. I am not at all inclined to accept such changes, sorry.
Quoted 3 lines
Quoted 3 lines
Including such changes means I'll have to put extra scrutiny on your patch submissions in the future to ensure that you don't try to sneak in similar changes, which I find quite frustrating. Is that really necessary
?
Quoted 5 lines
Quoted 3 lines
Guenter
Sorry for this! I thought, if I am adding client to the private structure I
might as well delete the second parameter of
init_client, because I can easily retrieve the device structure from client. I added this line so that the changes to the code are kept to a minimum.Quoted 1 line
You are making unnecessary changes (several unsigned int -> u16 plus this one), and claim this would be "so that the changes to the code are kept to a minimum". Really ? How does making unnecessary changes keep the changes to the code to a minimum ?
Guenter
Guenter Roeck
maintainerQuoted 56 lines · Daniel
Quoted 56 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Saturday, December 16, 2023 3:33 AM
To: Matyas, Daniel <[email protected]>
Cc: Jean Delvare <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 1/3] hwmon: max31827: Add PEC support[External]
Quoted 4 lines · Daniel
Quoted 4 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of GuenterRoeck
Quoted 10 lines
Quoted 10 lines
Sent: Thursday, December 14, 2023 6:10 PM
To: Matyas, Daniel <[email protected]>
Cc: Jean Delvare <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 1/3] hwmon: max31827: Add PEC supportQuoted 4 lines
Quoted 4 lines
[External]
Quoted 1 line · Daniel Matyas
Removed regmap and used my functions to read, write and update
bits.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
In these functions
i2c_smbus_helper functions are used. These check if there were any PEC errors during read. In the write function, if PEC is enabled, I check for PEC Error bit, to see if there were anyerrors.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Signed-off-by Daniel Matyas <[email protected]>The "PEC" attribute needs to be attached to the I2C device. See
lm90.corpmbus_core.cfor examples.I added
pec_show()andpec_store()functions and created the pec filewithin the
max31827_groups.Quoted 1 line
I did not set the flags, because I want them to be set only in
pec_store.By default the PEC flag should not be set.
Quoted 1 line
That is not the point. Again,
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
The "PEC" attribute needs to be attached to the I2C device. See
lm90.corpmbus_core.cfor examples.That is not about regmap, it is about the location of the "pec" attribute.
I understand that this is not about regmap. Still, I would argue, that when I am registering the device with groups, the "pec" attribute is attached.
Sure. To the hwmon device. I asked you to attach it to the i2c device, as implemented all other hwmon drivers supporting this attribute. I am not inclined to make an exception for this driver, and I do not see a reason to do so.
Guenter
Quoted 31 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Thursday, December 14, 2023 6:10 PM
To: Matyas, Daniel <[email protected]>
Cc: Jean Delvare <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 1/3] hwmon: max31827: Add PEC support[External]
Quoted 6 lines · Daniel Matyas
Removed regmap and used my functions to read, write and update bits. In these functions
i2c_smbus_helper functions are used. These check if there were any PEC errors during read. In the write function, if PEC is enabled, I check for PEC Error bit, to see if there were any errors.Signed-off-by Daniel Matyas <[email protected]>The "PEC" attribute needs to be attached to the I2C device. See
lm90.corpmbus_core.cfor examples.The changes, if indeed needed, do not warant dropping regmap. You will need to explain why the
reg_readandreg_writecallbacks provideed by regmap can not be used.
Quoted 6 lines
On top of that, it is not clear why regmap can't be used in the first place. It seems that the major change is that one needs to read the configuration register after a write to see if there was a PEC error. It is not immediately obvious why that additional read (if indeed necessary) would require regmap support to be dropped.
I tried out writing and and reading with regmap, but it is not working properly. Even if I modify the client flag, I still receive only 2 bytes of data (a word). I should be receiving 2+1 bytes = data + CRC-8.
With i2c_smbus reads and writes, when I set the flag, I receive the 2+1 bytes, as expected.
Daniel
Quoted 579 lines
Regarding "if indeed necessary": There needs to be a comment explaining that the device will return ACK even after a packet with bad PEC is received.
Quoted 3 lines
--- Documentation/hwmon/max31827.rst | 14 +- drivers/hwmon/max31827.c | 219 +++++++++++++++++++++++--------
Documentation/hwmon/max31827.rst The Fault Queue bits select how many
Quoted 8 lines
2 files changed, 171 insertions(+), 62 deletions(-)Documentation/hwmon/max31827.rst +0
-0@@ -131,7 +131,13 @@ The Fault Queue bits select how manyconsecutive temperature faults must occur
Documentation/hwmon/max31827.rst The Fault Queue bits select how many · line 131
Quoted 1 line
Documentation/hwmon/max31827.rst +0
-0before overtemperature or undertemperature faults are indicated inthe
Documentation/hwmon/max31827.rst The Fault Queue bits select how many consecutive temperature faults must occur
Quoted 7 lines
Documentation/hwmon/max31827.rst +1
-4corresponding status bits. -Notes ------ - -PEC is not implemented. +PEC (packet error checking) can be enabled from the "pec" deviceattribute.
Documentation/hwmon/max31827.rst The Fault Queue bits select how many · line 135
Quoted 1 line
Documentation/hwmon/max31827.rst +1
-0+If PEC is enabled, a PEC byte is appended to the end of each messagetransfer.
Documentation/hwmon/max31827.rst The Fault Queue bits select how many · line 139
Quoted 4 lines
Documentation/hwmon/max31827.rst +4
-0+This is a CRC-8 byte that is calculated on all of the message bytes +(including the address/read/write byte). The last device to transmit +a data byte also transmits the PEC byte. The master transmits the PEC +byte after a write transaction, and the MAX31827 transmits the PECbyte after a read transaction.
Documentation/hwmon/max31827.rst The Fault Queue bits select how many · line 141
Quoted 2 lines
Documentation/hwmon/max31827.rst +2
-0+ +The read PEC error is handled inside the
i2c_smbus_read_word_swapped()function.drivers/hwmon/max31827.c
Quoted 4 lines
Documentation/hwmon/max31827.rst +2
-0+To check if the write had any PEC error a read is performed on the +configuration register, to check the PEC Error bit.drivers/hwmon/max31827.c +0
-0index
Quoted 14 lines
71ad3934dfb6..db93492193bd100644drivers/hwmon/max31827.c +1
-1@@ -11,8 +11,8 @@#include <linux/hwmon.h> #include <linux/i2c.h> #include <linux/mutex.h> -#include <linux/regmap.h> #include <linux/regulator/consumer.h> +#include <linux/hwmon-sysfs.h> #include <linux/of_device.h> #define MAX31827_T_REG 0x0drivers/hwmon/max31827.c line 26
Quoted 3 lines
drivers/hwmon/max31827.c +0
-0@@ -24,11 +24,13 @@#define MAX31827_CONFIGURATION_1SHOT_MASK BIT(0)#define MAX31827_CONFIGURATION_CNV_RATE_MASK GENMASK(3, 1)drivers/hwmon/max31827.c
Quoted 3 lines
drivers/hwmon/max31827.c +1
-0+#define MAX31827_CONFIGURATION_PEC_EN_MASK BIT(4)#define MAX31827_CONFIGURATION_TIMEOUT_MASK BIT(5)#define MAX31827_CONFIGURATION_RESOLUTION_MASK GENMASK(7, 6)Quoted 18 lines
drivers/hwmon/max31827.c +2
-1#define MAX31827_CONFIGURATION_ALRM_POL_MASK BIT(8)#define MAX31827_CONFIGURATION_COMP_INT_MASK BIT(9)#define MAX31827_CONFIGURATION_FLT_Q_MASK GENMASK(11, 10) +#define MAX31827_CONFIGURATION_PEC_ERR_MASK BIT(13)#define MAX31827_CONFIGURATION_U_TEMP_STAT_MASK BIT(14)#define MAX31827_CONFIGURATION_O_TEMP_STAT_MASK BIT(15)@@ -94,23 +96,67 @@ struct max31827_state {* Prevent simultaneous access to the i2c client. */ struct mutex lock; -struct regmap *regmap;bool enable;unsigned int resolution;unsigned int update_interval; +struct i2c_client *client; };drivers/hwmon/max31827.c struct max31827_state { · line 109
Quoted 10 lines
drivers/hwmon/max31827.c +5
-5-static const struct regmap_config max31827_regmap = { - .reg_bits =8 , - .val_bits =16 , - .max_register =0xA , -}; +static int max31827_reg_read (struct i2c_client *client,u8 reg,u16 +*val) { +u16 tmp =i2c_smbus_read_word_swapped (client, reg); + +if (tmp <0 )An u16 variable will never be negative.
drivers/hwmon/max31827.c struct max31827_state { · line 114
Quoted 5 lines
drivers/hwmon/max31827.c +5
-0+return tmp; + + *val = tmp; +return 0 ; +}If regmap can indeed not be used, it is unnecessary to provide a pointer to the return value. Instead, just like with smbus calls, the error return and the return value can be combined. Adding this function just to separate error from return value adds zero value (and, as can be seen from the above, actually adds an opportunity to introduce bugs).
drivers/hwmon/max31827.c struct max31827_state { · line 125
Quoted 11 lines
drivers/hwmon/max31827.c +11
-0+ +static int max31827_reg_write (struct i2c_client *client,u8 reg,u16 +val) { +u16 cfg; +int ret; + + ret =i2c_smbus_write_word_swapped (client, reg, val); +if (ret) +return ret; + +// If PEC is not enabled, return with success Do not mix comment styles. The rest of the driver doesn't use C++ comments.
Besides, the comment does not add any value.drivers/hwmon/max31827.c struct max31827_state {
Quoted 4 lines
drivers/hwmon/max31827.c +4
-0+if (!(client->flags &I2C_CLIENT_PEC )) +return 0 ; + + ret = max31827_reg_read(client,
MAX31827_CONFIGURATION_REG, &cfg);drivers/hwmon/max31827.c struct max31827_state { · line 135
Quoted 6 lines
drivers/hwmon/max31827.c +6
-0+if (ret) +return ret; + +if (cfg &MAX31827_CONFIGURATION_PEC_ERR_MASK ) +return -EBADMSG ; +EBADMSG is "Not a data message". I don't think that is appropriate here.
I would very much prefer
if (client->flags & I2C_CLIENT_PEC) { ... }Quoted 16 lines
drivers/hwmon/max31827.c +16
-0+return 0 ; +} + +static int max31827_update_bits (struct i2c_client *client,u8 reg, +u16 mask,u16 val) +{ +u16 tmp; +int ret; + + ret =max31827_reg_read (client, reg, &tmp); +if (ret) +return ret; + + tmp = (tmp & ~mask) | (val & mask); + ret =max31827_reg_write (client, reg, tmp); +drivers/hwmon/max31827.c struct max31827_state { · line 159
Quoted 10 lines
drivers/hwmon/max31827.c +4
-2+return ret; +}static int shutdown_write (struct max31827_state *st,unsigned int reg,unsigned int mask,unsigned int val) { -unsigned int cfg; -unsigned int cnv_rate; +u16 cfg; +u16 cnv_rate;I really do not see the point of those changes. u16 is more expensive than unsigned int on many architectures. If retained, you'll have to explain why this is needed and beneficial.
drivers/hwmon/max31827.c static int shutdown_write(struct
Quoted 4 lines
drivers/hwmon/max31827.c +0
-0int ret;/* @@ -125,34 +171,34 @@ static int shutdown_write(struct
max31827_statedrivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 8 lines
drivers/hwmon/max31827.c +1
-2*st, unsigned int reg, if (!st->enable) {if (!mask) - ret =regmap_write (st->regmap, reg, val); + ret =max31827_reg_write (st->client, reg, val);else - ret = regmap_update_bits(st->regmap, reg, mask,val);
drivers/hwmon/max31827.c static int shutdown_write(struct · line 177
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_update_bits(st->client, reg,mask, val);
drivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-1goto unlock; } - ret = regmap_read(st->regmap,
MAX31827_CONFIGURATION_REG, &cfg);drivers/hwmon/max31827.c static int shutdown_write(struct · line 181
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 8 lines
drivers/hwmon/max31827.c +1
-1+&cfg);if (ret) goto unlock; cnv_rate =MAX31827_CONFIGURATION_CNV_RATE_MASK & cfg; cfg = cfg & ~(MAX31827_CONFIGURATION_1SHOT_MASK |MAX31827_CONFIGURATION_CNV_RATE_MASK ); - ret = regmap_write(st->regmap,
MAX31827_CONFIGURATION_REG, cfg);drivers/hwmon/max31827.c static int shutdown_write(struct · line 189
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_write(st->client,
MAX31827_CONFIGURATION_REG,Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+cfg);if (ret) goto unlock;if (!mask)drivers/hwmon/max31827.c static int shutdown_write(struct max31827_state *st, unsigned int reg,
Quoted 10 lines
drivers/hwmon/max31827.c +2
-3- ret =regmap_write (st->regmap, reg, val); + ret =max31827_reg_write (st->client, reg, val); else - ret =regmap_update_bits (st->regmap, reg, mask, val); + ret =max31827_update_bits (st->client, reg, mask, val);if (ret) goto unlock; - ret = regmap_update_bits(st->regmap,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int shutdown_write(struct · line 155
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int shutdown_write(struct · line 202
Quoted 2 lines
drivers/hwmon/max31827.c +1
-1- cnv_rate); + ret = max31827_update_bits(st->client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int shutdown_write(struct · line 203
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ cnv_rate); unlock:mutex_unlock (&st->lock);@@ -198,15 +244,16 @@ static int max31827_read(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 13 lines
drivers/hwmon/max31827.c +1
-3u32 attr, int channel, long *val) { struct max31827_state *st = dev_get_drvdata(dev); -unsigned int uval; +u16 uval;int ret =0 ;switch (type) {case hwmon_temp:switch (attr) {case hwmon_temp_enable: - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 255
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ &uval);if (ret)break ;@@ -226,10 +273,10 @@ static int max31827_read(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 273
Quoted 1 line
drivers/hwmon/max31827.c +0
-0* be changed during the conversion process.
drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-2*/ - ret = regmap_update_bits(st->regmap, -
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 231
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_1SHOT_MASK,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 3 lines
drivers/hwmon/max31827.c +2
-1- 1); + ret = max31827_update_bits(st->client, +
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 278
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_1SHOT_MASK,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ 1);if (ret) {mutex_unlock (&st->lock);return ret;@@ -246,7 +293,8 @@ static int max31827_read(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-1st->update_interval == 125)usleep_range (15000 ,20000 ); - ret = regmap_read(st->regmap,
MAX31827_T_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 296
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_T_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 261
Quoted 10 lines
drivers/hwmon/max31827.c +1
-1+ &uval);mutex_unlock (&st->lock);@@ -257,23 +305,26 @@ static int max31827_read(struct device *dev,enum hwmon_sensor_types type, break;case hwmon_temp_max: - ret = regmap_read(st->regmap,
MAX31827_TH_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 309
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_TH_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type, · line 275
Quoted 8 lines
drivers/hwmon/max31827.c +1
-1+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_max_hyst: - ret = regmap_read(st->regmap,
MAX31827_TH_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 3 lines
drivers/hwmon/max31827.c +2
-1- &uval); + ret = max31827_reg_read(st->client, +MAX31827_TH_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 9 lines
drivers/hwmon/max31827.c +1
-2+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_max_alarm: - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 327
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ &uval);if (ret)break ;@@ -281,23 +332,25 @@ static int max31827_read(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type, · line 299
Quoted 4 lines
drivers/hwmon/max31827.c +0
-1uval);break ;case hwmon_temp_min: - ret = regmap_read(st->regmap,
MAX31827_TL_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 335
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_TL_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type, · line 299
Quoted 8 lines
drivers/hwmon/max31827.c +1
-1+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_min_hyst: - ret = regmap_read(st->regmap,
MAX31827_TL_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 343
Quoted 2 lines
drivers/hwmon/max31827.c +1
-1- &uval); + ret = max31827_reg_read(st->client,
MAX31827_TL_HYST_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 9 lines
drivers/hwmon/max31827.c +1
-2+ &uval);if (ret)break ; *val =MAX31827_16_BIT_TO_M_DGR (uval);break ;case hwmon_temp_min_alarm: - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 352
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_read(struct device *dev,
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ &uval);if (ret)break ;@@ -313,8 +366,9 @@ static int max31827_read(struct device *dev,enum
drivers/hwmon/max31827.c static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
Quoted 6 lines
drivers/hwmon/max31827.c +0
-2hwmon_sensor_types type, case hwmon_chip: if (attr == hwmon_chip_update_interval) { - ret = regmap_read(st->regmap, -
MAX31827_CONFIGURATION_REG, &uval);drivers/hwmon/max31827.c static int max31827_read(struct device *dev, · line 371
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_reg_read(st->client, +MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 360
Quoted 11 lines
drivers/hwmon/max31827.c +1
-2+ &uval);if (ret)break ;@@ -355,11 +409,11 @@ static int max31827_write(struct device *dev,enum hwmon_sensor_types type, st->enable = val; - ret = regmap_update_bits(st->regmap, -
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 361
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_1SHOT_MASK|drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 362
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 363
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_DEVICE_ENABLE(val));drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 414
Quoted 2 lines
drivers/hwmon/max31827.c +2
-0+ ret = max31827_update_bits(st->client, +
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 415
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_1SHOT_MASK|drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 416
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 417
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_DEVICE_ENABLE(val));drivers/hwmon/max31827.c static int max31827_write(struct device *dev,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-0mutex_unlock (&st->lock);@@ -402,10 +456,10 @@ static int max31827_write(struct device *dev,enum
hwmon_sensor_typestype,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 456
Quoted 1 line
drivers/hwmon/max31827.c +0
-0res =FIELD_PREP(MAX31827_CONFIGURATION_CNV_RATE_MASK,
drivers/hwmon/max31827.c static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
Quoted 4 lines
drivers/hwmon/max31827.c +0
-2res); - ret = regmap_update_bits(st->regmap, -
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 407
Quoted 1 line
drivers/hwmon/max31827.c +0
-1-
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
Quoted 3 lines
drivers/hwmon/max31827.c +2
-1- res); + ret = max31827_update_bits(st->client, +
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_write(struct device *dev, · line 461
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_CNV_RATE_MASK,drivers/hwmon/max31827.c static ssize_t temp1_resolution_show(struct
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+ res);if (ret)return ret;@@ -425,10 +479,10 @@ static ssize_t temp1_resolution_show(structdevice *dev,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_show(struct device *dev,
Quoted 8 lines
drivers/hwmon/max31827.c +1
-2char *buf) {struct max31827_state *st =dev_get_drvdata (dev); -unsigned int val; +u16 val;int ret; - ret = regmap_read(st->regmap,
MAX31827_CONFIGURATION_REG, &val);drivers/hwmon/max31827.c static ssize_t temp1_resolution_show(struct · line 485
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ ret = max31827_reg_read(st->client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct
Quoted 5 lines
drivers/hwmon/max31827.c +1
-0+&val);if (ret)return ret;@@ -473,10 +527,63 @@ static ssize_t temp1_resolution_store(structdevice *dev,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 4 lines
drivers/hwmon/max31827.c +1
-0return ret ? ret : count; } +static ssize_t pec_show(struct device *dev, struct device_attribute*devattr,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 9 lines
drivers/hwmon/max31827.c +9
-0+ char *buf) +{ +struct max31827_state *st =dev_get_drvdata (dev); +struct i2c_client *client = st->client; + +return scnprintf (buf,PAGE_SIZE ,"%d\n" , !!(client->flags & +I2C_CLIENT_PEC )); } + +static ssize_t pec_store(struct device *dev, struct device_attribute*devattr,
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 13 lines
drivers/hwmon/max31827.c +13
-0+ const char *buf, size_t count) +{ +struct max31827_state *st =dev_get_drvdata (dev); +struct i2c_client *client = st->client; +unsigned int val; +u16 val2; +int err; + + err =kstrtouint (buf,10 , &val); +if (err <0 ) +return err; + + val2 = FIELD_PREP(MAX31827_CONFIGURATION_PEC_EN_MASK,val);
drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 8 lines
drivers/hwmon/max31827.c +8
-0+ +if (err) +return err; + +switch (val) { +case 0 : + client->flags &= ~I2C_CLIENT_PEC ; + err = max31827_update_bits(client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct · line 561
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_PEC_EN_MASK,drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct device *dev,
Quoted 6 lines
drivers/hwmon/max31827.c +6
-0+ val2); +if (err) +return err; +break ; +case 1 : + err = max31827_update_bits(client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static ssize_t temp1_resolution_store(struct · line 568
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+
MAX31827_CONFIGURATION_PEC_EN_MASK,drivers/hwmon/max31827.c static const struct i2c_device_id
Quoted 22 lines
drivers/hwmon/max31827.c +14
-0+ val2); +if (err) +return err; + client->flags |=I2C_CLIENT_PEC ; +break ; +default : +return -EINVAL ; + } + +return count; +} +static DEVICE_ATTR_RW (temp1_resolution); +static DEVICE_ATTR_RW (pec);static struct attribute *max31827_attrs[] = { &dev_attr_temp1_resolution.attr, + &dev_attr_pec.attr,NULL };ATTRIBUTE_GROUPS (max31827);@@ -489,9 +596,9 @@ static const struct i2c_device_idmax31827_i2c_ids[] = {
drivers/hwmon/max31827.c static const struct i2c_device_id max31827_i2c_ids[] = { · line 601
Quoted 8 lines
drivers/hwmon/max31827.c +2
-2};MODULE_DEVICE_TABLE (i2c, max31827_i2c_ids); -static int max31827_init_client (struct max31827_state *st, -struct device *dev) +static int max31827_init_client (struct max31827_state *st) { +struct device *dev = &st->client->dev;Now we are absolutely down to personal preference changes. I am not at all inclined to accept such changes, sorry.
Including such changes means I'll have to put extra scrutiny on your patch submissions in the future to ensure that you don't try to sneak in similar changes, which I find quite frustrating. Is that really necessary ?
Guenter
drivers/hwmon/max31827.c static int max31827_init_client(struct
Quoted 4 lines
drivers/hwmon/max31827.c +0
-0struct fwnode_handle *fwnode;unsigned int res =0 ;u32 data, lsb_idx;@@ -575,7 +682,7 @@ static int max31827_init_client(struct
max31827_state*st,drivers/hwmon/max31827.c static int max31827_init_client(struct · line 578
Quoted 4 lines
drivers/hwmon/max31827.c +0
-1} } - return regmap_write(st->regmap,
MAX31827_CONFIGURATION_REG, res);drivers/hwmon/max31827.c static int max31827_init_client(struct · line 685
Quoted 1 line
drivers/hwmon/max31827.c +1
-0+ return max31827_reg_write(st->client,
MAX31827_CONFIGURATION_REG,drivers/hwmon/max31827.c static int max31827_init_client(struct
Quoted 5 lines
drivers/hwmon/max31827.c +1
-1+res); } static const struct hwmon_channel_info *max31827_info[] = { @@ -613,17 +720,13 @@ static int max31827_probe(struct i2c_client*client)
drivers/hwmon/max31827.c
Quoted 5 lines
return
-ENOMEM;mutex_init(&st->lock);drivers/hwmon/max31827.c +0
-2- - st->regmap = devm_regmap_init_i2c(client,
&max31827_regmap);drivers/hwmon/max31827.c static int max31827_probe(struct i2c_client *client)
Quoted 8 lines
drivers/hwmon/max31827.c +1
-3-if (IS_ERR (st->regmap)) -return dev_err_probe (dev,PTR_ERR (st->regmap), -"Failed to allocate regmap.\n" ); + st->client = client; err =devm_regulator_get_enable (dev,"vref" );if (err) return dev_err_probe(dev, err, "failed to enableregulator\n");
Quoted 6 lines
drivers/hwmon/max31827.c +1
-1- err =max31827_init_client (st, dev); + err =max31827_init_client (st);if (err)return err;
Guenter Roeck
maintainerOn 12/18/23 06:55, Matyas, Daniel wrote:
[ ... ]
Quoted 11 lines
Quoted 6 lines
On top of that, it is not clear why regmap can't be used in the first place. It seems that the major change is that one needs to read the configuration register after a write to see if there was a PEC error. It is not immediately obvious why that additional read (if indeed necessary) would require regmap support to be dropped.
I tried out writing and and reading with regmap, but it is not working properly. Even if I modify the client flag, I still receive only 2 bytes of data (a word). I should be receiving 2+1 bytes = data + CRC-8.
With
i2c_smbusreads and writes, when I set the flag, I receive the 2+1 bytes, as expected.
The SMBus code in drivers/i2c/i2c-core-smbus.c is supposed to check if the received PEC is correct for SMBus transfers. Are you saying that this doesn't work, or that regmap doesn't use SMBus functions to communicate with the chip ?
Thanks,
Guenter
A message that is not in the archive (sent off-list or not yet received): PH0PR03MB6771CF6A95CB576E534C225F8990A@PH0PR03MB6771.namprd03.prod.outlook.com
Guenter Roeck
maintainerQuoted 30 lines · Daniel
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*Von:* Guenter Roeck <[email protected]> im Auftrag von Guenter Roeck <[email protected]>
*Gesendet:* Montag, Dezember 18, 2023 6:26:57 nachm.
*An:* Matyas, Daniel <[email protected]>
*Cc:* Jean Delvare <[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] <[email protected]>; [email protected] <[email protected]> *Betreff:* Re: [PATCH 1/3] hwmon: max31827: Add PEC support[External]
On 12/18/23 06:55, Matyas, Daniel wrote:
[ ... ]Quoted 11 lines
Quoted 6 lines
On top of that, it is not clear why regmap can't be used in the first place. It seems that the major change is that one needs to read the configuration register after a write to see if there was a PEC error. It is not immediately obvious why that additional read (if indeed necessary) would require regmap support to be dropped.
I tried out writing and and reading with regmap, but it is not working properly. Even if I modify the client flag, I still receive only 2 bytes of data (a word). I should be receiving 2+1 bytes = data + CRC-8.
With
i2c_smbusreads and writes, when I set the flag, I receive the 2+1 bytes, as expected.The SMBus code in
drivers/i2c/i2c-core-smbus.cis supposed to check if the received PEC is correct for SMBus transfers. Are you saying that this doesn't work, or that regmap doesn't use SMBus functions to communicate with the chip ?
Quoted 6 lines
Thanks,
GuenterI am 70% sure, that the regmap does not use SMBus functions.
It should.
$ git grep smbus drivers/base/regmap/regmap-i2c.c
drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_byte_reg_read(void *context, unsigned int reg,
drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_read_byte_data(i2c, reg);
drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_byte_reg_write(void *context, unsigned int reg,
drivers/base/regmap/regmap-i2c.c: return i2c_smbus_write_byte_data(i2c, reg, val);
drivers/base/regmap/regmap-i2c.c:static const struct regmap_bus regmap_smbus_byte = {
drivers/base/regmap/regmap-i2c.c: .reg_write = regmap_smbus_byte_reg_write,
drivers/base/regmap/regmap-i2c.c: .reg_read = regmap_smbus_byte_reg_read,
drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_word_reg_read(void *context, unsigned int reg,
drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_read_word_data(i2c, reg);
drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_word_reg_write(void *context, unsigned int reg,
drivers/base/regmap/regmap-i2c.c: return i2c_smbus_write_word_data(i2c, reg, val);
drivers/base/regmap/regmap-i2c.c:static const struct regmap_bus regmap_smbus_word = {
drivers/base/regmap/regmap-i2c.c: .reg_write = regmap_smbus_word_reg_write,
drivers/base/regmap/regmap-i2c.c: .reg_read = regmap_smbus_word_reg_read,
drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_word_read_swapped(void *context, unsigned int reg,
drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_read_word_swapped(i2c, reg);
drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_word_write_swapped(void *context, unsigned int reg,
drivers/base/regmap/regmap-i2c.c: return i2c_smbus_write_word_swapped(i2c, reg, val);
drivers/base/regmap/regmap-i2c.c:static const struct regmap_bus regmap_smbus_word_swapped = {
drivers/base/regmap/regmap-i2c.c: .reg_write = regmap_smbus_word_write_swapped,
drivers/base/regmap/regmap-i2c.c: .reg_read = regmap_smbus_word_read_swapped,
drivers/base/regmap/regmap-i2c.c:static int regmap_i2c_smbus_i2c_write(void *context, const void *data,
drivers/base/regmap/regmap-i2c.c: return i2c_smbus_write_i2c_block_data(i2c, ((u8 *)data)[0], count,
drivers/base/regmap/regmap-i2c.c:static int regmap_i2c_smbus_i2c_read(void *context, const void *reg,
drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_read_i2c_block_data(i2c, ((u8 *)reg)[0], val_size, val);
drivers/base/regmap/regmap-i2c.c:static const struct regmap_bus regmap_i2c_smbus_i2c_block = {
drivers/base/regmap/regmap-i2c.c: .write = regmap_i2c_smbus_i2c_write,
drivers/base/regmap/regmap-i2c.c: .read = regmap_i2c_smbus_i2c_read,
drivers/base/regmap/regmap-i2c.c:static int regmap_i2c_smbus_i2c_write_reg16(void *context, const void *data,
drivers/base/regmap/regmap-i2c.c: return i2c_smbus_write_i2c_block_data(i2c, ((u8 *)data)[0], count,
drivers/base/regmap/regmap-i2c.c:static int regmap_i2c_smbus_i2c_read_reg16(void *context, const void *reg,
drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_write_byte_data(i2c, ((u16 *)reg)[0] & 0xff,
drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_read_byte(i2c);
drivers/base/regmap/regmap-i2c.c:static const struct regmap_bus regmap_i2c_smbus_i2c_block_reg16 = {
drivers/base/regmap/regmap-i2c.c: .write = regmap_i2c_smbus_i2c_write_reg16,
drivers/base/regmap/regmap-i2c.c: .read = regmap_i2c_smbus_i2c_read_reg16,
drivers/base/regmap/regmap-i2c.c: bus = ®map_i2c_smbus_i2c_block;
drivers/base/regmap/regmap-i2c.c: bus = ®map_i2c_smbus_i2c_block_reg16;
drivers/base/regmap/regmap-i2c.c: bus = ®map_smbus_word;
drivers/base/regmap/regmap-i2c.c: bus = ®map_smbus_word_swapped;
drivers/base/regmap/regmap-i2c.c: bus = ®map_smbus_byte;If that doesn't work for some reason, I'd rather figure out why instead of starting to drop regmap support.
Guenter
Quoted 166 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Monday, December 18, 2023 9:01 PM
To: Matyas, Daniel <[email protected]>
Cc: Jean Delvare <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 1/3] hwmon: max31827: Add PEC support[External]
Quoted 18 lines · Daniel
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------
*Von:* Guenter Roeck <[email protected]> im Auftrag von GuenterRoeck
Quoted 13 lines
<[email protected]>
*Gesendet:* Montag, Dezember 18, 2023 6:26:57 nachm. *An:* Matyas, Daniel <[email protected]> *Cc:* Jean Delvare <[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] <[email protected]>; [email protected] <[email protected]> *Betreff:* Re: [PATCH 1/3] hwmon: max31827: Add PEC supportQuoted 5 lines
[External]
On 12/18/23 06:55, Matyas, Daniel wrote:
[ ... ]Quoted 1 line
Quoted 1 line
On top of that, it is not clear why regmap can't be used in the first
place.
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
It seems that the major change is that one needs to read the configuration register after a write to see if there was a PEC error. It is not immediately obvious why that additional read (if indeed necessary) would require regmap support to be dropped.
I tried out writing and and reading with regmap, but it is not working
properly. Even if I modify the client flag, I still receive only 2 bytes of data (a word). I should be receiving 2+1 bytes = data + CRC-8.
Quoted 2 lines
Quoted 2 lines
With
i2c_smbusreads and writes, when I set the flag, I receive the 2+1bytes, as expected.
Quoted 7 lines
Quoted 1 line
The SMBus code in
drivers/i2c/i2c-core-smbus.cis supposed to check if the received PEC is correct for SMBus transfers. Are you saying that this doesn't work, or that regmap doesn't use SMBus functions to communicate with the chip ?Quoted 6 lines
Thanks,
GuenterI am 70% sure, that the regmap does not use SMBus functions.
It should.
$ git grep smbus drivers/base/regmap/regmap-i2c.c drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_byte_reg_read(void *context, unsigned int reg, drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_read_byte_data(i2c, reg); drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_byte_reg_write(void *context, unsigned int reg, drivers/base/regmap/regmap-i2c.c: return i2c_smbus_write_byte_data(i2c, reg, val); drivers/base/regmap/regmap-i2c.c:static const struct regmap_bus regmap_smbus_byte = { drivers/base/regmap/regmap-i2c.c: .reg_write = regmap_smbus_byte_reg_write, drivers/base/regmap/regmap-i2c.c: .reg_read = regmap_smbus_byte_reg_read, drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_word_reg_read(void *context, unsigned int reg, drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_read_word_data(i2c, reg); drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_word_reg_write(void *context, unsigned int reg, drivers/base/regmap/regmap-i2c.c: return i2c_smbus_write_word_data(i2c, reg, val); drivers/base/regmap/regmap-i2c.c:static const struct regmap_bus regmap_smbus_word = { drivers/base/regmap/regmap-i2c.c: .reg_write = regmap_smbus_word_reg_write, drivers/base/regmap/regmap-i2c.c: .reg_read = regmap_smbus_word_reg_read, drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_word_read_swapped(void *context, unsigned int reg, drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_read_word_swapped(i2c, reg); drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_word_write_swapped(void *context, unsigned int reg, drivers/base/regmap/regmap-i2c.c: return i2c_smbus_write_word_swapped(i2c, reg, val); drivers/base/regmap/regmap-i2c.c:static const struct regmap_bus regmap_smbus_word_swapped = { drivers/base/regmap/regmap-i2c.c: .reg_write = regmap_smbus_word_write_swapped, drivers/base/regmap/regmap-i2c.c: .reg_read = regmap_smbus_word_read_swapped, drivers/base/regmap/regmap-i2c.c:static int regmap_i2c_smbus_i2c_write(void *context, const void *data, drivers/base/regmap/regmap-i2c.c: return i2c_smbus_write_i2c_block_data(i2c, ((u8 *)data)[0], count, drivers/base/regmap/regmap-i2c.c:static int regmap_i2c_smbus_i2c_read(void *context, const void *reg, drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_read_i2c_block_data(i2c, ((u8 *)reg)[0], val_size, val); drivers/base/regmap/regmap-i2c.c:static const struct regmap_bus regmap_i2c_smbus_i2c_block = { drivers/base/regmap/regmap-i2c.c: .write = regmap_i2c_smbus_i2c_write, drivers/base/regmap/regmap-i2c.c: .read = regmap_i2c_smbus_i2c_read, drivers/base/regmap/regmap-i2c.c:static int regmap_i2c_smbus_i2c_write_reg16(void *context, const void *data, drivers/base/regmap/regmap-i2c.c: return i2c_smbus_write_i2c_block_data(i2c, ((u8 *)data)[0], count, drivers/base/regmap/regmap-i2c.c:static int regmap_i2c_smbus_i2c_read_reg16(void *context, const void *reg, drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_write_byte_data(i2c, ((u16 *)reg)[0] & 0xff, drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_read_byte(i2c); drivers/base/regmap/regmap-i2c.c:static const struct regmap_bus regmap_i2c_smbus_i2c_block_reg16 = { drivers/base/regmap/regmap-i2c.c: .write = regmap_i2c_smbus_i2c_write_reg16, drivers/base/regmap/regmap-i2c.c: .read = regmap_i2c_smbus_i2c_read_reg16, drivers/base/regmap/regmap-i2c.c: bus = ®map_i2c_smbus_i2c_block; drivers/base/regmap/regmap-i2c.c: bus = ®map_i2c_smbus_i2c_block_reg16; drivers/base/regmap/regmap-i2c.c: bus = ®map_smbus_word; drivers/base/regmap/regmap-i2c.c: bus = ®map_smbus_word_swapped; drivers/base/regmap/regmap-i2c.c: bus = ®map_smbus_byte;
Quoted 4 lines
If that doesn't work for some reason, I'd rather figure out why instead of starting to drop regmap support.
Guenter
I tried to figure it out and this is what I came up with. The code snippet below is from drivers/base/regmap/regmap-i2c.c:
static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c,
const struct regmap_config *config)
{
const struct i2c_adapter_quirks *quirks;
const struct regmap_bus *bus = NULL;
struct regmap_bus *ret_bus;
u16 max_read = 0, max_write = 0;
if (i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C))
bus = ®map_i2c;
else if (config->val_bits == 8 && config->reg_bits == 8 &&
i2c_check_functionality(i2c->adapter,
I2C_FUNC_SMBUS_I2C_BLOCK))
bus = ®map_i2c_smbus_i2c_block;
else if (config->val_bits == 8 && config->reg_bits == 16 &&
i2c_check_functionality(i2c->adapter,
I2C_FUNC_SMBUS_I2C_BLOCK))
bus = ®map_i2c_smbus_i2c_block_reg16;
else if (config->val_bits == 16 && config->reg_bits == 8 &&
i2c_check_functionality(i2c->adapter,
I2C_FUNC_SMBUS_WORD_DATA))
switch (regmap_get_val_endian(&i2c->dev, NULL, config)) {
case REGMAP_ENDIAN_LITTLE:
bus = ®map_smbus_word;
break;
case REGMAP_ENDIAN_BIG:
bus = ®map_smbus_word_swapped;
break;
default: /* everything else is not supported */
break;
}This is executed when regmap is initialized. My adapter has the I2C_FUNC_I2C functionality (I use a raspberry pi 4), so it seems to me like regmap_i2c is loaded as the bus. This uses i2c_transfer internally to read and write.
For PEC I need regmap_smbus_word. This uses i2c_smbus_xfer internally. Unlike i2c_transfer, i2c_smbus_xfer can be used to send and receive PEC byte.
What should I do?
Kind regards,
Daniel
Guenter Roeck
maintainerQuoted 205 lines · Daniel
Quoted 166 lines
-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Monday, December 18, 2023 9:01 PM
To: Matyas, Daniel <[email protected]>
Cc: Jean Delvare <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Jonathan Corbet <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 1/3] hwmon: max31827: Add PEC support[External]
Quoted 18 lines · Daniel
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------------------------
----------
*Von:* Guenter Roeck <[email protected]> im Auftrag von GuenterRoeck
Quoted 13 lines
<[email protected]>
*Gesendet:* Montag, Dezember 18, 2023 6:26:57 nachm. *An:* Matyas, Daniel <[email protected]> *Cc:* Jean Delvare <[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] <[email protected]>; [email protected] <[email protected]> *Betreff:* Re: [PATCH 1/3] hwmon: max31827: Add PEC supportQuoted 5 lines
[External]
On 12/18/23 06:55, Matyas, Daniel wrote:
[ ... ]Quoted 1 line
Quoted 1 line
On top of that, it is not clear why regmap can't be used in the first
place.
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
It seems that the major change is that one needs to read the configuration register after a write to see if there was a PEC error. It is not immediately obvious why that additional read (if indeed necessary) would require regmap support to be dropped.
I tried out writing and and reading with regmap, but it is not working
properly. Even if I modify the client flag, I still receive only 2 bytes of data (a word). I should be receiving 2+1 bytes = data + CRC-8.
Quoted 2 lines
Quoted 2 lines
With
i2c_smbusreads and writes, when I set the flag, I receive the 2+1bytes, as expected.
Quoted 7 lines
Quoted 1 line
The SMBus code in
drivers/i2c/i2c-core-smbus.cis supposed to check if the received PEC is correct for SMBus transfers. Are you saying that this doesn't work, or that regmap doesn't use SMBus functions to communicate with the chip ?Quoted 6 lines
Thanks,
GuenterI am 70% sure, that the regmap does not use SMBus functions.
It should.
$ git grep smbus drivers/base/regmap/regmap-i2c.c drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_byte_reg_read(void *context, unsigned int reg, drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_read_byte_data(i2c, reg); drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_byte_reg_write(void *context, unsigned int reg, drivers/base/regmap/regmap-i2c.c: return i2c_smbus_write_byte_data(i2c, reg, val); drivers/base/regmap/regmap-i2c.c:static const struct regmap_bus regmap_smbus_byte = { drivers/base/regmap/regmap-i2c.c: .reg_write = regmap_smbus_byte_reg_write, drivers/base/regmap/regmap-i2c.c: .reg_read = regmap_smbus_byte_reg_read, drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_word_reg_read(void *context, unsigned int reg, drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_read_word_data(i2c, reg); drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_word_reg_write(void *context, unsigned int reg, drivers/base/regmap/regmap-i2c.c: return i2c_smbus_write_word_data(i2c, reg, val); drivers/base/regmap/regmap-i2c.c:static const struct regmap_bus regmap_smbus_word = { drivers/base/regmap/regmap-i2c.c: .reg_write = regmap_smbus_word_reg_write, drivers/base/regmap/regmap-i2c.c: .reg_read = regmap_smbus_word_reg_read, drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_word_read_swapped(void *context, unsigned int reg, drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_read_word_swapped(i2c, reg); drivers/base/regmap/regmap-i2c.c:static int regmap_smbus_word_write_swapped(void *context, unsigned int reg, drivers/base/regmap/regmap-i2c.c: return i2c_smbus_write_word_swapped(i2c, reg, val); drivers/base/regmap/regmap-i2c.c:static const struct regmap_bus regmap_smbus_word_swapped = { drivers/base/regmap/regmap-i2c.c: .reg_write = regmap_smbus_word_write_swapped, drivers/base/regmap/regmap-i2c.c: .reg_read = regmap_smbus_word_read_swapped, drivers/base/regmap/regmap-i2c.c:static int regmap_i2c_smbus_i2c_write(void *context, const void *data, drivers/base/regmap/regmap-i2c.c: return i2c_smbus_write_i2c_block_data(i2c, ((u8 *)data)[0], count, drivers/base/regmap/regmap-i2c.c:static int regmap_i2c_smbus_i2c_read(void *context, const void *reg, drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_read_i2c_block_data(i2c, ((u8 *)reg)[0], val_size, val); drivers/base/regmap/regmap-i2c.c:static const struct regmap_bus regmap_i2c_smbus_i2c_block = { drivers/base/regmap/regmap-i2c.c: .write = regmap_i2c_smbus_i2c_write, drivers/base/regmap/regmap-i2c.c: .read = regmap_i2c_smbus_i2c_read, drivers/base/regmap/regmap-i2c.c:static int regmap_i2c_smbus_i2c_write_reg16(void *context, const void *data, drivers/base/regmap/regmap-i2c.c: return i2c_smbus_write_i2c_block_data(i2c, ((u8 *)data)[0], count, drivers/base/regmap/regmap-i2c.c:static int regmap_i2c_smbus_i2c_read_reg16(void *context, const void *reg, drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_write_byte_data(i2c, ((u16 *)reg)[0] & 0xff, drivers/base/regmap/regmap-i2c.c: ret = i2c_smbus_read_byte(i2c); drivers/base/regmap/regmap-i2c.c:static const struct regmap_bus regmap_i2c_smbus_i2c_block_reg16 = { drivers/base/regmap/regmap-i2c.c: .write = regmap_i2c_smbus_i2c_write_reg16, drivers/base/regmap/regmap-i2c.c: .read = regmap_i2c_smbus_i2c_read_reg16, drivers/base/regmap/regmap-i2c.c: bus = ®map_i2c_smbus_i2c_block; drivers/base/regmap/regmap-i2c.c: bus = ®map_i2c_smbus_i2c_block_reg16; drivers/base/regmap/regmap-i2c.c: bus = ®map_smbus_word; drivers/base/regmap/regmap-i2c.c: bus = ®map_smbus_word_swapped; drivers/base/regmap/regmap-i2c.c: bus = ®map_smbus_byte;Quoted 4 lines
If that doesn't work for some reason, I'd rather figure out why instead of starting to drop regmap support.
Guenter
I tried to figure it out and this is what I came up with. The code snippet below is from
drivers/base/regmap/regmap-i2c.c:static const struct
regmap_bus*regmap_get_i2c_bus(structi2c_client*i2c,
const structregmap_config*config){ const struct i2c_adapter_quirks *quirks; const struct regmap_bus *bus = NULL; struct regmap_bus *ret_bus; u16 max_read = 0, max_write = 0; if (i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) bus = ®map_i2c; else if (config->val_bits == 8 && config->reg_bits == 8 && i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) bus = ®map_i2c_smbus_i2c_block; else if (config->val_bits == 8 && config->reg_bits == 16 && i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) bus = ®map_i2c_smbus_i2c_block_reg16; else if (config->val_bits == 16 && config->reg_bits == 8 && i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_WORD_DATA)) switch (regmap_get_val_endian(&i2c->dev, NULL, config)) { case REGMAP_ENDIAN_LITTLE: bus = ®map_smbus_word; break; case REGMAP_ENDIAN_BIG: bus = ®map_smbus_word_swapped; break; default: /* everything else is not supported */ break; }
Quoted 6 lines
This is executed when regmap is initialized. My adapter has the
I2C_FUNC_I2Cfunctionality (I use a raspberry pi 4), so it seems to me likeregmap_i2cis loaded as the bus. This usesi2c_transferinternally to read and write.For PEC I need
regmap_smbus_word. This usesi2c_smbus_xferinternally. Unlikei2c_transfer,i2c_smbus_xfercan be used to send and receive PEC byte.What should I do?
It seems to me that regmap should not use functions not supporting PEC if I2C_CLIENT_PEC is enabled on an i2c device. Of course, that is tricky if not impossible to implement because the flag can be set at runtime but the bus function assignment in regmap is static.
The only alternative I can think of is to define driver specific regmap access functions to re-implement the regmap_smbus_word access functions. That is less than perfect but better than to drop regmap access entirely.
Copying Mark Brown for additional input.
Thanks,
Guenter