xref: /openbmc/linux/drivers/clk/qcom/clk-branch.h (revision b96fbb03)
1f9419783STaniya Das /* SPDX-License-Identifier: GPL-2.0 */
2f9419783STaniya Das /* Copyright (c) 2013, The Linux Foundation. All rights reserved. */
36e0ad1b6SStephen Boyd 
46e0ad1b6SStephen Boyd #ifndef __QCOM_CLK_BRANCH_H__
56e0ad1b6SStephen Boyd #define __QCOM_CLK_BRANCH_H__
66e0ad1b6SStephen Boyd 
70932e565SKonrad Dybcio #include <linux/bitfield.h>
86e0ad1b6SStephen Boyd #include <linux/clk-provider.h>
96e0ad1b6SStephen Boyd 
106e0ad1b6SStephen Boyd #include "clk-regmap.h"
116e0ad1b6SStephen Boyd 
126e0ad1b6SStephen Boyd /**
136e0ad1b6SStephen Boyd  * struct clk_branch - gating clock with status bit and dynamic hardware gating
146e0ad1b6SStephen Boyd  *
156e0ad1b6SStephen Boyd  * @hwcg_reg: dynamic hardware clock gating register
166e0ad1b6SStephen Boyd  * @hwcg_bit: ORed with @hwcg_reg to enable dynamic hardware clock gating
176e0ad1b6SStephen Boyd  * @halt_reg: halt register
186e0ad1b6SStephen Boyd  * @halt_bit: ANDed with @halt_reg to test for clock halted
196e0ad1b6SStephen Boyd  * @halt_check: type of halt checking to perform
206e0ad1b6SStephen Boyd  * @clkr: handle between common and hardware-specific interfaces
216e0ad1b6SStephen Boyd  *
226e0ad1b6SStephen Boyd  * Clock which can gate its output.
236e0ad1b6SStephen Boyd  */
246e0ad1b6SStephen Boyd struct clk_branch {
256e0ad1b6SStephen Boyd 	u32	hwcg_reg;
266e0ad1b6SStephen Boyd 	u32	halt_reg;
276e0ad1b6SStephen Boyd 	u8	hwcg_bit;
286e0ad1b6SStephen Boyd 	u8	halt_bit;
296e0ad1b6SStephen Boyd 	u8	halt_check;
306e0ad1b6SStephen Boyd #define BRANCH_VOTED			BIT(7) /* Delay on disable */
316e0ad1b6SStephen Boyd #define BRANCH_HALT			0 /* pol: 1 = halt */
326e0ad1b6SStephen Boyd #define BRANCH_HALT_VOTED		(BRANCH_HALT | BRANCH_VOTED)
336e0ad1b6SStephen Boyd #define BRANCH_HALT_ENABLE		1 /* pol: 0 = halt */
346e0ad1b6SStephen Boyd #define BRANCH_HALT_ENABLE_VOTED	(BRANCH_HALT_ENABLE | BRANCH_VOTED)
356e0ad1b6SStephen Boyd #define BRANCH_HALT_DELAY		2 /* No bit to check; just delay */
367d99ced8SAmit Nischal #define BRANCH_HALT_SKIP		3 /* Don't check halt bit */
376e0ad1b6SStephen Boyd 
386e0ad1b6SStephen Boyd 	struct clk_regmap clkr;
396e0ad1b6SStephen Boyd };
406e0ad1b6SStephen Boyd 
41b594e6f6SKonrad Dybcio /* Branch clock common bits for HLOS-owned clocks */
42*b96fbb03SKonrad Dybcio #define CBCR_CLK_OFF			BIT(31)
43*b96fbb03SKonrad Dybcio #define CBCR_NOC_FSM_STATUS		GENMASK(30, 28)
44*b96fbb03SKonrad Dybcio  #define FSM_STATUS_ON			BIT(1)
45b594e6f6SKonrad Dybcio #define CBCR_FORCE_MEM_CORE_ON		BIT(14)
46b594e6f6SKonrad Dybcio #define CBCR_FORCE_MEM_PERIPH_ON	BIT(13)
47b594e6f6SKonrad Dybcio #define CBCR_FORCE_MEM_PERIPH_OFF	BIT(12)
480932e565SKonrad Dybcio #define CBCR_WAKEUP			GENMASK(11, 8)
490932e565SKonrad Dybcio #define CBCR_SLEEP			GENMASK(7, 4)
50b594e6f6SKonrad Dybcio 
qcom_branch_set_force_mem_core(struct regmap * regmap,struct clk_branch clk,bool on)51b594e6f6SKonrad Dybcio static inline void qcom_branch_set_force_mem_core(struct regmap *regmap,
52b594e6f6SKonrad Dybcio 						  struct clk_branch clk, bool on)
53b594e6f6SKonrad Dybcio {
54b594e6f6SKonrad Dybcio 	regmap_update_bits(regmap, clk.halt_reg, CBCR_FORCE_MEM_CORE_ON,
55b594e6f6SKonrad Dybcio 			   on ? CBCR_FORCE_MEM_CORE_ON : 0);
56b594e6f6SKonrad Dybcio }
57b594e6f6SKonrad Dybcio 
qcom_branch_set_force_periph_on(struct regmap * regmap,struct clk_branch clk,bool on)58b594e6f6SKonrad Dybcio static inline void qcom_branch_set_force_periph_on(struct regmap *regmap,
59b594e6f6SKonrad Dybcio 						   struct clk_branch clk, bool on)
60b594e6f6SKonrad Dybcio {
61b594e6f6SKonrad Dybcio 	regmap_update_bits(regmap, clk.halt_reg, CBCR_FORCE_MEM_PERIPH_ON,
62b594e6f6SKonrad Dybcio 			   on ? CBCR_FORCE_MEM_PERIPH_ON : 0);
63b594e6f6SKonrad Dybcio }
64b594e6f6SKonrad Dybcio 
qcom_branch_set_force_periph_off(struct regmap * regmap,struct clk_branch clk,bool on)65b594e6f6SKonrad Dybcio static inline void qcom_branch_set_force_periph_off(struct regmap *regmap,
66b594e6f6SKonrad Dybcio 						    struct clk_branch clk, bool on)
67b594e6f6SKonrad Dybcio {
68b594e6f6SKonrad Dybcio 	regmap_update_bits(regmap, clk.halt_reg, CBCR_FORCE_MEM_PERIPH_OFF,
69b594e6f6SKonrad Dybcio 			   on ? CBCR_FORCE_MEM_PERIPH_OFF : 0);
70b594e6f6SKonrad Dybcio }
71b594e6f6SKonrad Dybcio 
qcom_branch_set_wakeup(struct regmap * regmap,struct clk_branch clk,u32 val)720932e565SKonrad Dybcio static inline void qcom_branch_set_wakeup(struct regmap *regmap, struct clk_branch clk, u32 val)
730932e565SKonrad Dybcio {
740932e565SKonrad Dybcio 	regmap_update_bits(regmap, clk.halt_reg, CBCR_WAKEUP,
750932e565SKonrad Dybcio 			   FIELD_PREP(CBCR_WAKEUP, val));
760932e565SKonrad Dybcio }
770932e565SKonrad Dybcio 
qcom_branch_set_sleep(struct regmap * regmap,struct clk_branch clk,u32 val)780932e565SKonrad Dybcio static inline void qcom_branch_set_sleep(struct regmap *regmap, struct clk_branch clk, u32 val)
790932e565SKonrad Dybcio {
800932e565SKonrad Dybcio 	regmap_update_bits(regmap, clk.halt_reg, CBCR_SLEEP,
810932e565SKonrad Dybcio 			   FIELD_PREP(CBCR_SLEEP, val));
820932e565SKonrad Dybcio }
830932e565SKonrad Dybcio 
846e0ad1b6SStephen Boyd extern const struct clk_ops clk_branch_ops;
856e0ad1b6SStephen Boyd extern const struct clk_ops clk_branch2_ops;
866e0ad1b6SStephen Boyd extern const struct clk_ops clk_branch_simple_ops;
87360fed42SBjorn Andersson extern const struct clk_ops clk_branch2_aon_ops;
886e0ad1b6SStephen Boyd 
896e0ad1b6SStephen Boyd #define to_clk_branch(_hw) \
906e0ad1b6SStephen Boyd 	container_of(to_clk_regmap(_hw), struct clk_branch, clkr)
916e0ad1b6SStephen Boyd 
926e0ad1b6SStephen Boyd #endif
93