clk.c 730 B

123456789101112131415161718192021222324252627282930313233343536
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2012 ST Microelectronics
  4. * Viresh Kumar <vireshk@kernel.org>
  5. *
  6. * SPEAr clk - Common routines
  7. */
  8. #include <linux/clk-provider.h>
  9. #include <linux/types.h>
  10. #include "clk.h"
  11. long clk_round_rate_index(struct clk_hw *hw, unsigned long drate,
  12. unsigned long parent_rate, clk_calc_rate calc_rate, u8 rtbl_cnt,
  13. int *index)
  14. {
  15. unsigned long prev_rate, rate = 0;
  16. for (*index = 0; *index < rtbl_cnt; (*index)++) {
  17. prev_rate = rate;
  18. rate = calc_rate(hw, parent_rate, *index);
  19. if (drate < rate) {
  20. /* previous clock was best */
  21. if (*index) {
  22. rate = prev_rate;
  23. (*index)--;
  24. }
  25. break;
  26. }
  27. }
  28. if ((*index) == rtbl_cnt)
  29. (*index)--;
  30. return rate;
  31. }