diff mbox series

[v3,17/19] hwmon: (mr75203) parse temperature coefficients from device-tree

Message ID 20220830192212.28570-18-farbere@amazon.com (mailing list archive)
State Changes Requested
Headers show
Series Variety of fixes and new features for mr75203 driver | expand

Commit Message

Eliav Farber Aug. 30, 2022, 7:22 p.m. UTC
Use thermal coefficients from the device tree if they exist.
Otherwise, use default values according to the series (5 or 6).
All coefficients can be used or only part of them.

The coefficients shall be used for fine tuning the default values since
coefficients can vary between product and product.

Signed-off-by: Eliav Farber <farbere@amazon.com>
---
 drivers/hwmon/mr75203.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

Comments

Andy Shevchenko Aug. 31, 2022, 12:11 p.m. UTC | #1
On Tue, Aug 30, 2022 at 07:22:10PM +0000, Eliav Farber wrote:
> Use thermal coefficients from the device tree if they exist.
> Otherwise, use default values according to the series (5 or 6).
> All coefficients can be used or only part of them.
> 
> The coefficients shall be used for fine tuning the default values since
> coefficients can vary between product and product.

...

> +	ret = of_property_read_u32(np, "moortec,ts-coeff-h", &coeff_h);

of_ ?! Ditto for the rest.

> +	if (!ret)
> +		ts_coeff->h = coeff_h;

...

> +	ret = of_property_read_s32(np, "moortec,ts-coeff-j", &coeff_j);
> +	if (!ret)
> +		ts_coeff->j = coeff_j;

You may avoid conditional:

	_property_read_s32(..., "moortec,ts-coeff-j", &ts_coeff->j);


...

> +	ret = of_property_read_u32(np, "moortec,ts-coeff-cal5", &coeff_cal5);
> +	if (!ret) {

> +		if (coeff_cal5 == 0) {
> +			dev_err(dev, "moortec,ts-coeff-cal5 can't be 0\n");
> +			return -EINVAL;
> +		}

Code shouldn't be a YAML validator. Drop this and make sure you have correct
DT schema.

> +		ts_coeff->cal5 = coeff_cal5;
> +	}

Also see above.
Eliav Farber Sept. 1, 2022, 9:54 a.m. UTC | #2
On 8/31/2022 3:11 PM, Andy Shevchenko wrote:
> On Tue, Aug 30, 2022 at 07:22:10PM +0000, Eliav Farber wrote:
>> Use thermal coefficients from the device tree if they exist.
>> Otherwise, use default values according to the series (5 or 6).
>> All coefficients can be used or only part of them.
>>
>> The coefficients shall be used for fine tuning the default values since
>> coefficients can vary between product and product.
>
> ...
>
>> +     ret = of_property_read_u32(np, "moortec,ts-coeff-h", &coeff_h);
>
> of_ ?! Ditto for the rest.


Fixed for v4.
I replaced it with device_property_read_u32().

>> +     if (!ret)
>> +             ts_coeff->h = coeff_h;
>
> ...
>
>> +     ret = of_property_read_s32(np, "moortec,ts-coeff-j", &coeff_j);
>> +     if (!ret)
>> +             ts_coeff->j = coeff_j;
>
> You may avoid conditional:
>
>        _property_read_s32(..., "moortec,ts-coeff-j", &ts_coeff->j);


Fixed for v4.
I removed the condition.

> ...
>
>> +     ret = of_property_read_u32(np, "moortec,ts-coeff-cal5", 
>> &coeff_cal5);
>> +     if (!ret) {
>
>> +             if (coeff_cal5 == 0) {
>> +                     dev_err(dev, "moortec,ts-coeff-cal5 can't be 
>> 0\n");
>> +                     return -EINVAL;
>> +             }
>
> Code shouldn't be a YAML validator. Drop this and make sure you have 
> correct
> DT schema.


Fixed for v4.
I dropped the validation check.
The YAML already mentions that it can't be 0.

>> +             ts_coeff->cal5 = coeff_cal5;
>> +     }

--
Thanks, Eliav
diff mbox series

Patch

diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c
index 6a035fd115ca..d9fc5d225868 100644
--- a/drivers/hwmon/mr75203.c
+++ b/drivers/hwmon/mr75203.c
@@ -676,7 +676,8 @@  static int pvt_set_temp_coeff(struct device *dev, struct pvt_device *pvt)
 {
 	struct temp_coeff *ts_coeff = &pvt->ts_coeff;
 	const struct device_node *np = dev->of_node;
-	u32 series;
+	u32 series, coeff_h, coeff_g, coeff_cal5;
+	s32 coeff_j;
 	int ret;
 
 	/* Incase ts-series property is not defined, use default 5. */
@@ -702,6 +703,32 @@  static int pvt_set_temp_coeff(struct device *dev, struct pvt_device *pvt)
 
 	dev_dbg(dev, "temperature sensor series = %u\n", series);
 
+	/* Override ts-coeff-h/g/j/cal5 if they are defined. */
+	ret = of_property_read_u32(np, "moortec,ts-coeff-h", &coeff_h);
+	if (!ret)
+		ts_coeff->h = coeff_h;
+
+	ret = of_property_read_u32(np, "moortec,ts-coeff-g", &coeff_g);
+	if (!ret)
+		ts_coeff->g = coeff_g;
+
+	ret = of_property_read_s32(np, "moortec,ts-coeff-j", &coeff_j);
+	if (!ret)
+		ts_coeff->j = coeff_j;
+
+	ret = of_property_read_u32(np, "moortec,ts-coeff-cal5", &coeff_cal5);
+	if (!ret) {
+		if (coeff_cal5 == 0) {
+			dev_err(dev, "moortec,ts-coeff-cal5 can't be 0\n");
+			return -EINVAL;
+		}
+
+		ts_coeff->cal5 = coeff_cal5;
+	}
+
+	dev_dbg(dev, "ts-coeff: h = %u, g = %u, j = %d, cal5 = %u\n",
+		ts_coeff->h, ts_coeff->g, ts_coeff->j, ts_coeff->cal5);
+
 	return 0;
 }