1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (C) 2019 DENX Software Engineering
4 * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
6 * Copyright (c) 2010-2011 Jeremy Kerr <jeremy.kerr@canonical.com>
7 * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
9 #ifndef __LINUX_CLK_PROVIDER_H
10 #define __LINUX_CLK_PROVIDER_H
12 #include <linux/bitops.h>
13 #include <linux/err.h>
14 #include <clk-uclass.h>
15 #include <linux/err.h>
19 static inline void clk_dm(ulong id, struct clk *clk)
26 * flags used across common struct clk. these flags should only affect the
27 * top-level framework. custom flags for dealing with hardware specifics
28 * belong in struct clk_foo
30 * Please update clk_flags[] in drivers/clk/clk.c when making changes here!
32 #define CLK_SET_RATE_GATE BIT(0) /* must be gated across rate change */
33 #define CLK_SET_PARENT_GATE BIT(1) /* must be gated across re-parent */
34 #define CLK_SET_RATE_PARENT BIT(2) /* propagate rate change up one level */
35 #define CLK_IGNORE_UNUSED BIT(3) /* do not gate even if unused */
37 #define CLK_IS_BASIC BIT(5) /* Basic clk, can't do a to_clk_foo() */
38 #define CLK_GET_RATE_NOCACHE BIT(6) /* do not use the cached clk rate */
39 #define CLK_SET_RATE_NO_REPARENT BIT(7) /* don't re-parent on rate change */
40 #define CLK_GET_ACCURACY_NOCACHE BIT(8) /* do not use the cached clk accuracy */
41 #define CLK_RECALC_NEW_RATES BIT(9) /* recalc rates after notifications */
42 #define CLK_SET_RATE_UNGATE BIT(10) /* clock needs to run to set rate */
43 #define CLK_IS_CRITICAL BIT(11) /* do not gate, ever */
44 /* parents need enable during gate/ungate, set rate and re-parent */
45 #define CLK_OPS_PARENT_ENABLE BIT(12)
46 /* duty cycle call may be forwarded to the parent clock */
47 #define CLK_DUTY_CYCLE_PARENT BIT(13)
49 #define CLK_MUX_INDEX_ONE BIT(0)
50 #define CLK_MUX_INDEX_BIT BIT(1)
51 #define CLK_MUX_HIWORD_MASK BIT(2)
52 #define CLK_MUX_READ_ONLY BIT(3) /* mux can't be changed */
53 #define CLK_MUX_ROUND_CLOSEST BIT(4)
64 * Fields from struct clk_init_data - this struct has been
65 * omitted to avoid too deep level of CCF for bootloader
67 const char * const *parent_names;
69 #if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
75 #define to_clk_mux(_clk) container_of(_clk, struct clk_mux, clk)
76 extern const struct clk_ops clk_mux_ops;
77 u8 clk_mux_get_parent(struct clk *clk);
80 * clk_mux_index_to_val() - Convert the parent index to the register value
82 * It returns the value to write in the hardware register to output the selected
85 * @table: array of register values corresponding to the parent index (optional)
86 * @flags: hardware-specific flags
87 * @index: parent clock index
88 * @return the register value
90 unsigned int clk_mux_index_to_val(u32 *table, unsigned int flags, u8 index);
97 #if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
102 #define to_clk_gate(_clk) container_of(_clk, struct clk_gate, clk)
104 #define CLK_GATE_SET_TO_DISABLE BIT(0)
105 #define CLK_GATE_HIWORD_MASK BIT(1)
107 extern const struct clk_ops clk_gate_ops;
108 struct clk *clk_register_gate(struct device *dev, const char *name,
109 const char *parent_name, unsigned long flags,
110 void __iomem *reg, u8 bit_idx,
111 u8 clk_gate_flags, spinlock_t *lock);
113 struct clk_div_table {
124 const struct clk_div_table *table;
125 #if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
130 #define clk_div_mask(width) ((1 << (width)) - 1)
131 #define to_clk_divider(_clk) container_of(_clk, struct clk_divider, clk)
133 #define CLK_DIVIDER_ONE_BASED BIT(0)
134 #define CLK_DIVIDER_POWER_OF_TWO BIT(1)
135 #define CLK_DIVIDER_ALLOW_ZERO BIT(2)
136 #define CLK_DIVIDER_HIWORD_MASK BIT(3)
137 #define CLK_DIVIDER_ROUND_CLOSEST BIT(4)
138 #define CLK_DIVIDER_READ_ONLY BIT(5)
139 #define CLK_DIVIDER_MAX_AT_ZERO BIT(6)
140 extern const struct clk_ops clk_divider_ops;
143 * clk_divider_get_table_div() - convert the register value to the divider
145 * @table: array of register values corresponding to valid dividers
146 * @val: value to convert
147 * @return the divider
149 unsigned int clk_divider_get_table_div(const struct clk_div_table *table,
153 * clk_divider_get_table_val() - convert the divider to the register value
155 * It returns the value to write in the hardware register to divide the input
156 * clock rate by @div.
158 * @table: array of register values corresponding to valid dividers
159 * @div: requested divider
160 * @return the register value
162 unsigned int clk_divider_get_table_val(const struct clk_div_table *table,
166 * clk_divider_is_valid_div() - check if the divider is valid
168 * @table: array of valid dividers (optional)
169 * @div: divider to check
170 * @flags: hardware-specific flags
171 * @return true if the divider is valid, false otherwise
173 bool clk_divider_is_valid_div(const struct clk_div_table *table,
174 unsigned int div, unsigned long flags);
177 * clk_divider_is_valid_table_div - check if the divider is in the @table array
179 * @table: array of valid dividers
180 * @div: divider to check
181 * @return true if the divider is found in the @table array, false otherwise
183 bool clk_divider_is_valid_table_div(const struct clk_div_table *table,
185 unsigned long divider_recalc_rate(struct clk *hw, unsigned long parent_rate,
187 const struct clk_div_table *table,
188 unsigned long flags, unsigned long width);
190 struct clk_fixed_factor {
196 #define to_clk_fixed_factor(_clk) container_of(_clk, struct clk_fixed_factor,\
199 struct clk_fixed_rate {
201 unsigned long fixed_rate;
204 #define to_clk_fixed_rate(dev) ((struct clk_fixed_rate *)dev_get_plat(dev))
206 struct clk_composite {
214 const struct clk_ops *mux_ops;
215 const struct clk_ops *rate_ops;
216 const struct clk_ops *gate_ops;
219 #define to_clk_composite(_clk) container_of(_clk, struct clk_composite, clk)
221 struct clk *clk_register_composite(struct device *dev, const char *name,
222 const char * const *parent_names, int num_parents,
223 struct clk *mux_clk, const struct clk_ops *mux_ops,
224 struct clk *rate_clk, const struct clk_ops *rate_ops,
225 struct clk *gate_clk, const struct clk_ops *gate_ops,
226 unsigned long flags);
228 int clk_register(struct clk *clk, const char *drv_name, const char *name,
229 const char *parent_name);
231 struct clk *clk_register_fixed_factor(struct device *dev, const char *name,
232 const char *parent_name, unsigned long flags,
233 unsigned int mult, unsigned int div);
235 struct clk *clk_register_divider(struct device *dev, const char *name,
236 const char *parent_name, unsigned long flags,
237 void __iomem *reg, u8 shift, u8 width,
238 u8 clk_divider_flags);
240 struct clk *clk_register_mux(struct device *dev, const char *name,
241 const char * const *parent_names, u8 num_parents,
243 void __iomem *reg, u8 shift, u8 width,
246 const char *clk_hw_get_name(const struct clk *hw);
247 ulong clk_generic_get_rate(struct clk *clk);
249 struct clk *dev_get_clk_ptr(struct udevice *dev);
250 #endif /* __LINUX_CLK_PROVIDER_H */