Message ID | 20220830192212.28570-16-farbere@amazon.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | Variety of fixes and new features for mr75203 driver | expand |
On Tue, Aug 30, 2022 at 07:22:08PM +0000, Eliav Farber wrote: > The current equation used in code is aligned to series 5: > T = G + H * (n / cal5 - 0.5) + J * F > Where: > G = 60, H = 200, cal5 = 4094, J = -0.1, F = frequency clock in MHz > > Series 6 has a slightly different equation: > T = G + H * (n / cal5 - 0.5) > and a different set of coefficients: > G = 57.4, H = 249.4, cal5 = 4096 > > This change supports equation and coefficients for both series. > (for series 6, J is set to 0). > > The series is determined according to “ts-series” property in device > tree. > If absent, series 5 is assumed to be the default. ... > -#define PVT_H_CONST 200000 > -#define PVT_G_CONST 60000 > -#define PVT_J_CONST -100 > -#define PVT_CAL5_CONST 4094 You just introduced them patch before. Please, avoid ping-pong style in the same series. ... > + ret = of_property_read_u32(np, "moortec,ts-series", &series); of_ ?! Be consistent. Either you use OF everywhere, or device property APIs. ... > + if (ret) > + series = TEMPERATURE_SENSOR_SERIES_5; > + > + if (series == TEMPERATURE_SENSOR_SERIES_5) { > + ts_coeff->h = PVT_SERIES5_H_CONST; > + ts_coeff->g = PVT_SERIES5_G_CONST; > + ts_coeff->j = PVT_SERIES5_J_CONST; > + ts_coeff->cal5 = PVT_SERIES5_CAL5_CONST; > + } else if (series == TEMPERATURE_SENSOR_SERIES_6) { > + ts_coeff->h = PVT_SERIES6_H_CONST; > + ts_coeff->g = PVT_SERIES6_G_CONST; > + ts_coeff->j = PVT_SERIES6_J_CONST; > + ts_coeff->cal5 = PVT_SERIES6_CAL5_CONST; > + } else { > + dev_err(dev, "invalid temperature sensor series (%u)\n", > + series); > + return -EINVAL; > + } switch-case?
On 8/31/2022 3:08 PM, Andy Shevchenko wrote: > On Tue, Aug 30, 2022 at 07:22:08PM +0000, Eliav Farber wrote: >> The current equation used in code is aligned to series 5: >> T = G + H * (n / cal5 - 0.5) + J * F >> Where: >> G = 60, H = 200, cal5 = 4094, J = -0.1, F = frequency clock in MHz >> >> Series 6 has a slightly different equation: >> T = G + H * (n / cal5 - 0.5) >> and a different set of coefficients: >> G = 57.4, H = 249.4, cal5 = 4096 >> >> This change supports equation and coefficients for both series. >> (for series 6, J is set to 0). >> >> The series is determined according to “ts-series” property in device >> tree. >> If absent, series 5 is assumed to be the default. > > ... > >> -#define PVT_H_CONST 200000 >> -#define PVT_G_CONST 60000 >> -#define PVT_J_CONST -100 >> -#define PVT_CAL5_CONST 4094 > > You just introduced them patch before. Please, avoid ping-pong style in > the same series. Fixed for v4. I now introduce these defines in patch 13 to avoid modifying the above ones and then remove them: /* Temperature coefficients for series 5 */ #define PVT_SERIES5_H_CONST 200000 #define PVT_SERIES5_G_CONST 60000 #define PVT_SERIES5_J_CONST -100 #define PVT_SERIES5_CAL5_CONST 4094 > ... > >> + ret = of_property_read_u32(np, "moortec,ts-series", &series); > > of_ ?! > > Be consistent. Either you use OF everywhere, or device property APIs. > Fixed for v4. Using device_property_read_u32() instead. > ... > >> + if (ret) >> + series = TEMPERATURE_SENSOR_SERIES_5; >> + >> + if (series == TEMPERATURE_SENSOR_SERIES_5) { >> + ts_coeff->h = PVT_SERIES5_H_CONST; >> + ts_coeff->g = PVT_SERIES5_G_CONST; >> + ts_coeff->j = PVT_SERIES5_J_CONST; >> + ts_coeff->cal5 = PVT_SERIES5_CAL5_CONST; >> + } else if (series == TEMPERATURE_SENSOR_SERIES_6) { >> + ts_coeff->h = PVT_SERIES6_H_CONST; >> + ts_coeff->g = PVT_SERIES6_G_CONST; >> + ts_coeff->j = PVT_SERIES6_J_CONST; >> + ts_coeff->cal5 = PVT_SERIES6_CAL5_CONST; >> + } else { >> + dev_err(dev, "invalid temperature sensor series (%u)\n", >> + series); >> + return -EINVAL; >> + } > > switch-case? Changed to switch-case (will be part of v4). -- Thanks, Eliav
diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 5b8ca1ee4a54..6a035fd115ca 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -103,10 +103,6 @@ #define PVT_POLL_DELAY_US 20 #define PVT_POLL_TIMEOUT_US 20000 -#define PVT_H_CONST 200000 -#define PVT_G_CONST 60000 -#define PVT_J_CONST -100 -#define PVT_CAL5_CONST 4094 #define PVT_CONV_BITS 10 #define PVT_N_CONST 90 #define PVT_R_CONST 245805 @@ -114,9 +110,31 @@ #define PVT_TEMP_MIN -40000 #define PVT_TEMP_MAX 125000 +/* Temperature coefficients for series 5 */ +#define PVT_SERIES5_H_CONST 200000 +#define PVT_SERIES5_G_CONST 60000 +#define PVT_SERIES5_J_CONST -100 +#define PVT_SERIES5_CAL5_CONST 4094 + +/* Temperature coefficients for series 6 */ +#define PVT_SERIES6_H_CONST 249400 +#define PVT_SERIES6_G_CONST 57400 +#define PVT_SERIES6_J_CONST 0 +#define PVT_SERIES6_CAL5_CONST 4096 + +#define TEMPERATURE_SENSOR_SERIES_5 5 +#define TEMPERATURE_SENSOR_SERIES_6 6 + #define PRE_SCALER_X1 1 #define PRE_SCALER_X2 2 +struct temp_coeff { + u32 h; + u32 g; + u32 cal5; + s32 j; +}; + struct voltage_device { u32 vm_map; /* Map channel number to VM index */ u32 ch_map; /* Map channel number to channel index */ @@ -137,6 +155,7 @@ struct pvt_device { struct reset_control *rst; struct voltage_device *vd; struct voltage_channels vm_channels; + struct temp_coeff ts_coeff; u32 t_num; u32 p_num; u32 v_num; @@ -167,8 +186,9 @@ static long pvt_calc_temp(struct pvt_device *pvt, u32 nbs) * Convert the register value to degrees centigrade temperature: * T = G + H * (n / cal5 - 0.5) + J * F */ - s64 tmp = PVT_G_CONST + PVT_H_CONST * (s64)nbs / PVT_CAL5_CONST - - PVT_H_CONST / 2 + PVT_J_CONST * (s64)pvt->ip_freq / HZ_PER_MHZ; + struct temp_coeff *ts_coeff = &pvt->ts_coeff; + s64 tmp = ts_coeff->g + ts_coeff->h * (s64)nbs / ts_coeff->cal5 - + ts_coeff->h / 2 + ts_coeff->j * (s64)pvt->ip_freq / HZ_PER_MHZ; return clamp_val(tmp, PVT_TEMP_MIN, PVT_TEMP_MAX); } @@ -652,6 +672,39 @@ static int pvt_get_pre_scaler(struct device *dev, struct pvt_device *pvt) return ret; } +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; + int ret; + + /* Incase ts-series property is not defined, use default 5. */ + ret = of_property_read_u32(np, "moortec,ts-series", &series); + if (ret) + series = TEMPERATURE_SENSOR_SERIES_5; + + if (series == TEMPERATURE_SENSOR_SERIES_5) { + ts_coeff->h = PVT_SERIES5_H_CONST; + ts_coeff->g = PVT_SERIES5_G_CONST; + ts_coeff->j = PVT_SERIES5_J_CONST; + ts_coeff->cal5 = PVT_SERIES5_CAL5_CONST; + } else if (series == TEMPERATURE_SENSOR_SERIES_6) { + ts_coeff->h = PVT_SERIES6_H_CONST; + ts_coeff->g = PVT_SERIES6_G_CONST; + ts_coeff->j = PVT_SERIES6_J_CONST; + ts_coeff->cal5 = PVT_SERIES6_CAL5_CONST; + } else { + dev_err(dev, "invalid temperature sensor series (%u)\n", + series); + return -EINVAL; + } + + dev_dbg(dev, "temperature sensor series = %u\n", series); + + return 0; +} + static int mr75203_probe(struct platform_device *pdev) { const struct hwmon_channel_info **pvt_info; @@ -722,6 +775,10 @@ static int mr75203_probe(struct platform_device *pdev) if (ret) return ret; + ret = pvt_set_temp_coeff(dev, pvt); + if (ret) + return ret; + temp_config = devm_kcalloc(dev, ts_num + 1, sizeof(*temp_config), GFP_KERNEL); if (!temp_config)
The current equation used in code is aligned to series 5: T = G + H * (n / cal5 - 0.5) + J * F Where: G = 60, H = 200, cal5 = 4094, J = -0.1, F = frequency clock in MHz Series 6 has a slightly different equation: T = G + H * (n / cal5 - 0.5) and a different set of coefficients: G = 57.4, H = 249.4, cal5 = 4096 This change supports equation and coefficients for both series. (for series 6, J is set to 0). The series is determined according to “ts-series” property in device tree. If absent, series 5 is assumed to be the default. Signed-off-by: Eliav Farber <farbere@amazon.com> --- V3 -> V2: - New patch to support temperature sensor series 6 instead of having to set all 4 coefficients. drivers/hwmon/mr75203.c | 69 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 6 deletions(-)