Skip to content

Commit fd47ac9

Browse files
committed
Revert "clk: Always set the rate on clk_set_range_rate"
This reverts commit c80ac50.
1 parent f52bb34 commit fd47ac9

File tree

2 files changed

+52
-47
lines changed

2 files changed

+52
-47
lines changed

drivers/clk/clk.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,29 +2373,28 @@ int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max)
23732373
goto out;
23742374
}
23752375

2376-
/*
2377-
* Since the boundaries have been changed, let's give the
2378-
* opportunity to the provider to adjust the clock rate based on
2379-
* the new boundaries.
2380-
*
2381-
* We also need to handle the case where the clock is currently
2382-
* outside of the boundaries. Clamping the last requested rate
2383-
* to the current minimum and maximum will also handle this.
2384-
*
2385-
* FIXME:
2386-
* There is a catch. It may fail for the usual reason (clock
2387-
* broken, clock protected, etc) but also because:
2388-
* - round_rate() was not favorable and fell on the wrong
2389-
* side of the boundary
2390-
* - the determine_rate() callback does not really check for
2391-
* this corner case when determining the rate
2392-
*/
2393-
rate = clamp(clk->core->req_rate, min, max);
2394-
ret = clk_core_set_rate_nolock(clk->core, rate);
2395-
if (ret) {
2396-
/* rollback the changes */
2397-
clk->min_rate = old_min;
2398-
clk->max_rate = old_max;
2376+
rate = clk_core_get_rate_nolock(clk->core);
2377+
if (rate < min || rate > max) {
2378+
/*
2379+
* FIXME:
2380+
* We are in bit of trouble here, current rate is outside the
2381+
* the requested range. We are going try to request appropriate
2382+
* range boundary but there is a catch. It may fail for the
2383+
* usual reason (clock broken, clock protected, etc) but also
2384+
* because:
2385+
* - round_rate() was not favorable and fell on the wrong
2386+
* side of the boundary
2387+
* - the determine_rate() callback does not really check for
2388+
* this corner case when determining the rate
2389+
*/
2390+
2391+
rate = clamp(clk->core->req_rate, min, max);
2392+
ret = clk_core_set_rate_nolock(clk->core, rate);
2393+
if (ret) {
2394+
/* rollback the changes */
2395+
clk->min_rate = old_min;
2396+
clk->max_rate = old_max;
2397+
}
23992398
}
24002399

24012400
out:

drivers/clk/clk_test.c

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -549,12 +549,13 @@ static struct kunit_suite clk_range_test_suite = {
549549
};
550550

551551
/*
552-
* Test that if we have several subsequent calls to
553-
* clk_set_rate_range(), the core will reevaluate whether a new rate is
554-
* needed each and every time.
552+
* Test that if:
553+
* - we have several subsequent calls to clk_set_rate_range();
554+
* - and we have a round_rate ops that always return the maximum
555+
* frequency allowed;
555556
*
556-
* With clk_dummy_maximize_rate_ops, this means that the rate will
557-
* trail along the maximum as it evolves.
557+
* The clock will run at the minimum of all maximum boundaries
558+
* requested, even if those boundaries aren't there anymore.
558559
*/
559560
static void clk_range_test_set_range_rate_maximized(struct kunit *test)
560561
{
@@ -595,16 +596,18 @@ static void clk_range_test_set_range_rate_maximized(struct kunit *test)
595596

596597
rate = clk_get_rate(clk);
597598
KUNIT_ASSERT_GT(test, rate, 0);
598-
KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2);
599+
KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2 - 1000);
599600
}
600601

601602
/*
602-
* Test that if we have several subsequent calls to
603-
* clk_set_rate_range(), across multiple users, the core will reevaluate
604-
* whether a new rate is needed each and every time.
603+
* Test that if:
604+
* - we have several subsequent calls to clk_set_rate_range(), across
605+
* multiple users;
606+
* - and we have a round_rate ops that always return the maximum
607+
* frequency allowed;
605608
*
606-
* With clk_dummy_maximize_rate_ops, this means that the rate will
607-
* trail along the maximum as it evolves.
609+
* The clock will run at the minimum of all maximum boundaries
610+
* requested, even if those boundaries aren't there anymore.
608611
*/
609612
static void clk_range_test_multiple_set_range_rate_maximized(struct kunit *test)
610613
{
@@ -650,7 +653,7 @@ static void clk_range_test_multiple_set_range_rate_maximized(struct kunit *test)
650653

651654
rate = clk_get_rate(clk);
652655
KUNIT_ASSERT_GT(test, rate, 0);
653-
KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2);
656+
KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1);
654657

655658
clk_put(user2);
656659
clk_put(user1);
@@ -670,12 +673,13 @@ static struct kunit_suite clk_range_maximize_test_suite = {
670673
};
671674

672675
/*
673-
* Test that if we have several subsequent calls to
674-
* clk_set_rate_range(), the core will reevaluate whether a new rate is
675-
* needed each and every time.
676+
* Test that if:
677+
* - we have several subsequent calls to clk_set_rate_range()
678+
* - and we have a round_rate ops that always return the minimum
679+
* frequency allowed;
676680
*
677-
* With clk_dummy_minimize_rate_ops, this means that the rate will
678-
* trail along the minimum as it evolves.
681+
* The clock will run at the maximum of all minimum boundaries
682+
* requested, even if those boundaries aren't there anymore.
679683
*/
680684
static void clk_range_test_set_range_rate_minimized(struct kunit *test)
681685
{
@@ -716,16 +720,18 @@ static void clk_range_test_set_range_rate_minimized(struct kunit *test)
716720

717721
rate = clk_get_rate(clk);
718722
KUNIT_ASSERT_GT(test, rate, 0);
719-
KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1);
723+
KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1 + 1000);
720724
}
721725

722726
/*
723-
* Test that if we have several subsequent calls to
724-
* clk_set_rate_range(), across multiple users, the core will reevaluate
725-
* whether a new rate is needed each and every time.
727+
* Test that if:
728+
* - we have several subsequent calls to clk_set_rate_range(), across
729+
* multiple users;
730+
* - and we have a round_rate ops that always return the minimum
731+
* frequency allowed;
726732
*
727-
* With clk_dummy_minimize_rate_ops, this means that the rate will
728-
* trail along the minimum as it evolves.
733+
* The clock will run at the maximum of all minimum boundaries
734+
* requested, even if those boundaries aren't there anymore.
729735
*/
730736
static void clk_range_test_multiple_set_range_rate_minimized(struct kunit *test)
731737
{
@@ -767,7 +773,7 @@ static void clk_range_test_multiple_set_range_rate_minimized(struct kunit *test)
767773

768774
rate = clk_get_rate(clk);
769775
KUNIT_ASSERT_GT(test, rate, 0);
770-
KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1);
776+
KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2);
771777

772778
clk_put(user2);
773779
clk_put(user1);

0 commit comments

Comments
 (0)