]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/arm/mach-imx/clk-cpu.c
2 * Copyright (c) 2014 Lucas Stach <l.stach@pengutronix.de>, Pengutronix
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * http://www.opensource.org/licenses/gpl-license.html
9 * http://www.gnu.org/copyleft/gpl.html
12 #include <linux/clk.h>
13 #include <linux/clk-provider.h>
14 #include <linux/slab.h>
24 static inline struct clk_cpu
*to_clk_cpu(struct clk_hw
*hw
)
26 return container_of(hw
, struct clk_cpu
, hw
);
29 static unsigned long clk_cpu_recalc_rate(struct clk_hw
*hw
,
30 unsigned long parent_rate
)
32 struct clk_cpu
*cpu
= to_clk_cpu(hw
);
34 return clk_get_rate(cpu
->div
);
37 static long clk_cpu_round_rate(struct clk_hw
*hw
, unsigned long rate
,
40 struct clk_cpu
*cpu
= to_clk_cpu(hw
);
42 return clk_round_rate(cpu
->pll
, rate
);
45 static int clk_cpu_set_rate(struct clk_hw
*hw
, unsigned long rate
,
46 unsigned long parent_rate
)
48 struct clk_cpu
*cpu
= to_clk_cpu(hw
);
51 /* switch to PLL bypass clock */
52 ret
= clk_set_parent(cpu
->mux
, cpu
->step
);
57 ret
= clk_set_rate(cpu
->pll
, rate
);
59 clk_set_parent(cpu
->mux
, cpu
->pll
);
62 /* switch back to PLL clock */
63 clk_set_parent(cpu
->mux
, cpu
->pll
);
65 /* Ensure the divider is what we expect */
66 clk_set_rate(cpu
->div
, rate
);
71 static const struct clk_ops clk_cpu_ops
= {
72 .recalc_rate
= clk_cpu_recalc_rate
,
73 .round_rate
= clk_cpu_round_rate
,
74 .set_rate
= clk_cpu_set_rate
,
77 struct clk
*imx_clk_cpu(const char *name
, const char *parent_name
,
78 struct clk
*div
, struct clk
*mux
, struct clk
*pll
,
83 struct clk_init_data init
;
85 cpu
= kzalloc(sizeof(*cpu
), GFP_KERNEL
);
87 return ERR_PTR(-ENOMEM
);
95 init
.ops
= &clk_cpu_ops
;
97 init
.parent_names
= &parent_name
;
100 cpu
->hw
.init
= &init
;
102 clk
= clk_register(NULL
, &cpu
->hw
);