-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clk: starfive: jh7100: Make hw clock implementation reusable
The JH7100 has additional audio and video clocks at different memory ranges, but they use the same register layout. Add a header and export the starfive_jh7100_clk_ops function so the clock implementation can be reused by drivers handling these clocks. Signed-off-by: Emil Renner Berthing <kernel@esmil.dk> Link: https://lore.kernel.org/r/20220126173953.1016706-6-kernel@esmil.dk Signed-off-by: Stephen Boyd <sboyd@kernel.org>
- Loading branch information
Emil Renner Berthing
authored and
Stephen Boyd
committed
Mar 11, 2022
1 parent
c31b32f
commit 26ad971
Showing
2 changed files
with
104 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
#ifndef __CLK_STARFIVE_JH7100_H | ||
#define __CLK_STARFIVE_JH7100_H | ||
|
||
#include <linux/bits.h> | ||
#include <linux/clk-provider.h> | ||
|
||
/* register fields */ | ||
#define JH7100_CLK_ENABLE BIT(31) | ||
#define JH7100_CLK_INVERT BIT(30) | ||
#define JH7100_CLK_MUX_MASK GENMASK(27, 24) | ||
#define JH7100_CLK_MUX_SHIFT 24 | ||
#define JH7100_CLK_DIV_MASK GENMASK(23, 0) | ||
#define JH7100_CLK_FRAC_MASK GENMASK(15, 8) | ||
#define JH7100_CLK_FRAC_SHIFT 8 | ||
#define JH7100_CLK_INT_MASK GENMASK(7, 0) | ||
|
||
/* fractional divider min/max */ | ||
#define JH7100_CLK_FRAC_MIN 100UL | ||
#define JH7100_CLK_FRAC_MAX 25599UL | ||
|
||
/* clock data */ | ||
struct jh7100_clk_data { | ||
const char *name; | ||
unsigned long flags; | ||
u32 max; | ||
u8 parents[4]; | ||
}; | ||
|
||
#define JH7100_GATE(_idx, _name, _flags, _parent) [_idx] = { \ | ||
.name = _name, \ | ||
.flags = CLK_SET_RATE_PARENT | (_flags), \ | ||
.max = JH7100_CLK_ENABLE, \ | ||
.parents = { [0] = _parent }, \ | ||
} | ||
|
||
#define JH7100__DIV(_idx, _name, _max, _parent) [_idx] = { \ | ||
.name = _name, \ | ||
.flags = 0, \ | ||
.max = _max, \ | ||
.parents = { [0] = _parent }, \ | ||
} | ||
|
||
#define JH7100_GDIV(_idx, _name, _flags, _max, _parent) [_idx] = { \ | ||
.name = _name, \ | ||
.flags = _flags, \ | ||
.max = JH7100_CLK_ENABLE | (_max), \ | ||
.parents = { [0] = _parent }, \ | ||
} | ||
|
||
#define JH7100_FDIV(_idx, _name, _parent) [_idx] = { \ | ||
.name = _name, \ | ||
.flags = 0, \ | ||
.max = JH7100_CLK_FRAC_MAX, \ | ||
.parents = { [0] = _parent }, \ | ||
} | ||
|
||
#define JH7100__MUX(_idx, _name, _nparents, ...) [_idx] = { \ | ||
.name = _name, \ | ||
.flags = 0, \ | ||
.max = ((_nparents) - 1) << JH7100_CLK_MUX_SHIFT, \ | ||
.parents = { __VA_ARGS__ }, \ | ||
} | ||
|
||
#define JH7100_GMUX(_idx, _name, _flags, _nparents, ...) [_idx] = { \ | ||
.name = _name, \ | ||
.flags = _flags, \ | ||
.max = JH7100_CLK_ENABLE | \ | ||
(((_nparents) - 1) << JH7100_CLK_MUX_SHIFT), \ | ||
.parents = { __VA_ARGS__ }, \ | ||
} | ||
|
||
#define JH7100__INV(_idx, _name, _parent) [_idx] = { \ | ||
.name = _name, \ | ||
.flags = CLK_SET_RATE_PARENT, \ | ||
.max = JH7100_CLK_INVERT, \ | ||
.parents = { [0] = _parent }, \ | ||
} | ||
|
||
struct jh7100_clk { | ||
struct clk_hw hw; | ||
unsigned int idx; | ||
unsigned int max_div; | ||
}; | ||
|
||
struct jh7100_clk_priv { | ||
/* protect clk enable and set rate/parent from happening at the same time */ | ||
spinlock_t rmw_lock; | ||
struct device *dev; | ||
void __iomem *base; | ||
struct clk_hw *pll[3]; | ||
struct jh7100_clk reg[]; | ||
}; | ||
|
||
const struct clk_ops *starfive_jh7100_clk_ops(u32 max); | ||
|
||
#endif |