Lines Matching refs:tmdev

62 	struct ths_device		*tmdev;  member
76 int (*calibrate)(struct ths_device *tmdev,
78 int (*init)(struct ths_device *tmdev);
79 unsigned long (*irq_ack)(struct ths_device *tmdev);
80 int (*calc_temp)(struct ths_device *tmdev,
99 static int sun8i_ths_calc_temp(struct ths_device *tmdev, in sun8i_ths_calc_temp() argument
102 return tmdev->chip->offset - (reg * tmdev->chip->scale / 10); in sun8i_ths_calc_temp()
105 static int sun50i_h5_calc_temp(struct ths_device *tmdev, in sun50i_h5_calc_temp() argument
119 struct ths_device *tmdev = s->tmdev; in sun8i_ths_get_temp() local
122 regmap_read(tmdev->regmap, tmdev->chip->temp_data_base + in sun8i_ths_get_temp()
129 *temp = tmdev->chip->calc_temp(tmdev, s->id, val); in sun8i_ths_get_temp()
138 *temp += tmdev->chip->ft_deviation; in sun8i_ths_get_temp()
155 static unsigned long sun8i_h3_irq_ack(struct ths_device *tmdev) in sun8i_h3_irq_ack() argument
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()
173 static unsigned long sun50i_h6_irq_ack(struct ths_device *tmdev) in sun50i_h6_irq_ack() argument
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()
193 struct ths_device *tmdev = data; in sun8i_irq_thread() local
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()
208 static int sun8i_h3_ths_calibrate(struct ths_device *tmdev, in sun8i_h3_ths_calibrate() argument
213 if (!caldata[0] || callen < 2 * tmdev->chip->sensor_num) 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()
228 static int sun50i_h6_ths_calibrate(struct ths_device *tmdev, in sun50i_h6_ths_calibrate() argument
231 struct device *dev = tmdev->dev; 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()
279 ((sensor_temp - ft_temp) * 10 / tmdev->chip->scale); in sun50i_h6_ths_calibrate()
292 regmap_update_bits(tmdev->regmap, in sun50i_h6_ths_calibrate()
301 static int sun8i_ths_calibrate(struct ths_device *tmdev) in sun8i_ths_calibrate() argument
304 struct device *dev = tmdev->dev; in sun8i_ths_calibrate()
335 tmdev->chip->calibrate(tmdev, caldata, callen); in sun8i_ths_calibrate()
377 static int sun8i_ths_resource_init(struct ths_device *tmdev) in sun8i_ths_resource_init() argument
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()
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()
434 ret = sun8i_ths_calibrate(tmdev); in sun8i_ths_resource_init()
441 static int sun8i_h3_thermal_init(struct ths_device *tmdev) in sun8i_h3_thermal_init() argument
446 regmap_write(tmdev->regmap, SUN8I_THS_MFC, 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()
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()
476 static int sun50i_h6_thermal_init(struct ths_device *tmdev) in sun50i_h6_thermal_init() argument
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()
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()
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()
525 static int sun8i_ths_register(struct ths_device *tmdev) in sun8i_ths_register() argument
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()
557 struct ths_device *tmdev; in sun8i_ths_probe() local
561 tmdev = devm_kzalloc(dev, sizeof(*tmdev), GFP_KERNEL); in sun8i_ths_probe()
562 if (!tmdev) 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()
570 ret = sun8i_ths_resource_init(tmdev); in sun8i_ths_probe()
578 ret = tmdev->chip->init(tmdev); in sun8i_ths_probe()
582 ret = sun8i_ths_register(tmdev); in sun8i_ths_probe()
593 IRQF_ONESHOT, "ths", tmdev); in sun8i_ths_probe()