sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / clk / sunxi-ng / ccu_div.c
blob8659b4cb6c2099cba086b29713e2312a7703b87d
1 /*
2 * Copyright (C) 2016 Maxime Ripard
3 * Maxime Ripard <maxime.ripard@free-electrons.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
9 */
11 #include <linux/clk-provider.h>
13 #include "ccu_gate.h"
14 #include "ccu_div.h"
16 static unsigned long ccu_div_round_rate(struct ccu_mux_internal *mux,
17 unsigned long parent_rate,
18 unsigned long rate,
19 void *data)
21 struct ccu_div *cd = data;
22 unsigned long val;
25 * We can't use divider_round_rate that assumes that there's
26 * several parents, while we might be called to evaluate
27 * several different parents.
29 val = divider_get_val(rate, parent_rate, cd->div.table, cd->div.width,
30 cd->div.flags);
32 return divider_recalc_rate(&cd->common.hw, parent_rate, val,
33 cd->div.table, cd->div.flags);
36 static void ccu_div_disable(struct clk_hw *hw)
38 struct ccu_div *cd = hw_to_ccu_div(hw);
40 return ccu_gate_helper_disable(&cd->common, cd->enable);
43 static int ccu_div_enable(struct clk_hw *hw)
45 struct ccu_div *cd = hw_to_ccu_div(hw);
47 return ccu_gate_helper_enable(&cd->common, cd->enable);
50 static int ccu_div_is_enabled(struct clk_hw *hw)
52 struct ccu_div *cd = hw_to_ccu_div(hw);
54 return ccu_gate_helper_is_enabled(&cd->common, cd->enable);
57 static unsigned long ccu_div_recalc_rate(struct clk_hw *hw,
58 unsigned long parent_rate)
60 struct ccu_div *cd = hw_to_ccu_div(hw);
61 unsigned long val;
62 u32 reg;
64 reg = readl(cd->common.base + cd->common.reg);
65 val = reg >> cd->div.shift;
66 val &= (1 << cd->div.width) - 1;
68 ccu_mux_helper_adjust_parent_for_prediv(&cd->common, &cd->mux, -1,
69 &parent_rate);
71 return divider_recalc_rate(hw, parent_rate, val, cd->div.table,
72 cd->div.flags);
75 static int ccu_div_determine_rate(struct clk_hw *hw,
76 struct clk_rate_request *req)
78 struct ccu_div *cd = hw_to_ccu_div(hw);
80 return ccu_mux_helper_determine_rate(&cd->common, &cd->mux,
81 req, ccu_div_round_rate, cd);
84 static int ccu_div_set_rate(struct clk_hw *hw, unsigned long rate,
85 unsigned long parent_rate)
87 struct ccu_div *cd = hw_to_ccu_div(hw);
88 unsigned long flags;
89 unsigned long val;
90 u32 reg;
92 ccu_mux_helper_adjust_parent_for_prediv(&cd->common, &cd->mux, -1,
93 &parent_rate);
95 val = divider_get_val(rate, parent_rate, cd->div.table, cd->div.width,
96 cd->div.flags);
98 spin_lock_irqsave(cd->common.lock, flags);
100 reg = readl(cd->common.base + cd->common.reg);
101 reg &= ~GENMASK(cd->div.width + cd->div.shift - 1, cd->div.shift);
103 writel(reg | (val << cd->div.shift),
104 cd->common.base + cd->common.reg);
106 spin_unlock_irqrestore(cd->common.lock, flags);
108 return 0;
111 static u8 ccu_div_get_parent(struct clk_hw *hw)
113 struct ccu_div *cd = hw_to_ccu_div(hw);
115 return ccu_mux_helper_get_parent(&cd->common, &cd->mux);
118 static int ccu_div_set_parent(struct clk_hw *hw, u8 index)
120 struct ccu_div *cd = hw_to_ccu_div(hw);
122 return ccu_mux_helper_set_parent(&cd->common, &cd->mux, index);
125 const struct clk_ops ccu_div_ops = {
126 .disable = ccu_div_disable,
127 .enable = ccu_div_enable,
128 .is_enabled = ccu_div_is_enabled,
130 .get_parent = ccu_div_get_parent,
131 .set_parent = ccu_div_set_parent,
133 .determine_rate = ccu_div_determine_rate,
134 .recalc_rate = ccu_div_recalc_rate,
135 .set_rate = ccu_div_set_rate,