Lines Matching refs:mt
307 struct mtk_thermal *mt; member
350 int (*raw_to_mcelsius)(struct mtk_thermal *mt, int sensno, s32 raw);
709 static int raw_to_mcelsius_v1(struct mtk_thermal *mt, int sensno, s32 raw) in raw_to_mcelsius_v1() argument
716 tmp /= mt->conf->cali_val + mt->o_slope; in raw_to_mcelsius_v1()
717 tmp /= 10000 + mt->adc_ge; in raw_to_mcelsius_v1()
718 tmp *= raw - mt->vts[sensno] - 3350; in raw_to_mcelsius_v1()
721 return mt->degc_cali * 500 - tmp; in raw_to_mcelsius_v1()
724 static int raw_to_mcelsius_v2(struct mtk_thermal *mt, int sensno, s32 raw) in raw_to_mcelsius_v2() argument
737 g_gain = 10000 + (((mt->adc_ge - 512) * 10000) >> 12); in raw_to_mcelsius_v2()
738 g_oe = mt->adc_oe - 512; in raw_to_mcelsius_v2()
739 format_1 = mt->vts[VTS2] + 3105 - g_oe; in raw_to_mcelsius_v2()
740 format_2 = (mt->degc_cali * 10) >> 1; in raw_to_mcelsius_v2()
746 if (mt->o_slope_sign == 0) in raw_to_mcelsius_v2()
747 tmp = tmp / (165 - mt->o_slope); in raw_to_mcelsius_v2()
749 tmp = tmp / (165 + mt->o_slope); in raw_to_mcelsius_v2()
754 static int raw_to_mcelsius_v3(struct mtk_thermal *mt, int sensno, s32 raw) in raw_to_mcelsius_v3() argument
763 tmp /= 4096 - 512 + mt->adc_ge; in raw_to_mcelsius_v3()
765 tmp *= raw - mt->vts[sensno] - 2900; in raw_to_mcelsius_v3()
767 return mt->degc_cali * 500 - tmp; in raw_to_mcelsius_v3()
779 struct mtk_thermal *mt = bank->mt; in mtk_thermal_get_bank() local
782 if (mt->conf->need_switch_bank) { in mtk_thermal_get_bank()
783 mutex_lock(&mt->lock); in mtk_thermal_get_bank()
785 val = readl(mt->thermal_base + PTPCORESEL); in mtk_thermal_get_bank()
788 writel(val, mt->thermal_base + PTPCORESEL); in mtk_thermal_get_bank()
800 struct mtk_thermal *mt = bank->mt; in mtk_thermal_put_bank() local
802 if (mt->conf->need_switch_bank) in mtk_thermal_put_bank()
803 mutex_unlock(&mt->lock); in mtk_thermal_put_bank()
815 struct mtk_thermal *mt = bank->mt; in mtk_thermal_bank_temperature() local
816 const struct mtk_thermal_data *conf = mt->conf; in mtk_thermal_bank_temperature()
821 raw = readl(mt->thermal_base + conf->msr[i]); in mtk_thermal_bank_temperature()
823 temp = mt->raw_to_mcelsius( in mtk_thermal_bank_temperature()
824 mt, conf->bank_data[bank->id].sensors[i], raw); in mtk_thermal_bank_temperature()
847 struct mtk_thermal *mt = thermal_zone_device_priv(tz); in mtk_read_temp() local
851 for (i = 0; i < mt->conf->num_banks; i++) { in mtk_read_temp()
852 struct mtk_thermal_bank *bank = &mt->banks[i]; in mtk_read_temp()
870 static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num, in mtk_thermal_init_bank() argument
874 struct mtk_thermal_bank *bank = &mt->banks[num]; in mtk_thermal_init_bank()
875 const struct mtk_thermal_data *conf = mt->conf; in mtk_thermal_init_bank()
878 int offset = mt->conf->controller_offset[ctrl_id]; in mtk_thermal_init_bank()
879 void __iomem *controller_base = mt->thermal_base + offset; in mtk_thermal_init_bank()
882 bank->mt = mt; in mtk_thermal_init_bank()
930 if (mt->conf->version == MTK_THERMAL_V1) { in mtk_thermal_init_bank()
967 mt->thermal_base + conf->adcpnp[i]); in mtk_thermal_init_bank()
989 static int mtk_thermal_extract_efuse_v1(struct mtk_thermal *mt, u32 *buf) in mtk_thermal_extract_efuse_v1() argument
996 mt->adc_ge = CALIB_BUF1_ADC_GE_V1(buf[1]); in mtk_thermal_extract_efuse_v1()
998 for (i = 0; i < mt->conf->num_sensors; i++) { in mtk_thermal_extract_efuse_v1()
999 switch (mt->conf->vts_index[i]) { in mtk_thermal_extract_efuse_v1()
1001 mt->vts[VTS1] = CALIB_BUF0_VTS_TS1_V1(buf[0]); in mtk_thermal_extract_efuse_v1()
1004 mt->vts[VTS2] = CALIB_BUF0_VTS_TS2_V1(buf[0]); in mtk_thermal_extract_efuse_v1()
1007 mt->vts[VTS3] = CALIB_BUF1_VTS_TS3_V1(buf[1]); in mtk_thermal_extract_efuse_v1()
1010 mt->vts[VTS4] = CALIB_BUF2_VTS_TS4_V1(buf[2]); in mtk_thermal_extract_efuse_v1()
1013 mt->vts[VTS5] = CALIB_BUF2_VTS_TS5_V1(buf[2]); in mtk_thermal_extract_efuse_v1()
1016 mt->vts[VTSABB] = in mtk_thermal_extract_efuse_v1()
1024 mt->degc_cali = CALIB_BUF0_DEGC_CALI_V1(buf[0]); in mtk_thermal_extract_efuse_v1()
1027 mt->o_slope = -CALIB_BUF0_O_SLOPE_V1(buf[0]); in mtk_thermal_extract_efuse_v1()
1029 mt->o_slope = CALIB_BUF0_O_SLOPE_V1(buf[0]); in mtk_thermal_extract_efuse_v1()
1034 static int mtk_thermal_extract_efuse_v2(struct mtk_thermal *mt, u32 *buf) in mtk_thermal_extract_efuse_v2() argument
1039 mt->adc_oe = CALIB_BUF0_ADC_OE_V2(buf[0]); in mtk_thermal_extract_efuse_v2()
1040 mt->adc_ge = CALIB_BUF0_ADC_GE_V2(buf[0]); in mtk_thermal_extract_efuse_v2()
1041 mt->degc_cali = CALIB_BUF0_DEGC_CALI_V2(buf[0]); in mtk_thermal_extract_efuse_v2()
1042 mt->o_slope = CALIB_BUF0_O_SLOPE_V2(buf[0]); in mtk_thermal_extract_efuse_v2()
1043 mt->vts[VTS1] = CALIB_BUF1_VTS_TS1_V2(buf[1]); in mtk_thermal_extract_efuse_v2()
1044 mt->vts[VTS2] = CALIB_BUF1_VTS_TS2_V2(buf[1]); in mtk_thermal_extract_efuse_v2()
1045 mt->vts[VTSABB] = CALIB_BUF1_VTS_TSABB_V2(buf[1]); in mtk_thermal_extract_efuse_v2()
1046 mt->o_slope_sign = CALIB_BUF1_O_SLOPE_SIGN_V2(buf[1]); in mtk_thermal_extract_efuse_v2()
1051 static int mtk_thermal_extract_efuse_v3(struct mtk_thermal *mt, u32 *buf) in mtk_thermal_extract_efuse_v3() argument
1056 mt->adc_ge = CALIB_BUF0_ADC_GE_V3(buf[0]); in mtk_thermal_extract_efuse_v3()
1057 mt->degc_cali = CALIB_BUF0_DEGC_CALI_V3(buf[0]); in mtk_thermal_extract_efuse_v3()
1058 mt->o_slope = CALIB_BUF0_O_SLOPE_V3(buf[0]); in mtk_thermal_extract_efuse_v3()
1059 mt->vts[VTS1] = CALIB_BUF1_VTS_TS1_V3(buf[1]); in mtk_thermal_extract_efuse_v3()
1060 mt->vts[VTS2] = CALIB_BUF1_VTS_TS2_V3(buf[1]); in mtk_thermal_extract_efuse_v3()
1061 mt->vts[VTSABB] = CALIB_BUF1_VTS_TSABB_V3(buf[1]); in mtk_thermal_extract_efuse_v3()
1062 mt->o_slope_sign = CALIB_BUF1_O_SLOPE_SIGN_V3(buf[1]); in mtk_thermal_extract_efuse_v3()
1065 mt->o_slope = 0; in mtk_thermal_extract_efuse_v3()
1071 struct mtk_thermal *mt) in mtk_thermal_get_calibration_data() argument
1079 mt->adc_ge = 512; in mtk_thermal_get_calibration_data()
1080 mt->adc_oe = 512; in mtk_thermal_get_calibration_data()
1081 for (i = 0; i < mt->conf->num_sensors; i++) in mtk_thermal_get_calibration_data()
1082 mt->vts[i] = 260; in mtk_thermal_get_calibration_data()
1083 mt->degc_cali = 40; in mtk_thermal_get_calibration_data()
1084 mt->o_slope = 0; in mtk_thermal_get_calibration_data()
1106 switch (mt->conf->version) { in mtk_thermal_get_calibration_data()
1108 ret = mtk_thermal_extract_efuse_v1(mt, buf); in mtk_thermal_get_calibration_data()
1111 ret = mtk_thermal_extract_efuse_v2(mt, buf); in mtk_thermal_get_calibration_data()
1114 ret = mtk_thermal_extract_efuse_v3(mt, buf); in mtk_thermal_get_calibration_data()
1165 static void mtk_thermal_turn_on_buffer(struct mtk_thermal *mt, in mtk_thermal_turn_on_buffer() argument
1170 if (!mt->conf->apmixed_buffer_ctl_reg) in mtk_thermal_turn_on_buffer()
1173 tmp = readl(apmixed_base + mt->conf->apmixed_buffer_ctl_reg); in mtk_thermal_turn_on_buffer()
1174 tmp &= mt->conf->apmixed_buffer_ctl_mask; in mtk_thermal_turn_on_buffer()
1175 tmp |= mt->conf->apmixed_buffer_ctl_set; in mtk_thermal_turn_on_buffer()
1176 writel(tmp, apmixed_base + mt->conf->apmixed_buffer_ctl_reg); in mtk_thermal_turn_on_buffer()
1180 static void mtk_thermal_release_periodic_ts(struct mtk_thermal *mt, in mtk_thermal_release_periodic_ts() argument
1186 writel(0x1, mt->thermal_base + TEMP_MONCTL0); in mtk_thermal_release_periodic_ts()
1187 tmp = readl(mt->thermal_base + TEMP_MSRCTL1); in mtk_thermal_release_periodic_ts()
1188 writel((tmp & (~0x10e)), mt->thermal_base + TEMP_MSRCTL1); in mtk_thermal_release_periodic_ts()
1195 struct mtk_thermal *mt; in mtk_thermal_probe() local
1200 mt = devm_kzalloc(&pdev->dev, sizeof(*mt), GFP_KERNEL); in mtk_thermal_probe()
1201 if (!mt) in mtk_thermal_probe()
1204 mt->conf = of_device_get_match_data(&pdev->dev); in mtk_thermal_probe()
1206 mt->thermal_base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); in mtk_thermal_probe()
1207 if (IS_ERR(mt->thermal_base)) in mtk_thermal_probe()
1208 return PTR_ERR(mt->thermal_base); in mtk_thermal_probe()
1210 ret = mtk_thermal_get_calibration_data(&pdev->dev, mt); in mtk_thermal_probe()
1214 mutex_init(&mt->lock); in mtk_thermal_probe()
1216 mt->dev = &pdev->dev; in mtk_thermal_probe()
1254 mt->clk_auxadc = devm_clk_get_enabled(&pdev->dev, "auxadc"); in mtk_thermal_probe()
1255 if (IS_ERR(mt->clk_auxadc)) { in mtk_thermal_probe()
1256 ret = PTR_ERR(mt->clk_auxadc); in mtk_thermal_probe()
1261 mt->clk_peri_therm = devm_clk_get_enabled(&pdev->dev, "therm"); in mtk_thermal_probe()
1262 if (IS_ERR(mt->clk_peri_therm)) { in mtk_thermal_probe()
1263 ret = PTR_ERR(mt->clk_peri_therm); in mtk_thermal_probe()
1268 mtk_thermal_turn_on_buffer(mt, apmixed_base); in mtk_thermal_probe()
1270 if (mt->conf->version != MTK_THERMAL_V1) in mtk_thermal_probe()
1271 mtk_thermal_release_periodic_ts(mt, auxadc_base); in mtk_thermal_probe()
1273 if (mt->conf->version == MTK_THERMAL_V1) in mtk_thermal_probe()
1274 mt->raw_to_mcelsius = raw_to_mcelsius_v1; in mtk_thermal_probe()
1275 else if (mt->conf->version == MTK_THERMAL_V2) in mtk_thermal_probe()
1276 mt->raw_to_mcelsius = raw_to_mcelsius_v2; in mtk_thermal_probe()
1278 mt->raw_to_mcelsius = raw_to_mcelsius_v3; in mtk_thermal_probe()
1280 for (ctrl_id = 0; ctrl_id < mt->conf->num_controller ; ctrl_id++) in mtk_thermal_probe()
1281 for (i = 0; i < mt->conf->num_banks; i++) in mtk_thermal_probe()
1282 mtk_thermal_init_bank(mt, i, apmixed_phys_base, in mtk_thermal_probe()
1285 tzdev = devm_thermal_of_zone_register(&pdev->dev, 0, mt, in mtk_thermal_probe()