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> 1716b25920SPaul Mundt #include <linux/io.h> 189d4436a6SYoshinori Sato #include <asm/clock.h> 199d4436a6SYoshinori Sato #include <asm/freq.h> 2016b25920SPaul 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}; 2416b25920SPaul Mundt static unsigned int pll2_mult; 259d4436a6SYoshinori Sato 269d4436a6SYoshinori Sato static void master_clk_init(struct clk *clk) 279d4436a6SYoshinori Sato { 2816b25920SPaul Mundt clk->rate *= pll2_mult * pll1rate[(__raw_readw(FREQCR) >> 8) & 7]; 299d4436a6SYoshinori Sato } 309d4436a6SYoshinori Sato 31*71984236SMagnus Damm static struct sh_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 41*71984236SMagnus Damm static struct sh_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 50*71984236SMagnus Damm static struct sh_clk_ops sh7619_bus_clk_ops = { 519d4436a6SYoshinori Sato .recalc = bus_clk_recalc, 529d4436a6SYoshinori Sato }; 539d4436a6SYoshinori Sato 54*71984236SMagnus Damm static struct sh_clk_ops sh7619_cpu_clk_ops = { 55a02cb230SPaul Mundt .recalc = followparent_recalc, 569d4436a6SYoshinori Sato }; 579d4436a6SYoshinori Sato 58*71984236SMagnus Damm static struct sh_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 65*71984236SMagnus Damm void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx) 669d4436a6SYoshinori Sato { 6716b25920SPaul Mundt if (test_mode_pin(MODE_PIN2 | MODE_PIN0) || 6816b25920SPaul Mundt test_mode_pin(MODE_PIN2 | MODE_PIN1)) 6916b25920SPaul Mundt pll2_mult = 2; 7016b25920SPaul Mundt else if (test_mode_pin(MODE_PIN0) || test_mode_pin(MODE_PIN1)) 7116b25920SPaul Mundt pll2_mult = 4; 7216b25920SPaul Mundt 7316b25920SPaul Mundt BUG_ON(!pll2_mult); 7416b25920SPaul Mundt 759d4436a6SYoshinori Sato if (idx < ARRAY_SIZE(sh7619_clk_ops)) 769d4436a6SYoshinori Sato *ops = sh7619_clk_ops[idx]; 779d4436a6SYoshinori Sato } 78