clk-composite.c (4ba24fef3eb3b142197135223b90ced2f319cd53) clk-composite.c (4e907ef6bd5eeb18bcc78f08bc993b94f007b79f)
1/*
2 * Copyright (c) 2013 NVIDIA CORPORATION. All rights reserved.
3 *
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.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT

--- 13 unchanged lines hidden (view full) ---

22#define to_clk_composite(_hw) container_of(_hw, struct clk_composite, hw)
23
24static u8 clk_composite_get_parent(struct clk_hw *hw)
25{
26 struct clk_composite *composite = to_clk_composite(hw);
27 const struct clk_ops *mux_ops = composite->mux_ops;
28 struct clk_hw *mux_hw = composite->mux_hw;
29
1/*
2 * Copyright (c) 2013 NVIDIA CORPORATION. All rights reserved.
3 *
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.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT

--- 13 unchanged lines hidden (view full) ---

22#define to_clk_composite(_hw) container_of(_hw, struct clk_composite, hw)
23
24static u8 clk_composite_get_parent(struct clk_hw *hw)
25{
26 struct clk_composite *composite = to_clk_composite(hw);
27 const struct clk_ops *mux_ops = composite->mux_ops;
28 struct clk_hw *mux_hw = composite->mux_hw;
29
30 mux_hw->clk = hw->clk;
30 __clk_hw_set_clk(mux_hw, hw);
31
32 return mux_ops->get_parent(mux_hw);
33}
34
35static int clk_composite_set_parent(struct clk_hw *hw, u8 index)
36{
37 struct clk_composite *composite = to_clk_composite(hw);
38 const struct clk_ops *mux_ops = composite->mux_ops;
39 struct clk_hw *mux_hw = composite->mux_hw;
40
31
32 return mux_ops->get_parent(mux_hw);
33}
34
35static int clk_composite_set_parent(struct clk_hw *hw, u8 index)
36{
37 struct clk_composite *composite = to_clk_composite(hw);
38 const struct clk_ops *mux_ops = composite->mux_ops;
39 struct clk_hw *mux_hw = composite->mux_hw;
40
41 mux_hw->clk = hw->clk;
41 __clk_hw_set_clk(mux_hw, hw);
42
43 return mux_ops->set_parent(mux_hw, index);
44}
45
46static unsigned long clk_composite_recalc_rate(struct clk_hw *hw,
47 unsigned long parent_rate)
48{
49 struct clk_composite *composite = to_clk_composite(hw);
50 const struct clk_ops *rate_ops = composite->rate_ops;
51 struct clk_hw *rate_hw = composite->rate_hw;
52
42
43 return mux_ops->set_parent(mux_hw, index);
44}
45
46static unsigned long clk_composite_recalc_rate(struct clk_hw *hw,
47 unsigned long parent_rate)
48{
49 struct clk_composite *composite = to_clk_composite(hw);
50 const struct clk_ops *rate_ops = composite->rate_ops;
51 struct clk_hw *rate_hw = composite->rate_hw;
52
53 rate_hw->clk = hw->clk;
53 __clk_hw_set_clk(rate_hw, hw);
54
55 return rate_ops->recalc_rate(rate_hw, parent_rate);
56}
57
58static long clk_composite_determine_rate(struct clk_hw *hw, unsigned long rate,
54
55 return rate_ops->recalc_rate(rate_hw, parent_rate);
56}
57
58static long clk_composite_determine_rate(struct clk_hw *hw, unsigned long rate,
59 unsigned long min_rate,
60 unsigned long max_rate,
59 unsigned long *best_parent_rate,
60 struct clk_hw **best_parent_p)
61{
62 struct clk_composite *composite = to_clk_composite(hw);
63 const struct clk_ops *rate_ops = composite->rate_ops;
64 const struct clk_ops *mux_ops = composite->mux_ops;
65 struct clk_hw *rate_hw = composite->rate_hw;
66 struct clk_hw *mux_hw = composite->mux_hw;
67 struct clk *parent;
68 unsigned long parent_rate;
69 long tmp_rate, best_rate = 0;
70 unsigned long rate_diff;
71 unsigned long best_rate_diff = ULONG_MAX;
72 int i;
73
74 if (rate_hw && rate_ops && rate_ops->determine_rate) {
61 unsigned long *best_parent_rate,
62 struct clk_hw **best_parent_p)
63{
64 struct clk_composite *composite = to_clk_composite(hw);
65 const struct clk_ops *rate_ops = composite->rate_ops;
66 const struct clk_ops *mux_ops = composite->mux_ops;
67 struct clk_hw *rate_hw = composite->rate_hw;
68 struct clk_hw *mux_hw = composite->mux_hw;
69 struct clk *parent;
70 unsigned long parent_rate;
71 long tmp_rate, best_rate = 0;
72 unsigned long rate_diff;
73 unsigned long best_rate_diff = ULONG_MAX;
74 int i;
75
76 if (rate_hw && rate_ops && rate_ops->determine_rate) {
75 rate_hw->clk = hw->clk;
76 return rate_ops->determine_rate(rate_hw, rate, best_parent_rate,
77 __clk_hw_set_clk(rate_hw, hw);
78 return rate_ops->determine_rate(rate_hw, rate, min_rate,
79 max_rate,
80 best_parent_rate,
77 best_parent_p);
78 } else if (rate_hw && rate_ops && rate_ops->round_rate &&
79 mux_hw && mux_ops && mux_ops->set_parent) {
80 *best_parent_p = NULL;
81
82 if (__clk_get_flags(hw->clk) & CLK_SET_RATE_NO_REPARENT) {
83 parent = clk_get_parent(mux_hw->clk);
84 *best_parent_p = __clk_get_hw(parent);

--- 26 unchanged lines hidden (view full) ---

111 }
112
113 if (!rate_diff)
114 return rate;
115 }
116
117 return best_rate;
118 } else if (mux_hw && mux_ops && mux_ops->determine_rate) {
81 best_parent_p);
82 } else if (rate_hw && rate_ops && rate_ops->round_rate &&
83 mux_hw && mux_ops && mux_ops->set_parent) {
84 *best_parent_p = NULL;
85
86 if (__clk_get_flags(hw->clk) & CLK_SET_RATE_NO_REPARENT) {
87 parent = clk_get_parent(mux_hw->clk);
88 *best_parent_p = __clk_get_hw(parent);

--- 26 unchanged lines hidden (view full) ---

115 }
116
117 if (!rate_diff)
118 return rate;
119 }
120
121 return best_rate;
122 } else if (mux_hw && mux_ops && mux_ops->determine_rate) {
119 mux_hw->clk = hw->clk;
120 return mux_ops->determine_rate(mux_hw, rate, best_parent_rate,
123 __clk_hw_set_clk(mux_hw, hw);
124 return mux_ops->determine_rate(mux_hw, rate, min_rate,
125 max_rate, best_parent_rate,
121 best_parent_p);
122 } else {
123 pr_err("clk: clk_composite_determine_rate function called, but no mux or rate callback set!\n");
124 return 0;
125 }
126}
127
128static long clk_composite_round_rate(struct clk_hw *hw, unsigned long rate,
129 unsigned long *prate)
130{
131 struct clk_composite *composite = to_clk_composite(hw);
132 const struct clk_ops *rate_ops = composite->rate_ops;
133 struct clk_hw *rate_hw = composite->rate_hw;
134
126 best_parent_p);
127 } else {
128 pr_err("clk: clk_composite_determine_rate function called, but no mux or rate callback set!\n");
129 return 0;
130 }
131}
132
133static long clk_composite_round_rate(struct clk_hw *hw, unsigned long rate,
134 unsigned long *prate)
135{
136 struct clk_composite *composite = to_clk_composite(hw);
137 const struct clk_ops *rate_ops = composite->rate_ops;
138 struct clk_hw *rate_hw = composite->rate_hw;
139
135 rate_hw->clk = hw->clk;
140 __clk_hw_set_clk(rate_hw, hw);
136
137 return rate_ops->round_rate(rate_hw, rate, prate);
138}
139
140static int clk_composite_set_rate(struct clk_hw *hw, unsigned long rate,
141 unsigned long parent_rate)
142{
143 struct clk_composite *composite = to_clk_composite(hw);
144 const struct clk_ops *rate_ops = composite->rate_ops;
145 struct clk_hw *rate_hw = composite->rate_hw;
146
141
142 return rate_ops->round_rate(rate_hw, rate, prate);
143}
144
145static int clk_composite_set_rate(struct clk_hw *hw, unsigned long rate,
146 unsigned long parent_rate)
147{
148 struct clk_composite *composite = to_clk_composite(hw);
149 const struct clk_ops *rate_ops = composite->rate_ops;
150 struct clk_hw *rate_hw = composite->rate_hw;
151
147 rate_hw->clk = hw->clk;
152 __clk_hw_set_clk(rate_hw, hw);
148
149 return rate_ops->set_rate(rate_hw, rate, parent_rate);
150}
151
152static int clk_composite_is_enabled(struct clk_hw *hw)
153{
154 struct clk_composite *composite = to_clk_composite(hw);
155 const struct clk_ops *gate_ops = composite->gate_ops;
156 struct clk_hw *gate_hw = composite->gate_hw;
157
153
154 return rate_ops->set_rate(rate_hw, rate, parent_rate);
155}
156
157static int clk_composite_is_enabled(struct clk_hw *hw)
158{
159 struct clk_composite *composite = to_clk_composite(hw);
160 const struct clk_ops *gate_ops = composite->gate_ops;
161 struct clk_hw *gate_hw = composite->gate_hw;
162
158 gate_hw->clk = hw->clk;
163 __clk_hw_set_clk(gate_hw, hw);
159
160 return gate_ops->is_enabled(gate_hw);
161}
162
163static int clk_composite_enable(struct clk_hw *hw)
164{
165 struct clk_composite *composite = to_clk_composite(hw);
166 const struct clk_ops *gate_ops = composite->gate_ops;
167 struct clk_hw *gate_hw = composite->gate_hw;
168
164
165 return gate_ops->is_enabled(gate_hw);
166}
167
168static int clk_composite_enable(struct clk_hw *hw)
169{
170 struct clk_composite *composite = to_clk_composite(hw);
171 const struct clk_ops *gate_ops = composite->gate_ops;
172 struct clk_hw *gate_hw = composite->gate_hw;
173
169 gate_hw->clk = hw->clk;
174 __clk_hw_set_clk(gate_hw, hw);
170
171 return gate_ops->enable(gate_hw);
172}
173
174static void clk_composite_disable(struct clk_hw *hw)
175{
176 struct clk_composite *composite = to_clk_composite(hw);
177 const struct clk_ops *gate_ops = composite->gate_ops;
178 struct clk_hw *gate_hw = composite->gate_hw;
179
175
176 return gate_ops->enable(gate_hw);
177}
178
179static void clk_composite_disable(struct clk_hw *hw)
180{
181 struct clk_composite *composite = to_clk_composite(hw);
182 const struct clk_ops *gate_ops = composite->gate_ops;
183 struct clk_hw *gate_hw = composite->gate_hw;
184
180 gate_hw->clk = hw->clk;
185 __clk_hw_set_clk(gate_hw, hw);
181
182 gate_ops->disable(gate_hw);
183}
184
185struct clk *clk_register_composite(struct device *dev, const char *name,
186 const char **parent_names, int num_parents,
187 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
188 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,

--- 100 unchanged lines hidden ---
186
187 gate_ops->disable(gate_hw);
188}
189
190struct clk *clk_register_composite(struct device *dev, const char *name,
191 const char **parent_names, int num_parents,
192 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
193 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,

--- 100 unchanged lines hidden ---