diff options
Diffstat (limited to 'drivers/gpu/nvgpu/gv100/clk_gv100.c')
-rw-r--r-- | drivers/gpu/nvgpu/gv100/clk_gv100.c | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/gv100/clk_gv100.c b/drivers/gpu/nvgpu/gv100/clk_gv100.c new file mode 100644 index 00000000..7855aa41 --- /dev/null +++ b/drivers/gpu/nvgpu/gv100/clk_gv100.c | |||
@@ -0,0 +1,193 @@ | |||
1 | /* | ||
2 | * GV100 Clocks | ||
3 | * | ||
4 | * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved. | ||
5 | * | ||
6 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
7 | * copy of this software and associated documentation files (the "Software"), | ||
8 | * to deal in the Software without restriction, including without limitation | ||
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
10 | * and/or sell copies of the Software, and to permit persons to whom the | ||
11 | * Software is furnished to do so, subject to the following conditions: | ||
12 | * | ||
13 | * The above copyright notice and this permission notice shall be included in | ||
14 | * all copies or substantial portions of the Software. | ||
15 | * | ||
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
22 | * DEALINGS IN THE SOFTWARE. | ||
23 | */ | ||
24 | |||
25 | #ifdef CONFIG_DEBUG_FS | ||
26 | #include <linux/debugfs.h> | ||
27 | #include "os/linux/os_linux.h" | ||
28 | #endif | ||
29 | |||
30 | #include <nvgpu/kmem.h> | ||
31 | #include <nvgpu/io.h> | ||
32 | #include <nvgpu/list.h> | ||
33 | #include <nvgpu/clk_arb.h> | ||
34 | #include <nvgpu/timers.h> | ||
35 | |||
36 | #include "gk20a/gk20a.h" | ||
37 | |||
38 | #include "clk_gv100.h" | ||
39 | |||
40 | #include <nvgpu/hw/gv100/hw_trim_gv100.h> | ||
41 | |||
42 | |||
43 | u32 gv100_crystal_clk_hz(struct gk20a *g) | ||
44 | { | ||
45 | return (XTAL4X_KHZ * 1000); | ||
46 | } | ||
47 | |||
48 | unsigned long gv100_clk_measure_freq(struct gk20a *g, u32 api_domain) | ||
49 | { | ||
50 | struct clk_gk20a *clk = &g->clk; | ||
51 | u32 freq_khz; | ||
52 | u32 i; | ||
53 | struct namemap_cfg *c = NULL; | ||
54 | |||
55 | for (i = 0; i < clk->namemap_num; i++) { | ||
56 | if (api_domain == clk->namemap_xlat_table[i]) { | ||
57 | c = &clk->clk_namemap[i]; | ||
58 | break; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | if (c == NULL) { | ||
63 | return 0; | ||
64 | } | ||
65 | if (c->is_counter != 0U) { | ||
66 | freq_khz = c->scale * gv100_get_rate_cntr(g, c); | ||
67 | } else { | ||
68 | freq_khz = 0U; | ||
69 | /* TODO: PLL read */ | ||
70 | } | ||
71 | |||
72 | /* Convert to HZ */ | ||
73 | return freq_khz * 1000UL; | ||
74 | } | ||
75 | |||
76 | int gv100_init_clk_support(struct gk20a *g) | ||
77 | { | ||
78 | struct clk_gk20a *clk = &g->clk; | ||
79 | int err = 0; | ||
80 | |||
81 | nvgpu_log_fn(g, " "); | ||
82 | |||
83 | err = nvgpu_mutex_init(&clk->clk_mutex); | ||
84 | if (err != 0) { | ||
85 | return err; | ||
86 | } | ||
87 | |||
88 | clk->clk_namemap = (struct namemap_cfg *) | ||
89 | nvgpu_kzalloc(g, sizeof(struct namemap_cfg) * NUM_NAMEMAPS); | ||
90 | |||
91 | if (clk->clk_namemap == NULL) { | ||
92 | nvgpu_mutex_destroy(&clk->clk_mutex); | ||
93 | return -ENOMEM; | ||
94 | } | ||
95 | |||
96 | clk->namemap_xlat_table = nvgpu_kcalloc(g, NUM_NAMEMAPS, sizeof(u32)); | ||
97 | |||
98 | if (clk->namemap_xlat_table == NULL) { | ||
99 | nvgpu_kfree(g, clk->clk_namemap); | ||
100 | nvgpu_mutex_destroy(&clk->clk_mutex); | ||
101 | return -ENOMEM; | ||
102 | } | ||
103 | |||
104 | clk->clk_namemap[0] = (struct namemap_cfg) { | ||
105 | .namemap = CLK_NAMEMAP_INDEX_GPCCLK, | ||
106 | .is_enable = 1, | ||
107 | .is_counter = 1, | ||
108 | .g = g, | ||
109 | .cntr = { | ||
110 | .reg_ctrl_addr = trim_gpc_bcast_fr_clk_cntr_ncgpcclk_cfg_r(), | ||
111 | .reg_ctrl_idx = trim_gpc_bcast_fr_clk_cntr_ncgpcclk_cfg_source_gpcclk_f(), | ||
112 | .reg_cntr_addr[0] = trim_gpc_bcast_fr_clk_cntr_ncgpcclk_cnt0_r(), | ||
113 | .reg_cntr_addr[1] = trim_gpc_bcast_fr_clk_cntr_ncgpcclk_cnt1_r() | ||
114 | }, | ||
115 | .name = "gpcclk", | ||
116 | .scale = 1 | ||
117 | }; | ||
118 | clk->namemap_xlat_table[0] = CTRL_CLK_DOMAIN_GPCCLK; | ||
119 | |||
120 | clk->clk_namemap[1] = (struct namemap_cfg) { | ||
121 | .namemap = CLK_NAMEMAP_INDEX_SYSCLK, | ||
122 | .is_enable = 1, | ||
123 | .is_counter = 1, | ||
124 | .g = g, | ||
125 | .cntr = { | ||
126 | .reg_ctrl_addr = trim_sys_fr_clk_cntr_sysclk_cfg_r(), | ||
127 | .reg_ctrl_idx = trim_sys_fr_clk_cntr_sysclk_cfg_source_sysclk_f(), | ||
128 | .reg_cntr_addr[0] = trim_sys_fr_clk_cntr_sysclk_cntr0_r(), | ||
129 | .reg_cntr_addr[1] = trim_sys_fr_clk_cntr_sysclk_cntr1_r() | ||
130 | }, | ||
131 | .name = "sysclk", | ||
132 | .scale = 1 | ||
133 | }; | ||
134 | clk->namemap_xlat_table[1] = CTRL_CLK_DOMAIN_SYSCLK; | ||
135 | |||
136 | clk->clk_namemap[2] = (struct namemap_cfg) { | ||
137 | .namemap = CLK_NAMEMAP_INDEX_XBARCLK, | ||
138 | .is_enable = 1, | ||
139 | .is_counter = 1, | ||
140 | .g = g, | ||
141 | .cntr = { | ||
142 | .reg_ctrl_addr = trim_sys_nafll_fr_clk_cntr_xbarclk_cfg_r(), | ||
143 | .reg_ctrl_idx = trim_sys_nafll_fr_clk_cntr_xbarclk_cfg_source_xbarclk_f(), | ||
144 | .reg_cntr_addr[0] = trim_sys_nafll_fr_clk_cntr_xbarclk_cntr0_r(), | ||
145 | .reg_cntr_addr[1] = trim_sys_nafll_fr_clk_cntr_xbarclk_cntr1_r() | ||
146 | }, | ||
147 | .name = "xbarclk", | ||
148 | .scale = 1 | ||
149 | }; | ||
150 | clk->namemap_xlat_table[2] = CTRL_CLK_DOMAIN_XBARCLK; | ||
151 | |||
152 | clk->namemap_num = NUM_NAMEMAPS; | ||
153 | |||
154 | clk->g = g; | ||
155 | |||
156 | return err; | ||
157 | } | ||
158 | |||
159 | u32 gv100_get_rate_cntr(struct gk20a *g, struct namemap_cfg *c) { | ||
160 | u32 cntr = 0; | ||
161 | u64 cntr_start = 0; | ||
162 | u64 cntr_stop = 0; | ||
163 | |||
164 | struct clk_gk20a *clk = &g->clk; | ||
165 | |||
166 | if ((c == NULL) || (c->cntr.reg_ctrl_addr == 0U) || | ||
167 | (c->cntr.reg_cntr_addr[0] == 0U) || | ||
168 | (c->cntr.reg_cntr_addr[1]) == 0U) { | ||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | nvgpu_mutex_acquire(&clk->clk_mutex); | ||
173 | |||
174 | /* Read the counter values */ | ||
175 | /* Counter is 36bits , 32 bits on addr[0] and 4 lsb on addr[1] others zero*/ | ||
176 | cntr_start = (u64)gk20a_readl(g, c->cntr.reg_cntr_addr[0]); | ||
177 | cntr_start += ((u64)gk20a_readl(g, c->cntr.reg_cntr_addr[1]) << 32); | ||
178 | nvgpu_udelay(XTAL_CNTR_DELAY); | ||
179 | cntr_stop = (u64) gk20a_readl(g, c->cntr.reg_cntr_addr[0]); | ||
180 | cntr_stop += ((u64)gk20a_readl(g, c->cntr.reg_cntr_addr[1]) << 32); | ||
181 | /*Calculate the difference and convert to KHz*/ | ||
182 | cntr = (u32)((cntr_stop - cntr_start) / 10ULL); | ||
183 | nvgpu_mutex_release(&clk->clk_mutex); | ||
184 | |||
185 | return cntr; | ||
186 | |||
187 | } | ||
188 | |||
189 | int gv100_suspend_clk_support(struct gk20a *g) | ||
190 | { | ||
191 | nvgpu_mutex_destroy(&g->clk.clk_mutex); | ||
192 | return 0; | ||
193 | } | ||