18 #include <linux/module.h>
19 #include <linux/slab.h>
34 static int wm831x_xtal_is_enabled(
struct clk_hw *
hw)
42 static unsigned long wm831x_xtal_recalc_rate(
struct clk_hw *
hw,
43 unsigned long parent_rate)
54 static const struct clk_ops wm831x_xtal_ops = {
55 .is_enabled = wm831x_xtal_is_enabled,
56 .recalc_rate = wm831x_xtal_recalc_rate,
59 static struct clk_init_data wm831x_xtal_init = {
61 .ops = &wm831x_xtal_ops,
65 static const unsigned long wm831x_fll_auto_rates[] = {
76 static int wm831x_fll_is_enabled(
struct clk_hw *hw)
85 dev_err(wm831x->
dev,
"Unable to read FLL_CONTROL_1: %d\n",
93 static int wm831x_fll_prepare(
struct clk_hw *hw)
97 struct wm831x *wm831x = clkdata->
wm831x;
103 dev_crit(wm831x->
dev,
"Failed to enable FLL: %d\n", ret);
110 static void wm831x_fll_unprepare(
struct clk_hw *hw)
114 struct wm831x *wm831x = clkdata->
wm831x;
119 dev_crit(wm831x->
dev,
"Failed to disaable FLL: %d\n", ret);
122 static unsigned long wm831x_fll_recalc_rate(
struct clk_hw *hw,
123 unsigned long parent_rate)
127 struct wm831x *wm831x = clkdata->
wm831x;
132 dev_err(wm831x->
dev,
"Unable to read CLOCK_CONTROL_2: %d\n",
140 dev_err(wm831x->
dev,
"FLL only supported in AUTO mode\n");
145 static long wm831x_fll_round_rate(
struct clk_hw *hw,
unsigned long rate,
151 for (i = 0; i <
ARRAY_SIZE(wm831x_fll_auto_rates); i++)
152 if (
abs(wm831x_fll_auto_rates[i] - rate) <
153 abs(wm831x_fll_auto_rates[best] - rate))
156 return wm831x_fll_auto_rates[best];
159 static int wm831x_fll_set_rate(
struct clk_hw *hw,
unsigned long rate,
160 unsigned long parent_rate)
164 struct wm831x *wm831x = clkdata->
wm831x;
167 for (i = 0; i <
ARRAY_SIZE(wm831x_fll_auto_rates); i++)
168 if (wm831x_fll_auto_rates[i] == rate)
173 if (wm831x_fll_is_enabled(hw))
180 static const char *wm831x_fll_parents[] = {
185 static u8 wm831x_fll_get_parent(
struct clk_hw *hw)
189 struct wm831x *wm831x = clkdata->
wm831x;
195 dev_err(wm831x->
dev,
"Unable to read CLOCK_CONTROL_2: %d\n",
205 dev_err(wm831x->
dev,
"Unable to read FLL_CONTROL_5: %d\n",
216 dev_err(wm831x->
dev,
"Unsupported FLL clock source %d\n",
217 ret & WM831X_FLL_CLK_SRC_MASK);
222 static const struct clk_ops wm831x_fll_ops = {
223 .is_enabled = wm831x_fll_is_enabled,
224 .prepare = wm831x_fll_prepare,
225 .unprepare = wm831x_fll_unprepare,
226 .round_rate = wm831x_fll_round_rate,
227 .recalc_rate = wm831x_fll_recalc_rate,
228 .set_rate = wm831x_fll_set_rate,
229 .get_parent = wm831x_fll_get_parent,
232 static struct clk_init_data wm831x_fll_init = {
234 .ops = &wm831x_fll_ops,
235 .parent_names = wm831x_fll_parents,
236 .num_parents =
ARRAY_SIZE(wm831x_fll_parents),
237 .flags = CLK_SET_RATE_GATE,
240 static int wm831x_clkout_is_enabled(
struct clk_hw *hw)
244 struct wm831x *wm831x = clkdata->
wm831x;
249 dev_err(wm831x->
dev,
"Unable to read CLOCK_CONTROL_1: %d\n",
257 static int wm831x_clkout_prepare(
struct clk_hw *hw)
261 struct wm831x *wm831x = clkdata->
wm831x;
266 dev_crit(wm831x->
dev,
"Failed to lock registers: %d\n", ret);
273 dev_crit(wm831x->
dev,
"Failed to enable CLKOUT: %d\n", ret);
280 static void wm831x_clkout_unprepare(
struct clk_hw *hw)
284 struct wm831x *wm831x = clkdata->
wm831x;
289 dev_crit(wm831x->
dev,
"Failed to lock registers: %d\n", ret);
296 dev_crit(wm831x->
dev,
"Failed to disable CLKOUT: %d\n", ret);
301 static const char *wm831x_clkout_parents[] = {
306 static u8 wm831x_clkout_get_parent(
struct clk_hw *hw)
310 struct wm831x *wm831x = clkdata->
wm831x;
315 dev_err(wm831x->
dev,
"Unable to read CLOCK_CONTROL_1: %d\n",
326 static int wm831x_clkout_set_parent(
struct clk_hw *hw,
u8 parent)
330 struct wm831x *wm831x = clkdata->
wm831x;
337 static const struct clk_ops wm831x_clkout_ops = {
338 .is_enabled = wm831x_clkout_is_enabled,
339 .prepare = wm831x_clkout_prepare,
340 .unprepare = wm831x_clkout_unprepare,
341 .get_parent = wm831x_clkout_get_parent,
342 .set_parent = wm831x_clkout_set_parent,
345 static struct clk_init_data wm831x_clkout_init = {
347 .ops = &wm831x_clkout_ops,
348 .parent_names = wm831x_clkout_parents,
349 .num_parents =
ARRAY_SIZE(wm831x_clkout_parents),
350 .flags = CLK_SET_RATE_PARENT,
366 dev_err(wm831x->
dev,
"Unable to read CLOCK_CONTROL_2: %d\n",
372 clkdata->
xtal_hw.init = &wm831x_xtal_init;
377 clkdata->
fll_hw.init = &wm831x_fll_init;
384 clkdata->
clkout_hw.init = &wm831x_clkout_init;
414 .probe = wm831x_clk_probe,
417 .name =
"wm831x-clk",