1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2016 Maxime Ripard. All rights reserved.
9 #include <linux/clk-provider.h>
11 #include "ccu_common.h"
15 * struct ccu_div_internal - Internal divider description
16 * @shift: Bit offset of the divider in its register
17 * @width: Width of the divider field in its register
18 * @max: Maximum value allowed for that divider. This is the
19 * arithmetic value, not the maximum value to be set in the
21 * @flags: clk_divider flags to apply on this divider
22 * @table: Divider table pointer (if applicable)
24 * That structure represents a single divider, and is meant to be
25 * embedded in other structures representing the various clock
28 * It is basically a wrapper around the clk_divider functions
31 struct ccu_div_internal
{
40 struct clk_div_table
*table
;
43 #define _SUNXI_CCU_DIV_TABLE_FLAGS(_shift, _width, _table, _flags) \
51 #define _SUNXI_CCU_DIV_TABLE(_shift, _width, _table) \
52 _SUNXI_CCU_DIV_TABLE_FLAGS(_shift, _width, _table, 0)
54 #define _SUNXI_CCU_DIV_OFFSET_MAX_FLAGS(_shift, _width, _off, _max, _flags) \
63 #define _SUNXI_CCU_DIV_MAX_FLAGS(_shift, _width, _max, _flags) \
64 _SUNXI_CCU_DIV_OFFSET_MAX_FLAGS(_shift, _width, 1, _max, _flags)
66 #define _SUNXI_CCU_DIV_FLAGS(_shift, _width, _flags) \
67 _SUNXI_CCU_DIV_MAX_FLAGS(_shift, _width, 0, _flags)
69 #define _SUNXI_CCU_DIV_MAX(_shift, _width, _max) \
70 _SUNXI_CCU_DIV_MAX_FLAGS(_shift, _width, _max, 0)
72 #define _SUNXI_CCU_DIV_OFFSET(_shift, _width, _offset) \
73 _SUNXI_CCU_DIV_OFFSET_MAX_FLAGS(_shift, _width, _offset, 0, 0)
75 #define _SUNXI_CCU_DIV(_shift, _width) \
76 _SUNXI_CCU_DIV_FLAGS(_shift, _width, 0)
81 struct ccu_div_internal div
;
82 struct ccu_mux_internal mux
;
83 struct ccu_common common
;
84 unsigned int fixed_post_div
;
87 #define SUNXI_CCU_DIV_TABLE_WITH_GATE(_struct, _name, _parent, _reg, \
89 _table, _gate, _flags) \
90 struct ccu_div _struct = { \
91 .div = _SUNXI_CCU_DIV_TABLE(_shift, _width, \
96 .hw.init = CLK_HW_INIT(_name, \
104 #define SUNXI_CCU_DIV_TABLE(_struct, _name, _parent, _reg, \
107 SUNXI_CCU_DIV_TABLE_WITH_GATE(_struct, _name, _parent, _reg, \
108 _shift, _width, _table, 0, \
111 #define SUNXI_CCU_M_WITH_MUX_TABLE_GATE(_struct, _name, \
115 _muxshift, _muxwidth, \
117 struct ccu_div _struct = { \
119 .div = _SUNXI_CCU_DIV(_mshift, _mwidth), \
120 .mux = _SUNXI_CCU_MUX_TABLE(_muxshift, _muxwidth, _table), \
123 .hw.init = CLK_HW_INIT_PARENTS(_name, \
130 #define SUNXI_CCU_M_WITH_MUX_GATE(_struct, _name, _parents, _reg, \
131 _mshift, _mwidth, _muxshift, _muxwidth, \
133 SUNXI_CCU_M_WITH_MUX_TABLE_GATE(_struct, _name, \
135 _reg, _mshift, _mwidth, \
136 _muxshift, _muxwidth, \
139 #define SUNXI_CCU_M_WITH_MUX(_struct, _name, _parents, _reg, \
140 _mshift, _mwidth, _muxshift, _muxwidth, \
142 SUNXI_CCU_M_WITH_MUX_TABLE_GATE(_struct, _name, \
144 _reg, _mshift, _mwidth, \
145 _muxshift, _muxwidth, \
149 #define SUNXI_CCU_M_WITH_GATE(_struct, _name, _parent, _reg, \
150 _mshift, _mwidth, _gate, \
152 struct ccu_div _struct = { \
154 .div = _SUNXI_CCU_DIV(_mshift, _mwidth), \
157 .hw.init = CLK_HW_INIT(_name, \
164 #define SUNXI_CCU_M(_struct, _name, _parent, _reg, _mshift, _mwidth, \
166 SUNXI_CCU_M_WITH_GATE(_struct, _name, _parent, _reg, \
167 _mshift, _mwidth, 0, _flags)
169 static inline struct ccu_div
*hw_to_ccu_div(struct clk_hw
*hw
)
171 struct ccu_common
*common
= hw_to_ccu_common(hw
);
173 return container_of(common
, struct ccu_div
, common
);
176 extern const struct clk_ops ccu_div_ops
;
178 #endif /* _CCU_DIV_H_ */