blob: a0eff8d857b527a57fd51ccf0cc91e7a9600327a [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001/*
2 * Copyright (c) 2014 MediaTek Inc.
3 * Author: James Liao <jamesjj.liao@mediatek.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#ifndef __DRV_CLK_MTK_H
15#define __DRV_CLK_MTK_H
16#include <linux/bitops.h>
17#include <linux/clk-provider.h>
18#include <linux/regmap.h>
19struct clk;
20struct clk *mtk_clk_register_fixed_factor_pdn(struct device *dev,
21 const char *name,
22 const char *parent_name, unsigned long flags,
23 unsigned int mult, unsigned int div, unsigned int shift,
24 unsigned int pd_reg, void __iomem *base);
25#define MAX_MUX_GATE_BIT 31
26#define INVALID_MUX_GATE_BIT (MAX_MUX_GATE_BIT + 1)
27#define INVALID_OFS -1
28#define INVALID_SHFT -1
29#define INVALID_WIDTH -1
30#define MHZ (1000 * 1000)
31struct mtk_fixed_clk {
32 int id;
33 const char *name;
34 const char *parent;
35 unsigned long rate;
36};
37#define FIXED_CLK(_id, _name, _parent, _rate) { \
38 .id = _id, \
39 .name = _name, \
40 .parent = _parent, \
41 .rate = _rate, \
42 }
43void mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks,
44 int num, struct clk_onecell_data *clk_data);
45struct mtk_fixed_factor {
46 int id;
47 const char *name;
48 const char *parent_name;
49 int mult;
50 int div;
51};
52struct mtk_fixed_factor_pdn {
53 int id;
54 const char *name;
55 const char *parent_name;
56 int mult;
57 int div;
58 int shift;
59 int pd_reg;
60};
61#define FACTOR(_id, _name, _parent, _mult, _div) { \
62 .id = _id, \
63 .name = _name, \
64 .parent_name = _parent, \
65 .mult = _mult, \
66 .div = _div, \
67 }
68#define FACTOR_PDN(_id, _name, _parent, _mult, _div, _shift, _pd_reg) { \
69 .id = _id, \
70 .name = _name, \
71 .parent_name = _parent, \
72 .mult = _mult, \
73 .div = _div, \
74 .shift = _shift, \
75 .pd_reg = _pd_reg, \
76 }
77void mtk_clk_register_factors(const struct mtk_fixed_factor *clks,
78 int num, struct clk_onecell_data *clk_data);
79void mtk_clk_register_factors_pdn(const struct mtk_fixed_factor_pdn *clks,
80 int num, struct clk_onecell_data *clk_data, void __iomem *base);
81struct mtk_composite {
82 int id;
83 const char *name;
84 const char * const *parent_names;
85 const char *parent;
86 unsigned long flags;
87 uint32_t mux_reg;
88 uint32_t divider_reg;
89 uint32_t gate_reg;
90 signed char mux_shift;
91 signed char mux_width;
92 signed char gate_shift;
93 signed char divider_shift;
94 signed char divider_width;
95 u8 mux_flags;
96 signed char num_parents;
97};
98#define MUX_GATE_FLAGS_2(_id, _name, _parents, _reg, _shift, \
99 _width, _gate, _flags, _muxflags) { \
100 .id = _id, \
101 .name = _name, \
102 .mux_reg = _reg, \
103 .mux_shift = _shift, \
104 .mux_width = _width, \
105 .gate_reg = _reg, \
106 .gate_shift = _gate, \
107 .divider_shift = -1, \
108 .parent_names = _parents, \
109 .num_parents = ARRAY_SIZE(_parents), \
110 .flags = _flags, \
111 .mux_flags = _muxflags, \
112 }
113/*
114 * In case the rate change propagation to parent clocks is undesirable,
115 * this macro allows to specify the clock flags manually.
116 */
117#define MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, \
118 _gate, _flags) \
119 MUX_GATE_FLAGS_2(_id, _name, _parents, _reg, \
120 _shift, _width, _gate, _flags, 0)
121/*
122 * Unless necessary, all MUX_GATE clocks propagate rate changes to their
123 * parent clock by default.
124 */
125#define MUX_GATE(_id, _name, _parents, _reg, _shift, _width, _gate) \
126 MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, \
127 _gate, CLK_SET_RATE_PARENT)
128#define MUX(_id, _name, _parents, _reg, _shift, _width) \
129 MUX_FLAGS(_id, _name, _parents, _reg, \
130 _shift, _width, CLK_SET_RATE_PARENT)
131#define MUX_FLAGS(_id, _name, _parents, _reg, _shift, _width, _flags) { \
132 .id = _id, \
133 .name = _name, \
134 .mux_reg = _reg, \
135 .mux_shift = _shift, \
136 .mux_width = _width, \
137 .gate_shift = -1, \
138 .divider_shift = -1, \
139 .parent_names = _parents, \
140 .num_parents = ARRAY_SIZE(_parents), \
141 .flags = _flags, \
142 }
143#define DIV_GATE(_id, _name, _parent, _gate_reg, _gate_shift, _div_reg, \
144 _div_width, _div_shift) { \
145 .id = _id, \
146 .parent = _parent, \
147 .name = _name, \
148 .divider_reg = _div_reg, \
149 .divider_shift = _div_shift, \
150 .divider_width = _div_width, \
151 .gate_reg = _gate_reg, \
152 .gate_shift = _gate_shift, \
153 .mux_shift = -1, \
154 .flags = 0, \
155 }
156struct clk *mtk_clk_register_composite(const struct mtk_composite *mc,
157 void __iomem *base, spinlock_t *lock);
158void mtk_clk_register_composites(const struct mtk_composite *mcs,
159 int num, void __iomem *base, spinlock_t *lock,
160 struct clk_onecell_data *clk_data);
161struct mtk_gate_regs {
162 u32 sta_ofs;
163 u32 clr_ofs;
164 u32 set_ofs;
165};
166struct mtk_gate {
167 int id;
168 const char *name;
169 const char *parent_name;
170 const struct mtk_gate_regs *regs;
171 int shift;
172 const struct clk_ops *ops;
173 unsigned long flags;
174 struct pwr_status *pwr_stat;
175};
176int mtk_clk_register_gates(struct device_node *node,
177 const struct mtk_gate *clks, int num,
178 struct clk_onecell_data *clk_data);
179struct mtk_clk_divider {
180 int id;
181 const char *name;
182 const char *parent_name;
183 unsigned long flags;
184 u32 div_reg;
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;
189};
190#define DIV_ADJ(_id, _name, _parent, _reg, _shift, _width) { \
191 .id = _id, \
192 .name = _name, \
193 .parent_name = _parent, \
194 .div_reg = _reg, \
195 .div_shift = _shift, \
196 .div_width = _width, \
197}
198void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds,
199 int num, void __iomem *base, spinlock_t *lock,
200 struct clk_onecell_data *clk_data);
201struct clk_onecell_data *mtk_alloc_clk_data(unsigned int clk_num);
202#define HAVE_RST_BAR BIT(0)
203#define PLL_AO BIT(1)
204#define HAVE_RST_BAR_4_TIMES (BIT(2) | BIT(0))
205struct mtk_pll_div_table {
206 u32 div;
207 unsigned long freq;
208};
209struct mtk_pll_data {
210 int id;
211 const char *name;
212 uint32_t reg;
213 uint32_t pwr_reg;
214 uint32_t en_reg;
215 uint32_t en_mask;
216 uint32_t iso_mask;
217 uint32_t pwron_mask;
218 uint32_t pd_reg;
219 uint32_t tuner_reg;
220 uint32_t tuner_en_reg;
221 uint8_t tuner_en_bit;
222 int pd_shift;
223 unsigned int flags;
224 const struct clk_ops *ops;
225 uint32_t rst_bar_reg;
226 int rst_bar_mask;
227 unsigned long fmin;
228 unsigned long fmax;
229 int pcwbits;
230 int pcwibits;
231 uint32_t pcw_reg;
232 int pcw_shift;
233 uint32_t pcw_chg_reg;
234 const struct mtk_pll_div_table *div_table;
235 const char *parent_name;
236};
237void mtk_clk_register_plls(struct device_node *node,
238 const struct mtk_pll_data *plls, int num_plls,
239 struct clk_onecell_data *clk_data);
240struct clk *mtk_clk_register_ref2usb_tx(const char *name,
241 const char *parent_name, void __iomem *reg);
242extern bool (*mtk_fh_set_rate)(int pll_id, unsigned long dds, int postdiv);
243#ifdef CONFIG_RESET_CONTROLLER
244void mtk_register_reset_controller(struct device_node *np,
245 unsigned int num_regs, int regofs);
246#else
247static inline void mtk_register_reset_controller(struct device_node *np,
248 unsigned int num_regs, int regofs)
249{
250}
251#endif
252#endif /* __DRV_CLK_MTK_H */