blob: 150963a6001e714a1f69fac95b66147f57be44fb [file] [log] [blame]
Paul Mundt36ddf312006-01-16 22:14:17 -08001/*
Uwe Kleine-König58862692007-05-09 07:51:49 +02002 * arch/sh/kernel/cpu/sh4a/clock-sh7780.c
Paul Mundt36ddf312006-01-16 22:14:17 -08003 *
4 * SH7780 support for the clock framework
5 *
6 * Copyright (C) 2005 Paul Mundt
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <asm/clock.h>
15#include <asm/freq.h>
16#include <asm/io.h>
17
18static int ifc_divisors[] = { 2, 4 };
19static int bfc_divisors[] = { 1, 1, 1, 8, 12, 16, 24, 1 };
20static int pfc_divisors[] = { 1, 24, 24, 1 };
21static int cfc_divisors[] = { 1, 1, 4, 1, 6, 1, 1, 1 };
22
23static void master_clk_init(struct clk *clk)
24{
Paul Mundt9d56dd32010-01-26 12:58:40 +090025 clk->rate *= pfc_divisors[__raw_readl(FRQCR) & 0x0003];
Paul Mundt36ddf312006-01-16 22:14:17 -080026}
27
28static struct clk_ops sh7780_master_clk_ops = {
29 .init = master_clk_init,
30};
31
Paul Mundtb68d82012009-05-12 03:45:08 +090032static unsigned long module_clk_recalc(struct clk *clk)
Paul Mundt36ddf312006-01-16 22:14:17 -080033{
Paul Mundt9d56dd32010-01-26 12:58:40 +090034 int idx = (__raw_readl(FRQCR) & 0x0003);
Paul Mundtb68d82012009-05-12 03:45:08 +090035 return clk->parent->rate / pfc_divisors[idx];
Paul Mundt36ddf312006-01-16 22:14:17 -080036}
37
38static struct clk_ops sh7780_module_clk_ops = {
39 .recalc = module_clk_recalc,
40};
41
Paul Mundtb68d82012009-05-12 03:45:08 +090042static unsigned long bus_clk_recalc(struct clk *clk)
Paul Mundt36ddf312006-01-16 22:14:17 -080043{
Paul Mundt9d56dd32010-01-26 12:58:40 +090044 int idx = ((__raw_readl(FRQCR) >> 16) & 0x0007);
Paul Mundtb68d82012009-05-12 03:45:08 +090045 return clk->parent->rate / bfc_divisors[idx];
Paul Mundt36ddf312006-01-16 22:14:17 -080046}
47
48static struct clk_ops sh7780_bus_clk_ops = {
49 .recalc = bus_clk_recalc,
50};
51
Paul Mundtb68d82012009-05-12 03:45:08 +090052static unsigned long cpu_clk_recalc(struct clk *clk)
Paul Mundt36ddf312006-01-16 22:14:17 -080053{
Paul Mundt9d56dd32010-01-26 12:58:40 +090054 int idx = ((__raw_readl(FRQCR) >> 24) & 0x0001);
Paul Mundtb68d82012009-05-12 03:45:08 +090055 return clk->parent->rate / ifc_divisors[idx];
Paul Mundt36ddf312006-01-16 22:14:17 -080056}
57
58static struct clk_ops sh7780_cpu_clk_ops = {
59 .recalc = cpu_clk_recalc,
60};
61
62static struct clk_ops *sh7780_clk_ops[] = {
63 &sh7780_master_clk_ops,
64 &sh7780_module_clk_ops,
65 &sh7780_bus_clk_ops,
66 &sh7780_cpu_clk_ops,
67};
68
69void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
70{
71 if (idx < ARRAY_SIZE(sh7780_clk_ops))
72 *ops = sh7780_clk_ops[idx];
73}
74
Paul Mundtb68d82012009-05-12 03:45:08 +090075static unsigned long shyway_clk_recalc(struct clk *clk)
Paul Mundt36ddf312006-01-16 22:14:17 -080076{
Paul Mundt9d56dd32010-01-26 12:58:40 +090077 int idx = ((__raw_readl(FRQCR) >> 20) & 0x0007);
Paul Mundtb68d82012009-05-12 03:45:08 +090078 return clk->parent->rate / cfc_divisors[idx];
Paul Mundt36ddf312006-01-16 22:14:17 -080079}
80
81static struct clk_ops sh7780_shyway_clk_ops = {
82 .recalc = shyway_clk_recalc,
83};
84
85static struct clk sh7780_shyway_clk = {
86 .name = "shyway_clk",
Paul Mundt4ff29ff2009-05-12 05:14:53 +090087 .flags = CLK_ENABLE_ON_INIT,
Paul Mundt36ddf312006-01-16 22:14:17 -080088 .ops = &sh7780_shyway_clk_ops,
89};
90
91/*
92 * Additional SH7780-specific on-chip clocks that aren't already part of the
93 * clock framework
94 */
95static struct clk *sh7780_onchip_clocks[] = {
96 &sh7780_shyway_clk,
97};
98
Paul Mundt9fe5ee02009-05-12 19:29:04 +090099int __init arch_clk_init(void)
Paul Mundt36ddf312006-01-16 22:14:17 -0800100{
Paul Mundt253b0882009-05-13 17:38:11 +0900101 struct clk *clk;
Paul Mundtf5c84cf2009-05-12 05:59:27 +0900102 int i, ret = 0;
Paul Mundt36ddf312006-01-16 22:14:17 -0800103
Paul Mundt253b0882009-05-13 17:38:11 +0900104 cpg_clk_init();
105
106 clk = clk_get(NULL, "master_clk");
Paul Mundt36ddf312006-01-16 22:14:17 -0800107 for (i = 0; i < ARRAY_SIZE(sh7780_onchip_clocks); i++) {
108 struct clk *clkp = sh7780_onchip_clocks[i];
109
110 clkp->parent = clk;
Paul Mundtf5c84cf2009-05-12 05:59:27 +0900111 ret |= clk_register(clkp);
Paul Mundt36ddf312006-01-16 22:14:17 -0800112 }
113
Paul Mundt36ddf312006-01-16 22:14:17 -0800114 clk_put(clk);
115
Paul Mundtf5c84cf2009-05-12 05:59:27 +0900116 return ret;
Paul Mundt36ddf312006-01-16 22:14:17 -0800117}