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> 17*16b25920SPaul Mundt #include <linux/io.h> 189d4436a6SYoshinori Sato #include <asm/clock.h> 199d4436a6SYoshinori Sato #include <asm/freq.h> 20*16b25920SPaul Mundt #include <asm/processor.h> 219d4436a6SYoshinori Sato 22c5a69d57STobias Klauser static const int pll1rate[] = {1,2}; 23c5a69d57STobias Klauser static const int pfc_divisors[] = {1,2,0,4}; 24*16b25920SPaul Mundt static unsigned int pll2_mult; 259d4436a6SYoshinori Sato 269d4436a6SYoshinori Sato static void master_clk_init(struct clk *clk) 279d4436a6SYoshinori Sato { 28*16b25920SPaul Mundt clk->rate *= pll2_mult * pll1rate[(__raw_readw(FREQCR) >> 8) & 7]; 299d4436a6SYoshinori Sato } 309d4436a6SYoshinori Sato 319d4436a6SYoshinori Sato static struct clk_ops sh7619_master_clk_ops = { 329d4436a6SYoshinori Sato .init = master_clk_init, 339d4436a6SYoshinori Sato }; 349d4436a6SYoshinori Sato 35b68d8201SPaul Mundt static unsigned long module_clk_recalc(struct clk *clk) 369d4436a6SYoshinori Sato { 379d56dd3bSPaul Mundt int idx = (__raw_readw(FREQCR) & 0x0007); 38b68d8201SPaul Mundt return clk->parent->rate / pfc_divisors[idx]; 399d4436a6SYoshinori Sato } 409d4436a6SYoshinori Sato 419d4436a6SYoshinori Sato static struct clk_ops sh7619_module_clk_ops = { 429d4436a6SYoshinori Sato .recalc = module_clk_recalc, 439d4436a6SYoshinori Sato }; 449d4436a6SYoshinori Sato 45b68d8201SPaul Mundt static unsigned long bus_clk_recalc(struct clk *clk) 469d4436a6SYoshinori Sato { 479d56dd3bSPaul Mundt return clk->parent->rate / pll1rate[(__raw_readw(FREQCR) >> 8) & 7]; 489d4436a6SYoshinori Sato } 499d4436a6SYoshinori Sato 509d4436a6SYoshinori Sato static struct clk_ops sh7619_bus_clk_ops = { 519d4436a6SYoshinori Sato .recalc = bus_clk_recalc, 529d4436a6SYoshinori Sato }; 539d4436a6SYoshinori Sato 549d4436a6SYoshinori Sato static struct clk_ops sh7619_cpu_clk_ops = { 55a02cb230SPaul Mundt .recalc = followparent_recalc, 569d4436a6SYoshinori Sato }; 579d4436a6SYoshinori Sato 589d4436a6SYoshinori Sato static struct clk_ops *sh7619_clk_ops[] = { 599d4436a6SYoshinori Sato &sh7619_master_clk_ops, 609d4436a6SYoshinori Sato &sh7619_module_clk_ops, 619d4436a6SYoshinori Sato &sh7619_bus_clk_ops, 629d4436a6SYoshinori Sato &sh7619_cpu_clk_ops, 639d4436a6SYoshinori Sato }; 649d4436a6SYoshinori Sato 659d4436a6SYoshinori Sato void __init arch_init_clk_ops(struct clk_ops **ops, int idx) 669d4436a6SYoshinori Sato { 67*16b25920SPaul Mundt if (test_mode_pin(MODE_PIN2 | MODE_PIN0) || 68*16b25920SPaul Mundt test_mode_pin(MODE_PIN2 | MODE_PIN1)) 69*16b25920SPaul Mundt pll2_mult = 2; 70*16b25920SPaul Mundt else if (test_mode_pin(MODE_PIN0) || test_mode_pin(MODE_PIN1)) 71*16b25920SPaul Mundt pll2_mult = 4; 72*16b25920SPaul Mundt 73*16b25920SPaul Mundt BUG_ON(!pll2_mult); 74*16b25920SPaul Mundt 759d4436a6SYoshinori Sato if (idx < ARRAY_SIZE(sh7619_clk_ops)) 769d4436a6SYoshinori Sato *ops = sh7619_clk_ops[idx]; 779d4436a6SYoshinori Sato } 78