xref: /linux/arch/sh/kernel/cpu/sh2/clock-sh7619.c (revision 9d56dd3b083a3bec56e9da35ce07baca81030b03)
19d4436a6SYoshinori Sato /*
29d4436a6SYoshinori Sato  * arch/sh/kernel/cpu/sh2/clock-sh7619.c
39d4436a6SYoshinori Sato  *
49d4436a6SYoshinori Sato  * SH7619 support for the clock framework
59d4436a6SYoshinori Sato  *
69d4436a6SYoshinori Sato  *  Copyright (C) 2006  Yoshinori Sato
79d4436a6SYoshinori Sato  *
89d4436a6SYoshinori Sato  * Based on clock-sh4.c
99d4436a6SYoshinori Sato  *  Copyright (C) 2005  Paul Mundt
109d4436a6SYoshinori Sato  *
119d4436a6SYoshinori Sato  * This file is subject to the terms and conditions of the GNU General Public
129d4436a6SYoshinori Sato  * License.  See the file "COPYING" in the main directory of this archive
139d4436a6SYoshinori Sato  * for more details.
149d4436a6SYoshinori Sato  */
159d4436a6SYoshinori Sato #include <linux/init.h>
169d4436a6SYoshinori Sato #include <linux/kernel.h>
179d4436a6SYoshinori Sato #include <asm/clock.h>
189d4436a6SYoshinori Sato #include <asm/freq.h>
199d4436a6SYoshinori Sato #include <asm/io.h>
209d4436a6SYoshinori Sato 
21c5a69d57STobias Klauser static const int pll1rate[] = {1,2};
22c5a69d57STobias Klauser static const int pfc_divisors[] = {1,2,0,4};
239d4436a6SYoshinori Sato 
249d4436a6SYoshinori Sato #if (CONFIG_SH_CLK_MD == 1) || (CONFIG_SH_CLK_MD == 2)
259d4436a6SYoshinori Sato #define PLL2 (4)
269d4436a6SYoshinori Sato #elif (CONFIG_SH_CLK_MD == 5) || (CONFIG_SH_CLK_MD == 6)
279d4436a6SYoshinori Sato #define PLL2 (2)
289d4436a6SYoshinori Sato #else
299d4436a6SYoshinori Sato #error "Illigal Clock Mode!"
309d4436a6SYoshinori Sato #endif
319d4436a6SYoshinori Sato 
329d4436a6SYoshinori Sato static void master_clk_init(struct clk *clk)
339d4436a6SYoshinori Sato {
34*9d56dd3bSPaul Mundt 	clk->rate *= PLL2 * pll1rate[(__raw_readw(FREQCR) >> 8) & 7];
359d4436a6SYoshinori Sato }
369d4436a6SYoshinori Sato 
379d4436a6SYoshinori Sato static struct clk_ops sh7619_master_clk_ops = {
389d4436a6SYoshinori Sato 	.init		= master_clk_init,
399d4436a6SYoshinori Sato };
409d4436a6SYoshinori Sato 
41b68d8201SPaul Mundt static unsigned long module_clk_recalc(struct clk *clk)
429d4436a6SYoshinori Sato {
43*9d56dd3bSPaul Mundt 	int idx = (__raw_readw(FREQCR) & 0x0007);
44b68d8201SPaul Mundt 	return clk->parent->rate / pfc_divisors[idx];
459d4436a6SYoshinori Sato }
469d4436a6SYoshinori Sato 
479d4436a6SYoshinori Sato static struct clk_ops sh7619_module_clk_ops = {
489d4436a6SYoshinori Sato 	.recalc		= module_clk_recalc,
499d4436a6SYoshinori Sato };
509d4436a6SYoshinori Sato 
51b68d8201SPaul Mundt static unsigned long bus_clk_recalc(struct clk *clk)
529d4436a6SYoshinori Sato {
53*9d56dd3bSPaul Mundt 	return clk->parent->rate / pll1rate[(__raw_readw(FREQCR) >> 8) & 7];
549d4436a6SYoshinori Sato }
559d4436a6SYoshinori Sato 
569d4436a6SYoshinori Sato static struct clk_ops sh7619_bus_clk_ops = {
579d4436a6SYoshinori Sato 	.recalc		= bus_clk_recalc,
589d4436a6SYoshinori Sato };
599d4436a6SYoshinori Sato 
609d4436a6SYoshinori Sato static struct clk_ops sh7619_cpu_clk_ops = {
61a02cb230SPaul Mundt 	.recalc		= followparent_recalc,
629d4436a6SYoshinori Sato };
639d4436a6SYoshinori Sato 
649d4436a6SYoshinori Sato static struct clk_ops *sh7619_clk_ops[] = {
659d4436a6SYoshinori Sato 	&sh7619_master_clk_ops,
669d4436a6SYoshinori Sato 	&sh7619_module_clk_ops,
679d4436a6SYoshinori Sato 	&sh7619_bus_clk_ops,
689d4436a6SYoshinori Sato 	&sh7619_cpu_clk_ops,
699d4436a6SYoshinori Sato };
709d4436a6SYoshinori Sato 
719d4436a6SYoshinori Sato void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
729d4436a6SYoshinori Sato {
739d4436a6SYoshinori Sato 	if (idx < ARRAY_SIZE(sh7619_clk_ops))
749d4436a6SYoshinori Sato 		*ops = sh7619_clk_ops[idx];
759d4436a6SYoshinori Sato }
76