1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2014 MediaTek Inc.
4 * Author: James Liao <jamesjj.liao@mediatek.com>
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>
15 struct clk_onecell_data;
17 #define MAX_MUX_GATE_BIT 31
18 #define INVALID_MUX_GATE_BIT (MAX_MUX_GATE_BIT + 1)
20 #define MHZ (1000 * 1000)
22 struct mtk_fixed_clk {
29 #define FIXED_CLK(_id, _name, _parent, _rate) { \
36 void mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks,
37 int num, struct clk_onecell_data *clk_data);
39 struct mtk_fixed_factor {
42 const char *parent_name;
47 #define FACTOR(_id, _name, _parent, _mult, _div) { \
50 .parent_name = _parent, \
55 void mtk_clk_register_factors(const struct mtk_fixed_factor *clks,
56 int num, struct clk_onecell_data *clk_data);
58 struct mtk_composite {
61 const char * const *parent_names;
69 signed char mux_shift;
70 signed char mux_width;
71 signed char gate_shift;
73 signed char divider_shift;
74 signed char divider_width;
78 signed char num_parents;
81 #define MUX_GATE_FLAGS_2(_id, _name, _parents, _reg, _shift, \
82 _width, _gate, _flags, _muxflags) { \
86 .mux_shift = _shift, \
87 .mux_width = _width, \
89 .gate_shift = _gate, \
90 .divider_shift = -1, \
91 .parent_names = _parents, \
92 .num_parents = ARRAY_SIZE(_parents), \
94 .mux_flags = _muxflags, \
98 * In case the rate change propagation to parent clocks is undesirable,
99 * this macro allows to specify the clock flags manually.
101 #define MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, \
103 MUX_GATE_FLAGS_2(_id, _name, _parents, _reg, \
104 _shift, _width, _gate, _flags, 0)
107 * Unless necessary, all MUX_GATE clocks propagate rate changes to their
108 * parent clock by default.
110 #define MUX_GATE(_id, _name, _parents, _reg, _shift, _width, _gate) \
111 MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, \
112 _gate, CLK_SET_RATE_PARENT)
114 #define MUX(_id, _name, _parents, _reg, _shift, _width) \
115 MUX_FLAGS(_id, _name, _parents, _reg, \
116 _shift, _width, CLK_SET_RATE_PARENT)
118 #define MUX_FLAGS(_id, _name, _parents, _reg, _shift, _width, _flags) { \
122 .mux_shift = _shift, \
123 .mux_width = _width, \
125 .divider_shift = -1, \
126 .parent_names = _parents, \
127 .num_parents = ARRAY_SIZE(_parents), \
131 #define DIV_GATE(_id, _name, _parent, _gate_reg, _gate_shift, _div_reg, \
132 _div_width, _div_shift) { \
136 .divider_reg = _div_reg, \
137 .divider_shift = _div_shift, \
138 .divider_width = _div_width, \
139 .gate_reg = _gate_reg, \
140 .gate_shift = _gate_shift, \
145 struct clk *mtk_clk_register_composite(const struct mtk_composite *mc,
146 void __iomem *base, spinlock_t *lock);
148 void mtk_clk_register_composites(const struct mtk_composite *mcs,
149 int num, void __iomem *base, spinlock_t *lock,
150 struct clk_onecell_data *clk_data);
152 struct mtk_gate_regs {
161 const char *parent_name;
162 const struct mtk_gate_regs *regs;
164 const struct clk_ops *ops;
168 int mtk_clk_register_gates(struct device_node *node,
169 const struct mtk_gate *clks, int num,
170 struct clk_onecell_data *clk_data);
172 struct mtk_clk_divider {
175 const char *parent_name;
179 unsigned char div_shift;
180 unsigned char div_width;
181 unsigned char clk_divider_flags;
182 const struct clk_div_table *clk_div_table;
185 #define DIV_ADJ(_id, _name, _parent, _reg, _shift, _width) { \
188 .parent_name = _parent, \
190 .div_shift = _shift, \
191 .div_width = _width, \
194 void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds,
195 int num, void __iomem *base, spinlock_t *lock,
196 struct clk_onecell_data *clk_data);
198 struct clk_onecell_data *mtk_alloc_clk_data(unsigned int clk_num);
200 #define HAVE_RST_BAR BIT(0)
201 #define PLL_AO BIT(1)
203 struct mtk_pll_div_table {
208 struct mtk_pll_data {
216 uint32_t tuner_en_reg;
217 uint8_t tuner_en_bit;
220 const struct clk_ops *ops;
228 uint32_t pcw_chg_reg;
229 const struct mtk_pll_div_table *div_table;
230 const char *parent_name;
233 void mtk_clk_register_plls(struct device_node *node,
234 const struct mtk_pll_data *plls, int num_plls,
235 struct clk_onecell_data *clk_data);
237 struct clk *mtk_clk_register_ref2usb_tx(const char *name,
238 const char *parent_name, void __iomem *reg);
240 void mtk_register_reset_controller(struct device_node *np,
241 unsigned int num_regs, int regofs);
243 #endif /* __DRV_CLK_MTK_H */