diff options
author | Nitin Kumbhar <nkumbhar@nvidia.com> | 2018-08-10 02:00:19 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2018-08-29 23:34:43 -0400 |
commit | a846037fdfeedb179da0a9c19637cfcb9035689e (patch) | |
tree | 3f7c0f253ec0e49a5de97adffef78fcb15f8b44b /drivers/gpu/nvgpu/os/linux/debug_clk_gm20b.c | |
parent | 94eebcdd8cacc9a2dc20485e0d3d15fc51507c2c (diff) |
gpu: nvgpu: rename gm20b clk debugfs file
debug_clk.c implements clk debugfs of gm20b. Rename the file
to reflect clk debugfs functions implemented for gm20b.
JIRA NVGPU-603
Change-Id: I6ff4b71abe400b8fc2a8d79e12e53e2048ccdc05
Signed-off-by: Nitin Kumbhar <nkumbhar@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1797903
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/os/linux/debug_clk_gm20b.c')
-rw-r--r-- | drivers/gpu/nvgpu/os/linux/debug_clk_gm20b.c | 273 |
1 files changed, 273 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/os/linux/debug_clk_gm20b.c b/drivers/gpu/nvgpu/os/linux/debug_clk_gm20b.c new file mode 100644 index 00000000..f514d2c8 --- /dev/null +++ b/drivers/gpu/nvgpu/os/linux/debug_clk_gm20b.c | |||
@@ -0,0 +1,273 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017-2018 NVIDIA Corporation. All rights reserved. | ||
3 | * | ||
4 | * This software is licensed under the terms of the GNU General Public | ||
5 | * License version 2, as published by the Free Software Foundation, and | ||
6 | * may be copied, distributed, and modified under those terms. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/uaccess.h> | ||
16 | #include <linux/debugfs.h> | ||
17 | #include <linux/seq_file.h> | ||
18 | |||
19 | #include <nvgpu/io.h> | ||
20 | |||
21 | #include "gm20b/clk_gm20b.h" | ||
22 | #include "os_linux.h" | ||
23 | #include "platform_gk20a.h" | ||
24 | |||
25 | static int rate_get(void *data, u64 *val) | ||
26 | { | ||
27 | struct gk20a *g = (struct gk20a *)data; | ||
28 | struct clk_gk20a *clk = &g->clk; | ||
29 | |||
30 | *val = (u64)rate_gpc2clk_to_gpu(clk->gpc_pll.freq); | ||
31 | return 0; | ||
32 | } | ||
33 | static int rate_set(void *data, u64 val) | ||
34 | { | ||
35 | struct gk20a *g = (struct gk20a *)data; | ||
36 | return g->ops.clk.set_rate(g, CTRL_CLK_DOMAIN_GPCCLK, (u32)val); | ||
37 | } | ||
38 | DEFINE_SIMPLE_ATTRIBUTE(rate_fops, rate_get, rate_set, "%llu\n"); | ||
39 | |||
40 | static int pll_reg_show(struct seq_file *s, void *data) | ||
41 | { | ||
42 | struct gk20a *g = s->private; | ||
43 | struct nvgpu_clk_pll_debug_data d; | ||
44 | u32 reg, m, n, pl, f; | ||
45 | int err = 0; | ||
46 | |||
47 | if (g->ops.clk.get_pll_debug_data) { | ||
48 | err = g->ops.clk.get_pll_debug_data(g, &d); | ||
49 | if (err) | ||
50 | return err; | ||
51 | } else { | ||
52 | return -EINVAL; | ||
53 | } | ||
54 | |||
55 | seq_printf(s, "bypassctrl = %s, ", | ||
56 | d.trim_sys_bypassctrl_val ? "bypass" : "vco"); | ||
57 | seq_printf(s, "sel_vco = %s, ", | ||
58 | d.trim_sys_sel_vco_val ? "vco" : "bypass"); | ||
59 | |||
60 | seq_printf(s, "cfg = 0x%x : %s : %s : %s\n", d.trim_sys_gpcpll_cfg_val, | ||
61 | d.trim_sys_gpcpll_cfg_enabled ? "enabled" : "disabled", | ||
62 | d.trim_sys_gpcpll_cfg_locked ? "locked" : "unlocked", | ||
63 | d.trim_sys_gpcpll_cfg_sync_on ? "sync_on" : "sync_off"); | ||
64 | |||
65 | reg = d.trim_sys_gpcpll_coeff_val; | ||
66 | m = d.trim_sys_gpcpll_coeff_mdiv; | ||
67 | n = d.trim_sys_gpcpll_coeff_ndiv; | ||
68 | pl = d.trim_sys_gpcpll_coeff_pldiv; | ||
69 | f = g->clk.gpc_pll.clk_in * n / (m * nvgpu_pl_to_div(pl)); | ||
70 | seq_printf(s, "coef = 0x%x : m = %u : n = %u : pl = %u", reg, m, n, pl); | ||
71 | seq_printf(s, " : pll_f(gpu_f) = %u(%u) kHz\n", f, f/2); | ||
72 | |||
73 | seq_printf(s, "dvfs0 = 0x%x : d = %u : dmax = %u : doffs = %u\n", | ||
74 | d.trim_sys_gpcpll_dvfs0_val, | ||
75 | d.trim_sys_gpcpll_dvfs0_dfs_coeff, | ||
76 | d.trim_sys_gpcpll_dvfs0_dfs_det_max, | ||
77 | d.trim_sys_gpcpll_dvfs0_dfs_dc_offset); | ||
78 | |||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | static int pll_reg_open(struct inode *inode, struct file *file) | ||
83 | { | ||
84 | return single_open(file, pll_reg_show, inode->i_private); | ||
85 | } | ||
86 | |||
87 | static const struct file_operations pll_reg_fops = { | ||
88 | .open = pll_reg_open, | ||
89 | .read = seq_read, | ||
90 | .llseek = seq_lseek, | ||
91 | .release = single_release, | ||
92 | }; | ||
93 | |||
94 | static int pll_reg_raw_show(struct seq_file *s, void *data) | ||
95 | { | ||
96 | struct gk20a *g = s->private; | ||
97 | struct nvgpu_clk_pll_debug_data d; | ||
98 | u32 reg; | ||
99 | int err = 0; | ||
100 | |||
101 | if (g->ops.clk.get_pll_debug_data) { | ||
102 | err = g->ops.clk.get_pll_debug_data(g, &d); | ||
103 | if (err) | ||
104 | return err; | ||
105 | } else { | ||
106 | return -EINVAL; | ||
107 | } | ||
108 | |||
109 | seq_puts(s, "GPCPLL REGISTERS:\n"); | ||
110 | for (reg = d.trim_sys_gpcpll_cfg_reg; | ||
111 | reg <= d.trim_sys_gpcpll_dvfs2_reg; | ||
112 | reg += sizeof(u32)) | ||
113 | seq_printf(s, "[0x%02x] = 0x%08x\n", reg, gk20a_readl(g, reg)); | ||
114 | |||
115 | seq_puts(s, "\nGPC CLK OUT REGISTERS:\n"); | ||
116 | |||
117 | seq_printf(s, "[0x%02x] = 0x%08x\n", d.trim_sys_sel_vco_reg, | ||
118 | d.trim_sys_sel_vco_val); | ||
119 | seq_printf(s, "[0x%02x] = 0x%08x\n", d.trim_sys_gpc2clk_out_reg, | ||
120 | d.trim_sys_gpc2clk_out_val); | ||
121 | seq_printf(s, "[0x%02x] = 0x%08x\n", d.trim_sys_bypassctrl_reg, | ||
122 | d.trim_sys_bypassctrl_val); | ||
123 | |||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | static int pll_reg_raw_open(struct inode *inode, struct file *file) | ||
128 | { | ||
129 | return single_open(file, pll_reg_raw_show, inode->i_private); | ||
130 | } | ||
131 | |||
132 | static ssize_t pll_reg_raw_write(struct file *file, | ||
133 | const char __user *userbuf, size_t count, loff_t *ppos) | ||
134 | { | ||
135 | struct gk20a *g = file->f_path.dentry->d_inode->i_private; | ||
136 | char buf[80]; | ||
137 | u32 reg, val; | ||
138 | int err = 0; | ||
139 | |||
140 | if (sizeof(buf) <= count) | ||
141 | return -EINVAL; | ||
142 | |||
143 | if (copy_from_user(buf, userbuf, count)) | ||
144 | return -EFAULT; | ||
145 | |||
146 | /* terminate buffer and trim - white spaces may be appended | ||
147 | * at the end when invoked from shell command line */ | ||
148 | buf[count] = '\0'; | ||
149 | strim(buf); | ||
150 | |||
151 | if (sscanf(buf, "[0x%x] = 0x%x", ®, &val) != 2) | ||
152 | return -EINVAL; | ||
153 | |||
154 | if (g->ops.clk.pll_reg_write(g, reg, val)) | ||
155 | err = g->ops.clk.pll_reg_write(g, reg, val); | ||
156 | else | ||
157 | err = -EINVAL; | ||
158 | |||
159 | return err; | ||
160 | } | ||
161 | |||
162 | static const struct file_operations pll_reg_raw_fops = { | ||
163 | .open = pll_reg_raw_open, | ||
164 | .read = seq_read, | ||
165 | .write = pll_reg_raw_write, | ||
166 | .llseek = seq_lseek, | ||
167 | .release = single_release, | ||
168 | }; | ||
169 | |||
170 | static int monitor_get(void *data, u64 *val) | ||
171 | { | ||
172 | struct gk20a *g = (struct gk20a *)data; | ||
173 | int err = 0; | ||
174 | |||
175 | if (g->ops.clk.get_gpcclk_clock_counter) | ||
176 | err = g->ops.clk.get_gpcclk_clock_counter(&g->clk, val); | ||
177 | else | ||
178 | err = -EINVAL; | ||
179 | |||
180 | return err; | ||
181 | } | ||
182 | DEFINE_SIMPLE_ATTRIBUTE(monitor_fops, monitor_get, NULL, "%llu\n"); | ||
183 | |||
184 | static int voltage_get(void *data, u64 *val) | ||
185 | { | ||
186 | struct gk20a *g = (struct gk20a *)data; | ||
187 | int err = 0; | ||
188 | |||
189 | if (g->ops.clk.get_voltage) | ||
190 | err = g->ops.clk.get_voltage(&g->clk, val); | ||
191 | else | ||
192 | err = -EINVAL; | ||
193 | |||
194 | return err; | ||
195 | } | ||
196 | DEFINE_SIMPLE_ATTRIBUTE(voltage_fops, voltage_get, NULL, "%llu\n"); | ||
197 | |||
198 | static int pll_param_show(struct seq_file *s, void *data) | ||
199 | { | ||
200 | struct pll_parms *gpc_pll_params = gm20b_get_gpc_pll_parms(); | ||
201 | |||
202 | seq_printf(s, "ADC offs = %d uV, ADC slope = %d uV, VCO ctrl = 0x%x\n", | ||
203 | gpc_pll_params->uvdet_offs, gpc_pll_params->uvdet_slope, | ||
204 | gpc_pll_params->vco_ctrl); | ||
205 | return 0; | ||
206 | } | ||
207 | |||
208 | static int pll_param_open(struct inode *inode, struct file *file) | ||
209 | { | ||
210 | return single_open(file, pll_param_show, inode->i_private); | ||
211 | } | ||
212 | |||
213 | static const struct file_operations pll_param_fops = { | ||
214 | .open = pll_param_open, | ||
215 | .read = seq_read, | ||
216 | .llseek = seq_lseek, | ||
217 | .release = single_release, | ||
218 | }; | ||
219 | |||
220 | int gm20b_clk_init_debugfs(struct gk20a *g) | ||
221 | { | ||
222 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
223 | struct dentry *d; | ||
224 | |||
225 | if (!l->debugfs) | ||
226 | return -EINVAL; | ||
227 | |||
228 | d = debugfs_create_file( | ||
229 | "rate", S_IRUGO|S_IWUSR, l->debugfs, g, &rate_fops); | ||
230 | if (!d) | ||
231 | goto err_out; | ||
232 | |||
233 | d = debugfs_create_file( | ||
234 | "pll_reg", S_IRUGO, l->debugfs, g, &pll_reg_fops); | ||
235 | if (!d) | ||
236 | goto err_out; | ||
237 | |||
238 | d = debugfs_create_file("pll_reg_raw", | ||
239 | S_IRUGO, l->debugfs, g, &pll_reg_raw_fops); | ||
240 | if (!d) | ||
241 | goto err_out; | ||
242 | |||
243 | d = debugfs_create_file( | ||
244 | "monitor", S_IRUGO, l->debugfs, g, &monitor_fops); | ||
245 | if (!d) | ||
246 | goto err_out; | ||
247 | |||
248 | d = debugfs_create_file( | ||
249 | "voltage", S_IRUGO, l->debugfs, g, &voltage_fops); | ||
250 | if (!d) | ||
251 | goto err_out; | ||
252 | |||
253 | d = debugfs_create_file( | ||
254 | "pll_param", S_IRUGO, l->debugfs, g, &pll_param_fops); | ||
255 | if (!d) | ||
256 | goto err_out; | ||
257 | |||
258 | d = debugfs_create_u32("pll_na_mode", S_IRUGO, l->debugfs, | ||
259 | (u32 *)&g->clk.gpc_pll.mode); | ||
260 | if (!d) | ||
261 | goto err_out; | ||
262 | |||
263 | d = debugfs_create_u32("fmax2x_at_vmin_safe_t", S_IRUGO, | ||
264 | l->debugfs, (u32 *)&g->clk.dvfs_safe_max_freq); | ||
265 | if (!d) | ||
266 | goto err_out; | ||
267 | |||
268 | return 0; | ||
269 | |||
270 | err_out: | ||
271 | pr_err("%s: Failed to make debugfs node\n", __func__); | ||
272 | return -ENOMEM; | ||
273 | } | ||