2 * arch/sh/kernel/cpu/sh3/clock-sh7709.c
4 * SH7709 support for the clock framework
6 * Copyright (C) 2005 Andriy Skulysh
8 * Based on arch/sh/kernel/cpu/sh3/clock-sh7705.c
9 * Copyright (C) 2005 Paul Mundt
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
15 #include <linux/init.h>
16 #include <linux/kernel.h>
17 #include <asm/clock.h>
21 static int stc_multipliers[] = { 1, 2, 4, 8, 3, 6, 1, 1 };
22 static int ifc_divisors[] = { 1, 2, 4, 1, 3, 1, 1, 1 };
23 static int pfc_divisors[] = { 1, 2, 4, 1, 3, 6, 1, 1 };
25 static void set_bus_parent(struct clk *clk)
27 struct clk *bus_clk = clk_get(NULL, "bus_clk");
28 clk->parent = bus_clk;
32 static void master_clk_init(struct clk *clk)
34 int frqcr = ctrl_inw(FRQCR);
35 int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003);
37 clk->rate *= pfc_divisors[idx];
40 static struct clk_ops sh7709_master_clk_ops = {
41 .init = master_clk_init,
44 static void module_clk_recalc(struct clk *clk)
46 int frqcr = ctrl_inw(FRQCR);
47 int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003);
49 clk->rate = clk->parent->rate / pfc_divisors[idx];
52 static struct clk_ops sh7709_module_clk_ops = {
53 #ifdef CLOCK_MODE_0_1_2_7
54 .init = set_bus_parent,
56 .recalc = module_clk_recalc,
59 static void bus_clk_recalc(struct clk *clk)
61 int frqcr = ctrl_inw(FRQCR);
62 int idx = (frqcr & 0x0080) ?
63 ((frqcr & 0x8000) >> 13) | ((frqcr & 0x0030) >> 4) : 1;
65 clk->rate = clk->parent->rate * stc_multipliers[idx];
68 static struct clk_ops sh7709_bus_clk_ops = {
69 .recalc = bus_clk_recalc,
72 static void cpu_clk_recalc(struct clk *clk)
74 int frqcr = ctrl_inw(FRQCR);
75 int idx = ((frqcr & 0x4000) >> 12) | ((frqcr & 0x000c) >> 2);
77 clk->rate = clk->parent->rate / ifc_divisors[idx];
80 static struct clk_ops sh7709_cpu_clk_ops = {
81 .init = set_bus_parent,
82 .recalc = cpu_clk_recalc,
85 static struct clk_ops *sh7709_clk_ops[] = {
86 &sh7709_master_clk_ops,
87 &sh7709_module_clk_ops,
92 void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
94 if (idx < ARRAY_SIZE(sh7709_clk_ops))
95 *ops = sh7709_clk_ops[idx];