1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2014 MediaTek Inc.
7 #ifndef __DRV_CLK_MTK_H
8 #define __DRV_CLK_MTK_H
10 #include <linux/regmap.h>
11 #include <linux/bitops.h>
12 #include <linux/clk-provider.h>
13 #include <linux/platform_device.h>
16 struct clk_onecell_data;
18 #define MAX_MUX_GATE_BIT 31
19 #define INVALID_MUX_GATE_BIT (MAX_MUX_GATE_BIT + 1)
21 #define MHZ (1000 * 1000)
23 struct mtk_fixed_clk {
30 #define FIXED_CLK(_id, _name, _parent, _rate) { \
37 void mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks,
38 int num, struct clk_onecell_data *clk_data);
40 struct mtk_fixed_factor {
43 const char *parent_name;
48 #define FACTOR(_id, _name, _parent, _mult, _div) { \
51 .parent_name = _parent, \
56 void mtk_clk_register_factors(const struct mtk_fixed_factor *clks,
57 int num, struct clk_onecell_data *clk_data);
59 struct mtk_composite {
62 const char * const *parent_names;
70 signed char mux_shift;
71 signed char mux_width;
72 signed char gate_shift;
74 signed char divider_shift;
75 signed char divider_width;
79 signed char num_parents;
82 #define MUX_GATE_FLAGS_2(_id, _name, _parents, _reg, _shift, \
83 _width, _gate, _flags, _muxflags) { \
87 .mux_shift = _shift, \
88 .mux_width = _width, \
90 .gate_shift = _gate, \
91 .divider_shift = -1, \
92 .parent_names = _parents, \
93 .num_parents = ARRAY_SIZE(_parents), \
95 .mux_flags = _muxflags, \
99 * In case the rate change propagation to parent clocks is undesirable,
100 * this macro allows to specify the clock flags manually.
102 #define MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, \
104 MUX_GATE_FLAGS_2(_id, _name, _parents, _reg, \
105 _shift, _width, _gate, _flags, 0)
108 * Unless necessary, all MUX_GATE clocks propagate rate changes to their
109 * parent clock by default.
111 #define MUX_GATE(_id, _name, _parents, _reg, _shift, _width, _gate) \
112 MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, \
113 _gate, CLK_SET_RATE_PARENT)
115 #define MUX(_id, _name, _parents, _reg, _shift, _width) \
116 MUX_FLAGS(_id, _name, _parents, _reg, \
117 _shift, _width, CLK_SET_RATE_PARENT)
119 #define MUX_FLAGS(_id, _name, _parents, _reg, _shift, _width, _flags) { \
123 .mux_shift = _shift, \
124 .mux_width = _width, \
126 .divider_shift = -1, \
127 .parent_names = _parents, \
128 .num_parents = ARRAY_SIZE(_parents), \
132 #define DIV_GATE(_id, _name, _parent, _gate_reg, _gate_shift, _div_reg, \
133 _div_width, _div_shift) { \
137 .divider_reg = _div_reg, \
138 .divider_shift = _div_shift, \
139 .divider_width = _div_width, \
140 .gate_reg = _gate_reg, \
141 .gate_shift = _gate_shift, \
146 struct clk *mtk_clk_register_composite(const struct mtk_composite *mc,
147 void __iomem *base, spinlock_t *lock);
149 void mtk_clk_register_composites(const struct mtk_composite *mcs,
150 int num, void __iomem *base, spinlock_t *lock,
151 struct clk_onecell_data *clk_data);
153 struct mtk_gate_regs {
162 const char *parent_name;
163 const struct mtk_gate_regs *regs;
165 const struct clk_ops *ops;
169 int mtk_clk_register_gates(struct device_node *node,
170 const struct mtk_gate *clks, int num,
171 struct clk_onecell_data *clk_data);
173 int mtk_clk_register_gates_with_dev(struct device_node *node,
174 const struct mtk_gate *clks,
175 int num, struct clk_onecell_data *clk_data,
178 struct mtk_clk_divider {
181 const char *parent_name;
185 unsigned char div_shift;
186 unsigned char div_width;
187 unsigned char clk_divider_flags;
188 const struct clk_div_table *clk_div_table;
191 #define DIV_ADJ(_id, _name, _parent, _reg, _shift, _width) { \
194 .parent_name = _parent, \
196 .div_shift = _shift, \
197 .div_width = _width, \
200 void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds,
201 int num, void __iomem *base, spinlock_t *lock,
202 struct clk_onecell_data *clk_data);
204 struct clk_onecell_data *mtk_alloc_clk_data(unsigned int clk_num);
206 #define HAVE_RST_BAR BIT(0)
207 #define PLL_AO BIT(1)
209 struct mtk_pll_div_table {
214 struct mtk_pll_data {
226 const struct clk_ops *ops;
235 const struct mtk_pll_div_table *div_table;
236 const char *parent_name;
238 u8 pll_en_bit; /* Assume 0, indicates BIT(0) by default */
241 void mtk_clk_register_plls(struct device_node *node,
242 const struct mtk_pll_data *plls, int num_plls,
243 struct clk_onecell_data *clk_data);
245 struct clk *mtk_clk_register_ref2usb_tx(const char *name,
246 const char *parent_name, void __iomem *reg);
248 void mtk_register_reset_controller(struct device_node *np,
249 unsigned int num_regs, int regofs);
251 void mtk_register_reset_controller_set_clr(struct device_node *np,
252 unsigned int num_regs, int regofs);
254 struct mtk_clk_desc {
255 const struct mtk_gate *clks;
259 int mtk_clk_simple_probe(struct platform_device *pdev);
261 #endif /* __DRV_CLK_MTK_H */