• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // Spreadtrum composite clock driver
4 //
5 // Copyright (C) 2017 Spreadtrum, Inc.
6 // Author: Chunyan Zhang <chunyan.zhang@spreadtrum.com>
7 
8 #include <linux/clk-provider.h>
9 
10 #include "composite.h"
11 
sprd_comp_round_rate(struct clk_hw * hw,unsigned long rate,unsigned long * parent_rate)12 static long sprd_comp_round_rate(struct clk_hw *hw, unsigned long rate,
13 				unsigned long *parent_rate)
14 {
15 	struct sprd_comp *cc = hw_to_sprd_comp(hw);
16 
17 	return sprd_div_helper_round_rate(&cc->common, &cc->div,
18 					 rate, parent_rate);
19 }
20 
sprd_comp_recalc_rate(struct clk_hw * hw,unsigned long parent_rate)21 static unsigned long sprd_comp_recalc_rate(struct clk_hw *hw,
22 					  unsigned long parent_rate)
23 {
24 	struct sprd_comp *cc = hw_to_sprd_comp(hw);
25 
26 	return sprd_div_helper_recalc_rate(&cc->common, &cc->div, parent_rate);
27 }
28 
sprd_comp_set_rate(struct clk_hw * hw,unsigned long rate,unsigned long parent_rate)29 static int sprd_comp_set_rate(struct clk_hw *hw, unsigned long rate,
30 			     unsigned long parent_rate)
31 {
32 	struct sprd_comp *cc = hw_to_sprd_comp(hw);
33 
34 	return sprd_div_helper_set_rate(&cc->common, &cc->div,
35 				       rate, parent_rate);
36 }
37 
sprd_comp_get_parent(struct clk_hw * hw)38 static u8 sprd_comp_get_parent(struct clk_hw *hw)
39 {
40 	struct sprd_comp *cc = hw_to_sprd_comp(hw);
41 
42 	return sprd_mux_helper_get_parent(&cc->common, &cc->mux);
43 }
44 
sprd_comp_set_parent(struct clk_hw * hw,u8 index)45 static int sprd_comp_set_parent(struct clk_hw *hw, u8 index)
46 {
47 	struct sprd_comp *cc = hw_to_sprd_comp(hw);
48 
49 	return sprd_mux_helper_set_parent(&cc->common, &cc->mux, index);
50 }
51 
52 const struct clk_ops sprd_comp_ops = {
53 	.get_parent	= sprd_comp_get_parent,
54 	.set_parent	= sprd_comp_set_parent,
55 
56 	.round_rate	= sprd_comp_round_rate,
57 	.recalc_rate	= sprd_comp_recalc_rate,
58 	.set_rate	= sprd_comp_set_rate,
59 };
60 EXPORT_SYMBOL_GPL(sprd_comp_ops);
61