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
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>
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
);
31 static long clk_sync_source_round_rate(struct clk_hw
*hw
, unsigned long rate
,
34 struct tegra_clk_sync_source
*sync
= to_clk_sync_source(hw
);
36 if (rate
> sync
->max_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
);
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 max_rate
)
60 struct tegra_clk_sync_source
*sync
;
61 struct clk_init_data init
;
64 sync
= kzalloc(sizeof(*sync
), GFP_KERNEL
);
66 pr_err("%s: could not allocate sync source clk\n", __func__
);
67 return ERR_PTR(-ENOMEM
);
70 sync
->max_rate
= max_rate
;
72 init
.ops
= &tegra_clk_sync_source_ops
;
75 init
.parent_names
= NULL
;
78 /* Data in .init is copied by clk_register(), so stack variable OK */
79 sync
->hw
.init
= &init
;
81 clk
= clk_register(NULL
, &sync
->hw
);