Skip to content

Commit 6673699

Browse files
committed
clk: microchip: mpfs: setup for using other mss pll outputs
Now that the MSSPLL is split, and the "postdiv" divider of the cpu/AHB/AXI bus clock is represented by its own "hw" struct, make the shifts, register offset and width a parameter of the initialisation macro, rather than using defines that only work for one of the four outputs. Configuring this at initialisaion paves the way for using the other three output clocks, where the register offset, and the bit shift within that register, will differ. Signed-off-by: Conor Dooley <[email protected]>
1 parent 1afa948 commit 6673699

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

drivers/clk/microchip/clk-mpfs.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
/* address offset of control registers */
1717
#define REG_MSSPLL_REF_CR 0x08u
18-
#define REG_MSSPLL_POSTDIV_CR 0x10u
18+
#define REG_MSSPLL_POSTDIV01_CR 0x10u
19+
#define REG_MSSPLL_POSTDIV23_CR 0x14u
1920
#define REG_MSSPLL_SSCG_2_CR 0x2Cu
2021
#define REG_CLOCK_CONFIG_CR 0x08u
2122
#define REG_RTC_CLOCK_CR 0x0Cu
@@ -26,7 +27,7 @@
2627
#define MSSPLL_FBDIV_WIDTH 0x0Cu
2728
#define MSSPLL_REFDIV_SHIFT 0x08u
2829
#define MSSPLL_REFDIV_WIDTH 0x06u
29-
#define MSSPLL_POSTDIV_SHIFT 0x08u
30+
#define MSSPLL_POSTDIV02_SHIFT 0x08u
3031
#define MSSPLL_POSTDIV_WIDTH 0x07u
3132
#define MSSPLL_FIXED_DIV 4u
3233

@@ -62,6 +63,9 @@ struct mpfs_msspll_out_hw_clock {
6263
struct clk_hw hw;
6364
struct clk_init_data init;
6465
unsigned int id;
66+
u32 reg_offset;
67+
u32 shift;
68+
u32 width;
6569
u32 flags;
6670
};
6771

@@ -175,11 +179,11 @@ static int mpfs_clk_register_mssplls(struct device *dev, struct mpfs_msspll_hw_c
175179
static unsigned long mpfs_clk_msspll_out_recalc_rate(struct clk_hw *hw, unsigned long prate)
176180
{
177181
struct mpfs_msspll_out_hw_clock *msspll_out_hw = to_mpfs_msspll_out_clk(hw);
178-
void __iomem *postdiv_addr = msspll_out_hw->base + REG_MSSPLL_POSTDIV_CR;
182+
void __iomem *postdiv_addr = msspll_out_hw->base + msspll_out_hw->reg_offset;
179183
u32 postdiv;
180184

181-
postdiv = readl_relaxed(postdiv_addr) >> MSSPLL_POSTDIV_SHIFT;
182-
postdiv &= clk_div_mask(MSSPLL_POSTDIV_WIDTH);
185+
postdiv = readl_relaxed(postdiv_addr) >> msspll_out_hw->shift;
186+
postdiv &= clk_div_mask(msspll_out_hw->width);
183187

184188
return prate / postdiv;
185189
}
@@ -189,19 +193,19 @@ static long mpfs_clk_msspll_out_round_rate(struct clk_hw *hw, unsigned long rate
189193
{
190194
struct mpfs_msspll_out_hw_clock *msspll_out_hw = to_mpfs_msspll_out_clk(hw);
191195

192-
return divider_round_rate(hw, rate, prate, NULL, MSSPLL_POSTDIV_WIDTH,
196+
return divider_round_rate(hw, rate, prate, NULL, msspll_out_hw->width,
193197
msspll_out_hw->flags);
194198
}
195199

196200
static int mpfs_clk_msspll_out_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long prate)
197201
{
198202
struct mpfs_msspll_out_hw_clock *msspll_out_hw = to_mpfs_msspll_out_clk(hw);
199-
void __iomem *postdiv_addr = msspll_out_hw->base + REG_MSSPLL_POSTDIV_CR;
203+
void __iomem *postdiv_addr = msspll_out_hw->base + msspll_out_hw->reg_offset;
200204
u32 postdiv;
201205
int divider_setting;
202206
unsigned long flags;
203207

204-
divider_setting = divider_get_val(rate, prate, NULL, MSSPLL_POSTDIV_WIDTH,
208+
divider_setting = divider_get_val(rate, prate, NULL, msspll_out_hw->width,
205209
msspll_out_hw->flags);
206210

207211
if (divider_setting < 0)
@@ -210,7 +214,7 @@ static int mpfs_clk_msspll_out_set_rate(struct clk_hw *hw, unsigned long rate, u
210214
spin_lock_irqsave(&mpfs_clk_lock, flags);
211215

212216
postdiv = readl_relaxed(postdiv_addr);
213-
postdiv &= ~(clk_div_mask(MSSPLL_POSTDIV_WIDTH) << MSSPLL_POSTDIV_SHIFT);
217+
postdiv &= ~(clk_div_mask(msspll_out_hw->width) << msspll_out_hw->shift);
214218
writel_relaxed(postdiv, postdiv_addr);
215219

216220
spin_unlock_irqrestore(&mpfs_clk_lock, flags);
@@ -224,14 +228,18 @@ static const struct clk_ops mpfs_clk_msspll_out_ops = {
224228
.set_rate = mpfs_clk_msspll_out_set_rate,
225229
};
226230

227-
#define CLK_PLL_OUT(_id, _name, _parent, _flags) { \
231+
#define CLK_PLL_OUT(_id, _name, _parent, _flags, _shift, _width, _offset) { \
228232
.id = _id, \
233+
.shift = _shift, \
234+
.width = _width, \
235+
.reg_offset = _offset, \
229236
.flags = _flags, \
230237
.hw.init = CLK_HW_INIT(_name, _parent, &mpfs_clk_msspll_out_ops, 0), \
231238
}
232239

233240
static struct mpfs_msspll_out_hw_clock mpfs_msspll_out_clks[] = {
234-
CLK_PLL_OUT(CLK_MSSPLL0, "clk_msspll", "clk_msspll_internal", 0),
241+
CLK_PLL_OUT(CLK_MSSPLL0, "clk_msspll", "clk_msspll_internal", 0,
242+
MSSPLL_POSTDIV02_SHIFT, MSSPLL_POSTDIV_WIDTH, REG_MSSPLL_POSTDIV01_CR),
235243
};
236244

237245
static int mpfs_clk_register_msspll_outs(struct device *dev,

0 commit comments

Comments
 (0)