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> 179d4436a6SYoshinori Sato #include <asm/clock.h> 189d4436a6SYoshinori Sato #include <asm/freq.h> 199d4436a6SYoshinori Sato #include <asm/io.h> 209d4436a6SYoshinori Sato 21*c5a69d57STobias Klauser static const int pll1rate[] = {1,2}; 22*c5a69d57STobias Klauser static const int pfc_divisors[] = {1,2,0,4}; 239d4436a6SYoshinori Sato 249d4436a6SYoshinori Sato #if (CONFIG_SH_CLK_MD == 1) || (CONFIG_SH_CLK_MD == 2) 259d4436a6SYoshinori Sato #define PLL2 (4) 269d4436a6SYoshinori Sato #elif (CONFIG_SH_CLK_MD == 5) || (CONFIG_SH_CLK_MD == 6) 279d4436a6SYoshinori Sato #define PLL2 (2) 289d4436a6SYoshinori Sato #else 299d4436a6SYoshinori Sato #error "Illigal Clock Mode!" 309d4436a6SYoshinori Sato #endif 319d4436a6SYoshinori Sato 329d4436a6SYoshinori Sato static void master_clk_init(struct clk *clk) 339d4436a6SYoshinori Sato { 349d4436a6SYoshinori Sato clk->rate *= PLL2 * pll1rate[(ctrl_inw(FREQCR) >> 8) & 7]; 359d4436a6SYoshinori Sato } 369d4436a6SYoshinori Sato 379d4436a6SYoshinori Sato static struct clk_ops sh7619_master_clk_ops = { 389d4436a6SYoshinori Sato .init = master_clk_init, 399d4436a6SYoshinori Sato }; 409d4436a6SYoshinori Sato 419d4436a6SYoshinori Sato static void module_clk_recalc(struct clk *clk) 429d4436a6SYoshinori Sato { 439d4436a6SYoshinori Sato int idx = (ctrl_inw(FREQCR) & 0x0007); 449d4436a6SYoshinori Sato clk->rate = clk->parent->rate / pfc_divisors[idx]; 459d4436a6SYoshinori Sato } 469d4436a6SYoshinori Sato 479d4436a6SYoshinori Sato static struct clk_ops sh7619_module_clk_ops = { 489d4436a6SYoshinori Sato .recalc = module_clk_recalc, 499d4436a6SYoshinori Sato }; 509d4436a6SYoshinori Sato 519d4436a6SYoshinori Sato static void bus_clk_recalc(struct clk *clk) 529d4436a6SYoshinori Sato { 539d4436a6SYoshinori Sato clk->rate = clk->parent->rate / pll1rate[(ctrl_inw(FREQCR) >> 8) & 7]; 549d4436a6SYoshinori Sato } 559d4436a6SYoshinori Sato 569d4436a6SYoshinori Sato static struct clk_ops sh7619_bus_clk_ops = { 579d4436a6SYoshinori Sato .recalc = bus_clk_recalc, 589d4436a6SYoshinori Sato }; 599d4436a6SYoshinori Sato 609d4436a6SYoshinori Sato static void cpu_clk_recalc(struct clk *clk) 619d4436a6SYoshinori Sato { 629d4436a6SYoshinori Sato clk->rate = clk->parent->rate; 639d4436a6SYoshinori Sato } 649d4436a6SYoshinori Sato 659d4436a6SYoshinori Sato static struct clk_ops sh7619_cpu_clk_ops = { 669d4436a6SYoshinori Sato .recalc = cpu_clk_recalc, 679d4436a6SYoshinori Sato }; 689d4436a6SYoshinori Sato 699d4436a6SYoshinori Sato static struct clk_ops *sh7619_clk_ops[] = { 709d4436a6SYoshinori Sato &sh7619_master_clk_ops, 719d4436a6SYoshinori Sato &sh7619_module_clk_ops, 729d4436a6SYoshinori Sato &sh7619_bus_clk_ops, 739d4436a6SYoshinori Sato &sh7619_cpu_clk_ops, 749d4436a6SYoshinori Sato }; 759d4436a6SYoshinori Sato 769d4436a6SYoshinori Sato void __init arch_init_clk_ops(struct clk_ops **ops, int idx) 779d4436a6SYoshinori Sato { 789d4436a6SYoshinori Sato if (idx < ARRAY_SIZE(sh7619_clk_ops)) 799d4436a6SYoshinori Sato *ops = sh7619_clk_ops[idx]; 809d4436a6SYoshinori Sato } 819d4436a6SYoshinori Sato 82