summaryrefslogtreecommitdiff
path: root/drivers/clk/spacemit/ccu_common.h
blob: da72f3836e0b5c3482ffbb32d9d0f7f9185bfb54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2024 SpacemiT Technology Co. Ltd
 * Copyright (c) 2024-2025 Haylen Chu <heylenay@4d2.org>
 */

#ifndef _CCU_COMMON_H_
#define _CCU_COMMON_H_

#include <linux/regmap.h>

struct ccu_common {
	struct regmap *regmap;
	struct regmap *lock_regmap;

	union {
		/* For DDN and MIX */
		struct {
			u32 reg_ctrl;
			u32 reg_fc;
			u32 mask_fc;
		};

		/* For PLL */
		struct {
			u32 reg_swcr1;
			u32 reg_swcr3;
		};
	};

	struct clk_hw hw;
};

static inline struct ccu_common *hw_to_ccu_common(struct clk_hw *hw)
{
	return container_of(hw, struct ccu_common, hw);
}

#define ccu_read(c, reg)						\
	({								\
		u32 tmp;						\
		regmap_read((c)->regmap, (c)->reg_##reg, &tmp);		\
		tmp;							\
	 })
#define ccu_update(c, reg, mask, val) \
	regmap_update_bits((c)->regmap, (c)->reg_##reg, mask, val)

#endif /* _CCU_COMMON_H_ */