treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / arch / sh / kernel / cpu / sh4a / clock-sh7763.c
blobaaff4b96812c6a5df07248b21c9e9256c3dd3a76
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * arch/sh/kernel/cpu/sh4a/clock-sh7763.c
5 * SH7763 support for the clock framework
7 * Copyright (C) 2005 Paul Mundt
8 * Copyright (C) 2007 Yoshihiro Shimoda
9 */
10 #include <linux/init.h>
11 #include <linux/kernel.h>
12 #include <linux/io.h>
13 #include <linux/clkdev.h>
14 #include <asm/clock.h>
15 #include <asm/freq.h>
16 #include <asm/io.h>
18 static int bfc_divisors[] = { 1, 1, 1, 8, 1, 1, 1, 1 };
19 static int p0fc_divisors[] = { 1, 1, 1, 8, 1, 1, 1, 1 };
20 static int cfc_divisors[] = { 1, 1, 4, 1, 1, 1, 1, 1 };
22 static void master_clk_init(struct clk *clk)
24 clk->rate *= p0fc_divisors[(__raw_readl(FRQCR) >> 4) & 0x07];
27 static struct sh_clk_ops sh7763_master_clk_ops = {
28 .init = master_clk_init,
31 static unsigned long module_clk_recalc(struct clk *clk)
33 int idx = ((__raw_readl(FRQCR) >> 4) & 0x07);
34 return clk->parent->rate / p0fc_divisors[idx];
37 static struct sh_clk_ops sh7763_module_clk_ops = {
38 .recalc = module_clk_recalc,
41 static unsigned long bus_clk_recalc(struct clk *clk)
43 int idx = ((__raw_readl(FRQCR) >> 16) & 0x07);
44 return clk->parent->rate / bfc_divisors[idx];
47 static struct sh_clk_ops sh7763_bus_clk_ops = {
48 .recalc = bus_clk_recalc,
51 static struct sh_clk_ops sh7763_cpu_clk_ops = {
52 .recalc = followparent_recalc,
55 static struct sh_clk_ops *sh7763_clk_ops[] = {
56 &sh7763_master_clk_ops,
57 &sh7763_module_clk_ops,
58 &sh7763_bus_clk_ops,
59 &sh7763_cpu_clk_ops,
62 void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
64 if (idx < ARRAY_SIZE(sh7763_clk_ops))
65 *ops = sh7763_clk_ops[idx];
68 static unsigned long shyway_clk_recalc(struct clk *clk)
70 int idx = ((__raw_readl(FRQCR) >> 20) & 0x07);
71 return clk->parent->rate / cfc_divisors[idx];
74 static struct sh_clk_ops sh7763_shyway_clk_ops = {
75 .recalc = shyway_clk_recalc,
78 static struct clk sh7763_shyway_clk = {
79 .flags = CLK_ENABLE_ON_INIT,
80 .ops = &sh7763_shyway_clk_ops,
84 * Additional SH7763-specific on-chip clocks that aren't already part of the
85 * clock framework
87 static struct clk *sh7763_onchip_clocks[] = {
88 &sh7763_shyway_clk,
91 static struct clk_lookup lookups[] = {
92 /* main clocks */
93 CLKDEV_CON_ID("shyway_clk", &sh7763_shyway_clk),
96 int __init arch_clk_init(void)
98 struct clk *clk;
99 int i, ret = 0;
101 cpg_clk_init();
103 clk = clk_get(NULL, "master_clk");
104 for (i = 0; i < ARRAY_SIZE(sh7763_onchip_clocks); i++) {
105 struct clk *clkp = sh7763_onchip_clocks[i];
107 clkp->parent = clk;
108 ret |= clk_register(clkp);
111 clk_put(clk);
113 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
115 return ret;