1*234a0538SKuninori Morimoto // SPDX-License-Identifier: GPL-2.0
29d4436a6SYoshinori Sato /*
39d4436a6SYoshinori Sato * arch/sh/kernel/cpu/sh2a/clock-sh7206.c
49d4436a6SYoshinori Sato *
59d4436a6SYoshinori Sato * SH7206 support for the clock framework
69d4436a6SYoshinori Sato *
79d4436a6SYoshinori Sato * Copyright (C) 2006 Yoshinori Sato
89d4436a6SYoshinori Sato *
99d4436a6SYoshinori Sato * Based on clock-sh4.c
109d4436a6SYoshinori Sato * Copyright (C) 2005 Paul Mundt
119d4436a6SYoshinori Sato */
129d4436a6SYoshinori Sato #include <linux/init.h>
139d4436a6SYoshinori Sato #include <linux/kernel.h>
149d4436a6SYoshinori Sato #include <asm/clock.h>
159d4436a6SYoshinori Sato #include <asm/freq.h>
169d4436a6SYoshinori Sato #include <asm/io.h>
179d4436a6SYoshinori Sato
18c5a69d57STobias Klauser static const int pll1rate[]={1,2,3,4,6,8};
19c5a69d57STobias Klauser static const int pfc_divisors[]={1,2,3,4,6,8,12};
209d4436a6SYoshinori Sato #define ifc_divisors pfc_divisors
219d4436a6SYoshinori Sato
2216b25920SPaul Mundt static unsigned int pll2_mult;
239d4436a6SYoshinori Sato
master_clk_init(struct clk * clk)249d4436a6SYoshinori Sato static void master_clk_init(struct clk *clk)
259d4436a6SYoshinori Sato {
2616b25920SPaul Mundt clk->rate *= pll2_mult * pll1rate[(__raw_readw(FREQCR) >> 8) & 0x0007];
279d4436a6SYoshinori Sato }
289d4436a6SYoshinori Sato
294ad2c061SMagnus Damm static struct sh_clk_ops sh7206_master_clk_ops = {
309d4436a6SYoshinori Sato .init = master_clk_init,
319d4436a6SYoshinori Sato };
329d4436a6SYoshinori Sato
module_clk_recalc(struct clk * clk)33b68d8201SPaul Mundt static unsigned long module_clk_recalc(struct clk *clk)
349d4436a6SYoshinori Sato {
359d56dd3bSPaul Mundt int idx = (__raw_readw(FREQCR) & 0x0007);
36b68d8201SPaul Mundt return clk->parent->rate / pfc_divisors[idx];
379d4436a6SYoshinori Sato }
389d4436a6SYoshinori Sato
394ad2c061SMagnus Damm static struct sh_clk_ops sh7206_module_clk_ops = {
409d4436a6SYoshinori Sato .recalc = module_clk_recalc,
419d4436a6SYoshinori Sato };
429d4436a6SYoshinori Sato
bus_clk_recalc(struct clk * clk)43b68d8201SPaul Mundt static unsigned long bus_clk_recalc(struct clk *clk)
449d4436a6SYoshinori Sato {
459d56dd3bSPaul Mundt return clk->parent->rate / pll1rate[(__raw_readw(FREQCR) >> 8) & 0x0007];
469d4436a6SYoshinori Sato }
479d4436a6SYoshinori Sato
484ad2c061SMagnus Damm static struct sh_clk_ops sh7206_bus_clk_ops = {
499d4436a6SYoshinori Sato .recalc = bus_clk_recalc,
509d4436a6SYoshinori Sato };
519d4436a6SYoshinori Sato
cpu_clk_recalc(struct clk * clk)52b68d8201SPaul Mundt static unsigned long cpu_clk_recalc(struct clk *clk)
539d4436a6SYoshinori Sato {
549d56dd3bSPaul Mundt int idx = (__raw_readw(FREQCR) & 0x0007);
55b68d8201SPaul Mundt return clk->parent->rate / ifc_divisors[idx];
569d4436a6SYoshinori Sato }
579d4436a6SYoshinori Sato
584ad2c061SMagnus Damm static struct sh_clk_ops sh7206_cpu_clk_ops = {
599d4436a6SYoshinori Sato .recalc = cpu_clk_recalc,
609d4436a6SYoshinori Sato };
619d4436a6SYoshinori Sato
624ad2c061SMagnus Damm static struct sh_clk_ops *sh7206_clk_ops[] = {
639d4436a6SYoshinori Sato &sh7206_master_clk_ops,
649d4436a6SYoshinori Sato &sh7206_module_clk_ops,
659d4436a6SYoshinori Sato &sh7206_bus_clk_ops,
669d4436a6SYoshinori Sato &sh7206_cpu_clk_ops,
679d4436a6SYoshinori Sato };
689d4436a6SYoshinori Sato
arch_init_clk_ops(struct sh_clk_ops ** ops,int idx)694ad2c061SMagnus Damm void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
709d4436a6SYoshinori Sato {
7116b25920SPaul Mundt if (test_mode_pin(MODE_PIN2 | MODE_PIN1 | MODE_PIN0))
7216b25920SPaul Mundt pll2_mult = 1;
7316b25920SPaul Mundt else if (test_mode_pin(MODE_PIN2 | MODE_PIN1))
7416b25920SPaul Mundt pll2_mult = 2;
7516b25920SPaul Mundt else if (test_mode_pin(MODE_PIN1))
7616b25920SPaul Mundt pll2_mult = 4;
7716b25920SPaul Mundt
789d4436a6SYoshinori Sato if (idx < ARRAY_SIZE(sh7206_clk_ops))
799d4436a6SYoshinori Sato *ops = sh7206_clk_ops[idx];
809d4436a6SYoshinori Sato }
81