clk.c 879 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (C) 2012 ST Microelectronics
  3. * Viresh Kumar <vireshk@kernel.org>
  4. *
  5. * This file is licensed under the terms of the GNU General Public
  6. * License version 2. This program is licensed "as is" without any
  7. * warranty of any kind, whether express or implied.
  8. *
  9. * SPEAr clk - Common routines
  10. */
  11. #include <linux/clk-provider.h>
  12. #include <linux/types.h>
  13. #include "clk.h"
  14. long clk_round_rate_index(struct clk_hw *hw, unsigned long drate,
  15. unsigned long parent_rate, clk_calc_rate calc_rate, u8 rtbl_cnt,
  16. int *index)
  17. {
  18. unsigned long prev_rate, rate = 0;
  19. for (*index = 0; *index < rtbl_cnt; (*index)++) {
  20. prev_rate = rate;
  21. rate = calc_rate(hw, parent_rate, *index);
  22. if (drate < rate) {
  23. /* previous clock was best */
  24. if (*index) {
  25. rate = prev_rate;
  26. (*index)--;
  27. }
  28. break;
  29. }
  30. }
  31. if ((*index) == rtbl_cnt)
  32. (*index)--;
  33. return rate;
  34. }