Quoting Amit Kucheria (2019-08-27 05:14:10) > diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c > index ea2c46cc6a66a..06b44cfd5eab9 100644 > --- a/drivers/thermal/qcom/tsens-common.c > +++ b/drivers/thermal/qcom/tsens-common.c > @@ -84,13 +84,43 @@ static inline int code_to_degc(u32 adc_code, const struct tsens_sensor *s) > return degc; > } > > +/** > + * tsens_hw_to_mC - Return sign-extended temperature in mCelsius. > + * @s: Pointer to sensor struct sensor? This isn't golang! > + * @field: Index into regmap_field array pointing to temperature data > + * > + * This function handles temperature returned in ADC code or deciCelsius > + * depending on IP version. > + * > + * Return: Temperature in milliCelsius on success, a negative errno will > + * be returned in error cases > + */ > +static int tsens_hw_to_mC(struct tsens_sensor *s, int field) > +{ > + struct tsens_priv *priv = s->priv; > + u32 temp = 0; > + int ret; > + > + ret = regmap_field_read(priv->rf[field], &temp); > + if (ret) > + return ret; > + > + if (priv->feat->adc) { > + /* Convert temperature from ADC code to milliCelsius */ Nitpick: Move this comment above the if and drop the braces. > + return code_to_degc(temp, s) * 1000; > + } > + > + /* deciCelsius -> milliCelsius along with sign extension */ > + return sign_extend32(temp, priv->tempres) * 100; > +} > + > int get_temp_tsens_valid(struct tsens_sensor *s, int *temp) > { > struct tsens_priv *priv = s->priv; > int hw_id = s->hw_id; > u32 temp_idx = LAST_TEMP_0 + hw_id; > u32 valid_idx = VALID_0 + hw_id; > - u32 last_temp = 0, valid, mask; > + u32 valid; > int ret; > > ret = regmap_field_read(priv->rf[valid_idx], &valid); > @@ -310,6 +328,10 @@ int __init init_common(struct tsens_priv *priv) > goto err_put_device; > } > } > + > + /* Save away resolution of signed temperature value for this IP */ > + priv->tempres = priv->fields[LAST_TEMP_0].msb - priv->fields[LAST_TEMP_0].lsb; > + Why not just calculate this in the function that uses it? Is there a reason to stash it away in the struct? > for (i = 0, j = VALID_0; i < priv->feat->max_sensors; i++, j++) { > priv->rf[j] = devm_regmap_field_alloc(dev, priv->tm_map, > priv->fields[j]);