1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * (C) Copyright 2022 - Analog Devices, Inc.
5 * Written and/or maintained by Timesys Corporation
15 #include <linux/compiler_types.h>
16 #include <linux/types.h>
17 #include <linux/clk-provider.h>
20 #define CGU_PLLCTL 0x04
23 #define CGU_CLKOUTSEL 0x10
24 #define CGU_OSCWDCTL 0x14
25 #define CGU_TSCTL 0x18
26 #define CGU_TSVALUE0 0x1C
27 #define CGU_TSVALUE1 0x20
28 #define CGU_TSCOUNT0 0x24
29 #define CGU_TSCOUNT1 0x28
30 #define CGU_CCBF_DIS 0x2C
31 #define CGU_CCBF_STAT 0x30
32 #define CGU_SCBF_DIS 0x38
33 #define CGU_SCBF_STAT 0x3C
34 #define CGU_DIVEX 0x40
35 #define CGU_REVID 0x48
47 #define CDU_CFG10 0x28
48 #define CDU_CFG11 0x2C
49 #define CDU_CFG12 0x30
50 #define CDU_CFG13 0x34
51 #define CDU_CFG14 0x38
53 #define PLL3_OFFSET 0x2c
55 #define CDU_CLKINSEL 0x44
57 #define CGU_MSEL_SHIFT 8
58 #define CGU_MSEL_WIDTH 7
60 #define PLL3_MSEL_SHIFT 4
61 #define PLL3_MSEL_WIDTH 7
63 #define CDU_MUX_SIZE 4
64 #define CDU_MUX_SHIFT 1
65 #define CDU_MUX_WIDTH 2
68 extern const struct clk_ops adi_clk_ops;
70 struct clk *sc5xx_cgu_pll(const char *name, const char *parent_name,
71 void __iomem *base, u8 shift, u8 width, u32 m_offset, bool half_m);
74 * All CDU clock muxes are the same size
76 static inline struct clk *cdu_mux(const char *name, void __iomem *reg,
77 const char * const *parents)
79 return clk_register_mux(NULL, name, parents, CDU_MUX_SIZE,
80 CLK_SET_RATE_PARENT, reg, CDU_MUX_SHIFT, CDU_MUX_WIDTH, 0);
83 static inline struct clk *cgu_divider(const char *name, const char *parent,
84 void __iomem *reg, u8 shift, u8 width, u8 extra_flags)
86 return clk_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT,
87 reg, shift, width, CLK_DIVIDER_MAX_AT_ZERO | extra_flags);
90 static inline struct clk *cdu_gate(const char *name, const char *parent,
91 void __iomem *reg, u32 flags)
93 return clk_register_gate(NULL, name, parent, CLK_SET_RATE_PARENT | flags,
94 reg, CDU_EN_BIT, 0, NULL);
97 static inline struct clk *cgu_gate(const char *name, const char *parent,
98 void __iomem *reg, u8 bit)
100 return clk_register_gate(NULL, name, parent, CLK_SET_RATE_PARENT, reg, bit,
101 CLK_GATE_SET_TO_DISABLE, NULL);
104 static inline int cdu_check_clocks(struct clk *clks[], size_t count)
108 for (i = 0; i < count; ++i) {
110 if (IS_ERR(clks[i])) {
111 pr_err("Clock %zu failed to register: %ld\n", i, PTR_ERR(clks[i]));
112 return PTR_ERR(clks[i]);
116 pr_err("ADI Clock framework: Null pointer detected on clock %zu\n", i);