Lines Matching +full:combined +full:- +full:sensors

1 // SPDX-License-Identifier: GPL-2.0
8 #include <linux/nvmem-consumer.h>
58 #define SPRD_THM_TEMP_LOW -40000
139 return -EINVAL; in sprd_thm_cal_read()
163 ratio += thm->ratio_sign * thm->ratio_off; in sprd_thm_sensor_calibration()
166 * According to the ideal slope K and ideal offset B, combined with in sprd_thm_sensor_calibration()
170 * b_cal = b + (dt_offset - 64) * 500. in sprd_thm_sensor_calibration()
172 sen->cal_slope = (thm->var_data->ideal_k * ratio) / 1000; in sprd_thm_sensor_calibration()
173 sen->cal_offset = thm->var_data->ideal_b + (dt_offset - 128) * 250; in sprd_thm_sensor_calibration()
186 * T_final = k_cal * x - b_cal. in sprd_thm_rawdata_to_temp()
188 return sen->cal_slope * rawdata - sen->cal_offset; in sprd_thm_rawdata_to_temp()
200 * T_final = k_cal * x - b_cal. in sprd_thm_temp_to_rawdata()
202 val = (temp + sen->cal_offset) / sen->cal_slope; in sprd_thm_temp_to_rawdata()
204 return clamp(val, val, (u32)(SPRD_THM_RAW_DATA_HIGH - 1)); in sprd_thm_temp_to_rawdata()
212 data = readl(sen->data->base + SPRD_THM_TEMP(sen->id)) & in sprd_thm_read_temp()
232 ret = readl_poll_timeout(thm->base + SPRD_THM_CTL, val, in sprd_thm_poll_ready_status()
239 sprd_thm_update_bits(thm->base + SPRD_THM_CTL, SPRD_THM_MON_EN, in sprd_thm_poll_ready_status()
241 sprd_thm_update_bits(thm->base + SPRD_THM_CTL, SPRD_THM_SET_RDY, in sprd_thm_poll_ready_status()
251 return readl_poll_timeout(thm->base + SPRD_THM_INTERNAL_STS1, val, in sprd_thm_wait_temp_ready()
274 writel(SPRD_THM_INT_CLR_MASK, thm->base + SPRD_THM_INT_CLR); in sprd_thm_set_ready()
275 sprd_thm_update_bits(thm->base + SPRD_THM_INT_EN, in sprd_thm_set_ready()
277 sprd_thm_update_bits(thm->base + SPRD_THM_CTL, in sprd_thm_set_ready()
291 sprd_thm_update_bits(thm->base + SPRD_THM_INT_EN, in sprd_thm_sensor_init()
292 SPRD_THM_SEN_OVERHEAT_ALARM_EN(sen->id), in sprd_thm_sensor_init()
293 SPRD_THM_SEN_OVERHEAT_ALARM_EN(sen->id)); in sprd_thm_sensor_init()
296 sprd_thm_update_bits(thm->base + SPRD_THM_THRES(sen->id), in sprd_thm_sensor_init()
302 sprd_thm_update_bits(thm->base + SPRD_THM_CTL, SPRD_THM_SEN(sen->id), in sprd_thm_sensor_init()
303 SPRD_THM_SEN(sen->id)); in sprd_thm_sensor_init()
309 sprd_thm_update_bits(thm->base + SPRD_THM_DET_PERIOD, in sprd_thm_para_config()
312 /* Set the sensors' monitor mode */ in sprd_thm_para_config()
313 sprd_thm_update_bits(thm->base + SPRD_THM_MON_CTL, in sprd_thm_para_config()
316 /* Set the sensors' monitor period */ in sprd_thm_para_config()
317 sprd_thm_update_bits(thm->base + SPRD_THM_MON_PERIOD, in sprd_thm_para_config()
323 struct thermal_zone_device *tzd = sen->tzd; in sprd_thm_toggle_sensor()
333 struct device_node *np = pdev->dev.of_node; in sprd_thm_probe()
341 pdata = of_device_get_match_data(&pdev->dev); in sprd_thm_probe()
343 dev_err(&pdev->dev, "No matching driver data found\n"); in sprd_thm_probe()
344 return -EINVAL; in sprd_thm_probe()
347 thm = devm_kzalloc(&pdev->dev, sizeof(*thm), GFP_KERNEL); in sprd_thm_probe()
349 return -ENOMEM; in sprd_thm_probe()
351 thm->var_data = pdata; in sprd_thm_probe()
352 thm->base = devm_platform_ioremap_resource(pdev, 0); in sprd_thm_probe()
353 if (IS_ERR(thm->base)) in sprd_thm_probe()
354 return PTR_ERR(thm->base); in sprd_thm_probe()
356 thm->nr_sensors = of_get_child_count(np); in sprd_thm_probe()
357 if (thm->nr_sensors == 0 || thm->nr_sensors > SPRD_THM_MAX_SENSOR) { in sprd_thm_probe()
358 dev_err(&pdev->dev, "incorrect sensor count\n"); in sprd_thm_probe()
359 return -EINVAL; in sprd_thm_probe()
362 thm->clk = devm_clk_get_enabled(&pdev->dev, "enable"); in sprd_thm_probe()
363 if (IS_ERR(thm->clk)) { in sprd_thm_probe()
364 dev_err(&pdev->dev, "failed to get enable clock\n"); in sprd_thm_probe()
365 return PTR_ERR(thm->clk); in sprd_thm_probe()
375 thm->ratio_sign = -1; in sprd_thm_probe()
377 thm->ratio_sign = 1; in sprd_thm_probe()
379 ret = sprd_thm_cal_read(np, "thm_ratio_cal", &thm->ratio_off); in sprd_thm_probe()
384 sen = devm_kzalloc(&pdev->dev, sizeof(*sen), GFP_KERNEL); in sprd_thm_probe()
386 ret = -ENOMEM; in sprd_thm_probe()
390 sen->data = thm; in sprd_thm_probe()
391 sen->dev = &pdev->dev; in sprd_thm_probe()
393 ret = of_property_read_u32(sen_child, "reg", &sen->id); in sprd_thm_probe()
395 dev_err(&pdev->dev, "get sensor reg failed"); in sprd_thm_probe()
401 dev_err(&pdev->dev, "efuse cal analysis failed"); in sprd_thm_probe()
407 sen->tzd = devm_thermal_of_zone_register(sen->dev, in sprd_thm_probe()
408 sen->id, in sprd_thm_probe()
411 if (IS_ERR(sen->tzd)) { in sprd_thm_probe()
412 dev_err(&pdev->dev, "register thermal zone failed %d\n", in sprd_thm_probe()
413 sen->id); in sprd_thm_probe()
414 ret = PTR_ERR(sen->tzd); in sprd_thm_probe()
418 thm->sensor[sen->id] = sen; in sprd_thm_probe()
430 for (i = 0; i < thm->nr_sensors; i++) in sprd_thm_probe()
431 sprd_thm_toggle_sensor(thm->sensor[i], true); in sprd_thm_probe()
446 for (i = 0; i < thm->nr_sensors; i++) { in sprd_thm_hw_suspend()
447 sprd_thm_update_bits(thm->base + SPRD_THM_CTL, in sprd_thm_hw_suspend()
448 SPRD_THM_SEN(thm->sensor[i]->id), 0); in sprd_thm_hw_suspend()
451 sprd_thm_update_bits(thm->base + SPRD_THM_CTL, in sprd_thm_hw_suspend()
460 for (i = 0; i < thm->nr_sensors; i++) in sprd_thm_suspend()
461 sprd_thm_toggle_sensor(thm->sensor[i], false); in sprd_thm_suspend()
464 clk_disable_unprepare(thm->clk); in sprd_thm_suspend()
473 for (i = 0; i < thm->nr_sensors; i++) { in sprd_thm_hw_resume()
474 sprd_thm_update_bits(thm->base + SPRD_THM_CTL, in sprd_thm_hw_resume()
475 SPRD_THM_SEN(thm->sensor[i]->id), in sprd_thm_hw_resume()
476 SPRD_THM_SEN(thm->sensor[i]->id)); in sprd_thm_hw_resume()
483 writel(SPRD_THM_INT_CLR_MASK, thm->base + SPRD_THM_INT_CLR); in sprd_thm_hw_resume()
484 sprd_thm_update_bits(thm->base + SPRD_THM_CTL, in sprd_thm_hw_resume()
494 ret = clk_prepare_enable(thm->clk); in sprd_thm_resume()
502 for (i = 0; i < thm->nr_sensors; i++) in sprd_thm_resume()
503 sprd_thm_toggle_sensor(thm->sensor[i], true); in sprd_thm_resume()
508 clk_disable_unprepare(thm->clk); in sprd_thm_resume()
518 for (i = 0; i < thm->nr_sensors; i++) { in sprd_thm_remove()
519 sprd_thm_toggle_sensor(thm->sensor[i], false); in sprd_thm_remove()
520 devm_thermal_of_zone_unregister(&pdev->dev, in sprd_thm_remove()
521 thm->sensor[i]->tzd); in sprd_thm_remove()
526 { .compatible = "sprd,ums512-thermal", .data = &ums512_data },
539 .name = "sprd-thermal",