Lines Matching +full:sun8i +full:- +full:a83t +full:- +full:ths
1 // SPDX-License-Identifier: GPL-2.0
16 #include <linux/nvmem-consumer.h>
95 return tmdev->chip->offset - (reg * tmdev->chip->scale / 10); in sun8i_ths_calc_temp()
102 return -1191 * reg / 10 + 223000; in sun50i_h5_calc_temp()
104 return -1452 * reg / 10 + 259000; in sun50i_h5_calc_temp()
106 return -1590 * reg / 10 + 276000; in sun50i_h5_calc_temp()
112 struct ths_device *tmdev = s->tmdev; in sun8i_ths_get_temp()
115 regmap_read(tmdev->regmap, tmdev->chip->temp_data_base + in sun8i_ths_get_temp()
116 0x4 * s->id, &val); in sun8i_ths_get_temp()
118 /* ths have no data yet */ in sun8i_ths_get_temp()
120 return -EAGAIN; in sun8i_ths_get_temp()
122 *temp = tmdev->chip->calc_temp(tmdev, s->id, val); in sun8i_ths_get_temp()
131 *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()
171 regmap_read(tmdev->regmap, SUN50I_H6_THS_DIS, &state); in sun50i_h6_irq_ack()
173 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun50i_h6_irq_ack()
175 regmap_write(tmdev->regmap, SUN50I_H6_THS_DIS, in sun50i_h6_irq_ack()
187 unsigned long irq_bitmap = tmdev->chip->irq_ack(tmdev); in sun8i_irq_thread()
190 for_each_set_bit(i, &irq_bitmap, tmdev->chip->sensor_num) { in sun8i_irq_thread()
191 thermal_zone_device_update(tmdev->sensor[i].tzd, in sun8i_irq_thread()
203 if (!caldata[0] || callen < 2 * tmdev->chip->sensor_num) in sun8i_h3_ths_calibrate()
204 return -EINVAL; in sun8i_h3_ths_calibrate()
206 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun8i_h3_ths_calibrate()
209 regmap_update_bits(tmdev->regmap, in sun8i_h3_ths_calibrate()
221 struct device *dev = tmdev->dev; in sun50i_h6_ths_calibrate()
224 if (!caldata[0] || callen < 2 + 2 * tmdev->chip->sensor_num) in sun50i_h6_ths_calibrate()
225 return -EINVAL; in sun50i_h6_ths_calibrate()
231 * +-------+-------+-------+ in sun50i_h6_ths_calibrate()
233 * +-------+-------+-------+ in sun50i_h6_ths_calibrate()
245 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun50i_h6_ths_calibrate()
248 int sensor_temp = tmdev->chip->calc_temp(tmdev, i, sensor_reg); in sun50i_h6_ths_calibrate()
251 * Calibration data is CALIBRATE_DEFAULT - (calculated in sun50i_h6_ths_calibrate()
256 cdata = CALIBRATE_DEFAULT - in sun50i_h6_ths_calibrate()
257 ((sensor_temp - ft_temp) * 10 / tmdev->chip->scale); in sun50i_h6_ths_calibrate()
260 * Calibration value more than 12-bit, but calibration in sun50i_h6_ths_calibrate()
261 * register is 12-bit. In this case, ths hardware can in sun50i_h6_ths_calibrate()
270 regmap_update_bits(tmdev->regmap, in sun50i_h6_ths_calibrate()
282 struct device *dev = tmdev->dev; in sun8i_ths_calibrate()
289 if (PTR_ERR(calcell) == -EPROBE_DEFER) in sun8i_ths_calibrate()
290 return -EPROBE_DEFER; in sun8i_ths_calibrate()
293 * not accessible, the THS hardware can still work, although in sun8i_ths_calibrate()
313 tmdev->chip->calibrate(tmdev, caldata, callen); in sun8i_ths_calibrate()
329 struct device *dev = tmdev->dev; in sun8i_ths_resource_init()
338 tmdev->regmap = devm_regmap_init_mmio(dev, base, &config); in sun8i_ths_resource_init()
339 if (IS_ERR(tmdev->regmap)) in sun8i_ths_resource_init()
340 return PTR_ERR(tmdev->regmap); in sun8i_ths_resource_init()
342 if (tmdev->chip->has_bus_clk_reset) { in sun8i_ths_resource_init()
343 tmdev->reset = devm_reset_control_get(dev, NULL); in sun8i_ths_resource_init()
344 if (IS_ERR(tmdev->reset)) in sun8i_ths_resource_init()
345 return PTR_ERR(tmdev->reset); in sun8i_ths_resource_init()
347 ret = reset_control_deassert(tmdev->reset); in sun8i_ths_resource_init()
352 tmdev->reset); in sun8i_ths_resource_init()
356 tmdev->bus_clk = devm_clk_get_enabled(&pdev->dev, "bus"); in sun8i_ths_resource_init()
357 if (IS_ERR(tmdev->bus_clk)) in sun8i_ths_resource_init()
358 return PTR_ERR(tmdev->bus_clk); in sun8i_ths_resource_init()
361 if (tmdev->chip->has_mod_clk) { in sun8i_ths_resource_init()
362 tmdev->mod_clk = devm_clk_get_enabled(&pdev->dev, "mod"); in sun8i_ths_resource_init()
363 if (IS_ERR(tmdev->mod_clk)) in sun8i_ths_resource_init()
364 return PTR_ERR(tmdev->mod_clk); in sun8i_ths_resource_init()
367 ret = clk_set_rate(tmdev->mod_clk, 24000000); in sun8i_ths_resource_init()
383 regmap_write(tmdev->regmap, SUN8I_THS_MFC, in sun8i_h3_thermal_init()
391 * x = period * clkin / 4096 / filter_samples - 1 in sun8i_h3_thermal_init()
394 val = GENMASK(7 + tmdev->chip->sensor_num, 8); in sun8i_h3_thermal_init()
395 regmap_write(tmdev->regmap, SUN8I_THS_IC, in sun8i_h3_thermal_init()
401 * x = T_acq * clkin - 1 in sun8i_h3_thermal_init()
404 regmap_write(tmdev->regmap, SUN8I_THS_CTRL0, in sun8i_h3_thermal_init()
406 val = GENMASK(tmdev->chip->sensor_num - 1, 0); in sun8i_h3_thermal_init()
407 regmap_write(tmdev->regmap, SUN8I_THS_CTRL2, in sun8i_h3_thermal_init()
427 * x = T_acq * clkin - 1 in sun50i_h6_thermal_init()
430 regmap_write(tmdev->regmap, SUN50I_THS_CTRL0, in sun50i_h6_thermal_init()
433 regmap_write(tmdev->regmap, SUN50I_H6_THS_MFC, in sun50i_h6_thermal_init()
441 * x = period * clkin / 4096 / filter_samples - 1 in sun50i_h6_thermal_init()
444 regmap_write(tmdev->regmap, SUN50I_H6_THS_PC, in sun50i_h6_thermal_init()
447 val = GENMASK(tmdev->chip->sensor_num - 1, 0); in sun50i_h6_thermal_init()
448 regmap_write(tmdev->regmap, SUN50I_H6_THS_ENABLE, val); in sun50i_h6_thermal_init()
450 val = GENMASK(tmdev->chip->sensor_num - 1, 0); in sun50i_h6_thermal_init()
451 regmap_write(tmdev->regmap, SUN50I_H6_THS_DIC, val); in sun50i_h6_thermal_init()
460 for (i = 0; i < tmdev->chip->sensor_num; i++) { in sun8i_ths_register()
461 tmdev->sensor[i].tmdev = tmdev; in sun8i_ths_register()
462 tmdev->sensor[i].id = i; in sun8i_ths_register()
463 tmdev->sensor[i].tzd = in sun8i_ths_register()
464 devm_thermal_of_zone_register(tmdev->dev, in sun8i_ths_register()
466 &tmdev->sensor[i], in sun8i_ths_register()
468 if (IS_ERR(tmdev->sensor[i].tzd)) in sun8i_ths_register()
469 return PTR_ERR(tmdev->sensor[i].tzd); in sun8i_ths_register()
471 devm_thermal_add_hwmon_sysfs(tmdev->dev, tmdev->sensor[i].tzd); in sun8i_ths_register()
480 struct device *dev = &pdev->dev; in sun8i_ths_probe()
485 return -ENOMEM; in sun8i_ths_probe()
487 tmdev->dev = dev; in sun8i_ths_probe()
488 tmdev->chip = of_device_get_match_data(&pdev->dev); in sun8i_ths_probe()
489 if (!tmdev->chip) in sun8i_ths_probe()
490 return -EINVAL; in sun8i_ths_probe()
500 ret = tmdev->chip->init(tmdev); in sun8i_ths_probe()
515 IRQF_ONESHOT, "ths", tmdev); in sun8i_ths_probe()
610 { .compatible = "allwinner,sun8i-a83t-ths", .data = &sun8i_a83t_ths },
611 { .compatible = "allwinner,sun8i-h3-ths", .data = &sun8i_h3_ths },
612 { .compatible = "allwinner,sun8i-r40-ths", .data = &sun8i_r40_ths },
613 { .compatible = "allwinner,sun50i-a64-ths", .data = &sun50i_a64_ths },
614 { .compatible = "allwinner,sun50i-a100-ths", .data = &sun50i_a100_ths },
615 { .compatible = "allwinner,sun50i-h5-ths", .data = &sun50i_h5_ths },
616 { .compatible = "allwinner,sun50i-h6-ths", .data = &sun50i_h6_ths },
624 .name = "sun8i-thermal",