Skip to content

Commit a225493

Browse files
committed
Merge tag 'sunxi-clk-fixes-for-6.9-1' of https://git.kernel.org/pub/scm/linux/kernel/git/sunxi/linux into clk-fixes
Pull Allwinner clk driver fixes from Jernej Skrabec: - fix H6 CPU rate change via reparenting - set A64 MIPI PLL min & max rate * tag 'sunxi-clk-fixes-for-6.9-1' of https://git.kernel.org/pub/scm/linux/kernel/git/sunxi/linux: clk: sunxi-ng: a64: Set minimum and maximum rate for PLL-MIPI clk: sunxi-ng: common: Support minimum and maximum rate clk: sunxi-ng: h6: Reparent CPUX during PLL CPUX rate change
2 parents f8981b0 + 69f16d9 commit a225493

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

drivers/clk/sunxi-ng/ccu-sun50i-a64.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ static struct ccu_nkm pll_mipi_clk = {
182182
&ccu_nkm_ops,
183183
CLK_SET_RATE_UNGATE | CLK_SET_RATE_PARENT),
184184
.features = CCU_FEATURE_CLOSEST_RATE,
185+
.min_rate = 500000000,
186+
.max_rate = 1400000000,
185187
},
186188
};
187189

drivers/clk/sunxi-ng/ccu-sun50i-h6.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,11 +1181,18 @@ static const u32 usb2_clk_regs[] = {
11811181
SUN50I_H6_USB3_CLK_REG,
11821182
};
11831183

1184+
static struct ccu_mux_nb sun50i_h6_cpu_nb = {
1185+
.common = &cpux_clk.common,
1186+
.cm = &cpux_clk.mux,
1187+
.delay_us = 1,
1188+
.bypass_index = 0, /* index of 24 MHz oscillator */
1189+
};
1190+
11841191
static int sun50i_h6_ccu_probe(struct platform_device *pdev)
11851192
{
11861193
void __iomem *reg;
1194+
int i, ret;
11871195
u32 val;
1188-
int i;
11891196

11901197
reg = devm_platform_ioremap_resource(pdev, 0);
11911198
if (IS_ERR(reg))
@@ -1252,7 +1259,15 @@ static int sun50i_h6_ccu_probe(struct platform_device *pdev)
12521259
val |= BIT(24);
12531260
writel(val, reg + SUN50I_H6_HDMI_CEC_CLK_REG);
12541261

1255-
return devm_sunxi_ccu_probe(&pdev->dev, reg, &sun50i_h6_ccu_desc);
1262+
ret = devm_sunxi_ccu_probe(&pdev->dev, reg, &sun50i_h6_ccu_desc);
1263+
if (ret)
1264+
return ret;
1265+
1266+
/* Reparent CPU during PLL CPUX rate changes */
1267+
ccu_mux_notifier_register(pll_cpux_clk.common.hw.clk,
1268+
&sun50i_h6_cpu_nb);
1269+
1270+
return 0;
12561271
}
12571272

12581273
static const struct of_device_id sun50i_h6_ccu_ids[] = {

drivers/clk/sunxi-ng/ccu_common.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ bool ccu_is_better_rate(struct ccu_common *common,
4444
unsigned long current_rate,
4545
unsigned long best_rate)
4646
{
47+
unsigned long min_rate, max_rate;
48+
49+
clk_hw_get_rate_range(&common->hw, &min_rate, &max_rate);
50+
51+
if (current_rate > max_rate)
52+
return false;
53+
54+
if (current_rate < min_rate)
55+
return false;
56+
4757
if (common->features & CCU_FEATURE_CLOSEST_RATE)
4858
return abs(current_rate - target_rate) < abs(best_rate - target_rate);
4959

@@ -122,6 +132,7 @@ static int sunxi_ccu_probe(struct sunxi_ccu *ccu, struct device *dev,
122132

123133
for (i = 0; i < desc->hw_clks->num ; i++) {
124134
struct clk_hw *hw = desc->hw_clks->hws[i];
135+
struct ccu_common *common = hw_to_ccu_common(hw);
125136
const char *name;
126137

127138
if (!hw)
@@ -136,6 +147,14 @@ static int sunxi_ccu_probe(struct sunxi_ccu *ccu, struct device *dev,
136147
pr_err("Couldn't register clock %d - %s\n", i, name);
137148
goto err_clk_unreg;
138149
}
150+
151+
if (common->max_rate)
152+
clk_hw_set_rate_range(hw, common->min_rate,
153+
common->max_rate);
154+
else
155+
WARN(common->min_rate,
156+
"No max_rate, ignoring min_rate of clock %d - %s\n",
157+
i, name);
139158
}
140159

141160
ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get,

drivers/clk/sunxi-ng/ccu_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ struct ccu_common {
3131
u16 lock_reg;
3232
u32 prediv;
3333

34+
unsigned long min_rate;
35+
unsigned long max_rate;
36+
3437
unsigned long features;
3538
spinlock_t *lock;
3639
struct clk_hw hw;

0 commit comments

Comments
 (0)