2 * Copyright (c) 2016 Maxime Ripard. All rights reserved.
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
17 #include <linux/clk-provider.h>
19 #include "ccu_common.h"
26 * struct ccu_nm - Definition of an N-M clock
28 * Clocks based on the formula parent * N / M
34 struct ccu_mult_internal n;
35 struct ccu_div_internal m;
36 struct ccu_frac_internal frac;
37 struct ccu_sdm_internal sdm;
39 unsigned int fixed_post_div;
40 unsigned int min_rate;
41 unsigned int max_rate;
43 struct ccu_common common;
46 #define SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(_struct, _name, _parent, _reg, \
49 _sdm_table, _sdm_en, \
50 _sdm_reg, _sdm_reg_en, \
51 _gate, _lock, _flags) \
52 struct ccu_nm _struct = { \
55 .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
56 .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
57 .sdm = _SUNXI_CCU_SDM(_sdm_table, _sdm_en, \
58 _sdm_reg, _sdm_reg_en),\
61 .features = CCU_FEATURE_SIGMA_DELTA_MOD, \
62 .hw.init = CLK_HW_INIT(_name, \
69 #define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(_struct, _name, _parent, _reg, \
72 _frac_en, _frac_sel, \
73 _frac_rate_0, _frac_rate_1, \
74 _gate, _lock, _flags) \
75 struct ccu_nm _struct = { \
78 .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
79 .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
80 .frac = _SUNXI_CCU_FRAC(_frac_en, _frac_sel, \
85 .features = CCU_FEATURE_FRACTIONAL, \
86 .hw.init = CLK_HW_INIT(_name, \
93 #define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN(_struct, _name, _parent, \
97 _frac_en, _frac_sel, \
98 _frac_rate_0, _frac_rate_1,\
99 _gate, _lock, _flags) \
100 struct ccu_nm _struct = { \
103 .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
104 .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
105 .frac = _SUNXI_CCU_FRAC(_frac_en, _frac_sel, \
108 .min_rate = _min_rate, \
111 .features = CCU_FEATURE_FRACTIONAL, \
112 .hw.init = CLK_HW_INIT(_name, \
119 #define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(_struct, _name, \
121 _min_rate, _max_rate, \
124 _frac_en, _frac_sel, \
127 _gate, _lock, _flags) \
128 struct ccu_nm _struct = { \
131 .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
132 .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
133 .frac = _SUNXI_CCU_FRAC(_frac_en, _frac_sel, \
136 .min_rate = _min_rate, \
137 .max_rate = _max_rate, \
140 .features = CCU_FEATURE_FRACTIONAL, \
141 .hw.init = CLK_HW_INIT(_name, \
148 #define SUNXI_CCU_NM_WITH_GATE_LOCK(_struct, _name, _parent, _reg, \
151 _gate, _lock, _flags) \
152 struct ccu_nm _struct = { \
155 .n = _SUNXI_CCU_MULT(_nshift, _nwidth), \
156 .m = _SUNXI_CCU_DIV(_mshift, _mwidth), \
159 .hw.init = CLK_HW_INIT(_name, \
166 static inline struct ccu_nm *hw_to_ccu_nm(struct clk_hw *hw)
168 struct ccu_common *common = hw_to_ccu_common(hw);
170 return container_of(common, struct ccu_nm, common);
173 extern const struct clk_ops ccu_nm_ops;
175 #endif /* _CCU_NM_H_ */