summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gp106/therm_gp106.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/gp106/therm_gp106.c')
-rw-r--r--drivers/gpu/nvgpu/gp106/therm_gp106.c141
1 files changed, 141 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/gp106/therm_gp106.c b/drivers/gpu/nvgpu/gp106/therm_gp106.c
new file mode 100644
index 00000000..ab5563cc
--- /dev/null
+++ b/drivers/gpu/nvgpu/gp106/therm_gp106.c
@@ -0,0 +1,141 @@
1/*
2 * Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23#include "gk20a/gk20a.h"
24
25#include "therm_gp106.h"
26#include "therm/thrmpmu.h"
27
28#ifdef CONFIG_DEBUG_FS
29#include <linux/debugfs.h>
30#include "common/linux/os_linux.h"
31#endif
32
33#include <nvgpu/hw/gp106/hw_therm_gp106.h>
34
35void gp106_get_internal_sensor_limits(s32 *max_24_8, s32 *min_24_8)
36{
37 *max_24_8 = (0x87 << 8);
38 *min_24_8 = ((-216) << 8);
39}
40
41int gp106_get_internal_sensor_curr_temp(struct gk20a *g, u32 *temp_f24_8)
42{
43 int err = 0;
44 u32 readval;
45
46 readval = gk20a_readl(g, therm_temp_sensor_tsense_r());
47
48 if (!(therm_temp_sensor_tsense_state_v(readval) &
49 therm_temp_sensor_tsense_state_valid_v())) {
50 nvgpu_err(g,
51 "Attempt to read temperature while sensor is OFF!");
52 err = -EINVAL;
53 } else if (therm_temp_sensor_tsense_state_v(readval) &
54 therm_temp_sensor_tsense_state_shadow_v()) {
55 nvgpu_err(g, "Reading temperature from SHADOWed sensor!");
56 }
57
58 // Convert from F9.5 -> F27.5 -> F24.8.
59 readval &= therm_temp_sensor_tsense_fixed_point_m();
60
61 *temp_f24_8 = readval;
62
63 return err;
64}
65
66#ifdef CONFIG_DEBUG_FS
67static int therm_get_internal_sensor_curr_temp(void *data, u64 *val)
68{
69 struct gk20a *g = (struct gk20a *)data;
70 u32 readval;
71 int err;
72
73 err = gp106_get_internal_sensor_curr_temp(g, &readval);
74 if (!err)
75 *val = readval;
76
77 return err;
78}
79DEFINE_SIMPLE_ATTRIBUTE(therm_ctrl_fops, therm_get_internal_sensor_curr_temp, NULL, "%llu\n");
80
81void gp106_therm_debugfs_init(struct gk20a *g)
82{
83 struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g);
84 struct dentry *dbgentry;
85
86 dbgentry = debugfs_create_file(
87 "temp", S_IRUGO, l->debugfs, g, &therm_ctrl_fops);
88 if (!dbgentry)
89 nvgpu_err(g, "debugfs entry create failed for therm_curr_temp");
90}
91#endif
92
93int gp106_elcg_init_idle_filters(struct gk20a *g)
94{
95 u32 gate_ctrl, idle_filter;
96 u32 engine_id;
97 u32 active_engine_id = 0;
98 struct fifo_gk20a *f = &g->fifo;
99
100 gk20a_dbg_fn("");
101
102 for (engine_id = 0; engine_id < f->num_engines; engine_id++) {
103 active_engine_id = f->active_engines_list[engine_id];
104 gate_ctrl = gk20a_readl(g, therm_gate_ctrl_r(active_engine_id));
105
106 gate_ctrl = set_field(gate_ctrl,
107 therm_gate_ctrl_eng_idle_filt_exp_m(),
108 therm_gate_ctrl_eng_idle_filt_exp_f(2));
109 gate_ctrl = set_field(gate_ctrl,
110 therm_gate_ctrl_eng_idle_filt_mant_m(),
111 therm_gate_ctrl_eng_idle_filt_mant_f(1));
112 gate_ctrl = set_field(gate_ctrl,
113 therm_gate_ctrl_eng_delay_before_m(),
114 therm_gate_ctrl_eng_delay_before_f(0));
115 gk20a_writel(g, therm_gate_ctrl_r(active_engine_id), gate_ctrl);
116 }
117
118 /* default fecs_idle_filter to 0 */
119 idle_filter = gk20a_readl(g, therm_fecs_idle_filter_r());
120 idle_filter &= ~therm_fecs_idle_filter_value_m();
121 gk20a_writel(g, therm_fecs_idle_filter_r(), idle_filter);
122 /* default hubmmu_idle_filter to 0 */
123 idle_filter = gk20a_readl(g, therm_hubmmu_idle_filter_r());
124 idle_filter &= ~therm_hubmmu_idle_filter_value_m();
125 gk20a_writel(g, therm_hubmmu_idle_filter_r(), idle_filter);
126
127 gk20a_dbg_fn("done");
128 return 0;
129}
130
131u32 gp106_configure_therm_alert(struct gk20a *g, s32 curr_warn_temp)
132{
133 u32 err = 0;
134
135 if (g->curr_warn_temp != curr_warn_temp) {
136 g->curr_warn_temp = curr_warn_temp;
137 err = therm_configure_therm_alert(g);
138 }
139
140 return err;
141}