summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/clk/clk_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/clk/clk_common.c')
-rw-r--r--drivers/gpu/nvgpu/clk/clk_common.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/clk/clk_common.c b/drivers/gpu/nvgpu/clk/clk_common.c
new file mode 100644
index 00000000..346ad12b
--- /dev/null
+++ b/drivers/gpu/nvgpu/clk/clk_common.c
@@ -0,0 +1,61 @@
1/*
2 * Copyright (c) 2011-2016, NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/clk.h>
18
19#include "gk20a/gk20a.h"
20
21struct clk *gk20a_clk_get(struct gk20a *g)
22{
23 if (!g->clk.tegra_clk) {
24 struct clk *clk;
25 char clk_dev_id[32];
26 struct device *dev = dev_from_gk20a(g);
27
28 snprintf(clk_dev_id, 32, "tegra_%s", dev_name(dev));
29
30 clk = clk_get_sys(clk_dev_id, "gpu");
31 if (IS_ERR(clk)) {
32 gk20a_err(dev, "fail to get tegra gpu clk %s/gpu\n",
33 clk_dev_id);
34 return NULL;
35 }
36 g->clk.tegra_clk = clk;
37 }
38
39 return g->clk.tegra_clk;
40}
41
42unsigned long gk20a_clk_get_rate(struct gk20a *g)
43{
44 struct clk_gk20a *clk = &g->clk;
45 return rate_gpc2clk_to_gpu(clk->gpc_pll.freq);
46}
47
48long gk20a_clk_round_rate(struct gk20a *g, unsigned long rate)
49{
50 /* make sure the clock is available */
51 if (!gk20a_clk_get(g))
52 return rate;
53
54 return clk_round_rate(clk_get_parent(g->clk.tegra_clk), rate);
55}
56
57int gk20a_clk_set_rate(struct gk20a *g, unsigned long rate)
58{
59 return clk_set_rate(g->clk.tegra_clk, rate);
60}
61