1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2018 Amarula Solutions.
4  * Author: Jagan Teki <jagan@amarulasolutions.com>
5  */
6 
7 #ifndef _ASM_ARCH_CCU_H
8 #define _ASM_ARCH_CCU_H
9 
10 #ifndef __ASSEMBLY__
11 #include <linux/bitops.h>
12 #endif
13 
14 /**
15  * enum ccu_flags - ccu clock/reset flags
16  *
17  * @CCU_CLK_F_IS_VALID:		is given clock gate is valid?
18  * @CCU_RST_F_IS_VALID:		is given reset control is valid?
19  */
20 enum ccu_flags {
21 	CCU_CLK_F_IS_VALID		= BIT(0),
22 	CCU_RST_F_IS_VALID		= BIT(1),
23 };
24 
25 /**
26  * struct ccu_clk_gate - ccu clock gate
27  * @off:	gate offset
28  * @bit:	gate bit
29  * @flags:	ccu clock gate flags
30  */
31 struct ccu_clk_gate {
32 	u16 off;
33 	u32 bit;
34 	enum ccu_flags flags;
35 };
36 
37 #define GATE(_off, _bit) {			\
38 	.off = _off,				\
39 	.bit = _bit,				\
40 	.flags = CCU_CLK_F_IS_VALID,		\
41 }
42 
43 /**
44  * struct ccu_reset - ccu reset
45  * @off:	reset offset
46  * @bit:	reset bit
47  * @flags:	ccu reset control flags
48  */
49 struct ccu_reset {
50 	u16 off;
51 	u32 bit;
52 	enum ccu_flags flags;
53 };
54 
55 #define RESET(_off, _bit) {			\
56 	.off = _off,				\
57 	.bit = _bit,				\
58 	.flags = CCU_RST_F_IS_VALID,		\
59 }
60 
61 /**
62  * struct ccu_desc - clock control unit descriptor
63  *
64  * @gates:	clock gates
65  * @resets:	reset unit
66  */
67 struct ccu_desc {
68 	const struct ccu_clk_gate *gates;
69 	const struct ccu_reset *resets;
70 };
71 
72 /**
73  * struct ccu_priv - sunxi clock control unit
74  *
75  * @base:	base address
76  * @desc:	ccu descriptor
77  */
78 struct ccu_priv {
79 	void *base;
80 	const struct ccu_desc *desc;
81 };
82 
83 /**
84  * sunxi_clk_probe - common sunxi clock probe
85  * @dev:	clock device
86  */
87 int sunxi_clk_probe(struct udevice *dev);
88 
89 extern struct clk_ops sunxi_clk_ops;
90 
91 /**
92  * sunxi_reset_bind() - reset binding
93  *
94  * @dev:       reset device
95  * @count:     reset count
96  * @return 0 success, or error value
97  */
98 int sunxi_reset_bind(struct udevice *dev, ulong count);
99 
100 #endif /* _ASM_ARCH_CCU_H */
101