2 * Copyright (c) 2014 MediaTek Inc.
3 * Author: James Liao <jamesjj.liao@mediatek.com>
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.
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.
15 #ifndef __DRV_CLK_MTK_H
16 #define __DRV_CLK_MTK_H
18 #include <linux/regmap.h>
19 #include <linux/bitops.h>
20 #include <linux/clk-provider.h>
24 #define MAX_MUX_GATE_BIT 31
25 #define INVALID_MUX_GATE_BIT (MAX_MUX_GATE_BIT + 1)
27 #define MHZ (1000 * 1000)
29 struct mtk_fixed_clk {
36 #define FIXED_CLK(_id, _name, _parent, _rate) { \
43 void mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks,
44 int num, struct clk_onecell_data *clk_data);
46 struct mtk_fixed_factor {
49 const char *parent_name;
54 #define FACTOR(_id, _name, _parent, _mult, _div) { \
57 .parent_name = _parent, \
62 void mtk_clk_register_factors(const struct mtk_fixed_factor *clks,
63 int num, struct clk_onecell_data *clk_data);
65 struct mtk_composite {
68 const char * const *parent_names;
76 signed char mux_shift;
77 signed char mux_width;
78 signed char gate_shift;
80 signed char divider_shift;
81 signed char divider_width;
83 signed char num_parents;
87 * In case the rate change propagation to parent clocks is undesirable,
88 * this macro allows to specify the clock flags manually.
90 #define MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, \
95 .mux_shift = _shift, \
96 .mux_width = _width, \
98 .gate_shift = _gate, \
99 .divider_shift = -1, \
100 .parent_names = _parents, \
101 .num_parents = ARRAY_SIZE(_parents), \
106 * Unless necessary, all MUX_GATE clocks propagate rate changes to their
107 * parent clock by default.
109 #define MUX_GATE(_id, _name, _parents, _reg, _shift, _width, _gate) \
110 MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, \
111 _gate, CLK_SET_RATE_PARENT)
113 #define MUX(_id, _name, _parents, _reg, _shift, _width) { \
117 .mux_shift = _shift, \
118 .mux_width = _width, \
120 .divider_shift = -1, \
121 .parent_names = _parents, \
122 .num_parents = ARRAY_SIZE(_parents), \
123 .flags = CLK_SET_RATE_PARENT, \
126 #define DIV_GATE(_id, _name, _parent, _gate_reg, _gate_shift, _div_reg, \
127 _div_width, _div_shift) { \
131 .divider_reg = _div_reg, \
132 .divider_shift = _div_shift, \
133 .divider_width = _div_width, \
134 .gate_reg = _gate_reg, \
135 .gate_shift = _gate_shift, \
140 struct clk *mtk_clk_register_composite(const struct mtk_composite *mc,
141 void __iomem *base, spinlock_t *lock);
143 void mtk_clk_register_composites(const struct mtk_composite *mcs,
144 int num, void __iomem *base, spinlock_t *lock,
145 struct clk_onecell_data *clk_data);
147 struct mtk_gate_regs {
156 const char *parent_name;
157 const struct mtk_gate_regs *regs;
159 const struct clk_ops *ops;
162 int mtk_clk_register_gates(struct device_node *node,
163 const struct mtk_gate *clks, int num,
164 struct clk_onecell_data *clk_data);
166 struct mtk_clk_divider {
169 const char *parent_name;
173 unsigned char div_shift;
174 unsigned char div_width;
175 unsigned char clk_divider_flags;
176 const struct clk_div_table *clk_div_table;
179 #define DIV_ADJ(_id, _name, _parent, _reg, _shift, _width) { \
182 .parent_name = _parent, \
184 .div_shift = _shift, \
185 .div_width = _width, \
188 void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds,
189 int num, void __iomem *base, spinlock_t *lock,
190 struct clk_onecell_data *clk_data);
192 struct clk_onecell_data *mtk_alloc_clk_data(unsigned int clk_num);
194 #define HAVE_RST_BAR BIT(0)
195 #define PLL_AO BIT(1)
197 struct mtk_pll_div_table {
202 struct mtk_pll_data {
212 const struct clk_ops *ops;
218 const struct mtk_pll_div_table *div_table;
221 void mtk_clk_register_plls(struct device_node *node,
222 const struct mtk_pll_data *plls, int num_plls,
223 struct clk_onecell_data *clk_data);
225 struct clk *mtk_clk_register_ref2usb_tx(const char *name,
226 const char *parent_name, void __iomem *reg);
228 #ifdef CONFIG_RESET_CONTROLLER
229 void mtk_register_reset_controller(struct device_node *np,
230 unsigned int num_regs, int regofs);
232 static inline void mtk_register_reset_controller(struct device_node *np,
233 unsigned int num_regs, int regofs)
238 #endif /* __DRV_CLK_MTK_H */