Lines Matching +full:imx6sx +full:- +full:ocotp

1 // SPDX-License-Identifier: GPL-2.0
17 #include <linux/nvmem-consumer.h>
222 const struct thermal_soc_data *soc_data = data->socdata; in imx_set_panic_temp()
223 struct regmap *map = data->tempmon; in imx_set_panic_temp()
226 critical_value = (data->c2 - panic_temp) / data->c1; in imx_set_panic_temp()
228 regmap_write(map, soc_data->panic_alarm_ctrl + REG_CLR, in imx_set_panic_temp()
229 soc_data->panic_alarm_mask); in imx_set_panic_temp()
230 regmap_write(map, soc_data->panic_alarm_ctrl + REG_SET, in imx_set_panic_temp()
231 critical_value << soc_data->panic_alarm_shift); in imx_set_panic_temp()
237 struct regmap *map = data->tempmon; in imx_set_alarm_temp()
238 const struct thermal_soc_data *soc_data = data->socdata; in imx_set_alarm_temp()
241 data->alarm_temp = alarm_temp; in imx_set_alarm_temp()
243 if (data->socdata->version == TEMPMON_IMX7D) in imx_set_alarm_temp()
244 alarm_value = alarm_temp / 1000 + data->c1 - 25; in imx_set_alarm_temp()
246 alarm_value = (data->c2 - alarm_temp) / data->c1; in imx_set_alarm_temp()
248 regmap_write(map, soc_data->high_alarm_ctrl + REG_CLR, in imx_set_alarm_temp()
249 soc_data->high_alarm_mask); in imx_set_alarm_temp()
250 regmap_write(map, soc_data->high_alarm_ctrl + REG_SET, in imx_set_alarm_temp()
251 alarm_value << soc_data->high_alarm_shift); in imx_set_alarm_temp()
257 const struct thermal_soc_data *soc_data = data->socdata; in imx_get_temp()
258 struct regmap *map = data->tempmon; in imx_get_temp()
263 ret = pm_runtime_resume_and_get(data->dev); in imx_get_temp()
267 regmap_read(map, soc_data->temp_data, &val); in imx_get_temp()
269 if ((val & soc_data->temp_valid_mask) == 0) in imx_get_temp()
270 return -EAGAIN; in imx_get_temp()
272 n_meas = (val & soc_data->temp_value_mask) in imx_get_temp()
273 >> soc_data->temp_value_shift; in imx_get_temp()
276 if (data->socdata->version == TEMPMON_IMX7D) in imx_get_temp()
277 *temp = (n_meas - data->c1 + 25) * 1000; in imx_get_temp()
279 *temp = data->c2 - n_meas * data->c1; in imx_get_temp()
282 if (data->socdata->version == TEMPMON_IMX6Q) { in imx_get_temp()
283 if (data->alarm_temp == trips[IMX_TRIP_PASSIVE].temperature && in imx_get_temp()
286 if (data->alarm_temp == trips[IMX_TRIP_CRITICAL].temperature && in imx_get_temp()
289 dev_dbg(data->dev, "thermal alarm off: T < %d\n", in imx_get_temp()
290 data->alarm_temp / 1000); in imx_get_temp()
294 if (*temp != data->last_temp) { in imx_get_temp()
295 dev_dbg(data->dev, "millicelsius: %d\n", *temp); in imx_get_temp()
296 data->last_temp = *temp; in imx_get_temp()
300 if (!data->irq_enabled && *temp < data->alarm_temp) { in imx_get_temp()
301 data->irq_enabled = true; in imx_get_temp()
302 enable_irq(data->irq); in imx_get_temp()
305 pm_runtime_put(data->dev); in imx_get_temp()
316 pm_runtime_get(data->dev); in imx_change_mode()
318 if (!data->irq_enabled) { in imx_change_mode()
319 data->irq_enabled = true; in imx_change_mode()
320 enable_irq(data->irq); in imx_change_mode()
323 pm_runtime_put(data->dev); in imx_change_mode()
325 if (data->irq_enabled) { in imx_change_mode()
326 disable_irq(data->irq); in imx_change_mode()
327 data->irq_enabled = false; in imx_change_mode()
340 ret = pm_runtime_resume_and_get(data->dev); in imx_set_trip_temp()
346 return -EINVAL; in imx_set_trip_temp()
351 pm_runtime_put(data->dev); in imx_set_trip_temp()
361 return trip->type == THERMAL_TRIP_PASSIVE; in imx_should_bind()
378 dev_err(&pdev->dev, "invalid sensor calibration data\n"); in imx_init_calib()
379 return -EINVAL; in imx_init_calib()
384 * Tmeas = ( Nmeas - n1) + 25; n1 is the fuse value for 25C. in imx_init_calib()
386 if (data->socdata->version == TEMPMON_IMX7D) { in imx_init_calib()
387 data->c1 = (ocotp_ana1 >> 9) & 0x1ff; in imx_init_calib()
394 * i.MX's OCOTP value ANA1. in imx_init_calib()
398 * T = T1 + (N - N1) / (0.4148468 - 0.0015423 * N1) °C + 3.580661 °C in imx_init_calib()
399 * = [T1' - N1 / (0.4148468 - 0.0015423 * N1) °C] + N / (0.4148468 - 0.0015423 * N1) °C in imx_init_calib()
400 * = [T1' + N1 / (0.0015423 * N1 - 0.4148468) °C] - N / (0.0015423 * N1 - 0.4148468) °C in imx_init_calib()
401 * = c2 - c1 * N in imx_init_calib()
406 * c1 = 1 / (0.0015423 * N1 - 0.4297157) °C in imx_init_calib()
407 * c2 = T1' + N1 / (0.0015423 * N1 - 0.4148468) °C in imx_init_calib()
414 do_div(temp64, 15423 * n1 - 4148468); in imx_init_calib()
415 data->c1 = temp64; in imx_init_calib()
416 data->c2 = n1 * data->c1 + 28581; in imx_init_calib()
428 data->temp_grade = "Commercial"; in imx_init_temp_grade()
429 data->temp_max = 95000; in imx_init_temp_grade()
431 case 1: /* Extended Commercial (-20 °C to 105 °C) */ in imx_init_temp_grade()
432 data->temp_grade = "Extended Commercial"; in imx_init_temp_grade()
433 data->temp_max = 105000; in imx_init_temp_grade()
435 case 2: /* Industrial (-40 °C to 105 °C) */ in imx_init_temp_grade()
436 data->temp_grade = "Industrial"; in imx_init_temp_grade()
437 data->temp_max = 105000; in imx_init_temp_grade()
439 case 3: /* Automotive (-40 °C to 125 °C) */ in imx_init_temp_grade()
440 data->temp_grade = "Automotive"; in imx_init_temp_grade()
441 data->temp_max = 125000; in imx_init_temp_grade()
449 trips[IMX_TRIP_PASSIVE].temperature = data->temp_max - (1000 * 10); in imx_init_temp_grade()
450 trips[IMX_TRIP_CRITICAL].temperature = data->temp_max - (1000 * 5); in imx_init_temp_grade()
459 map = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, in imx_init_from_tempmon_data()
460 "fsl,tempmon-data"); in imx_init_from_tempmon_data()
463 dev_err(&pdev->dev, "failed to get sensor regmap: %d\n", ret); in imx_init_from_tempmon_data()
469 dev_err(&pdev->dev, "failed to read sensor data: %d\n", ret); in imx_init_from_tempmon_data()
478 dev_err(&pdev->dev, "failed to read sensor data: %d\n", ret); in imx_init_from_tempmon_data()
491 ret = nvmem_cell_read_u32(&pdev->dev, "calib", &val); in imx_init_from_nvmem_cells()
499 ret = nvmem_cell_read_u32(&pdev->dev, "temp_grade", &val); in imx_init_from_nvmem_cells()
512 data->irq_enabled = false; in imx_thermal_alarm_irq()
521 dev_dbg(data->dev, "THERMAL ALARM: T > %d\n", data->alarm_temp / 1000); in imx_thermal_alarm_irq_thread()
523 thermal_zone_device_update(data->tz, THERMAL_EVENT_UNSPECIFIED); in imx_thermal_alarm_irq_thread()
529 { .compatible = "fsl,imx6q-tempmon", .data = &thermal_imx6q_data, },
530 { .compatible = "fsl,imx6sx-tempmon", .data = &thermal_imx6sx_data, },
531 { .compatible = "fsl,imx7d-tempmon", .data = &thermal_imx7d_data, },
538 * Create cooling device in case no #cooling-cells property is available in
546 data->policy = cpufreq_cpu_get(0); in imx_thermal_register_legacy_cooling()
547 if (!data->policy) { in imx_thermal_register_legacy_cooling()
549 return -EPROBE_DEFER; in imx_thermal_register_legacy_cooling()
552 np = of_get_cpu_node(data->policy->cpu, NULL); in imx_thermal_register_legacy_cooling()
554 if (!np || !of_property_present(np, "#cooling-cells")) { in imx_thermal_register_legacy_cooling()
555 data->cdev = cpufreq_cooling_register(data->policy); in imx_thermal_register_legacy_cooling()
556 if (IS_ERR(data->cdev)) { in imx_thermal_register_legacy_cooling()
557 ret = PTR_ERR(data->cdev); in imx_thermal_register_legacy_cooling()
558 cpufreq_cpu_put(data->policy); in imx_thermal_register_legacy_cooling()
569 cpufreq_cooling_unregister(data->cdev); in imx_thermal_unregister_legacy_cooling()
570 cpufreq_cpu_put(data->policy); in imx_thermal_unregister_legacy_cooling()
587 struct device *dev = &pdev->dev; in imx_thermal_probe()
595 return -ENOMEM; in imx_thermal_probe()
597 data->dev = dev; in imx_thermal_probe()
599 map = syscon_regmap_lookup_by_phandle(dev->of_node, "fsl,tempmon"); in imx_thermal_probe()
605 data->tempmon = map; in imx_thermal_probe()
607 data->socdata = of_device_get_match_data(dev); in imx_thermal_probe()
608 if (!data->socdata) { in imx_thermal_probe()
610 return -ENODEV; in imx_thermal_probe()
614 if (data->socdata->version == TEMPMON_IMX6SX) { in imx_thermal_probe()
622 regmap_write(map, data->socdata->low_alarm_ctrl + REG_SET, in imx_thermal_probe()
623 data->socdata->low_alarm_mask); in imx_thermal_probe()
626 data->irq = platform_get_irq(pdev, 0); in imx_thermal_probe()
627 if (data->irq < 0) in imx_thermal_probe()
628 return data->irq; in imx_thermal_probe()
632 if (of_property_present(dev->of_node, "nvmem-cells")) { in imx_thermal_probe()
640 dev_err(dev, "failed to init from fsl,tempmon-data\n"); in imx_thermal_probe()
646 regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, in imx_thermal_probe()
647 data->socdata->power_down_mask); in imx_thermal_probe()
648 regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, in imx_thermal_probe()
649 data->socdata->measure_temp_mask); in imx_thermal_probe()
650 regmap_write(map, data->socdata->measure_freq_ctrl + REG_CLR, in imx_thermal_probe()
651 data->socdata->measure_freq_mask); in imx_thermal_probe()
652 if (data->socdata->version != TEMPMON_IMX7D) in imx_thermal_probe()
655 regmap_write(map, data->socdata->sensor_ctrl + REG_SET, in imx_thermal_probe()
656 data->socdata->power_down_mask); in imx_thermal_probe()
663 data->thermal_clk = devm_clk_get(dev, NULL); in imx_thermal_probe()
664 if (IS_ERR(data->thermal_clk)) { in imx_thermal_probe()
665 ret = dev_err_probe(dev, PTR_ERR(data->thermal_clk), "failed to get thermal clk\n"); in imx_thermal_probe()
676 ret = clk_prepare_enable(data->thermal_clk); in imx_thermal_probe()
682 data->tz = thermal_zone_device_register_with_trips("imx_thermal_zone", in imx_thermal_probe()
689 if (IS_ERR(data->tz)) { in imx_thermal_probe()
690 ret = PTR_ERR(data->tz); in imx_thermal_probe()
696 dev_info(dev, "%s CPU temperature grade - max:%dC" in imx_thermal_probe()
697 " critical:%dC passive:%dC\n", data->temp_grade, in imx_thermal_probe()
698 data->temp_max / 1000, trips[IMX_TRIP_CRITICAL].temperature / 1000, in imx_thermal_probe()
702 regmap_write(map, data->socdata->measure_freq_ctrl + REG_CLR, in imx_thermal_probe()
703 data->socdata->measure_freq_mask); in imx_thermal_probe()
705 regmap_write(map, data->socdata->measure_freq_ctrl + REG_SET, in imx_thermal_probe()
706 measure_freq << data->socdata->measure_freq_shift); in imx_thermal_probe()
709 if (data->socdata->version == TEMPMON_IMX6SX) in imx_thermal_probe()
712 regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, in imx_thermal_probe()
713 data->socdata->power_down_mask); in imx_thermal_probe()
714 regmap_write(map, data->socdata->sensor_ctrl + REG_SET, in imx_thermal_probe()
715 data->socdata->measure_temp_mask); in imx_thermal_probe()
721 pm_runtime_enable(data->dev); in imx_thermal_probe()
723 ret = pm_runtime_resume_and_get(data->dev); in imx_thermal_probe()
727 data->irq_enabled = true; in imx_thermal_probe()
728 ret = thermal_zone_device_enable(data->tz); in imx_thermal_probe()
732 ret = devm_request_threaded_irq(dev, data->irq, in imx_thermal_probe()
740 pm_runtime_put(data->dev); in imx_thermal_probe()
745 thermal_zone_device_unregister(data->tz); in imx_thermal_probe()
747 pm_runtime_put_noidle(data->dev); in imx_thermal_probe()
748 pm_runtime_disable(data->dev); in imx_thermal_probe()
750 clk_disable_unprepare(data->thermal_clk); in imx_thermal_probe()
761 pm_runtime_put_noidle(data->dev); in imx_thermal_remove()
762 pm_runtime_disable(data->dev); in imx_thermal_remove()
764 thermal_zone_device_unregister(data->tz); in imx_thermal_remove()
780 ret = thermal_zone_device_disable(data->tz); in imx_thermal_suspend()
784 return pm_runtime_force_suspend(data->dev); in imx_thermal_suspend()
792 ret = pm_runtime_force_resume(data->dev); in imx_thermal_resume()
796 return thermal_zone_device_enable(data->tz); in imx_thermal_resume()
802 const struct thermal_soc_data *socdata = data->socdata; in imx_thermal_runtime_suspend()
803 struct regmap *map = data->tempmon; in imx_thermal_runtime_suspend()
806 ret = regmap_write(map, socdata->sensor_ctrl + REG_CLR, in imx_thermal_runtime_suspend()
807 socdata->measure_temp_mask); in imx_thermal_runtime_suspend()
811 ret = regmap_write(map, socdata->sensor_ctrl + REG_SET, in imx_thermal_runtime_suspend()
812 socdata->power_down_mask); in imx_thermal_runtime_suspend()
816 clk_disable_unprepare(data->thermal_clk); in imx_thermal_runtime_suspend()
824 const struct thermal_soc_data *socdata = data->socdata; in imx_thermal_runtime_resume()
825 struct regmap *map = data->tempmon; in imx_thermal_runtime_resume()
828 ret = clk_prepare_enable(data->thermal_clk); in imx_thermal_runtime_resume()
832 ret = regmap_write(map, socdata->sensor_ctrl + REG_CLR, in imx_thermal_runtime_resume()
833 socdata->power_down_mask); in imx_thermal_runtime_resume()
837 ret = regmap_write(map, socdata->sensor_ctrl + REG_SET, in imx_thermal_runtime_resume()
838 socdata->measure_temp_mask); in imx_thermal_runtime_resume()
871 MODULE_ALIAS("platform:imx-thermal");