Lines Matching +full:ambient +full:- +full:celsius
1 // SPDX-License-Identifier: GPL-2.0
15 #include <linux/nvmem-consumer.h>
58 /* millidegree celsius */
92 /* Temp Unit: millidegree Celsius */
96 return tmdev->chip->offset - (reg * tmdev->chip->scale / 10); in sun8i_ths_calc_temp()
103 return -1191 * reg / 10 + 223000; in sun50i_h5_calc_temp()
105 return -1452 * reg / 10 + 259000; in sun50i_h5_calc_temp()
107 return -1590 * reg / 10 + 276000; in sun50i_h5_calc_temp()
113 struct ths_device *tmdev = s->tmdev; in sun8i_ths_get_temp()
116 regmap_read(tmdev->regmap, tmdev->chip->temp_data_base + in sun8i_ths_get_temp()
117 0x4 * s->id, &val); in sun8i_ths_get_temp()
121 return -EAGAIN; in sun8i_ths_get_temp()
123 *temp = tmdev->chip->calc_temp(tmdev, s->id, val); in sun8i_ths_get_temp()
132 *temp += tmdev->chip->ft_deviation; in sun8i_ths_get_temp()
153 regmap_read(tmdev->regmap, SUN8I_THS_IS, &state); in sun8i_h3_irq_ack()
155 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun8i_h3_irq_ack()
157 regmap_write(tmdev->regmap, SUN8I_THS_IS, in sun8i_h3_irq_ack()
170 regmap_read(tmdev->regmap, SUN50I_H6_THS_DIS, &state); in sun50i_h6_irq_ack()
172 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun50i_h6_irq_ack()
174 regmap_write(tmdev->regmap, SUN50I_H6_THS_DIS, in sun50i_h6_irq_ack()
188 state = tmdev->chip->irq_ack(tmdev); in sun8i_irq_thread()
190 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun8i_irq_thread()
192 thermal_zone_device_update(tmdev->sensor[i].tzd, in sun8i_irq_thread()
204 if (!caldata[0] || callen < 2 * tmdev->chip->sensor_num) in sun8i_h3_ths_calibrate()
205 return -EINVAL; in sun8i_h3_ths_calibrate()
207 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun8i_h3_ths_calibrate()
210 regmap_update_bits(tmdev->regmap, in sun8i_h3_ths_calibrate()
222 struct device *dev = tmdev->dev; in sun50i_h6_ths_calibrate()
225 if (!caldata[0] || callen < 2 + 2 * tmdev->chip->sensor_num) in sun50i_h6_ths_calibrate()
226 return -EINVAL; in sun50i_h6_ths_calibrate()
232 * +-------+-------+-------+ in sun50i_h6_ths_calibrate()
234 * +-------+-------+-------+ in sun50i_h6_ths_calibrate()
236 * The calibration data on the H6 is the ambient temperature and in sun50i_h6_ths_calibrate()
246 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun50i_h6_ths_calibrate()
249 int sensor_temp = tmdev->chip->calc_temp(tmdev, i, sensor_reg); in sun50i_h6_ths_calibrate()
252 * Calibration data is CALIBRATE_DEFAULT - (calculated in sun50i_h6_ths_calibrate()
257 cdata = CALIBRATE_DEFAULT - in sun50i_h6_ths_calibrate()
258 ((sensor_temp - ft_temp) * 10 / tmdev->chip->scale); in sun50i_h6_ths_calibrate()
261 * Calibration value more than 12-bit, but calibration in sun50i_h6_ths_calibrate()
262 * register is 12-bit. In this case, ths hardware can in sun50i_h6_ths_calibrate()
271 regmap_update_bits(tmdev->regmap, in sun50i_h6_ths_calibrate()
283 struct device *dev = tmdev->dev; in sun8i_ths_calibrate()
290 if (PTR_ERR(calcell) == -EPROBE_DEFER) in sun8i_ths_calibrate()
291 return -EPROBE_DEFER; in sun8i_ths_calibrate()
314 tmdev->chip->calibrate(tmdev, caldata, callen); in sun8i_ths_calibrate()
323 struct device *dev = tmdev->dev; in sun8i_ths_resource_init()
332 tmdev->regmap = devm_regmap_init_mmio(dev, base, &config); in sun8i_ths_resource_init()
333 if (IS_ERR(tmdev->regmap)) in sun8i_ths_resource_init()
334 return PTR_ERR(tmdev->regmap); in sun8i_ths_resource_init()
336 if (tmdev->chip->has_bus_clk_reset) { in sun8i_ths_resource_init()
337 tmdev->reset = devm_reset_control_get(dev, NULL); in sun8i_ths_resource_init()
338 if (IS_ERR(tmdev->reset)) in sun8i_ths_resource_init()
339 return PTR_ERR(tmdev->reset); in sun8i_ths_resource_init()
341 tmdev->bus_clk = devm_clk_get(&pdev->dev, "bus"); in sun8i_ths_resource_init()
342 if (IS_ERR(tmdev->bus_clk)) in sun8i_ths_resource_init()
343 return PTR_ERR(tmdev->bus_clk); in sun8i_ths_resource_init()
346 if (tmdev->chip->has_mod_clk) { in sun8i_ths_resource_init()
347 tmdev->mod_clk = devm_clk_get(&pdev->dev, "mod"); in sun8i_ths_resource_init()
348 if (IS_ERR(tmdev->mod_clk)) in sun8i_ths_resource_init()
349 return PTR_ERR(tmdev->mod_clk); in sun8i_ths_resource_init()
352 ret = reset_control_deassert(tmdev->reset); in sun8i_ths_resource_init()
356 ret = clk_prepare_enable(tmdev->bus_clk); in sun8i_ths_resource_init()
360 ret = clk_set_rate(tmdev->mod_clk, 24000000); in sun8i_ths_resource_init()
364 ret = clk_prepare_enable(tmdev->mod_clk); in sun8i_ths_resource_init()
375 clk_disable_unprepare(tmdev->mod_clk); in sun8i_ths_resource_init()
377 clk_disable_unprepare(tmdev->bus_clk); in sun8i_ths_resource_init()
379 reset_control_assert(tmdev->reset); in sun8i_ths_resource_init()
389 regmap_write(tmdev->regmap, SUN8I_THS_MFC, in sun8i_h3_thermal_init()
397 * x = period * clkin / 4096 / filter_samples - 1 in sun8i_h3_thermal_init()
400 val = GENMASK(7 + tmdev->chip->sensor_num, 8); in sun8i_h3_thermal_init()
401 regmap_write(tmdev->regmap, SUN8I_THS_IC, in sun8i_h3_thermal_init()
407 * x = T_acq * clkin - 1 in sun8i_h3_thermal_init()
410 regmap_write(tmdev->regmap, SUN8I_THS_CTRL0, in sun8i_h3_thermal_init()
412 val = GENMASK(tmdev->chip->sensor_num - 1, 0); in sun8i_h3_thermal_init()
413 regmap_write(tmdev->regmap, SUN8I_THS_CTRL2, in sun8i_h3_thermal_init()
433 * x = T_acq * clkin - 1 in sun50i_h6_thermal_init()
436 regmap_write(tmdev->regmap, SUN50I_THS_CTRL0, in sun50i_h6_thermal_init()
439 regmap_write(tmdev->regmap, SUN50I_H6_THS_MFC, in sun50i_h6_thermal_init()
447 * x = period * clkin / 4096 / filter_samples - 1 in sun50i_h6_thermal_init()
450 regmap_write(tmdev->regmap, SUN50I_H6_THS_PC, in sun50i_h6_thermal_init()
453 val = GENMASK(tmdev->chip->sensor_num - 1, 0); in sun50i_h6_thermal_init()
454 regmap_write(tmdev->regmap, SUN50I_H6_THS_ENABLE, val); in sun50i_h6_thermal_init()
456 val = GENMASK(tmdev->chip->sensor_num - 1, 0); in sun50i_h6_thermal_init()
457 regmap_write(tmdev->regmap, SUN50I_H6_THS_DIC, val); in sun50i_h6_thermal_init()
466 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun8i_ths_register()
467 tmdev->sensor[i].tmdev = tmdev; in sun8i_ths_register()
468 tmdev->sensor[i].id = i; in sun8i_ths_register()
469 tmdev->sensor[i].tzd = in sun8i_ths_register()
470 devm_thermal_zone_of_sensor_register(tmdev->dev, in sun8i_ths_register()
472 &tmdev->sensor[i], in sun8i_ths_register()
474 if (IS_ERR(tmdev->sensor[i].tzd)) in sun8i_ths_register()
475 return PTR_ERR(tmdev->sensor[i].tzd); in sun8i_ths_register()
477 if (devm_thermal_add_hwmon_sysfs(tmdev->sensor[i].tzd)) in sun8i_ths_register()
478 dev_warn(tmdev->dev, in sun8i_ths_register()
488 struct device *dev = &pdev->dev; in sun8i_ths_probe()
493 return -ENOMEM; in sun8i_ths_probe()
495 tmdev->dev = dev; in sun8i_ths_probe()
496 tmdev->chip = of_device_get_match_data(&pdev->dev); in sun8i_ths_probe()
497 if (!tmdev->chip) in sun8i_ths_probe()
498 return -EINVAL; in sun8i_ths_probe()
510 ret = tmdev->chip->init(tmdev); in sun8i_ths_probe()
536 clk_disable_unprepare(tmdev->mod_clk); in sun8i_ths_remove()
537 clk_disable_unprepare(tmdev->bus_clk); in sun8i_ths_remove()
538 reset_control_assert(tmdev->reset); in sun8i_ths_remove()
631 { .compatible = "allwinner,sun8i-a83t-ths", .data = &sun8i_a83t_ths },
632 { .compatible = "allwinner,sun8i-h3-ths", .data = &sun8i_h3_ths },
633 { .compatible = "allwinner,sun8i-r40-ths", .data = &sun8i_r40_ths },
634 { .compatible = "allwinner,sun50i-a64-ths", .data = &sun50i_a64_ths },
635 { .compatible = "allwinner,sun50i-a100-ths", .data = &sun50i_a100_ths },
636 { .compatible = "allwinner,sun50i-h5-ths", .data = &sun50i_h5_ths },
637 { .compatible = "allwinner,sun50i-h6-ths", .data = &sun50i_h6_ths },
646 .name = "sun8i-thermal",