Skip to content

Commit 48a8748

Browse files
Zhifeng Tangbebarino
authored andcommitted
clk: sprd: Composite driver support offset config
The composite interface support the offset configuration, which is used to support mux and div in different registers. Because some sprd projects, the divider has different addresses from mux for one composite clk. Signed-off-by: Zhifeng Tang <[email protected]> Reviewed-by: Chunyan Zhang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 0bb80ec commit 48a8748

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

drivers/clk/sprd/composite.h

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ struct sprd_comp {
1919
};
2020

2121
#define SPRD_COMP_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, _table, \
22-
_mshift, _mwidth, _dshift, _dwidth, \
23-
_flags, _fn) \
22+
_mshift, _mwidth, _doffset, _dshift, \
23+
_dwidth, _flags, _fn) \
2424
struct sprd_comp _struct = { \
2525
.mux = _SPRD_MUX_CLK(_mshift, _mwidth, _table), \
26-
.div = _SPRD_DIV_CLK(_dshift, _dwidth), \
26+
.div = _SPRD_DIV_CLK(_doffset, _dshift, _dwidth), \
2727
.common = { \
2828
.regmap = NULL, \
2929
.reg = _reg, \
3030
.hw.init = _fn(_name, _parent, \
3131
&sprd_comp_ops, _flags), \
32-
} \
32+
} \
3333
}
3434

3535
#define SPRD_COMP_CLK_TABLE(_struct, _name, _parent, _reg, _table, \
3636
_mshift, _mwidth, _dshift, _dwidth, _flags) \
3737
SPRD_COMP_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, _table, \
38-
_mshift, _mwidth, _dshift, _dwidth, \
39-
_flags, CLK_HW_INIT_PARENTS)
38+
_mshift, _mwidth, 0x0, _dshift, \
39+
_dwidth, _flags, CLK_HW_INIT_PARENTS)
4040

4141
#define SPRD_COMP_CLK(_struct, _name, _parent, _reg, _mshift, \
4242
_mwidth, _dshift, _dwidth, _flags) \
@@ -47,15 +47,33 @@ struct sprd_comp {
4747
_mshift, _mwidth, _dshift, \
4848
_dwidth, _flags) \
4949
SPRD_COMP_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, _table, \
50-
_mshift, _mwidth, _dshift, _dwidth, \
51-
_flags, CLK_HW_INIT_PARENTS_DATA)
50+
_mshift, _mwidth, 0x0, _dshift, \
51+
_dwidth, _flags, \
52+
CLK_HW_INIT_PARENTS_DATA)
5253

5354
#define SPRD_COMP_CLK_DATA(_struct, _name, _parent, _reg, _mshift, \
5455
_mwidth, _dshift, _dwidth, _flags) \
55-
SPRD_COMP_CLK_DATA_TABLE(_struct, _name, _parent, _reg, NULL, \
56+
SPRD_COMP_CLK_DATA_TABLE(_struct, _name, _parent, _reg, NULL, \
5657
_mshift, _mwidth, _dshift, _dwidth, \
5758
_flags)
5859

60+
#define SPRD_COMP_CLK_DATA_TABLE_OFFSET(_struct, _name, _parent, _reg, \
61+
_table, _mshift, _mwidth, \
62+
_doffset, _dshift, _dwidth, \
63+
_flags) \
64+
SPRD_COMP_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, _table, \
65+
_mshift, _mwidth, _doffset, _dshift, \
66+
_dwidth, _flags, \
67+
CLK_HW_INIT_PARENTS_DATA)
68+
69+
#define SPRD_COMP_CLK_DATA_OFFSET(_struct, _name, _parent, _reg, \
70+
_mshift, _mwidth, _doffset, _dshift, \
71+
_dwidth, _flags) \
72+
SPRD_COMP_CLK_DATA_TABLE_OFFSET(_struct, _name, _parent, _reg, \
73+
NULL, _mshift, _mwidth, \
74+
_doffset, _dshift, _dwidth, \
75+
_flags)
76+
5977
static inline struct sprd_comp *hw_to_sprd_comp(const struct clk_hw *hw)
6078
{
6179
struct sprd_clk_common *common = hw_to_sprd_clk_common(hw);

drivers/clk/sprd/div.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ unsigned long sprd_div_helper_recalc_rate(struct sprd_clk_common *common,
2525
unsigned long val;
2626
unsigned int reg;
2727

28-
regmap_read(common->regmap, common->reg, &reg);
28+
regmap_read(common->regmap, common->reg + div->offset, &reg);
2929
val = reg >> div->shift;
3030
val &= (1 << div->width) - 1;
3131

@@ -53,10 +53,10 @@ int sprd_div_helper_set_rate(const struct sprd_clk_common *common,
5353
val = divider_get_val(rate, parent_rate, NULL,
5454
div->width, 0);
5555

56-
regmap_read(common->regmap, common->reg, &reg);
56+
regmap_read(common->regmap, common->reg + div->offset, &reg);
5757
reg &= ~GENMASK(div->width + div->shift - 1, div->shift);
5858

59-
regmap_write(common->regmap, common->reg,
59+
regmap_write(common->regmap, common->reg + div->offset,
6060
reg | (val << div->shift));
6161

6262
return 0;

drivers/clk/sprd/div.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
* classes.
2121
*/
2222
struct sprd_div_internal {
23+
s32 offset;
2324
u8 shift;
2425
u8 width;
2526
};
2627

27-
#define _SPRD_DIV_CLK(_shift, _width) \
28+
#define _SPRD_DIV_CLK(_offset, _shift, _width) \
2829
{ \
30+
.offset = _offset, \
2931
.shift = _shift, \
3032
.width = _width, \
3133
}
@@ -35,10 +37,10 @@ struct sprd_div {
3537
struct sprd_clk_common common;
3638
};
3739

38-
#define SPRD_DIV_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, \
40+
#define SPRD_DIV_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, _offset, \
3941
_shift, _width, _flags, _fn) \
4042
struct sprd_div _struct = { \
41-
.div = _SPRD_DIV_CLK(_shift, _width), \
43+
.div = _SPRD_DIV_CLK(_offset, _shift, _width), \
4244
.common = { \
4345
.regmap = NULL, \
4446
.reg = _reg, \
@@ -49,12 +51,17 @@ struct sprd_div {
4951

5052
#define SPRD_DIV_CLK(_struct, _name, _parent, _reg, \
5153
_shift, _width, _flags) \
52-
SPRD_DIV_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, \
54+
SPRD_DIV_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, 0x0, \
5355
_shift, _width, _flags, CLK_HW_INIT)
5456

57+
#define SPRD_DIV_CLK_FW_NAME(_struct, _name, _parent, _reg, \
58+
_shift, _width, _flags) \
59+
SPRD_DIV_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, 0x0, \
60+
_shift, _width, _flags, CLK_HW_INIT_FW_NAME)
61+
5562
#define SPRD_DIV_CLK_HW(_struct, _name, _parent, _reg, \
5663
_shift, _width, _flags) \
57-
SPRD_DIV_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, \
64+
SPRD_DIV_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, 0x0, \
5865
_shift, _width, _flags, CLK_HW_INIT_HW)
5966

6067
static inline struct sprd_div *hw_to_sprd_div(const struct clk_hw *hw)

0 commit comments

Comments
 (0)