From: Ciprian Costea <[email protected]> commit fae976973e60dc610aeeb9318efaf64209e8a763 from https://github.com/nxp-auto-linux/linux
'TRANGE' represents the valid temperature range on which the TMU can operate on. This value interval differs depending on S32CC SoC. Issue: ALB-9890 Signed-off-by: Ciprian Costea <[email protected]> Signed-off-by: Zhantao Tang <[email protected]> --- drivers/thermal/s32cc_thermal.c | 47 +++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/drivers/thermal/s32cc_thermal.c b/drivers/thermal/s32cc_thermal.c index 76c1b4cb25af..8a051a4f966c 100644 --- a/drivers/thermal/s32cc_thermal.c +++ b/drivers/thermal/s32cc_thermal.c @@ -44,6 +44,9 @@ struct tmu_chip { u32 *warm_idxes; u32 *cold_idxes; u8 trim_idxes_num; + + s16 trange_min; + s16 trange_max; }; static struct tmu_chip s32g2_tmu = { @@ -55,6 +58,8 @@ static struct tmu_chip s32g2_tmu = { .warm_idxes = (u32 []){3}, .cold_idxes = (u32 []){0}, .trim_idxes_num = 1, + .trange_min = -40, + .trange_max = 125, }; static struct tmu_chip s32g3_tmu = { @@ -66,6 +71,8 @@ static struct tmu_chip s32g3_tmu = { .warm_idxes = (u32 []){4, 5}, .cold_idxes = (u32 []){0, 1}, .trim_idxes_num = 2, + .trange_min = -45, + .trange_max = 130, }; static struct tmu_chip s32r45_tmu = { @@ -77,6 +84,8 @@ static struct tmu_chip s32r45_tmu = { .warm_idxes = (u32 []){4, 5}, .cold_idxes = (u32 []){0, 1}, .trim_idxes_num = 2, + .trange_min = -45, + .trange_max = 155, }; enum measurement_interval_t { @@ -110,6 +119,8 @@ struct tmu_driver_data { union s32cc_tmu_fuse tmu_fuse_val; struct device *hwmon_device; s16 temp_offset; + s16 trange_min; + s16 trange_max; }; static int get_site_idx_from_label(const char *label) @@ -132,23 +143,16 @@ static int get_site_idx_from_label(const char *label) !strncmp(label, "temp6_input", cmp_size)) return 2; - return -1; + return -EINVAL; } -static inline int is_out_of_range(int8_t temperature) +static inline int is_out_of_range(struct tmu_driver_data *tmu_dd, + s16 temp) { - return (temperature < -40 || temperature > 125); + return (temp < tmu_dd->trange_min || + temp > tmu_dd->trange_max); } -/* 8 bit TEMP field of the RITSR and RATSR registers should be interpreted - * as a signed integer when the temperature is below 25 degrees - * Celsius and as an unsigned integer when the temperature is above 25 - * degrees. The fact that the sensor reading range is -40 to 125 degrees - * allows us to simply cast to an int8_t, since within this range - * interpreting the field as a signed integer always leads to the - * correct result. If the value would ever fall outside this range, - * the `Valid` bit of the registers would be cleared by hardware. - */ static int tmu_immediate_temperature(struct device *dev, s16 *immediate_temperature, bool *point5, int site) @@ -161,10 +165,10 @@ static int tmu_immediate_temperature(struct device *dev, *immediate_temperature = (s16)tmu_ritsr.B.TEMP; *immediate_temperature -= tmu_dd->temp_offset; *point5 = (bool)tmu_ritsr.B.TP5; - return is_out_of_range(*immediate_temperature); + return is_out_of_range(tmu_dd, *immediate_temperature); } - return -1; + return -EBUSY; } static int tmu_average_temperature(struct device *dev, @@ -177,10 +181,10 @@ static int tmu_average_temperature(struct device *dev, if (likely(tmu_ratsr.B.V == 0x1)) { *average_temperature = (s16)tmu_ratsr.B.TEMP; *average_temperature -= tmu_dd->temp_offset; - return is_out_of_range(*average_temperature); + return is_out_of_range(tmu_dd, *average_temperature); } - return -1; + return -EBUSY; } static ssize_t tmu_show_immediate_label(struct device *dev, @@ -190,7 +194,7 @@ static ssize_t tmu_show_immediate_label(struct device *dev, int site; site = get_site_idx_from_label(attr->attr.name); - if (site == -1) + if (site == -EINVAL) return snprintf(buffer, PAGE_SIZE, "Invalid site\n"); return snprintf(buffer, PAGE_SIZE, "Immediate temperature for site %d\n", site); @@ -205,7 +209,7 @@ static ssize_t tmu_show_immediate(struct device *dev, int site; site = get_site_idx_from_label(attr->attr.name); - if (site == -1) + if (site == -EINVAL) return snprintf(buffer, PAGE_SIZE, "Invalid site\n"); if (tmu_immediate_temperature(dev, &immediate_temperature, &point5, site)) @@ -223,7 +227,7 @@ static ssize_t tmu_show_average_label(struct device *dev, int site; site = get_site_idx_from_label(attr->attr.name); - if (site == -1) + if (site == -EINVAL) return snprintf(buffer, PAGE_SIZE, "Invalid site\n"); return snprintf(buffer, PAGE_SIZE, "Average temperature for site %d\n", site); @@ -237,7 +241,7 @@ static ssize_t tmu_show_average(struct device *dev, int site; site = get_site_idx_from_label(attr->attr.name); - if (site == -1) + if (site == -EINVAL) return snprintf(buffer, PAGE_SIZE, "Invalid site\n"); if (tmu_average_temperature(dev, &average_temperature, site)) return snprintf(buffer, PAGE_SIZE, @@ -478,6 +482,9 @@ static int tmu_probe(struct platform_device *pd) GFP_KERNEL); if (!tmu_dd) return -ENOMEM; + + tmu_dd->trange_min = tmu_chip->trange_min; + tmu_dd->trange_max = tmu_chip->trange_max; dev_set_drvdata(dev, tmu_dd); tmu_resource = platform_get_resource(pd, IORESOURCE_MEM, 0); -- 2.25.1
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#12332): https://lists.yoctoproject.org/g/linux-yocto/message/12332 Mute This Topic: https://lists.yoctoproject.org/mt/97945968/21656 Group Owner: [email protected] Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
