|
120 | 120 | * MT2701 has 3 sensors and needs 3 VTS calibration data.
|
121 | 121 | * MT2712 has 4 sensors and needs 4 VTS calibration data.
|
122 | 122 | */
|
123 |
| -#define CALIB_BUF0_VALID BIT(0) |
124 |
| -#define CALIB_BUF1_ADC_GE(x) (((x) >> 22) & 0x3ff) |
125 |
| -#define CALIB_BUF0_VTS_TS1(x) (((x) >> 17) & 0x1ff) |
126 |
| -#define CALIB_BUF0_VTS_TS2(x) (((x) >> 8) & 0x1ff) |
127 |
| -#define CALIB_BUF1_VTS_TS3(x) (((x) >> 0) & 0x1ff) |
128 |
| -#define CALIB_BUF2_VTS_TS4(x) (((x) >> 23) & 0x1ff) |
129 |
| -#define CALIB_BUF2_VTS_TS5(x) (((x) >> 5) & 0x1ff) |
130 |
| -#define CALIB_BUF2_VTS_TSABB(x) (((x) >> 14) & 0x1ff) |
131 |
| -#define CALIB_BUF0_DEGC_CALI(x) (((x) >> 1) & 0x3f) |
132 |
| -#define CALIB_BUF0_O_SLOPE(x) (((x) >> 26) & 0x3f) |
133 |
| -#define CALIB_BUF0_O_SLOPE_SIGN(x) (((x) >> 7) & 0x1) |
134 |
| -#define CALIB_BUF1_ID(x) (((x) >> 9) & 0x1) |
| 123 | +#define CALIB_BUF0_VALID_V1 BIT(0) |
| 124 | +#define CALIB_BUF1_ADC_GE_V1(x) (((x) >> 22) & 0x3ff) |
| 125 | +#define CALIB_BUF0_VTS_TS1_V1(x) (((x) >> 17) & 0x1ff) |
| 126 | +#define CALIB_BUF0_VTS_TS2_V1(x) (((x) >> 8) & 0x1ff) |
| 127 | +#define CALIB_BUF1_VTS_TS3_V1(x) (((x) >> 0) & 0x1ff) |
| 128 | +#define CALIB_BUF2_VTS_TS4_V1(x) (((x) >> 23) & 0x1ff) |
| 129 | +#define CALIB_BUF2_VTS_TS5_V1(x) (((x) >> 5) & 0x1ff) |
| 130 | +#define CALIB_BUF2_VTS_TSABB_V1(x) (((x) >> 14) & 0x1ff) |
| 131 | +#define CALIB_BUF0_DEGC_CALI_V1(x) (((x) >> 1) & 0x3f) |
| 132 | +#define CALIB_BUF0_O_SLOPE_V1(x) (((x) >> 26) & 0x3f) |
| 133 | +#define CALIB_BUF0_O_SLOPE_SIGN_V1(x) (((x) >> 7) & 0x1) |
| 134 | +#define CALIB_BUF1_ID_V1(x) (((x) >> 9) & 0x1) |
135 | 135 |
|
136 | 136 | enum {
|
137 | 137 | VTS1,
|
@@ -525,7 +525,7 @@ static const struct mtk_thermal_data mt8183_thermal_data = {
|
525 | 525 | * This converts the raw ADC value to mcelsius using the SoC specific
|
526 | 526 | * calibration constants
|
527 | 527 | */
|
528 |
| -static int raw_to_mcelsius(struct mtk_thermal *mt, int sensno, s32 raw) |
| 528 | +static int raw_to_mcelsius_v1(struct mtk_thermal *mt, int sensno, s32 raw) |
529 | 529 | {
|
530 | 530 | s32 tmp;
|
531 | 531 |
|
@@ -594,9 +594,9 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
|
594 | 594 | raw = readl(mt->thermal_base +
|
595 | 595 | conf->msr[conf->bank_data[bank->id].sensors[i]]);
|
596 | 596 |
|
597 |
| - temp = raw_to_mcelsius(mt, |
598 |
| - conf->bank_data[bank->id].sensors[i], |
599 |
| - raw); |
| 597 | + temp = raw_to_mcelsius_v1(mt, |
| 598 | + conf->bank_data[bank->id].sensors[i], |
| 599 | + raw); |
600 | 600 |
|
601 | 601 | /*
|
602 | 602 | * The first read of a sensor often contains very high bogus
|
@@ -758,6 +758,51 @@ static u64 of_get_phys_base(struct device_node *np)
|
758 | 758 | return of_translate_address(np, regaddr_p);
|
759 | 759 | }
|
760 | 760 |
|
| 761 | +static int mtk_thermal_extract_efuse_v1(struct mtk_thermal *mt, u32 *buf) |
| 762 | +{ |
| 763 | + int i; |
| 764 | + |
| 765 | + if (!(buf[0] & CALIB_BUF0_VALID_V1)) |
| 766 | + return -EINVAL; |
| 767 | + |
| 768 | + mt->adc_ge = CALIB_BUF1_ADC_GE_V1(buf[1]); |
| 769 | + |
| 770 | + for (i = 0; i < mt->conf->num_sensors; i++) { |
| 771 | + switch (mt->conf->vts_index[i]) { |
| 772 | + case VTS1: |
| 773 | + mt->vts[VTS1] = CALIB_BUF0_VTS_TS1_V1(buf[0]); |
| 774 | + break; |
| 775 | + case VTS2: |
| 776 | + mt->vts[VTS2] = CALIB_BUF0_VTS_TS2_V1(buf[0]); |
| 777 | + break; |
| 778 | + case VTS3: |
| 779 | + mt->vts[VTS3] = CALIB_BUF1_VTS_TS3_V1(buf[1]); |
| 780 | + break; |
| 781 | + case VTS4: |
| 782 | + mt->vts[VTS4] = CALIB_BUF2_VTS_TS4_V1(buf[2]); |
| 783 | + break; |
| 784 | + case VTS5: |
| 785 | + mt->vts[VTS5] = CALIB_BUF2_VTS_TS5_V1(buf[2]); |
| 786 | + break; |
| 787 | + case VTSABB: |
| 788 | + mt->vts[VTSABB] = |
| 789 | + CALIB_BUF2_VTS_TSABB_V1(buf[2]); |
| 790 | + break; |
| 791 | + default: |
| 792 | + break; |
| 793 | + } |
| 794 | + } |
| 795 | + |
| 796 | + mt->degc_cali = CALIB_BUF0_DEGC_CALI_V1(buf[0]); |
| 797 | + if (CALIB_BUF1_ID_V1(buf[1]) & |
| 798 | + CALIB_BUF0_O_SLOPE_SIGN_V1(buf[0])) |
| 799 | + mt->o_slope = -CALIB_BUF0_O_SLOPE_V1(buf[0]); |
| 800 | + else |
| 801 | + mt->o_slope = CALIB_BUF0_O_SLOPE_V1(buf[0]); |
| 802 | + |
| 803 | + return 0; |
| 804 | +} |
| 805 | + |
761 | 806 | static int mtk_thermal_get_calibration_data(struct device *dev,
|
762 | 807 | struct mtk_thermal *mt)
|
763 | 808 | {
|
@@ -793,43 +838,8 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
|
793 | 838 | goto out;
|
794 | 839 | }
|
795 | 840 |
|
796 |
| - if (buf[0] & CALIB_BUF0_VALID) { |
797 |
| - mt->adc_ge = CALIB_BUF1_ADC_GE(buf[1]); |
798 |
| - |
799 |
| - for (i = 0; i < mt->conf->num_sensors; i++) { |
800 |
| - switch (mt->conf->vts_index[i]) { |
801 |
| - case VTS1: |
802 |
| - mt->vts[VTS1] = CALIB_BUF0_VTS_TS1(buf[0]); |
803 |
| - break; |
804 |
| - case VTS2: |
805 |
| - mt->vts[VTS2] = CALIB_BUF0_VTS_TS2(buf[0]); |
806 |
| - break; |
807 |
| - case VTS3: |
808 |
| - mt->vts[VTS3] = CALIB_BUF1_VTS_TS3(buf[1]); |
809 |
| - break; |
810 |
| - case VTS4: |
811 |
| - mt->vts[VTS4] = CALIB_BUF2_VTS_TS4(buf[2]); |
812 |
| - break; |
813 |
| - case VTS5: |
814 |
| - mt->vts[VTS5] = CALIB_BUF2_VTS_TS5(buf[2]); |
815 |
| - break; |
816 |
| - case VTSABB: |
817 |
| - mt->vts[VTSABB] = CALIB_BUF2_VTS_TSABB(buf[2]); |
818 |
| - break; |
819 |
| - default: |
820 |
| - break; |
821 |
| - } |
822 |
| - } |
823 |
| - |
824 |
| - mt->degc_cali = CALIB_BUF0_DEGC_CALI(buf[0]); |
825 |
| - if (CALIB_BUF1_ID(buf[1]) & |
826 |
| - CALIB_BUF0_O_SLOPE_SIGN(buf[0])) |
827 |
| - mt->o_slope = -CALIB_BUF0_O_SLOPE(buf[0]); |
828 |
| - else |
829 |
| - mt->o_slope = CALIB_BUF0_O_SLOPE(buf[0]); |
830 |
| - } else { |
| 841 | + if (mtk_thermal_extract_efuse_v1(mt, buf)) |
831 | 842 | dev_info(dev, "Device not calibrated, using default calibration values\n");
|
832 |
| - } |
833 | 843 |
|
834 | 844 | out:
|
835 | 845 | kfree(buf);
|
|
0 commit comments