18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2016 Maxime Ripard. All rights reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef _COMMON_H_
78c2ecf20Sopenharmony_ci#define _COMMON_H_
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/compiler.h>
108c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define CCU_FEATURE_FRACTIONAL		BIT(0)
138c2ecf20Sopenharmony_ci#define CCU_FEATURE_VARIABLE_PREDIV	BIT(1)
148c2ecf20Sopenharmony_ci#define CCU_FEATURE_FIXED_PREDIV	BIT(2)
158c2ecf20Sopenharmony_ci#define CCU_FEATURE_FIXED_POSTDIV	BIT(3)
168c2ecf20Sopenharmony_ci#define CCU_FEATURE_ALL_PREDIV		BIT(4)
178c2ecf20Sopenharmony_ci#define CCU_FEATURE_LOCK_REG		BIT(5)
188c2ecf20Sopenharmony_ci#define CCU_FEATURE_MMC_TIMING_SWITCH	BIT(6)
198c2ecf20Sopenharmony_ci#define CCU_FEATURE_SIGMA_DELTA_MOD	BIT(7)
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* MMC timing mode switch bit */
228c2ecf20Sopenharmony_ci#define CCU_MMC_NEW_TIMING_MODE		BIT(30)
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistruct device_node;
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistruct ccu_common {
278c2ecf20Sopenharmony_ci	void __iomem	*base;
288c2ecf20Sopenharmony_ci	u16		reg;
298c2ecf20Sopenharmony_ci	u16		lock_reg;
308c2ecf20Sopenharmony_ci	u32		prediv;
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	unsigned long	features;
338c2ecf20Sopenharmony_ci	spinlock_t	*lock;
348c2ecf20Sopenharmony_ci	struct clk_hw	hw;
358c2ecf20Sopenharmony_ci};
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic inline struct ccu_common *hw_to_ccu_common(struct clk_hw *hw)
388c2ecf20Sopenharmony_ci{
398c2ecf20Sopenharmony_ci	return container_of(hw, struct ccu_common, hw);
408c2ecf20Sopenharmony_ci}
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct sunxi_ccu_desc {
438c2ecf20Sopenharmony_ci	struct ccu_common		**ccu_clks;
448c2ecf20Sopenharmony_ci	unsigned long			num_ccu_clks;
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	struct clk_hw_onecell_data	*hw_clks;
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	struct ccu_reset_map		*resets;
498c2ecf20Sopenharmony_ci	unsigned long			num_resets;
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_civoid ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock);
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistruct ccu_pll_nb {
558c2ecf20Sopenharmony_ci	struct notifier_block	clk_nb;
568c2ecf20Sopenharmony_ci	struct ccu_common	*common;
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci	u32	enable;
598c2ecf20Sopenharmony_ci	u32	lock;
608c2ecf20Sopenharmony_ci};
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#define to_ccu_pll_nb(_nb) container_of(_nb, struct ccu_pll_nb, clk_nb)
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ciint ccu_pll_notifier_register(struct ccu_pll_nb *pll_nb);
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ciint sunxi_ccu_probe(struct device_node *node, void __iomem *reg,
678c2ecf20Sopenharmony_ci		    const struct sunxi_ccu_desc *desc);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#endif /* _COMMON_H_ */
70