Loading...
1/*
2 * arch/sh/kernel/cpu/sh3/clock-sh7710.c
3 *
4 * SH7710 support for the clock framework
5 *
6 * Copyright (C) 2005 Paul Mundt
7 *
8 * FRQCR parsing hacked out of arch/sh/kernel/time.c
9 *
10 * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
11 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
12 * Copyright (C) 2002, 2003, 2004 Paul Mundt
13 * Copyright (C) 2002 M. R. Brown <mrbrown@linux-sh.org>
14 *
15 * This file is subject to the terms and conditions of the GNU General Public
16 * License. See the file "COPYING" in the main directory of this archive
17 * for more details.
18 */
19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <asm/clock.h>
22#include <asm/freq.h>
23#include <asm/io.h>
24
25static int md_table[] = { 1, 2, 3, 4, 6, 8, 12 };
26
27static void master_clk_init(struct clk *clk)
28{
29 clk->rate *= md_table[__raw_readw(FRQCR) & 0x0007];
30}
31
32static struct sh_clk_ops sh7710_master_clk_ops = {
33 .init = master_clk_init,
34};
35
36static unsigned long module_clk_recalc(struct clk *clk)
37{
38 int idx = (__raw_readw(FRQCR) & 0x0007);
39 return clk->parent->rate / md_table[idx];
40}
41
42static struct sh_clk_ops sh7710_module_clk_ops = {
43 .recalc = module_clk_recalc,
44};
45
46static unsigned long bus_clk_recalc(struct clk *clk)
47{
48 int idx = (__raw_readw(FRQCR) & 0x0700) >> 8;
49 return clk->parent->rate / md_table[idx];
50}
51
52static struct sh_clk_ops sh7710_bus_clk_ops = {
53 .recalc = bus_clk_recalc,
54};
55
56static unsigned long cpu_clk_recalc(struct clk *clk)
57{
58 int idx = (__raw_readw(FRQCR) & 0x0070) >> 4;
59 return clk->parent->rate / md_table[idx];
60}
61
62static struct sh_clk_ops sh7710_cpu_clk_ops = {
63 .recalc = cpu_clk_recalc,
64};
65
66static struct sh_clk_ops *sh7710_clk_ops[] = {
67 &sh7710_master_clk_ops,
68 &sh7710_module_clk_ops,
69 &sh7710_bus_clk_ops,
70 &sh7710_cpu_clk_ops,
71};
72
73void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
74{
75 if (idx < ARRAY_SIZE(sh7710_clk_ops))
76 *ops = sh7710_clk_ops[idx];
77}
78
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * arch/sh/kernel/cpu/sh3/clock-sh7710.c
4 *
5 * SH7710 support for the clock framework
6 *
7 * Copyright (C) 2005 Paul Mundt
8 *
9 * FRQCR parsing hacked out of arch/sh/kernel/time.c
10 *
11 * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
12 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
13 * Copyright (C) 2002, 2003, 2004 Paul Mundt
14 * Copyright (C) 2002 M. R. Brown <mrbrown@linux-sh.org>
15 */
16#include <linux/init.h>
17#include <linux/kernel.h>
18#include <asm/clock.h>
19#include <asm/freq.h>
20#include <asm/io.h>
21
22static int md_table[] = { 1, 2, 3, 4, 6, 8, 12 };
23
24static void master_clk_init(struct clk *clk)
25{
26 clk->rate *= md_table[__raw_readw(FRQCR) & 0x0007];
27}
28
29static struct sh_clk_ops sh7710_master_clk_ops = {
30 .init = master_clk_init,
31};
32
33static unsigned long module_clk_recalc(struct clk *clk)
34{
35 int idx = (__raw_readw(FRQCR) & 0x0007);
36 return clk->parent->rate / md_table[idx];
37}
38
39static struct sh_clk_ops sh7710_module_clk_ops = {
40 .recalc = module_clk_recalc,
41};
42
43static unsigned long bus_clk_recalc(struct clk *clk)
44{
45 int idx = (__raw_readw(FRQCR) & 0x0700) >> 8;
46 return clk->parent->rate / md_table[idx];
47}
48
49static struct sh_clk_ops sh7710_bus_clk_ops = {
50 .recalc = bus_clk_recalc,
51};
52
53static unsigned long cpu_clk_recalc(struct clk *clk)
54{
55 int idx = (__raw_readw(FRQCR) & 0x0070) >> 4;
56 return clk->parent->rate / md_table[idx];
57}
58
59static struct sh_clk_ops sh7710_cpu_clk_ops = {
60 .recalc = cpu_clk_recalc,
61};
62
63static struct sh_clk_ops *sh7710_clk_ops[] = {
64 &sh7710_master_clk_ops,
65 &sh7710_module_clk_ops,
66 &sh7710_bus_clk_ops,
67 &sh7710_cpu_clk_ops,
68};
69
70void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
71{
72 if (idx < ARRAY_SIZE(sh7710_clk_ops))
73 *ops = sh7710_clk_ops[idx];
74}
75