Skip to content

Commit 4fcba55

Browse files
Lyra-Zhangbebarino
authored andcommitted
clk: sprd: add composite clock support
This patch introduced composite driver for Spreadtrum's SoCs. The functions of this composite clock simply consist of divider and mux clocks. Signed-off-by: Chunyan Zhang <chunyan.zhang@spreadtrum.com> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
1 parent e3f05d3 commit 4fcba55

3 files changed

Lines changed: 112 additions & 0 deletions

File tree

‎drivers/clk/sprd/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ clk-sprd-y += common.o
44
clk-sprd-y += gate.o
55
clk-sprd-y += mux.o
66
clk-sprd-y += div.o
7+
clk-sprd-y += composite.o

‎drivers/clk/sprd/composite.c‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
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+
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+
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+
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+
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);

‎drivers/clk/sprd/composite.h‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
#ifndef _SPRD_COMPOSITE_H_
9+
#define _SPRD_COMPOSITE_H_
10+
11+
#include "common.h"
12+
#include "mux.h"
13+
#include "div.h"
14+
15+
struct sprd_comp {
16+
struct sprd_mux_ssel mux;
17+
struct sprd_div_internal div;
18+
struct sprd_clk_common common;
19+
};
20+
21+
#define SPRD_COMP_CLK_TABLE(_struct, _name, _parent, _reg, _table, \
22+
_mshift, _mwidth, _dshift, _dwidth, _flags) \
23+
struct sprd_comp _struct = { \
24+
.mux = _SPRD_MUX_CLK(_mshift, _mwidth, _table), \
25+
.div = _SPRD_DIV_CLK(_dshift, _dwidth), \
26+
.common = { \
27+
.regmap = NULL, \
28+
.reg = _reg, \
29+
.hw.init = CLK_HW_INIT_PARENTS(_name, \
30+
_parent, \
31+
&sprd_comp_ops, \
32+
_flags), \
33+
} \
34+
}
35+
36+
#define SPRD_COMP_CLK(_struct, _name, _parent, _reg, _mshift, \
37+
_mwidth, _dshift, _dwidth, _flags) \
38+
SPRD_COMP_CLK_TABLE(_struct, _name, _parent, _reg, \
39+
NULL, _mshift, _mwidth, \
40+
_dshift, _dwidth, _flags)
41+
42+
static inline struct sprd_comp *hw_to_sprd_comp(const struct clk_hw *hw)
43+
{
44+
struct sprd_clk_common *common = hw_to_sprd_clk_common(hw);
45+
46+
return container_of(common, struct sprd_comp, common);
47+
}
48+
49+
extern const struct clk_ops sprd_comp_ops;
50+
51+
#endif /* _SPRD_COMPOSITE_H_ */

0 commit comments

Comments
 (0)