Skip to content

Commit 720e4a4

Browse files
committed
Merge branches 'clk-renesas', 'clk-kunit', 'clk-regmap' and 'clk-frac-divider' into clk-next
- Make clk kunit tests work with lockdep - Fix clk gate kunit test for big-endian - Convert more than a handful of clk drivers to use regmap maple tree - Consider the CLK_FRAC_DIVIDER_ZERO_BASED in fractional divider clk implementation * clk-renesas: (23 commits) clk: renesas: r9a08g045: Add clock and reset support for SDHI1 and SDHI2 clk: renesas: rzg2l: Use %x format specifier to print CLK_ON_R() clk: renesas: Add minimal boot support for RZ/G3S SoC clk: renesas: rzg2l: Add divider clock for RZ/G3S clk: renesas: rzg2l: Refactor SD mux driver clk: renesas: rzg2l: Remove CPG_SDHI_DSEL from generic header clk: renesas: rzg2l: Add struct clk_hw_data clk: renesas: rzg2l: Add support for RZ/G3S PLL clk: renesas: rzg2l: Remove critical area clk: renesas: rzg2l: Fix computation formula clk: renesas: rzg2l: Trust value returned by hardware clk: renesas: rzg2l: Lock around writes to mux register clk: renesas: rzg2l: Wait for status bit of SD mux before continuing clk: renesas: rcar-gen3: Extend SDnH divider table dt-bindings: clock: renesas,rzg2l-cpg: Document RZ/G3S SoC clk: renesas: r8a7795: Constify r8a7795_*_clks clk: renesas: r9a06g032: Name anonymous structs clk: renesas: r9a06g032: Fix kerneldoc warning clk: renesas: rzg2l: Use u32 for flag and mux_flags clk: renesas: rzg2l: Use FIELD_GET() for PLL register fields ... * clk-kunit: clk: Fix clk gate kunit test on big-endian CPUs clk: Parameterize clk_leaf_mux_set_rate_parent clk: Drive clk_leaf_mux_set_rate_parent test from clk_ops * clk-regmap: clk: versaclock7: Convert to use maple tree register cache clk: versaclock5: Convert to use maple tree register cache clk: versaclock3: Convert to use maple tree register cache clk: versaclock3: Remove redundant _is_writeable() clk: si570: Convert to use maple tree register cache clk: si544: Convert to use maple tree register cache clk: si5351: Convert to use maple tree register cache clk: si5341: Convert to use maple tree register cache clk: si514: Convert to use maple tree register cache clk: cdce925: Convert to use maple tree register cache * clk-frac-divider: clk: fractional-divider: tests: Add test suite for edge cases clk: fractional-divider: Improve approximation when zero based and export
5 parents d33050a + c3f1874 + 7535782 + 9e95292 + 2790e2a commit 720e4a4

28 files changed

+1314
-184
lines changed

Documentation/devicetree/bindings/clock/renesas,rzg2l-cpg.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ properties:
2727
- renesas,r9a07g043-cpg # RZ/G2UL{Type-1,Type-2} and RZ/Five
2828
- renesas,r9a07g044-cpg # RZ/G2{L,LC}
2929
- renesas,r9a07g054-cpg # RZ/V2L
30+
- renesas,r9a08g045-cpg # RZ/G3S
3031
- renesas,r9a09g011-cpg # RZ/V2M
3132

3233
reg:

drivers/clk/.kunitconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ CONFIG_KUNIT=y
22
CONFIG_COMMON_CLK=y
33
CONFIG_CLK_KUNIT_TEST=y
44
CONFIG_CLK_GATE_KUNIT_TEST=y
5+
CONFIG_CLK_FD_KUNIT_TEST=y
56
CONFIG_UML_PCI_OVER_VIRTIO=n

drivers/clk/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,4 +526,11 @@ config CLK_GATE_KUNIT_TEST
526526
help
527527
Kunit test for the basic clk gate type.
528528

529+
config CLK_FD_KUNIT_TEST
530+
tristate "Basic fractional divider type Kunit test" if !KUNIT_ALL_TESTS
531+
depends on KUNIT
532+
default KUNIT_ALL_TESTS
533+
help
534+
Kunit test for the clk-fractional-divider type.
535+
529536
endif

drivers/clk/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ obj-$(CONFIG_COMMON_CLK) += clk-multiplier.o
1212
obj-$(CONFIG_COMMON_CLK) += clk-mux.o
1313
obj-$(CONFIG_COMMON_CLK) += clk-composite.o
1414
obj-$(CONFIG_COMMON_CLK) += clk-fractional-divider.o
15+
obj-$(CONFIG_CLK_FD_KUNIT_TEST) += clk-fractional-divider_test.o
1516
obj-$(CONFIG_COMMON_CLK) += clk-gpio.o
1617
ifeq ($(CONFIG_OF), y)
1718
obj-$(CONFIG_COMMON_CLK) += clk-conf.o

drivers/clk/clk-cdce925.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ static int cdce925_probe(struct i2c_client *client)
647647
.name = "configuration0",
648648
.reg_bits = 8,
649649
.val_bits = 8,
650-
.cache_type = REGCACHE_RBTREE,
650+
.cache_type = REGCACHE_MAPLE,
651651
};
652652

653653
dev_dbg(&client->dev, "%s\n", __func__);

drivers/clk/clk-fractional-divider.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ void clk_fractional_divider_general_approximation(struct clk_hw *hw,
123123
unsigned long *m, unsigned long *n)
124124
{
125125
struct clk_fractional_divider *fd = to_clk_fd(hw);
126+
unsigned long max_m, max_n;
126127

127128
/*
128129
* Get rate closer to *parent_rate to guarantee there is no overflow
@@ -138,10 +139,17 @@ void clk_fractional_divider_general_approximation(struct clk_hw *hw,
138139
rate <<= scale - fd->nwidth;
139140
}
140141

141-
rational_best_approximation(rate, *parent_rate,
142-
GENMASK(fd->mwidth - 1, 0), GENMASK(fd->nwidth - 1, 0),
143-
m, n);
142+
if (fd->flags & CLK_FRAC_DIVIDER_ZERO_BASED) {
143+
max_m = 1 << fd->mwidth;
144+
max_n = 1 << fd->nwidth;
145+
} else {
146+
max_m = GENMASK(fd->mwidth - 1, 0);
147+
max_n = GENMASK(fd->nwidth - 1, 0);
148+
}
149+
150+
rational_best_approximation(rate, *parent_rate, max_m, max_n, m, n);
144151
}
152+
EXPORT_SYMBOL_GPL(clk_fractional_divider_general_approximation);
145153

146154
static long clk_fd_round_rate(struct clk_hw *hw, unsigned long rate,
147155
unsigned long *parent_rate)
@@ -169,13 +177,18 @@ static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate,
169177
{
170178
struct clk_fractional_divider *fd = to_clk_fd(hw);
171179
unsigned long flags = 0;
172-
unsigned long m, n;
180+
unsigned long m, n, max_m, max_n;
173181
u32 mmask, nmask;
174182
u32 val;
175183

176-
rational_best_approximation(rate, parent_rate,
177-
GENMASK(fd->mwidth - 1, 0), GENMASK(fd->nwidth - 1, 0),
178-
&m, &n);
184+
if (fd->flags & CLK_FRAC_DIVIDER_ZERO_BASED) {
185+
max_m = 1 << fd->mwidth;
186+
max_n = 1 << fd->nwidth;
187+
} else {
188+
max_m = GENMASK(fd->mwidth - 1, 0);
189+
max_n = GENMASK(fd->nwidth - 1, 0);
190+
}
191+
rational_best_approximation(rate, parent_rate, max_m, max_n, &m, &n);
179192

180193
if (fd->flags & CLK_FRAC_DIVIDER_ZERO_BASED) {
181194
m--;
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Kunit test for clock fractional divider
4+
*/
5+
#include <linux/clk-provider.h>
6+
#include <kunit/test.h>
7+
8+
#include "clk-fractional-divider.h"
9+
10+
/*
11+
* Test the maximum denominator case for fd clock without flags.
12+
*
13+
* Expect the highest possible denominator to be used in order to get as close as possible to the
14+
* requested rate.
15+
*/
16+
static void clk_fd_test_approximation_max_denominator(struct kunit *test)
17+
{
18+
struct clk_fractional_divider *fd;
19+
unsigned long rate, parent_rate, parent_rate_before, m, n, max_n;
20+
21+
fd = kunit_kzalloc(test, sizeof(*fd), GFP_KERNEL);
22+
KUNIT_ASSERT_NOT_NULL(test, fd);
23+
24+
fd->mwidth = 3;
25+
fd->nwidth = 3;
26+
max_n = 7;
27+
28+
rate = 240000000;
29+
parent_rate = (max_n + 1) * rate; /* so that it exceeds the maximum divisor */
30+
parent_rate_before = parent_rate;
31+
32+
clk_fractional_divider_general_approximation(&fd->hw, rate, &parent_rate, &m, &n);
33+
KUNIT_ASSERT_EQ(test, parent_rate, parent_rate_before);
34+
35+
KUNIT_EXPECT_EQ(test, m, 1);
36+
KUNIT_EXPECT_EQ(test, n, max_n);
37+
}
38+
39+
/*
40+
* Test the maximum numerator case for fd clock without flags.
41+
*
42+
* Expect the highest possible numerator to be used in order to get as close as possible to the
43+
* requested rate.
44+
*/
45+
static void clk_fd_test_approximation_max_numerator(struct kunit *test)
46+
{
47+
struct clk_fractional_divider *fd;
48+
unsigned long rate, parent_rate, parent_rate_before, m, n, max_m;
49+
50+
fd = kunit_kzalloc(test, sizeof(*fd), GFP_KERNEL);
51+
KUNIT_ASSERT_NOT_NULL(test, fd);
52+
53+
fd->mwidth = 3;
54+
max_m = 7;
55+
fd->nwidth = 3;
56+
57+
rate = 240000000;
58+
parent_rate = rate / (max_m + 1); /* so that it exceeds the maximum numerator */
59+
parent_rate_before = parent_rate;
60+
61+
clk_fractional_divider_general_approximation(&fd->hw, rate, &parent_rate, &m, &n);
62+
KUNIT_ASSERT_EQ(test, parent_rate, parent_rate_before);
63+
64+
KUNIT_EXPECT_EQ(test, m, max_m);
65+
KUNIT_EXPECT_EQ(test, n, 1);
66+
}
67+
68+
/*
69+
* Test the maximum denominator case for zero based fd clock.
70+
*
71+
* Expect the highest possible denominator to be used in order to get as close as possible to the
72+
* requested rate.
73+
*/
74+
static void clk_fd_test_approximation_max_denominator_zero_based(struct kunit *test)
75+
{
76+
struct clk_fractional_divider *fd;
77+
unsigned long rate, parent_rate, parent_rate_before, m, n, max_n;
78+
79+
fd = kunit_kzalloc(test, sizeof(*fd), GFP_KERNEL);
80+
KUNIT_ASSERT_NOT_NULL(test, fd);
81+
82+
fd->flags = CLK_FRAC_DIVIDER_ZERO_BASED;
83+
fd->mwidth = 3;
84+
fd->nwidth = 3;
85+
max_n = 8;
86+
87+
rate = 240000000;
88+
parent_rate = (max_n + 1) * rate; /* so that it exceeds the maximum divisor */
89+
parent_rate_before = parent_rate;
90+
91+
clk_fractional_divider_general_approximation(&fd->hw, rate, &parent_rate, &m, &n);
92+
KUNIT_ASSERT_EQ(test, parent_rate, parent_rate_before);
93+
94+
KUNIT_EXPECT_EQ(test, m, 1);
95+
KUNIT_EXPECT_EQ(test, n, max_n);
96+
}
97+
98+
/*
99+
* Test the maximum numerator case for zero based fd clock.
100+
*
101+
* Expect the highest possible numerator to be used in order to get as close as possible to the
102+
* requested rate.
103+
*/
104+
static void clk_fd_test_approximation_max_numerator_zero_based(struct kunit *test)
105+
{
106+
struct clk_fractional_divider *fd;
107+
unsigned long rate, parent_rate, parent_rate_before, m, n, max_m;
108+
109+
fd = kunit_kzalloc(test, sizeof(*fd), GFP_KERNEL);
110+
KUNIT_ASSERT_NOT_NULL(test, fd);
111+
112+
fd->flags = CLK_FRAC_DIVIDER_ZERO_BASED;
113+
fd->mwidth = 3;
114+
max_m = 8;
115+
fd->nwidth = 3;
116+
117+
rate = 240000000;
118+
parent_rate = rate / (max_m + 1); /* so that it exceeds the maximum numerator */
119+
parent_rate_before = parent_rate;
120+
121+
clk_fractional_divider_general_approximation(&fd->hw, rate, &parent_rate, &m, &n);
122+
KUNIT_ASSERT_EQ(test, parent_rate, parent_rate_before);
123+
124+
KUNIT_EXPECT_EQ(test, m, max_m);
125+
KUNIT_EXPECT_EQ(test, n, 1);
126+
}
127+
128+
static struct kunit_case clk_fd_approximation_test_cases[] = {
129+
KUNIT_CASE(clk_fd_test_approximation_max_denominator),
130+
KUNIT_CASE(clk_fd_test_approximation_max_numerator),
131+
KUNIT_CASE(clk_fd_test_approximation_max_denominator_zero_based),
132+
KUNIT_CASE(clk_fd_test_approximation_max_numerator_zero_based),
133+
{}
134+
};
135+
136+
/*
137+
* Test suite for clk_fractional_divider_general_approximation().
138+
*/
139+
static struct kunit_suite clk_fd_approximation_suite = {
140+
.name = "clk-fd-approximation",
141+
.test_cases = clk_fd_approximation_test_cases,
142+
};
143+
144+
kunit_test_suites(
145+
&clk_fd_approximation_suite
146+
);
147+
MODULE_LICENSE("GPL");

drivers/clk/clk-gate_test.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ struct clk_gate_test_context {
131131
void __iomem *fake_mem;
132132
struct clk_hw *hw;
133133
struct clk_hw *parent;
134-
u32 fake_reg; /* Keep at end, KASAN can detect out of bounds */
134+
__le32 fake_reg; /* Keep at end, KASAN can detect out of bounds */
135135
};
136136

137137
static struct clk_gate_test_context *clk_gate_test_alloc_ctx(struct kunit *test)
@@ -166,7 +166,7 @@ static void clk_gate_test_enable(struct kunit *test)
166166

167167
KUNIT_ASSERT_EQ(test, clk_prepare_enable(clk), 0);
168168

169-
KUNIT_EXPECT_EQ(test, enable_val, ctx->fake_reg);
169+
KUNIT_EXPECT_EQ(test, enable_val, le32_to_cpu(ctx->fake_reg));
170170
KUNIT_EXPECT_TRUE(test, clk_hw_is_enabled(hw));
171171
KUNIT_EXPECT_TRUE(test, clk_hw_is_prepared(hw));
172172
KUNIT_EXPECT_TRUE(test, clk_hw_is_enabled(parent));
@@ -183,10 +183,10 @@ static void clk_gate_test_disable(struct kunit *test)
183183
u32 disable_val = 0;
184184

185185
KUNIT_ASSERT_EQ(test, clk_prepare_enable(clk), 0);
186-
KUNIT_ASSERT_EQ(test, enable_val, ctx->fake_reg);
186+
KUNIT_ASSERT_EQ(test, enable_val, le32_to_cpu(ctx->fake_reg));
187187

188188
clk_disable_unprepare(clk);
189-
KUNIT_EXPECT_EQ(test, disable_val, ctx->fake_reg);
189+
KUNIT_EXPECT_EQ(test, disable_val, le32_to_cpu(ctx->fake_reg));
190190
KUNIT_EXPECT_FALSE(test, clk_hw_is_enabled(hw));
191191
KUNIT_EXPECT_FALSE(test, clk_hw_is_prepared(hw));
192192
KUNIT_EXPECT_FALSE(test, clk_hw_is_enabled(parent));
@@ -246,7 +246,7 @@ static void clk_gate_test_invert_enable(struct kunit *test)
246246

247247
KUNIT_ASSERT_EQ(test, clk_prepare_enable(clk), 0);
248248

249-
KUNIT_EXPECT_EQ(test, enable_val, ctx->fake_reg);
249+
KUNIT_EXPECT_EQ(test, enable_val, le32_to_cpu(ctx->fake_reg));
250250
KUNIT_EXPECT_TRUE(test, clk_hw_is_enabled(hw));
251251
KUNIT_EXPECT_TRUE(test, clk_hw_is_prepared(hw));
252252
KUNIT_EXPECT_TRUE(test, clk_hw_is_enabled(parent));
@@ -263,10 +263,10 @@ static void clk_gate_test_invert_disable(struct kunit *test)
263263
u32 disable_val = BIT(15);
264264

265265
KUNIT_ASSERT_EQ(test, clk_prepare_enable(clk), 0);
266-
KUNIT_ASSERT_EQ(test, enable_val, ctx->fake_reg);
266+
KUNIT_ASSERT_EQ(test, enable_val, le32_to_cpu(ctx->fake_reg));
267267

268268
clk_disable_unprepare(clk);
269-
KUNIT_EXPECT_EQ(test, disable_val, ctx->fake_reg);
269+
KUNIT_EXPECT_EQ(test, disable_val, le32_to_cpu(ctx->fake_reg));
270270
KUNIT_EXPECT_FALSE(test, clk_hw_is_enabled(hw));
271271
KUNIT_EXPECT_FALSE(test, clk_hw_is_prepared(hw));
272272
KUNIT_EXPECT_FALSE(test, clk_hw_is_enabled(parent));
@@ -290,7 +290,7 @@ static int clk_gate_test_invert_init(struct kunit *test)
290290
2000000);
291291
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent);
292292

293-
ctx->fake_reg = BIT(15); /* Default to off */
293+
ctx->fake_reg = cpu_to_le32(BIT(15)); /* Default to off */
294294
hw = clk_hw_register_gate_parent_hw(NULL, "test_gate", parent, 0,
295295
ctx->fake_mem, 15,
296296
CLK_GATE_SET_TO_DISABLE, NULL);
@@ -319,7 +319,7 @@ static void clk_gate_test_hiword_enable(struct kunit *test)
319319

320320
KUNIT_ASSERT_EQ(test, clk_prepare_enable(clk), 0);
321321

322-
KUNIT_EXPECT_EQ(test, enable_val, ctx->fake_reg);
322+
KUNIT_EXPECT_EQ(test, enable_val, le32_to_cpu(ctx->fake_reg));
323323
KUNIT_EXPECT_TRUE(test, clk_hw_is_enabled(hw));
324324
KUNIT_EXPECT_TRUE(test, clk_hw_is_prepared(hw));
325325
KUNIT_EXPECT_TRUE(test, clk_hw_is_enabled(parent));
@@ -336,10 +336,10 @@ static void clk_gate_test_hiword_disable(struct kunit *test)
336336
u32 disable_val = BIT(9 + 16);
337337

338338
KUNIT_ASSERT_EQ(test, clk_prepare_enable(clk), 0);
339-
KUNIT_ASSERT_EQ(test, enable_val, ctx->fake_reg);
339+
KUNIT_ASSERT_EQ(test, enable_val, le32_to_cpu(ctx->fake_reg));
340340

341341
clk_disable_unprepare(clk);
342-
KUNIT_EXPECT_EQ(test, disable_val, ctx->fake_reg);
342+
KUNIT_EXPECT_EQ(test, disable_val, le32_to_cpu(ctx->fake_reg));
343343
KUNIT_EXPECT_FALSE(test, clk_hw_is_enabled(hw));
344344
KUNIT_EXPECT_FALSE(test, clk_hw_is_prepared(hw));
345345
KUNIT_EXPECT_FALSE(test, clk_hw_is_enabled(parent));
@@ -387,7 +387,7 @@ static void clk_gate_test_is_enabled(struct kunit *test)
387387
struct clk_gate_test_context *ctx;
388388

389389
ctx = clk_gate_test_alloc_ctx(test);
390-
ctx->fake_reg = BIT(7);
390+
ctx->fake_reg = cpu_to_le32(BIT(7));
391391
hw = clk_hw_register_gate(NULL, "test_gate", NULL, 0, ctx->fake_mem, 7,
392392
0, NULL);
393393
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
@@ -402,7 +402,7 @@ static void clk_gate_test_is_disabled(struct kunit *test)
402402
struct clk_gate_test_context *ctx;
403403

404404
ctx = clk_gate_test_alloc_ctx(test);
405-
ctx->fake_reg = BIT(4);
405+
ctx->fake_reg = cpu_to_le32(BIT(4));
406406
hw = clk_hw_register_gate(NULL, "test_gate", NULL, 0, ctx->fake_mem, 7,
407407
0, NULL);
408408
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
@@ -417,7 +417,7 @@ static void clk_gate_test_is_enabled_inverted(struct kunit *test)
417417
struct clk_gate_test_context *ctx;
418418

419419
ctx = clk_gate_test_alloc_ctx(test);
420-
ctx->fake_reg = BIT(31);
420+
ctx->fake_reg = cpu_to_le32(BIT(31));
421421
hw = clk_hw_register_gate(NULL, "test_gate", NULL, 0, ctx->fake_mem, 2,
422422
CLK_GATE_SET_TO_DISABLE, NULL);
423423
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
@@ -432,7 +432,7 @@ static void clk_gate_test_is_disabled_inverted(struct kunit *test)
432432
struct clk_gate_test_context *ctx;
433433

434434
ctx = clk_gate_test_alloc_ctx(test);
435-
ctx->fake_reg = BIT(29);
435+
ctx->fake_reg = cpu_to_le32(BIT(29));
436436
hw = clk_hw_register_gate(NULL, "test_gate", NULL, 0, ctx->fake_mem, 29,
437437
CLK_GATE_SET_TO_DISABLE, NULL);
438438
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);

drivers/clk/clk-si514.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static bool si514_regmap_is_writeable(struct device *dev, unsigned int reg)
321321
static const struct regmap_config si514_regmap_config = {
322322
.reg_bits = 8,
323323
.val_bits = 8,
324-
.cache_type = REGCACHE_RBTREE,
324+
.cache_type = REGCACHE_MAPLE,
325325
.max_register = SI514_REG_CONTROL,
326326
.writeable_reg = si514_regmap_is_writeable,
327327
.volatile_reg = si514_regmap_is_volatile,

drivers/clk/clk-si5341.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ static int si5341_wait_device_ready(struct i2c_client *client)
12601260
static const struct regmap_config si5341_regmap_config = {
12611261
.reg_bits = 8,
12621262
.val_bits = 8,
1263-
.cache_type = REGCACHE_RBTREE,
1263+
.cache_type = REGCACHE_MAPLE,
12641264
.ranges = si5341_regmap_ranges,
12651265
.num_ranges = ARRAY_SIZE(si5341_regmap_ranges),
12661266
.max_register = SI5341_REGISTER_MAX,

0 commit comments

Comments
 (0)