17 #include <linux/kernel.h>
18 #include <linux/list.h>
19 #include <linux/errno.h>
21 #include <linux/module.h>
22 #include <linux/string.h>
33 static int clocks_initialized;
35 #define CLK_HAS_RATE 0x1
36 #define CLK_HAS_CTRL 0x2
54 static struct clk *mpc5121_clk_get(
struct device *
dev,
const char *
id)
65 dev_match = id_match = 0;
71 if ((dev_match || id_match) && try_module_get(p->
owner)) {
82 static void dump_clocks(
void)
99 #define DEBUG_CLK_DUMP() dump_clocks()
101 #define DEBUG_CLK_DUMP()
105 static void mpc5121_clk_put(
struct clk *clk)
107 module_put(clk->
owner);
127 static int mpc5121_clk_enable(
struct clk *clk)
133 mask |= 1 << clk->
bit;
139 static void mpc5121_clk_disable(
struct clk *clk)
145 mask &= ~(1 << clk->
bit);
150 static unsigned long mpc5121_clk_get_rate(
struct clk *clk)
158 static long mpc5121_clk_round_rate(
struct clk *clk,
unsigned long rate)
163 static int mpc5121_clk_set_rate(
struct clk *clk,
unsigned long rate)
171 list_add(&clk->
node, &clocks);
176 static unsigned long spmf_mult(
void)
181 static int spmf_to_mult[] = {
187 int spmf = (clockctl->
spmr >> 24) & 0xf;
188 return spmf_to_mult[spmf];
191 static unsigned long sysdiv_div_x_2(
void)
198 static int sysdiv_to_div_x_2[] = {
209 int sysdiv = (clockctl->
scfr2 >> 26) & 0x3f;
210 return sysdiv_to_div_x_2[sysdiv];
213 static unsigned long ref_to_sys(
unsigned long rate)
217 rate /= sysdiv_div_x_2();
222 static unsigned long sys_to_ref(
unsigned long rate)
224 rate *= sysdiv_div_x_2();
231 static long ips_to_ref(
unsigned long rate)
233 int ips_div = (clockctl->
scfr1 >> 23) & 0x7;
237 return sys_to_ref(rate);
240 static unsigned long devtree_getfreq(
char *clockname)
243 const unsigned int *prop;
244 unsigned int val = 0;
256 static void ref_clk_calc(
struct clk *clk)
260 rate = devtree_getfreq(
"bus-frequency");
266 clk->
rate = ips_to_ref(rate);
269 static struct clk ref_clk = {
271 .calc = ref_clk_calc,
275 static void sys_clk_calc(
struct clk *clk)
277 clk->
rate = ref_to_sys(ref_clk.
rate);
282 .calc = sys_clk_calc,
285 static void diu_clk_calc(
struct clk *clk)
287 int diudiv_x_2 = clockctl->
scfr1 & 0xff;
298 static void viu_clk_calc(
struct clk *clk)
307 static void half_clk_calc(
struct clk *clk)
312 static void generic_div_clk_calc(
struct clk *clk)
319 static void unity_clk_calc(
struct clk *clk)
324 static struct clk csb_clk = {
326 .calc = half_clk_calc,
330 static void e300_clk_calc(
struct clk *clk)
332 int spmf = (clockctl->
spmr >> 16) & 0xf;
333 int ratex2 = clk->
parent->rate * spmf;
335 clk->
rate = ratex2 / 2;
338 static struct clk e300_clk = {
340 .calc = e300_clk_calc,
344 static struct clk ips_clk = {
346 .calc = generic_div_clk_calc,
354 static struct clk lpc_clk = {
359 .calc = generic_div_clk_calc,
364 static struct clk nfc_clk = {
369 .calc = generic_div_clk_calc,
374 static struct clk pata_clk = {
379 .calc = unity_clk_calc,
388 static struct clk sata_clk = {
393 .calc = unity_clk_calc,
397 static struct clk fec_clk = {
402 .calc = unity_clk_calc,
406 static struct clk pci_clk = {
411 .calc = generic_div_clk_calc,
419 static struct clk diu_clk = {
424 .calc = diu_clk_calc,
427 static struct clk viu_clk = {
432 .calc = viu_clk_calc,
435 static struct clk axe_clk = {
440 .calc = unity_clk_calc,
444 static struct clk usb1_clk = {
449 .calc = unity_clk_calc,
453 static struct clk usb2_clk = {
458 .calc = unity_clk_calc,
467 .calc = unity_clk_calc,
471 static struct clk mscan_clk = {
476 .calc = unity_clk_calc,
480 static struct clk sdhc_clk = {
485 .calc = unity_clk_calc,
489 static struct clk mbx_bus_clk = {
490 .name =
"mbx_bus_clk",
494 .calc = half_clk_calc,
498 static struct clk mbx_clk = {
503 .calc = unity_clk_calc,
507 static struct clk mbx_3d_clk = {
508 .name =
"mbx_3d_clk",
512 .calc = generic_div_clk_calc,
513 .parent = &mbx_bus_clk,
517 static void psc_mclk_in_calc(
struct clk *clk)
519 clk->
rate = devtree_getfreq(
"psc_mclk_in");
521 clk->
rate = 25000000;
524 static struct clk psc_mclk_in = {
525 .name =
"psc_mclk_in",
526 .calc = psc_mclk_in_calc,
529 static struct clk spdif_txclk = {
530 .name =
"spdif_txclk",
536 static struct clk spdif_rxclk = {
537 .name =
"spdif_rxclk",
543 static void ac97_clk_calc(
struct clk *clk)
546 clk->
rate = 24567000;
549 static struct clk ac97_clk = {
550 .name =
"ac97_clk_in",
551 .calc = ac97_clk_calc,
584 static void rate_clk_init(
struct clk *clk)
592 "Could not initialize clk %s without a calc routine\n",
597 static void rate_clks_init(
void)
599 struct clk **
cpp, *clk;
602 while ((clk = *cpp++))
616 static struct clk *psc_dev_clk(
int pscnum)
633 static void psc_calc_rate(
struct clk *clk,
int pscnum,
struct device_node *np)
635 unsigned long mclk_src = sys_clk.
rate;
651 if (clockctl->
pccr[pscnum] & 0x80) {
656 switch ((clockctl->
pccr[pscnum] >> 14) & 0x3) {
658 mclk_src = sys_clk.
rate;
661 mclk_src = ref_clk.
rate;
664 mclk_src = psc_mclk_in.
rate;
667 mclk_src = spdif_txclk.
rate;
671 mclk_div = ((clockctl->
pccr[pscnum] >> 17) & 0x7fff) + 1;
680 static void psc_clks_init(
void)
683 const u32 *cell_index;
686 for_each_compatible_node(np,
NULL,
"fsl,mpc5121-psc") {
689 int pscnum = *cell_index;
690 struct clk *clk = psc_dev_clk(pscnum);
702 psc_calc_rate(clk, pscnum, np);
711 .clk_get = mpc5121_clk_get,
712 .clk_enable = mpc5121_clk_enable,
713 .clk_disable = mpc5121_clk_disable,
714 .clk_get_rate = mpc5121_clk_get_rate,
715 .clk_put = mpc5121_clk_put,
716 .clk_round_rate = mpc5121_clk_round_rate,
717 .clk_set_rate = mpc5121_clk_set_rate,
718 .clk_set_parent =
NULL,
719 .clk_get_parent =
NULL,
743 clocks_initialized++;