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

1 // SPDX-License-Identifier: GPL-2.0
16 #include <linux/nvmem-consumer.h>
54 #define SUN50I_THS_CTRL0_T_ACQ(x) (GENMASK(15, 0) & ((x) - 1))
55 #define SUN50I_THS_CTRL0_T_SAMPLE_PER(x) ((GENMASK(15, 0) & ((x) - 1)) << 16)
102 return tmdev->chip->offset - (reg * tmdev->chip->scale / 10); in sun8i_ths_calc_temp()
109 return -1191 * reg / 10 + 223000; in sun50i_h5_calc_temp()
111 return -1452 * reg / 10 + 259000; in sun50i_h5_calc_temp()
113 return -1590 * reg / 10 + 276000; in sun50i_h5_calc_temp()
119 struct ths_device *tmdev = s->tmdev; in sun8i_ths_get_temp()
122 regmap_read(tmdev->regmap, tmdev->chip->temp_data_base + in sun8i_ths_get_temp()
123 0x4 * s->id, &val); in sun8i_ths_get_temp()
125 /* ths have no data yet */ in sun8i_ths_get_temp()
127 return -EAGAIN; in sun8i_ths_get_temp()
129 *temp = tmdev->chip->calc_temp(tmdev, s->id, val); in sun8i_ths_get_temp()
136 * do this, the correct calibration formula is hard to know. in sun8i_ths_get_temp()
138 *temp += tmdev->chip->ft_deviation; in sun8i_ths_get_temp()
160 regmap_read(tmdev->regmap, SUN8I_THS_IS, &state); in sun8i_h3_irq_ack()
162 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun8i_h3_irq_ack()
164 regmap_write(tmdev->regmap, SUN8I_THS_IS, in sun8i_h3_irq_ack()
178 regmap_read(tmdev->regmap, SUN50I_H6_THS_DIS, &state); in sun50i_h6_irq_ack()
180 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun50i_h6_irq_ack()
182 regmap_write(tmdev->regmap, SUN50I_H6_THS_DIS, in sun50i_h6_irq_ack()
191 static irqreturn_t sun8i_irq_thread(int irq, void *data) in sun8i_irq_thread() argument
193 struct ths_device *tmdev = data; in sun8i_irq_thread()
194 unsigned long irq_bitmap = tmdev->chip->irq_ack(tmdev); in sun8i_irq_thread()
197 for_each_set_bit(i, &irq_bitmap, tmdev->chip->sensor_num) { in sun8i_irq_thread()
199 if (IS_ERR(tmdev->sensor[i].tzd)) in sun8i_irq_thread()
201 thermal_zone_device_update(tmdev->sensor[i].tzd, in sun8i_irq_thread()
213 if (!caldata[0] || callen < 2 * tmdev->chip->sensor_num) in sun8i_h3_ths_calibrate()
214 return -EINVAL; in sun8i_h3_ths_calibrate()
216 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun8i_h3_ths_calibrate()
219 regmap_update_bits(tmdev->regmap, in sun8i_h3_ths_calibrate()
231 struct device *dev = tmdev->dev; in sun50i_h6_ths_calibrate()
235 return -EINVAL; in sun50i_h6_ths_calibrate()
241 * +----------+-----------+-----------+-----------+ in sun50i_h6_ths_calibrate()
243 * +----------+-----------+-----------+-----------+ in sun50i_h6_ths_calibrate()
250 * The calibration data on the H6 is the ambient temperature and in sun50i_h6_ths_calibrate()
256 * register values and this will become a calibration offset. in sun50i_h6_ths_calibrate()
260 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun50i_h6_ths_calibrate()
270 sensor_temp = tmdev->chip->calc_temp(tmdev, i, sensor_reg); in sun50i_h6_ths_calibrate()
273 * Calibration data is CALIBRATE_DEFAULT - (calculated in sun50i_h6_ths_calibrate()
278 cdata = CALIBRATE_DEFAULT - in sun50i_h6_ths_calibrate()
279 ((sensor_temp - ft_temp) * 10 / tmdev->chip->scale); in sun50i_h6_ths_calibrate()
282 * Calibration value more than 12-bit, but calibration in sun50i_h6_ths_calibrate()
283 * register is 12-bit. In this case, ths hardware can in sun50i_h6_ths_calibrate()
284 * still work without calibration, although the data in sun50i_h6_ths_calibrate()
292 regmap_update_bits(tmdev->regmap, in sun50i_h6_ths_calibrate()
304 struct device *dev = tmdev->dev; in sun8i_ths_calibrate()
309 calcell = nvmem_cell_get(dev, "calibration"); in sun8i_ths_calibrate()
311 if (PTR_ERR(calcell) == -EPROBE_DEFER) in sun8i_ths_calibrate()
312 return -EPROBE_DEFER; in sun8i_ths_calibrate()
314 * Even if the external calibration data stored in sid is in sun8i_ths_calibrate()
316 * the data won't be so accurate. in sun8i_ths_calibrate()
318 * The default value of calibration register is 0x800 for in sun8i_ths_calibrate()
319 * every sensor, and the calibration value is usually 0x7xx in sun8i_ths_calibrate()
323 * So here we do not return error if the calibration data is in sun8i_ths_calibrate()
335 tmdev->chip->calibrate(tmdev, caldata, callen); in sun8i_ths_calibrate()
344 static void sun8i_ths_reset_control_assert(void *data) in sun8i_ths_reset_control_assert() argument
346 reset_control_assert(data); in sun8i_ths_reset_control_assert()
357 return ERR_PTR(-ENODEV); in sun8i_ths_get_sram_regmap()
362 regmap = ERR_PTR(-EPROBE_DEFER); in sun8i_ths_get_sram_regmap()
367 regmap = dev_get_regmap(&sram_pdev->dev, NULL); in sun8i_ths_get_sram_regmap()
369 regmap = ERR_PTR(-EINVAL); in sun8i_ths_get_sram_regmap()
379 struct device *dev = tmdev->dev; in sun8i_ths_resource_init()
388 tmdev->regmap = devm_regmap_init_mmio(dev, base, &config); in sun8i_ths_resource_init()
389 if (IS_ERR(tmdev->regmap)) in sun8i_ths_resource_init()
390 return PTR_ERR(tmdev->regmap); in sun8i_ths_resource_init()
392 if (tmdev->chip->has_bus_clk_reset) { in sun8i_ths_resource_init()
393 tmdev->reset = devm_reset_control_get(dev, NULL); in sun8i_ths_resource_init()
394 if (IS_ERR(tmdev->reset)) in sun8i_ths_resource_init()
395 return PTR_ERR(tmdev->reset); in sun8i_ths_resource_init()
397 ret = reset_control_deassert(tmdev->reset); in sun8i_ths_resource_init()
402 tmdev->reset); in sun8i_ths_resource_init()
406 tmdev->bus_clk = devm_clk_get_enabled(&pdev->dev, "bus"); in sun8i_ths_resource_init()
407 if (IS_ERR(tmdev->bus_clk)) in sun8i_ths_resource_init()
408 return PTR_ERR(tmdev->bus_clk); in sun8i_ths_resource_init()
411 if (tmdev->chip->has_mod_clk) { in sun8i_ths_resource_init()
412 tmdev->mod_clk = devm_clk_get_enabled(&pdev->dev, "mod"); in sun8i_ths_resource_init()
413 if (IS_ERR(tmdev->mod_clk)) in sun8i_ths_resource_init()
414 return PTR_ERR(tmdev->mod_clk); in sun8i_ths_resource_init()
417 ret = clk_set_rate(tmdev->mod_clk, 24000000); in sun8i_ths_resource_init()
421 if (tmdev->chip->needs_sram) { in sun8i_ths_resource_init()
424 regmap = sun8i_ths_get_sram_regmap(dev->of_node); in sun8i_ths_resource_init()
427 tmdev->sram_regmap_field = devm_regmap_field_alloc(dev, in sun8i_ths_resource_init()
430 if (IS_ERR(tmdev->sram_regmap_field)) in sun8i_ths_resource_init()
431 return PTR_ERR(tmdev->sram_regmap_field); in sun8i_ths_resource_init()
446 regmap_write(tmdev->regmap, SUN8I_THS_MFC, in sun8i_h3_thermal_init()
454 * x = period * clkin / 4096 / filter_samples - 1 in sun8i_h3_thermal_init()
457 val = GENMASK(7 + tmdev->chip->sensor_num, 8); in sun8i_h3_thermal_init()
458 regmap_write(tmdev->regmap, SUN8I_THS_IC, in sun8i_h3_thermal_init()
464 * x = T_acq * clkin - 1 in sun8i_h3_thermal_init()
467 regmap_write(tmdev->regmap, SUN8I_THS_CTRL0, in sun8i_h3_thermal_init()
469 val = GENMASK(tmdev->chip->sensor_num - 1, 0); in sun8i_h3_thermal_init()
470 regmap_write(tmdev->regmap, SUN8I_THS_CTRL2, in sun8i_h3_thermal_init()
481 if (tmdev->sram_regmap_field) in sun50i_h6_thermal_init()
482 regmap_field_write(tmdev->sram_regmap_field, 0); in sun50i_h6_thermal_init()
498 regmap_write(tmdev->regmap, SUN50I_THS_CTRL0, in sun50i_h6_thermal_init()
502 regmap_write(tmdev->regmap, SUN50I_H6_THS_MFC, in sun50i_h6_thermal_init()
510 * x = period * clkin / 4096 / filter_samples - 1 in sun50i_h6_thermal_init()
513 regmap_write(tmdev->regmap, SUN50I_H6_THS_PC, in sun50i_h6_thermal_init()
516 val = GENMASK(tmdev->chip->sensor_num - 1, 0); in sun50i_h6_thermal_init()
517 regmap_write(tmdev->regmap, SUN50I_H6_THS_ENABLE, val); in sun50i_h6_thermal_init()
518 /* thermal data interrupt enable */ in sun50i_h6_thermal_init()
519 val = GENMASK(tmdev->chip->sensor_num - 1, 0); in sun50i_h6_thermal_init()
520 regmap_write(tmdev->regmap, SUN50I_H6_THS_DIC, val); in sun50i_h6_thermal_init()
529 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun8i_ths_register()
530 tmdev->sensor[i].tmdev = tmdev; in sun8i_ths_register()
531 tmdev->sensor[i].id = i; in sun8i_ths_register()
532 tmdev->sensor[i].tzd = in sun8i_ths_register()
533 devm_thermal_of_zone_register(tmdev->dev, in sun8i_ths_register()
535 &tmdev->sensor[i], in sun8i_ths_register()
543 if (IS_ERR(tmdev->sensor[i].tzd)) { in sun8i_ths_register()
544 if (PTR_ERR(tmdev->sensor[i].tzd) == -EPROBE_DEFER) in sun8i_ths_register()
545 return PTR_ERR(tmdev->sensor[i].tzd); in sun8i_ths_register()
549 devm_thermal_add_hwmon_sysfs(tmdev->dev, tmdev->sensor[i].tzd); in sun8i_ths_register()
558 struct device *dev = &pdev->dev; in sun8i_ths_probe()
563 return -ENOMEM; in sun8i_ths_probe()
565 tmdev->dev = dev; in sun8i_ths_probe()
566 tmdev->chip = of_device_get_match_data(&pdev->dev); in sun8i_ths_probe()
567 if (!tmdev->chip) in sun8i_ths_probe()
568 return -EINVAL; in sun8i_ths_probe()
578 ret = tmdev->chip->init(tmdev); in sun8i_ths_probe()
714 { .compatible = "allwinner,sun8i-a83t-ths", .data = &sun8i_a83t_ths },
715 { .compatible = "allwinner,sun8i-h3-ths", .data = &sun8i_h3_ths },
716 { .compatible = "allwinner,sun8i-r40-ths", .data = &sun8i_r40_ths },
717 { .compatible = "allwinner,sun50i-a64-ths", .data = &sun50i_a64_ths },
718 { .compatible = "allwinner,sun50i-a100-ths", .data = &sun50i_a100_ths },
719 { .compatible = "allwinner,sun50i-h5-ths", .data = &sun50i_h5_ths },
720 { .compatible = "allwinner,sun50i-h6-ths", .data = &sun50i_h6_ths },
721 { .compatible = "allwinner,sun20i-d1-ths", .data = &sun20i_d1_ths },
722 { .compatible = "allwinner,sun50i-h616-ths", .data = &sun50i_h616_ths },
730 .name = "sun8i-thermal",