xref: /linux/arch/sh/kernel/cpu/sh2/clock-sh7619.c (revision 597473720f4dc69749542bfcfed4a927a43d935e)
1*47d11326SKuninori Morimoto // SPDX-License-Identifier: GPL-2.0
29d4436a6SYoshinori Sato /*
39d4436a6SYoshinori Sato  * arch/sh/kernel/cpu/sh2/clock-sh7619.c
49d4436a6SYoshinori Sato  *
59d4436a6SYoshinori Sato  * SH7619 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>
1416b25920SPaul Mundt #include <linux/io.h>
159d4436a6SYoshinori Sato #include <asm/clock.h>
169d4436a6SYoshinori Sato #include <asm/freq.h>
1716b25920SPaul Mundt #include <asm/processor.h>
189d4436a6SYoshinori Sato 
19c5a69d57STobias Klauser static const int pll1rate[] = {1,2};
20c5a69d57STobias Klauser static const int pfc_divisors[] = {1,2,0,4};
2116b25920SPaul Mundt static unsigned int pll2_mult;
229d4436a6SYoshinori Sato 
master_clk_init(struct clk * clk)239d4436a6SYoshinori Sato static void master_clk_init(struct clk *clk)
249d4436a6SYoshinori Sato {
2516b25920SPaul Mundt 	clk->rate *= pll2_mult * pll1rate[(__raw_readw(FREQCR) >> 8) & 7];
269d4436a6SYoshinori Sato }
279d4436a6SYoshinori Sato 
2871984236SMagnus Damm static struct sh_clk_ops sh7619_master_clk_ops = {
299d4436a6SYoshinori Sato 	.init		= master_clk_init,
309d4436a6SYoshinori Sato };
319d4436a6SYoshinori Sato 
module_clk_recalc(struct clk * clk)32b68d8201SPaul Mundt static unsigned long module_clk_recalc(struct clk *clk)
339d4436a6SYoshinori Sato {
349d56dd3bSPaul Mundt 	int idx = (__raw_readw(FREQCR) & 0x0007);
35b68d8201SPaul Mundt 	return clk->parent->rate / pfc_divisors[idx];
369d4436a6SYoshinori Sato }
379d4436a6SYoshinori Sato 
3871984236SMagnus Damm static struct sh_clk_ops sh7619_module_clk_ops = {
399d4436a6SYoshinori Sato 	.recalc		= module_clk_recalc,
409d4436a6SYoshinori Sato };
419d4436a6SYoshinori Sato 
bus_clk_recalc(struct clk * clk)42b68d8201SPaul Mundt static unsigned long bus_clk_recalc(struct clk *clk)
439d4436a6SYoshinori Sato {
449d56dd3bSPaul Mundt 	return clk->parent->rate / pll1rate[(__raw_readw(FREQCR) >> 8) & 7];
459d4436a6SYoshinori Sato }
469d4436a6SYoshinori Sato 
4771984236SMagnus Damm static struct sh_clk_ops sh7619_bus_clk_ops = {
489d4436a6SYoshinori Sato 	.recalc		= bus_clk_recalc,
499d4436a6SYoshinori Sato };
509d4436a6SYoshinori Sato 
5171984236SMagnus Damm static struct sh_clk_ops sh7619_cpu_clk_ops = {
52a02cb230SPaul Mundt 	.recalc		= followparent_recalc,
539d4436a6SYoshinori Sato };
549d4436a6SYoshinori Sato 
5571984236SMagnus Damm static struct sh_clk_ops *sh7619_clk_ops[] = {
569d4436a6SYoshinori Sato 	&sh7619_master_clk_ops,
579d4436a6SYoshinori Sato 	&sh7619_module_clk_ops,
589d4436a6SYoshinori Sato 	&sh7619_bus_clk_ops,
599d4436a6SYoshinori Sato 	&sh7619_cpu_clk_ops,
609d4436a6SYoshinori Sato };
619d4436a6SYoshinori Sato 
arch_init_clk_ops(struct sh_clk_ops ** ops,int idx)6271984236SMagnus Damm void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
639d4436a6SYoshinori Sato {
6416b25920SPaul Mundt 	if (test_mode_pin(MODE_PIN2 | MODE_PIN0) ||
6516b25920SPaul Mundt 	    test_mode_pin(MODE_PIN2 | MODE_PIN1))
6616b25920SPaul Mundt 		pll2_mult = 2;
6716b25920SPaul Mundt 	else if (test_mode_pin(MODE_PIN0) || test_mode_pin(MODE_PIN1))
6816b25920SPaul Mundt 		pll2_mult = 4;
6916b25920SPaul Mundt 
7016b25920SPaul Mundt 	BUG_ON(!pll2_mult);
7116b25920SPaul Mundt 
729d4436a6SYoshinori Sato 	if (idx < ARRAY_SIZE(sh7619_clk_ops))
739d4436a6SYoshinori Sato 		*ops = sh7619_clk_ops[idx];
749d4436a6SYoshinori Sato }
75