Lines Matching +full:adc +full:- +full:res +full:- +full:names

1 // SPDX-License-Identifier: GPL-2.0-only
8 #include <linux/clk-provider.h>
15 #include <linux/nvmem-consumer.h>
20 #include <dt-bindings/thermal/mediatek,lvts-thermal.h>
83 #define LVTS_COEFF_A_MT8195 -250460
85 #define LVTS_COEFF_A_MT7988 -204650
121 if (!((lvts_ctrl)->valid_sensor_mask & BIT(i))) \
224 lvts_td->dom_dentry = debugfs_create_dir(dev_name(dev), NULL); in lvts_debugfs_init()
225 if (IS_ERR(lvts_td->dom_dentry)) in lvts_debugfs_init()
228 for (i = 0; i < lvts_td->num_lvts_ctrl; i++) { in lvts_debugfs_init()
230 lvts_ctrl = &lvts_td->lvts_ctrl[i]; in lvts_debugfs_init()
233 dentry = debugfs_create_dir(name, lvts_td->dom_dentry); in lvts_debugfs_init()
241 regset->base = lvts_ctrl->base; in lvts_debugfs_init()
242 regset->regs = lvts_regs; in lvts_debugfs_init()
243 regset->nregs = ARRAY_SIZE(lvts_regs); in lvts_debugfs_init()
253 debugfs_remove_recursive(lvts_td->dom_dentry); in lvts_debugfs_exit()
280 u32 raw_temp = ((s64)(golden_temp_offset - temperature)) << 14; in lvts_temp_to_raw()
282 raw_temp = div_s64(raw_temp, -temp_factor); in lvts_temp_to_raw()
291 sensors[lvts_sensor->id]); in lvts_get_temp()
292 const struct lvts_data *lvts_data = lvts_ctrl->lvts_data; in lvts_get_temp()
293 void __iomem *msr = lvts_sensor->msr; in lvts_get_temp()
300 * LVTS_MSR[0-3] / LVTS_IMMD[0-3] in lvts_get_temp()
304 * 32-17: Unused in lvts_get_temp()
306 * 15-0 : Raw temperature in lvts_get_temp()
323 return -EAGAIN; in lvts_get_temp()
325 *temp = lvts_raw_to_temp(value & 0xFFFF, lvts_data->temp_factor); in lvts_get_temp()
341 value = readl(LVTS_MONINT(lvts_ctrl->base)); in lvts_update_irq_mask()
344 if (lvts_ctrl->sensors[i].high_thresh == lvts_ctrl->high_thresh in lvts_update_irq_mask()
345 && lvts_ctrl->sensors[i].low_thresh == lvts_ctrl->low_thresh) in lvts_update_irq_mask()
351 writel(value, LVTS_MONINT(lvts_ctrl->base)); in lvts_update_irq_mask()
358 if (high > lvts_ctrl->high_thresh) in lvts_should_update_thresh()
362 if (lvts_ctrl->sensors[i].high_thresh == lvts_ctrl->high_thresh in lvts_should_update_thresh()
363 && lvts_ctrl->sensors[i].low_thresh == lvts_ctrl->low_thresh) in lvts_should_update_thresh()
373 sensors[lvts_sensor->id]); in lvts_set_trips()
374 const struct lvts_data *lvts_data = lvts_ctrl->lvts_data; in lvts_set_trips()
375 void __iomem *base = lvts_sensor->base; in lvts_set_trips()
376 u32 raw_low = lvts_temp_to_raw(low != -INT_MAX ? low : LVTS_MINIMUM_THRESHOLD, in lvts_set_trips()
377 lvts_data->temp_factor); in lvts_set_trips()
378 u32 raw_high = lvts_temp_to_raw(high, lvts_data->temp_factor); in lvts_set_trips()
381 lvts_sensor->low_thresh = low; in lvts_set_trips()
382 lvts_sensor->high_thresh = high; in lvts_set_trips()
386 lvts_ctrl->high_thresh = high; in lvts_set_trips()
387 lvts_ctrl->low_thresh = low; in lvts_set_trips()
401 * 14-0 : Raw temperature for threshold in lvts_set_trips()
414 * 14-0 : Raw temperature for threshold in lvts_set_trips()
497 value = readl(LVTS_MONINTSTS(lvts_ctrl->base)); in lvts_ctrl_irq_handler()
511 thermal_zone_device_update(lvts_ctrl->sensors[i].tz, in lvts_ctrl_irq_handler()
519 writel(value, LVTS_MONINTSTS(lvts_ctrl->base)); in lvts_ctrl_irq_handler()
544 for (i = 0; i < lvts_td->num_lvts_ctrl; i++) { in lvts_irq_handler()
546 aux = lvts_ctrl_irq_handler(&lvts_td->lvts_ctrl[i]); in lvts_irq_handler()
564 struct lvts_sensor *lvts_sensor = lvts_ctrl->sensors; in lvts_sensor_init()
567 LVTS_MSR0(lvts_ctrl->base), in lvts_sensor_init()
568 LVTS_MSR1(lvts_ctrl->base), in lvts_sensor_init()
569 LVTS_MSR2(lvts_ctrl->base), in lvts_sensor_init()
570 LVTS_MSR3(lvts_ctrl->base) in lvts_sensor_init()
574 LVTS_IMMD0(lvts_ctrl->base), in lvts_sensor_init()
575 LVTS_IMMD1(lvts_ctrl->base), in lvts_sensor_init()
576 LVTS_IMMD2(lvts_ctrl->base), in lvts_sensor_init()
577 LVTS_IMMD3(lvts_ctrl->base) in lvts_sensor_init()
584 int dt_id = lvts_ctrl_data->lvts_sensor[i].dt_id; in lvts_sensor_init()
610 lvts_sensor[i].base = lvts_ctrl->base; in lvts_sensor_init()
615 lvts_sensor[i].msr = lvts_ctrl_data->mode == LVTS_MSR_IMMEDIATE_MODE ? in lvts_sensor_init()
622 lvts_ctrl->valid_sensor_mask = lvts_ctrl_data->valid_sensor_mask; in lvts_sensor_init()
634 * <-----mcu-tc#0-----> <-----sensor#0-----> <-----sensor#1----->
637 * <-----sensor#2-----> <-----sensor#3----->
640 …* <-----sensor#4-----> <-----sensor#5-----> <-----sensor#6-----> <-----sensor…
645 * <-----sensor#0-----> <-----sensor#1----->
648 * <-----sensor#2-----> <-----sensor#3----->
651 * <-----sensor#4-----> <-----sensor#5----->
654 * <-----sensor#6-----> <-----sensor#7-----> <-----sensor#8----->
660 * <-----mcu-tc#0-----> <-----sensor#0-----> <-----sensor#1----->
663 * <-----mcu-tc#1-----> <-----sensor#2-----> <-----sensor#3----->
666 …* <-----mcu-tc#2-----> <-----sensor#4-----> <-----sensor#5-----> <-----sensor#6-----> <-----sensor…
671 * <-----ap--tc#0-----> <-----sensor#0-----> <-----sensor#1----->
674 * <-----ap--tc#1-----> <-----sensor#2-----> <-----sensor#3----->
677 * <-----ap--tc#2-----> <-----sensor#4-----> <-----sensor#5-----> <-----sensor#6----->
680 * <-----ap--tc#3-----> <-----sensor#7-----> <-----sensor#8----->
696 gt = (((u32 *)efuse_calibration)[0] >> lvts_ctrl->lvts_data->gt_calib_bit_offset) & 0xff; in lvts_calibration_init()
700 &lvts_ctrl_data->lvts_sensor[i]; in lvts_calibration_init()
702 if (sensor->cal_offsets[0] >= calib_len || in lvts_calibration_init()
703 sensor->cal_offsets[1] >= calib_len || in lvts_calibration_init()
704 sensor->cal_offsets[2] >= calib_len) in lvts_calibration_init()
705 return -EINVAL; in lvts_calibration_init()
708 lvts_ctrl->calibration[i] = in lvts_calibration_init()
709 (efuse_calibration[sensor->cal_offsets[0]] << 0) + in lvts_calibration_init()
710 (efuse_calibration[sensor->cal_offsets[1]] << 8) + in lvts_calibration_init()
711 (efuse_calibration[sensor->cal_offsets[2]] << 16); in lvts_calibration_init()
712 } else if (lvts_ctrl->lvts_data->def_calibration) { in lvts_calibration_init()
713 lvts_ctrl->calibration[i] = lvts_ctrl->lvts_data->def_calibration; in lvts_calibration_init()
716 return -ENODATA; in lvts_calibration_init()
737 of_property_for_each_string(np, "nvmem-cell-names", prop, cell_name) { in lvts_calibration_read()
756 lvts_td->calib = devm_krealloc(dev, lvts_td->calib, in lvts_calibration_read()
757 lvts_td->calib_len + len, GFP_KERNEL); in lvts_calibration_read()
758 if (!lvts_td->calib) { in lvts_calibration_read()
760 return -ENOMEM; in lvts_calibration_read()
763 memcpy(lvts_td->calib + lvts_td->calib_len, efuse, len); in lvts_calibration_read()
765 lvts_td->calib_len += len; in lvts_calibration_read()
779 * The golden temp information is contained in the first 32-bit in lvts_golden_temp_init()
782 gt = (((u32 *)calib)[0] >> lvts_data->gt_calib_bit_offset) & 0xff; in lvts_golden_temp_init()
788 golden_temp_offset = golden_temp * 500 + lvts_data->temp_offset; in lvts_golden_temp_init()
798 size_t size = sizeof(*lvts_td->lvts_ctrl) * lvts_data->num_lvts_ctrl; in lvts_ctrl_init()
809 ret = lvts_golden_temp_init(dev, lvts_td->calib, lvts_data); in lvts_ctrl_init()
815 return -ENOMEM; in lvts_ctrl_init()
817 for (i = 0; i < lvts_data->num_lvts_ctrl; i++) { in lvts_ctrl_init()
819 lvts_ctrl[i].base = lvts_td->base + lvts_data->lvts_ctrl[i].offset; in lvts_ctrl_init()
823 &lvts_data->lvts_ctrl[i]); in lvts_ctrl_init()
828 &lvts_data->lvts_ctrl[i], in lvts_ctrl_init()
829 lvts_td->calib, in lvts_ctrl_init()
830 lvts_td->calib_len); in lvts_ctrl_init()
838 lvts_ctrl[i].mode = lvts_data->lvts_ctrl[i].mode; in lvts_ctrl_init()
846 lvts_data->temp_factor); in lvts_ctrl_init()
855 devm_kfree(dev, lvts_td->calib); in lvts_ctrl_init()
857 lvts_td->lvts_ctrl = lvts_ctrl; in lvts_ctrl_init()
858 lvts_td->num_lvts_ctrl = lvts_data->num_lvts_ctrl; in lvts_ctrl_init()
877 writel(cmds[i], LVTS_CONFIG(lvts_ctrl->base)); in lvts_write_config()
889 * 19-18 : Sensor to base the protection on in lvts_irq_init()
890 * 17-16 : Strategy: in lvts_irq_init()
893 * 10 : Selected sensor with bits 19-18 in lvts_irq_init()
896 writel(BIT(16), LVTS_PROTCTL(lvts_ctrl->base)); in lvts_irq_init()
905 * 14-0: Raw temperature threshold in lvts_irq_init()
907 * writel(0x0, LVTS_PROTTA(lvts_ctrl->base)); in lvts_irq_init()
908 * writel(0x0, LVTS_PROTTB(lvts_ctrl->base)); in lvts_irq_init()
910 writel(lvts_ctrl->hw_tshut_raw_temp, LVTS_PROTTC(lvts_ctrl->base)); in lvts_irq_init()
918 writel(LVTS_MONINT_CONF, LVTS_MONINT(lvts_ctrl->base)); in lvts_irq_init()
946 writel(enable, LVTS_CLKEN(lvts_ctrl->base)); in lvts_ctrl_set_enable()
962 * 0-5 : thermal controller id in lvts_ctrl_connect()
965 id = readl(LVTS_ID(lvts_ctrl->base)); in lvts_ctrl_connect()
967 return -EIO; in lvts_ctrl_connect()
993 LVTS_EDATA00(lvts_ctrl->base), in lvts_ctrl_calibrate()
994 LVTS_EDATA01(lvts_ctrl->base), in lvts_ctrl_calibrate()
995 LVTS_EDATA02(lvts_ctrl->base), in lvts_ctrl_calibrate()
996 LVTS_EDATA03(lvts_ctrl->base) in lvts_ctrl_calibrate()
1004 * 20-0 : Efuse value for normalization data in lvts_ctrl_calibrate()
1007 writel(lvts_ctrl->calibration[i], lvts_edata[i]); in lvts_ctrl_calibrate()
1021 * 31-24: ADC Sense 3 in lvts_ctrl_configure()
1022 * 23-16: ADC Sense 2 in lvts_ctrl_configure()
1023 * 15-8 : ADC Sense 1 in lvts_ctrl_configure()
1024 * 7-0 : ADC Sense 0 in lvts_ctrl_configure()
1027 writel(value, LVTS_TSSEL(lvts_ctrl->base)); in lvts_ctrl_configure()
1030 * LVTS_CALSCALE : ADC voltage round in lvts_ctrl_configure()
1049 * 0-2 : Sensor0 filter in lvts_ctrl_configure()
1050 * 3-5 : Sensor1 filter in lvts_ctrl_configure()
1051 * 6-8 : Sensor2 filter in lvts_ctrl_configure()
1052 * 9-11 : Sensor3 filter in lvts_ctrl_configure()
1056 writel(value, LVTS_MSRCTL0(lvts_ctrl->base)); in lvts_ctrl_configure()
1070 * - Filter interval delay is a delay between two samples of in lvts_ctrl_configure()
1073 * - Sensor interval delay is a delay between two samples of in lvts_ctrl_configure()
1076 * - Group interval delay is a delay between different rounds. in lvts_ctrl_configure()
1088 * <--> Filter interval delay in lvts_ctrl_configure()
1089 * <--> Sensor interval delay in lvts_ctrl_configure()
1090 * <--> Group interval delay in lvts_ctrl_configure()
1092 * 29 - 20 : Group interval in lvts_ctrl_configure()
1093 * 16 - 13 : Send a single interrupt when crossing the hot threshold (1) in lvts_ctrl_configure()
1095 * 9 - 0 : Period unit in lvts_ctrl_configure()
1099 writel(value, LVTS_MONCTL1(lvts_ctrl->base)); in lvts_ctrl_configure()
1106 * 25-16 : Interval unit in PERIOD_UNIT between sample on in lvts_ctrl_configure()
1108 * 9-0 : Interval unit in PERIOD_UNIT between each sensor in lvts_ctrl_configure()
1112 writel(value, LVTS_MONCTL2(lvts_ctrl->base)); in lvts_ctrl_configure()
1119 struct lvts_sensor *lvts_sensors = lvts_ctrl->sensors; in lvts_ctrl_start()
1130 u32 *sensor_bitmap = lvts_ctrl->mode == LVTS_MSR_IMMEDIATE_MODE ? in lvts_ctrl_start()
1145 if (PTR_ERR(tz) == -ENODEV) in lvts_ctrl_start()
1178 if (lvts_ctrl->mode == LVTS_MSR_IMMEDIATE_MODE) { in lvts_ctrl_start()
1192 writel(sensor_map, LVTS_MSRCTL1(lvts_ctrl->base)); in lvts_ctrl_start()
1197 * 0-3: Enable sensing point 0-3 in lvts_ctrl_start()
1199 writel(sensor_map | BIT(9), LVTS_MONCTL0(lvts_ctrl->base)); in lvts_ctrl_start()
1215 ret = lvts_domain_reset(dev, lvts_td->reset); in lvts_domain_init()
1221 for (i = 0; i < lvts_td->num_lvts_ctrl; i++) { in lvts_domain_init()
1223 lvts_ctrl = &lvts_td->lvts_ctrl[i]; in lvts_domain_init()
1228 * - Enable the clock in lvts_domain_init()
1229 * - Connect to the LVTS in lvts_domain_init()
1230 * - Initialize the LVTS in lvts_domain_init()
1231 * - Prepare the calibration data in lvts_domain_init()
1232 * - Select monitored sensors in lvts_domain_init()
1235 * - Start measurement in lvts_domain_init()
1281 struct device *dev = &pdev->dev; in lvts_probe()
1282 struct resource *res; in lvts_probe() local
1287 return -ENOMEM; in lvts_probe()
1291 return -ENODEV; in lvts_probe()
1293 lvts_td->clk = devm_clk_get_enabled(dev, NULL); in lvts_probe()
1294 if (IS_ERR(lvts_td->clk)) in lvts_probe()
1295 return dev_err_probe(dev, PTR_ERR(lvts_td->clk), "Failed to retrieve clock\n"); in lvts_probe()
1297 res = platform_get_mem_or_io(pdev, 0); in lvts_probe()
1298 if (!res) in lvts_probe()
1299 return dev_err_probe(dev, (-ENXIO), "No IO resource\n"); in lvts_probe()
1301 lvts_td->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in lvts_probe()
1302 if (IS_ERR(lvts_td->base)) in lvts_probe()
1303 return dev_err_probe(dev, PTR_ERR(lvts_td->base), "Failed to map io resource\n"); in lvts_probe()
1305 lvts_td->reset = devm_reset_control_get_by_index(dev, 0); in lvts_probe()
1306 if (IS_ERR(lvts_td->reset)) in lvts_probe()
1307 return dev_err_probe(dev, PTR_ERR(lvts_td->reset), "Failed to get reset control\n"); in lvts_probe()
1313 golden_temp_offset = lvts_data->temp_offset; in lvts_probe()
1340 for (i = 0; i < lvts_td->num_lvts_ctrl; i++) in lvts_remove()
1341 lvts_ctrl_set_enable(&lvts_td->lvts_ctrl[i], false); in lvts_remove()
1384 for (i = 0; i < lvts_td->num_lvts_ctrl; i++) in lvts_suspend()
1385 lvts_ctrl_set_enable(&lvts_td->lvts_ctrl[i], false); in lvts_suspend()
1387 clk_disable_unprepare(lvts_td->clk); in lvts_suspend()
1399 ret = clk_prepare_enable(lvts_td->clk); in lvts_resume()
1403 for (i = 0; i < lvts_td->num_lvts_ctrl; i++) in lvts_resume()
1404 lvts_ctrl_set_enable(&lvts_td->lvts_ctrl[i], true); in lvts_resume()
1410 * The MT8186 calibration data is stored as packed 3-byte little-endian
1411 * values using a weird layout that makes sense only when viewed as a 32-bit
1415 * [S0B2-S0B1-S0B0-S1B2] [S1B1-S1B0-S2B2-S2B1] [S2B0-S3B2-S3B1-S3B0]
1773 { .compatible = "mediatek,mt7988-lvts-ap", .data = &mt7988_lvts_ap_data },
1774 { .compatible = "mediatek,mt8186-lvts", .data = &mt8186_lvts_data },
1775 { .compatible = "mediatek,mt8188-lvts-mcu", .data = &mt8188_lvts_mcu_data },
1776 { .compatible = "mediatek,mt8188-lvts-ap", .data = &mt8188_lvts_ap_data },
1777 { .compatible = "mediatek,mt8192-lvts-mcu", .data = &mt8192_lvts_mcu_data },
1778 { .compatible = "mediatek,mt8192-lvts-ap", .data = &mt8192_lvts_ap_data },
1779 { .compatible = "mediatek,mt8195-lvts-mcu", .data = &mt8195_lvts_mcu_data },
1780 { .compatible = "mediatek,mt8195-lvts-ap", .data = &mt8195_lvts_ap_data },
1793 .name = "mtk-lvts-thermal",