1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _CCU_MULT_H_
3 #define _CCU_MULT_H_
4 
5 #include "ccu_common.h"
6 #include "ccu_frac.h"
7 #include "ccu_mux.h"
8 
9 struct ccu_mult_internal
10 {
11     u8  offset;
12     u8  shift;
13     u8  width;
14     u8  min;
15     u8  max;
16 };
17 
18 #define _SUNXI_CCU_MULT_OFFSET_MIN_MAX(_shift, _width, _offset, _min, _max) \
19     {                               \
20         .min    = _min,                     \
21                   .max    = _max,                     \
22                             .offset = _offset,                  \
23                                       .shift  = _shift,                   \
24                                                 .width  = _width,                   \
25     }
26 
27 #define _SUNXI_CCU_MULT_MIN(_shift, _width, _min)   \
28     _SUNXI_CCU_MULT_OFFSET_MIN_MAX(_shift, _width, 1, _min, 0)
29 
30 #define _SUNXI_CCU_MULT_OFFSET(_shift, _width, _offset) \
31     _SUNXI_CCU_MULT_OFFSET_MIN_MAX(_shift, _width, _offset, 1, 0)
32 
33 #define _SUNXI_CCU_MULT(_shift, _width)     \
34     _SUNXI_CCU_MULT_OFFSET_MIN_MAX(_shift, _width, 1, 1, 0)
35 
36 struct ccu_mult
37 {
38     u32         enable;
39     u32         lock;
40 
41     struct ccu_frac_internal    frac;
42     struct ccu_mult_internal    mult;
43     struct ccu_mux_internal mux;
44     struct ccu_common   common;
45 };
46 
47 #define SUNXI_CCU_N_WITH_GATE_LOCK(_struct, _name, _parent, _reg,   \
48                                    _mshift, _mwidth, _gate, _lock,  \
49                                    _flags)              \
50 struct ccu_mult _struct = {                 \
51     .enable = _gate,                    \
52               .lock   = _lock,                    \
53                         .mult   = _SUNXI_CCU_MULT(_mshift, _mwidth),        \
54                                   .common = {                     \
55                                                                   .reg        = _reg,             \
56                                                                   .hw.init    = CLK_HW_INIT(_name,        \
57                                                                           _parent,      \
58                                                                           &ccu_mult_ops,    \
59                                                                           _flags),      \
60                                             },                          \
61 }
62 
hw_to_ccu_mult(struct clk_hw * hw)63 static inline struct ccu_mult *hw_to_ccu_mult(struct clk_hw *hw)
64 {
65     struct ccu_common *common = hw_to_ccu_common(hw);
66 
67     return container_of(common, struct ccu_mult, common);
68 }
69 
70 extern const struct clk_ops ccu_mult_ops;
71 
72 #endif /* _CCU_MULT_H_ */
73