xref: /linux/drivers/clk/actions/owl-divider.h (revision c39f2d9db0fd81ea20bb5cce9b3f082ca63753e2)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 //
3 // OWL divider clock driver
4 //
5 // Copyright (c) 2014 Actions Semi Inc.
6 // Author: David Liu <liuwei@actions-semi.com>
7 //
8 // Copyright (c) 2018 Linaro Ltd.
9 // Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
10 
11 #ifndef _OWL_DIVIDER_H_
12 #define _OWL_DIVIDER_H_
13 
14 #include "owl-common.h"
15 
16 struct owl_divider_hw {
17 	u32			reg;
18 	u8			shift;
19 	u8			width;
20 	u8			div_flags;
21 	struct clk_div_table	*table;
22 };
23 
24 struct owl_divider {
25 	struct owl_divider_hw	div_hw;
26 	struct owl_clk_common	common;
27 };
28 
29 #define OWL_DIVIDER_HW(_reg, _shift, _width, _div_flags, _table)	\
30 	{								\
31 		.reg		= _reg,					\
32 		.shift		= _shift,				\
33 		.width		= _width,				\
34 		.div_flags	= _div_flags,				\
35 		.table		= _table,				\
36 	}
37 
38 #define OWL_DIVIDER(_struct, _name, _parent, _reg,			\
39 		    _shift, _width, _table, _div_flags, _flags)		\
40 	struct owl_divider _struct = {					\
41 		.div_hw	= OWL_DIVIDER_HW(_reg, _shift, _width,		\
42 					 _div_flags, _table),		\
43 		.common = {						\
44 			.regmap		= NULL,				\
45 			.hw.init	= CLK_HW_INIT(_name,		\
46 						      _parent,		\
47 						      &owl_divider_ops,	\
48 						      _flags),		\
49 		},							\
50 	}
51 
hw_to_owl_divider(const struct clk_hw * hw)52 static inline struct owl_divider *hw_to_owl_divider(const struct clk_hw *hw)
53 {
54 	struct owl_clk_common *common = hw_to_owl_clk_common(hw);
55 
56 	return container_of(common, struct owl_divider, common);
57 }
58 
59 long owl_divider_helper_round_rate(struct owl_clk_common *common,
60 				const struct owl_divider_hw *div_hw,
61 				unsigned long rate,
62 				unsigned long *parent_rate);
63 
64 unsigned long owl_divider_helper_recalc_rate(struct owl_clk_common *common,
65 					 const struct owl_divider_hw *div_hw,
66 					 unsigned long parent_rate);
67 
68 int owl_divider_helper_set_rate(const struct owl_clk_common *common,
69 				const struct owl_divider_hw *div_hw,
70 				unsigned long rate,
71 				unsigned long parent_rate);
72 
73 extern const struct clk_ops owl_divider_ops;
74 
75 #endif /* _OWL_DIVIDER_H_ */
76