1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
6 #include <linux/clk-provider.h>
7 #include <linux/slab.h>
12 static unsigned long clk_sync_source_recalc_rate(struct clk_hw *hw,
13 unsigned long parent_rate)
15 struct tegra_clk_sync_source *sync = to_clk_sync_source(hw);
20 static long clk_sync_source_round_rate(struct clk_hw *hw, unsigned long rate,
23 struct tegra_clk_sync_source *sync = to_clk_sync_source(hw);
25 if (rate > sync->max_rate)
31 static int clk_sync_source_set_rate(struct clk_hw *hw, unsigned long rate,
32 unsigned long parent_rate)
34 struct tegra_clk_sync_source *sync = to_clk_sync_source(hw);
40 const struct clk_ops tegra_clk_sync_source_ops = {
41 .round_rate = clk_sync_source_round_rate,
42 .set_rate = clk_sync_source_set_rate,
43 .recalc_rate = clk_sync_source_recalc_rate,
46 struct clk *tegra_clk_register_sync_source(const char *name,
47 unsigned long max_rate)
49 struct tegra_clk_sync_source *sync;
50 struct clk_init_data init;
53 sync = kzalloc(sizeof(*sync), GFP_KERNEL);
55 pr_err("%s: could not allocate sync source clk\n", __func__);
56 return ERR_PTR(-ENOMEM);
59 sync->max_rate = max_rate;
61 init.ops = &tegra_clk_sync_source_ops;
64 init.parent_names = NULL;
67 /* Data in .init is copied by clk_register(), so stack variable OK */
68 sync->hw.init = &init;
70 clk = clk_register(NULL, &sync->hw);