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