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()
365 dev_info_once(ts->dev, "ch%u: PMC emergency shutdown trip set to %dC\n", in tegra_tsensor_enable_hw_channel()
368 hot_trip = tegra_tsensor_temp_to_counter(ts, hot_trip); in tegra_tsensor_enable_hw_channel()
369 crit_trip = tegra_tsensor_temp_to_counter(ts, crit_trip); in tegra_tsensor_enable_hw_channel()
411 dev_err(ts->dev, "ch%u: failed to enable zone: %d\n", id, err); in tegra_tsensor_enable_hw_channel()
427 static int tegra_tsensor_nvmem_setup(struct tegra_tsensor *ts) in tegra_tsensor_nvmem_setup() argument
434 dev_err_probe(ts->dev, err, "failed to get ATE version\n"); in tegra_tsensor_nvmem_setup()
439 dev_info(ts->dev, "unsupported ATE version: %u\n", ate_ver); in tegra_tsensor_nvmem_setup()
449 dev_info_once(ts->dev, in tegra_tsensor_nvmem_setup()
451 ts->swap_channels = true; in tegra_tsensor_nvmem_setup()
456 dev_err(ts->dev, "failed to get calibration data: %d\n", err); in tegra_tsensor_nvmem_setup()
474 dev_err(ts->dev, "invalid calibration data: %d %d %u %u\n", in tegra_tsensor_nvmem_setup()
481 ts->calib.a = DIV_ROUND_CLOSEST((t2_90C - t1_25C) * 1000000, in tegra_tsensor_nvmem_setup()
484 ts->calib.b = t1_25C * 1000000 - ts->calib.a * c1_25C; in tegra_tsensor_nvmem_setup()
487 ts->calib.m = -2775; in tegra_tsensor_nvmem_setup()
488 ts->calib.n = 1338811; in tegra_tsensor_nvmem_setup()
489 ts->calib.p = -7300000; in tegra_tsensor_nvmem_setup()
491 ts->calib.m = -3512; in tegra_tsensor_nvmem_setup()
492 ts->calib.n = 1528943; in tegra_tsensor_nvmem_setup()
493 ts->calib.p = -11100000; in tegra_tsensor_nvmem_setup()
497 ts->calib.r = DIV_ROUND_CLOSEST(ts->calib.n, ts->calib.m * 2); in tegra_tsensor_nvmem_setup()
499 dev_info_once(ts->dev, in tegra_tsensor_nvmem_setup()
507 static int tegra_tsensor_register_channel(struct tegra_tsensor *ts, in tegra_tsensor_register_channel() argument
510 struct tegra_tsensor_channel *tsc = &ts->ch[id]; in tegra_tsensor_register_channel()
511 unsigned int hw_id = ts->swap_channels ? !id : id; in tegra_tsensor_register_channel()
513 tsc->ts = ts; in tegra_tsensor_register_channel()
515 tsc->regs = ts->regs + 0x40 * (hw_id + 1); in tegra_tsensor_register_channel()
517 tsc->tzd = devm_thermal_of_zone_register(ts->dev, id, tsc, &ops); in tegra_tsensor_register_channel()
520 return dev_err_probe(ts->dev, PTR_ERR(tsc->tzd), in tegra_tsensor_register_channel()
532 dev_warn(ts->dev, "failed to add hwmon sysfs attributes\n"); in tegra_tsensor_register_channel()
539 struct tegra_tsensor *ts; in tegra_tsensor_probe() local
543 ts = devm_kzalloc(&pdev->dev, sizeof(*ts), GFP_KERNEL); in tegra_tsensor_probe()
544 if (!ts) in tegra_tsensor_probe()
551 ts->dev = &pdev->dev; in tegra_tsensor_probe()
552 platform_set_drvdata(pdev, ts); in tegra_tsensor_probe()
554 ts->regs = devm_platform_ioremap_resource(pdev, 0); in tegra_tsensor_probe()
555 if (IS_ERR(ts->regs)) in tegra_tsensor_probe()
556 return PTR_ERR(ts->regs); in tegra_tsensor_probe()
558 ts->clk = devm_clk_get(&pdev->dev, NULL); in tegra_tsensor_probe()
559 if (IS_ERR(ts->clk)) in tegra_tsensor_probe()
560 return dev_err_probe(&pdev->dev, PTR_ERR(ts->clk), in tegra_tsensor_probe()
563 ts->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL); in tegra_tsensor_probe()
564 if (IS_ERR(ts->rst)) in tegra_tsensor_probe()
565 return dev_err_probe(&pdev->dev, PTR_ERR(ts->rst), in tegra_tsensor_probe()
568 err = tegra_tsensor_nvmem_setup(ts); in tegra_tsensor_probe()
572 err = tegra_tsensor_hw_enable(ts); in tegra_tsensor_probe()
578 ts); in tegra_tsensor_probe()
582 for (i = 0; i < ARRAY_SIZE(ts->ch); i++) { in tegra_tsensor_probe()
583 err = tegra_tsensor_register_channel(ts, i); in tegra_tsensor_probe()
590 "tegra_tsensor", ts); in tegra_tsensor_probe()
595 for (i = 0; i < ARRAY_SIZE(ts->ch); i++) { in tegra_tsensor_probe()
596 err = tegra_tsensor_enable_hw_channel(ts, i); in tegra_tsensor_probe()
606 struct tegra_tsensor *ts = dev_get_drvdata(dev); in tegra_tsensor_suspend() local
610 for (i = 0; i < ARRAY_SIZE(ts->ch); i++) { in tegra_tsensor_suspend()
611 err = tegra_tsensor_disable_hw_channel(ts, i); in tegra_tsensor_suspend()
616 err = tegra_tsensor_hw_disable(ts); in tegra_tsensor_suspend()
624 tegra_tsensor_enable_hw_channel(ts, i); in tegra_tsensor_suspend()
631 struct tegra_tsensor *ts = dev_get_drvdata(dev); in tegra_tsensor_resume() local
635 err = tegra_tsensor_hw_enable(ts); in tegra_tsensor_resume()
639 for (i = 0; i < ARRAY_SIZE(ts->ch); i++) { in tegra_tsensor_resume()
640 err = tegra_tsensor_enable_hw_channel(ts, i); in tegra_tsensor_resume()