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/clk-provider.h>
12 #include <linux/kernel.h>
13 #include <linux/spinlock.h>
14 #include <linux/types.h>
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 platform_device;
25 struct mtk_fixed_clk {
32 #define FIXED_CLK(_id, _name, _parent, _rate) { \
39 int mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, int num,
40 struct clk_hw_onecell_data *clk_data);
41 void mtk_clk_unregister_fixed_clks(const struct mtk_fixed_clk *clks, int num,
42 struct clk_hw_onecell_data *clk_data);
44 struct mtk_fixed_factor {
47 const char *parent_name;
52 #define FACTOR(_id, _name, _parent, _mult, _div) { \
55 .parent_name = _parent, \
60 int mtk_clk_register_factors(const struct mtk_fixed_factor *clks, int num,
61 struct clk_hw_onecell_data *clk_data);
62 void mtk_clk_unregister_factors(const struct mtk_fixed_factor *clks, int num,
63 struct clk_hw_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;
85 signed char num_parents;
88 #define MUX_GATE_FLAGS_2(_id, _name, _parents, _reg, _shift, \
89 _width, _gate, _flags, _muxflags) { \
93 .mux_shift = _shift, \
94 .mux_width = _width, \
96 .gate_shift = _gate, \
97 .divider_shift = -1, \
98 .parent_names = _parents, \
99 .num_parents = ARRAY_SIZE(_parents), \
101 .mux_flags = _muxflags, \
105 * In case the rate change propagation to parent clocks is undesirable,
106 * this macro allows to specify the clock flags manually.
108 #define MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, \
110 MUX_GATE_FLAGS_2(_id, _name, _parents, _reg, \
111 _shift, _width, _gate, _flags, 0)
114 * Unless necessary, all MUX_GATE clocks propagate rate changes to their
115 * parent clock by default.
117 #define MUX_GATE(_id, _name, _parents, _reg, _shift, _width, _gate) \
118 MUX_GATE_FLAGS(_id, _name, _parents, _reg, _shift, _width, \
119 _gate, CLK_SET_RATE_PARENT)
121 #define MUX(_id, _name, _parents, _reg, _shift, _width) \
122 MUX_FLAGS(_id, _name, _parents, _reg, \
123 _shift, _width, CLK_SET_RATE_PARENT)
125 #define MUX_FLAGS(_id, _name, _parents, _reg, _shift, _width, _flags) { \
129 .mux_shift = _shift, \
130 .mux_width = _width, \
132 .divider_shift = -1, \
133 .parent_names = _parents, \
134 .num_parents = ARRAY_SIZE(_parents), \
138 #define DIV_GATE(_id, _name, _parent, _gate_reg, _gate_shift, _div_reg, \
139 _div_width, _div_shift) { \
143 .divider_reg = _div_reg, \
144 .divider_shift = _div_shift, \
145 .divider_width = _div_width, \
146 .gate_reg = _gate_reg, \
147 .gate_shift = _gate_shift, \
152 int mtk_clk_register_composites(const struct mtk_composite *mcs, int num,
153 void __iomem *base, spinlock_t *lock,
154 struct clk_hw_onecell_data *clk_data);
155 void mtk_clk_unregister_composites(const struct mtk_composite *mcs, int num,
156 struct clk_hw_onecell_data *clk_data);
158 struct mtk_clk_divider {
161 const char *parent_name;
165 unsigned char div_shift;
166 unsigned char div_width;
167 unsigned char clk_divider_flags;
168 const struct clk_div_table *clk_div_table;
171 #define DIV_ADJ(_id, _name, _parent, _reg, _shift, _width) { \
174 .parent_name = _parent, \
176 .div_shift = _shift, \
177 .div_width = _width, \
180 int mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, int num,
181 void __iomem *base, spinlock_t *lock,
182 struct clk_hw_onecell_data *clk_data);
183 void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num,
184 struct clk_hw_onecell_data *clk_data);
186 struct clk_hw_onecell_data *mtk_alloc_clk_data(unsigned int clk_num);
187 struct clk_hw_onecell_data *mtk_devm_alloc_clk_data(struct device *dev,
188 unsigned int clk_num);
189 void mtk_free_clk_data(struct clk_hw_onecell_data *clk_data);
191 struct clk_hw *mtk_clk_register_ref2usb_tx(const char *name,
192 const char *parent_name, void __iomem *reg);
193 void mtk_clk_unregister_ref2usb_tx(struct clk_hw *hw);
195 struct mtk_clk_desc {
196 const struct mtk_gate *clks;
198 const struct mtk_clk_rst_desc *rst_desc;
201 int mtk_clk_simple_probe(struct platform_device *pdev);
202 int mtk_clk_simple_remove(struct platform_device *pdev);
204 #endif /* __DRV_CLK_MTK_H */