Merge tag 'probes-fixes-v6.16-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / arch / sh / kernel / cpu / sh4a / clock-sh7780.c
CommitLineData
add5ca2c 1// SPDX-License-Identifier: GPL-2.0
36ddf31b 2/*
58862699 3 * arch/sh/kernel/cpu/sh4a/clock-sh7780.c
36ddf31b
PM
4 *
5 * SH7780 support for the clock framework
6 *
7 * Copyright (C) 2005 Paul Mundt
36ddf31b
PM
8 */
9#include <linux/init.h>
10#include <linux/kernel.h>
29497ec4 11#include <linux/io.h>
6d803ba7 12#include <linux/clkdev.h>
36ddf31b
PM
13#include <asm/clock.h>
14#include <asm/freq.h>
15#include <asm/io.h>
16
17static int ifc_divisors[] = { 2, 4 };
18static int bfc_divisors[] = { 1, 1, 1, 8, 12, 16, 24, 1 };
19static int pfc_divisors[] = { 1, 24, 24, 1 };
20static int cfc_divisors[] = { 1, 1, 4, 1, 6, 1, 1, 1 };
21
22static void master_clk_init(struct clk *clk)
23{
9d56dd3b 24 clk->rate *= pfc_divisors[__raw_readl(FRQCR) & 0x0003];
36ddf31b
PM
25}
26
33cb61a4 27static struct sh_clk_ops sh7780_master_clk_ops = {
36ddf31b
PM
28 .init = master_clk_init,
29};
30
b68d8201 31static unsigned long module_clk_recalc(struct clk *clk)
36ddf31b 32{
9d56dd3b 33 int idx = (__raw_readl(FRQCR) & 0x0003);
b68d8201 34 return clk->parent->rate / pfc_divisors[idx];
36ddf31b
PM
35}
36
33cb61a4 37static struct sh_clk_ops sh7780_module_clk_ops = {
36ddf31b
PM
38 .recalc = module_clk_recalc,
39};
40
b68d8201 41static unsigned long bus_clk_recalc(struct clk *clk)
36ddf31b 42{
9d56dd3b 43 int idx = ((__raw_readl(FRQCR) >> 16) & 0x0007);
b68d8201 44 return clk->parent->rate / bfc_divisors[idx];
36ddf31b
PM
45}
46
33cb61a4 47static struct sh_clk_ops sh7780_bus_clk_ops = {
36ddf31b
PM
48 .recalc = bus_clk_recalc,
49};
50
b68d8201 51static unsigned long cpu_clk_recalc(struct clk *clk)
36ddf31b 52{
9d56dd3b 53 int idx = ((__raw_readl(FRQCR) >> 24) & 0x0001);
b68d8201 54 return clk->parent->rate / ifc_divisors[idx];
36ddf31b
PM
55}
56
33cb61a4 57static struct sh_clk_ops sh7780_cpu_clk_ops = {
36ddf31b
PM
58 .recalc = cpu_clk_recalc,
59};
60
33cb61a4 61static struct sh_clk_ops *sh7780_clk_ops[] = {
36ddf31b
PM
62 &sh7780_master_clk_ops,
63 &sh7780_module_clk_ops,
64 &sh7780_bus_clk_ops,
65 &sh7780_cpu_clk_ops,
66};
67
33cb61a4 68void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
36ddf31b
PM
69{
70 if (idx < ARRAY_SIZE(sh7780_clk_ops))
71 *ops = sh7780_clk_ops[idx];
72}
73
b68d8201 74static unsigned long shyway_clk_recalc(struct clk *clk)
36ddf31b 75{
9d56dd3b 76 int idx = ((__raw_readl(FRQCR) >> 20) & 0x0007);
b68d8201 77 return clk->parent->rate / cfc_divisors[idx];
36ddf31b
PM
78}
79
33cb61a4 80static struct sh_clk_ops sh7780_shyway_clk_ops = {
36ddf31b
PM
81 .recalc = shyway_clk_recalc,
82};
83
84static struct clk sh7780_shyway_clk = {
4ff29ff8 85 .flags = CLK_ENABLE_ON_INIT,
36ddf31b
PM
86 .ops = &sh7780_shyway_clk_ops,
87};
88
89/*
90 * Additional SH7780-specific on-chip clocks that aren't already part of the
91 * clock framework
92 */
93static struct clk *sh7780_onchip_clocks[] = {
94 &sh7780_shyway_clk,
95};
96
29497ec4
MD
97static struct clk_lookup lookups[] = {
98 /* main clocks */
99 CLKDEV_CON_ID("shyway_clk", &sh7780_shyway_clk),
100};
101
9fe5ee0e 102int __init arch_clk_init(void)
36ddf31b 103{
253b0887 104 struct clk *clk;
f5c84cf5 105 int i, ret = 0;
36ddf31b 106
253b0887
PM
107 cpg_clk_init();
108
109 clk = clk_get(NULL, "master_clk");
36ddf31b
PM
110 for (i = 0; i < ARRAY_SIZE(sh7780_onchip_clocks); i++) {
111 struct clk *clkp = sh7780_onchip_clocks[i];
112
113 clkp->parent = clk;
f5c84cf5 114 ret |= clk_register(clkp);
36ddf31b
PM
115 }
116
36ddf31b
PM
117 clk_put(clk);
118
29497ec4
MD
119 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
120
f5c84cf5 121 return ret;
36ddf31b 122}