xref: /linux/drivers/clk/spacemit/ccu_ddn.h (revision 9f32a03e3e0d372c520d829dd4da6022fe88832a)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2024 SpacemiT Technology Co. Ltd
4  * Copyright (c) 2024-2025 Haylen Chu <heylenay@4d2.org>
5  */
6 
7 #ifndef _CCU_DDN_H_
8 #define _CCU_DDN_H_
9 
10 #include <linux/bitops.h>
11 #include <linux/clk-provider.h>
12 
13 #include "ccu_common.h"
14 
15 struct ccu_ddn {
16 	struct ccu_common common;
17 	unsigned int num_mask;
18 	unsigned int num_shift;
19 	unsigned int den_mask;
20 	unsigned int den_shift;
21 };
22 
23 #define CCU_DDN_INIT(_name, _parent, _flags) \
24 	CLK_HW_INIT_HW(#_name, &_parent.common.hw, &spacemit_ccu_ddn_ops, _flags)
25 
26 #define CCU_DDN_DEFINE(_name, _parent, _reg_ctrl, _num_shift, _num_width,	\
27 		       _den_shift, _den_width, _flags)				\
28 static struct ccu_ddn _name = {							\
29 	.common = {								\
30 		.reg_ctrl	= _reg_ctrl,					\
31 		.hw.init	= CCU_DDN_INIT(_name, _parent, _flags),		\
32 	},									\
33 	.num_mask	= GENMASK(_num_shift + _num_width - 1, _num_shift),	\
34 	.num_shift	= _num_shift,						\
35 	.den_mask	= GENMASK(_den_shift + _den_width - 1, _den_shift),	\
36 	.den_shift	= _den_shift,					\
37 }
38 
hw_to_ccu_ddn(struct clk_hw * hw)39 static inline struct ccu_ddn *hw_to_ccu_ddn(struct clk_hw *hw)
40 {
41 	struct ccu_common *common = hw_to_ccu_common(hw);
42 
43 	return container_of(common, struct ccu_ddn, common);
44 }
45 
46 extern const struct clk_ops spacemit_ccu_ddn_ops;
47 
48 #endif
49