Lines Matching refs:ts
76 struct tegra_tsensor *ts; member
90 static int tegra_tsensor_hw_enable(const struct tegra_tsensor *ts) in tegra_tsensor_hw_enable() argument
95 err = reset_control_assert(ts->rst); in tegra_tsensor_hw_enable()
97 dev_err(ts->dev, "failed to assert hardware reset: %d\n", err); in tegra_tsensor_hw_enable()
101 err = clk_prepare_enable(ts->clk); in tegra_tsensor_hw_enable()
103 dev_err(ts->dev, "failed to enable clock: %d\n", err); in tegra_tsensor_hw_enable()
109 err = reset_control_deassert(ts->rst); in tegra_tsensor_hw_enable()
111 dev_err(ts->dev, "failed to deassert hardware reset: %d\n", err); in tegra_tsensor_hw_enable()
128 writel_relaxed(val, ts->regs + 0x40 + TSENSOR_SENSOR0_CONFIG0); in tegra_tsensor_hw_enable()
129 writel_relaxed(val, ts->regs + 0x80 + TSENSOR_SENSOR0_CONFIG0); in tegra_tsensor_hw_enable()
134 clk_disable_unprepare(ts->clk); in tegra_tsensor_hw_enable()
139 static int tegra_tsensor_hw_disable(const struct tegra_tsensor *ts) in tegra_tsensor_hw_disable() argument
143 err = reset_control_assert(ts->rst); in tegra_tsensor_hw_disable()
145 dev_err(ts->dev, "failed to assert hardware reset: %d\n", err); in tegra_tsensor_hw_disable()
149 clk_disable_unprepare(ts->clk); in tegra_tsensor_hw_disable()
156 const struct tegra_tsensor *ts = data; in devm_tegra_tsensor_hw_disable() local
158 tegra_tsensor_hw_disable(ts); in devm_tegra_tsensor_hw_disable()
164 const struct tegra_tsensor *ts = tsc->ts; in tegra_tsensor_get_temp() local
177 dev_err_once(ts->dev, "ch%u: counter invalid\n", tsc->id); in tegra_tsensor_get_temp()
190 dev_err_once(ts->dev, "ch%u: counter overflow\n", tsc->id); in tegra_tsensor_get_temp()
198 c1 = DIV_ROUND_CLOSEST(ts->calib.a * counter + ts->calib.b, 1000000); in tegra_tsensor_get_temp()
200 c2 = DIV_ROUND_CLOSEST(ts->calib.p, c1); in tegra_tsensor_get_temp()
201 c3 = c1 * ts->calib.m; in tegra_tsensor_get_temp()
202 c4 = ts->calib.n; in tegra_tsensor_get_temp()
209 static int tegra_tsensor_temp_to_counter(const struct tegra_tsensor *ts, int temp) in tegra_tsensor_temp_to_counter() argument
213 c1 = DIV_ROUND_CLOSEST(ts->calib.p - temp * 1000, ts->calib.m); in tegra_tsensor_temp_to_counter()
214 c2 = -ts->calib.r - int_sqrt(ts->calib.r * ts->calib.r - c1); in tegra_tsensor_temp_to_counter()
216 return DIV_ROUND_CLOSEST(c2 * 1000000 - ts->calib.b, ts->calib.a); in tegra_tsensor_temp_to_counter()
222 const struct tegra_tsensor *ts = tsc->ts; in tegra_tsensor_set_trips() local
235 high = tegra_tsensor_temp_to_counter(ts, high); in tegra_tsensor_set_trips()
248 tegra_tsensor_handle_channel_interrupt(const struct tegra_tsensor *ts, in tegra_tsensor_handle_channel_interrupt() argument
251 const struct tegra_tsensor_channel *tsc = &ts->ch[id]; in tegra_tsensor_handle_channel_interrupt()
258 dev_err_ratelimited(ts->dev, "ch%u: counter overflowed\n", id); in tegra_tsensor_handle_channel_interrupt()
270 const struct tegra_tsensor *ts = data; in tegra_tsensor_isr() local
274 for (i = 0; i < ARRAY_SIZE(ts->ch); i++) in tegra_tsensor_isr()
275 handled |= tegra_tsensor_handle_channel_interrupt(ts, i); in tegra_tsensor_isr()
280 static int tegra_tsensor_disable_hw_channel(const struct tegra_tsensor *ts, in tegra_tsensor_disable_hw_channel() argument
283 const struct tegra_tsensor_channel *tsc = &ts->ch[id]; in tegra_tsensor_disable_hw_channel()
293 dev_err(ts->dev, "ch%u: failed to disable zone: %d\n", id, err); in tegra_tsensor_disable_hw_channel()
344 static int tegra_tsensor_enable_hw_channel(const struct tegra_tsensor *ts, in tegra_tsensor_enable_hw_channel() argument
347 const struct tegra_tsensor_channel *tsc = &ts->ch[id]; in tegra_tsensor_enable_hw_channel()
362 dev_info_once(ts->dev, "ch%u: PMC emergency shutdown trip set to %dC\n", in tegra_tsensor_enable_hw_channel()
365 hot_trip = tegra_tsensor_temp_to_counter(ts, hot_trip); in tegra_tsensor_enable_hw_channel()
366 crit_trip = tegra_tsensor_temp_to_counter(ts, crit_trip); in tegra_tsensor_enable_hw_channel()
406 dev_err(ts->dev, "ch%u: failed to enable zone: %d\n", id, err); in tegra_tsensor_enable_hw_channel()
422 static int tegra_tsensor_nvmem_setup(struct tegra_tsensor *ts) in tegra_tsensor_nvmem_setup() argument
429 dev_err_probe(ts->dev, err, "failed to get ATE version\n"); in tegra_tsensor_nvmem_setup()
434 dev_info(ts->dev, "unsupported ATE version: %u\n", ate_ver); in tegra_tsensor_nvmem_setup()
444 dev_info_once(ts->dev, in tegra_tsensor_nvmem_setup()
446 ts->swap_channels = true; in tegra_tsensor_nvmem_setup()
451 dev_err(ts->dev, "failed to get calibration data: %d\n", err); in tegra_tsensor_nvmem_setup()
469 dev_err(ts->dev, "invalid calibration data: %d %d %u %u\n", in tegra_tsensor_nvmem_setup()
476 ts->calib.a = DIV_ROUND_CLOSEST((t2_90C - t1_25C) * 1000000, in tegra_tsensor_nvmem_setup()
479 ts->calib.b = t1_25C * 1000000 - ts->calib.a * c1_25C; in tegra_tsensor_nvmem_setup()
482 ts->calib.m = -2775; in tegra_tsensor_nvmem_setup()
483 ts->calib.n = 1338811; in tegra_tsensor_nvmem_setup()
484 ts->calib.p = -7300000; in tegra_tsensor_nvmem_setup()
486 ts->calib.m = -3512; in tegra_tsensor_nvmem_setup()
487 ts->calib.n = 1528943; in tegra_tsensor_nvmem_setup()
488 ts->calib.p = -11100000; in tegra_tsensor_nvmem_setup()
492 ts->calib.r = DIV_ROUND_CLOSEST(ts->calib.n, ts->calib.m * 2); in tegra_tsensor_nvmem_setup()
494 dev_info_once(ts->dev, in tegra_tsensor_nvmem_setup()
502 static int tegra_tsensor_register_channel(struct tegra_tsensor *ts, in tegra_tsensor_register_channel() argument
505 struct tegra_tsensor_channel *tsc = &ts->ch[id]; in tegra_tsensor_register_channel()
506 unsigned int hw_id = ts->swap_channels ? !id : id; in tegra_tsensor_register_channel()
508 tsc->ts = ts; in tegra_tsensor_register_channel()
510 tsc->regs = ts->regs + 0x40 * (hw_id + 1); in tegra_tsensor_register_channel()
512 tsc->tzd = devm_thermal_of_zone_register(ts->dev, id, tsc, &ops); in tegra_tsensor_register_channel()
515 return dev_err_probe(ts->dev, PTR_ERR(tsc->tzd), in tegra_tsensor_register_channel()
526 devm_thermal_add_hwmon_sysfs(ts->dev, tsc->tzd); in tegra_tsensor_register_channel()
533 struct tegra_tsensor *ts; in tegra_tsensor_probe() local
537 ts = devm_kzalloc(&pdev->dev, sizeof(*ts), GFP_KERNEL); in tegra_tsensor_probe()
538 if (!ts) in tegra_tsensor_probe()
545 ts->dev = &pdev->dev; in tegra_tsensor_probe()
546 platform_set_drvdata(pdev, ts); in tegra_tsensor_probe()
548 ts->regs = devm_platform_ioremap_resource(pdev, 0); in tegra_tsensor_probe()
549 if (IS_ERR(ts->regs)) in tegra_tsensor_probe()
550 return PTR_ERR(ts->regs); in tegra_tsensor_probe()
552 ts->clk = devm_clk_get(&pdev->dev, NULL); in tegra_tsensor_probe()
553 if (IS_ERR(ts->clk)) in tegra_tsensor_probe()
554 return dev_err_probe(&pdev->dev, PTR_ERR(ts->clk), in tegra_tsensor_probe()
557 ts->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL); in tegra_tsensor_probe()
558 if (IS_ERR(ts->rst)) in tegra_tsensor_probe()
559 return dev_err_probe(&pdev->dev, PTR_ERR(ts->rst), in tegra_tsensor_probe()
562 err = tegra_tsensor_nvmem_setup(ts); in tegra_tsensor_probe()
566 err = tegra_tsensor_hw_enable(ts); in tegra_tsensor_probe()
572 ts); in tegra_tsensor_probe()
576 for (i = 0; i < ARRAY_SIZE(ts->ch); i++) { in tegra_tsensor_probe()
577 err = tegra_tsensor_register_channel(ts, i); in tegra_tsensor_probe()
590 for (i = 0; i < ARRAY_SIZE(ts->ch); i++) { in tegra_tsensor_probe()
591 err = tegra_tsensor_enable_hw_channel(ts, i); in tegra_tsensor_probe()
598 "tegra_tsensor", ts); in tegra_tsensor_probe()
608 struct tegra_tsensor *ts = dev_get_drvdata(dev); in tegra_tsensor_suspend() local
612 for (i = 0; i < ARRAY_SIZE(ts->ch); i++) { in tegra_tsensor_suspend()
613 err = tegra_tsensor_disable_hw_channel(ts, i); in tegra_tsensor_suspend()
618 err = tegra_tsensor_hw_disable(ts); in tegra_tsensor_suspend()
626 tegra_tsensor_enable_hw_channel(ts, i); in tegra_tsensor_suspend()
633 struct tegra_tsensor *ts = dev_get_drvdata(dev); in tegra_tsensor_resume() local
637 err = tegra_tsensor_hw_enable(ts); in tegra_tsensor_resume()
641 for (i = 0; i < ARRAY_SIZE(ts->ch); i++) { in tegra_tsensor_resume()
642 err = tegra_tsensor_enable_hw_channel(ts, i); in tegra_tsensor_resume()