summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/linux/clk.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/clk.c')
-rw-r--r--drivers/gpu/nvgpu/common/linux/clk.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/clk.c b/drivers/gpu/nvgpu/common/linux/clk.c
new file mode 100644
index 00000000..ea5b023d
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/linux/clk.c
@@ -0,0 +1,146 @@
1/*
2 * Linux clock support
3 *
4 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/clk.h>
20
21#include <soc/tegra/tegra-dvfs.h>
22
23#include "clk.h"
24#include "os_linux.h"
25#include "platform_gk20a.h"
26
27#include "gk20a/gk20a.h"
28
29static unsigned long nvgpu_linux_clk_get_rate(struct gk20a *g, u32 api_domain)
30{
31 struct gk20a_platform *platform = gk20a_get_platform(dev_from_gk20a(g));
32 unsigned long ret;
33
34 switch (api_domain) {
35 case CTRL_CLK_DOMAIN_GPCCLK:
36 if (g->clk.tegra_clk)
37 ret = clk_get_rate(g->clk.tegra_clk);
38 else
39 ret = clk_get_rate(platform->clk[0]);
40 break;
41 case CTRL_CLK_DOMAIN_PWRCLK:
42 ret = clk_get_rate(platform->clk[1]);
43 break;
44 default:
45 nvgpu_err(g, "unknown clock: %u", api_domain);
46 ret = 0;
47 break;
48 }
49
50 return ret;
51}
52
53static int nvgpu_linux_clk_set_rate(struct gk20a *g,
54 u32 api_domain, unsigned long rate)
55{
56 struct gk20a_platform *platform = gk20a_get_platform(dev_from_gk20a(g));
57 int ret;
58
59 switch (api_domain) {
60 case CTRL_CLK_DOMAIN_GPCCLK:
61 if (g->clk.tegra_clk)
62 ret = clk_set_rate(g->clk.tegra_clk, rate);
63 else
64 ret = clk_set_rate(platform->clk[0], rate);
65 break;
66 case CTRL_CLK_DOMAIN_PWRCLK:
67 ret = clk_set_rate(platform->clk[1], rate);
68 break;
69 default:
70 nvgpu_err(g, "unknown clock: %u", api_domain);
71 ret = -EINVAL;
72 break;
73 }
74
75 return ret;
76}
77
78static unsigned long nvgpu_linux_get_fmax_at_vmin_safe(struct clk_gk20a *clk)
79{
80 /*
81 * On Tegra GPU clock exposed to frequency governor is a shared user on
82 * GPCPLL bus (gbus). The latter can be accessed as GPU clock parent.
83 * Respectively the grandparent is PLL reference clock.
84 */
85 return tegra_dvfs_get_fmax_at_vmin_safe_t(
86 clk_get_parent(clk->tegra_clk));
87}
88
89static u32 nvgpu_linux_get_ref_clock_rate(struct gk20a *g)
90{
91 struct clk *c;
92
93 c = clk_get_sys("gpu_ref", "gpu_ref");
94 if (IS_ERR(c)) {
95 nvgpu_err(g, "failed to get GPCPLL reference clock");
96 return 0;
97 }
98
99 return clk_get_rate(c);
100}
101
102static int nvgpu_linux_predict_mv_at_hz_cur_tfloor(struct clk_gk20a *clk,
103 unsigned long rate)
104{
105 return tegra_dvfs_predict_mv_at_hz_cur_tfloor(
106 clk_get_parent(clk->tegra_clk), rate);
107}
108
109static unsigned long nvgpu_linux_get_maxrate(struct gk20a *g, u32 api_domain)
110{
111 int ret;
112
113 switch (api_domain) {
114 case CTRL_CLK_DOMAIN_GPCCLK:
115 ret = tegra_dvfs_get_maxrate(clk_get_parent(g->clk.tegra_clk));
116 break;
117 default:
118 nvgpu_err(g, "unknown clock: %u", api_domain);
119 ret = 0;
120 break;
121 }
122
123 return ret;
124}
125
126static int nvgpu_linux_prepare_enable(struct clk_gk20a *clk)
127{
128 return clk_prepare_enable(clk->tegra_clk);
129}
130
131static void nvgpu_linux_disable_unprepare(struct clk_gk20a *clk)
132{
133 clk_disable_unprepare(clk->tegra_clk);
134}
135
136void nvgpu_linux_init_clk_support(struct gk20a *g)
137{
138 g->ops.clk.get_rate = nvgpu_linux_clk_get_rate;
139 g->ops.clk.set_rate = nvgpu_linux_clk_set_rate;
140 g->ops.clk.get_fmax_at_vmin_safe = nvgpu_linux_get_fmax_at_vmin_safe;
141 g->ops.clk.get_ref_clock_rate = nvgpu_linux_get_ref_clock_rate;
142 g->ops.clk.predict_mv_at_hz_cur_tfloor = nvgpu_linux_predict_mv_at_hz_cur_tfloor;
143 g->ops.clk.get_maxrate = nvgpu_linux_get_maxrate;
144 g->ops.clk.prepare_enable = nvgpu_linux_prepare_enable;
145 g->ops.clk.disable_unprepare = nvgpu_linux_disable_unprepare;
146}