Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) // OWL composite clock driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) // Copyright (c) 2014 Actions Semi Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) // Author: David Liu <liuwei@actions-semi.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) // Copyright (c) 2018 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) // Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/clk-provider.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "owl-composite.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) static u8 owl_comp_get_parent(struct clk_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	struct owl_composite *comp = hw_to_owl_comp(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	return owl_mux_helper_get_parent(&comp->common, &comp->mux_hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static int owl_comp_set_parent(struct clk_hw *hw, u8 index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct owl_composite *comp = hw_to_owl_comp(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	return owl_mux_helper_set_parent(&comp->common, &comp->mux_hw, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static void owl_comp_disable(struct clk_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct owl_composite *comp = hw_to_owl_comp(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct owl_clk_common *common = &comp->common;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	owl_gate_set(common, &comp->gate_hw, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static int owl_comp_enable(struct clk_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct owl_composite *comp = hw_to_owl_comp(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct owl_clk_common *common = &comp->common;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	owl_gate_set(common, &comp->gate_hw, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static int owl_comp_is_enabled(struct clk_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct owl_composite *comp = hw_to_owl_comp(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct owl_clk_common *common = &comp->common;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	return owl_gate_clk_is_enabled(common, &comp->gate_hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static long owl_comp_div_round_rate(struct clk_hw *hw, unsigned long rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 				unsigned long *parent_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct owl_composite *comp = hw_to_owl_comp(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	return owl_divider_helper_round_rate(&comp->common, &comp->rate.div_hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 					rate, parent_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static unsigned long owl_comp_div_recalc_rate(struct clk_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 					  unsigned long parent_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct owl_composite *comp = hw_to_owl_comp(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return owl_divider_helper_recalc_rate(&comp->common, &comp->rate.div_hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 					parent_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static int owl_comp_div_set_rate(struct clk_hw *hw, unsigned long rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 				unsigned long parent_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct owl_composite *comp = hw_to_owl_comp(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	return owl_divider_helper_set_rate(&comp->common, &comp->rate.div_hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 					rate, parent_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static long owl_comp_fact_round_rate(struct clk_hw *hw, unsigned long rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			unsigned long *parent_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct owl_composite *comp = hw_to_owl_comp(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return owl_factor_helper_round_rate(&comp->common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 					&comp->rate.factor_hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 					rate, parent_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static unsigned long owl_comp_fact_recalc_rate(struct clk_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			unsigned long parent_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct owl_composite *comp = hw_to_owl_comp(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return owl_factor_helper_recalc_rate(&comp->common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 					&comp->rate.factor_hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 					parent_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int owl_comp_fact_set_rate(struct clk_hw *hw, unsigned long rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			unsigned long parent_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct owl_composite *comp = hw_to_owl_comp(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return owl_factor_helper_set_rate(&comp->common,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 					&comp->rate.factor_hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 					rate, parent_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static long owl_comp_fix_fact_round_rate(struct clk_hw *hw, unsigned long rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			unsigned long *parent_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct owl_composite *comp = hw_to_owl_comp(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct clk_fixed_factor *fix_fact_hw = &comp->rate.fix_fact_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return comp->fix_fact_ops->round_rate(&fix_fact_hw->hw, rate, parent_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static unsigned long owl_comp_fix_fact_recalc_rate(struct clk_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			unsigned long parent_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct owl_composite *comp = hw_to_owl_comp(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct clk_fixed_factor *fix_fact_hw = &comp->rate.fix_fact_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return comp->fix_fact_ops->recalc_rate(&fix_fact_hw->hw, parent_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static int owl_comp_fix_fact_set_rate(struct clk_hw *hw, unsigned long rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			unsigned long parent_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	 * We must report success but we can do so unconditionally because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	 * owl_comp_fix_fact_round_rate returns values that ensure this call is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	 * a nop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) const struct clk_ops owl_comp_div_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	/* mux_ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	.get_parent	= owl_comp_get_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	.set_parent	= owl_comp_set_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	/* gate_ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	.disable	= owl_comp_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	.enable		= owl_comp_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	.is_enabled	= owl_comp_is_enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	/* div_ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	.round_rate	= owl_comp_div_round_rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	.recalc_rate	= owl_comp_div_recalc_rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	.set_rate	= owl_comp_div_set_rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) const struct clk_ops owl_comp_fact_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	/* mux_ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	.get_parent	= owl_comp_get_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	.set_parent	= owl_comp_set_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	/* gate_ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	.disable	= owl_comp_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	.enable		= owl_comp_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	.is_enabled	= owl_comp_is_enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	/* fact_ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	.round_rate	= owl_comp_fact_round_rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	.recalc_rate	= owl_comp_fact_recalc_rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	.set_rate	= owl_comp_fact_set_rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) const struct clk_ops owl_comp_fix_fact_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	/* gate_ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	.disable	= owl_comp_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	.enable		= owl_comp_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	.is_enabled	= owl_comp_is_enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	/* fix_fact_ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	.round_rate	= owl_comp_fix_fact_round_rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	.recalc_rate	= owl_comp_fix_fact_recalc_rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	.set_rate	= owl_comp_fix_fact_set_rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) const struct clk_ops owl_comp_pass_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	/* mux_ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	.get_parent	= owl_comp_get_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	.set_parent	= owl_comp_set_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	/* gate_ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	.disable	= owl_comp_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	.enable		= owl_comp_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	.is_enabled	= owl_comp_is_enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) };