uapi/if_ether.h: move __UAPI_DEF_ETHHDR libc define
[linux/fpc-iii.git] / drivers / clk / tegra / clk-audio-sync.c
blob92d04ce2dee6b7e4e5131a1f9052bbee7d5de134
1 /*
2 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
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.
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.
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/>.
17 #include <linux/clk-provider.h>
18 #include <linux/slab.h>
19 #include <linux/err.h>
21 #include "clk.h"
23 static unsigned long clk_sync_source_recalc_rate(struct clk_hw *hw,
24 unsigned long parent_rate)
26 struct tegra_clk_sync_source *sync = to_clk_sync_source(hw);
28 return sync->rate;
31 static long clk_sync_source_round_rate(struct clk_hw *hw, unsigned long rate,
32 unsigned long *prate)
34 struct tegra_clk_sync_source *sync = to_clk_sync_source(hw);
36 if (rate > sync->max_rate)
37 return -EINVAL;
38 else
39 return rate;
42 static int clk_sync_source_set_rate(struct clk_hw *hw, unsigned long rate,
43 unsigned long parent_rate)
45 struct tegra_clk_sync_source *sync = to_clk_sync_source(hw);
47 sync->rate = rate;
48 return 0;
51 const struct clk_ops tegra_clk_sync_source_ops = {
52 .round_rate = clk_sync_source_round_rate,
53 .set_rate = clk_sync_source_set_rate,
54 .recalc_rate = clk_sync_source_recalc_rate,
57 struct clk *tegra_clk_register_sync_source(const char *name,
58 unsigned long rate, unsigned long max_rate)
60 struct tegra_clk_sync_source *sync;
61 struct clk_init_data init;
62 struct clk *clk;
64 sync = kzalloc(sizeof(*sync), GFP_KERNEL);
65 if (!sync) {
66 pr_err("%s: could not allocate sync source clk\n", __func__);
67 return ERR_PTR(-ENOMEM);
70 sync->rate = rate;
71 sync->max_rate = max_rate;
73 init.ops = &tegra_clk_sync_source_ops;
74 init.name = name;
75 init.flags = 0;
76 init.parent_names = NULL;
77 init.num_parents = 0;
79 /* Data in .init is copied by clk_register(), so stack variable OK */
80 sync->hw.init = &init;
82 clk = clk_register(NULL, &sync->hw);
83 if (IS_ERR(clk))
84 kfree(sync);
86 return clk;