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>
18 static inline void clk_dm(ulong id, struct clk *clk)
25 * flags used across common struct clk. these flags should only affect the
26 * top-level framework. custom flags for dealing with hardware specifics
27 * belong in struct clk_foo
29 * Please update clk_flags[] in drivers/clk/clk.c when making changes here!
31 #define CLK_SET_RATE_GATE BIT(0) /* must be gated across rate change */
32 #define CLK_SET_PARENT_GATE BIT(1) /* must be gated across re-parent */
33 #define CLK_SET_RATE_PARENT BIT(2) /* propagate rate change up one level */
34 #define CLK_IGNORE_UNUSED BIT(3) /* do not gate even if unused */
36 #define CLK_IS_BASIC BIT(5) /* Basic clk, can't do a to_clk_foo() */
37 #define CLK_GET_RATE_NOCACHE BIT(6) /* do not use the cached clk rate */
38 #define CLK_SET_RATE_NO_REPARENT BIT(7) /* don't re-parent on rate change */
39 #define CLK_GET_ACCURACY_NOCACHE BIT(8) /* do not use the cached clk accuracy */
40 #define CLK_RECALC_NEW_RATES BIT(9) /* recalc rates after notifications */
41 #define CLK_SET_RATE_UNGATE BIT(10) /* clock needs to run to set rate */
42 #define CLK_IS_CRITICAL BIT(11) /* do not gate, ever */
43 /* parents need enable during gate/ungate, set rate and re-parent */
44 #define CLK_OPS_PARENT_ENABLE BIT(12)
45 /* duty cycle call may be forwarded to the parent clock */
46 #define CLK_DUTY_CYCLE_PARENT BIT(13)
48 #define CLK_MUX_INDEX_ONE BIT(0)
49 #define CLK_MUX_INDEX_BIT BIT(1)
50 #define CLK_MUX_HIWORD_MASK BIT(2)
51 #define CLK_MUX_READ_ONLY BIT(3) /* mux can't be changed */
52 #define CLK_MUX_ROUND_CLOSEST BIT(4)
63 * Fields from struct clk_init_data - this struct has been
64 * omitted to avoid too deep level of CCF for bootloader
66 const char * const *parent_names;
68 #if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
74 #define to_clk_mux(_clk) container_of(_clk, struct clk_mux, clk)
75 extern const struct clk_ops clk_mux_ops;
76 u8 clk_mux_get_parent(struct clk *clk);
79 * clk_mux_index_to_val() - Convert the parent index to the register value
81 * It returns the value to write in the hardware register to output the selected
84 * @table: array of register values corresponding to the parent index (optional)
85 * @flags: hardware-specific flags
86 * @index: parent clock index
87 * @return the register value
89 unsigned int clk_mux_index_to_val(u32 *table, unsigned int flags, u8 index);
96 #if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
101 #define to_clk_gate(_clk) container_of(_clk, struct clk_gate, clk)
103 #define CLK_GATE_SET_TO_DISABLE BIT(0)
104 #define CLK_GATE_HIWORD_MASK BIT(1)
106 extern const struct clk_ops clk_gate_ops;
107 struct clk *clk_register_gate(struct device *dev, const char *name,
108 const char *parent_name, unsigned long flags,
109 void __iomem *reg, u8 bit_idx,
110 u8 clk_gate_flags, spinlock_t *lock);
112 struct clk_div_table {
123 const struct clk_div_table *table;
124 #if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
129 #define clk_div_mask(width) ((1 << (width)) - 1)
130 #define to_clk_divider(_clk) container_of(_clk, struct clk_divider, clk)
132 #define CLK_DIVIDER_ONE_BASED BIT(0)
133 #define CLK_DIVIDER_POWER_OF_TWO BIT(1)
134 #define CLK_DIVIDER_ALLOW_ZERO BIT(2)
135 #define CLK_DIVIDER_HIWORD_MASK BIT(3)
136 #define CLK_DIVIDER_ROUND_CLOSEST BIT(4)
137 #define CLK_DIVIDER_READ_ONLY BIT(5)
138 #define CLK_DIVIDER_MAX_AT_ZERO BIT(6)
139 extern const struct clk_ops clk_divider_ops;
142 * clk_divider_get_table_div() - convert the register value to the divider
144 * @table: array of register values corresponding to valid dividers
145 * @val: value to convert
146 * @return the divider
148 unsigned int clk_divider_get_table_div(const struct clk_div_table *table,
152 * clk_divider_get_table_val() - convert the divider to the register value
154 * It returns the value to write in the hardware register to divide the input
155 * clock rate by @div.
157 * @table: array of register values corresponding to valid dividers
158 * @div: requested divider
159 * @return the register value
161 unsigned int clk_divider_get_table_val(const struct clk_div_table *table,
165 * clk_divider_is_valid_div() - check if the divider is valid
167 * @table: array of valid dividers (optional)
168 * @div: divider to check
169 * @flags: hardware-specific flags
170 * @return true if the divider is valid, false otherwise
172 bool clk_divider_is_valid_div(const struct clk_div_table *table,
173 unsigned int div, unsigned long flags);
176 * clk_divider_is_valid_table_div - check if the divider is in the @table array
178 * @table: array of valid dividers
179 * @div: divider to check
180 * @return true if the divider is found in the @table array, false otherwise
182 bool clk_divider_is_valid_table_div(const struct clk_div_table *table,
184 unsigned long divider_recalc_rate(struct clk *hw, unsigned long parent_rate,
186 const struct clk_div_table *table,
187 unsigned long flags, unsigned long width);
189 struct clk_fixed_factor {
195 extern const struct clk_ops clk_fixed_rate_ops;
197 #define to_clk_fixed_factor(_clk) container_of(_clk, struct clk_fixed_factor,\
200 struct clk_fixed_rate {
202 unsigned long fixed_rate;
205 #define to_clk_fixed_rate(dev) ((struct clk_fixed_rate *)dev_get_plat(dev))
207 void clk_fixed_rate_ofdata_to_plat_(struct udevice *dev,
208 struct clk_fixed_rate *plat);
210 struct clk_composite {
218 const struct clk_ops *mux_ops;
219 const struct clk_ops *rate_ops;
220 const struct clk_ops *gate_ops;
223 #define to_clk_composite(_clk) container_of(_clk, struct clk_composite, clk)
225 struct clk *clk_register_composite(struct device *dev, const char *name,
226 const char * const *parent_names, int num_parents,
227 struct clk *mux_clk, const struct clk_ops *mux_ops,
228 struct clk *rate_clk, const struct clk_ops *rate_ops,
229 struct clk *gate_clk, const struct clk_ops *gate_ops,
230 unsigned long flags);
232 int clk_register(struct clk *clk, const char *drv_name, const char *name,
233 const char *parent_name);
235 struct clk *clk_register_fixed_factor(struct device *dev, const char *name,
236 const char *parent_name, unsigned long flags,
237 unsigned int mult, unsigned int div);
239 struct clk *clk_register_divider(struct device *dev, const char *name,
240 const char *parent_name, unsigned long flags,
241 void __iomem *reg, u8 shift, u8 width,
242 u8 clk_divider_flags);
244 struct clk *clk_register_mux(struct device *dev, const char *name,
245 const char * const *parent_names, u8 num_parents,
247 void __iomem *reg, u8 shift, u8 width,
250 struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
253 const char *clk_hw_get_name(const struct clk *hw);
254 ulong clk_generic_get_rate(struct clk *clk);
256 struct clk *dev_get_clk_ptr(struct udevice *dev);
257 #endif /* __LINUX_CLK_PROVIDER_H */