Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal/drivers/mediatek/lvts_thermal: Provide default calibration data

On some pre-production hardware, the SoCs do not contain calibration
data for the thermal sensors. The downstream drivers provide default
values that sort of work, instead of having the thermal sensors not
work at all.

Port the default values to the upstream driver. These values are from
the ChromeOS kernels, which sadly do not cover the MT7988.

Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20240620092306.2352606-1-wenst@chromium.org
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

authored by

Chen-Yu Tsai and committed by
Daniel Lezcano
a5d4afb9 97e32381

+26 -8
+26 -8
drivers/thermal/mediatek/lvts_thermal.c
··· 128 128 int temp_factor; 129 129 int temp_offset; 130 130 int gt_calib_bit_offset; 131 + unsigned int def_calibration; 131 132 }; 132 133 133 134 struct lvts_sensor { ··· 690 689 size_t calib_len) 691 690 { 692 691 int i; 692 + u32 gt; 693 + 694 + /* A zero value for gt means that device has invalid efuse data */ 695 + gt = (((u32 *)efuse_calibration)[0] >> lvts_ctrl->lvts_data->gt_calib_bit_offset) & 0xff; 693 696 694 697 lvts_for_each_valid_sensor(i, lvts_ctrl_data) { 695 698 const struct lvts_sensor_data *sensor = ··· 704 699 sensor->cal_offsets[2] >= calib_len) 705 700 return -EINVAL; 706 701 707 - lvts_ctrl->calibration[i] = 708 - (efuse_calibration[sensor->cal_offsets[0]] << 0) + 709 - (efuse_calibration[sensor->cal_offsets[1]] << 8) + 710 - (efuse_calibration[sensor->cal_offsets[2]] << 16); 702 + if (gt) { 703 + lvts_ctrl->calibration[i] = 704 + (efuse_calibration[sensor->cal_offsets[0]] << 0) + 705 + (efuse_calibration[sensor->cal_offsets[1]] << 8) + 706 + (efuse_calibration[sensor->cal_offsets[2]] << 16); 707 + } else if (lvts_ctrl->lvts_data->def_calibration) { 708 + lvts_ctrl->calibration[i] = lvts_ctrl->lvts_data->def_calibration; 709 + } else { 710 + dev_err(dev, "efuse contains invalid calibration data and no default given.\n"); 711 + return -ENODATA; 712 + } 711 713 } 712 714 713 715 return 0; ··· 782 770 gt = (((u32 *)calib)[0] >> lvts_data->gt_calib_bit_offset) & 0xff; 783 771 784 772 /* A zero value for gt means that device has invalid efuse data */ 785 - if (!gt) 786 - return -ENODATA; 787 - 788 - if (gt < LVTS_GOLDEN_TEMP_MAX) 773 + if (gt && gt < LVTS_GOLDEN_TEMP_MAX) 789 774 golden_temp = gt; 790 775 791 776 golden_temp_offset = golden_temp * 500 + lvts_data->temp_offset; 777 + 778 + dev_info(dev, "%sgolden temp=%d\n", gt ? "" : "fake ", golden_temp); 792 779 793 780 return 0; 794 781 } ··· 1712 1701 .temp_factor = LVTS_COEFF_A_MT7988, 1713 1702 .temp_offset = LVTS_COEFF_B_MT7988, 1714 1703 .gt_calib_bit_offset = 24, 1704 + .def_calibration = 19000, 1715 1705 }; 1716 1706 1717 1707 static const struct lvts_data mt8188_lvts_mcu_data = { ··· 1721 1709 .temp_factor = LVTS_COEFF_A_MT8195, 1722 1710 .temp_offset = LVTS_COEFF_B_MT8195, 1723 1711 .gt_calib_bit_offset = 20, 1712 + .def_calibration = 35000, 1724 1713 }; 1725 1714 1726 1715 static const struct lvts_data mt8188_lvts_ap_data = { ··· 1730 1717 .temp_factor = LVTS_COEFF_A_MT8195, 1731 1718 .temp_offset = LVTS_COEFF_B_MT8195, 1732 1719 .gt_calib_bit_offset = 20, 1720 + .def_calibration = 35000, 1733 1721 }; 1734 1722 1735 1723 static const struct lvts_data mt8192_lvts_mcu_data = { ··· 1739 1725 .temp_factor = LVTS_COEFF_A_MT8195, 1740 1726 .temp_offset = LVTS_COEFF_B_MT8195, 1741 1727 .gt_calib_bit_offset = 24, 1728 + .def_calibration = 35000, 1742 1729 }; 1743 1730 1744 1731 static const struct lvts_data mt8192_lvts_ap_data = { ··· 1748 1733 .temp_factor = LVTS_COEFF_A_MT8195, 1749 1734 .temp_offset = LVTS_COEFF_B_MT8195, 1750 1735 .gt_calib_bit_offset = 24, 1736 + .def_calibration = 35000, 1751 1737 }; 1752 1738 1753 1739 static const struct lvts_data mt8195_lvts_mcu_data = { ··· 1757 1741 .temp_factor = LVTS_COEFF_A_MT8195, 1758 1742 .temp_offset = LVTS_COEFF_B_MT8195, 1759 1743 .gt_calib_bit_offset = 24, 1744 + .def_calibration = 35000, 1760 1745 }; 1761 1746 1762 1747 static const struct lvts_data mt8195_lvts_ap_data = { ··· 1766 1749 .temp_factor = LVTS_COEFF_A_MT8195, 1767 1750 .temp_offset = LVTS_COEFF_B_MT8195, 1768 1751 .gt_calib_bit_offset = 24, 1752 + .def_calibration = 35000, 1769 1753 }; 1770 1754 1771 1755 static const struct of_device_id lvts_of_match[] = {