Lines Matching refs:ts
77 struct tegra_tsensor *ts; member
91 static int tegra_tsensor_hw_enable(const struct tegra_tsensor *ts) in tegra_tsensor_hw_enable() argument
96 err = reset_control_assert(ts->rst); in tegra_tsensor_hw_enable()
98 dev_err(ts->dev, "failed to assert hardware reset: %d\n", err); in tegra_tsensor_hw_enable()
102 err = clk_prepare_enable(ts->clk); in tegra_tsensor_hw_enable()
104 dev_err(ts->dev, "failed to enable clock: %d\n", err); in tegra_tsensor_hw_enable()
110 err = reset_control_deassert(ts->rst); in tegra_tsensor_hw_enable()
112 dev_err(ts->dev, "failed to deassert hardware reset: %d\n", err); in tegra_tsensor_hw_enable()
129 writel_relaxed(val, ts->regs + 0x40 + TSENSOR_SENSOR0_CONFIG0); in tegra_tsensor_hw_enable()
130 writel_relaxed(val, ts->regs + 0x80 + TSENSOR_SENSOR0_CONFIG0); in tegra_tsensor_hw_enable()
135 clk_disable_unprepare(ts->clk); in tegra_tsensor_hw_enable()
140 static int tegra_tsensor_hw_disable(const struct tegra_tsensor *ts) in tegra_tsensor_hw_disable() argument
144 err = reset_control_assert(ts->rst); in tegra_tsensor_hw_disable()
146 dev_err(ts->dev, "failed to assert hardware reset: %d\n", err); in tegra_tsensor_hw_disable()
150 clk_disable_unprepare(ts->clk); in tegra_tsensor_hw_disable()
157 const struct tegra_tsensor *ts = data; in devm_tegra_tsensor_hw_disable() local
159 tegra_tsensor_hw_disable(ts); in devm_tegra_tsensor_hw_disable()
165 const struct tegra_tsensor *ts = tsc->ts; in tegra_tsensor_get_temp() local
178 dev_err_once(ts->dev, "ch%u: counter invalid\n", tsc->id); in tegra_tsensor_get_temp()
191 dev_err_once(ts->dev, "ch%u: counter overflow\n", tsc->id); in tegra_tsensor_get_temp()
199 c1 = DIV_ROUND_CLOSEST(ts->calib.a * counter + ts->calib.b, 1000000); in tegra_tsensor_get_temp()
201 c2 = DIV_ROUND_CLOSEST(ts->calib.p, c1); in tegra_tsensor_get_temp()
202 c3 = c1 * ts->calib.m; in tegra_tsensor_get_temp()
203 c4 = ts->calib.n; in tegra_tsensor_get_temp()
210 static int tegra_tsensor_temp_to_counter(const struct tegra_tsensor *ts, int temp) in tegra_tsensor_temp_to_counter() argument
214 c1 = DIV_ROUND_CLOSEST(ts->calib.p - temp * 1000, ts->calib.m); in tegra_tsensor_temp_to_counter()
215 c2 = -ts->calib.r - int_sqrt(ts->calib.r * ts->calib.r - c1); in tegra_tsensor_temp_to_counter()
217 return DIV_ROUND_CLOSEST(c2 * 1000000 - ts->calib.b, ts->calib.a); in tegra_tsensor_temp_to_counter()
223 const struct tegra_tsensor *ts = tsc->ts; in tegra_tsensor_set_trips() local
236 high = tegra_tsensor_temp_to_counter(ts, high); in tegra_tsensor_set_trips()
249 tegra_tsensor_handle_channel_interrupt(const struct tegra_tsensor *ts, in tegra_tsensor_handle_channel_interrupt() argument
252 const struct tegra_tsensor_channel *tsc = &ts->ch[id]; in tegra_tsensor_handle_channel_interrupt()
259 dev_err_ratelimited(ts->dev, "ch%u: counter overflowed\n", id); in tegra_tsensor_handle_channel_interrupt()
271 const struct tegra_tsensor *ts = data; in tegra_tsensor_isr() local
275 for (i = 0; i < ARRAY_SIZE(ts->ch); i++) in tegra_tsensor_isr()
276 handled |= tegra_tsensor_handle_channel_interrupt(ts, i); in tegra_tsensor_isr()
281 static int tegra_tsensor_disable_hw_channel(const struct tegra_tsensor *ts, in tegra_tsensor_disable_hw_channel() argument
284 const struct tegra_tsensor_channel *tsc = &ts->ch[id]; in tegra_tsensor_disable_hw_channel()
294 dev_err(ts->dev, "ch%u: failed to disable zone: %d\n", id, err); in tegra_tsensor_disable_hw_channel()
346 static int tegra_tsensor_enable_hw_channel(const struct tegra_tsensor *ts, in tegra_tsensor_enable_hw_channel() argument
349 const struct tegra_tsensor_channel *tsc = &ts->ch[id]; in tegra_tsensor_enable_hw_channel()
367 dev_info_once(ts->dev, "ch%u: PMC emergency shutdown trip set to %dC\n", in tegra_tsensor_enable_hw_channel()
370 hot_trip = tegra_tsensor_temp_to_counter(ts, hot_trip); in tegra_tsensor_enable_hw_channel()
371 crit_trip = tegra_tsensor_temp_to_counter(ts, crit_trip); in tegra_tsensor_enable_hw_channel()
413 dev_err(ts->dev, "ch%u: failed to enable zone: %d\n", id, err); in tegra_tsensor_enable_hw_channel()
429 static int tegra_tsensor_nvmem_setup(struct tegra_tsensor *ts) in tegra_tsensor_nvmem_setup() argument
436 dev_err_probe(ts->dev, err, "failed to get ATE version\n"); in tegra_tsensor_nvmem_setup()
441 dev_info(ts->dev, "unsupported ATE version: %u\n", ate_ver); in tegra_tsensor_nvmem_setup()
451 dev_info_once(ts->dev, in tegra_tsensor_nvmem_setup()
453 ts->swap_channels = true; in tegra_tsensor_nvmem_setup()
458 dev_err(ts->dev, "failed to get calibration data: %d\n", err); in tegra_tsensor_nvmem_setup()
476 dev_err(ts->dev, "invalid calibration data: %d %d %u %u\n", in tegra_tsensor_nvmem_setup()
483 ts->calib.a = DIV_ROUND_CLOSEST((t2_90C - t1_25C) * 1000000, in tegra_tsensor_nvmem_setup()
486 ts->calib.b = t1_25C * 1000000 - ts->calib.a * c1_25C; in tegra_tsensor_nvmem_setup()
489 ts->calib.m = -2775; in tegra_tsensor_nvmem_setup()
490 ts->calib.n = 1338811; in tegra_tsensor_nvmem_setup()
491 ts->calib.p = -7300000; in tegra_tsensor_nvmem_setup()
493 ts->calib.m = -3512; in tegra_tsensor_nvmem_setup()
494 ts->calib.n = 1528943; in tegra_tsensor_nvmem_setup()
495 ts->calib.p = -11100000; in tegra_tsensor_nvmem_setup()
499 ts->calib.r = DIV_ROUND_CLOSEST(ts->calib.n, ts->calib.m * 2); in tegra_tsensor_nvmem_setup()
501 dev_info_once(ts->dev, in tegra_tsensor_nvmem_setup()
509 static int tegra_tsensor_register_channel(struct tegra_tsensor *ts, in tegra_tsensor_register_channel() argument
512 struct tegra_tsensor_channel *tsc = &ts->ch[id]; in tegra_tsensor_register_channel()
513 unsigned int hw_id = ts->swap_channels ? !id : id; in tegra_tsensor_register_channel()
515 tsc->ts = ts; in tegra_tsensor_register_channel()
517 tsc->regs = ts->regs + 0x40 * (hw_id + 1); in tegra_tsensor_register_channel()
519 tsc->tzd = devm_thermal_zone_of_sensor_register(ts->dev, id, tsc, &ops); in tegra_tsensor_register_channel()
522 return dev_err_probe(ts->dev, PTR_ERR(tsc->tzd), in tegra_tsensor_register_channel()
534 dev_warn(ts->dev, "failed to add hwmon sysfs attributes\n"); in tegra_tsensor_register_channel()
541 struct tegra_tsensor *ts; in tegra_tsensor_probe() local
545 ts = devm_kzalloc(&pdev->dev, sizeof(*ts), GFP_KERNEL); in tegra_tsensor_probe()
546 if (!ts) in tegra_tsensor_probe()
553 ts->dev = &pdev->dev; in tegra_tsensor_probe()
554 platform_set_drvdata(pdev, ts); in tegra_tsensor_probe()
556 ts->regs = devm_platform_ioremap_resource(pdev, 0); in tegra_tsensor_probe()
557 if (IS_ERR(ts->regs)) in tegra_tsensor_probe()
558 return PTR_ERR(ts->regs); in tegra_tsensor_probe()
560 ts->clk = devm_clk_get(&pdev->dev, NULL); in tegra_tsensor_probe()
561 if (IS_ERR(ts->clk)) in tegra_tsensor_probe()
562 return dev_err_probe(&pdev->dev, PTR_ERR(ts->clk), in tegra_tsensor_probe()
565 ts->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL); in tegra_tsensor_probe()
566 if (IS_ERR(ts->rst)) in tegra_tsensor_probe()
567 return dev_err_probe(&pdev->dev, PTR_ERR(ts->rst), in tegra_tsensor_probe()
570 err = tegra_tsensor_nvmem_setup(ts); in tegra_tsensor_probe()
574 err = tegra_tsensor_hw_enable(ts); in tegra_tsensor_probe()
580 ts); in tegra_tsensor_probe()
584 for (i = 0; i < ARRAY_SIZE(ts->ch); i++) { in tegra_tsensor_probe()
585 err = tegra_tsensor_register_channel(ts, i); in tegra_tsensor_probe()
592 "tegra_tsensor", ts); in tegra_tsensor_probe()
597 for (i = 0; i < ARRAY_SIZE(ts->ch); i++) { in tegra_tsensor_probe()
598 err = tegra_tsensor_enable_hw_channel(ts, i); 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()