136ddf31bSPaul Mundt /* 236ddf31bSPaul Mundt * arch/sh/kernel/cpu/sh4/clock-sh4.c 336ddf31bSPaul Mundt * 436ddf31bSPaul Mundt * Generic SH-4 support for the clock framework 536ddf31bSPaul Mundt * 636ddf31bSPaul Mundt * Copyright (C) 2005 Paul Mundt 736ddf31bSPaul Mundt * 836ddf31bSPaul Mundt * FRQCR parsing hacked out of arch/sh/kernel/time.c 936ddf31bSPaul Mundt * 1036ddf31bSPaul Mundt * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka 1136ddf31bSPaul Mundt * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org> 1236ddf31bSPaul Mundt * Copyright (C) 2002, 2003, 2004 Paul Mundt 1336ddf31bSPaul Mundt * Copyright (C) 2002 M. R. Brown <mrbrown@linux-sh.org> 1436ddf31bSPaul Mundt * 1536ddf31bSPaul Mundt * This file is subject to the terms and conditions of the GNU General Public 1636ddf31bSPaul Mundt * License. See the file "COPYING" in the main directory of this archive 1736ddf31bSPaul Mundt * for more details. 1836ddf31bSPaul Mundt */ 1936ddf31bSPaul Mundt #include <linux/init.h> 2036ddf31bSPaul Mundt #include <linux/kernel.h> 2136ddf31bSPaul Mundt #include <asm/clock.h> 2236ddf31bSPaul Mundt #include <asm/freq.h> 2336ddf31bSPaul Mundt #include <asm/io.h> 2436ddf31bSPaul Mundt 2536ddf31bSPaul Mundt static int ifc_divisors[] = { 1, 2, 3, 4, 6, 8, 1, 1 }; 2636ddf31bSPaul Mundt #define bfc_divisors ifc_divisors /* Same */ 2736ddf31bSPaul Mundt static int pfc_divisors[] = { 2, 3, 4, 6, 8, 2, 2, 2 }; 2836ddf31bSPaul Mundt 2936ddf31bSPaul Mundt static void master_clk_init(struct clk *clk) 3036ddf31bSPaul Mundt { 31*9d56dd3bSPaul Mundt clk->rate *= pfc_divisors[__raw_readw(FRQCR) & 0x0007]; 3236ddf31bSPaul Mundt } 3336ddf31bSPaul Mundt 3436ddf31bSPaul Mundt static struct clk_ops sh4_master_clk_ops = { 3536ddf31bSPaul Mundt .init = master_clk_init, 3636ddf31bSPaul Mundt }; 3736ddf31bSPaul Mundt 38b68d8201SPaul Mundt static unsigned long module_clk_recalc(struct clk *clk) 3936ddf31bSPaul Mundt { 40*9d56dd3bSPaul Mundt int idx = (__raw_readw(FRQCR) & 0x0007); 41b68d8201SPaul Mundt return clk->parent->rate / pfc_divisors[idx]; 4236ddf31bSPaul Mundt } 4336ddf31bSPaul Mundt 4436ddf31bSPaul Mundt static struct clk_ops sh4_module_clk_ops = { 4536ddf31bSPaul Mundt .recalc = module_clk_recalc, 4636ddf31bSPaul Mundt }; 4736ddf31bSPaul Mundt 48b68d8201SPaul Mundt static unsigned long bus_clk_recalc(struct clk *clk) 4936ddf31bSPaul Mundt { 50*9d56dd3bSPaul Mundt int idx = (__raw_readw(FRQCR) >> 3) & 0x0007; 51b68d8201SPaul Mundt return clk->parent->rate / bfc_divisors[idx]; 5236ddf31bSPaul Mundt } 5336ddf31bSPaul Mundt 5436ddf31bSPaul Mundt static struct clk_ops sh4_bus_clk_ops = { 5536ddf31bSPaul Mundt .recalc = bus_clk_recalc, 5636ddf31bSPaul Mundt }; 5736ddf31bSPaul Mundt 58b68d8201SPaul Mundt static unsigned long cpu_clk_recalc(struct clk *clk) 5936ddf31bSPaul Mundt { 60*9d56dd3bSPaul Mundt int idx = (__raw_readw(FRQCR) >> 6) & 0x0007; 61b68d8201SPaul Mundt return clk->parent->rate / ifc_divisors[idx]; 6236ddf31bSPaul Mundt } 6336ddf31bSPaul Mundt 6436ddf31bSPaul Mundt static struct clk_ops sh4_cpu_clk_ops = { 6536ddf31bSPaul Mundt .recalc = cpu_clk_recalc, 6636ddf31bSPaul Mundt }; 6736ddf31bSPaul Mundt 6836ddf31bSPaul Mundt static struct clk_ops *sh4_clk_ops[] = { 6936ddf31bSPaul Mundt &sh4_master_clk_ops, 7036ddf31bSPaul Mundt &sh4_module_clk_ops, 7136ddf31bSPaul Mundt &sh4_bus_clk_ops, 7236ddf31bSPaul Mundt &sh4_cpu_clk_ops, 7336ddf31bSPaul Mundt }; 7436ddf31bSPaul Mundt 7536ddf31bSPaul Mundt void __init arch_init_clk_ops(struct clk_ops **ops, int idx) 7636ddf31bSPaul Mundt { 7736ddf31bSPaul Mundt if (idx < ARRAY_SIZE(sh4_clk_ops)) 7836ddf31bSPaul Mundt *ops = sh4_clk_ops[idx]; 7936ddf31bSPaul Mundt } 8036ddf31bSPaul Mundt 81