xref: /linux/arch/sh/kernel/cpu/sh2a/clock-sh7203.c (revision 4ad2c061550faa8def698fa7c2e4f1c81e90ac18)
16d01f510SPaul Mundt /*
26d01f510SPaul Mundt  * arch/sh/kernel/cpu/sh2a/clock-sh7203.c
36d01f510SPaul Mundt  *
46d01f510SPaul Mundt  * SH7203 support for the clock framework
56d01f510SPaul Mundt  *
66d01f510SPaul Mundt  *  Copyright (C) 2007 Kieran Bingham (MPC-Data Ltd)
76d01f510SPaul Mundt  *
86d01f510SPaul Mundt  * Based on clock-sh7263.c
96d01f510SPaul Mundt  *  Copyright (C) 2006  Yoshinori Sato
106d01f510SPaul Mundt  *
116d01f510SPaul Mundt  * Based on clock-sh4.c
126d01f510SPaul Mundt  *  Copyright (C) 2005  Paul Mundt
136d01f510SPaul Mundt  *
146d01f510SPaul Mundt  * This file is subject to the terms and conditions of the GNU General Public
156d01f510SPaul Mundt  * License.  See the file "COPYING" in the main directory of this archive
166d01f510SPaul Mundt  * for more details.
176d01f510SPaul Mundt  */
186d01f510SPaul Mundt #include <linux/init.h>
196d01f510SPaul Mundt #include <linux/kernel.h>
206d01f510SPaul Mundt #include <asm/clock.h>
216d01f510SPaul Mundt #include <asm/freq.h>
226d01f510SPaul Mundt #include <asm/io.h>
236d01f510SPaul Mundt 
244377e605STobias Klauser static const int pll1rate[]={8,12,16,0};
254377e605STobias Klauser static const int pfc_divisors[]={1,2,3,4,6,8,12};
266d01f510SPaul Mundt #define ifc_divisors pfc_divisors
276d01f510SPaul Mundt 
2816b25920SPaul Mundt static unsigned int pll2_mult;
296d01f510SPaul Mundt 
306d01f510SPaul Mundt static void master_clk_init(struct clk *clk)
316d01f510SPaul Mundt {
3216b25920SPaul Mundt 	clk->rate *= pll1rate[(__raw_readw(FREQCR) >> 8) & 0x0003] * pll2_mult;
336d01f510SPaul Mundt }
346d01f510SPaul Mundt 
35*4ad2c061SMagnus Damm static struct sh_clk_ops sh7203_master_clk_ops = {
366d01f510SPaul Mundt 	.init		= master_clk_init,
376d01f510SPaul Mundt };
386d01f510SPaul Mundt 
39b68d8201SPaul Mundt static unsigned long module_clk_recalc(struct clk *clk)
406d01f510SPaul Mundt {
419d56dd3bSPaul Mundt 	int idx = (__raw_readw(FREQCR) & 0x0007);
42b68d8201SPaul Mundt 	return clk->parent->rate / pfc_divisors[idx];
436d01f510SPaul Mundt }
446d01f510SPaul Mundt 
45*4ad2c061SMagnus Damm static struct sh_clk_ops sh7203_module_clk_ops = {
466d01f510SPaul Mundt 	.recalc		= module_clk_recalc,
476d01f510SPaul Mundt };
486d01f510SPaul Mundt 
49b68d8201SPaul Mundt static unsigned long bus_clk_recalc(struct clk *clk)
506d01f510SPaul Mundt {
519d56dd3bSPaul Mundt 	int idx = (__raw_readw(FREQCR) & 0x0007);
52b68d8201SPaul Mundt 	return clk->parent->rate / pfc_divisors[idx-2];
536d01f510SPaul Mundt }
546d01f510SPaul Mundt 
55*4ad2c061SMagnus Damm static struct sh_clk_ops sh7203_bus_clk_ops = {
566d01f510SPaul Mundt 	.recalc		= bus_clk_recalc,
576d01f510SPaul Mundt };
586d01f510SPaul Mundt 
59*4ad2c061SMagnus Damm static struct sh_clk_ops sh7203_cpu_clk_ops = {
60a02cb230SPaul Mundt 	.recalc		= followparent_recalc,
616d01f510SPaul Mundt };
626d01f510SPaul Mundt 
63*4ad2c061SMagnus Damm static struct sh_clk_ops *sh7203_clk_ops[] = {
646d01f510SPaul Mundt 	&sh7203_master_clk_ops,
656d01f510SPaul Mundt 	&sh7203_module_clk_ops,
666d01f510SPaul Mundt 	&sh7203_bus_clk_ops,
676d01f510SPaul Mundt 	&sh7203_cpu_clk_ops,
686d01f510SPaul Mundt };
696d01f510SPaul Mundt 
70*4ad2c061SMagnus Damm void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
716d01f510SPaul Mundt {
7216b25920SPaul Mundt 	if (test_mode_pin(MODE_PIN1))
7316b25920SPaul Mundt 		pll2_mult = 4;
7416b25920SPaul Mundt 	else if (test_mode_pin(MODE_PIN0))
7516b25920SPaul Mundt 		pll2_mult = 2;
7616b25920SPaul Mundt 	else
7716b25920SPaul Mundt 		pll2_mult = 1;
7816b25920SPaul Mundt 
796d01f510SPaul Mundt 	if (idx < ARRAY_SIZE(sh7203_clk_ops))
806d01f510SPaul Mundt 		*ops = sh7203_clk_ops[idx];
816d01f510SPaul Mundt }
82