Lines Matching refs:mt

307 	struct mtk_thermal *mt;  member
350 int (*raw_to_mcelsius)(struct mtk_thermal *mt, int sensno, s32 raw);
712 static int raw_to_mcelsius_v1(struct mtk_thermal *mt, int sensno, s32 raw) in raw_to_mcelsius_v1() argument
719 tmp /= mt->conf->cali_val + mt->o_slope; in raw_to_mcelsius_v1()
720 tmp /= 10000 + mt->adc_ge; in raw_to_mcelsius_v1()
721 tmp *= raw - mt->vts[sensno] - 3350; in raw_to_mcelsius_v1()
724 return mt->degc_cali * 500 - tmp; in raw_to_mcelsius_v1()
727 static int raw_to_mcelsius_v2(struct mtk_thermal *mt, int sensno, s32 raw) in raw_to_mcelsius_v2() argument
740 g_gain = 10000 + (((mt->adc_ge - 512) * 10000) >> 12); in raw_to_mcelsius_v2()
741 g_oe = mt->adc_oe - 512; in raw_to_mcelsius_v2()
742 format_1 = mt->vts[VTS2] + 3105 - g_oe; in raw_to_mcelsius_v2()
743 format_2 = (mt->degc_cali * 10) >> 1; in raw_to_mcelsius_v2()
749 if (mt->o_slope_sign == 0) in raw_to_mcelsius_v2()
750 tmp = tmp / (165 - mt->o_slope); in raw_to_mcelsius_v2()
752 tmp = tmp / (165 + mt->o_slope); in raw_to_mcelsius_v2()
757 static int raw_to_mcelsius_v3(struct mtk_thermal *mt, int sensno, s32 raw) in raw_to_mcelsius_v3() argument
766 tmp /= 4096 - 512 + mt->adc_ge; in raw_to_mcelsius_v3()
768 tmp *= raw - mt->vts[sensno] - 2900; in raw_to_mcelsius_v3()
770 return mt->degc_cali * 500 - tmp; in raw_to_mcelsius_v3()
782 struct mtk_thermal *mt = bank->mt; in mtk_thermal_get_bank() local
785 if (mt->conf->need_switch_bank) { in mtk_thermal_get_bank()
786 mutex_lock(&mt->lock); in mtk_thermal_get_bank()
788 val = readl(mt->thermal_base + PTPCORESEL); in mtk_thermal_get_bank()
791 writel(val, mt->thermal_base + PTPCORESEL); in mtk_thermal_get_bank()
803 struct mtk_thermal *mt = bank->mt; in mtk_thermal_put_bank() local
805 if (mt->conf->need_switch_bank) in mtk_thermal_put_bank()
806 mutex_unlock(&mt->lock); in mtk_thermal_put_bank()
818 struct mtk_thermal *mt = bank->mt; in mtk_thermal_bank_temperature() local
819 const struct mtk_thermal_data *conf = mt->conf; in mtk_thermal_bank_temperature()
824 raw = readl(mt->thermal_base + conf->msr[i]); in mtk_thermal_bank_temperature()
826 temp = mt->raw_to_mcelsius( in mtk_thermal_bank_temperature()
827 mt, conf->bank_data[bank->id].sensors[i], raw); in mtk_thermal_bank_temperature()
850 struct mtk_thermal *mt = thermal_zone_device_priv(tz); in mtk_read_temp() local
854 for (i = 0; i < mt->conf->num_banks; i++) { in mtk_read_temp()
855 struct mtk_thermal_bank *bank = &mt->banks[i]; in mtk_read_temp()
873 static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num, in mtk_thermal_init_bank() argument
877 struct mtk_thermal_bank *bank = &mt->banks[num]; in mtk_thermal_init_bank()
878 const struct mtk_thermal_data *conf = mt->conf; in mtk_thermal_init_bank()
881 int offset = mt->conf->controller_offset[ctrl_id]; in mtk_thermal_init_bank()
882 void __iomem *controller_base = mt->thermal_base + offset; in mtk_thermal_init_bank()
885 bank->mt = mt; in mtk_thermal_init_bank()
933 if (mt->conf->version == MTK_THERMAL_V1) { in mtk_thermal_init_bank()
970 mt->thermal_base + conf->adcpnp[i]); in mtk_thermal_init_bank()
992 static int mtk_thermal_extract_efuse_v1(struct mtk_thermal *mt, u32 *buf) in mtk_thermal_extract_efuse_v1() argument
999 mt->adc_ge = CALIB_BUF1_ADC_GE_V1(buf[1]); in mtk_thermal_extract_efuse_v1()
1001 for (i = 0; i < mt->conf->num_sensors; i++) { in mtk_thermal_extract_efuse_v1()
1002 switch (mt->conf->vts_index[i]) { in mtk_thermal_extract_efuse_v1()
1004 mt->vts[VTS1] = CALIB_BUF0_VTS_TS1_V1(buf[0]); in mtk_thermal_extract_efuse_v1()
1007 mt->vts[VTS2] = CALIB_BUF0_VTS_TS2_V1(buf[0]); in mtk_thermal_extract_efuse_v1()
1010 mt->vts[VTS3] = CALIB_BUF1_VTS_TS3_V1(buf[1]); in mtk_thermal_extract_efuse_v1()
1013 mt->vts[VTS4] = CALIB_BUF2_VTS_TS4_V1(buf[2]); in mtk_thermal_extract_efuse_v1()
1016 mt->vts[VTS5] = CALIB_BUF2_VTS_TS5_V1(buf[2]); in mtk_thermal_extract_efuse_v1()
1019 mt->vts[VTSABB] = in mtk_thermal_extract_efuse_v1()
1027 mt->degc_cali = CALIB_BUF0_DEGC_CALI_V1(buf[0]); in mtk_thermal_extract_efuse_v1()
1030 mt->o_slope = -CALIB_BUF0_O_SLOPE_V1(buf[0]); in mtk_thermal_extract_efuse_v1()
1032 mt->o_slope = CALIB_BUF0_O_SLOPE_V1(buf[0]); in mtk_thermal_extract_efuse_v1()
1037 static int mtk_thermal_extract_efuse_v2(struct mtk_thermal *mt, u32 *buf) in mtk_thermal_extract_efuse_v2() argument
1042 mt->adc_oe = CALIB_BUF0_ADC_OE_V2(buf[0]); in mtk_thermal_extract_efuse_v2()
1043 mt->adc_ge = CALIB_BUF0_ADC_GE_V2(buf[0]); in mtk_thermal_extract_efuse_v2()
1044 mt->degc_cali = CALIB_BUF0_DEGC_CALI_V2(buf[0]); in mtk_thermal_extract_efuse_v2()
1045 mt->o_slope = CALIB_BUF0_O_SLOPE_V2(buf[0]); in mtk_thermal_extract_efuse_v2()
1046 mt->vts[VTS1] = CALIB_BUF1_VTS_TS1_V2(buf[1]); in mtk_thermal_extract_efuse_v2()
1047 mt->vts[VTS2] = CALIB_BUF1_VTS_TS2_V2(buf[1]); in mtk_thermal_extract_efuse_v2()
1048 mt->vts[VTSABB] = CALIB_BUF1_VTS_TSABB_V2(buf[1]); in mtk_thermal_extract_efuse_v2()
1049 mt->o_slope_sign = CALIB_BUF1_O_SLOPE_SIGN_V2(buf[1]); in mtk_thermal_extract_efuse_v2()
1054 static int mtk_thermal_extract_efuse_v3(struct mtk_thermal *mt, u32 *buf) in mtk_thermal_extract_efuse_v3() argument
1059 mt->adc_ge = CALIB_BUF0_ADC_GE_V3(buf[0]); in mtk_thermal_extract_efuse_v3()
1060 mt->degc_cali = CALIB_BUF0_DEGC_CALI_V3(buf[0]); in mtk_thermal_extract_efuse_v3()
1061 mt->o_slope = CALIB_BUF0_O_SLOPE_V3(buf[0]); in mtk_thermal_extract_efuse_v3()
1062 mt->vts[VTS1] = CALIB_BUF1_VTS_TS1_V3(buf[1]); in mtk_thermal_extract_efuse_v3()
1063 mt->vts[VTS2] = CALIB_BUF1_VTS_TS2_V3(buf[1]); in mtk_thermal_extract_efuse_v3()
1064 mt->vts[VTSABB] = CALIB_BUF1_VTS_TSABB_V3(buf[1]); in mtk_thermal_extract_efuse_v3()
1065 mt->o_slope_sign = CALIB_BUF1_O_SLOPE_SIGN_V3(buf[1]); in mtk_thermal_extract_efuse_v3()
1068 mt->o_slope = 0; in mtk_thermal_extract_efuse_v3()
1074 struct mtk_thermal *mt) in mtk_thermal_get_calibration_data() argument
1082 mt->adc_ge = 512; in mtk_thermal_get_calibration_data()
1083 mt->adc_oe = 512; in mtk_thermal_get_calibration_data()
1084 for (i = 0; i < mt->conf->num_sensors; i++) in mtk_thermal_get_calibration_data()
1085 mt->vts[i] = 260; in mtk_thermal_get_calibration_data()
1086 mt->degc_cali = 40; in mtk_thermal_get_calibration_data()
1087 mt->o_slope = 0; in mtk_thermal_get_calibration_data()
1109 switch (mt->conf->version) { in mtk_thermal_get_calibration_data()
1111 ret = mtk_thermal_extract_efuse_v1(mt, buf); in mtk_thermal_get_calibration_data()
1114 ret = mtk_thermal_extract_efuse_v2(mt, buf); in mtk_thermal_get_calibration_data()
1117 ret = mtk_thermal_extract_efuse_v3(mt, buf); in mtk_thermal_get_calibration_data()
1168 static void mtk_thermal_turn_on_buffer(struct mtk_thermal *mt, in mtk_thermal_turn_on_buffer() argument
1173 if (!mt->conf->apmixed_buffer_ctl_reg) in mtk_thermal_turn_on_buffer()
1176 tmp = readl(apmixed_base + mt->conf->apmixed_buffer_ctl_reg); in mtk_thermal_turn_on_buffer()
1177 tmp &= mt->conf->apmixed_buffer_ctl_mask; in mtk_thermal_turn_on_buffer()
1178 tmp |= mt->conf->apmixed_buffer_ctl_set; in mtk_thermal_turn_on_buffer()
1179 writel(tmp, apmixed_base + mt->conf->apmixed_buffer_ctl_reg); in mtk_thermal_turn_on_buffer()
1183 static void mtk_thermal_release_periodic_ts(struct mtk_thermal *mt, in mtk_thermal_release_periodic_ts() argument
1189 writel(0x1, mt->thermal_base + TEMP_MONCTL0); in mtk_thermal_release_periodic_ts()
1190 tmp = readl(mt->thermal_base + TEMP_MSRCTL1); in mtk_thermal_release_periodic_ts()
1191 writel((tmp & (~0x10e)), mt->thermal_base + TEMP_MSRCTL1); in mtk_thermal_release_periodic_ts()
1198 struct mtk_thermal *mt; in mtk_thermal_probe() local
1203 mt = devm_kzalloc(&pdev->dev, sizeof(*mt), GFP_KERNEL); in mtk_thermal_probe()
1204 if (!mt) in mtk_thermal_probe()
1207 mt->conf = of_device_get_match_data(&pdev->dev); in mtk_thermal_probe()
1209 mt->thermal_base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); in mtk_thermal_probe()
1210 if (IS_ERR(mt->thermal_base)) in mtk_thermal_probe()
1211 return PTR_ERR(mt->thermal_base); in mtk_thermal_probe()
1213 ret = mtk_thermal_get_calibration_data(&pdev->dev, mt); in mtk_thermal_probe()
1217 mutex_init(&mt->lock); in mtk_thermal_probe()
1219 mt->dev = &pdev->dev; in mtk_thermal_probe()
1257 mt->clk_auxadc = devm_clk_get_enabled(&pdev->dev, "auxadc"); in mtk_thermal_probe()
1258 if (IS_ERR(mt->clk_auxadc)) { in mtk_thermal_probe()
1259 ret = PTR_ERR(mt->clk_auxadc); in mtk_thermal_probe()
1264 mt->clk_peri_therm = devm_clk_get_enabled(&pdev->dev, "therm"); in mtk_thermal_probe()
1265 if (IS_ERR(mt->clk_peri_therm)) { in mtk_thermal_probe()
1266 ret = PTR_ERR(mt->clk_peri_therm); in mtk_thermal_probe()
1271 mtk_thermal_turn_on_buffer(mt, apmixed_base); in mtk_thermal_probe()
1273 if (mt->conf->version != MTK_THERMAL_V1) in mtk_thermal_probe()
1274 mtk_thermal_release_periodic_ts(mt, auxadc_base); in mtk_thermal_probe()
1276 if (mt->conf->version == MTK_THERMAL_V1) in mtk_thermal_probe()
1277 mt->raw_to_mcelsius = raw_to_mcelsius_v1; in mtk_thermal_probe()
1278 else if (mt->conf->version == MTK_THERMAL_V2) in mtk_thermal_probe()
1279 mt->raw_to_mcelsius = raw_to_mcelsius_v2; in mtk_thermal_probe()
1281 mt->raw_to_mcelsius = raw_to_mcelsius_v3; in mtk_thermal_probe()
1283 for (ctrl_id = 0; ctrl_id < mt->conf->num_controller ; ctrl_id++) in mtk_thermal_probe()
1284 for (i = 0; i < mt->conf->num_banks; i++) in mtk_thermal_probe()
1285 mtk_thermal_init_bank(mt, i, apmixed_phys_base, in mtk_thermal_probe()
1288 tzdev = devm_thermal_of_zone_register(&pdev->dev, 0, mt, in mtk_thermal_probe()