diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c index 89e27f34a..1687497dc 100644 --- a/drivers/thermal/sun8i_thermal.c +++ b/drivers/thermal/sun8i_thermal.c @@ -81,7 +81,8 @@ struct ths_thermal_chip { }; struct ths_device { - const struct ths_thermal_chip *chip; +// const struct ths_thermal_chip *chip; + struct ths_thermal_chip *chip; struct device *dev; struct regmap *regmap; struct reset_control *reset; @@ -223,6 +224,32 @@ static int sun8i_h3_ths_calibrate(struct ths_device *tmdev, return 0; } +static int sun8i_h3only_ths_calibrate(struct ths_device *tmdev, + u16 *caldata, int callen) +{ + // 12.4.2023 radoslavv: meaningless code for H3 chip in sun8i_h3_ths_calibrate() + // 1) no need to iterate 1 sensor on h3 chip (however still another family chips needs this) => separate function for h3 chip only + // 2) register SUN8I_THS_TEMP_CALIB is rather to be read, than trying to "FIX" factory written value with regmap_update_bits + // 3) we need to read it to update .offset value => main reason for change + // 4) per each chip could be value slightly different, can't be predefined const in code + + int val = 0; + + dev_warn(tmdev->dev, "DEBUG: h3 caldata=0x%04x=%u, callen=%i\n", (*caldata), (*caldata), callen ); + + if (callen != 4) + return -EINVAL; + + regmap_read(tmdev->regmap, SUN8I_THS_TEMP_CALIB, &val); + val &= 0xFFF; //only 12bits to use + caldata[0] = val; + + tmdev->chip->scale = 10000/14.882; //according datasheet (= 672) + tmdev->chip->offset = val * tmdev->chip->scale / 10; + + return 0; +} + static int sun50i_h6_ths_calibrate(struct ths_device *tmdev, u16 *caldata, int callen) { @@ -663,14 +690,15 @@ static const struct ths_thermal_chip sun8i_a83t_ths = { .calc_temp = sun8i_ths_calc_temp, }; -static const struct ths_thermal_chip sun8i_h3_ths = { +//static const struct ths_thermal_chip sun8i_h3_ths = { +static struct ths_thermal_chip sun8i_h3_ths = { .sensor_num = 1, .scale = 1211, .offset = 217000, .has_mod_clk = true, .has_bus_clk_reset = true, .temp_data_base = SUN8I_THS_TEMP_DATA, - .calibrate = sun8i_h3_ths_calibrate, + .calibrate = sun8i_h3only_ths_calibrate, .init = sun8i_h3_thermal_init, .irq_ack = sun8i_h3_irq_ack, .calc_temp = sun8i_ths_calc_temp,