Lines Matching full:lvts_ctrl
119 #define lvts_for_each_valid_sensor(i, lvts_ctrl) \ argument
121 if (!((lvts_ctrl)->valid_sensor_mask & BIT(i))) \
126 const struct lvts_ctrl_data *lvts_ctrl; member
144 struct lvts_ctrl { struct
157 struct lvts_ctrl *lvts_ctrl; argument
219 struct lvts_ctrl *lvts_ctrl; in lvts_debugfs_init() local
230 lvts_ctrl = &lvts_td->lvts_ctrl[i]; in lvts_debugfs_init()
241 regset->base = lvts_ctrl->base; in lvts_debugfs_init()
290 struct lvts_ctrl *lvts_ctrl = container_of(lvts_sensor, struct lvts_ctrl, in lvts_get_temp() local
292 const struct lvts_data *lvts_data = lvts_ctrl->lvts_data; in lvts_get_temp()
330 static void lvts_update_irq_mask(struct lvts_ctrl *lvts_ctrl) in lvts_update_irq_mask() argument
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()
354 static bool lvts_should_update_thresh(struct lvts_ctrl *lvts_ctrl, int high) in lvts_should_update_thresh() argument
358 if (high > lvts_ctrl->high_thresh) in lvts_should_update_thresh()
361 lvts_for_each_valid_sensor(i, lvts_ctrl) 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()
372 struct lvts_ctrl *lvts_ctrl = container_of(lvts_sensor, struct lvts_ctrl, in lvts_set_trips() local
374 const struct lvts_data *lvts_data = lvts_ctrl->lvts_data; in lvts_set_trips()
384 should_update_thresh = lvts_should_update_thresh(lvts_ctrl, 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()
389 lvts_update_irq_mask(lvts_ctrl); in lvts_set_trips()
423 static irqreturn_t lvts_ctrl_irq_handler(struct lvts_ctrl *lvts_ctrl) in lvts_ctrl_irq_handler() argument
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()
546 aux = lvts_ctrl_irq_handler(&lvts_td->lvts_ctrl[i]); in lvts_irq_handler()
561 static int lvts_sensor_init(struct device *dev, struct lvts_ctrl *lvts_ctrl, in lvts_sensor_init() argument
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()
610 lvts_sensor[i].base = lvts_ctrl->base; in lvts_sensor_init()
622 lvts_ctrl->valid_sensor_mask = lvts_ctrl_data->valid_sensor_mask; in lvts_sensor_init()
687 static int lvts_calibration_init(struct device *dev, struct lvts_ctrl *lvts_ctrl, in lvts_calibration_init() argument
696 gt = (((u32 *)efuse_calibration)[0] >> lvts_ctrl->lvts_data->gt_calib_bit_offset) & 0xff; in lvts_calibration_init()
708 lvts_ctrl->calibration[i] = 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()
798 size_t size = sizeof(*lvts_td->lvts_ctrl) * lvts_data->num_lvts_ctrl; in lvts_ctrl_init()
799 struct lvts_ctrl *lvts_ctrl; in lvts_ctrl_init() local
813 lvts_ctrl = devm_kzalloc(dev, size, GFP_KERNEL); in lvts_ctrl_init()
814 if (!lvts_ctrl) in lvts_ctrl_init()
819 lvts_ctrl[i].base = lvts_td->base + lvts_data->lvts_ctrl[i].offset; in lvts_ctrl_init()
820 lvts_ctrl[i].lvts_data = lvts_data; in lvts_ctrl_init()
822 ret = lvts_sensor_init(dev, &lvts_ctrl[i], in lvts_ctrl_init()
823 &lvts_data->lvts_ctrl[i]); in lvts_ctrl_init()
827 ret = lvts_calibration_init(dev, &lvts_ctrl[i], in lvts_ctrl_init()
828 &lvts_data->lvts_ctrl[i], in lvts_ctrl_init()
838 lvts_ctrl[i].mode = lvts_data->lvts_ctrl[i].mode; in lvts_ctrl_init()
844 lvts_ctrl[i].hw_tshut_raw_temp = in lvts_ctrl_init()
848 lvts_ctrl[i].low_thresh = INT_MIN; in lvts_ctrl_init()
849 lvts_ctrl[i].high_thresh = INT_MIN; in lvts_ctrl_init()
857 lvts_td->lvts_ctrl = lvts_ctrl; in lvts_ctrl_init()
869 static void lvts_write_config(struct lvts_ctrl *lvts_ctrl, u32 *cmds, int nr_cmds) in lvts_write_config() argument
877 writel(cmds[i], LVTS_CONFIG(lvts_ctrl->base)); in lvts_write_config()
882 static int lvts_irq_init(struct lvts_ctrl *lvts_ctrl) in lvts_irq_init() argument
896 writel(BIT(16), LVTS_PROTCTL(lvts_ctrl->base)); 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()
937 static int lvts_ctrl_set_enable(struct lvts_ctrl *lvts_ctrl, int enable) in lvts_ctrl_set_enable() argument
946 writel(enable, LVTS_CLKEN(lvts_ctrl->base)); in lvts_ctrl_set_enable()
951 static int lvts_ctrl_connect(struct device *dev, struct lvts_ctrl *lvts_ctrl) in lvts_ctrl_connect() argument
955 lvts_write_config(lvts_ctrl, cmds, ARRAY_SIZE(cmds)); in lvts_ctrl_connect()
965 id = readl(LVTS_ID(lvts_ctrl->base)); in lvts_ctrl_connect()
972 static int lvts_ctrl_initialize(struct device *dev, struct lvts_ctrl *lvts_ctrl) in lvts_ctrl_initialize() argument
984 lvts_write_config(lvts_ctrl, cmds, ARRAY_SIZE(cmds)); in lvts_ctrl_initialize()
989 static int lvts_ctrl_calibrate(struct device *dev, struct lvts_ctrl *lvts_ctrl) in lvts_ctrl_calibrate() argument
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()
1007 writel(lvts_ctrl->calibration[i], lvts_edata[i]); in lvts_ctrl_calibrate()
1012 static int lvts_ctrl_configure(struct device *dev, struct lvts_ctrl *lvts_ctrl) in lvts_ctrl_configure() argument
1027 writel(value, LVTS_TSSEL(lvts_ctrl->base)); in lvts_ctrl_configure()
1056 writel(value, LVTS_MSRCTL0(lvts_ctrl->base)); in lvts_ctrl_configure()
1099 writel(value, LVTS_MONCTL1(lvts_ctrl->base)); in lvts_ctrl_configure()
1112 writel(value, LVTS_MONCTL2(lvts_ctrl->base)); in lvts_ctrl_configure()
1114 return lvts_irq_init(lvts_ctrl); in lvts_ctrl_configure()
1117 static int lvts_ctrl_start(struct device *dev, struct lvts_ctrl *lvts_ctrl) in lvts_ctrl_start() argument
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()
1133 lvts_for_each_valid_sensor(i, lvts_ctrl) { 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()
1199 writel(sensor_map | BIT(9), LVTS_MONCTL0(lvts_ctrl->base)); in lvts_ctrl_start()
1208 struct lvts_ctrl *lvts_ctrl; in lvts_domain_init() local
1223 lvts_ctrl = &lvts_td->lvts_ctrl[i]; in lvts_domain_init()
1237 ret = lvts_ctrl_set_enable(lvts_ctrl, true); in lvts_domain_init()
1243 ret = lvts_ctrl_connect(dev, lvts_ctrl); in lvts_domain_init()
1249 ret = lvts_ctrl_initialize(dev, lvts_ctrl); in lvts_domain_init()
1255 ret = lvts_ctrl_calibrate(dev, lvts_ctrl); in lvts_domain_init()
1261 ret = lvts_ctrl_configure(dev, lvts_ctrl); in lvts_domain_init()
1267 ret = lvts_ctrl_start(dev, lvts_ctrl); in lvts_domain_init()
1341 lvts_ctrl_set_enable(&lvts_td->lvts_ctrl[i], false); in lvts_remove()
1385 lvts_ctrl_set_enable(&lvts_td->lvts_ctrl[i], false); in lvts_suspend()
1404 lvts_ctrl_set_enable(&lvts_td->lvts_ctrl[i], true); in lvts_resume()
1702 .lvts_ctrl = mt7988_lvts_ap_data_ctrl,
1710 .lvts_ctrl = mt8186_lvts_data_ctrl,
1719 .lvts_ctrl = mt8188_lvts_mcu_data_ctrl,
1728 .lvts_ctrl = mt8188_lvts_ap_data_ctrl,
1737 .lvts_ctrl = mt8192_lvts_mcu_data_ctrl,
1746 .lvts_ctrl = mt8192_lvts_ap_data_ctrl,
1755 .lvts_ctrl = mt8195_lvts_mcu_data_ctrl,
1764 .lvts_ctrl = mt8195_lvts_ap_data_ctrl,