xref: /linux/arch/sh/kernel/cpu/sh4/clock-sh4.c (revision 597473720f4dc69749542bfcfed4a927a43d935e)
1*6ecc0a4dSKuninori Morimoto // SPDX-License-Identifier: GPL-2.0
236ddf31bSPaul Mundt /*
336ddf31bSPaul Mundt  * arch/sh/kernel/cpu/sh4/clock-sh4.c
436ddf31bSPaul Mundt  *
536ddf31bSPaul Mundt  * Generic SH-4 support for the clock framework
636ddf31bSPaul Mundt  *
736ddf31bSPaul Mundt  *  Copyright (C) 2005  Paul Mundt
836ddf31bSPaul Mundt  *
936ddf31bSPaul Mundt  * FRQCR parsing hacked out of arch/sh/kernel/time.c
1036ddf31bSPaul Mundt  *
1136ddf31bSPaul Mundt  *  Copyright (C) 1999  Tetsuya Okada & Niibe Yutaka
1236ddf31bSPaul Mundt  *  Copyright (C) 2000  Philipp Rumpf <prumpf@tux.org>
1336ddf31bSPaul Mundt  *  Copyright (C) 2002, 2003, 2004  Paul Mundt
1436ddf31bSPaul Mundt  *  Copyright (C) 2002  M. R. Brown  <mrbrown@linux-sh.org>
1536ddf31bSPaul Mundt  */
1636ddf31bSPaul Mundt #include <linux/init.h>
1736ddf31bSPaul Mundt #include <linux/kernel.h>
1836ddf31bSPaul Mundt #include <asm/clock.h>
1936ddf31bSPaul Mundt #include <asm/freq.h>
2036ddf31bSPaul Mundt #include <asm/io.h>
2136ddf31bSPaul Mundt 
2236ddf31bSPaul Mundt static int ifc_divisors[] = { 1, 2, 3, 4, 6, 8, 1, 1 };
2336ddf31bSPaul Mundt #define bfc_divisors ifc_divisors	/* Same */
2436ddf31bSPaul Mundt static int pfc_divisors[] = { 2, 3, 4, 6, 8, 2, 2, 2 };
2536ddf31bSPaul Mundt 
master_clk_init(struct clk * clk)2636ddf31bSPaul Mundt static void master_clk_init(struct clk *clk)
2736ddf31bSPaul Mundt {
289d56dd3bSPaul Mundt 	clk->rate *= pfc_divisors[__raw_readw(FRQCR) & 0x0007];
2936ddf31bSPaul Mundt }
3036ddf31bSPaul Mundt 
313b874415SMagnus Damm static struct sh_clk_ops sh4_master_clk_ops = {
3236ddf31bSPaul Mundt 	.init		= master_clk_init,
3336ddf31bSPaul Mundt };
3436ddf31bSPaul Mundt 
module_clk_recalc(struct clk * clk)35b68d8201SPaul Mundt static unsigned long module_clk_recalc(struct clk *clk)
3636ddf31bSPaul Mundt {
379d56dd3bSPaul Mundt 	int idx = (__raw_readw(FRQCR) & 0x0007);
38b68d8201SPaul Mundt 	return clk->parent->rate / pfc_divisors[idx];
3936ddf31bSPaul Mundt }
4036ddf31bSPaul Mundt 
413b874415SMagnus Damm static struct sh_clk_ops sh4_module_clk_ops = {
4236ddf31bSPaul Mundt 	.recalc		= module_clk_recalc,
4336ddf31bSPaul Mundt };
4436ddf31bSPaul Mundt 
bus_clk_recalc(struct clk * clk)45b68d8201SPaul Mundt static unsigned long bus_clk_recalc(struct clk *clk)
4636ddf31bSPaul Mundt {
479d56dd3bSPaul Mundt 	int idx = (__raw_readw(FRQCR) >> 3) & 0x0007;
48b68d8201SPaul Mundt 	return clk->parent->rate / bfc_divisors[idx];
4936ddf31bSPaul Mundt }
5036ddf31bSPaul Mundt 
513b874415SMagnus Damm static struct sh_clk_ops sh4_bus_clk_ops = {
5236ddf31bSPaul Mundt 	.recalc		= bus_clk_recalc,
5336ddf31bSPaul Mundt };
5436ddf31bSPaul Mundt 
cpu_clk_recalc(struct clk * clk)55b68d8201SPaul Mundt static unsigned long cpu_clk_recalc(struct clk *clk)
5636ddf31bSPaul Mundt {
579d56dd3bSPaul Mundt 	int idx = (__raw_readw(FRQCR) >> 6) & 0x0007;
58b68d8201SPaul Mundt 	return clk->parent->rate / ifc_divisors[idx];
5936ddf31bSPaul Mundt }
6036ddf31bSPaul Mundt 
613b874415SMagnus Damm static struct sh_clk_ops sh4_cpu_clk_ops = {
6236ddf31bSPaul Mundt 	.recalc		= cpu_clk_recalc,
6336ddf31bSPaul Mundt };
6436ddf31bSPaul Mundt 
653b874415SMagnus Damm static struct sh_clk_ops *sh4_clk_ops[] = {
6636ddf31bSPaul Mundt 	&sh4_master_clk_ops,
6736ddf31bSPaul Mundt 	&sh4_module_clk_ops,
6836ddf31bSPaul Mundt 	&sh4_bus_clk_ops,
6936ddf31bSPaul Mundt 	&sh4_cpu_clk_ops,
7036ddf31bSPaul Mundt };
7136ddf31bSPaul Mundt 
arch_init_clk_ops(struct sh_clk_ops ** ops,int idx)723b874415SMagnus Damm void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
7336ddf31bSPaul Mundt {
7436ddf31bSPaul Mundt 	if (idx < ARRAY_SIZE(sh4_clk_ops))
7536ddf31bSPaul Mundt 		*ops = sh4_clk_ops[idx];
7636ddf31bSPaul Mundt }
7736ddf31bSPaul Mundt 
78