2 * Copyright (c) 2015, 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>
22 static inline struct tegra_clk_periph_fixed *
23 to_tegra_clk_periph_fixed(struct clk_hw *hw)
25 return container_of(hw, struct tegra_clk_periph_fixed, hw);
28 static int tegra_clk_periph_fixed_is_enabled(struct clk_hw *hw)
30 struct tegra_clk_periph_fixed *fixed = to_tegra_clk_periph_fixed(hw);
31 u32 mask = 1 << (fixed->num % 32), value;
33 value = readl(fixed->base + fixed->regs->enb_reg);
35 value = readl(fixed->base + fixed->regs->rst_reg);
36 if ((value & mask) == 0)
43 static int tegra_clk_periph_fixed_enable(struct clk_hw *hw)
45 struct tegra_clk_periph_fixed *fixed = to_tegra_clk_periph_fixed(hw);
46 u32 mask = 1 << (fixed->num % 32);
48 writel(mask, fixed->base + fixed->regs->enb_set_reg);
53 static void tegra_clk_periph_fixed_disable(struct clk_hw *hw)
55 struct tegra_clk_periph_fixed *fixed = to_tegra_clk_periph_fixed(hw);
56 u32 mask = 1 << (fixed->num % 32);
58 writel(mask, fixed->base + fixed->regs->enb_clr_reg);
62 tegra_clk_periph_fixed_recalc_rate(struct clk_hw *hw,
63 unsigned long parent_rate)
65 struct tegra_clk_periph_fixed *fixed = to_tegra_clk_periph_fixed(hw);
66 unsigned long long rate;
68 rate = (unsigned long long)parent_rate * fixed->mul;
69 do_div(rate, fixed->div);
71 return (unsigned long)rate;
74 static const struct clk_ops tegra_clk_periph_fixed_ops = {
75 .is_enabled = tegra_clk_periph_fixed_is_enabled,
76 .enable = tegra_clk_periph_fixed_enable,
77 .disable = tegra_clk_periph_fixed_disable,
78 .recalc_rate = tegra_clk_periph_fixed_recalc_rate,
81 struct clk *tegra_clk_register_periph_fixed(const char *name,
89 const struct tegra_clk_periph_regs *regs;
90 struct tegra_clk_periph_fixed *fixed;
91 struct clk_init_data init;
94 regs = get_reg_bank(num);
96 return ERR_PTR(-EINVAL);
98 fixed = kzalloc(sizeof(*fixed), GFP_KERNEL);
100 return ERR_PTR(-ENOMEM);
104 init.parent_names = parent ? &parent : NULL;
105 init.num_parents = parent ? 1 : 0;
106 init.ops = &tegra_clk_periph_fixed_ops;
114 fixed->hw.init = &init;
116 clk = clk_register(NULL, &fixed->hw);