From 3a6d47db9d00f86d90a1230dd2225bf4ae8944b8 Mon Sep 17 00:00:00 2001 From: Peter Boonstoppel Date: Tue, 25 Oct 2016 13:54:51 -0700 Subject: gpu: nvgpu: Move gk20a clock helper functions to common file This allows us to use these functions with both Tegra and Common Clock Frameworks Bug 200233943 Change-Id: I5a394d7bacfecabeabc64d32dab214d2e7cf89d7 Signed-off-by: Peter Boonstoppel Reviewed-on: http://git-master/r/1242481 GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/Makefile.nvgpu | 3 +- drivers/gpu/nvgpu/clk/clk_common.c | 61 +++++++++++++++++++++++++++++++++++++ drivers/gpu/nvgpu/gk20a/clk_gk20a.c | 41 ------------------------- 3 files changed, 63 insertions(+), 42 deletions(-) create mode 100644 drivers/gpu/nvgpu/clk/clk_common.c (limited to 'drivers') diff --git a/drivers/gpu/nvgpu/Makefile.nvgpu b/drivers/gpu/nvgpu/Makefile.nvgpu index 22c679ca..f587a930 100644 --- a/drivers/gpu/nvgpu/Makefile.nvgpu +++ b/drivers/gpu/nvgpu/Makefile.nvgpu @@ -119,7 +119,8 @@ nvgpu-$(CONFIG_TEGRA_GR_VIRTUALIZATION) += \ nvgpu-$(CONFIG_TEGRA_CLK_FRAMEWORK) += \ gm20b/clk_gm20b.o \ - gk20a/clk_gk20a.o + gk20a/clk_gk20a.o \ + clk/clk_common.o nvgpu-$(CONFIG_GK20A_DEVFREQ) += \ gk20a/gk20a_scale.o 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 @@ +/* + * Copyright (c) 2011-2016, NVIDIA CORPORATION. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "gk20a/gk20a.h" + +struct clk *gk20a_clk_get(struct gk20a *g) +{ + if (!g->clk.tegra_clk) { + struct clk *clk; + char clk_dev_id[32]; + struct device *dev = dev_from_gk20a(g); + + snprintf(clk_dev_id, 32, "tegra_%s", dev_name(dev)); + + clk = clk_get_sys(clk_dev_id, "gpu"); + if (IS_ERR(clk)) { + gk20a_err(dev, "fail to get tegra gpu clk %s/gpu\n", + clk_dev_id); + return NULL; + } + g->clk.tegra_clk = clk; + } + + return g->clk.tegra_clk; +} + +unsigned long gk20a_clk_get_rate(struct gk20a *g) +{ + struct clk_gk20a *clk = &g->clk; + return rate_gpc2clk_to_gpu(clk->gpc_pll.freq); +} + +long gk20a_clk_round_rate(struct gk20a *g, unsigned long rate) +{ + /* make sure the clock is available */ + if (!gk20a_clk_get(g)) + return rate; + + return clk_round_rate(clk_get_parent(g->clk.tegra_clk), rate); +} + +int gk20a_clk_set_rate(struct gk20a *g, unsigned long rate) +{ + return clk_set_rate(g->clk.tegra_clk, rate); +} + diff --git a/drivers/gpu/nvgpu/gk20a/clk_gk20a.c b/drivers/gpu/nvgpu/gk20a/clk_gk20a.c index 26fd1eaf..e3a486b6 100644 --- a/drivers/gpu/nvgpu/gk20a/clk_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/clk_gk20a.c @@ -412,27 +412,6 @@ static int gk20a_init_clk_reset_enable_hw(struct gk20a *g) return 0; } -struct clk *gk20a_clk_get(struct gk20a *g) -{ - if (!g->clk.tegra_clk) { - struct clk *clk; - char clk_dev_id[32]; - struct device *dev = dev_from_gk20a(g); - - snprintf(clk_dev_id, 32, "tegra_%s", dev_name(dev)); - - clk = clk_get_sys(clk_dev_id, "gpu"); - if (IS_ERR(clk)) { - gk20a_err(dev, "fail to get tegra gpu clk %s/gpu\n", - clk_dev_id); - return NULL; - } - g->clk.tegra_clk = clk; - } - - return g->clk.tegra_clk; -} - static int gk20a_init_clk_setup_sw(struct gk20a *g) { struct clk_gk20a *clk = &g->clk; @@ -709,26 +688,6 @@ void gk20a_init_clk_ops(struct gpu_ops *gops) gops->clk.suspend_clk_support = gk20a_suspend_clk_support; } -unsigned long gk20a_clk_get_rate(struct gk20a *g) -{ - struct clk_gk20a *clk = &g->clk; - return rate_gpc2clk_to_gpu(clk->gpc_pll.freq); -} - -long gk20a_clk_round_rate(struct gk20a *g, unsigned long rate) -{ - /* make sure the clock is available */ - if (!gk20a_clk_get(g)) - return rate; - - return clk_round_rate(clk_get_parent(g->clk.tegra_clk), rate); -} - -int gk20a_clk_set_rate(struct gk20a *g, unsigned long rate) -{ - return clk_set_rate(g->clk.tegra_clk, rate); -} - #ifdef CONFIG_DEBUG_FS static int rate_get(void *data, u64 *val) -- cgit v1.2.2