Lines Matching +full:calibration +full:- +full:data

1 // SPDX-License-Identifier: GPL-2.0
16 #include <linux/nvmem-consumer.h>
97 return tmdev->chip->offset - (reg * tmdev->chip->scale / 10); in sun8i_ths_calc_temp()
104 return -1191 * reg / 10 + 223000; in sun50i_h5_calc_temp()
106 return -1452 * reg / 10 + 259000; in sun50i_h5_calc_temp()
108 return -1590 * reg / 10 + 276000; in sun50i_h5_calc_temp()
113 struct tsensor *s = tz->devdata; in sun8i_ths_get_temp()
114 struct ths_device *tmdev = s->tmdev; in sun8i_ths_get_temp()
117 regmap_read(tmdev->regmap, tmdev->chip->temp_data_base + in sun8i_ths_get_temp()
118 0x4 * s->id, &val); in sun8i_ths_get_temp()
120 /* ths have no data yet */ in sun8i_ths_get_temp()
122 return -EAGAIN; in sun8i_ths_get_temp()
124 *temp = tmdev->chip->calc_temp(tmdev, s->id, val); in sun8i_ths_get_temp()
131 * do this, the correct calibration formula is hard to know. in sun8i_ths_get_temp()
133 *temp += tmdev->chip->ft_deviation; in sun8i_ths_get_temp()
155 regmap_read(tmdev->regmap, SUN8I_THS_IS, &state); in sun8i_h3_irq_ack()
157 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun8i_h3_irq_ack()
159 regmap_write(tmdev->regmap, SUN8I_THS_IS, in sun8i_h3_irq_ack()
173 regmap_read(tmdev->regmap, SUN50I_H6_THS_DIS, &state); in sun50i_h6_irq_ack()
175 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun50i_h6_irq_ack()
177 regmap_write(tmdev->regmap, SUN50I_H6_THS_DIS, in sun50i_h6_irq_ack()
186 static irqreturn_t sun8i_irq_thread(int irq, void *data) in sun8i_irq_thread() argument
188 struct ths_device *tmdev = data; in sun8i_irq_thread()
189 unsigned long irq_bitmap = tmdev->chip->irq_ack(tmdev); in sun8i_irq_thread()
192 for_each_set_bit(i, &irq_bitmap, tmdev->chip->sensor_num) { in sun8i_irq_thread()
193 thermal_zone_device_update(tmdev->sensor[i].tzd, in sun8i_irq_thread()
205 if (!caldata[0] || callen < 2 * tmdev->chip->sensor_num) in sun8i_h3_ths_calibrate()
206 return -EINVAL; in sun8i_h3_ths_calibrate()
208 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun8i_h3_ths_calibrate()
211 regmap_update_bits(tmdev->regmap, in sun8i_h3_ths_calibrate()
223 struct device *dev = tmdev->dev; in sun50i_h6_ths_calibrate()
226 if (!caldata[0] || callen < 2 + 2 * tmdev->chip->sensor_num) in sun50i_h6_ths_calibrate()
227 return -EINVAL; in sun50i_h6_ths_calibrate()
233 * +-------+-------+-------+ in sun50i_h6_ths_calibrate()
235 * +-------+-------+-------+ in sun50i_h6_ths_calibrate()
237 * The calibration data on the H6 is the ambient temperature and in sun50i_h6_ths_calibrate()
243 * register values and this will become a calibration offset. in sun50i_h6_ths_calibrate()
247 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun50i_h6_ths_calibrate()
250 int sensor_temp = tmdev->chip->calc_temp(tmdev, i, sensor_reg); in sun50i_h6_ths_calibrate()
253 * Calibration data is CALIBRATE_DEFAULT - (calculated in sun50i_h6_ths_calibrate()
258 cdata = CALIBRATE_DEFAULT - in sun50i_h6_ths_calibrate()
259 ((sensor_temp - ft_temp) * 10 / tmdev->chip->scale); in sun50i_h6_ths_calibrate()
262 * Calibration value more than 12-bit, but calibration in sun50i_h6_ths_calibrate()
263 * register is 12-bit. In this case, ths hardware can in sun50i_h6_ths_calibrate()
264 * still work without calibration, although the data in sun50i_h6_ths_calibrate()
272 regmap_update_bits(tmdev->regmap, in sun50i_h6_ths_calibrate()
284 struct device *dev = tmdev->dev; in sun8i_ths_calibrate()
289 calcell = devm_nvmem_cell_get(dev, "calibration"); in sun8i_ths_calibrate()
291 if (PTR_ERR(calcell) == -EPROBE_DEFER) in sun8i_ths_calibrate()
292 return -EPROBE_DEFER; in sun8i_ths_calibrate()
294 * Even if the external calibration data stored in sid is in sun8i_ths_calibrate()
296 * the data won't be so accurate. in sun8i_ths_calibrate()
298 * The default value of calibration register is 0x800 for in sun8i_ths_calibrate()
299 * every sensor, and the calibration value is usually 0x7xx in sun8i_ths_calibrate()
303 * So here we do not return error if the calibration data is in sun8i_ths_calibrate()
315 tmdev->chip->calibrate(tmdev, caldata, callen); in sun8i_ths_calibrate()
324 struct device *dev = tmdev->dev; in sun8i_ths_resource_init()
333 tmdev->regmap = devm_regmap_init_mmio(dev, base, &config); in sun8i_ths_resource_init()
334 if (IS_ERR(tmdev->regmap)) in sun8i_ths_resource_init()
335 return PTR_ERR(tmdev->regmap); in sun8i_ths_resource_init()
337 if (tmdev->chip->has_bus_clk_reset) { in sun8i_ths_resource_init()
338 tmdev->reset = devm_reset_control_get(dev, NULL); in sun8i_ths_resource_init()
339 if (IS_ERR(tmdev->reset)) in sun8i_ths_resource_init()
340 return PTR_ERR(tmdev->reset); in sun8i_ths_resource_init()
342 tmdev->bus_clk = devm_clk_get(&pdev->dev, "bus"); in sun8i_ths_resource_init()
343 if (IS_ERR(tmdev->bus_clk)) in sun8i_ths_resource_init()
344 return PTR_ERR(tmdev->bus_clk); in sun8i_ths_resource_init()
347 if (tmdev->chip->has_mod_clk) { in sun8i_ths_resource_init()
348 tmdev->mod_clk = devm_clk_get(&pdev->dev, "mod"); in sun8i_ths_resource_init()
349 if (IS_ERR(tmdev->mod_clk)) in sun8i_ths_resource_init()
350 return PTR_ERR(tmdev->mod_clk); in sun8i_ths_resource_init()
353 ret = reset_control_deassert(tmdev->reset); in sun8i_ths_resource_init()
357 ret = clk_prepare_enable(tmdev->bus_clk); in sun8i_ths_resource_init()
361 ret = clk_set_rate(tmdev->mod_clk, 24000000); in sun8i_ths_resource_init()
365 ret = clk_prepare_enable(tmdev->mod_clk); in sun8i_ths_resource_init()
376 clk_disable_unprepare(tmdev->mod_clk); in sun8i_ths_resource_init()
378 clk_disable_unprepare(tmdev->bus_clk); in sun8i_ths_resource_init()
380 reset_control_assert(tmdev->reset); in sun8i_ths_resource_init()
390 regmap_write(tmdev->regmap, SUN8I_THS_MFC, in sun8i_h3_thermal_init()
398 * x = period * clkin / 4096 / filter_samples - 1 in sun8i_h3_thermal_init()
401 val = GENMASK(7 + tmdev->chip->sensor_num, 8); in sun8i_h3_thermal_init()
402 regmap_write(tmdev->regmap, SUN8I_THS_IC, in sun8i_h3_thermal_init()
408 * x = T_acq * clkin - 1 in sun8i_h3_thermal_init()
411 regmap_write(tmdev->regmap, SUN8I_THS_CTRL0, in sun8i_h3_thermal_init()
413 val = GENMASK(tmdev->chip->sensor_num - 1, 0); in sun8i_h3_thermal_init()
414 regmap_write(tmdev->regmap, SUN8I_THS_CTRL2, in sun8i_h3_thermal_init()
434 * x = T_acq * clkin - 1 in sun50i_h6_thermal_init()
437 regmap_write(tmdev->regmap, SUN50I_THS_CTRL0, in sun50i_h6_thermal_init()
440 regmap_write(tmdev->regmap, SUN50I_H6_THS_MFC, in sun50i_h6_thermal_init()
448 * x = period * clkin / 4096 / filter_samples - 1 in sun50i_h6_thermal_init()
451 regmap_write(tmdev->regmap, SUN50I_H6_THS_PC, in sun50i_h6_thermal_init()
454 val = GENMASK(tmdev->chip->sensor_num - 1, 0); in sun50i_h6_thermal_init()
455 regmap_write(tmdev->regmap, SUN50I_H6_THS_ENABLE, val); in sun50i_h6_thermal_init()
456 /* thermal data interrupt enable */ in sun50i_h6_thermal_init()
457 val = GENMASK(tmdev->chip->sensor_num - 1, 0); in sun50i_h6_thermal_init()
458 regmap_write(tmdev->regmap, SUN50I_H6_THS_DIC, val); in sun50i_h6_thermal_init()
467 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun8i_ths_register()
468 tmdev->sensor[i].tmdev = tmdev; in sun8i_ths_register()
469 tmdev->sensor[i].id = i; in sun8i_ths_register()
470 tmdev->sensor[i].tzd = in sun8i_ths_register()
471 devm_thermal_of_zone_register(tmdev->dev, in sun8i_ths_register()
473 &tmdev->sensor[i], in sun8i_ths_register()
475 if (IS_ERR(tmdev->sensor[i].tzd)) in sun8i_ths_register()
476 return PTR_ERR(tmdev->sensor[i].tzd); in sun8i_ths_register()
478 if (devm_thermal_add_hwmon_sysfs(tmdev->sensor[i].tzd)) in sun8i_ths_register()
479 dev_warn(tmdev->dev, in sun8i_ths_register()
489 struct device *dev = &pdev->dev; in sun8i_ths_probe()
494 return -ENOMEM; in sun8i_ths_probe()
496 tmdev->dev = dev; in sun8i_ths_probe()
497 tmdev->chip = of_device_get_match_data(&pdev->dev); in sun8i_ths_probe()
498 if (!tmdev->chip) in sun8i_ths_probe()
499 return -EINVAL; in sun8i_ths_probe()
511 ret = tmdev->chip->init(tmdev); in sun8i_ths_probe()
537 clk_disable_unprepare(tmdev->mod_clk); in sun8i_ths_remove()
538 clk_disable_unprepare(tmdev->bus_clk); in sun8i_ths_remove()
539 reset_control_assert(tmdev->reset); in sun8i_ths_remove()
632 { .compatible = "allwinner,sun8i-a83t-ths", .data = &sun8i_a83t_ths },
633 { .compatible = "allwinner,sun8i-h3-ths", .data = &sun8i_h3_ths },
634 { .compatible = "allwinner,sun8i-r40-ths", .data = &sun8i_r40_ths },
635 { .compatible = "allwinner,sun50i-a64-ths", .data = &sun50i_a64_ths },
636 { .compatible = "allwinner,sun50i-a100-ths", .data = &sun50i_a100_ths },
637 { .compatible = "allwinner,sun50i-h5-ths", .data = &sun50i_h5_ths },
638 { .compatible = "allwinner,sun50i-h6-ths", .data = &sun50i_h6_ths },
647 .name = "sun8i-thermal",